Skip to content

Commit 02c1a14

Browse files
authored
Merge pull request #48 from MineralsCloud:iterators
Use iteration methods in `basis_vectors`, `MetricTensor` & `cellparameters`
2 parents 3ad3878 + dc6c539 commit 02c1a14

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/lattice.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ function Lattice(a, b, c, α, β, γ)
102102
return Lattice(a1, a2, a3)
103103
end
104104

105-
function basis_vectors(lattice::Lattice)
106-
data = lattice.data
107-
return data[:, 1], data[:, 2], data[:, 3]
108-
end
105+
basis_vectors(lattice::Lattice) = lattice[:, 1], lattice[:, 2], lattice[:, 3]
109106

110107
centering(::Bravais{A,B}) where {A,B} = B()
111108

src/metric.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end
99
MetricTensor(m::AbstractMatrix) = MetricTensor(SHermitianCompact{3}(m))
1010
function MetricTensor(𝐚::AbstractVector, 𝐛::AbstractVector, 𝐜::AbstractVector)
1111
vecs = (𝐚, 𝐛, 𝐜)
12-
return MetricTensor([dot(vecs[i], vecs[j]) for i in 1:3, j in 1:3])
12+
return MetricTensor([dot(vᵢ, vⱼ) for vᵢ in vecs, vⱼ in vecs])
1313
end
1414
function MetricTensor(a, b, c, α, β, γ)
1515
g₁₂ = a * b * cos(γ)
@@ -21,9 +21,7 @@ end
2121
Lattice(g::MetricTensor) = Lattice(cellparameters(g))
2222

2323
function cellparameters(g::MetricTensor)
24-
data = g.data
25-
a², b², c², ab, ac, bc =
26-
data[1, 1], data[2, 2], data[3, 3], data[1, 2], data[1, 3], data[2, 3]
24+
a², b², c², ab, ac, bc = g[1, 1], g[2, 2], g[3, 3], g[1, 2], g[1, 3], g[2, 3]
2725
a, b, c = map(sqrt, (a², b², c²))
2826
γ, β, α = acos(ab / (a * b)), acos(ac / (a * c)), acos(bc / (b * c))
2927
return a, b, c, α, β, γ

0 commit comments

Comments
 (0)