Skip to content

Commit 57c5004

Browse files
fix(abacus): fix bug to read the data when relax job not set cal_stress (#549)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ee70942 commit 57c5004

File tree

4 files changed

+1458
-5
lines changed

4 files changed

+1458
-5
lines changed

dpdata/abacus/relax.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ def get_coords_from_log(loglines, natoms):
158158
cells *= bohr2ang
159159
coords *= bohr2ang
160160

161-
virial = np.zeros([len(cells), 3, 3])
162-
for i in range(len(cells)):
163-
volume = np.linalg.det(cells[i, :, :].reshape([3, 3]))
164-
virial[i] = stress[i] * kbar2evperang3 * volume
161+
if len(stress) > 0:
162+
virial = np.zeros([len(cells), 3, 3])
163+
for i in range(len(cells)):
164+
volume = np.linalg.det(cells[i, :, :].reshape([3, 3]))
165+
virial[i] = stress[i] * kbar2evperang3 * volume
166+
else:
167+
virial = None
165168

166169
return energy, cells, coords, force, stress, virial
167170

@@ -203,7 +206,8 @@ def get_frame(fname):
203206
data["coords"] = coords
204207
data["energies"] = energy
205208
data["forces"] = force
206-
data["virials"] = virial
209+
if isinstance(virial, np.ndarray):
210+
data["virials"] = virial
207211
data["stress"] = stress
208212
data["orig"] = np.zeros(3)
209213

0 commit comments

Comments
 (0)