• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

materialsproject / pymatgen / 4075885785

pending completion
4075885785

push

github

Shyue Ping Ong
Merge branch 'master' of github.com:materialsproject/pymatgen

96 of 96 new or added lines in 27 files covered. (100.0%)

81013 of 102710 relevant lines covered (78.88%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.97
/pymatgen/symmetry/tests/test_maggroups.py
1
from __future__ import annotations
1✔
2

3
import unittest
1✔
4

5
import numpy as np
1✔
6

7
from pymatgen.core.lattice import Lattice
1✔
8
from pymatgen.symmetry.groups import SpaceGroup
1✔
9
from pymatgen.symmetry.maggroups import MagneticSpaceGroup
1✔
10
from pymatgen.util.testing import PymatgenTest
1✔
11

12
__author__ = "Matthew Horton"
1✔
13
__copyright__ = "Copyright 2017, The Materials Project"
1✔
14
__version__ = "0.1"
1✔
15
__maintainer__ = "Matthew Horton"
1✔
16
__email__ = "mkhorton@lbl.gov"
1✔
17
__status__ = "Beta"
1✔
18
__date__ = "Feb 2017"
1✔
19

20

21
class MagneticSpaceGroupTest(PymatgenTest):
1✔
22
    def setUp(self):
1✔
23
        self.msg_1 = MagneticSpaceGroup([70, 530])
1✔
24
        self.msg_2 = MagneticSpaceGroup([62, 448])
1✔
25
        self.msg_3 = MagneticSpaceGroup([20, 37])
1✔
26
        self.msg_4 = MagneticSpaceGroup([2, 7], "c,1/4a+1/4b,-1/2a+1/2b;0,0,0")
1✔
27

28
    def test_init(self):
1✔
29
        # test init with the following space group:
30
        # 71.538 (BNS number), I_cmmm (BNS label)
31
        # 65.10.554 (same space group as above, OG number), C_Immm (OG label)
32
        msg_from_bns_1 = MagneticSpaceGroup("I_cmmm")
1✔
33
        msg_from_bns_2 = MagneticSpaceGroup([71, 538])
1✔
34
        msg_from_og_1 = MagneticSpaceGroup.from_og("C_Immm")
1✔
35
        msg_from_og_2 = MagneticSpaceGroup.from_og([65, 10, 554])
1✔
36
        assert msg_from_bns_1 == msg_from_bns_2
1✔
37
        assert msg_from_og_1 == msg_from_og_2
1✔
38
        assert msg_from_bns_1 == msg_from_og_1
1✔
39

40
    def test_crystal_system(self):
1✔
41
        assert self.msg_1.crystal_system == "orthorhombic"
1✔
42
        assert self.msg_2.crystal_system == "orthorhombic"
1✔
43
        assert self.msg_3.crystal_system == "orthorhombic"
1✔
44

45
    def test_sg_symbol(self):
1✔
46
        assert self.msg_1.sg_symbol == "Fd'd'd"
1✔
47
        assert self.msg_2.sg_symbol == "Pn'ma'"
1✔
48
        assert self.msg_3.sg_symbol == "C_A222_1"
1✔
49

50
    def test_is_compatible(self):
1✔
51
        cubic = Lattice.cubic(1)
1✔
52
        hexagonal = Lattice.hexagonal(1, 2)
1✔
53
        rhom = Lattice.rhombohedral(3, 80)
1✔
54
        tet = Lattice.tetragonal(1, 2)
1✔
55
        ortho = Lattice.orthorhombic(1, 2, 3)
1✔
56
        msg = MagneticSpaceGroup("Fm-3m")
1✔
57
        assert msg.is_compatible(cubic)
1✔
58
        assert not msg.is_compatible(hexagonal)
1✔
59
        msg = MagneticSpaceGroup("Pnma")
1✔
60
        assert msg.is_compatible(cubic)
1✔
61
        assert msg.is_compatible(tet)
1✔
62
        assert msg.is_compatible(ortho)
1✔
63
        assert not msg.is_compatible(rhom)
1✔
64
        assert not msg.is_compatible(hexagonal)
1✔
65
        msg = MagneticSpaceGroup("P2/c")
1✔
66
        assert msg.is_compatible(cubic)
1✔
67
        assert msg.is_compatible(tet)
1✔
68
        assert msg.is_compatible(ortho)
1✔
69
        assert not msg.is_compatible(rhom)
1✔
70
        assert not msg.is_compatible(hexagonal)
1✔
71
        msg = MagneticSpaceGroup("P-1")
1✔
72
        assert msg.is_compatible(cubic)
1✔
73
        assert msg.is_compatible(tet)
1✔
74
        assert msg.is_compatible(ortho)
1✔
75
        assert msg.is_compatible(rhom)
1✔
76
        assert msg.is_compatible(hexagonal)
1✔
77

78
    def test_symmetry_ops(self):
1✔
79
        msg_1_symmops = "\n".join(map(str, self.msg_1.symmetry_ops))
1✔
80
        msg_1_symmops_ref = """x, y, z, +1
1✔
81
-x+3/4, -y+3/4, z, +1
82
-x, -y, -z, +1
83
x+1/4, y+1/4, -z, +1
84
x, -y+3/4, -z+3/4, -1
85
-x+3/4, y, -z+3/4, -1
86
-x, y+1/4, z+1/4, -1
87
x+1/4, -y, z+1/4, -1
88
x, y+1/2, z+1/2, +1
89
-x+3/4, -y+5/4, z+1/2, +1
90
-x, -y+1/2, -z+1/2, +1
91
x+1/4, y+3/4, -z+1/2, +1
92
x, -y+5/4, -z+5/4, -1
93
-x+3/4, y+1/2, -z+5/4, -1
94
-x, y+3/4, z+3/4, -1
95
x+1/4, -y+1/2, z+3/4, -1
96
x+1/2, y, z+1/2, +1
97
-x+5/4, -y+3/4, z+1/2, +1
98
-x+1/2, -y, -z+1/2, +1
99
x+3/4, y+1/4, -z+1/2, +1
100
x+1/2, -y+3/4, -z+5/4, -1
101
-x+5/4, y, -z+5/4, -1
102
-x+1/2, y+1/4, z+3/4, -1
103
x+3/4, -y, z+3/4, -1
104
x+1/2, y+1/2, z, +1
105
-x+5/4, -y+5/4, z, +1
106
-x+1/2, -y+1/2, -z, +1
107
x+3/4, y+3/4, -z, +1
108
x+1/2, -y+5/4, -z+3/4, -1
109
-x+5/4, y+1/2, -z+3/4, -1
110
-x+1/2, y+3/4, z+1/4, -1
111
x+3/4, -y+1/2, z+1/4, -1"""
112
        self.assertStrContentEqual(msg_1_symmops, msg_1_symmops_ref)
1✔
113

114
        msg_2_symmops = "\n".join(map(str, self.msg_2.symmetry_ops))
1✔
115
        msg_2_symmops_ref = """x, y, z, +1
1✔
116
-x, y+1/2, -z, +1
117
-x, -y, -z, +1
118
x, -y+1/2, z, +1
119
x+1/2, -y+1/2, -z+1/2, -1
120
-x+1/2, -y, z+1/2, -1
121
-x+1/2, y+1/2, z+1/2, -1
122
x+1/2, y, -z+1/2, -1"""
123
        self.assertStrContentEqual(msg_2_symmops, msg_2_symmops_ref)
1✔
124

125
        msg_3_symmops = "\n".join(map(str, self.msg_3.symmetry_ops))
1✔
126
        msg_3_symmops_ref = """x, y, z, +1
1✔
127
x, -y, -z, +1
128
-x, y, -z+1/2, +1
129
-x, -y, z+1/2, +1
130
x, y+1/2, z+1/2, -1
131
x+1/2, -y, -z+1/2, -1
132
-x+1/2, y, -z, -1
133
-x+1/2, -y, z, -1
134
x+1/2, y+1/2, z, +1
135
x+1/2, -y+1/2, -z, +1
136
-x+1/2, y+1/2, -z+1/2, +1
137
-x+1/2, -y+1/2, z+1/2, +1
138
x+1/2, y, z+1/2, -1
139
x, -y+1/2, -z+1/2, -1
140
-x, y+1/2, -z, -1
141
-x, -y+1/2, z, -1"""
142
        assert msg_3_symmops == msg_3_symmops_ref
1✔
143

144
        msg_4_symmops = "\n".join(map(str, self.msg_4.symmetry_ops))
1✔
145
        msg_4_symmops_ref = """x, y, z, +1
1✔
146
-x, -y, -z, +1
147
x+1/2, y, z, -1
148
-x+1/2, -y, -z, -1"""
149
        assert msg_4_symmops == msg_4_symmops_ref
1✔
150

151
    def test_equivalence_to_spacegroup(self):
1✔
152
        # first 230 magnetic space groups have same symmetry operations
153
        # as normal space groups, so should give same orbits
154

155
        labels = ["Fm-3m", "Pnma", "P2/c", "P-1"]
1✔
156

157
        points = [[0, 0, 0], [0.5, 0, 0], [0.11, 0.22, 0.33]]
1✔
158

159
        for label in labels:
1✔
160
            sg = SpaceGroup(label)
1✔
161
            msg = MagneticSpaceGroup(label)
1✔
162
            assert sg.crystal_system == msg.crystal_system
1✔
163
            for p in points:
1✔
164
                pp_sg = np.array(sg.get_orbit(p))
1✔
165
                pp_msg = np.array(msg.get_orbit(p, 0)[0])  # discarding magnetic moment information
1✔
166
                pp_sg = pp_sg[np.lexsort(np.transpose(pp_sg)[::-1])]  # sorting arrays so we can compare them
1✔
167
                pp_msg = pp_msg[np.lexsort(np.transpose(pp_msg)[::-1])]
1✔
168
                assert np.allclose(pp_sg, pp_msg)
1✔
169

170
    def test_str(self):
1✔
171
        msg = MagneticSpaceGroup([4, 11])
1✔
172

173
        ref_string = """BNS: 4.11 P_b2_1
1✔
174
Operators: (1|0,0,0) (2y|0,1/2,0) (1|0,1/2,0)' (2y|0,0,0)'
175
Wyckoff Positions:
176
4e  (x,y,z;mx,my,mz) (-x,y+1/2,-z;-mx,my,-mz) (x,y+1/2,z;-mx,-my,-mz)
177
    (-x,y,-z;mx,-my,mz)
178
2d  (1/2,y,1/2;mx,0,mz) (1/2,y+1/2,1/2;-mx,0,-mz)
179
2c  (1/2,y,0;mx,0,mz) (1/2,y+1/2,0;-mx,0,-mz)
180
2b  (0,y,1/2;mx,0,mz) (0,y+1/2,1/2;-mx,0,-mz)
181
2a  (0,y,0;mx,0,mz) (0,y+1/2,0;-mx,0,-mz)
182
Alternative OG setting exists for this space group."""
183

184
        ref_string_all = """BNS: 4.11 P_b2_1                OG: 3.7.14 P_2b2'
1✔
185
OG-BNS Transform: (a,2b,c;0,0,0)
186
Operators (BNS): (1|0,0,0) (2y|0,1/2,0) (1|0,1/2,0)' (2y|0,0,0)'
187
Wyckoff Positions (BNS):
188
4e  (x,y,z;mx,my,mz) (-x,y+1/2,-z;-mx,my,-mz) (x,y+1/2,z;-mx,-my,-mz)
189
    (-x,y,-z;mx,-my,mz)
190
2d  (1/2,y,1/2;mx,0,mz) (1/2,y+1/2,1/2;-mx,0,-mz)
191
2c  (1/2,y,0;mx,0,mz) (1/2,y+1/2,0;-mx,0,-mz)
192
2b  (0,y,1/2;mx,0,mz) (0,y+1/2,1/2;-mx,0,-mz)
193
2a  (0,y,0;mx,0,mz) (0,y+1/2,0;-mx,0,-mz)
194
Operators (OG): (1|0,0,0) (2y|0,1,0) (1|0,1,0)' (2y|0,0,0)'
195
Wyckoff Positions (OG): (1,0,0)+ (0,2,0)+ (0,0,1)+
196
4e  (x,y,z;mx,my,mz) (-x,y+1,-z;-mx,my,-mz) (x,y+1,z;-mx,-my,-mz)
197
    (-x,y,-z;mx,-my,mz)
198
2d  (1/2,y,1/2;mx,0,mz) (-1/2,y+1,-1/2;-mx,0,-mz)
199
2c  (1/2,y,0;mx,0,mz) (-1/2,y+1,0;-mx,0,-mz)
200
2b  (0,y,1/2;mx,0,mz) (0,y+1,-1/2;-mx,0,-mz)
201
2a  (0,y,0;mx,0,mz) (0,y+1,0;-mx,0,-mz)"""
202

203
        self.assertStrContentEqual(str(msg), ref_string)
1✔
204
        self.assertStrContentEqual(msg.data_str(), ref_string_all)
1✔
205

206

207
if __name__ == "__main__":
1✔
208
    unittest.main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc