Skip to content

Commit

Permalink
Update openmmdlsetup.py
Browse files Browse the repository at this point in the history
Adjusted with new sessions script and final amber scripts
  • Loading branch information
talagayev authored Aug 11, 2024
1 parent 2705bc8 commit 1119b6c
Showing 1 changed file with 9 additions and 161 deletions.
170 changes: 9 additions & 161 deletions openmmdl/openmmdl_setup/openmmdlsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import webbrowser
import zipfile

from openmmdl.openmmdl_setup.setup_options import SetupOptionsConfigurator
from openmmdl.openmmdl_setup.setup_options import SetupOptionsConfigurator, RequestSessionManager
from openmmdl.openmmdl_setup.configfile_creator import ConfigCreator
from openmmdl.openmmdl_setup.amberscript_creator import AmberScriptGenerator

Expand Down Expand Up @@ -235,19 +235,8 @@ def setAmberOptions():
saveUploadedFiles()

######## Add Water/Membrane ########
session["addType"] = request.form.get("addType", "")
session["boxType"] = request.form.get("boxType", "")
session["dist"] = request.form.get("dist", "")
session["lipid_tp"] = request.form.get("lipid_tp", "")
session["other_lipid_tp_input"] = request.form.get("other_lipid_tp_input", "")
session["lipid_ratio"] = request.form.get("lipid_ratio", "")
session["lipid_ff"] = request.form.get("lipid_ff", "")
session["dist2Border"] = request.form.get("dist2Border", "")
session["padDist"] = request.form.get("padDist", "")
session["water_ff"] = request.form.get("water_ff", "")
session["pos_ion"] = request.form.get("pos_ion", "")
session["neg_ion"] = request.form.get("neg_ion", "")
session["ionConc"] = request.form.get("ionConc", "")
form = request.form
session_manager = RequestSessionManager(form)

return createAmberBashScript()

Expand All @@ -269,31 +258,9 @@ def configureDefaultAmberOptions():

def createAmberBashScript():
a_script = []
a_script.append(
"# This script was generated by OpenMMDL-Setup on %s.\n" % datetime.date.today()
)
a_script.append(
"""
# ,-----. .-------. .-''-. ,---. .--.,---. ,---.,---. ,---. ______ .---.
# .' .-, '. \ _(`)_ \ .'_ _ \ | \ | || \ / || \ / || _ `''. | ,_|
# / ,-.| \ _ \ | (_ o._)| / ( ` ) '| , \ | || , \/ , || , \/ , || _ | ) _ \,-./ )
# ; \ '_ / | :| (_,_) /. (_ o _) || |\_ \| || |\_ /| || |\_ /| ||( ''_' ) |\ '_ '`)
# | _`,/ \ _/ || '-.-' | (_,_)___|| _( )_\ || _( )_/ | || _( )_/ | || . (_) `. | > (_) )
# : ( '\_/ \ ;| | ' \ .---.| (_ o _) || (_ o _) | || (_ o _) | ||(_ ._) '( . .-'
# \ `"/ \ ) / | | \ `-' /| (_,_)\ || (_,_) | || (_,_) | || (_.\.' / `-'`-'|___
# '. \_/``".' / ) \ / | | | || | | || | | || .' | \
# '-----' `---' `'-..-' '--' '--''--' '--''--' '--''-----'` `--------`
"""
)
boxType = session.get("boxType")

a_script.append("#!/bin/bash\n")

amber_script = AmberScriptGenerator(session, uploadedFiles)


amber_script.add_openmmdl_amber_logo(a_script)

# Receptor
amber_script.add_receptor_type(a_script)
Expand All @@ -307,132 +274,23 @@ def createAmberBashScript():
# Combine all components to be modelled.
amber_script.add_combine_components_commands(a_script)

# Add Water/Membrane
a_script.append(
"################################ Add Water/Membrane ##############################"
)

## Box setting
amber_script.add_solvation_commands(a_script)
amber_script.add_membrane_commands(a_script)
addType = session["addType"]

## Water Setting
amber_script.add_water_ff_commands(a_script)
water_ff = session["water_ff"]

## Ion Setting
pos_ion = session["pos_ion"]
if pos_ion != "other_pos_ion":
a_script.append("pos_ion=%s" % session["pos_ion"])
elif pos_ion == "other_pos_ion":
a_script.append(
"pos_ion=%s # In development!" % session["other_pos_ion_input"]
)

neg_ion = session["neg_ion"]
if neg_ion != "other_neg_ion":
a_script.append("neg_ion=%s" % session["neg_ion"])
elif neg_ion == "other_neg_ion":
a_script.append(
"neg_ion=%s # In development!" % session["other_neg_ion_input"]
)

if addType == "addWater":
a_script.append(
"numIon=0 # `numIon` is the flag for `addions` in tleap. When set to 0, the system will be neutralized"
)
a_script.append("\n")
elif addType == "addMembrane":
a_script.append("ionConc=%s" % session["ionConc"])
a_script.append("\n")
amber_script.add_ion_commands(a_script)

## Build the membrane
if addType == "addMembrane":
a_script.append("## Build the membrane")
if session["nmLig"] == False and session["spLig"] == False:
a_script.append(
"packmol-memgen --pdb ${rcp_nm}_cnt_rmv.pdb --lipids ${lipid_tp} --ratio ${lipid_ratio} --preoriented --dist ${dist2Border} --dist_wat ${padDist} --salt --salt_c ${pos_ion} --saltcon ${ionConc} --nottrim --overwrite --notprotonate\n"
)
a_script.append(
"## Clean the complex pdb by `pdb4amber` for further `tleap` process"
)
a_script.append(
"pdb4amber -i bilayer_${rcp_nm}_cnt_rmv.pdb -o clean_bilayer_${rcp_nm}.pdb"
)
## remove 'CONECT' line in the pdb file
a_script.append(
"grep -v '^CONECT' clean_bilayer_${rcp_nm}.pdb > clean_bilayer_${rcp_nm}_cnt_rmv.pdb"
)
a_script.append("\n")
if session["nmLig"] or session["spLig"]:
a_script.append(
"packmol-memgen --pdb comp.pdb --lipids ${lipid_tp} --ratio ${lipid_ratio} --preoriented --dist ${dist2Border} --dist_wat ${padDist} --salt --salt_c ${pos_ion} --saltcon ${ionConc} --nottrim --overwrite --notprotonate\n"
)
a_script.append(
"## Clean the complex pdb by `pdb4amber` for further `tleap` process"
)
a_script.append("pdb4amber -i bilayer_comp.pdb -o clean_bilayer_comp.pdb")
## remove 'CONECT' line in the pdb file
a_script.append(
"grep -v '^CONECT' clean_bilayer_comp.pdb > clean_bilayer_comp_cnt_rmv.pdb"
)
a_script.append("\n")
amber_script.add_membrane_building_commands(a_script)

# Generate the prmtop and frcmod file for the complex.
a_script.append(
"##################### Generate Prmtop and Frcmod File for the Complex ###################### "
)
a_script.append("cat > tleap.in <<EOF\n")
## source the force field
a_script.append("source ${rcp_ff}")
a_script.append("source leaprc.water.${water_ff}")
if session["nmLig"] or session["spLig"]:
a_script.append("source leaprc.${lig_ff}")
if addType == "addMembrane":
a_script.append("source leaprc.${lipid_ff}")
## load the prepc and frcmod file
if session["nmLig"]:
a_script.append("\nloadamberprep ${nmLigFile}.prepc")
a_script.append("loadamberparams ${nmLigFile}.frcmod\n")
if session["spLig"]:
a_script.append("loadamberprep ${prepc}.prepc")
a_script.append("loadamberparams ${frcmod}.frcmod\n")
## load the complex pdb which comtains all the components to be modelled.
if addType == "addWater":
if session["nmLig"] == False and session["spLig"] == False:
a_script.append("\nsystem = loadpdb ${rcp_nm}_cnt_rmv.pdb\n ")
else:
a_script.append("system = loadpdb comp_cnt_rmv.pdb\n")
elif addType == "addMembrane":
if session["nmLig"] == False and session["spLig"] == False:
a_script.append("\nsystem = loadpdb clean_bilayer_${rcp_nm}_cnt_rmv.pdb\n")
if session["nmLig"] or session["spLig"]:
a_script.append("system = loadpdb clean_bilayer_comp_cnt_rmv.pdb\n")
## add box
if addType == "addWater":
if boxType == "cube":
a_script.append("solvatebox system ${solvent} ${dist} ")
elif boxType == "octahedron":
a_script.append("solvateoct system ${solvent} ${dist}")
elif boxType == "cap":
a_script.append("solvatecap system ${solvent} ${radius}")
elif boxType == "shell":
a_script.append("solvateshell system ${solvent} ${thickness}")
a_script.append("addions2 system ${neg_ion} ${numIon}")
a_script.append("addions2 system ${pos_ion} ${numIon}")
elif addType == "addMembrane":
a_script.append('setBox system "vdw"')
a_script.append("check system ")
a_script.append("charge system\n")
## save pdb, prmtop and inpcrd file.
a_script.append("savepdb system system.${water_ff}.pdb")
a_script.append(
"saveamberparm system system.${water_ff}.prmtop system.${water_ff}.inpcrd"
)
a_script.append("\nquit")
a_script.append("\nEOF")
a_script.append("\ntleap -s -f tleap.in > tleap.out")
amber_script.generate_tleap_commands(a_script)


return "\n".join(a_script)

Expand Down Expand Up @@ -760,20 +618,15 @@ def createScript():

config_creator.add_forcefield_and_water_model_configuration(script)


config_creator.add_solvent_configuration(script)

config_creator.add_solvent_configuration(script)

# System configuration
config_creator.add_system_configuration(script)

# Integration options

config_creator.add_integration_configuration(script)

# Simulation options


config_creator.add_simulation_time_and_steps_configuration(script)

config_creator.add_equilibration_configuration(script)
Expand All @@ -782,17 +635,12 @@ def createScript():

config_creator.add_checkpoint_configuration(script)


config_creator.add_xml_serialization_configuration(script)

config_creator.add_postprocessing_configuration(script)

config_creator.add_openmmdl_analysis_configuration(script)





return "\n".join(script)


Expand Down

0 comments on commit 1119b6c

Please sign in to comment.