@@ -31,11 +31,9 @@ def get_atype(lines, type_idx_zero = False) :
31
31
tidx = keys .index ('type' ) - 2
32
32
atype = []
33
33
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 ])])
36
35
atype .sort ()
37
36
atype = np .array (atype , dtype = int )
38
- atype = atype [:, ::- 1 ]
39
37
if type_idx_zero :
40
38
return atype [:,1 ] - 1
41
39
else :
@@ -78,17 +76,15 @@ def safe_get_posi(lines,cell,orig=np.zeros(3), unwrap=False) :
78
76
assert coord_tp_and_sf is not None , 'Dump file does not contain atomic coordinates!'
79
77
coordtype , sf , uw = coord_tp_and_sf
80
78
id_idx = keys .index ('id' ) - 2
81
- tidx = keys .index ('type' ) - 2
82
79
xidx = keys .index (coordtype [0 ])- 2
83
80
yidx = keys .index (coordtype [1 ])- 2
84
81
zidx = keys .index (coordtype [2 ])- 2
85
- sel = (xidx , yidx , zidx )
86
82
posis = []
87
83
for ii in blk :
88
84
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 ])])
90
86
posis .sort ()
91
- posis = np .array (posis )[:,2 : 5 ]
87
+ posis = np .array (posis )[:,1 : 4 ]
92
88
if not sf :
93
89
posis = (posis - orig ) @ np .linalg .inv (cell ) # Convert to scaled coordinates for unscaled coordinates
94
90
if uw and unwrap :
@@ -178,14 +174,16 @@ def system_data(lines, type_map = None, type_idx_zero = True, unwrap=False) :
178
174
orig , cell = dumpbox2box (bounds , tilt )
179
175
system ['orig' ] = np .array (orig ) - np .array (orig )
180
176
system ['cells' ] = [np .array (cell )]
181
- natoms = sum (system ['atom_numbs' ])
182
177
system ['atom_types' ] = get_atype (lines , type_idx_zero = type_idx_zero )
183
178
system ['coords' ] = [safe_get_posi (lines , cell , np .array (orig ), unwrap )]
184
179
for ii in range (1 , len (array_lines )) :
185
180
bounds , tilt = get_dumpbox (array_lines [ii ])
186
181
orig , cell = dumpbox2box (bounds , tilt )
187
182
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 ])
189
187
system ['cells' ] = np .array (system ['cells' ])
190
188
system ['coords' ] = np .array (system ['coords' ])
191
189
return system
0 commit comments