Skip to content

Commit

Permalink
fix bug with no seed set
Browse files Browse the repository at this point in the history
  • Loading branch information
shinkle-lanl committed May 9, 2024
1 parent bdf3173 commit 341c5b7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions hippynn/molecular_dynamics/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def __init__(
self.frix = frix
self.kB = 0.001987204 * self.force_factor

torch.manual_seed(seed)
if seed is not None:
torch.manual_seed(seed)

def _pre_step(self, dt):
"""Updates to variables performed during each step of MD simulation
Expand All @@ -316,6 +317,7 @@ def _pre_step(self, dt):
dt : float
timestep
"""

self.variable.values["position"] = (
self.variable.values["position"] + self.variable.values["velocity"] * dt
)
Expand All @@ -335,14 +337,20 @@ def _post_step(self, dt, model_outputs):
self.variable.device
)

if len(self.variable.values["force"].shape) != len(
self.variable.values["mass"].shape
):
self.variable.values["mass"] = self.variable.values["mass"][..., None]

self.variable.values["acceleration"] = (
self.variable.values["force"].detach()
/ self.variable.values["mass"]
* self.force_factor
)

self.variable.values["velocity"] = self.variable.values["velocity"] + (
+dt * self.variable.values["acceleration"]
self.variable.values["velocity"] = (
self.variable.values["velocity"]
+ dt * self.variable.values["acceleration"]
- self.frix * self.variable.values["velocity"] * dt
+ torch.sqrt(
2
Expand Down

0 comments on commit 341c5b7

Please sign in to comment.