• 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.11
/pymatgen/symmetry/tests/test_settings.py
1
from __future__ import annotations
1✔
2

3
import unittest
1✔
4

5
import numpy as np
1✔
6

7
from pymatgen.symmetry.settings import JonesFaithfulTransformation, Lattice, SymmOp
1✔
8

9
__author__ = "Matthew Horton"
1✔
10
__copyright__ = "Copyright 2017, The Materials Project"
1✔
11
__version__ = "0.1"
1✔
12
__maintainer__ = "Matthew Horton"
1✔
13
__email__ = "mkhorton@lbl.gov"
1✔
14
__status__ = "Development"
1✔
15
__date__ = "Apr 2017"
1✔
16

17

18
class JonesFaithfulTransformationTest(unittest.TestCase):
1✔
19
    def setUp(self):
1✔
20
        self.test_strings = [
1✔
21
            "a,b,c;0,0,0",  # identity
22
            "a-b,a+b,2c;0,0,1/2",
23
            "a/4+b/4-c/2,a/4-b/4,-a/2-b/2;0,0,0",
24
            "a,b,c;1/4,1/2,3/4",
25
        ]  # pure translation
26
        self.test_Pps = [
1✔
27
            ([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [0, 0, 0]),
28
            ([[1, 1, 0], [-1, 1, 0], [0, 0, 2]], [0, 0, 0.5]),
29
            ([[0.25, 0.25, -0.5], [0.25, -0.25, -0.5], [-0.5, 0, 0]], [0, 0, 0]),
30
            ([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [0.25, 0.5, 0.75]),
31
        ]
32

33
    def test_init(self):
1✔
34
        for test_string, test_Pp in zip(self.test_strings, self.test_Pps):
1✔
35
            jft = JonesFaithfulTransformation.from_transformation_string(test_string)
1✔
36
            jft2 = JonesFaithfulTransformation(test_Pp[0], test_Pp[1])
1✔
37
            assert np.allclose(jft.P, jft2.P)
1✔
38
            assert np.allclose(jft.p, jft2.p)
1✔
39
            assert test_string == jft.transformation_string
1✔
40
            assert test_string == jft2.transformation_string
1✔
41

42
    def test_inverse(self):
1✔
43
        for test_string in self.test_strings:
1✔
44
            jft = JonesFaithfulTransformation.from_transformation_string(test_string)
1✔
45
            assert jft == jft.inverse.inverse
1✔
46
            assert jft.transformation_string == jft.inverse.inverse.transformation_string
1✔
47

48
    def test_transform_lattice(self):
1✔
49
        lattice = Lattice.cubic(5)
1✔
50

51
        all_ref_lattices = [
1✔
52
            [[5.0, 0.0, 0.0], [0.0, 5.0, 0.0], [0.0, 0.0, 5.0]],
53
            [[5.0, 5.0, 0.0], [-5.0, 5.0, 0.0], [0.0, 0.0, 10.0]],
54
            [[1.25, 1.25, -2.5], [1.25, -1.25, -2.5], [-2.5, 0.0, 0.0]],
55
            [[5.0, 0.0, 0.0], [0.0, 5.0, 0.0], [0.0, 0.0, 5.0]],
56
        ]
57

58
        for ref_lattice, (P, p) in zip(all_ref_lattices, self.test_Pps):
1✔
59
            jft = JonesFaithfulTransformation(P, p)
1✔
60
            assert np.allclose(jft.transform_lattice(lattice).matrix, ref_lattice)
1✔
61

62
    def test_transform_coords(self):
1✔
63
        coords = [[0, 0, 0], [0.5, 0.5, 0.5]]
1✔
64

65
        all_ref_coords = [
1✔
66
            [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
67
            [[0.0, 0.0, -0.25], [0.0, 0.5, 0.0]],
68
            [[0.0, 0.0, 0.0], [-1.0, 0.0, -1.5]],
69
            [[-0.25, -0.5, -0.75], [0.25, 0.0, -0.25]],
70
        ]
71

72
        for ref_coords, (P, p) in zip(all_ref_coords, self.test_Pps):
1✔
73
            jft = JonesFaithfulTransformation(P, p)
1✔
74
            transformed_coords = jft.transform_coords(coords)
1✔
75
            for coord, ref_coord in zip(transformed_coords, ref_coords):
1✔
76
                assert np.allclose(coord, ref_coord)
1✔
77

78
    def test_transform_symmops(self):
1✔
79
        # reference data for this test taken from GENPOS
80
        # http://cryst.ehu.es/cryst/get_gen.html
81

82
        # Fm-3m
83
        input_symmops = """x,y,z
1✔
84
-x,-y,z
85
-x,y,-z
86
x,-y,-z
87
z,x,y
88
z,-x,-y
89
-z,-x,y
90
-z,x,-y
91
y,z,x
92
-y,z,-x
93
y,-z,-x
94
-y,-z,x
95
y,x,-z
96
-y,-x,-z
97
y,-x,z
98
-y,x,z
99
x,z,-y
100
-x,z,y
101
-x,-z,-y
102
x,-z,y
103
z,y,-x
104
z,-y,x
105
-z,y,x
106
-z,-y,-x
107
-x,-y,-z
108
x,y,-z
109
x,-y,z
110
-x,y,z
111
-z,-x,-y
112
-z,x,y
113
z,x,-y
114
z,-x,y
115
-y,-z,-x
116
y,-z,x
117
-y,z,x
118
y,z,-x
119
-y,-x,z
120
y,x,z
121
-y,x,-z
122
y,-x,-z
123
-x,-z,y
124
x,-z,-y
125
x,z,y
126
-x,z,-y
127
-z,-y,x
128
-z,y,-x
129
z,-y,-x
130
z,y,x"""
131

132
        # Fm-3m transformed by (a-b,a+b,2c;0,0,1/2)
133
        ref_transformed_symmops = """x,y,z
1✔
134
-x,-y,z
135
-y,-x,-z+1/2
136
y,x,-z+1/2
137
-1/2x-1/2y+z+1/4,1/2x+1/2y+z+1/4,-1/2x+1/2y+3/4
138
1/2x+1/2y+z+1/4,-1/2x-1/2y+z+1/4,1/2x-1/2y+3/4
139
1/2x+1/2y-z+3/4,-1/2x-1/2y-z+3/4,-1/2x+1/2y+3/4
140
-1/2x-1/2y-z+3/4,1/2x+1/2y-z+3/4,1/2x-1/2y+3/4
141
-1/2x+1/2y-z+3/4,-1/2x+1/2y+z+1/4,1/2x+1/2y+3/4
142
1/2x-1/2y-z+3/4,1/2x-1/2y+z+1/4,-1/2x-1/2y+3/4
143
-1/2x+1/2y+z+1/4,-1/2x+1/2y-z+3/4,-1/2x-1/2y+3/4
144
1/2x-1/2y+z+1/4,1/2x-1/2y-z+3/4,1/2x+1/2y+3/4
145
-x,y,-z+1/2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/2y-z+3/4,1/2x+1/2y+z+1/4,-1/2x+1/2y+3/4
176
-1/2x-1/2y-z+3/4,-1/2x-1/2y+z+1/4,1/2x-1/2y+3/4
177
-1/2x+1/2y-z+3/4,1/2x-1/2y-z+3/4,1/2x+1/2y+3/4
178
1/2x-1/2y-z+3/4,-1/2x+1/2y-z+3/4,-1/2x-1/2y+3/4
179
-1/2x+1/2y+z+1/4,1/2x-1/2y+z+1/4,-1/2x-1/2y+3/4
180
1/2x-1/2y+z+1/4,-1/2x+1/2y+z+1/4,1/2x+1/2y+3/4"""
181

182
        jft = JonesFaithfulTransformation.from_transformation_string(self.test_strings[1])
1✔
183

184
        input_symmops = [SymmOp.from_xyz_string(s) for s in input_symmops.split()]
1✔
185
        ref_transformed_symmops = [SymmOp.from_xyz_string(s) for s in ref_transformed_symmops.split()]
1✔
186

187
        transformed_symmops = [jft.transform_symmop(op) for op in input_symmops]
1✔
188

189
        for transformed_op, ref_transformed_op in zip(transformed_symmops, ref_transformed_symmops):
1✔
190
            assert transformed_op == ref_transformed_op
1✔
191

192

193
if __name__ == "__main__":
1✔
194
    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