Skip to content

Commit

Permalink
Merge pull request #202 from MineralsCloud:Deprecate
Browse files Browse the repository at this point in the history
Deprecate extending `Lattice`, use `latticevectors`
  • Loading branch information
singularitti authored Mar 5, 2023
2 parents f4a2f4e + 3528742 commit 3d22eea
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 63 deletions.
11 changes: 2 additions & 9 deletions src/Inputs/PWscf/crystallography.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using CrystallographyBase: CartesianFromFractional
using LinearAlgebra: det
using Spglib: get_dataset

using ..Inputs: Ibrav
using ..Inputs: Ibrav, latticevectors

import CrystallographyBase: Cell, crystaldensity
import ChemicalFormula: Formula
Expand All @@ -14,19 +14,12 @@ struct InsufficientInfoError <: Exception
msg::AbstractString
end

"""
Ibrav(nml::SystemNamelist)
Return a `Ibrav` from a `SystemNamelist`.
"""
Ibrav(nml::SystemNamelist) = Ibrav(nml.ibrav)

"""
Lattice(nml::SystemNamelist)
Create a `Lattice` from a `SystemNamelist`.
"""
Lattice(nml::SystemNamelist) = Lattice(nml.celldm, Ibrav(nml))
Lattice(nml::SystemNamelist) = Lattice(latticevectors(nml.celldm, Ibrav(nml.ibrav)))
"""
Lattice(card::CellParametersCard)
Expand Down
95 changes: 41 additions & 54 deletions src/Inputs/crystallography.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CrystallographyBase: Lattice
using StaticArrays: MVector

@enum Ibrav begin
PrimitiveCubic = 1
Expand All @@ -23,92 +23,79 @@ import CrystallographyBase: Lattice
PrimitiveTriclinic = 14
end

"""
Lattice(p, ibrav::Ibrav)
Create a Bravais lattice from the exact lattice type and cell parameters `p` (not `celldm`!).
The first elements of `p` are `a`, `b`, `c`; the last 3 are `α`, `β`, `γ` (in radians).
"""
Lattice(p, ibrav::Ibrav) = Lattice(p, Val(Int(ibrav)))
Lattice(p, ::Val{1}) = Lattice(p[1] * [[1, 0, 0], [0, 1, 0], [0, 0, 1]]...)
Lattice(p, ::Val{2}) = Lattice(p[1] / 2 * [[-1, 0, 1], [0, 1, 1], [-1, 1, 0]]...)
Lattice(p, ::Val{3}) = Lattice(p[1] / 2 * [[1, 1, 1], [-1, 1, 1], [-1, -1, 1]]...)
Lattice(p, ::Val{-3}) = Lattice(p[1] / 2 * [[-1, 1, 1], [1, -1, 1], [1, 1, -1]]...)
Lattice(p, ::Val{4}) = Lattice(p[1] * [[1, 0, 0], [-1 / 2, 3 / 2, 0], [0, 0, p[3]]]...)
function Lattice(p, ::Val{5})
latticevectors(p, ibrav::Ibrav) = latticevectors(p, Val(Int(ibrav)))
latticevectors(p, ::Val{1}) = p[1] * [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
latticevectors(p, ::Val{2}) = p[1] / 2 * [[-1, 0, 1], [0, 1, 1], [-1, 1, 0]]
latticevectors(p, ::Val{3}) = p[1] / 2 * [[1, 1, 1], [-1, 1, 1], [-1, -1, 1]]
latticevectors(p, ::Val{-3}) = p[1] / 2 * [[-1, 1, 1], [1, -1, 1], [1, 1, -1]]
latticevectors(p, ::Val{4}) = p[1] * [[1, 0, 0], [-1 / 2, 3 / 2, 0], [0, 0, p[3]]]
function latticevectors(p, ::Val{5})
cosγ = p[4]
ty = sqrt((1 - cosγ) / 6)
tz = sqrt((1 + 2cosγ) / 3)
tx = sqrt((1 - cosγ) / 2)
return Lattice(p[1] * [[tx, -ty, tz], [0, 2ty, tz], [-tx, -ty, tz]]...)
return p[1] * [[tx, -ty, tz], [0, 2ty, tz], [-tx, -ty, tz]]
end
function Lattice(p, ::Val{-5})
function latticevectors(p, ::Val{-5})
cosγ = p[4]
ty = sqrt((1 - cosγ) / 6)
tz = sqrt((1 + 2cosγ) / 3)
a′ = p[1] / 3
u = tz - 2 * 2 * ty
v = tz + 2 * ty
return Lattice(a′ * [[u, v, v], [v, u, v], [v, v, u]]...)
return a′ * [[u, v, v], [v, u, v], [v, v, u]]
end
Lattice(p, ::Val{6}) = Lattice(p[1] * [[1, 0, 0], [0, 1, 0], [0, 0, p[3]]]...)
function Lattice(p, ::Val{7})
latticevectors(p, ::Val{6}) = p[1] * [[1, 0, 0], [0, 1, 0], [0, 0, p[3]]]
function latticevectors(p, ::Val{7})
r = p[3]
return Lattice(p[1] / 2 * [[1, -1, r], [1, 1, r], [-1, -1, r]]...)
return p[1] / 2 * [[1, -1, r], [1, 1, r], [-1, -1, r]]
end
Lattice(p, ::Val{8}) = Lattice(p[1] * [[1, 0, 0], [0, p[2], 0], [0, 0, p[3]]]...)
function Lattice(p, ::Val{9})
latticevectors(p, ::Val{8}) = p[1] * [[1, 0, 0], [0, p[2], 0], [0, 0, p[3]]]
function latticevectors(p, ::Val{9})
a, b, c = p[1] .* (1, p[2], p[3])
return Lattice([[a / 2, b / 2, 0], [-a / 2, b / 2, 0], [0, 0, c]]...)
return [[a / 2, b / 2, 0], [-a / 2, b / 2, 0], [0, 0, c]]
end
function Lattice(p, ::Val{-9})
function latticevectors(p, ::Val{-9})
a, b, c = p[1] .* (1, p[2], p[3])
return Lattice([[a / 2, -b / 2, 0], [a / 2, b / 2, 0], [0, 0, c]]...)
return [[a / 2, -b / 2, 0], [a / 2, b / 2, 0], [0, 0, c]]
end
function Lattice(p, ::Val{91})
function latticevectors(p, ::Val{91})
a, r1, r2 = p[1:3]
return Lattice(a * [[1, 0, 0], [0, r1 / 2, -r2 / 2], [0, r1 / 2, r2 / 2]]...)
return a * [[1, 0, 0], [0, r1 / 2, -r2 / 2], [0, r1 / 2, r2 / 2]]
end # New in QE 6.4
function Lattice(p, ::Val{10})
function latticevectors(p, ::Val{10})
a, b, c = p[1], p[1] * p[2], p[1] * p[3]
return Lattice(1 / 2 * [[a, 0, c], [a, b, 0], [0, b, c]]...)
return [[a, 0, c], [a, b, 0], [0, b, c]] / 2
end
function Lattice(p, ::Val{11})
function latticevectors(p, ::Val{11})
a, b, c = p[1] .* (1, p[2], p[3])
return Lattice(1 / 2 * [[a, b, c], [-a, b, c], [-a, -b, c]]...)
return [[a, b, c], [-a, b, c], [-a, -b, c]] / 2
end
function Lattice(p, ::Val{12})
function latticevectors(p, ::Val{12})
a, r1, r2, cosγ = p[1:4]
return Lattice(a * [[1, 0, 0], [r1 * cosγ, r1 * sin(acos(cosγ)), 0], [0, 0, r2]]...)
return a * [[1, 0, 0], [r1 * cosγ, r1 * sin(acos(cosγ)), 0], [0, 0, r2]]
end
function Lattice(p, ::Val{-12})
function latticevectors(p, ::Val{-12})
a, r1, r2, _, cosβ = p[1:5]
return Lattice(a * [[1, 0, 0], [0, r1, 0], [r2 * cosβ, 0, r2 * sin(acos(cosβ))]]...)
return a * [[1, 0, 0], [0, r1, 0], [r2 * cosβ, 0, r2 * sin(acos(cosβ))]]
end
function Lattice(p, ::Val{13})
function latticevectors(p, ::Val{13})
a, r1, r2, cosγ = p[1:4]
return Lattice(
a *
[[1 / 2, 0, -r2 / 2], [r1 * cosγ, r1 * sin(acos(cosγ)), 0], [1 / 2, 0, r2 / 2]]...,
)
return a *
[[1 / 2, 0, -r2 / 2], [r1 * cosγ, r1 * sin(acos(cosγ)), 0], [1 / 2, 0, r2 / 2]]
end
function Lattice(p, ::Val{-13})
function latticevectors(p, ::Val{-13})
a, r1, r2, _, cosβ = p[1:3]
return Lattice(
a *
[[1 / 2, r1 / 2, 0], [-1 / 2, r1 / 2, 0], [r2 * cosβ, 0, r2 * sin(acos(cosβ))]]...,
)
return a *
[[1 / 2, r1 / 2, 0], [-1 / 2, r1 / 2, 0], [r2 * cosβ, 0, r2 * sin(acos(cosβ))]]
end
function Lattice(p, ::Val{14})
function latticevectors(p, ::Val{14})
a, r1, r2, cosα, cosβ, cosγ = p[1:6] # Every `p` that is an iterable can be used
sinγ = sin(acos(cosγ))
δ = r2 * sqrt(1 + 2 * cosα * cosβ * cosγ - cosα^2 - cosβ^2 - cosγ^2) / sinγ
return Lattice(
a * [
[1, 0, 0],
[r1 * cosγ, r1 * sinγ, 0],
[r2 * cosβ, r2 * (cosα - cosβ * cosγ) / sinγ, δ],
]...,
)
return a * [
[1, 0, 0],
[r1 * cosγ, r1 * sinγ, 0],
[r2 * cosβ, r2 * (cosα - cosβ * cosγ) / sinγ, δ],
]
end

0 comments on commit 3d22eea

Please sign in to comment.