Skip to content

Commit 8d0cb75

Browse files
authored
fix bug for duplicated header cp2k output (#233)
* fix bug: nonconverged cp2k ouput should return None virial * fix bug for duplicated header cp2k output
1 parent f639f95 commit 8d0cb75

File tree

4 files changed

+2902
-2334
lines changed

4 files changed

+2902
-2334
lines changed

dpdata/cp2k/output.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -238,46 +238,55 @@ def get_frames (fname) :
238238
content = fp.read()
239239
count = content.count('SCF run converged')
240240
if count == 0:
241-
return [], [], [], [], [], [], [], []
241+
return [], [], [], [], [], [], [], None
242242

243+
# search duplicated header
243244
fp.seek(0)
245+
header_idx = []
244246
for idx, ii in enumerate(fp) :
245-
if ('CELL| Vector' in ii) and (cell_count < 3) :
246-
cell.append(ii.split()[4:7])
247-
cell_count += 1
248-
if 'Atom Kind Element' in ii :
249-
coord_flag = True
250-
coord_idx = idx
251-
coord_count += 1
252-
# get the coord block info
253-
if coord_flag and (coord_count == 1):
254-
if (idx > coord_idx + 1) :
255-
if (ii == '\n') :
256-
coord_flag = False
257-
else :
258-
coord.append(ii.split()[4:7])
259-
atom_symbol_list.append(ii.split()[2])
260-
if 'ENERGY|' in ii :
261-
energy = (ii.split()[8])
262-
if ' Atom Kind ' in ii :
263-
force_flag = True
264-
force_idx = idx
265-
if force_flag :
266-
if (idx > force_idx) :
267-
if 'SUM OF ATOMIC FORCES' in ii :
268-
force_flag = False
269-
else :
270-
force.append(ii.split()[3:6])
271-
# add reading stress tensor
272-
if 'STRESS TENSOR [GPa' in ii :
273-
stress_flag = True
274-
stress_idx = idx
275-
if stress_flag :
276-
if (idx > stress_idx + 2):
277-
if (ii == '\n') :
278-
stress_flag = False
279-
else :
280-
stress.append(ii.split()[1:4])
247+
if 'Multiplication driver' in ii :
248+
header_idx.append(idx)
249+
250+
# parse from last header
251+
fp.seek(0)
252+
for idx, ii in enumerate(fp) :
253+
if idx > header_idx[-1] :
254+
if 'CELL| Vector' in ii:
255+
cell.append(ii.split()[4:7])
256+
257+
if 'Atom Kind Element' in ii :
258+
coord_flag = True
259+
coord_idx = idx
260+
261+
# get the coord block info
262+
if coord_flag :
263+
if (idx > coord_idx + 1) :
264+
if (ii == '\n') :
265+
coord_flag = False
266+
else :
267+
coord.append(ii.split()[4:7])
268+
atom_symbol_list.append(ii.split()[2])
269+
if 'ENERGY|' in ii :
270+
energy = (ii.split()[8])
271+
if ' Atom Kind ' in ii :
272+
force_flag = True
273+
force_idx = idx
274+
if force_flag :
275+
if (idx > force_idx) :
276+
if 'SUM OF ATOMIC FORCES' in ii :
277+
force_flag = False
278+
else :
279+
force.append(ii.split()[3:6])
280+
# add reading stress tensor
281+
if 'STRESS TENSOR [GPa' in ii :
282+
stress_flag = True
283+
stress_idx = idx
284+
if stress_flag :
285+
if (idx > stress_idx + 2):
286+
if (ii == '\n') :
287+
stress_flag = False
288+
else :
289+
stress.append(ii.split()[1:4])
281290

282291

283292
fp.close()

0 commit comments

Comments
 (0)