text: user3284: I am working on a project about phosphorylation, and I am creating a database of some proteins. I have a list of protein accession ids for which I need to get the corresponding PDB file for each one to map it to PSM matrix. I want to get the PDB file using Python or BioPython tools. Any suggestions will be appreciated.
  
  user461: A typical Uniprot URL would look like the example here:
  https://www.uniprot.org/uniprot/?query=ID:P26378&format=tab&columns=id%2Cdatabase(PDB)
  The response will be:
  
  Entry Cross-reference (PDB) 
  P26378    1FXL;1G2E;
  
  We want our query to include the protein ID, the output format should be tab separated and the only contain the columns id and database (PDB).
  To get the PDB IDs you would need to split the response, take the last line, split this line after each tab and split it again after each semi-colon.
  Using Python's Requests library the whole code would be.
  import requests
  import time
  
  uniprot_ids = ['P26378', 'O35433', 'Q02910']
  url = 'https://www.uniprot.org/uniprot/'
  
  protein_to_pdb = {}
  for protein in uniprot_ids:
      params = {
          'format': 'tab',
          'query': 'ID:{}'.format(protein),
          'columns': 'id,database(PDB)'
      }
      contact = ""  # Please set your email address here.
      headers = {'User-Agent': 'Python {}'.format(contact)}
      r = requests.get(url, params=params, headers=headers)
  
      protein_to_pdb[protein] = str(r.text).splitlines()[-1].split('\t')[-1].split(';')
      protein_to_pdb[protein].pop(-1)
      time.sleep(1)  # be respectful and don't overwhelm the server with requests
  
  print(protein_to_pdb)
  
  
  
  To accelerate things, you could store your protein_to_pdb dict in a file and only retrieve the new ones
  Checking if the returned ID matches your input ID is always a good idea 
  
  
original_text: 3284: <p>I am working on a project about phosphorylation, and I am creating a database of some proteins. I have a list of protein accession ids for which I need to get the corresponding PDB file for each one to map it to PSM matrix. I want to get the PDB file using Python or BioPython tools. Any suggestions will be appreciated.</p>
   461: <p>A typical Uniprot URL would look like the example here:</p>
  
  <p><a href="https://www.uniprot.org/uniprot/?query=ID:P26378&amp;format=tab&amp;columns=id%2Cdatabase(PDB)" rel="nofollow noreferrer">https://www.uniprot.org/uniprot/?query=ID:P26378&amp;format=tab&amp;columns=id%2Cdatabase(PDB)</a></p>
  
  <p>The response will be:</p>
  
  <blockquote>
    <p>Entry Cross-reference (PDB) </p>
    
    <p>P26378    1FXL;1G2E;</p>
  </blockquote>
  
  <p>We want our query to include the protein ID, the output format should be tab separated and the only contain the columns <code>id</code> and <code>database (PDB)</code>.</p>
  
  <p>To get the PDB IDs you would need to split the response, take the last line, split this line after each tab and split it again after each semi-colon.</p>
  
  <p>Using Python's Requests library the whole code would be.</p>
  
  <pre><code>import requests
  import time
  
  uniprot_ids = ['P26378', 'O35433', 'Q02910']
  url = 'https://www.uniprot.org/uniprot/'
  
  protein_to_pdb = {}
  for protein in uniprot_ids:
      params = {
          'format': 'tab',
          'query': 'ID:{}'.format(protein),
          'columns': 'id,database(PDB)'
      }
      contact = ""  # Please set your email address here.
      headers = {'User-Agent': 'Python {}'.format(contact)}
      r = requests.get(url, params=params, headers=headers)
  
      protein_to_pdb[protein] = str(r.text).splitlines()[-1].split('\t')[-1].split(';')
      protein_to_pdb[protein].pop(-1)
      time.sleep(1)  # be respectful and don't overwhelm the server with requests
  
  print(protein_to_pdb)
  </code></pre>
  
  <hr>
  
  <ul>
  <li>To accelerate things, you could store your <code>protein_to_pdb</code> dict in a file and only retrieve the new ones</li>
  <li>Checking if the returned ID matches your input ID is always a good idea </li>
  </ul>
  