Skip to content

Instantly share code, notes, and snippets.

@keitaroyam
Last active June 15, 2024 00:59
Show Gist options
  • Save keitaroyam/1732dcddc87b7f4ca576c19102009540 to your computer and use it in GitHub Desktop.
Save keitaroyam/1732dcddc87b7f4ca576c19102009540 to your computer and use it in GitHub Desktop.
Getting the list of monomers from PDB
import json
import urllib
import requests
def req(query):
url = "https://pdbj.org/rest/newweb/search/sql?q=" + urllib.parse.quote(query)
raw = urllib.request.urlopen(url).read()
return json.loads(raw)["results"]
# [(pdb_id, monomer_id), ...]
all_mon = req("SELECT distinct pdbid,id FROM chem_comp")
json.dump(all_mon, open("./pdb_all_mon.json", "w"))
all_res = dict(req("SELECT pdbid, ls_d_res_high FROM refine"))
mons = {} # {monomer_id: [(pdb_id, resolution), ...]}
for p, m in all_mon:
res = all_res.get(p)
if res is None: res = float("inf")
mons.setdefault(m, []).append((p, res))
for m in mons:
mons[m].sort(key=lambda x: x[1])
json.dump(mons, open("./pdb_all_mon_res.json", "w"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment