handle dump files with extra UNITS or TIME info

This commit is contained in:
Axel Kohlmeyer
2022-08-21 14:01:41 -04:00
parent 1f37087156
commit f18b96e517
2 changed files with 18 additions and 4 deletions

View File

@ -357,7 +357,21 @@ class dump:
def read_snapshot(self,f): def read_snapshot(self,f):
try: try:
snap = Snap() snap = Snap()
item = f.readline() snap.units = 'unknown'
snap.stime = -1.0
# read until hitting next "TIMESTEP" item
while True:
try:
item = f.readline().split()
if item[0] == 'ITEM:' and item[1] == 'UNITS':
snap.units = f.readline().split()[0]
if item[0] == 'ITEM:' and item[1] == 'TIME':
snap.time = f.readline().split()[0]
if item[0] == 'ITEM:' and item[1] == 'TIMESTEP':
break
except:
return
snap.time = int(f.readline().split()[0]) # just grab 1st field snap.time = int(f.readline().split()[0]) # just grab 1st field
item = f.readline() item = f.readline()
snap.natoms = int(f.readline()) snap.natoms = int(f.readline())
@ -391,7 +405,7 @@ class dump:
for i in range(1,snap.natoms): for i in range(1,snap.natoms):
words += f.readline().split() words += f.readline().split()
floats = map(float,words) floats = map(float,words)
atom_data = np.array(list(floats),np.float) atom_data = np.array(list(floats),float)
snap.atoms = atom_data.reshape((snap.natoms, ncol)) snap.atoms = atom_data.reshape((snap.natoms, ncol))
else: else:

View File

@ -318,9 +318,9 @@ class log:
last = 1 # entire read is a chunk last = 1 # entire read is a chunk
s1 = 0 s1 = 0
if self.style == 1: if self.style == 1:
s2 = txt.rfind("\n--".encode('utf-8'),s1) + 1 s2 = txt.rfind("\n--",s1) + 1
else: else:
s2 = txt.rfind("\n".encode('utf-8'),s1) + 1 s2 = txt.rfind("\n",s1) + 1
eof -= len(txt) - s2 eof -= len(txt) - s2
if s1 == s2: break if s1 == s2: break