def test_explicit_runner_scaler(self): p = subsystem.SubSystemFromSequence("NALA ALA CALA") b = builder.SystemBuilder(explicit_solvent=True) sys = b.build_system([p]) sys.temperature_scaler = temperature.ConstantTemperatureScaler(300.0 * u.kelvin) rest2_scaler = temperature.GeometricTemperatureScaler( 0, 1, 300.0 * u.kelvin, 350.0 * u.kelvin ) opt = options.RunOptions(solvation="explicit") opt.rest2_scaler = temperature.REST2Scaler(300.0 * u.kelvin, rest2_scaler) opt.minimize_steps = 100 opt.timesteps = 2 opt.use_rest2 = True runner = openmm_runner.OpenMMRunner(sys, opt, platform="Reference") runner.prepare_for_timestep(sys.get_state_template(), 0.0, 1) pos = sys._coordinates.copy() vel = np.zeros_like(pos) alpha = 0.0 energy = 0.0 box_vectors = sys._box_vectors s = state.SystemState(pos, vel, alpha, energy, box_vectors) s = runner.minimize_then_run(s) s = runner.run(s) assert s
def test_adds_maps_to_force(self): with mock.patch("meld.runner.transform.cmap.np.loadtxt") as mock_loadtxt: # this is a bit hacky and depends on what order the maps are loaded in expected_gly = 3.0 * 0.0 + 7.0 * 1.0 + np.zeros((24, 24)).flatten() expected_pro = 3.0 * 2.0 + 7.0 * 3.0 + np.zeros((24, 24)).flatten() expected_ala = 3.0 * 4.0 + 7.0 * 5.0 + np.zeros((24, 24)).flatten() expected_gen = 3.0 * 6.0 + 7.0 * 7.0 + np.zeros((24, 24)).flatten() mock_loadtxt.side_effect = self.maps opt = options.RunOptions() opt.use_amap = True opt.amap_alpha_bias = 3.0 opt.amap_beta_bias = 7.0 adder = cmap.CMAPTransformer(opt, self.system.top_string) adder.add_interactions(mock.Mock(), self.mock_openmm_system, mock.Mock()) self.assertEqual(self.MockCMAP.call_count, 1) self.assertEqual(self.mock_cmap.addMap.call_count, 4) # make sure all of the sizes are correct add_map_args = self.mock_cmap.addMap.call_args_list self.assertEqual(add_map_args[0][0][0], 24) self.assertEqual(add_map_args[1][0][0], 24) self.assertEqual(add_map_args[2][0][0], 24) self.assertEqual(add_map_args[3][0][0], 24) # make sure the maps are correct np.testing.assert_almost_equal(add_map_args[0][0][1], expected_gly) np.testing.assert_almost_equal(add_map_args[1][0][1], expected_pro) np.testing.assert_almost_equal(add_map_args[2][0][1], expected_ala) np.testing.assert_almost_equal(add_map_args[3][0][1], expected_gen)
def test_implicit_runner_amap(self): p = subsystem.SubSystemFromSequence("NALA ALA CALA") b = builder.SystemBuilder() sys = b.build_system([p]) sys.temperature_scaler = temperature.ConstantTemperatureScaler(300.0 * u.kelvin) opt = options.RunOptions() opt.timesteps = 20 opt.use_amap = True opt.amap_beta_bias = 10 runner = openmm_runner.OpenMMRunner(sys, opt, platform="Reference") runner.prepare_for_timestep(sys.get_state_template(), 0.0, 1) pos = sys._coordinates.copy() vel = np.zeros_like(pos) alpha = 0.0 energy = 0.0 box_vectors = np.zeros(3) s = state.SystemState(pos, vel, alpha, energy, box_vectors) s = runner.minimize_then_run(s) s = runner.run(s) assert s
def test_force_should_be_added_to_system(self): opt = options.RunOptions() opt.use_amap = True adder = cmap.CMAPTransformer(opt, self.system.top_string) adder.add_interactions(mock.Mock(), self.mock_openmm_system, mock.Mock()) self.mock_openmm_system.addForce.assert_called_once_with(self.mock_cmap)
def test_runner_equals_fake_runner_should_create_fake_runner(self): meld_system = mock.Mock() comm = mock.Mock() opt = options.RunOptions() opt.runner = "fake_runner" with mock.patch( "meld.runner.fake_runner.FakeSystemRunner") as mock_runner: runner.get_runner(meld_system, opt, comm, platform="Reference") self.assertEqual(mock_runner.call_count, 1)
def test_correct_torsions_should_be_added_to_force(self): opt = options.RunOptions() opt.use_amap = True adder = cmap.CMAPTransformer(opt, self.system.top_string) adder.add_interactions(mock.Mock(), self.mock_openmm_system, mock.Mock()) # map should be #2 for alanine # all atom indices are zero-based in openmm self.mock_cmap.addTorsion.assert_called_once_with( 2, 10, 12, 14, 20, 12, 14, 20, 22 )
def test_correct_map_used_for_ALA(self): self.make_system("ALA") opt = options.RunOptions() opt.use_amap = True adder = cmap.CMAPTransformer(opt, self.system.top_string) adder.add_interactions(mock.Mock(), self.mock_openmm_system, mock.Mock) self.mock_cmap.addTorsion.assert_called_once_with( 2, ANY, ANY, ANY, ANY, ANY, ANY, ANY, ANY )
def test_save_and_load_run_options(self): "should be able to save and load run options" with in_temp_dir(): # dummy pdb writer; can't use a mock because they can't be pickled pdb_writer = object() store = vault.DataStore(self.state_template, self.N_REPLICAS, pdb_writer) store.initialize(mode="w") fake_run_options = options.RunOptions() store.save_run_options(fake_run_options) store.load_run_options() self.assertTrue(os.path.exists("Data/run_options.dat"))
def test_correct_map_used_for_general_case(self): res_names = [ "CYS", "CYX", "ASP", "ASH", "GLU", "GLH", "PHE", "HIS", "HID", "HIE", "HIP", "LYS", "LYN", "MET", "SER", "TRP", "TYR", "ILE", "ASN", "GLN", "THR", "TRP", "LEU", "ARG", ] for res in res_names: self.mock_cmap.reset_mock() self.make_system(res) opt = options.RunOptions() opt.use_amap = True adder = cmap.CMAPTransformer(opt, self.system.top_string) adder.add_interactions(mock.Mock(), self.mock_openmm_system, mock.Mock()) self.mock_cmap.addTorsion.assert_called_once_with( 3, ANY, ANY, ANY, ANY, ANY, ANY, ANY, ANY )
def setup_system(): # create a store writer = pdb_writer.PDBWriter( range(N_ATOMS), ["CA"] * N_ATOMS, [1] * N_ATOMS, ["ALA"] * N_ATOMS ) store = vault.DataStore(gen_state(0), N_REPLICAS, writer, block_size=BACKUP_FREQ) store.initialize(mode="w") # create and store the remd_runner l = ladder.NearestNeighborLadder(n_trials=100) policy = adaptor.AdaptationPolicy(1.0, 50, 100) a = adaptor.EqualAcceptanceAdaptor(n_replicas=N_REPLICAS, adaptation_policy=policy) remd_runner = leader.LeaderReplicaExchangeRunner( N_REPLICAS, max_steps=N_STEPS, ladder=l, adaptor=a ) store.save_remd_runner(remd_runner) # create and store the communicator c = comm.MPICommunicator(N_ATOMS, N_REPLICAS) store.save_communicator(c) # create and store the fake system s = helper.FakeSystem() s.temperature_scaler = temperature.ConstantTemperatureScaler(300.0) store.save_system(s) # create and store the options o = options.RunOptions() o.runner = "fake_runner" store.save_run_options(o) # create and save the initial states states = [gen_state(i) for i in range(N_REPLICAS)] store.save_states(states, 0) # save data_store store.save_data_store()
def test_raises_when_system_has_no_temperature_scaler(self): self.system.temperature_scaler = None with self.assertRaises(RuntimeError): openmm_runner.OpenMMRunner(self.system, options.RunOptions())