Skip to content

Commit

Permalink
Bug at naming clean files (CleanPDB tool). It was taking the whole fi…
Browse files Browse the repository at this point in the history
…le name instead of just the protein identifier making the name longer. 2. Adding some printing statements for clarity in case of errors for the user. 3. Fix registry of the path of packed structures. It mapped them originally when they where at the root directory and then moved the file to the files/pdb directory. Next calls of the file was failing because of this
  • Loading branch information
Jgmedina95 committed Feb 1, 2024
1 parent f2cda4f commit 72fb134
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mdagent/tools/base_tools/preprocess_tools/clean_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def _run(self, **input_args) -> str:
file_mode = "w" if add_hydrogens else "a"
file_name = self.path_registry.write_file_name(
type=FileType.PROTEIN,
protein_name=name,
protein_name=name.split("_")[0],
description="Clean",
file_format=end,
)
Expand Down
12 changes: 9 additions & 3 deletions mdagent/tools/base_tools/preprocess_tools/pdb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def validate_pdb_format(fhandle):
- 1 if error was found, 0 if no errors were found.
- List of error messages encountered.
"""
# check if filename is in directory
if not os.path.exists(fhandle):
return (1, ["File not found. Packmol failed to write the file."])
errors = []
_fmt_check = (
("Atm. Num.", (slice(6, 11), re.compile(r"[\d\s]+"))),
Expand Down Expand Up @@ -160,7 +163,7 @@ def _make_pointer(column):
if not line:
continue

if line[0:6] in ("ATOM ", "HETATM"):
if line[0:6] in ["ATOM ", "HETATM"]:
# ... [rest of the code unchanged here]
linelen = len(line)
if linelen < 80:
Expand Down Expand Up @@ -338,10 +341,12 @@ def run_packmol(self, PathRegistry):
cmd = "packmol < packmol.inp"
result = subprocess.run(cmd, shell=True, text=True, capture_output=True)
if result.returncode != 0:
print("Packmol failed to run with 'packmol < packmol.inp' command")
result = subprocess.run(
"./" + cmd, shell=True, text=True, capture_output=True
)
if result.returncode != 0:
print("Packmol failed to run with './packmol < packmol.inp' command")
return (
"Packmol failed to run. Please check the input file and try again."
)
Expand All @@ -355,13 +360,13 @@ def run_packmol(self, PathRegistry):
os.remove(molecule.filename)
# name of packed pdb file
time_stamp = PathRegistry.get_timestamp()[-6:]
os.rename(self.final_name, f"files/pdb/{self.final_name}")
PathRegistry.map_path(
f"PACKED_{time_stamp}",
f"{self.final_name}",
f"files/pdb/{self.final_name}",
self.file_description,
)
# move file to files/pdb
os.rename(self.final_name, f"files/pdb/{self.final_name}")
return f"PDB file validated successfully. FileID: PACKED_{time_stamp}"
elif pdb_validation[0] == 1:
# format pdb_validation[1] list of errors
Expand Down Expand Up @@ -486,6 +491,7 @@ def _run(self, **values) -> str:
"./" + cmd, shell=True, text=True, capture_output=True
)
if result.returncode != 0:
print("Packmol is not installed")
return (
"Packmol is not installed. Please install packmol "
"at 'https://m3g.github.io/packmol/download.shtml' and try again."
Expand Down

0 comments on commit 72fb134

Please sign in to comment.