Skip to content

Commit

Permalink
move openmm util out of walkers.utils to avoid importing yaff
Browse files Browse the repository at this point in the history
  • Loading branch information
svandenhaute committed Nov 1, 2023
1 parent 1c8f037 commit 0401aec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
23 changes: 22 additions & 1 deletion psiflow/walkers/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ def molecular_dynamics_openmm(
return " ".join(command_list)


def parse_openmm_output(stdout):
temperatures = []
counter = 0
time = 0
start = False
for line in stdout.split("\n"):
if start:
try:
metrics = [s for s in line.split(",")]
time = float(metrics[-1])
counter = int(metrics[0])
temperatures.append(float(metrics[2]))
except ValueError:
break
if '#"Step","Potential Energy (kJ/mole)"' in line:
start = True
if len(temperatures) == 0:
temperatures.append(-1)
return counter, np.mean(np.array(temperatures)), time


@python_app(executors=["default_threads"])
def molecular_dynamics_openmm_post(
inputs: list[File] = [],
Expand All @@ -175,7 +196,7 @@ def molecular_dynamics_openmm_post(
from ase.io import read

from psiflow.data import FlowAtoms, NullState
from psiflow.walkers.utils import parse_openmm_output
from psiflow.walkers.dynamic import parse_openmm_output

with open(inputs[1], "r") as f:
stdout = f.read()
Expand Down
21 changes: 0 additions & 21 deletions psiflow/walkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,27 +267,6 @@ def parse_yaff_output(stdout):
return counter, np.mean(np.array(temperatures)), time


def parse_openmm_output(stdout):
temperatures = []
counter = 0
time = 0
start = False
for line in stdout.split("\n"):
if start:
try:
metrics = [s for s in line.split(",")]
time = float(metrics[-1])
counter = int(metrics[0])
temperatures.append(float(metrics[2]))
except ValueError:
break
if '#"Step","Potential Energy (kJ/mole)"' in line:
start = True
if len(temperatures) == 0:
temperatures.append(-1)
return counter, np.mean(np.array(temperatures)), time


def max_temperature(temperature: float, natoms: int, quantile: float) -> float:
ndof = 3 * natoms
return chi2.ppf(1 - quantile, ndof) * temperature / ndof
Expand Down
7 changes: 2 additions & 5 deletions tests/test_walkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
RandomWalker,
load_walker,
)
from psiflow.walkers.utils import (
get_velocities_at_temperature,
parse_openmm_output,
parse_yaff_output,
)
from psiflow.walkers.dynamic import parse_openmm_output
from psiflow.walkers.utils import get_velocities_at_temperature, parse_yaff_output


def test_random_walker_multiply(dataset, tmp_path):
Expand Down

0 comments on commit 0401aec

Please sign in to comment.