def find_b_turn(structure_name, file_name, chain, error):
    parser = PDBParser()

    structure = parser.get_structure(structure_name, file_name)

    vectors = []
    phi = []
    psi = []
    exp_phi = np.array([60, -80])
    exp_psi = np.array([-120, 0])
    b_turns = []

    for atom in structure[0][chain].get_atoms():
        vectors.append(atom.get_vector())

    for i in range(len(vectors) - 2):
        if i % 2 == 0:
            phi.append(calc_angle(vectors[i], vectors[i + 1], vectors[i + 2]))
        else:
            psi.append(calc_angle(vectors[i], vectors[i + 1], vectors[i + 2]))

    df = pd.DataFrame(list(zip(phi, psi)), columns=['phi', 'psi'])

    for df_slice in df.rolling(window=2):
        if np.allclose(df_slice['phi'].values, exp_phi,
                       atol=error) and np.allclose(
                           df_slice['psi'].values, exp_psi, atol=error):
            b_turns.append(df_slice)

    return b_turns
Example #2
0
def build_all_angles_model(pdb_filename):
    parser = PDBParser()
    structure = parser.get_structure("sample", Path(PDBdir, pdb_filename))
    model = structure[0]
    chain = model["A"]
    model_structure_geo = []
    prev = "0"
    N_prev = "0"
    CA_prev = "0"
    CO_prev = "0"
    prev_res = ""
    rad = 180.0 / math.pi
    for res in chain:
        if res.get_resname() in resdict.keys():
            geo = Geometry.geometry(resdict[res.get_resname()])
            if prev == "0":
                N_prev = res["N"]
                CA_prev = res["CA"]
                C_prev = res["C"]
                prev = "1"
            else:
                n1 = N_prev.get_vector()
                ca1 = CA_prev.get_vector()
                c1 = C_prev.get_vector()

                C_curr = res["C"]
                N_curr = res["N"]
                CA_curr = res["CA"]

                c = C_curr.get_vector()
                n = N_curr.get_vector()
                ca = CA_curr.get_vector()

                geo.CA_C_N_angle = calc_angle(ca1, c1, n) * rad
                geo.C_N_CA_angle = calc_angle(c1, n, ca) * rad

                psi = calc_dihedral(n1, ca1, c1, n)  ##goes to current res
                omega = calc_dihedral(ca1, c1, n, ca)  ##goes to current res
                phi = calc_dihedral(c1, n, ca, c)  ##goes to current res

                geo.psi_im1 = psi * rad
                geo.omega = omega * rad
                geo.phi = phi * rad

                geo.N_CA_C_angle = calc_angle(n, ca, c) * rad
                ##geo.CA_C_O_angle= calc_angle(ca, c, o)*rad

                ##geo.N_CA_C_O= calc_dihedral(n, ca, c, o)*rad

                N_prev = res["N"]
                CA_prev = res["CA"]
                C_prev = res["C"]
                ##O_prev=res['O']

            model_structure_geo.append(geo)
    return model_structure_geo
def get_angles(vectors):
    """ Get the angles between each pair in the list of vectors """
    angles = []
    for i in range(len(vectors)-2):
        angles.append(calc_angle(vectors[i],
                                 vectors[i+1],
                                 vectors[i+2]))
    return angles
def CalcOrientationOf4CAs(CAi1, CAi2, CAj1, CAj2):
    angle = calc_angle(CAi1, CAi2, CAj1) * 180 / np.pi
    if CAj2 is None:
        angle2 = InvalidDegree
        dihedral = InvalidDegree
        dihedral2 = InvalidDegree
    else:
        angle2 = calc_angle(CAi1, CAi2, CAj2) * 180 / np.pi
        dihedral = calc_dihedral(CAi1, CAi2, CAj1, CAj2) * 180 / np.pi
        dihedral2 = calc_dihedral(CAi1, CAi2, CAj2, CAj1) * 180 / np.pi

    return {
        'Ca1Ca2Ca3Ca4': dihedral,
        'Ca1Ca2Ca3': angle,
        'Ca1Ca2Ca4Ca3': dihedral2,
        'Ca1Ca2Ca4': angle2
    }
 def __str__(self):
     d1 = abs(O3_P_DIST - float(self.o3 - self.p))
     d2 = abs(P_O5_DIST - float(self.p - self.o5))
     d3 = abs(O5_C5_DIST - float(self.o5 - self.c5))
     a1 = math.degrees(calc_angle(self.c3v, self.o3v, self.p.get_vector()))
     a2 = math.degrees(
         calc_angle(self.o3v, self.p.get_vector(), self.o5.get_vector()))
     a3 = math.degrees(
         calc_angle(self.p.get_vector(), self.o5.get_vector(),
                    self.c5.get_vector()))
     a4 = math.degrees(calc_angle(self.o5.get_vector(), self.c5v,
                                  self.c42v))
     a1 = abs(a1 - A1)
     a2 = abs(a2 - A2)
     a3 = abs(a3 - A3)
     a4 = abs(a4 - A4)
     result = "%5.2f\t%5.2f\t%5.2f\t" % (d1, d2, d3)
     result += "%5.2f\t%5.2f\t%5.2f\t%5.2f\t" % (a1, a2, a3, a4)
     result += "total %5.2f\n" % self.get_score()
     return result
 def get_score(self, max_score=0.0):
     """Returns the square deviation from reference values."""
     d2 = P_O5_DIST - float(self.p - self.o5)
     d3 = O5_C5_DIST - float(self.o5 - self.c5)
     dscore = d2 * d2 + d3 * d3
     if dscore > max_score: return dscore
     #a2 = calc_angle(self.o3v,self.pv,self.o5v)* MAKE_DEGREES
     a3 = calc_angle(self.pv, self.o5v, self.c5v) * MAKE_DEGREES
     a4 = calc_angle(self.o5v, self.c5v, self.c42v) * MAKE_DEGREES
     # calc difference to standard values
     #a2 = (a2-A2)*ANGLE_WEIGHT
     a3 = (a3 - A3) * ANGLE_WEIGHT
     a4 = (a4 - A4) * ANGLE_WEIGHT
     # using a small numpy array is slower
     #ang = array((a2, a3, a4))
     #ang = ang * MAKE_DEGREES
     #ascore = ang-STD_ANGLES
     #ascore *= ANGLE_WEIGHT
     #ascore = sum(ascore * ascore)
     ascore = a3 * a3 + a4 * a4  # a2*a2 +
     return dscore + ascore
Example #7
0
 def get_theta_list(self):
     """List of theta angles for all 3 consecutive Calpha atoms."""
     theta_list = []
     ca_list = self.get_ca_list()
     for i in range(0, len(ca_list) - 2):
         atom_list = (ca_list[i], ca_list[i + 1], ca_list[i + 2])
         v1, v2, v3 = [a.get_vector() for a in atom_list]
         theta = calc_angle(v1, v2, v3)
         theta_list.append(theta)
         # Put tau in xtra dict of residue
         res = ca_list[i + 1].get_parent()
         res.xtra["THETA"] = theta
     return theta_list
 def get_angles(self, expression):
     result = GeometryResult('angles of (%s)'%expression, angles=True)
     expr = GeometryExpression(expression)
     for struc in self.get_structures():
         for atom1,atom2,atom3 in expr.get_atoms(struc):
             a = calc_angle(atom1.get_vector(),atom2.get_vector(),atom3.get_vector())
             #a=angle(atom2.coord-atom1.coord,atom2.coord-atom3.coord)
             a = a*180.0/math.pi
             a1 = self.get_atom_annotation(atom1)
             a2 = self.get_atom_annotation(atom2)
             a3 = self.get_atom_annotation(atom3)
             result.append((a,a1,a2,a3))
     return result
Example #9
0
 def get_theta_list(self):
     """List of theta angles for all 3 consecutive Calpha atoms."""
     theta_list = []
     ca_list = self.get_ca_list()
     for i in range(0, len(ca_list) - 2):
         atom_list = (ca_list[i], ca_list[i + 1], ca_list[i + 2])
         v1, v2, v3 = [a.get_vector() for a in atom_list]
         theta = calc_angle(v1, v2, v3)
         theta_list.append(theta)
         # Put tau in xtra dict of residue
         res = ca_list[i + 1].get_parent()
         res.xtra["THETA"] = theta
     return theta_list
Example #10
0
def add_terminal_OXT(structure: Structure,
                     C_OXT_length: float = 1.23) -> Structure:
    """Adds a terminal oxygen atom ('OXT') to the last residue of chain A model 0 of the given structure, and returns the new structure. The OXT atom object will be contained in the last residue object of the structure.

    This function should be used only when the structure object is completed and no further residues need to be appended."""

    rad = 180.0 / math.pi

    # obtain last residue infomation
    resRef = getReferenceResidue(structure, -1)
    N_resRef = resRef["N"]
    CA_resRef = resRef["CA"]
    C_resRef = resRef["C"]
    O_resRef = resRef["O"]

    n_vec = N_resRef.get_vector()
    ca_vec = CA_resRef.get_vector()
    c_vec = C_resRef.get_vector()
    o_vec = O_resRef.get_vector()

    # geometry to bring together residue
    CA_C_OXT_angle = calc_angle(ca_vec, c_vec, o_vec) * rad
    N_CA_C_O_diangle = calc_dihedral(n_vec, ca_vec, c_vec, o_vec) * rad
    N_CA_C_OXT_diangle = N_CA_C_O_diangle - 180.0
    if N_CA_C_O_diangle < 0:
        N_CA_C_OXT_diangle = N_CA_C_O_diangle + 180.0

    # OXT atom creation
    OXT_coord = calculateCoordinates(N_resRef, CA_resRef, C_resRef,
                                     C_OXT_length, CA_C_OXT_angle,
                                     N_CA_C_OXT_diangle)
    OXT = Atom("OXT", OXT_coord, 0.0, 1.0, " ", "OXT", 0, "O")

    # modify last residue of the structure to contain the OXT atom
    resRef.add(OXT)

    if structure[0]["A"][1].get_resname() == "ACE":
        del structure[0]["A"][1]["N"]

    return structure
residues = structure.get_residues()
for residue in residues:
    print(residue)
# 나도 이거 처음보는거라 목록부터 봐야됨...
residue1 = structure[0]["A"][273]["CA"]
residue2 = structure[0]["A"][278]["CA"]
print(residue1 - residue2)
# Residue간 거리
# 6.962208
atom1 = structure[0]["A"][423]["CA"]
atom2 = structure[0]["A"][423]["CB"]
atom3 = structure[0]["A"][423]["N"]
vector1 = atom1.get_vector()
vector2 = atom2.get_vector()
vector3 = atom3.get_vector()
angle = calc_angle(vector1, vector2, vector3)
print(angle)
# 각(별)도
# 0.5872530070961592

atom1 = structure[0]["A"][415]["CA"]
atom2 = structure[0]["A"][423]["CA"]
atom3 = structure[0]["A"][431]["CA"]
atom4 = structure[0]["A"][439]["CA"]
vector1 = atom1.get_vector()
vector2 = atom2.get_vector()
vector3 = atom3.get_vector()
vector4 = atom4.get_vector()
torsion = calc_dihedral(vector1, vector2, vector3, vector4)
print(torsion)
# Torsion angle 계산
def CalcTwoROriMatrix(coordinates):
    seqLen = len(coordinates)
    oriMatrix = dict()

    apts = ['Ca1Cb1Cb2Ca2', 'N1Ca1Cb1Cb2', 'Ca1Cb1Cb2']
    for apt in apts:
        oriMatrix[apt] = np.full((seqLen, seqLen),
                                 InvalidDegree,
                                 dtype=np.float16)

    numInvalidTwoROri = 0

    def ValidCB(c):
        if c['CB'] is None:
            return False

        ## when CB is copied from CA, we do not use it to calculate some angles
        if c['CA'] is not None and np.linalg.norm(c['CB'] - c['CA']) < 0.1:
            return False
        return True

    for i in range(seqLen):
        ci = coordinates[i]
        if ci is None:
            continue

## we cannot replace ci CB by its CA atom since CA itself is needed for the three angles
        if ValidCB(ci):
            cicb = ci['CB']
        elif ci.has_key('vCB') and (ci['vCB'] is not None):
            cicb = ci['vCB']
        else:
            continue

        for j in range(seqLen):
            if i == j:
                continue

            cj = coordinates[j]
            if cj is None:
                continue

            if ci['CA'] is not None and cj['CA'] is not None:
                if ValidCB(cj):
                    oriMatrix['Ca1Cb1Cb2Ca2'][i, j] = calc_dihedral(
                        ci['CA'], cicb, cj['CB'], cj['CA']) * 180 / np.pi
                elif cj.has_key('vCB') and cj['vCB'] is not None:
                    oriMatrix['Ca1Cb1Cb2Ca2'][i, j] = calc_dihedral(
                        ci['CA'], cicb, cj['vCB'], cj['CA']) * 180 / np.pi
                ## otherwise, assign InvalidDegree to Ca1Cb1Cb2Ca2 since we cannot replace cj CB by its CA atom

            if ci['N'] is not None and ci['CA'] is not None:
                if ValidCB(cj):
                    oriMatrix['N1Ca1Cb1Cb2'][i, j] = calc_dihedral(
                        ci['N'], ci['CA'], cicb, cj['CB']) * 180 / np.pi
                else:
                    ## replace cj CB by cj CA if the latter exists, otherwise check if vCB exists
                    if cj['CA'] is not None:
                        oriMatrix['N1Ca1Cb1Cb2'][i, j] = calc_dihedral(
                            ci['N'], ci['CA'], cicb, cj['CA']) * 180 / np.pi
                    elif cj.has_key('vCB') and cj['vCB'] is not None:
                        oriMatrix['N1Ca1Cb1Cb2'][i, j] = calc_dihedral(
                            ci['N'], ci['CA'], cicb, cj['vCB']) * 180 / np.pi

            if ci['CA'] is not None:
                if ValidCB(cj):
                    oriMatrix['Ca1Cb1Cb2'][i, j] = calc_angle(
                        ci['CA'], cicb, cj['CB']) * 180 / np.pi
                else:
                    ## replace cj CB by cj CA if the latter exists, otherwise check if vCB exists
                    if cj['CA'] is not None:
                        oriMatrix['Ca1Cb1Cb2'][i, j] = calc_angle(
                            ci['CA'], cicb, cj['CA']) * 180 / np.pi
                    elif cj.has_key('vCB') and cj['vCB'] is not None:
                        oriMatrix['Ca1Cb1Cb2'][i, j] = calc_angle(
                            ci['CA'], cicb, cj['vCB']) * 180 / np.pi

    for apt in apts:
        np.fill_diagonal(oriMatrix[apt], ValueOfSelf)

#oriMatrix['numInvalidTwoROri'] = numInvalidTwoROri

    return oriMatrix
Example #13
0
def find_geometry(metals,
                  structure,
                  permissive=False,
                  all_metals=False,
                  external=None):

    # check metal contacts
    output = []
    checked_metals = []
    structure_list = Selection.unfold_entities(structure, "A")

    for metal in metals:

        # search distance based on metal type
        if metal[0].element == "YB":
            dist = 3.5
        elif metal[0].element == "K":
            dist = 3.3
        else:
            dist = 2.9

        metal_str = "{}:{}:{}".format(metal[2].id, metal[1].get_id()[1],
                                      metal[0].name)
        in_ext = []

        for i in external:
            if metal_str in i:
                in_ext = True

        if not in_ext and list(metal[0].coord) not in checked_metals:
            coords = metal[0].coord

            contacts = []

            for chain in structure.get_chains():

                for residue in chain.get_residues():
                    contacts_atoms = NeighborSearch(structure_list).search(
                        coords, dist, "A")
                    # exclude self-contacts, carbons and hydrogens
                    excluded_contacts = cs.metals + ['C', 'H']
                    contacts_atoms = [
                        c for c in contacts_atoms
                        if c.element not in excluded_contacts
                    ]

                    for atom in contacts_atoms:
                        if residue in chain.get_residues(
                        ) and atom in residue.get_atoms():
                            contacts.append([atom, residue, chain])

            combinations = list(itertools.combinations(contacts, 2))
            combinations = [list(c) for c in combinations]

            # get all atom - metal - atom angles
            for c in combinations:
                vi = Vector(c[0][0].coord)
                vj = Vector(c[1][0].coord)
                angle = vectors.calc_angle(vi, coords, vj) * 180 / np.pi
                c.append(angle)

            geo, coordinated_atoms = angle_classification(combinations, False)

            if geo is None and permissive:
                geo, coordinated_atoms = angle_classification(
                    combinations, True)

                if geo is None and all_metals and combinations:

                    geo, coordinated_atoms = angle_classification(
                        combinations, True)
                    if geo:
                        print(
                            "Found {} geometry around {} (residue {}). Adding constraints."
                            .format(geo, metal[0].name, metal[1].get_id()[1]))
                        checked_metals.append(list(metal[0].coord))
                    else:
                        coordinated_atoms = combinations
                        checked_metals.append(list(metal[0].coord))
                        geo = "no"
                        print(
                            "Found {} geometry around {} (residue {}). Adding constraints to all atoms within {}A of the metal."
                            .format(geo, metal[0].name, metal[1].get_id()[1],
                                    dist))

                elif geo is None and not all_metals:
                    raise ce.NoGeometryAroundMetal(
                        "Failed to determine geometry around {} (residue {}). Add constraints manually or set 'constrain_all_metals: true' to constrain all atoms within {}A of the metal."
                        .format(metal[0].name, metal[1].get_id()[1], dist))

                elif geo is None and all_metals and not combinations:
                    print("No atoms coordinated to {} (residue {}).".format(
                        metal[0].name, metal[1].get_id()[1]))

                elif geo:
                    checked_metals.append(list(metal[0].coord))
                    print(
                        "Found {} geometry around {} (residue {}). Adding constraints."
                        .format(geo, metal[0].name, metal[1].get_id()[1]))

            elif geo is None and all_metals and combinations:
                geo, coordinated_atoms = angle_classification(
                    combinations, True)

                if geo is None:
                    geo = "no"
                    coordinated_atoms = combinations
                    checked_metals.append(list(metal[0].coord))
                    print(
                        "Found {} geometry around {} (residue {}). Adding constraints to all atoms within {}A of the metal."
                        .format(geo, metal[0].name, metal[1].get_id()[1],
                                dist))

                else:
                    print(
                        "Found {} geometry around {} (residue {}). Adding constraints."
                        .format(geo, metal[0].name, metal[1].get_id()[1]))

            elif geo is None and all_metals and not combinations:
                print("No atoms coordinated to {} (residue {}).".format(
                    metal[0].name, metal[1].get_id()[1]))

            elif geo is None and not all_metals and not permissive:
                raise ce.NoGeometryAroundMetal(
                    "Failed to determine geometry around {} (residue {}). Add constraints manually or set 'constrain_all_metals: true' to constrain all atoms within {}A of the metal."
                    .format(metal[0].name, metal[1].get_id()[1], dist))

            else:
                checked_metals.append(list(metal[0].coord))
                print(
                    "Found {} geometry around {} (residue {}). Adding constraints."
                    .format(geo, metal[0].name, metal[1].get_id()[1]))

            # format string
            yaml_string = "{}-{}-{}:{}:{}-{}:{}:{}"
            spring_const = 50

            string_atoms = []
            for c in coordinated_atoms:
                atom1, atom2, angle = c

                if atom1 not in string_atoms:
                    string_atoms.append(atom1)
                if atom2 not in string_atoms:
                    string_atoms.append(atom2)

            for atom in string_atoms:
                atomname1 = atom[0].name
                resnum1 = atom[1].get_id()[1]
                chain1 = atom[2].get_id()

                atomname2 = metal[0].name
                resnum2 = metal[1].get_id()[1]
                chain2 = metal[2].get_id()

                atom_dist = atom[0] - metal[0]
                out = yaml_string.format(spring_const, atom_dist, chain1,
                                         resnum1, atomname1, chain2, resnum2,
                                         atomname2)

                output.append(out)

            output = list(set(output))

            if output:
                output = ['{}'.format(o) for o in output]

    return output
 def _get_alpha(self):
     # SLOWER
     #return PDB.calc_angle(Vector(self.donor), Vector(self.hydrogen), Vector(self.acceptor))* 180.0/pi
     return degrees(calc_angle(self.donor, self.hydrogen, self.acceptor))
 def _get_gamma(self):
     return degrees(calc_angle(self.donor, self.hydrogen, self.acc_support))
 def _get_beta(self):
     return degrees(
         calc_angle(self.hydrogen, self.acceptor, self.acc_support))
def process_tertiary(tertiary):
    '''compute the bond lengths, bond angles, and dihedral angles'''
    phi = []
    psi = []
    omega = []
    bond_angle_CNCa = []
    bond_angle_NCaC = []
    bond_angle_CaCN = []
    bond_len_NCa = []
    bond_len_CaC = []
    bond_len_CN = []
    # convert tertiary coords into Vectors
    pV = [vec for vec in map(lambda v: Vector(v[0], v[1], v[2]),
                             zip(tertiary[0], tertiary[1], tertiary[2]))]

    for i in range(0, len(pV), 3):
        # check for zero coords
        norm_im1 = False
        norm_i = False
        norm_i1 = False
        norm_i2 = False
        norm_i3 = False
        norm_i4 = False
        if i > 0 and pV[i-1].norm() > 0:
            norm_im1 = True
        if pV[i].norm() > 0:
            norm_i = True
        if pV[i+1].norm() > 0:
            norm_i1 = True
        if pV[i+2].norm() > 0:
            norm_i2 = True
        if i + 3 < len(pV) and pV[i+3].norm() > 0:
            norm_i3 = True
        if i + 3 < len(pV) and pV[i+4].norm() > 0:
            norm_i4 = True

        # compute bond lengths
        if norm_im1 and norm_i:
            blen_CN = (pV[i-1]-pV[i]).norm()
            bond_len_CN.append(blen_CN)

        if norm_i and norm_i1:
            blen_NCa = (pV[i]-pV[i+1]).norm()
            bond_len_NCa.append(blen_NCa)

        if norm_i1 and norm_i2:
            blen_CaC = (pV[i+1]-pV[i+2]).norm()
            bond_len_CaC.append(blen_CaC)

        # compute bond angles
        if norm_im1 and norm_i and norm_i1:
            theta_CNCa = calc_angle(pV[i-1], pV[i], pV[i+1])  # C-N-Ca
            bond_angle_CNCa.append(theta_CNCa)

        if norm_i and norm_i1 and norm_i2:
            theta_NCaC = calc_angle(pV[i], pV[i+1], pV[i+2])  # N-Ca-C
            bond_angle_NCaC.append(theta_NCaC)

        if norm_i1 and norm_i2 and norm_i3:
            theta_CaCN = calc_angle(pV[i+1], pV[i+2], pV[i+3])  # Ca-C-N
            bond_angle_CaCN.append(theta_CaCN)

        # compute dihedral angles
        if norm_im1 and norm_i and norm_i1 and norm_i2:
            phi_i = calc_dihedral(
                pV[i-1], pV[i], pV[i+1], pV[i+2])  # N-Ca-C-N
        else:
            phi_i = INVALID_ANGLE
        phi.append(phi_i)

        if norm_i and norm_i1 and norm_i2 and norm_i3:
            psi_i = calc_dihedral(
                pV[i], pV[i+1], pV[i+2], pV[i+3])  # C-N-Ca-C
        else:
            psi_i = INVALID_ANGLE
        psi.append(psi_i)

        if norm_i1 and norm_i2 and norm_i3 and norm_i4:
            omega_i = calc_dihedral(
                pV[i+1], pV[i+2], pV[i+3], pV[i+4])  # Ca-C-N-Ca
        else:
            omega_i = INVALID_ANGLE
        omega.append(omega_i)

    return (phi, psi, omega, bond_angle_NCaC, bond_angle_CaCN,
            bond_angle_CNCa, bond_len_CN, bond_len_NCa, bond_len_CaC)
Example #18
0
error = 30

vectors = []
phi = []
psi = []
exp_phi = np.array([60, -80])
exp_psi = np.array([-120, 0])
b_turns = []

for atom in structure[0]['A'].get_atoms():
    vectors.append(atom.get_vector())

for i in range(len(vectors) - 2):
    if i % 2 == 0:
        phi.append(calc_angle(vectors[i], vectors[i + 1], vectors[i + 2]))
    else:
        psi.append(calc_angle(vectors[i], vectors[i + 1], vectors[i + 2]))

df = pd.DataFrame(list(zip(phi, psi)), columns=['phi', 'psi'])

for df_slice in df.rolling(window=2):
    if np.allclose(df_slice['phi'].values, exp_phi,
                   atol=error) and np.allclose(
                       df_slice['psi'].values, exp_psi, atol=error):
        b_turns.append(df_slice)

print('hello')

dssp = DSSP(structure[0], '1g60.pdb', dssp='mkdssp')
Example #19
0
# print(fe1_atom.get_vector)
# <bound method Atom.get_vector of <Atom FE1>>

fe1Vec = fe1_atom.get_vector()
# print(fe1_atom.get_vector())
# <Vector 2.26, 14.39, 74.72>

# fe2_atom = residue['FE2']
# fe2Vec = fe2.get_vector()

#calculate S3-FE4-S2  angle
S3_atom = residue[
    'S3']  #need to know which atoms (atom name i.e. "FE4") are connected and which atom is the center atom in angle
S3Vec = S3_atom.get_vector()

FE4_atom = residue['FE4']
FE4Vec = FE4_atom.get_vector()

S2_atom = residue['S2']
S2Vec = S2_atom.get_vector()

angleS3_SF4_S2 = vectors.calc_angle(S3Vec, FE4Vec, S2Vec)
# 1.867073476442546 #in radians
angleDegrees = (angleS3_SF4_S2 * 180 / np.pi)  #convert to degrees
print(angleDegrees)

# residue = chain
# print(residue)
# atom = residue["SF4"]

# print(atom.get_list())
Example #20
0
def pdb_to_npz(npz_name, pdb_file=False, mmCIF_file=False, std=1):
    """
    Convert a pdb/mcif to trRosetta distances/angles
    """

    if pdb_file:
        from Bio.PDB.PDBParser import PDBParser
        bio_parser = PDBParser(PERMISSIVE=1)
        structure_file = pdb_file
        structure_id = pdb_file.name[:-4]
    elif mmCIF_file:
        from Bio.PDB.MMCIFParser import MMCIFParser
        bio_parser = MMCIFParser()
        structure_file = mmCIF_file
        structure_id = mmCIF_file.name[:-4]
    else:
        print("No file given: one pdb or one mmCIF file has to be definied")
        sys.exit()

    # Load structure
    structure = bio_parser.get_structure(structure_id, structure_file)

    # Get residues and length of protein
    residues = []
    for chain in structure[0]:
        for residue1 in structure[0][chain.id]:
            if not is_aa(residue1):
                continue
            residues.append(residue1.get_resname())
    plen = len(residues)

    # Setup bins and step for the final matrix
    DIST_STEP = 0.5
    OMEGA_STEP = 15
    THETA_STEP = 15
    PHI_STEP = 15

    z_per_bin = std/DIST_STEP
    z_step = z_per_bin/2
    angle_z_step = 1

    minvalue = 0.01
    dist_wanted_bins = (20 - 2)/DIST_STEP
    omega_wanted_bins = 360/OMEGA_STEP
    theta_wanted_bins = 360/THETA_STEP
    phi_wanted_bins = 180/PHI_STEP
    cumm_cutoff = 0.899
    # cb_lst = get_cb_coordinates(open(args.pdb_file, 'r'), "A")
    # contact_mat = get_cb_contacts(len(residues))
    dist_mat = np.full((plen, plen, 37), minvalue/36)
    omega_mat = np.full((plen, plen, 25), minvalue/24)
    theta_mat = np.full((plen, plen, 25), minvalue/24)
    phi_mat = np.full((plen, plen, 13), minvalue/12)

    dist_bins = [i for i in np.arange(2, 2 + (dist_wanted_bins)*0.5, 0.5)]
    omega_bins = [i for i in np.arange(-180, -180 +
                  (omega_wanted_bins)*OMEGA_STEP, OMEGA_STEP)]
    theta_bins = [i for i in np.arange(-180, -180 +
                  (theta_wanted_bins)*THETA_STEP, THETA_STEP)]
    phi_bins = [i for i in np.arange(0, (phi_wanted_bins)*PHI_STEP, PHI_STEP)]
    dist_num_bins = len(dist_bins)
    omega_num_bins = len(omega_bins)
    theta_num_bins = len(theta_bins)
    phi_num_bins = len(phi_bins)

    # Iterate over all residues and calculate distances
    i = 0
    j = 0
    for chain in structure[0]:
        for residue1 in structure[0][chain.id]:
        # Only use real atoms, not HET or water
            if not is_aa(residue1):
                continue
            
            # If the residue lacks CB (Glycine etc), create a virtual
            if residue1.has_id('CB'):
                c1B = residue1['CB'].get_vector()
            else:
                c1B = _virtual_cb_vector(residue1)
            
            j = 0
            for chain in structure[0]:
                for residue2 in structure[0][chain.id]:
                    symm = False
                    if not is_aa(residue2):
                        continue
                    # print(i,j)
                    if i == j:
                        dist_mat[i, j, 0] = (1-minvalue)
                        omega_mat[i, j, 0] = (1-minvalue)
                        theta_mat[i, j, 0] = (1-minvalue)
                        phi_mat[i, j, 0] = (1-minvalue)
                        j += 1
                        continue
                    
                    if i > j:
                        dist_mat[i, j] = dist_mat[j, i]
                        omega_mat[i, j] = omega_mat[j, i]
                        symm = True
                    # If the residue lacks CB (Glycine etc), create a virtual
                    if residue2.has_id('CB'):
                        c2B = residue2['CB'].get_vector()
                    else:
                        c2B = _virtual_cb_vector(residue2)
                    ###############################################
                    dist = (c2B-c1B).norm()
                    
                    if dist > 20:
                        dist_mat[i, j, 0] = (1-minvalue)
                        omega_mat[i, j, 0] = (1-minvalue)
                        theta_mat[i, j, 0] = (1-minvalue)
                        phi_mat[i, j, 0] = (1-minvalue)
                    else:
                        # Dist and omega are symmetrical and have already been copied
                        if not symm:
                            ix = np.digitize(dist, dist_bins)
                            cum_prob = 0
                            b_step = 0
                            while cum_prob < cumm_cutoff:
                                bin_prob = st.norm.cdf(b_step*-z_step) -\
                                    st.norm.cdf(-z_step*(1+b_step))
                                dist_mat[i, j, np.min([ix+b_step, dist_num_bins])]\
                                    += bin_prob
                                dist_mat[i, j, np.max([ix-b_step, 1])] += bin_prob
                                cum_prob += bin_prob*2
                                b_step += 1
                        ###############################################
                        # # Omega
                        c1A = residue1['CA'].get_vector()
                        c2A = residue2['CA'].get_vector()
                    
                        if not symm:
                            raw_omega = calc_dihedral(c1A, c1B, c2B, c2A)
                            omega = (raw_omega*180)/pi
                    
                            ix = np.digitize(omega, omega_bins)
                            cum_prob = 0
                            b_step = 0
                            while cum_prob < cumm_cutoff:
                                bin_prob = st.norm.cdf(b_step*-angle_z_step) -\
                                    st.norm.cdf(-angle_z_step*(1+b_step))
                                omega_mat[i, j, np.min([ix+b_step, omega_num_bins])]\
                                    += bin_prob
                                omega_mat[i, j, np.max([ix-b_step, 1])] += bin_prob
                                cum_prob += bin_prob*2
                                b_step += 1
                    
                        ###############################################
                        # # Theta
                        N1 = residue1['N'].get_vector()
                    
                        raw_theta = calc_dihedral(N1, c1A, c1B, c2B)
                        theta = (raw_theta*180)/pi
                    
                        ix = np.digitize(theta, theta_bins)
                        cum_prob = 0
                        b_step = 0
                        while cum_prob < cumm_cutoff:
                            bin_prob = st.norm.cdf(b_step*-angle_z_step) -\
                                st.norm.cdf(-angle_z_step*(1+b_step))
                            theta_mat[i, j, np.min([ix+b_step, theta_num_bins])]\
                                += bin_prob
                            theta_mat[i, j, np.max([ix-b_step, 1])] += bin_prob
                            cum_prob += bin_prob*2
                            b_step += 1
                    
                        ###############################################
                        # # Phi
                    
                        raw_phi = calc_angle(c1A, c1B, c2B)
                        phi = (raw_phi*180)/pi
                    
                        ix = np.digitize(phi, phi_bins)
                        cum_prob = 0
                        b_step = 0
                        while cum_prob < cumm_cutoff:
                            bin_prob = st.norm.cdf(b_step*-angle_z_step) -\
                                st.norm.cdf(-angle_z_step*(1+b_step))
                            phi_mat[i, j, np.min([ix+b_step, phi_num_bins])]\
                                += bin_prob
                            phi_mat[i, j, np.max([ix-b_step, 1])] += bin_prob
                            cum_prob += bin_prob*2
                            b_step += 1
                    j += 1
            i += 1

    np.savez_compressed(npz_name,
                        dist=dist_mat,
                        omega=omega_mat,
                        theta=theta_mat,
                        phi=phi_mat)