From e19d9c6f0ca4aa0fad00618b54e60b55509efe67 Mon Sep 17 00:00:00 2001 From: Keisuke Yanagisawa Date: Sat, 4 Nov 2023 19:46:16 +0900 Subject: [PATCH] update --- script/utilities/Bio/PDB.py | 5 ++++- script/utilities/executable/cpptraj.py | 13 ++++++++----- script/utilities/executable/parmchk.py | 2 ++ .../utilities/executable/template/cpptraj_pmap.in | 2 +- script/utilities/util.py | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/script/utilities/Bio/PDB.py b/script/utilities/Bio/PDB.py index ca4aedf..d24845e 100644 --- a/script/utilities/Bio/PDB.py +++ b/script/utilities/Bio/PDB.py @@ -23,6 +23,7 @@ from Bio.PDB.Structure import Structure import numpy.typing as npt from ..scipy.spatial_func import estimate_volume +from ..util import expandpath class AtomSelector(PDB.Select): @@ -137,7 +138,7 @@ class PDBIOhelper(): """ def __init__(self, path: str): - self.path = path + self.path = expandpath(path) self.open() def __enter__(self): @@ -197,6 +198,7 @@ def get_structure(filepath: str, structname="") -> Structure: Bio.PDB.Structure Structure object of the PDB file """ + filepath = expandpath(filepath) if filepath.endswith(".gz"): fileobj = gzip.open(filepath, "rt") else: @@ -414,6 +416,7 @@ def save(structs, path) -> None: structs : Bio.PDB.Struct or list of Bio.PDB.Struct path : str """ + path = expandpath(path) if not isinstance(structs, Iterable): structs = [structs] diff --git a/script/utilities/executable/cpptraj.py b/script/utilities/executable/cpptraj.py index 1de10d3..47f424d 100644 --- a/script/utilities/executable/cpptraj.py +++ b/script/utilities/executable/cpptraj.py @@ -43,7 +43,7 @@ def run(self, basedir, prefix, box_center=[0., 0., 0.], box_size=80, interval=1, self._gen_parm7() _, self.inp = tempfile.mkstemp(prefix=const.TMP_PREFIX, suffix=const.EXT_INP) - _, tmp_rmsdfile = tempfile.mkstemp(suffix=".dat") + rmsdfile = "rmsd.dat" _, tmp_volumefile = tempfile.mkstemp(suffix=".dat") data = { @@ -56,7 +56,7 @@ def run(self, basedir, prefix, box_center=[0., 0., 0.], box_size=80, interval=1, "map_voxel": " ".join([str(n) for n in self.voxel]) + " gridcenter " + " ".join([str(x) for x in box_center]), "prefix": self.prefix, "maps": maps, - "tmp_rmsdfile": tmp_rmsdfile, + "rmsdfile": rmsdfile, "tmp_volumefile": tmp_volumefile, } @@ -67,13 +67,16 @@ def run(self, basedir, prefix, box_center=[0., 0., 0.], box_size=80, interval=1, logger.info(template.render(data)) command = Command(f"{self.exe} < {self.inp}") logger.debug(command) - logger.info(command.run()) + try: + logger.info(command.run()) + except e: + Command(f"cat {self.inp}") + raise e for i in range(len(maps)): maps[i]["grid"] = f"{self.basedir}/{self.prefix}_{maps[i]['suffix']}.dx" - self.frames = len(open(tmp_rmsdfile).readlines()) - 1 # -1 for header line - os.system(f"rm {tmp_rmsdfile}") + self.frames = len(open(rmsdfile).readlines()) - 1 # -1 for header line self.last_volume = float(open(tmp_volumefile).readlines()[-1].split()[1]) os.system(f"rm {tmp_volumefile}") for i in range(len(maps)): diff --git a/script/utilities/executable/parmchk.py b/script/utilities/executable/parmchk.py index 273bbb0..bd38cb6 100644 --- a/script/utilities/executable/parmchk.py +++ b/script/utilities/executable/parmchk.py @@ -3,6 +3,7 @@ from .execute import Command from .. import const from ..logger import logger +from ..util import expandpath class Parmchk(object): @@ -12,6 +13,7 @@ def __init__(self, debug=False): self.debug = debug def set(self, mol2, at): + mol2 = expandpath(mol2) if at not in self.at_indices: raise ValueError(f"atomtype {at} is not supported") if not os.path.exists(mol2): diff --git a/script/utilities/executable/template/cpptraj_pmap.in b/script/utilities/executable/template/cpptraj_pmap.in index c93a25b..6ada142 100644 --- a/script/utilities/executable/template/cpptraj_pmap.in +++ b/script/utilities/executable/template/cpptraj_pmap.in @@ -10,7 +10,7 @@ center @CA&(!:CA)&(!:{{ cid }}) fiximagedbonds autoimage -rms ToREF ref [REF] @CA&(!:CA)&(!:{{ cid }}) @CA&(!:CA)&(!:{{ cid }}) out {{ tmp_rmsdfile }} +rms ToREF ref [REF] @CA&(!:CA)&(!:{{ cid }}) @CA&(!:CA)&(!:{{ cid }}) out {{ basedir }}/{{ rmsdfile }} {% for MAP in maps %} grid {{ basedir }}/{{ prefix }}_{{ MAP.suffix }}.dx {{ map_voxel }} :{{ cid }}&{{ MAP.selector }} diff --git a/script/utilities/util.py b/script/utilities/util.py index c36da9b..4589b7c 100644 --- a/script/utilities/util.py +++ b/script/utilities/util.py @@ -132,17 +132,32 @@ def parse_yaml(yamlpath: str) -> dict: setting["input"]["probe"]["pdb"] \ = setting["input"]["probe"]["cid"] + ".pdb" + setting["general"]["workdir"] = expandpath(setting["general"]["workdir"]) setting["general"]["workdir"] = setting["general"]["workdir"] \ if setting["general"]["workdir"].startswith("/") \ + or setting["general"]["workdir"].startswith("$HOME") \ + or setting["general"]["workdir"].startswith("~") \ else YAML_DIR_PATH + "/" + setting["general"]["workdir"] + + setting["input"]["protein"]["pdb"] = expandpath(setting["input"]["protein"]["pdb"]) setting["input"]["protein"]["pdb"] = setting["input"]["protein"]["pdb"] \ if setting["input"]["protein"]["pdb"].startswith("/") \ + or setting["input"]["protein"]["pdb"].startswith("$HOME") \ + or setting["input"]["protein"]["pdb"].startswith("~") \ else YAML_DIR_PATH + "/" + setting["input"]["protein"]["pdb"] + + setting["input"]["probe"]["pdb"] = expandpath(setting["input"]["probe"]["pdb"]) setting["input"]["probe"]["pdb"] = setting["input"]["probe"]["pdb"] \ if setting["input"]["probe"]["pdb"].startswith("/") \ + or setting["input"]["probe"]["pdb"].startswith("$HOME") \ + or setting["input"]["probe"]["pdb"].startswith("~") \ else YAML_DIR_PATH + "/" + setting["input"]["probe"]["pdb"] + + setting["input"]["probe"]["mol2"] = expandpath(setting["input"]["probe"]["mol2"]) setting["input"]["probe"]["mol2"] = setting["input"]["probe"]["mol2"] \ if setting["input"]["probe"]["mol2"].startswith("/") \ + or setting["input"]["probe"]["mol2"].startswith("$HOME") \ + or setting["input"]["probe"]["mol2"].startswith("~") \ else YAML_DIR_PATH + "/" + setting["input"]["probe"]["mol2"] if setting["input"]["protein"]["ssbond"] is None: