Ejemplo n.º 1
0
def test_get_traj():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 300.0 * unit.kelvin
    T_i = [T_min, T_min * 1.01, T_min * 1.1]
    n_replicas = len(T_i)

    ho = testsystems.AlanineDipeptideExplicit()

    system = ho.system
    positions = ho.positions

    states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ]

    coordinates = [positions] * n_replicas

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations":3}
    replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, mpicomm=mpicomm, parameters=parameters)
    replica_exchange.run()

    db = replica_exchange.database

    prmtop_filename = testsystems.get_data_filename("data/alanine-dipeptide-explicit/alanine-dipeptide.prmtop")
    crd_filename = testsystems.get_data_filename("data/alanine-dipeptide-explicit/alanine-dipeptide.crd")
    trj0 = md.load_restrt(crd_filename, top=prmtop_filename)
    db.set_traj(trj0)

    trj1 = db.get_traj(state_index=0)
    trj2 = db.get_traj(replica_index=0)
Ejemplo n.º 2
0
def test_alchemy():
    import os
    import simtk.unit as unit
    import simtk.openmm as openmm
    import numpy as np
    import simtk.openmm.app as app
    import alchemy

    # Create SystemBuilder objects.
    from openmmtools import testsystems

    receptor_pdb_filename = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit/receptor.pdb")
    ligand_mol2_filename = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit/ligand.tripos.mol2")
    receptor = BiopolymerPDBSystemBuilder(receptor_pdb_filename, pH=7.0)
    ligand = Mol2SystemBuilder(ligand_mol2_filename, charge=0)
    complex = ComplexSystemBuilder(ligand, receptor, remove_ligand_overlap=True)

    timestep = 2 * unit.femtoseconds  # timestep
    temperature = 300.0 * unit.kelvin  # simulation temperature
    collision_rate = 20.0 / unit.picoseconds  # Langevin collision rate
    minimization_tolerance = 10.0 * unit.kilojoules_per_mole / unit.nanometer
    minimization_steps = 20
    plat = "CPU"
    i = 2
    platform = openmm.Platform.getPlatformByName(plat)
    forcefield = app.ForceField
    systembuilders = [ligand, receptor, complex]
    receptor_atoms = complex.receptor_atoms
    ligand_atoms = complex.ligand_atoms
    factory = alchemy.AbsoluteAlchemicalFactory(systembuilders[i].system, ligand_atoms=ligand_atoms)
    protocol = factory.defaultComplexProtocolImplicit()
    systems = factory.createPerturbedSystems(protocol)
    integrator_interacting = openmm.LangevinIntegrator(temperature, collision_rate, timestep)
    # test an alchemical intermediate and an unperturbed system:
    fully_interacting = app.Simulation(systembuilders[i].topology, systems[0], integrator_interacting, platform=plat)
    fully_interacting.context.setPositions(systembuilders[i].positions)
    fully_interacting.minimizeEnergy(tolerance=10 * unit.kilojoule_per_mole)
    fully_interacting.reporters.append(app.PDBReporter("fully_interacting.pdb", 10))
    for j in range(10):
        print str(j)
        fully_interacting.step(100)
    del fully_interacting

    for p in range(1, len(systems)):
        print "now simulating " + str(p)
        integrator_partialinteracting = openmm.LangevinIntegrator(temperature, collision_rate, timestep)
        partially_interacting = app.Simulation(
            systembuilders[i].topology, systems[p], integrator_partialinteracting, platform=plat
        )
        partially_interacting.context.setPositions(systembuilders[i].positions)
        partially_interacting.minimizeEnergy(tolerance=10 * unit.kilojoule_per_mole)
        partially_interacting.reporters.append(app.PDBReporter("partial_interacting" + str(p) + ".pdb", 10))
        for k in range(10):
            print str(k)
            partially_interacting.step(100)
        del partially_interacting
Ejemplo n.º 3
0
def test_alchemy():
    import os
    import simtk.unit as unit
    import simtk.openmm as openmm
    import numpy as np
    import simtk.openmm.app as app
    import alchemy

    # Create SystemBuilder objects.
    from openmmtools import testsystems
    receptor_pdb_filename = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit/receptor.pdb")
    ligand_mol2_filename = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit/ligand.tripos.mol2")
    receptor = BiopolymerPDBSystemBuilder(receptor_pdb_filename, pH=7.0)
    ligand = Mol2SystemBuilder(ligand_mol2_filename, charge=0)
    complex = ComplexSystemBuilder(ligand, receptor, remove_ligand_overlap=True)

    timestep = 2 * unit.femtoseconds # timestep
    temperature = 300.0 * unit.kelvin # simulation temperature
    collision_rate = 20.0 / unit.picoseconds # Langevin collision rate
    minimization_tolerance = 10.0 * unit.kilojoules_per_mole / unit.nanometer
    minimization_steps = 20
    plat = "CPU"
    i=2
    platform = openmm.Platform.getPlatformByName(plat)
    forcefield = app.ForceField
    systembuilders = [ligand, receptor, complex]
    receptor_atoms = complex.receptor_atoms
    ligand_atoms = complex.ligand_atoms
    factory = alchemy.AbsoluteAlchemicalFactory(systembuilders[i].system, ligand_atoms=ligand_atoms)
    protocol = factory.defaultComplexProtocolImplicit()
    systems = factory.createPerturbedSystems(protocol)
    integrator_interacting = openmm.LangevinIntegrator(temperature, collision_rate, timestep)
    #test an alchemical intermediate and an unperturbed system:
    fully_interacting = app.Simulation(systembuilders[i].topology, systems[0], integrator_interacting, platform=plat)
    fully_interacting.context.setPositions(systembuilders[i].positions)
    fully_interacting.minimizeEnergy(tolerance=10*unit.kilojoule_per_mole)
    fully_interacting.reporters.append(app.PDBReporter('fully_interacting.pdb', 10))
    for j in range(10):
        logger.info(str(j))
        fully_interacting.step(100)
    del fully_interacting


    for p in range(1, len(systems)):
        logger.info("now simulating " + str(p))
        integrator_partialinteracting = openmm.LangevinIntegrator(temperature, collision_rate, timestep)
        partially_interacting = app.Simulation(systembuilders[i].topology, systems[p], integrator_partialinteracting, platform=plat)
        partially_interacting.context.setPositions(systembuilders[i].positions)
        partially_interacting.minimizeEnergy(tolerance=10*unit.kilojoule_per_mole)
        partially_interacting.reporters.append(app.PDBReporter('partial_interacting'+str(p)+'.pdb', 10))
        for k in range(10):
            logger.info(str(k))
            partially_interacting.step(100)
        del partially_interacting
Ejemplo n.º 4
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = testsystems.get_data_filename(
            "data/alanine-dipeptide-gbsa/alanine-dipeptide.prmtop")
        inpcrd = testsystems.get_data_filename(
            "data/alanine-dipeptide-gbsa/alanine-dipeptide.crd")
        testsystem = testsystems.AlanineDipeptideVacuum(constraints=None)
        structure = parmed.openmm.topsystem.load_topology(
            topology=testsystem.topology,
            system=testsystem.system,
            xyz=testsystem.positions)

        #Initialize the Model object
        basis_particles = [0, 2, 7]
        self.move = SmartDartMove(structure,
                                  basis_particles=basis_particles,
                                  coord_files=[inpcrd, inpcrd],
                                  topology=prmtop,
                                  resname='ALA',
                                  self_dart=True)
        self.move.atom_indices = range(22)
        self.move.topology = structure.topology
        self.move.positions = structure.positions
        self.move_engine = MoveEngine(self.move)

        self.system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }
        self.systems = SystemFactory(structure, self.move.atom_indices,
                                     self.system_cfg)

        #Initialize the SimulationFactory object
        self.cfg = {
            'dt': 0.002 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 10,
            'nstepsMD': 50,
            'nstepsNC': 10,
            'alchemical_functions': {
                'lambda_sterics':
                'step(0.199999-lambda) + step(lambda-0.2)*step(0.8-lambda)*abs(lambda-0.5)*1/0.3 + step(lambda-0.800001)',
                'lambda_electrostatics':
                'step(0.2-lambda)- 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)'
            }
        }
        sims = SimulationFactory(self.systems, self.move_engine, self.cfg)
        self.ncmc_sim = sims.ncmc
        self.move.calculateProperties()
        self.initial_positions = self.ncmc_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)
Ejemplo n.º 5
0
def test_get_data_filename():
    """Testing retrieval of data files shipped with distro.
    """
    relative_path = 'data/alanine-dipeptide-gbsa/alanine-dipeptide.prmtop'
    filename = testsystems.get_data_filename(relative_path)
    if not os.path.exists(filename):
        raise Exception("Could not locate data files. Expected %s" % relative_path)
Ejemplo n.º 6
0
def test_get_data_filename():
    """Testing retrieval of data files shipped with distro.
    """
    relative_path = 'data/alanine-dipeptide-gbsa/alanine-dipeptide.prmtop'
    filename = testsystems.get_data_filename(relative_path)
    if not os.path.exists(filename):
        raise Exception("Could not locate data files. Expected %s" % relative_path)
Ejemplo n.º 7
0
def test_systembuilder_lysozyme_pdb_mol2():
    # TODO: Ensure we have some way to skip these when OpenEye tools are not installed.
    raise SkipTest

    logger.info("====================================================================")
    logger.info("Creating T4 lysozyme L99A in OBC GBSA from PDB and mol2 with SystemBuilder...")
    # Retrieve receptor and ligand file paths.
    receptor_pdb_filename = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit/receptor.pdb")
    ligand_mol2_filename = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit/ligand.tripos.mol2")
    # Use systembuilder
    from yank.systembuilder import Mol2SystemBuilder, BiopolymerPDBSystemBuilder, ComplexSystemBuilder
    ligand = Mol2SystemBuilder(ligand_mol2_filename)
    receptor = BiopolymerPDBSystemBuilder(receptor_pdb_filename)
    complex = ComplexSystemBuilder(ligand, receptor, remove_ligand_overlap=True)
    # Test alchemically modified systems.
    receptor_atoms = range(0,2603) # T4 lysozyme L99A
    ligand_atoms = range(2603,2621) # p-xylene
    alchemical_factory_check(complex.system, complex.positions, receptor_atoms, ligand_atoms)
    logger.info("====================================================================")
    logger.info("")
Ejemplo n.º 8
0
def test_get_traj():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 300.0 * unit.kelvin
    T_i = [T_min, T_min * 1.01, T_min * 1.1]
    n_replicas = len(T_i)

    ho = testsystems.AlanineDipeptideExplicit()

    system = ho.system
    positions = ho.positions

    states = [
        ThermodynamicState(system=system, temperature=T_i[i])
        for i in range(n_replicas)
    ]

    coordinates = [positions] * n_replicas

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations": 3}
    replica_exchange = ReplicaExchange.create(states,
                                              coordinates,
                                              nc_filename,
                                              mpicomm=mpicomm,
                                              parameters=parameters)
    replica_exchange.run()

    db = replica_exchange.database

    prmtop_filename = testsystems.get_data_filename(
        "data/alanine-dipeptide-explicit/alanine-dipeptide.prmtop")
    crd_filename = testsystems.get_data_filename(
        "data/alanine-dipeptide-explicit/alanine-dipeptide.crd")
    trj0 = md.load_restrt(crd_filename, top=prmtop_filename)
    db.set_traj(trj0)

    trj1 = db.get_traj(state_index=0)
    trj2 = db.get_traj(replica_index=0)
Ejemplo n.º 9
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = testsystems.get_data_filename("data/alanine-dipeptide-gbsa/alanine-dipeptide.prmtop")
        inpcrd = testsystems.get_data_filename("data/alanine-dipeptide-gbsa/alanine-dipeptide.crd")
        testsystem = testsystems.AlanineDipeptideVacuum(constraints=None)
        structure = parmed.openmm.topsystem.load_topology(topology=testsystem.topology,
                                            system=testsystem.system,
                                            xyz=testsystem.positions,
                                            )

        #self.atom_indices = utils.atomIndexfromTop('LIG', structure.topology)
        self.functions = { 'lambda_sterics' : 'step(0.199999-lambda) + step(lambda-0.2)*step(0.8-lambda)*abs(lambda-0.5)*1/0.3 + step(lambda-0.800001)',
                           'lambda_electrostatics' : 'step(0.2-lambda)- 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)' }
        self.opt = { 'temperature' : 300.0, 'friction' : 1, 'dt' : 0.002,
                'nIter' : 10, 'nstepsNC' : 10, 'nstepsMD' : 50,
                'nonbondedMethod' : 'NoCutoff', 'nonbondedCutoff': 10, 'constraints': 'HBonds',
                'trajectory_interval' : 10, 'reporter_interval' : 10, 'outfname' : 'smartdart-test',
                'platform' : None,
                'verbose' : False }


        #Initialize the Model object
        basis_particles = [0,2,7]
        self.move = SmartDartMove(structure, basis_particles=basis_particles,
                                coord_files=[inpcrd, inpcrd],
                                topology=prmtop,
                                resname='ALA', self_dart=True)
        self.move.atom_indices = range(22)
        self.move.topology = structure.topology
        self.move.positions = structure.positions
        self.move_engine = MoveEngine(self.move)

        #Initialize the SimulationFactory object
        sims = SimulationFactory(structure, self.move_engine, **self.opt)
        system = sims.generateSystem(structure, **self.opt)
        alch_system = sims.generateAlchSystem(system, self.move.atom_indices)
        self.nc_sim = sims.generateSimFromStruct(structure, self.move_engine, alch_system, ncmc=True, **self.opt)
        self.move.calculateProperties()
        self.initial_positions = self.nc_sim.context.getState(getPositions=True).getPositions(asNumpy=True)
Ejemplo n.º 10
0
 def setUp(self):
     # Load the waterbox with toluene into a structure.
     self.prmtop = get_data_filename(
         "data/alanine-dipeptide-explicit/alanine-dipeptide.prmtop")
     self.inpcrd = get_data_filename(
         "data/alanine-dipeptide-explicit/alanine-dipeptide.crd")
     self.full_struct = parmed.load_file(self.prmtop, xyz=self.inpcrd)
     self.opt = {
         'temperature': 300.0,
         'friction': 1,
         'dt': 0.00002,
         'nIter': 2,
         'nstepsNC': 4,
         'nstepsMD': 2,
         'nprop': 1,
         'nonbondedMethod': 'PME',
         'nonbondedCutoff': 10,
         'constraints': 'HBonds',
         'trajectory_interval': 1,
         'reporter_interval': 1,
         'outfname': 'mc-test',
         'platform': None
     }
Ejemplo n.º 11
0
def test_setup_binding():
    dirname = testsystems.get_data_filename("data/T4-lysozyme-L99A-implicit")
    storedir = tempfile.mkdtemp()
    run_cli('setup binding amber --setupdir=%(dirname)s --ligname MOL --store %(storedir)s' % vars())
Ejemplo n.º 12
0
    def setUp(self):

        prmtop = testsystems.get_data_filename(
            "data/alanine-dipeptide-explicit/alanine-dipeptide.prmtop")
        inpcrd = testsystems.get_data_filename(
            "data/alanine-dipeptide-explicit/alanine-dipeptide.crd")
        self.structure = parmed.load_file(prmtop, xyz=inpcrd)

        class SetRotationMove(RandomLigandRotationMove):
            def __init__(self, structure, resname='ALA'):
                super(SetRotationMove, self).__init__(structure, resname)

            def move(self, context):
                """Function that performs a random rotation about the
                center of mass of the ligand. Define a set rotation
                for reproducibility
                """
                positions = context.getState(getPositions=True).getPositions(
                    asNumpy=True)

                self.positions = positions[self.atom_indices]
                self.center_of_mass = self.getCenterOfMass(
                    self.positions, self.masses)
                reduced_pos = self.positions - self.center_of_mass

                # Define random rotational move on the ligand
                #set rotation so that test is reproducible
                set_rotation_matrix = np.array(
                    [[-0.62297988, -0.17349253, 0.7627558],
                     [0.55082352, -0.78964857, 0.27027502],
                     [0.55541834, 0.58851973, 0.58749893]])

                #multiply lig coordinates by rot matrix and add back COM translation from origin
                rot_move = np.dot(reduced_pos, set_rotation_matrix
                                  ) * positions.unit + self.center_of_mass

                # Update ligand positions in nc_sim
                for index, atomidx in enumerate(self.atom_indices):
                    positions[atomidx] = rot_move[index]
                context.setPositions(positions)
                positions = context.getState(getPositions=True).getPositions(
                    asNumpy=True)
                self.positions = positions[self.atom_indices]
                return context

        self.move = SetRotationMove(self.structure, resname='ALA')
        self.move.atom_indices = range(22)
        self.move.topology = self.structure[self.move.atom_indices].topology
        self.move.positions = self.structure[self.move.atom_indices].positions
        self.move.calculateProperties()

        self.engine = MoveEngine(self.move)

        system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }

        #self.systems = self.structure.createSystem(**system_cfg)
        self.systems = SystemFactory(self.structure, self.move.atom_indices,
                                     system_cfg)

        mc_rep_cfg = {
            'stream': {
                'title': 'mc',
                'reportInterval': 1,
                'totalSteps': 4,
                'step': True,
                'speed': True,
                'progress': True,
                'remainingTime': True,
                'currentIter': True
            }
        }
        mc_reporters = ReporterConfig('ala-dipep-vac',
                                      mc_rep_cfg).makeReporters()

        cfg = {
            'nprop': 1,
            'dt': 0.000021 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 2,
            'nstepsMD': 1,
            'mc_per_iter': 2
        }
        self.simulations = SimulationFactory(self.systems,
                                             self.engine,
                                             cfg,
                                             md_reporters=mc_reporters)