4.3.1. PYMOL
This example below uses the external software called PyMOL. It can be installed via conda:
conda install -c schrodinger pymol-bundle
The following code uses BioServices to get the PDB Identifier of a protein
called ZAP70. To do so, we use bioservices.uniprot.UniProt to get its accession number (P43403) and its
PDB identifer. Then, we use bioservices.pdb.PDB to get the 3D structure in PDB
format.
1import __main__
2
3__main__.pymol_argv = ["pymol", "-qc"] # Quiet and no GUI
4
5import os
6
7if os.path.isfile("bioservices_pdb.png"):
8 os.remove("bioservices_pdb.png")
9
10# BioServices 1: obtain the PDB ID from a given uniprot ID (P43403 i.e. ZAP70)
11from bioservices import PDBe, UniProt
12
13print("Retrieving PDB ID")
14u = UniProt(verbose=False)
15res = u.mapping(fr="UniProtKB_AC-ID", to="PDB", query="P43403")
16pdb_id = res["results"][0]["to"] # e.g, "1FBV"
17
18# BioServices 2: Download the PDB file from the PDB Web Service
19print("Fetching PDB file")
20p = PDBe()
21res = p.get_files(pdb_id)
22
23# General: save the fetched file in a temporary file
24import tempfile
25
26fh = tempfile.NamedTemporaryFile()
27fh.write(res)
28sname = fh.name
29
30# THIS IS NOT BIOSERVICES ANYMORE but PYMOL
31import pymol
32
33pymol.finish_launching()
34pymol.cmd.load(sname)
35pymol.cmd.png("bioservices_pdb.png", width="15cm", height="15cm", dpi=140)
36# pymol.cmd.png("my_image.png")
37# Get out!
38pymol.cmd.quit()
The script above uses PyMOL in a script manner to save the 3D graphical representation of the protein (here below) but you could also use PyMOL in an interactive mode.