{
  "filename": "plot_3.png",
  "iteration": 1,
  "description": "Corrected structural mapping of PNLIP disease alleles with geometric identification of the catalytic triad in 1LPB",
  "timestamp": "2026-11-28 23:57:26",
  "code": "\nimport requests, numpy as np, pandas as pd\nimport matplotlib.pyplot as plt\nfrom collections import defaultdict\n\npdbtxt = requests.get(\"https://files.rcsb.org/download/1LPB.pdb\", timeout=90).text\nat=defaultdict(dict); resn={}\nfor l in pdbtxt.splitlines():\n    if l.startswith(\"ATOM\"):\n        ch=l[21]; ri=int(l[22:26]); an=l[12:16].strip()\n        at[(ch,ri)][an]=np.array([float(l[30:38]),float(l[38:46]),float(l[46:54])]); resn[(ch,ri)]=l[17:20].strip()\nLIP,COL='B','A'\n# geometric triad search: Ser OG within 3.5 A of His NE2, His ND1 within 3.5 A of Asp OD1/OD2\nsers=[k for k in at if k[0]==LIP and resn[k]==\"SER\" and \"OG\" in at[k]]\nhiss=[k for k in at if k[0]==LIP and resn[k]==\"HIS\" and \"NE2\" in at[k] and \"ND1\" in at[k]]\nasps=[k for k in at if k[0]==LIP and resn[k] in (\"ASP\",\"GLU\")]\ntriad=None\nfor s in sers:\n    for h in hiss:\n        if np.linalg.norm(at[s][\"OG\"]-at[h][\"NE2\"])<3.6:\n            for d in asps:\n                oc=[v for k2,v in at[d].items() if k2 in (\"OD1\",\"OD2\",\"OE1\",\"OE2\")]\n                if oc and min(np.linalg.norm(at[h][\"ND1\"]-o) for o in oc)<3.6:\n                    triad=(s,h,d)\nprint(\"Geometric catalytic triad in 1LPB chain B:\",\n      [(resn[x], x[1]) for x in triad])\nOFF = 169 - triad[0][1]   # UniProt Ser169 -> PDB Ser\nprint(\"UniProt->PDB offset =\", OFF, \"(PDB res = UniProt - %d)\"%OFF)\n\ndef mind(k, pool):\n    A=np.array(list(at[k].values())); B=np.array(pool)\n    return float(np.sqrt(((A[:,None,:]-B[None,:,:])**2).sum(-1)).min())\ntriad_atoms=[v for x in triad for v in at[x].values()]\ncol_atoms=[v for k,d in at.items() if k[0]==COL for v in d.values()]\n\nVAR=[(\"p.W102*\",102,\"CPLD\",\"nonsense\"),(\"p.A174P\",174,\"CP\",\"missense\"),(\"p.R188C\",188,\"CPLD\",\"missense\"),\n (\"p.T221M\",221,\"CPLD\",\"missense\"),(\"p.G233E\",233,\"CP\",\"missense\"),(\"p.C254R\",254,\"CP\",\"missense\"),\n (\"p.I265R\",265,\"CP protease-sensitive\",\"missense\"),(\"p.S290N\",290,\"CPLD\",\"missense\"),\n (\"p.F300L\",300,\"CP protease-sensitive\",\"missense\"),(\"p.W419*\",419,\"CPLD\",\"nonsense\"),\n (\"p.A433T\",433,\"CP\",\"missense\"),(\"p.V454F\",454,\"CP\",\"missense\")]\nAA3={'A':'ALA','R':'ARG','N':'ASN','D':'ASP','C':'CYS','Q':'GLN','E':'GLU','G':'GLY','H':'HIS','I':'ILE',\n     'L':'LEU','K':'LYS','M':'MET','F':'PHE','P':'PRO','S':'SER','T':'THR','W':'TRP','Y':'TYR','V':'VAL'}\nrows=[]\nfor name,up,cls,typ in VAR:\n    r=up-OFF; k=(LIP,r); exp=AA3[name[2]]\n    ok = resn.get(k)==exp\n    rows.append(dict(variant=name,uniprot=up,pdb_res=r,pdb_aa=resn.get(k,\"n/d\"),matches_wt=ok,\n                     d_triad=round(mind(k,triad_atoms),1) if k in at else np.nan,\n                     d_colipase=round(mind(k,col_atoms),1) if k in at else np.nan,\n                     domain=\"C-term PLAT (colipase binding)\" if up>=355 else \"N-term a/b hydrolase\",cls=cls,typ=typ))\nv=pd.DataFrame(rows); pd.set_option(\"display.width\",240)\nprint(\"\\nPNLIP disease alleles mapped onto 1LPB (human lipase + procolipase, 2.46 A)\")\nprint(v.to_string(index=False))\nprint(\"\\nWT identity check passed for %d/%d residues\"%(v.matches_wt.sum(),len(v)))\nmis=v[v.typ==\"missense\"]\nprint(\"\\nMean distance to catalytic triad: CPLD missense %.1f A, CP missense %.1f A\"\n      %(mis[mis.cls=='CPLD'].d_triad.mean(), mis[mis.cls!='CPLD'].d_triad.mean()))\nprint(\"Range of distances to triad (all missense): %.1f - %.1f A\"%(mis.d_triad.min(),mis.d_triad.max()))\nprint(\"Number of missense alleles within 5 A of the triad: %d/%d\"%((mis.d_triad<5).sum(),len(mis)))\n\ncolors={\"CPLD\":\"#C44E52\",\"CP\":\"#4C72B0\",\"CP protease-sensitive\":\"#55A868\"}\nfig,axes=plt.subplots(1,2,figsize=(14.5,5.6))\nax=axes[0]\nfor _,r in mis.iterrows():\n    ax.scatter(r.d_triad,r.d_colipase,s=140,color=colors[r.cls],edgecolor=\"k\",zorder=3)\n    ax.annotate(r.variant,(r.d_triad,r.d_colipase),textcoords=\"offset points\",xytext=(7,5),fontsize=9)\nfor k,c in colors.items(): ax.scatter([],[],color=c,edgecolor=\"k\",s=100,label=k)\nax.axvline(5,ls=\"--\",color=\"grey\",lw=1); ax.text(5.3,ax.get_ylim()[1]*0.02+2,\"5 A from triad\",fontsize=8,color=\"grey\",rotation=90)\nax.set_xlabel(\"min distance to catalytic triad Ser/Asp/His (A)\")\nax.set_ylabel(\"min distance to bound colipase (A)\")\nax.set_title(\"PNLIP missense alleles are scattered through the fold,\\nmostly far from the active site and the colipase interface\")\nax.legend(fontsize=8); ax.grid(alpha=.3)\n\nax=axes[1]\nax.add_patch(plt.Rectangle((17,.4),355-17,.2,color=\"#DDDDDD\",ec=\"k\")); ax.text((17+355)/2,.48,\"N-terminal alpha/beta hydrolase (17-354)\",ha=\"center\",fontsize=8.5)\nax.add_patch(plt.Rectangle((355,.4),110,.2,color=\"#BBD5EA\",ec=\"k\")); ax.text(410,.48,\"PLAT (355-465)\",ha=\"center\",fontsize=8.5)\nax.add_patch(plt.Rectangle((1,.4),16,.2,color=\"#F2C14E\",ec=\"k\"))\nfor pos,lab in [(169,\"S169\"),(193,\"D193\"),(280,\"H280\")]:\n    ax.plot([pos,pos],[.38,.62],color=\"k\",lw=2); ax.text(pos,.3,lab,ha=\"center\",fontsize=8)\nfor s,e in [(20,26),(107,118),(254,278),(302,313),(316,321),(449,465)]:\n    ax.plot([s,e],[.68,.68],color=\"#8172B2\",lw=2)\nax.text(240,.72,\"disulfide bonds\",fontsize=8,color=\"#8172B2\")\nfor name,up,cls,typ in VAR:\n    y=0.95 if typ==\"nonsense\" else 1.12\n    ax.plot([up,up],[.6,y-.03],color=colors[cls],lw=1)\n    ax.scatter([up],[y],color=colors[cls],marker=\"v\" if typ==\"nonsense\" else \"o\",s=60,edgecolor=\"k\",zorder=3)\n    ax.text(up,y+.05,name,rotation=68,fontsize=7.5,ha=\"left\")\nax.set_xlim(-10,520); ax.set_ylim(.2,1.6); ax.set_yticks([])\nax.set_xlabel(\"PNLIP residue (UniProt P16233 numbering)\"); ax.set_title(\"Domain positions of reported PNLIP disease alleles\")\nplt.tight_layout(); plt.show()\nglobals()['vmap']=v\n",
  "plot_number": 3
}