Last active
June 15, 2024 00:59
-
-
Save keitaroyam/1732dcddc87b7f4ca576c19102009540 to your computer and use it in GitHub Desktop.
Getting the list of monomers from PDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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