Skip to content

Commit

Permalink
change AtomsBase constructor arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreener64 committed Mar 18, 2024
1 parent 49b79b4 commit 94104ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ AtomsCalculators.forces(ab_sys, calc)
```
We can also convert the AtomsBase.jl system to a Molly [`System`](@ref):
```julia
System(ab_sys, u"kJ", u"kJ/Å")
System(ab_sys; force_units=u"kJ/Å", energy_units=u"kJ")
```
```
System with 5 atoms, boundary CubicBoundary{Quantity{Float64, 𝐋, Unitful.FreeUnits{(Å,), 𝐋, nothing}}}(Quantity{Float64, 𝐋, Unitful.FreeUnits{(Å,), 𝐋, nothing}}[1.54732 Å, 1.4654985 Å, 1.792895 Å])
Expand Down
15 changes: 10 additions & 5 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1095,14 +1095,17 @@ end
Base.show(io::IO, ::MIME"text/plain", s::Union{System, ReplicaSystem}) = show(io, s)

"""
System(abstract_system)
System(abstract_system; force_units=u"kJ * mol^-1 * nm^-1", energy_units=u"kJ * mol^-1")
Convert an AtomsBase `AbstractSystem` to a Molly `System`.
`force_units` and `energy_units` should be set as appropriate.
To add properties not present in the AtomsBase interface (e.g. pair potentials) use the
convenience constructor `System(sys::System)`.
"""
function System(sys::AbstractSystem{D}, energy_units, force_units) where D
function System(sys::AbstractSystem{D};
force_units=u"kJ * mol^-1 * nm^-1",
energy_units=u"kJ * mol^-1") where D
# Convert BC to Molly types
bb = bounding_box(sys)
bcs = AtomsBase.boundary_conditions(sys)
Expand Down Expand Up @@ -1175,8 +1178,8 @@ function System(sys::AbstractSystem{D}, energy_units, force_units) where D
boundary=molly_boundary,
velocities=vels,
atoms_data=atoms_data,
energy_units=energy_units,
force_units=force_units,
energy_units=energy_units,
)
end

Expand Down Expand Up @@ -1251,7 +1254,8 @@ AtomsCalculators.@generate_interface function AtomsCalculators.forces(
n_threads::Integer=Threads.nthreads(),
kwargs...,
)
sys_nointers = System(abstract_sys, calc.energy_units, calc.force_units)
sys_nointers = System(abstract_sys; force_units=calc.force_units,
energy_units=calc.energy_units)
sys = System(
sys_nointers;
pairwise_inters=calc.pairwise_inters,
Expand All @@ -1271,7 +1275,8 @@ AtomsCalculators.@generate_interface function AtomsCalculators.potential_energy(
n_threads::Integer=Threads.nthreads(),
kwargs...,
)
sys_nointers = System(abstract_sys, calc.energy_units, calc.force_units)
sys_nointers = System(abstract_sys; force_units=calc.force_units,
energy_units=calc.energy_units)
sys = System(
sys_nointers;
pairwise_inters=calc.pairwise_inters,
Expand Down
2 changes: 1 addition & 1 deletion test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ end
[0.0 , 1.4654985, 0.0 ],
[0.0 , 0.0 , 1.7928950]]u"Å",
)
molly_sys = System(ab_sys_2, u"kJ", u"kJ/Å")
molly_sys = System(ab_sys_2; energy_units=u"kJ", force_units=u"kJ/Å")
test_approx_eq(ab_sys_2, molly_sys; common_only=true)
end

Expand Down

0 comments on commit 94104ed

Please sign in to comment.