├── DLGaMDSimulationIntegrator.py ├── LICENSE ├── README.md ├── deeplearningmodel.py ├── runSimulation ├── simParams.py ├── simulationCmdStage.py ├── simulationEquilPrepStage.py ├── simulationEquilStage.py ├── simulationProdStage.py ├── test ├── gcaa_unfold.crd └── gcaa_unfold.top └── utils.py /DLGaMDSimulationIntegrator.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import numpy as np 3 | import sys, os 4 | 5 | restartFile = "gamd-restart.dat" 6 | isExist = os.path.exists(restartFile) 7 | if isExist: 8 | column_names = ["Parameters", "Values"] 9 | gamdRestart = pd.read_csv("gamd-restart.dat", names=column_names, header=0, delimiter="\t", index_col=False) 10 | boost_parameters = gamdRestart.Values.to_list() 11 | boost_parameters = np.array(boost_parameters) 12 | 13 | nbsteps = boost_parameters[0] 14 | min_dihedral, max_dihedral = boost_parameters[1] * 4.184, boost_parameters[2] * 4.184 15 | min_total, max_total = boost_parameters[6] * 4.184, boost_parameters[7] * 4.184 16 | final_k0D, final_k0P = boost_parameters[5], boost_parameters[10] 17 | else: 18 | nbsteps = 0 19 | min_dihedral, max_dihedral = 0 * 4.184, 0 * 4.184 20 | min_total, max_total = 0 * 4.184, 0 * 4.184 21 | final_k0D, final_k0P = 0, 0 22 | 23 | from math import sqrt 24 | from openmm.app.statedatareporter import StateDataReporter 25 | from openmm.app import * 26 | from openmm import * 27 | from openmm.unit import * 28 | from utils import * 29 | from simParams import * 30 | """ 31 | OpenMM Custom Integrator Manual: http://docs.openmm.org/latest/api-python/generated/openmm.openmm.CustomIntegrator.html 32 | """ 33 | class conventionalMDIntegrator(CustomIntegrator): 34 | def __init__(self, dt=0.002*picoseconds, temperature=temperature*kelvins): 35 | CustomIntegrator.__init__(self, dt) 36 | 37 | self.collision_rate = 1/picoseconds 38 | self.kB = BOLTZMANN_CONSTANT_kB * AVOGADRO_CONSTANT_NA 39 | self.temperature = temperature 40 | self.thermal_energy = self.kB * self.temperature 41 | 42 | self.addGlobalVariable("thermal_energy", self.thermal_energy) 43 | self.addGlobalVariable("collision_rate", self.collision_rate) 44 | self.addGlobalVariable("vscale", 0.0) 45 | self.addGlobalVariable("fscale", 0.0) 46 | self.addGlobalVariable("noisescale", 0.0) 47 | self.addPerDofVariable("oldx", 0.0) 48 | self.addUpdateContextState() 49 | 50 | self.addComputeGlobal("vscale", "exp(-dt*collision_rate)") 51 | self.addComputeGlobal("fscale", "(1-vscale)/collision_rate") 52 | self.addComputeGlobal("noisescale", "sqrt(thermal_energy*(1-vscale*vscale))") 53 | self.addComputePerDof("oldx", "x") 54 | self.addComputePerDof("v", "vscale*v + fscale*f/m + noisescale*gaussian/sqrt(m)") 55 | self.addComputePerDof("x", "x+dt*v") 56 | self.addConstrainPositions() 57 | self.addComputePerDof("v", "(x-oldx)/dt") 58 | 59 | class DualDeepLearningGaMDEquilibration(CustomIntegrator): 60 | def __init__(self, dt=0.002*picoseconds, temperature=temperature*kelvins): 61 | CustomIntegrator.__init__(self, dt) 62 | 63 | self.collision_rate = 1/picosecond 64 | self.kB = BOLTZMANN_CONSTANT_kB * AVOGADRO_CONSTANT_NA 65 | self.temperature = temperature 66 | self.thermal_energy = self.kB * self.temperature 67 | 68 | self.addGlobalVariable("thermal_energy", self.thermal_energy) 69 | self.addGlobalVariable("collision_rate", self.collision_rate) 70 | self.addGlobalVariable("vscale", 0.0) 71 | self.addGlobalVariable("fscale", 0.0) 72 | self.addGlobalVariable("noisescale", 0.0) 73 | self.addGlobalVariable("DihedralEnergy", 0.0) 74 | self.addGlobalVariable("BoostedDihedralEnergy", 0.0) 75 | self.addGlobalVariable("VminD", min_dihedral) 76 | self.addGlobalVariable("VmaxD", max_dihedral) 77 | self.addGlobalVariable("DihedralBoostPotential", 0.0) 78 | self.addGlobalVariable("Dihedralk0", final_k0D) 79 | self.addGlobalVariable("DihedralRefEnergy", 0.0) 80 | self.addGlobalVariable("DihedralForceScalingFactor", 1.0) 81 | self.addGlobalVariable("TotalEnergy", 0.0) 82 | self.addGlobalVariable("BoostedTotalEnergy", 0.0) 83 | self.addGlobalVariable("VminP", min_total) 84 | self.addGlobalVariable("VmaxP", max_total) 85 | self.addGlobalVariable("TotalBoostPotential", 0.0) 86 | self.addGlobalVariable("Totalk0", final_k0P) 87 | self.addGlobalVariable("TotalRefEnergy", 0.0) 88 | self.addGlobalVariable("TotalForceScalingFactor", 1.0) 89 | self.addPerDofVariable("oldx", 0.0) 90 | self.addUpdateContextState() 91 | 92 | self.addComputeGlobal("DihedralEnergy", "energy2") 93 | self.addComputeGlobal("DihedralRefEnergy", "VminD+(VmaxD-VminD)/Dihedralk0") 94 | self.beginIfBlock(f"DihedralRefEnergy > VmaxD+{refED_factor}*abs(VmaxD)") 95 | self.addComputeGlobal("DihedralRefEnergy", "VmaxD") 96 | self.endBlock() 97 | self.beginIfBlock("DihedralEnergy < DihedralRefEnergy") 98 | self.addComputeGlobal("DihedralBoostPotential", "(0.5)*Dihedralk0*(DihedralRefEnergy-DihedralEnergy)^2/(VmaxD-VminD)") 99 | self.addComputeGlobal("DihedralForceScalingFactor", "1-Dihedralk0*(DihedralRefEnergy-DihedralEnergy)/(VmaxD-VminD)") 100 | self.endBlock() 101 | self.beginIfBlock("DihedralEnergy >= DihedralRefEnergy") 102 | self.addComputeGlobal("DihedralBoostPotential", "0.0") 103 | self.addComputeGlobal("DihedralForceScalingFactor", "1.0") 104 | self.endBlock() 105 | self.addComputeGlobal("BoostedDihedralEnergy", "DihedralEnergy+DihedralBoostPotential") 106 | self.addComputeGlobal("VminD", "min(BoostedDihedralEnergy, VminD)") 107 | self.addComputeGlobal("VmaxD", "max(BoostedDihedralEnergy, VmaxD)") 108 | 109 | self.addComputeGlobal("TotalEnergy", "energy+DihedralBoostPotential") 110 | self.addComputeGlobal("TotalRefEnergy", "VminP+(VmaxP-VminP)/Totalk0") 111 | self.beginIfBlock(f"TotalRefEnergy > VmaxP+{refEP_factor}*abs(VmaxP)") 112 | self.addComputeGlobal("TotalRefEnergy", "VmaxP") 113 | self.endBlock() 114 | self.beginIfBlock("TotalEnergy < TotalRefEnergy") 115 | self.addComputeGlobal("TotalBoostPotential", "(0.5)*Totalk0*(TotalRefEnergy-TotalEnergy)^2/(VmaxP-VminP)") 116 | self.addComputeGlobal("TotalForceScalingFactor", "1-Totalk0*(TotalRefEnergy-TotalEnergy)/(VmaxP-VminP)") 117 | self.endBlock() 118 | self.beginIfBlock("TotalEnergy >= TotalRefEnergy") 119 | self.addComputeGlobal("TotalBoostPotential", "0.0") 120 | self.addComputeGlobal("TotalForceScalingFactor", "1.0") 121 | self.endBlock() 122 | self.addComputeGlobal("BoostedTotalEnergy", "TotalEnergy+TotalBoostPotential") 123 | self.addComputeGlobal("VminP", "min(BoostedTotalEnergy, VminP)") 124 | self.addComputeGlobal("VmaxP", "max(BoostedTotalEnergy, VmaxP)") 125 | 126 | self.addComputeGlobal("vscale", "exp(-dt*collision_rate)") 127 | self.addComputeGlobal("fscale", "(1-vscale)/collision_rate") 128 | self.addComputeGlobal("noisescale", "sqrt(thermal_energy*(1-vscale*vscale))") 129 | self.addComputePerDof("oldx", "x") 130 | self.addComputePerDof("v", "vscale*v + noisescale*gaussian/sqrt(m)") 131 | self.addComputePerDof("v", "v + fscale*f2*TotalForceScalingFactor*DihedralForceScalingFactor/m") 132 | self.addComputePerDof("v", "v + fscale*f0*TotalForceScalingFactor/m") 133 | self.addComputePerDof("x", "x+dt*v") 134 | self.addConstrainPositions() 135 | self.addComputePerDof("v", "(x-oldx)/dt") 136 | 137 | class DualDeepLearningGaMDProduction(CustomIntegrator): 138 | def __init__(self, dt=0.002 * picoseconds, temperature=temperature*kelvins): 139 | CustomIntegrator.__init__(self, dt) 140 | 141 | self.collision_rate = 1 / picosecond 142 | self.kB = BOLTZMANN_CONSTANT_kB * AVOGADRO_CONSTANT_NA 143 | self.temperature = temperature 144 | self.thermal_energy = self.kB * self.temperature 145 | 146 | self.addGlobalVariable("thermal_energy", self.thermal_energy) 147 | self.addGlobalVariable("collision_rate", self.collision_rate) 148 | self.addGlobalVariable("vscale", 0.0) 149 | self.addGlobalVariable("fscale", 0.0) 150 | self.addGlobalVariable("noisescale", 0.0) 151 | self.addGlobalVariable("DihedralEnergy", 0.0) 152 | self.addGlobalVariable("BoostedDihedralEnergy", 0.0) 153 | self.addGlobalVariable("VminD", min_dihedral) 154 | self.addGlobalVariable("VmaxD", max_dihedral) 155 | self.addGlobalVariable("DihedralBoostPotential", 0.0) 156 | self.addGlobalVariable("Dihedralk0", final_k0D) 157 | self.addGlobalVariable("DihedralRefEnergy", 0.0) 158 | self.addGlobalVariable("DihedralForceScalingFactor", 1.0) 159 | self.addGlobalVariable("TotalEnergy", 0.0) 160 | self.addGlobalVariable("BoostedTotalEnergy", 0.0) 161 | self.addGlobalVariable("VminP", min_total) 162 | self.addGlobalVariable("VmaxP", max_total) 163 | self.addGlobalVariable("TotalBoostPotential", 0.0) 164 | self.addGlobalVariable("Totalk0", final_k0P) 165 | self.addGlobalVariable("TotalRefEnergy", 0.0) 166 | self.addGlobalVariable("TotalForceScalingFactor", 1.0) 167 | self.addPerDofVariable("oldx", 0.0) 168 | self.addUpdateContextState() 169 | 170 | self.addComputeGlobal("DihedralEnergy", "energy2") 171 | self.addComputeGlobal("DihedralRefEnergy", "VminD+(VmaxD-VminD)/Dihedralk0") 172 | self.beginIfBlock(f"DihedralRefEnergy > VmaxD+{refED_factor}*abs(VmaxD)") 173 | self.addComputeGlobal("DihedralRefEnergy", "VmaxD") 174 | self.endBlock() 175 | self.beginIfBlock("DihedralEnergy < DihedralRefEnergy") 176 | self.addComputeGlobal("DihedralBoostPotential", "(0.5)*Dihedralk0*(DihedralRefEnergy-DihedralEnergy)^2/(VmaxD-VminD)") 177 | self.addComputeGlobal("DihedralForceScalingFactor", "1-Dihedralk0*(DihedralRefEnergy-DihedralEnergy)/(VmaxD-VminD)") 178 | self.endBlock() 179 | self.beginIfBlock("DihedralEnergy >= DihedralRefEnergy") 180 | self.addComputeGlobal("DihedralBoostPotential", "0.0") 181 | self.addComputeGlobal("DihedralForceScalingFactor", "1.0") 182 | self.endBlock() 183 | self.addComputeGlobal("BoostedDihedralEnergy", "DihedralEnergy+DihedralBoostPotential") 184 | 185 | self.addComputeGlobal("TotalEnergy", "energy+DihedralBoostPotential") 186 | self.addComputeGlobal("TotalRefEnergy", "VminP+(VmaxP-VminP)/Totalk0") 187 | self.beginIfBlock(f"TotalRefEnergy > VmaxP+{refEP_factor}*abs(VmaxP)") 188 | self.addComputeGlobal("TotalRefEnergy", "VmaxP") 189 | self.endBlock() 190 | self.beginIfBlock("TotalEnergy < TotalRefEnergy") 191 | self.addComputeGlobal("TotalBoostPotential", "(0.5)*Totalk0*(TotalRefEnergy-TotalEnergy)^2/(VmaxP-VminP)") 192 | self.addComputeGlobal("TotalForceScalingFactor", "1-Totalk0*(TotalRefEnergy-TotalEnergy)/(VmaxP-VminP)") 193 | self.endBlock() 194 | self.beginIfBlock("TotalEnergy >= TotalRefEnergy") 195 | self.addComputeGlobal("TotalBoostPotential", "0.0") 196 | self.addComputeGlobal("TotalForceScalingFactor", "1.0") 197 | self.endBlock() 198 | self.addComputeGlobal("BoostedTotalEnergy", "TotalEnergy+TotalBoostPotential") 199 | 200 | self.addComputeGlobal("vscale", "exp(-dt*collision_rate)") 201 | self.addComputeGlobal("fscale", "(1-vscale)/collision_rate") 202 | self.addComputeGlobal("noisescale", "sqrt(thermal_energy*(1-vscale*vscale))") 203 | self.addComputePerDof("oldx", "x") 204 | self.addComputePerDof("v", "vscale*v + noisescale*gaussian/sqrt(m)") 205 | self.addComputePerDof("v", "v + fscale*f2*TotalForceScalingFactor*DihedralForceScalingFactor/m") 206 | self.addComputePerDof("v", "v + fscale*f0*TotalForceScalingFactor/m") 207 | self.addComputePerDof("x", "x+dt*v") 208 | self.addConstrainPositions() 209 | self.addComputePerDof("v", "(x-oldx)/dt") 210 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 MiaoLab 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deep Boosted Molecular Dynamics: Accelerating molecular simulations with Gaussian boost potentials generated using probabilistic Bayesian deep neural network 2 | In Deep Boosted Molecular Dynamics (DBMD), probabilistic Bayesian neural network models are implemented to construct boost potentials that exhibit Gaussian distribution with minimized anharmonicity, thereby allowing for accurate energetic reweighting and enhanced sampling of molecular simulations. DBMD has been demonstrated on a wide range of model systems, including alanine dipeptide and the fast-folding protein and RNA structures. Based on Deep Learning neural network, DBMD provides a powerful and generally applicable approach to boosting biomolecular simulations. Currently, DBMD has only been tested with AMBER force fields. The performance of DBMD using different force fields other than AMBER will be examined in the future. 3 | 4 | An example ***test*** folder that contains the input topology and coordinate file for the folding simulation of the hairpin RNA with GCAA tetraloop is included in this repository. The following *python* modules must be installed to perform a DBMD simulation: 5 | * OpenMM: https://openmm.org/ 6 | * TensorFlow: https://www.tensorflow.org/install 7 | * TensorFlow Keras: https://www.tensorflow.org/api_docs/python/tf/keras 8 | * TensorFlow Probability: https://www.tensorflow.org/probability/install 9 | * Scikit-learn: https://scikit-learn.org/stable/install.html 10 | * Numpy: https://numpy.org/install/ 11 | * Pandas: https://pandas.pydata.org/getting_started.html (*panda is also my favorite friend*) 12 | 13 | * image 14 | 15 | * Matplotlib: https://matplotlib.org/ 16 | * Seaborn: https://seaborn.pydata.org/installing.html 17 | 18 | It is recommended to install these modules and run DBMD in OpenMM in an Anaconda environment: https://www.anaconda.com/ 19 | 20 | An example input file for an DBMD simulation can be found in ***simParams.py***. A run script can be found in ***runSimulation***. To run the ***test*** folder, simply install all the necessary *python* modules and run the following commands: 21 | 22 | ***sh runSimulation*** 23 | 24 | Explanations for all parameters in the example input file can be found at the reference below. It is recommended to set up and run DBMD in OpenMM on NVIDIA GPUs to achieve the best possible speeds. 25 | 26 | # Reference 27 | Do, H.N. and Miao, Y. (2023) Deep Boosted Molecular Dynamics (DBMD): Accelerating molecular simulations with Gaussian boost potentials generated using probabilistic Bayesian deep neural network. *The Journal of Physical Chemistry Letters*, 14, 21, 4970-4982. https://doi.org/10.1021/acs.jpclett.3c00926 28 | -------------------------------------------------------------------------------- /deeplearningmodel.py: -------------------------------------------------------------------------------- 1 | from tensorflow.keras.models import Sequential 2 | from tensorflow.keras.optimizers import Adam 3 | from tensorflow.keras.losses import KLDivergence, Reduction 4 | import tensorflow as tf 5 | import tensorflow_probability as tfp 6 | import numpy as np 7 | from simParams import * 8 | 9 | tfpd = tfp.distributions 10 | tfpl = tfp.layers 11 | 12 | mu, sigma = 0.5, 1.0 13 | 14 | def priorModel(kernel_size, bias_size, dtype=None): 15 | size_sum = kernel_size + bias_size 16 | prior_model = Sequential() 17 | prior_model.add(tfpl.DistributionLambda( 18 | lambda t: tfpd.MultivariateNormalDiag(loc=mu*tf.ones(size_sum), scale_diag=sigma*tf.ones(size_sum)))) 19 | return prior_model 20 | 21 | def postModel(kernel_size, bias_size, dtype=None): 22 | size_sum = kernel_size + bias_size 23 | post_model = Sequential() 24 | post_model.add(tfpl.VariableLayer(tfpl.MultivariateNormalTriL.params_size(size_sum), dtype=dtype)) 25 | post_model.add(tfpl.MultivariateNormalTriL(size_sum)) 26 | return post_model 27 | 28 | def fullModel(nbsteps): 29 | full_model = Sequential() 30 | for _ in np.arange(0,1): 31 | full_model.add(tfpl.DenseVariational(64, input_dim=1, 32 | make_prior_fn=priorModel, make_posterior_fn=postModel, 33 | kl_weight=1/nbsteps, kl_use_exact=False, activation="sigmoid")) 34 | if simType == "explicit": nbEndLayers = 1 35 | else: nbEndLayers = 3 36 | for _ in np.arange(0,nbEndLayers): 37 | full_model.add(tfpl.DenseVariational(tfpl.IndependentNormal.params_size(1), 38 | make_prior_fn=priorModel, make_posterior_fn=postModel, 39 | kl_weight=1/nbsteps, kl_use_exact=False)) 40 | full_model.add(tfpl.IndependentNormal(1)) 41 | kl_divergence = KLDivergence(reduction="auto", name="kl_divergence") 42 | opt = Adam(learning_rate=3e-4) 43 | full_model.compile(loss=kl_divergence, optimizer=opt) 44 | # full_model.summary() 45 | return full_model 46 | -------------------------------------------------------------------------------- /runSimulation: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Set the number to the appropriate GPU 3 | export CUDA_VISIBLE_DEVICES=0 4 | 5 | python simulationCmdStage.py 6 | python simulationEquilPrepStage.py 7 | python simulationEquilStage.py 8 | 9 | python simulationProdStage.py 10 | -------------------------------------------------------------------------------- /simParams.py: -------------------------------------------------------------------------------- 1 | parmFile = "test/gcaa_unfold.top" 2 | crdFile = "test/gcaa_unfold.crd" 3 | simType = "RNA.implicit" # "explicit", "protein.implicit", "RNA.implicit" 4 | 5 | nbCutoff = 9.0 # if "explicit" 6 | temperature = 300 7 | 8 | ntcmd = 10000000 9 | cmdRestartFreq = 100 10 | 11 | ncycebprepstart, ncycebprepend = 0, 1 12 | ntebpreppercyc = 2500000 13 | ebprepRestartFreq = 100 14 | 15 | ncycebstart, ncycebend = 0, 3 16 | ntebpercyc = 2500000 17 | ebRestartFreq = 100 18 | 19 | ncycprodstart, ncycprodend = 0, 4 20 | ntprodpercyc = 250000000 21 | prodRestartFreq = 500 22 | 23 | refEP_factor, refED_factor = 0.05, 0.05 # between 0 and 1 24 | -------------------------------------------------------------------------------- /simulationCmdStage.py: -------------------------------------------------------------------------------- 1 | import sys, os 2 | from openmm.app.statedatareporter import StateDataReporter 3 | from openmm.app import * 4 | from openmm import * 5 | from openmm.unit import * 6 | from DLGaMDSimulationIntegrator import * 7 | from utils import * 8 | from simParams import * 9 | """ 10 | OpenMM Application Manual: http://docs.openmm.org/7.2.0/userguide/application.html 11 | """ 12 | prmtop = AmberPrmtopFile(parmFile) 13 | inpcrd = AmberInpcrdFile(crdFile) 14 | if simType == "explicit": system = prmtop.createSystem(nonbondedMethod=PME, nonbondedCutoff=nbCutoff*angstrom, constraints=HBonds) 15 | else: system = prmtop.createSystem(implicitSolvent=GBn2, implicitSolventKappa=1.0/nanometer, soluteDielectric=1.0, solventDielectric=78.5) 16 | set_dihedral_group(system) 17 | integrator = conventionalMDIntegrator(0.002*picoseconds, temperature*kelvins) 18 | 19 | isExist = os.path.exists("cmd.mdout") 20 | if isExist: 21 | os.remove("cmd.mdout") 22 | simulation = Simulation(prmtop.topology, system, integrator) 23 | simulation.context.setPositions(inpcrd.positions) 24 | if inpcrd.boxVectors is not None: 25 | simulation.context.setPeriodicBoxVectors(*inpcrd.boxVectors) 26 | simulation.minimizeEnergy() 27 | simulation.reporters.append(DCDReporter("cmd.dcd", cmdRestartFreq)) 28 | simulation.reporters.append(ExpandedStateDataReporter(system, "cmd.mdout", cmdRestartFreq, step=True, temperature=True, 29 | brokenOutForceEnergies=True, potentialEnergy=True, 30 | totalEnergy=True, density=True, separator="\t", 31 | speed=True, remainingTime=True, totalSteps=ntcmd)) 32 | simulation.step(ntcmd) 33 | simulation.saveState("cmd.rst") 34 | -------------------------------------------------------------------------------- /simulationEquilPrepStage.py: -------------------------------------------------------------------------------- 1 | import pandas as pd, numpy as np, os, sys 2 | from utils import * 3 | from simParams import * 4 | from openmm.app.statedatareporter import StateDataReporter 5 | from openmm.app import * 6 | from openmm import * 7 | from openmm.unit import * 8 | 9 | for cycle in np.arange(ncycebprepstart, ncycebprepend): 10 | if simType == "protein.implicit": 11 | column_names = ["Steps", "PotentialEnergy", "TotalEnergy", "Temperature", "Density", "Speed", 12 | "TimeRemaining", "HarmonicBondForce", "HarmonicAngleForce", "PeriodicTorsionForce", 13 | "CMAPTorsionForce", "NonbondedForce", "CustomGBForce", "CMMotionRemover"] 14 | elif simType == "RNA.implicit": 15 | column_names = ["Steps", "PotentialEnergy", "TotalEnergy", "Temperature", "Density", "Speed", 16 | "TimeRemaining", "HarmonicBondForce", "HarmonicAngleForce", "PeriodicTorsionForce", 17 | "NonbondedForce", "CustomGBForce", "CMMotionRemover"] 18 | else: # simType == "explicit" 19 | column_names = ["Steps", "PotentialEnergy", "TotalEnergy", "Temperature", "Density", "Speed", 20 | "TimeRemaining", "HarmonicBondForce", "HarmonicAngleForce", "PeriodicTorsionForce", 21 | "NonbondedForce", "CMMotionRemover"] 22 | if cycle == 0: df = pd.read_csv("cmd.mdout", names=column_names, header=0, delimiter="\t", index_col=False) 23 | else: df = pd.read_csv("equil-prep.mdout", names=column_names, header=0, delimiter="\t", index_col=False) 24 | 25 | steps = df.Steps.to_list() 26 | steps = np.array(steps[-10000:]) 27 | nbsteps = len(steps) 28 | 29 | dihedralEnergy = df.PeriodicTorsionForce.to_list() 30 | dihedralEnergy = np.array(dihedralEnergy[-10000:]) / 4.184 31 | min_dihedral, max_dihedral = min(dihedralEnergy), max(dihedralEnergy) 32 | 33 | totalEnergy = df.PotentialEnergy.to_list() 34 | totalEnergy = np.array(totalEnergy[-10000:]) / 4.184 35 | min_total, max_total = min(totalEnergy), max(totalEnergy) 36 | 37 | restartFile = "gamd-restart.dat" 38 | isExist = os.path.exists(restartFile) 39 | if isExist: os.remove(restartFile) 40 | gamdRestart = open(restartFile, "w") 41 | gamdRestart.write("#Parameters\tValues(kcal/mol)\n") 42 | gamdRestart.write("(0)Trained Steps:\t" + str(nbsteps) + "\n") 43 | gamdRestart.write("(1)Boosted VminD:\t" + str(min(dihedralEnergy)) + "\n") 44 | gamdRestart.write("(2)Boosted VmaxD:\t" + str(max(dihedralEnergy)) + "\n") 45 | gamdRestart.write("(3)Boosted VfinalD:\t" + str(dihedralEnergy[-1]) + "\n") 46 | gamdRestart.write("(4)Average k0D:\t" + str(1.0) + "\n") 47 | gamdRestart.write("(5)Final k0D:\t" + str(1.0) + "\n") 48 | gamdRestart.write("(6)Boosted VminP:\t" + str(min(totalEnergy)) + "\n") 49 | gamdRestart.write("(7)Boosted VmaxP:\t" + str(max(totalEnergy)) + "\n") 50 | gamdRestart.write("(8)Boosted VfinalP:\t" + str(totalEnergy[-1]) + "\n") 51 | gamdRestart.write("(9)Average k0P:\t" + str(1.0) + "\n") 52 | gamdRestart.write("(10)Final k0P:\t" + str(1.0) + "\n") 53 | gamdRestart.close() 54 | 55 | if cycle == 0: os.system("scp -v gamd-restart.dat cmd-restart.dat") 56 | else: os.system("scp -v gamd-restart.dat " + "equil-prep-"+str(cycle)+".restart.dat") 57 | 58 | from DLGaMDSimulationIntegrator import * 59 | """ 60 | OpenMM Application Manual: http://docs.openmm.org/7.2.0/userguide/application.html 61 | """ 62 | prmtop = AmberPrmtopFile(parmFile) 63 | if simType == "explicit": system = prmtop.createSystem(nonbondedMethod=PME, nonbondedCutoff=nbCutoff*angstrom, constraints=HBonds) 64 | else: system = prmtop.createSystem(implicitSolvent=GBn2, implicitSolventKappa=1.0/nanometer, soluteDielectric=1.0, solventDielectric=78.5) 65 | set_dihedral_group(system) 66 | 67 | integrator = DualDeepLearningGaMDEquilibration(0.002*picoseconds, temperature*kelvins) 68 | isExist = os.path.exists("equil-prep-"+str(cycle)+".mdout") 69 | if isExist: os.remove("equil-prep-"+str(cycle)+".mdout") 70 | simulation = Simulation(prmtop.topology, system, integrator) 71 | 72 | if cycle == 0: simulation.loadState("cmd.rst") 73 | else: simulation.loadState("equil-prep.rst") 74 | 75 | column_names = ["Parameters", "Values"] 76 | gamdRestart = pd.read_csv("gamd-restart.dat", names=column_names, header=0, delimiter="\t", index_col=False) 77 | boost_parameters = gamdRestart.Values.to_list() 78 | boost_parameters = np.array(boost_parameters) 79 | min_dihedral, max_dihedral = boost_parameters[1] * 4.184, boost_parameters[2] * 4.184 80 | min_total, max_total = boost_parameters[6] * 4.184, boost_parameters[7] * 4.184 81 | if simType == "explicit": final_k0D, final_k0P = 1.0, 1.0 82 | else: final_k0D, final_k0P = 1.0, 0.05 83 | 84 | integrator.setGlobalVariableByName("VminD", min_dihedral) 85 | integrator.setGlobalVariableByName("VmaxD", max_dihedral) 86 | integrator.setGlobalVariableByName("Dihedralk0", final_k0D) 87 | integrator.setGlobalVariableByName("VminP", min_total) 88 | integrator.setGlobalVariableByName("VmaxP", max_total) 89 | integrator.setGlobalVariableByName("Totalk0", final_k0P) 90 | 91 | simulation.reporters.append(DCDReporter("equil-prep-"+str(cycle)+".dcd", ebprepRestartFreq)) 92 | simulation.reporters.append(ExpandedStateDataReporter(system, "equil-prep-"+str(cycle)+".mdout", ebprepRestartFreq, 93 | step=True, temperature=True, 94 | brokenOutForceEnergies=True, potentialEnergy=True, 95 | totalEnergy=True, density=True, separator="\t", 96 | speed=True, remainingTime=True, totalSteps=ntebpreppercyc)) 97 | logFile = "equil-prep-"+str(cycle)+".log" 98 | isExist = os.path.exists(logFile) 99 | if isExist: os.remove(logFile) 100 | gamdLog = open(logFile, "w") 101 | gamdLog.write("# Gaussian accelerated Molecular Dynamics log file\n") 102 | gamdLog.write("# All energy terms are stored in unit of kcal/mol\n") 103 | gamdLog.write("# ntwx,total_nstep,Total-Energy,Dihedral-Energy,Total-Force-Weight,Dihedral-Force-Weight," 104 | "Total-Boost,Dihedral-Boost,Total-Harmonic-Force-Constant,Dihedral-Harmonic-Force-Constant," 105 | "Minimum-Total-Energy,Maximum-Total-Energy,Minimum-Dihedral-Energy,Maximum-Dihedral-Energy," 106 | "Total-Reference-Energy,Dihedral-Reference-Energy\n") 107 | gamdLog.close() 108 | 109 | for step in np.arange(0, ntebpreppercyc / ebprepRestartFreq): 110 | simulation.step(ebprepRestartFreq) 111 | simulation.saveState("equil-prep-"+str(cycle)+".rst") 112 | gamdLog = open(logFile, "a") 113 | gamdLog.write(str(ebprepRestartFreq) + "\t" + str(int((step + 1) * ebprepRestartFreq)) + "\t" 114 | + str(integrator.getGlobalVariableByName("TotalEnergy") / 4.184) + "\t" 115 | + str(integrator.getGlobalVariableByName("DihedralEnergy") / 4.184) + "\t" 116 | + str(integrator.getGlobalVariableByName("TotalForceScalingFactor")) + "\t" 117 | + str(integrator.getGlobalVariableByName("DihedralForceScalingFactor")) + "\t" 118 | + str(integrator.getGlobalVariableByName("TotalBoostPotential") / 4.184) + "\t" 119 | + str(integrator.getGlobalVariableByName("DihedralBoostPotential") / 4.184) + "\t" 120 | + str(integrator.getGlobalVariableByName("Totalk0")) + "\t" 121 | + str(integrator.getGlobalVariableByName("Dihedralk0")) + "\t" 122 | + str(integrator.getGlobalVariableByName("VminP") / 4.184) + "\t" 123 | + str(integrator.getGlobalVariableByName("VmaxP") / 4.184) + "\t" 124 | + str(integrator.getGlobalVariableByName("VminD") / 4.184) + "\t" 125 | + str(integrator.getGlobalVariableByName("VmaxD") / 4.184) + "\t" 126 | + str(integrator.getGlobalVariableByName("TotalRefEnergy") / 4.184) + "\t" 127 | + str(integrator.getGlobalVariableByName("DihedralRefEnergy") / 4.184) + "\n") 128 | gamdLog.close() 129 | 130 | isExist = os.path.exists("gamd-restart.dat") 131 | if isExist: os.remove("gamd-restart.dat") 132 | gamdRestart = open("gamd-restart.dat", "w") 133 | gamdRestart.write("#Parameters\tValues(kcal/mol)\n") 134 | gamdRestart.write("(0)Steps:\t" + str(int((step + 1)*ebprepRestartFreq)) + "\n") 135 | gamdRestart.write("(1)Boosted VminD:\t" + str(integrator.getGlobalVariableByName("VminD") / 4.184) + "\n") 136 | gamdRestart.write("(2)Boosted VmaxD:\t" + str(integrator.getGlobalVariableByName("VmaxD") / 4.184) + "\n") 137 | gamdRestart.write("(3)DihedralRefEnergy:\t" + str(integrator.getGlobalVariableByName("DihedralRefEnergy") / 4.184) + "\n") 138 | gamdRestart.write("(4)Final DihedralBoost:\t" + str(integrator.getGlobalVariableByName("DihedralBoostPotential") / 4.184) + "\n") 139 | gamdRestart.write("(5)Final k0D:\t" + str(integrator.getGlobalVariableByName("Dihedralk0")) + "\n") 140 | gamdRestart.write("(6)Boosted VminP:\t" + str(integrator.getGlobalVariableByName("VminP") / 4.184) + "\n") 141 | gamdRestart.write("(7)Boosted VmaxP:\t" + str(integrator.getGlobalVariableByName("VmaxP") / 4.184) + "\n") 142 | gamdRestart.write("(8)TotalRefEnergy:\t" + str(integrator.getGlobalVariableByName("TotalRefEnergy") / 4.184) + "\n") 143 | gamdRestart.write("(9)Final TotalBoost:\t" + str(integrator.getGlobalVariableByName("TotalBoostPotential") / 4.184) + "\n") 144 | gamdRestart.write("(10)Final k0P:\t" + str(integrator.getGlobalVariableByName("Totalk0")) + "\n") 145 | gamdRestart.close() 146 | 147 | os.system("scp equil-prep-"+str(cycle)+".mdout equil-prep.mdout") 148 | os.system("scp gamd-restart.dat equil-prep-"+str(cycle)+".restart.dat") 149 | os.system("scp equil-prep-"+str(cycle)+".rst equil-prep.rst") 150 | -------------------------------------------------------------------------------- /simulationEquilStage.py: -------------------------------------------------------------------------------- 1 | import pandas as pd, numpy as np, os, sys 2 | import seaborn as sns 3 | import matplotlib.pyplot as plt 4 | 5 | from sklearn.model_selection import train_test_split 6 | from tensorflow.keras.models import Sequential 7 | from tensorflow.keras.optimizers import Adam 8 | from tensorflow.keras.losses import KLDivergence, Reduction 9 | from tensorflow.keras.callbacks import ModelCheckpoint 10 | import tensorflow as tf 11 | import tensorflow_probability as tfp 12 | from deeplearningmodel import * 13 | from math import sqrt 14 | from utils import * 15 | from simParams import * 16 | 17 | tfpd = tfp.distributions 18 | tfpl = tfp.layers 19 | 20 | from openmm.app.statedatareporter import StateDataReporter 21 | from openmm.app import * 22 | from openmm import * 23 | from openmm.unit import * 24 | 25 | for cycle in np.arange(ncycebstart, ncycebend): 26 | if simType == "protein.implicit": 27 | column_names = ["Steps", "PotentialEnergy", "TotalEnergy", "Temperature", "Density", "Speed", 28 | "TimeRemaining", "HarmonicBondForce", "HarmonicAngleForce", "PeriodicTorsionForce", 29 | "CMAPTorsionForce", "NonbondedForce", "CustomGBForce", "CMMotionRemover"] 30 | elif simType == "RNA.implicit": 31 | column_names = ["Steps", "PotentialEnergy", "TotalEnergy", "Temperature", "Density", "Speed", 32 | "TimeRemaining", "HarmonicBondForce", "HarmonicAngleForce", "PeriodicTorsionForce", 33 | "NonbondedForce", "CustomGBForce", "CMMotionRemover"] 34 | else: # simType == "explicit" 35 | column_names = ["Steps", "PotentialEnergy", "TotalEnergy", "Temperature", "Density", "Speed", 36 | "TimeRemaining", "HarmonicBondForce", "HarmonicAngleForce", "PeriodicTorsionForce", 37 | "NonbondedForce", "CMMotionRemover"] 38 | if cycle == 0: df = pd.read_csv("equil-prep.mdout", names=column_names, header=0, delimiter="\t", index_col=False) 39 | else: df = pd.read_csv("equil.mdout", names=column_names, header=0, delimiter="\t", index_col=False) 40 | 41 | steps = df.Steps.to_list() 42 | steps = np.array(steps[-10000:]) 43 | steps = np.repeat(steps, 50, axis=-1) 44 | nbsteps = len(steps) 45 | 46 | dihedralEnergy = df.PeriodicTorsionForce.to_list() 47 | dihedralEnergy = np.array(dihedralEnergy[-10000:]) / 4.184 48 | dihedralEnergy = np.repeat(dihedralEnergy, 50, axis=-1) 49 | min_dihedral, max_dihedral = min(dihedralEnergy), max(dihedralEnergy) 50 | 51 | totalEnergy = df.PotentialEnergy.to_list() 52 | totalEnergy = np.array(totalEnergy[-10000:]) / 4.184 53 | totalEnergy = np.repeat(totalEnergy, 50, axis=-1) 54 | min_total, max_total = min(totalEnergy), max(totalEnergy) 55 | 56 | totalEnergies, totalBoosts, dihedralEnergies, dihedralBoosts = [], [], [], [] 57 | 58 | for step in np.arange(0, len(steps)): 59 | totalEnergies.append(totalEnergy[step]) 60 | totalfc0 = np.random.uniform(0, 1) 61 | while totalfc0 == 0: totalfc0 = np.random.uniform(0, 1) 62 | totalrefE = min_total + (max_total - min_total) / totalfc0 63 | totalboost = (1/2) * totalfc0 * (1/(max_total - min_total)) * (totalrefE - totalEnergy[step])**2 64 | if np.isnan(totalboost) == True: totalboost = 0 65 | totalBoosts.append(totalboost) 66 | 67 | dihedralEnergies.append(dihedralEnergy[step]) 68 | dihedralfc0 = np.random.uniform(0, 1) 69 | while dihedralfc0 == 0: dihedralfc0 = np.random.uniform(0, 1) 70 | dihedralrefE = min_dihedral + (max_dihedral - min_dihedral) / dihedralfc0 71 | dihedralboost = (1/2) * dihedralfc0 * (1/(max_dihedral - min_dihedral)) * (dihedralrefE - dihedralEnergy[step])**2 72 | if np.isnan(dihedralboost) == True: dihedralboost = 0 73 | dihedralBoosts.append(dihedralboost) 74 | 75 | Xtot = np.array(totalEnergies) 76 | Ytot = np.array(totalBoosts) 77 | Xdih = np.array(dihedralEnergies) 78 | Ydih = np.array(dihedralBoosts) 79 | Ydual = np.add(Ytot,Ydih) 80 | anharmtot, anharmdih, anharmdual = anharm(Ytot), anharm(Ydih), anharm(Ydual) 81 | 82 | boostFolder = "equil-boosts-"+str(cycle) 83 | isExist = os.path.exists(boostFolder) 84 | if not isExist: os.makedirs(boostFolder) 85 | 86 | plt.figure(figsize=(9, 6)) 87 | sns.kdeplot(Ytot, color="Blue", bw_method=0.25) 88 | sns.kdeplot(Ydih, color="Orange", bw_method=0.25) 89 | sns.kdeplot(Ydual, color="Green", bw_method=0.25) 90 | plt.legend(labels=["Total(γ="+str(round(anharmtot,3))+"; ∆V="+str(round(np.mean(Ytot), 2))+"±"+str(round(np.std(Ytot), 2))+")", 91 | "Dihedral(γ="+str(round(anharmdih,3))+"; ∆V="+str(round(np.mean(Ydih), 2))+"±"+str(round(np.std(Ydih), 2))+")", 92 | "Dual(γ="+str(round(anharmdual,3))+"; ∆V="+str(round(np.mean(Ydual), 2))+"±"+str(round(np.std(Ydual), 2))+")"], fontsize=15) 93 | plt.xlabel("∆V (kcal/mol)", fontsize=19, rotation=0) 94 | plt.ylabel("p(∆V)", fontsize=19, rotation=90) 95 | plt.xticks(fontsize=17) 96 | plt.yticks(fontsize=17) 97 | plt.savefig(boostFolder + "/randomboosts.png") 98 | 99 | iter = 0 100 | while (anharmdual > 1e-2) and iter <= 2: 101 | Xtot_train, Xtot_test, Ytot_train, Ytot_test = train_test_split(Xtot, Ytot, test_size=0.2) 102 | Xdih_train, Xdih_test, Ydih_train, Ydih_test = train_test_split(Xdih, Ydih, test_size=0.2) 103 | 104 | modeltot = fullModel(nbsteps) 105 | modeldih = fullModel(nbsteps) 106 | 107 | totalFolder, dihedralFolder = "equil-cptot-"+str(cycle), "equil-cpdih-"+str(cycle) 108 | isExist = os.path.exists(totalFolder) 109 | if not isExist: os.makedirs(totalFolder) 110 | isExist = os.path.exists(dihedralFolder) 111 | if not isExist: os.makedirs(dihedralFolder) 112 | 113 | cptot_path = totalFolder + "/cptot-{epoch:04d}.ckpt" 114 | cpdih_path = dihedralFolder + "/cpdih-{epoch:04d}.ckpt" 115 | cptot_callback = ModelCheckpoint(filepath=cptot_path, save_weights_only=True, save_freq="epoch") 116 | cpdih_callback = ModelCheckpoint(filepath=cpdih_path, save_weights_only=True, save_freq="epoch") 117 | 118 | historytot = modeltot.fit(Xtot_train, Ytot_train, epochs=50, batch_size=100, verbose=0, 119 | callbacks=[cptot_callback], validation_data=[Xtot_test, Ytot_test]) 120 | historydih = modeldih.fit(Xdih_train, Ydih_train, epochs=50, batch_size=100, verbose=0, 121 | callbacks=[cpdih_callback], validation_data=[Xdih_test, Ydih_test]) 122 | 123 | Ytot = modeltot.predict(Xtot) 124 | Ytot = np.absolute(Ytot.flatten()) 125 | Ydih = modeldih.predict(Xdih) 126 | Ydih = np.absolute(Ydih.flatten()) 127 | Ydual = np.add(Ytot,Ydih) 128 | anharmtot, anharmdih, anharmdual = anharm(Ytot), anharm(Ydih), anharm(Ydual) 129 | 130 | plt.figure(figsize=(9, 6)) 131 | sns.kdeplot(Ytot, color="Blue", bw_method=0.25) 132 | sns.kdeplot(Ydih, color="Orange", bw_method=0.25) 133 | sns.kdeplot(Ydual, color="Green", bw_method=0.25) 134 | plt.legend(labels=["Total(γ="+str(round(anharmtot,3))+"; ∆V="+str(round(np.mean(Ytot), 2))+"±"+str(round(np.std(Ytot), 2))+")", 135 | "Dihedral(γ="+str(round(anharmdih, 3))+"; ∆V="+str(round(np.mean(Ydih), 2))+"±"+str(round(np.std(Ydih), 2))+")", 136 | "Dual(γ="+str(round(anharmdual, 3))+"; ∆V="+str(round(np.mean(Ydual), 2))+"±"+str(round(np.std(Ydual), 2))+")"], fontsize=15) 137 | plt.xlabel("∆V (kcal/mol)", fontsize=19, rotation=0) 138 | plt.ylabel("p(∆V)", fontsize=19, rotation=90) 139 | plt.xticks(fontsize=17) 140 | plt.yticks(fontsize=17) 141 | plt.savefig(boostFolder + "/DLBoosts" + str(iter + 1) + ".png") 142 | 143 | totalfc0s, dihedralfc0s, totalfscales, dihedralfscales = [], [], [], [] 144 | for i in np.arange(0, len(Ydih), 100): 145 | dVD, VminD, VmaxD, VD = Ydih[i], min_dihedral, max_dihedral, Xdih[i] 146 | k0D = ((sqrt(2*dVD*(VmaxD-VminD))-sqrt(2*dVD*(VmaxD-VminD)-4*(VminD-VD)*(VmaxD-VminD)))/(2*(VminD-VD)))**2 147 | dihedralrefE = VminD + (VmaxD - VminD) / k0D 148 | if (k0D > 1.0) or (dihedralrefE > VmaxD+refED_factor*np.abs(VmaxD)): 149 | dihedralrefE = VmaxD 150 | k0D = (2*dVD*(VmaxD-VminD)) / (dihedralrefE-VD)**2 151 | k0D = min(1.0, k0D) 152 | kD = 1 - (k0D/(VmaxD-VminD)) * (dihedralrefE-VD) 153 | dihedralfc0s.append(k0D) 154 | dihedralfscales.append(kD) 155 | 156 | dVP, VminP, VmaxP, VP = Ytot[i], min_total, max_total, Xtot[i] 157 | k0P = ((sqrt(2*dVP*(VmaxP-VminP))-sqrt(2*dVP*(VmaxP-VminP)-4*(VminP-VP)*(VmaxP-VminP)))/(2*(VminP-VP)))**2 158 | totalrefE = VminP + (VmaxP - VminP) / k0P 159 | if (k0P > 1.0) or (totalrefE > VmaxP+refEP_factor*np.abs(VmaxP)): 160 | totalrefE = VmaxP 161 | k0P = (2*dVP*(VmaxP-VminP)) / (totalrefE-VP)**2 162 | k0P = min(1.0, k0P) 163 | kP = 1 - (k0P/(VmaxP-VminP)) * (totalrefE-VP) 164 | totalfc0s.append(k0P) 165 | totalfscales.append(kP) 166 | 167 | totalfc0s = np.asarray([totalfc0s]).flatten() 168 | dihedralfc0s = np.asarray([dihedralfc0s]).flatten() 169 | plt.figure(figsize=(9, 6)) 170 | plt.scatter(np.arange(0, len(totalfc0s)), totalfc0s, label="Total k0P") 171 | plt.scatter(np.arange(0, len(dihedralfc0s)), dihedralfc0s, label="Dihedral k0D") 172 | plt.ylim(0, 1.5) 173 | plt.xlabel("Steps", fontsize=19, rotation=0) 174 | plt.ylabel("k0P / k0D", fontsize=19, rotation=90) 175 | plt.xticks(fontsize=17) 176 | plt.yticks(fontsize=17) 177 | plt.legend(fontsize=15) 178 | plt.savefig(boostFolder + "/efconstants0" + str(iter + 1) + ".png") 179 | 180 | restartFile = "gamd-restart.dat" 181 | isExist = os.path.exists(restartFile) 182 | if isExist: os.remove(restartFile) 183 | gamdRestart = open(restartFile, "w") 184 | gamdRestart.write("#Parameters\tValues(kcal/mol)\n") 185 | gamdRestart.write("(0)Trained Steps:\t" + str(nbsteps) + "\n") 186 | gamdRestart.write("(1)Boosted VminD:\t" + str(min(dihedralEnergy)) + "\n") 187 | gamdRestart.write("(2)Boosted VmaxD:\t" + str(max(dihedralEnergy)) + "\n") 188 | gamdRestart.write("(3)Boosted VfinalD:\t" + str(Xdih[-1]) + "\n") 189 | gamdRestart.write("(4)Average k0D:\t" + str(np.mean([k0D for k0D in dihedralfc0s if np.isnan(k0D) == False])) + "\n") 190 | gamdRestart.write("(5)Final k0D:\t" + str(dihedralfc0s[-1]) + "\n") 191 | gamdRestart.write("(6)Boosted VminP:\t" + str(min(totalEnergy)) + "\n") 192 | gamdRestart.write("(7)Boosted VmaxP:\t" + str(max(totalEnergy)) + "\n") 193 | gamdRestart.write("(8)Boosted VfinalP:\t" + str(Xtot[-1]) + "\n") 194 | gamdRestart.write("(9)Average k0P:\t" + str(np.mean([k0P for k0P in totalfc0s if np.isnan(k0P) == False])) + "\n") 195 | gamdRestart.write("(10)Final k0P:\t" + str(totalfc0s[-1]) + "\n") 196 | gamdRestart.close() 197 | 198 | iter += 1 199 | 200 | os.system("scp gamd-restart.dat " + "equil-"+str(cycle)+".restart.dat") 201 | 202 | from DLGaMDSimulationIntegrator import * 203 | """ 204 | OpenMM Application Manual: http://docs.openmm.org/7.2.0/userguide/application.html 205 | """ 206 | prmtop = AmberPrmtopFile(parmFile) 207 | if simType == "explicit": system = prmtop.createSystem(nonbondedMethod=PME, nonbondedCutoff=nbCutoff*angstrom, constraints=HBonds) 208 | else: system = prmtop.createSystem(implicitSolvent=GBn2, implicitSolventKappa=1.0/nanometer, soluteDielectric=1.0, solventDielectric=78.5) 209 | set_dihedral_group(system) 210 | 211 | integrator = DualDeepLearningGaMDEquilibration(0.002*picoseconds, temperature*kelvins) 212 | isExist = os.path.exists("equil-"+str(cycle)+".mdout") 213 | if isExist: os.remove("equil-"+str(cycle)+".mdout") 214 | simulation = Simulation(prmtop.topology, system, integrator) 215 | 216 | if cycle == 0: simulation.loadState("equil-prep.rst") 217 | else: simulation.loadState("equil.rst") 218 | 219 | column_names = ["Parameters", "Values"] 220 | gamdRestart = pd.read_csv("gamd-restart.dat", names=column_names, header=0, delimiter="\t", index_col=False) 221 | boost_parameters = gamdRestart.Values.to_list() 222 | boost_parameters = np.array(boost_parameters) 223 | min_dihedral, max_dihedral = boost_parameters[1] * 4.184, boost_parameters[2] * 4.184 224 | min_total, max_total = boost_parameters[6] * 4.184, boost_parameters[7] * 4.184 225 | final_k0D, final_k0P = boost_parameters[5], boost_parameters[10] 226 | 227 | integrator.setGlobalVariableByName("VminD", min_dihedral) 228 | integrator.setGlobalVariableByName("VmaxD", max_dihedral) 229 | integrator.setGlobalVariableByName("Dihedralk0", final_k0D) 230 | integrator.setGlobalVariableByName("VminP", min_total) 231 | integrator.setGlobalVariableByName("VmaxP", max_total) 232 | integrator.setGlobalVariableByName("Totalk0", final_k0P) 233 | 234 | simulation.reporters.append(DCDReporter("equil-"+str(cycle)+".dcd", ebRestartFreq)) 235 | simulation.reporters.append(ExpandedStateDataReporter(system, "equil-"+str(cycle)+".mdout", ebRestartFreq, 236 | step=True, temperature=True, 237 | brokenOutForceEnergies=True, potentialEnergy=True, 238 | totalEnergy=True, density=True, separator="\t", 239 | speed=True, remainingTime=True, totalSteps=ntebpercyc)) 240 | logFile = "equil-"+str(cycle)+".log" 241 | isExist = os.path.exists(logFile) 242 | if isExist: os.remove(logFile) 243 | gamdLog = open(logFile, "w") 244 | gamdLog.write("# Gaussian accelerated Molecular Dynamics log file\n") 245 | gamdLog.write("# All energy terms are stored in unit of kcal/mol\n") 246 | gamdLog.write("# ntwx,total_nstep,Total-Energy,Dihedral-Energy,Total-Force-Weight,Dihedral-Force-Weight," 247 | "Total-Boost,Dihedral-Boost,Total-Harmonic-Force-Constant,Dihedral-Harmonic-Force-Constant," 248 | "Minimum-Total-Energy,Maximum-Total-Energy,Minimum-Dihedral-Energy,Maximum-Dihedral-Energy," 249 | "Total-Reference-Energy,Dihedral-Reference-Energy\n") 250 | gamdLog.close() 251 | 252 | for step in np.arange(0, ntebpercyc / ebRestartFreq): 253 | simulation.step(ebRestartFreq) 254 | simulation.saveState("equil-"+str(cycle)+".rst") 255 | gamdLog = open(logFile, "a") 256 | gamdLog.write(str(ebRestartFreq) + "\t" + str(int((step + 1) * ebRestartFreq)) + "\t" 257 | + str(integrator.getGlobalVariableByName("TotalEnergy") / 4.184) + "\t" 258 | + str(integrator.getGlobalVariableByName("DihedralEnergy") / 4.184) + "\t" 259 | + str(integrator.getGlobalVariableByName("TotalForceScalingFactor")) + "\t" 260 | + str(integrator.getGlobalVariableByName("DihedralForceScalingFactor")) + "\t" 261 | + str(integrator.getGlobalVariableByName("TotalBoostPotential") / 4.184) + "\t" 262 | + str(integrator.getGlobalVariableByName("DihedralBoostPotential") / 4.184) + "\t" 263 | + str(integrator.getGlobalVariableByName("Totalk0")) + "\t" 264 | + str(integrator.getGlobalVariableByName("Dihedralk0")) + "\t" 265 | + str(integrator.getGlobalVariableByName("VminP") / 4.184) + "\t" 266 | + str(integrator.getGlobalVariableByName("VmaxP") / 4.184) + "\t" 267 | + str(integrator.getGlobalVariableByName("VminD") / 4.184) + "\t" 268 | + str(integrator.getGlobalVariableByName("VmaxD") / 4.184) + "\t" 269 | + str(integrator.getGlobalVariableByName("TotalRefEnergy") / 4.184) + "\t" 270 | + str(integrator.getGlobalVariableByName("DihedralRefEnergy") / 4.184) + "\n") 271 | gamdLog.close() 272 | 273 | isExist = os.path.exists("gamd-restart.dat") 274 | if isExist: os.remove("gamd-restart.dat") 275 | gamdRestart = open("gamd-restart.dat", "w") 276 | gamdRestart.write("#Parameters\tValues(kcal/mol)\n") 277 | gamdRestart.write("(0)Steps:\t" + str(int((step + 1)*ebRestartFreq)) + "\n") 278 | gamdRestart.write("(1)Boosted VminD:\t" + str(integrator.getGlobalVariableByName("VminD") / 4.184) + "\n") 279 | gamdRestart.write("(2)Boosted VmaxD:\t" + str(integrator.getGlobalVariableByName("VmaxD") / 4.184) + "\n") 280 | gamdRestart.write("(3)DihedralRefEnergy:\t" + str(integrator.getGlobalVariableByName("DihedralRefEnergy") / 4.184) + "\n") 281 | gamdRestart.write("(4)Final DihedralBoost:\t" + str(integrator.getGlobalVariableByName("DihedralBoostPotential") / 4.184) + "\n") 282 | gamdRestart.write("(5)Final k0D:\t" + str(integrator.getGlobalVariableByName("Dihedralk0")) + "\n") 283 | gamdRestart.write("(6)Boosted VminP:\t" + str(integrator.getGlobalVariableByName("VminP") / 4.184) + "\n") 284 | gamdRestart.write("(7)Boosted VmaxP:\t" + str(integrator.getGlobalVariableByName("VmaxP") / 4.184) + "\n") 285 | gamdRestart.write("(8)TotalRefEnergy:\t" + str(integrator.getGlobalVariableByName("TotalRefEnergy") / 4.184) + "\n") 286 | gamdRestart.write("(9)Final TotalBoost:\t" + str(integrator.getGlobalVariableByName("TotalBoostPotential") / 4.184) + "\n") 287 | gamdRestart.write("(10)Final k0P:\t" + str(integrator.getGlobalVariableByName("Totalk0")) + "\n") 288 | gamdRestart.close() 289 | 290 | os.system("scp equil-"+str(cycle)+".mdout equil.mdout") 291 | os.system("scp gamd-restart.dat equil-"+str(cycle)+".restart.dat") 292 | os.system("scp equil-"+str(cycle)+".rst equil.rst") 293 | -------------------------------------------------------------------------------- /simulationProdStage.py: -------------------------------------------------------------------------------- 1 | from openmm.app.statedatareporter import StateDataReporter 2 | from openmm.app import * 3 | from openmm import * 4 | from openmm.unit import * 5 | from DLGaMDSimulationIntegrator import * 6 | from utils import * 7 | from simParams import * 8 | import pandas as pd, numpy as np, os, sys 9 | """ 10 | OpenMM Application Manual: http://docs.openmm.org/7.2.0/userguide/application.html 11 | """ 12 | for cycle in np.arange(ncycprodstart, ncycprodend): 13 | prmtop = AmberPrmtopFile(parmFile) 14 | if simType == "explicit": system = prmtop.createSystem(nonbondedMethod=PME, nonbondedCutoff=nbCutoff*angstrom, constraints=HBonds) 15 | else: system = prmtop.createSystem(implicitSolvent=GBn2, implicitSolventKappa=1.0/nanometer, soluteDielectric=1.0, solventDielectric=78.5) 16 | set_dihedral_group(system) 17 | 18 | integrator = DualDeepLearningGaMDProduction(0.002*picoseconds, temperature*kelvins) 19 | isExist = os.path.exists("gamd-"+str(cycle)+".mdout") 20 | if isExist: os.remove("gamd-"+str(cycle)+".mdout") 21 | simulation = Simulation(prmtop.topology, system, integrator) 22 | 23 | if cycle == 0: simulation.loadState("equil.rst") 24 | else: simulation.loadState("gamd.rst") 25 | 26 | column_names = ["Parameters", "Values"] 27 | gamdRestart = pd.read_csv("gamd-restart.dat", names=column_names, header=0, delimiter="\t", index_col=False) 28 | boost_parameters = gamdRestart.Values.to_list() 29 | boost_parameters = np.array(boost_parameters) 30 | min_dihedral, max_dihedral = boost_parameters[1] * 4.184, boost_parameters[2] * 4.184 31 | min_total, max_total = boost_parameters[6] * 4.184, boost_parameters[7] * 4.184 32 | final_k0D, final_k0P = boost_parameters[5], boost_parameters[10] 33 | 34 | integrator.setGlobalVariableByName("VminD", min_dihedral) 35 | integrator.setGlobalVariableByName("VmaxD", max_dihedral) 36 | integrator.setGlobalVariableByName("Dihedralk0", final_k0D) 37 | integrator.setGlobalVariableByName("VminP", min_total) 38 | integrator.setGlobalVariableByName("VmaxP", max_total) 39 | integrator.setGlobalVariableByName("Totalk0", final_k0P) 40 | 41 | simulation.reporters.append(DCDReporter("gamd-"+str(cycle)+".dcd", prodRestartFreq)) 42 | simulation.reporters.append(ExpandedStateDataReporter(system, "gamd-"+str(cycle)+".mdout", prodRestartFreq, 43 | step=True, temperature=True, 44 | brokenOutForceEnergies=True, potentialEnergy=True, 45 | totalEnergy=True, density=True, separator="\t", 46 | speed=True, remainingTime=True, totalSteps=ntprodpercyc)) 47 | 48 | logFile = "gamd-"+str(cycle)+".log" 49 | isExist = os.path.exists(logFile) 50 | if isExist: os.remove(logFile) 51 | gamdLog = open(logFile, "w") 52 | gamdLog.write("# Gaussian accelerated Molecular Dynamics log file\n") 53 | gamdLog.write("# All energy terms are stored in unit of kcal/mol\n") 54 | gamdLog.write("# ntwx,total_nstep,Total-Energy,Dihedral-Energy,Total-Force-Weight,Dihedral-Force-Weight," 55 | "Total-Boost,Dihedral-Boost,Total-Harmonic-Force-Constant,Dihedral-Harmonic-Force-Constant," 56 | "Minimum-Total-Energy,Maximum-Total-Energy,Minimum-Dihedral-Energy,Maximum-Dihedral-Energy," 57 | "Total-Reference-Energy,Dihedral-Reference-Energy\n") 58 | gamdLog.close() 59 | 60 | for step in np.arange(0, ntprodpercyc / prodRestartFreq): 61 | simulation.step(prodRestartFreq) 62 | simulation.saveState("gamd.rst") 63 | gamdLog = open(logFile, "a") 64 | gamdLog.write(str(prodRestartFreq) + "\t" + str(int((step + 1) * prodRestartFreq)) + "\t" 65 | + str(integrator.getGlobalVariableByName("TotalEnergy") / 4.184) + "\t" 66 | + str(integrator.getGlobalVariableByName("DihedralEnergy") / 4.184) + "\t" 67 | + str(integrator.getGlobalVariableByName("TotalForceScalingFactor")) + "\t" 68 | + str(integrator.getGlobalVariableByName("DihedralForceScalingFactor")) + "\t" 69 | + str(integrator.getGlobalVariableByName("TotalBoostPotential") / 4.184) + "\t" 70 | + str(integrator.getGlobalVariableByName("DihedralBoostPotential") / 4.184) + "\t" 71 | + str(integrator.getGlobalVariableByName("Totalk0")) + "\t" 72 | + str(integrator.getGlobalVariableByName("Dihedralk0")) + "\t" 73 | + str(integrator.getGlobalVariableByName("VminP") / 4.184) + "\t" 74 | + str(integrator.getGlobalVariableByName("VmaxP") / 4.184) + "\t" 75 | + str(integrator.getGlobalVariableByName("VminD") / 4.184) + "\t" 76 | + str(integrator.getGlobalVariableByName("VmaxD") / 4.184) + "\t" 77 | + str(integrator.getGlobalVariableByName("TotalRefEnergy") / 4.184) + "\t" 78 | + str(integrator.getGlobalVariableByName("DihedralRefEnergy") / 4.184) + "\n") 79 | gamdLog.close() 80 | 81 | isExist = os.path.exists("gamd-restart.dat") 82 | if isExist: os.remove("gamd-restart.dat") 83 | gamdRestart = open("gamd-restart.dat", "w") 84 | gamdRestart.write("#Parameters\tValues(kcal/mol)\n") 85 | gamdRestart.write("(0)Steps:\t" + str(int((step + 1)*prodRestartFreq)) + "\n") 86 | gamdRestart.write("(1)Boosted VminD:\t" + str(integrator.getGlobalVariableByName("VminD") / 4.184) + "\n") 87 | gamdRestart.write("(2)Boosted VmaxD:\t" + str(integrator.getGlobalVariableByName("VmaxD") / 4.184) + "\n") 88 | gamdRestart.write("(3)DihedralRefEnergy:\t" + str(integrator.getGlobalVariableByName("DihedralRefEnergy") / 4.184) + "\n") 89 | gamdRestart.write("(4)Final DihedralBoost:\t" + str(integrator.getGlobalVariableByName("DihedralBoostPotential") / 4.184) + "\n") 90 | gamdRestart.write("(5)Final k0D:\t" + str(integrator.getGlobalVariableByName("Dihedralk0")) + "\n") 91 | gamdRestart.write("(6)Boosted VminP:\t" + str(integrator.getGlobalVariableByName("VminP") / 4.184) + "\n") 92 | gamdRestart.write("(7)Boosted VmaxP:\t" + str(integrator.getGlobalVariableByName("VmaxP") / 4.184) + "\n") 93 | gamdRestart.write("(8)TotalRefEnergy:\t" + str(integrator.getGlobalVariableByName("TotalRefEnergy") / 4.184) + "\n") 94 | gamdRestart.write("(9)Final TotalBoost:\t" + str(integrator.getGlobalVariableByName("TotalBoostPotential") / 4.184) + "\n") 95 | gamdRestart.write("(10)Final k0P:\t" + str(integrator.getGlobalVariableByName("Totalk0")) + "\n") 96 | gamdRestart.close() 97 | 98 | os.system("scp -v gamd.rst gamd-"+str(cycle)+".rst") 99 | os.system("scp -v gamd-restart.dat gamd-"+str(cycle)+".restart.dat") 100 | -------------------------------------------------------------------------------- /test/gcaa_unfold.crd: -------------------------------------------------------------------------------- 1 | default_name 2 | 389 3 | 3.4290000 -7.8610000 3.6410000 4.2320000 -7.3600000 3.4800000 4 | 5.4800000 -8.0640000 3.3500000 5.4290000 -8.7660000 2.5180000 5 | 5.6790000 -8.6090000 4.2730000 6.6140000 -7.0680000 3.1000000 6 | 7.5690000 -7.5900000 3.0490000 6.4360000 -6.5040000 1.7700000 7 | 6.8370000 -5.1340000 1.7700000 7.5520000 -4.9570000 0.9670000 8 | 5.6710000 -4.3050000 1.3900000 4.3380000 -4.6510000 1.3200000 9 | 4.0300000 -5.6560000 1.5680000 3.5500000 -3.6760000 0.9400000 10 | 4.4200000 -2.6040000 0.7400000 4.1480000 -1.2760000 0.3300000 11 | 3.0670000 -0.7590000 0.0400000 5.3250000 -0.5130000 0.2600000 12 | 5.2410000 0.4460000 -0.0120000 6.5970000 -0.9860000 0.5500000 13 | 7.5790000 -0.0930000 0.4200000 7.4910000 0.8690000 0.1260000 14 | 8.5140000 -0.4190000 0.6180000 6.8480000 -2.2250000 0.9400000 15 | 5.7120000 -2.9740000 1.0100000 6.6460000 -5.8590000 4.0200000 16 | 5.9150000 -5.3540000 4.6510000 7.3800000 -4.8300000 3.1700000 17 | 7.2010000 -3.9290000 3.7560000 8.7720000 -5.1060000 3.1400000 18 | 9.2000000 -4.3480000 2.7360000 7.2970000 -6.1450000 5.2500000 19 | 6.8820000 -5.3380000 6.5600000 7.5050000 -5.9700000 7.7500000 20 | 5.4040000 -5.2010000 6.6100000 7.5380000 -3.9070000 6.2900000 21 | 8.9680000 -3.8250000 6.1600000 9.3040000 -4.4430000 5.3270000 22 | 9.4300000 -4.1760000 7.0830000 9.3840000 -2.3750000 5.9100000 23 | 10.4700000 -2.2990000 5.8600000 8.9300000 -1.9960000 4.5800000 24 | 8.5270000 -0.6260000 4.5800000 9.0330000 -0.0910000 3.7760000 25 | 7.0980000 -0.5590000 4.2000000 6.1630000 -1.5710000 4.1300000 26 | 6.4470000 -2.5830000 4.3780000 4.9730000 -1.1760000 3.7500000 27 | 5.1260000 0.1970000 3.5500000 4.1800000 1.1670000 3.1400000 28 | 2.9910000 1.0180000 2.8500000 4.7580000 2.4450000 3.0700000 29 | 4.1700000 3.2070000 2.7980000 6.0840000 2.7340000 3.3600000 30 | 6.4280000 4.0170000 3.2300000 5.8340000 4.7790000 2.9360000 31 | 7.3910000 4.2480000 3.4280000 6.9640000 1.8270000 3.7500000 32 | 6.4130000 0.5840000 3.8200000 8.7580000 -1.3400000 6.8300000 33 | 7.8700000 -1.3100000 7.4610000 8.8200000 -0.0770000 5.9800000 34 | 8.1830000 0.5850000 6.5660000 10.1400000 0.4430000 5.9500000 35 | 10.0900000 1.3130000 5.5460000 9.4610000 -1.2290000 8.0600000 36 | 8.6760000 -0.7740000 9.3700000 9.5410000 -0.9690000 10.5600000 37 | 7.3570000 -1.4570000 9.4200000 8.4540000 0.7840000 9.1000000 38 | 9.6130000 1.6260000 8.9700000 10.2310000 1.2880000 8.1380000 39 | 10.1910000 1.5800000 9.8930000 9.1800000 3.0720000 8.7200000 40 | 10.0520000 3.7240000 8.6690000 8.5930000 3.1440000 7.3900000 41 | 7.5140000 4.0800000 7.3900000 7.6510000 4.8040000 6.5870000 42 | 6.2750000 3.3650000 7.0100000 6.0350000 2.0080000 6.9400000 43 | 6.8210000 1.3100000 7.1880000 4.8200000 1.6970000 6.5600000 44 | 4.2070000 2.9350000 6.3600000 2.8870000 3.2400000 5.9500000 45 | 1.9670000 2.4730000 5.6600000 2.6830000 4.6290000 5.8800000 46 | 1.7770000 4.9530000 5.6090000 3.6430000 5.5880000 6.1700000 47 | 3.2390000 6.8530000 6.0400000 2.3270000 7.1730000 5.7470000 48 | 3.9240000 7.5680000 6.2380000 4.8740000 5.3000000 6.5600000 49 | 5.0820000 3.9560000 6.6300000 8.0940000 3.6040000 9.6400000 50 | 7.3300000 3.1480000 10.2700000 7.4630000 4.7000000 8.7900000 51 | 6.5690000 4.9130000 9.3760000 8.2940000 5.8510000 8.7600000 52 | 7.7830000 6.5560000 8.3560000 8.6250000 4.0770000 10.8700000 53 | 7.7190000 4.0350000 12.1800000 8.5520000 4.3390000 13.3700000 54 | 6.9780000 2.7490000 12.2300000 6.6900000 5.2270000 11.9100000 55 | 7.2110000 6.5620000 11.7800000 7.9140000 6.6110000 10.9480000 56 | 7.7220000 6.8350000 12.7030000 6.0660000 7.5440000 11.5300000 57 | 6.4480000 8.5640000 11.4790000 5.5320000 7.2880000 10.2000000 58 | 4.1190000 7.4920000 10.2000000 3.8510000 8.1720000 9.3920000 59 | 3.4630000 6.2210000 9.8200000 4.1540000 5.0390000 9.8100000 60 | 5.1980000 5.0260000 10.0860000 3.5540000 3.8780000 9.4600000 61 | 4.1260000 2.9500000 9.4520000 2.1610000 3.9470000 9.1000000 62 | 1.5160000 2.8520000 8.7400000 0.5400000 2.9410000 8.4950000 63 | 1.9960000 1.9630000 8.7160000 1.4930000 5.1060000 9.1100000 64 | 2.1190000 6.2610000 9.4700000 1.5360000 7.3510000 9.4900000 65 | 4.8640000 7.4050000 12.4500000 4.4670000 6.6090000 13.0800000 66 | 3.7410000 7.9870000 11.6000000 2.8730000 7.6840000 12.1860000 67 | 3.8190000 9.4040000 11.5700000 3.0080000 9.7210000 11.1660000 68 | 5.0550000 8.0900000 13.6800000 4.3150000 7.5660000 14.9900000 69 | 4.8530000 8.2720000 16.1800000 4.3870000 6.0830000 15.0400000 70 | 2.8060000 8.0130000 14.7200000 2.5230000 9.4180000 14.5900000 71 | 3.0870000 9.8380000 13.7570000 2.8060000 9.9260000 15.5120000 72 | 1.0290000 9.6250000 14.3400000 0.8010000 10.6900000 14.2900000 73 | 0.7180000 9.1220000 13.0100000 -0.5820000 8.5300000 13.0100000 74 | -1.1830000 8.9550000 12.2060000 -0.4470000 7.1060000 12.6300000 75 | 0.6870000 6.3230000 12.5600000 1.6490000 6.7460000 12.8070000 76 | 0.4630000 5.0890000 12.1800000 -0.9170000 5.0470000 11.9800000 77 | -1.7440000 3.9740000 11.5700000 -1.4300000 2.8180000 11.2800000 78 | -3.0920000 4.3660000 11.5000000 -3.7640000 3.6770000 11.2290000 79 | -3.5640000 5.6380000 11.7900000 -4.8820000 5.7980000 11.6600000 80 | -5.5530000 5.1020000 11.3660000 -5.2460000 6.7190000 11.8580000 81 | -2.7900000 6.6370000 12.1800000 -1.4820000 6.2670000 12.2500000 82 | 0.0930000 8.8600000 15.2600000 0.1900000 7.9760000 15.8900000 83 | -1.1670000 8.7430000 14.4100000 -1.7330000 8.0190000 14.9960000 84 | -1.8670000 9.9770000 14.3800000 -2.7210000 9.8060000 13.9760000 85 | -0.1170000 9.5390000 16.4900000 -0.4560000 8.6980000 17.8000000 86 | -0.3850000 9.5820000 18.9900000 0.4060000 7.4890000 17.8500000 87 | -1.9680000 8.2590000 17.5300000 -2.9640000 9.2880000 17.4000000 88 | -2.7160000 9.9460000 16.5670000 -3.0000000 9.8680000 18.3220000 89 | -4.3340000 8.6550000 17.1500000 -5.1010000 9.4270000 17.1000000 90 | -4.3240000 8.0640000 15.8200000 -5.0980000 6.8640000 15.8200000 91 | -5.8280000 6.9030000 15.0120000 -4.2150000 5.7380000 15.4400000 92 | -2.8520000 5.8740000 15.4300000 -2.4050000 6.8180000 15.7060000 93 | -2.0470000 4.8450000 15.0800000 -0.9650000 4.9780000 15.0720000 94 | -2.6890000 3.6080000 14.7200000 -1.9620000 2.5660000 14.3600000 95 | -2.4490000 1.7160000 14.1150000 -0.9540000 2.6320000 14.3360000 96 | -4.0210000 3.4830000 14.7300000 -4.8110000 4.5330000 15.0900000 97 | -6.0450000 4.4570000 15.1100000 -4.7080000 7.5060000 18.0700000 98 | -4.1490000 6.8140000 18.7000000 -5.7050000 6.7270000 17.2200000 99 | -5.7900000 5.8120000 17.8060000 -6.9610000 7.3870000 17.1900000 100 | -7.5870000 6.7810000 16.7860000 -5.2520000 7.9640000 19.3000000 101 | -5.0830000 7.0730000 20.6100000 -5.5010000 7.8560000 21.8000000 102 | -3.7050000 6.5210000 20.6600000 -6.1170000 5.8870000 20.3400000 103 | -7.5130000 6.2150000 20.2100000 -7.6600000 6.9030000 19.3770000 104 | -7.8570000 6.6830000 21.1320000 -8.3230000 4.9420000 19.9600000 105 | -9.3860000 5.1770000 19.9100000 -7.9950000 4.4500000 18.6300000 106 | -7.9980000 3.0220000 18.6300000 -8.6340000 2.5890000 17.8580000 107 | -6.6470000 2.5520000 18.2500000 -5.4890000 3.2720000 18.1900000 108 | -5.4770000 4.3090000 18.4920000 -4.4600000 2.5750000 17.8100000 109 | -4.9720000 1.3040000 17.6100000 -4.3890000 0.0920000 17.2000000 110 | -3.0800000 -0.0320000 16.9100000 -2.7100000 -0.9260000 16.6200000 111 | -2.4690000 0.7690000 16.9830000 -5.1880000 -0.9800000 17.1000000 112 | -6.4840000 -0.8540000 17.4000000 -7.1430000 -1.7070000 17.3380000 113 | -7.1460000 0.2250000 17.7900000 -6.3130000 1.2730000 17.8700000 114 | -8.0170000 3.7720000 20.8800000 -7.1740000 3.4910000 21.5110000 115 | -8.4350000 2.5790000 20.0300000 -8.0120000 1.7630000 20.6160000 116 | -9.8490000 2.4560000 20.0000000 -10.0480000 1.6080000 19.5960000 117 | -8.7220000 3.8650000 22.1100000 -8.0980000 3.2060000 23.4200000 118 | -8.8730000 3.6390000 24.6100000 -6.6400000 3.4860000 23.4700000 119 | -8.3280000 1.6490000 23.1500000 -9.6790000 1.1710000 23.0200000 120 | -10.1750000 1.6700000 22.1880000 -10.2200000 1.3800000 23.9430000 121 | -9.6740000 -0.3380000 22.7700000 -10.6960000 -0.7150000 22.7200000 122 | -9.1320000 -0.5750000 21.4400000 -8.3630000 -1.7780000 21.4400000 123 | -8.6650000 -2.4860000 20.6680000 -6.9720000 -1.4440000 21.0600000 124 | -6.3860000 -0.2120000 21.0000000 -6.9350000 0.6670000 21.3020000 125 | -5.1440000 -0.2430000 20.6200000 -4.8880000 -1.5880000 20.4200000 126 | -3.7430000 -2.2940000 20.0100000 -2.5740000 -1.6910000 19.7200000 127 | -1.7800000 -2.2430000 19.4290000 -2.4920000 -0.6870000 19.7930000 128 | -3.8360000 -3.6280000 19.9100000 -4.9950000 -4.2210000 20.2100000 129 | -5.0880000 -5.2950000 20.1480000 -6.1350000 -3.6720000 20.6000000 130 | -6.0000000 -2.3390000 20.6800000 -8.7840000 -1.1560000 23.6900000 131 | -7.9230000 -0.9370000 24.3210000 -8.4910000 -2.3870000 22.8400000 132 | -7.6940000 -2.8450000 23.4260000 -9.6140000 -3.2540000 22.8100000 133 | -9.3240000 -4.0750000 22.4060000 -9.4280000 -1.4590000 24.9200000 134 | -8.5470000 -1.6770000 26.2300000 -9.4320000 -1.7310000 27.4200000 135 | -7.4710000 -0.6540000 26.2800000 -7.8990000 -3.1120000 25.9600000 136 | -8.7780000 -4.2440000 25.8300000 -9.4650000 -4.0920000 24.9970000 137 | -9.3470000 -4.3610000 26.7530000 -7.9580000 -5.5110000 25.5800000 138 | -8.6140000 -6.3800000 25.5290000 -7.3740000 -5.4170000 24.2500000 139 | -6.0770000 -6.0140000 24.2500000 -6.0070000 -6.7470000 23.4460000 140 | -5.0870000 -4.9820000 23.8700000 -5.2350000 -3.6110000 23.8000000 141 | -6.1840000 -3.1590000 24.0480000 -4.1550000 -2.9750000 23.4200000 142 | -3.2210000 -3.9920000 23.2200000 -1.8680000 -3.9170000 22.8100000 143 | -1.1990000 -2.9240000 22.5200000 -1.2850000 -5.1930000 22.7400000 144 | -0.3240000 -5.2510000 22.4680000 -1.9390000 -6.3820000 23.0300000 145 | -1.1990000 -7.4850000 22.9000000 -0.2340000 -7.5390000 22.6060000 146 | -1.6580000 -8.3620000 23.0980000 -3.2010000 -6.4490000 23.4200000 147 | -3.7760000 -5.2170000 23.4900000 -6.7670000 -5.7190000 26.5000000 148 | -6.1600000 -5.0690000 27.1310000 -5.8560000 -6.5960000 25.6500000 149 | -4.9380000 -6.5510000 26.2360000 -6.3320000 -7.9320000 25.6200000 150 | -5.6440000 -8.4660000 25.2160000 -7.1450000 -6.3210000 27.7300000 151 | -6.2870000 -6.0290000 29.0400000 -7.0020000 -6.5530000 30.2300000 152 | -5.9340000 -4.5860000 29.0900000 -4.9660000 -6.8860000 28.7700000 153 | -5.0940000 -8.3130000 28.6400000 -5.7550000 -8.5560000 27.8080000 154 | -5.5090000 -8.7180000 29.5630000 -3.7200000 -8.9370000 28.3900000 155 | -3.8020000 -10.0230000 28.3390000 -3.2790000 -8.5420000 27.0600000 156 | -1.8650000 -8.3440000 27.0600000 -1.4170000 -8.9220000 26.2510000 157 | -1.5900000 -6.9400000 26.6800000 -2.5830000 -5.9970000 26.6700000 158 | -3.5890000 -6.2760000 26.9460000 -2.3310000 -4.7160000 26.3200000 159 | -3.1390000 -3.9850000 26.3110000 -0.9740000 -4.3930000 25.9600000 160 | -0.6610000 -3.1620000 25.6000000 0.3010000 -2.9750000 25.3550000 161 | -1.3700000 -2.4430000 25.5750000 -0.0090000 -5.3200000 25.9700000 162 | -0.2880000 -6.6040000 26.3300000 0.5760000 -7.4880000 26.3500000 163 | -2.6050000 -8.4680000 29.3100000 -2.4450000 -7.5940000 29.9420000 164 | -1.3650000 -8.7140000 28.4600000 -0.6170000 -8.1800000 29.0470000 165 | -1.0430000 -10.0960000 28.4300000 -0.1750000 -10.1730000 28.0260000 166 | -2.5980000 -9.1800000 30.5400000 -2.0330000 -8.4690000 31.8500000 167 | -2.3520000 -9.2970000 33.0400000 -2.5160000 -7.0650000 31.9000000 168 | -0.4590000 -8.4780000 31.5800000 0.2040000 -9.7480000 31.4500000 169 | -0.2210000 -10.3090000 30.6170000 0.0740000 -10.3140000 32.3720000 170 | 1.6980000 -9.5300000 31.2000000 2.2150000 -10.4880000 31.1500000 171 | 1.8560000 -8.9600000 29.8700000 2.9380000 -8.0290000 29.8700000 172 | 3.6270000 -8.2740000 29.0620000 2.4120000 -6.6990000 29.4900000 173 | 1.0670000 -6.4420000 29.4800000 0.3720000 -7.2210000 29.7560000 174 | 0.5860000 -5.2270000 29.1300000 -0.4890000 -5.0470000 29.1220000 175 | 1.5540000 -4.2230000 28.7700000 1.1520000 -3.0170000 28.4100000 176 | 1.8600000 -2.3400000 28.1650000 0.1670000 -2.7950000 28.3860000 177 | 2.8660000 -4.4820000 28.7800000 3.3250000 -5.7130000 29.1400000 178 | 4.5300000 -5.9900000 29.1600000 2.3830000 -8.5340000 32.1200000 179 | 2.0440000 -7.7120000 32.7510000 3.5590000 -8.0700000 31.2700000 180 | 3.9000000 -7.2170000 31.8560000 4.5760000 -9.0600000 31.2400000 181 | 5.3480000 -8.6570000 30.8360000 2.7730000 -9.1280000 33.3500000 182 | 2.8640000 -8.2260000 34.6600000 3.0430000 -9.0940000 35.8500000 183 | 1.7000000 -7.3050000 34.7100000 4.1940000 -7.3820000 34.3900000 184 | 5.4380000 -8.0930000 34.2600000 5.3840000 -8.7950000 33.4280000 185 | 5.6340000 -8.6390000 35.1830000 6.5770000 -7.1030000 34.0100000 186 | 7.5300000 -7.6300000 33.9590000 6.4020000 -6.5370000 32.6800000 187 | 6.8100000 -5.1690000 32.6800000 7.5370000 -4.9480000 31.8990000 188 | 5.6490000 -4.3340000 32.3000000 4.3760000 -4.8600000 32.2900000 189 | 4.2110000 -5.8810000 32.6010000 3.3160000 -4.1090000 31.9500000 190 | 2.3180000 -4.5480000 31.9490000 3.4780000 -2.7270000 31.5700000 191 | 2.5740000 -1.9680000 31.2300000 4.7930000 -2.2860000 31.6000000 192 | 4.9690000 -1.2460000 31.3270000 5.8970000 -3.0310000 31.9500000 193 | 7.0150000 -2.5390000 31.9500000 6.6150000 -5.8940000 34.9300000 194 | 5.8860000 -5.3850000 35.5610000 7.3550000 -4.8680000 34.0800000 195 | 7.1820000 -3.9660000 34.6660000 8.7460000 -5.1520000 34.0500000 196 | 9.1780000 -4.3960000 33.6460000 7.2650000 -6.1830000 36.1600000 197 | 7.3130000 -5.4480000 36.7750000 198 | -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | from openmm.app.statedatareporter import StateDataReporter 2 | from openmm.app import * 3 | from openmm import * 4 | from openmm.unit import * 5 | import numpy as np 6 | 7 | class ExpandedStateDataReporter(StateDataReporter): 8 | def __init__(self, system, file, reportInterval, step=True, time=False, brokenOutForceEnergies=True, 9 | potentialEnergy=True, kineticEnergy=False, totalEnergy=True, 10 | temperature=True, volume=False, density=True, progress=False, 11 | remainingTime=True, speed=True, elapsedTime=False, separator="\t", 12 | systemMass=None, totalSteps=None): 13 | self._brokenOutForceEnergies = brokenOutForceEnergies 14 | self._system = system 15 | # use super() to inherit methods from parent class StateDataReporter 16 | super().__init__(file, reportInterval, step, time, potentialEnergy, kineticEnergy, totalEnergy, 17 | temperature, volume, density, progress, remainingTime, speed, elapsedTime, separator, 18 | systemMass, totalSteps) 19 | 20 | def _constructReportValues(self, simulation, state): 21 | values = super()._constructReportValues(simulation, state) 22 | if self._brokenOutForceEnergies: 23 | # use enumerate to print out both the count and value of item of current iteration 24 | for i, force in enumerate(self._system.getForces()): 25 | values.append(simulation.context.getState( 26 | getEnergy=True, 27 | groups={i}).getPotentialEnergy().value_in_unit( 28 | kilojoules_per_mole)) 29 | return values 30 | 31 | def _constructHeaders(self): 32 | headers = super()._constructHeaders() 33 | if self._brokenOutForceEnergies: 34 | # use enumerate to print out both the count and value of item of current iteration 35 | for i, force in enumerate(self._system.getForces()): 36 | headers.append(force.__class__.__name__) 37 | return headers 38 | 39 | def set_all_forces_to_group(system): 40 | group = 1 41 | for force in system.getForces(): 42 | force.setForceGroup(group) 43 | return group 44 | 45 | def set_single_group(group, name, system): 46 | for force in system.getForces(): 47 | if force.__class__.__name__ == name: 48 | force.setForceGroup(group) 49 | break 50 | return group 51 | 52 | def set_dihedral_group(system): 53 | return set_single_group(2, 'PeriodicTorsionForce', system) 54 | 55 | def set_non_bonded_group(system): 56 | return set_single_group(1, 'NonbondedForce', system) 57 | 58 | def anharm(data): 59 | var = np.var(data) 60 | hist, edges = np.histogram(data, 50, density=True) 61 | hist = np.add(hist,0.000000000000000001) 62 | dx = edges[1] - edges[0] 63 | S1 = (-1) * np.trapz(np.multiply(hist, np.log(hist)),dx=dx) 64 | S2 = (1/2) * np.log(np.add(2.00*np.pi*np.exp(1)*var,0.000000000000000001)) 65 | return (S2 - S1) 66 | --------------------------------------------------------------------------------