Skip to content

Commit 2b8779d

Browse files
fix psi4 length conversion (#571)
The length conversion in Psi4 is not fixed to Bohr. Instead, the output unit follows the input unit and is written in the output file. --------- 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 d4b28ba commit 2b8779d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

dpdata/plugins/psi4.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
from dpdata.format import Format
44
from dpdata.psi4.input import write_psi4_input
55
from dpdata.psi4.output import read_psi4_output
6-
from dpdata.unit import EnergyConversion, ForceConversion, LengthConversion
6+
from dpdata.unit import EnergyConversion, ForceConversion
77

8-
length_convert = LengthConversion("bohr", "angstrom").value()
98
energy_convert = EnergyConversion("hartree", "eV").value()
109
force_convert = ForceConversion("hartree/bohr", "eV/angstrom").value()
1110

@@ -44,7 +43,7 @@ def from_labeled_system(self, file_name: str, **kwargs) -> dict:
4443
"atom_types": atom_types,
4544
"atom_names": list(atom_names),
4645
"atom_numbs": list(atom_numbs),
47-
"coords": (coord * length_convert).reshape((1, natoms, 3)),
46+
"coords": (coord).reshape((1, natoms, 3)),
4847
"energies": np.array([energy * energy_convert]),
4948
"forces": (forces * force_convert).reshape((1, natoms, 3)),
5049
"cells": np.zeros((1, 3, 3)),

dpdata/psi4/output.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import numpy as np
44

5+
from dpdata.unit import LengthConversion
6+
57

68
def read_psi4_output(fn: str) -> Tuple[str, np.ndarray, float, np.ndarray]:
79
"""Read from Psi4 output.
@@ -28,6 +30,7 @@ def read_psi4_output(fn: str) -> Tuple[str, np.ndarray, float, np.ndarray]:
2830
symbols = None
2931
forces = None
3032
energy = None
33+
length_unit = None
3134
with open(fn) as f:
3235
flag = 0
3336
for line in f:
@@ -53,14 +56,19 @@ def read_psi4_output(fn: str) -> Tuple[str, np.ndarray, float, np.ndarray]:
5356
flag = 1
5457
coord = []
5558
symbols = []
59+
elif line.startswith(" Geometry (in "):
60+
# remove ),
61+
length_unit = line.split()[2][:-2].lower()
5662
elif line.startswith(" ## Total Gradient"):
5763
flag = 3
5864
forces = []
5965
elif line.startswith(" Total Energy ="):
6066
energy = float(line.split()[-1])
67+
assert length_unit is not None
68+
length_convert = LengthConversion(length_unit, "angstrom").value()
6169
symbols = np.array(symbols)
6270
forces = -np.array(forces)
63-
coord = np.array(coord)
71+
coord = np.array(coord) * length_convert
6472
assert coord.shape == forces.shape
6573

6674
return symbols, coord, energy, forces

0 commit comments

Comments
 (0)