Skip to content

Commit

Permalink
Merge pull request #81 from wiederm/stream_file
Browse files Browse the repository at this point in the history
read in str files
  • Loading branch information
JohannesKarwou authored Aug 8, 2022
2 parents 2d503aa + 352a22b commit 130b7c9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
20 changes: 19 additions & 1 deletion transformato/charmm_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
from transformato.constants import temperature, charmm_gpu
from openmm import unit
import os


class CharmmFactory:
Expand Down Expand Up @@ -65,7 +66,7 @@ def generate_CHARMM_production_files(self, env: str) -> str:
return charmm_production_script

@staticmethod
def build_reduced_toppar(tlc: str) -> str:
def build_reduced_toppar(tlc: str, charmm_gui_base :str) -> str:
date = datetime.date.today()
toppar = f"""* Simplified toppar script
* Version from {date}
Expand Down Expand Up @@ -168,8 +169,11 @@ def build_reduced_toppar(tlc: str) -> str:
! Additional topologies and parameters for spin/fluorophore labels
stream ../../toppar/toppar_all36_label_spin.str
stream ../../toppar/toppar_all36_label_fluorophore.str
"""


if os.path.isfile(f"{charmm_gui_base}/waterbox/{tlc.lower()}/{tlc.lower()}_g.rtf"):
toppar += f"""
! Read {tlc} RTF
open read unit 10 card name {tlc}_g.rtf
read rtf card unit 10 append
Expand All @@ -185,8 +189,22 @@ def build_reduced_toppar(tlc: str) -> str:
! Read dummy_atom prm
open read unit 10 card name dummy_parameters.prm
read para card unit 10 append flex
"""
else:
toppar += f"""
! Read {tlc} STR
stream {tlc}.str
read para card unit 10 append flex
! Read dummy_atom RTF
open read unit 10 card name dummy_atom_definitions.rtf
read rtf card unit 10 append
! Read dummy_atom prm
open read unit 10 card name dummy_parameters.prm
read para card unit 10 append flex
"""

return toppar

def _get_CHARMM_production_header(self, env: str) -> str:
Expand Down
27 changes: 24 additions & 3 deletions transformato/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@ def _copy_ligand_specific_top_and_par(
toppar_target = f"{intermediate_state_file_path}/{self.system.tlc.lower()}.prm"
shutil.copyfile(ligand_prm, toppar_target)

def _copy_ligand_specific_str(
self, basedir: str, intermediate_state_file_path: str
):

# copy ligand rtf file
ligand_rtf = f"{basedir}/waterbox/{self.system.tlc.lower()}/{self.system.tlc.lower()}.str"
toppar_target = (f"{intermediate_state_file_path}/{self.system.tlc.lower()}.str")
shutil.copyfile(ligand_rtf, toppar_target)

def _copy_crd_file(self, intermediate_state_file_path: str):

basedir = self.system.charmm_gui_base
Expand All @@ -538,7 +547,12 @@ def _copy_files(self, intermediate_state_file_path: str):

basedir = self.system.charmm_gui_base

self._copy_ligand_specific_top_and_par(basedir, intermediate_state_file_path)
try:
self._copy_ligand_specific_top_and_par(basedir, intermediate_state_file_path)
except:
self._copy_ligand_specific_str(basedir, intermediate_state_file_path)



# copy crd file
self._copy_crd_file((intermediate_state_file_path))
Expand Down Expand Up @@ -964,10 +978,17 @@ def _write_toppar_str(self, output_file_base):
../../toppar/toppar_all36_lipid_model.str
../../toppar/toppar_all36_lipid_prot.str
../../toppar/toppar_all36_lipid_sphingo.str
{self.system.tlc.lower()}_g.rtf
"""
if os.path.isfile(f"{self.system.charmm_gui_base}/waterbox/{self.system.tlc.lower()}/{self.system.tlc.lower()}_g.rtf"):
toppar_format += f"""{self.system.tlc.lower()}_g.rtf
{self.system.tlc.lower()}.prm
dummy_atom_definitions.rtf
dummy_parameters.prm
"""
else:
toppar_format += f"""{self.system.tlc.lower()}.str
dummy_atom_definitions.rtf
dummy_parameters.prm
"""

f = open(f"{output_file_base}/toppar.str", "w+")
Expand All @@ -976,7 +997,7 @@ def _write_toppar_str(self, output_file_base):

# write charmm_toppar.str
charmm_toppar = self.charmm_factory.build_reduced_toppar(
self.system.tlc.lower()
self.system.tlc.lower(), self.system.charmm_gui_base
)

f = open(f"{output_file_base}/charmm_toppar.str", "w+")
Expand Down
3 changes: 2 additions & 1 deletion transformato/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ def _read_parameters(self, env: str) -> pm.charmm.CharmmParameterSet:
parameter_files = tuple()
l1 = f"{charmm_gui_env}/{tlc_lower}/{tlc_lower}.rtf"
l2 = f"{charmm_gui_env}/{tlc_lower}/{tlc_lower}.prm"
l3 = f"{charmm_gui_env}/{tlc_lower}/{tlc_lower}.str"

for file_path in [l1, l2]:
for file_path in [l1, l2, l3]:
if os.path.isfile(file_path):
parameter_files += (file_path,)
else:
Expand Down

0 comments on commit 130b7c9

Please sign in to comment.