Skip to content

Commit

Permalink
Bug records (#90)
Browse files Browse the repository at this point in the history
* fixing bug that made two record files or simulation files get the same ID
* change the location where records are mapped in setup and run, and improve the return statement
  • Loading branch information
Jgmedina95 authored Feb 21, 2024
1 parent 427624a commit 4498a76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
20 changes: 15 additions & 5 deletions mdagent/tools/base_tools/simulation_tools/setup_and_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,7 @@ def create_simulation(self):
Sim_id=self.sim_id,
term="txt",
)
traj_id = self.path_registry.get_fileid(trajectory_name, FileType.RECORD)
log_id = self.path_registry.get_fileid(log_name, FileType.RECORD)

traj_desc = (
f"Simulation trajectory for protein {self.pdb_id}"
f" and simulation {self.sim_id}"
Expand All @@ -801,8 +800,8 @@ def create_simulation(self):
)
)
self.registry_records = [
(traj_id, f"files/records/{trajectory_name}", traj_desc),
(log_id, f"files/records/{log_name}", log_desc),
("holder", f"files/records/{trajectory_name}", traj_desc),
("holder", f"files/records/{log_name}", log_desc),
]

# TODO add checkpoint too?
Expand Down Expand Up @@ -1237,8 +1236,19 @@ def _run(self, **input_args):
for record in records:
os.rename(record[1].split("/")[-1], f"{record[1]}")
for record in records:
record[0] = self.path_registry.get_fileid( # Step necessary here to
record[1].split("/")[-1], # avoid id being repeated
FileType.RECORD,
)
self.path_registry.map_path(*record)
return "Simulation done!"
return (
"Simulation done! \n Summary: \n"
"Record files written to files/records/ with IDs and descriptions: "
f"{[(record[0],record[2]) for record in records]}\n"
"Standalone script written to files/simulations/ with ID: "
f"{sim_id}.\n"
f"The initial topology file ID is top_{sim_id} saved in files/pdb/"
)
except Exception as e:
print(f"An exception was found: {str(e)}.")
return f"An exception was found trying to write the filenames: {str(e)}."
Expand Down
16 changes: 13 additions & 3 deletions mdagent/utils/path_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_fileid(self, file_name: str, type: FileType):
# Split the filename on underscores
parts, ending = file_name.split(".")
parts_list = parts.split("_")

current_ids = self.list_path_names()
# Extract the timestamp (assuming it's always in the second to last part)
timestamp_part = parts_list[-1]
# Get the last 6 digits of the timestamp
Expand All @@ -218,9 +218,19 @@ def get_fileid(self, file_name: str, type: FileType):
pdb_id = parts_list[0]
return pdb_id + "_" + timestamp_digits
if type == FileType.SIMULATION:
return "sim" + "_" + timestamp_digits
num = 0
sim_id = "sim" + f"{num}" + "_" + timestamp_digits
while sim_id in current_ids:
num += 1
sim_id = "sim" + f"{num}" + "_" + timestamp_digits
return sim_id
if type == FileType.RECORD:
return "rec" + "_" + timestamp_digits
num = 0
rec_id = "rec" + f"{num}" + "_" + timestamp_digits
while rec_id in current_ids:
num += 1
rec_id = "rec" + f"{num}" + "_" + timestamp_digits
return rec_id
if type == FileType.SOLVENT:
return parts + "_" + timestamp_digits

Expand Down

0 comments on commit 4498a76

Please sign in to comment.