Beispiel #1
0
def getBackbone(residues):
    phi = [0.0]
    psi = []
    for i, res_i in enumerate(residues):
        N_i = res_i["N"].get_vector()
        CA_i = res_i["CA"].get_vector()
        C_i = res_i["C"].get_vector()
        if i > 0:
            res_im1 = residues[i - 1]
            C_im1 = res_im1["C"].get_vector()
            phi.append(calc_dihedral(C_im1, N_i, CA_i, C_i))
        if i < (len(residues) - 1):
            res_ip1 = residues[i + 1]
            N_ip1 = res_ip1["N"].get_vector()
            psi.append(calc_dihedral(N_i, CA_i, C_i, N_ip1))
    psi.append(0.0)
    return phi, psi
Beispiel #2
0
    def omega(self, i, rosetta_definitions=True):
        """
        Get the Omega Angle of i in radians
        Omega is defined as the dihedral angle between the peptide bond of i and i + 1, as in Rosetta.
        If rosetta_definitions are False, omega is then treated as being between i and i -1

        :param i: int
        :param reverse_rosetta_definitions: bool
        :rtype: float
        """
        res = self.all_residues[i]

        try:
            n = res['N'].get_vector()
            ca = res['CA'].get_vector()
            c = res['C'].get_vector()

            if rosetta_definitions and i < len(
                    self.all_residues) - 1 and self.connected_to_next(i):
                res_plus_one = self.all_residues[i + 1]
                next_n = res_plus_one['N'].get_vector()
                next_ca = res_plus_one['CA'].get_vector()
                omega = calc_dihedral(ca, c, next_n, next_ca)
                return omega

            elif not rosetta_definitions and i > 1 and self.connected_to_previous(
                    i):
                res_minus_one = self.all_residues[i - 1]
                pre_c = res_minus_one['C'].get_vector()
                pre_ca = res_minus_one['CA'].get_vector()
                omega = calc_dihedral(pre_ca, pre_c, n, ca)
                return omega
            else:
                return 0.0

        except BaseException:
            print "Could not get omega for " + repr(i)
            raise LookupError
    def test_Vector(self):
        """Test Vector object."""
        v1 = Vector(0, 0, 1)
        v2 = Vector(0, 0, 0)
        v3 = Vector(0, 1, 0)
        v4 = Vector(1, 1, 0)

        self.assertEqual(calc_angle(v1, v2, v3), 1.5707963267948966)
        self.assertEqual(calc_dihedral(v1, v2, v3, v4), 1.5707963267948966)
        self.assertTrue(
            numpy.array_equal((v1 - v2).get_array(), numpy.array([0.0, 0.0, 1.0]))
        )
        self.assertTrue(
            numpy.array_equal((v1 - 1).get_array(), numpy.array([-1.0, -1.0, 0.0]))
        )
        self.assertTrue(
            numpy.array_equal(
                (v1 - (1, 2, 3)).get_array(), numpy.array([-1.0, -2.0, -2.0])
            )
        )
        self.assertTrue(
            numpy.array_equal((v1 + v2).get_array(), numpy.array([0.0, 0.0, 1.0]))
        )
        self.assertTrue(
            numpy.array_equal((v1 + 3).get_array(), numpy.array([3.0, 3.0, 4.0]))
        )
        self.assertTrue(
            numpy.array_equal(
                (v1 + (1, 2, 3)).get_array(), numpy.array([1.0, 2.0, 4.0])
            )
        )
        self.assertTrue(numpy.array_equal(v1.get_array() / 2, numpy.array([0, 0, 0.5])))
        self.assertTrue(numpy.array_equal(v1.get_array() / 2, numpy.array([0, 0, 0.5])))
        self.assertEqual(v1 * v2, 0.0)
        self.assertTrue(
            numpy.array_equal((v1 ** v2).get_array(), numpy.array([0.0, -0.0, 0.0]))
        )
        self.assertTrue(
            numpy.array_equal((v1 ** 2).get_array(), numpy.array([0.0, 0.0, 2.0]))
        )
        self.assertTrue(
            numpy.array_equal(
                (v1 ** (1, 2, 3)).get_array(), numpy.array([0.0, 0.0, 3.0])
            )
        )
        self.assertEqual(v1.norm(), 1.0)
        self.assertEqual(v1.normsq(), 1.0)
        v1[2] = 10
        self.assertEqual(v1.__getitem__(2), 10)
Beispiel #4
0
def parse(structure, aa):
    # Solo consideramos el 1er modelo
    model = structure[0]
    num_chains = len(structure[0])
    print('Number of chains ' + str(num_chains))

    df = DataFrame([])
    res = 0

    for chain in model:
        for residue in chain:
            if residue.get_id()[0] == ' ': #ignore all hetero atoms
                name = residue.get_resname()
                if not isin(name, aa):
                    print('Non recognized residue ' + name)
                    return DataFrame([])
                N_xyz = residue['N'].get_vector()
                df = df.append({'chain':chain.id, 'aa': name, 'atom': 'N', 'res': res, 'coord': N_xyz}, ignore_index=True)
                CA_xyz = residue['CA'].get_vector()
                df = df.append({'chain':chain.id, 'aa': name, 'atom': 'CA', 'res': res, 'coord': CA_xyz}, ignore_index=True)
                C_xyz = residue['C'].get_vector()
                df = df.append({'chain':chain.id, 'aa': name, 'atom': 'C', 'res': res, 'coord': C_xyz}, ignore_index=True)
                res = res + 1

    bond_length = [(df.iloc[1].coord - df.iloc[0].coord).norm(), (df.iloc[2].coord - df.iloc[1].coord).norm()]
    bond_angle = [0, calc_angle(df.iloc[0].coord, df.iloc[1].coord, df.iloc[2].coord)*180/pi]
    torsion_angle = [0, 0]
    coord = [df.iloc[0].coord.get_array(), df.iloc[1].coord.get_array()]
    for ij in range(2, len(df)-1):
        bond_length.append((df.iloc[ij+1].coord - df.iloc[ij].coord).norm())
        bond_angle.append(calc_angle(df.iloc[ij-1].coord, df.iloc[ij].coord, df.iloc[ij+1].coord)*180/pi)
        torsion_angle.append(calc_dihedral(df.iloc[ij-2].coord, df.iloc[ij-1].coord, df.iloc[ij].coord, df.iloc[ij+1].coord)*180/pi)
        coord.append(df.iloc[ij].coord.get_array())

    bond_length.append(0)
    bond_angle.append(0)
    torsion_angle.append(0)
    coord.append(df.iloc[len(df)-1].coord.get_array())
    coord = array(coord)
    df_new = df.drop('coord', axis=1)
    df_new['x'] = coord[:, 0]
    df_new['y'] = coord[:, 1]
    df_new['z'] = coord[:, 2]
    df_new['bond_length'] = bond_length
    df_new['bond_angle'] = bond_angle
    df_new['torsion_angle'] = torsion_angle
    return df_new
Beispiel #5
0
    def create_j_dict(self):
        """ Description:
              Given an JCalcPdb struct, create J dictioary with chosen 3JH,H
              information to calc all J values

            Usage:
              JcalcPdb.create_j_dict()
        """

        j_dict = {}

        for j in self.j_list:
            chosen_j = f"{j[0]},{j[3]}"
            j_dict[chosen_j] = {}
            j_dict[chosen_j]["HX"] = self.atom_dict[j[0]][0]
            j_dict[chosen_j]["CX"] = self.atom_dict[j[1]][0]
            j_dict[chosen_j]["CY"] = self.atom_dict[j[2]][0]
            j_dict[chosen_j]["HY"] = self.atom_dict[j[3]][0]
            j_dict[chosen_j]["dih"] = calc_dihedral(self.atom_dict[j[0]][0],
                                                    self.atom_dict[j[1]][0],
                                                    self.atom_dict[j[2]][0],
                                                    self.atom_dict[j[3]][0]
                                                    )
            j_dict[chosen_j]["dih"] = math.degrees(j_dict[chosen_j]["dih"])
            j_dict[chosen_j]["substituents"] = {}
            self.j_dict = j_dict

            # Search subs for CX and create subs dict
            self.search_subs(hx_atom=j[0],
                             cx_atom=j[1],
                             cy_atom=j[2],
                             hy_atom=j[3],
                             j_atoms=j,
                             chosen_j=chosen_j
                             )
            # Search subs for CY and create subs dict
            self.search_subs(hx_atom=j[3],
                             cx_atom=j[2],
                             cy_atom=j[1],
                             hy_atom=j[0],
                             j_atoms=j,
                             chosen_j=chosen_j
                             )
Beispiel #6
0
    def calc_subs_coupling(self, HX, CX, CY, SY, dihedral, element):
        """ Description:
              Given an JCalcPdb struct and atom vectors, calculate
              J pertubation from substitute atoms

            Usage:
              JcalcPdb.calc_subs_coupling(vector_HX, vector_CX, vector_CY,
                                          vector_SY, HX-CX-CY-XY_dih,
                                          substitue_element
                                         )

            Parameters:
              HX:
                Atom coordinates vector, HX from HX-CX-CY-SY fragment
              CX:
                Atom coordinates vector, CX from HX-CX-CY-SY fragment
              CY:
                Atom coordinates vector, CY from HX-CX-CY-SY fragment
              SY:
                Atom coordinates vector, SY from HX-CX-CY-SY fragment
              dihedral:
                float, dihedral from JH,H fragment HX-CX-CY-XY in radians
              element:
                string, atom element from substitute atom (H, O, N)
        """

        huggins_constant = HUGGINS_ELECTRO[element]
        subs_dih = calc_dihedral(HX, CX, CY, SY)

        if subs_dih >= 0:
            return huggins_constant * \
                (0.56 + (-2.32 * (math.cos(math.radians((dihedral * -1) +
                 (17.9 * huggins_constant))) ** 2)))

        else:
            return huggins_constant * \
                (0.56 + (-2.32 * (math.cos(math.radians(dihedral +
                 (17.9 * huggins_constant))) ** 2)))
Beispiel #7
0
    def psi(self, i):
        """
        Get the Psi Angle of i in radians

        :param i: int
        :rtype: float
        """
        res = self.all_residues[i]

        if i == len(self.all_residues) or not self.connected_to_next(i):
            return 0.0

        try:
            n = res['N'].get_vector()
            ca = res['CA'].get_vector()
            c = res['C'].get_vector()
            res_plus_one = self.all_residues[i + 1]

            nn = res_plus_one['N'].get_vector()
            psi = calc_dihedral(n, ca, c, nn)
            return psi
        except Exception:
            print "Could not get psi for " + repr(i)
            raise LookupError
Beispiel #8
0
    def phi(self, i):
        """
        Get the Phi Angle of i in radians

        :param i: int
        :rtype: float
        """
        if i == 1 or not self.connected_to_previous(i):
            return 0.0

        res = self.all_residues[i]

        try:
            n = res['N'].get_vector()
            ca = res['CA'].get_vector()
            c = res['C'].get_vector()

            res_minus_one = self.all_residues[i - 1]
            cp = res_minus_one['C'].get_vector()
            phi = calc_dihedral(cp, n, ca, c)
            return phi
        except Exception:
            print "Could not get phi for " + repr(i)
            raise LookupError
Beispiel #9
0
from Bio.Alphabet import generic_protein
from Bio.PDB import calc_dihedral

seqs = [
    Seq('HRFKVYNYMSPTFCDHCGSLLWGLVKQGLKCEDCGMNVHHKCREKVANLC', generic_protein)
]

s = ds.Distructure('1ptq', seqs)
s.generate_primary_contacts()
s.run()

for r in s.get_residues():
    if r.get_resname() != 'GLY':
        v1 = r['CA'].get_vector()
        v2 = r['N'].get_vector()
        v3 = r['C'].get_vector()
        v4 = r['CB'].get_vector()
        theta = calc_dihedral(v1, v2, v3, v4)
        if theta < 0.:
            print("dihedral error at", r)
        else:
            print(r)
        pass
    pass

# NOTE write result to file
from Bio.PDB.mmcifio import MMCIFIO
io = MMCIFIO()
io.set_structure(s)
io.save('chirality_test.cif')