Skip to content

Commit

Permalink
Update Spglib interface
Browse files Browse the repository at this point in the history
  • Loading branch information
zhubonan committed Dec 13, 2022
1 parent 3e05108 commit 2e4071d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/spg.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Base
import Spglib
import Spglib: get_symmetry, get_international, get_dataset
import Spglib: standardize_cell, find_primitive, refine_cell, SpglibError
import Spglib: standardize_cell, find_primitive, refine_cell, niggli_reduce, SpglibError

struct SpglibConversionError <: Exception
var::String
Expand Down Expand Up @@ -101,20 +101,30 @@ end
@extend_scell_roundtrip standardize_cell
@extend_scell_roundtrip find_primitive
@extend_scell_roundtrip refine_cell
@extend_scell_roundtrip niggli_reduce
#@extend_scell_roundtrip niggli_reduce
@extend_scell_roundtrip delaunay_reduce

"""
niggli_reduce_cell(cell::Cell; wrap_pos=true)
Apply niggli reduction to the lattice using Spglib
"""
function niggli_reduce_cell(cell::Cell; wrap_pos=true)
reduced_cellmat = Spglib.niggli_reduce(cellmat(cell))
function niggli_reduce_cell(cell::Cell, symprec=1e-5; wrap_pos=true)
reduced_cellmat = Spglib.niggli_reduce(cellmat(cell), symprec)
outcell = deepcopy(cell)
set_cellmat!(outcell, reduced_cellmat, scale_positions=false)
wrap_pos && wrap!(outcell)
outcell
end

export get_symmetry, get_dataset, get_international, refine_cell, standardize_cell, find_primitive, niggli_reduce_cell
"""
niggli_reduce(cell::Cell, symprec=1e-5;)
Apply niggli reduction to the lattice using Spglib.
The positions are not wrapped.
"""
function Spglib.niggli_reduce(cell::Cell, symprec=1e-5)
niggli_reduce_cell(cell, symprec;wrap_pos=false)
end

export get_symmetry, get_dataset, get_international, refine_cell, standardize_cell, find_primitive, niggli_reduce_cell, niggli_reduce
8 changes: 8 additions & 0 deletions test/test_cell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ end
@test all(get_scaled_positions(reduced_cell) .== get_scaled_positions(reduced_cell2))
end

@testset "niggli_reduce" begin
testcell = Cell(Lattice(5.,5.,5.,30.,30.,30.), [1,2,3,3,3], pos)
testtmp = testcell
reduced_cell = niggli_reduce(testcell)
reduced_cell2 = niggli_reduce_cell(testcell;wrap_pos=false)
@test all(isapprox.(get_scaled_positions(reduced_cell), get_scaled_positions(reduced_cell2), atol=1e-7))
end

@testset "roundtrip functions" begin
testcell = Cell(Lattice(5.,5.,5.,30.,30.,30.), [1,2,3,3,3], pos)
@test isa(standardize_cell(testcell), Cell)
Expand Down
2 changes: 1 addition & 1 deletion test/test_composition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using CellBase: Composition, Cell, Lattice, formula

c1 = Composition("C3O4")
@test formula(c1) == :C3O4
show(c1)
show(devnull, c1)

# Equality test
@test Composition(formula(c1)) == c1
Expand Down

0 comments on commit 2e4071d

Please sign in to comment.