@@ -31,11 +31,9 @@ def get_atype(lines, type_idx_zero = False) :
3131 tidx = keys .index ('type' ) - 2
3232 atype = []
3333 for ii in blk :
34- atype .append ([int (ii .split ()[tidx ]), int (ii .split ()[id_idx ])])
35- # sort with type id
34+ atype .append ([int (ii .split ()[id_idx ]), int (ii .split ()[tidx ])])
3635 atype .sort ()
3736 atype = np .array (atype , dtype = int )
38- atype = atype [:, ::- 1 ]
3937 if type_idx_zero :
4038 return atype [:,1 ] - 1
4139 else :
@@ -78,17 +76,15 @@ def safe_get_posi(lines,cell,orig=np.zeros(3), unwrap=False) :
7876 assert coord_tp_and_sf is not None , 'Dump file does not contain atomic coordinates!'
7977 coordtype , sf , uw = coord_tp_and_sf
8078 id_idx = keys .index ('id' ) - 2
81- tidx = keys .index ('type' ) - 2
8279 xidx = keys .index (coordtype [0 ])- 2
8380 yidx = keys .index (coordtype [1 ])- 2
8481 zidx = keys .index (coordtype [2 ])- 2
85- sel = (xidx , yidx , zidx )
8682 posis = []
8783 for ii in blk :
8884 words = ii .split ()
89- posis .append ([float (words [tidx ]), float ( words [ id_idx ]), float (words [xidx ]), float (words [yidx ]), float (words [zidx ])])
85+ posis .append ([float (words [id_idx ]), float (words [xidx ]), float (words [yidx ]), float (words [zidx ])])
9086 posis .sort ()
91- posis = np .array (posis )[:,2 : 5 ]
87+ posis = np .array (posis )[:,1 : 4 ]
9288 if not sf :
9389 posis = (posis - orig ) @ np .linalg .inv (cell ) # Convert to scaled coordinates for unscaled coordinates
9490 if uw and unwrap :
@@ -178,14 +174,16 @@ def system_data(lines, type_map = None, type_idx_zero = True, unwrap=False) :
178174 orig , cell = dumpbox2box (bounds , tilt )
179175 system ['orig' ] = np .array (orig ) - np .array (orig )
180176 system ['cells' ] = [np .array (cell )]
181- natoms = sum (system ['atom_numbs' ])
182177 system ['atom_types' ] = get_atype (lines , type_idx_zero = type_idx_zero )
183178 system ['coords' ] = [safe_get_posi (lines , cell , np .array (orig ), unwrap )]
184179 for ii in range (1 , len (array_lines )) :
185180 bounds , tilt = get_dumpbox (array_lines [ii ])
186181 orig , cell = dumpbox2box (bounds , tilt )
187182 system ['cells' ].append (cell )
188- system ['coords' ].append (safe_get_posi (array_lines [ii ], cell , np .array (orig ), unwrap ))
183+ atype = get_atype (array_lines [ii ], type_idx_zero = type_idx_zero )
184+ # map atom type; a[as[a][as[as[b]]]] = b[as[b][as^{-1}[b]]] = b[id]
185+ idx = np .argsort (atype )[np .argsort (np .argsort (system ['atom_types' ]))]
186+ system ['coords' ].append (safe_get_posi (array_lines [ii ], cell , np .array (orig ), unwrap )[idx ])
189187 system ['cells' ] = np .array (system ['cells' ])
190188 system ['coords' ] = np .array (system ['coords' ])
191189 return system
0 commit comments