@@ -159,8 +159,18 @@ def parse_first_step(self, aliases, config):
159
159
elif line .startswith ("ITEM: ATOMS" ):
160
160
keywords = line .split ()[2 :]
161
161
162
- self ._id = keywords .index ("id" )
163
- self ._type = keywords .index ("type" )
162
+ if "id" in keywords :
163
+ self ._id = keywords .index ("id" )
164
+ else :
165
+ self ._id = None
166
+ if "type" in keywords :
167
+ self ._type = keywords .index ("type" )
168
+ else :
169
+ self ._type = None
170
+ if "element" in keywords :
171
+ self ._element = keywords .index ("element" )
172
+ else :
173
+ self ._element = None
164
174
try :
165
175
self ._charge = keywords .index ("q" )
166
176
except ValueError :
@@ -194,12 +204,28 @@ def parse_first_step(self, aliases, config):
194
204
self ._itemsPosition ["ATOMS" ] = [comp + 1 , comp + self ._nAtoms + 1 ]
195
205
for i in range (self ._nAtoms ):
196
206
temp = self ._file .readline ().split ()
197
- idx = int (temp [self ._id ]) - 1
198
- ty = int (temp [self ._type ]) - 1
207
+ if self ._id is not None :
208
+ idx = int (temp [self ._id ]) - 1
209
+ else :
210
+ idx = int (i )
211
+ if self ._type is not None :
212
+ ty = int (temp [self ._type ]) - 1
213
+ else :
214
+ try :
215
+ ty = int (config ["atom_types" ][i ]) - 1
216
+ except IndexError :
217
+ LOG .error (
218
+ f"Failed to find index [{ i } ] in list of len { len (config ['atom_types' ])} "
219
+ )
199
220
label = str (config ["elements" ][ty ][0 ])
200
221
mass = str (config ["elements" ][ty ][1 ])
201
222
name = "{:s}_{:d}" .format (str (config ["elements" ][ty ][0 ]), idx )
202
- self ._rankToName [int (temp [0 ]) - 1 ] = name
223
+ try :
224
+ temp_index = int (temp [0 ])
225
+ except ValueError :
226
+ self ._rankToName [i ] = name
227
+ else :
228
+ self ._rankToName [temp_index - 1 ] = name
203
229
g .add_node (idx , label = label , mass = mass , atomName = name )
204
230
205
231
if config ["n_bonds" ] is not None :
@@ -335,7 +361,12 @@ def run_step(self, index):
335
361
range (self ._itemsPosition ["ATOMS" ][0 ], self ._itemsPosition ["ATOMS" ][1 ])
336
362
):
337
363
temp = self ._file .readline ().split ()
338
- idx = self ._nameToIndex [self ._rankToName [int (temp [0 ]) - 1 ]]
364
+ try :
365
+ temp_index = int (temp [0 ])
366
+ except ValueError :
367
+ idx = i
368
+ else :
369
+ idx = self ._nameToIndex [self ._rankToName [temp_index - 1 ]]
339
370
coords [idx , :] = np .array (
340
371
[temp [self ._x ], temp [self ._y ], temp [self ._z ]], dtype = np .float64
341
372
)
0 commit comments