Beispiel #1
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
Beispiel #2
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
Beispiel #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
Beispiel #4
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
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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
Beispiel #9
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])
Beispiel #10
0
    def test_dummy_residue(self):
        dummy = Residue.dummy(1.0, 2.0, 3.0)

        assert len(dummy.atoms) == 1
        assert dummy.atoms[0].name == "CA"
        assert str(dummy.atoms[0]) == "  CA   1.000   2.000   3.000"