Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for neutral point mutation #98

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3a27d07
improving parametr handling
JohannesKarwou Nov 15, 2022
2ec0e83
Fix code style issues with Black
lint-action Nov 15, 2022
ea374e9
supporting a first point mutation
JohannesKarwou Nov 15, 2022
ca092bb
Fix code style issues with Black
lint-action Nov 15, 2022
dc19d70
setting NGRP section to zero
JohannesKarwou Nov 15, 2022
f647c16
Merge branch 'support_point_mutation' of github.com:wiederm/transform…
JohannesKarwou Nov 15, 2022
4763c89
Fix code style issues with Black
lint-action Nov 15, 2022
8d9c0ca
minor comments
JohannesKarwou Nov 15, 2022
5745122
Merge branch 'support_point_mutation' of github.com:wiederm/transform…
JohannesKarwou Nov 15, 2022
d1d06e8
paramters which are used by tf are now written out to toppar.st
JohannesKarwou Nov 16, 2022
d0b390e
Merge branch 'parameter_handling' of github.com:wiederm/transformato …
JohannesKarwou Nov 16, 2022
99fe889
Fix code style issues with Black
lint-action Nov 16, 2022
bc0908f
removing ligand1 and ligand2 from parameterset
JohannesKarwou Nov 16, 2022
bcbafc3
Fix code style issues with Black
lint-action Nov 16, 2022
19a022c
extending function to work with asfe
JohannesKarwou Nov 17, 2022
c657551
strange merge conflict
JohannesKarwou Nov 17, 2022
04a2beb
assure that only chain A is mutated
JohannesKarwou Nov 25, 2022
87c5850
Fix code style issues with Black
lint-action Nov 25, 2022
89ae17f
Merge branch 'support_point_mutation' into parameter_handling
JohannesKarwou Nov 27, 2022
33e4d6a
Fix code style issues with Black
lint-action Nov 27, 2022
96b5ab9
Merge pull request #100 from wiederm/parameter_handling
JohannesKarwou Nov 27, 2022
d0123f0
consider empty tlc for s2
JohannesKarwou Nov 27, 2022
d3c724b
Fix code style issues with Black
lint-action Nov 27, 2022
559f0c9
remove unnecessary print statements
JohannesKarwou Nov 28, 2022
a19eda0
comments + way of copying ligand specific files if necessary
JohannesKarwou Nov 28, 2022
aa1f3a0
Fix code style issues with Black
lint-action Nov 28, 2022
575ed84
automatic common core transformation
JohannesKarwou Nov 29, 2022
d821c88
Fix code style issues with Black
lint-action Nov 29, 2022
0380568
create again corrected psf for the tests
JohannesKarwou Nov 29, 2022
4d94b82
Merge branch 'support_point_mutation' of github.com:wiederm/transform…
JohannesKarwou Nov 29, 2022
a536d96
Update mutate.py
JohannesKarwou Jan 13, 2023
92168a6
Update system.py
JohannesKarwou Jan 13, 2023
2915b8c
Fix code style issues with Black
lint-action Jan 13, 2023
5fb7353
Update mutate.py
JohannesKarwou Jan 16, 2023
65bcaba
Fix code style issues with Black
lint-action Jan 16, 2023
bd3a580
handling of different residue names
JohannesKarwou Jan 16, 2023
bdc06b5
Fix code style issues with Black
lint-action Jan 16, 2023
aced89e
avoid parameter changes for dummy atoms in last step
JohannesKarwou Jan 27, 2023
8040e2b
Fix code style issues with Black
lint-action Jan 27, 2023
bd2abe9
remove redundant and statement
JohannesKarwou Jan 30, 2023
f7cc923
Merge branch 'support_point_mutation' of github.com:wiederm/transform…
JohannesKarwou Jan 30, 2023
10793e7
remove unnecessary and statement
JohannesKarwou Jan 30, 2023
e7587ec
compare only within tlc of mutation
JohannesKarwou May 17, 2023
3acaaff
adding addtional toppar file for modified nucleobases
JohannesKarwou May 25, 2023
58191de
Merge branch 'master' into support_point_mutation
JohannesKarwou May 25, 2023
5221929
Fix code style issues with Black
lint-action May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 102 additions & 13 deletions transformato/mutate.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ def __init__(
self.dummy_region_cc2: DummyRegion

self.asfe: bool = False
self._check_cgenff_versions()

except:
# self._check_cgenff_versions()

except AttributeError:
logger.info(
"Only information about one structure, assume an ASFE simulation is requested"
)

mol1_name: str = "m1"
self.system: dict = {"system1": s1}
self.mols: dict = {mol1_name: s1.mol}
Expand Down Expand Up @@ -602,10 +602,9 @@ def _check_for_lp(
]
lp_dict_dummy_region = defaultdict(list)
lp_dict_common_core = defaultdict(list)
print(f"die version {pm.__version__}")

for atom in psf.view[f":{tlc}"].atoms:
if atom.name.find("LP") == False:
print(f"die Atome {atom}")
if atom.frame_type.atom1.idx in flat_ordered_connected_dummy_regions:
lp_dict_dummy_region[atom.frame_type.atom1.idx].append(atom.idx)

Expand Down Expand Up @@ -1222,8 +1221,8 @@ def _transform_common_core(self) -> list:
logger.warning(f"Charge parameters mutation: {charge_mutation}.")

t = CommonCoreTransformation(
self.get_common_core_idx_mol1() + self.dummy_region_cc1.lj_default,
self.get_common_core_idx_mol2() + self.dummy_region_cc2.lj_default,
self.get_common_core_idx_mol1(),
self.get_common_core_idx_mol2(),
self.psfs["m1"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we can remove the self.dummy_region_cc1.lj_default variable, but in my opinion I think it's not necessary since this atom (the lj default atom) is not part of the common core anymore and thus can vary between different ligands

self.psfs["m2"],
self.s1_tlc,
Expand Down Expand Up @@ -1458,8 +1457,55 @@ def _get_atom_mapping(self) -> dict:
cc_names_struc1.append(ligand1_atom.name)
cc_names_struc2.append(ligand2_atom.name)

print(f"CC Struc1: {cc_names_struc1}")
print(f"CC Struc2: {cc_names_struc2}")
logger.info(f"CC Struc1: {cc_names_struc1}")
logger.info(f"CC Struc2: {cc_names_struc2}")

### DANGER ONLY FOR ONE MUTATION NEEEDS TO BE FIXED #####
# match_atom_names_cc1_to_cc2 = {
# "O5'": "O5'",
# "H5T": "H5T",
# "C5'": "C5'",
# "H5''": "H5''",
# "H5'": "H5'",
# "C4'": "C4'",
# "H4'": "H4'",
# "O4'": "O4'",
# "C1'": "C1'",
# "C2'": "C2'",
# "C3'": "C3'",
# "H3'": "H3'",
# "O3'": "O3'",
# "P": "P",
# "O2P": "O2P",
# "O1P": "O1P",
# "H1'": "H1'",
# "H2''": "H2''",
# "O2'": "O2'",
# "H2'": "H2'",
# "N1": "N1",
# "C6": "C6",
# "H6": "H6",
# "C5": "C5",
# "H5": "H5",
# "C4": "C4",
# "N3": "N3",
# "C2": "C2",
# "O2": "O2",
# "N4": "N4",
# "H42": "H42",
# "H41": "H41",
# "N9": "N9",
# "N7": "N7",
# "C8": "C8",
# "H8": "H8",
# "N2": "N2",
# "H21": "H21",
# "H22": "H22",
# "H1": "H1",
# "O6": "O6",
# "H3T": "H3T",
# }

return match_atom_names_cc1_to_cc2

def _mutate_charges(self, psf: pm.charmm.CharmmPsfFile, scale: float):
Expand All @@ -1472,7 +1518,15 @@ def _mutate_charges(self, psf: pm.charmm.CharmmPsfFile, scale: float):

# compare to charge compenstated psf 2
for ligand2_atom in self.charge_compensated_ligand2_psf:
if self.atom_names_mapping[ligand1_atom.name] == ligand2_atom.name:
# Assure that only atoms from the same resdiue are compared, and only atoms belonging to the same chain!
if (
self.atom_names_mapping[ligand1_atom.name] == ligand2_atom.name
and ligand1_atom.residue.name == ligand2_atom.residue.name
and ligand1_atom.type == ligand2_atom.type
and len(ligand1_atom.residue.atoms)
== len(ligand2_atom.residue.atoms)
and ligand1_atom.residue.chain == ligand2_atom.residue.chain
):
found = True
# are the atoms different?
logger.debug(f"Modifying atom: {ligand1_atom}")
Expand All @@ -1488,7 +1542,34 @@ def _mutate_charges(self, psf: pm.charmm.CharmmPsfFile, scale: float):
ligand1_atom.charge = modified_charge

if not found:
raise RuntimeError("No corresponding atom in cc2 found")
try:
for ligand2_atom in self.charge_compensated_ligand2_psf:
# make sure resdiue PSU which is like CYT are nevertheless found
if (
self.atom_names_mapping[ligand1_atom.name]
== ligand2_atom.name
and len(ligand1_atom.residue.atoms)
== len(ligand2_atom.residue.atoms)
and ligand1_atom.residue.chain == ligand2_atom.residue.chain
):
found = True
# are the atoms different?
logger.debug(f"Modifying atom: {ligand1_atom}")
logger.debug(f"Template atom: {ligand2_atom}")

# scale epsilon
modified_charge = (
scale * ligand1_atom.charge
+ (1 - scale) * ligand2_atom.charge
)
logger.debug(
f"Current charge: {ligand1_atom.charge}; target charge: {ligand2_atom.charge}; modified charge: {modified_charge}"
)
ligand1_atom.charge = modified_charge
except:
raise RuntimeError(
f"No corresponding atom for {ligand1_atom} in cc2 found"
)

def _mutate_atoms(self, psf: pm.charmm.CharmmPsfFile, lambda_value: float):
"""
Expand Down Expand Up @@ -1516,8 +1597,10 @@ def _mutate_atoms(self, psf: pm.charmm.CharmmPsfFile, lambda_value: float):
# is there a match up?
if self.atom_names_mapping[ligand1_atom.name] == ligand2_atom.name:
found = True
# are the atoms different?
if ligand1_atom.type != ligand2_atom.type:
# are the atoms different? and assure that only atomtypes in the same residue are compared
if ligand1_atom.type != ligand2_atom.type and len(
ligand1_atom.residue.atoms
) == len(ligand2_atom.residue.atoms):
if "DDX" in ligand1_atom.type:
logger.warning(
"This is the terminal LJ atom. If everything went correct, this does not have to change atom types."
Expand Down Expand Up @@ -1845,6 +1928,9 @@ def _modify_type_in_cc(atom: pm.Atom, psf: pm.charmm.CharmmPsfFile):
if hasattr(atom, "initial_type"):
# only change parameters
pass
elif atom.residue.chain == "RNAB":
# only change parameters
pass
else:
logger.info(f"Setting RRR atomtype for atom: {atom}.")
atom.initial_type = atom.type
Expand Down Expand Up @@ -2045,6 +2131,9 @@ def _modify_type(atom, psf, atom_type_suffix: str):
if hasattr(atom, "initial_type"):
# only change parameters
pass
elif atom.residue.chain == "RNAB":
# only change parameters
pass
else:
atom.initial_type = atom.type
if atom_type_suffix == "DDD":
Expand Down
78 changes: 40 additions & 38 deletions transformato/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def write_state(
)

else:
# mutation_type.print_details()

logger.debug(f"Lambda electrostatics: {lambda_value_electrostatic}")
logger.debug(f"Lambda vdw: {lambda_value_vdw}")

Expand Down Expand Up @@ -628,12 +628,13 @@ def _copy_files(self, intermediate_state_file_path: str):

basedir = self.system.charmm_gui_base

try:
self._copy_ligand_specific_top_and_par(
basedir, intermediate_state_file_path
)
except:
self._copy_ligand_specific_str(basedir, intermediate_state_file_path)
if os.path.exists(f"{basedir}/waterbox/{self.system.tlc.lower()}/"):
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 @@ -1031,35 +1032,30 @@ def _init_base_dir(self):

def _write_toppar_str(self, output_file_base):

toppar_format = f"""
../../toppar/top_all36_prot.rtf
../../toppar/par_all36m_prot.prm
../../toppar/top_all36_na.rtf
../../toppar/par_all36_na.prm
../../toppar/top_all36_carb.rtf
../../toppar/par_all36_carb.prm
../../toppar/top_all36_lipid.rtf
../../toppar/par_all36_lipid.prm
../../toppar/top_all36_cgenff.rtf
../../toppar/par_all36_cgenff.prm
../../toppar/toppar_water_ions.str
../../toppar/toppar_dum_noble_gases.str
../../toppar/toppar_all36_prot_c36m_d_aminoacids.str
../../toppar/toppar_all36_prot_fluoro_alkanes.str
../../toppar/toppar_all36_prot_heme.str
../../toppar/toppar_all36_prot_na_combined.str
../../toppar/toppar_all36_prot_retinol.str
../../toppar/toppar_all36_na_nad_ppi.str
../../toppar/toppar_all36_lipid_bacterial.str
../../toppar/toppar_all36_lipid_cardiolipin.str
../../toppar/toppar_all36_lipid_cholesterol.str
../../toppar/toppar_all36_lipid_inositol.str
../../toppar/toppar_all36_lipid_lps.str
../../toppar/toppar_all36_lipid_miscellaneous.str
../../toppar/toppar_all36_lipid_model.str
../../toppar/toppar_all36_lipid_prot.str
../../toppar/toppar_all36_lipid_sphingo.str
"""
from transformato.system import parameter_files

base = "../../toppar"
toppar_format = ""
# Only necessary because the variable self.configuration["system"]["structure2"]["tlc"] gives a keyError for asfe
# since its not defined there
try:
if self.configuration["system"]["structure2"]["tlc"].lower():
struct2 = self.configuration["system"]["structure2"]["tlc"].lower()
else:
struct2 = "emptyString"

except KeyError:
struct2 = "emptyString"

for i in parameter_files:
# the parameterfiles for customized ligands are in another directory and are considered below
if self.configuration["system"]["structure1"]["tlc"].lower() in i:
pass
if struct2 in i:
pass
else:
toppar_format += f"{base}/{i.split('/')[-1]} \n"

if os.path.isfile(
f"{self.system.charmm_gui_base}/waterbox/{self.system.tlc.lower()}/{self.system.tlc.lower()}_g.rtf"
):
Expand All @@ -1068,10 +1064,16 @@ def _write_toppar_str(self, output_file_base):
dummy_atom_definitions.rtf
dummy_parameters.prm
"""
else:
elif os.path.isfile(
f"{self.system.charmm_gui_base}/waterbox/{self.system.tlc.lower()}/{self.system.tlc.lower()}.str"
):
toppar_format += f"""{self.system.tlc.lower()}.str
dummy_atom_definitions.rtf
dummy_parameters.prm
"""
else:
toppar_format += f"""dummy_atom_definitions.rtf
dummy_parameters.prm
"""

f = open(f"{output_file_base}/toppar.str", "w+")
Expand Down Expand Up @@ -1100,7 +1102,7 @@ def _write_psf(psf, output_file_base: str, env: str):
psf.write_psf(string_object)
# read in psf and correct some aspects of the file not suitable for CHARMM
corrected_psf = psf_correction(string_object)
with open(f"{output_file_base}/lig_in_{env}_corr.psf", "w+") as f:
with open(f"{output_file_base}/lig_in_{env}.psf", "w+") as f:
f.write(corrected_psf)
# write pdb
psf.write_pdb(f"{output_file_base}/lig_in_{env}.pdb")
Expand Down
Loading