Skip to content

Commit 1d87e82

Browse files
authored
style: enforce LF line ending (#661)
Try to fix #657 automatically
1 parent 626e692 commit 1d87e82

File tree

11 files changed

+1085
-1083
lines changed

11 files changed

+1085
-1083
lines changed

.github/workflows/test_import.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
name: test Python import
2-
3-
on:
4-
- push
5-
- pull_request
6-
7-
jobs:
8-
build:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v4
12-
- uses: actions/setup-python@v5
13-
with:
14-
python-version: '3.9'
15-
architecture: 'x64'
16-
- run: python -m pip install uv
17-
- run: python -m uv pip install --system .
18-
- run: python -c 'import dpdata'
1+
name: test Python import
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.9'
15+
architecture: 'x64'
16+
- run: python -m pip install uv
17+
- run: python -m uv pip install --system .
18+
- run: python -c 'import dpdata'

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ repos:
1616
- id: check-merge-conflict
1717
- id: check-symlinks
1818
- id: check-toml
19+
- id: mixed-line-ending
20+
args: ["--fix=lf"]
1921
# Python
2022
- repo: https://github.com/astral-sh/ruff-pre-commit
2123
# Ruff version.

docs/credits.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Authors
2-
=======
3-
1+
Authors
2+
=======
3+
44
.. git-shortlog-authors::

dpdata/orca/output.py

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

0 commit comments

Comments
 (0)