# Print out the energy of the system - note that you must explicitly # state the units you want the energy to be output it, using .to(), # in this case we are using kcal mol-1, so we have .to(kcal_per_mol) print "Block %3d: Energy = %f kcal mol-1" % ( i + 1, system.energy().to(kcal_per_mol)) # Now print out a new PDB of the waters - note that MGName("waters") selects # the molecule group with name 'waters' PDB().write(system[MGName("waters")], "montecarlo_output/output%003d.pdb" % (i + 1)) # Now write out the new XSC file for the simulation box xscfile = open("montecarlo_output/output%003d.xsc" % (i + 1), "w") # the volume is held in the "space" property of the system vol = system.property("space") print "Simulation box: %s" % vol mincoords = vol.minCoords() maxcoords = vol.maxCoords() print >> xscfile, "%f %f %f %f %f %f" % (mincoords[0], mincoords[1], mincoords[2], maxcoords[0], maxcoords[1], maxcoords[2]) xscfile.close() print "Simulation complete!"
sys = System() from Sire.Maths import * box0 = PeriodicBox(Vector(10.0, 10.0, 10.0)) box1 = PeriodicBox(Vector(20.0, 20.0, 20.0)) print(box0) print(box0.volume()) print(box1.volume()) from Sire.MM import * sys.add(InterCLJFF("cljff")) print(sys) print(sys.property("space")) print(sys.userProperties().propertyKeys()) print(sys.builtinProperties().propertyKeys()) sys.setProperty("space0", LinkToProperty("space", FFIdx(0))) print(sys.property("space0")) sys.setProperty("space0", box0) print(sys.property("space")) sys.setProperty("space1", box1) sys.setProperty("combined_space", CombineSpaces("space0", "space1"))
system = sim.system() moves = sim.moves() # Print out the energy of the system - note that you must explicitly # state the units you want the energy to be output it, using .to(), # in this case we are using kcal mol-1, so we have .to(kcal_per_mol) print "Block %3d: Energy = %f kcal mol-1" % (i+1, system.energy().to(kcal_per_mol)) # Now print out a new PDB of the waters - note that MGName("waters") selects # the molecule group with name 'waters' PDB().write( system[MGName("waters")], "montecarlo_output/output%003d.pdb" % (i+1) ) # Now write out the new XSC file for the simulation box xscfile = open("montecarlo_output/output%003d.xsc" % (i+1), "w") # the volume is held in the "space" property of the system vol = system.property("space") print "Simulation box: %s" % vol mincoords = vol.minCoords() maxcoords = vol.maxCoords() print >>xscfile,"%f %f %f %f %f %f" % (mincoords[0], mincoords[1], mincoords[2], maxcoords[0], maxcoords[1], maxcoords[2]) xscfile.close() print "Simulation complete!"
sys = System() from Sire.Maths import * box0 = PeriodicBox( Vector(10.0,10.0,10.0) ) box1 = PeriodicBox( Vector(20.0,20.0,20.0) ) print(box0) print(box0.volume()) print(box1.volume()) from Sire.MM import * sys.add( InterCLJFF("cljff") ) print(sys) print(sys.property("space")) print(sys.userProperties().propertyKeys()) print(sys.builtinProperties().propertyKeys()) sys.setProperty( "space0", LinkToProperty("space", FFIdx(0)) ) print(sys.property("space0")) sys.setProperty("space0", box0) print(sys.property("space")) sys.setProperty("space1", box1) sys.setProperty("combined_space", CombineSpaces("space0", "space1"))
def test_props(verbose=False): sys = System() box0 = PeriodicBox( Vector(10.0,10.0,10.0) ) box1 = PeriodicBox( Vector(20.0,20.0,20.0) ) if verbose: print(box0) print(box0.volume()) print(box1.volume()) assert(not sys.containsProperty("space")) sys.add( InterCLJFF("cljff") ) if verbose: print(sys) print(sys.property("space")) print(sys.userProperties().propertyKeys()) print(sys.builtinProperties().propertyKeys()) assert(sys.containsProperty("space")) assert_equal( sys.property("space"), Cartesian() ) sys.setProperty( "space0", LinkToProperty("space", FFIdx(0)) ) if verbose: print(sys.property("space0")) assert(sys.containsProperty("space0")) sys.setProperty("space0", box0) if verbose: print(sys.property("space")) assert_equal(sys.property("space0"), box0) sys.setProperty("space1", box1) sys.setProperty("combined_space", CombineSpaces("space0", "space1")) assert_equal(sys.property("space1"), box1) if verbose: print(sys.properties().propertyKeys()) print(sys.property("combined_space")) print(sys.property("combined_space").volume()) assert_almost_equal( sys.property("combined_space").volume().value(), sys.property("space0").volume().value() + sys.property("space1").volume().value(), 5 ) space3 = PeriodicBox( Vector(5,5,5) ) sys.setProperty("space0", space3) assert_equal( sys.property("space0"), space3 ) if verbose: print(sys.property("combined_space")) print(sys.property("combined_space").volume()) assert_almost_equal( sys.property("combined_space").volume().value(), sys.property("space0").volume().value() + sys.property("space1").volume().value(), 5 ) sys.removeProperty("space0") if verbose: print(sys.properties().propertyKeys()) assert( not sys.containsProperty("space0") )
else: na = na.edit().renumber() \ .setProperty("coordinates", AtomCoords([coords]) ) \ .commit() salt.add(na) add_cl = True cljff = InterCLJFF("salt-salt") cljff.add(salt) system = System() system.add(salt) system.add(cljff) t.start() print("Initial energy = %s" % system.energy()) print("(took %d ms)" % t.elapsed()) hmcmove = HybridMC(salt, 100) print(system.property("space")) for i in range(0, 250): print("\nmove %d" % (i + 1)) hmcmove.move(system, 1) print(system.energy()) PDB().write(system.molecules(), "test%0004d.pdb" % i)
def makeSim(system, ligand_mol, watersys): """Create simulation systems with and without the ligand and return those systems together with the moves""" stage1 = System("with_ligand") stage2 = System("without_ligand") if system.containsProperty("reflection center"): reflection_center = system.property("reflection center").toVector()[0] reflection_radius = float( str(system.property("reflection sphere radius"))) stage1.setProperty("reflection center", AtomCoords(CoordGroup(1, reflection_center))) stage1.setProperty("reflection sphere radius", VariantProperty(reflection_radius)) stage2.setProperty("reflection center", AtomCoords(CoordGroup(1, reflection_center))) stage2.setProperty("reflection sphere radius", VariantProperty(reflection_radius)) # create a molecule group for fixed atoms (everything except the mobile water) fixed_group = MoleculeGroup("fixed") if MGName("fixed_molecules") in system.mgNames(): fixed_group.add(system[MGName("fixed_molecules")]) if MGName("mobile_solutes") in system.mgNames(): fixed_group.add(system[MGName("mobile_solutes")]) if MGName("protein_sidechains") in system.mgNames() or \ MGName("protein_backbones") in system.mgNames(): all_proteins = Molecules() try: protein_sidechains = system[MGName("protein_sidechains")] all_proteins.add(protein_sidechains.molecules()) except: pass try: protein_backbones = system[MGName("protein_backbones")] all_proteins.add(protein_backbones.molecules()) except: pass try: boundary_molecules = system[MGName("boundary_molecules")] all_proteins.add(boundary_molecules.molecules()) except: pass for molnum in all_proteins.molNums(): protein_mol = Molecule.join(all_proteins[molnum]) fixed_group.add(protein_mol) stage1_fixed_group = MoleculeGroup(fixed_group) stage2_fixed_group = MoleculeGroup(fixed_group) stage1_fixed_group.add(ligand_mol) stage2_fixed_group.remove(ligand_mol) mobile_group = MoleculeGroup("mobile_group") if MGName("mobile_solvents") in system.mgNames(): mobile_group.add(system[MGName("mobile_solvents")]) stage1_mobile_group = MoleculeGroup(mobile_group) stage2_mobile_group = MoleculeGroup(mobile_group) # now find water molecules from the water system that can be substituted for the ligand watermols = findOverlappingWaters(ligand_mol, watersys) stage2_mobile_group.add(watermols) print("The number of stage 1 fixed non-solvent molecules is %d." % stage1_fixed_group.nMolecules()) print("The number of stage 1 mobile solvent molecules is %d." % stage1_mobile_group.nMolecules()) print("The number of stage 2 fixed non-solvent molecules is %d." % stage2_fixed_group.nMolecules()) print("The number of stage 2 mobile solvent molecules is %d." % stage2_mobile_group.nMolecules()) # write a PDB of all of the fixed molecules PDB().write(stage1_mobile_group, "stage1_mobile_atoms.pdb") PDB().write(stage2_mobile_group, "stage2_mobile_atoms.pdb") PDB().write(stage1_fixed_group, "stage1_fixed_atoms.pdb") PDB().write(stage2_fixed_group, "stage2_fixed_atoms.pdb") # create the forcefields if use_fast_ff.val: stage1_ff = InterFF("ff") stage2_ff = InterFF("ff") stage1_ff.setCLJFunction( CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val)) stage2_ff.setCLJFunction( CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val)) if disable_grid.val: stage1_ff.disableGrid() stage2_ff.disableGrid() else: stage1_ff.enableGrid() stage1_ff.setGridSpacing(grid_spacing.val) stage1_ff.setGridBuffer(grid_buffer.val) stage2_ff.enableGrid() stage2_ff.setGridSpacing(grid_spacing.val) stage2_ff.setGridBuffer(grid_buffer.val) stage1_ff.add(stage1_mobile_group) stage1_ff.setFixedAtoms(stage1_fixed_group.molecules()) stage2_ff.add(stage2_mobile_group) stage2_ff.setFixedAtoms(stage2_fixed_group.molecules()) stage1.add(stage1_ff) stage1.setComponent(stage1.totalComponent(), stage1_ff.components().total()) stage2.add(stage1_ff) stage2.setComponent(stage2.totalComponent(), stage2_ff.components().total()) else: # forcefield holding the energy between the mobile atoms and # the fixed atoms if disable_grid.val: stage1_mobile_fixed = InterGroupCLJFF("mobile-fixed") stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed) stage1_mobile_fixed = setFakeGridProperties(stage1_mobile_fixed) stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0)) stage1_mobile_fixed.add(stage1_fixed_group, MGIdx(1)) stage2_mobile_fixed = InterGroupCLJFF("mobile-fixed") stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed) stage2_mobile_fixed = setFakeGridProperties(stage2_mobile_fixed) stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0)) stage2_mobile_fixed.add(stage2_fixed_group, MGIdx(1)) else: stage1_mobile_fixed = GridFF2("mobile-fixed") stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed) stage1_mobile_fixed = setGridProperties(stage1_mobile_fixed) stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0)) stage1_mobile_fixed.addFixedAtoms(stage1_fixed_group) stage2_mobile_fixed = GridFF2("mobile-fixed") stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed) stage2_mobile_fixed = setGridProperties(stage2_mobile_fixed) stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0)) stage2_mobile_fixed.addFixedAtoms(stage2_fixed_group) # forcefield holding the energy between fixed atoms stage1_mobile_mobile = InterCLJFF("mobile-mobile") stage1_mobile_mobile = setCLJProperties(stage1_mobile_mobile) stage1_mobile_mobile.add(stage1_mobile_group) stage2_mobile_mobile = InterCLJFF("mobile-mobile") stage2_mobile_mobile = setCLJProperties(stage2_mobile_mobile) stage2_mobile_mobile.add(stage2_mobile_group) stage1.add(stage1_mobile_group) stage1.add(stage1_mobile_fixed) stage1.add(stage1_mobile_mobile) stage2.add(stage2_mobile_group) stage2.add(stage2_mobile_fixed) stage2.add(stage2_mobile_mobile) stage1.setComponent( stage1.totalComponent(), stage1_mobile_mobile.components().total() + stage1_mobile_fixed.components().total()) stage2.setComponent( stage2.totalComponent(), stage2_mobile_mobile.components().total() + stage2_mobile_fixed.components().total()) stage1.add(stage1_mobile_group) stage2.add(stage2_mobile_group) stage1.add("volume_map", VolMapMonitor(stage1_mobile_group), 1000) stage2.add("volume_map", VolMapMonitor(stage2_mobile_group), 1000) max_water_translation = 0.15 * angstroms max_water_rotation = 15 * degrees stage1_moves = WeightedMoves() if stage1_mobile_group.nViews() > 0: rb_moves = RigidBodyMC(stage1_mobile_group) rb_moves.setMaximumTranslation(max_water_translation) rb_moves.setMaximumRotation(max_water_rotation) if stage1.containsProperty("reflection sphere radius"): reflection_radius = float( str(stage1.property("reflection sphere radius"))) * angstroms reflection_center = stage1.property( "reflection center").toVector()[0] rb_moves.setReflectionSphere(reflection_center, reflection_radius) stage1_moves.add(rb_moves, stage1_mobile_group.nViews()) stage2_moves = WeightedMoves() if stage2_mobile_group.nViews() > 0: rb_moves = RigidBodyMC(stage2_mobile_group) rb_moves.setMaximumTranslation(max_water_translation) rb_moves.setMaximumRotation(max_water_rotation) if stage2.containsProperty("reflection sphere radius"): reflection_radius = float( str(stage2.property("reflection sphere radius"))) * angstroms reflection_center = stage2.property( "reflection center").toVector()[0] rb_moves.setReflectionSphere(reflection_center, reflection_radius) stage2_moves.add(rb_moves, stage2_mobile_group.nViews()) stage1_moves.setTemperature(temperature.val) stage2_moves.setTemperature(temperature.val) seed = random_seed.val if seed is None: seed = RanGenerator().randInt(100000, 1000000) print("Using generated random number seed %d" % seed) else: print("Using supplied random number seed %d" % seed) stage1_moves.setGenerator(RanGenerator(seed)) stage2_moves.setGenerator(RanGenerator(seed + 7)) return ((stage1, stage1_moves), (stage2, stage2_moves))
do_mc = False intra_mcmove = InternalMove(salt) inter_mcmove = RigidBodyMC(salt) mcmove = WeightedMoves() mcmove.add(intra_mcmove) mcmove.add(inter_mcmove) do_mc = False hmcmove = HybridMC(salt, 4*femtosecond, 20) do_hmc = True do_hmc = False print(system.property("space")) print("\nMove 0") print(system.energy()) print(mdmove.kineticEnergy()) print(system.energy() + mdmove.kineticEnergy()) PDB().write(system.molecules(), "test%0004d.pdb" % 0) if do_mc: for i in range(1,1000): system = mcmove.move(system, 20, False) print(i, system.energy()) PDB().write(system.molecules(), "test%0004d.pdb" % i)
solvent.add(mol) cljff.add(mol) ms = t.elapsed() print("Parameterised all of the water molecules (in %d ms)!" % ms) system = System() system.add(solvent) system.add(cljff) t.start() print("Initial energy = %s" % system.energy()) print("(took %d ms)" % t.elapsed()) print(system.property("space")) print(system.property("switchingFunction")) print(system.groupNumbers()) print(system.groupNames()) print(system.energies()) mc = RigidBodyMC(solvent) moves = SameMoves(mc) moves.setGenerator( RanGenerator(42) ) print("Running 10000 moves without saving the trajectory...") t.start() system = moves.move(system, 10000, True)
def makeSim(system, ligand_mol, watersys): """Create simulation systems with and without the ligand and return those systems together with the moves""" stage1 = System("with_ligand") stage2 = System("without_ligand") if system.containsProperty("reflection center"): reflection_center = system.property("reflection center").toVector()[0] reflection_radius = float(str(system.property("reflection sphere radius"))) stage1.setProperty("reflection center", AtomCoords(CoordGroup(1,reflection_center))) stage1.setProperty("reflection sphere radius", VariantProperty(reflection_radius)) stage2.setProperty("reflection center", AtomCoords(CoordGroup(1,reflection_center))) stage2.setProperty("reflection sphere radius", VariantProperty(reflection_radius)) # create a molecule group for fixed atoms (everything except the mobile water) fixed_group = MoleculeGroup("fixed") if MGName("fixed_molecules") in system.mgNames(): fixed_group.add( system[ MGName("fixed_molecules") ] ) if MGName("mobile_solutes") in system.mgNames(): fixed_group.add( system[MGName("mobile_solutes")] ) if MGName("protein_sidechains") in system.mgNames() or \ MGName("protein_backbones") in system.mgNames(): all_proteins = Molecules() try: protein_sidechains = system[MGName("protein_sidechains")] all_proteins.add(protein_sidechains.molecules()) except: pass try: protein_backbones = system[MGName("protein_backbones")] all_proteins.add(protein_backbones.molecules()) except: pass try: boundary_molecules = system[MGName("boundary_molecules")] all_proteins.add(boundary_molecules.molecules()) except: pass for molnum in all_proteins.molNums(): protein_mol = all_proteins[molnum].join() fixed_group.add(protein_mol) stage1_fixed_group = MoleculeGroup(fixed_group) stage2_fixed_group = MoleculeGroup(fixed_group) stage1_fixed_group.add(ligand_mol) stage2_fixed_group.remove(ligand_mol) mobile_group = MoleculeGroup("mobile_group") if MGName("mobile_solvents") in system.mgNames(): mobile_group.add( system[MGName("mobile_solvents")] ) stage1_mobile_group = MoleculeGroup(mobile_group) stage2_mobile_group = MoleculeGroup(mobile_group) # now find water molecules from the water system that can be substituted for the ligand watermols = findOverlappingWaters(ligand_mol, watersys) stage2_mobile_group.add(watermols) print("The number of stage 1 fixed non-solvent molecules is %d." % stage1_fixed_group.nMolecules()) print("The number of stage 1 mobile solvent molecules is %d." % stage1_mobile_group.nMolecules()) print("The number of stage 2 fixed non-solvent molecules is %d." % stage2_fixed_group.nMolecules()) print("The number of stage 2 mobile solvent molecules is %d." % stage2_mobile_group.nMolecules()) # write a PDB of all of the fixed molecules PDB().write(stage1_mobile_group, "stage1_mobile_atoms.pdb") PDB().write(stage2_mobile_group, "stage2_mobile_atoms.pdb") PDB().write(stage1_fixed_group, "stage1_fixed_atoms.pdb") PDB().write(stage2_fixed_group, "stage2_fixed_atoms.pdb") # create the forcefields if use_fast_ff.val: stage1_ff = InterFF("ff") stage2_ff = InterFF("ff") stage1_ff.setCLJFunction( CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val) ) stage2_ff.setCLJFunction( CLJShiftFunction(Cartesian(), coul_cutoff.val, lj_cutoff.val) ) if disable_grid.val: stage1_ff.disableGrid() stage2_ff.disableGrid() else: stage1_ff.enableGrid() stage1_ff.setGridSpacing(grid_spacing.val) stage1_ff.setGridBuffer(grid_buffer.val) stage2_ff.enableGrid() stage2_ff.setGridSpacing(grid_spacing.val) stage2_ff.setGridBuffer(grid_buffer.val) stage1_ff.add(stage1_mobile_group) stage1_ff.setFixedAtoms(stage1_fixed_group.molecules()) stage2_ff.add(stage2_mobile_group) stage2_ff.setFixedAtoms(stage2_fixed_group.molecules()) stage1.add(stage1_ff) stage1.setComponent(stage1.totalComponent(), stage1_ff.components().total()) stage2.add(stage1_ff) stage2.setComponent(stage2.totalComponent(), stage2_ff.components().total()) else: # forcefield holding the energy between the mobile atoms and # the fixed atoms if disable_grid.val: stage1_mobile_fixed = InterGroupCLJFF("mobile-fixed") stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed) stage1_mobile_fixed = setFakeGridProperties(stage1_mobile_fixed) stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0)) stage1_mobile_fixed.add(stage1_fixed_group, MGIdx(1)) stage2_mobile_fixed = InterGroupCLJFF("mobile-fixed") stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed) stage2_mobile_fixed = setFakeGridProperties(stage2_mobile_fixed) stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0)) stage2_mobile_fixed.add(stage2_fixed_group, MGIdx(1)) else: stage1_mobile_fixed = GridFF("mobile-fixed") stage1_mobile_fixed = setCLJProperties(stage1_mobile_fixed) stage1_mobile_fixed = setGridProperties(stage1_mobile_fixed) stage1_mobile_fixed.add(stage1_mobile_group, MGIdx(0)) stage1_mobile_fixed.addFixedAtoms(stage1_fixed_group) stage2_mobile_fixed = GridFF("mobile-fixed") stage2_mobile_fixed = setCLJProperties(stage2_mobile_fixed) stage2_mobile_fixed = setGridProperties(stage2_mobile_fixed) stage2_mobile_fixed.add(stage2_mobile_group, MGIdx(0)) stage2_mobile_fixed.addFixedAtoms(stage2_fixed_group) # forcefield holding the energy between fixed atoms stage1_mobile_mobile = InterCLJFF("mobile-mobile") stage1_mobile_mobile = setCLJProperties(stage1_mobile_mobile) stage1_mobile_mobile.add(stage1_mobile_group) stage2_mobile_mobile = InterCLJFF("mobile-mobile") stage2_mobile_mobile = setCLJProperties(stage2_mobile_mobile) stage2_mobile_mobile.add(stage2_mobile_group) stage1.add(stage1_mobile_group) stage1.add(stage1_mobile_fixed) stage1.add(stage1_mobile_mobile) stage2.add(stage2_mobile_group) stage2.add(stage2_mobile_fixed) stage2.add(stage2_mobile_mobile) stage1.setComponent(stage1.totalComponent(), stage1_mobile_mobile.components().total() + stage1_mobile_fixed.components().total()) stage2.setComponent(stage2.totalComponent(), stage2_mobile_mobile.components().total() + stage2_mobile_fixed.components().total()) stage1.add(stage1_mobile_group) stage2.add(stage2_mobile_group) stage1.add("volume_map", VolMapMonitor(stage1_mobile_group), 1000) stage2.add("volume_map", VolMapMonitor(stage2_mobile_group), 1000) max_water_translation = 0.15 * angstroms max_water_rotation = 15 * degrees stage1_moves = WeightedMoves() if stage1_mobile_group.nViews() > 0: rb_moves = RigidBodyMC(stage1_mobile_group) rb_moves.setMaximumTranslation(max_water_translation) rb_moves.setMaximumRotation(max_water_rotation) if stage1.containsProperty("reflection sphere radius"): reflection_radius = float(str(stage1.property("reflection sphere radius"))) * angstroms reflection_center = stage1.property("reflection center").toVector()[0] rb_moves.setReflectionSphere(reflection_center, reflection_radius) stage1_moves.add(rb_moves, stage1_mobile_group.nViews()) stage2_moves = WeightedMoves() if stage2_mobile_group.nViews() > 0: rb_moves = RigidBodyMC(stage2_mobile_group) rb_moves.setMaximumTranslation(max_water_translation) rb_moves.setMaximumRotation(max_water_rotation) if stage2.containsProperty("reflection sphere radius"): reflection_radius = float(str(stage2.property("reflection sphere radius"))) * angstroms reflection_center = stage2.property("reflection center").toVector()[0] rb_moves.setReflectionSphere(reflection_center, reflection_radius) stage2_moves.add(rb_moves, stage2_mobile_group.nViews()) stage1_moves.setTemperature(temperature.val) stage2_moves.setTemperature(temperature.val) seed = random_seed.val if seed is None: seed = RanGenerator().randInt(100000,1000000) print("Using generated random number seed %d" % seed) else: print("Using supplied random number seed %d" % seed) stage1_moves.setGenerator( RanGenerator(seed) ) stage2_moves.setGenerator( RanGenerator(seed+7) ) return ( (stage1,stage1_moves), (stage2,stage2_moves) )