From 352a22b7b85de156fe0f1b0560d43fe4fa72913f Mon Sep 17 00:00:00 2001 From: JohannesKarwou Date: Mon, 1 Aug 2022 15:38:01 +0200 Subject: [PATCH] giving the option of readint in str files --- transformato/charmm_factory.py | 20 +++++++++++++++++++- transformato/state.py | 27 ++++++++++++++++++++++++--- transformato/system.py | 3 ++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/transformato/charmm_factory.py b/transformato/charmm_factory.py index 44e66a9b..d6760224 100644 --- a/transformato/charmm_factory.py +++ b/transformato/charmm_factory.py @@ -1,6 +1,7 @@ import datetime from transformato.constants import temperature, charmm_gpu from openmm import unit +import os class CharmmFactory: @@ -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} @@ -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 @@ -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: diff --git a/transformato/state.py b/transformato/state.py index 990bd3d2..12ced72c 100644 --- a/transformato/state.py +++ b/transformato/state.py @@ -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 @@ -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)) @@ -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+") @@ -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+") diff --git a/transformato/system.py b/transformato/system.py index a42549b5..a5ff0b7e 100644 --- a/transformato/system.py +++ b/transformato/system.py @@ -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: