Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #26 and add complete AC v0.2 interface with tests #28

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
[compat]
AtomsBase = "0.3, 0.4"
AtomsCalculators = "0.2"
AtomsCalculatorsUtilities = "0.1.0"
AtomsCalculatorsUtilities = "0.1.3"
Bumper = "0.6, 0.7"
ForwardDiff = "0.10"
LinearAlgebra = "1"
Expand Down
4 changes: 2 additions & 2 deletions src/lennardjones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ cutoff_radius(V::LennardJones) = V.rcut * length_unit(V)
function eval_pair(V::LennardJones, r, z1, z2)
iz1 = _z2i(V.zlist, z1)
iz2 = _z2i(V.zlist, z2)
if iz1 == 0 || iz1 == 0 || r > V.rcut
return zero(_fltype(V))
if iz1 == 0 || iz2 == 0 || r > V.rcut
return zero( promote_type(_fltype(V), typeof(r)) )
end

_lj(s) = s^12 - 2 * s^6
Expand Down
4 changes: 2 additions & 2 deletions src/morse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ cutoff_radius(V::Morse) = V.rcut * length_unit(V)
function eval_pair(V::Morse, r, z1, z2)
iz1 = _z2i(V.zlist, z1)
iz2 = _z2i(V.zlist, z2)
if iz1 == 0 || iz1 == 0 || r > V.rcut
return zero(_fltype(V))
if iz1 == 0 || iz2 == 0 || r > V.rcut
return zero( promote_type(_fltype(V), typeof(r)) )
end

_m(s) = exp(-2 * s) - 2 * exp(-s)
Expand Down
8 changes: 5 additions & 3 deletions test/test_lennardjones.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using AtomsCalculators, EmpiricalPotentials, AtomsCalculatorsUtilities,

using LinearAlgebra: dot, norm, I
using AtomsCalculators: potential_energy, forces
using AtomsCalculators.Testing
using EmpiricalPotentials: cutoff_radius, LennardJones
ACT = AtomsCalculatorsUtilities.Testing

Expand Down Expand Up @@ -41,12 +42,13 @@ lj = LennardJones(emins, rmins, rcut)

function rand_struct(nrep)
sys = rattle!(bulk(:Al, cubic=true) * nrep, 0.1u"Å")
return randz!(sys, [ :Al => 0.5, :Cu => 0.5 ])
# Add an element that is not in the potential to see that it is ignored
return randz!(sys, [ :Al => 0.5, :Cu => 0.4, :Sn => 0.1 ])
end

sys = rand_struct(2)
@test potential_energy(sys, lj) isa Unitful.Energy
@test forces(sys, lj) isa Vector{<: SVector{3, <: Unitful.Force}}

test_energy_forces_virial(sys, lj)

for sys in [ rand_struct(1), rand_struct(2), rand_struct(2) ]
@test all( ACT.fdtest(sys, lj; rattle = 0.01u"Å", verbose=false) )
Expand Down
8 changes: 5 additions & 3 deletions test/test_morse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using AtomsCalculators, EmpiricalPotentials, AtomsCalculatorsUtilities,

using LinearAlgebra: dot, norm, I
using AtomsCalculators: potential_energy, forces
using AtomsCalculators.Testing
using EmpiricalPotentials: cutoff_radius, LennardJones
ACT = AtomsCalculatorsUtilities.Testing

Expand Down Expand Up @@ -38,12 +39,13 @@ V = Morse(params, rcut)

function rand_struct_morse(nrep)
sys = rattle!(bulk(:Al, cubic=true) * nrep, 0.1u"Å")
return randz!(sys, [ :Al => 0.5, :Cu => 0.5 ])
# Add an element that is not in the potential to see that it is ignored
return randz!(sys, [ :Al => 0.5, :Cu => 0.4, :Sn => 0.1 ])
end

sys = rand_struct_morse(2)
@test potential_energy(sys, V) isa Unitful.Energy
@test forces(sys, V) isa Vector{<: SVector{3, <: Unitful.Force}}

test_energy_forces_virial(sys, V)

for sys in [ rand_struct_morse(1), rand_struct_morse(2), rand_struct_morse(2) ]
@test all( ACT.fdtest(sys, V; rattle = 0.01u"Å", verbose=false) )
Expand Down
Loading