def rotateTranslatePdb(fname, rotX, rotY, rotZ, transX, transY, transZ, fnameOut=None): print(fname, rotX, rotY, rotZ, transX, transY, transZ, fnameOut) struct = myPDBParser(QUIET=True).get_structure(fname) rotationX = rotaxis(-rotX, Vector(1, 0, 0)) rotationY = rotaxis(rotY, Vector(0, 1, 0)) rotationZ = rotaxis(-rotZ, Vector(0, 0, 1)) translation = np.array((transX, transY, transZ), 'f') rotation = rotationX.dot(rotationY).dot(rotationZ) struct.transform(rotation, translation) if fnameOut is not None: fnameOut = fnameOut pdbWriter = PDBIO() pdbWriter.set_structure(struct) pdbWriter.save(fnameOut) return struct
def _get_gly_cb_vector(self, residue): """ Return a pseudo CB vector for a Gly residue. The pseudoCB vector is centered at the origin. CB coord=N coord rotated over -120 degrees along the CA-C axis. """ try: n_v=residue["N"].get_vector() c_v=residue["C"].get_vector() ca_v=residue["CA"].get_vector() except: return None # center at origin n_v=n_v-ca_v c_v=c_v-ca_v # rotation around c-ca over -120 deg rot=rotaxis(-math.pi*120.0/180.0, c_v) cb_at_origin_v=n_v.left_multiply(rot) # move back to ca position cb_v=cb_at_origin_v+ca_v # This is for PyMol visualization self.ca_cb_list.append((ca_v, cb_v)) return cb_at_origin_v
def BuildVirtualCB(residue): if residue.get_resname().upper() != 'GLY': print 'ERROR: you shall not build a virtual Cb atom for non-Glycine residue' exit(1) # get atom coordinates as vectors try: n = residue['N'].get_vector() c = residue['C'].get_vector() ca = residue['CA'].get_vector() except: print 'WARNING: failed to obtain all of N, C and CA atoms in building a virtual Cb atom for residue ', residue.get_full_id( ) return None # center at origin n = n - ca c = c - ca # find rotation matrix that rotates n -120 degrees along the ca-c vector rot = rotaxis(-np.pi * 120.0 / 180.0, c) # apply rotation to ca-n vector cb_at_origin = n.left_multiply(rot) # put on top of ca atom cb = cb_at_origin + ca return cb
def _virtual_cb_vector(residue): # get atom coordinates as vectors n = residue['N'].get_vector() c = residue['C'].get_vector() ca = residue['CA'].get_vector() # center at origin n = n - ca c = c - ca # find rotation matrix that rotates n -120 degrees along the ca-c vector rot = rotaxis(-pi*120.0/180.0, c) # apply rotation to ca-n vector cb_at_origin = n.left_multiply(rot) # put on top of ca atom cb = cb_at_origin + ca return cb
def virtual_cbeta(residue): """Copied from: https://biopython.org/wiki/The_Biopython_Structural_Bioinformatics_FAQ Function Calculates Atomic coordinates of virtual C-beta atom for glycine residue """ # get atom coordinates as vectors n = residue['N'].get_vector() c = residue['C'].get_vector() ca = residue['CA'].get_vector() # center at origin n = n - ca c = c - ca # find rotation matrix that rotates n -120 degrees along the ca-c vector rot = rotaxis(-np.pi * 120.0 / 180.0, c) # apply rotation to ca-n vector cb_at_origin = n.left_multiply(rot) # put on top of ca atom cb = cb_at_origin + ca return [round(i, 3) for i in cb]
def build_coords_2xSP3(dst, at0, at1, at2): """ Generates coordinates for two SP3 bonds given the other two **dst** Bond distance **at0** Central atom **at1** atom with existing bond **at2** atom with existing bond """ cr0 = Vector(at0.get_coord()) cr1 = Vector(at1.get_coord()) cr2 = Vector(at2.get_coord()) axe = cr0 - cr1 mat = rotaxis(120. * pi / 180., axe) bond = cr2 - cr0 bond.normalize() bond._ar = bond._ar * dst cr3 = cr0 + bond.left_multiply(mat) cr4 = cr0 + bond.left_multiply(mat).left_multiply(mat) crs = [] crs.append(cr3._ar) crs.append(cr4._ar) return crs
n_atoms = list(filter(lambda a: a.name == 'N', input_structure.get_atoms())) c_atoms = list(filter(lambda a: a.name == 'C', input_structure.get_atoms())) ca_atoms = list( filter(lambda a: a.name == 'CA', input_structure.get_atoms())) cb_xyz = [] for n_at, c_at, ca_at in zip(n_atoms, c_atoms, ca_atoms): n = n_at.get_vector() c = c_at.get_vector() ca = ca_at.get_vector() n = n - ca c = c - ca rot = rotaxis(-1 * np.pi * 120.0 / 180.0, c) cb_at_origin = n.left_multiply(rot) cb = cb_at_origin + ca cb_xyz.append(cb) input_distance_matrix = pd.DataFrame( np.array([[np.linalg.norm(at2 - at1) for at2 in cb_xyz] for at1 in cb_xyz])) input_distance_matrix[input_distance_matrix > 20] = 0 ppb = PDB.Polypeptide.PPBuilder() input_sequence = ppb.build_peptides(input_structure).pop().get_sequence() # dump input sequence into a temporary file and run TrRosetta with NamedTemporaryFile('+w') as fasta: fasta.write('> input\n{}'.format(input_sequence))
def calculateCoordinates(refA: Residue, refB: Residue, refC: Residue, L: float, ang: float, di: float) -> np.ndarray: AV = refA.get_vector() BV = refB.get_vector() CV = refC.get_vector() CA = AV - CV CB = BV - CV ##CA vector AX = CA[0] AY = CA[1] AZ = CA[2] ##CB vector BX = CB[0] BY = CB[1] BZ = CB[2] ##Plane Parameters A = (AY * BZ) - (AZ * BY) B = (AZ * BX) - (AX * BZ) G = (AX * BY) - (AY * BX) ##Dot Product Constant F = math.sqrt(BX * BX + BY * BY + BZ * BZ) * L * math.cos( ang * (math.pi / 180.0)) ##Constants const = math.sqrt( math.pow((B * BZ - BY * G), 2) * (-(F * F) * (A * A + B * B + G * G) + (B * B * (BX * BX + BZ * BZ) + A * A * (BY * BY + BZ * BZ) - (2 * A * BX * BZ * G) + (BX * BX + BY * BY) * G * G - (2 * B * BY) * (A * BX + BZ * G)) * L * L)) denom = ((B * B) * (BX * BX + BZ * BZ) + (A * A) * (BY * BY + BZ * BZ) - (2 * A * BX * BZ * G) + (BX * BX + BY * BY) * (G * G) - (2 * B * BY) * (A * BX + BZ * G)) X = ((B * B * BX * F) - (A * B * BY * F) + (F * G) * (-A * BZ + BX * G) + const) / denom if (B == 0 or BZ == 0) and (BY == 0 or G == 0): const1 = math.sqrt(G * G * (-A * A * X * X + (B * B + G * G) * (L - X) * (L + X))) Y = ((-A * B * X) + const1) / (B * B + G * G) Z = -(A * G * G * X + B * const1) / (G * (B * B + G * G)) else: Y = ((A * A * BY * F) * (B * BZ - BY * G) + G * (-F * math.pow(B * BZ - BY * G, 2) + BX * const) - A * (B * B * BX * BZ * F - B * BX * BY * F * G + BZ * const)) / ( (B * BZ - BY * G) * denom) Z = ((A * A * BZ * F) * (B * BZ - BY * G) + (B * F) * math.pow(B * BZ - BY * G, 2) + (A * BX * F * G) * (-B * BZ + BY * G) - B * BX * const + A * BY * const) / ( (B * BZ - BY * G) * denom) # Get the new Vector from the origin D = Vector(X, Y, Z) + CV with warnings.catch_warnings(): # ignore inconsequential warning warnings.simplefilter("ignore") temp = calc_dihedral(AV, BV, CV, D) * (180.0 / math.pi) di = di - temp rot = rotaxis(math.pi * (di / 180.0), CV - BV) D = (D - BV).left_multiply(rot) + BV return D.get_array()
def protein_synthesis(l,t,d,t5,t95,d5,d95): """ protein_synthesis takes all the lengths, angles and dihedrals and returns points in 3-D space using rotation matrices, as well as returning the points in space of the 5th and 95th percentiles of the angles and dihedrals """ V=[] VA5=[] VA95=[] VD5=[] VD95=[] #rotation matrices for the second vector, rotating about a vector perpendicular to the first vector if (t[0] >= 0): RT = rotaxis(math.pi - t[0], Vector(0, 1, 0)) elif (t[0] < 0): RT = rotaxis(-(math.pi - t[0]), Vector(0, 1, 0)) if (t5[0] >= 0): RT5 = rotaxis(math.pi - t5[0], Vector(0, 1, 0)) elif (t[0] < 0): RT5 = rotaxis(-(math.pi - t5[0]), Vector(0, 1, 0)) if (t5[0] >= 0): RT95 = rotaxis(math.pi - t95[0], Vector(0, 1, 0)) elif (t[0] < 0): RT95 = rotaxis(-(math.pi - t95[0]), Vector(0, 1, 0)) #First 3 points for the representation #point 0 V.append(Vector(0,0,0)) #point 1 V.append(Vector(l[0],0,0)) #point 2, found by rotating the original vector and changing the length V.append(V[1]+(V[1].left_multiply(RT)).normalized()**l[1]) #Points for the 5th and 95th percentiles # point 0 VA5.append(Vector(0, 0, 0)) # point 1 VA5.append(Vector(l[0], 0, 0)) # point 2 VA5.append(V[1] + (V[1].left_multiply(RT5)).normalized() ** l[1]) # point 0 VA95.append(Vector(0, 0, 0)) # point 1 VA95.append(Vector(l[0], 0, 0)) # point 2 VA95.append(V[1] + (V[1].left_multiply(RT95)).normalized() ** l[1]) # point 0 VD5.append(Vector(0, 0, 0)) # point 1 VD5.append(Vector(l[0], 0, 0)) # point 2 VD5.append(V[1] + (V[1].left_multiply(RT)).normalized() ** l[1]) # point 0 VD95.append(Vector(0, 0, 0)) # point 1 VD95.append(Vector(l[0], 0, 0)) # point 2 VD95.append(V[1] + (V[1].left_multiply(RT)).normalized() ** l[1]) #loops through all the lengths, angles and dihedrals, creating new vectors and points in 3-D space i=2 while (i<=len(l)-1): #New angle rotation matrices if (t[i-1] >= 0): RT = rotaxis(math.pi - t[i-1], (V[i] - V[i-1]) ** (V[i-1]-V[i-2])) elif (t[i-1] < 0): RT = rotaxis(-(math.pi - t[i-1]), (V[i] - V[i-1]) ** (V[i-1]-V[i-2])) if (t5[i-1] >= 0): RT5 = rotaxis(math.pi - t5[i-1], (V[i] - V[i-1]) ** (V[i-1]-V[i-2])) elif (t5[i-1] < 0): RT5 = rotaxis(-(math.pi - t5[i-1]), (V[i] - V[i-1]) ** (V[i-1]-V[i-2])) if (t95[i-1] >= 0): RT95 = rotaxis(math.pi - t95[i-1], (V[i] - V[i-1]) ** (V[i-1]-V[i-2])) elif (t95[i-1] < 0): RT95 = rotaxis(-(math.pi - t95[i-1]), (V[i] - V[i-1]) ** (V[i-1]-V[i-2])) #New dihedral rotation matrices if (d[i-2] >= 0): RD = rotaxis((math.pi - d[i-2]), V[i] - V[i-1]) elif (d[i-2] < 0): RD = rotaxis(-(math.pi - d[i-2]), V[i] - V[i-1]) if (d5[i-2] >= 0): RD5 = rotaxis((math.pi - d5[i-2]), V[i] - V[i-1]) elif (d5[i-2] < 0): RD5 = rotaxis(-(math.pi - d5[i-2]), V[i] - V[i-1]) if (d95[i-2] >= 0): RD95 = rotaxis((math.pi - d95[i-2]), V[i] - V[i-1]) elif (d95[i-2] < 0): RD95 = rotaxis(-(math.pi - d95[i-2]), V[i] - V[i-1]) #point i+1 #rotates by angles and by dihedral V.append(V[i]+(((V[i]-V[i-1]).left_multiply(RT)).left_multiply(RD)).normalized()**l[i]) VA5.append(V[i] + (((V[i] - V[i - 1]).left_multiply(RT5)).left_multiply(RD)).normalized() ** l[i]) VA95.append(V[i] + (((V[i] - V[i - 1]).left_multiply(RT95)).left_multiply(RD)).normalized() ** l[i]) VD5.append(V[i] + (((V[i] - V[i - 1]).left_multiply(RT)).left_multiply(RD5)).normalized() ** l[i]) VD95.append(V[i] + (((V[i] - V[i - 1]).left_multiply(RT)).left_multiply(RD95)).normalized() ** l[i]) i=i+1 return V,VA5,VA95,VD5,VD95