Skip to content

Commit fb27e05

Browse files
fix vasp/xml errors when no virial is printed (#574)
Fix #212. --------- Signed-off-by: Jinzhe Zeng <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e52b699 commit fb27e05

File tree

3 files changed

+1756
-5
lines changed

3 files changed

+1756
-5
lines changed

dpdata/plugins/vasp.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def from_labeled_system(self, file_name, begin=0, step=1, **kwargs):
109109
data["coords"],
110110
data["energies"],
111111
data["forces"],
112-
data["virials"],
112+
tmp_virial,
113113
) = dpdata.vasp.xml.analyze(
114114
file_name, type_idx_zero=True, begin=begin, step=step
115115
)
@@ -121,9 +121,11 @@ def from_labeled_system(self, file_name, begin=0, step=1, **kwargs):
121121
for ii in range(data["cells"].shape[0]):
122122
data["coords"][ii] = np.matmul(data["coords"][ii], data["cells"][ii])
123123
# scale virial to the unit of eV
124-
v_pref = 1 * 1e3 / 1.602176621e6
125-
for ii in range(data["cells"].shape[0]):
126-
vol = np.linalg.det(np.reshape(data["cells"][ii], [3, 3]))
127-
data["virials"][ii] *= v_pref * vol
124+
if tmp_virial.size > 0:
125+
data["virials"] = tmp_virial
126+
v_pref = 1 * 1e3 / 1.602176621e6
127+
for ii in range(data["cells"].shape[0]):
128+
vol = np.linalg.det(np.reshape(data["cells"][ii], [3, 3]))
129+
data["virials"][ii] *= v_pref * vol
128130
data = uniq_atom_names(data)
129131
return data

0 commit comments

Comments
 (0)