Example #1
0
def maxmins(atoms):
    xmax = -999999999
    xmin = 999999999
    ymax = -999999999
    ymin = 999999999
    zmax = -99999999
    zmin = 999999999
    xs = 0
    ys = 0
    zs = 0
    num = 0
    nx = Atributs.atomt("xcoor")
    ny = Atributs.atomt("ycoor")
    nz = Atributs.atomt("zcoor")
    for i in range(len(atoms) - 1):
        linia = atoms[i]
        x = linia[nx]
        y = linia[ny]
        z = linia[nz]
        if x > xmax: xmax = x
        if x <= xmin: xmin = x
        if y > ymax: ymax = y
        if y <= ymin: ymin = y
        if z > zmax: zmax = z
        if z <= zmin: zmin = z
        num += 1
        xs = xs + x
        ys = ys + y
        zs = zs + z
        llista = [xmin, ymin, zmin], [xmax, ymax, zmax], [(round(xs / num, 4)),
                                                          round(ys / num, 4),
                                                          round(zs / num, 4)]
    return (llista)
Example #2
0
    def __init__(self, fitxer):
        self.fitxer = fitxer
        E = Entitat(self.fitxer)
        self.linies = E.get_linies()
        dadestotals = E.crear_entitat()
        self.capcalera = dadestotals[0]
        self.molecules = dadestotals[2]
        self.residus = dadestotals[3]
        self.atoms = dadestotals[4]
        self.nom_taula = dadestotals[5]

        self.nomResidu = Atributs.residut("nomResidu")
        self.nomElement = Atributs.atomt("elemQuim")
        self.idTResidu = Atributs.residut("idTResidu")
        self.idTAtom = Atributs.atomt("idTAtom")
Example #3
0
    def plot_atoms(self):
        xs = []
        ys = []
        zs = []
        cs = []
        watoms = []
        if self.tipus == 1:
            watoms = [
                atom for atom in self.atoms
                if atom[Atributs.atomt("idTAtom")] == True
            ]
        if self.tipus == 2:
            watoms = [
                residu for residu in self.residus
                if residu[Atributs.residut("idTResidu")] == True
            ]
        self.tipus2 = 1
        for linia in watoms:
            if self.tipus == 1:
                x = linia[Atributs.atomt("xcoor")]
                y = linia[Atributs.atomt("ycoor")]
                z = linia[Atributs.atomt("zcoor")]
            if self.tipus == 2:
                x = linia[Atributs.residut("xcoor")]
                y = linia[Atributs.residut("ycoor")]
                z = linia[Atributs.residut("zcoor")]

            # Get color
            chain = linia[Atributs.atomt("idChain")]
            colors = Colors(chain, 1)
            col = colors.color_molecula()

            xs.append(x)
            ys.append(y)
            zs.append(z)
            cs.append(col)

        fig = plt.figure(figsize=(10, 5))
        ax = fig.add_subplot(111, projection='3d')
        ax.set_facecolor([0.98, 0.92, 0.84])  # blanc antic
        ax.text2D(-0.10,
                  0.95,
                  self.capcalera,
                  horizontalalignment='left',
                  verticalalignment='top',
                  family='Serif',
                  size=9,
                  transform=ax.transAxes)
        ax.scatter(xs, ys, zs, c=cs, marker='o', alpha=0.35)
        ax.set_xlabel('Eix X')
        ax.set_ylabel('Eix Y')
        ax.set_zlabel('Eix Z')
        plt.show()
Example #4
0
    def cercar_centre_proteina(self):
        sx = 0
        sy = 0
        sz = 0
        atms = 0
        for linia in self.linies:
            if linia[0:4] == "ATOM":
                atom = Entitat.flinia_atoms(linia)
                x = atom[Atributs.campsAtoms("xcoor")]
                y = atom[Atributs.campsAtoms("ycoor")]
                z = atom[Atributs.campsAtoms("zcoor")]
                sx += x
                sy += y
                sz += z
                atms += 1
        dx = 0 - round(sx / atms, 4)
        dy = 0 - round(sy / atms, 4)
        dz = 0 - round(sz / atms, 4)

        return (dx, dy, dz)
Example #5
0
    def get_residus(self):
        a = Atributs(self, )
        self.lresidus = []
        self.lresidusn = []
        self.lresiduts = []
        self.lresidutsn = []
        self.lreshets = []
        self.lreshetsn = []
        self.sig = []
        self.nom_amino = []
        #       self.nom, self.lletra, self.sig, self.tipologia = a.llista_aminoacids()
        self.mestre_aminoacids = a.mestre_aminoacids
        n = len(self.mestre_aminoacids)
        for i in range(len(self.mestre_aminoacids)):
            self.sig.append(self.mestre_aminoacids[i][0])
            self.nom_amino.append(self.mestre_aminoacids[i][2])
        for residu in self.residus:
            res = residu[self.nomResidu]
            prot = residu[self.idTResidu]
            if prot:
                if res in self.sig:
                    if res in self.lresidus:
                        idx = self.lresidus.index(res)
                        self.lresidusn[idx] = int(self.lresidusn[idx]) + 1
                    else:
                        self.lresidus.append(res)
                        self.lresidusn.append(1)
                else:
                    if res in self.lresiduts:
                        idx = self.lresiduts.index(res)
                        self.lresidutsn[idx] = int(self.lresidutsn[idx]) + 1
                    else:
                        self.lresiduts.append(res)
                        self.lresidutsn.append(1)
            else:
                if res in self.lreshets:
                    idx = self.lreshets.index(res)
                    self.lreshetsn[idx] = int(self.lreshetsn[idx]) + 1
                else:
                    self.lreshets.append(res)
                    self.lreshetsn.append(1)

        return self.lresidus, self.lresidusn, self.lresiduts, self.lresidutsn, self.lreshets, self.lreshetsn
Example #6
0
    def crear_entitat(self):

        self.models.append(1)
        widModel = 1
        idModel = 1
        wnmodels = 1
        widChain = ""
        wwidChain = ""
        widnumSeqres = 0
        idTAtom = True
        widTResidu = True
        idCA = False
        wnAtoms = 0
        primer = True
        xCA = 0.0
        yCA = 0.0
        zCA = 0.0
        totalAtoms = 0
        wclau = ""

        # posicions dels camps necessaris en el registre d'atoms del pdb

        ntipus = Atributs.campsAtoms("tipus")
        nnumser = Atributs.campsAtoms("numser")
        nsigatom = Atributs.campsAtoms("sigatom")
        nnomResidu = Atributs.campsAtoms("nomResidu")
        nidChain = Atributs.campsAtoms("idChain")
        nidnumSeqres = Atributs.campsAtoms("numSeqres")
        nxcoor = Atributs.campsAtoms("xcoor")
        nycoor = Atributs.campsAtoms("ycoor")
        nzcoor = Atributs.campsAtoms("zcoor")
        nelemQuim = Atributs.campsAtoms("elemQuim")

        # Càlcul del centre de la proteian i diferencia respecte a les coordenades (0,0.0)

        self.dx, self.dy, self.dz = Entitat.cercar_centre_proteina(self)
        primer = True
        '''  Models '''
        sx = 0
        sy = 0
        sz = 0
        num = 0
        idCA = False
        for lin in self.linies:
            tipus = lin[0:6]
            if tipus == "MODEL ":
                idModel = Atributs.get_models(lin)
                if idModel > 1:
                    self.models.append(idModel)
                    nmodels += 1
            ''' Ordre dels camps en el registre de atom'''
            if tipus == "ATOM  " or tipus == "HETATM":
                linia = Entitat.flinia_atoms(lin)
                nomResidu = linia[nnomResidu]
                if nomResidu != "HOH":
                    clau = ""
                    tipus = linia[ntipus]
                    sigatom = linia[nsigatom]
                    idChain = linia[nidChain]
                    idAtom = linia[nnumser]
                    idnumSeqres = linia[nidnumSeqres]
                    xcoor = round(linia[nxcoor] + self.dx,
                                  4)  # Coordenada transformada,
                    ycoor = round(linia[nycoor] + self.dy,
                                  4)  # Coordenada transformada
                    zcoor = round(linia[nzcoor] + self.dz,
                                  4)  # Coordenada transformada
                    sx = sx + xcoor
                    sy = sy + ycoor
                    sz = sz + zcoor
                    num += 1
                    elemQuim = linia[nelemQuim]
                    ''' Clau de comparacio'''
                    clau = str(idModel) + idChain + str(idnumSeqres).rjust(
                        4, "0")
                    '''  Proteina o Estranys '''
                    if tipus == "ATOM":
                        idTAtom = True
                    else:
                        idTAtom = False
                    idTResidu = idTAtom
                    ''' Molecules '''
                    if idChain != wwidChain:
                        wwidChain = idChain
                        if idChain in self.molecules:
                            pass
                        else:
                            self.molecules.append(idChain)
                    ''' carbono alfa'''
                    if sigatom == "CA":
                        idCA = True
                        xCA = xcoor
                        yCA = ycoor
                        zCA = zcoor

                    if primer:

                        widModel = idModel
                        widChain = idChain
                        widAtom = idAtom
                        widnumSeqres = idnumSeqres
                        wnomResidu = nomResidu
                        widTResidu = idTResidu
                        wclau = clau
                        primer = False
                        self.atoms.append([
                            idModel, idChain, idnumSeqres, idAtom, sigatom,
                            nomResidu, xcoor, ycoor, zcoor, elemQuim, idCA,
                            idTAtom
                        ])
                        wnAtoms = 1
                        totalAtoms = 1

                    elif clau != wclau:
                        self.atoms.append([
                            idModel, idChain, idnumSeqres, idAtom, sigatom,
                            nomResidu, xcoor, ycoor, zcoor, elemQuim, idCA,
                            idTAtom
                        ])
                        if idCA == False:
                            xCA = round(sx / num, 4)
                            yCA = round(sy / num, 4)
                            zCA = round(sz / num, 4)
                        self.residus.append([
                            widModel, widChain, widnumSeqres, wnomResidu, xCA,
                            yCA, zCA, wnAtoms, widTResidu
                        ])
                        sx = 0
                        sy = 0
                        sz = 0
                        num = 0
                        xCA = 0.0
                        yCA = 0.0
                        zCA = 0.0
                        idCA = False
                        wnAtoms = 1
                        totalAtoms += 1
                        widModel = idModel
                        widChain = idChain
                        widnumSeqres = idnumSeqres
                        wnomResidu = nomResidu
                        widTResidu = idTResidu
                        wclau = clau
                    elif clau == wclau:
                        self.atoms.append([
                            idModel, idChain, idnumSeqres, idAtom, sigatom,
                            nomResidu, xcoor, ycoor, zcoor, elemQuim, idCA,
                            idTAtom
                        ])
                        wnAtoms += 1
                        totalAtoms += 1
                else:
                    continue
            # ultim registre
            if idCA == False:
                if num > 0:
                    xCA = round(sx / num, 4)
                    yCA = round(sy / num, 4)
                    zCA = round(sz / num, 4)
                    xCA = sx + self.dx
                    yCA = sy + self.dy
                    zCA = sz + self.dz
        self.residus.append([
            widModel, widChain, widnumSeqres, wnomResidu, xCA, yCA, zCA,
            wnAtoms, widTResidu
        ])
        caps = [linia for linia in self.linies if linia[0:6] == "TITLE "]
        text = ""
        for cap in caps:
            nom = str(cap[10:80].strip(' \t\n\r'))
            text = text + nom
            self.capcalera = text
        return self.capcalera, self.models, self.molecules, self.residus, self.atoms, self.nomtaula
Example #7
0
    def plot_linies(self):
        # Coordenades
        tx = 0.0
        ty = 0.0
        tz = 0.0
        txp = 0.0
        typ = 0.0
        tzp = 0.0
        self.tipus2 = 2
        fig = plt.figure(figsize=(11, 5))
        ax = fig.add_subplot(111, projection='3d')
        ax.set_facecolor([0.98, 0.92, 0.84])  # blanc antic

        ax.text2D(-0.10,
                  0.95,
                  self.capcalera,
                  horizontalalignment='left',
                  verticalalignment='top',
                  family='Serif',
                  size=9,
                  transform=ax.transAxes)

        # ax.text2D(0.05, 0.95, self.capcalera, transform=ax.transAxes)

        # Posicions en el refistre de residus
        chain = Atributs.residut("idChain")
        s = Atributs.residut("idResidu")
        amin = Atributs.residut("nomResidu")
        x = Atributs.residut("xcoor")
        y = Atributs.residut("ycoor")
        z = Atributs.residut("zcoor")
        prot = Atributs.residut("idTResidu")

        # Vectors plot
        punt_inici_x = []
        punt_inici_y = []
        punt_inici_z = []
        punt_final_x = []
        punt_final_y = []
        punt_final_z = []

        colamin = []

        # Nomes aminoacids de la proteina residu[prot] == True

        cadena = [residu for residu in self.residus if residu[prot] == True]

        residus_net = cadena
        n = len(residus_net) - 1
        for i in range(n):
            linia = residus_net[i]
            chain1 = linia[chain]
            amino = linia[amin]
            tx = linia[x]
            ty = linia[y]
            tz = linia[z]
            res1 = [chain1 + str(linia[s])]
            if i < n:
                liniapost = residus_net[i + 1]
                chain2 = liniapost[chain]
                txp = liniapost[x]
                typ = liniapost[y]
                tzp = liniapost[z]
                res2 = [chain2 + str(liniapost[s])]
            else:
                pass

            # Get color
            if self.tipus == 1:
                colors = Colors(chain1, 1)
                cl = colors.color_molecula()
            elif self.tipus == 2:
                aminos = ('ALA', 'ARG', 'ASN', 'ASP', 'CYS', 'PHE', 'GLN',
                          'GLU', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'PRO',
                          'MET', 'SER', 'THR', 'TYR', 'TRP', 'VAL')
                if amino in aminos:
                    ccolors = Colors(amino, 2)
                    cl = ccolors.color_tipus()
                else:
                    cl = ('k')
            else:
                cl = ('c')

            punt_inici_x.append(tx)
            punt_inici_y.append(ty)
            punt_inici_z.append(tz)
            colamin.append(cl)

            if i < n and chain1 == chain2:
                punt_final_x.append(txp)
                punt_final_y.append(typ)
                punt_final_z.append(tzp)
            else:
                punt_final_x.append(tx)
                punt_final_y.append(ty)
                punt_final_z.append(tz)

        for i in range(n):
            xs = [punt_inici_x[i], punt_final_x[i]]
            ys = [punt_inici_y[i], punt_final_y[i]]
            zs = [punt_inici_z[i], punt_final_z[i]]
            col = colamin[i]
            ax.plot(xs, ys, zs, linewidth=2, color=col)
            # linea = []
            # linea = [x for x in punt_inici_x if x == 0]

        # ax.set_xlabel('Eix X')
        # ax.set_ylabel('Eix Y')
        # ax.set_zlabel('Eix Z')
        plt.show()
Example #8
0
    def plot2d_3d(self):
        fig = plt.figure(figsize=(11, 5))
        ax = fig.add_subplot(111, projection='3d')
        ax.text2D(-0.10,
                  -0.10,
                  self.capcalera,
                  horizontalalignment='left',
                  verticalalignment='top',
                  family='Serif',
                  size=8,
                  transform=ax.transAxes)
        self.tipus2 = 1
        ax_xy = fig.add_subplot(331)
        ax_xy.set_title('X/Y')
        ax_xz = fig.add_subplot(333)
        ax_xz.set_title('X/Z')
        ax_zy = fig.add_subplot(334)
        ax_zy.set_title('Z/Y')
        ax.set_facecolor([0.98, 0.92, 0.84])  # blanc antic
        zx, zy, zz = [], [], []

        idchains = Atributs.residut("idChain")
        idresidus = Atributs.residut("idResidu")
        idresatom = Atributs.atomt("idResidu")
        aprot = Atributs.atomt("idTAtom")

        idx = Atributs.atomt("xcoor")
        idy = Atributs.atomt("ycoor")
        idz = Atributs.atomt("zcoor")

        vella_mol = ""
        for chain_id in self.molecules:
            if chain_id != vella_mol:
                atr = Colors(chain_id)
                nom = atr.color_molecula()
                vella_mol = chain_id
            xs = []
            ys = []
            zs = []
            wresidus = [
                res for res in self.residus if res[idchains] == chain_id
            ]
            for residu in wresidus:
                watoms = []
                watoms = [
                    atom for atom in self.atoms
                    if atom[idresatom] == residu[idresidus]
                    and atom[idchains] == chain_id and atom[aprot] == True
                ]
                for atom in watoms:
                    x = atom[idx]
                    y = atom[idy]
                    z = atom[idz]
                    xs.append(x)
                    ys.append(y)
                    zs.append(z)
                    atr = Colors(chain_id, 1)
                    nom = atr.color_molecula()
            ax.scatter(xs, ys, zs, marker='*', color=nom, alpha=0.35)
            ax_xy.scatter(xs, ys, marker='.', color=nom, alpha=0.15)
            ax_xz.scatter(xs, zs, marker='.', color=nom, alpha=0.15)
            ax_zy.scatter(zs, ys, marker='.', color=nom, alpha=0.15)
            # ax.text2D(0.05, 0.95, self.capcalera, transform=ax.transAxes)
            # ax.text(9, 0, 0,self.capcalera , color='red')
        plt.show()
Example #9
0
##!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from codi.atributs.atributs import Atributs

so =sys.platform
if so == 'win32' or  so=="win64":
    os.system('cls')
else:
    os.system('clear')


a = Atributs()
nom, lletra,  sig, volum, tipus1, tipus2, escala = a.llista_aminoacids()
frase = "Aminoàcid".ljust(15, " ") + " SIG "+"Lletra  " + "Tipologia" +"  " +"Masa relativa(*) "
print(frase)
print "--------------- ----- ---- ---------  ------------"
for i in range(len(sig)):
    frase= nom[i].ljust(15, " ") +" "+ sig[i].ljust(3, " ")+"    "+lletra[i] +"       " + str(tipus2[i])+ "     "+ str(escala[i])
    print(frase)
print(" ")
print (" * massa relativa a la massa de la Glicina = 1 ")
print(" ")
tipologia = ( 'Tipologia   Descripció',
'----------------------',
'      1	Hidrofòbics',
'      2	Hidrofílics',
'      3	Àcids',
'      4	Bàsics' )