def test_cr(TOP, CRD, PERT, RULE): combining_rules = Parameter( "combining rules", RULE, """Combining rules to use for the non-bonded interactions.""") amber = Amber() (molecules, space) = amber.readCrdTop(CRD, TOP) system = createSystemFreeEnergy(molecules, PERT) system = setupForceFieldsFreeEnergy(system, space, RULE) if random_seed.val: ranseed = random_seed.val else: ranseed = RanGenerator().randInt(100000, 1000000) moves = setupMovesFreeEnergy(system, ranseed, reference.val, lambda_val.val, RULE) # Get energy from Sire nrg_sire = system.energy() # Get energy from SOMD mdmoves = moves.moves()[0] integrator = mdmoves.integrator() nrg_somd = integrator.getPotentialEnergy(system) if (RULE == 'arithmetic'): global diff_arith diff_arith = (nrg_sire - nrg_somd).value() print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("TESTING ARITHMETIC COMBINING RULES") print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("* The energy from Sire is: %s" % nrg_sire) print("* The energy from SOMD is: %s" % nrg_somd) print( " For the arithmetic combining rules the single point energy difference between sire and somd at lambda %s is %s " % (lambda_val.val, diff_arith)) elif (RULE == 'geometric'): global diff_geom diff_geom = (nrg_sire - nrg_somd).value() print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("TESTING GEOMETRIC COMBINING RULES") print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("* The energy from Sire is: %s" % nrg_sire) print("* The energy from SOMD is: %s" % nrg_somd) print( " For the geometric combining rules the single point energy difference between sire and somd at lambda %s is %s " % (lambda_val.val, diff_geom))
# # Evaluates electrostatics corrections to free energy changes # import os, sys, random import math import mdtraj from Sire.Tools.OpenMMMD import * from Sire.Tools import Parameter, resolveParameters # from Sire.Tools.LJcutoff import getFreeEnergy, resample solvent_residues = ["WAT", "ZBK", "ZBT", "CYC"] ion_residues = ["Cl-", "Na+"] DIME = 97 model_eps = Parameter("model_eps", 78.4, """The dielectric constant of the modelled solvent.""") trajfile = Parameter("trajfile", "traj000000001.dcd", """File name of the trajectory to process.""") stepframe = Parameter( "step_frame", 20, """The number of frames to step to between two succcessive evaluations.""") simfile = Parameter( "simfile", "sim.cfg", """ Configuration file with distance restraints dictionary""") topfile = Parameter( "topfile", "SYSTEM.top", """File name of the topology file containing the system to be simulated.""" ) crdfile = Parameter( "crdfile", "SYSTEM.crd",
from Sire.Config import * from Sire.Tools import Parameter, resolveParameters, readParams ###### CALCULATION PARAMETERS ## temperature = 298 * kelvin ## the dielectric for the reaction field rfdielectric=78.3 kb = 0.0019872041 # Boltzmann constant kcal/mol K ############################################# SOLVENT_RESNAMES = ["CYC","ZBT","WAT","T3P","HOH","T4P"] IONS_RESNAMES = ["Na+","Cl-"] ################################################ shift_delta = Parameter("shift delta", 2.0, """Value of the Lennard-Jones softcore parameter.""") coulomb_power = Parameter("coulomb power", 0, """Value of the Coulombic softcore parameter.""") combining_rules = Parameter("combining rules", "arithmetic", """Combining rules to use for the non-bonded interactions.""") def createSystem(molecules): #print("Applying flexibility and zmatrix templates...") print("Creating the system...") moleculeNumbers = molecules.molNums() moleculeList = [] for moleculeNumber in moleculeNumbers:
import Sire.Config import Sire.Stream from Sire.Tools.AmberLoader import * from Sire.Tools import Parameter, resolveParameters import os import shutil import copy ######################################################## # ALL OF THE GLOBAL USER-AVAILABLE QuanToMM PARAMETERS # ######################################################## cutoff_method = Parameter( "cutoff method", "shift electrostatics", """Method used to apply the non-bonded electrostatic cutoff.""") rf_dielectric = Parameter( "reaction field dielectric", 78.3, """Dielectric constant to use if the reaction field cutoff method is used.""" ) coul_cutoff = Parameter("coulomb cutoff", 15 * angstrom, """Coulomb cutoff length""") lj_cutoff = Parameter("LJ cutoff", 15 * angstrom, """Lennard Jones cutoff length""") grid_spacing = Parameter( "grid spacing", 1.0 * angstrom,
import numpy as np #try: # import mdtraj #except ImportError: # print ("LJcutoff.py depends on a working install of the python module mdtraj. Please install mdtraj in your sire python.") # sys.exit(-1) # #try: # import numpy as np #except ImportError: # print ("LJcutoff.py depends on a working install of the python module mdtraj. Please install mdtraj in your sire python.") # sys.exit(-1) bulk_rho = Parameter("bulk_rho", 1.0 * gram/(centimeter*centimeter*centimeter)\ ,"""The density of buk solvent.""") trajfile = Parameter("trajfile", "traj000000001.dcd", """File name of the trajectory to process.""") stepframe = Parameter( "step_frame", 1, """The number of frames to step to between two succcessive evaluations.""") def setupLJFF(system, space, cutoff=10 * angstrom): print("Creating force fields... ") solutes = system[MGName("solutes")] solute = system[MGName("solute_ref")] solute_hard = system[MGName("solute_ref_hard")]
try: shutil = Sire.try_import("shutil") except: pass try: numpy = Sire.try_import("numpy") except: pass # Constant for conversion NM_TO_ANG = 10.0 trajfile = Parameter("trajfile", "traj000000001.dcd", """File name of the trajectory to process.""") stepframe = Parameter("step_frame",1,"""The number of frames to step to between two succcessive evaluations.""") simfile = Parameter("simfile", "sim.cfg", """ Configuration file with distance restraints dictionary""") topfile = Parameter("topfile", "SYSTEM.top", """File name of the topology file containing the system to be simulated.""") buffer = Parameter("buffer", 5.0, """Buffer to be added to coordinates to create domain of integration""") delta_trans = Parameter("dtrans", 0.20, """Step size for translational volume elements, in Angstrom""") norient = Parameter("norient", 4, """Number of orientations per [0,2pi] Euler Angles interval""") temperature = Parameter("temperature",298 * kelvin,"""The temperature of the system""") verbose = Parameter("verbose", False, """Print debug output""") def averageCoordinates(restr_dict): r"""This function computes the average x,y and z coordinates for host atoms
from Sire.System import * from Sire.Move import * from Sire.MM import * from Sire.FF import * from Sire.Units import * from Sire.Vol import * from Sire.Maths import * from Sire.Base import * from Sire.Qt import * from Sire.ID import * from Sire.Config import * from Sire.Analysis import * from Sire.Tools import Parameter, resolveParameters cutoff_type = Parameter("cutoff type", "cutoffperiodic", """The cutoff method to use during the simulation.""") cutoff_dist = Parameter( "cutoff distance", 10 * angstrom, """The cutoff distance to use for the non-bonded interactions.""") rf_dielectric = Parameter( "reaction field dielectric", 78.3, """Dielectric constant to use if the reaction field cutoff method is used.""" ) use_restraints = Parameter( "use restraints", False, """Whether or not to use harmonic restaints on the solute atoms.""") combining_rules = Parameter(
from Sire.Maths import * from Sire.Base import * from Sire.Qt import * from Sire.ID import * from Sire.Config import * import Sire.Stream from Sire.Tools import Parameter, resolveParameters from Sire.Tools.WaterChanger import convertTip3PtoTip4P ################################### # Parameters used by this module # ################################### dobonds = Parameter("move bonds", True, """Whether or not to move the ligands bonds""") doangles = Parameter("move angles", True, """Whether or not to move the ligands angles""") dodihedrals = Parameter("move dihedrals", True, """Whether or not to move the ligands dihedrals""") water_model = Parameter( "water model", None, """The water model to use. Note, by default the water model is read from the protein and water crd/top files. If you want to force a change in water model, then set it here, e.g. if you are loading a TIP3P box but want to use TIP4P, then set this parameter to "tip4p".""" ) BASE_DIHEDRALH_FLEX = Parameter("h dihedral flex", 30 * degrees, "Base dihedral rotation for H")
def estimateDG(topfile=None,crdfile=None,pertfile=None, trajfile=None,librarypath=None): """ This subroutine loads a trajectory for an alchemical state, and a list of ligand molecules For each frame of the trajectory for each perturbed ligand Align the perturbed ligand onto reference ligand. Generate K poses Accumulate exp energy difference Estimate (w bootstrapping) free energy difference & uncertainties """ print ("HELLO ESTIMATE DG") # Setup system describing alchemical state amber = Amber() (molecules, space) = amber.readCrdTop(crdfile, topfile) morphfile = Parameter("morphfile",pertfile,""".""") system = createSystemFreeEnergy(molecules, morphfile=morphfile) cutoff_type = Parameter(".","cutoffperiodic",""".""") cutoff_dist = Parameter(".",10*angstrom,""".""") rf_dielectric = Parameter(".",82.0,""".""") shift_delta = Parameter(".",2.0,""".""") coulomb_power = Parameter(".",0,""".""") combining_rules = Parameter(".","arithmetic",""".""") lambda_val = Parameter(".",0.0,""".""") system = setupForceFieldsFreeEnergy(system, space, cutoff_type=cutoff_type, cutoff_dist=cutoff_dist, rf_dielectric=rf_dielectric, shift_delta=shift_delta, coulomb_power=coulomb_power, combining_rules=combining_rules, lambda_val=lambda_val) # Load ligands library # FIX ME ! Don't include ligands that have already been simulated ! library = loadLibrary(librarypath) library_deltaenergies = {} # library_deltaenergies contain the list of computed energy differences for ligand in library: library_deltaenergies[ligand] = [] #import pdb; pdb.set_trace() # Now scan trajectory start_frame = 1 end_frame = 3 step_frame = 1 trajfile = Parameter(".",trajfile,""".""") mdtraj_trajfile = mdtraj.open(trajfile.val,'r') nframes = len(mdtraj_trajfile) if end_frame > (nframes - 1): end_frame = nframes - 1 mdtraj_trajfile.seek(start_frame) current_frame = start_frame energies = {} for (ID, ligand) in library: energies[ID] = [] while (current_frame <= end_frame): print ("#Processing frame %s " % current_frame) frames_xyz, cell_lengths, cell_angles = mdtraj_trajfile.read(n_frames=1) system = updateSystemfromTraj(system, frames_xyz, cell_lengths, cell_angles) ref_ligand = system[MGName("solutes")].molecules().first().molecule() ref_nrg = system.energy() print (ref_nrg) for (ID, ligand) in library: # Align ligand onto reference ligand mapping = AtomMCSMatcher(1*second).match(ref_ligand, PropertyMap(), ligand, PropertyMap()) mapper = AtomResultMatcher(mapping) # This does a RB alignment # TODO) Explore optimised alignment codes # For instance could construct aligned ligand by reusing MCSS coordinates # and completing topology for variable part using BAT internal coordinates # Also, better otherwise never get intramolecular energy variations ! # Basic test...SAME LIGAND should give 0 energy difference ! # FIXME) Return multiple coordinates and update system in each instance aligned_ligand = ligand.move().align(ref_ligand, AtomMatchInverter(mapper)) #print (ref_ligand.property("coordinates").toVector()) #print ("####") #print (aligned_ligand.property("coordinates").toVector()) # FIXME) Optimise for speed new_system = System() new_space = system.property("space") new_system.add( system[MGName("solvent")] ) sols = MoleculeGroup("solutes") solref = MoleculeGroup("solute_ref") solhard = MoleculeGroup("solute_ref_hard") soltodummy = MoleculeGroup("solute_ref_todummy") solfromdummy = MoleculeGroup("solute_ref_fromdummy") sols.add(aligned_ligand) solref.add(aligned_ligand) solhard.add(aligned_ligand) new_system.add(sols) new_system.add(solref) new_system.add(solhard) new_system.add(soltodummy) new_system.add(solfromdummy) #print ("###") # DONE) Optimise for speed, only doing ligand energies #print (new_system[MGName("solutes")].first().molecule().property("coordinates").toVector()) new_system = setupForceFieldsFreeEnergy(new_system, new_space, cutoff_type=cutoff_type, cutoff_dist=cutoff_dist, rf_dielectric=rf_dielectric, shift_delta=shift_delta, coulomb_power=coulomb_power, combining_rules=combining_rules, lambda_val=lambda_val) new_nrg = new_system.energy() print (new_nrg) energies[ID].append( new_nrg - ref_nrg ) # for each conformation generated # consider further optimisation (rapid MC --> if loaded flex files?) # update 'perturbed' group with aligned ligand coordinates # compute 'perturbed' energy # accumulate 'perturbed' - reference #import pdb; pdb.set_trace() current_frame += step_frame import pdb; pdb.set_trace() # Now convert accumulated data int return 0
from Sire.Qt import * from Sire.ID import * from Sire.Config import * from Sire.Analysis import * from Sire.Tools.DCDFile import * from Sire.Tools import Parameter, resolveParameters import Sire.Stream import time import numpy as np ######################################### # Config file parameters # ######################################### combining_rules = Parameter( "combining rules", "geometric", """Combining rules to use for the non-bonded interactions.""") cutoff_type = Parameter("cutoff type", "nocutoff", """The cutoff method to use during the simulation.""") cutoff_dist = Parameter( "cutoff distance", 500 * angstrom, """The cutoff distance to use for the non-bonded interactions.""") use_restraints = Parameter( "use restraints", False, """Whether or not to use harmonic restaints on the solute atoms.""") def createSystem(molecules):
from Sire.Qt import * from Sire.ID import * from Sire.Config import * from Sire.Analysis import * from Sire.Tools.DCDFile import * from Sire.Tools import Parameter, resolveParameters import Sire.Stream import time import numpy as np #################################################################################################### # # Config file parameters # #################################################################################################### gpu = Parameter( "gpu", 0, """The device ID of the GPU on which to run the simulation.""") rf_dielectric = Parameter( "reaction field dielectric", 78.3, """Dielectric constant to use if the reaction field cutoff method is used.""" ) temperature = Parameter("temperature", 25 * celsius, """Simulation temperature""") pressure = Parameter("pressure", 1 * atm, """Simulation pressure""") topfile = Parameter( "topfile", "SYSTEM.top", """File name of the topology file containing the system to be simulated.""" )
from Sire.Tools.AmberLoader import * from Sire.Tools import Parameter, resolveParameters import os import shutil import copy # We will use the waterbox held in the WSRC tools directory wsrc_tools_dir = "%s/Tools/WSRC" % Sire.Config.share_directory #################################################### # ALL OF THE GLOBAL USER-AVAILABLE LSRC PARAMETERS # #################################################### cutoff_method = Parameter( "cutoff method", "shift electrostatics", """Method used to apply the non-bonded electrostatic cutoff.""") rf_dielectric = Parameter( "reaction field dielectric", 78.3, """Dielectric constant to use if the reaction field cutoff method is used.""" ) coul_cutoff = Parameter("coulomb cutoff", 15 * angstrom, """Coulomb cutoff length""") lj_cutoff = Parameter("LJ cutoff", 15 * angstrom, """Lennard Jones cutoff length""") grid_spacing = Parameter( "grid spacing", 1.0 * angstrom,
from BioSimSpace._SireWrappers import System as _System from BioSimSpace._Exceptions import IncompatibleError as _IncompatibleError from BioSimSpace.Types import Length as _Length from BioSimSpace._Exceptions import AlignmentError as _AlignmentError from BioSimSpace._Exceptions import MissingSoftwareError as _MissingSoftwareError from BioSimSpace._SireWrappers import Molecule as _Molecule from BioSimSpace import IO as _IO from BioSimSpace import Units as _Units from BioSimSpace import _Utils as _Utils ######################################### # Config file parameters # ######################################### combining_rules = Parameter( "combining rules", "geometric", """Combining rules to use for the non-bonded interactions.""") cutoff_type = Parameter("cutoff type", "nocutoff", """The cutoff method to use during the simulation.""") cutoff_dist = Parameter( "cutoff distance", 500 * angstrom, """The cutoff distance to use for the non-bonded interactions.""") use_restraints = Parameter( "use restraints", False, """Whether or not to use harmonic restaints on the solute atoms.""") perturbed_resnum = Parameter( "perturbed residue number", 1,
# try: import mdtraj except ImportError: print ("CoulCutoff.py depends on a working install of the python module mdtraj. Please install mdtraj in your sire python.") sys.exit(-1) try: import numpy as np except ImportError: print ("CoulCutoff.py depends on a working install of the python module mdtraj. Please install mdtraj in your sire python.") sys.exit(-1) ## Free energy specific keywords cutoff_type = Parameter("cutoff type", "cutoffperiodic", """The cutoff method to use during the simulation.""") cutoff_dist = Parameter("cutoff distance", 12 * angstrom, """The cutoff distance to use for the non-bonded interactions.""") topfile = Parameter("topfile", "SYSTEM.top", """File name of the topology file containing the system to be simulated.""") crdfile = Parameter("crdfile", "SYSTEM.crd", """File name of the coordinate file containing the coordinates of the system to be simulated.""") morphfile = Parameter("morphfile", "MORPH.pert", """Name of the morph file containing the perturbation to apply to the system.""") #lambda_val = Parameter("lambda_val", 0.0,
import ast except ImportError: print( "StandarState.py depends on a working install of the python module ast. Please install ast in your sire python." ) sys.exit(-1) try: import shutil except ImportError: print( "StandarState.py depends on a working install of the python module shutil. Please install shutil in your sire python." ) sys.exit(-1) trajfile = Parameter("trajfile", "traj000000001.dcd", """File name of the trajectory to process.""") stepframe = Parameter( "step_frame", 1, """The number of frames to step to between two succcessive evaluations.""") simfile = Parameter( "simfile", "sim.cfg", """ Configuration file with distance restraints dictionary""") topfile = Parameter( "topfile", "SYSTEM.top", """File name of the topology file containing the system to be simulated.""" ) buff = Parameter( "buff", 5.0, """Buffer to be added to coordinates to create domain of integration""")
from Sire.Qt import * from Sire.ID import * from Sire.Config import * from Sire.Analysis import * from Sire.Tools.DCDFile import * from Sire.Tools import Parameter, resolveParameters import Sire.Stream import time import numpy as np ######################################### # Config file parameters # ######################################### gpu = Parameter("gpu", 0, """The device ID of the GPU on which to run the simulation.""") platform = Parameter("platform", "OpenCL", """Which OpenMM platform should be used to perform the dynamics.""") timestep = Parameter("timestep", 2 * femtosecond, """Timestep for the dynamics simulation.""") temperature = Parameter("temperature", 25 * celsius, """Simulation temperature""") pressure = Parameter("pressure", 1 * atm, """Simulation pressure""") rf_dielectric = Parameter("reaction field dielectric", 78.3, """Dielectric constant to use if the reaction field cutoff method is used.""") combining_rules = Parameter("combining rules", "arithmetic",