def test_protocol_work_accumulation_waterbox(self): """Testing protocol work accumulation for ExternalPerturbationLangevinIntegrator with AlchemicalWaterBox """ from simtk.openmm import app parameter_name = "lambda_electrostatics" parameter_initial = 1.0 parameter_final = 0.0 platform_names = [ openmm.Platform.getPlatform(index).getName() for index in range(openmm.Platform.getNumPlatforms()) ] for nonbonded_method in ["CutoffPeriodic", "PME"]: testsystem = testsystems.AlchemicalWaterBox( nonbondedMethod=getattr(app, nonbonded_method)) for platform_name in platform_names: name = "%s %s %s" % (testsystem.name, nonbonded_method, platform_name) self.compare_external_protocol_work_accumulation( testsystem, parameter_name, parameter_initial, parameter_final, platform_name=platform_name, name=name, )
def test_protocol_work_accumulation_waterbox_barostat(self): """ Testing protocol work accumulation for ExternalPerturbationLangevinIntegrator with AlchemicalWaterBox with an active barostat. For brevity, only using CutoffPeriodic as the non-bonded method. """ from simtk.openmm import app parameter_name = "lambda_electrostatics" parameter_initial = 1.0 parameter_final = 0.0 platform_names = [ openmm.Platform.getPlatform(index).getName() for index in range(openmm.Platform.getNumPlatforms()) ] nonbonded_method = "CutoffPeriodic" testsystem = testsystems.AlchemicalWaterBox( nonbondedMethod=getattr(app, nonbonded_method)) # Adding the barostat with a high frequency testsystem.system.addForce( openmm.MonteCarloBarostat(1 * unit.atmospheres, 300 * unit.kelvin, 2)) for platform_name in platform_names: name = "%s %s %s" % (testsystem.name, nonbonded_method, platform_name) self.compare_external_protocol_work_accumulation( testsystem, parameter_name, parameter_initial, parameter_final, platform_name=platform_name, name=name, )
def generate_example_waterbox_states(temperature=300.0 * unit.kelvin, pressure=1.0 * unit.atmosphere): """ This is a convenience function to generate a CompoundThermodynamicState and SamplerState to use in other tests. Here, we generate an alchemical water box """ #get the water box testsystem water_ts = testsystems.AlchemicalWaterBox() system = water_ts.system positions = water_ts.positions #construct the openmmtools objects for it sampler_state = states.SamplerState( positions, box_vectors=system.getDefaultPeriodicBoxVectors()) thermodynamic_state = states.ThermodynamicState(system, temperature=temperature, pressure=pressure) #make an alchemical state alchemical_state = alchemy.AlchemicalState.from_system(system) alchemical_state.set_alchemical_parameters(0.0) #make a compound thermodynamic state cpd_thermodynamic_state = states.CompoundThermodynamicState( thermodynamic_state, [alchemical_state]) return cpd_thermodynamic_state, sampler_state, water_ts.topology
def test_initial_protocol_work(self): """ Ensure the protocol work is initially zero and remains zero after a number of integrator steps. """ from simtk.openmm import app parameter_name = 'lambda_electrostatics' temperature = 298.0 * unit.kelvin parameter_initial = 1.0 platform_name = 'CPU' nonbonded_method = 'CutoffPeriodic' # Create the system testsystem = testsystems.AlchemicalWaterBox(nonbondedMethod=getattr(app, nonbonded_method)) testsystem.system.addForce(openmm.MonteCarloBarostat(1 * unit.atmospheres, temperature, 2)) context, integrator = self.create_system(testsystem, parameter_name, parameter_initial, temperature, platform_name) assert (integrator.get_protocol_work(dimensionless=True) == 0) integrator.step(5) assert(integrator.get_protocol_work(dimensionless=True) == 0)