Skip to content

Commit

Permalink
Changing final to save parameter inside setup and run function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jgmedina95 committed Jan 24, 2024
1 parent 232a7d8 commit f9b19c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
8 changes: 5 additions & 3 deletions mdagent/tools/base_tools/preprocess_tools/clean_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def _run(self, **input_args) -> str:
else:
input_args = input_args
pdbfile_id = input_args.get("pdb_id", None)
# TODO check if pdbfile_id is a valid pdb_id from the registry
if pdbfile_id is None:
return """No file was provided.
The input has to be a dictionary with the key 'pdb_id'"""
Expand All @@ -297,9 +298,10 @@ def _run(self, **input_args) -> str:
try:
pdbfile = self.path_registry.get_mapped_path(pdbfile_id)
if "/" in pdbfile:
pdbfile_name = pdbfile.split("/")[-1]
name = pdbfile_name.split("_")[0]
end = pdbfile_name.split(".")[1]
pdbfile = pdbfile.split("/")[-1]

name = pdbfile.split("_")[0]
end = pdbfile.split(".")[1]

except Exception as e:
print(f"error retrieving from path_registry, trying to read file {e}")
Expand Down
28 changes: 14 additions & 14 deletions mdagent/tools/base_tools/simulation_tools/setup_and_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,12 @@ def __init__(
self,
input_params: SetUpandRunFunctionInput,
path_registry: PathRegistry,
final: bool,
save: bool,
sim_id: str,
pdb_id: str,
):
self.params = input_params
self.final = final
self.save = save
self.sim_id = sim_id
self.pdb_id = pdb_id
self.int_params = self.params.get("integrator_params", None)
Expand Down Expand Up @@ -736,7 +736,7 @@ def create_simulation(self):
self.simulation.context.setPositions(self.pdb.positions)

# TEMPORARY FILE MANAGEMENT OR PATH REGISTRY MAPPING
if self.final:
if self.save:
trajectory_name = self.path_registry.write_file_name(
type=FileType.RECORD,
record_type="TRAJ",
Expand Down Expand Up @@ -1066,7 +1066,7 @@ def run(self):
self.simulation.currentStep = 0
self.simulation.step(self.sim_params["Number of Steps"])
print("Done!")
if not self.final:
if not self.save:
if os.path.exists("temp_trajectory.dcd"):
os.remove("temp_trajectory.dcd")
if os.path.exists("temp_log.txt"):
Expand Down Expand Up @@ -1110,12 +1110,12 @@ def _run(self, **input_args):
print("whoops no pdb_id found in input,", input)
return "No pdb_id found in input"
try:
final = input["final"] # either this simulation
# the final one or not for this system
save = input["save"] # either this simulation
# to save or not the output files from this simulation
except KeyError:
final = False
save = True
print(
"No 'final' key found in input, setting to False. "
"No 'save' key found in input, setting to True. "
"Record files will be deleted after script is written."
)
try:
Expand All @@ -1131,7 +1131,7 @@ def _run(self, **input_args):
return f"An exception was found trying to write the filenames: {str(e)}."
try:
Simulation = OpenMMSimulation(
input, self.path_registry, final, sim_id, pdb_id
input, self.path_registry, save, sim_id, pdb_id
)
print("simulation set!")
except ValueError as e:
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def _run(self, **input_args):
f"files/simulations/{file_name}",
f"Basic Simulation of Protein {pdb_id}",
)
if final:
if save:
records = Simulation.registry_records
# move record files to files/records/
print(os.listdir("."))
Expand Down Expand Up @@ -1603,9 +1603,9 @@ def check_system_params(cls, values):
if file not in FORCEFIELD_LIST:
error_msg += "The forcefield file is not present"

final = values.get("final", False)
if type(final) != bool:
error_msg += "final must be a boolean value"
save = values.get("final", False)
if type(save) != bool:
error_msg += "save must be a boolean value"

if error_msg != "":
return {
Expand All @@ -1615,7 +1615,7 @@ def check_system_params(cls, values):
values = {
"pdb_id": pdb_id,
"forcefield_files": forcefield_files,
"final": final,
"save": save,
"system_params": system_params,
"integrator_params": integrator_params,
"simmulation_params": simmulation_params,
Expand Down

0 comments on commit f9b19c8

Please sign in to comment.