Skip to content

Commit

Permalink
AtomsBase compat
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreener64 committed Nov 25, 2024
1 parent 216a112 commit 5cfef68
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ MollyPythonCallExt = "PythonCall"

[compat]
Atomix = "0.1"
AtomsBase = "0.4"
AtomsBase = "0.5"
AtomsCalculators = "0.2"
BioStructures = "4"
CUDA = "4.2, 5"
Expand All @@ -69,7 +69,7 @@ PeriodicTable = "1.1"
PythonCall = "0.9"
Random = "1.9"
Reexport = "1"
SimpleCrystals = "0.3"
SimpleCrystals = "0.4"
SparseArrays = "1.9"
StaticArrays = "1.8.2"
Statistics = "1.9"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ using AtomsCalculators

ab_sys = AtomsBase.AbstractSystem(
make_test_system().system;
bounding_box = [[1.54732, 0.0 , 0.0 ],
cell_vectors = [[1.54732, 0.0 , 0.0 ],
[0.0 , 1.4654985, 0.0 ],
[0.0 , 0.0 , 1.7928950]]u"Å",
)
Expand Down
6 changes: 3 additions & 3 deletions src/spatial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Unitful.ustrip(u::Unitful.Units, b::CubicBoundary) = CubicBoundary(ustrip.(u, b.
Unitful.ustrip(b::RectangularBoundary) = RectangularBoundary(ustrip.(b.side_lengths))
Unitful.ustrip(u::Unitful.Units, b::RectangularBoundary) = RectangularBoundary(ustrip.(u, b.side_lengths))

function AtomsBase.bounding_box(b::CubicBoundary)
function AtomsBase.cell_vectors(b::CubicBoundary)
z = zero(b[1])
bb = (
SVector(b[1], z , z ),
Expand All @@ -218,7 +218,7 @@ function AtomsBase.bounding_box(b::CubicBoundary)
return unit(z) == NoUnits ? (bb .* u"nm") : bb # Assume nm without other information
end

function AtomsBase.bounding_box(b::RectangularBoundary)
function AtomsBase.cell_vectors(b::RectangularBoundary)
z = zero(b[1])
bb = (
SVector(b[1], z ),
Expand All @@ -227,7 +227,7 @@ function AtomsBase.bounding_box(b::RectangularBoundary)
return unit(z) == NoUnits ? (bb .* u"nm") : bb
end

function AtomsBase.bounding_box(b::TriclinicBoundary)
function AtomsBase.cell_vectors(b::TriclinicBoundary)
bb = (b.basis_vectors[1], b.basis_vectors[2], b.basis_vectors[3])
return unit(b[1][1]) == NoUnits ? (bb .* u"nm") : bb
end
Expand Down
10 changes: 5 additions & 5 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ function System(crystal::Crystal{D};
coords = [SVector{D}(AtomsBase.position(crystal, i)) for i in 1:length(crystal)]

# Build bounding box
side_lengths = norm.(AtomsBase.bounding_box(crystal))
side_lengths = norm.(AtomsBase.cell_vectors(crystal))
if any(typeof(crystal.lattice.crystal_family) .<: [CubicLattice, OrthorhombicLattice, TetragonalLattice])
boundary = CubicBoundary(side_lengths...)
elseif any(typeof(crystal.lattice.crystal_family) .<: [SquareLattice, RectangularLattice])
Expand Down Expand Up @@ -1162,12 +1162,12 @@ function AtomsBase.atomic_number(s::Union{System, ReplicaSystem}, i::Integer)
end
end

AtomsBase.bounding_box(s::System) = AtomsBase.bounding_box(s.boundary)
AtomsBase.bounding_box(s::ReplicaSystem) = AtomsBase.bounding_box(s.replicas[1])
AtomsBase.cell_vectors(s::System) = AtomsBase.cell_vectors(s.boundary)
AtomsBase.cell_vectors(s::ReplicaSystem) = AtomsBase.cell_vectors(s.replicas[1])

function AtomsBase.cell(sys::System{D}) where D
return AtomsBase.PeriodicCell(
AtomsBase.bounding_box(sys),
AtomsBase.cell_vectors(sys),
has_infinite_boundary(sys) ? ntuple(i -> !isinf(sys.boundary.side_lengths[i]), D) :
ntuple(i -> true, D),
)
Expand Down Expand Up @@ -1199,7 +1199,7 @@ convenience constructor `System(sys::System)`.
function System(sys::AtomsBase.AbstractSystem{D};
force_units=u"kJ * mol^-1 * nm^-1",
energy_units=u"kJ * mol^-1") where D
bb = AtomsBase.bounding_box(sys)
bb = AtomsBase.cell_vectors(sys)
is_cubic = true
for (i, bv) in enumerate(bb)
for j in 1:(i - 1)
Expand Down
6 changes: 3 additions & 3 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
@test TriclinicBoundary(b.basis_vectors) == b
@test TriclinicBoundary([b.basis_vectors[1], b.basis_vectors[2], b.basis_vectors[3]]) == b

@test AtomsBase.bounding_box(b) == (b.basis_vectors[1], b.basis_vectors[2], b.basis_vectors[3])
@test AtomsBase.cell_vectors(b) == (b.basis_vectors[1], b.basis_vectors[2], b.basis_vectors[3])
@test volume(b) 3.89937463181886u"nm^3"
@test isapprox(box_center(b), SVector(2.28944, 1.1359815, 0.5116602)u"nm"; atol=1e-6u"nm")
sb = scale_boundary(b, 1.2)
Expand Down Expand Up @@ -476,7 +476,7 @@ end
# Update values to be something that works with Molly
ab_sys_2 = AtomsBase.AbstractSystem(
ab_sys_1;
bounding_box = [[1.54732, 0.0 , 0.0],
cell_vectors = [[1.54732, 0.0 , 0.0],
[0.0 , 1.4654985, 0.0],
[0.0 , 0.0 , Inf]]u"Å",
)
Expand All @@ -487,7 +487,7 @@ end
@testset "AtomsCalculators" begin
ab_sys = AtomsBase.AbstractSystem(
make_test_system().system;
bounding_box = [[1.54732, 0.0 , 0.0 ],
cell_vectors = [[1.54732, 0.0 , 0.0 ],
[0.0 , 1.4654985, 0.0 ],
[0.0 , 0.0 , 1.7928950]]u"Å",
)
Expand Down
6 changes: 3 additions & 3 deletions test/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
random_velocities!(s, temp)

@test masses(s) == fill(10.0u"g/mol", n_atoms)
@test AtomsBase.bounding_box(s) == (
@test AtomsBase.cell_vectors(s) == (
SVector(2.0, 0.0)u"nm",
SVector(0.0, 2.0)u"nm",
)
Expand Down Expand Up @@ -109,7 +109,7 @@ end
@test AtomsBase.mass(s, 5) == atom_mass
@test AtomsBase.atomic_symbol(s) == fill(:Ar, n_atoms)
@test AtomsBase.atomic_symbol(s, 5) == :Ar
@test AtomsBase.bounding_box(s) == (
@test AtomsBase.cell_vectors(s) == (
SVector(2.0, 0.0, 0.0)u"nm",
SVector(0.0, 2.0, 0.0)u"nm",
SVector(0.0, 0.0, 2.0)u"nm",
Expand Down Expand Up @@ -671,7 +671,7 @@ end
@test eachindex(repsys) == Base.OneTo(n_atoms)
@test AtomsBase.mass(repsys, :) == fill(atom_mass, n_atoms)
@test AtomsBase.mass(repsys, 5) == atom_mass
@test AtomsBase.bounding_box(repsys) == (
@test AtomsBase.cell_vectors(repsys) == (
SVector(2.0, 0.0, 0.0)u"nm",
SVector(0.0, 2.0, 0.0)u"nm",
SVector(0.0, 0.0, 2.0)u"nm",
Expand Down

0 comments on commit 5cfef68

Please sign in to comment.