1
1
from __future__ import annotations
2
2
3
+ import numpy as np
4
+
3
5
from pymatgen .core .structure import Structure
4
6
from pymatgen .io .xcrysden import XSF
5
7
from pymatgen .util .testing import PymatgenTest
6
8
7
9
8
10
class TestXSF (PymatgenTest ):
9
- def test_xsf (self ):
10
- coords = [[0 , 0 , 0 ], [0.75 , 0.5 , 0.75 ]]
11
- lattice = [
11
+ def setUp (self ):
12
+ self . coords = [[0 , 0 , 0 ], [0.75 , 0.5 , 0.75 ]]
13
+ self . lattice = [
12
14
[3.8401979337 , 0.00 , 0.00 ],
13
15
[1.9200989668 , 3.3257101909 , 0.00 ],
14
16
[0.00 , - 2.2171384943 , 3.1355090603 ],
15
17
]
16
- structure = Structure (lattice , ["Si" , "Si" ], coords )
17
- xsf = XSF (structure )
18
- assert structure , XSF .from_str (xsf .to_str ())
18
+ self .struct = Structure (self .lattice , ["Si" , "Si" ], self .coords )
19
+
20
+ def test_xsf (self ):
21
+ xsf = XSF (self .struct )
22
+ assert self .struct , XSF .from_str (xsf .to_str ())
23
+ xsf = XSF (self .struct )
24
+ assert self .struct , XSF .from_str (xsf .to_str ())
25
+
26
+ def test_append_vect (self ):
27
+ self .struct .add_site_property ("vect" , np .eye (2 , 3 ))
28
+ xsf_str = XSF (self .struct ).to_str ()
29
+ last_line_split = xsf_str .split ("\n " )[- 1 ].split ()
30
+ assert len (last_line_split ) == 7
31
+ assert last_line_split [- 1 ] == "0.00000000000000"
32
+ assert last_line_split [- 2 ] == "1.00000000000000"
33
+ assert last_line_split [- 3 ] == "0.00000000000000"
19
34
20
35
def test_to_str (self ):
21
36
structure = self .get_structure ("Li2O" )
22
37
xsf = XSF (structure )
23
- xsf_str = xsf .to_str ()
24
38
assert (
25
- xsf_str
39
+ xsf . to_str ()
26
40
== """CRYSTAL
27
41
# Primitive lattice vectors in Angstrom
28
42
PRIMVEC
@@ -36,9 +50,9 @@ def test_to_str(self):
36
50
Li 3.01213761017484 2.21364440998406 4.74632330032018
37
51
Li 1.00309136982516 0.73718000001594 1.58060372967982"""
38
52
)
39
- xsf_str = xsf . to_str ( atom_symbol = False )
53
+
40
54
assert (
41
- xsf_str
55
+ xsf . to_str ( atom_symbol = False )
42
56
== """CRYSTAL
43
57
# Primitive lattice vectors in Angstrom
44
58
PRIMVEC
0 commit comments