Example #1
0
 def test_check_termination_equilibrium_path_sampling_thread(self):
     """Tests check_termination thread criterion with job_type = 'equilibrium_path_sampling'"""
     settings = config_equilibrium_path_sampling()
     settings.initial_coordinates = [
         '../test_data/test_velocities.rst7',
         '../test_data/test_velocities.rst7'
     ]
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     allthreads[0].history.prod_trajs = [[
         '../test_data/test.nc', '../test_data/test.nc'
     ]]
     allthreads[0].history.prod_lens = [[2, 2]]
     allthreads[0].history.init_coords = [[
         '../test_data/test_velocities.rst7',
         '../test_data/test_velocities.rst7'
     ]]
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.update_results(allthreads[0], allthreads, settings)
     settings.samples_per_window = 1
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.check_termination(
         allthreads[0], allthreads,
         settings) == False  # global termination False
     assert allthreads[0].terminated == True  # thread termination True
Example #2
0
 def test_algorithm_aimless_shooting_init(self):
     """Tests algorithm with job_type = 'aimless_shooting' and thread.current_type = ['init']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     settings.initial_coordinates = ['../test_data/test_velocities.rst7']
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     allthreads[0].history.init_coords = [[
         'test_velocities.rst7_0_init.rst7'
     ]]
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.algorithm(allthreads[0], allthreads, allthreads, settings)
     assert allthreads[0].current_type == [
     ]  # result for missing .rst7 file (haven't copied it yet)
     allthreads[0].current_type = ['init']  # reset last result
     shutil.copy(
         '../test_data/test_velocities.rst7',
         'test_velocities.rst7_0_init.rst7')  # create the needed file
     jobtype.algorithm(allthreads[0], allthreads, allthreads, settings)
     assert allthreads[0].current_type == ['init'
                                           ]  # results for .rst7 was found
     assert allthreads[0].history.init_coords == [[
         'test_velocities.rst7_0_init.rst7',
         'test_velocities.rst7_0_init_bwd.rst7'
     ]]
Example #3
0
 def test_algorithm_aimless_shooting_prod_always_new_not_accepted(self):
     """Tests algorithm with job_type = 'aimless_shooting', always_new = True and thread.current_type =
     ['prod', 'prod'] for a move that isn't accepted"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.topology = '../test_data/test.prmtop'
     settings.always_new = True
     settings.initial_coordinates = ['../test_data/test_velocities.rst7']
     settings.min_dt = -1
     settings.max_dt = -1  # set these to the same value to guarantee which frame is chosen
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     allthreads[0].history.prod_results = [['bwd', 'fwd'], ['fwd', 'fwd']
                                           ]  # accepted then not accepted
     allthreads[0].history.prod_trajs = [[
         '../test_data/test.nc', '../test_data/test.nc'
     ], ['../test_data/test.nc', '../test_data/test.nc']]
     allthreads[0].suffix = 1
     allthreads[0].history.last_accepted = 0
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.algorithm(allthreads[0], allthreads, allthreads, settings)
     assert filecmp.cmp(
         allthreads[0].history.init_inpcrd[1],
         '../test_data/test.rst7')  # test.rst7 is last frame of test.nc
     os.remove(
         '../test_data/test.nc_frame_-1.rst7'
     )  # have to do this manually because aimless shooting's mdengine getframe method keeps the '../test_data/' in front of the file name
Example #4
0
 def test_algorithm_equilibrium_path_sampling_prod_not_accepted(self):
     """Tests algorithm with job_type = 'equilibrium_path_sampling' and thread.current_type = ['prod', 'prod'] for a
     move that isn't accepted"""
     settings = config_equilibrium_path_sampling()
     settings.min_dt = -1
     settings.max_dt = -1  # set these to the same value to guarantee which frame is chosen
     settings.eps_dynamic_seed = 0
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     allthreads[0].history.prod_results = [[-34.12, -35.1,
                                            -36], [12, 13, 11]
                                           ]  # accepted then not accepted
     allthreads[0].history.prod_trajs = [['test.nc', 'test.nc'],
                                         [
                                             'not_a_real_file.nc',
                                             'not_a_real_file.nc'
                                         ]]
     allthreads[0].history.init_coords = [[
         '../test_data/test_velocities.rst7',
         '../test_data/test_velocities.rst7'
     ]]
     allthreads[0].suffix = 1
     allthreads[0].history.last_accepted = 0
     shutil.copy('../test_data/test.nc', 'test.nc')
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.algorithm(allthreads[0], allthreads, allthreads, settings)
     assert filecmp.cmp(
         allthreads[0].history.init_inpcrd[1],
         '../test_data/test.rst7')  # test.rst7 is last frame of test.nc
Example #5
0
 def test_update_results_aimless_shooting_prod(self):
     """Tests update_results with job_type = 'aimless_shooting' and thread.current_type = ['prod', 'prod']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.initial_coordinates = [
         '../test_data/test_velocities.rst7',
         '../test_data/test_velocities.rst7'
     ]
     settings.topology = '../test_data/test.prmtop'
     settings.commit_fwd = [[1, 2], [3, 4], [1.5, 2.0], ['lt', 'gt']]
     settings.commit_bwd = [[1, 2], [3, 4], [2.0, 1.5], ['gt', 'lt']]
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     allthreads[0].history.prod_trajs = [[
         '../test_data/test.nc', '../test_data/test.nc'
     ]]
     allthreads[0].history.init_coords = [[
         'test_velocities.rst7_0_init.rst7'
     ]]
     shutil.copy(
         '../test_data/test_velocities.rst7',
         'test_velocities.rst7_0_init.rst7')  # create the needed file
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.update_results(allthreads[0], allthreads, settings)
     assert os.path.exists('restart.pkl')
     assert os.path.exists('status.txt')
     assert allthreads[0].history.prod_results == [['', '']]
Example #6
0
 def test_gatekeep_equilibrium_path_sampling(self):
     """Tests gatekeep with job_type = 'committor_analysis'"""
     settings = config_equilibrium_path_sampling()
     settings.DEBUG = True
     allthreads = main.init_threads(settings)
     allthreads[0].jobids = ['123456']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.gatekeeper(allthreads[0], settings) == True
Example #7
0
 def test_check_for_successful_step_committor_analysis(self):
     """Tests check_for_successful_step with job_type = 'committor_analysis'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.committor_analysis_use_rc_out = False
     allthreads = main.init_threads(settings)
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.check_for_successful_step(allthreads[0],
                                              settings) == True
Example #8
0
 def test_update_history_equilibrium_path_sampling_init(self):
     """Tests update_history with job_type = 'equilibrium_path_sampling' with current_type = ['init']"""
     settings = config_equilibrium_path_sampling()
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     these_kwargs = {'rst': 'fakey_mcfakename.rst7'}
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.update_history(allthreads[0], settings, **these_kwargs)
     assert allthreads[0].history.init_coords == [['fakey_mcfakename.rst7']]
Example #9
0
 def test_gatekeep_committor_analysis(self):
     """Tests gatekeep with job_type = 'committor_analysis'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.DEBUG = True
     settings.committor_analysis_use_rc_out = False
     allthreads = main.init_threads(settings)
     allthreads[0].jobids = ['123456']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.gatekeeper(allthreads[0], settings) == True
Example #10
0
 def test_check_termination_equilibrium_path_sampling_global(self):
     """Tests check_termination global criterion with job_type = 'equilibrium_path_sampling'"""
     settings = config_equilibrium_path_sampling()
     settings.samples_per_window = -1
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.check_termination(allthreads[0], allthreads,
                                      settings) == False
     assert allthreads[0].terminated == False
Example #11
0
 def test_update_results_aimless_shooting_init(self):
     """Tests update_results with job_type = 'aimless_shooting' and thread.current_type = ['init']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.update_results(allthreads[0], allthreads, settings)
     assert os.path.exists('restart.pkl')
Example #12
0
 def test_gatekeep_aimless_shooting(self):
     """Tests gatekeep with job_type = 'aimless_shooting'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     settings.DEBUG = True
     allthreads = main.init_threads(settings)
     allthreads[0].jobids = ['123456']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.gatekeeper(allthreads[0], settings) == True
Example #13
0
 def test_get_inpcrd_equilibrium_path_sampling(self):
     """Tests get_inpcrd with job_type = 'equilibrium_path_sampling'"""
     settings = config_equilibrium_path_sampling()
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     allthreads[0].history.init_coords = [[
         'not_a_real_file_at_all_init.rst7'
     ]]
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_inpcrd(
         allthreads[0]) == ['not_a_real_file_at_all_init.rst7']
Example #14
0
 def test_check_termination_committor_analysis(self):
     """Tests check_termination with job_type = 'committor_analysis'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.committor_analysis_use_rc_out = False
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod', 'prod']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.check_termination(allthreads[0], allthreads,
                                      settings) == False
     assert allthreads[0].terminated == True
Example #15
0
 def test_check_termination_aimless_shooting_init(self):
     """Tests check_termination with job_type = 'aimless_shooting' and thread.current_type = ['init']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.check_termination(
         allthreads[0], allthreads,
         settings) == False  # never terminate after an 'init' step
Example #16
0
 def test_get_initial_coordinates_committor_analysis_rc_out_does_not_exist(
         self):
     """Tests get_initial_coordinates with job_type = 'committor_analysis' using an RC out file that does not exist"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.committor_analysis_use_rc_out = True
     settings.path_to_rc_out = '../test_data/rc_eval_FAKE.out'
     settings.rc_threshold = 0.002
     jobtype = factory.jobtype_factory(settings.job_type)
     with pytest.raises(FileNotFoundError):
         allthreads = main.init_threads(settings)
Example #17
0
 def test_get_next_step_committor_analysis(self):
     """Tests get_next_step with job_type = 'committor_analysis'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.committor_analysis_use_rc_out = False
     settings.committor_analysis_n = 3
     allthreads = main.init_threads(settings)
     jobtype = factory.jobtype_factory(settings.job_type)
     this_types, this_names = jobtype.get_next_step(allthreads[0], settings)
     assert this_types == ['prod', 'prod', 'prod']
     assert this_names == ['0', '1', '2']
Example #18
0
 def test_get_initial_coordinates_committor_analysis_rc_out(self):
     """Tests get_initial_coordinates with job_type = 'committor_analysis' using an RC out file"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.committor_analysis_use_rc_out = True
     settings.path_to_rc_out = '../test_data/rc_eval.out'
     settings.rc_threshold = 0.002
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_initial_coordinates(settings) == [
         '1.1_1.2_2.2_2.6.rst7_2_10_init_fwd.rst_2_1_2.rst7_5_init_fwd.rst',
         '1.1_1.2_2.2_2.6.rst7_2_10_init_fwd.rst_4_58_3.rst7_4_init_fwd.rst'
     ]
Example #19
0
 def test_get_inpcrd_aimless_shooting_init(self):
     """Tests get_inpcrd with job_type = 'aimless_shooting' and thread.current_type = ['init']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     settings.initial_coordinates = ['../test_data/test_velocities.rst7']
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_inpcrd(
         allthreads[0]) == allthreads[0].history.init_inpcrd
     assert allthreads[0].history.init_inpcrd == ['test_velocities.rst7']
Example #20
0
 def test_get_initial_coordinates_committor_analysis_rc_out_no_shooting_points(
         self):
     """Tests get_initial_coordinates with job_type = 'committor_analysis' using an RC out file containing no
     shooting points within the threshold"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.committor_analysis_use_rc_out = True
     settings.path_to_rc_out = '../test_data/rc_eval.out'
     settings.rc_threshold = 0.0002
     jobtype = factory.jobtype_factory(settings.job_type)
     with pytest.raises(RuntimeError):
         allthreads = main.init_threads(settings)
Example #21
0
 def test_get_batch_template_committor_analysis(self):
     """Tests get_batch_template with job_type = 'committor_analysis'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.md_engine = 'amber'
     settings.batch_system = 'slurm'
     settings.committor_analysis_use_rc_out = False
     settings.path_to_templates = sys.path[0] + '/atesa/data/templates'
     allthreads = main.init_threads(settings)
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_batch_template(allthreads[0], 'prod',
                                       settings) == 'amber_slurm.tpl'
Example #22
0
 def test_get_input_file_aimless_shooting(self):
     """Tests get_input_file with job_type = 'aimless_shooting'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     settings.initial_coordinates = ['../test_data/test_velocities.rst7']
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_input_file(
         allthreads[0], 0, settings
     ) == settings.path_to_input_files + '/' + settings.job_type + '_' + allthreads[
         0].current_type[0] + '_' + settings.md_engine + '.in'
Example #23
0
 def test_get_initial_coordinates_aimless_shooting(self):
     """Tests get_initial_coordinates with job_type = 'aimless_shooting'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.initial_coordinates = [
         '../test_data/test.rst7', '../test_data/test_two_init.rst7'
     ]
     settings.degeneracy = 2
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_initial_coordinates(settings) == [
         'test.rst7_0', 'test.rst7_1', 'test_two_init.rst7_0',
         'test_two_init.rst7_1'
     ]
Example #24
0
 def test_get_input_file_committor_analysis(self):
     """Tests get_input_file with job_type = 'committor_analysis'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.committor_analysis_use_rc_out = False
     settings.initial_coordinates = ['../test_data/test_velocities.rst7']
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_input_file(
         allthreads[0], 0, settings
     ) == settings.path_to_input_files + '/' + settings.job_type + '_' + allthreads[
         0].current_type[0] + '_' + settings.md_engine + '.in'
Example #25
0
 def test_check_termination_aimless_shooting_prod(self):
     """Tests check_termination with job_type = 'aimless_shooting' and thread.current_type = ['prod', 'prod']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.check_termination(
         allthreads[0], allthreads,
         settings) == False  # todo: update after implementation
     assert allthreads[
         0].terminated == False  # todo: update after implementation
Example #26
0
 def test_update_history_equilibrium_path_sampling_prod(self):
     """Tests update_history with job_type = 'equilibrium_path_sampling' with current_type = ['prod', 'prod']"""
     settings = config_equilibrium_path_sampling()
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod']
     these_kwargs = {'nc': 'fakey_mcfakename.nc'}
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.update_history(allthreads[0], settings, **these_kwargs)
     assert allthreads[0].history.prod_trajs == [['fakey_mcfakename.nc']]
     jobtype.update_history(allthreads[0], settings, **these_kwargs)
     assert allthreads[0].history.prod_trajs == [[
         'fakey_mcfakename.nc', 'fakey_mcfakename.nc'
     ]]
Example #27
0
 def test_update_history_aimless_shooting_init(self):
     """Tests update_history with job_type = 'aimless_shooting' and thread.current_type = ['init']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     settings.initial_coordinates = ['../test_data/test_velocities.rst7']
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     these_kwargs = {'rst': 'fakey_mcfakename.rst'}
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.update_history(allthreads[0], settings, **these_kwargs)
     assert allthreads[0].history.init_coords[-1] == [
         'fakey_mcfakename.rst'
     ]
Example #28
0
 def test_check_for_successful_step_aimless_shooting_init(self):
     """Tests check_for_successful_step with job_type = 'aimless_shooting' and thread.current_type = ['init']"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'aimless_shooting'
     settings.degeneracy = 1
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     allthreads[0].history.init_coords = [['some_init_coords.rst7']]
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.check_for_successful_step(
         allthreads[0],
         settings) == False  # necessary file does not yet exist
     shutil.copy('../test_data/test.rst7',
                 'some_init_coords.rst7')  # make the necessary file
     assert jobtype.check_for_successful_step(
         allthreads[0], settings) == True  # necessary file exists
Example #29
0
 def test_update_history_committor_analysis(self):
     """Tests update_history with job_type = 'committor_analysis'"""
     settings = configure('../../data/atesa.config')
     settings.job_type = 'committor_analysis'
     settings.initial_coordinates = ['../test_data/test_velocities.rst7']
     settings.committor_analysis_use_rc_out = False
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['prod', 'prod', 'prod']
     these_kwargs = {'nc': 'fakey_mcfakename.nc'}
     jobtype = factory.jobtype_factory(settings.job_type)
     jobtype.update_history(allthreads[0], settings, **these_kwargs)
     assert allthreads[0].history.prod_trajs == ['fakey_mcfakename.nc']
     jobtype.update_history(allthreads[0], settings, **these_kwargs)
     assert allthreads[0].history.prod_trajs == [
         'fakey_mcfakename.nc', 'fakey_mcfakename.nc'
     ]
Example #30
0
 def test_get_input_file_equilibrium_path_sampling(self):
     """Tests get_input_file with job_type = 'equilibrium_path_sampling'"""
     settings = config_equilibrium_path_sampling()
     allthreads = main.init_threads(settings)
     allthreads[0].current_type = ['init']
     jobtype = factory.jobtype_factory(settings.job_type)
     assert jobtype.get_input_file(
         allthreads[0], 0, settings
     ) == settings.path_to_input_files + '/' + settings.job_type + '_' + allthreads[
         0].current_type[0] + '_' + settings.md_engine + '.in'
     allthreads[0].current_type = ['prod', 'prod']
     new_file = jobtype.get_input_file(allthreads[0], 0, settings)
     assert os.path.exists(new_file)
     assert allthreads[0].history.prod_lens[-1][0] + allthreads[
         0].history.prod_lens[-1][1] == settings.eps_n_steps
     new_file = jobtype.get_input_file(allthreads[0], 1, settings)
     assert os.path.exists(new_file)