Skip to content

Commit 16b428b

Browse files
authored
Integration with AbstractSystem (#10)
1 parent a0c1f1d commit 16b428b

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

Project.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PseudoPotentialData"
22
uuid = "5751a51d-ac76-4487-a056-413ecf6fbe19"
33
authors = ["Michael F. Herbst <[email protected]> and contributors"]
4-
version = "0.2.2"
4+
version = "0.2.3"
55

66
[deps]
77
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
@@ -10,8 +10,15 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1010
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
1111
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1212

13+
[weakdeps]
14+
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
15+
16+
[extensions]
17+
PseudoPotentialDataAtomsBaseExt = "AtomsBase"
18+
1319
[compat]
1420
Artifacts = "1"
21+
AtomsBase = "0.5"
1522
Compat = "4.16"
1623
DocStringExtensions = "0.9.3"
1724
LazyArtifacts = "1"
@@ -20,6 +27,8 @@ julia = "1.10"
2027

2128
[extras]
2229
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
30+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
31+
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
2332

2433
[targets]
25-
test = ["Test"]
34+
test = ["AtomsBase", "Unitful", "Test"]

docs/src/index.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,18 @@ cutoffs of plane-wave bases. These can be also accessed more conveniently via
7070
```@example index-example
7171
recommended_cutoff(family, :Si)
7272
```
73-
Note, that the `Ecut` and `Ecut_density` values are in atomic Hartree units.
73+
The `Ecut` and `Ecut_density` values are provided in atomic Hartree units.
74+
Note, that if you are working with `AbstractSystem` objects from
75+
[AtomsBase.jl](https://github.com/JuliaMolSim/AtomsBase.jl) compatible packages
76+
you can also directly supply a system to `recommended_cutoff` in order to obtain
77+
the *maximal* recommended values over all elements contained in the respective
78+
system, e.g.
79+
```julia
80+
using AtomsBuilder
81+
system = bulk(:Si)
82+
recommended_cutoff(family, system)
83+
```
84+
7485

7586
## Available pseudopotential families and naming convention
7687
A list of available pseudopotential families is available as
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module PseudoPotentialDataAtomsBaseExt
2+
using AtomsBase
3+
using PseudoPotentialData
4+
import PseudoPotentialData: recommended_cutoff
5+
6+
"""
7+
recommended_cutoff(family::PseudoFamily, system::AbstractSystem)
8+
9+
Return the recommended kinetic energy cutoff, supersampling and density cutoff
10+
for this `system`. Values may be `missing` if the respective data cannot be determined.
11+
"""
12+
function recommended_cutoff(family::PseudoFamily, system::AbstractSystem)
13+
function get_maximum(property)
14+
maximum(system) do atom
15+
getproperty(recommended_cutoff(family, element_symbol(atom)), property)
16+
end
17+
end
18+
19+
(; :Ecut => get_maximum(:Ecut),
20+
:supersampling => get_maximum(:supersampling),
21+
:Ecut_density => get_maximum(:Ecut_density))
22+
end
23+
24+
end

src/pseudofamily.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ function Base.show(io::IO, family::PseudoFamily)
6161
end
6262
Base.show(io::IO, ::MIME"text/plain", family::PseudoFamily) = show(io, family)
6363

64+
function Base.:(==)(lhs::PseudoFamily, rhs::PseudoFamily)
65+
lhs.identifier == rhs.identifier
66+
end
67+
6468
"""
6569
Get the full path to the file containing the pseudopotential information
6670
for a particular `element` (identified by an atomic symbol) and a particular

test/runtests.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using AtomsBase
12
using PseudoPotentialData
23
using Test
4+
using Unitful
5+
36

47
@testset "PseudoPotentialData.jl" begin
58
@testset "Test one family can be loaded" begin
@@ -59,6 +62,15 @@ using Test
5962
@test occursin("PseudoFamily", String(take!(io)))
6063
end
6164

65+
@testset "Comparison of family objects" begin
66+
f1 = PseudoFamily("dojo.nc.sr.pbe.v0_4_1.stringent.upf")
67+
f2 = PseudoFamily("dojo.nc.sr.lda.v0_4_1.stringent.upf")
68+
69+
@test f1 == f1
70+
@test f2 == f2
71+
@test f1 != f2
72+
end
73+
6274
@testset "Pseudometa on families" begin
6375
family = PseudoFamily("dojo.nc.sr.lda.v0_4_1.stringent.upf")
6476
meta = pseudometa(family)
@@ -114,4 +126,28 @@ using Test
114126
end
115127
end
116128
end
129+
130+
@testset "recommended_cutoff on systems" begin
131+
family = PseudoFamily("dojo.nc.sr.lda.v0_4_1.standard.upf")
132+
cutoffs_Si = recommended_cutoff(family, :Si)
133+
cutoffs_Ga = recommended_cutoff(family, :Ga)
134+
cutoffs_As = recommended_cutoff(family, :As)
135+
136+
ref_Ecut = max(cutoffs_Ga.Ecut, cutoffs_As.Ecut, cutoffs_Si.Ecut)
137+
ref_Edens = max(cutoffs_Ga.Ecut_density, cutoffs_As.Ecut_density,
138+
cutoffs_Si.Ecut_density)
139+
ref_super = max(cutoffs_Ga.supersampling, cutoffs_As.supersampling,
140+
cutoffs_Si.supersampling)
141+
142+
box = [[10, 0.0, 0.0], [0.0, 5, 0.0], [0.0, 0.0, 7]]u"Å"
143+
atoms = [:Si => [0.0, -0.125, 0.0],
144+
:Ga => [0.125, 0.0, 0.0],
145+
:As => [-0.125, 0.0, 0.0]]
146+
system = periodic_system(atoms, box; fractional=true)
147+
148+
cutoffs = recommended_cutoff(family, system)
149+
@test cutoffs.Ecut == ref_Ecut
150+
@test cutoffs.Ecut_density == ref_Edens
151+
@test cutoffs.supersampling == ref_super
152+
end
117153
end

0 commit comments

Comments
 (0)