Пример #1
0
 def test_clone(self):
     residue1 = Residue('ALA', 1)
     residue2 = residue1.clone()
     
     assert residue1.name == residue2.name and residue2.number == residue2.number
     residue2.name = "MET"
     assert residue1.name != residue2.name and residue2.number == residue2.number
Пример #2
0
    def test_get_quaternion_for_restraint2(self):
        # Origin is 0,0,0
        # Ligand center
        l_center = [-5., 5., -5.]
        # Ligand residue
        l_res = [-7., 6., -7.]
        # Receptor residue
        r_res = [3., 1., 0.]
        # Calculate quaternion for rotation from l_res to point to r_res
        rec_residue = Residue.dummy(r_res[0], r_res[1], r_res[2])
        lig_residue = Residue.dummy(l_res[0], l_res[1], l_res[2])

        q = get_quaternion_for_restraint(
            rec_residue,
            lig_residue,
            l_center[0],
            l_center[1],
            l_center[2],  # translation
            [0., 0., 0.],  # receptor translation 
            [5., -5., 5.]  # ligand translation
        )

        e = Quaternion(0.10977233, -0.44451098, -0.88902195, 0.)

        assert e == q
Пример #3
0
    def test_get_quaternion_for_restraint2d_different_quadrant(self):
        # Origin is 0,0,0
        # Ligand center
        l_center = [5., -5., 0.]
        # Ligand residue
        l_res = [7., -7., 0.]
        # Receptor residue
        r_res = [-3., 1., 0.]
        # Calculate quaternion for rotation from l_res to point to r_res
        rec_residue = Residue.dummy(r_res[0], r_res[1], r_res[2])
        lig_residue = Residue.dummy(l_res[0], l_res[1], l_res[2])

        q = get_quaternion_for_restraint(
            rec_residue,
            lig_residue,
            l_center[0],
            l_center[1],
            l_center[2],  # translation
            [0., 0., 0.],  # receptor translation 
            [5., -5., 0.]  # ligand translation
        )

        e = Quaternion(0.07088902, 0., 0., -0.99748421)

        assert e == q
Пример #4
0
 def test_clone(self):
     residue1 = Residue('ALA', 1)
     residue2 = residue1.clone()
     
     assert residue1.name == residue2.name and residue2.number == residue2.number
     residue2.name = "MET"
     assert residue1.name != residue2.name and residue2.number == residue2.number
Пример #5
0
    def test_get_quaternion_for_restraint1(self):
        # Origin is 0,0,0
        # Ligand center
        l_center = [-5., 5., -5.]
        # Ligand residue
        l_res = [-7., 7., -7.]
        # Receptor residue
        r_res = [3., 1., 0.]
        # Calculate quaternion for rotation from l_res to point to r_res
        rec_residue = Residue.dummy(r_res[0], r_res[1], r_res[2])
        lig_residue = Residue.dummy(l_res[0], l_res[1], l_res[2])

        q = get_quaternion_for_restraint(
            rec_residue,
            lig_residue,
            l_center[0],
            l_center[1],
            l_center[2],  # translation
            [0., 0., 0.],  # receptor translation 
            [5., -5., 5.]  # ligand translation
        )

        e = Quaternion(w=0.14518697,
                       x=0.19403814,
                       y=-0.58211441,
                       z=-0.77615254)

        assert e == q
Пример #6
0
    def test_populate_poses_both_restraints(self):
        to_generate = 3
        center = [15., 15., 15.]
        radius = 10.
        seed = 1984
        number_generator = MTGenerator(seed)
        # No needed if no restraints are provided
        rec_translation = [0., 0., 0.]
        lig_translation = [-15.0, -15.0, -15.0]
        # Restraints
        receptor_restraints = [Residue.dummy(1.0, 1.0, 1.0)]
        ligand_restraints = [Residue.dummy(16.0, 16.0, 16.0)]
        ligand_diameter = 10.

        poses = populate_poses(to_generate, center, radius, number_generator, rec_translation, lig_translation,
                               receptor_restraints=receptor_restraints, ligand_restraints=ligand_restraints,
                               ligand_diameter=ligand_diameter)

        expected = [[12.270567117106161, 14.884113636383933, 11.792201743436038, 0.05643308208136652, 0.7572287178886188, -0.11715469622945059, -0.6400740216591683],
                    [21.986658842426436, 12.715708176897868, 9.881149636072841, 0.17754420770338322, 0.179865123253213, -0.7681474466249519, 0.5882823233717389],
                    [22.833743558777538, 15.523806353077699, 17.906625032282104, 0.0847943426151146, -0.2599970108635702, -0.5376137514110186, 0.7976107622745888]]

        # We generate 3 poses
        assert len(poses) == 3
        # We generate poses with ANM
        assert len(poses[0]) == 7
        # We generate the expected poses
        assert np.allclose(expected, poses)
Пример #7
0
    def test_get_quaternion_for_restraint2d(self):
        # Origin is 0,0,0
        # Ligand center
        l_center = [5., 5., 0.]
        # Ligand residue
        l_res = [7., 7., 0.]
        # Receptor residue
        r_res = [3., 1., 0.]
        # Calculate quaternion for rotation from l_res to point to r_res
        rec_residue = Residue.dummy(r_res[0], r_res[1], r_res[2])
        lig_residue = Residue.dummy(l_res[0], l_res[1], l_res[2])

        q = get_quaternion_for_restraint(
            rec_residue,
            lig_residue,
            l_center[0],
            l_center[1],
            l_center[2],  # translation
            [0., 0., 0.],  # receptor translation 
            [5., 5., 0.]  # ligand translation
        )

        e = Quaternion(0.16018224, 0., 0., -0.98708746)

        assert e == q
Пример #8
0
    def test_clone(self):
        chain1 = Chain('A', [Residue('ALA', 1), Residue('MET', 2)])
        chain2 = chain1.clone()

        assert len(chain1.residues) == len(chain2.residues) and \
            chain1.residues[0].name == chain2.residues[0].name

        chain1.residues[0].name = 'MET'
        assert chain1.residues[0].name != chain2.residues[0].name
Пример #9
0
    def test_get_atom(self):
        atoms = [Atom(1, 'CA', '', 'A', 'ALA'), Atom(2, 'N', '', 'A', 'ALA')]
        residue = Residue('ALA', 1, atoms)

        atom1 = residue.get_atom('CA')
        atom2 = residue.get_atom('N')
        atom3 = residue.get_atom('CG')

        assert 'CA' == atom1.name
        assert 'N' == atom2.name
        assert None == atom3
Пример #10
0
    def test_get_atom(self):
        atoms = [Atom(1, 'CA', '', 'A', 'ALA'), Atom(2, 'N', '', 'A', 'ALA')]
        residue = Residue('ALA', 1, atoms)

        atom1 = residue.get_atom('CA')
        atom2 = residue.get_atom('N')
        atom3 = residue.get_atom('CG')

        assert 'CA' == atom1.name
        assert 'N' == atom2.name
        assert None == atom3
Пример #11
0
    def test_get_atom(self):
        atoms = [Atom(1, 'CA', '', 'A', 'ALA'), Atom(2, 'N', '', 'A', 'ALA')]
        residue = Residue('ALA', 1, atoms)

        atom1 = residue.get_atom('CA')
        atom2 = residue.get_atom('N')
        atom3 = residue.get_atom('CG')

        assert atom1.name == "CA"
        assert atom2.name == "N"
        assert atom3 is None
Пример #12
0
 def setUp(self):
     self.atoms1 = [
         Atom(1, 'CA', '', 'A', 'ALA', x=1., y=1., z=1.),
         Atom(2, 'N', '', 'A', 'ALA', x=2., y=2., z=2.)
     ]
     self.atoms2 = [
         Atom(3, 'CA', '', 'A', 'HIS', x=1.1, y=1.2, z=1.3),
         Atom(4, 'N', '', 'A', 'HIS', x=2.9, y=2.8, z=2.7)
     ]
     self.residues = [
         Residue('ALA', 1, self.atoms1),
         Residue('HIS', 2, self.atoms2)
     ]
Пример #13
0
    def test_apply_restraints_with_blocking(self):
        swarm_centers = [
            [13.861446721229493, -28.730453433364488, 0.024305878079852336],
            [-29.427540743780476, -2.960299745528308, -5.168493906227671],
            [24.244162925019417, 2.9322386764307304, -15.44286271885186],
            [2.0463687050893857, -13.94537658944639, -24.099372234598455],
            [-10.833120242061193, 13.517315520348813, -20.69794891072167],
            [-10.934383879949547, 24.302392364266915, 4.508648686944662],
            [-13.742376304140548, -18.137915011405447, 12.54861921589357],
            [-6.5003433948735, 7.824777098389764, 23.942006739050495],
            [17.345254847698744, 18.209853942307866, 6.384609403593564],
            [13.837506572006518, -7.152838167487336, 18.165186863034638]
        ]
        distance_cutoff = 19.522956365520056
        translation = [
            -21.630461302211305, -5.510320024570013, -20.27116646191647
        ]
        atoms = [
            Atom(atom_number=1, atom_name='N', x=25.344, y=-10.048, z=26.435),
            Atom(atom_number=2, atom_name='CA', x=26.439, y=-10.798, z=26.994),
            Atom(atom_number=3, atom_name='C', x=26.646, y=-12.135, z=26.328),
            Atom(atom_number=4, atom_name='O', x=27.790, y=-12.531, z=26.028),
            Atom(atom_number=5, atom_name='CB', x=26.230, y=-10.933, z=28.503),
            Atom(atom_number=6, atom_name='CG', x=26.448, y=-9.540, z=29.191),
            Atom(atom_number=7, atom_name='CD', x=26.283, y=-9.676, z=30.689),
            Atom(atom_number=8, atom_name='CE', x=26.609, y=-8.392, z=31.454),
            Atom(atom_number=9, atom_name='NZ', x=26.210, y=-8.498, z=32.884)
        ]
        receptor_restraints = [Residue('LYS', 239, atoms=atoms)]

        atoms = [
            Atom(atom_number=1, atom_name='N', x=30.795, y=-14.563, z=19.577),
            Atom(atom_number=2, atom_name='CA', x=30.969, y=-13.948, z=18.287),
            Atom(atom_number=3, atom_name='C', x=32.148, y=-12.988, z=18.291),
            Atom(atom_number=4, atom_name='O', x=32.601, y=-12.684, z=19.413),
            Atom(atom_number=5, atom_name='CB', x=29.742, y=-13.163, z=17.861),
            Atom(atom_number=6, atom_name='CG', x=28.586, y=-14.066, z=17.510),
            Atom(atom_number=7, atom_name='OD1', x=28.470, y=-14.548,
                 z=16.359),
            Atom(atom_number=8, atom_name='ND2', x=27.742, y=-14.322, z=18.456)
        ]
        blocking_restraints = [Residue('ASN', 245, atoms=atoms)]
        expected_new_centers = [[
            13.837506572006518, -7.152838167487336, 18.165186863034638
        ]]

        new_centers = apply_restraints(swarm_centers, receptor_restraints,
                                       blocking_restraints, distance_cutoff,
                                       translation)

        assert np.allclose(expected_new_centers, new_centers)
Пример #14
0
    def setUp(self):
        self.atoms1 = [
            Atom(1, 'CA', '', 'A', 'ALA', x=1., y=1., z=1.),
            Atom(2, 'N', '', 'A', 'ALA', x=2., y=2., z=2.)
        ]
        self.atoms2 = [
            Atom(3, 'CA', '', 'A', 'HIS', x=1.1, y=1.2, z=1.3),
            Atom(4, 'N', '', 'A', 'HIS', x=2.9, y=2.8, z=2.7)
        ]
        self.residues = [
            Residue('ALA', 1, self.atoms1),
            Residue('HIS', 2, self.atoms2)
        ]
        self.chains = [Chain('A', self.residues)]

        self.atoms3 = [
            Atom(1, 'N', '', 'A', 'CYS', 3, x=2.496, y=13.096, z=10.611),
            Atom(2, 'CA', '', 'A', 'CYS', 3, x=2.787, y=12.161, z=9.557),
            Atom(3, 'C', '', 'A', 'CYS', 3, x=4.052, y=11.431, z=9.896),
            Atom(4, 'O', '', 'A', 'CYS', 3, x=5.120, y=12.044, z=9.912),
            Atom(5, 'CB', '', 'A', 'CYS', 3, x=2.879, y=12.853, z=8.246),
            Atom(6, 'SG', '', 'A', 'CYS', 3, x=3.492, y=11.911, z=6.838)
        ]

        self.atoms4 = [
            Atom(7, 'N', '', 'A', 'PRO', 4, x=3.987, y=10.183, z=10.286),
            Atom(8, 'CA', '', 'A', 'PRO', 4, x=5.219, y=9.484, z=10.695),
            Atom(9, 'C', '', 'A', 'PRO', 4, x=6.277, y=9.424, z=9.662),
            Atom(10, 'O', '', 'A', 'PRO', 4, x=5.993, y=9.385, z=8.431),
            Atom(11, 'CB', '', 'A', 'PRO', 4, x=4.664, y=8.140, z=11.092),
            Atom(12, 'CG', '', 'A', 'PRO', 4, x=3.295, y=8.087, z=10.812),
            Atom(13, 'CD', '', 'A', 'PRO', 4, x=2.797, y=9.351, z=10.427)
        ]
        self.residues2 = [
            Residue('CYS', 1, self.atoms3),
            Residue('PRO', 2, self.atoms4)
        ]
        self.chains2 = [Chain('A', self.residues2)]

        self.path = os.path.dirname(os.path.realpath(__file__))
        self.test_path = self.path + '/scratch/'
        try:
            shutil.rmtree(self.test_path)
        except:
            pass
        os.mkdir(self.test_path)
        self.golden_data_path = os.path.normpath(
            os.path.dirname(os.path.realpath(__file__))) + '/golden_data/'
Пример #15
0
    def test_populate_poses_restraints_only_receptor(self):
        to_generate = 3
        center = [15., 15., 15.]
        radius = 10.
        seed = 1984
        number_generator = MTGenerator(seed)
        # No needed if no restraints are provided
        rec_translation = [0., 0., 0.]
        lig_translation = [-15.0, -15.0, -15.0]
        # Restraints
        receptor_restraints = [Residue.dummy(1.0, 1.0, 1.0)]
        ligand_diameter = 10.

        poses = populate_poses(to_generate, center, radius, number_generator, rec_translation, lig_translation,
                               receptor_restraints=receptor_restraints, ligand_diameter=ligand_diameter)

        expected = [[12.270567117106161, 14.884113636383933, 11.792201743436038, -0.6725323168859286, 0.5755106199757826, -0.37756439233549577, 0.27190612107759393],
                    [12.715708176897868, 9.881149636072841, 18.262252550718056, -0.6132005094145724, 0.757439137867041, -0.0367297456106423, -0.22118321244687617],
                    [17.906625032282104, 11.374830853855302, 8.903837618881248, -0.8727759595729266, -0.22555077047578467, -0.2572320124803007, 0.3481675833340481]]

        # We generate 3 poses
        assert len(poses) == 3
        # We generate poses with ANM
        assert len(poses[0]) == 7
        # We generate the expected poses
        assert np.allclose(expected, poses)
Пример #16
0
    def test_populate_poses_restraints_only_ligand(self):
        to_generate = 3
        center = [15., 15., 15.]
        radius = 10.
        seed = 1984
        number_generator = MTGenerator(seed)
        # No needed if no restraints are provided
        rec_translation = [0., 0., 0.]
        lig_translation = [-15.0, -15.0, -15.0]
        # Restraints
        ligand_restraints = [Residue.dummy(16.0, 16.0, 16.0)]
        ligand_diameter = 30.

        poses = populate_poses(to_generate, center, radius, number_generator, rec_translation, lig_translation,
                               ligand_restraints=ligand_restraints, ligand_diameter=ligand_diameter)

        expected = [[12.270567117106161, 14.884113636383933, 11.792201743436038, 0.7092076459798842, 0.5346980891115, -0.08272585379354264, -0.4519722353179574],
                    [22.833743558777538, 15.523806353077699, 17.906625032282104, 0.24053986913227657, -0.25327548418133206, -0.5237151871050496, 0.7769906712863817],
                    [8.903837618881248, 8.747779486586737, 19.195006601282643, 0.7560980480558669, -0.46621474071247004, 0.45925053854810693, 0.00696420216436307]]

        # We generate 3 poses
        assert len(poses) == 3
        # We generate poses with ANM
        assert len(poses[0]) == 7
        # We generate the expected poses
        assert np.allclose(expected, poses)
Пример #17
0
def parse_complex_from_file(input_file_name,
                            atoms_to_ignore=[],
                            verbose=False):
    """Reads and parses a given input_file_name PDB file.
    
    TODO: Check if chain have been already created and insert it into the first one
    """
    lines = open(input_file_name).readlines()
    atoms = []
    residues = []
    chains = []
    num_models = 0
    last_chain_id = '#'
    last_residue_name = '#'
    last_residue_number = '#'
    current_chain = None
    current_residue = None
    for line in lines:
        # Only first model is going to be read
        if num_models <= 1:
            line_type = line[0:6].strip()
            if line_type == "MODEL":
                num_models += 1
                if num_models > 1:
                    log.warning(
                        'Multiple models found in %s. Only first model will be used.'
                        % input_file_name)
            elif line_type == "ATOM" or line_type == "HETATM":
                try:
                    atom = read_atom_line(line, line_type, atoms_to_ignore)
                    atoms.append(atom)
                except PDBParsingWarning as warning:
                    if verbose:
                        print(warning)
                    continue

                if last_chain_id != atom.chain_id:
                    last_chain_id = atom.chain_id
                    current_chain = Chain(last_chain_id)
                    chains.append(current_chain)
                if last_residue_name != atom.residue_name or last_residue_number != atom.residue_number:
                    last_residue_name = atom.residue_name
                    last_residue_number = atom.residue_number
                    current_residue = Residue(atom.residue_name,
                                              atom.residue_number)
                    residues.append(current_residue)
                    current_chain.residues.append(current_residue)
                current_residue.atoms.append(atom)

    # Set backbone and side-chain atoms
    for residue in residues:
        residue.set_backbone_and_sidechain()
        try:
            residue.check()
        except Exception as e:
            log.warning("Possible problem: %s" % str(e))

    return atoms, residues, chains
Пример #18
0
    def __init__(self):
        self.atoms1 = [
            Atom(1, 'CA', '', 'A', 'ALA', x=1., y=1., z=1.),
            Atom(2, 'N', '', 'A', 'ALA', x=2., y=2., z=2.)
        ]
        self.atoms2 = [
            Atom(3, 'CA', '', 'A', 'HIS', x=1.1, y=1.2, z=1.3),
            Atom(4, 'N', '', 'A', 'HIS', x=2.9, y=2.8, z=2.7)
        ]
        self.residues = [
            Residue('ALA', 1, self.atoms1),
            Residue('HIS', 2, self.atoms2)
        ]
        self.chains = [Chain('A', self.residues)]

        self.atoms3 = [
            Atom(1, 'N', '', 'A', 'CYS', 3, x=2.496, y=13.096, z=10.611),
            Atom(2, 'CA', '', 'A', 'CYS', 3, x=2.787, y=12.161, z=9.557),
            Atom(3, 'C', '', 'A', 'CYS', 3, x=4.052, y=11.431, z=9.896),
            Atom(4, 'O', '', 'A', 'CYS', 3, x=5.120, y=12.044, z=9.912),
            Atom(5, 'CB', '', 'A', 'CYS', 3, x=2.879, y=12.853, z=8.246),
            Atom(6, 'SG', '', 'A', 'CYS', 3, x=3.492, y=11.911, z=6.838)
        ]

        self.atoms4 = [
            Atom(7, 'N', '', 'A', 'PRO', 4, x=3.987, y=10.183, z=10.286),
            Atom(8, 'CA', '', 'A', 'PRO', 4, x=5.219, y=9.484, z=10.695),
            Atom(9, 'C', '', 'A', 'PRO', 4, x=6.277, y=9.424, z=9.662),
            Atom(10, 'O', '', 'A', 'PRO', 4, x=5.993, y=9.385, z=8.431),
            Atom(11, 'CB', '', 'A', 'PRO', 4, x=4.664, y=8.140, z=11.092),
            Atom(12, 'CG', '', 'A', 'PRO', 4, x=3.295, y=8.087, z=10.812),
            Atom(13, 'CD', '', 'A', 'PRO', 4, x=2.797, y=9.351, z=10.427)
        ]
        self.residues2 = [
            Residue('CYS', 1, self.atoms3),
            Residue('PRO', 2, self.atoms4)
        ]
        self.chains2 = [Chain('A', self.residues2)]

        self.path = Path(__file__).absolute().parent
        self.test_path = self.path / 'scratch_complex'
        self.golden_data_path = self.path / 'golden_data'
Пример #19
0
    def test_backbone_sidechain(self):
        atoms = [Atom(1, 'CA', '', 'A', 'ALA'),
                 Atom(2, 'N', '', 'A', 'ALA'),
                 Atom(3, 'C', '', 'A', 'ALA'),
                 Atom(4, 'O', '', 'A', 'ALA'),
                 Atom(5, 'CB', '', 'A', 'ALA')]
        residue = Residue('ALA', 1, atoms)

        assert 1 == len(residue.sidechain)
        assert 'CB' == residue.sidechain[0].name
        assert 4 == len(residue.backbone)
Пример #20
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()
Пример #21
0
    def test_translate(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
        residues = [Residue('ALA', 1, [atom1, atom2])]
        docking_model = DockingModel(residues, SpacePoints([[2., 2., 2.], [0, 0, 0]]))

        docking_model.translate([-2, -2, -2])

        expected_coordinates = SpacePoints([[0, 0, 0], [-2, -2, -2]])
        assert expected_coordinates == docking_model.coordinates[0]

        expected_coordinates = SpacePoints([[-1, -1, -1]])
        assert np.allclose(expected_coordinates, docking_model.reference_points)
Пример #22
0
    def test_backbone_sidechain(self):
        atoms = [
            Atom(1, 'CA', '', 'A', 'ALA'),
            Atom(2, 'N', '', 'A', 'ALA'),
            Atom(3, 'C', '', 'A', 'ALA'),
            Atom(4, 'O', '', 'A', 'ALA'),
            Atom(5, 'CB', '', 'A', 'ALA')
        ]
        residue = Residue('ALA', 1, atoms)

        assert len(residue.sidechain) == 1
        assert residue.sidechain[0].name == "CB"
        assert len(residue.backbone) == 4
Пример #23
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()
Пример #24
0
    def test__to_string(self):
        chain = Chain('A', [Residue('ALA', 1), Residue('MET', 2)])

        assert "[Chain A]\nALA.1\nMET.2" == str(chain)
Пример #25
0
 def test_create_chain(self):
     chain = Chain('A', [Residue('ALA', 1), Residue('MET', 2)])
     assert chain.cid == 'A' and len(chain.residues) == 2
Пример #26
0
    def test_dummy_residue(self):
        dummy = Residue.dummy(1.0, 2.0, 3.0)

        assert 1 == len(dummy.atoms)
        assert 'CA' == dummy.atoms[0].name
        assert "  CA   1.000   2.000   3.000" == str(dummy.atoms[0])
Пример #27
0
def populate_poses(to_generate,
                   center,
                   radius,
                   number_generator,
                   rec_translation,
                   lig_translation,
                   rng_nm=None,
                   rec_nm=0,
                   lig_nm=0,
                   receptor_restraints=None,
                   ligand_restraints=None,
                   ligand_diameter=1.):
    """Creates new poses around a given center and a given radius"""
    new_poses = []

    # Flatten if necessary receptor_restraints
    if receptor_restraints:
        try:
            receptor_restraints = receptor_restraints[
                'active'] + receptor_restraints['passive']
        except TypeError:
            pass

    # Calculate closest residue restraints
    closest_residues = []
    if receptor_restraints:
        distances = []
        for i, residue in enumerate(receptor_restraints):
            ca = residue.get_calpha()
            if not ca:
                ca = residue.get_atom('P')
            distances.append(
                (i, cdistance(ca.x, ca.y, ca.z, center[0], center[1],
                              center[2])))
        distances.sort(key=lambda tup: tup[1])
        closest_residues = [x[0] for x in distances[:10]]

    for _ in range(to_generate):
        # First calculate a random translation within the swarm sphere
        x, y, z = get_random_point_within_sphere(number_generator, radius)
        tx = center[0] + x
        ty = center[1] + y
        tz = center[2] + z

        # Restraints in both partners
        if receptor_restraints and ligand_restraints:
            # We select one of the closest residue restraints to point the quaternion
            rec_residue = receptor_restraints[closest_residues[
                number_generator.randint(0,
                                         len(closest_residues) - 1)]]
            # Random restraint on the ligand to use for pre-orientation
            lig_residue = ligand_restraints[number_generator.randint(
                0,
                len(ligand_restraints) - 1)]
            # Calculate the quaternion which rotates the ligand to point to the given receptor restraint
            q = get_quaternion_for_restraint(rec_residue, lig_residue, tx, ty,
                                             tz, rec_translation,
                                             lig_translation)

        # Only restraints in the ligand partner
        elif ligand_restraints and not receptor_restraints:
            # The strategy is similar to previous but for the receptor side we will use a simulated point
            # over the receptor surface to point out the quaternion
            coef = norm(center) / ligand_diameter
            if coef > 1.0:
                raise LightDockWarning(
                    'Found wrong coefficient on calculating poses with restraints'
                )
            # It is important to keep the coordinates as in the original complex without
            # moving to the center of coordinates (applying translation)
            rec_residue = Residue.dummy(center[0] * coef - rec_translation[0],
                                        center[1] * coef - rec_translation[1],
                                        center[2] * coef - rec_translation[2])

            lig_residue = ligand_restraints[number_generator.randint(
                0,
                len(ligand_restraints) - 1)]
            q = get_quaternion_for_restraint(rec_residue, lig_residue, tx, ty,
                                             tz, rec_translation,
                                             lig_translation)
        # No restraints at all
        else:
            q = Quaternion.random(number_generator)

        # Glowworm's optimization vector
        op_vector = [tx, ty, tz, q.w, q.x, q.y, q.z]

        # If ANM is enabled, we need to create random components for the extents
        if rng_nm:
            if rec_nm > 0:
                op_vector.extend([rng_nm() for _ in range(rec_nm)])
            if lig_nm > 0:
                op_vector.extend([rng_nm() for _ in range(lig_nm)])

        new_poses.append(op_vector)

    return new_poses
Пример #28
0
 def test_to_string(self):
     atoms = [Atom(1, 'CA', '', 'A', 'ALA'), Atom(2, 'N', '', 'A', 'ALA')] 
     residue = Residue('ALA', 1, atoms)
     assert "ALA.1    CA   0.000   0.000   0.000\nALA.1     N   0.000   0.000   0.000" == str(residue)
Пример #29
0
 def test_is_standard(self):
     residue1 = Residue('ALA', 1)
     residue2 = Residue('MG2', 2)
     
     assert residue1.is_standard()
     assert not residue2.is_standard()
Пример #30
0
 def test_create_residue_with_atoms(self):
     residue = Residue('ALA', 1, [Atom(), Atom()])
     assert residue.name == 'ALA' and residue.number == 1 and len(residue.atoms) == 2
Пример #31
0
 def test_is_nucleic(self):
     residue1 = Residue('DT', 1)
     residue2 = Residue('I', 2)
     
     assert residue1.is_nucleic()
     assert residue2.is_nucleic()
Пример #32
0
 def test_create_residue_empty_atoms(self):
     residue = Residue('ALA', 1)
     assert residue.name == 'ALA' and residue.number == 1 and len(residue.atoms) == 0
Пример #33
0
 def test_is_standard(self):
     residue1 = Residue('ALA', 1)
     residue2 = Residue('MG2', 2)
     
     assert residue1.is_standard()
     assert not residue2.is_standard()