Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
keisuke-yanagisawa committed Nov 4, 2023
1 parent bc72911 commit e19d9c6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion script/utilities/Bio/PDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -137,7 +138,7 @@ class PDBIOhelper():
"""

def __init__(self, path: str):
self.path = path
self.path = expandpath(path)
self.open()

def __enter__(self):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down
13 changes: 8 additions & 5 deletions script/utilities/executable/cpptraj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
}

Expand All @@ -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)):
Expand Down
2 changes: 2 additions & 0 deletions script/utilities/executable/parmchk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .execute import Command
from .. import const
from ..logger import logger
from ..util import expandpath


class Parmchk(object):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion script/utilities/executable/template/cpptraj_pmap.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
15 changes: 15 additions & 0 deletions script/utilities/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e19d9c6

Please sign in to comment.