diff --git a/src/core.jl b/src/core.jl index e821e84..05000e5 100644 --- a/src/core.jl +++ b/src/core.jl @@ -1,6 +1,6 @@ using CrystallographyCore: AbstractCell, Cell as CrystallographyCell, basisvectors using StaticArrays: MMatrix, MVector, SMatrix, SVector -using StructEquality: @struct_hash_equal +using StructEquality: @struct_hash_equal_isequal import CrystallographyCore: Lattice, natoms, atomtypes @@ -22,7 +22,7 @@ Numbers to distinguish atomic species `types` are given by a list of ``N`` integ The collinear polarizations `magmoms` only work with `get_symmetry` and are given as a list of ``N`` floating point values, or a vector of vectors. """ -@struct_hash_equal struct SpglibCell{L,P,T,M} <: AbstractCell +@struct_hash_equal_isequal struct SpglibCell{L,P,T,M} <: AbstractCell lattice::Lattice{L} positions::Vector{MVector{3,P}} atoms::Vector{T} @@ -158,7 +158,7 @@ end Represent `SpglibDataset`, see its [official documentation](https://spglib.github.io/spglib/dataset.html#spglib-dataset). """ -struct Dataset +@struct_hash_equal_isequal struct Dataset spacegroup_number::Int32 hall_number::Int32 international_symbol::String diff --git a/test/dataset.jl b/test/dataset.jl index dcc65c9..6b46b13 100644 --- a/test/dataset.jl +++ b/test/dataset.jl @@ -139,19 +139,19 @@ [0.5, 0.0, 0.5], [0.5, 0.0, 0.5], ] # Compared with Python results - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 64, - :international_short => "Cmce", - :international_full => "C 2/m 2/c 2_1/e", - :international => "C m c e", - :schoenflies => "D2h^18", - :hall_number => 304, - :hall_symbol => "-C 2bc 2", - :choice => "", - :pointgroup_international => "mmm", - :pointgroup_schoenflies => "D2h", - :arithmetic_crystal_class_number => 19, - :arithmetic_crystal_class_symbol => "mmmC", + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == SpacegroupType( + 64, + "Cmce", + "C 2/m 2/c 2_1/e", + "C m c e", + "D2h^18", + 304, + "-C 2bc 2", + "", + "mmm", + "D2h", + 19, + "mmmC", ) # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) @@ -271,19 +271,19 @@ end @test dataset.std_types == [1, 1, 2, 2, 2, 2] # 14, 14, 8, 8, 8, 8 @test dataset.std_mapping_to_primitive == [0, 1, 2, 3, 4, 5] @test dataset.pointgroup_symbol == "4/mmm" - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 136, - :international_short => "P4_2/mnm", - :international_full => "P 4_2/m 2_1/n 2/m", - :international => "P 4_2/m n m", - :schoenflies => "D4h^14", - :hall_number => 419, - :hall_symbol => "-P 4n 2n", - :choice => "", - :pointgroup_international => "4/mmm", - :pointgroup_schoenflies => "D4h", - :arithmetic_crystal_class_number => 36, - :arithmetic_crystal_class_symbol => "4/mmmP", + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == SpacegroupType( + 136, + "P4_2/mnm", + "P 4_2/m 2_1/n 2/m", + "P 4_2/m n m", + "D4h^14", + 419, + "-P 4n 2n", + "", + "4/mmm", + "D4h", + 36, + "4/mmmP", ) # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) @@ -376,20 +376,8 @@ end @test get_symmetry(cell) == (dataset.rotations, dataset.translations) @test get_symmetry_from_database(dataset.hall_number)[1] == dataset.rotations @test get_symmetry_from_database(dataset.hall_number)[2] == dataset.translations - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 1, - :international_short => "P1", - :international_full => "P 1", - :international => "P 1", - :schoenflies => "C1^1", - :hall_number => 1, - :hall_symbol => "P 1", - :choice => "", - :pointgroup_international => "1", - :pointgroup_schoenflies => "C1", - :arithmetic_crystal_class_number => 1, - :arithmetic_crystal_class_symbol => "1P", - ) # Compared with Python results + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == + SpacegroupType(1, "P1", "P 1", "P 1", "C1^1", 1, "P 1", "", "1", "C1", 1, "1P") # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) @test get_dataset_with_hall_number(cell, dataset.hall_number) == dataset @@ -523,19 +511,19 @@ end end @test dataset.std_mapping_to_primitive == [0, 1] @test dataset.pointgroup_symbol == "-3m" - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 164, - :international_short => "P-3m1", - :international_full => "P -3 2/m 1", - :international => "P -3 m 1", - :schoenflies => "D3d^3", - :hall_number => 456, - :hall_symbol => "-P 3 2\"", - :choice => "", - :pointgroup_international => "-3m", - :pointgroup_schoenflies => "D3d", - :arithmetic_crystal_class_number => 49, - :arithmetic_crystal_class_symbol => "-3m1P", + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == SpacegroupType( + 164, + "P-3m1", + "P -3 2/m 1", + "P -3 m 1", + "D3d^3", + 456, + "-P 3 2\"", + "", + "-3m", + "D3d", + 49, + "-3m1P", ) # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) @@ -1008,19 +996,19 @@ end end @test dataset.std_mapping_to_primitive == [0, 1, 0, 1, 0, 1, 0, 1] @test dataset.pointgroup_symbol == "m-3m" - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 227, - :international_short => "Fd-3m", - :international_full => "F 4_1/d -3 2/m", - :international => "F d -3 m", - :schoenflies => "Oh^7", - :hall_number => 525, - :hall_symbol => "F 4d 2 3 -1d", - :choice => "1", - :pointgroup_international => "m-3m", - :pointgroup_schoenflies => "Oh", - :arithmetic_crystal_class_number => 72, - :arithmetic_crystal_class_symbol => "m-3mF", + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == SpacegroupType( + 227, + "Fd-3m", + "F 4_1/d -3 2/m", + "F d -3 m", + "Oh^7", + 525, + "F 4d 2 3 -1d", + "1", + "m-3m", + "Oh", + 72, + "m-3mF", ) # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) @@ -1194,19 +1182,19 @@ end end @test dataset.std_mapping_to_primitive == [0, 1, 0, 1, 0, 1, 0, 1] @test dataset.pointgroup_symbol == "m-3m" - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 227, - :international_short => "Fd-3m", - :international_full => "F 4_1/d -3 2/m", - :international => "F d -3 m", - :schoenflies => "Oh^7", - :hall_number => 525, - :hall_symbol => "F 4d 2 3 -1d", - :choice => "1", - :pointgroup_international => "m-3m", - :pointgroup_schoenflies => "Oh", - :arithmetic_crystal_class_number => 72, - :arithmetic_crystal_class_symbol => "m-3mF", + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == SpacegroupType( + 227, + "Fd-3m", + "F 4_1/d -3 2/m", + "F d -3 m", + "Oh^7", + 525, + "F 4d 2 3 -1d", + "1", + "m-3m", + "Oh", + 72, + "m-3mF", ) # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) @@ -1323,19 +1311,19 @@ end dataset.std_rotation_matrix * std_lattice_before_idealization end @test dataset.std_mapping_to_primitive == 0:2 - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 191, - :international_short => "P6/mmm", - :international_full => "P 6/m 2/m 2/m", - :international => "P 6/m m m", - :schoenflies => "D6h^1", - :hall_number => 485, - :hall_symbol => "-P 6 2", - :choice => "", - :pointgroup_international => "6/mmm", - :pointgroup_schoenflies => "D6h", - :arithmetic_crystal_class_number => 58, - :arithmetic_crystal_class_symbol => "6/mmm", + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == SpacegroupType( + 191, + "P6/mmm", + "P 6/m 2/m 2/m", + "P 6/m m m", + "D6h^1", + 485, + "-P 6 2", + "", + "6/mmm", + "D6h", + 58, + "6/mmm", ) # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) @@ -1451,19 +1439,19 @@ end dataset.std_rotation_matrix * std_lattice_before_idealization end @test dataset.std_mapping_to_primitive == 0:3 # FIXME: should I +1? - @test type2dict(get_spacegroup_type_from_symmetry(cell, 1e-5)) == Dict( - :number => 186, - :international_short => "P6_3mc", - :international_full => "P 6_3 m c", - :international => "P 6_3 m c", - :schoenflies => "C6v^4", - :hall_number => 480, - :hall_symbol => "P 6c -2c", - :choice => "", - :pointgroup_international => "6mm", - :pointgroup_schoenflies => "C6v", - :arithmetic_crystal_class_number => 55, - :arithmetic_crystal_class_symbol => "6mmP", + @test get_spacegroup_type_from_symmetry(cell, 1e-5) == SpacegroupType( + 186, + "P6_3mc", + "P 6_3 m c", + "P 6_3 m c", + "C6v^4", + 480, + "P 6c -2c", + "", + "6mm", + "C6v", + 55, + "6mmP", ) # Compared with Python results @test get_hall_number_from_symmetry(cell, 1e-5) == dataset.hall_number @test get_multiplicity(cell, 1e-5) == length(dataset.translations) diff --git a/test/symmetry.jl b/test/symmetry.jl index fb6bd96..b53acec 100644 --- a/test/symmetry.jl +++ b/test/symmetry.jl @@ -1,81 +1,61 @@ -function type2dict(dt) - dict = Dict{Symbol,Any}() - for n in propertynames(dt) - dict[n] = getproperty(dt, n) - end - return dict -end - @testset "Test `get_spacegroup_type`" begin # Adapted from https://github.com/unkcpz/LibSymspg.jl/blob/53d2f6d/test/test_api.jl#L7-L12 - @test type2dict(get_spacegroup_type(101)) == Dict( - :number => 15, - :international_short => "C2/c", - :international_full => "I 1 1 2/a", - :international => "C 2/c = I 1 1 2/a", - :schoenflies => "C2h^6", - :hall_number => 101, - :hall_symbol => "-I 2a", - :choice => "-c3", - :pointgroup_international => "2/m", - :pointgroup_schoenflies => "C2h", - :arithmetic_crystal_class_number => 8, - :arithmetic_crystal_class_symbol => "2/mC", - ) - @test type2dict(get_spacegroup_type(419)) == Dict( - :number => 136, - :international_short => "P4_2/mnm", - :international_full => "P 4_2/m 2_1/n 2/m", - :international => "P 4_2/m n m", - :schoenflies => "D4h^14", - :hall_number => 419, - :hall_symbol => "-P 4n 2n", - :choice => "", - :pointgroup_schoenflies => "D4h", - :pointgroup_international => "4/mmm", - :arithmetic_crystal_class_number => 36, - :arithmetic_crystal_class_symbol => "4/mmmP", + @test get_spacegroup_type(101) == SpacegroupType( + 15, + "C2/c", + "I 1 1 2/a", + "C 2/c = I 1 1 2/a", + "C2h^6", + 101, + "-I 2a", + "-c3", + "2/m", + "C2h", + 8, + "2/mC", ) - @test type2dict(get_spacegroup_type(1)) == Dict( - :number => 1, - :international_short => "P1", - :international_full => "P 1", - :international => "P 1", - :schoenflies => "C1^1", - :hall_number => 1, - :hall_symbol => "P 1", - :choice => "", - :pointgroup_schoenflies => "C1", - :pointgroup_international => "1", - :arithmetic_crystal_class_number => 1, - :arithmetic_crystal_class_symbol => "1P", + @test get_spacegroup_type(419) == SpacegroupType( + 136, + "P4_2/mnm", + "P 4_2/m 2_1/n 2/m", + "P 4_2/m n m", + "D4h^14", + 419, + "-P 4n 2n", + "", + "4/mmm", + "D4h", + 36, + "4/mmmP", ) - @test type2dict(get_spacegroup_type(525)) == Dict( - :number => 227, - :international_short => "Fd-3m", - :international_full => "F 4_1/d -3 2/m", - :international => "F d -3 m", - :schoenflies => "Oh^7", - :hall_number => 525, - :hall_symbol => "F 4d 2 3 -1d", - :choice => "1", - :pointgroup_schoenflies => "Oh", - :pointgroup_international => "m-3m", - :arithmetic_crystal_class_number => 72, - :arithmetic_crystal_class_symbol => "m-3mF", + @test get_spacegroup_type(1) == + SpacegroupType(1, "P1", "P 1", "P 1", "C1^1", 1, "P 1", "", "1", "C1", 1, "1P") + @test get_spacegroup_type(525) == SpacegroupType( + 227, + "Fd-3m", + "F 4_1/d -3 2/m", + "F d -3 m", + "Oh^7", + 525, + "F 4d 2 3 -1d", + "1", + "m-3m", + "Oh", + 72, + "m-3mF", ) - @test type2dict(get_spacegroup_type(485)) == Dict( - :number => 191, - :international_short => "P6/mmm", - :international_full => "P 6/m 2/m 2/m", - :international => "P 6/m m m", - :schoenflies => "D6h^1", - :hall_number => 485, - :hall_symbol => "-P 6 2", - :choice => "", - :pointgroup_schoenflies => "D6h", - :pointgroup_international => "6/mmm", - :arithmetic_crystal_class_number => 58, - :arithmetic_crystal_class_symbol => "6/mmm", + @test get_spacegroup_type(485) == SpacegroupType( + 191, + "P6/mmm", + "P 6/m 2/m 2/m", + "P 6/m m m", + "D6h^1", + 485, + "-P 6 2", + "", + "6/mmm", + "D6h", + 58, + "6/mmm", ) end