Skip to content

Commit

Permalink
enabled TIP3P mixed solvent
Browse files Browse the repository at this point in the history
  • Loading branch information
fangning-ren committed Jul 2, 2024
1 parent 302930b commit 0526d93
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 114 deletions.
4 changes: 2 additions & 2 deletions autosolvate/autosolvate.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def __init__(self,
]

def get_solvent(self, solvent:str, slv_xyz:str = "", solvent_frcmod:str = "", solvent_off:str = "", slv_generate:bool = False, slv_count:int = 210*8, solvent_box_name:str = "SLVBOX"):
if solvent in AMBER_SOLVENT_DICT:
if solvent in AMBER_SOLVENTBOX_DICT:
# amber solvents
self_solvent = AMBER_SOLVENT_DICT[solvent]
self_solvent = AMBER_SOLVENTBOX_DICT[solvent]
elif solvent in custom_solv_dict:
# solvent data prepared by autosolvate
solvPrefix = custom_solv_dict[solvent]
Expand Down
2 changes: 1 addition & 1 deletion autosolvate/data/ch3cn/ch3cn.xyz
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
6
/home/fren5/AutoSolvae-update/AutoSolvate/autosolvate/data/ch3cn/ch3cn.pdb
/home/fren5/AutoSolvate-update/AutoSolvate/autosolvate/data/ch3cn/ch3cn.pdb
N 14.18200 11.28800 13.72000
C 13.67300 12.18800 13.29900
C 13.15300 13.38300 12.69800
Expand Down
13 changes: 13 additions & 0 deletions autosolvate/dockers/_tleap_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def __init__(self,
##### check_system method for different systems
def check_system_molecule(self, mol:Molecule):
self.logger.info("Checking system {:s}...".format(mol.name))
if mol.amber_solvent:
self.logger.info("This is a predefined AMBER solvent.")
if mol.name == "water":
self.logger.info(f"Using TIP3P water model with predefined residue name {mol.residue_name}")
else:
self.logger.info("Solvent prep file: {:s}".format(mol.prep))
self.logger.info("Solvent frcmod file: {:s}".format(mol.frcmod))
return

suffixs = ["mol2", "lib", "prep", "off"]
suffixf = [0, 0, 0, 0]
for i, suffix in enumerate(suffixs):
Expand Down Expand Up @@ -199,6 +208,10 @@ def load_solvent_box(self,
mol: SolventBox,
check: bool = False
) -> None:
if mol.amber_solvent:
doc.write('{:<5} {} \n'.format("loadamberparams", mol.frcmod))
return

if mol.check_exist("off"):
doc.write('{:<5} {} \n'.format("loadoff", mol.off))
if mol.check_exist("lib"):
Expand Down
83 changes: 77 additions & 6 deletions autosolvate/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def __init__(
name = "",
residue_name = "MOL",
folder = WORKING_DIR,
amber_solvent = False,
) -> None:
"""
The data class for holding all files of a molecule.
Expand All @@ -243,32 +244,102 @@ def __init__(
The residue name of the molecule, by default "MOL".
folder : str, optional
The folder to store all files of the molecule, by default is the current working directory.
amber_solvent : bool, optional
A flag to indicate whether the molecule will use amber predefined parameters, by default False.
"""

self.name = process_system_name(name, xyzfile, support_input_format=Molecule._SUPPORT_INPUT_FORMATS)
self.folder = os.path.abspath(folder)
self.charge = charge
self.multiplicity = multiplicity
self.spinmult = multiplicity
self.residue_name = residue_name
self.number = 0
self.read_coordinate(xyzfile)
self.amber_solvent = amber_solvent
self.name = name
super(Molecule, self).__init__(name = self.name)
self.logger.name = self.__class__.__name__
# super(Molecule, self).__post_init__()

if not self.amber_solvent:
self.name = process_system_name(name, xyzfile, support_input_format=Molecule._SUPPORT_INPUT_FORMATS)
self.read_coordinate(xyzfile)

def read_coordinate(self, fname:str):
ext = os.path.splitext(fname)[-1][1:]
setattr(self, ext, fname)
for e in Molecule._SUPPORT_INPUT_FORMATS:
if e == ext:
continue
nname = os.path.splitext(fname)[0] + "." + e
subprocess.run(f"obabel -i {ext} {fname} -o {e} -O {nname} ---errorlevel 0", shell = True)
setattr(self, e, nname)
newpath = self.reference_name + "." + e
subprocess.run(f"obabel -i {ext} {fname} -o {e} -O {newpath} ---errorlevel 0", shell = True)
setattr(self, e, newpath)

def generate_pdb(self):
if not self.check_exist("pdb") and self.name != "water":
prep2pdb4amber_solvent(self)
self.logger.info(f"AMBER predefined solvent {self.name} is used.")
self.logger.info(f"Converted the predefined prep file {self.prep} to pdb file {self.pdb}")
elif self.name == "water":
assign_water_pdb(self)
self.logger.info(f"AMBER predefined water is used.")
self.logger.info(f"Write the reference pdb file for {self.name} to {self.pdb}")
self.logger.info(f"Water model used: TIP3P")

def update(self):
if not self.amber_solvent:
super(Molecule, self).update()



# if one want to use other water forcefield, one may need to change the residue name of water to other, such as PL3 for POL3 model.
AMBER_WATER = Molecule(name = "water",
xyzfile = None,
charge = 0,
multiplicity = 1,
residue_name = "WAT",
folder = WORKING_DIR,
amber_solvent = True,
)

AMBER_METHANOL = Molecule(name = "methanol",
xyzfile = None,
charge = 0,
multiplicity = 1,
residue_name = "MOH",
folder = WORKING_DIR,
amber_solvent = True,
)
AMBER_METHANOL.frcmod = "frcmod.meoh"
AMBER_METHANOL.prep = "meoh.in"

AMBER_CHLOROFORM = Molecule(name = "chloroform",
xyzfile = None,
charge = 0,
multiplicity = 1,
residue_name = "CL3",
folder = WORKING_DIR,
amber_solvent = True,
)
AMBER_CHLOROFORM.frcmod = "frcmod.chcl3"
AMBER_CHLOROFORM.prep = "chcl3.in"

AMBER_NMA = Molecule(name = "nma",
xyzfile = None,
charge = 0,
multiplicity = 1,
residue_name = "NMA",
folder = WORKING_DIR,
amber_solvent = True,
)
AMBER_NMA.frcmod = "frcmod.nma"
AMBER_NMA.prep = "nma.in"

AMBER_SOLVENT_LIST = [AMBER_WATER, AMBER_METHANOL, AMBER_CHLOROFORM, AMBER_NMA]
AMBER_SOLVENT_DICT = {
AMBER_WATER.name: AMBER_WATER,
AMBER_METHANOL.name: AMBER_METHANOL,
AMBER_CHLOROFORM.name: AMBER_CHLOROFORM,
AMBER_NMA.name: AMBER_NMA,
}

if __name__ == "__main__":
pass
83 changes: 47 additions & 36 deletions autosolvate/molecule/solventbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ def __init__(self,
"""
self.name = process_system_name(name, solventbox, support_input_format=SolventBox._SUPPORT_INPUT_FORMATS, check_exist = False if amber_solvent else True)
self.folder = os.path.abspath(folder)
self.frcmod = os.path.abspath(frcmod)
self.box_name = box_name
self.amber_solvent = amber_solvent
self.solventbox = os.path.abspath(solventbox)

if not amber_solvent:
self.frcmod = os.path.abspath(frcmod)
self.solventbox = os.path.abspath(solventbox)

if not os.path.exists(solventbox):
logger.error("The pre-built solvent box file {} does not exist".format(solventbox))
raise FileNotFoundError("The solvent box file does not exist")
Expand All @@ -65,7 +66,9 @@ def __init__(self,
self.box_name = self.get_box_name(self.solventbox)
self.solventbox = getattr(self, ext)
else:
pass
self.solventbox = solventbox
self.frcmod = frcmod

super(SolventBox, self).__init__(name = self.name)
self.logger.name = self.__class__.__name__

Expand All @@ -86,38 +89,46 @@ def get_box_name(self, fname:str):
break
return previousname

AMBER_WATER = SolventBox( name='water',
solventbox='solvents.lib',
box_name='TIP3PBOX',
amber_solvent = True
)

AMBER_METHANOL = SolventBox( name='methanol',
solventbox='solvents.lib',
frcmod="frcmod.meoh",
box_name='MEOHBOX',
amber_solvent = True
)

AMBER_CHLOROFORM = SolventBox(name='chloroform',
solventbox='solvents.lib',
frcmod="frcmod.chcl3",
box_name='CHCL3BOX',
amber_solvent = True
)

AMBER_NMA = SolventBox(name='nma',
solventbox='solvents.lib',
frcmod="frcmod.nma",
box_name='NMABOX',
amber_solvent = True
)
def update(self):
# override the original update method for default system as some parameter for solvent box are predefined then cannot be updated
if self.amber_solvent:
return
super().update()

AMBER_SOLVENT_LIST = [AMBER_WATER, AMBER_METHANOL, AMBER_CHLOROFORM, AMBER_NMA]
AMBER_SOLVENT_DICT = {
AMBER_WATER.name :AMBER_WATER,
AMBER_METHANOL.name :AMBER_METHANOL,
AMBER_CHLOROFORM.name :AMBER_CHLOROFORM,
AMBER_NMA.name :AMBER_NMA,
# available name for pre-equilibrated water box includes:
# POL3BOX, QSPCFWBOX, SPCBOX, SPCFWBOX, TIP3PBOX, TIP3PFBOX, TIP4PBOX, TIP4PEWBOX, OPCBOX, OPC3BOX, TIP5PBOX
AMBER_WATER_BOX = SolventBox(name='water',
solventbox='solvents.lib',
box_name='TIP3PBOX',
amber_solvent=True
)

AMBER_METHANOL_BOX = SolventBox(name='methanol',
solventbox='solvents.lib',
frcmod="frcmod.meoh",
box_name='MEOHBOX',
amber_solvent=True
)

AMBER_CHLOROFORM_BOX = SolventBox(name='chloroform',
solventbox='solvents.lib',
frcmod="frcmod.chcl3",
box_name='CHCL3BOX',
amber_solvent=True
)

AMBER_NMA_BOX = SolventBox(name='nma',
solventbox='solvents.lib',
frcmod="frcmod.nma",
box_name='NMABOX',
amber_solvent=True
)

AMBER_SOLVENTBOX_LIST = [AMBER_WATER_BOX, AMBER_METHANOL_BOX, AMBER_CHLOROFORM_BOX, AMBER_NMA_BOX]
AMBER_SOLVENTBOX_DICT = {
AMBER_WATER_BOX.name : AMBER_WATER_BOX,
AMBER_METHANOL_BOX.name : AMBER_METHANOL_BOX,
AMBER_CHLOROFORM_BOX.name : AMBER_CHLOROFORM_BOX,
AMBER_NMA_BOX.name : AMBER_NMA_BOX,
}
logging.basicConfig(level = INFO, force = True, handlers=[])
logging.basicConfig(level=INFO, force=True, handlers=[])
Loading

0 comments on commit 0526d93

Please sign in to comment.