Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 29, 2024
1 parent 3edff60 commit b6c385f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 106 deletions.
14 changes: 6 additions & 8 deletions ipsuite/analysis/bin_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,9 @@ def run(self):
self.get_plots(counts[0], bin_edges[0], hydrostatic=True)
self.get_plots(counts[1], bin_edges[1], hydrostatic=False)

self.labels_df = pd.DataFrame(
{
"hydro_bin_edges": bin_edges[0][1:],
"hydro_counts": counts[0],
"deviatoric_bin_edges": bin_edges[1][1:],
"deviatoric_counts": counts[1],
}
)
self.labels_df = pd.DataFrame({
"hydro_bin_edges": bin_edges[0][1:],
"hydro_counts": counts[0],
"deviatoric_bin_edges": bin_edges[1][1:],
"deviatoric_counts": counts[1],
})
9 changes: 3 additions & 6 deletions ipsuite/analysis/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,9 @@ def run(self):
figures[2].savefig(self.histogram)

def get_plots(self):
energy = np.stack(
[
np.stack([x.get_potential_energy() for x in p])
for p in self.prediction_list
]
)
energy = np.stack([
np.stack([x.get_potential_energy() for x in p]) for p in self.prediction_list
])

figures = []
# Plot the energy
Expand Down
72 changes: 30 additions & 42 deletions ipsuite/analysis/model/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,14 @@ def get_dataframes(self):
"""Create a pandas dataframe from the given data."""
true_data, pred_data = self.get_data()

self.energy_df = pd.DataFrame(
{
"true": (
np.array([x.get_potential_energy() / len(x) for x in true_data])
* 1000
),
"prediction": (
np.array([x.get_potential_energy() / len(x) for x in pred_data])
* 1000
),
}
)
self.energy_df = pd.DataFrame({
"true": (
np.array([x.get_potential_energy() / len(x) for x in true_data]) * 1000
),
"prediction": (
np.array([x.get_potential_energy() / len(x) for x in pred_data]) * 1000
),
})

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

self.forces_df = pd.DataFrame(
{
"true": np.linalg.norm(true_forces, axis=-1),
"true_x": true_forces[:, 0],
"true_y": true_forces[:, 1],
"true_z": true_forces[:, 2],
"prediction": np.linalg.norm(pred_forces, axis=-1),
"prediction_x": pred_forces[:, 0],
"prediction_y": pred_forces[:, 1],
"prediction_z": pred_forces[:, 2],
}
)
self.forces_df = pd.DataFrame({
"true": np.linalg.norm(true_forces, axis=-1),
"true_x": true_forces[:, 0],
"true_y": true_forces[:, 1],
"true_z": true_forces[:, 2],
"prediction": np.linalg.norm(pred_forces, axis=-1),
"prediction_x": pred_forces[:, 0],
"prediction_y": pred_forces[:, 1],
"prediction_z": pred_forces[:, 2],
})
except PropertyNotImplementedError:
self.forces_df = pd.DataFrame({})

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

self.stress_df = pd.DataFrame(
{
"true": true_stress,
"prediction": pred_stress,
}
)
self.stress_hydro_df = pd.DataFrame(
{
"true": hydro_true,
"prediction": hydro_pred,
}
)
self.stress_deviat_df = pd.DataFrame(
{
"true": deviat_true,
"prediction": deviat_pred,
}
)
self.stress_df = pd.DataFrame({
"true": true_stress,
"prediction": pred_stress,
})
self.stress_hydro_df = pd.DataFrame({
"true": hydro_true,
"prediction": hydro_pred,
})
self.stress_deviat_df = pd.DataFrame({
"true": deviat_true,
"prediction": deviat_pred,
})
except PropertyNotImplementedError:
self.stress_df = pd.DataFrame({})
self.stress_hydro_df = pd.DataFrame({})
Expand Down
24 changes: 10 additions & 14 deletions ipsuite/calculators/ase_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ def modify(self, thermostat, step, total_steps):
[[self.end_cell, 0, 0], [0, self.end_cell, 0], [0, 0, self.end_cell]]
)
elif isinstance(self.end_cell, list):
self.end_cell = np.array(
[
[self.end_cell[0], 0, 0],
[0, self.end_cell[1], 0],
[0, 0, self.end_cell[2]],
]
)
self.end_cell = np.array([
[self.end_cell[0], 0, 0],
[0, self.end_cell[1], 0],
[0, 0, self.end_cell[2]],
])

percentage = step / (total_steps - 1)
# if num_ramp_oscillations is set, the cell size is ramped to end_cell within
Expand Down Expand Up @@ -312,13 +310,11 @@ class NPTThermostat(base.IPSNode):

def get_thermostat(self, atoms):
if self.tetragonal_strain:
mask = np.array(
[
[True, False, False],
[False, True, False],
[False, False, True],
]
)
mask = np.array([
[True, False, False],
[False, True, False],
[False, False, True],
])
else:
mask = None
self.time_step *= units.fs
Expand Down
16 changes: 7 additions & 9 deletions ipsuite/models/nequip.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,13 @@ def get_metrics_from_plots(self):

def deploy_model(self):
"""Deploy the model using nequip-deploy."""
subprocess.check_call(
[
"nequip-deploy",
"build",
"--train-dir",
(self.model_directory / "dvc-run").as_posix(),
self.deployed_model.as_posix(),
]
)
subprocess.check_call([
"nequip-deploy",
"build",
"--train-dir",
(self.model_directory / "dvc-run").as_posix(),
self.deployed_model.as_posix(),
])

def run(self):
"""Primary method to run which executes all steps of the model training."""
Expand Down
47 changes: 20 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
References
----------
https://docs.pytest.org/en/6.2.x/fixture.html#scope-sharing-fixtures-across-classes-modules-packages-or-session
"""

import logging
Expand Down Expand Up @@ -131,35 +132,27 @@ def data_repo(tmp_path, request) -> pathlib.Path:
def atoms_with_composed_forces():
atoms = Atoms(
"OH2",
positions=np.array(
[
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
]
),
)
ft = np.array(
[
[0.0, 0.0, 1.0 * 15.999],
[0.0, 0.0, 1.008],
[0.0, 0.0, 1.008],
]
)
fr = np.array(
[
positions=np.array([
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.008],
[0.0, 0.0, -1.008],
]
)
fv = np.array(
[
[1.0, 1.0, 0.0],
[-1.0, 0.0, 0.0],
[0.0, -1.0, 0.0],
]
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
]),
)
ft = np.array([
[0.0, 0.0, 1.0 * 15.999],
[0.0, 0.0, 1.008],
[0.0, 0.0, 1.008],
])
fr = np.array([
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.008],
[0.0, 0.0, -1.008],
])
fv = np.array([
[1.0, 1.0, 0.0],
[-1.0, 0.0, 0.0],
[0.0, -1.0, 0.0],
])
atoms.calc = ase.calculators.singlepoint.SinglePointCalculator(
atoms, forces=ft + fr + fv
)
Expand Down

0 comments on commit b6c385f

Please sign in to comment.