Skip to content

Commit 8bac571

Browse files
authored
Format Python API with ruff (#212)
1 parent 6bb6511 commit 8bac571

9 files changed

Lines changed: 275 additions & 76 deletions

File tree

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: v0.15.10
6+
hooks:
7+
# Run the linter.
8+
- id: ruff
9+
args: [--config, python/pyproject.toml, --fix]
10+
# Run the formatter.
11+
- id: ruff-format
12+
args: [--config, python/pyproject.toml]
413
- repo: https://github.com/PlasmaFAIR/fortitude-pre-commit
514
rev: v0.9.0
615
hooks:

doc/guide/minimal-example/energy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
num = np.array([6, 1, 1, 1, 1])
55
xyz = np.array( # coordinates in Bohr
66
[
7-
[ 0.0000000, -0.0000000, 0.0000000],
8-
[-1.1922080, 1.1922080, 1.1922080],
9-
[ 1.1922080, -1.1922080, 1.1922080],
7+
[0.0000000, -0.0000000, 0.0000000],
8+
[-1.1922080, 1.1922080, 1.1922080],
9+
[1.1922080, -1.1922080, 1.1922080],
1010
[-1.1922080, -1.1922080, -1.1922080],
11-
[ 1.1922080, 1.1922080, -1.1922080],
11+
[1.1922080, 1.1922080, -1.1922080],
1212
]
1313
)
1414
method = "PBE0"

python/dftd3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"""Python API for the DFT-D3 dispersion model"""
1717

1818
# make sure we have a CFFI available
19-
import cffi
19+
import cffi # noqa
2020

2121
__version__ = "1.4.0"

python/dftd3/ase.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,21 @@
9999
[-0. , 0.00004060, -0.00004786]])
100100
"""
101101

102-
try:
103-
import ase
104-
except ModuleNotFoundError:
105-
raise ModuleNotFoundError("This submodule requires ASE installed")
106-
107102
from typing import List, Optional
108103

104+
try:
105+
from ase.calculators.calculator import (
106+
Calculator,
107+
InputError,
108+
CalculationFailed,
109+
all_changes,
110+
)
111+
from ase.calculators.mixing import SumCalculator
112+
from ase.atoms import Atoms
113+
from ase.units import Hartree, Bohr
114+
except ModuleNotFoundError as e:
115+
raise ModuleNotFoundError("This submodule requires ASE installed") from e
116+
109117
from .interface import (
110118
DispersionModel,
111119
DampingParam,
@@ -117,15 +125,6 @@
117125
CSODampingParam,
118126
ZDampingParam,
119127
)
120-
from ase.calculators.calculator import (
121-
Calculator,
122-
InputError,
123-
CalculationFailed,
124-
all_changes,
125-
)
126-
from ase.calculators.mixing import SumCalculator
127-
from ase.atoms import Atoms
128-
from ase.units import Hartree, Bohr
129128

130129

131130
_damping_param = {

python/dftd3/library.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ def new_z_damping(
285285

286286
def load_z_damping(method: str, atm: bool) -> ParamHandle:
287287
"""Load Z damping parameters from internal storage"""
288-
return ParamHandle.with_gc(error_check(lib.dftd3_load_z_damping)(_char(method), atm))
288+
return ParamHandle.with_gc(
289+
error_check(lib.dftd3_load_z_damping)(_char(method), atm)
290+
)
289291

290292

291293
def update_structure(

python/dftd3/qcschema.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ def run_qcschema(input_data):
368368

369369
if schema_version == 1:
370370
return qcel_v1.AtomicResult(**ret_data)
371-
371+
372372
if "error" in ret_data:
373-
return qcel_v2.FailedOperation(
374-
input_data=atomic_input, error=ret_data["error"]
375-
)
373+
return qcel_v2.FailedOperation(input_data=atomic_input, error=ret_data["error"])
376374
return qcel_v2.AtomicResult(**ret_data)

python/dftd3/test_interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ def test_b97d_d3_op(atm: bool, model: DispersionModel) -> None:
281281

282282
def test_pbe_d3_z(atm: bool, model: DispersionModel) -> None:
283283
ref = -0.005741490224533363 if atm else -0.005841389688523762
284-
res = model.get_dispersion(ZDampingParam(a1=200770.0, s9=1.0 if atm else 0.0), grad=False)
284+
res = model.get_dispersion(
285+
ZDampingParam(a1=200770.0, s9=1.0 if atm else 0.0), grad=False
286+
)
285287
assert approx(res.get("energy")) == ref
286288

287289

0 commit comments

Comments
 (0)