Skip to content

Commit 23b3374

Browse files
Merge pull request #44 from chrisjonesBSU/add-ruff
Update pre-commit config, bump to numpy 2.0 and hoomd 5.0 in environment files.
2 parents 9e7db75 + f1da50f commit 23b3374

12 files changed

Lines changed: 60 additions & 103 deletions

.pre-commit-config.yaml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
ci:
2-
autofix_commit_msg: |
3-
[pre-commit.ci] auto fixes from pre-commit.com hooks
4-
for more information, see https://pre-commit.ci
5-
autofix_prs: true
6-
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
7-
autoupdate_schedule: weekly
8-
skip: [ ]
9-
submodules: false
2+
autofix_commit_msg: |
3+
[pre-commit.ci] auto fixes from pre-commit.com hooks
4+
for more information, see https://pre-commit.ci
5+
autofix_prs: true
6+
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
7+
autoupdate_schedule: weekly
8+
skip: []
9+
submodules: false
1010
repos:
11-
- repo: https://github.com/astral-sh/ruff-pre-commit
12-
rev: v0.6.1 # Ruff version
13-
hooks:
14-
- id: ruff
15-
args: [--fix, --extend-ignore=E203]
16-
- id: ruff-format
17-
args: [--line-length=80]
18-
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v4.6.0
20-
hooks:
21-
- id: check-yaml
22-
- id: end-of-file-fixer
23-
- id: trailing-whitespace
24-
exclude: 'msibi/tests/assets/.*'
25-
- repo: https://github.com/pycqa/isort
26-
rev: 5.13.2
27-
hooks:
28-
- id: isort
29-
name: isort (python)
30-
args:
31-
[ --profile=black, --line-length=80 ]
32-
exclude: 'msibi/tests/assets/.* '
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
# Ruff version.
13+
rev: v0.12.3
14+
hooks:
15+
# Run the linter.
16+
- id: ruff
17+
args: [--line-length=80, --fix]
18+
# Run the formatter.
19+
- id: ruff-format
20+
- repo: https://github.com/pre-commit/pre-commit-hooks
21+
rev: v5.0.0
22+
hooks:
23+
- id: check-yaml
24+
- id: end-of-file-fixer
25+
- id: trailing-whitespace
26+
exclude: 'setup.cfg|msibi/tests/assets/.*'
27+
28+
- repo: https://github.com/pycqa/isort
29+
rev: 6.0.1
30+
hooks:
31+
- id: isort
32+
name: isort (python)
33+
args: [--profile=black, --line-length=80]
34+
exclude: "msibi/tests/assets/.*"

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3535

3636
html_theme = "sphinx_rtd_theme"
37-
#html_static_path = ["_static"]
37+
# html_static_path = ["_static"]

environment-dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ channels:
44
dependencies:
55
- freud >=3.0,<3.2
66
- gsd >=3.0
7-
- hoomd >=4.0,<5.0
7+
- hoomd >=5.0
88
- python >=3.10
99
- pandas
1010
- cmeutils >=1.3
11-
- numpy <2.0
11+
- numpy >=2.0,<2.3
1212
- more-itertools
1313
- pytest
1414
- pytest-cov

environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ channels:
44
dependencies:
55
- freud >=3.0,<3.2
66
- gsd >=3.0
7-
- hoomd >=4.0,<5.0
7+
- hoomd >=5.0
88
- python >=3.10
99
- pandas
1010
- cmeutils >=1.3
11-
- numpy <2.0
11+
- numpy >=2.0,<2.3
1212
- more-itertools

msibi/forces.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ def save_state_data(self, state: msibi.state.State, file_path: str) -> None:
264264
state_data = {
265265
"target_distribution": state_dict["target_distribution"],
266266
"current_distribution": state_dict["current_distribution"],
267-
"distribution_history": np.asarray(
268-
state_dict["distribution_history"]
269-
),
267+
"distribution_history": np.asarray(state_dict["distribution_history"]),
270268
"f_fit": np.asarray(state_dict["f_fit"]),
271269
}
272270
np.savez(file_path, **state_data)
@@ -321,9 +319,7 @@ def plot_target_distribution(
321319
if file_path:
322320
plt.savefig(file_path)
323321

324-
def plot_fit_scores(
325-
self, state: msibi.state.State, file_path: str = None
326-
) -> None:
322+
def plot_fit_scores(self, state: msibi.state.State, file_path: str = None) -> None:
327323
"""Plot the evolution of the distribution matching fit scores.
328324
329325
Parameters
@@ -563,9 +559,7 @@ def _add_state(self, state: msibi.state.State) -> None:
563559
Instance of a State object previously created.
564560
"""
565561
if self.optimize:
566-
target_distribution = self._get_state_distribution(
567-
state=state, query=False
568-
)
562+
target_distribution = self._get_state_distribution(state=state, query=False)
569563
if self.smoothing_window and self.smoothing_order:
570564
target_distribution[:, 1] = savitzky_golay(
571565
y=target_distribution[:, 1],
@@ -669,9 +663,7 @@ def _update_potential(self) -> None:
669663
self.x_range, self.potential, self.correction_form
670664
)
671665
self.potential_history.append(np.copy(self.potential))
672-
self._head_correction_history.append(
673-
np.copy(self.potential[0:head_cut])
674-
)
666+
self._head_correction_history.append(np.copy(self.potential[0:head_cut]))
675667
self._tail_correction_history.append(np.copy(self.potential[tail_cut:]))
676668
self._learned_potential_history.append(np.copy(self.potential[real]))
677669

@@ -767,9 +759,7 @@ def _table_entry(self) -> dict:
767759
}
768760
return table_entry
769761

770-
def _get_distribution(
771-
self, state: msibi.state.State, gsd_file: str
772-
) -> np.ndarray:
762+
def _get_distribution(self, state: msibi.state.State, gsd_file: str) -> np.ndarray:
773763
"""Calculate a bond length distribution.
774764
775765
Parameters
@@ -881,9 +871,7 @@ def _table_entry(self) -> dict:
881871
table_entry = {"U": self.potential, "tau": self.force}
882872
return table_entry
883873

884-
def _get_distribution(
885-
self, state: msibi.state.State, gsd_file: str
886-
) -> np.ndarray:
874+
def _get_distribution(self, state: msibi.state.State, gsd_file: str) -> np.ndarray:
887875
"""Calculate a bond angle distribution.
888876
889877
Parameters
@@ -996,9 +984,7 @@ def set_lj(
996984
self.x_range = np.arange(r_min, r_cut + self.dx, self.dx)
997985
self.x_min = self.x_range[0]
998986
self.r_cut = self.x_range[-1]
999-
self.potential = lennard_jones(
1000-
r=self.x_range, epsilon=epsilon, sigma=sigma
1001-
)
987+
self.potential = lennard_jones(r=self.x_range, epsilon=epsilon, sigma=sigma)
1002988
self.force_init = "Table"
1003989

1004990
def _table_entry(self) -> dict:
@@ -1010,9 +996,7 @@ def _table_entry(self) -> dict:
1010996
}
1011997
return table_entry
1012998

1013-
def _get_distribution(
1014-
self, state: msibi.state.State, gsd_file: str
1015-
) -> np.ndarray:
999+
def _get_distribution(self, state: msibi.state.State, gsd_file: str) -> np.ndarray:
10161000
"""Calculate a pair distribution (RDF).
10171001
10181002
Parameters
@@ -1142,9 +1126,7 @@ def _table_entry(self) -> dict:
11421126
table_entry = {"U": self.potential, "tau": self.force}
11431127
return table_entry
11441128

1145-
def _get_distribution(
1146-
self, state: msibi.state.State, gsd_file: str
1147-
) -> np.ndarray:
1129+
def _get_distribution(self, state: msibi.state.State, gsd_file: str) -> np.ndarray:
11481130
"""Calculate a dihedral angle distribution.
11491131
11501132
Parameters

msibi/optimize.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ def dihedrals(self) -> list:
146146

147147
def _add_optimize_force(self, force: msibi.forces.Force) -> None:
148148
"""Check that all forces to be optimized are the same type."""
149-
if not all(
150-
[isinstance(force, f.__class__) for f in self._optimize_forces]
151-
):
149+
if not all([isinstance(force, f.__class__) for f in self._optimize_forces]):
152150
raise RuntimeError(
153151
"Only one type of force (i.e., Bonds, Angles, Pairs, etc) "
154152
"can be set to optimize at a time."
@@ -182,7 +180,7 @@ def run_optimization(
182180
are saved in their respective :class:`msibi.state.State` directory.
183181
"""
184182
for n in range(n_iterations):
185-
print(f"---Optimization: {n+1} of {n_iterations}---")
183+
print(f"---Optimization: {n + 1} of {n_iterations}---")
186184
forces = self._build_force_objects()
187185
for state in self.states:
188186
state._run_simulation(
@@ -216,9 +214,7 @@ def pickle_forces(self, file_path: str) -> None:
216214
"""
217215
forces = self._build_force_objects()
218216
if len(forces) == 0:
219-
raise RuntimeError(
220-
"No forces have been created yet. See MSIBI.add_force()"
221-
)
217+
raise RuntimeError("No forces have been created yet. See MSIBI.add_force()")
222218
f = open(file_path, "wb")
223219
pickle.dump(forces, f)
224220

@@ -269,9 +265,7 @@ def _build_force_objects(self) -> list:
269265
dihedral_force = None
270266
for dih in self.dihedrals:
271267
if not dihedral_force:
272-
hoomd_dihedral_force = getattr(
273-
hoomd.md.dihedral, dih.force_init
274-
)
268+
hoomd_dihedral_force = getattr(hoomd.md.dihedral, dih.force_init)
275269
if dih.force_init == "Table":
276270
dihedral_force = hoomd_dihedral_force(width=dih.nbins + 1)
277271
else:

msibi/potentials.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def pair_correction(r, V, form, r_switch=2.5):
5959
pass
6060
# Trim off edge cases
6161
_real_idx = np.where(np.isfinite(V))[0]
62-
real_idx = max(
63-
[list(g) for g in mit.consecutive_groups(_real_idx)], key=len
64-
)
62+
real_idx = max([list(g) for g in mit.consecutive_groups(_real_idx)], key=len)
6563

6664
head_cutoff = real_idx[0] - 1
6765
tail_cutoff = real_idx[-1] + 1
@@ -104,9 +102,7 @@ def bond_correction(r, V, form):
104102
pass
105103
# Trim off edge cases
106104
_real_idx = np.where(np.isfinite(V))[0]
107-
real_idx = max(
108-
[list(g) for g in mit.consecutive_groups(_real_idx)], key=len
109-
)
105+
real_idx = max([list(g) for g in mit.consecutive_groups(_real_idx)], key=len)
110106

111107
head_cutoff = real_idx[0] - 1
112108
tail_cutoff = real_idx[-1] + 1

msibi/tests/base_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ def bond(self):
105105

106106
@pytest.fixture
107107
def angle(self):
108-
angle = Angle(
109-
type1="A", type2="B", type3="A", optimize=False, nbins=100
110-
)
108+
angle = Angle(type1="A", type2="B", type3="A", optimize=False, nbins=100)
111109
return angle
112110

113111
@pytest.fixture

msibi/tests/test_forces.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def test_smooth_potential(self, bond):
4343
x_min=1,
4444
x_max=3,
4545
)
46-
bond.potential = bond.potential + np.random.normal(
47-
0, 0.5, bond.potential.shape
48-
)
46+
bond.potential = bond.potential + np.random.normal(0, 0.5, bond.potential.shape)
4947
noisy_pot = np.copy(bond.potential)
5048
bond.smoothing_window = 5
5149
bond.smooth_potential()
@@ -241,18 +239,14 @@ def test_set_dihedral_harmonic(self, dihedral):
241239
assert dihedral.force_entry["n"] == 1
242240

243241
def test_set_dihedral_polynomail(self, dihedral):
244-
dihedral.set_polynomial(
245-
x0=0, k4=0, k3=0, k2=100, x_min=-np.pi, x_max=np.pi
246-
)
242+
dihedral.set_polynomial(x0=0, k4=0, k3=0, k2=100, x_min=-np.pi, x_max=np.pi)
247243
assert dihedral.format == "table"
248244
assert len(dihedral.x_range) == dihedral.nbins + 1
249245
assert np.allclose(dihedral.x_range[0], -np.pi, atol=1e-3)
250246
assert np.allclose(dihedral.x_range[-1], np.pi, atol=1e-3)
251247

252248
def test_save_angle_potential(self, tmp_path, dihedral):
253-
dihedral.set_polynomial(
254-
x0=0, k4=0, k3=0, k2=100, x_min=-np.pi, x_max=np.pi
255-
)
249+
dihedral.set_polynomial(x0=0, k4=0, k3=0, k2=100, x_min=-np.pi, x_max=np.pi)
256250
path = os.path.join(tmp_path, "ABAA_dihedral.csv")
257251
dihedral.save_potential(path)
258252
assert os.path.isfile(path)

msibi/tests/test_optimize.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ def test_run_with_static_force(self, msibi, stateX, stateY):
8181
ff = msibi._build_force_objects()
8282
assert len(ff) == 2
8383

84-
def test_optimize_pairs_linear_alpha(
85-
self, msibi, stateX_linear_alpha, stateY
86-
):
84+
def test_optimize_pairs_linear_alpha(self, msibi, stateX_linear_alpha, stateY):
8785
msibi.gsd_period = 10
8886
msibi.add_state(stateX_linear_alpha)
8987
msibi.add_state(stateY)
@@ -185,9 +183,7 @@ def test_run_with_all_forces(self, msibi, stateX, stateY):
185183
pair3.set_lj(sigma=1.5, epsilon=1, r_cut=2.0, r_min=0.1)
186184
msibi.add_force(pair3)
187185

188-
dihedral = Dihedral(
189-
type1="B", type2="A", type3="B", type4="A", optimize=False
190-
)
186+
dihedral = Dihedral(type1="B", type2="A", type3="B", type4="A", optimize=False)
191187
dihedral.set_periodic(k=100, phi0=0, d=-1, n=1)
192188
msibi.add_force(dihedral)
193189

0 commit comments

Comments
 (0)