Skip to content

Commit 652bb22

Browse files
authored
find the line index of viral in OUTCAR (#352)
see #347
1 parent 5462242 commit 652bb22

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

dpdata/vasp/outcar.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def analyze_block(lines, ntot, nelm, ml = False):
101101
#select different searching tokens based on the ml label
102102
energy_token = ['free energy TOTEN', 'free energy ML TOTEN']
103103
energy_index = [4, 5]
104-
viral_token = ['FORCE on cell =-STRESS in cart. coord. units', 'ML FORCE']
105-
viral_index = [14, 4]
104+
virial_token = ['FORCE on cell =-STRESS in cart. coord. units', 'ML FORCE']
105+
virial_index = [14, 4]
106106
cell_token = ['VOLUME and BASIS', 'ML FORCE']
107107
cell_index = [5, 12]
108108
ml_index = int(ml)
@@ -121,8 +121,12 @@ def analyze_block(lines, ntot, nelm, ml = False):
121121
tmp_l = lines[idx+cell_index[ml_index]+dd]
122122
cell.append([float(ss)
123123
for ss in tmp_l.replace('-',' -').split()[0:3]])
124-
elif viral_token[ml_index] in ii:
125-
tmp_v = [float(ss) for ss in lines[idx+viral_index[ml_index]].split()[2:8]]
124+
elif virial_token[ml_index] in ii:
125+
in_kB_index = virial_index[ml_index]
126+
while idx+in_kB_index < len(lines) and (not lines[idx+in_kB_index].split()[0:2] == ["in", "kB"]) :
127+
in_kB_index += 1
128+
assert(idx+in_kB_index < len(lines)),'ERROR: "in kB" is not found in OUTCAR. Unable to extract virial.'
129+
tmp_v = [float(ss) for ss in lines[idx+in_kB_index].split()[2:8]]
126130
virial = np.zeros([3,3])
127131
virial[0][0] = tmp_v[0]
128132
virial[1][1] = tmp_v[1]

0 commit comments

Comments
 (0)