Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable loading of virials for 'qe/cp/traj' if prefix.str file is present #583

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dpdata/plugins/qe.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

import dpdata.md.pbc
import dpdata.qe.scf
import dpdata.qe.traj
Expand Down Expand Up @@ -26,9 +28,13 @@
data["coords"],
data["cells"],
)
data["energies"], data["forces"], es = dpdata.qe.traj.to_system_label(
data["energies"], data["forces"], stress, es = dpdata.qe.traj.to_system_label(
file_name + ".in", file_name, begin=begin, step=step
)
if stress is not None:
# Compute virials of all frames by: virial = stress * volume
virial = stress * np.linalg.det(data["cells"])[:, np.newaxis, np.newaxis]
data["virials"] = virial

Check warning on line 37 in dpdata/plugins/qe.py

View check run for this annotation

Codecov / codecov/patch

dpdata/plugins/qe.py#L36-L37

Added lines #L36 - L37 were not covered by tests
assert cs == es, "the step key between files are not consistent"
return data

Expand Down
13 changes: 11 additions & 2 deletions dpdata/qe/traj.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python3
import os
import warnings

import numpy as np
Expand All @@ -16,6 +17,7 @@
length_convert = LengthConversion("bohr", "angstrom").value()
energy_convert = EnergyConversion("hartree", "eV").value()
force_convert = ForceConversion("hartree/bohr", "eV/angstrom").value()
stress_convert = PressureConversion("GPa", "eV/angstrom^3").value()


def load_key(lines, key):
Expand Down Expand Up @@ -233,8 +235,15 @@
step=step,
convert=force_convert,
)
assert esteps == fsteps, "the step key between files are not consistent "
return energy, force, esteps
# Load stress from .str file if it exists
if os.path.isfile(prefix + ".str"):
stress, vsteps = load_data(

Check warning on line 240 in dpdata/qe/traj.py

View check run for this annotation

Codecov / codecov/patch

dpdata/qe/traj.py#L240

Added line #L240 was not covered by tests
prefix + ".str", 3, begin=begin, step=step, convert=stress_convert
)
else:
stress, vsteps = None, esteps
assert esteps == fsteps == vsteps, "the step key between files are not consistent "
return energy, force, stress, esteps


if __name__ == "__main__":
Expand Down
Loading