Get a list of PDB ids from a list of sequence protein number? 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.
A typical Uniprot URL would look like the example here:

https://www.uniprot.org/uniprot/?query=ID:P26378&amp;format=tab&amp;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