Skip to content

Commit

Permalink
check install
Browse files Browse the repository at this point in the history
  • Loading branch information
VGPReys committed Sep 20, 2024
1 parent 97c63cb commit d66f515
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
43 changes: 24 additions & 19 deletions src/haddock/modules/refinement/openmm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""OpenMM refinement module for HADDOCK3."""
import os
import shutil

from contextlib import suppress
from pathlib import Path

from haddock.core.exceptions import ThirdPartyIntallationError
from subprocess import run as subprocrun
from haddock.core.exceptions import ThirdPartyIntallationError, HaddockModuleError
from haddock.libs.libontology import PDBFile
from haddock.libs.libsubprocess import run_subprocess
from haddock.modules import BaseHaddockModule, get_engine

# allow general testing when OpenMM is not installed
Expand Down Expand Up @@ -68,6 +68,16 @@ def confirm_installation(cls) -> None:
ThirdPartyIntallationError
When OpenMM pdbfixer is not installed
"""
def run_subprocess(command_to_run: str) -> str:
"""Run subprocess."""
subprocess_output = subprocrun(
[command_to_run],
shell=True,
capture_output=True,
encoding='utf-8',
)
return subprocess_output.stdout.strip()

checkOpenMM = run_subprocess("conda list openmm --json")
checkPdbfixer = run_subprocess("conda list pdbfixer --json")

Expand Down Expand Up @@ -102,7 +112,6 @@ def _run(self) -> None:
Path("."),
directory_dict,
self.params,
self.log,
)
# Hold it
openmm_jobs.append(openmm_job_i)
Expand All @@ -118,21 +127,9 @@ def _run(self) -> None:

# Check if at least one output file was generated
if len(output_pdbs) == 0:
raise Exception("No output models generated. Check Openmm Execution.") # noqa: E501
# ensemble_name = "openmm_ensemble.pdb"
# ensemble = make_ensemble(output_pdbs) # ensemble is a generator
# with open(ensemble_name, "w") as wfile:
# for line in ensemble:
# wfile.write(line)
# self.log(f'Output ensemble {ensemble_name} created.')

# Setting the output variable
self.output_models = [
PDBFile(openmmout)
for openmmout in sorted(output_pdbs)
]
# Generating standardized haddock3 outputs
self.export_output_models()
raise HaddockModuleError(
"No output models generated. Check Openmm Execution."
)

# deleting unnecessary directories
self.log("Removing unnecessary directories...")
Expand All @@ -144,3 +141,11 @@ def _run(self) -> None:
" the OpenMM module, the next module should be `[topoaa]`, "
"to rebuild the CNS molecular topologies."
)

# Setting the output variable
self.output_models = [
PDBFile(openmmout)
for openmmout in sorted(output_pdbs)
]
# Generating standardized haddock3 outputs
self.export_io_models()
19 changes: 9 additions & 10 deletions src/haddock/modules/refinement/openmm/openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def __init__(
path: Path,
directory_dict: dict[str, str],
params: ParamDict,
logger: Optional,
):
"""
Initialize the class.
Expand Down Expand Up @@ -111,14 +110,14 @@ def __init__(
self.path = path
self.directory_dict = directory_dict
self.params = params
self.log = logger if logger else log
self.log = log

# other parameters
self.output = Path("output_openmm.log")
self.constraints = self.import_constraints()
self.output_filename = self.model.file_name.replace(".pdb", "_omm.pdb")

def import_constraints(self) -> Optional[Union[AllBonds, HAngles, HBonds]]:
def import_constraints(self): # type: ignore
"""Cast parameter string to proper openmm constraints."""
if self.params["constraints"] == "HBonds":
return HBonds
Expand Down Expand Up @@ -365,7 +364,7 @@ def equilibrate_solvation_box(
simulation,
max_temperature,
statereporter._dof,
tolerence=10.0,
tolerance=10.0,
steps=50
)
# Print log info
Expand Down Expand Up @@ -418,7 +417,7 @@ def _stabilize_temperature(
simulation: Simulation,
temperature: float,
dof: int,
tolerence: float = 5.0,
tolerance: float = 5.0,
steps: int = 50,
) -> None:
"""
Expand All @@ -432,16 +431,16 @@ def _stabilize_temperature(
The temperature hoped to be reached
dof : int
The degree of freedom obtained from the statereporter._dof
tolerence : float
The tolerence allowed for the temperature
tolerance : float
The tolerance allowed for the temperature
steps : int
The number of steps to do before checking again that
temperature was reached
"""
# Makes sure temperature of the system is reached
while not ((temperature - tolerence)
while not ((temperature - tolerance)
<= self._get_simulation_temperature(simulation, dof)
<= (temperature + tolerence)):
<= (temperature + tolerance)):
# Do several simulation steps
simulation.step(steps)

Expand Down Expand Up @@ -721,7 +720,7 @@ def run_openmm(
simulation,
qtemp,
statereporter._dof,
tolerence=5.0,
tolerance=5.0,
steps=50
)
log.info(
Expand Down

0 comments on commit d66f515

Please sign in to comment.