-
Notifications
You must be signed in to change notification settings - Fork 145
Orca support #597
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
Merged
Merged
Orca support #597
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eae52b3
extract info from orca sp output file
hl2500 0a10901
fix typos
hl2500 489c675
add orca sp test
hl2500 3307f71
add orca test
hl2500 b414879
remove a file
hl2500 675dc99
add orca plugin
hl2500 ff29a85
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from typing import Tuple | ||
|
||
import numpy as np | ||
|
||
|
||
def read_orca_sp_output(fn: str) -> Tuple[np.ndarray, np.ndarray, float, np.ndarray]: | ||
"""Read from ORCA output. | ||
|
||
Note that both the energy and the gradient should be printed. | ||
|
||
Parameters | ||
---------- | ||
fn : str | ||
file name | ||
|
||
Returns | ||
------- | ||
np.ndarray | ||
atomic symbols | ||
np.ndarray | ||
atomic coordinates | ||
float | ||
total potential energy | ||
np.ndarray | ||
atomic forces | ||
""" | ||
coord = None | ||
symbols = None | ||
forces = None | ||
energy = None | ||
with open(fn) as f: | ||
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
flag = 0 | ||
for line in f: | ||
if flag in (1, 3, 4): | ||
flag += 1 | ||
elif flag == 2: | ||
s = line.split() | ||
if not len(s): | ||
flag = 0 | ||
else: | ||
symbols.append(s[0].capitalize()) | ||
coord.append([float(s[1]), float(s[2]), float(s[3])]) | ||
elif flag == 5: | ||
s = line.split() | ||
if not len(s): | ||
flag = 0 | ||
else: | ||
forces.append([float(s[3]), float(s[4]), float(s[5])]) | ||
elif line.startswith("CARTESIAN COORDINATES (ANGSTROEM)"): | ||
# coord | ||
flag = 1 | ||
coord = [] | ||
symbols = [] | ||
elif line.startswith("CARTESIAN GRADIENT"): | ||
flag = 3 | ||
forces = [] | ||
elif line.startswith("FINAL SINGLE POINT ENERGY"): | ||
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
energy = float(line.split()[-1]) | ||
symbols = np.array(symbols) | ||
forces = -np.array(forces) | ||
coord = np.array(coord) | ||
assert coord.shape == forces.shape | ||
|
||
return symbols, coord, energy, forces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import numpy as np | ||
|
||
from dpdata.format import Format | ||
from dpdata.orca.output import read_orca_sp_output | ||
from dpdata.unit import EnergyConversion, ForceConversion | ||
|
||
energy_convert = EnergyConversion("hartree", "eV").value() | ||
force_convert = ForceConversion("hartree/bohr", "eV/angstrom").value() | ||
|
||
|
||
@Format.register("orca/spout") | ||
class ORCASPOutFormat(Format): | ||
"""ORCA single point energy output. | ||
|
||
Note that both the energy and the gradient should be | ||
printed into the output file. | ||
""" | ||
|
||
def from_labeled_system(self, file_name: str, **kwargs) -> dict: | ||
"""Read from ORCA single point energy output. | ||
|
||
Parameters | ||
---------- | ||
file_name : str | ||
file name | ||
**kwargs | ||
keyword arguments | ||
|
||
Returns | ||
------- | ||
dict | ||
system data | ||
""" | ||
symbols, coord, energy, forces = read_orca_sp_output(file_name) | ||
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
atom_names, atom_types, atom_numbs = np.unique( | ||
symbols, return_inverse=True, return_counts=True | ||
) | ||
natoms = coord.shape[0] | ||
|
||
return { | ||
"atom_types": atom_types, | ||
"atom_names": list(atom_names), | ||
"atom_numbs": list(atom_numbs), | ||
"coords": coord.reshape((1, natoms, 3)), | ||
"energies": np.array([energy * energy_convert]), | ||
"forces": (forces * force_convert).reshape((1, natoms, 3)), | ||
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"cells": np.zeros((1, 3, 3)), | ||
"orig": np.zeros(3), | ||
"nopbc": True, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.