def test_move_different_coordinates(self): coordinates1 = Coordinates(self.values_2D) coordinates2 = Coordinates([0.0, 1.0]) expected = Coordinates([-1.12132034356, -0.12132034356]) assert expected == coordinates1.move(coordinates2, 3.0)
def test_coordinates_subtraction(self): coordinates1 = Coordinates(self.values_2D) coordinates2 = Coordinates(self.values_2D) expected = Coordinates([0.0, 0.0]) assert expected == coordinates1 - coordinates2
def test_coordinates_addition(self): coordinates1 = Coordinates(self.values_2D) coordinates2 = Coordinates(self.values_2D) expected = Coordinates([2.0, 4.0]) assert expected == coordinates1 + coordinates2
def setUp(self): self.objective_function = J1() self.coordinates1 = Coordinates([0.0, 0.0]) self.coordinates2 = Coordinates([1.0, 1.0]) self.coordinates3 = Coordinates([5.0, -5.0]) self.coordinates4 = Coordinates([2.0, 2.0]) self.coordinates5 = Coordinates([-1.0, -1.0])
def test_move_step_rot_half_step_trans_half(self): atoms, residues, chains = parse_complex_from_file( self.golden_data_path + '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates1 = Coordinates([0., 0., 0., 1., 0., 0., 0.]) landscape_position1 = DockingLandscapePosition(scoring_function, coordinates1, adapter.receptor_model, adapter.ligand_model, step_translation=5.0, step_rotation=0.5) adapter2 = MJ3hAdapter(self.receptor, ligand) coordinates2 = Coordinates([10., 0., 0., 0., 0., 1., 0.]) landscape_position2 = DockingLandscapePosition(scoring_function, coordinates2, adapter2.receptor_model, adapter2.ligand_model) landscape_position1.move(landscape_position2) expected_translation = np.array([5., 0., 0.]) expected_rotation = Quaternion(0.707106781, 0.0, 0.707106781, 0.0) assert (expected_translation == landscape_position1.translation).all() assert expected_rotation == landscape_position1.rotation
def setUp(self): self.gso_parameters = GSOParameters() self.objective_function = J1() self.landscape_position1 = LandscapePosition(self.objective_function, Coordinates([0.0, 0.0])) self.landscape_position2 = LandscapePosition(self.objective_function, Coordinates([1.0, 1.0])) self.positions = [[self.landscape_position1, self.landscape_position2]]
def test_multiplication_and_assigment(self): coordinates = Coordinates(self.values_3D) expected = Coordinates([-3.0, -6.0, -9.0]) coordinates *= -3.0 assert expected == coordinates
def test_coordinates_addition_and_assigment(self): coordinates1 = Coordinates(self.values_2D) coordinates2 = Coordinates(self.values_2D) expected = Coordinates([2.0, 4.0]) coordinates1 += coordinates2 assert expected == coordinates1
def test_coordinates_subtraction_and_assigment(self): coordinates1 = Coordinates(self.values_2D) coordinates2 = Coordinates(self.values_2D) expected = Coordinates([0.0, 0.0]) coordinates1 -= coordinates2 assert expected == coordinates1
def setUp(self): self.gso_parameters = GSOParameters() self.objective_function = J1() self.landscape_position1 = [ LandscapePosition(self.objective_function, Coordinates([0.0, 0.0])) ] self.landscape_position2 = [ LandscapePosition(self.objective_function, Coordinates([1.0, 1.0])) ] self.landscape_position3 = [ LandscapePosition(self.objective_function, Coordinates([2.0, 2.0])) ] self.landscape_position4 = [ LandscapePosition(self.objective_function, Coordinates([0.5, 0.5])) ] self.landscape_position5 = [ LandscapePosition(self.objective_function, Coordinates([5.0, 5.0])) ] self.landscape_position6 = [ LandscapePosition(self.objective_function, Coordinates([0.0, 1.0])) ] self.landscape_position7 = [ LandscapePosition(self.objective_function, Coordinates([0.1, 0.0])) ] self.landscape_position8 = [ LandscapePosition(self.objective_function, Coordinates([0.0, 0.1])) ] self.landscape_position9 = [ LandscapePosition(self.objective_function, Coordinates([0.2, 0.0])) ]
def test_compute_J1_matrix(self): j3 = J3() for i in range(5): for j in range(5): assert_almost_equals( self.expected_values[i][j], j3(Coordinates([-10.0 + j * 5.0, -10.0 + i * 5.0])))
def test_compute_J1_matrix(self): j4 = J4() for i in range(6): for j in range(6): assert_almost_equals( self.expected_values[i][j], j4(Coordinates([-2.0 + j * 0.8, -2.0 + i * 0.8])))
def test_LandscapePosition_with_J1_matrix(self): expected_values = [[ 6.671280296717448e-05, 0.004156270134668844, -0.2449540405743497, -0.02975999770667323, -5.864187872589536e-06 ], [ -0.0004517936594085711, 0.3265409898164098, -5.680276001896266, -0.4404918548935705, 0.003599520786098113 ], [ -0.03650620461319554, -2.773610019456342, 0.9810118431238463, 3.269463326439044, 0.03312494992430833 ], [ -0.003078234252739988, 0.4784411467828077, 7.996620241631349, 1.185275846660814, 0.0044245231361739 ], [ 3.223535961269275e-05, 0.0311759440751708, 0.2998710282262348, 0.03200763718576478, 4.102972745826762e-05 ]] for i in range(5): for j in range(5): coord = Coordinates([-3.0 + i * 1.5, -3.0 + j * 1.5]) landscape_point = LandscapePosition(self.objective_function, coord) assert_almost_equals( expected_values[j][i], landscape_point.evaluate_objective_function())
def test_compute_J1_matrix(self): j1 = J1() for i in range(5): for j in range(5): assert_almost_equals( self.expected_values[i][j], j1(Coordinates([-3.0 + j * 1.5, -3.0 + i * 1.5])))
def test_compute_J1_matrix(self): j2 = J2() for i in range(5): for j in range(5): assert_almost_equals( self.expected_values[i][j], j2(Coordinates([-5.0 + j * 2.5, -5.0 + i * 2.5])))
def test_move_using_default_step(self): landscape_point1 = LandscapePosition(self.objective_function, self.coordinates1) landscape_point2 = LandscapePosition(self.objective_function, self.coordinates2) expected = LandscapePosition(self.objective_function, Coordinates([0.021213203435596423,0.021213203435596423])) landscape_point1.move(landscape_point2) assert expected == landscape_point1
def test_move_step_rot_full_step_trans_full(self): atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates1 = Coordinates([0.,0.,0.,1.,0.,0.,0.]) landscape_position1 = DockingLandscapePosition(scoring_function, coordinates1, adapter.receptor_model, adapter.ligand_model, step_translation=10.0) adapter2 = MJ3hAdapter(self.receptor, ligand) coordinates2 = Coordinates([10.,0.,0.,1.,0.,0.,0.]) landscape_position2 = DockingLandscapePosition(scoring_function, coordinates2, adapter2.receptor_model, adapter2.ligand_model) landscape_position1.move(landscape_position2) assert landscape_position1 == landscape_position2
def test_clone_coordinates(self): coordinates1 = Coordinates(self.values_2D) coordinates2 = coordinates1.clone() assert coordinates1 == coordinates2 coordinates2[0] = -1.0 assert coordinates1 != coordinates2
def test_move_using_other_step(self): landscape_point1 = LandscapePosition(self.objective_function, self.coordinates1, 1.0) landscape_point2 = LandscapePosition(self.objective_function, self.coordinates2) expected = LandscapePosition(self.objective_function, Coordinates([0.70710678118654746,0.70710678118654746])) landscape_point1.move(landscape_point2) assert expected == landscape_point1
def test_index_assigment(self): coordinates = Coordinates(self.values_2D) assert_almost_equals(self.values_2D[0], coordinates[0]) assert_almost_equals(self.values_2D[1], coordinates[1]) coordinates[0] = -1.0 assert_almost_equals(-1.0, coordinates[0]) assert_almost_equals(self.values_2D[1], coordinates[1])
def test_evaluate_objective_function_rotation_y_axis_180_translation_10(self): atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates = Coordinates([10.,0.,0.,0.,0.,1.,0.]) landscape_position = DockingLandscapePosition(scoring_function, coordinates, adapter.receptor_model, adapter.ligand_model) assert_almost_equal(6.39, landscape_position.evaluate_objective_function())
def test_repr(self): atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates = Coordinates([0.,0.,0.,1.,0.,0.,0.]) landscape_position = DockingLandscapePosition(scoring_function, coordinates, adapter.receptor_model, adapter.ligand_model) expected = "( 0.0000000, 0.0000000, 0.0000000, 1.0000000, 0.0000000, 0.0000000, 0.0000000) 0 0" assert expected == str(landscape_position)
def test_distance2_same_landscape_position(self): atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates = Coordinates([0., 0., 0., 1., 0., 0., 0.]) landscape_position1 = DockingLandscapePosition(scoring_function, coordinates, adapter.receptor_model, adapter.ligand_model) landscape_position2 = DockingLandscapePosition(scoring_function, coordinates, adapter.receptor_model, adapter.ligand_model) assert_almost_equal(0.0, landscape_position1.distance2(landscape_position2))
def test_evaluate_objective_function_no_movement(self): """The result of this test must be the same value as testing the MJ3h function. Translation is 0 and Quaternion [1,0,0,0] means no rotation. """ atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates = Coordinates([0.,0.,0.,1.,0.,0.,0.]) landscape_position = DockingLandscapePosition(scoring_function, coordinates, adapter.receptor_model, adapter.ligand_model) assert_almost_equal(2.02, landscape_position.evaluate_objective_function())
def test_move_same_coordinates(self): landscape_position1 = [ LandscapePosition(self.objective_function, Coordinates([1.0, 2.0])) ] landscape_position2 = [ LandscapePosition(self.objective_function, Coordinates([1.0, 2.0])) ] glowworm1 = Glowworm(landscape_position1, self.gso_parameters) glowworm2 = Glowworm(landscape_position2, self.gso_parameters) glowworm1.luciferin = 4.0 glowworm1.vision_range = 2.0 glowworm1.max_vision_range = 1.0 glowworm2.luciferin = 4.0 glowworm2.vision_range = 2.0 glowworm2.max_vision_range = 1.0 glowworm1.move(glowworm2) expected = LandscapePosition(self.objective_function, Coordinates([1.0, 2.0])) assert expected == glowworm1.landscape_positions[0]
def test_move_step_rot_half_step_trans_half_and_anm(self): atoms, _, chains = parse_complex_from_file(self.golden_data_path / '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates1 = Coordinates( [0., 0., 0., 1., 0., 0., 0., 1., 1., 1., 1.]) landscape_position1 = DockingLandscapePosition(scoring_function, coordinates1, adapter.receptor_model, adapter.ligand_model, step_translation=5.0, step_rotation=0.5, step_nmodes=0.5, num_rec_nmodes=2, num_lig_nmodes=2) adapter2 = MJ3hAdapter(self.receptor, ligand) coordinates2 = Coordinates( [10., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.]) landscape_position2 = DockingLandscapePosition(scoring_function, coordinates2, adapter2.receptor_model, adapter2.ligand_model, num_rec_nmodes=2, num_lig_nmodes=2) landscape_position1.move(landscape_position2) expected_translation = np.array([5., 0., 0.]) expected_rotation = Quaternion(0.707106781, 0.0, 0.707106781, 0.0) expected_anm = np.array([0.64644661, 0.64644661]) assert np.allclose(expected_translation, landscape_position1.translation) assert expected_rotation == landscape_position1.rotation assert np.allclose(expected_anm, landscape_position1.rec_extent) assert np.allclose(expected_anm, landscape_position1.lig_extent)
def generate_landscape_positions(self): """Generates a list of landscape positions that have been read from initial_population_file. """ positions = [] for index in range(self.number_of_glowworms): coordinates = [] for dimension in range(self.bounding_box.dimension): bound = self.bounding_box.get_boundary_of_dimension(dimension) coord = self.random_number_generator(bound.lower_limit, bound.upper_limit) coordinates.append(coord) positions.append( LandscapePosition(self.objective_functions[0], Coordinates(coordinates))) return [positions]
def test_clone(self): atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates = Coordinates([0.,0.,0.,1.,0.,0.,0.]) landscape_position_1 = DockingLandscapePosition(scoring_function, coordinates, adapter.receptor_model, adapter.ligand_model) landscape_position_2 = landscape_position_1.clone() assert landscape_position_1.translation.all() == landscape_position_2.translation.all() assert landscape_position_1.rotation == landscape_position_2.rotation landscape_position_2.translation[0] = 5.0 assert_almost_equal(5.0, landscape_position_2.translation[0]) assert_almost_equal(0.0, landscape_position_1.translation[0])
def test_distance2_minus_10A_translation_y(self): atoms, _, chains = parse_complex_from_file(self.golden_data_path / '1PPElig.pdb') ligand = Complex(chains, atoms) adapter = MJ3hAdapter(self.receptor, ligand) scoring_function = MJ3h() coordinates = Coordinates([0., 0., 0., 1., 0., 0., 0.]) landscape_position1 = DockingLandscapePosition(scoring_function, coordinates, adapter.receptor_model, adapter.ligand_model) adapter2 = MJ3hAdapter(self.receptor, ligand) adapter2.ligand_model.translate([0.0, -10.0, 0.0]) landscape_position2 = DockingLandscapePosition(scoring_function, coordinates, adapter2.receptor_model, adapter2.ligand_model) assert_almost_equal(100.0, landscape_position1.distance2(landscape_position2)) assert_almost_equal(10.0, landscape_position1.distance(landscape_position2))
def test_compute_J1_matrix(self): j5 = J5() for i in range(15): for j in range(15): assert_equals(self.expected_values[i][j], j5(Coordinates([-6.24+j*0.89143, -6.24+i*0.89143])))