1919from pymatgen .core .lattice import Lattice
2020from pymatgen .core .operations import SymmOp
2121from pymatgen .core .periodic_table import Element , Species
22- from pymatgen .core .structure import IMolecule , IStructure , Molecule , PeriodicNeighbor , Structure , StructureError
22+ from pymatgen .core .structure import (
23+ IMolecule ,
24+ IStructure ,
25+ Molecule ,
26+ Neighbor ,
27+ PeriodicNeighbor ,
28+ Structure ,
29+ StructureError ,
30+ )
2331from pymatgen .electronic_structure .core import Magmom
2432from pymatgen .io .ase import AseAtomsAdaptor
2533from pymatgen .util .testing import PymatgenTest
@@ -45,16 +53,21 @@ def test_msonable(self):
4553 nn = json .loads (str_ , cls = MontyDecoder )
4654 assert isinstance (nn [0 ], PeriodicNeighbor )
4755
56+ def test_neighbor_labels (self ):
57+ comp = Composition ("C" )
58+ for label in (None , "" , "str label" , ("tuple" , "label" )):
59+ neighbor = Neighbor (comp , (0 , 0 , 0 ), label = label )
60+ assert neighbor .label == label if label is not None else str (comp )
61+
62+ p_neighbor = PeriodicNeighbor (comp , (0 , 0 , 0 ), (10 , 10 , 10 ), label = label )
63+ assert p_neighbor .label == label if label is not None else str (comp )
64+
4865
4966class IStructureTest (PymatgenTest ):
5067 def setUp (self ):
5168 coords = [[0 , 0 , 0 ], [0.75 , 0.5 , 0.75 ]]
5269 self .lattice = Lattice (
53- [
54- [3.8401979337 , 0.00 , 0.00 ],
55- [1.9200989668 , 3.3257101909 , 0.00 ],
56- [0.00 , - 2.2171384943 , 3.1355090603 ],
57- ]
70+ [[3.8401979337 , 0 , 0 ], [1.9200989668 , 3.3257101909 , 0 ], [0 , - 2.2171384943 , 3.1355090603 ]]
5871 )
5972 self .struct = IStructure (self .lattice , ["Si" ] * 2 , coords )
6073 assert len (self .struct ) == 2 , "Wrong number of sites in structure!"
@@ -69,11 +82,7 @@ def setUp(self):
6982 self .labeled_structure = IStructure (self .lattice , ["Si" ] * 2 , coords , labels = ["Si1" , "Si2" ])
7083
7184 self .lattice_pbc = Lattice (
72- [
73- [3.8401979337 , 0.00 , 0.00 ],
74- [1.9200989668 , 3.3257101909 , 0.00 ],
75- [0.00 , - 2.2171384943 , 3.1355090603 ],
76- ],
85+ [[3.8401979337 , 0 , 0 ], [1.9200989668 , 3.3257101909 , 0 ], [0 , - 2.2171384943 , 3.1355090603 ]],
7786 pbc = (True , True , False ),
7887 )
7988
@@ -171,7 +180,7 @@ def test_fractional_occupations(self):
171180
172181 def test_labeled_structure (self ):
173182 assert self .labeled_structure .labels == ["Si1" , "Si2" ]
174- assert self .struct .labels == [None , None ]
183+ assert self .struct .labels == ["Si" , "Si" ]
175184
176185 def test_get_distance (self ):
177186 assert self .struct .get_distance (0 , 1 ) == approx (2.35 , abs = 1e-2 ), "Distance calculated wrongly!"
@@ -318,7 +327,7 @@ def test_interpolate(self):
318327 assert interpolated_structs [0 ].lattice == inter_struct .lattice
319328 assert_array_equal (interpolated_structs [1 ][1 ].frac_coords , [0.625 , 0.5 , 0.625 ])
320329
321- bad_lattice = [[1 , 0.00 , 0.00 ], [0 , 1 , 0.00 ], [0.00 , 0 , 1 ]]
330+ bad_lattice = [[1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]]
322331 struct2 = IStructure (bad_lattice , ["Si" ] * 2 , coords2 )
323332 with pytest .raises (ValueError , match = "Structures with different lattices" ):
324333 struct .interpolate (struct2 )
@@ -764,9 +773,7 @@ def setUp(self):
764773 coords = []
765774 coords .append ([0 , 0 , 0 ])
766775 coords .append ([0.75 , 0.5 , 0.75 ])
767- lattice = Lattice (
768- [[3.8401979337 , 0.00 , 0.00 ], [1.9200989668 , 3.3257101909 , 0.00 ], [0.00 , - 2.2171384943 , 3.1355090603 ]]
769- )
776+ lattice = Lattice ([[3.8401979337 , 0 , 0 ], [1.9200989668 , 3.3257101909 , 0 ], [0 , - 2.2171384943 , 3.1355090603 ]])
770777 self .structure = Structure (lattice , ["Si" , "Si" ], coords )
771778 self .cu_structure = Structure (lattice , ["Cu" , "Cu" ], coords )
772779 self .disordered = Structure .from_spacegroup ("Im-3m" , Lattice .cubic (3 ), [Composition ("Fe0.5Mn0.5" )], [[0 , 0 , 0 ]])
@@ -1157,7 +1164,7 @@ def test_from_magnetic_spacegroup(self):
11571164 "P4_2'/mnm'" ,
11581165 Lattice .tetragonal (4.87 , 3.30 ),
11591166 ["Mn" , "F" ],
1160- [[0 , 0 , 0 ], [0.30 , 0.30 , 0.00 ]],
1167+ [[0 , 0 , 0 ], [0.30 , 0.30 , 0 ]],
11611168 {"magmom" : [4 , 0 ]},
11621169 )
11631170
@@ -1173,7 +1180,7 @@ def test_from_magnetic_spacegroup(self):
11731180 ["La" , "Mn" , "O" , "O" ],
11741181 [
11751182 [0.05 , 0.25 , 0.99 ],
1176- [0.00 , 0.00 , 0.50 ],
1183+ [0 , 0 , 0.50 ],
11771184 [0.48 , 0.25 , 0.08 ],
11781185 [0.31 , 0.04 , 0.72 ],
11791186 ],
0 commit comments