示例#1
0
 def test_calculate_PISA_1EAW(self):
     atoms, residues, chains = parse_complex_from_file(
         self.golden_data_path + '1EAWrec.pdb')
     receptor = Complex(chains, atoms)
     atoms, residues, chains = parse_complex_from_file(
         self.golden_data_path + '1EAWlig.pdb')
     ligand = Complex(chains, atoms)
     adapter = PISAAdapter(receptor, ligand)
     assert_almost_equal(
         -0.2097,
         round(
             self.pisa(adapter.receptor_model,
                       adapter.receptor_model.coordinates[0],
                       adapter.ligand_model,
                       adapter.ligand_model.coordinates[0]), 4))
示例#2
0
 def __init__(self):
     self.path = Path(__file__).absolute().parent
     self.test_path = self.path / 'scratch_docking_landscape'
     self.golden_data_path = self.path / 'golden_data'
     atoms, _, chains = parse_complex_from_file(self.golden_data_path /
                                                '1PPErec.pdb')
     self.receptor = Complex(chains, atoms)
示例#3
0
    def test_calculate_min_volume_ellipsoid(self):
        atoms, _, chains = parse_complex_from_file(self.golden_data_path / '1PPE_l_u.pdb')
        protein = Complex(chains, atoms)

        ellipsoid = MinimumVolumeEllipsoid(protein.atom_coordinates[0].coordinates)

        assert_almost_equal(5.79979144, ellipsoid.center[0])
        assert_almost_equal(13.30609275, ellipsoid.center[1])
        assert_almost_equal(6.28378695, ellipsoid.center[2])

        assert_almost_equal(11.51000999, ellipsoid.radii[0])
        assert_almost_equal(17.41300089, ellipsoid.radii[1])
        assert_almost_equal(25.1317681, ellipsoid.radii[2])

        assert_almost_equal(-0.64868458, ellipsoid.rotation[0][0])
        assert_almost_equal(-0.43420895, ellipsoid.rotation[0][1])
        assert_almost_equal(0.62503673, ellipsoid.rotation[0][2])
        assert_almost_equal(0.75208829, ellipsoid.rotation[1][0])
        assert_almost_equal(-0.49144928, ellipsoid.rotation[1][1])
        assert_almost_equal(0.43913643, ellipsoid.rotation[1][2])
        assert_almost_equal(0.11649688, ellipsoid.rotation[2][0])
        assert_almost_equal(0.75494384, ellipsoid.rotation[2][1])
        assert_almost_equal(0.64535903, ellipsoid.rotation[2][2])

        expected_poles = [[13.266157381855532, 18.303842059830465, -0.91039204503235993],
                          [-1.6665744987943629, 8.3083434397316651, 13.477965942387469],
                          [-7.296322648355452, 21.863699498711949, -1.3628961564119457],
                          [18.89590553141662, 4.7484860008501819, 13.930470053767054],
                          [2.8720188105117521, -5.6669806736857815, -9.9352265853089641],
                          [8.7275640725494164, 32.279166173247916, 22.502800482664075]]

        assert np.allclose(expected_poles, ellipsoid.poles, ERROR_TOLERANCE)
def calculate_sasa(pdb_file):
    # Read PDB structure
    atoms, residues, chains = parse_complex_from_file(pdb_file)
    molecule = Complex(chains, atoms, structure_file_name=pdb_file)

    parameters = DesolvationParameters()

    # Lightdock structure to freesasa structure
    structure = Structure()
    for atom in molecule.atoms:
        structure.addAtom(atom.name, atom.residue_name, atom.residue_number,
                          atom.chain_id, atom.x, atom.y, atom.z)

    atom_names = []
    atom_radius = []
    for atom in molecule.atoms:
        atom_names.append("%-4s" % atom.name)
        if atom.residue_name == 'CYX':
            atom.residue_name = 'CYS'
        atom_radius.append(parameters.radius_per_atom[atom.residue_name + "-" +
                                                      atom.name])

    structure.setRadii(atom_radius)

    start_time = timeit.default_timer()
    result = freesasa.calc(structure)
    elapsed = timeit.default_timer() - start_time

    return result.totalArea(), elapsed
示例#5
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
示例#6
0
 def test_null_rotation(self):
     protein = Complex(chains=self.chains2)
     q = Quaternion()
     protein.rotate(q)
     write_pdb_to_file(protein, self.test_path + 'rotated.pdb',
                       protein.atom_coordinates[0])
     assert filecmp.cmp(self.golden_data_path + 'two_residues.pdb',
                        self.test_path + 'rotated.pdb')
示例#7
0
    def setUp(self):
        self.path = os.path.dirname(os.path.realpath(__file__))
        self.golden_data_path = os.path.normpath(
            os.path.dirname(os.path.realpath(__file__))) + '/golden_data/'

        atoms, residues, chains = parse_complex_from_file(
            self.golden_data_path + '1PPErec.pdb')
        self.receptor = Complex(chains, atoms)
示例#8
0
    def test_calculate_initial_poses(self):

        atoms, residues, chains = parse_complex_from_file(
            os.path.join(self.golden_data_path, '3p0g',
                         'receptor_membrane.pdb'))
        receptor = Complex(chains)
        atoms, residues, chains = parse_complex_from_file(
            os.path.join(self.golden_data_path, '3p0g', 'ligand.pdb'))
        ligand = Complex(chains)

        rec_translation = receptor.move_to_origin()
        lig_translation = ligand.move_to_origin()

        num_swarms = 10
        num_glowworms = 10
        seed = 324324
        restraints = parse_restraints_file(
            os.path.join(self.golden_data_path, '3p0g', 'restraints.list'))
        receptor_restraints = get_restraints(receptor, restraints['receptor'])
        ligand_restraints = get_restraints(ligand, restraints['ligand'])
        rec_restraints = receptor_restraints['active'] + receptor_restraints[
            'passive']
        lig_restraints = ligand_restraints['active'] + ligand_restraints[
            'passive']

        positions_files = calculate_initial_poses(receptor,
                                                  ligand,
                                                  num_swarms,
                                                  num_glowworms,
                                                  seed,
                                                  rec_restraints,
                                                  lig_restraints,
                                                  rec_translation,
                                                  lig_translation,
                                                  dest_folder=self.test_path,
                                                  is_membrane=True)

        assert filecmp.cmp(
            positions_files[0],
            os.path.join(self.golden_data_path, '3p0g', 'init',
                         'initial_positions_0.dat'))
        assert filecmp.cmp(
            positions_files[1],
            os.path.join(self.golden_data_path, '3p0g', 'init',
                         'initial_positions_1.dat'))
示例#9
0
    def test_calculate_starting_points(self):
        # Receptor
        file_name = self.golden_data_path / '1PPE_rec.pdb'
        atoms, _, chains = parse_complex_from_file(file_name)
        receptor = Complex(chains, atoms, structure_file_name=file_name)

        # Ligand
        file_name = self.golden_data_path / '1PPE_lig.pdb'
        atoms, _, chains = parse_complex_from_file(file_name)
        ligand = Complex(chains, atoms, structure_file_name=file_name)

        starting_points, rec_diameter, lig_diameter = calculate_surface_points(receptor, ligand, 50, [0.,0.,0.], 50.)

        assert_almost_equal(rec_diameter, 50.213210831413676)
        assert_almost_equal(lig_diameter, 27.855559534857672)

        create_pdb_from_points(self.test_path / 'points.pdb', starting_points)
        assert filecmp.cmp(self.golden_data_path / 'starting_points.pdb', self.test_path / 'points.pdb')
示例#10
0
    def test_get_restraints_with_error(self):
        input_file = os.path.join(self.golden_data_path, '2UUY_lig.pdb')
        atoms, residues, chains = parse_complex_from_file(input_file)
        structure = Complex(chains)
        restraints = {'active':['B.VAL.21'], 'passive':['B.GLY.75'], 'blocked':[]}
        
        residues = get_restraints(structure, restraints)

        assert False
示例#11
0
    def test_calculate_anm_dna(self):
        pdb_file = self.golden_data_path / 'nm_dna' / '1DIZ_lig.pdb.H'
        _, _, chains = parse_complex_from_file(pdb_file)
        molecule = Complex(chains)

        nmodes = calculate_nmodes(pdb_file, n_modes=10, molecule=molecule)

        expected_nmodes = read_nmodes(self.golden_data_path / 'nm_dna' / 'lightdock_lig.nm.npy')

        assert np.allclose(expected_nmodes, nmodes)
示例#12
0
    def test_calculate_anm_protein_2(self):
        pdb_file = self.golden_data_path / 'nm_prot' / '2UUY_rec.pdb'
        _, _, chains = parse_complex_from_file(pdb_file)
        molecule = Complex(chains)

        nmodes = calculate_nmodes(pdb_file, n_modes=10, molecule=molecule)

        expected_nmodes = read_nmodes(self.golden_data_path / 'nm_prot' / 'lightdock_rec.nm.npy')

        assert np.allclose(expected_nmodes, nmodes)
示例#13
0
def calculate_membrane_height(parsed_receptor_file, restraints):
    atoms, residues, chains = parse_complex_from_file(parsed_receptor_file)
    receptor = Complex(chains, atoms)
    z_coord = []
    for restraint in restraints:
        chain_id, residue_name, residue_number = restraint.split(".")
        residue = receptor.get_residue(chain_id, residue_name, residue_number)
        ca = residue.get_calpha()
        z_coord.append(ca.z)
    return min(z_coord)
示例#14
0
 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())
示例#15
0
    def test_get_restraints(self):
        input_file = os.path.join(self.golden_data_path, '2UUY_lig.pdb')
        atoms, residues, chains = parse_complex_from_file(input_file)
        structure = Complex(chains)
        restraints = {'active':['B.ALA.21'], 'passive':['B.GLY.75'], 'blocked':[]}
        
        residues = get_restraints(structure, restraints)

        assert len(residues['active']) == 1 and len(residues['passive']) == 1
        assert residues['active'][0].name == 'ALA' and residues['active'][0].number == 21
        assert residues['passive'][0].name == 'GLY' and residues['passive'][0].number == 75
示例#16
0
 def test_calculate_DNA_3MFK(self):
     atoms, _, chains = parse_complex_from_file(self.golden_data_path /
                                                '3mfk_homodimer.pdb')
     receptor = Complex(chains,
                        atoms,
                        structure_file_name=(self.golden_data_path /
                                             '3mfk_homodimer.pdb'))
     atoms, _, chains = parse_complex_from_file(self.golden_data_path /
                                                '3mfk_dna.pdb')
     ligand = Complex(chains,
                      atoms,
                      structure_file_name=(self.golden_data_path /
                                           '3mfk_dna.pdb'))
     adapter = DNAAdapter(receptor, ligand)
     assert_almost_equal(
         -2716.68018700585,
         self.dna(adapter.receptor_model,
                  adapter.receptor_model.coordinates[0],
                  adapter.ligand_model,
                  adapter.ligand_model.coordinates[0]))
示例#17
0
 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)
示例#18
0
 def test_calculate_DNA_3MFK_with_hydrogens(self):
     atoms, _, chains = parse_complex_from_file(self.golden_data_path /
                                                '3mfk_homodimer.pdb.H')
     receptor = Complex(chains,
                        atoms,
                        structure_file_name=(self.golden_data_path /
                                             '3mfk_homodimer.pdb.H'))
     atoms, _t, chains = parse_complex_from_file(self.golden_data_path /
                                                 '3mfk_dna.pdb')
     ligand = Complex(chains,
                      atoms,
                      structure_file_name=(self.golden_data_path /
                                           '3mfk_dna.pdb'))
     adapter = DNAAdapter(receptor, ligand)
     assert_almost_equal(
         688.1703668834168,
         self.dna(adapter.receptor_model,
                  adapter.receptor_model.coordinates[0],
                  adapter.ligand_model,
                  adapter.ligand_model.coordinates[0]))
示例#19
0
 def test_calculate_PyDock_1AY7(self):
     atoms, residues, chains = parse_complex_from_file(
         self.golden_data_path + '1AY7_rec.pdb.H')
     receptor = Complex(chains,
                        atoms,
                        structure_file_name=(self.golden_data_path +
                                             '1AY7_rec.pdb.H'))
     atoms, residues, chains = parse_complex_from_file(
         self.golden_data_path + '1AY7_lig.pdb.H')
     ligand = Complex(chains,
                      atoms,
                      structure_file_name=(self.golden_data_path +
                                           '1AY7_lig.pdb.H'))
     adapter = CPyDockAdapter(receptor, ligand)
     assert_almost_equal(
         -15.923994756,
         self.pydock(adapter.receptor_model,
                     adapter.receptor_model.coordinates[0],
                     adapter.ligand_model,
                     adapter.ligand_model.coordinates[0]))
示例#20
0
    def test_create_complex_only_with_chains(self):
        protein = Complex(chains=self.chains)

        expected_coordinates = np.array([[1, 1, 1], [2, 2, 2], [1.1, 1.2, 1.3],
                                         [2.9, 2.8, 2.7]])

        assert 4 == protein.num_atoms
        assert 2 == protein.num_residues
        assert (expected_coordinates == protein.atom_coordinates).all()
        for expected_index, atom in enumerate(protein.atoms):
            assert expected_index == atom.index
示例#21
0
    def test_write_pdb_to_file(self):
        atoms, _, chains = parse_complex_from_file(self.golden_data_path /
                                                   '1PPE_l_u.pdb')
        protein = Complex(chains)
        assert atoms == protein.atoms

        write_pdb_to_file(protein, self.test_path / '1PPE_l_u.pdb.parsed',
                          protein.atom_coordinates[0])

        assert filecmp.cmp(self.golden_data_path / '1PPE_l_u.pdb.parsed',
                           self.test_path / '1PPE_l_u.pdb.parsed')
示例#22
0
    def test_parse_pdb_noh(self):
        atoms_to_ignore = ['H']
        atoms, _, chains = parse_complex_from_file(
            self.golden_data_path / '1PPE_lig.pdb.H', atoms_to_ignore)
        protein = Complex(chains)
        assert atoms == protein.atoms

        write_pdb_to_file(protein, self.test_path / 'parsed_1PPE_lig.pdb.H',
                          protein.atom_coordinates[0])

        assert filecmp.cmp(self.golden_data_path / 'parsed_1PPE_lig.pdb.H',
                           self.test_path / 'parsed_1PPE_lig.pdb.H')
示例#23
0
    def test_get_restraints_with_error(self):
        input_file = self.golden_data_path / '2UUY_lig.pdb'
        _, _, chains = parse_complex_from_file(input_file)
        structure = Complex(chains)
        restraints = {
            'active': ['B.VAL.21'],
            'passive': ['B.GLY.75'],
            'blocked': []
        }

        residues = get_restraints(structure, restraints)

        assert residues is not None
示例#24
0
    def test_calculate_anm_dna(self):
        pdb_file = os.path.join(self.golden_data_path, 'nm_dna',
                                '1DIZ_lig.pdb.H')
        atoms, residues, chains = parse_complex_from_file(pdb_file)
        molecule = Complex(chains)

        nmodes = calculate_nmodes(pdb_file, n_modes=10, molecule=molecule)

        expected_nmodes = read_nmodes(
            os.path.join(self.golden_data_path, 'nm_dna',
                         'lightdock_lig.nm.npy'))

        assert np.allclose(expected_nmodes, nmodes)
示例#25
0
    def test_translate(self):
        atom1 = Atom(2, 'C', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'C', '', 'A', 'ALA', x=0., y=0., z=0.)
        residue = Residue('ALA', 1, [atom1, atom2])
        chains = [Chain('A', [residue])]
        protein = Complex(chains)

        com = protein.center_of_mass()
        protein.translate([c * -1 for c in com])

        expected_coordinates = np.array([[1, 1, 1], [-1, -1, -1]])

        assert (expected_coordinates == protein.atom_coordinates).all()
示例#26
0
 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))
示例#27
0
    def test_rotation_180_degrees_y_axis_origin_is_0(self):
        """Expected file has been generated with Chimera fixing the rotation to the
        center of coordinates and modifying the column of atom name to have the
        same padding as the write_pdb_file function.
        """
        protein = Complex(chains=self.chains2)
        q = Quaternion(0, 0.0, 1.0, 0)

        protein.rotate(q)

        write_pdb_to_file(protein, self.test_path + 'rotated.pdb',
                          protein.atom_coordinates[0])
        assert filecmp.cmp(self.golden_data_path + 'two_residues_y_180.pdb',
                           self.test_path + 'rotated.pdb')
示例#28
0
    def test_move_to_origin(self):
        atom1 = Atom(2, 'C', '', 'A', 'ALA', x=0., y=0., z=0.)
        atom2 = Atom(2, 'C', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom3 = Atom(2, 'C', '', 'A', 'ALA', x=4., y=4., z=4.)
        residue = Residue('ALA', 1, [atom1, atom2, atom3])
        chains = [Chain('A', [residue])]
        protein = Complex(chains)

        protein.move_to_origin()

        expected_coordinates = np.array([[-2., -2., -2.], [0, 0, 0],
                                         [2., 2., 2.]])

        assert (expected_coordinates == protein.atom_coordinates).all()
示例#29
0
 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())
示例#30
0
    def test_LightDockGSOBuilder_using_FromFileInitializer(self):
        builder = LightdockGSOBuilder()
        number_of_glowworms = 5
        atoms, residues, chains = parse_complex_from_file(
            self.golden_data_path + '1PPErec.pdb')
        receptor = Complex(chains, atoms)
        atoms, residues, chains = parse_complex_from_file(
            self.golden_data_path + '1PPElig.pdb')
        ligand = Complex(chains, atoms)
        adapter = MJ3hAdapter(receptor, ligand)
        scoring_function = MJ3h()
        gso = builder.create_from_file(
            number_of_glowworms, self.random_number_generator,
            self.gso_parameters, [adapter], [scoring_function],
            self.bounding_box,
            self.golden_data_path + 'initial_positions_1PPE.txt', 0.5, 0.5,
            0.5, False, 10, 10)

        assert 5 == gso.swarm.get_size()

        gso.report(self.test_path + 'report.out')
        assert filecmp.cmp(
            self.golden_data_path + 'report_lightdockbuilder.out',
            self.test_path + 'report.out')