Esempio n. 1
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues', 'tests/data/TOL-parm.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/TOL-parm.inpcrd')
        structure = parmed.load_file(prmtop, xyz=inpcrd)

        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' : 'PME', 'nonbondedCutoff': 10, 'constraints': 'HBonds',
                'trajectory_interval' : 10, 'reporter_interval' : 10,
                'platform' : None, 'outfname' : 'smartdart-test',
                'verbose' : False }


        #Initialize the SmartDartMove object
        self.move = SmartDartMove(structure,
            basis_particles=[100, 110, 150],
            coord_files = [inpcrd, inpcrd], topology=prmtop,
            self_dart=False, resname='LIG', )
        self.engine = MoveEngine(self.move)
        self.engine.selectMove()
        #Initialize the SimulationFactory object
        sims = SimulationFactory(structure, self.engine, **self.opt)
        system = sims.generateSystem(structure, **self.opt)
        alch_system = sims.generateAlchSystem(system, self.atom_indices)
        self.nc_sim = sims.generateSimFromStruct(structure, self.engine, alch_system, ncmc=True, **self.opt)

        self.initial_positions = self.nc_sim.context.getState(getPositions=True).getPositions(asNumpy=True)
Esempio n. 2
0
class DartLoaderTester(unittest.TestCase):
    """
    Test if darts are made successfully
    using SmartDartMove.dartsFromParmEd.
    """
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues', 'tests/data/TOL-parm.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/TOL-parm.inpcrd')
        structure = parmed.load_file(prmtop, xyz=inpcrd)

        self.atom_indices = utils.atomIndexfromTop('LIG', structure.topology)

        #Initialize the SmartDartMove object
        self.move = SmartDartMove(
            structure,
            basis_particles=[100, 110, 150],
            coord_files=[inpcrd, inpcrd],
            topology=prmtop,
            self_dart=False,
            resname='LIG',
        )
        self.engine = MoveEngine(self.move)
        self.engine.selectMove()

        self.system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }
        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(systems, self.engine, self.cfg)
        self.ncmc_sim = sims.ncmc

        self.initial_positions = self.ncmc_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)

    def test_dartsFromParmEd(self):
        #load files to see if there are any errors
        prmtop = utils.get_data_filename('blues', 'tests/data/TOL-parm.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/TOL-parm.inpcrd')
        self.move.dartsFromParmEd(coord_files=[inpcrd], topology=prmtop)
Esempio n. 3
0
class RandomRotationTester(unittest.TestCase):
    """
    Test the RandomLigandRotationMove class.
    """
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues', 'tests/data/TOL-parm.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/TOL-parm.inpcrd')
        structure = parmed.load_file(prmtop, xyz=inpcrd)

        self.atom_indices = utils.atomIndexfromTop('LIG', structure.topology)

        #Initialize the Move object
        self.move = RandomLigandRotationMove(structure, 'LIG', 3134)
        self.engine = MoveEngine(self.move)
        self.engine.selectMove()

        self.system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }
        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,
            'nprop': 1,
            'nIter': 1,
            'nstepsMD': 1,
            '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)'
            }
        }
        self.simulations = SimulationFactory(systems, self.engine, self.cfg)
        self.ncmc_sim = self.simulations.ncmc
        self.initial_positions = self.ncmc_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)

    def test_random_rotation(self):
        before_move = self.simulations.ncmc.context.getState(
            getPositions=True).getPositions(asNumpy=True)[self.atom_indices, :]
        self.simulations.ncmc.context = self.engine.runEngine(
            self.simulations.ncmc.context)
        after_move = self.simulations.ncmc.context.getState(
            getPositions=True).getPositions(asNumpy=True)[self.atom_indices, :]

        #Check that the ligand has been rotated
        pos_compare = np.not_equal(before_move, after_move).all()
        self.assertTrue(pos_compare)
Esempio n. 4
0
    def test_simulationRun(self):
        """Tests the Simulation.runNCMC() function"""
        self.opt = { 'temperature' : 300.0, 'friction' : 1, 'dt' : 0.002,
                'nIter' : 2, 'nstepsNC' : 100, 'nstepsMD' : 2, 'nprop' : 1,
                'nonbondedMethod' : 'NoCutoff', 'constraints': 'HBonds',
                'trajectory_interval' : 1, 'reporter_interval' : 1, 'outfname' : 'blues-test',
                'platform' : None, 'write_move' : False}

        testsystem = testsystems.AlanineDipeptideVacuum(constraints=None)
        structure = parmed.openmm.topsystem.load_topology(topology=testsystem.topology,
                                            system=testsystem.system,
                                            xyz=testsystem.positions,
                                            )

        self.model = RandomLigandRotationMove(structure, resname='ALA')
        self.model.atom_indices = range(22)
        self.model.topology = structure.topology
        self.model.positions = structure.positions
        self.model.calculateProperties()
        self.mover = MoveEngine(self.model)
        #Initialize the SimulationFactory object
        sims = SimulationFactory(structure, self.mover, **self.opt)
        #print(sims)
        system = sims.generateSystem(structure, **self.opt)
        simdict = sims.createSimulationSet()
        alch_system = sims.generateAlchSystem(system, self.model.atom_indices)
        self.nc_sim = sims.generateSimFromStruct(structure, self.mover, alch_system, ncmc=True, **self.opt)
        self.model.calculateProperties()
        self.initial_positions = self.nc_sim.context.getState(getPositions=True).getPositions(asNumpy=True)
        asim = Simulation(sims, self.mover, **self.opt)
        asim.run(self.opt['nIter'])
def rotmove_cuda(yaml_file):
    # Parse a YAML configuration, return as Dict
    cfg = Settings('rotmove_cuda.yaml').asDict()
    structure = cfg['Structure']

    #Select move type
    ligand = RandomLigandRotationMove(structure, 'MOL')
    #Iniitialize object that selects movestep
    ligand_mover = MoveEngine(ligand)

    #Generate the openmm.Systems outside SimulationFactory to allow modifications
    systems = SystemFactory(structure, ligand.atom_indices, cfg['system'])

    #Freeze atoms in the alchemical system to speed up alchemical calculation
    cfg['freeze'] = { 'freeze_distance' : 12 ,
                      'freeze_center' : ':MOL',
                      'freeze_solvent': ':HOH,NA,CL'}

    systems.alch = systems.freeze_radius(structure, systems.alch, **cfg['freeze'])

    #Generate the OpenMM Simulations
    simulations = SimulationFactory(systems, ligand_mover, cfg['simulation'], cfg['md_reporters'],
                                    cfg['ncmc_reporters'])

    # Run BLUES Simulation
    blues = BLUESSimulation(simulations, cfg['simulation'])
    blues.run()
Esempio n. 6
0
def runNCMC(platform_name, nstepsNC, nprop, outfname):

    #Generate the ParmEd Structure
    prmtop = '../../complex_wat.prmtop'
    inpcrd = '../../ligand1.equi.rst'

    struct = parmed.load_file(prmtop, xyz=inpcrd)
    print('Structure: %s' % struct.topology)

    nstepsNC = 1000

    #Define some options
    opt = { 'temperature' : 300.0, 'friction' : 1, 'dt' : 0.002,
            'nIter' : 5000, 'nstepsNC' : nstepsNC, 'nstepsMD' : 1000, 'nprop' : nprop,
            'nonbondedMethod' : 'PME', 'nonbondedCutoff': 10,
            'constraints': 'HBonds', 'freeze_distance' : 5.0,
            'trajectory_interval' : 1000, 'reporter_interval' : 1000,
            'ncmc_traj' : False, 'write_move' : False,
            'platform' : platform_name,
            'outfname' : 'gmx', 'NPT' : False,
            'verbose' : False}



    #Define the 'model' object we are perturbing here.
    # Calculate particle masses of object to be moved
    resname = "LIG"
    dihedral_atoms = ["C10", "C9", "C3", "C2" ]
    alch_list = ['C9', 'H92', 'H93', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'H1', 'H2', 'H4', 'H5', 'H6']
    ligand = RotatableBondNoMove(struct, prmtop, inpcrd, dihedral_atoms, alch_list, resname)

    # Initialize object that proposes moves.
    ligand_mover = MoveEngine(ligand)

    # Generate the MD, NCMC, ALCHEMICAL Simulation objects
    simulations = SimulationFactory(struct, ligand_mover, **opt)
    simulations.createSimulationSet()

    # Add reporters to MD simulation.
    #traj_reporter = openmm.app.DCDReporter(outfname+'-nc{}.dcd'.format(nstepsNC), opt['trajectory_interval'])
    progress_reporter = openmm.app.StateDataReporter(sys.stdout, separator="\t",
                                reportInterval=opt['reporter_interval'],
                                step=True, totalSteps=opt['nIter']*opt['nstepsMD'],
                                time=True, speed=True, progress=True, remainingTime=True)
    #simulations.md.reporters.append(traj_reporter)
    simulations.md.reporters.append(progress_reporter)
    netcdf_reporter = NetCDFReporter('gmx.nc', 500, crds=True)
    simulations.md.reporters.append(netcdf_reporter)

    # Run BLUES Simulation
    blues = Simulation(simulations, ligand_mover, **opt)
    blues.run(opt['nIter'])

    # saving last restart
    restrt = RestartReporter('blues.rst', 1, struct.ptr('natom') );
    state = simulations.md.context.getState(getPositions=True, getEnergy=True, getVelocities=True, enforcePeriodicBox=True)
    restrt.report(simulations.md, state)
Esempio n. 7
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)
Esempio n. 8
0
 def setUp(self):
     testsystem = testsystems.AlanineDipeptideVacuum(constraints=None)
     self.structure = parmed.openmm.topsystem.load_topology(
         topology=testsystem.topology,
         system=testsystem.system,
         xyz=testsystem.positions)
     self.move = RandomLigandRotationMove(self.structure, 'ALA')
     self.engine = MoveEngine(self.move)
     system_cfg = {
         'nonbondedMethod': app.NoCutoff,
         'constraints': app.HBonds
     }
     self.systems = SystemFactory(self.structure, self.move.atom_indices,
                                  system_cfg)
Esempio n. 9
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues',
                                         'tests/data/vacDivaline.prmtop')
        inpcrd = utils.get_data_filename('blues',
                                         'tests/data/vacDivaline.inpcrd')
        self.struct = parmed.load_file(prmtop, xyz=inpcrd)

        self.sidechain = SideChainMove(self.struct, [1])
        self.engine = MoveEngine(self.sidechain)
        self.engine.selectMove()

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

        self.cfg = {
            'dt': 0.002 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 1,
            'nstepsMD': 1,
            'nstepsNC': 4,
            '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)'
            }
        }

        self.simulations = SimulationFactory(self.systems, self.engine,
                                             self.cfg)
Esempio n. 10
0
    def test_simulationfactory(self):
        #Initialize the SimulationFactory object
        move = RandomLigandRotationMove(self.full_struct, 'LIG')
        engine = MoveEngine(move)
        sims = SimulationFactory(self.full_struct, engine, **self.opt)

        system = sims.generateSystem(self.full_struct, **self.opt)
        self.assertIsInstance(system, openmm.System)

        alch_system = sims.generateAlchSystem(system, move.atom_indices)
        self.assertIsInstance(alch_system, openmm.System)

        md_sim = sims.generateSimFromStruct(self.full_struct, engine, system, **self.opt)
        self.assertIsInstance(md_sim, openmm.app.simulation.Simulation)

        nc_sim = sims.generateSimFromStruct(self.full_struct, engine, alch_system, ncmc=True, **self.opt)
        self.assertIsInstance(nc_sim, openmm.app.simulation.Simulation)
Esempio n. 11
0
def runNCMC(platform_name, relaxstepsNC, themdsteps):
    #Define some options

    opt = {
        'temperature': 300.0,
        'friction': 1,
        'dt': 0.002,
        'nIter': 50000,
        'nstepsNC': relaxstepsNC,
        'nstepsMD': themdsteps,
        'nonbondedMethod': 'PME',
        'nonbondedCutoff': 10,
        'constraints': 'HBonds',
        'trajectory_interval': 1000,
        'reporter_interval': 1000,
        'platform': platform_name,
        'verbose': False,
        'write_ncmc': False
    }

    #Generate the ParmEd Structure
    #prmtop = utils.get_data_filename('blues', 'tests/data/eqToluene.prmtop')#
    #inpcrd = utils.get_data_filename('blues', 'tests/data/eqToluene.inpcrd')
    prmtop = '/home/burleyk/projects/sidechain/inputs/watDivaline.prmtop'
    inpcrd = '/home/burleyk/projects/sidechain/inputs/watDivaline.inpcrd'
    struct = parmed.load_file(prmtop, xyz=inpcrd)

    #Define the 'model' object we are perturbing here.
    # Calculate particle masses of object to be moved

    ligand = SideChainMove(struct, [1])

    ligand.atom_indices = ligand.rot_bond_atoms
    # Initialize object that proposes moves.
    ligand_mover = MoveEngine(ligand)

    # Generate the MD, NCMC, ALCHEMICAL Simulation objects
    simulations = SimulationFactory(struct, ligand_mover, **opt)
    simulations.createSimulationSet()

    blues = Simulation(simulations, ligand_mover, **opt)
    #add the reporter here
    blues.md_sim.reporters.append(
        openmm.app.dcdreporter.DCDReporter('accept.dcd', 1000))
    blues.runNCMC()
Esempio n. 12
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues', 'tests/data/vacDivaline.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/vacDivaline.inpcrd')
        self.struct = parmed.load_file(prmtop, xyz=inpcrd)


        #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' : 'PME', 'nonbondedCutoff': 10, 'constraints': 'HBonds',
                'trajectory_interval' : 10, 'reporter_interval' : 10, 'outfname' : 'vacDivaline',
                'platform' : None,
                'verbose' : False }
        self.sidechain = SideChainMove(self.struct, [1])
        self.mover = MoveEngine(self.sidechain)
Esempio n. 13
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)
Esempio n. 14
0
    def setUp(self):
        # Load the waterbox with toluene into a structure.
        self.prmtop = utils.get_data_filename('blues',
                                              'tests/data/TOL-parm.prmtop')
        self.inpcrd = utils.get_data_filename('blues',
                                              'tests/data/TOL-parm.inpcrd')
        self.structure = parmed.load_file(self.prmtop, xyz=self.inpcrd)
        self.atom_indices = utils.atomIndexfromTop('LIG',
                                                   self.structure.topology)

        system_cfg = {
            'nonbondedMethod': app.PME,
            'nonbondedCutoff': 8.0 * unit.angstroms,
            'constraints': app.HBonds
        }
        self.systems = SystemFactory(self.structure, self.atom_indices,
                                     system_cfg)

        move = RandomLigandRotationMove(self.structure, 'LIG')
        self.engine = MoveEngine(move)

        self.simulations = SimulationFactory(self.systems, self.engine)
        self.system = self.simulations._system
Esempio n. 15
0
def runNCMC(platform_name, nstepsNC, nprop, outfname):

    #Generate the ParmEd Structure
    prmtop = utils.get_data_filename('blues', 'tests/data/vacDivaline.prmtop')
    inpcrd = utils.get_data_filename('blues', 'tests/data/vacDivaline.inpcrd')
    struct = parmed.load_file(prmtop, xyz=inpcrd)
    print('Structure: %s' % struct.topology)

    #Define some options
    opt = {
        'temperature': 300.0,
        'friction': 1,
        'dt': 0.004,
        'hydrogenMass': 3.024,
        'nIter': 100,
        'nstepsNC': nstepsNC,
        'nstepsMD': 1000,
        'nprop': nprop,
        'nonbondedMethod': 'PME',
        'nonbondedCutoff': 10,
        'constraints': 'HBonds',
        'trajectory_interval': 100,
        'reporter_interval': 250,
        'ncmc_traj': None,
        'write_move': False,
        'platform': platform_name,
        'outfname': 'vacDivaline',
        'verbose': False
    }
    #Define the 'model' object we are perturbing here.
    # Calculate particle masses of object to be moved
    ligand = SideChainMove(struct, [1])

    # Initialize object that proposes moves.
    ligand_mover = MoveEngine(ligand)

    # Generate the MD, NCMC, ALCHEMICAL Simulation objects
    simulations = SimulationFactory(struct, ligand_mover, **opt)
    simulations.createSimulationSet()

    # Add reporters to MD simulation.
    trajfile = outfname + '-nc{}.dcd'.format(nstepsNC)
    traj_reporter = openmm.app.DCDReporter(trajfile,
                                           opt['trajectory_interval'])
    progress_reporter = openmm.app.StateDataReporter(
        sys.stdout,
        separator="\t",
        reportInterval=opt['reporter_interval'],
        step=True,
        totalSteps=opt['nIter'] * opt['nstepsMD'],
        time=True,
        speed=True,
        progress=True,
        elapsedTime=True,
        remainingTime=True)
    simulations.md.reporters.append(traj_reporter)
    simulations.md.reporters.append(progress_reporter)

    # Run BLUES Simulation
    blues = Simulation(simulations, ligand_mover, **opt)
    blues.run(opt['nIter'])

    #Analysis
    import mdtraj as md
    import numpy as np
    traj = md.load_dcd(trajfile, top='protein.pdb')
    indicies = np.array([[0, 4, 6, 8]])
    dihedraldata = md.compute_dihedrals(traj, indicies)
    with open("dihedrals-%iNC.txt" % (nstepsNC), 'w') as output:
        for value in dihedraldata:
            output.write("%s\n" % str(value)[1:-1])
Esempio n. 16
0
class SideChainTester(unittest.TestCase):
    """
    Test the SmartDartMove.move() function.
    """
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues',
                                         'tests/data/vacDivaline.prmtop')
        inpcrd = utils.get_data_filename('blues',
                                         'tests/data/vacDivaline.inpcrd')
        self.struct = parmed.load_file(prmtop, xyz=inpcrd)

        self.sidechain = SideChainMove(self.struct, [1])
        self.engine = MoveEngine(self.sidechain)
        self.engine.selectMove()

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

        self.cfg = {
            'dt': 0.002 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 1,
            'nstepsMD': 1,
            'nstepsNC': 4,
            '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)'
            }
        }

        self.simulations = SimulationFactory(self.systems, self.engine,
                                             self.cfg)

    def test_getRotBondAtoms(self):
        vals = [v for v in self.sidechain.rot_atoms[1].values()][0]
        self.assertEqual(len(vals), 11)
        #Ensure it selects 1 rotatable bond in Valine
        self.assertEqual(len(self.sidechain.rot_bonds), 1)

    def test_sidechain_move(self):
        atom_indices = [v for v in self.sidechain.rot_atoms[1].values()][0]
        before_move = self.simulations.ncmc.context.getState(
            getPositions=True).getPositions(asNumpy=True)[atom_indices, :]
        self.simulations.ncmc.context = self.engine.runEngine(
            self.simulations.ncmc.context)
        after_move = self.simulations.ncmc.context.getState(
            getPositions=True).getPositions(asNumpy=True)[atom_indices, :]

        #Check that our system has run dynamics
        # Integrator must step for context to update positions
        # Remove the first two atoms in check as these are the anchor atoms and are not rotated.
        pos_compare = np.not_equal(before_move, after_move)[2:, :].all()
        self.assertTrue(pos_compare)
Esempio n. 17
0
    def test_simulationRun(self):
        """Tests the Simulation.runMC() function"""
        self.opt = {
            'temperature': 300.0,
            'friction': 1,
            'dt': 0.00002,
            'nIter': 2,
            'nstepsNC': 2,
            'nstepsMD': 1,
            'nprop': 1,
            'nonbondedMethod': 'NoCutoff',
            'constraints': 'HBonds',
            'trajectory_interval': 1,
            'reporter_interval': 1,
            'outfname': 'mc-test',
            'platform': None,
            'constraints': 'HBonds',
            'mc_per_iter': 2
        }

        structure = self.full_struct

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

            def move(self, context):
                """Function that performs a random rotation about the
                center of mass of the ligand.
                """
                #TODO: check if we need to deepcopy
                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]])

                #set_rotation_matrix = np.array([[1, 0, 0],
                #                                 [0, 1, 0],
                #                                 [0, 0, 1]])

                #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.model = SetRotationMove(structure, resname='ALA')
        #self.model = RandomLigandRotationMove(structure, resname='ALA')

        self.model.atom_indices = range(22)
        self.model.topology = structure[self.model.atom_indices].topology
        self.model.positions = structure[self.model.atom_indices].positions
        self.model.calculateProperties()

        self.mover = MoveEngine(self.model)
        #Initialize the SimulationFactory object
        sims = SimulationFactory(structure, self.mover, **self.opt)
        #print(sims)
        system = sims.generateSystem(structure, **self.opt)
        simdict = sims.createSimulationSet()
        alch_system = sims.generateAlchSystem(system, self.model.atom_indices)
        self.nc_sim = sims.generateSimFromStruct(structure,
                                                 self.mover,
                                                 alch_system,
                                                 ncmc=True,
                                                 **self.opt)
        self.model.calculateProperties()
        self.initial_positions = self.nc_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)
        mc_sim = Simulation(sims, self.mover, **self.opt)

        #monkeypatch to access acceptance value
        def nacceptRejectMC(self, temperature=300, **opt):
            """Function that chooses to accept or reject the proposed move.
            """
            md_state0 = self.current_state['md']['state0']
            md_state1 = self.current_state['md']['state1']
            log_mc = (md_state1['potential_energy'] -
                      md_state0['potential_energy']) * (
                          -1.0 / self.nc_sim.context._integrator.kT)
            randnum = math.log(np.random.random())

            if log_mc > randnum:
                self.accept += 1
                print('MC MOVE ACCEPTED: log_mc {} > randnum {}'.format(
                    log_mc, randnum))
                self.md_sim.context.setPositions(md_state1['positions'])
            else:
                self.reject += 1
                print('MC MOVE REJECTED: log_mc {} < {}'.format(
                    log_mc, randnum))
                self.md_sim.context.setPositions(md_state0['positions'])
            self.log_mc = log_mc
            self.md_sim.context.setVelocitiesToTemperature(
                self.opt['temperature'])

        mc_sim.acceptRejectMC = nacceptRejectMC
        nacceptRejectMC.__get__(mc_sim)
        mc_sim.acceptRejectMC = types.MethodType(nacceptRejectMC, mc_sim)
        mc_sim.runMC(self.opt['nIter'])
        #get log acceptance
        print(mc_sim.log_mc)
        #if mc is working, should be around -24.1
        assert mc_sim.log_mc <= -23.8 and mc_sim.log_mc >= -24.3
Esempio n. 18
0
def runNCMC(platform_name, nstepsNC, nprop, outfname):

    #Generate the ParmEd Structure
    prmtop = utils.get_data_filename('blues', 'tests/data/eqToluene.prmtop')  #
    inpcrd = utils.get_data_filename('blues', 'tests/data/eqToluene.inpcrd')
    struct = parmed.load_file(prmtop, xyz=inpcrd)

    #Define some options
    opt = {
        'temperature': 300.0,
        'friction': 1,
        'dt': 0.002,
        'nIter': 100,
        'nstepsNC': 10000,
        'nstepsMD': 10000,
        'nprop': 1,
        'nonbondedMethod': 'PME',
        'nonbondedCutoff': 10,
        'constraints': 'HBonds',
        'freeze_distance': 5.0,
        'trajectory_interval': 2000,
        'reporter_interval': 1000,
        'write_move': False,
        'platform': platform_name,
        'outfname': 't4-toluene'
    }

    logger = init_logger(logging.getLogger(),
                         level=logging.INFO,
                         outfname=opt['outfname'])
    opt['Logger'] = logger

    #Define the 'model' object we are perturbing here.
    # Calculate particle masses of object to be moved
    ligand = RandomLigandRotationMove(struct, 'LIG')
    ligand.calculateProperties()

    # Initialize object that proposes moves.
    ligand_mover = MoveEngine(ligand)

    # Generate the MD, NCMC, ALCHEMICAL Simulation objects
    simulations = SimulationFactory(struct, ligand_mover, **opt)
    simulations.createSimulationSet()

    # Add reporters to MD simulation.
    traj_reporter = openmm.app.DCDReporter(
        opt['outfname'] + '-nc{}.dcd'.format(nstepsNC),
        opt['trajectory_interval'])
    md_progress_reporter = BLUESStateDataReporter(
        logger,
        separator="\t",
        title='md',
        reportInterval=opt['reporter_interval'],
        step=True,
        totalSteps=opt['nIter'] * opt['nstepsMD'],
        time=False,
        speed=True,
        progress=True,
        remainingTime=True)
    simulations.md.reporters.append(traj_reporter)
    simulations.md.reporters.append(md_progress_reporter)

    # Add reporters to NCMC simulation.
    ncmc_reporter = BLUESHDF5Reporter(file=opt['outfname'] + '-pmoves.h5',
                                      reportInterval=1,
                                      coordinates=True,
                                      frame_indices=[1, opt['nstepsNC']],
                                      time=False,
                                      cell=True,
                                      temperature=False,
                                      potentialEnergy=False,
                                      kineticEnergy=False,
                                      velocities=False,
                                      atomSubset=None,
                                      protocolWork=True,
                                      alchemicalLambda=True,
                                      parameters=opt,
                                      environment=True)
    ncmc_progress_reporter = BLUESStateDataReporter(
        logger,
        separator="\t",
        title='ncmc',
        reportInterval=opt['reporter_interval'],
        step=True,
        totalSteps=opt['nstepsNC'],
        time=False,
        speed=True,
        progress=True,
        remainingTime=True)
    simulations.nc.reporters.append(ncmc_reporter)
    simulations.nc.reporters.append(ncmc_progress_reporter)

    # Run BLUES Simulation
    blues = Simulation(simulations, ligand_mover, **opt)
    blues.run(opt['nIter'])
Esempio n. 19
0
from blues.moves import RandomLigandRotationMove
from blues.engine import MoveEngine
from blues.simulation import *
import json
from blues.settings import *

# Parse a YAML configuration, return as Dict
cfg = Settings('rotmove_cuda.yaml').asDict()
structure = cfg['Structure']

#Select move type
ligand = RandomLigandRotationMove(structure, 'LIG')
#Iniitialize object that selects movestep
ligand_mover = MoveEngine(ligand)

#Generate the openmm.Systems outside SimulationFactory to allow modifications
systems = SystemFactory(structure, ligand.atom_indices, cfg['system'])

#Freeze atoms in the alchemical system to speed up alchemical calculation
systems.alch = systems.freeze_radius(structure, systems.alch, **cfg['freeze'])

#Generate the OpenMM Simulations
simulations = SimulationFactory(systems, ligand_mover, cfg['simulation'],
                                cfg['md_reporters'], cfg['ncmc_reporters'])

# Run BLUES Simulation
blues = BLUESSimulation(simulations, cfg['simulation'])
blues.run()
Esempio n. 20
0
def runNCMC(platform_name, nstepsNC, nprop, outfname):

    #Generate the ParmEd Structure
    prmtop = utils.get_data_filename('blues', 'tests/data/eqToluene.prmtop')  #
    inpcrd = utils.get_data_filename('blues', 'tests/data/eqToluene.inpcrd')
    struct = parmed.load_file(prmtop, xyz=inpcrd)
    print('Structure: %s' % struct.topology)

    #Define some options
    opt = {
        'temperature': 300.0,
        'friction': 1,
        'dt': 0.002,
        'nIter': 100,
        'nstepsNC': nstepsNC,
        'nstepsMD': 5000,
        'nprop': nprop,
        'nonbondedMethod': 'PME',
        'nonbondedCutoff': 10,
        'constraints': 'HBonds',
        'freeze_distance': 5.0,
        'trajectory_interval': 1000,
        'reporter_interval': 1000,
        'ncmc_traj': None,
        'write_move': True,
        'platform': platform_name,
        'outfname': 't4-tol',
        'verbose': False
    }

    #Define the 'model' object we are perturbing here.
    # Calculate particle masses of object to be moved
    ligand = RandomLigandRotationMove(struct, 'LIG')
    ligand.calculateProperties()

    # Initialize object that proposes moves.
    ligand_mover = MoveEngine(ligand)

    # Generate the MD, NCMC, ALCHEMICAL Simulation objects
    simulations = SimulationFactory(struct, ligand_mover, **opt)
    simulations.createSimulationSet()

    # Add reporters to MD simulation.
    traj_reporter = openmm.app.DCDReporter(
        outfname + '-nc{}.dcd'.format(nstepsNC), opt['trajectory_interval'])
    progress_reporter = openmm.app.StateDataReporter(
        sys.stdout,
        separator="\t",
        reportInterval=opt['reporter_interval'],
        step=True,
        totalSteps=opt['nIter'] * opt['nstepsMD'],
        time=True,
        speed=True,
        progress=True,
        remainingTime=True)
    simulations.md.reporters.append(traj_reporter)
    simulations.md.reporters.append(progress_reporter)

    # Run BLUES Simulation
    blues = Simulation(simulations, ligand_mover, **opt)
    blues.run(opt['nIter'])
Esempio n. 21
0
from blues.moves import SideChainMove
from blues.engine import MoveEngine
from blues.simulation import *
import json
from blues.settings import *

# Parse a YAML configuration, return as Dict
cfg = Settings('sidechain_cuda.yaml').asDict()
structure = cfg['Structure']

#Select move type
sidechain = SideChainMove(structure, [1])
#Iniitialize object that selects movestep
sidechain_mover = MoveEngine(sidechain)

#Generate the openmm.Systems outside SimulationFactory to allow modifications
systems = SystemFactory(structure, sidechain.atom_indices, cfg['system'])

#Generate the OpenMM Simulations
simulations = SimulationFactory(systems, sidechain_mover, cfg['simulation'], cfg['md_reporters'],
                                cfg['ncmc_reporters'])

# Run BLUES Simulation
blues = BLUESSimulation(simulations, cfg['simulation'])
blues.run()

#Analysis
import mdtraj as md
import numpy as np

traj = md.load_netcdf('vacDivaline-test/vacDivaline.nc', top='tests/data/vacDivaline.prmtop')
Esempio n. 22
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)