Skip to content

Commit 53fdc1c

Browse files
committed
unit fix
1 parent a69e992 commit 53fdc1c

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

nff/io/bias_calculators.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,22 @@ def calculate(
297297

298298
prediction = self.model(batch, **kwargs)
299299

300-
# change energy and force to numpy array and eV
301-
model_energy = prediction[self.en_key].detach().cpu().numpy() * (1 / const.EV_TO_KCAL_MOL)
300+
# change energy and force to numpy array and eV (use model_units -> prediction_units like NeuralFF)
301+
conv_dict = const.conversion_factors.get(
302+
(getattr(self, "model_units", "kcal/mol"), getattr(self, "prediction_units", "eV")),
303+
const.DEFAULT,
304+
)
305+
energy_factor = conv_dict["energy"]
306+
grad_factor = conv_dict["_grad"]
307+
308+
model_energy = prediction[self.en_key].detach().cpu().numpy() * energy_factor
302309

303310
gradient = prediction.get(grad_key)
304311
forces = prediction.get("forces")
305312
if gradient is not None:
306-
model_grad = gradient.detach().cpu().numpy() * (1 / const.EV_TO_KCAL_MOL)
313+
model_grad = gradient.detach().cpu().numpy() * grad_factor
307314
elif forces is not None:
308-
model_grad = - forces.detach().cpu().numpy() * (1 / const.EV_TO_KCAL_MOL)
315+
model_grad = - forces.detach().cpu().numpy() * grad_factor
309316
else:
310317
raise KeyError(grad_key)
311318

@@ -373,7 +380,8 @@ def calculate(
373380
self.results["const_vals"] = consts
374381

375382
if requires_stress:
376-
stress = prediction["stress_volume"].detach().cpu().numpy() * (1 / const.EV_TO_KCAL_MOL)
383+
stress_factor = conv_dict.get("stress", 1.0)
384+
stress = prediction["stress_volume"].detach().cpu().numpy() * stress_factor
377385
self.results["stress"] = stress * (1 / atoms.get_volume())
378386

379387

0 commit comments

Comments
 (0)