Exemple #1
0
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))
Exemple #2
0
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") )
Exemple #3
0
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) )