Skip to content

Commit fd427a6

Browse files
committed
build: changed black lint strategy and versions + code formatting
1 parent f6ae16a commit fd427a6

3 files changed

Lines changed: 46 additions & 36 deletions

File tree

overreact/_misc.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def _derivative(func, x0, dx=1.0, n=1, args=(), order=3):
139139
msg = "'order' (the number of points used to compute the derivative), must be at least the derivative order 'n' + 1."
140140
raise ValueError(msg)
141141
if order % 2 == 0:
142-
msg = "'order' (the number of points used to compute the derivative) must be odd."
142+
msg = (
143+
"'order' (the number of points used to compute the derivative) must be odd."
144+
)
143145
raise ValueError(msg)
144146

145147
# pre-computed for n=1 and 2 and low-order for speed.
@@ -175,6 +177,7 @@ def _derivative(func, x0, dx=1.0, n=1, args=(), order=3):
175177
val += weights[k] * func(x0 + (k - ho) * dx, *args)
176178
return val / prod((dx,) * n, axis=0)
177179

180+
178181
def make_hashable(obj):
179182
"""
180183
Given an array, list or set make it immutable by transforming it into a tuple.
@@ -194,10 +197,11 @@ def make_hashable(obj):
194197
if isinstance(obj, np.ndarray):
195198
return (tuple(obj.shape), tuple(obj.ravel()))
196199
elif isinstance(obj, (list, set)):
197-
return tuple(make_hashable(item) for item in obj)
200+
return tuple(make_hashable(item) for item in obj)
198201
else:
199202
return obj
200203

204+
201205
def copy_unhashable(maxsize=128, typed=False):
202206
"""
203207
Cache resultant tuples while handling the received unhashable types (array, list, dictionaries).
@@ -218,6 +222,7 @@ def copy_unhashable(maxsize=128, typed=False):
218222
function
219223
A wrapper version of the original function that is cacheable now
220224
"""
225+
221226
def decorator(func):
222227
@cache(maxsize=maxsize, typed=typed)
223228
@wraps(func)
@@ -242,7 +247,6 @@ def convert_back(arg):
242247
raise ValueError(msg)
243248
return arg
244249

245-
246250
args = [convert_back(arg) for arg in hashable_args]
247251
for k, v in hashable_kwargs.items():
248252
kwargs[k] = convert_back(v)
@@ -254,14 +258,18 @@ def wrapper(*args, **kwargs):
254258
wrapper_hashable_kwargs = {}
255259

256260
wrapper_hashable_args = [make_hashable(arg) for arg in args]
257-
for k,v in kwargs.items():
261+
for k, v in kwargs.items():
258262
wrapper_hashable_kwargs[k] = make_hashable(v)
259263
wrapper_hashable_args = tuple(wrapper_hashable_args)
260-
return deepcopy(cached_func(*wrapper_hashable_args, **wrapper_hashable_kwargs))
264+
return deepcopy(
265+
cached_func(*wrapper_hashable_args, **wrapper_hashable_kwargs),
266+
)
261267

262268
return wrapper
269+
263270
return decorator
264271

272+
265273
def _find_package(package):
266274
"""Check if a package exists without importing it.
267275

overreact/coords.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,7 @@ def gyradius(atommasses, atomcoords, method="iupac"):
16801680
msg = f"unavailable method: '{method}'"
16811681
raise ValueError(msg)
16821682

1683+
16831684
@misc.copy_unhashable()
16841685
def inertia(atommasses, atomcoords, align=True):
16851686
r"""Calculate primary moments and axes from the inertia tensor.

tests/test_rates.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ruff: noqa: ERA001
1+
# ruff: noqa: ERA001
22
"""Tests for rates module."""
33

44
from __future__ import annotations
@@ -77,37 +77,38 @@ def test_eyring_calculates_reaction_barrier() -> None:
7777
temperature=[298.15, 1074.0],
7878
) == pytest.approx([1.38, 3.2513e9], 4e-3)
7979

80+
8081
# TODO(mrauen): this piece of code tests the old implementation for diffusion controlled reactions. I will implement the new test and change it here.
81-
#def test_smoluchowski_calculates_diffusion_limited_reaction_rates() -> None:
82-
# """Ensure Smoluchowski rates are correct."""
83-
# radii = np.array([2.59, 2.71]) * constants.angstrom
84-
# assert rx.rates.collins_kimball(
85-
# radii,
86-
# reactive_radius=2.6 * constants.angstrom,
87-
# viscosity=[
88-
# 8.90e-4,
89-
# 8.54e-4,
90-
# 6.94e-4,
91-
# 5.77e-4,
92-
# 4.90e-4,
93-
# 4.22e-4,
94-
# 3.69e-4,
95-
# ],
96-
# temperature=[298.15, 300.00, 310.00, 320.00, 330.00, 340.00, 350.00],
97-
# ) / constants.liter == pytest.approx(
98-
# [3.6e9, 3.8e9, 4.9e9, 6.0e9, 7.3e9, 8.8e9, 1.0e10],
99-
# 4e-2,
100-
# )
101-
102-
# assert rx.rates.collins_kimball(
103-
# radii,
104-
# reactive_radius=2.6 * constants.angstrom,
105-
# viscosity="water",
106-
# temperature=[298.15, 300.00, 310.00, 320.00, 330.00, 340.00, 350.00],
107-
# ) / constants.liter == pytest.approx(
108-
# [3.6e9, 3.8e9, 4.9e9, 6.0e9, 7.3e9, 8.8e9, 1.0e10],
109-
# 4e-2,
110-
# )
82+
# def test_smoluchowski_calculates_diffusion_limited_reaction_rates() -> None:
83+
# """Ensure Smoluchowski rates are correct."""
84+
# radii = np.array([2.59, 2.71]) * constants.angstrom
85+
# assert rx.rates.collins_kimball(
86+
# radii,
87+
# reactive_radius=2.6 * constants.angstrom,
88+
# viscosity=[
89+
# 8.90e-4,
90+
# 8.54e-4,
91+
# 6.94e-4,
92+
# 5.77e-4,
93+
# 4.90e-4,
94+
# 4.22e-4,
95+
# 3.69e-4,
96+
# ],
97+
# temperature=[298.15, 300.00, 310.00, 320.00, 330.00, 340.00, 350.00],
98+
# ) / constants.liter == pytest.approx(
99+
# [3.6e9, 3.8e9, 4.9e9, 6.0e9, 7.3e9, 8.8e9, 1.0e10],
100+
# 4e-2,
101+
# )
102+
103+
# assert rx.rates.collins_kimball(
104+
# radii,
105+
# reactive_radius=2.6 * constants.angstrom,
106+
# viscosity="water",
107+
# temperature=[298.15, 300.00, 310.00, 320.00, 330.00, 340.00, 350.00],
108+
# ) / constants.liter == pytest.approx(
109+
# [3.6e9, 3.8e9, 4.9e9, 6.0e9, 7.3e9, 8.8e9, 1.0e10],
110+
# 4e-2,
111+
# )
111112

112113

113114
def test_liquid_viscosities_are_correct() -> None:

0 commit comments

Comments
 (0)