Skip to content

Commit 5ad1751

Browse files
Orca support (#597)
Added support for ORCA single point energy files --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1355f7b commit 5ad1751

File tree

5 files changed

+1555
-0
lines changed

5 files changed

+1555
-0
lines changed

dpdata/orca/__init__.py

Whitespace-only changes.

dpdata/orca/output.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from typing import Tuple
2+
3+
import numpy as np
4+
5+
6+
def read_orca_sp_output(fn: str) -> Tuple[np.ndarray, np.ndarray, float, np.ndarray]:
7+
"""Read from ORCA output.
8+
9+
Note that both the energy and the gradient should be printed.
10+
11+
Parameters
12+
----------
13+
fn : str
14+
file name
15+
16+
Returns
17+
-------
18+
np.ndarray
19+
atomic symbols
20+
np.ndarray
21+
atomic coordinates
22+
float
23+
total potential energy
24+
np.ndarray
25+
atomic forces
26+
"""
27+
coord = None
28+
symbols = None
29+
forces = None
30+
energy = None
31+
with open(fn) as f:
32+
flag = 0
33+
for line in f:
34+
if flag in (1, 3, 4):
35+
flag += 1
36+
elif flag == 2:
37+
s = line.split()
38+
if not len(s):
39+
flag = 0
40+
else:
41+
symbols.append(s[0].capitalize())
42+
coord.append([float(s[1]), float(s[2]), float(s[3])])
43+
elif flag == 5:
44+
s = line.split()
45+
if not len(s):
46+
flag = 0
47+
else:
48+
forces.append([float(s[3]), float(s[4]), float(s[5])])
49+
elif line.startswith("CARTESIAN COORDINATES (ANGSTROEM)"):
50+
# coord
51+
flag = 1
52+
coord = []
53+
symbols = []
54+
elif line.startswith("CARTESIAN GRADIENT"):
55+
flag = 3
56+
forces = []
57+
elif line.startswith("FINAL SINGLE POINT ENERGY"):
58+
energy = float(line.split()[-1])
59+
symbols = np.array(symbols)
60+
forces = -np.array(forces)
61+
coord = np.array(coord)
62+
assert coord.shape == forces.shape
63+
64+
return symbols, coord, energy, forces

dpdata/plugins/orca.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import numpy as np
2+
3+
from dpdata.format import Format
4+
from dpdata.orca.output import read_orca_sp_output
5+
from dpdata.unit import EnergyConversion, ForceConversion
6+
7+
energy_convert = EnergyConversion("hartree", "eV").value()
8+
force_convert = ForceConversion("hartree/bohr", "eV/angstrom").value()
9+
10+
11+
@Format.register("orca/spout")
12+
class ORCASPOutFormat(Format):
13+
"""ORCA single point energy output.
14+
15+
Note that both the energy and the gradient should be
16+
printed into the output file.
17+
"""
18+
19+
def from_labeled_system(self, file_name: str, **kwargs) -> dict:
20+
"""Read from ORCA single point energy output.
21+
22+
Parameters
23+
----------
24+
file_name : str
25+
file name
26+
**kwargs
27+
keyword arguments
28+
29+
Returns
30+
-------
31+
dict
32+
system data
33+
"""
34+
symbols, coord, energy, forces = read_orca_sp_output(file_name)
35+
36+
atom_names, atom_types, atom_numbs = np.unique(
37+
symbols, return_inverse=True, return_counts=True
38+
)
39+
natoms = coord.shape[0]
40+
41+
return {
42+
"atom_types": atom_types,
43+
"atom_names": list(atom_names),
44+
"atom_numbs": list(atom_numbs),
45+
"coords": coord.reshape((1, natoms, 3)),
46+
"energies": np.array([energy * energy_convert]),
47+
"forces": (forces * force_convert).reshape((1, natoms, 3)),
48+
"cells": np.zeros((1, 3, 3)),
49+
"orig": np.zeros(3),
50+
"nopbc": True,
51+
}

0 commit comments

Comments
 (0)