@@ -87,7 +87,7 @@ def __str__(self) -> str:
87
87
88
88
@dataclass (frozen = True )
89
89
class ResSFAC :
90
- species : set [str ]
90
+ species : list [str ]
91
91
ions : list [Ion ]
92
92
93
93
def __str__ (self ) -> str :
@@ -180,7 +180,7 @@ def _parse_ion(self, line: str) -> Ion:
180
180
181
181
def _parse_sfac (self , line : str , it : Iterator [str ]) -> ResSFAC :
182
182
"""Parses the SFAC block."""
183
- species = set (line .split ())
183
+ species = list (line .split ())
184
184
ions = []
185
185
try :
186
186
while True :
@@ -256,24 +256,24 @@ def _cell_from_lattice(cls, lattice: Lattice) -> ResCELL:
256
256
return ResCELL (1.0 , lattice .a , lattice .b , lattice .c , lattice .alpha , lattice .beta , lattice .gamma )
257
257
258
258
@classmethod
259
- def _ions_from_sites (cls , sites : list [PeriodicSite ]) -> list [ Ion ] :
260
- """Produce a list of entries for a SFAC block from a list of pymatgen PeriodicSite."""
259
+ def _sfac_from_sites (cls , sites : list [PeriodicSite ]) -> ResSFAC :
260
+ """Produce a SFAC block from a list of pymatgen PeriodicSite."""
261
261
ions : list [Ion ] = []
262
- i = 0
262
+ species : list [str ] = list ()
263
+
263
264
for site in sites :
264
265
for specie , occ in site .species .items ():
265
- i += 1
266
+ try :
267
+ i = species .index (specie ) + 1
268
+ except ValueError :
269
+ species .append (specie )
270
+ i = len (species )
271
+
266
272
x , y , z = map (float , site .frac_coords )
267
273
spin = site .properties .get ("magmom" )
268
274
spin = spin and float (spin )
269
275
ions .append (Ion (specie , i , (x , y , z ), occ , spin ))
270
- return ions
271
276
272
- @classmethod
273
- def _sfac_from_sites (cls , sites : list [PeriodicSite ]) -> ResSFAC :
274
- """Produce a SFAC block from a list of pymatgen PeriodicSite."""
275
- ions = cls ._ions_from_sites (sites )
276
- species = {ion .specie for ion in ions }
277
277
return ResSFAC (species , ions )
278
278
279
279
@classmethod
0 commit comments