system.add(cljff) system.add(solvent) system.setProperty("space", space) print("Initialising the ions...") titrator.applyTo(system) print("Randomising the location of ions...") titrator.randomiseCharge(3) titrator.applyTo(system) print("System is ready for simulation :-)") PDB().write(system.molecules(), "test0000.pdb") move = TitrationMove() move.setTemperature(25 * celsius) moves = WeightedMoves() moves.add(move, 1) move = RigidBodyMC(solvent) moves.add(move, 1) print("Start: %s" % system.energies()) for i in range(1, 11): system = moves.move(system, 1000, False) print("%5d: %s" % (i, system.energies())) PDB().write(system.molecules(), "test%0004d.pdb" % i) print(moves)
def loadQMMMSystem(): """This function is called to set up the system. It sets everything up, then returns a System object that holds the configured system""" print("Loading the system...") t = QTime() if os.path.exists(s3file.val): print("Loading existing s3 file %s..." % s3file.val) loadsys = Sire.Stream.load(s3file.val) else: print("Loading from Amber files %s / %s..." % (topfile.val, crdfile.val)) # Add the name of the ligand to the list of solute molecules sys_scheme = NamingScheme() sys_scheme.addSoluteResidueName(ligand_name.val) # Load up the system. This will automatically find the protein, solute, water, solvent # and ion molecules and assign them to different groups loadsys = createSystem(topfile.val, crdfile.val, sys_scheme) ligand_mol = findMolecule(loadsys, ligand_name.val) if ligand_mol is None: print( "Cannot find the ligand (%s) in the set of loaded molecules!" % ligand_name.val) sys.exit(-1) # Center the system with the ligand at (0,0,0) loadsys = centerSystem(loadsys, ligand_mol) ligand_mol = loadsys[ligand_mol.number()][0].molecule() if reflection_radius.val is None: loadsys = addFlexibility(loadsys, naming_scheme=sys_scheme) else: loadsys = addFlexibility(loadsys, Vector(0), reflection_radius.val, naming_scheme=sys_scheme) Sire.Stream.save(loadsys, s3file.val) ligand_mol = findMolecule(loadsys, ligand_name.val) if ligand_mol is None: print("Cannot find the ligand (%s) in the set of loaded molecules!" % ligand_name.val) sys.exit(-1) # Now build the QM/MM system system = System("QMMM system") if loadsys.containsProperty("reflection center"): reflect_center = loadsys.property("reflection center").toVector()[0] reflect_radius = float( str(loadsys.property("reflection sphere radius"))) system.setProperty("reflection center", AtomCoords(CoordGroup(1, reflect_center))) system.setProperty("reflection sphere radius", VariantProperty(reflect_radius)) space = Cartesian() else: space = loadsys.property("space") if loadsys.containsProperty("average solute translation delta"): system.setProperty("average solute translation delta", \ loadsys.property("average solute translation delta")) if loadsys.containsProperty("average solute rotation delta"): system.setProperty("average solute rotation delta", \ loadsys.property("average solute rotation delta")) # create a molecule group to hold all molecules all_group = MoleculeGroup("all") # create a molecule group for the ligand ligand_group = MoleculeGroup("ligand") ligand_group.add(ligand_mol) all_group.add(ligand_mol) groups = [] groups.append(ligand_group) # pull out the groups that we want from the two systems # create a group to hold all of the fixed molecules in the bound leg fixed_group = MoleculeGroup("fixed_molecules") if MGName("fixed_molecules") in loadsys.mgNames(): fixed_group.add(loadsys[MGName("fixed_molecules")]) if save_pdb.val: # write a PDB of the fixed atoms in the bound and free legs if not os.path.exists(outdir.val): os.makedirs(outdir.val) PDB().write(fixed_group, "%s/fixed.pdb" % outdir.val) # create a group to hold all of the mobile solute molecules mobile_solutes_group = MoleculeGroup("mobile_solutes") if MGName("mobile_solutes") in loadsys.mgNames(): mobile_solutes_group.add(loadsys[MGName("mobile_solutes")]) mobile_solutes_group.remove(ligand_mol) if mobile_solutes_group.nMolecules() > 0: all_group.add(mobile_solutes_group) groups.append(mobile_solutes_group) # create a group to hold all of the mobile solvent molecules mobile_solvents_group = MoleculeGroup("mobile_solvents") if MGName("mobile_solvents") in loadsys.mgNames(): mols = loadsys[MGName("mobile_solvents")] for molnum in mols.molNums(): solvent_mol = mols[molnum][0].molecule() mobile_solvents_group.add(solvent_mol) all_group.add(mobile_solvents_group) print("The number of mobile solvent molecules is %d." % mobile_solvents_group.nMolecules()) groups.append(mobile_solvents_group) # create the groups to hold all of the protein molecules. We will use "extract" to # pull out only those protein atoms that are in the mobile region protein_intra_group = MoleculeGroup("protein_intra_group") mobile_proteins_group = MoleculeGroup("proteins") mobile_protein_sidechains_group = MoleculeGroup("mobile_sidechains") mobile_protein_backbones_group = MoleculeGroup("mobile_backbones") if MGName("protein_sidechains") in loadsys.mgNames() or \ MGName("protein_backbones") in loadsys.mgNames(): all_proteins = Molecules() try: protein_sidechains = loadsys[MGName("protein_sidechains")] all_proteins.add(protein_sidechains.molecules()) except: protein_sidechains = MoleculeGroup() try: protein_backbones = loadsys[MGName("protein_backbones")] all_proteins.add(protein_backbones.molecules()) except: protein_backbones = MoleculeGroup() try: boundary_molecules = loadsys[MGName("boundary_molecules")] all_proteins.add(boundary_molecules.molecules()) except: boundary_molecules = MoleculeGroup() for molnum in all_proteins.molNums(): protein_mol = Molecule.join(all_proteins[molnum]) if protein_mol.selectedAll(): protein_intra_group.add(protein_mol) all_group.add(protein_mol) mobile_protein = [] if protein_sidechains.contains(molnum): sidechains = protein_sidechains[molnum] for sidechain in sidechains: mobile_protein_sidechains_group.add(sidechain) mobile_protein += sidechains if protein_backbones.contains(molnum): backbones = protein_backbones[molnum] for backbone in backbones: mobile_protein_backbones_group.add(backbone) mobile_protein += backbones if len(mobile_protein) > 0: mobile_proteins_group.add(Molecule.join(mobile_protein)) else: # only some of the atoms have been selected. We will extract # the mobile atoms and will then update all of the other selections print("Extracting the mobile atoms of protein %s" % protein_mol.molecule()) new_protein_mol = protein_mol.extract() print("Extracted %d mobile atoms from %d total atoms..." % \ (new_protein_mol.nAtoms(), protein_mol.molecule().nAtoms())) protein_intra_group.add(new_protein_mol) all_group.add(new_protein_mol) mobile_protein_view = new_protein_mol.selection() mobile_protein_view = mobile_protein_view.selectNone() if protein_sidechains.contains(molnum): sidechains = protein_sidechains[molnum] for sidechain in sidechains: view = new_protein_mol.selection() view = view.selectNone() for atomid in sidechain.selection().selectedAtoms(): atom = protein_mol.atom(atomid) resatomid = ResAtomID(atom.residue().number(), atom.name()) view = view.select(resatomid) mobile_protein_view = mobile_protein_view.select( resatomid) if view.nSelected() > 0: mobile_protein_sidechains_group.add( PartialMolecule(new_protein_mol, view)) if protein_backbones.contains(molnum): backbones = protein_backbones[molnum] for backbone in backbones: view = new_protein_mol.selection() view = view.selectNone() for atomid in backbone.selection().selectedAtoms(): atom = protein_mol.atom(atomid) resatomid = ResAtomID(atom.residue().number(), atom.name()) view = view.select(resatomid) mobile_protein_view = mobile_protein_view.select( resatomid) if view.nSelected() > 0: mobile_protein_backbones_group.add( PartialMolecule(new_protein_mol, view)) print("Number of moved protein sidechain residues = %s" % mobile_protein_sidechains_group.nViews()) print("Number of moved protein backbone residues = %s" % mobile_protein_backbones_group.nViews()) if mobile_protein_view.nSelected() > 0: mobile_proteins_group.add( PartialMolecule(new_protein_mol, mobile_protein_view)) groups.append(mobile_protein_backbones_group) groups.append(mobile_protein_sidechains_group) groups.append(all_group) # finished added in all of the proteins for group in groups: if group.nMolecules() > 0: print("Adding group %s" % group.name()) system.add(group) # now add in the forcefields for the system... print("Creating the forcefields for the QM/MM system...") # first, group together the molecules grouped above into convenient # groups for the forcefields # group holding just the ligand ligand_mols = ligand_group.molecules() # group holding all of the mobile atoms mobile_mols = mobile_solvents_group.molecules() mobile_mols.add(mobile_solutes_group.molecules()) mobile_mols.add(protein_intra_group.molecules()) # group holding all of the mobile atoms in the bound leg, excluding the # buffer atoms that are fixed, but bonded to mobile atoms mobile_buffered_mols = mobile_solvents_group.molecules() mobile_buffered_mols.add(mobile_solutes_group.molecules()) mobile_buffered_mols.add(mobile_proteins_group.molecules()) # group holding all of the protein molecules that need intramolecular terms calculated protein_intra_mols = protein_intra_group.molecules() # group holding all of the solute molecules that nede intramolecular terms calculated solute_intra_mols = mobile_solutes_group.molecules() forcefields = [] ### ### INTRA-ENERGY OF THE LIGAND AND CLUSTER ### # intramolecular energy of the ligand ligand_intraclj = IntraCLJFF("ligand:intraclj") ligand_intraclj = setCLJProperties(ligand_intraclj, space) ligand_intraclj.add(ligand_mols) ligand_intraff = InternalFF("ligand:intra") ligand_intraff.add(ligand_mols) forcefields.append(ligand_intraclj) forcefields.append(ligand_intraff) ligand_mm_nrg = ligand_intraclj.components().total( ) + ligand_intraff.components().total() ### ### FORCEFIELDS INVOLVING THE LIGAND/CLUSTER AND OTHER ATOMS ### # forcefield holding the energy between the ligand and the mobile atoms in the # bound leg ligand_mobile = InterGroupCLJFF("system:ligand-mobile") ligand_mobile = setCLJProperties(ligand_mobile, space) ligand_mobile.add(ligand_mols, MGIdx(0)) ligand_mobile.add(mobile_mols, MGIdx(1)) qm_ligand = QMMMFF("system:ligand-QM") qm_ligand.add(ligand_mols, MGIdx(0)) qm_ligand = setQMProperties(qm_ligand, space) zero_energy = 0 if not intermolecular_only.val: if qm_zero_energy.val is None: # calculate the delta value for the system - this is the difference between # the MM and QM intramolecular energy of the ligand t.start() print("\nComparing the MM and QM energies of the ligand...") mm_intra = ligand_intraclj.energy().value( ) + ligand_intraff.energy().value() print("MM energy = %s kcal mol-1 (took %s ms)" % (mm_intra, t.elapsed())) t.start() zero_sys = System() zero_sys.add(qm_ligand) qm_intra = zero_sys.energy().value() print("QM energy = %s kcal mol-1 (took %s ms)" % (qm_intra, t.elapsed())) print("\nSetting the QM zero energy to %s kcal mol-1" % (qm_intra - mm_intra)) qm_ligand.setZeroEnergy((qm_intra - mm_intra) * kcal_per_mol) zero_energy = qm_intra - mm_intra else: print("\nManually setting the QM zero energy to %s" % qm_zero_energy.val) qm_ligand.setZeroEnergy(qm_zero_energy.val) zero_energy = qm_zero_energy.val qm_ligand.add(mobile_mols, MGIdx(1)) ligand_mm_nrg += ligand_mobile.components().total() ligand_qm_nrg = qm_ligand.components().total() + ligand_mobile.components( ).lj() if intermolecular_only.val: # the QM model still uses the MM intramolecular energy of the ligand ligand_qm_nrg += ligand_intraclj.components().total( ) + ligand_intraff.components().total() forcefields.append(ligand_mobile) forcefields.append(qm_ligand) if fixed_group.nMolecules() > 0: # there are fixed molecules # Whether or not to disable the grid and calculate all energies atomisticly if disable_grid: # we need to renumber all of the fixed molecules so that they don't clash # with the mobile molecules print("Renumbering fixed molecules...") fixed_group = renumberMolecules(fixed_group) # forcefield holding the energy between the ligand and the fixed atoms in the bound leg if disable_grid: ligand_fixed = InterGroupCLJFF("system:ligand-fixed") ligand_fixed = setCLJProperties(ligand_fixed, space) ligand_fixed = setFakeGridProperties(ligand_fixed, space) ligand_fixed.add(ligand_mols, MGIdx(0)) ligand_fixed.add(fixed_group, MGIdx(1)) qm_ligand.add(fixed_group, MGIdx(1)) ligand_mm_nrg += ligand_fixed.components().total() ligand_qm_nrg += ligand_fixed.components().lj() forcefields.append(ligand_fixed) else: ligand_fixed = GridFF2("system:ligand-fixed") ligand_fixed = setCLJProperties(ligand_fixed, space) ligand_fixed = setGridProperties(ligand_fixed) ligand_fixed.add(ligand_mols, MGIdx(0)) ligand_fixed.addFixedAtoms(fixed_group) qm_ligand.addFixedAtoms(fixed_group) ligand_mm_nrg += ligand_fixed.components().total() ligand_qm_nrg += ligand_fixed.components().lj() forcefields.append(ligand_fixed) ### ### FORCEFIELDS NOT INVOLVING THE LIGAND ### # forcefield holding the intermolecular energy between all molecules mobile_mobile = InterCLJFF("mobile-mobile") mobile_mobile = setCLJProperties(mobile_mobile, space) mobile_mobile.add(mobile_mols) other_nrg = mobile_mobile.components().total() forcefields.append(mobile_mobile) # forcefield holding the energy between the mobile atoms and # the fixed atoms if disable_grid.val: mobile_fixed = InterGroupCLJFF("mobile-fixed") mobile_fixed = setCLJProperties(mobile_fixed) mobile_fixed = setFakeGridProperties(mobile_fixed, space) mobile_fixed.add(mobile_buffered_mols, MGIdx(0)) mobile_fixed.add(fixed_group, MGIdx(1)) other_nrg += mobile_fixed.components().total() forcefields.append(mobile_fixed) else: mobile_fixed = GridFF2("mobile-fixed") mobile_fixed = setCLJProperties(mobile_fixed, space) mobile_fixed = setGridProperties(mobile_fixed) # we use mobile_buffered_group as this group misses out atoms that are bonded # to fixed atoms (thus preventing large energies caused by incorrect non-bonded calculations) mobile_fixed.add(mobile_buffered_mols, MGIdx(0)) mobile_fixed.addFixedAtoms(fixed_group) other_nrg += mobile_fixed.components().total() forcefields.append(mobile_fixed) # intramolecular energy of the protein if protein_intra_mols.nMolecules() > 0: protein_intraclj = IntraCLJFF("protein_intraclj") protein_intraclj = setCLJProperties(protein_intraclj, space) protein_intraff = InternalFF("protein_intra") for molnum in protein_intra_mols.molNums(): protein_mol = Molecule.join(protein_intra_mols[molnum]) protein_intraclj.add(protein_mol) protein_intraff.add(protein_mol) other_nrg += protein_intraclj.components().total() other_nrg += protein_intraff.components().total() forcefields.append(protein_intraclj) forcefields.append(protein_intraff) # intramolecular energy of any other solutes if solute_intra_mols.nMolecules() > 0: solute_intraclj = IntraCLJFF("solute_intraclj") solute_intraclj = setCLJProperties(solute_intraclj, space) solute_intraff = InternalFF("solute_intra") for molnum in solute_intra_mols.molNums(): solute_mol = Molecule.join(solute_intra_mols[molnum]) solute_intraclj.add(solute_mol) solute_intraff.add(solute_mol) other_nrg += solute_intraclj.components().total() other_nrg += solute_intraff.components().total() forcefields.append(solute_intraclj) forcefields.append(solute_intraff) ### ### NOW ADD THE FORCEFIELDS TO THE SYSTEM ### ### ### SETTING THE FORCEFIELD EXPRESSIONS ### lam = Symbol("lambda") e_slow = ((1 - lam) * ligand_qm_nrg) + (lam * ligand_mm_nrg) + other_nrg e_fast = ligand_mm_nrg + other_nrg de_by_dlam = ligand_mm_nrg - ligand_qm_nrg for forcefield in forcefields: system.add(forcefield) system.setConstant(lam, 0.0) system.setComponent(Symbol("E_{fast}"), e_fast) system.setComponent(Symbol("E_{slow}"), e_slow) system.setComponent(Symbol("dE/dlam"), de_by_dlam) system.setComponent(system.totalComponent(), e_slow) system.setProperty("space", space) if space.isPeriodic(): # ensure that all molecules are wrapped into the space with the ligand at the center print("Adding in a space wrapper constraint %s, %s" % (space, ligand_mol.evaluate().center())) system.add(SpaceWrapper(ligand_mol.evaluate().center(), all_group)) system.applyConstraints() print("\nHere are the values of all of the initial energy components...") t.start() printEnergies(system.energies()) print("(these took %d ms to evaluate)\n" % t.elapsed()) # Create a monitor to monitor the free energy average system.add("dG/dlam", MonitorComponent(Symbol("dE/dlam"), AverageAndStddev())) if intermolecular_only.val: print( "\n\n## This simulation uses QM to model *only* the intermolecular energy between" ) print( "## the QM and MM atoms. The intramolecular energy of the QM atoms is still" ) print("## modelled using MM.\n") else: print( "\n\n## This simulation uses QM to model both the intermolecular and intramolecular" ) print( "## energies of the QM atoms. Because the this, we have to adjust the 'zero' point" ) print( "## of the QM potential. You need to add the value %s kcal mol-1 back onto the" % zero_energy) print("## QM->MM free energy calculated using this program.\n") return system
waters.update(water) print("Constructing the forcefields...") pol_tip4p = waters.moleculeAt(0).molecule() waters.remove(pol_tip4p) cljff = InterGroupCLJFF("pol_tip4p-water") cljff.add(pol_tip4p, MGIdx(0)) cljff.add(waters, MGIdx(1)) system = System() system.add(cljff) print(system.energies()) polchgs = PolariseCharges(cljff[MGIdx(0)], cljff.components().coulomb(), CoulombProbe(1*mod_electron)) system.add(polchgs) system.add(polchgs.selfEnergyFF()) print("Applying the polarisation constraint...") system.applyConstraints() print(system.energies()) pol_tip4p = system[MGIdx(0)][pol_tip4p.number()].molecule() print("MM charges\n",tip4p.property("charge"), \
group1.add(mols.moleculeAt(103)) group1.add(mols.moleculeAt(104)) cljff2 = InterGroupCLJFF("group_energy") cljff2.add(group0, MGIdx(0)) cljff2.add(group1, MGIdx(1)) cljff2.setSpace(vol) cljff2.setSwitchingFunction(switchfunc) print(cljff2.energy()) system.add(cljff2) system.add(group0) system.add(group1) print(system.energies()) nrgmon = EnergyMonitor(group0, group1) print(nrgmon) nrgmon.monitor(system) cnrgs = nrgmon.coulombEnergies() ljnrgs = nrgmon.ljEnergies() for i in range(0, cnrgs.nRows()): for j in range(0, cnrgs.nColumns()): print(i, j, cnrgs(i, j).average(), ljnrgs(i, j).average()) print(nrgmon.views0())
forcefield.add(protein) system.add(forcefield) def printEnergies(nrgs): keys = list(nrgs.keys()) keys.sort() for key in keys: print("%25s : %12.8f" % (key, nrgs[key])) system.setProperty("switchingFunction", HarmonicSwitchingFunction(10 * angstrom, 9.5 * angstrom)) printEnergies(system.energies()) print("\nEnergy with respect to cutoff length\n") print(" Distance Group Shifted ReactionField ") for i in range(10, 501, 5): x = i * 0.1 switchfunc = HarmonicSwitchingFunction(x * angstrom, (x - 0.5) * angstrom) system.setProperty("switchingFunction", switchfunc) print( "%12.8f %12.8f %12.8f %12.8f" % (x, system.energy(group_coul).value(), system.energy(shift_coul).value(), system.energy(field_coul).value()))
system = System() for forcefield in forcefields: forcefield.add(waters) system.add(forcefield) def printEnergies(nrgs): keys = list(nrgs.keys()) keys.sort() for key in keys: print("%25s : %12.8f" % (key, nrgs[key])) system.setProperty("space", space) system.setProperty("switchingFunction", switchfunc) printEnergies(system.energies()) print("\nEnergy with respect to cutoff length\n") print(" Distance Group Shifted ReactionField Atomistic") for i in range(10,200,5): x = i*0.1 switchfunc = HarmonicSwitchingFunction(x*angstrom, (x-0.5)*angstrom) system.setProperty("switchingFunction", switchfunc) print("%12.8f %12.8f %12.8f %12.8f %12.8f" % (x, system.energy(group_coul).value(), system.energy(shift_coul).value(), system.energy(field_coul).value(), system.energy(atom_coul).value()))
def loadQMMMSystem(): """This function is called to set up the system. It sets everything up, then returns a System object that holds the configured system""" print("Loading the system...") t = QTime() if os.path.exists(s3file.val): print("Loading existing s3 file %s..." % s3file.val) loadsys = Sire.Stream.load(s3file.val) else: print("Loading from Amber files %s / %s..." % (topfile.val, crdfile.val)) # Add the name of the ligand to the list of solute molecules sys_scheme = NamingScheme() sys_scheme.addSoluteResidueName(ligand_name.val) # Load up the system. This will automatically find the protein, solute, water, solvent # and ion molecules and assign them to different groups loadsys = createSystem(topfile.val, crdfile.val, sys_scheme) ligand_mol = findMolecule(loadsys, ligand_name.val) if ligand_mol is None: print("Cannot find the ligand (%s) in the set of loaded molecules!" % ligand_name.val) sys.exit(-1) # Center the system with the ligand at (0,0,0) loadsys = centerSystem(loadsys, ligand_mol) ligand_mol = loadsys[ligand_mol.number()].molecule() if reflection_radius.val is None: loadsys = addFlexibility(loadsys, naming_scheme=sys_scheme ) else: loadsys = addFlexibility(loadsys, Vector(0), reflection_radius.val, naming_scheme=sys_scheme) Sire.Stream.save(loadsys, s3file.val) ligand_mol = findMolecule(loadsys, ligand_name.val) if ligand_mol is None: print("Cannot find the ligand (%s) in the set of loaded molecules!" % ligand_name.val) sys.exit(-1) # Now build the QM/MM system system = System("QMMM system") if loadsys.containsProperty("reflection center"): reflect_center = loadsys.property("reflection center").toVector()[0] reflect_radius = float(str(loadsys.property("reflection sphere radius"))) system.setProperty("reflection center", AtomCoords(CoordGroup(1,reflect_center))) system.setProperty("reflection sphere radius", VariantProperty(reflect_radius)) space = Cartesian() else: space = loadsys.property("space") if loadsys.containsProperty("average solute translation delta"): system.setProperty("average solute translation delta", \ loadsys.property("average solute translation delta")) if loadsys.containsProperty("average solute rotation delta"): system.setProperty("average solute rotation delta", \ loadsys.property("average solute rotation delta")) # create a molecule group to hold all molecules all_group = MoleculeGroup("all") # create a molecule group for the ligand ligand_group = MoleculeGroup("ligand") ligand_group.add(ligand_mol) all_group.add(ligand_mol) groups = [] groups.append(ligand_group) # pull out the groups that we want from the two systems # create a group to hold all of the fixed molecules in the bound leg fixed_group = MoleculeGroup("fixed_molecules") if MGName("fixed_molecules") in loadsys.mgNames(): fixed_group.add( loadsys[ MGName("fixed_molecules") ] ) if save_pdb.val: # write a PDB of the fixed atoms in the bound and free legs if not os.path.exists(outdir.val): os.makedirs(outdir.val) PDB().write(fixed_group, "%s/fixed.pdb" % outdir.val) # create a group to hold all of the mobile solute molecules mobile_solutes_group = MoleculeGroup("mobile_solutes") if MGName("mobile_solutes") in loadsys.mgNames(): mobile_solutes_group.add( loadsys[MGName("mobile_solutes")] ) mobile_solutes_group.remove(ligand_mol) if mobile_solutes_group.nMolecules() > 0: all_group.add(mobile_solutes_group) groups.append(mobile_solutes_group) # create a group to hold all of the mobile solvent molecules mobile_solvents_group = MoleculeGroup("mobile_solvents") if MGName("mobile_solvents") in loadsys.mgNames(): mols = loadsys[MGName("mobile_solvents")] for molnum in mols.molNums(): solvent_mol = mols[molnum].molecule() mobile_solvents_group.add(solvent_mol) all_group.add(mobile_solvents_group) print("The number of mobile solvent molecules is %d." % mobile_solvents_group.nMolecules()) groups.append(mobile_solvents_group) # create the groups to hold all of the protein molecules. We will use "extract" to # pull out only those protein atoms that are in the mobile region protein_intra_group = MoleculeGroup("protein_intra_group") mobile_proteins_group = MoleculeGroup("proteins") mobile_protein_sidechains_group = MoleculeGroup("mobile_sidechains") mobile_protein_backbones_group = MoleculeGroup("mobile_backbones") if MGName("protein_sidechains") in loadsys.mgNames() or \ MGName("protein_backbones") in loadsys.mgNames(): all_proteins = Molecules() try: protein_sidechains = loadsys[MGName("protein_sidechains")] all_proteins.add(protein_sidechains.molecules()) except: protein_sidechains = MoleculeGroup() try: protein_backbones = loadsys[MGName("protein_backbones")] all_proteins.add(protein_backbones.molecules()) except: protein_backbones = MoleculeGroup() try: boundary_molecules = loadsys[MGName("boundary_molecules")] all_proteins.add(boundary_molecules.molecules()) except: boundary_molecules = MoleculeGroup() for molnum in all_proteins.molNums(): protein_mol = all_proteins[molnum].join() if protein_mol.selectedAll(): protein_intra_group.add(protein_mol) all_group.add(protein_mol) mobile_protein = None try: mobile_protein = protein_sidechains[molnum] mobile_protein_sidechains_group.add( mobile_protein ) except: pass try: if mobile_protein is None: mobile_protein = protein_backbones[molnum] mobile_protein_backbones_group.add( mobile_protein ) else: mobile_protein.add( protein_backbones[molnum].selection() ) mobile_protein_backbones_group.add( protein_backbones[molnum] ) except: pass if not (mobile_protein is None): mobile_proteins_group.add( mobile_protein.join() ) else: # only some of the atoms have been selected. We will extract # the mobile atoms and will then update all of the other selections print("Extracting the mobile atoms of protein %s" % protein_mol) new_protein_mol = protein_mol.extract() print("Extracted %d mobile atoms from %d total atoms..." % \ (new_protein_mol.nAtoms(), protein_mol.molecule().nAtoms())) protein_intra_group.add(new_protein_mol) all_group.add( new_protein_mol ) mobile_protein_view = new_protein_mol.selection() mobile_protein_view = mobile_protein_view.selectNone() try: sidechains = protein_sidechains[molnum] for i in range(0,sidechains.nViews()): view = new_protein_mol.selection() view = view.selectNone() for atomid in sidechains.viewAt(i).selectedAtoms(): atom = protein_mol.atom(atomid) resatomid = ResAtomID( atom.residue().number(), atom.name() ) view = view.select( resatomid ) mobile_protein_view = mobile_protein_view.select( resatomid ) if view.nSelected() > 0: mobile_protein_sidechains_group.add( PartialMolecule(new_protein_mol, view) ) except: pass try: backbones = protein_backbones[molnum] for i in range(0,backbones.nViews()): view = new_protein_mol.selection() view = view.selectNone() for atomid in backbones.viewAt(i).selectedAtoms(): atom = protein_mol.atom(atomid) resatomid = ResAtomID( atom.residue().number(), atom.name() ) view = view.select( resatomid ) mobile_protein_view = mobile_protein_view.select( resatomid ) if view.nSelected() > 0: mobile_protein_backbones_group.add( PartialMolecule(new_protein_mol, view) ) except: pass if mobile_protein_view.nSelected() > 0: mobile_proteins_group.add( PartialMolecule(new_protein_mol, mobile_protein_view) ) groups.append(mobile_protein_backbones_group) groups.append(mobile_protein_sidechains_group) groups.append(all_group) # finished added in all of the proteins for group in groups: if group.nMolecules() > 0: print("Adding group %s" % group.name()) system.add(group) # now add in the forcefields for the system... print("Creating the forcefields for the QM/MM system...") # first, group together the molecules grouped above into convenient # groups for the forcefields # group holding just the ligand ligand_mols = ligand_group.molecules() # group holding all of the mobile atoms mobile_mols = mobile_solvents_group.molecules() mobile_mols.add( mobile_solutes_group.molecules() ) mobile_mols.add( protein_intra_group.molecules() ) # group holding all of the mobile atoms in the bound leg, excluding the # buffer atoms that are fixed, but bonded to mobile atoms mobile_buffered_mols = mobile_solvents_group.molecules() mobile_buffered_mols.add( mobile_solutes_group.molecules() ) mobile_buffered_mols.add( mobile_proteins_group.molecules() ) # group holding all of the protein molecules that need intramolecular terms calculated protein_intra_mols = protein_intra_group.molecules() # group holding all of the solute molecules that nede intramolecular terms calculated solute_intra_mols = mobile_solutes_group.molecules() forcefields = [] ### ### INTRA-ENERGY OF THE LIGAND AND CLUSTER ### # intramolecular energy of the ligand ligand_intraclj = IntraCLJFF("ligand:intraclj") ligand_intraclj = setCLJProperties(ligand_intraclj, space) ligand_intraclj.add(ligand_mols) ligand_intraff = InternalFF("ligand:intra") ligand_intraff.add(ligand_mols) forcefields.append(ligand_intraclj) forcefields.append(ligand_intraff) ligand_mm_nrg = ligand_intraclj.components().total() + ligand_intraff.components().total() ### ### FORCEFIELDS INVOLVING THE LIGAND/CLUSTER AND OTHER ATOMS ### # forcefield holding the energy between the ligand and the mobile atoms in the # bound leg ligand_mobile = InterGroupCLJFF("system:ligand-mobile") ligand_mobile = setCLJProperties(ligand_mobile, space) ligand_mobile.add(ligand_mols, MGIdx(0)) ligand_mobile.add(mobile_mols, MGIdx(1)) qm_ligand = QMMMFF("system:ligand-QM") qm_ligand = setQMProperties(qm_ligand, space) qm_ligand.add(ligand_mols, MGIdx(0)) zero_energy = 0 if not intermolecular_only.val: if qm_zero_energy.val is None: # calculate the delta value for the system - this is the difference between # the MM and QM intramolecular energy of the ligand t.start() print("\nComparing the MM and QM energies of the ligand...") mm_intra = ligand_intraclj.energy().value() + ligand_intraff.energy().value() print("MM energy = %s kcal mol-1 (took %s ms)" % (mm_intra, t.elapsed())) t.start() qm_intra = qm_ligand.energy().value() print("QM energy = %s kcal mol-1 (took %s ms)" % (qm_intra, t.elapsed())) print("\nSetting the QM zero energy to %s kcal mol-1" % (qm_intra - mm_intra)) qm_ligand.setZeroEnergy( (qm_intra-mm_intra) * kcal_per_mol ) zero_energy = qm_intra - mm_intra else: print("\nManually setting the QM zero energy to %s" % qm_zero_energy.val) qm_ligand.setZeroEnergy( qm_zero_energy.val ) zero_energy = qm_zero_energy.val qm_ligand.add(mobile_mols, MGIdx(1)) ligand_mm_nrg += ligand_mobile.components().total() ligand_qm_nrg = qm_ligand.components().total() + ligand_mobile.components().lj() if intermolecular_only.val: # the QM model still uses the MM intramolecular energy of the ligand ligand_qm_nrg += ligand_intraclj.components().total() + ligand_intraff.components().total() forcefields.append(ligand_mobile) forcefields.append(qm_ligand) if fixed_group.nMolecules() > 0: # there are fixed molecules # Whether or not to disable the grid and calculate all energies atomisticly if disable_grid: # we need to renumber all of the fixed molecules so that they don't clash # with the mobile molecules print("Renumbering fixed molecules...") fixed_group = renumberMolecules(fixed_group) # forcefield holding the energy between the ligand and the fixed atoms in the bound leg if disable_grid: ligand_fixed = InterGroupCLJFF("system:ligand-fixed") ligand_fixed = setCLJProperties(ligand_fixed, space) ligand_fixed = setFakeGridProperties(ligand_fixed, space) ligand_fixed.add(ligand_mols, MGIdx(0)) ligand_fixed.add(fixed_group, MGIdx(1)) qm_ligand.add(fixed_group, MGIdx(1)) ligand_mm_nrg += ligand_fixed.components().total() ligand_qm_nrg += ligand_fixed.components().lj() forcefields.append(ligand_fixed) else: ligand_fixed = GridFF("system:ligand-fixed") ligand_fixed = setCLJProperties(ligand_fixed, space) ligand_fixed = setGridProperties(ligand_fixed) ligand_fixed.add(ligand_mols, MGIdx(0)) ligand_fixed.addFixedAtoms( fixed_group ) qm_ligand.addFixedAtoms( fixed_group ) ligand_mm_nrg += ligand_fixed.components().total() ligand_qm_nrg += ligand_fixed.components().lj() forcefields.append(ligand_fixed) ### ### FORCEFIELDS NOT INVOLVING THE LIGAND ### # forcefield holding the intermolecular energy between all molecules mobile_mobile = InterCLJFF("mobile-mobile") mobile_mobile = setCLJProperties(mobile_mobile, space) mobile_mobile.add(mobile_mols) other_nrg = mobile_mobile.components().total() forcefields.append(mobile_mobile) # forcefield holding the energy between the mobile atoms and # the fixed atoms if disable_grid.val: mobile_fixed = InterGroupCLJFF("mobile-fixed") mobile_fixed = setCLJProperties(mobile_fixed) mobile_fixed = setFakeGridProperties(mobile_fixed, space) mobile_fixed.add(mobile_buffered_mols, MGIdx(0)) mobile_fixed.add(fixed_group, MGIdx(1)) other_nrg += mobile_fixed.components().total() forcefields.append(mobile_fixed) else: mobile_fixed = GridFF("mobile-fixed") mobile_fixed = setCLJProperties(mobile_fixed, space) mobile_fixed = setGridProperties(mobile_fixed) # we use mobile_buffered_group as this group misses out atoms that are bonded # to fixed atoms (thus preventing large energies caused by incorrect non-bonded calculations) mobile_fixed.add(mobile_buffered_mols, MGIdx(0)) mobile_fixed.addFixedAtoms(fixed_group) other_nrg += mobile_fixed.components().total() forcefields.append(mobile_fixed) # intramolecular energy of the protein if protein_intra_mols.nMolecules() > 0: protein_intraclj = IntraCLJFF("protein_intraclj") protein_intraclj = setCLJProperties(protein_intraclj, space) protein_intraff = InternalFF("protein_intra") for molnum in protein_intra_mols.molNums(): protein_mol = protein_intra_mols[molnum].join() protein_intraclj.add(protein_mol) protein_intraff.add(protein_mol) other_nrg += protein_intraclj.components().total() other_nrg += protein_intraff.components().total() forcefields.append(protein_intraclj) forcefields.append(protein_intraff) # intramolecular energy of any other solutes if solute_intra_mols.nMolecules() > 0: solute_intraclj = IntraCLJFF("solute_intraclj") solute_intraclj = setCLJProperties(solute_intraclj, space) solute_intraff = InternalFF("solute_intra") for molnum in solute_intra_mols.molNums(): solute_mol = solute_intra_mols[molnum].join() solute_intraclj.add(solute_mol) solute_intraff.add(solute_mol) other_nrg += solute_intraclj.components().total() other_nrg += solute_intraff.components().total() forcefields.append(solute_intraclj) forcefields.append(solute_intraff) ### ### NOW ADD THE FORCEFIELDS TO THE SYSTEM ### ### ### SETTING THE FORCEFIELD EXPRESSIONS ### lam = Symbol("lambda") e_slow = ((1-lam) * ligand_qm_nrg) + (lam * ligand_mm_nrg) + other_nrg e_fast = ligand_mm_nrg + other_nrg de_by_dlam = ligand_mm_nrg - ligand_qm_nrg for forcefield in forcefields: system.add(forcefield) system.setConstant(lam, 0.0) system.setComponent(Symbol("E_{fast}"), e_fast) system.setComponent(Symbol("E_{slow}"), e_slow) system.setComponent(Symbol("dE/dlam"), de_by_dlam) system.setComponent( system.totalComponent(), e_slow ) system.setProperty("space", space) if space.isPeriodic(): # ensure that all molecules are wrapped into the space with the ligand at the center print("Adding in a space wrapper constraint %s, %s" % (space, ligand_mol.evaluate().center())) system.add( SpaceWrapper( ligand_mol.evaluate().center(), all_group ) ) system.applyConstraints() print("\nHere are the values of all of the initial energy components...") t.start() printEnergies(system.energies()) print("(these took %d ms to evaluate)\n" % t.elapsed()) # Create a monitor to monitor the free energy average system.add( "dG/dlam", MonitorComponent(Symbol("dE/dlam"), AverageAndStddev()) ) if intermolecular_only.val: print("\n\n## This simulation uses QM to model *only* the intermolecular energy between") print("## the QM and MM atoms. The intramolecular energy of the QM atoms is still") print("## modelled using MM.\n") else: print("\n\n## This simulation uses QM to model both the intermolecular and intramolecular") print("## energies of the QM atoms. Because the this, we have to adjust the 'zero' point") print("## of the QM potential. You need to add the value %s kcal mol-1 back onto the" % zero_energy) print("## QM->MM free energy calculated using this program.\n") return system
def test_sim(verbose = False): oldsys = System() newsys = System() oldsys.add(mols) newsys.add(mols) oldsys.add(oldff) newsys.add(newff) t = QElapsedTimer() oldsys.mustNowRecalculateFromScratch() newsys.mustNowRecalculateFromScratch() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() oldcnrg = oldsys.energy( oldff.components().coulomb() ).value() oldljnrg = oldsys.energy( oldff.components().lj() ).value() newcnrg = newsys.energy( newff.components().coulomb() ).value() newljnrg = newsys.energy( newff.components().lj() ).value() if verbose: print("\nStarting energy") print("OLD SYS: %s %s %s : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg, 0.000001*oldns)) print("NEW SYS: %s %s %s : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg, 0.000001*newns)) moves = RigidBodyMC(mols) moves.setGenerator( RanGenerator( 42 ) ) moves.enableOptimisedMoves() t.start() moves.move(oldsys, nmoves, False) move_oldns = t.nsecsElapsed() old_naccepted = moves.nAccepted() old_nrejected = moves.nRejected() moves.setGenerator( RanGenerator( 42 ) ) moves.clearStatistics() t.start() moves.move(newsys, nmoves, False) move_newns = t.nsecsElapsed() new_naccepted = moves.nAccepted() new_nrejected = moves.nRejected() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() oldcnrg = oldsys.energy( oldff.components().coulomb() ).value() oldljnrg = oldsys.energy( oldff.components().lj() ).value() newcnrg = newsys.energy( newff.components().coulomb() ).value() newljnrg = newsys.energy( newff.components().lj() ).value() if verbose: print("\nMoves: old %s ms vs. new %s ms" % (0.000001*move_oldns, 0.000001*move_newns)) print("OLD SYS: %s %s %s : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg, 0.000001*oldns)) print("nAccepted() = %s, nRejected() = %s" % (old_naccepted, old_nrejected)) print("NEW SYS: %s %s %s : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg, 0.000001*newns)) print("nAccepted() = %s, nRejected() = %s" % (new_naccepted, new_nrejected)) oldsys.mustNowRecalculateFromScratch() newsys.mustNowRecalculateFromScratch() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() r_oldcnrg = oldsys.energy( oldff.components().coulomb() ).value() r_oldljnrg = oldsys.energy( oldff.components().lj() ).value() r_newcnrg = newsys.energy( newff.components().coulomb() ).value() r_newljnrg = newsys.energy( newff.components().lj() ).value() if verbose: print("\nRecalculated energy") print("OLD SYS: %s %s %s : %s ms" % (r_oldcnrg+r_oldljnrg,r_oldcnrg,r_oldljnrg, 0.000001*oldns)) print("NEW SYS: %s %s %s : %s ms" % (r_newcnrg+r_newljnrg,r_newcnrg,r_newljnrg, 0.000001*newns))
move.setMaximumRotation(5 * degrees) # We now group all of the moves to be performed into a single Moves # object. In this case, a WeightedMoves will draw moves randomly # according to their weight moves = WeightedMoves() moves.add( move, 1 ) # Lets perform 100 moves. The moves are performed on a copy of 'system', # with the updated version of 'system' after the moves returned by this # function print("Running 100 moves...") new_system = moves.move(system, 100, True) # Now lets run a simulation, writing out a PDB trajectory PDB().write(system.molecules(), "output000.pdb") print(system.energies()) # Here we run 10 blocks of 1000 moves, printing out the # energies and a PDB of the coordinates after each block for i in range(1,11): system = moves.move(system, 1000, True) print("%d: %s" % (i, system.energies())) PDB().write(system.molecules(), "output%003d.pdb" % i) # Finally, we print out information about how many moves # were accepted and rejected. print("Move information:") print(moves)
def test_sim(verbose=False): oldsys = System() newsys = System() #oldsys.add(mols) #newsys.add(mols) oldsys.add(oldff) newsys.add(newff) t = QElapsedTimer() oldsys.mustNowRecalculateFromScratch() newsys.mustNowRecalculateFromScratch() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() oldcnrg = oldsys.energy(oldff.components().coulomb()).value() oldljnrg = oldsys.energy(oldff.components().lj()).value() newcnrg = newsys.energy(newff.components().coulomb()).value() newljnrg = newsys.energy(newff.components().lj()).value() if verbose: print("\nStarting energy") print("OLD SYS: %s %s %s : %s ms" % (oldcnrg + oldljnrg, oldcnrg, oldljnrg, 0.000001 * oldns)) print("NEW SYS: %s %s %s : %s ms" % (newcnrg + newljnrg, newcnrg, newljnrg, 0.000001 * newns)) moves = RigidBodyMC(mols) moves.setGenerator(RanGenerator(42)) t.start() moves.move(oldsys, nmoves, False) move_oldns = t.nsecsElapsed() old_naccepted = moves.nAccepted() old_nrejected = moves.nRejected() moves.setGenerator(RanGenerator(42)) moves.clearStatistics() t.start() moves.move(newsys, nmoves, False) move_newns = t.nsecsElapsed() new_naccepted = moves.nAccepted() new_nrejected = moves.nRejected() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() oldcnrg = oldsys.energy(oldff.components().coulomb()).value() oldljnrg = oldsys.energy(oldff.components().lj()).value() newcnrg = newsys.energy(newff.components().coulomb()).value() newljnrg = newsys.energy(newff.components().lj()).value() if verbose: print("\nMoves: %s ms vs. %s ms" % (0.000001 * move_oldns, 0.000001 * move_newns)) print("OLD SYS: %s %s %s : %s ms" % (oldcnrg + oldljnrg, oldcnrg, oldljnrg, 0.000001 * oldns)) print("nAccepted() = %s, nRejected() = %s" % (old_naccepted, old_nrejected)) print("NEW SYS: %s %s %s : %s ms" % (newcnrg + newljnrg, newcnrg, newljnrg, 0.000001 * newns)) print("nAccepted() = %s, nRejected() = %s" % (new_naccepted, new_nrejected)) oldsys.mustNowRecalculateFromScratch() newsys.mustNowRecalculateFromScratch() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() r_oldcnrg = oldsys.energy(oldff.components().coulomb()).value() r_oldljnrg = oldsys.energy(oldff.components().lj()).value() r_newcnrg = newsys.energy(newff.components().coulomb()).value() r_newljnrg = newsys.energy(newff.components().lj()).value() if verbose: print("\nRecalculated energy") print( "OLD SYS: %s %s %s : %s ms" % (r_oldcnrg + r_oldljnrg, r_oldcnrg, r_oldljnrg, 0.000001 * oldns)) print( "NEW SYS: %s %s %s : %s ms" % (r_newcnrg + r_newljnrg, r_newcnrg, r_newljnrg, 0.000001 * newns))
c2 = Sire.Stream.load(data) ms = t.elapsed() print(("Reading the data took %d ms" % ms)) print(c) print(c2) testStream(system) data = Sire.Stream.save(system) print("Probing the system...") print((system.energy())) print((system.energies())) system = Sire.Stream.load(data) print((system.energy())) print((system.energies())) print("\nGetting data info...") t.start() Sire.Stream.save(system, "test/SireStream/tmp_testdata.sire") ms = t.elapsed() print(("Saving a system to a file took %d ms" % ms)) t.start()
def test_sim(verbose = False): oldsys = System() newsys = System() parsys = System() oldsys.add(mols) newsys.add(mols) parsys.add(mols) oldsys.add(newff) newsys.add(newff) parsys.add(parff) t = QElapsedTimer() oldsys.mustNowRecalculateFromScratch() newsys.mustNowRecalculateFromScratch() parsys.mustNowRecalculateFromScratch() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() t.start() nrgs = parsys.energies() parns = t.nsecsElapsed() oldcnrg = oldsys.energy( newff.components().coulomb() ).value() oldljnrg = oldsys.energy( newff.components().lj() ).value() newcnrg = newsys.energy( newff.components().coulomb() ).value() newljnrg = newsys.energy( newff.components().lj() ).value() parcnrg = parsys.energy( parff.components().coulomb() ).value() parljnrg = parsys.energy( parff.components().lj() ).value() if verbose: print("\nStarting energy") print("OLD SYS: %s %s %s : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg, 0.000001*oldns)) print("NEW SYS: %s %s %s : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg, 0.000001*newns)) print("PAR SYS: %s %s %s : %s ms" % (parcnrg+parljnrg,parcnrg,parljnrg, 0.000001*parns)) assert_almost_equal( oldcnrg, newcnrg ) assert_almost_equal( oldljnrg, newljnrg ) assert_almost_equal( parcnrg, newcnrg ) assert_almost_equal( parljnrg, newljnrg ) moves = RigidBodyMC(mols) moves.disableOptimisedMoves() moves.setGenerator( RanGenerator( 42 ) ) optmoves = RigidBodyMC(mols) optmoves.enableOptimisedMoves() optmoves.setGenerator( RanGenerator( 42 ) ) parmoves = RigidBodyMC(mols) parmoves.enableOptimisedMoves() parmoves.setGenerator( RanGenerator( 42 ) ) t.start() moves.move(oldsys, nmoves, False) move_oldns = t.nsecsElapsed() old_naccepted = moves.nAccepted() old_nrejected = moves.nRejected() t.start() optmoves.move(newsys, nmoves, False) move_newns = t.nsecsElapsed() new_naccepted = optmoves.nAccepted() new_nrejected = optmoves.nRejected() t.start() parmoves.move(parsys, nmoves, False) move_parns = t.nsecsElapsed() par_naccepted = parmoves.nAccepted() par_nrejected = parmoves.nRejected() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() t.start() nrgs = parsys.energies() parns = t.nsecsElapsed() oldcnrg = oldsys.energy( newff.components().coulomb() ).value() oldljnrg = oldsys.energy( newff.components().lj() ).value() newcnrg = newsys.energy( newff.components().coulomb() ).value() newljnrg = newsys.energy( newff.components().lj() ).value() parcnrg = parsys.energy( parff.components().coulomb() ).value() parljnrg = parsys.energy( parff.components().lj() ).value() if verbose: print("\nMoves: %s ms vs. %s ms vs. %s ms" % (0.000001*move_oldns, 0.000001*move_newns, 0.000001*move_parns)) print("OLD SYS: %s %s %s : %s ms" % (oldcnrg+oldljnrg,oldcnrg,oldljnrg, 0.000001*oldns)) print("nAccepted() = %s, nRejected() = %s" % (old_naccepted, old_nrejected)) print("NEW SYS: %s %s %s : %s ms" % (newcnrg+newljnrg,newcnrg,newljnrg, 0.000001*newns)) print("nAccepted() = %s, nRejected() = %s" % (new_naccepted, new_nrejected)) print("PAR SYS: %s %s %s : %s ms" % (parcnrg+parljnrg,parcnrg,parljnrg, 0.000001*parns)) print("nAccepted() = %s, nRejected() = %s" % (par_naccepted, par_nrejected)) assert_almost_equal( old_naccepted, new_naccepted ) assert_almost_equal( old_nrejected, new_nrejected ) assert_almost_equal( oldcnrg, newcnrg ) assert_almost_equal( oldljnrg, newljnrg ) assert_almost_equal( par_naccepted, new_naccepted ) assert_almost_equal( par_nrejected, new_nrejected ) assert_almost_equal( parcnrg, newcnrg ) assert_almost_equal( parljnrg, newljnrg ) oldsys.mustNowRecalculateFromScratch() newsys.mustNowRecalculateFromScratch() parsys.mustNowRecalculateFromScratch() t.start() nrgs = oldsys.energies() oldns = t.nsecsElapsed() t.start() nrgs = newsys.energies() newns = t.nsecsElapsed() t.start() nrgs = parsys.energies() parns = t.nsecsElapsed() r_oldcnrg = oldsys.energy( newff.components().coulomb() ).value() r_oldljnrg = oldsys.energy( newff.components().lj() ).value() r_newcnrg = newsys.energy( newff.components().coulomb() ).value() r_newljnrg = newsys.energy( newff.components().lj() ).value() r_parcnrg = parsys.energy( parff.components().coulomb() ).value() r_parljnrg = parsys.energy( parff.components().lj() ).value() if verbose: print("\nRecalculated energy") print("OLD SYS: %s %s %s : %s ms" % (r_oldcnrg+r_oldljnrg,r_oldcnrg,r_oldljnrg, 0.000001*oldns)) print("NEW SYS: %s %s %s : %s ms" % (r_newcnrg+r_newljnrg,r_newcnrg,r_newljnrg, 0.000001*newns)) print("PAR SYS: %s %s %s : %s ms" % (r_parcnrg+r_parljnrg,r_parcnrg,r_parljnrg, 0.000001*parns)) assert_almost_equal( r_oldcnrg, r_newcnrg ) assert_almost_equal( r_oldljnrg, r_newljnrg ) assert_almost_equal( r_parljnrg, r_newljnrg )
swap_swapff = InterCLJFF("swap-swap") swap_swapff.setSpace(Cartesian()) swap_swapff.setSwitchingFunction( HarmonicSwitchingFunction(25*angstrom, 25*angstrom, 10*angstrom, 10*angstrom) ) swap_swapff.add(swapwaters) grid_system.add(swap_swapff) exp_system.add(swap_swapff) grid_system.add(gridff) exp_system.add(cljff) grid_system.setComponent( grid_system.totalComponent(), \ gridff.components().total() + swap_swapff.components().total() ) exp_system.setComponent( exp_system.totalComponent(), \ cljff.components().total() + swap_swapff.components().total() ) print((grid_system.energies())) print((exp_system.energies())) print(("\nGrid energy equals: %s. Explicit energy equals: %s." % \ (grid_system.energy(), exp_system.energy()))) diff = grid_system.energy() - exp_system.energy() print(("The difference is %s\n" % diff)) rbmc = RigidBodyMC(swapwaters) rbmc.setReflectionSphere(center_point, 7.5*angstrom) moves = SameMoves(rbmc) PDB().write(grid_system.molecules(), "test0000.pdb")
swap_swapff = InterCLJFF("swap-swap") swap_swapff.setSpace(Cartesian()) swap_swapff.setSwitchingFunction( HarmonicSwitchingFunction(25*angstrom, 25*angstrom, 10*angstrom, 10*angstrom) ) swap_swapff.add(swapwaters) grid_system.add(swap_swapff) grid_system2.add(swap_swapff) grid_system.add(gridff) grid_system2.add(gridff2) grid_system.setComponent( grid_system.totalComponent(), \ gridff.components().total() + swap_swapff.components().total() ) grid_system2.setComponent( grid_system2.totalComponent(), \ gridff2.components().total() + swap_swapff.components().total() ) print(grid_system.energies()) print(grid_system2.energies()) print("\nOld Grid energy equals: %s. New GridFF energy equals: %s." % \ (grid_system.energy(), grid_system2.energy())) diff = grid_system.energy() - grid_system2.energy() print("The difference is %s\n" % diff) rbmc = RigidBodyMC(swapwaters) rbmc.setReflectionSphere(center_point, 7.5*angstrom) moves = SameMoves(rbmc) PDB().write(grid_system2.molecules(), "test0000.pdb")
system.add(solvent) system.setProperty("space", space) print("Initialising the ions...") titrator.applyTo(system) print("Randomising the location of ions...") titrator.randomiseCharge(3) titrator.applyTo(system) print("System is ready for simulation :-)") PDB().write(system.molecules(), "test0000.pdb") move = TitrationMove() move.setTemperature( 25*celsius ) moves = WeightedMoves() moves.add(move, 1) move = RigidBodyMC(solvent) moves.add(move, 1) print("Start: %s" % system.energies()) for i in range(1,11): system = moves.move(system, 1000, False) print("%5d: %s" % (i, system.energies())) PDB().write(system.molecules(), "test%0004d.pdb" % i) print(moves)
move.setMaximumTranslation(0.5 * angstrom) move.setMaximumRotation(5 * degrees) # We now group all of the moves to be performed into a single Moves # object. In this case, a WeightedMoves will draw moves randomly # according to their weight moves = WeightedMoves() moves.add(move, 1) # Lets perform 100 moves. The moves are performed on a copy of 'system', # with the updated version of 'system' after the moves returned by this # function print("Running 100 moves...") new_system = moves.move(system, 100, True) # Now lets run a simulation, writing out a PDB trajectory PDB().write(system.molecules(), "output000.pdb") print(system.energies()) # Here we run 10 blocks of 1000 moves, printing out the # energies and a PDB of the coordinates after each block for i in range(1, 11): system = moves.move(system, 1000, True) print("%d: %s" % (i, system.energies())) PDB().write(system.molecules(), "output%003d.pdb" % i) # Finally, we print out information about how many moves # were accepted and rejected. print("Move information:") print(moves)