Skip to content

Commit a2f7c3e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 648fd27 commit a2f7c3e

File tree

10 files changed

+102
-130
lines changed

10 files changed

+102
-130
lines changed

ipsuite/analysis/bin_property.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,9 @@ def run(self):
205205
self.get_plots(counts[0], bin_edges[0], hydrostatic=True)
206206
self.get_plots(counts[1], bin_edges[1], hydrostatic=False)
207207

208-
self.labels_df = pd.DataFrame(
209-
{
210-
"hydro_bin_edges": bin_edges[0][1:],
211-
"hydro_counts": counts[0],
212-
"deviatoric_bin_edges": bin_edges[1][1:],
213-
"deviatoric_counts": counts[1],
214-
}
215-
)
208+
self.labels_df = pd.DataFrame({
209+
"hydro_bin_edges": bin_edges[0][1:],
210+
"hydro_counts": counts[0],
211+
"deviatoric_bin_edges": bin_edges[1][1:],
212+
"deviatoric_counts": counts[1],
213+
})

ipsuite/analysis/ensemble.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def run(self):
7979
for idx, atom in enumerate(self.data):
8080
atom.calc = ase.calculators.singlepoint.SinglePointCalculator(
8181
atoms=atom,
82-
energy=np.mean(
83-
[p[idx].get_potential_energy() for p in self.prediction_list]
84-
),
82+
energy=np.mean([
83+
p[idx].get_potential_energy() for p in self.prediction_list
84+
]),
8585
forces=np.mean(
8686
[p[idx].get_forces() for p in self.prediction_list], axis=0
8787
),
@@ -94,9 +94,9 @@ def run(self):
9494
figures[2].savefig(self.histogram)
9595

9696
def get_plots(self):
97-
energy = np.stack(
98-
[np.stack(x.get_potential_energy() for x in p) for p in self.prediction_list]
99-
)
97+
energy = np.stack([
98+
np.stack(x.get_potential_energy() for x in p) for p in self.prediction_list
99+
])
100100

101101
figures = []
102102
# Plot the energy

ipsuite/analysis/model/dynamics.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ def run(self):
165165
if "energy_uncertainty" in self.atoms[0].calc.results:
166166
fig, ax, _ = plot_with_uncertainty(
167167
{
168-
"std": np.std(
169-
[a.calc.results["energy_uncertainty"] for a in self.atoms]
170-
),
168+
"std": np.std([
169+
a.calc.results["energy_uncertainty"] for a in self.atoms
170+
]),
171171
"mean": self.energies["y"],
172172
},
173173
x=self.energies["x"],

ipsuite/analysis/model/predict.py

+30-42
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,14 @@ def get_dataframes(self):
105105
"""Create a pandas dataframe from the given data."""
106106
true_data, pred_data = self.get_data()
107107

108-
self.energy_df = pd.DataFrame(
109-
{
110-
"true": (
111-
np.array([x.get_potential_energy() / len(x) for x in true_data])
112-
* 1000
113-
),
114-
"prediction": (
115-
np.array([x.get_potential_energy() / len(x) for x in pred_data])
116-
* 1000
117-
),
118-
}
119-
)
108+
self.energy_df = pd.DataFrame({
109+
"true": (
110+
np.array([x.get_potential_energy() / len(x) for x in true_data]) * 1000
111+
),
112+
"prediction": (
113+
np.array([x.get_potential_energy() / len(x) for x in pred_data]) * 1000
114+
),
115+
})
120116

121117
try:
122118
true_forces = [np.reshape(x.get_forces(), (-1, 3)) for x in true_data]
@@ -125,18 +121,16 @@ def get_dataframes(self):
125121
pred_forces = [np.reshape(x.get_forces(), (-1, 3)) for x in pred_data]
126122
pred_forces = np.concatenate(pred_forces, axis=0) * 1000
127123

128-
self.forces_df = pd.DataFrame(
129-
{
130-
"true": np.linalg.norm(true_forces, axis=-1),
131-
"true_x": true_forces[:, 0],
132-
"true_y": true_forces[:, 1],
133-
"true_z": true_forces[:, 2],
134-
"prediction": np.linalg.norm(pred_forces, axis=-1),
135-
"prediction_x": pred_forces[:, 0],
136-
"prediction_y": pred_forces[:, 1],
137-
"prediction_z": pred_forces[:, 2],
138-
}
139-
)
124+
self.forces_df = pd.DataFrame({
125+
"true": np.linalg.norm(true_forces, axis=-1),
126+
"true_x": true_forces[:, 0],
127+
"true_y": true_forces[:, 1],
128+
"true_z": true_forces[:, 2],
129+
"prediction": np.linalg.norm(pred_forces, axis=-1),
130+
"prediction_x": pred_forces[:, 0],
131+
"prediction_y": pred_forces[:, 1],
132+
"prediction_z": pred_forces[:, 2],
133+
})
140134
except PropertyNotImplementedError:
141135
self.forces_df = pd.DataFrame({})
142136

@@ -153,24 +147,18 @@ def get_dataframes(self):
153147
hydro_pred = np.reshape(hydro_pred, -1)
154148
deviat_pred = np.reshape(deviat_pred, -1)
155149

156-
self.stress_df = pd.DataFrame(
157-
{
158-
"true": true_stress,
159-
"prediction": pred_stress,
160-
}
161-
)
162-
self.stress_hydro_df = pd.DataFrame(
163-
{
164-
"true": hydro_true,
165-
"prediction": hydro_pred,
166-
}
167-
)
168-
self.stress_deviat_df = pd.DataFrame(
169-
{
170-
"true": deviat_true,
171-
"prediction": deviat_pred,
172-
}
173-
)
150+
self.stress_df = pd.DataFrame({
151+
"true": true_stress,
152+
"prediction": pred_stress,
153+
})
154+
self.stress_hydro_df = pd.DataFrame({
155+
"true": hydro_true,
156+
"prediction": hydro_pred,
157+
})
158+
self.stress_deviat_df = pd.DataFrame({
159+
"true": deviat_true,
160+
"prediction": deviat_pred,
161+
})
174162
except PropertyNotImplementedError:
175163
self.stress_df = pd.DataFrame({})
176164
self.stress_hydro_df = pd.DataFrame({})

ipsuite/calculators/ase_md.py

+19-23
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ class RescaleBoxModifier(base.IPSNode):
3030
def modify(self, thermostat, step, total_steps):
3131
# we use the thermostat, so we can also modify e.g. temperature
3232
if isinstance(self.cell, int):
33-
self.cell = np.array(
34-
[[self.cell, 0, 0], [0, self.cell, 0], [0, 0, self.cell]]
35-
)
33+
self.cell = np.array([
34+
[self.cell, 0, 0], [0, self.cell, 0], [0, 0, self.cell]
35+
])
3636
elif isinstance(self.cell, list):
37-
self.cell = np.array(
38-
[[self.cell[0], 0, 0], [0, self.cell[1], 0], [0, 0, self.cell[2]]]
39-
)
37+
self.cell = np.array([
38+
[self.cell[0], 0, 0], [0, self.cell[1], 0], [0, 0, self.cell[2]]
39+
])
4040

4141
if self._initial_cell is None:
4242
self._initial_cell = thermostat.atoms.get_cell()
@@ -73,17 +73,15 @@ def modify(self, thermostat, step, total_steps):
7373
if self._initial_cell is None:
7474
self._initial_cell = thermostat.atoms.get_cell()
7575
if isinstance(self.end_cell, (float, int)):
76-
self.end_cell = np.array(
77-
[[self.end_cell, 0, 0], [0, self.end_cell, 0], [0, 0, self.end_cell]]
78-
)
76+
self.end_cell = np.array([
77+
[self.end_cell, 0, 0], [0, self.end_cell, 0], [0, 0, self.end_cell]
78+
])
7979
elif isinstance(self.end_cell, list):
80-
self.end_cell = np.array(
81-
[
82-
[self.end_cell[0], 0, 0],
83-
[0, self.end_cell[1], 0],
84-
[0, 0, self.end_cell[2]],
85-
]
86-
)
80+
self.end_cell = np.array([
81+
[self.end_cell[0], 0, 0],
82+
[0, self.end_cell[1], 0],
83+
[0, 0, self.end_cell[2]],
84+
])
8785

8886
percentage = step / (total_steps - 1)
8987
ramp = percentage * (self.end_cell - self._initial_cell)
@@ -275,13 +273,11 @@ class NPTThermostat(base.IPSNode):
275273

276274
def get_thermostat(self, atoms):
277275
if self.tetragonal_strain:
278-
mask = np.array(
279-
[
280-
[True, False, False],
281-
[False, True, False],
282-
[False, False, True],
283-
]
284-
)
276+
mask = np.array([
277+
[True, False, False],
278+
[False, True, False],
279+
[False, False, True],
280+
])
285281
else:
286282
mask = None
287283
self.time_step *= units.fs

ipsuite/models/apax.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ def _get_plot(self, atoms_lst: typing.List[ase.Atoms], indices: typing.List[int]
233233
energies = np.array([atoms.calc.results["energy"] for atoms in atoms_lst])
234234

235235
if "energy_uncertainty" in atoms_lst[0].calc.results.keys():
236-
uncertainty = np.array(
237-
[atoms.calc.results["energy_uncertainty"] for atoms in atoms_lst]
238-
)
236+
uncertainty = np.array([
237+
atoms.calc.results["energy_uncertainty"] for atoms in atoms_lst
238+
])
239239
fig, ax, _ = plot_with_uncertainty(
240240
{"mean": energies, "std": uncertainty},
241241
ylabel="energy",

ipsuite/models/ensemble.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def calculate(
3737

3838
self.results["energy"] = np.mean([x.get_potential_energy() for x in results])
3939
self.results["forces"] = np.mean([x.get_forces() for x in results], axis=0)
40-
self.results["energy_uncertainty"] = np.std(
41-
[x.get_potential_energy() for x in results]
42-
)
40+
self.results["energy_uncertainty"] = np.std([
41+
x.get_potential_energy() for x in results
42+
])
4343
self.results["forces_uncertainty"] = np.std(
4444
[x.get_forces() for x in results], axis=0
4545
)

ipsuite/models/nequip.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ def _handle_parameter_file(self, n_train: int, n_val: int, chemical_symbols: lis
111111

112112
def train_model(self):
113113
"""Train the model using nequip-train."""
114-
subprocess.check_call(
115-
["nequip-train", (self.model_directory / "config.yaml").as_posix()]
116-
)
114+
subprocess.check_call([
115+
"nequip-train", (self.model_directory / "config.yaml").as_posix()
116+
])
117117

118118
def move_metrics(self):
119119
"""Move the metrics to the correct directories for DVC."""
@@ -137,15 +137,13 @@ def get_metrics_from_plots(self):
137137

138138
def deploy_model(self):
139139
"""Deploy the model using nequip-deploy."""
140-
subprocess.check_call(
141-
[
142-
"nequip-deploy",
143-
"build",
144-
"--train-dir",
145-
(self.model_directory / "dvc-run").as_posix(),
146-
self.deployed_model.as_posix(),
147-
]
148-
)
140+
subprocess.check_call([
141+
"nequip-deploy",
142+
"build",
143+
"--train-dir",
144+
(self.model_directory / "dvc-run").as_posix(),
145+
self.deployed_model.as_posix(),
146+
])
149147

150148
def run(self):
151149
"""Primary method to run which executes all steps of the model training."""

tests/conftest.py

+19-27
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,27 @@ def data_repo(tmp_path, request) -> pathlib.Path:
131131
def atoms_with_composed_forces():
132132
atoms = Atoms(
133133
"OH2",
134-
positions=np.array(
135-
[
136-
[0.0, 0.0, 0.0],
137-
[1.0, 0.0, 0.0],
138-
[0.0, 1.0, 0.0],
139-
]
140-
),
141-
)
142-
ft = np.array(
143-
[
144-
[0.0, 0.0, 1.0 * 15.999],
145-
[0.0, 0.0, 1.008],
146-
[0.0, 0.0, 1.008],
147-
]
148-
)
149-
fr = np.array(
150-
[
134+
positions=np.array([
151135
[0.0, 0.0, 0.0],
152-
[0.0, 0.0, 1.008],
153-
[0.0, 0.0, -1.008],
154-
]
155-
)
156-
fv = np.array(
157-
[
158-
[1.0, 1.0, 0.0],
159-
[-1.0, 0.0, 0.0],
160-
[0.0, -1.0, 0.0],
161-
]
136+
[1.0, 0.0, 0.0],
137+
[0.0, 1.0, 0.0],
138+
]),
162139
)
140+
ft = np.array([
141+
[0.0, 0.0, 1.0 * 15.999],
142+
[0.0, 0.0, 1.008],
143+
[0.0, 0.0, 1.008],
144+
])
145+
fr = np.array([
146+
[0.0, 0.0, 0.0],
147+
[0.0, 0.0, 1.008],
148+
[0.0, 0.0, -1.008],
149+
])
150+
fv = np.array([
151+
[1.0, 1.0, 0.0],
152+
[-1.0, 0.0, 0.0],
153+
[0.0, -1.0, 0.0],
154+
])
163155
atoms.calc = ase.calculators.singlepoint.SinglePointCalculator(
164156
atoms, forces=ft + fr + fv
165157
)

tests/unit_tests/test_utils_combine.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def test_ExcludeIds_dict_multi(ids):
101101
4 + 8 + 5,
102102
] # [missing + size of a, idx]
103103

104-
for x in exclude.get_original_ids(
105-
[8 + 0, 8 + 1, 8 + 2, 8 + 3, 8 + 4, 8 + 5]
106-
): # the ids must not be in the excluded ids.
104+
for x in exclude.get_original_ids([
105+
8 + 0, 8 + 1, 8 + 2, 8 + 3, 8 + 4, 8 + 5
106+
]): # the ids must not be in the excluded ids.
107107
assert x not in exclude.ids_as_list
108108

109109
assert exclude.get_original_ids([8 + 10 + 0, 8 + 10 + 1]) == [

0 commit comments

Comments
 (0)