Beispiel #1
0
    def load_CPK(self, structure, node):
        for atom in structure.get_atoms():
            x, y, z = atom.coord
            id = atom.get_id()
            a = loader.loadModel("data/atom_sphere")
            a.setPos(x, y, z)
            a.setColor(colorrgba(id))
            a.setScale(vrad(id))
            a.reparentTo(node)

        node.flattenStrong()
Beispiel #2
0
    def aa2d(self):
        """Draws atoms using a colour palette depending on the type of residue"""
        
        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        
        #Select residues only if they're aminoacids
        for resname, residuetype in resdict.iteritems():
            residues = [residue for residue in self.structure.get_residues() if residue.get_resname() == resname]
            rescoord = []
            color = colorrgba(residuetype)
            
            for residue in residues:
                atoms = [atom for atom in residue.get_atoms()]
                coordinates = [atom.coord for atom in atoms]
                rescoord.append(np.array(coordinates))
                
            if len(rescoord)>1:
                rescoord = np.concatenate(rescoord)
                
            if not len(residues)==0:
                x, y, z =zip(*rescoord)
                ax.scatter(x, y, z, c=color, marker='o')

        #Select residues that are not aminoacids, skipping water
        residues_1 = [residue for residue in self.structure.get_residues() if residue.get_resname() != 'HOH']
        residues_2 = [residue for residue in self.structure.get_residues() if residue.get_resname() in resdict.keys()]
        
        residues_pink = list(set(residues_1)-set(residues_2))
        rescoordpink = []
        
        for residue in residues_pink:
            atomspink = [atom for atom in residue.get_atoms()]
            coordinatespink = [atom.coord for atom in atomspink]
            rescoordpink.append(np.array(coordinatespink))
        
        if len(rescoordpink)>1:
            rescoordpink = np.concatenate(rescoordpink)
        
        xp, yp, zp = zip(*rescoordpink)
        ax.scatter(xp, yp, zp, c='pink', marker='o')
        
        ax.axis("off")
        plt.show()
Beispiel #3
0
def aa2d():
    #Seleccionamos los residuos, solo contando los aminoacidos
    for resname, residuetype in resdict.iteritems():
        residues = [residue for residue in structure.get_residues() if residue.get_resname() == resname]
        rescoord = []
        color = colorrgba(residuetype)

        for residue in residues:
            atoms = [atom for atom in residue.get_atoms()]
            coordinates = [atom.coord for atom in atoms]
            rescoord.append(np.array(coordinates))

        if len(rescoord)>1:
            rescoord = np.concatenate(rescoord)

        if not len(residues)==0:
            x, y, z =zip(*rescoord)
            ax.scatter(x, y, z, c=color, marker='o')

    #Seleccionamos el resto de 'residuos' que ha determinado el parser, sin incluir aguas
    residues_1 = [residue for residue in structure.get_residues() if residue.get_resname() != 'HOH']
    residues_2 = [residue for residue in structure.get_residues() if residue.get_resname() in resdict.keys()]

    residues_pink = list(set(residues_1)-set(residues_2))
    rescoordpink = []

    for residue in residues_pink:
        atomspink = [atom for atom in residue.get_atoms()]
        coordinatespink = [atom.coord for atom in atomspink]
        rescoordpink.append(np.array(coordinatespink))

    if len(rescoordpink)>1:
        rescoordpink = np.concatenate(rescoordpink)

    xp, yp, zp = zip(*rescoordpink)
    ax.scatter(xp, yp, zp, c='pink', marker='o')
    
    ax.axis("off")
    plt.show()
def atom_information(pdbdata, mode):

    #analyze pdb file
    parser = PDBParser(QUIET=True, PERMISSIVE=True)
    structure = parser.get_structure('model', pdbdata)

    #DSSP prediction
    pmodel = structure[0]
    dssp = DSSP(pmodel, pdbdata)

    #Set variables
    global coordinates
    global color
    global radius
    global chains
    global chain_coords
    global chain_colors

    if mode == 'cpk':
        #list of atoms
        atoms = [atom for atom in structure.get_atoms()]
        natoms = len(atoms)
        #atom coordinates
        coordinates = np.array([atom.coord for atom in atoms])
        center = centroid(coordinates)
        coordinates -= center

        #atom color
        color = [colorrgba(atom.get_id()) for atom in atoms]
        #atom radius
        radius = np.array([vrad(atom.get_id()) for atom in atoms])

    elif mode == 'aminoacid':
        #list of atoms
        atoms = [
            atom for atom in structure.get_atoms()
            if atom.get_parent().resname != 'HOH'
        ]
        natoms = len(atoms)
        #atom coordinates
        coordinates = np.array([atom.coord for atom in atoms])
        center = centroid(coordinates)
        coordinates -= center
        #atom color
        color = [
            colorrgba(restype(atom.get_parent().resname)) for atom in atoms
        ]
        #atom radius
        radius = np.array([vrad(atom.get_id()) for atom in atoms])

    elif mode == 'backbone':
        #list of atoms
        atoms = [
            atom for atom in structure.get_atoms()
            if atom.get_name() == 'CA' or atom.get_name() == 'N'
        ]
        natoms = len(atoms)
        #atom coordinates
        coordinates = np.array([atom.coord for atom in atoms])
        center = centroid(coordinates)
        coordinates -= center
        #atom color
        color = []
        #list of arrays of coordinates and colors for each chain
        chains = []
        chain_colors = []
        chain_coords = []
        for chain in structure.get_chains():
            chains.append(chain)
            can_coord = np.array([
                atom.coord for atom in chain.get_atoms()
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ])
            can_coord -= center
            chain_coords.append(can_coord)
            chain_length = len(can_coord)
            chain_color = np.append(np.random.rand(1, 3), [1.0])
            chain_colors.append(chain_color)
            color.append(np.tile(chain_color, (chain_length, 1)))
        if len(chains) > 1:
            color = np.concatenate(color)
        #atom radius
        radius = np.array([vrad(atom.get_id()) for atom in atoms])

    elif mode == 'dssp':
        #list of atoms
        atoms = [
            atom for atom in structure.get_atoms()
            if atom.get_name() == 'CA' or atom.get_name() == 'N'
        ]
        natoms = len(atoms)
        #atom coordinates
        coordinates = np.array([atom.coord for atom in atoms])
        center = centroid(coordinates)
        coordinates -= center
        #atom color
        struct3 = [dssp[key][2] for key in list(dssp.keys())]
        residues = [
            residue for residue in structure.get_residues()
            if residue.get_resname() in resdict.keys()
        ]
        color = []
        for i in range(len(struct3)):
            dsspcolor = crgbaDSSP(struct3[i])
            n_atoms = len([
                atom for atom in residues[i]
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ])
            color.append(np.tile(dsspcolor, (n_atoms, 1)))
        if len(struct3) > 1:
            color = np.concatenate(color)
        #list of arrays of coordinates and colors for each chain
        chains = []
        chain_colors = []
        chain_coords = []
        for chain in structure.get_chains():
            chains.append(chain)
            chain_color = np.append(np.random.rand(1, 3), [1.0])
            chain_colors.append(chain_color)
            can_coord = np.array([
                atom.coord for atom in chain.get_atoms()
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ])
            can_coord -= center
            chain_coords.append(can_coord)
        #atom radius
        radius = np.array([vrad(atom.get_id()) for atom in atoms])
def centroid(arr):
    length = arr.shape[0]
    sum_x = np.sum(arr[:, 0])
    sum_y = np.sum(arr[:, 1])
    sum_z = np.sum(arr[:, 2])
    return sum_x / length, sum_y / length, sum_z / length


atoms = [atom for atom in structure.get_atoms()]
natoms = len(atoms)
#atom coordinates
coordinates = np.array([atom.coord for atom in atoms])
center = centroid(coordinates)
coordinates -= center
#atom color
color = [colorrgba(atom.get_id()) for atom in atoms]
#atom radius
radius = [vrad(atom.get_id()) for atom in atoms]

W, H = 1200, 800

MySpheres = scene.visuals.create_visual_node(MySpheresVisual)

canvas = scene.SceneCanvas(keys='interactive',
                           app='pyqt4',
                           bgcolor='black',
                           size=(W, H),
                           show=True)

view = canvas.central_widget.add_view()
view.camera = 'arcball'
Beispiel #6
0
    def __init__(self):
        ShowBase.__init__(self)
        self.cloud = False
        self.help = False
        self.screen_text = []

        #Desglosamos archivo PDB
        pdbdata = sys.argv[1]
        parser = PDBParser(QUIET=True, PERMISSIVE=True)
        structure = parser.get_structure('model', pdbdata)

        #Hacemos la prediccion DSSP
        model = structure[0]
        dssp = DSSP(model, pdbdata)

        #Creamos los modelos
        self.cpknode = render.attachNewNode("CPK")
        self.aanode = render.attachNewNode("Aminoacids")
        self.bbnode = render.attachNewNode("BackBone")
        self.dsspnode = render.attachNewNode("DSSP")
        self.nnode = render.attachNewNode("Cloud")

        #CPK
        for atom in structure.get_atoms():
            x, y, z = atom.coord
            atomid = atom.get_id()
            a = loader.loadModel("data/atom_sphere")
            a.setPos(x, y, z)
            a.reparentTo(self.cpknode)
            a.setColor(colorrgba(atomid))
            a.setScale(vrad(atomid))

        self.cpknode.flattenStrong()

        #Aminoacids
        self.residues = [
            residue for residue in structure.get_residues()
            if residue.get_resname() in resdict.keys()
        ]
        for residue in self.residues:
            resid = residue.get_resname()
            color = colorrgba(restype(resid))
            atoms = [atom for atom in residue.get_atoms()]
            for atom in atoms:
                x, y, z = atom.coord
                atomid = atom.get_id()
                a = loader.loadModel("data/atom_sphere")
                a.setPos(x, y, z)
                a.setColor(color)
                a.setScale(vrad(atomid))
                a.reparentTo(self.aanode)

        self.residues2 = [
            residue for residue in structure.get_residues()
            if not residue in self.residues and residue.get_resname() != 'HOH'
        ]
        for residue in self.residues2:
            atoms = [atom for atom in residue.get_atoms()]
            for atom in atoms:
                x, y, z = atom.coord
                atomid = atom.get_id()
                a = loader.loadModel("data/atom_sphere")
                a.setPos(x, y, z)
                a.setColor(colorrgba(atomid))
                a.setScale(vrad(atomid))
                a.reparentTo(self.aanode)
        self.aanode.flattenStrong()
        self.aanode.hide()

        #Backbone
        for chain in structure.get_chains():
            carr = np.random.rand(3, 1)
            ccolor = float(carr[0]), float(carr[1]), float(carr[2]), 1.0
            can_atoms = [
                atom for atom in chain.get_atoms()
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ]
            can_coordinates = [atom.coord for atom in can_atoms]
            for atom in can_atoms:
                x, y, z = atom.coord
                atomid = atom.get_id()
                a = loader.loadModel("data/atom_sphere")
                a.setPos(x, y, z)
                a.reparentTo(self.bbnode)
                a.setColor(ccolor)
                a.setScale(vrad(atomid) / 2.5)

            lines = LineSegs()
            lines.setColor(ccolor)
            lines.moveTo(can_coordinates[0][0], can_coordinates[0][1],
                         can_coordinates[0][2])
            for i in range(len(can_atoms))[1:]:
                lines.drawTo(can_coordinates[i][0], can_coordinates[i][1],
                             can_coordinates[i][2])
            lines.setThickness(6)
            lnode = lines.create()
            self.linenp = NodePath(lnode)
            self.linenp.instanceTo(self.bbnode)

            #Cloud
            catoms = [atom for atom in chain.get_atoms()]
            for atom in catoms:
                x, y, z = atom.coord
                atomid = atom.get_id()
                a = loader.loadModel("data/atom_sphere")
                a.setPos(x, y, z)
                a.reparentTo(self.nnode)
                a.setColor(ccolor)
                a.setScale(vrad(atomid) * 1.1)

        self.bbnode.flattenStrong()
        self.bbnode.hide()
        self.nnode.setTransparency(TransparencyAttrib.MAlpha)
        self.nnode.setAlphaScale(0.3)
        self.nnode.hide()

        #DSSP
        self.linenp.instanceTo(self.dsspnode)
        self.struct3 = [dssp[key][2] for key in list(dssp.keys())]

        for i in range(len(self.struct3)):
            dsspcolor = crgbaDSSP(self.struct3[i])
            can_atoms = [
                atom for atom in self.residues[i]
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ]
            for atom in can_atoms:
                x, y, z = atom.coord
                atomid = atom.get_id()
                a = loader.loadModel("data/atom_sphere")
                a.setPos(x, y, z)
                a.reparentTo(self.dsspnode)
                a.setColor(dsspcolor)
                a.setScale(vrad(atomid) / 2.5)
            self.dsspnode.flattenStrong()
            self.dsspnode.hide()

        #Colocamos la proteina en el centro
        self.cpknode.setPos(0, 0, 0)
        self.bbnode.setPos(0, 0, 0)
        self.aanode.setPos(0, 0, 0)
        self.nnode.setPos(0, 0, 0)

        #Colocamos la camara en el centro
        xc, yc, zc = self.cpknode.getBounds().getCenter()
        self.center = xc, yc, zc
        self.pradius = self.cpknode.getBounds().getRadius()
        self.center_camera()

        #Creamos la iluminacion de ambiente
        self.ambient = AmbientLight('alight')
        self.ambient.setColor(LVecBase4f(0.16, 0.16, 0.17, 1.0))
        self.alight = render.attachNewNode(self.ambient)
        render.setLight(self.alight)

        #Creamos la iluminacion direccional
        self.directional = DirectionalLight('dlight')
        self.directional.setColor(LVecBase4f(0.8, 0.7, 0.75, 1.0))
        self.directional.setShadowCaster(True, 512, 512)
        render.setShaderAuto()
        self.dlight = render.attachNewNode(self.directional)
        self.dlight.setPos(0, -50, 0)
        render.setLight(self.dlight)
        self.dlight.lookAt(self.cpknode.getBounds().getCenter())

        # Post procesado
        render.setAntialias(AntialiasAttrib.MAuto)

        #Teclado
        self.accept('c', self.toggle_cloud)
        self.accept('1', self.showmodel, [self.cpknode])
        self.accept('2', self.showmodel, [self.aanode])
        self.accept('3', self.showmodel, [self.bbnode])
        self.accept('4', self.showmodel, [self.dsspnode])
        self.accept('x', self.center_camera)
        self.accept('arrow_left', self.taskMgr.add,
                    [self.spinCameraTaskX, "SpinCameraTaskX"])
        self.accept('arrow_up', self.taskMgr.add,
                    [self.spinCameraTaskY, "SpinCameraTaskY"])
        self.accept('arrow_down', self.stop_camera)
        self.accept('escape', sys.exit)
Beispiel #7
0
#Desglosamos archivo PDB
parser = PDBParser(QUIET=True,PERMISSIVE=True)
structure = parser.get_structure('MACROH2A', 'data/1yd9.pdb')

#Creamos el modelo

pnode = render.attachNewNode("Model")

for atom in structure.get_atoms():
	x, y, z = atom.coord
	id = atom.get_id()
	a = loader.loadModel("data/atom_sphere")
	a.setPos(x, y, z)
	a.reparentTo(pnode)
	a.setColor(colorrgba(id))
	a.setScale(vrad(id))

pnode.flattenStrong()

#Colocamos la proteina en el centro

pnode.setPos(0,0,0)

#Colocamos la camara en el centro
p_radius= pnode.getBounds().getRadius()
p_center= pnode.getBounds().getCenter()
xc, yc, zc = p_center

base.cam.setPos(xc, -150-yc-2*p_radius, zc)
base.cam.lookAt(xc, yc, zc)
Beispiel #8
0
    def atom_information(self):
        """Determines the coordinates, colors and sizes of the atoms depending on the mode"""

        if self.mode == 'cpk':
            #list of atoms
            self.atoms = [atom for atom in self.structure.get_atoms()]
            self.natoms = len(self.atoms)
            #atom coordinates
            self.coordinates = np.array([atom.coord for atom in self.atoms])
            self.center = centroid(self.coordinates)
            self.coordinates -= self.center
            #atom color
            self.color = [
                np.array(colorrgba(atom.get_id())[0:3]) for atom in self.atoms
            ]
            #atom radius
            self.radius = [vrad(atom.get_id()) for atom in self.atoms]

        elif self.mode == 'aminoacid':
            #list of atoms
            self.atoms = [
                atom for atom in self.structure.get_atoms()
                if atom.get_parent().resname != 'HOH'
            ]
            self.natoms = len(self.atoms)
            #atom coordinates
            self.coordinates = np.array([atom.coord for atom in self.atoms])
            self.center = centroid(self.coordinates)
            self.coordinates -= self.center
            #atom color
            self.color = [
                colorrgba(restype(atom.get_parent().resname))[0:3]
                for atom in self.atoms
            ]
            #atom radius
            self.radius = [vrad(atom.get_id()) for atom in self.atoms]

        elif self.mode == 'backbone':
            #list of atoms
            self.atoms = [
                atom for atom in self.structure.get_atoms()
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ]
            self.natoms = len(self.atoms)
            #atom coordinates
            self.coordinates = np.array([atom.coord for atom in self.atoms])
            self.center = centroid(self.coordinates)
            self.coordinates -= self.center
            #atom color
            self.color = []
            self.chains = []
            self.chain_coords = []
            self.chain_colors = []
            for chain in self.structure.get_chains():
                self.chains.append(chain)
                self.can_coord = np.array([
                    atom.coord for atom in chain.get_atoms()
                    if atom.get_name() == 'CA' or atom.get_name() == 'N'
                ])
                self.can_coord -= self.center
                self.chain_coords.append(self.can_coord)
                self.chain_length = len(self.can_coord)
                self.chain_color = np.random.rand(1, 3)
                self.chain_colors.append(self.chain_color)
                self.color.append(
                    np.tile(self.chain_color, (self.chain_length, 1)))
            if len(self.chains) > 1:
                self.color = np.concatenate(self.color)
            #atom radius
            self.radius = [vrad(atom.get_id()) for atom in self.atoms]
Beispiel #9
0
    def atom_information(self):
        """Determines the coordinates, colors and sizes of the atoms depending on the mode"""

        if self.mode == 'cpk':
            #list of atoms
            self.atoms = [atom for atom in self.structure.get_atoms()]
            self.natoms = len(self.atoms)
            #atom coordinates
            self.coordinates = np.array([atom.coord for atom in self.atoms])
            self.center = centroid(self.coordinates)
            self.coordinates -= self.center
            #atom color
            self.color = [
                np.array(colorrgba(atom.get_id())[0:3]) for atom in self.atoms
            ]
            #atom radius
            self.radius = [vrad(atom.get_id()) for atom in self.atoms]

        elif self.mode == 'aminoacid':
            #list of atoms
            self.atoms = [
                atom for atom in self.structure.get_atoms()
                if atom.get_parent().resname != 'HOH'
            ]
            self.natoms = len(self.atoms)
            #atom coordinates
            self.coordinates = np.array([atom.coord for atom in self.atoms])
            self.center = centroid(self.coordinates)
            self.coordinates -= self.center
            #atom color
            self.color = [
                colorrgba(restype(atom.get_parent().resname))[0:3]
                for atom in self.atoms
            ]
            #atom radius
            self.radius = [vrad(atom.get_id()) for atom in self.atoms]

        elif self.mode == 'backbone':
            #list of atoms
            self.atoms = [
                atom for atom in self.structure.get_atoms()
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ]
            self.natoms = len(self.atoms)
            #atom coordinates
            self.coordinates = np.array([atom.coord for atom in self.atoms])
            self.center = centroid(self.coordinates)
            self.coordinates -= self.center
            #atom color
            self.color = []
            self.chains = []
            for chain in self.structure.get_chains():
                self.chains.append(chain)
                self.chain_length = len([
                    atom for atom in chain.get_atoms()
                    if atom.get_name() == 'CA' or atom.get_name() == 'N'
                ])
                self.chain_color = np.random.rand(1, 3)
                self.color.append(
                    np.tile(self.chain_color, (self.chain_length, 1)))
            if len(self.chains) > 1:
                self.color = np.concatenate(self.color)
            #atom radius
            self.radius = [vrad(atom.get_id()) for atom in self.atoms]

        elif self.mode == 'dssp':
            #list of atoms
            self.atoms = [
                atom for atom in self.structure.get_atoms()
                if atom.get_name() == 'CA' or atom.get_name() == 'N'
            ]
            self.natoms = len(self.atoms)
            #atom coordinates
            self.coordinates = np.array([atom.coord for atom in self.atoms])
            self.center = centroid(self.coordinates)
            self.coordinates -= self.center
            #atom color
            self.struct3 = [
                self.dssp[key][2] for key in list(self.dssp.keys())
            ]
            self.residues = [
                residue for residue in self.structure.get_residues()
                if residue.get_resname() in resdict.keys()
            ]
            self.color = []
            for i in range(len(self.struct3)):
                self.dsspcolor = crgbaDSSP(self.struct3[i])[0:3]
                self.n_atoms = len([
                    atom for atom in self.residues[i]
                    if atom.get_name() == 'CA' or atom.get_name() == 'N'
                ])
                self.color.append(np.tile(self.dsspcolor, (self.n_atoms, 1)))
            if len(self.struct3) > 1:
                self.color = np.concatenate(self.color)
            #atom radius
            self.radius = [vrad(atom.get_id()) for atom in self.atoms]
Beispiel #10
0
#Desglosamos archivo PDB
parser = PDBParser(QUIET=True, PERMISSIVE=True)
structure = parser.get_structure('MACROH2A', 'data/1yd9.pdb')

#Creamos el modelo

pnode = render.attachNewNode("Model")

#Listado de residuos, solo contando los aminoacidos
residues = [
    residue for residue in structure.get_residues()
    if residue.get_resname() in resdict.keys()
]
for residue in residues:
    resid = residue.get_resname()
    color = colorrgba(restype(resid))
    atoms = [atom for atom in residue.get_atoms()]
    for atom in atoms:
        x, y, z = atom.coord
        id = atom.get_id()
        a = loader.loadModel("data/atom_sphere")
        a.setPos(x, y, z)
        a.setColor(color)
        a.setScale(vrad(id))
        a.reparentTo(pnode)

pnode.flattenStrong

#Seleccionamos el resto de 'residuos' que ha determinado el parser, sin incluir aguas
residues2 = [
    residue for residue in structure.get_residues()