Skip to content

Commit f01bb85

Browse files
committed
fix cell_vectors
1 parent b2c3f4d commit f01bb85

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SimpleCrystals"
22
uuid = "64031d72-e220-11ed-1a7e-43a2532b2fa8"
33
authors = ["Ethan Meitz <emeitz@andrew.cmu.edu>"]
4-
version = "0.4.2"
4+
version = "0.4.3"
55

66
[deps]
77
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"

src/Crystal.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ Base.length(sys::Crystal) = length(sys.atoms)
8282
Base.iterate(sys::Crystal, state = 1) = state > length(sys) ? nothing : (sys.atoms[state], state + 1)
8383
Base.eachindex(sys::Crystal) = Base.OneTo(length(sys))
8484

85-
AtomsBase.cell_vectors(sys::Crystal) = tuple(eachrow(sys.lattice.primitive_vectors .* sys.N_unit_cells)...)
86-
AtomsBase.periodicity(sys::Crystal{3}) = (true, true, true)
87-
AtomsBase.periodicity(sys::Crystal{2}) = (true, true)
85+
function AtomsBase.cell_vectors(sys::Crystal)
86+
t = tuple(eachrow(sys.lattice.primitive_vectors .* sys.N_unit_cells)...)
87+
return AtomsBase._auto_cell_vectors(t)
88+
end
89+
90+
AtomsBase.periodicity(::Crystal{3}) = (true, true, true)
91+
AtomsBase.periodicity(::Crystal{2}) = (true, true)
8892
AtomsBase.cell(sys::Crystal) = AtomsBase.PeriodicCell(cell_vectors(sys), periodicity(sys))
8993
AtomsBase.n_dimensions(sys::Crystal) = length(sys.N_unit_cells)
9094

src/atom.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
export
2-
Atom
1+
export Atom
32

43
#Load periodic table data
5-
periodic_table = PeriodicTable.elements
4+
const periodic_table = PeriodicTable.elements
65

76
struct Atom{D,T,C,M}
87
atomic_symbol::Symbol
@@ -11,12 +10,12 @@ struct Atom{D,T,C,M}
1110
atomic_mass::M
1211
end
1312

14-
function Atom(sym::Symbol, position; charge =0.0u"q", mass = periodic_table[sym].atomic_mass)
13+
function Atom(sym::Symbol, position; charge = 0.0u"q", mass = periodic_table[sym].atomic_mass)
1514
return Atom{length(position),eltype(position),typeof(charge),typeof(mass)}(sym, position, charge, mass)
1615
end
1716

18-
function Atom(position, mass::Number; charge = 0.0u"q")
19-
return Atom{length(position),eltype(position),typeof(charge), typeof(mass)}(:unknown, position, charge, mass)
17+
function Atom(position, mass::Number; charge = 0.0u"q", symbol = :unknown)
18+
return Atom{length(position),eltype(position),typeof(charge), typeof(mass)}(symbol, position, charge, mass)
2019
end
2120

2221

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ end
2929
@testset "AtomsBase" begin
3030

3131
fcc_crystal = FCC(0.54u"nm", :C, SVector(4,4,4))
32+
c = cell(fcc_crystal)
3233

3334
@test n_dimensions(fcc_crystal) == 3
3435
@test mass(fcc_crystal, 1) == mass(fcc_crystal[1])
3536
@test atomic_symbol(fcc_crystal,1) == :C
37+
38+
@test cell_vectors(fcc_crystal) isa NTuple{3, SVector{3}}
39+
@test periodicity(fcc_crystal) isa NTuple{3, Bool}
40+
@test cell(fcc_crystal) isa AtomsBase.PeriodicCell
41+
@test typeof(mass(fcc_crystal, 1)) <: Unitful.Mass
42+
@test ismissing(velocity(fcc_crystal))
43+
3644
end
3745

3846
@testset "Alternate Atom Constructor" begin

0 commit comments

Comments
 (0)