def test_freeze_radius(self, system_cfg): print('Testing freeze_radius') freeze_cfg = {'freeze_center': ':LIG', 'freeze_solvent': ':Cl-', 'freeze_distance': 3.0 * unit.angstroms} # Setup toluene-T4 lysozyme system 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) atom_indices = utils.atomIndexfromTop('LIG', structure.topology) system = SystemFactory.generateSystem(structure, **system_cfg) # Freeze everything around the binding site frzn_sys = SystemFactory.freeze_radius(structure, system, **freeze_cfg) # Check that the ligand has NOT been frozen lig_masses = [system.getParticleMass(i)._value for i in atom_indices] assert all(m != 0 for m in lig_masses) # Check that the binding site has NOT been frozen selection = "({freeze_center}<:{freeze_distance._value})&!({freeze_solvent})".format(**freeze_cfg) site_idx = SystemFactory.amber_selection_to_atomidx(structure, selection) masses = [frzn_sys.getParticleMass(i)._value for i in site_idx] assert all(m != 0 for m in masses) # Check that the selection has been frozen # Invert that selection to freeze everything but the binding site. freeze_idx = set(range(system.getNumParticles())) - set(site_idx) massless = [frzn_sys.getParticleMass(i)._value for i in freeze_idx] assert all(m == 0 for m in massless)
def test_freeze_radius(self, system_cfg): print('Testing freeze_radius') freeze_cfg = { 'freeze_center': ':LIG', 'freeze_solvent': ':Cl-', 'freeze_distance': 3.0 * unit.angstroms } # Setup toluene-T4 lysozyme system 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) atom_indices = utils.atomIndexfromTop('LIG', structure.topology) system = SystemFactory.generateSystem(structure, **system_cfg) # Freeze everything around the binding site frzn_sys = SystemFactory.freeze_radius(structure, system, **freeze_cfg) # Check that the ligand has NOT been frozen lig_masses = [system.getParticleMass(i)._value for i in atom_indices] assert all(m != 0 for m in lig_masses) # Check that the binding site has NOT been frozen selection = "({freeze_center}<:{freeze_distance._value})&!({freeze_solvent})".format( **freeze_cfg) site_idx = SystemFactory.amber_selection_to_atomidx( structure, selection) masses = [frzn_sys.getParticleMass(i)._value for i in site_idx] assert all(m != 0 for m in masses) # Check that the selection has been frozen # Invert that selection to freeze everything but the binding site. freeze_idx = set(range(system.getNumParticles())) - set(site_idx) massless = [frzn_sys.getParticleMass(i)._value for i in freeze_idx] assert all(m == 0 for m in massless)
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)
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 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.full_struct = parmed.load_file(self.prmtop, xyz=self.inpcrd) self.opt = { 'temperature' : 300.0, 'friction' : 1, 'dt' : 0.002, 'nIter' : 2, 'nstepsNC' : 4, 'nstepsMD' : 2, 'nprop' : 1, 'nonbondedMethod' : 'PME', 'nonbondedCutoff': 10, 'constraints': 'HBonds', 'trajectory_interval' : 1, 'reporter_interval' : 1, 'outfname' : 'blues-test', 'platform' : None}
def runEthyleneTest(dir, N): filename = dir.join('ethylene-test_%s' % N) print('Running %s...' % filename) # Set Simulation parameters temperature = 200 * unit.kelvin collision_rate = 1 / unit.picoseconds timestep = 1.0 * unit.femtoseconds n_steps = 20 nIter = 100 reportInterval = 5 alchemical_atoms = [2, 3, 4, 5, 6, 7] platform = openmm.Platform.getPlatformByName('CPU') context_cache = cache.ContextCache(platform) # Load a Parmed Structure for the Topology and create our openmm.Simulation structure_pdb = utils.get_data_filename( 'blues', 'tests/data/ethylene_structure.pdb') structure = parmed.load_file(structure_pdb) nc_reporter = NetCDF4Storage(filename + '_MD.nc', reportInterval) # Iniitialize our Move set rot_move = RandomLigandRotationMove(timestep=timestep, n_steps=n_steps, atom_subset=alchemical_atoms, context_cache=context_cache, reporters=[nc_reporter]) langevin_move = ReportLangevinDynamicsMove(timestep=timestep, collision_rate=collision_rate, n_steps=n_steps, reassign_velocities=True, context_cache=context_cache) # Load our OpenMM System and create Integrator system_xml = utils.get_data_filename('blues', 'tests/data/ethylene_system.xml') with open(system_xml, 'r') as infile: xml = infile.read() system = openmm.XmlSerializer.deserialize(xml) thermodynamic_state = ThermodynamicState(system=system, temperature=temperature) sampler_state = SamplerState( positions=structure.positions.in_units_of(unit.nanometers)) sampler = BLUESSampler(thermodynamic_state=thermodynamic_state, sampler_state=sampler_state, ncmc_move=rot_move, dynamics_move=langevin_move, topology=structure.topology) sampler.run(nIter) return filename
def test_runEthyleneRepeats(tmpdir): dir = tmpdir.mkdir("tmp") outfnames = [runEthyleneTest(dir, N=i) for i in range(5)] structure_pdb = utils.get_data_filename( 'blues', 'tests/data/ethylene_structure.pdb') trajs = [ md.load('%s_MD.nc' % traj, top=structure_pdb) for traj in outfnames ] dists = [] freqs = [] errs = [] populations = [0.25, 0.75] for traj in trajs: dist, freq = getPopulations(traj) dists.append(dist) errs.append(graphConvergence(dist, n_points=10)) freqs.append(freq) freqs = np.asarray(freqs) errs = np.asarray(errs) avg_freq = np.mean(freqs, axis=0) avg_err = np.mean(errs, axis=0) print(avg_freq, avg_err, np.absolute(avg_freq - populations)) check = np.allclose(avg_freq, populations, atol=avg_err) assert check is True
def setup_logging(filename=None, yml_path='logging.yml', default_level=logging.INFO, env_key='LOG_CFG'): """Setup logging configuration """ if not os.path.exists(yml_path): yml_path = get_data_filename('blues', 'logging.yml') path = yml_path value = os.getenv(env_key, None) if value: path = value if os.path.exists(path): with open(path, 'rt') as f: config = yaml.safe_load(f.read()) if filename: try: config['handlers']['file_handler']['filename'] = str( filename) except: pass logging.config.dictConfig(config) else: logging.basicConfig(level=default_level)
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 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) self.system_cfg = { 'nonbondedMethod': app.PME, 'nonbondedCutoff': 8.0 * unit.angstroms, 'constraints': app.HBonds } self.systems = SystemFactory(self.structure, self.atom_indices, self.system_cfg)
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)
def setUp(self): # Obtain topologies/positions prmtop = utils.get_data_filename('blues', 'tests/data/eqToluene.prmtop') inpcrd = utils.get_data_filename('blues', 'tests/data/eqToluene.pdb') structure = parmed.load_file(prmtop, xyz=inpcrd) #Initialize the Move object self.move = WaterTranslationMove( structure, protein_selection='(index 1656) or (index 1657)', radius=0.9 * unit.nanometer) self.atom_indices = self.move.atom_indices 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': 100, '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 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_runAnalysis(): outfnames = ['ethylene-test_%s.nc' % i for i in range(5)] structure_pdb = utils.get_data_filename( 'blues', 'tests/data/ethylene_structure.pdb') trajs = [md.load(traj, top=structure_pdb) for traj in outfnames] dists = [] freqs = [] errs = [] populations = [0.25, 0.75] for traj in trajs: dist, freq = getPopulations(traj) dists.append(dist) errs.append(graphConvergence(dist, n_points=10)) freqs.append(freq) freqs = np.asarray(freqs) errs = np.asarray(errs) avg_freq = np.mean(freqs, axis=0) avg_err = np.mean(errs, axis=0) print(avg_freq, avg_err, np.absolute(avg_freq - populations)) check = np.allclose(avg_freq, populations, atol=avg_err) assert check == True
def runEthyleneTest(N): filename = 'ethylene-test_%s' % N print('Running %s...' % filename) seed = np.random.randint(low=1, high=5000) #print('Seed', seed) # filename = 'ethylene-test_%s' % N # print(filename) # Set Simulation parameters sim_cfg = { 'platform': 'CPU', 'nprop': 1, 'propLambda': 0.3, 'dt': 1 * unit.femtoseconds, 'friction': 1 / unit.picoseconds, 'temperature': 200 * unit.kelvin, 'nIter': 100, 'nstepsMD': 20, 'nstepsNC': 20, 'propSteps': 20, 'moveStep': 10 } totalSteps = int(sim_cfg['nIter'] * sim_cfg['nstepsMD']) reportInterval = 5 alchemical_atoms = [2, 3, 4, 5, 6, 7] alchemical_functions = { 'lambda_sterics': 'min(1, (1/0.3)*abs(lambda-0.5))', 'lambda_electrostatics': 'step(0.2-lambda) - 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)' } md_reporters = {'traj_netcdf': {'reportInterval': reportInterval}} # Load a Parmed Structure for the Topology and create our openmm.Simulation structure_pdb = utils.get_data_filename( 'blues', 'tests/data/ethylene_structure.pdb') structure = parmed.load_file(structure_pdb) # Initialize our move proposal class rot_move = RandomLigandRotationMove(structure, 'LIG') mover = MoveEngine(rot_move) # Load our OpenMM System and create Integrator system_xml = utils.get_data_filename('blues', 'tests/data/ethylene_system.xml') with open(system_xml, 'r') as infile: xml = infile.read() system = openmm.XmlSerializer.deserialize(xml) integrator = openmm.LangevinIntegrator(sim_cfg['temperature'], sim_cfg['friction'], sim_cfg['dt']) integrator.setRandomNumberSeed(seed) alch_integrator = openmm.LangevinIntegrator(sim_cfg['temperature'], sim_cfg['friction'], sim_cfg['dt']) alch_integrator.setRandomNumberSeed(seed) alch_system = SystemFactory.generateAlchSystem(system, alchemical_atoms) ncmc_integrator = AlchemicalExternalLangevinIntegrator( nsteps_neq=sim_cfg['nstepsNC'], alchemical_functions=alchemical_functions, splitting="H V R O R V H", temperature=sim_cfg['temperature'], timestep=sim_cfg['dt']) # ncmc_integrator.setRandomNumberSeed(seed) # Pack our systems into a single object systems = SystemFactory(structure, alchemical_atoms) systems.md = system systems.alch = alch_system # Make our reporters md_reporter_cfg = ReporterConfig(filename, md_reporters) md_reporters_list = md_reporter_cfg.makeReporters() # Pack our simulations into a single object simulations = SimulationFactory(systems, mover) simulations.md = SimulationFactory.generateSimFromStruct( structure, system, integrator, 'CPU') simulations.md = SimulationFactory.attachReporters(simulations.md, md_reporters_list) simulations.alch = SimulationFactory.generateSimFromStruct( structure, system, alch_integrator, 'CPU') simulations.ncmc = SimulationFactory.generateSimFromStruct( structure, alch_system, ncmc_integrator, 'CPU') ethylene_sim = BLUESSimulation(simulations, sim_cfg) ethylene_sim.run()
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'])
type=int, help="reportInterval") args = parser.parse_args() # Define parameters outfname = args.jobname temperature = 300 * unit.kelvin collision_rate = 1 / unit.picoseconds timestep = 4.0 * unit.femtoseconds n_steps = args.nsteps reportInterval = args.reportInterval nIter = args.nIter setup_logging(filename=outfname + '.log') prmtop = utils.get_data_filename('blues', 'tests/data/eqToluene.prmtop') #TOL-parm inpcrd = utils.get_data_filename('blues', 'tests/data/eqToluene.inpcrd') tol = parmed.load_file(prmtop, xyz=inpcrd) tol.system = tol.createSystem(nonbondedMethod=openmm.app.PME, nonbondedCutoff=10 * unit.angstrom, constraints=openmm.app.HBonds, hydrogenMass=3.024 * unit.dalton, rigidWater=True, removeCMMotion=True, flexibleConstraints=True, splitDihedrals=False) # Create our State objects sampler_state = SamplerState(positions=tol.positions) thermodynamic_state = ThermodynamicState(system=tol.system, temperature=temperature)
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)
#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') indicies = np.array([[0, 4, 6, 8]]) dihedraldata = md.compute_dihedrals(traj, indicies) with open("vacDivaline-test/dihedrals.txt", 'w') as output: for value in dihedraldata: output.write("%s\n" % str(value)[1:-1]) ligrot_example(get_data_filename('blues', '../examples/rotmove_cuda.yml')) #sidechain_example(get_data_filename('blues', '../examples/sidechain_cuda.yml'))
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])
def structure(): # Load the waterbox with toluene into a structure. 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) return structure
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'])