From 3715f8260a434c30038c4939020d69e6264d40b4 Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Wed, 31 Aug 2022 12:32:46 +0800 Subject: [PATCH 1/3] fix viral in analyze_block --- dpdata/vasp/outcar.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dpdata/vasp/outcar.py b/dpdata/vasp/outcar.py index 1efdea2d8..c68bcefb3 100644 --- a/dpdata/vasp/outcar.py +++ b/dpdata/vasp/outcar.py @@ -122,7 +122,10 @@ def analyze_block(lines, ntot, nelm, ml = False): cell.append([float(ss) for ss in tmp_l.replace('-',' -').split()[0:3]]) elif viral_token[ml_index] in ii: - tmp_v = [float(ss) for ss in lines[idx+viral_index[ml_index]].split()[2:8]] + in_kB_index = viral_index[ml_index] + while lines[idx+in_kB_index].split()[0] != "in" : + in_kB_index += 1 + tmp_v = [float(ss) for ss in lines[idx+in_kB_index].split()[2:8]] virial = np.zeros([3,3]) virial[0][0] = tmp_v[0] virial[1][1] = tmp_v[1] From 007df8aa6bf220a4e6fc481b48f97e48b5217f69 Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Thu, 1 Sep 2022 10:17:22 +0800 Subject: [PATCH 2/3] check if in kB exist --- dpdata/vasp/outcar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dpdata/vasp/outcar.py b/dpdata/vasp/outcar.py index c68bcefb3..1bbbe152f 100644 --- a/dpdata/vasp/outcar.py +++ b/dpdata/vasp/outcar.py @@ -123,8 +123,9 @@ def analyze_block(lines, ntot, nelm, ml = False): for ss in tmp_l.replace('-',' -').split()[0:3]]) elif viral_token[ml_index] in ii: in_kB_index = viral_index[ml_index] - while lines[idx+in_kB_index].split()[0] != "in" : + while idx+in_kB_index < len(lines) and (not lines[idx+in_kB_index].split()[0:2] == ["in", "kB"]) : in_kB_index += 1 + assert(idx+in_kB_index < len(lines)),'ERROR: "in kB" is not found in OUTCAR. Unable to extract virial.' tmp_v = [float(ss) for ss in lines[idx+in_kB_index].split()[2:8]] virial = np.zeros([3,3]) virial[0][0] = tmp_v[0] From 51502a7948616436bd4442bb219942d59e9db4e6 Mon Sep 17 00:00:00 2001 From: HuangJiameng <105633685+HuangJiameng@users.noreply.github.com> Date: Thu, 1 Sep 2022 10:18:29 +0800 Subject: [PATCH 3/3] fix typo viral -> virial --- dpdata/vasp/outcar.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dpdata/vasp/outcar.py b/dpdata/vasp/outcar.py index 1bbbe152f..cae1dd158 100644 --- a/dpdata/vasp/outcar.py +++ b/dpdata/vasp/outcar.py @@ -101,8 +101,8 @@ def analyze_block(lines, ntot, nelm, ml = False): #select different searching tokens based on the ml label energy_token = ['free energy TOTEN', 'free energy ML TOTEN'] energy_index = [4, 5] - viral_token = ['FORCE on cell =-STRESS in cart. coord. units', 'ML FORCE'] - viral_index = [14, 4] + virial_token = ['FORCE on cell =-STRESS in cart. coord. units', 'ML FORCE'] + virial_index = [14, 4] cell_token = ['VOLUME and BASIS', 'ML FORCE'] cell_index = [5, 12] ml_index = int(ml) @@ -121,8 +121,8 @@ def analyze_block(lines, ntot, nelm, ml = False): tmp_l = lines[idx+cell_index[ml_index]+dd] cell.append([float(ss) for ss in tmp_l.replace('-',' -').split()[0:3]]) - elif viral_token[ml_index] in ii: - in_kB_index = viral_index[ml_index] + elif virial_token[ml_index] in ii: + in_kB_index = virial_index[ml_index] while idx+in_kB_index < len(lines) and (not lines[idx+in_kB_index].split()[0:2] == ["in", "kB"]) : in_kB_index += 1 assert(idx+in_kB_index < len(lines)),'ERROR: "in kB" is not found in OUTCAR. Unable to extract virial.'