Skip to content

Commit

Permalink
AtomsBase output (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjarvinen authored Aug 29, 2023
1 parent 4a286a3 commit 5e6e01f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "PotentialDB"
uuid = "e899a7e1-cf22-409b-b35c-84b9d10c2c8e"
authors = ["Teemu Järvinen <[email protected]>"]
version = "0.2.3"
authors = ["Teemu Järvinen"]
version = "0.2.4-DEV"

[deps]
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PotentialCalculation = "76415700-ec45-11e8-0f65-f1df3c899b21"
Expand All @@ -12,7 +13,8 @@ SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
AtomsBase = "0.3"
JLD2 = "0.4"
PotentialCalculation = "0.4.2, 0.5, 0.6"
PotentialCalculation = "0.6"
Reexport = "0.2, 1.0"
julia = "1.6"
8 changes: 8 additions & 0 deletions docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ To load a wanted potential, call with `loadpotential` and key
p=loadpotential(d,"1")
```

### AtomsBase output

To load data in [AtomsBase]() format use

```@example 1
data = load_data(d, "1")
```

## Custom registries

Registries are defined by a TOML-file that holds information on where the file
Expand Down
2 changes: 2 additions & 0 deletions src/PotentialDB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module PotentialDB

using Reexport

using AtomsBase
using JLD2
@reexport using PotentialCalculation
using TOML
Expand All @@ -14,6 +15,7 @@ export addpotential!
export defaultregistry
export listpotentials
export loadpotential
export load_data
export saveregistry


Expand Down
34 changes: 34 additions & 0 deletions src/potentialregistry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,37 @@ function listpotentials(r::PotentialRegistry)
end
end


"""
load_data(reg, i; kwargs...)
Load data from registry as AtomsBase FlexibleSystem.
# kwargs
- `energy_unit=u"hartree"` : energy unit for output
- `strip_unit=false` ; whether or not strip energy unit or not
"""
function load_data(reg, i; energy_unit=u"hartree", strip_unit=false)
tmp = loadpotential(reg, i)
points = map( zip( tmp["Points"], tmp["Energy"] ) ) do (xyz, e)
tmp_e = e *u"hartree"
e_out = strip_unit ? ustrip(energy_unit, tmp_e) : uconvert(energy_unit, tmp_e)
FlexibleSystem(xyz; energy = e_out )
end
lc1 = length(tmp["cluster1"])
lc2 = length(tmp["cluster2"])
r1 = 1:lc1
r2 = (1:lc2) .+ lc1
cluster1 = map( tmp["Points"] ) do xyz
tmp_e = 0.0 *u"hartree"
e_out = strip_unit ? ustrip(energy_unit, tmp_e) : uconvert(energy_unit, tmp_e)
FlexibleSystem(xyz(r1); energy = e_out )
end
cluster2 = map( tmp["Points"] ) do xyz
tmp_e = 0.0 *u"hartree"
e_out = strip_unit ? ustrip(energy_unit, tmp_e) : uconvert(energy_unit, tmp_e)
FlexibleSystem(xyz(r2); energy = e_out )
end
return Dict("Points" => points, "cluster1" => cluster1, "cluster2"=>cluster2)
end
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ end
@test r.keywords == r2.keywords
listpotentials(r)
end


@testset "AtomsBase" begin
reg = defaultregistry()
data_hartree = load_data(reg, 1)
data_ev = load_data(reg, 1; energy_unit=u"eV")
data_strip = load_data(reg, 1; strip_unit=true)
c_data = loadpotential(reg, 1)

@test data_hartree["Points"][1][:energy] |> unit == u"hartree"
@test data_hartree["Points"][1][:energy] data_ev["Points"][1][:energy]
@test data_hartree["Points"][1][:energy] |> ustrip data_strip["Points"][1][:energy]
@test c_data["Energy"][1] == data_strip["Points"][1][:energy]
end

0 comments on commit 5e6e01f

Please sign in to comment.