Skip to content

Commit

Permalink
Update Spglib
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst committed Oct 13, 2023
1 parent 37bfa08 commit f98b04e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ PseudoPotentialIO = "0.1"
Requires = "1"
Roots = "2"
SpecialFunctions = "2"
Spglib = "0.6, 0.7, 0.8"
Spglib = "0.8"
StaticArrays = "1"
Statistics = "1"
TimerOutputs = "0.5.12"
Unitful = "1"
UnitfulAtomic = "1"
julia = "1.7"
spglib_jll = "1.15"
spglib_jll = "2"

[extras]
ASEconvert = "3da9722f-58c2-4165-81be-b4d7253e8fd2"
Expand Down
16 changes: 10 additions & 6 deletions src/external/spglib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ function spglib_atoms(atom_groups,
end
end

@assert !arbitrary_spin # Not yet supported
collinear = !arbitrary_spin && !all(iszero, spg_spins)
(; positions=spg_positions, numbers=spg_numbers, spins=spg_spins, collinear)
end

function spglib_cell(lattice, atom_groups, positions, magnetic_moments)
spg = spglib_atoms(atom_groups, positions, magnetic_moments)
(; cell=Spglib.Cell(lattice, spg.positions, spg.numbers, spg.spins), spg.collinear)
Spglib.SpglibCell(lattice, spg.positions, spg.numbers, spg.spins)
end
function spglib_cell(model::Model, magnetic_moments)
spglib_cell(model.lattice, model.atom_groups, model.positions, magnetic_moments)
Expand Down Expand Up @@ -165,8 +166,8 @@ function spglib_standardize_cell(lattice::AbstractArray{T}, atom_groups, positio
# https://github.com/JuliaMolSim/DFTK.jl/pull/496/files#r725203554
# Essentially this does not influence the standardisation,
# but it only influences the kpath.
cell, _ = spglib_cell(lattice, atom_groups, positions, magnetic_moments)
std_cell = Spglib.standardize_cell(cell; to_primitive=primitive, symprec=tol_symmetry,
cell = spglib_cell(lattice, atom_groups, positions, magnetic_moments)
std_cell = Spglib.standardize_cell(cell, tol_symmetry; to_primitive=primitive,
no_idealize=!correct_symmetry)

lattice = Matrix{T}(std_cell.lattice)
Expand All @@ -180,9 +181,12 @@ function spglib_standardize_cell(model::Model, magnetic_moments=[]; kwargs...)
end


function spglib_spacegroup_number(model, magnetic_moments=[]; tol_symmetry=SYMMETRY_TOLERANCE)
function spglib_spacegroup_number(model::Model, magnetic_moments=[]; tol_symmetry=SYMMETRY_TOLERANCE)
# Get spacegroup number according to International Tables for Crystallography (ITA)
# TODO Time-reversal symmetry disabled? (not yet available in DFTK)
cell, _ = spglib_cell(model, magnetic_moments)
Spglib.get_spacegroup_number(cell, tol_symmetry)
spglib_dataset(model, magnetic_moments; tol_symmetry).spacegroup_number
end

function spglib_dataset(model::Model, magnetic_moments=[]; tol_symmetry=SYMMETRY_TOLERANCE)
Spglib.get_dataset(spglib_cell(model, magnetic_moments), tol_symmetry)
end
1 change: 1 addition & 0 deletions test/external/spglib.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DFTK
using DFTK: spglib_spacegroup_number, spglib_standardize_cell
using LinearAlgebra
using Test
Expand Down

0 comments on commit f98b04e

Please sign in to comment.