icn3d 3.45.3 → 3.45.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/icn3d.js +1 -1
- package/icn3d.min.js +1 -1
- package/icn3d.module.js +1 -1
- package/package.json +1 -1
package/icn3d.min.js
CHANGED
|
@@ -15,4 +15,4 @@ function Kr(){let e=null,t=!1,i=null,s=null;function n(t,r){i(t,r),s=e.requestAn
|
|
|
15
15
|
}hideHydrogens(){let e=this.icn3d;e.icn3dui;for(let t in e.hAtoms){let i=e.atoms[t];if("H"===i.elem.substr(0,1)){if(e.atoms[i.serial].bonds.length>0){let t=e.atoms[i.serial].bonds[0],s=e.atoms[t].bonds?e.atoms[t].bonds.indexOf(i.serial):-1;-1!==s&&(e.atoms[t].bonds.splice(s,1),e.atoms[t].bondOrder&&e.atoms[t].bondOrder.splice(s,1))}delete e.dAtoms[i.serial],delete e.hAtoms[i.serial]}}}hideExtraBonds(){let e=this.icn3d;e.icn3dui;for(let t in e.atoms)e.atoms[t].style2="nothing";for(let t in e.sidec)e.hAtoms.hasOwnProperty(t)&&(e.atoms[t].style2=e.opts.sidec);for(let t in e.water)e.hAtoms.hasOwnProperty(t)&&(e.atoms[t].style=e.opts.water)}hideHbondsContacts(){let e=this.icn3d,t=e.icn3dui,i="set hbonds off";t.htmlCls.clickMenuCls.setLogCmd(i,!0),e.hBondCls.hideHbonds(),i="set salt bridge off",t.htmlCls.clickMenuCls.setLogCmd(i,!0),e.saltbridgeCls.hideSaltbridge(),i="set contact off",t.htmlCls.clickMenuCls.setLogCmd(i,!0),e.contactCls.hideContact(),i="set halogen pi off",t.htmlCls.clickMenuCls.setLogCmd(i,!0),e.piHalogenCls.hideHalogenPi(),this.hideExtraBonds()}showIonicInteractions(e,t,i,s,n,r){let a,o,l,d,c=this.icn3d,h=c.icn3dui;if(!s&&(a="saltbridge",o="salt bridge "+e+" | sets "+t+" "+i+" | "+s,c.opts[a]="yes",l=c.definedSetsCls.getAtomsFromNameArray(t),d=c.definedSetsCls.getAtomsFromNameArray(i),c.firstAtomObjCls.getFirstAtomObj(l),Object.keys(d).length>0&&Object.keys(l).length>0)){let t,i=c.saltbridgeCls.calculateIonicInteractions(h.hashUtilsCls.hash2Atoms(d,c.atoms),h.hashUtilsCls.hash2Atoms(l,c.atoms),parseFloat(e),n);c.resid2ResidhashSaltbridge=h.hashUtilsCls.cloneHash(c.resid2Residhash),t="all atoms that have ionic interactions with the selected atoms";let s={};for(let e in i){s[c.atoms[e].structure+"_"+c.atoms[e].chain+"_"+c.atoms[e].resi]=1}c.hAtoms={};for(let e in s)for(let t in c.residues[e])c.hAtoms[t]=1,c.atoms[t].style2="stick",c.ions.hasOwnProperty(t)&&(c.atoms[t].style2="sphere");let r=a+"_auto";c.selectionCls.addCustomSelection(Object.keys(s),r,t,o,!0),c.selectionCls.saveSelectionIfSelected(),c.drawCls.draw()}}showHalogenPi(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui;if(s)return;let l,d,c=r+" "+e+" | sets "+t+" "+i+" | "+s;if(a.opts[r]="yes",l=a.definedSetsCls.getAtomsFromNameArray(t),d=a.definedSetsCls.getAtomsFromNameArray(i),a.firstAtomObjCls.getFirstAtomObj(l),Object.keys(d).length>0&&Object.keys(l).length>0){let t,i=a.piHalogenCls.calculateHalogenPiInteractions(o.hashUtilsCls.hash2Atoms(l,a.atoms),o.hashUtilsCls.hash2Atoms(d,a.atoms),parseFloat(e),n,r);"halogen"==r?(a.resid2ResidhashHalogen=o.hashUtilsCls.cloneHash(a.resid2Residhash),t="all atoms that have halogen bonds with the selected atoms"):"pi-cation"==r?(a.resid2ResidhashPication=o.hashUtilsCls.cloneHash(a.resid2Residhash),t="all atoms that have pi-cation interactions with the selected atoms"):"pi-stacking"==r&&(a.resid2ResidhashPistacking=o.hashUtilsCls.cloneHash(a.resid2Residhash),t="all atoms that have pi-stacking with the selected atoms");let s={};for(let e in i){s[a.atoms[e].structure+"_"+a.atoms[e].chain+"_"+a.atoms[e].resi]=1}a.hAtoms={};for(let e in s)for(let t in a.residues[e])a.hAtoms[t]=1,a.atoms[t].style2="stick",a.ions.hasOwnProperty(t)&&(a.atoms[t].style2="sphere");let h=r+"_auto";a.selectionCls.addCustomSelection(Object.keys(s),h,t,c,!0),a.selectionCls.saveSelectionIfSelected(),a.drawCls.draw()}}showClbonds(){let e=this.icn3d,t=e.icn3dui;e.opts.clbonds="yes";let i=e.applyClbondsCls.applyClbondsOptions();for(let s in i)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[s]);if(Object.keys(i).length>0){let t="clbonds",s="all atoms that have cross-linkages";e.selectionCls.addCustomSelection(Object.keys(i),t,s,"cross linkage",!0),e.selectionCls.saveSelectionIfSelected(),e.drawCls.draw()}}showSsbonds(){let e=this.icn3d,t=e.icn3dui;e.opts.ssbonds="yes";let i={},s=Object.keys(e.structures);for(let n=0,r=s.length;n<r;++n){let r=s[n];if(void 0!==e.ssbondpnts[r])for(let s=0,n=Math.floor(e.ssbondpnts[r].length/2);s<n;s++){let n=e.ssbondpnts[r][2*s],a=e.ssbondpnts[r][2*s+1];i[n]=1,i[a]=1,e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[n]),e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[a])}}if(Object.keys(i).length>0){let t="ssbonds",s="all atoms that have disulfide bonds";e.selectionCls.addCustomSelection(Object.keys(i),t,s,"disulfide bonds",!0),e.selectionCls.saveSelectionIfSelected(),e.drawCls.draw()}}pickCustomSphere(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui;if(s)return;let l,d,c="select zone cutoff "+e+" | sets "+t+" "+i+" | "+s;n&&(c="interactions "+e+" | sets "+t+" "+i+" | "+s,a.opts.contact="yes"),l=a.definedSetsCls.getAtomsFromNameArray(t),d=a.definedSetsCls.getAtomsFromNameArray(i);let h,p,u,m=this.pickCustomSphere_base(e,l,d,s,n,r,c,!0),f=Object.keys(m.residues);a.hAtoms={};for(let e=0,t=f.length;e<t;++e){let t=f[e];for(let e in a.residues[t])a.hAtoms[e]=1}let g=a.firstAtomObjCls.getFirstAtomObj(l);void 0!==g&&(h="sphere."+g.chain+":"+o.utilsCls.residueName2Abbr(g.resn.substr(0,3)).trim()+g.resi+"-"+e+"A",u="sphere-"+e+"A",n&&(h="interactions."+g.chain+":"+o.utilsCls.residueName2Abbr(g.resn.substr(0,3)).trim()+g.resi+"-"+$("#"+a.pre+"contactthreshold").val()+"A",u="interactions-"+$("#"+a.pre+"contactthreshold").val()+"A"),p=h,a.selectionCls.addCustomSelection(f,h,p,c,!0),a.selectionCls.addCustomSelection(f,u,p,c,!0)),a.selectionCls.saveSelectionIfSelected(),a.drawCls.draw()}pickCustomSphere_base(e,t,i,s,n,r,a,o,l){let d,c=this.icn3d,h=c.icn3dui;n?(d=c.contactCls.getAtomsWithinAtom(h.hashUtilsCls.hash2Atoms(i,c.atoms),h.hashUtilsCls.hash2Atoms(t,c.atoms),parseFloat(e),o,n,void 0,l),c.resid2ResidhashInteractions=h.hashUtilsCls.cloneHash(c.resid2Residhash)):(d=c.contactCls.getAtomsWithinAtom(i,t,parseFloat(e),o,n),c.resid2ResidhashSphere=h.hashUtilsCls.cloneHash(c.resid2Residhash));let p={};for(let e in d){let t=d[e];c.bOpm&&"DUM"===t.resn||(p[t.structure+"_"+t.chain+"_"+t.resi]=1)}return{residues:p,resid2Residhash:c.resid2Residhash}}}class yh{constructor(e){this.icn3d=e}async viewInteractionPairs(e,t,i,s,n,r,a,o,l,d,c){let h,p=this.icn3d,u=p.icn3dui;i||(p.hbondpnts=[],p.saltbridgepnts=[],p.contactpnts=[],p.halogenpnts=[],p.picationpnts=[],p.pistackingpnts=[]),p.bRender=!1;let m,f={},g=u.hashUtilsCls.cloneHash(p.hAtoms),b="calpha"==s||"cbeta"==s||"heavyatoms"==s,C={},v={};if(b)for(let e in p.hAtoms){let t=p.atoms[e];"HOH"!=t.resn&&"WAT"!=t.resn&&"SOL"!=t.resn&&(("calpha"==s&&(t.het||"CA"==t.name||"O3'"==t.name||"O3*"==t.name)||"cbeta"==s&&(t.het||"CB"==t.name||"O3'"==t.name||"O3*"==t.name)||"heavyatoms"==s&&"H"!=t.elem)&&(C[e]=t,v[e]=t))}else C=p.definedSetsCls.getAtomsFromNameArray(e),v=p.definedSetsCls.getAtomsFromNameArray(t);let _=0,y=0;for(let e in p.structures){for(let t=0,i=p.structures[e].length;t<i;++t){let i=p.structures[e][t];for(let e in p.chains[i])if(C.hasOwnProperty(e)||v.hasOwnProperty(e)){++_;break}}++y}m=y>1?"structure":_>1?"chain":"residue";let S=[];if(n&&S.push("hbonds"),r&&S.push("salt bridge"),a&&S.push("interactions"),o&&S.push("halogen"),l&&S.push("pi-cation"),d&&S.push("pi-stacking"),i||(p.resids2inter={},p.resids2interAll={}),r){let n=parseFloat($("#"+p.pre+"saltbridgethreshold").val());n&&!isNaN(n)||(n=p.tsIonic),i||(p.hAtoms=u.hashUtilsCls.cloneHash(g),p.showInterCls.showIonicInteractions(n,e,t,i,!0,s)),f=u.hashUtilsCls.unionHash(f,p.hAtoms)}if(n){let n=parseFloat($("#"+p.pre+"hbondthreshold").val());n&&!isNaN(n)||(n=p.tsHbond),i||(p.hAtoms=u.hashUtilsCls.cloneHash(g),p.showInterCls.showHbonds(n,e,t,i,void 0,s)),f=u.hashUtilsCls.unionHash(f,p.hAtoms)}let w,x,A,M,T="";if(n&&(T+=this.exportHbondPairs(s,m)),r&&(T+=this.exportSaltbridgePairs(s,m)),o){let n=parseFloat($("#"+p.pre+"halogenthreshold").val());n&&!isNaN(n)||(n=p.tsHalogen),i||(p.hAtoms=u.hashUtilsCls.cloneHash(g),p.showInterCls.showHalogenPi(n,e,t,i,s,"halogen")),f=u.hashUtilsCls.unionHash(f,p.hAtoms),T+=this.exportHalogenPiPairs(s,m,"halogen")}if(l){let n=parseFloat($("#"+p.pre+"picationthreshold").val());n&&!isNaN(n)||(n=p.tsPication),i||(p.hAtoms=u.hashUtilsCls.cloneHash(g),p.showInterCls.showHalogenPi(n,e,t,i,s,"pi-cation")),f=u.hashUtilsCls.unionHash(f,p.hAtoms),T+=this.exportHalogenPiPairs(s,m,"pi-cation")}if(d){let n=parseFloat($("#"+p.pre+"pistackingthreshold").val());n&&!isNaN(n)||(n=p.tsPistacking),i||(p.hAtoms=u.hashUtilsCls.cloneHash(g),p.showInterCls.showHalogenPi(n,e,t,i,s,"pi-stacking")),f=u.hashUtilsCls.unionHash(f,p.hAtoms),T+=this.exportHalogenPiPairs(s,m,"pi-stacking")}if(a){let n=b?c:parseFloat($("#"+p.pre+"contactthreshold").val());if(n&&!isNaN(n)||(n=p.tsContact),1!=e.length||1!=t.length||e[0]!=t[0])i||(p.hAtoms=u.hashUtilsCls.cloneHash(g),p.showInterCls.pickCustomSphere(n,e,t,i,!0,s)),f=u.hashUtilsCls.unionHash(f,p.hAtoms),T+=this.exportSpherePairs(!0,s,m);else{if(!i){let r={},o={};if(b){let e=!0,t=p.showInterCls.pickCustomSphere_base(n,C,v,i,!0,void 0,void 0,!0,e);r=u.hashUtilsCls.unionHash(r,t.residues);for(let e in t.resid2Residhash)o[e]=u.hashUtilsCls.unionHash(o[e],t.resid2Residhash[e])}else{let a=[],l="",d="",c={};for(let e in C){let t=p.atoms[e];t.ss==l&&t.chain==d||(Object.keys(c).length>0&&a.push(c),c={}),c[t.serial]=1,l=t.ss,d=t.chain}Object.keys(c).length>0&&a.push(c);let h=a.length,m="interactions "+n+" | sets "+e+" "+t+" | true";p.opts.contact="yes";for(let e=0;e<h;++e)for(let t=e+1;t<h;++t){p.hAtoms=u.hashUtilsCls.cloneHash(g);let l=p.showInterCls.pickCustomSphere_base(n,a[e],a[t],i,!0,s,m,!0);r=u.hashUtilsCls.unionHash(r,l.residues);for(let e in l.resid2Residhash)o[e]=u.hashUtilsCls.unionHash(o[e],l.resid2Residhash[e])}}p.resid2ResidhashInteractions=o;let l,d,c=Object.keys(r);p.hAtoms={};for(let e=0,t=c.length;e<t;++e){let t=c[e];for(let e in p.residues[t])p.hAtoms[e]=1}let h=p.firstAtomObjCls.getFirstAtomObj(r);void 0!==h&&(l="sphere."+h.chain+":"+u.utilsCls.residueName2Abbr(h.resn.substr(0,3)).trim()+h.resi+"-"+radius+"A",a&&(l="interactions."+h.chain+":"+u.utilsCls.residueName2Abbr(h.resn.substr(0,3)).trim()+h.resi+"-"+$("#"+p.pre+"contactthreshold").val()+"A"),d=l,p.selectionCls.addCustomSelection(c,l,d,x,!0)),p.selectionCls.saveSelectionIfSelected(),p.drawCls.draw()}f=u.hashUtilsCls.unionHash(f,p.hAtoms),T+=this.exportSpherePairs(!0,s,m)}}p.hAtoms=u.hashUtilsCls.cloneHash(f),p.bRender=!0,p.drawCls.draw(),w=p.firstAtomObjCls.getResiduesFromAtoms(f),x="select "+p.resid2specCls.residueids2spec(Object.keys(w)),A="interface_all",M=A,p.selectionCls.addCustomSelection(Object.keys(w),A,M,x,!0);let E=u.hashUtilsCls.intHash(f,C);w=p.firstAtomObjCls.getResiduesFromAtoms(E),x="select "+p.resid2specCls.residueids2spec(Object.keys(w)),A="interface_1",M=A,p.selectionCls.addCustomSelection(Object.keys(w),A,M,x,!0);let R=u.hashUtilsCls.intHash(f,v);w=p.firstAtomObjCls.getResiduesFromAtoms(R),x="select "+p.resid2specCls.residueids2spec(Object.keys(w)),A="interface_2",M=A,p.selectionCls.addCustomSelection(Object.keys(w),A,M,x,!0);let k='<div style="text-align:center"><b>'+S.join(", ")+" between Two Sets:</b><br>",O=p.resid2specCls.atoms2residues(Object.keys(C)),I=p.resid2specCls.atoms2residues(Object.keys(v)),P="select "+p.resid2specCls.residueids2spec(O),D="select "+p.resid2specCls.residueids2spec(I);k+="Set 1: "+e+' <button class="'+p.pre+'selset" cmd="'+P+'">Highlight in 3D</button><br>',k+="Set 2: "+t+' <button class="'+p.pre+'selset" cmd="'+D+'">Highlight in 3D</button><br><br></div>',k+='<div style="text-align:center"><b>The interfaces are:</b><br>';let L=p.resid2specCls.atoms2residues(Object.keys(E)),F=p.resid2specCls.atoms2residues(Object.keys(R)),N="select "+p.resid2specCls.residueids2spec(L),U="select "+p.resid2specCls.residueids2spec(F);k+='interface_1 <button class="'+p.pre+'selset" cmd="'+N+'">Highlight in 3D</button><br>',k+='interface_2 <button class="'+p.pre+'selset" cmd="'+U+'">Highlight in 3D</button><br><br></div>',k+='<div><b>Note</b>: Each checkbox below selects the corresponding residue. You can click "Save Selection" in the "Select" menu to save the selection and click on "Highlight" button to clear the checkboxes.</div><br>';let H=k;if(("graph"==s||"linegraph"==s||"scatterplot"==s||b)&&(k=""),k+=T,"save1"==s||"save2"==s){k=H;let e="";"save1"==s?e="Set 1":"save2"==s&&(e="Set 2"),k+='<div style="text-align:center"><br><b>Interactions Sorted on '+e+'</b>: <button class="'+p.pre+'showintercntonly" style="margin-left:20px">Show Count Only</button><button class="'+p.pre+'showinterdetails" style="margin-left:20px">Show Details</button></div>';let t=this.getAllInteractionTable(s);k+=t.html,h=t.bondCnt,$("#"+p.pre+"dl_interactionsorted_html").html(k),u.htmlCls.dialogCls.openDlg("dl_interactionsorted","Show sorted interactions")}else if("view"==s)$("#"+p.pre+"dl_allinteraction_html").html(k),u.htmlCls.dialogCls.openDlg("dl_allinteraction","Show interactions");else if("linegraph"==s){u.htmlCls.dialogCls.openDlg("dl_linegraph","Show interactions between two lines of residue nodes"),p.graphStr=p.getGraphCls.getGraphData(C,v,e,t,k,m),p.bLinegraph=!0;let i=p.lineGraphCls.drawLineGraph(p.graphStr);$("#"+p.pre+"linegraphDiv").html(i)}else if("scatterplot"==s){u.htmlCls.dialogCls.openDlg("dl_scatterplot","Show interactions as scatterplot"),p.graphStr=p.getGraphCls.getGraphData(C,v,e,t,k,m),p.bScatterplot=!0;let i=p.lineGraphCls.drawLineGraph(p.graphStr,!0);$("#"+p.pre+"scatterplotDiv").html(i)}else if("ligplot"==s)await p.ligplotCls.drawLigplot(C);else if(b){u.htmlCls.dialogCls.openDlg("dl_contactmap","Show contact map");let i=!0,s=p.getGraphCls.getGraphData(C,v,e,t,k,m,i);p.bContactMap=!0;let n=p.contactMapCls.drawContactMap(s);$("#"+p.pre+"contactmapDiv").html(n)}else if("graph"==s){if(p.graphStr=p.getGraphCls.getGraphData(C,v,e,t,k,m),p.bGraph=!0,Object.keys(v).length+Object.keys(C).length>Object.keys(p.dAtoms).length&&(p.graphStr=p.selectionCls.getGraphDataForDisplayed()),void 0===p.bD3){let e="./script/d3v4-force-all.min.js";await u.getAjaxPromise(e,"script"),p.bD3=!0}$("#"+u.svgid).empty(),u.htmlCls.dialogCls.openDlg("dl_graph","Force-directed graph"),p.drawGraphCls.drawGraph(p.graphStr,p.pre+"dl_graph")}return{interactionTypes:S.toString(),bondCnt:h}}clearInteractions(){let e=this.icn3d;e.icn3dui,e.lines.hbond=[],e.hbondpnts=[],e.lines.saltbridge=[],e.saltbridgepnts=[],e.lines.contact=[],e.contactpnts=[],e.lines.halogen=[],e.lines["pi-cation"]=[],e.lines["pi-stacking"]=[],e.halogenpnts=[],e.picationpnts=[],e.pistackingpnts=[]}resetInteractionPairs(){let e=this.icn3d;e.icn3dui,e.bHbondCalc=!1,e.showInterCls.hideHbondsContacts(),e.hlUpdateCls.clearHighlight(),e.resids2inter={},e.resids2interAll={}}async retrieveInteractionData(){let e=this.icn3d,t=e.icn3dui;if(!e.b2DShown)if(void 0!==t.cfg.align){let i=Object.keys(e.structures);if(2==t.cfg.atype){let t=!0;await e.alignParserCls.downloadAlignment(i[0]+","+i[1],t)}await e.ParserUtilsCls.set2DDiagramsForAlign(i[0].toUpperCase(),i[1].toUpperCase())}else void 0!==t.cfg.chainalign?(Object.keys(e.structures),await e.ParserUtilsCls.set2DDiagramsForChainalign(e.chainidArray)):e.ParserUtilsCls.download2Ddgm(e.inputid.toUpperCase())}getAllInteractionTable(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui,l="",d="",c=[],h=Object.keys(a.resids2inter);("save1"==e||"save2"==e)&&h.sort((function(t,i){return o.utilsCls.compResid(t,i,e)}));let p,u,m="",f="",g="",b="",C="",v="",_="",y="",S="",w=0,x=0,A=0,M=0,T=0,E=0,R="";for(let o=0,k=h.length;o<k;++o){let k=h[o],O=k.split(",");p="save1"==e?O[0]:O[1],u="save1"==e?O[1]:O[0];let I,P,D=p.split("_");o>0&&p!=f&&(c.push({res1:f,res2:R,cntHbond:w,cntIonic:x,cntContact:A,cntHalegen:M,cntPication:T,cntPistacking:E}),m+=this.getInteractionPerResidue(g,b,C,v,_,y,S,w,x,A,M,T,E),b="",C="",v="",_="",y="",S="",w=0,x=0,A=0,M=0,T=0,E=0,R=""),I=a.resids2inter[k].hbond,P=this.getInteractionPairDetails(I,e,"hbond",t,i,s,n,r),b+=P.html,w+=P.cnt,l+=P.svgHtmlNode,d+=P.svgHtmlLine,P.cnt>0&&(R+=u+":hbond_"+P.cnt+":type_"+P.mainside+" "),I=a.resids2inter[k].ionic,P=this.getInteractionPairDetails(I,e,"ionic",t,i,s,n,r),C+=P.html,x+=P.cnt,l+=P.svgHtmlNode,d+=P.svgHtmlLine,P.cnt>0&&(R+=u+":ionic_"+P.cnt+":type_"+P.mainside+" "),I=a.resids2inter[k].halogen,P=this.getInteractionPairDetails(I,e,"halogen",t,i,s,n,r),_+=P.html,M+=P.cnt,l+=P.svgHtmlNode,d+=P.svgHtmlLine,P.cnt>0&&(R+=u+":halogen_"+P.cnt+":type_"+P.mainside+" "),I=a.resids2inter[k]["pi-cation"],P=this.getInteractionPairDetails(I,e,"pi-cation",t,i,s,n,r),y+=P.html,T+=P.cnt,l+=P.svgHtmlNode,d+=P.svgHtmlLine,P.cnt>0&&(R+=u+":pi-cation_"+P.cnt+":type_"+P.mainside+" "),I=a.resids2inter[k]["pi-stacking"],P=this.getInteractionPairDetails(I,e,"pi-stacking",t,i,s,n,r),S+=P.html,E+=P.cnt,l+=P.svgHtmlNode,d+=P.svgHtmlLine,P.cnt>0&&(R+=u+":pi-stacking_"+P.cnt+":type_"+P.mainside+" "),I=a.resids2inter[k].contact,P=this.getContactPairDetails(I,e,"contact",t,i,s,n,r),v+=P.html,A+=P.cnt,l+=P.svgHtmlNode,d+=P.svgHtmlLine,P.cnt>0&&(R+=u+":contact_"+P.cnt+" "),f=p,g=D}c.push({res1:f,res2:R,cntHbond:w,cntIonic:x,cntContact:A,cntHalegen:M,cntPication:T,cntPistacking:E}),m+=this.getInteractionPerResidue(g,b,C,v,_,y,S,w,x,A,M,T,E);let k="";if(h.length>0){k+='<br><table class="icn3d-sticky" align=center border=1 cellpadding=10 cellspacing=0><thead>',k+="<tr><th rowspan=2>Residue</th><th rowspan=2># Hydrogen<br>Bond</th><th rowspan=2># Salt Bridge<br>/Ionic Interaction</th><th rowspan=2># Contact</th>",k+="<th rowspan=2># Halogen<br>Bond</th><th rowspan=2># π-Cation</th><th rowspan=2># π-Stacking</th>",k+="<th>Hydrogen Bond (backbone atoms: @CA, @N, @C, @O)</th><th>Salt Bridge/Ionic Interaction</th><th>Contact</th>",k+="<th>Halogen Bond</th><th>π-Cation</th><th>π-Stacking</th></tr>",k+="<tr>";let e='<td><table width="100%" class="icn3d-border"><tr><td>Atom1</td><td>Atom2</td><td>Distance(Å)</td><td>Highlight in 3D</td></tr></table></td>';k+=e,k+=e,k+='<td><table width="100%" class="icn3d-border"><tr><td>Atom1</td><td>Atom2</td><td># Contacts</td><td>Min Distance(Å)</td><td>C-alpha Distance(Å)</td><td>Highlight in 3D</td></tr></table></td>',k+=e,k+=e,k+=e,k+="</tr>",k+="</thead><tbody>",k+=m,k+="</tbody></table><br/>"}return{html:k,bondCnt:c,svgHtmlNode:l,svgHtmlLine:d}}getInteractionPerResidue(e,t,i,s,n,r,a,o,l,d,c,h,p){this.icn3d.icn3dui;let u="";u+='<tr align="center"><th>'+e[3]+e[2]+"</th><td>"+o+"</td><td>"+l+"</td><td>"+d+"</td><td>"+c+"</td><td>"+h+"</td><td>"+p+"</td>";let m=[t,i,s,n,r,a];for(let e in m){u+='<td valign="top"><table width="100%" class="icn3d-border">'+m[e]+"</table></td>"}return u+="</tr>",u}getInteractionPairDetails(e,t,i,s,n,r,a,o){let l=this.icn3d;l.icn3dui;let d="",c="",h="",p=0,u="",m=' <span style="background-color:#',f='"> </span>';if(void 0!==e){l.resid2cnt||(l.resid2cnt={}),l.resid2ToXy||(l.resid2ToXy={}),l.nodeid2lineid||(l.nodeid2lineid={});for(let g in e){let b=g.split("|"),C="save1"==t?b[0]:b[1],v="save1"==t?b[1]:b[0],_=C.lastIndexOf(" "),y=v.lastIndexOf(" "),S=C.substr(0,_),w=v.substr(0,y),x=S.substr(S.indexOf("@")+1);w.substr(w.indexOf("@")+1);let A="N"===x||"C"===x||"O"===x||"CA"===x?"main":"side";u&&(u+=";"),u+=A+","+A;let M=l.getGraphCls.convertLabel2Resid(S),T=l.firstAtomObjCls.getFirstAtomObj(l.residues[M]),E=T.color?T.color.getHexString():"",R=l.getGraphCls.convertLabel2Resid(w),k=l.firstAtomObjCls.getFirstAtomObj(l.residues[R]),O=k.color?k.color.getHexString():"",I=Math.sqrt(e[g]).toFixed(1);if(h+='<tr><td><span style="white-space:nowrap"><input type="checkbox" class="'+l.pre+'seloneres" id="'+l.pre+i+"2_"+p+'a" resid="'+S+'"/> '+S+m+E+f+'</span></td><td><span style="white-space:nowrap"><input type="checkbox" class="'+l.pre+'seloneres" id="'+l.pre+i+"2_"+p+'b" resid="'+w+'"/> '+w+m+O+f+'</span></td><td align="center">'+I+"</td>",h+='<td align="center"><button class="'+l.pre+'selres" resid="'+S+"|"+w+'">Highlight</button></td>',h+="</tr>",++p,s){let e=C.substr(_+1).split(","),t=l.ligplotCls.getSvgPerPair(e,S,w,i,s,n,r,a,o,I);d+=t.node,c+=t.line}}}return{html:h,cnt:p,svgHtmlNode:d,svgHtmlLine:c,mainside:u}}getContactPairDetails(e,t,i,s,n,r,a,o){let l=this.icn3d;l.icn3dui;let d="",c="",h="",p=0,u=' <span style="background-color:#',m='"> </span>';if(void 0!==e){let f={};l.resid2cnt||(l.resid2cnt={}),l.resid2ToXy||(l.resid2ToXy={}),l.nodeid2lineid||(l.nodeid2lineid={});for(let i in e){let n=i.split("|"),r="save1"==t?n[0]:n[1],a="save1"==t?n[1]:n[0],o=r.lastIndexOf(" "),d=a.lastIndexOf(" "),c=r.substr(o+1).split(","),h=r.substr(0,o);s&&(h+="@"+l.atoms[c[0]].name);let p=a.substr(0,d),u=h+"|"+p,m=l.getGraphCls.convertLabel2Resid(h);l.firstAtomObjCls.getFirstAtomObj(l.residues[m]);let g=l.getGraphCls.convertLabel2Resid(p);l.firstAtomObjCls.getFirstAtomObj(l.residues[g]);let b=e[i].split("_"),C=parseFloat(b[0]),v=parseInt(b[4]);f.hasOwnProperty(u)?(f[u].cnt+=v,C<f[u].dist1&&(f[u].dist1=C,f[u].dist1_dist2_atom1_atom2=b,f[u].serialArray1=c)):f[u]={dist1:C,dist1_dist2_atom1_atom2:b,cnt:v,serialArray1:c}}let g={};for(let e in f){let t=e.split("|"),i=t[0],s=t[1];g.hasOwnProperty(s)?g[s].push(i):g[s]=[i];let n=l.getGraphCls.convertLabel2Resid(i),r=l.firstAtomObjCls.getFirstAtomObj(l.residues[n]),a=r.color?r.color.getHexString():"",o=l.getGraphCls.convertLabel2Resid(s),d=l.firstAtomObjCls.getFirstAtomObj(l.residues[o]),c=d.color?d.color.getHexString():"",b=f[e].dist1_dist2_atom1_atom2,C=b[0],v=b[1],_=b[2],y=b[3],S=1;h+='<tr><td><span style="white-space:nowrap"><input type="checkbox" class="'+l.pre+'seloneres" id="'+l.pre+"inter2_"+p+'a" resid="'+i+'"/> '+i+"@"+_+u+a+m+'</span></td><td><span style="white-space:nowrap"><input type="checkbox" class="'+l.pre+'seloneres" id="'+l.pre+"inter2_"+p+'b" resid="'+s+'"/> '+s+"@"+y+u+c+m+'</span></td><td align="center">'+S+'</td><td align="center">'+C+'</td><td align="center">'+v+"</td>",h+='<td align="center"><button class="'+l.pre+'selres" resid="'+i+"|"+s+'">Highlight</button></td>',h+="</tr>",p+=parseInt(S)}if(s)for(let e in g){let t,h,p=g[e];for(let u=0,m=p.length;u<m;++u){let m=p[u],g=m+"|"+e,b=f[g].serialArray1,C=f[g].dist1_dist2_atom1_atom2,v=C[0];C[1];let _=0!=u,y=l.ligplotCls.getSvgPerPair(b,m,e,i,s,n,r,a,o,v,_,t,h);d+=y.node,c+=y.line,t=y.x2,h=y.y2}}}return{html:h,cnt:p,svgHtmlNode:d,svgHtmlLine:c}}exportInteractions(){var e=this.icn3d,t=e.icn3dui;let i='<html><body><div style="text-align:center"><br><b>Interacting residues</b>:<br/><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Base Chain: Residues</th><th>Interacting Chain</th></tr>';for(let t in e.chainname2residues)for(let s in e.chainname2residues[t]){let n=t.substr(0,t.indexOf("_"))+"_"+s.substr(0,s.indexOf(" "));i+="<tr><td>"+t+": ",i+=e.resid2specCls.residueids2spec(e.chainname2residues[t][s]),i+="</td><td>"+n+"</td></tr>"}i+="</table><br/></div></body></html>";let s=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(s+"_interactions.html","html",i)}exportSsbondPairs(){var e=this.icn3d,t=e.icn3dui;let i="",s=0;for(let t in e.structures){let n=e.ssbondpnts[t];if(void 0===n)break;for(let e=0,t=n.length;e<t;e+=2){i+="<tr><td>"+n[e]+" Cys</td><td>"+n[e+1]+" Cys</td></tr>",++s}}let n='<html><body><div style="text-align:center"><br><b>'+s+" disulfide pairs</b>:<br><br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Residue ID 1</th><th>Residue ID 2</th></tr>";n+=i,n+="</table><br/></div></body></html>";let r=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(r+"_disulfide_pairs.html","html",n)}exportClbondPairs(){var e=this.icn3d,t=e.icn3dui;let i="",s=0,n={};for(let t in e.structures){let r=e.clbondpnts[t];if(void 0===r)break;for(let t=0,a=r.length;t<a;t+=2){let a=r[t],o=r[t+1];if(!n.hasOwnProperty(a+"_"+o)){let t=e.firstAtomObjCls.getFirstAtomObj(e.residues[a]),n=e.firstAtomObjCls.getFirstAtomObj(e.residues[o]);i+="<tr><td>"+a+" "+t.resn+"</td><td>"+o+" "+n.resn+"</td></tr>",++s}n[a+"_"+o]=1,n[o+"_"+a]=1}}let r='<html><body><div style="text-align:center"><br><b>'+s+" cross-linkage pairs</b>:<br><br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Residue ID 1</th><th>Residue ID 2</th></tr>";r+=i,r+="</table><br/></div></body></html>";let a=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(a+"_crosslinkage_pairs.html","html",r)}exportHbondPairs(e,t){var i=this.icn3d,s=i.icn3dui;let n="",r=0,a=' <span style="background-color:#',o='"> </span>';for(let t in i.resid2ResidhashHbond){let s=i.getGraphCls.convertLabel2Resid(t),l=i.firstAtomObjCls.getFirstAtomObj(i.residues[s]),d=l.color?l.color.getHexString():"";for(let s in i.resid2ResidhashHbond[t]){let l=i.getGraphCls.convertLabel2Resid(s),c=i.firstAtomObjCls.getFirstAtomObj(i.residues[l]),h=c.color?c.color.getHexString():"",p=Math.sqrt(i.resid2ResidhashHbond[t][s]).toFixed(1);n+='<tr><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+"hbond_"+r+'a" resid="'+t+'"/> '+t+a+d+o+'</td><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+"hbond_"+r+'b" resid="'+s+'"/> '+s+a+h+o+'</td><td align="center">'+p+"</td>","view"==e&&(n+='<td align="center"><button class="'+i.pre+'selres" resid="'+t+"|"+s+'">Highlight</button></td>'),n+="</tr>",++r}}let l='<div style="text-align:center"><br><b>'+r+" hydrogen bond pairs</b> (backbone atoms: @CA, @N, @C, @O):</div><br>";if(r>0&&(l+="<br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Atom 1</th><th>Atom 2</th><th>Distance(Å)</th>","view"==e&&(l+='<th align="center">Highlight in 3D</th>'),l+="</tr>",l+=n,l+="</table><br/>"),"graph"==e||"linegraph"==e||"scatterplot"==e){return i.getGraphCls.getGraphLinks(i.resid2ResidhashHbond,i.resid2ResidhashHbond,s.htmlCls.hbondColor,t,s.htmlCls.hbondValue)}return l}exportSaltbridgePairs(e,t){var i=this.icn3d,s=i.icn3dui;let n="",r=0,a=' <span style="background-color:#',o='"> </span>';for(let t in i.resid2ResidhashSaltbridge){let s=i.getGraphCls.convertLabel2Resid(t),l=i.firstAtomObjCls.getFirstAtomObj(i.residues[s]),d=l.color?l.color.getHexString():"";for(let s in i.resid2ResidhashSaltbridge[t]){let l=i.getGraphCls.convertLabel2Resid(s),c=i.firstAtomObjCls.getFirstAtomObj(i.residues[l]),h=c.color?c.color.getHexString():"",p=Math.sqrt(i.resid2ResidhashSaltbridge[t][s]).toFixed(1);n+='<tr><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+"saltb_"+r+'a" resid="'+t+'"/> '+t+a+d+o+'</td><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+"saltb_"+r+'b" resid="'+s+'"/> '+s+a+h+o+'</td><td align="center">'+p+"</td>","view"==e&&(n+='<td align="center"><button class="'+i.pre+'selres" resid="'+t+"|"+s+'">Highlight</button></td>'),n+="</tr>",++r}}let l='<div style="text-align:center"><br><b>'+r+" salt bridge/ionic interaction pairs</b>:</div><br>";if(r>0&&(l+="<br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Atom 1</th><th>Atom 2</th><th>Distance(Å)</th>","view"==e&&(l+='<th align="center">Highlight in 3D</th>'),l+="</tr>",l+=n,l+="</table><br/>"),"graph"==e||"linegraph"==e||"scatterplot"==e){return i.getGraphCls.getGraphLinks(i.resid2ResidhashSaltbridge,i.resid2ResidhashSaltbridge,s.htmlCls.ionicColor,t,s.htmlCls.ionicValue)}return l}exportHalogenPiPairs(e,t,i){var s=this.icn3d,n=s.icn3dui;let r,a,o,l="",d=0,c=' <span style="background-color:#',h='"> </span>';"halogen"==i?(r=s.resid2ResidhashHalogen,a=n.htmlCls.halogenColor,o=n.htmlCls.halogenValue):"pi-cation"==i?(r=s.resid2ResidhashPication,a=n.htmlCls.picationColor,o=n.htmlCls.picationValue):"pi-stacking"==i&&(r=s.resid2ResidhashPistacking,a=n.htmlCls.pistackingColor,o=n.htmlCls.pistackingValue);for(let t in r){let n=s.getGraphCls.convertLabel2Resid(t),a=s.firstAtomObjCls.getFirstAtomObj(s.residues[n]),o=a.color?a.color.getHexString():"";for(let n in r[t]){let a=s.getGraphCls.convertLabel2Resid(n),p=s.firstAtomObjCls.getFirstAtomObj(s.residues[a]),u=p.color?p.color.getHexString():"",m=Math.sqrt(r[t][n]).toFixed(1);l+='<tr><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+i+"_"+d+'a" resid="'+t+'"/> '+t+c+o+h+'</td><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+i+"_"+d+'b" resid="'+n+'"/> '+n+c+u+h+'</td><td align="center">'+m+"</td>","view"==e&&(l+='<td align="center"><button class="'+s.pre+'selres" resid="'+t+"|"+n+'">Highlight</button></td>'),l+="</tr>",++d}}let p='<div style="text-align:center"><br><b>'+d+" "+i+" pairs</b>:</div><br>";if(d>0&&(p+="<br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Atom 1</th><th>Atom 2</th><th>Distance(Å)</th>","view"==e&&(p+='<th align="center">Highlight in 3D</th>'),p+="</tr>",p+=l,p+="</table><br/>"),"graph"==e||"linegraph"==e||"scatterplot"==e){return s.getGraphCls.getGraphLinks(r,r,a,t,o)}return p}exportSpherePairs(e,t,i){var s=this.icn3d,n=s.icn3dui;let r="",a=0,o=e?s.resid2ResidhashInteractions:s.resid2ResidhashSphere,l=' <span style="background-color:#',d='"> </span>';for(let i in o){let n=s.getGraphCls.convertLabel2Resid(i),c=s.firstAtomObjCls.getFirstAtomObj(s.residues[n]),h=c.color?c.color.getHexString():"";for(let n in o[i]){let p=s.getGraphCls.convertLabel2Resid(n),u=s.firstAtomObjCls.getFirstAtomObj(s.residues[p]),m=u.color?u.color.getHexString():"",f=o[i][n].split("_"),g=f[0],b=f[1];c=f[2],u=f[3];let C=f[4];e?(r+='<tr><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"inter_"+a+'a" resid="'+i+'"/> '+i+"@"+c+l+h+d+'</td><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"inter_"+a+'b" resid="'+n+'"/> '+n+"@"+u+l+m+d+'</td><td align="center">'+C+'</td><td align="center">'+g+'</td><td align="center">'+b+"</td>","view"==t&&(r+='<td align="center"><button class="'+s.pre+'selres" resid="'+i+"|"+n+'">Highlight</button></td>'),r+="</tr>"):r+="<tr><td>"+i+"</td><td>"+n+'</td><td align="center">'+C+'</td><td align="center">'+g+'</td><td align="center">'+b+"</td></tr>",++a}}let c='<div style="text-align:center"><br><b>'+a+" residue pairs in "+(e?"the contacts":"sphere")+"</b>:</div><br>";if(a>0&&(e?(c+='<br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Residue 1</th><th>Residue 2</th><th align="center">Num Contacts</th><th align="center">Min Distance(Å)</th><th align="center">C-alpha Distance(Å)</th>',"view"==t&&(c+='<th align="center">Highlight in 3D</th>'),c+="</tr>"):c+='<br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Residue 1</th><th>Residue 2</th><th align="center">Num Contacts</th><th align="center">Min Distance(Å)</th><th align="center">C-alpha Distance(Å)</th></tr>',c+=r,c+="</table><br/>"),"graph"==t||"linegraph"==t||"scatterplot"==t||"calpha"==t||"cbeta"==t||"heavyatoms"==t){return s.getGraphCls.getGraphLinks(o,o,n.htmlCls.contactColor,i,n.htmlCls.contactValue)}return c}}class Sh{constructor(e){this.icn3d=e}drawGraph(e,t){var i=this.icn3d,s=i.icn3dui;if(void 0===n)var n=d3;var r=JSON.parse(e),a=$("#"+t).width(),o=$("#"+t).height(),l=isNaN(a)?300:1*a,d=isNaN(o)?300:1*o,c=a,h=o,p=d3.select("#"+s.svgid).attr("width",a).attr("height",o).attr("viewBox","0,0,"+l+","+d);p.selectAll(".g-main").remove();var u=p.append("g").classed("g-main",!0),m=u.append("rect").attr("width",c).attr("height",h).style("fill","#FFF"),f=u.append("g"),g=n.zoom().on("zoom",(function(){f.attr("transform",n.event.transform)}));if(u.call(g),r.links){for(var b=[],C={},v=0,_=r.nodes.length;v<_;++v){C[(E=r.nodes[v]).id]=1}var y=!1;for(v=0,_=r.links.length;v<_;++v){var S=r.links[v];C.hasOwnProperty(S.source)&&C.hasOwnProperty(S.target)?b.push(S):(C.hasOwnProperty(S.source)||console.log("The node "+S.source+" is not found... "),C.hasOwnProperty(S.target)||console.log("The node "+S.target+" is not found... "),y=!0)}y&&console.log(JSON.stringify(r)),r.links=b;var w={};for(v=0;v<r.nodes.length;v++)s.htmlCls.force||(r.nodes[v].x*=10,r.nodes[v].y*=10),w[r.nodes[v].id]=r.nodes[v],r.nodes[v].weight=1.01;if(s.htmlCls.hideedges&&!s.htmlCls.force){var x=[];for(v=0;v<r.links.length;v++)"FFF"!=r.links[v].c&&x.push(r.links[v]);r.links=x}var A=f.append("g"),M=null,T=(S=f.append("g").attr("class","link").selectAll("line").data(r.links).enter().append("line").attr("stroke",(function(e){return e.v==s.htmlCls.contactInsideValue?"#"+s.htmlCls.contactInsideColor:e.v==s.htmlCls.hbondInsideValue?"#"+s.htmlCls.hbondInsideColor:e.v==s.htmlCls.ionicInsideValue?"#"+s.htmlCls.ionicInsideColor:e.v==s.htmlCls.halogenInsideValue?"#"+s.htmlCls.halogenInsideColor:e.v==s.htmlCls.picationInsideValue?"#"+s.htmlCls.picationInsideColor:e.v==s.htmlCls.pistackingInsideValue?"#"+s.htmlCls.pistackingInsideColor:"#"+e.c})).attr("stroke-width",(function(e){return e.v==s.htmlCls.contactValue||e.v==s.htmlCls.contactInsideValue||e.v==s.htmlCls.hbondInsideValue||e.v==s.htmlCls.ionicInsideValue||e.v==s.htmlCls.halogenInsideValue||e.v==s.htmlCls.picationInsideValue||e.v==s.htmlCls.pistackingInsideValue?"1px":e.v==s.htmlCls.hbondValue||e.v==s.htmlCls.ionicValue||e.v==s.htmlCls.halogenValue||e.v==s.htmlCls.picationValue||e.v==s.htmlCls.pistackingValue?"2px":e.v==s.htmlCls.ssbondValue||e.v==s.htmlCls.clbondValue?"3px":e.v+"px"})),f.append("g").attr("class","node")),E=T.selectAll("circle").data(r.nodes).enter().append("circle").attr("r",3).attr("fill",(function(e){return"#"+e.c})).attr("stroke",(function(e){return"#"+e.c})).attr("res",(function(e){return e.r})).attr("class","icn3d-node").call(n.drag().on("start",(function(e){n.event.active||s.htmlCls.simulation.alphaTarget(.9).restart();e.selected||H||E.classed("selected",(function(e){return e.selected=e.previouslySelected=!1}));n.select(this).classed("selected",(function(t){return e.previouslySelected=e.selected,e.selected=!0})),E.filter((function(e){return e.selected})).each((function(e){e.fx=e.x,e.fy=e.y}))})).on("drag",(function(e){E.filter((function(e){return e.selected})).each((function(e){e.fx+=n.event.dx,e.fy-=n.event.dy}))})).on("end",(function(e){n.event.active||s.htmlCls.simulation.alphaTarget(0);e.fx=null,e.fy=null,E.filter((function(e){return e.selected})).each((function(e){e.fx=null,e.fy=null}))}))),R=T.selectAll("text").data(r.nodes).enter().append("text").text((function(e){var t=e.id,i=t.indexOf(".");return-1!==i&&(t=t.substr(0,i)),t})).attr("fill",(function(e){return"#"+e.c})).attr("stroke","none").attr("class","icn3d-node-text8");E.append("title").text((function(e){return e.id}));var k=parseInt($("#"+i.pre+"dist_ss").val()),O=parseInt($("#"+i.pre+"dist_coil").val()),I=parseInt($("#"+i.pre+"dist_hbond").val()),P=parseInt($("#"+i.pre+"dist_inter").val()),D=parseInt($("#"+i.pre+"dist_ssbond").val()),L=parseInt($("#"+i.pre+"dist_ionic").val()),F=parseInt($("#"+i.pre+"dist_halogen").val()),N=parseInt($("#"+i.pre+"dist_pication").val()),U=parseInt($("#"+i.pre+"dist_pistacking").val());s.htmlCls.simulation=n.forceSimulation().force("link",n.forceLink().id((function(e){return e.id})).distance((function(e){return 30})).strength((function(e){return s.htmlCls.force?e.v==s.htmlCls.ssValue?isNaN(k)?1:k/100:e.v==s.htmlCls.coilValue||e.v==s.htmlCls.clbondValue?isNaN(O)?.5:O/100:e.v==s.htmlCls.hbondValue||e.v==s.htmlCls.hbondInsideValue?isNaN(I)?.5:I/100:e.v==s.htmlCls.contactValue||e.v==s.htmlCls.contactInsideValue?isNaN(P)?.25:P/100:e.v==s.htmlCls.ssbondValue?isNaN(D)?.5:D/100:e.v==s.htmlCls.ionicValue||e.v==s.htmlCls.ionicInsideValue?isNaN(L)?.5:L/100:e.v==s.htmlCls.halogenValue||e.v==s.htmlCls.halogenInsideValue?isNaN(F)?.5:F/100:e.v==s.htmlCls.picationValue||e.v==s.htmlCls.picationInsideValue?isNaN(N)?.5:N/100:e.v==s.htmlCls.pistackingValue||e.v==s.htmlCls.pistackingInsideValue?isNaN(U)?.5:U/100:0:0}))).force("center",n.forceCenter(c/2,h/2)),s.htmlCls.force&&s.htmlCls.simulation.force("charge",n.forceManyBody()),1==s.htmlCls.force?s.htmlCls.simulation.force("x",n.forceX((function(e){return"a"==e.s?c/4:.75*c})).strength((function(e){return.4}))).force("y",n.forceY(h/2).strength((function(e){return.02}))):2==s.htmlCls.force?s.htmlCls.simulation.force("y",n.forceY((function(e){return"a"==e.s?.75*h:h/4})).strength((function(e){return.4}))).force("x",n.forceX(c/2).strength((function(e){return.02}))):3==s.htmlCls.force?s.htmlCls.simulation.force("r",n.forceRadial((function(e){return"a"==e.s?200:100}),c/2,h/2).strength((function(e){return.8}))):s.htmlCls.force,s.htmlCls.simulation.nodes(r.nodes).on("tick",(function(){S.attr("x1",(function(e){var t=e.source.x;return isNaN(t)?0:t})).attr("y1",(function(e){var t=h-e.source.y;return isNaN(t)?0:t})).attr("x2",(function(e){var t=e.target.x;return isNaN(t)?0:t})).attr("y2",(function(e){var t=h-e.target.y;return isNaN(t)?0:t})),E.attr("cx",(function(e){var t=e.x;return isNaN(t)?0:t})).attr("cy",(function(e){var t=h-e.y;return isNaN(t)?0:t})),R.attr("x",(function(e){var t=e.x+6;return isNaN(t)?0:t})).attr("y",(function(e){var t=h-(e.y+3);return isNaN(t)?0:t}))})),s.htmlCls.simulation.force("link").links(r.links);var H,B=!1,z=!1,q=n.brush().on("start",(function(){z=!0,E.each((function(e){e.previouslySelected=H&&e.selected}))})).on("brush",(function(){if(!n.event.sourceEvent)return;if(!n.event.selection)return;var e=n.event.selection;E.classed("selected",(function(t){return t.selected=t.previouslySelected^(e[0][0]<=t.x&&t.x<e[1][0]&&e[0][1]<=h-t.y&&h-t.y<e[1][1])}))})).on("end",(function(){if(!n.event.sourceEvent)return;if(!n.event.selection)return;if(!M)return;M.call(q.move,null),B||(M.remove(),M=null);z=!1}));return m.on("click",(function(){E.each((function(e){e.selected=!1,e.previouslySelected=!1})),E.classed("selected",!1)})),n.select("body").on("keydown",(function(){if(H=n.event.ctrlKey){if(M)return;B=!0,M||(M=A.append("g")).call(q)}})),n.select("body").on("keyup",(function(){if(H=!1,B=!1,!M)return;z||(M.remove(),M=null)})),r}console.log("Graph is missing links")}}class wh{constructor(e){this.icn3d=e}async contactMap(e,t){let i=this.icn3d;i.icn3dui;let s=["selected"],n=["selected"];if(0==n.length)alert("Please select the first set");else{i.definedSetsCls.setMode("selection");let r=!1,a=!1,o=!0,l=!1,d=!1,c=!1;await i.viewInterPairsCls.viewInteractionPairs(n,s,!1,t,r,a,o,l,d,c,e)}}async afErrorMap(e,t){let i=this.icn3d,s=i.icn3dui;s.htmlCls.dialogCls.openDlg("dl_alignerrormap","Show Predicted Aligned Error (PAE) map");let n="https://alphafold.ebi.ac.uk/files/AF-"+e+"-F1-predicted_aligned_error_"+i.AFUniprotVersion+".json",r=await s.getAjaxPromise(n,"json",!1,"There are some problems in loading the PAE file...");this.processAfErrorMap(r,t)}processAfErrorMap(e,t){let i=this.icn3d,s=i.icn3dui,n=e[0]?e[0]:e,r=n.predicted_aligned_error||n.pae,a=n.max_predicted_aligned_error||n.max_pae;if(!r||!a)return void alert("The PAE file didn't have the right format...");let o,l='"nodes": [',d='"links": [',c=!1,h=!1;i.chains&&0!=Object.keys(i.chains).length?o=!0:(o=!1,i.init_base());let p=r.length,u=0,m={};for(let e in i.chains)for(let t=0,s=i.chainsSeq[e].length;t<s;++t)m[u]=i.chainsSeq[e][t],m[u].chainid=e,++u;u=0;for(let e=0;e<p;++e){let n=o?m[e].resi:e+1,f=o?m[e].name:"*",g=o?m[e].chainid:"stru_A",b=g+"_"+n,C=i.residues[b]?i.firstAtomObjCls.getFirstAtomObj(i.residues[b]):{color:s.parasCls.thr(8947848)},v=g.substr(g.indexOf("_")+1),_=C.color.getHexString();c&&(l+=", ");let y=f+n+"."+v;l+='{"id":"'+y+'","r":"1_1_'+b+'","s":"a","c":"'+_+'"}\n',l+=', {"id":"'+y+'.","r":"1_1_'+b+'","s":"b","c":"'+_+'"}',c=!0;for(let i=t?0:e;i<p;++i){u=e*p+i;let t=o?m[i].resi:i+1,s=o?m[i].name:"*",n=o?m[i].chainid:"stru_A",l=s+t+"."+n.substr(n.indexOf("_")+1),c=r[e][i]?r[e][i]/a:0,f=parseInt(255*c).toString(16),g=parseInt(255*(.698*c+.302)).toString(16),b=1==f.length?"0"+f:f;h&&(d+=", "),d+='{"source": "'+y+'", "target": "'+l+'.", "v": 11, "c": "'+(b+(1==g.length?"0"+g:g)+b)+'", "pae": '+parseInt(r[e][i])+"}\n",h=!0}}e={};let f="{"+l+"], "+d+"]}";this.drawContactMap(f,!0,a)}drawContactMap(e,t,i){let s,n=this.icn3d,r=n.icn3dui,a=JSON.parse(e),o=a.links,l=[],d=[],c={};for(let e=0,t=a.nodes.length;e<t;++e){let t=a.nodes[e];t&&(c[t.id]=t,"a"==t.s?l.push(t):"b"==t.s?d.push(t):"ab"==t.s&&(l.push(t),d.push(t)))}l.sort((function(e,t){return n.getGraphCls.compNode(e,t)})),d.sort((function(e,t){return n.getGraphCls.compNode(e,t)}));let h,p,u,m,f="{\n",g=Object.keys(n.structures).length>0?n.structures[0]:n.defaultPdbId;p=10*(l.length+2)+20+30,h=10*(d.length+2)+20+30,t?(n.alignerrormapWidth=2*h,m=n.alignerrormapWidth,u=r.alignerrormapid):(n.contactmapWidth=2*h,m=n.contactmapWidth,u=r.contactmapid),s=o.length>0?"":"No interactions found for these two sets<br><br>",s+="<svg xmlns='http://www.w3.org/2000/svg' id='"+u+"' viewBox='0,0,"+h+","+p+"' width='"+m+"px'>";if(t){n.hex2id={};let e=29/i;n.hex2skip={};let t=1e3;for(let i=0;i<t;++i){let s=1*i/t,a=parseInt(255*s).toString(16),o=parseInt(255*(.698*s+.302)).toString(16),l=1==a.length?"0"+a:a,d=l+(1==o.length?"0"+o:o)+l,c=r.pre+"afmap_"+i;n.hex2id[d]=c,s>e&&(n.hex2skip[d]=c)}}if(s+=n.lineGraphCls.drawScatterplot_base(l,d,o,c,0,!0,void 0,void 0,t),f+=n.getGraphCls.updateGraphJson(g,1,l,d,o),s+="</svg>",f+="}\n",t){n.alignerrormapStr=f,$("#"+n.pre+"alignerrormapDiv").html(s);let e=$("#"+r.alignerrormapid+"_scale").val();$("#"+r.alignerrormapid).attr("width",(n.alignerrormapWidth*parseFloat(e)).toString()+"px")}else n.contactmapStr=f,$("#"+n.pre+"contactmapDiv").html(s);return s}}class xh{constructor(e){this.icn3d=e}async downloadAlignment(e,t){let i=this.icn3d,s=i.icn3dui,n=this;i.opts.proteins="c alpha trace";let r=e.split(","),a="ids="+e,o=s.htmlCls.baseUrl+"vastplus/vastplus.cgi?v=3&cmd=c&b=1&s=1&w3d&"+a;void 0!==s.cfg.inpara&&(o+=s.cfg.inpara),i.pdbid_chain2title={},void 0===i.chainids2resids&&(i.chainids2resids={});let l={},d="These two MMDB IDs "+r+' do not have 3D alignment data in the VAST+ database. You can try the VAST alignment by visiting the VAST+ page https://www.ncbi.nlm.nih.gov/Structure/vastplus/vastplus.cgi?uid=[PDB ID] (e.g., uid=1KQ2), and clicking "Original VAST"',c=await s.getAjaxPromise(o,"jsonp",!0,d);if(l=c.seqalign,void 0===l)return alert(d),!1;i.pdbid_molid2chain={},i.chainsColor={};for(let e=0,t=2;e<t;++e){let t=c.alignedStructures[0][e],n=void 0!==t.pdbId?t.pdbId:t.mmdbId,r={};for(let e=0,a=t.molecules.length;e<a;++e){let a=t.molecules[e],o=a.moleculeId,l=a.chain.trim().replace(/_/g,"");void 0===r[l]?r[l]=1:++r[l];let d=1===r[l]?l:l+r[l].toString();i.pdbid_molid2chain[n+"_"+o]=d,"p"!==a.kind&&"n"!==a.kind||(i.chainsColor[n+"_"+d]=s.parasCls.thr(s.htmlCls.GREY8))}}i.mmdbidArray=[];for(let e=0,t=2;e<t;++e){let t=c.alignedStructures[0][e],s=t.pdbId;i.mmdbidArray.push(s);let n=t.molecules;for(let e in n){let t=n[e].chain;i.pdbid_chain2title[s+"_"+t]=n[e].name}}i.alignmolid2color=[],s.parasCls.stdChainColors.length;for(let e=0,t=l.length;e<t;++e){let t=l[e][0].moleculeId,s=l[e][1].moleculeId,n={};n[t]=(e+1).toString(),i.alignmolid2color.push(n),n={},n[s]=(e+1).toString(),i.alignmolid2color.push(n)}if(!t){let e=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+s.cfg.bu+"&uid="+i.mmdbidArray[0],t=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+s.cfg.bu+"&uid="+i.mmdbidArray[1],r=s.getAjaxPromise(e,"jsonp",!0),a=s.getAjaxPromise(t,"jsonp",!0),o=Promise.allSettled([r,a]),d=await o,h=c,p=d[0].value,u=d[1].value;if(void 0===p.atoms||void 0===u.atoms)return alert("invalid atoms data."),!1;{i.ParserUtilsCls.setYourNote((i.mmdbidArray[0]+","+i.mmdbidArray[1]).toUpperCase()+"(VAST+) in iCn3D");let e=1,t=h.transform.translate.master,s=new mt(t[0]/e,t[1]/e,t[2]/e),r=h.transform.translate.slave,a=new mt(r[0]/e,r[1]/e,r[2]/e),o=h.transform.rotate,d=[];for(let t=0,i=o.length;t<i;++t)d.push(o[t]/e);i.chainid2seq={};for(let e in p.sequences){let t=i.mmdbidArray[0]+"_"+e;i.chainid2seq[t]=p.sequences[e]}for(let e in u.sequences){let t=i.mmdbidArray[1]+"_"+e;i.chainid2seq[t]=u.sequences[e]}let c=p.atoms,m=u.atoms,f=p.atomCount,g=u.atomCount;for(let e=0,t=h.alignedStructures[0].length;e<t;++e){let t=h.alignedStructures[0][e];t.serialInterval=[],0==e?(t.serialInterval.push(1),t.serialInterval.push(f)):1==e&&(t.serialInterval.push(f+1),t.serialInterval.push(f+g))}let b={};for(let e in c){let t=c[e];t.coord=new mt(t.coord[0],t.coord[1],t.coord[2]),t.coord.add(s);let i=t.coord.x*d[0]+t.coord.y*d[1]+t.coord.z*d[2],n=t.coord.x*d[3]+t.coord.y*d[4]+t.coord.z*d[5],r=t.coord.x*d[6]+t.coord.y*d[7]+t.coord.z*d[8];t.coord.x=i,t.coord.y=n,t.coord.z=r,b[e]=t}for(let e in m){let t=m[e];t.coord=new mt(t.coord[0],t.coord[1],t.coord[2]),t.coord.add(a);for(let e=0,i=t.bonds.length;e<i;++e)t.bonds[e]+=f;b[(parseInt(e)+f).toString()]=t}let C={};C.alignedStructures=h.alignedStructures,C.alignment=h.alignment,C.atoms=b,await n.loadOpmDataForAlign(C,l,i.mmdbidArray)}}}async downloadAlignmentPart2(e,t,i){let s=this.icn3d,n=s.icn3dui;s.loadAtomDataCls.loadAtomDataIn(e,void 0,"align",t),void 0===n.cfg.align&&1==Object.keys(s.structures).length&&$("#"+s.pre+"alternateWrapper").hide();let r={};for(let e in s.atoms)r[e]=1;s.dAtoms=r,s.hAtoms=r,s.setStyleCls.setAtomStyleByOptions(s.opts),s.setColorCls.setColorByOptions(s.opts,s.atoms),void 0!==i&&s.ParserUtilsCls.transformToOpmOriForAlign(s.selectedPdbid,i,!0),await s.ParserUtilsCls.renderStructure(),void 0!==n.cfg.rotate&&s.resizeCanvasCls.rotStruc(n.cfg.rotate,!0),s.html2ddgm="",n.cfg.showalignseq&&n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),n.cfg.show2d&&s.bFullUi&&await s.ParserUtilsCls.set2DDiagramsForAlign(s.mmdbidArray[0].toUpperCase(),s.mmdbidArray[1].toUpperCase())}async loadOpmDataForAlign(e,t,i){let s=this.icn3d,n=s.icn3dui,r=this;try{let a="https://opm-assets.storage.googleapis.com/pdb/"+i[0].toLowerCase()+".pdb",o=n.getAjaxPromise(a,"text"),l="https://opm-assets.storage.googleapis.com/pdb/"+i[1].toLowerCase()+".pdb",d=n.getAjaxPromise(l,"text"),c=Promise.allSettled([o,d]),h=await c,p=!1;for(let n=0,a=h.length;n<a;++n){let a=h[n].value;if(!a)continue;s.selectedPdbid=i[n],s.bOpm=!0;let o=!0,l=s.loadPDBCls.loadPDB(a,i[n],s.bOpm,o);$("#"+s.pre+"selectplane_z1").val(s.halfBilayerSize),$("#"+s.pre+"selectplane_z2").val(-s.halfBilayerSize),$("#"+s.pre+"extra_mem_z").val(s.halfBilayerSize),$("#"+s.pre+"intra_mem_z").val(-s.halfBilayerSize),s.init(),await r.downloadAlignmentPart2(e,t,l),p=!0;break}p||(s.init(),await r.downloadAlignmentPart2(e,t))}catch(i){return s.init(),void await r.downloadAlignmentPart2(e,t)}}}class Ah{constructor(e){this.icn3d=e}async downloadChainalignmentPart2(e,t,i,s){let n,r,a=this.icn3d,o=a.icn3dui,l=this,d={},c={};n=s[0].substr(0,s[0].indexOf("_"));let h=!1;if(n.length>5){let t=!1,i=!0;d=await a.pdbParserCls.loadPdbData(e,n,!1,t,"target",h,i)}else{let t=!0;d=await a.mmdbParserCls.parseMmdbData(e,"target",s[0],0,h,t)}for(let e=0,i=t.length;e<i;++e){if(e==t.length-1&&(h=!0),r=s[e+1].substr(0,s[e+1].indexOf("_")),r.length>5){let i=!0,s=!0;c=await a.pdbParserCls.loadPdbData(t[e],r,!1,i,"query",h,s)}else{let i=!0;c=await a.mmdbParserCls.parseMmdbData(t[e],"query",s[e+1],e,h,i)}d=o.hashUtilsCls.unionHash(d,c)}if(o.cfg.resnum)await a.realignParserCls.realignChainOnSeqAlign(i,s);else if(o.cfg.resdef)await a.realignParserCls.realignChainOnSeqAlign(i,s,void 0,!0);else{await a.pdbParserCls.applyCommandDssp(!0);
|
|
16
16
|
//!!!
|
|
17
17
|
let e=[],t=[],c=[],h=o.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",p=o.htmlCls.baseUrl+"tmalign/tmalign.cgi",u=o.cfg.resrange?decodeURIComponent(o.cfg.resrange).split(" | "):[],m=o.cfg.resrange?a.realignParserCls.getSeqCoorResid([u[0]],s[0],!0).hAtoms:a.chains[s[0]];for(let i=1,n=s.length;i<n;++i){let n,l=o.cfg.resrange?a.realignParserCls.getSeqCoorResid([u[i]],s[i],!0).hAtoms:a.chains[s[i]];if("tmalign"!=o.cfg.aligntool){let e={domains1:a.domain3dCls.getDomainJsonForAlign(l),domains2:a.domain3dCls.getDomainJsonForAlign(m)};n=o.getAjaxPostPromise(h,e)}else{let e={pdb_query:a.saveFileCls.getAtomPDB(l),pdb_target:a.saveFileCls.getAtomPDB(m)};n=o.getAjaxPostPromise(p,e)}e.push(n),t.push(i-1),r=s[i].substr(0,s[i].indexOf("_")),c.push(r)}let f=Promise.allSettled(e),g=await f;await l.downloadChainalignmentPart2b(i,s,d,g,t,n,c)}}async downloadChainalignmentPart2b(e,t,i,s,n,r,a){let o=this.icn3d,l=o.icn3dui;for(let e=0,t=s.length;e<t;++e){let t=s[e].value,i=a[e],o=n[e],d=i.substr(0,4)==r.substr(0,4),c=!1,h={};l.htmlCls.clickMenuCls.setLogCmd("Align "+r+" with "+i,!1),this.processAlign(t,o,h,d,c)}for(let e=0,t=s.length;e<t;++e){let t=a[e],i=n[e];this.transformStructure(t,i,"query")}let d={};!o.bFullUi||void 0===o.q_rotation||l.cfg.resnum||l.cfg.resdef||(d=this.setMsa(t)),o.hAtoms=l.hashUtilsCls.cloneHash(d),o.transformCls.zoominSelection(),await this.downloadChainalignmentPart3(e,t,o.hAtoms)}setMsa(e,t,i){let s=this.icn3d,n=s.icn3dui,r=[];for(let t=1,i=e.length;t<i;++t){let e=0;if(s.qt_start_end&&s.qt_start_end[t-1])for(let i=0,n=s.qt_start_end[t-1].length;i<n;++i)e+=parseInt(s.qt_start_end[t-1][i].q_end)-parseInt(s.qt_start_end[t-1][i].q_start)+1;r.push({index:t,alignLen:e})}r.sort((function(e,t){return t.alignLen-e.alignLen}));let a=s.setSeqAlignCls.setSeqAlignChainForAll(e,r,i);t&&(s.opts.color="identity",s.setColorCls.setColorByOptions(s.opts,a));let o=n.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(s.alnChains),void 0,void 0,!1,void 0,!1),l=$("#"+s.pre+"dl_sequence2").html();return $("#"+s.pre+"dl_sequence2").html(l+o.sequencesHtml),$("#"+s.pre+"dl_sequence2").width(n.htmlCls.RESIDUE_WIDTH*o.maxSeqCnt+200),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),a}async downloadChainalignmentPart2bRealign(e,t,i){let s=this.icn3d,n=s.icn3dui;s.t_trans_add=[],s.q_trans_sub=[],"tmalign"==n.cfg.aligntool&&(s.q_trans_add=[]),s.q_rotation=[],s.qt_start_end=[];let r={},a={},o=!1;for(let i=0,s=e.length;i<s;++i){let s=e[i].value,l=!1,d=!1,c={},h=t[i].split(","),p=h[0].substr(0,h[0].indexOf("_")),u=h[1].substr(0,h[1].indexOf("_"));if(a.hasOwnProperty(p+"_"+u))continue;n.htmlCls.clickMenuCls.setLogCmd("Align "+p+" with "+u,!1);let m=!0;this.processAlign(s,i,c,l,d,m)&&(o=!0,r[p]=void 0===r[p]?1:++r[p],r[u]=void 0===r[u]?1:++r[u],a[p+"_"+u]=h+","+i)}if(!o){if(i)return"tmalign"==n.cfg.aligntool?void(s.bRender&&alert("These structures can NOT be aligned...")):(console.log("These structures can NOT be aligned with VAST. Realign the chains with TM-align."),n.cfg.aligntool="tmalign",void await s.realignParserCls.realignOnStructAlign());{let e=!0;return void s.realignParserCls.realignOnStructAlign(!0,e)}}let l,d,c=0;for(let e in a){let t=e.split("_");r[t[0]]>c&&(c=r[t[0]],l=t[0]),r[t[1]]>c&&(c=r[t[1]],l=t[1])}let h={},p={},u={},m={};for(let e in a){let t,i,s=e.split("_"),n=a[e].split(","),r=n[2];if(l==s[0]?(t=s[0],i=s[1]):l==s[1]?(t=s[1],i=s[0]):(t=s[0],i=s[1]),u[t]=1,u.hasOwnProperty(i))continue;u[i]=1,m[e]=a[e],d="target";let o=!0;this.transformStructure(t,r,d,o),d="query",this.transformStructure(i,r,d,o),h[n[0]]=1,h[n[1]]=1}for(let e in m)if(void 0!==s.q_rotation){let t=m[e].split(","),i=[t[1],t[0],t[2]],r=s.setSeqAlignCls.setSeqAlignChain(void 0,void 0,i);p=n.hashUtilsCls.unionHash(p,r);let a=!1,o=n.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(s.alnChains),void 0,void 0,!1,void 0,a),l=$("#"+s.pre+"dl_sequence2").html();$("#"+s.pre+"dl_sequence2").html(l+o.sequencesHtml),$("#"+s.pre+"dl_sequence2").width(n.htmlCls.RESIDUE_WIDTH*o.maxSeqCnt+200)}s.dAtoms=n.hashUtilsCls.cloneHash(p),s.hAtoms=n.hashUtilsCls.cloneHash(p);let f="protein_aligned";s.selectionCls.saveSelection(f,f),s.opts.color="identity",s.setColorCls.setColorByOptions(s.opts,s.hAtoms),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),s.drawCls.draw(),s.transformCls.zoominSelection(),s.hlUpdateCls.updateHlAll()}transformStructure(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=n.structures[e];for(let e=0,o=a.length;e<o;++e)for(let o in n.chains[a[e]]){let e=n.atoms[o];void 0===n.q_rotation||!s&&(r.cfg.resnum||r.cfg.resdef)||(e=this.transformAtom(e,t,i))}}transformAtom(e,t,i){let s=this.icn3d,n=s.icn3dui;if("target"===i);else if("query"===i){"tmalign"!=n.cfg.aligntool&&(e.coord.x-=s.q_trans_sub[t].x,e.coord.y-=s.q_trans_sub[t].y,e.coord.z-=s.q_trans_sub[t].z);let i=e.coord.x*s.q_rotation[t].x1+e.coord.y*s.q_rotation[t].y1+e.coord.z*s.q_rotation[t].z1,r=e.coord.x*s.q_rotation[t].x2+e.coord.y*s.q_rotation[t].y2+e.coord.z*s.q_rotation[t].z2,a=e.coord.x*s.q_rotation[t].x3+e.coord.y*s.q_rotation[t].y3+e.coord.z*s.q_rotation[t].z3;"tmalign"!=n.cfg.aligntool?(i-=s.t_trans_add[t].x,r-=s.t_trans_add[t].y,a-=s.t_trans_add[t].z):(i+=s.q_trans_add[t].x,r+=s.q_trans_add[t].y,a+=s.q_trans_add[t].z),e.coord.x=i,e.coord.y=r,e.coord.z=a}return e}async downloadChainalignmentPart3(e,t,i){let s=this.icn3d,n=s.icn3dui,r={};for(let e in s.atoms)r[e]=1;if(s.dAtoms=r,s.hAtoms=r,s.setStyleCls.setAtomStyleByOptions(s.opts),s.opts.color="identity",s.setColorCls.setColorByOptions(s.opts,s.atoms),void 0!==e&&s.ParserUtilsCls.transformToOpmOriForAlign(s.selectedPdbid,e,!0),s.hAtoms=n.hashUtilsCls.cloneHash(i),s.dAtoms=n.hashUtilsCls.cloneHash(i),await s.ParserUtilsCls.renderStructure(),t.length>2){let e=s.firstAtomObjCls.getResiduesFromAtoms(i),t="protein_aligned",n="protein aligned",r="select "+s.resid2specCls.residueids2spec(Object.keys(e));s.selectionCls.addCustomSelection(Object.keys(e),t,n,r,!0)}s.hlUpdateCls.updateHlAll(),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),void 0!==n.cfg.rotate&&s.resizeCanvasCls.rotStruc(n.cfg.rotate,!0),s.html2ddgm="",n.cfg.show2d&&s.bFullUi&&(n.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),s.bFullUi&&(s.bChainAlign?await s.ParserUtilsCls.set2DDiagramsForChainalign(t):s.ParserUtilsCls.download2Ddgm(s.inputid.toUpperCase())))}addPostfixForChainids(e){this.icn3d.icn3dui;let t={};for(let i=0,s=e.length;i<s;++i){let s=e[i],n=s.indexOf("_"),r=s.substr(0,n);t.hasOwnProperty(r)?++t[r]:t[r]=1,r=1==t[r]?r:r+t[r],e[i]=r+s.substr(n)}return e}addPostfixForStructureids(e){this.icn3d.icn3dui;let t={};for(let i=0,s=e.length;i<s;++i){let s=e[i].toUpperCase();t.hasOwnProperty(s)?++t[s]:t[s]=1,s=1==t[s]?s:s+t[s],e[i]=s}return e}async downloadChainalignment(e){let t=this.icn3d,i=t.icn3dui;t.opts.proteins="c alpha trace";let s=e.split(","),n=i.cfg.domainids?i.cfg.domainids.split(","):[];n.length<s.length&&(n=[]),t.chainidArray=this.addPostfixForChainids(s);let r=s[0].indexOf("_");t.mmdbid_t=s[0].substr(0,r).toUpperCase(),t.chain_t=s[0].substr(r+1);let a,o,l=[];t.mmdbid_t.length>5?(o="https://alphafold.ebi.ac.uk/files/AF-"+t.mmdbid_t+"-F1-model_"+t.AFUniprotVersion+".pdb",a=i.getAjaxPromise(o,"text")):(o=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+i.cfg.bu+"&uid="+t.mmdbid_t,void 0!==i.cfg.inpara&&(o+=i.cfg.inpara),a=i.getAjaxPromise(o,"jsonp")),l.push(a),t.ParserUtilsCls.setYourNote(e.toUpperCase()+" in iCn3D"),t.pdbid_chain2title={},void 0===t.chainids2resids&&(t.chainids2resids={}),t.afChainIndexHash={},t.pdbChainIndexHash={};for(let e=1,n=s.length;e<n;++e){let n,r,a=s[e].indexOf("_"),o=s[e].substr(0,a).toUpperCase();t.mmdbid_q=5==o.length?o.substr(0,4):o,t.chain_q=s[e].substr(a+1),t.mmdbid_q.length>5?(n="https://alphafold.ebi.ac.uk/files/AF-"+t.mmdbid_q+"-F1-model_"+t.AFUniprotVersion+".pdb",r=i.getAjaxPromise(n,"text")):(n=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+i.cfg.bu+"&uid="+t.mmdbid_q,void 0!==i.cfg.inpara&&(n+=i.cfg.inpara),r=i.getAjaxPromise(n,"jsonp")),l.push(r)}for(let e=1,r=s.length;e<r;++e){let r=s[e].indexOf("_"),a=s[e].substr(0,r).toUpperCase();if(t.mmdbid_q=5==a.length?a.substr(0,4):a,t.chain_q=s[e].substr(r+1),!i.cfg.resnum&&!i.cfg.resdef){let s=t.mmdbid_q+"_"+t.chain_q+","+t.mmdbid_t+"_"+t.chain_t,r=n.length>0?n[e]+","+n[0]:void 0;if("tmalign"!=i.cfg.aligntool&&4==t.mmdbid_t.length&&4==t.mmdbid_q.length){let o;o=n.length>0?i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?domainpairs="+r:i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?chainpairs="+s;let d=i.getAjaxPromise(o,"jsonp");l.push(d),t.pdbChainIndexHash[e]=a+"_"+t.chain_q+"_"+t.mmdbid_t+"_"+t.chain_t}else t.afChainIndexHash[e]=t.mmdbid_q+"_"+t.chain_q+"_"+t.mmdbid_t+"_"+t.chain_t}}let d=Promise.allSettled(l),c=await d;await this.parseChainAlignData(c,s,t.mmdbid_t,t.chain_t)}async parseChainAlignData(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=e[0].value,o="HEADER "+i+"\n";isNaN(i)&&i.length>5&&(a=o+a),n.t_trans_add=[],n.q_trans_sub=[],"tmalign"==r.cfg.aligntool&&(n.q_trans_add=[]),n.q_rotation=[],n.qt_start_end=[],n.mmdbidArray=[],n.mmdbidArray.push(i);let l=[];for(let i=1,s=t.length;i<s;++i){let s=e[i].value,r=t[i].indexOf("_"),a=t[i].substr(0,r).toUpperCase(),o="HEADER "+a+"\n";if(isNaN(a)&&a.length>5&&(s=o+s),void 0===s||-1!==JSON.stringify(s).indexOf("Oops there was a problem"))return void alert("The coordinate data can NOT be retrieved for the structure "+a+"...");n.mmdbidArray.push(a.substr(0,4)),l.push(s)}let d=0;for(let a=1,o=t.length;a<o;++a){let o=l[a-1],c=t[a].indexOf("_"),h=t[a].substr(0,c).toUpperCase(),p=t[a].substr(c+1);if(!r.cfg.resnum&&!r.cfg.resdef){let l=t.length+a-1;if(n.afChainIndexHash.hasOwnProperty(a))++d,"tmalign"==r.cfg.aligntool?n.q_trans_add[a-1]={x:0,y:0,z:0}:(n.t_trans_add[a-1]={x:0,y:0,z:0},n.q_trans_sub[a-1]={x:0,y:0,z:0}),n.q_rotation[a-1]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},n.qt_start_end[a-1]=void 0;else{let t=e[l-d].value,n=h.substr(0,4)==i.substr(0,4),c=p==s;r.htmlCls.clickMenuCls.setLogCmd("Align "+i+" with "+h,!1),this.processAlign(t,a-1,o,n,c)}}}n.mmdb_data_q=l,await this.loadOpmDataForChainalign(a,l,t,n.mmdbidArray)}processAlign(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui,l=!1;if(!(e&&0!=e.length||r)){let e="tmalign"==o.cfg.aligntool?"TM-align":"VAST";return a.bRender&&alert("These chains can not be aligned by "+e+"."),l}if(void 0!==i&&-1===JSON.stringify(i).indexOf("Oops there was a problem")&&void 0!==e&&-1===JSON.stringify(e).indexOf("Oops there was a problem"))if(("error"===e||void 0===e||0==e.length)&&s&&n)a.t_trans_add[t]={x:0,y:0,z:0},a.q_trans_sub[t]={x:0,y:0,z:0},a.q_rotation[t]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},a.qt_start_end[t]=void 0;else if("error"===e||void 0===e||0==e.length)o.cfg.command||r||alert('These two chains can not align to each other. Please select sequences from these two chains in the "Sequences & Annotations" window, and click "Realign Selection" in the "File" menu to align your selection.'),a.t_trans_add[t]={x:0,y:0,z:0},a.q_trans_sub[t]={x:0,y:0,z:0},a.q_rotation[t]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},a.qt_start_end[t]=void 0,o.cfg.showanno=1,o.cfg.showalignseq=0;else{"tmalign"==o.cfg.aligntool?a.q_trans_add[t]=e[0].q_trans_add:(a.t_trans_add[t]=e[0].t_trans_add,a.q_trans_sub[t]=e[0].q_trans_sub),a.q_rotation[t]=e[0].q_rotation,a.qt_start_end[t]=e[0].segs;let i=e[0].super_rmsd,s=i?i.toPrecision(4):i,n=e[0].score?e[0].score.toPrecision(4):e[0].score,r="alignment RMSD: "+s;"tmalign"==o.cfg.aligntool&&(r+="; TM-score: "+n),o.htmlCls.clickMenuCls.setLogCmd(r,!1);let d="<br><b>Alignment RMSD</b>: "+s+" Å<br>";"tmalign"==o.cfg.aligntool&&(d+="<b>TM-score</b>: "+n+"<br><br>",a.tmscore=n),$("#"+a.pre+"dl_rmsd_html").html(d),o.cfg.bSidebyside||o.htmlCls.dialogCls.openDlg("dl_rmsd","RMSD of alignment"),l=!0}return l}async loadOpmDataForChainalign(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=this;if(r.cfg.resnum||r.cfg.resdef||r.cfg.resrange)n.bCommandLoad||n.init(),await this.downloadChainalignmentPart2(e,t,void 0,i);else{let o=r.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?mmdbids2opm="+s.join("','"),l=await r.getAjaxPromise(o,"jsonp");if(l&&l.mmdbid){let s=l.mmdbid;n.selectedPdbid=s;let o="https://opm-assets.storage.googleapis.com/pdb/"+s.toLowerCase()+".pdb",d=await r.getAjaxPromise(o,"text");n.bOpm=!0;let c=!0,h=n.loadPDBCls.loadPDB(d,s,n.bOpm,c);$("#"+n.pre+"selectplane_z1").val(n.halfBilayerSize),$("#"+n.pre+"selectplane_z2").val(-n.halfBilayerSize),$("#"+n.pre+"extra_mem_z").val(n.halfBilayerSize),$("#"+n.pre+"intra_mem_z").val(-n.halfBilayerSize),n.bCommandLoad||n.init(),await a.downloadChainalignmentPart2(e,t,h,i)}else n.bCommandLoad||n.init(),await a.downloadChainalignmentPart2(e,t,void 0,i)}}async downloadMmdbAf(e,t,i,s){let n=this.icn3d,r=n.icn3dui;n.structArray=n.structures?Object.keys(n.structures):[],0==n.structArray.length?n.init():(n.bResetAnno=!0,n.bResetSets=!0);let a=e.split(","),o=[];if(s)for(let e=0,t=a.length;e<t;++e){let t=a[e].toUpperCase();n.structures.hasOwnProperty(t)||o.push(a[e])}else o=this.addPostfixForStructureids(a);if(0==o.length)return;n.structArray=n.structArray.concat(o);let l=[];for(let e=0,t=o.length;e<t;++e){let t,i,s=o[e];if(isNaN(s)&&s.length>5)t="https://alphafold.ebi.ac.uk/files/AF-"+s+"-F1-model_"+n.AFUniprotVersion+".pdb",i=r.getAjaxPromise(t,"text");else{let e=s;5==s.length&&(e=s.substr(0,4)),t=r.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+r.cfg.bu+"&uid="+e,void 0!==r.cfg.inpara&&(t+=r.cfg.inpara),i=r.getAjaxPromise(t,"jsonp")}l.push(i)}n.ParserUtilsCls.setYourNote(n.structArray+" in iCn3D"),n.ParserUtilsCls.showLoading();let d=Promise.allSettled(l),c=await d;await this.parseMMdbAfData(c,o,t,i),void 0===i&&n.ParserUtilsCls.hideLoading()}async parseMMdbAfData(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=[];for(let i=0,s=t.length;i<s;++i){let s=e[i].value,n="HEADER "+t[i]+"\n";if(isNaN(t[i])&&t[i].length>5&&(s=n+s),void 0===s||-1!==JSON.stringify(s).indexOf("Oops there was a problem"))return void alert("The coordinate data can NOT be retrieved for the structure "+t[i]+"...");a.push(s)}let o=!1;for(let e=0,s=t.length;e<s;++e){let s,r;if(e==t.length-1&&(o=!0),0!=e||i||n.structArray.length!=t.length?(s="query",r=!0):(s="target",r=!1),isNaN(t[e])&&t[e].length>5){let i=!1;await n.pdbParserCls.loadPdbData(a[e],t[e],!1,r,s,o,i)}else{let i=!0,r=t[e];await n.mmdbParserCls.parseMmdbData(a[e],s,void 0,void 0,o,i,r)}}let l=Object.keys(n.structures);if(n.opts.color=l.length>1?"structure":l[0].length>5?"confidence":"chain",n.setColorCls.setColorByOptions(n.opts,{}),await n.ParserUtilsCls.renderStructure(),n.bAnnoShown&&(await n.showAnnoCls.showAnnotations(),n.annotationCls.resetAnnoTabAll()),void 0!==r.cfg.rotate&&n.resizeCanvasCls.rotStruc(r.cfg.rotate,!0),i&&r.cfg.matchedchains){n.hAtoms=n.definedSetsCls.getAtomsFromNameArray(n.chainidArray);let e=!0;await n.realignParserCls.realignOnStructAlign(void 0,e),$("#"+n.pre+"dl_annotations").html(""),n.bAnnoShown=!1,$("#"+r.pre+"dl_selectannotations").hasClass("ui-dialog-content")&&$("#"+n.pre+"dl_selectannotations").dialog("isOpen")&&$("#"+n.pre+"dl_selectannotations").dialog("close")}else if(void 0!==s){let e=Object.keys(n.structures);2==s&&(r.cfg.aligntool="tmalign"),await n.vastplusCls.vastplusAlign(e,s)}}}class Mh{constructor(e){this.icn3d=e}async dsn6Parser(e,t,i){this.icn3d.icn3dui;let s="https://edmaps.rcsb.org/maps/"+e.toLowerCase()+"_"+t+".dsn6";await this.dsn6ParserBase(s,t,i,"url",!0)}async dsn6ParserBase(e,t,i,s,n){let r=this.icn3d,a=r.icn3dui,o=this;if("2fofc"==t&&r.bAjax2fofc)r.mapData.sigma2=i,r.setOptionCls.setOption("map",t);else if("fofc"==t&&r.bAjaxfofc)r.mapData.sigma=i,r.setOptionCls.setOption("map",t);else{let l=await a.getXMLHttpRqstPromise(e,"GET","arraybuffer","rcsbEdmaps");i=o.loadDsn6Data(l,t,i,s,n),"2fofc"==t?r.bAjax2fofc=!0:"fofc"==t&&(r.bAjaxfofc=!0),r.setOptionCls.setOption("map",t)}return i}loadDsn6Data(e,t,i,s,n){let r,a,o=this.icn3d,l=o.icn3dui,d={},c=e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e,h=new Int16Array(c),p=new Uint8Array(c),u=String.fromCharCode.apply(null,p.subarray(0,512));if(0==u.indexOf(":-)"))d.xStart=parseInt(u.substr(10,5)),d.yStart=parseInt(u.substr(15,5)),d.zStart=parseInt(u.substr(20,5)),d.xExtent=parseInt(u.substr(32,5)),d.yExtent=parseInt(u.substr(38,5)),d.zExtent=parseInt(u.substr(42,5)),d.xRate=parseInt(u.substr(52,5)),d.yRate=parseInt(u.substr(58,5)),d.zRate=parseInt(u.substr(62,5)),d.xlen=1*parseFloat(u.substr(73,10)),d.ylen=1*parseFloat(u.substr(83,10)),d.zlen=1*parseFloat(u.substr(93,10)),d.alpha=parseFloat(u.substr(103,10)),d.beta=parseFloat(u.substr(113,10)),d.gamma=parseFloat(u.substr(123,10)),r=parseFloat(u.substr(138,12))/100,a=parseInt(u.substr(155,8)),d.sigma=100*parseFloat(u.substr(170,12));else{if(100!==h[18])for(let e=0,t=h.length;e<t;++e){let t=h[e];h[e]=(255&t)<<8|t>>8&255}d.xStart=h[0],d.yStart=h[1],d.zStart=h[2],d.xExtent=h[3],d.yExtent=h[4],d.zExtent=h[5],d.xRate=h[6],d.yRate=h[7],d.zRate=h[8];let e=1/h[17],t=1*e;d.xlen=h[9]*t,d.ylen=h[10]*t,d.zlen=h[11]*t,d.alpha=h[12]*e,d.beta=h[13]*e,d.gamma=h[14]*e,r=h[15]/h[18],a=h[16]}l.bNode||console.log("header: "+JSON.stringify(d));let m=new Float32Array(d.xExtent*d.yExtent*d.zExtent),f=512,g=Math.ceil(d.xExtent/8),b=Math.ceil(d.yExtent/8),C=Math.ceil(d.zExtent/8),v=-999;for(let e=0;e<C;++e)for(let t=0;t<b;++t)for(let i=0;i<g;++i)for(let s=0;s<8;++s){let n=8*e+s;for(let e=0;e<8;++e){let s=8*t+e;for(let e=0;e<8;++e){let t=8*i+e;if(!(t<d.xExtent&&s<d.yExtent&&n<d.zExtent)){f+=8-e;break}{let e=(t*d.yExtent+s)*d.zExtent+n;m[e]=(p[f]-a)/r,m[e]>v&&(v=m[e]),++f}}}}return n||(i=this.setSigma(v,s,t,i)),"2fofc"==t?(o.mapData.header2=d,o.mapData.data2=m,o.mapData.matrix2=this.getMatrix(d),o.mapData.type2=t,o.mapData.sigma2=i):(o.mapData.header=d,o.mapData.data=m,o.mapData.matrix=this.getMatrix(d),o.mapData.type=t,o.mapData.sigma=i),i}setSigma(e,t,i,s){let n,r=this.icn3d.icn3dui;"file"==t?n="dsn6sigma"+i:"url"==t&&(n="dsn6sigmaurl"+i);return n&&($("#"+r.pre+n).val()?s=$("#"+r.pre+n).val():(s=(.2*e).toFixed(2),$("#"+r.pre+n).val(s))),s}getMatrix(e){this.icn3d.icn3dui;let t=e,i=[t.xlen,0,0],s=[t.ylen*Math.cos(Math.PI/180*t.gamma),t.ylen*Math.sin(Math.PI/180*t.gamma),0],n=[t.zlen*Math.cos(Math.PI/180*t.beta),t.zlen*(Math.cos(Math.PI/180*t.alpha)-Math.cos(Math.PI/180*t.gamma)*Math.cos(Math.PI/180*t.beta))/Math.sin(Math.PI/180*t.gamma),0];n[2]=Math.sqrt(t.zlen*t.zlen*Math.sin(Math.PI/180*t.beta)*Math.sin(Math.PI/180*t.beta)-n[1]*n[1]);let r=[[],i,s,n],a=[0,t.xRate,t.yRate,t.zRate],o=[0,1,2,3],l=new gi;return l.set(r[o[1]][0]/a[o[1]],r[o[2]][0]/a[o[2]],r[o[3]][0]/a[o[3]],0,r[o[1]][1]/a[o[1]],r[o[2]][1]/a[o[2]],r[o[3]][1]/a[o[3]],0,r[o[1]][2]/a[o[1]],r[o[2]][2]/a[o[2]],r[o[3]][2]/a[o[3]],0,0,0,0,1),l.multiply((new gi).makeTranslation(t.xStart,t.yStart,t.zStart)),l}loadDsn6File(e){var t=this.icn3d,i=t.icn3dui;let s=this,n=$("#"+t.pre+"dsn6file"+e)[0].files[0],r=$("#"+t.pre+"dsn6sigma"+e).val();if(n){i.utilsCls.checkFileAPI();let t=new FileReader;t.onload=function(t){let n=s.icn3d,a=t.target.result;r=s.loadDsn6Data(a,e,r,"file"),"2fofc"==e?n.bAjax2fofc=!0:"fofc"==e&&(n.bAjaxfofc=!0),n.setOptionCls.setOption("map",e),i.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+n.pre+"dsn6file"+e).val()+" with sigma "+r,!1)},t.readAsArrayBuffer(n)}else alert("Please select a file before clicking 'Load'")}loadDsn6FileUrl(e){var t=this.icn3d,i=t.icn3dui;let s=$("#"+t.pre+"dsn6fileurl"+e).val(),n=$("#"+t.pre+"dsn6sigmaurl"+e).val();s?(n=this.dsn6ParserBase(s,e,n,"url"),i.htmlCls.clickMenuCls.setLogCmd("set map "+e+" sigma "+n+" file dsn6 | "+encodeURIComponent(s),!0)):alert("Please input the file URL before clicking 'Load'")}}class Th{constructor(e){this.icn3d=e}async ccp4ParserBase(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=await r.getXMLHttpRqstPromise(e,"GET","arraybuffer","");return i=this.load_map_from_buffer(a,t,i,s,!0),n.setOptionCls.setOption("map",t),i}load_map_from_buffer(e,t,i,s,n){let r=this.icn3d;if(r.icn3dui,e.byteLength<1024)throw Error("File shorter than 1024 bytes.");const a=new Int32Array(e,0,256);if(542130509!==a[52])throw Error("not a CCP4 map");const o=[a[0],a[1],a[2]],l=a[3];let d;if(2===l)d=4;else{if(0!==l)throw Error("Only Mode 2 and Mode 0 of CCP4 map is supported.");d=1}const c=[a[4],a[5],a[6]],h=[a[7],a[8],a[9]],p=a[23];if(1024+p+d*o[0]*o[1]*o[2]!==e.byteLength)throw Error("ccp4 file too short or too long");const u=new Float32Array(e,0,e.byteLength/4),m=new Rh(h),f=new Eh(u[10],u[11],u[12],u[13],u[14],u[15]),g=[a[16],a[17],a[18]],b=g.indexOf(1),C=g.indexOf(2),v=g.indexOf(3),_=u[19],y=u[20];if(p%4!=0)throw Error("CCP4 map with NSYMBT not divisible by 4 is not supported.");let S;S=2===l?u:new Int8Array(e);let w=(1024+p)/d|0,x=1,A=0;0===l&&-128===a[39]&&127===a[40]&&(x=(y-_)/255,A=.5*(_+y+x));const M=[c[0]+o[0],c[1]+o[1],c[2]+o[2]];let T=[0,0,0],E=-999;for(T[2]=c[2];T[2]<M[2];T[2]++)for(T[1]=c[1];T[1]<M[1];T[1]++)for(T[0]=c[0];T[0]<M[0];T[0]++){let e=x*S[w]+A;m.set_grid_value(T[b],T[C],T[v],e),e>E&&(E=e),w++}return n||(i=r.dsn6ParserCls.setSigma(E,s,t,i)),"2fofc"==t?(r.mapData.ccp4=1,r.mapData.grid2=m,r.mapData.unit_cell2=f,r.mapData.type2=t,r.mapData.sigma2=i):(r.mapData.ccp4=1,r.mapData.grid=m,r.mapData.unit_cell=f,r.mapData.type=t,r.mapData.sigma=i),i}load_maps_from_mtz_buffer(e,t,i,s,n,r){let a=this.icn3d;a.icn3dui;let o="fofc"==t,l=e.calculate_map(o),d=e.cell;const c=new Eh(d.a,d.b,d.c,d.alpha,d.beta,d.gamma);let h=-999;for(let e=0,t=l.length;e<t;++e)l[e]>h&&(h=l[e]);if(n||(i=a.dsn6ParserCls.setSigma(h,s,t,i)),r){a.mapData.ccp4=0;let s={xExtent:e.nx,yExtent:e.ny,zExtent:e.nz,mean:void 0,sigma:i,ccp4:1,xStart:0,yStart:0,zStart:0};s.xRate=e.nx,s.yRate=e.ny,s.zRate=e.nz,s.xlen=d.a,s.ylen=d.b,s.zlen=d.c,s.alpha=d.alpha,s.beta=d.beta,s.gamma=d.gamma,"2fofc"==t?(a.mapData.header2=s,a.mapData.data2=l,a.mapData.matrix2=a.dsn6ParserCls.getMatrix(s),a.mapData.type2=t,a.mapData.sigma2=i):(a.mapData.header=s,a.mapData.data=l,a.mapData.matrix=a.dsn6ParserCls.getMatrix(s),a.mapData.type=t,a.mapData.sigma=i)}else{const s=new Rh([e.nx,e.ny,e.nz]);s.values.set(l),"2fofc"==t?(a.mapData.ccp4=1,a.mapData.grid2=s,a.mapData.unit_cell2=c,a.mapData.type2=t,a.mapData.sigma2=i):(a.mapData.ccp4=1,a.mapData.grid=s,a.mapData.unit_cell=c,a.mapData.type=t,a.mapData.sigma=i)}return e.delete(),i}parse_symop(e){const t=e.toLowerCase().replace(/\s+/g,"").split(",");if(3!==t.length)throw Error("Unexpected symop: "+e);let i=[];for(let s=0;s<3;s++){const n=t[s].split(/(?=[+-])/);let r=[0,0,0,0];for(let t=0;t<n.length;t++){const i="-"===n[t][0]?-1:1;let s=n[t].match(/^[+-]?([xyz])$/);if(s){r[{x:0,y:1,z:2}[s[1]]]=i}else{if(s=n[t].match(/^[+-]?(\d)\/(\d)$/),!s)throw Error("What is "+n[t]+" in "+e);r[3]=i*Number(s[1])/Number(s[2])}}i.push(r)}return i}loadCcp4File(e){let t=this.icn3d,i=t.icn3dui,s=this,n=$("#"+t.pre+"dsn6file"+e)[0].files[0],r=$("#"+t.pre+"dsn6sigma"+e).val();if(n){i.utilsCls.checkFileAPI();let t=new FileReader;t.onload=function(t){let n=s.icn3d,a=t.target.result;r=s.load_map_from_buffer(a,e,r,"file"),n.setOptionCls.setOption("map",e),i.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+n.pre+"dsn6file"+e).val()+" with sigma "+r,!1)},t.readAsArrayBuffer(n)}else alert("Please select a file before clicking 'Load'")}async loadCcp4FileUrl(e){let t=this.icn3d,i=t.icn3dui,s=$("#"+t.pre+"dsn6fileurl"+e).val(),n=$("#"+t.pre+"dsn6sigmaurl"+e).val();s?(n=await this.ccp4ParserBase(s,e,n,"file"),i.htmlCls.clickMenuCls.setLogCmd("set map "+e+" sigma "+n+" file ccp4 | "+encodeURIComponent(s),!0)):alert("Please input the file URL before clicking 'Load'")}extract_block(e,t,i,s,n){let r=this.icn3d;if(r.icn3dui,null==e||null==t)return;let a=t.fractionalize(s),o=[i/t.parameters[0],i/t.parameters[1],i/t.parameters[2]],l=e.frac2grid([a[0]-o[0],a[1]-o[1],a[2]-o[2]]),d=e.frac2grid([a[0]+o[0],a[1]+o[1],a[2]+o[2]]),c=[d[0]-l[0]+1,d[1]-l[1]+1,d[2]-l[2]+1],h=[],p=[],u=r.hAtoms&&Object.keys(r.hAtoms).length>0;for(let i=l[0];i<=d[0];i++)for(let s=l[1];s<=d[1];s++)for(let a=l[2];a<=d[2];a++){let o=e.grid2frac(i,s,a),l=t.orthogonalize(o);h.push(l);let d=new mt(l[0],l[1],l[2]),c=r.rayCls.getAtomsFromPosition(d,1,r.hAtoms)||!u?e.get_grid_value(i,s,a):0;"fofc_pos"==n&&c<0&&(c=0),"fofc_neg"==n&&(c=c>0?0:-c),p.push(c)}return{size:c,values:p,points:h}}marchingCubes(e,t,i,s,n){this.icn3d.icn3dui;const r=new Int32Array([0,0,514,770,1030,1030,1540,1796,2052,2053,2566,2566,3082,3331,3592,3840,144,152,658,658,1174,1182,1684,1684,2196,2196,2710,2710,3226,3218,3729,3728,560,560,51,314,1590,1590,1076,1084,2612,2613,2103,2358,3642,3890,3121,3376,672,680,163,170,1702,1711,1444,1196,2724,2724,2470,2214,4010,3747,3233,3232,1120,1120,1634,1890,102,102,613,868,3172,3173,3686,3686,2154,2147,2665,2656,1264,1272,1778,1778,246,254,757,764,3316,3316,3830,3830,2298,2291,2809,2800,1616,1616,1107,1362,598,598,84,340,3668,3924,3159,3414,2650,2898,2137,2384,1984,1729,1474,1218,966,718,197,196,4036,3781,3526,3270,3018,2754,2241,2240,2240,2240,2754,3010,3270,3270,3780,4044,196,197,710,966,1218,1474,1729,1984,2384,2137,2898,2650,3414,3159,3668,3676,340,84,606,598,1362,1107,1624,1616,2800,2800,2291,2298,3830,3830,3316,3324,756,1013,255,502,1778,1779,1273,1520,2656,2665,2147,2154,3686,3687,3429,3180,868,613,358,102,1898,1635,1120,1120,3232,3232,3746,4002,2214,2214,2724,2980,1196,1444,1710,1958,170,163,680,672,3376,3121,3890,3642,2358,2103,2869,2612,1084,1076,1854,1590,314,51,825,560,3728,3728,3218,3226,2710,2710,2196,2204,1684,1685,1183,1174,658,914,152,144,3840,3592,3331,3082,2566,2574,2053,2052,1796,1540,1286,1030,770,514,0,0]),a="snapped MC"===n,o=[[],[],[1,9],[1,8,1,9],[2,10,10,1],[2,10,10,1],[9,2,2,10,10,9],[2,8,2,10,10,8,10,9],[11,2],[0,11,11,2],[1,9,11,2],[1,11,11,2,1,9,9,11],[3,10,10,1,11,10],[0,10,10,1,8,10,11,10],[3,9,11,9,11,10,10,9],[8,10,10,9,11,10],[4,7],[4,3,4,7],[1,9,4,7],[4,1,1,9,4,7,7,1],[2,10,10,1,4,7],[3,4,4,7,2,10,10,1],[9,2,2,10,10,9,4,7],[2,10,10,9,9,2,9,7,7,2,4,7],[4,7,11,2],[11,4,4,7,11,2,2,4],[1,9,4,7,11,2],[4,7,11,4,11,9,11,2,2,9,1,9],[3,10,10,1,11,10,4,7],[1,11,11,10,10,1,1,4,4,11,4,7],[4,7,0,11,11,9,11,10,10,9],[4,7,11,4,11,9,11,10,10,9],[9,5,5,4],[9,5,5,4],[0,5,5,4,1,5],[8,5,5,4,3,5,1,5],[2,10,10,1,9,5,5,4],[2,10,10,1,9,5,5,4],[5,2,2,10,10,5,5,4,4,2],[2,10,10,5,5,2,5,3,5,4,4,3],[9,5,5,4,11,2],[0,11,11,2,9,5,5,4],[0,5,5,4,1,5,11,2],[1,5,5,2,5,8,8,2,11,2,5,4],[10,3,11,10,10,1,9,5,5,4],[9,5,5,4,8,1,8,10,10,1,11,10],[5,4,0,5,0,11,11,5,11,10,10,5],[5,4,8,5,8,10,10,5,11,10],[9,7,5,7,9,5],[9,3,9,5,5,3,5,7],[0,7,1,7,1,5,5,7],[1,5,5,3,5,7],[9,7,9,5,5,7,10,1,2,10],[10,1,2,10,9,5,5,0,5,3,5,7],[2,8,2,5,5,8,5,7,10,5,2,10],[2,10,10,5,5,2,5,3,5,7],[7,9,9,5,5,7,11,2],[9,5,5,7,7,9,7,2,2,9,11,2],[11,2,1,8,1,7,1,5,5,7],[11,2,1,11,1,7,1,5,5,7],[9,5,5,8,5,7,10,1,3,10,11,10],[5,7,7,0,0,5,9,5,11,0,0,10,10,1,11,10],[11,10,10,0,0,11,10,5,5,0,0,7,5,7],[11,10,10,5,5,11,5,7],[10,6,6,5,5,10],[5,10,10,6,6,5],[1,9,5,10,10,6,6,5],[1,8,1,9,5,10,10,6,6,5],[1,6,6,5,5,1,2,6],[1,6,6,5,5,1,2,6],[9,6,6,5,5,9,0,6,2,6],[5,9,8,5,8,2,2,5,2,6,6,5],[11,2,10,6,6,5,5,10],[11,0,11,2,10,6,6,5,5,10],[1,9,11,2,5,10,10,6,6,5],[5,10,10,6,6,5,1,9,9,2,9,11,11,2],[6,3,11,6,6,5,5,3,5,1],[11,0,11,5,5,0,5,1,11,6,6,5],[11,6,6,3,6,0,6,5,5,0,5,9],[6,5,5,9,9,6,9,11,11,6],[5,10,10,6,6,5,4,7],[4,3,4,7,6,5,5,10,10,6],[1,9,5,10,10,6,6,5,4,7],[10,6,6,5,5,10,1,9,9,7,7,1,4,7],[6,1,2,6,6,5,5,1,4,7],[2,5,5,1,2,6,6,5,4,3,4,7],[4,7,0,5,5,9,0,6,6,5,2,6],[3,9,9,7,4,7,2,9,5,9,9,6,6,5,2,6],[11,2,4,7,10,6,6,5,5,10],[5,10,10,6,6,5,4,7,7,2,2,4,11,2],[1,9,4,7,11,2,5,10,10,6,6,5],[9,2,1,9,9,11,11,2,4,11,4,7,5,10,10,6,6,5],[4,7,11,5,5,3,5,1,11,6,6,5],[5,1,1,11,11,5,11,6,6,5,0,11,11,4,4,7],[0,5,5,9,0,6,6,5,3,6,11,6,4,7],[6,5,5,9,9,6,9,11,11,6,4,7,7,9],[10,4,9,10,6,4,10,6],[4,10,10,6,6,4,9,10],[10,0,1,10,10,6,6,0,6,4],[1,8,1,6,6,8,6,4,1,10,10,6],[1,4,9,1,2,4,2,6,6,4],[2,9,9,1,2,4,2,6,6,4],[2,4,2,6,6,4],[2,8,2,4,2,6,6,4],[10,4,9,10,10,6,6,4,11,2],[8,2,11,2,9,10,10,4,10,6,6,4],[11,2,1,6,6,0,6,4,1,10,10,6],[6,4,4,1,1,6,1,10,10,6,8,1,1,11,11,2],[9,6,6,4,9,3,3,6,9,1,11,6],[11,1,1,8,11,6,6,1,9,1,1,4,6,4],[11,6,6,3,6,0,6,4],[6,4,8,6,11,6],[7,10,10,6,6,7,8,10,9,10],[0,7,0,10,10,7,9,10,6,7,10,6],[10,6,6,7,7,10,1,10,7,1,8,1],[10,6,6,7,7,10,7,1,1,10],[2,6,6,1,6,8,8,1,9,1,6,7],[2,6,6,9,9,2,9,1,6,7,7,9,9,3],[0,7,0,6,6,7,2,6],[2,7,6,7,2,6],[11,2,10,6,6,8,8,10,9,10,6,7],[0,7,7,2,11,2,9,7,6,7,7,10,10,6,9,10],[1,8,1,7,1,10,10,7,6,7,10,6,11,2],[11,2,1,11,1,7,10,6,6,1,1,10,6,7],[9,6,6,8,6,7,9,1,1,6,11,6,6,3],[9,1,11,6,6,7],[0,7,0,6,6,7,11,0,11,6],[11,6,6,7],[7,6,6,11],[7,6,6,11],[1,9,7,6,6,11],[8,1,1,9,7,6,6,11],[10,1,2,10,6,11,7,6],[2,10,10,1,6,11,7,6],[2,9,2,10,10,9,6,11,7,6],[6,11,7,6,2,10,10,3,10,8,10,9],[7,2,6,2,7,6],[7,0,7,6,6,0,6,2],[2,7,7,6,6,2,1,9],[1,6,6,2,1,8,8,6,1,9,7,6],[10,7,7,6,6,10,10,1,1,7],[10,7,7,6,6,10,1,7,10,1,1,8],[7,0,7,10,10,0,10,9,6,10,7,6],[7,6,6,10,10,7,10,8,10,9],[6,8,4,6,6,11],[3,6,6,11,0,6,4,6],[8,6,6,11,4,6,1,9],[4,6,6,9,6,3,3,9,1,9,6,11],[6,8,4,6,6,11,2,10,10,1],[2,10,10,1,0,11,0,6,6,11,4,6],[4,11,4,6,6,11,2,9,2,10,10,9],[10,9,9,3,3,10,2,10,4,3,3,6,6,11,4,6],[8,2,4,2,4,6,6,2],[4,2,4,6,6,2],[1,9,3,4,4,2,4,6,6,2],[1,9,4,1,4,2,4,6,6,2],[8,1,8,6,6,1,4,6,6,10,10,1],[10,1,0,10,0,6,6,10,4,6],[4,6,6,3,3,4,6,10,10,3,3,9,10,9],[10,9,4,10,6,10,4,6],[9,5,5,4,7,6,6,11],[9,5,5,4,7,6,6,11],[5,0,1,5,5,4,7,6,6,11],[7,6,6,11,3,4,3,5,5,4,1,5],[9,5,5,4,10,1,2,10,7,6,6,11],[6,11,7,6,2,10,10,1,9,5,5,4],[7,6,6,11,5,4,4,10,10,5,4,2,2,10],[3,4,3,5,5,4,2,5,10,5,2,10,7,6,6,11],[7,2,7,6,6,2,5,4,9,5],[9,5,5,4,8,6,6,0,6,2,7,6],[3,6,6,2,7,6,1,5,5,0,5,4],[6,2,2,8,8,6,7,6,1,8,8,5,5,4,1,5],[9,5,5,4,10,1,1,6,6,10,1,7,7,6],[1,6,6,10,10,1,1,7,7,6,0,7,9,5,5,4],[0,10,10,4,10,5,5,4,3,10,6,10,10,7,7,6],[7,6,6,10,10,7,10,8,5,4,4,10,10,5],[6,9,9,5,5,6,6,11,11,9],[3,6,6,11,0,6,0,5,5,6,9,5],[0,11,0,5,5,11,1,5,5,6,6,11],[6,11,3,6,3,5,5,6,1,5],[2,10,10,1,9,5,5,11,11,9,5,6,6,11],[0,11,0,6,6,11,9,6,5,6,9,5,2,10,10,1],[8,5,5,11,5,6,6,11,0,5,10,5,5,2,2,10],[6,11,3,6,3,5,5,6,2,10,10,3,10,5],[5,8,9,5,5,2,2,8,5,6,6,2],[9,5,5,6,6,9,6,0,6,2],[1,5,5,8,8,1,5,6,6,8,8,2,6,2],[1,5,5,6,6,1,6,2],[3,6,6,1,6,10,10,1,8,6,5,6,6,9,9,5],[10,1,0,10,0,6,6,10,9,5,5,0,5,6],[5,6,6,10,10,5],[10,5,5,6,6,10],[11,5,5,10,10,11,7,5],[11,5,5,10,10,11,7,5],[5,11,7,5,5,10,10,11,1,9],[10,7,7,5,5,10,10,11,8,1,1,9],[11,1,2,11,7,1,7,5,5,1],[2,7,7,1,7,5,5,1,2,11],[9,7,7,5,5,9,9,2,2,7,2,11],[7,5,5,2,2,7,2,11,5,9,9,2,2,8],[2,5,5,10,10,2,3,5,7,5],[8,2,8,5,5,2,7,5,10,2,5,10],[1,9,5,10,10,3,3,5,7,5,10,2],[8,2,2,9,1,9,7,2,10,2,2,5,5,10,7,5],[3,5,5,1,7,5],[7,0,7,1,7,5,5,1],[3,9,3,5,5,9,7,5],[7,9,5,9,7,5],[5,8,4,5,5,10,10,8,10,11],[5,0,4,5,5,11,11,0,5,10,10,11],[1,9,4,10,10,8,10,11,4,5,5,10],[10,11,11,4,4,10,4,5,5,10,3,4,4,1,1,9],[2,5,5,1,2,8,8,5,2,11,4,5],[4,11,11,0,4,5,5,11,2,11,11,1,5,1],[2,5,5,0,5,9,2,11,11,5,4,5,5,8],[4,5,5,9,2,11],[2,5,5,10,10,2,3,5,3,4,4,5],[5,10,10,2,2,5,2,4,4,5],[3,10,10,2,3,5,5,10,8,5,4,5,1,9],[5,10,10,2,2,5,2,4,4,5,1,9,9,2],[4,5,5,8,5,3,5,1],[4,5,5,0,5,1],[4,5,5,8,5,3,0,5,5,9],[4,5,5,9],[4,11,7,4,9,11,9,10,10,11],[9,7,7,4,9,11,9,10,10,11],[1,10,10,11,11,1,11,4,4,1,7,4],[1,4,4,3,1,10,10,4,7,4,4,11,10,11],[4,11,7,4,9,11,9,2,2,11,9,1],[9,7,7,4,9,11,9,1,1,11,2,11],[7,4,4,11,4,2,2,11],[7,4,4,11,4,2,2,11,3,4],[2,9,9,10,10,2,2,7,7,9,7,4],[9,10,10,7,7,9,7,4,10,2,2,7,7,0],[7,10,10,3,10,2,7,4,4,10,1,10,10,0],[1,10,10,2,7,4],[9,1,1,4,1,7,7,4],[9,1,1,4,1,7,7,4,8,1],[3,4,7,4],[7,4],[9,10,10,8,10,11],[9,3,9,11,9,10,10,11],[1,10,10,0,10,8,10,11],[1,10,10,3,10,11],[2,11,11,1,11,9,9,1],[9,3,9,11,2,9,9,1,2,11],[2,11,11,0],[2,11],[8,2,8,10,10,2,9,10],[9,10,10,2,2,9],[8,2,8,10,10,2,1,8,1,10],[1,10,10,2],[8,1,9,1],[9,1],[],[]];let l=new Array(12);const d=this.calculateVertOffsets(e),c=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]];let h=new Float32Array(8),p=[0,0,0],u=[p,p,p,p,p,p,p,p];const m=e[0],f=e[1],g=e[2];if(null==t||null==i)return;let b=[],C=[],v=0;for(let e=0;e<m-1;e++)for(let n=0;n<f-1;n++)for(let p=0;p<g-1;p++){const m=p+g*(n+f*e);let _,y,S=0;for(_=0;_<8;++_)y=m+d[_],S|=t[y]<s?1<<_:0;if(0===S||255===S)continue;for(_=0;_<8;++_)y=m+d[_],h[_]=t[y],u[_]=i[y];const w=r[S];for(_=0;_<12;++_)if(w&1<<_){const e=c[_];let t=(s-h[e[0]])/(h[e[1]]-h[e[0]]);!0===a&&(t>.85?t=1:t<.15&&(t=0));const i=u[e[0]],n=u[e[1]];b.push(i[0]+(n[0]-i[0])*t,i[1]+(n[1]-i[1])*t,i[2]+(n[2]-i[2])*t),l[_]=v++}const x=o[S];for(_=0;_<x.length;_++)C.push(l[x[_]])}return{vertices:b,segments:C}}calculateVertOffsets(e){this.icn3d.icn3dui;let t=[];const i=[[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]];for(let s=0;s<8;++s){const n=i[s];t.push(n[0]+e[2]*(n[1]+e[1]*n[2]))}return t}makeChickenWire(e,t){let i=this.icn3d,s=i.icn3dui,n=new Ts,r=new Float32Array(e.vertices);n.setAttribute("position",new gs(r,3));let a=e.vertices.length<196608?new Uint16Array(e.segments):new Uint32Array(e.segments);n.setIndex(new gs(a,1));let o=s.parasCls.thr("#00FFFF"),l=s.parasCls.thr("#00FF00"),d=s.parasCls.thr("#ff0000"),c=new Ln({linewidth:1,color:"2fofc"==t?o:"fofc_pos"==t?l:d}),h=new Wn(n,c);i.mdl.add(h),i.prevMaps.push(h)}}class Eh{constructor(e,t,i,s,n,r){if(e<=0||t<=0||i<=0||s<=0||n<=0||r<=0)throw Error("Zero or negative unit cell parameter(s).");this.parameters=[e,t,i,s,n,r];const a=Math.PI/180,o=Math.cos(a*s),l=Math.cos(a*n),d=Math.cos(a*r),c=Math.sin(a*s),h=Math.sin(a*n),p=Math.sin(a*r);if(0===c||0===h||0===p)throw Error("Impossible angle - N*180deg.");const u=(l*d-o)/p,m=u/h,f=Math.sqrt(1-m*m);this.orth=[e,t*d,i*l,0,t*p,-i*u,0,0,i*h*f],this.frac=[1/e,-d/(p*e),-(d*u+l*p)/(h*f*p*e),0,1/(p*t),m/(f*p*t),0,0,1/(h*f*i)]}multiply(e,t){return[t[0]*e[0]+t[1]*e[1]+t[2]*e[2],+t[4]*e[1]+t[5]*e[2],+t[8]*e[2]]}fractionalize(e){return this.multiply(e,this.frac)}orthogonalize(e){return this.multiply(e,this.orth)}}class Rh{constructor(e){this.dim=e,this.values=new Float32Array(e[0]*e[1]*e[2])}modulo(e,t){const i=e%t;return i>=0?i:i+t}grid2index(e,t,i){return e=this.modulo(e,this.dim[0]),t=this.modulo(t,this.dim[1]),i=this.modulo(i,this.dim[2]),this.dim[2]*(this.dim[1]*e+t)+i}grid2index_unchecked(e,t,i){return this.dim[2]*(this.dim[1]*e+t)+i}grid2frac(e,t,i){return[e/this.dim[0],t/this.dim[1],i/this.dim[2]]}frac2grid(e){return[0|Math.floor(e[0]*this.dim[0]),0|Math.floor(e[1]*this.dim[1]),0|Math.floor(e[2]*this.dim[2])]}set_grid_value(e,t,i,s){const n=this.grid2index(e,t,i);this.values[n]=s}get_grid_value(e,t,i){const s=this.grid2index(e,t,i);return this.values[s]}}class kh{constructor(e){this.icn3d=e}async mtzParserBase(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui,l=await o.getXMLHttpRqstPromise(e,"GET","arraybuffer","");return i=await this.loadMtzFileBase(l,t,i,s,n,e,r),a.setOptionCls.setOption("map",t),i}loadMtzFile(e,t){var i=this.icn3d,s=i.icn3dui;let n=this,r=$("#"+i.pre+"dsn6file"+e)[0].files[0],a=$("#"+i.pre+"dsn6sigma"+e).val();if(r){s.utilsCls.checkFileAPI();let i=new FileReader;i.onload=async function(i){let r=n.icn3d;a=await n.loadMtzFileBase(i.target.result,e,a,"file",void 0,void 0,t),s.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+r.pre+"dsn6file"+e).val()+" with sigma "+a,!1)},i.readAsArrayBuffer(r)}else alert("Please select a file before clicking 'Load'")}async loadMtzFileBase(e,t,i,s,n,r,a){var o=this.icn3d,l=o.icn3dui;if(void 0===o.bMtz){let e="./script/mtz.js";await l.getAjaxPromise(e,"script"),o.bMtz=!0}GemmiMtz().then((function(d){let c=d.readMtz(e);i=o.ccp4ParserCls.load_maps_from_mtz_buffer(c,t,i,s,n,a),o.setOptionCls.setOption("map",t);let h=a?"rcsbmtz":"mtz";return r&&l.htmlCls.clickMenuCls.setLogCmd("set map "+t+" sigma "+i+" file "+h+" | "+encodeURIComponent(r),!0),i}))}async loadMtzFileUrl(e,t){var i=this.icn3d;i.icn3dui;let s=$("#"+i.pre+"dsn6fileurl"+e).val(),n=$("#"+i.pre+"dsn6sigmaurl"+e).val();s?n=await this.mtzParserBase(s,e,n,"url",void 0,t):alert("Please input the file URL before clicking 'Load'")}}class Oh{constructor(e){this.icn3d=e}async downloadMmcif(e){let t=this.icn3d,i=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(MMCIF) in iCn3D");let s="https://files.rcsb.org/download/"+e+".cif",n=await i.getAjaxPromise(s,"text",!0);await t.opmParserCls.loadOpmData(n,e,void 0,"mmcif",void 0,!0)}async downloadMmcifSymmetry(e,t){let i=this.icn3d,s=i.icn3dui;try{let n="https://models.rcsb.org/"+e+".bcif",r=await s.getXMLHttpRqstPromise(n,"GET","arraybuffer","bcif"),a=!1,o=!0,l=i.bcifParserCls.getBcifJson(r,e,a,o),d=JSON.parse(l);if(void 0!==d.emd&&(i.emd=d.emd),void 0!==d.organism&&(i.organism=d.organism),i.bAssemblyUseAsu){for(let e=0,t=d.assembly.length;e<t;++e){let t=new gi;t.fromArray(d.assembly[e]),0==e&&1!=d.assembly[e][0]||i.biomtMatrices.push(t)}i.asuCnt=i.biomtMatrices.length,1==s.cfg.bu&&Object.keys(i.atoms).length*i.asuCnt>i.maxatomcnt&&(i.bAssembly=!0)}if("mmtfid"===t&&void 0!==d.missingseq){let t=0,n="";for(let r=0,a=d.missingseq.length;r<a;++r){let a=d.missingseq[r].resn,o=d.missingseq[r].chain,l=d.missingseq[r].resi,c=e+"_"+o;void 0===i.chainMissingResidueArray[c]&&(i.chainMissingResidueArray[c]=[]);let h={};h.resi=l,h.name=s.utilsCls.residueName2Abbr(a).toLowerCase(),o!=n&&(t=0),!isNaN(l)&&(""==n||o!=n||o==n&&l>t)&&(i.chainMissingResidueArray[c].push(h),t=l,n=o)}i.loadPDBCls.adjustSeq(i.chainMissingResidueArray)}}catch(e){return void(s.bNode||console.log("downloadMmcifSymmetry issues: "+e))}}async loadMmcifData(e,t){let i=this.icn3d;if(i.icn3dui,t||(t=e.mmcif),t||(t=i.defaultPdbId),void 0===e.atoms)return!1;i.init(),void 0!==e.emd&&(i.emd=e.emd),void 0!==e.organism&&(i.organism=e.organism),await i.opmParserCls.loadOpmData(e,t,void 0,"mmcif"),i.opmParserCls.modifyUIMapAssembly()}async loadMultipleMmcifData(e,t,i){let s=this.icn3d;s.icn3dui;s.loadCIFCls.loadCIF(e,t,!0,i),Object.keys(s.structures).length>1&&(s.opts.color="structure"),s.opmParserCls.modifyUIMapAssembly(),s.pdbParserCls.addSecondary(i)}}class Ih{constructor(e){this.icn3d=e}async downloadMmdb(e,t){let i,s=this.icn3d,n=s.icn3dui;try{if(i=await this.loadMmdbPrms(e,t),!i||i.error)return void this.getNoData(e,t)}catch(i){return void this.getNoData(e,t)}if(0!=Object.keys(i.atoms).length)if(n.utilsCls.isCalphaPhosOnly(i.atoms)||i.atomCount<=s.maxatomcnt)await this.parseMmdbData(i);else{let i;try{i=await this.loadMmdbPrms(e,t,!0)}catch(i){return void this.getNoData(e,t)}await this.parseMmdbData(i)}else{let e=i.pdbId;await s.bcifParserCls.downloadBcif(e)}}async downloadGi(e){let t=this.icn3d;t.icn3dui,t.bCid=void 0;await this.downloadMmdb(e,!0)}async downloadBlast_rep_id(e){let t=this.icn3d,i=t.icn3dui,s=e.split(",");i.cfg.query_id=s[0],i.cfg.blast_rep_id=s[1];let n=i.cfg.blast_rep_id.split("_")[0];4==n.length?await this.downloadMmdb(n):(t.blastAcxn=i.cfg.blast_rep_id.split(".")[0],await this.downloadRefseq(t.blastAcxn,!0))}async downloadRefseq(e,t){let i=this.icn3d,s=i.icn3dui,n=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?refseq2uniprot="+e;s.cfg.refseqid=e;let r=await s.getAjaxPromise(n,"jsonp",!1,"The protein accession "+e+" can not be mapped to AlphaFold UniProt ID...");if(!r||!r.uniprot)return void alert("The accession "+e+" can not be mapped to AlphaFold UniProt ID. It will be treated as a UniProt ID instead.");s.cfg.afid=r.uniprot,i.uniprot2acc||(i.uniprot2acc={}),i.uniprot2acc[r.uniprot]=e,t&&(s.cfg.blast_rep_id=s.cfg.afid+"_A");await i.pdbParserCls.downloadPdb(s.cfg.afid,!0)}async downloadProteinname(e){let t=this.icn3d,i=t.icn3dui;i.icn3d.bCid=void 0;let s=i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?protein2acc="+e,n=(await i.getAjaxPromise(s,"jsonp")).acc;if(0==n.length)return void(i.bNode||alert("The protein/gene name "+e+" can not be mapped to RefSeq proteins..."));let r=[];for(let e=0,t=n.length;e<t;++e){let t=n[e];s=i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?refseq2uniprot="+t;let a=i.getAjaxPromise(s,"jsonp");r.push(a)}let a=Promise.allSettled(r),o=await a;r=[];let l=[];for(let e=0,n=o.length;e<n;++e){let n=o[e].value;if(n&&n.uniprot){let e=n.uniprot;s="https://alphafold.ebi.ac.uk/files/AF-"+e+"-F1-model_"+t.AFUniprotVersion+".pdb",t.ParserUtilsCls.setYourNote(i.cfg.protein+"(NCBI Protein/Gene) in iCn3D");let a=i.getAjaxPromise(s,"text",!0);r.push(a),l.push(e)}}a=Promise.allSettled(r),o=await a;for(let e=0,s=o.length;e<s;++e){let s=o[e].value;if(i.cfg.afid=l[e],s){s="HEADER "+i.cfg.afid+"\n"+s,await t.opmParserCls.parseAtomData(s,i.cfg.afid,void 0,"pdb",void 0);break}}i.cfg.afid||i.bNode||alert("The protein/gene name "+e+" can not be mapped to AlphaFold structures...")}getNoData(e,t){let i=this.icn3d.icn3dui;t?alert("This gi "+e+" has no corresponding 3D structure..."):alert("This mmdbid "+e+" with the parameters "+i.cfg.inpara+" may not have 3D structure data. Please visit the summary page for details: "+i.htmlCls.baseUrl+"pdb/"+e)}async parseMmdbData(e,t,i,s,n,r,a){let o,l=this.icn3d,d=l.icn3dui,c=void 0!==e.pdbId?e.pdbId:e.mmdbId;if(a&&(c=a),this.parseMmdbDataPart1(e,t),void 0===t?(void 0!==e.opm&&void 0!==e.opm.rot&&(l.bOpm=!0,l.opmParserCls.setOpmData(e)),o=l.loadAtomDataCls.loadAtomDataIn(e,c,"mmdbid",void 0,t)):(i&&(c=i.substr(0,i.indexOf("_"))),o=l.loadAtomDataCls.loadAtomDataIn(e,c,"mmdbid",void 0,t,i,s,n,r)),d.cfg.ligand)for(let e in l.chainid2sid)if(l.chainid2sid[e]==d.cfg.ligand.substr(3)){let t=l.firstAtomObjCls.getResiduesFromAtoms(l.chains[e]),i=Object.keys(t)[0].split("_"),s="."+i[1]+":"+i[2];await l.selByCommCls.selectByCommand(s,d.cfg.ligand,d.cfg.ligand);break}l.hAtoms=o;let h=e.pdbId;void 0===t&&l.ParserUtilsCls.setYourNote(h.toUpperCase()+"(MMDB) in iCn3D");for(let t in e.domains){let i=e.domains[t].chain,s=h+"_"+i,n=e.domains[t].domains;for(let e=0,t=n.length;e<t;++e){let t=h+"_"+i+"_3d_domain_"+(e+1).toString();l.tddomains[t]={};let r=n[e].intervals,a={},o={};for(let e=0,i=r.length;e<i;++e){let i=Math.round(r[e][0])-1,n=Math.round(r[e][1])-1;if(!a.hasOwnProperty(i)&&!o.hasOwnProperty(n)){a[i]=1,o[n]=1;for(let e=i;e<=n;++e){let i,n=s+"_"+(e+1).toString();i=l.ncbi2resid[n],i&&(l.tddomains[t][i]=1)}}}}}return l.bAssemblyUseAsu=void 0!==e.asuAtomCount,void 0!==t?l.bAssemblyUseAsu=!1:await l.mmcifParserCls.downloadMmcifSymmetry(c),l.bAssemblyUseAsu&&$("#"+l.pre+"assemblyWrapper").show(),void 0!==l.emd?($("#"+l.pre+"mapWrapper1").hide(),$("#"+l.pre+"mapWrapper2").hide(),$("#"+l.pre+"mapWrapper3").hide()):($("#"+l.pre+"emmapWrapper1").hide(),$("#"+l.pre+"emmapWrapper2").hide(),$("#"+l.pre+"emmapWrapper3").hide()),l.setStyleCls.setAtomStyleByOptions(l.opts),void 0!==d.cfg.blast_rep_id?l.setColorCls.setColorByOptions(l.opts,l.atoms):l.setColorCls.setColorByOptions(l.opts,l.atoms,!0),void 0===t&&(await l.ParserUtilsCls.renderStructure(),void 0!==d.cfg.rotate&&l.resizeCanvasCls.rotStruc(d.cfg.rotate,!0),l.html2ddgm="",d.cfg.show2d&&(d.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),l.bFullUi&&l.ParserUtilsCls.download2Ddgm(l.inputid.toUpperCase()))),void 0!==d.cfg.align&&void 0!==d.cfg.chainalign&&void 0!==d.cfg.mmdbafid||1!=Object.keys(l.structures).length||null!==$("#"+l.pre+"alternateWrapper")&&$("#"+l.pre+"alternateWrapper").hide(),o}parseMmdbDataPart1(e,t){let i=this.icn3d,s=i.icn3dui;if(void 0===e.atoms&&void 0===e.molid2rescount)return alert("invalid MMDB data."),!1;if(void 0===t||"target"===t){let e=!!i.bCommandLoad;i.bStatefile||i.init(e),i.chainsColor={},i.chainsGene={}}"query"===t||(i.interactionData={moleculeInfor:e.moleculeInfor,intrac:e.intrac,intracResidues:e.intracResidues}),"query"===t||(i.mmdb_data=e);let n=void 0!==e.pdbId?e.pdbId:e.mmdbId;"query"===t?i.inputid2=n:i.inputid=n;let r=e.moleculeInfor,a={},o={};for(let e in r){if(0===Object.keys(r[e]).length)continue;let l=void 0===r[e].color?"#CCCCCC":"#"+("000000"+r[e].color.toString(16)).slice(-6),d=void 0===r[e].chain?"":r[e].chain.trim();d=d.replace(/_/g,""),void 0===o[d]?o[d]=1:++o[d];let c=n+"_"+(1===o[d]?d:d+o[d].toString());a[e]=c,(void 0===t||s.cfg.mmdbafid)&&(i.chainsColor[c]=s.parasCls.thr(l));let h=void 0===r[e].geneId?"":r[e].geneId,p=void 0===r[e].geneSymbol?"":r[e].geneSymbol,u=void 0===r[e].geneDesc?"":r[e].geneDesc;i.chainsGene[c]={geneId:h,geneSymbol:p,geneDesc:u}}i.molid2chain=a,$("#"+i.pre+"accordion5").show()}loadMmdbPrms(e,t,i){let s,n=this.icn3d,r=n.icn3dui;return s=t?r.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+r.cfg.bu+"&simple=1&gi="+e:r.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+r.cfg.bu+"&simple=1&uid="+e,void 0!==r.cfg.blast_rep_id&&(s+="&bu=0"),void 0!==r.cfg.inpara&&(s+=r.cfg.inpara),i&&(s+="&complexity=2"),void 0===n.chainids2resids&&(n.chainids2resids={}),r.getAjaxPromise(s,"jsonp",!0)}}class Ph{constructor(e){this.icn3d=e,this.mElem2Radius={},this.mElem2Radius.H=.31,this.mElem2Radius.HE=.28,this.mElem2Radius.LI=1.28,this.mElem2Radius.BE=.96,this.mElem2Radius.B=.84,this.mElem2Radius.C=.76,this.mElem2Radius.N=.71,this.mElem2Radius.O=.66,this.mElem2Radius.F=.57,this.mElem2Radius.NE=.58,this.mElem2Radius.NA=1.66,this.mElem2Radius.MG=1.41,this.mElem2Radius.AL=1.21,this.mElem2Radius.SI=1.11,this.mElem2Radius.P=1.07,this.mElem2Radius.S=1.05,this.mElem2Radius.CL=1.02,this.mElem2Radius.AR=1.06,this.mElem2Radius.K=2.03,this.mElem2Radius.CA=1.76,this.mElem2Radius.SC=1.7,this.mElem2Radius.TI=1.6,this.mElem2Radius.V=1.53,this.mElem2Radius.CR=1.39,this.mElem2Radius.MN=1.39,this.mElem2Radius.FE=1.32,this.mElem2Radius.CO=1.26,this.mElem2Radius.NI=1.24,this.mElem2Radius.CU=1.32,this.mElem2Radius.ZN=1.22,this.mElem2Radius.GA=1.22,this.mElem2Radius.GE=1.2,this.mElem2Radius.AS=1.19,this.mElem2Radius.SE=1.2,this.mElem2Radius.BR=1.2,this.mElem2Radius.KR=1.16,this.mElem2Radius.RB=2.2,this.mElem2Radius.SR=1.95,this.mElem2Radius.Y=1.9,this.mElem2Radius.ZR=1.75,this.mElem2Radius.NB=1.64,this.mElem2Radius.MO=1.54,this.mElem2Radius.TC=1.47,this.mElem2Radius.RU=1.46,this.mElem2Radius.RH=1.42,this.mElem2Radius.PD=1.39,this.mElem2Radius.AG=1.45,this.mElem2Radius.CD=1.44,this.mElem2Radius.IN=1.42,this.mElem2Radius.SN=1.39,this.mElem2Radius.SB=1.39,this.mElem2Radius.TE=1.38,this.mElem2Radius.I=1.39,this.mElem2Radius.XE=1.4,this.mElem2Radius.CS=2.44,this.mElem2Radius.BA=2.15,this.mElem2Radius.LA=2.07,this.mElem2Radius.CE=2.04,this.mElem2Radius.PR=2.03,this.mElem2Radius.ND=2.01,this.mElem2Radius.PM=1.99,this.mElem2Radius.SM=1.98,this.mElem2Radius.EU=1.98,this.mElem2Radius.GD=1.96,this.mElem2Radius.TB=1.94,this.mElem2Radius.DY=1.92,this.mElem2Radius.HO=1.92,this.mElem2Radius.ER=1.89,this.mElem2Radius.TM=1.9,this.mElem2Radius.YB=1.87,this.mElem2Radius.LU=1.87,this.mElem2Radius.HF=1.75,this.mElem2Radius.TA=1.7,this.mElem2Radius.W=1.62,this.mElem2Radius.RE=1.51,this.mElem2Radius.OS=1.44,this.mElem2Radius.IR=1.41,this.mElem2Radius.PT=1.36,this.mElem2Radius.AU=1.36,this.mElem2Radius.HG=1.32,this.mElem2Radius.TL=1.45,this.mElem2Radius.PB=1.46,this.mElem2Radius.BI=1.48,this.mElem2Radius.PO=1.4,this.mElem2Radius.AT=1.5,this.mElem2Radius.RN=1.5,this.mElem2Radius.FR=2.6,this.mElem2Radius.RA=2.21,this.mElem2Radius.AC=2.15,this.mElem2Radius.TH=2.06,this.mElem2Radius.PA=2,this.mElem2Radius.U=1.96,this.mElem2Radius.NP=1.9,this.mElem2Radius.PU=1.87,this.mElem2Radius.AM=1.8,this.mElem2Radius.CM=1.69}async downloadBcif(e){let t=this.icn3d,i=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(BCIF) in iCn3D");let s="https://models.rcsb.org/"+e+".bcif",n=await i.getXMLHttpRqstPromise(s,"GET","arraybuffer","bcif");if(0==n.length)return void alert("This PDB structure is not found at RCSB...");await t.opmParserCls.loadOpmData(n,e,void 0,"bcif",void 0,!1)}getBcifJson(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a="",o="",l="",d="",c="",h="",p=i?CIFTools.Text.parse(e):CIFTools.Binary.parse(e);if(p.isError)return void alert("The Binary CIF data can NOT be parsed: "+p.toString());let u=p.result.dataBlocks[0];t||(u.getCategory("_entry")&&(t=u.getCategory("_entry").getColumn("id").getString(0)),""==t&&(t="stru")),u.getCategory("_citation")&&(o=u.getCategory("_citation").getColumn("pdbx_database_id_PubMed").getString(0)),u.getCategory("_struct")&&(l=u.getCategory("_struct").getColumn("title").getString(0),l=l.replace(/"/,"'")),u.getCategory("_struct_keywords")&&(d=u.getCategory("_struct_keywords").getColumn("pdbx_keywords").getString(0)),u.getCategory("_entity_src_gen")&&(h=u.getCategory("_entity_src_gen").getColumn("gene_src_common_name").getString(0));let m={},f={},g={};if(u.getCategory("_database_2")){let e=u.getCategory("_database_2"),t=e.rowCount;for(let i=0;i<t;++i){let t=e.getColumn("database_id").getString(i),s=e.getColumn("database_code").getString(i);if("EMDB"==t){c=s;break}}}if(u.getCategory("_struct_conf")){let e=u.getCategory("_struct_conf"),t=e.getColumn("conf_type_id"),i=e.getColumn("beg_auth_asym_id"),s=e.getColumn("beg_auth_seq_id"),n=e.getColumn("end_auth_asym_id"),r=e.getColumn("end_auth_seq_id"),a=e.rowCount;for(let e=0;e<a;++e){let a,o=t.getString(e),l=i.getString(e),d=s.getString(e),c=l+"_"+d,h=n.getString(e),p=r.getString(e),u=h+"_"+p;if("HELX"==o.substr(0,4)?(a="helix",m[c]=1,f[u]=1):"STRN"==o.substr(0,4)&&(a="sheet",m[c]=1,f[u]=1),"helix"==a||"sheet"==a)for(let e=parseInt(d);e<=parseInt(p);++e){g[l+"_"+e]=a}}t=i=s=n=r=[]}if(u.getCategory("_struct_sheet_range")){let e=u.getCategory("_struct_sheet_range"),t=e.getColumn("beg_auth_asym_id"),i=e.getColumn("beg_auth_seq_id"),s=e.getColumn("end_auth_asym_id"),n=e.getColumn("end_auth_seq_id"),r=e.rowCount;for(let e=0;e<r;++e){let r=t.getString(e),a=i.getString(e);m[r+"_"+a]=1;let o=s.getString(e),l=n.getString(e);f[o+"_"+l]=1;let d="sheet";for(let e=parseInt(a);e<=parseInt(l);++e){g[r+"_"+e]=d}}t=i=s=n=[]}let b={},C=[],v=[];if(u.getCategory("_struct_conn")){let e=u.getCategory("_struct_conn"),i=e.getColumn("conn_type_id"),s=e.getColumn("ptnr1_auth_asym_id"),n=e.getColumn("ptnr1_label_atom_id"),r=e.getColumn("ptnr1_label_seq_id"),a=e.getColumn("ptnr2_auth_asym_id"),o=e.getColumn("ptnr2_label_atom_id"),l=e.getColumn("ptnr2_label_seq_id"),d=e.rowCount;for(let e=0;e<d;++e){let d=i.getString(e),c=s.getString(e),h=n.getString(e),p=r.getString(e),u=c+"_"+p+"_"+h,m=a.getString(e),f=o.getString(e),g=l.getString(e),b=m+"_"+g+"_"+f;"covale"==d?(C.push(u),C.push(b)):"disulf"==d&&(v.push(t+"_"+c+"_"+p),v.push(t+"_"+m+"_"+g))}i=s=n=r=a=o=l=[]}let _,y,S,w,x,A,M,T,E,R,k,O,I,P,D,L=u.getCategory("_atom_site"),F={},N={id:""},U="",H={},B={},z="",q=L.rowCount,j=1,G=!(10*q>n.maxatomcnt);if(!s){y=L.getColumn("group_PDB"),S=L.getColumn("label_comp_id"),w=L.getColumn("type_symbol"),x=L.getColumn("label_atom_id"),A=L.getColumn("auth_asym_id"),M=L.getColumn("label_seq_id"),T=L.getColumn("auth_seq_id"),E=L.getColumn("label_alt_id"),R=L.getColumn("B_iso_or_equiv"),k=L.getColumn("Cartn_x"),O=L.getColumn("Cartn_y"),I=L.getColumn("Cartn_z"),P=L.getColumn("label_asym_id"),D=L.getColumn("pdbx_PDB_model_num");let e={},t="";for(let i=0;i<q;++i){let s,n=y.getString(i),a=S.getString(i),o=w.getString(i),l=x.getString(i),d=A.getString(i),c=M.getString(i),h=T.getString(i),p=E.getString(i),u=P.getString(i);if(c=h,"ATOM"==n?s=3==a.length?"protein":"nucleotide":"WAT"==a||"HOH"==a?(s="solvent",d="Misc"):(s="ligand",d=a),!G&&("protein"==s&&("C"!=o||"CA"!=l)||"nucleotide"==s&&"P"!=l))continue;if("B"==p)continue;if(B[d]=1,"?"!=c&&"."!=c&&"0"!=c||(c=h),"solvent"==s||"ligand"==s){let i={};e.hasOwnProperty(d)||(e[d]=[]),3!=a.length||"HOH"==a||"WAT"==a?3==a.length&&("O"!=o||"HOH"!=a&&"WAT"!=a)||(i.resi=c,i.name=r.utilsCls.residueName2Abbr(a),e[d].push(i)):d+"_"+a==z&&t==u||(i.resi=c,i.name=r.utilsCls.residueName2Abbr(a),e[d].push(i))}let m=k.getFloat(i),f=O.getFloat(i),g=I.getFloat(i),C=j.toString();F[d+"_"+c+"_"+l]=C;let v={};v.id=C,v.elem=o,v.x=m,v.y=f,v.z=g,v.alt=p,_=d+"_"+c;let R=1.3;if(_!=U||t!=u)H={},H[_]={},H[_][v.id]=v;else{for(let e in H[_])this.hasCovalentBond(v,H[_][e],R)&&(b.hasOwnProperty(v.id)||(b[v.id]={}),b.hasOwnProperty(H[_][e].id)||(b[H[_][e].id]={}),b[v.id][H[_][e].id]=1,b[H[_][e].id][v.id]=1);H[_][v.id]=v}"N"==l&&""!=N.id&&this.hasCovalentBond(v,N,R)&&(b.hasOwnProperty(v.id)||(b[v.id]={}),b.hasOwnProperty(N.id)||(b[N.id]={}),b[v.id][N.id]=1,b[N.id][v.id]=1),"C"==l&&(N=v),U=_,z=d+"_"+a,t=u,++j}for(let e=0;e<C.length;e+=2){let t=F[C[e]],i=F[C[e+1]];b.hasOwnProperty(t)||(b[t]={}),b.hasOwnProperty(i)||(b[i]={}),b[t][i]=1,b[i][t]=1}}if(a+='{"bcif":"'+t+'", '+(""!=c?'"emd":"'+c+'",':"")+(""!=h?'"organism":"'+h+'",':"")+'"pubmedid":"'+o+'", "descr": {"name": "'+l+'", "class": "'+d+'"}',!s){a+=', "atoms":[\n',z="",j=1;let e=t;for(let i=0;i<q;++i){let s=D.getString(i);"1"!=s&&""!=s&&(e=t+s);let n,r=y.getString(i),o=S.getString(i),l=w.getString(i),d=x.getString(i),c=A.getString(i),h=M.getString(i),p=T.getString(i),u=E.getString(i),C=P.getString(i);if(h=p,"ATOM"==r?n=3==o.length?"protein":"nucleotide":"WAT"==o||"HOH"==o?(n="solvent",c="Misc"):(n="ligand",c=o),!G&&("protein"==n&&("C"!=l||"CA"!=d)||"nucleotide"==n&&"P"!=d))continue;if("B"==u)continue;"?"!=h&&"."!=h&&"0"!=h||(h=p);let v=R.getString(i),_=k.getFloat(i),L=O.getFloat(i),F=I.getFloat(i),N=j.toString(),U=c+"_"+h;a+="{",a+='"het":'+("HETATM"==r?"1":"0")+", ",a+='"serial":'+j+", ",a+='"name":"'+d+'", ',a+='"resn":"'+o+'", ',a+='"structure":"'+e+'", ',a+='"chain":"'+c+'", ',a+='"resi":'+h+", ",a+='"coord":{"x":'+_+', "y":'+L+', "z":'+F+"}, ",a+='"b":"'+v+'", ',a+='"elem":"'+l+'", ',a+='"bonds":[';let H={};b.hasOwnProperty(N)&&(H=b[N]);let B=Object.keys(H);for(let e=0,t=B.length;e<t;++e)"undefined"!==B[e]&&(a+=B[e],a+=", ");if(B.length>0&&(a=a.substr(0,a.length-2)),a+="], ",g.hasOwnProperty(U)){a+='"ss":"'+g[U]+'", '}else a+='"ss":"coil", ';m.hasOwnProperty(U)?a+='"ssbegin":1, ':a+='"ssbegin":0, ',f.hasOwnProperty(U)?a+='"ssend":1, ':a+='"ssend":0, ',a+='"mt":"'+n+'"',a+="}",a+=",\n",z=c+"_"+o,prevAutochain=C,++j}j>1&&(a=a.substr(0,a.length-2)),a+="]"}y=S=w=x=A=M=T=E=R=k=O=I=P=[];let $={};if(u.getCategory("_pdbx_poly_seq_scheme")){let e=u.getCategory("_pdbx_poly_seq_scheme"),t=e.getColumn("seq_id"),i=e.getColumn("pdb_seq_num"),s=e.getColumn("mon_id"),n=e.getColumn("pdb_strand_id"),r=e.rowCount,a="",o="";for(let e=0;e<r;++e){t.getString(e);let l=i.getString(e),d=s.getString(e),c=n.getString(e);c!=a&&(0==e||(o=o.substr(0,o.length-2),o+="]",$[a]=o),o="["),o+="["+l+', "'+d+'"]',e<r-1&&(o+=", "),a=c}o+="]",$[a]=o,t=i=s=n=[]}a+=', "sequences":{';let V=!1;for(let e in B){let t;t=ligSeqHash.hasOwnProperty(e)?"["+ligSeqHash[e]+"]":$[e],""!==t&&void 0!==t&&(a+='"'+e+'": '+t+", ",V=!0)}if(V&&(a=a.substr(0,a.length-2)),a+="}",u.getCategory("_pdbx_struct_oper_list")){let e=u.getCategory("_pdbx_struct_oper_list");a+=', "assembly":[';let t=', "pmatrix":',i=!1,s=e.rowCount;for(let n=0;n<s;++n){let r=e.getColumn("id").getString(n);if("X0"==r)continue;let o=e.getColumn("matrix[1][1]").getFloat(n),l=e.getColumn("matrix[1][2]").getFloat(n),d=e.getColumn("matrix[1][3]").getFloat(n),c=e.getColumn("vector[1]").getFloat(n),h=e.getColumn("matrix[2][1]").getFloat(n),p=e.getColumn("matrix[2][2]").getFloat(n),u=e.getColumn("matrix[2][3]").getFloat(n),m=e.getColumn("vector[2]").getFloat(n),f="["+o+","+h+","+e.getColumn("matrix[3][1]").getFloat(n)+", 0, "+l+","+p+","+e.getColumn("matrix[3][2]").getFloat(n)+", 0, "+d+","+u+","+e.getColumn("matrix[3][3]").getFloat(n)+", 0, "+c+","+m+","+e.getColumn("vector[3]").getFloat(n)+", 1]";"P"==r?(t+=f,i=!0):(a+=f,n<s-1&&(a+=", "))}a+="]",i&&(a+=t)}if(v.length>0){a+=', "disulfides":[';for(let e=0;e<v.length;e+=2)a+="[",a+='"'+v[e]+'", "'+v[e+1]+'"',a+="]",e<v.length-2&&(a+=", ");a+="]"}return a+="}",a}hasCovalentBond(e,t,i){this.icn3d.icn3dui;let s=this.mElem2Radius[e.elem]+this.mElem2Radius[t.elem],n=e.x-t.x,r=e.y-t.y,a=e.z-t.z;return n*n+r*r+a*a<i*s*s}}class Dh{constructor(e){this.icn3d=e}async loadMol2Data(e){let t=this.icn3d,i=t.icn3dui,s=this.loadMol2AtomData(e);void 0===i.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),s?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==i.cfg.rotate&&t.resizeCanvasCls.rotStruc(i.cfg.rotate,!0)):alert("The Mol2 file has the wrong format...")}loadMol2AtomData(e){let t=this.icn3d;t.icn3dui;let i=e.split(/\r?\n|\r/);if(i.length<4)return!1;t.init();let s,n,r="LIG",a={},o="1_A",l="1_A_1",d=0,c=0,h=1,p=!1,u=!1,m={},f={};for(let e=0,o=i.length;e<o;++e){let o=i[e].trim();if(""!==o&&"#"!==o.substr(0,1)){if("@<TRIPOS>MOLECULE"==o){t.molTitle=i[e+1].trim();let r=i[e+2].trim().replace(/\s+/g," ").split(" ");s=r[0],n=r[1],e+=4}else"@<TRIPOS>ATOM"==o?(h=1,p=!0,++e):"@<TRIPOS>BOND"==o?(u=!0,p=!1,++e):"@<TRIPOS>SUBSTRUCTURE"==o&&(u=!1,++e);if(o=i[e].trim(),""!==o&&"#"!==o.substr(0,1)){if(p&&d<s){let e=o.replace(/\s+/g," ").split(" "),i=parseInt(e[0]);m[i]=h;let s,n=e[1],l=parseFloat(e[2]),c=parseFloat(e[3]),p=parseFloat(e[4]),u=new mt(l,c,p),g=e[5],b=g.indexOf(".");if(s=-1===b?g:g.substr(0,b),"H"===s&&s===g)f[i]=1;else{let e={het:!0,serial:h,name:n,resn:r,structure:1,chain:"A",resi:1,coord:u,b:0,elem:s,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};t.atoms[h]=e,a[h]=1,++h}++d}if(u&&c<n){let e=o.replace(/\s+/g," ").split(" "),i=parseInt(e[1]),s=parseInt(e[2]),n=e[3],r=n;if("am"===n&&(r="1"),"ar"===n&&(r="1.5"),!(f.hasOwnProperty(i)||f.hasOwnProperty(s)||"1"!==r&&"2"!==r&&"3"!==r&&"1.5"!==r)){let e=r,n=m[i],a=m[s];t.atoms[n].bonds.push(a),t.atoms[n].bondOrder.push(e),t.atoms[a].bonds.push(n),t.atoms[a].bondOrder.push(e),"2"==e?(t.doublebonds[n+"_"+a]=1,t.doublebonds[a+"_"+n]=1):"3"==e?(t.triplebonds[n+"_"+a]=1,t.triplebonds[a+"_"+n]=1):"1.5"==e&&(t.aromaticbonds[n+"_"+a]=1,t.aromaticbonds[a+"_"+n]=1)}++c}}}}t.dAtoms=a,t.hAtoms=a,t.structures[1]=[o],t.chains[o]=a,t.residues[l]=a,t.residueId2Name[l]=r,void 0===t.chainsSeq[o]&&(t.chainsSeq[o]=[]);let g={resi:1};return g.name=r,t.chainsSeq[o].push(g),t.ParserUtilsCls.setMaxD(),t.saveFileCls.showTitle(),!0}}class Lh{constructor(e){this.icn3d=e}async downloadOpm(e){let t=this.icn3d,i=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(OPM) in iCn3D"),t.bStopRotate=!0;let s="https://opm-assets.storage.googleapis.com/pdb/"+e.toLowerCase()+".pdb",n=await i.getAjaxPromise(s,"text",!0,"This is probably not a transmembrane protein. It has no data in Orientations of Proteins in Membranes(OPM) database.");t.bOpm=!0,await t.pdbParserCls.loadPdbData(n,e,t.bOpm),$("#"+t.pre+"selectplane_z1").val(t.halfBilayerSize),$("#"+t.pre+"selectplane_z2").val(-t.halfBilayerSize),$("#"+t.pre+"extra_mem_z").val(t.halfBilayerSize),$("#"+t.pre+"intra_mem_z").val(-t.halfBilayerSize)}async loadOpmData(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui;try{t||(t=a.defaultPdbId);let l=o.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&opm&uid="+t.toLowerCase(),d=await o.getAjaxPromise(l,"jsonp",!1);this.setOpmData(d),await this.parseAtomData(e,t,i,s,n,r)}catch(a){await this.parseAtomData(e,t,i,s,n,r)}}setOpmData(e){let t=this.icn3d;t.icn3dui,void 0!==e.opm&&void 0!==e.opm.rot?(t.bOpm=!0,t.halfBilayerSize=e.opm.thickness,t.rmsd_supr={},t.rmsd_supr.rot=e.opm.rot,t.rmsd_supr.trans1=new mt(e.opm.trans1[0],e.opm.trans1[1],e.opm.trans1[2]),t.rmsd_supr.trans2=new mt(e.opm.trans2[0],e.opm.trans2[1],e.opm.trans2[2]),t.rmsd_supr.rmsd=e.opm.rmsd,$("#"+t.pre+"selectplane_z1").val(t.halfBilayerSize),$("#"+t.pre+"selectplane_z2").val(-t.halfBilayerSize),$("#"+t.pre+"extra_mem_z").val(t.halfBilayerSize),$("#"+t.pre+"intra_mem_z").val(-t.halfBilayerSize)):t.bOpm=!1}modifyUIMapAssembly(){let e=this.icn3d;e.icn3dui.bNode||(void 0!==e.emd?($("#"+e.pre+"mapWrapper1").hide(),$("#"+e.pre+"mapWrapper2").hide(),$("#"+e.pre+"mapWrapper3").hide()):($("#"+e.pre+"emmapWrapper1").hide(),$("#"+e.pre+"emmapWrapper2").hide(),$("#"+e.pre+"emmapWrapper3").hide()),1==Object.keys(e.structures).length&&$("#"+e.pre+"alternateWrapper").hide(),void 0!==e.biomtMatrices&&e.biomtMatrices.length>1&&($("#"+e.pre+"assemblyWrapper").show(),e.asuCnt=e.biomtMatrices.length))}async parseAtomData(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui;"mmcif"===s||"bcif"===s?(a.loadCIFCls.loadCIF(e,t,r),this.modifyUIMapAssembly(),a.setStyleCls.setAtomStyleByOptions(a.opts),a.setColorCls.setColorByOptions(a.opts,a.atoms),await a.ParserUtilsCls.renderStructure(),void 0!==o.cfg.rotate&&a.resizeCanvasCls.rotStruc(o.cfg.rotate,!0)):"pdb"===s?await a.pdbParserCls.loadPdbData(e,t):"align"===s&&(a.bOpm?await a.alignParserCls.downloadAlignmentPart2(t):void 0!==n?await this.loadOpmData(e,n,i,s):await a.alignParserCls.downloadAlignmentPart2(t))}}class Fh{constructor(e){this.icn3d=e}async downloadPdb(e,t){let i,s=this.icn3d,n=s.icn3dui;t?(i="https://alphafold.ebi.ac.uk/files/AF-"+e+"-F1-model_"+s.AFUniprotVersion+".pdb",n.cfg.refseqid?s.ParserUtilsCls.setYourNote(n.cfg.refseqid.toUpperCase()+"(NCBI Protein Acc.) in iCn3D"):n.cfg.protein?s.ParserUtilsCls.setYourNote(n.cfg.protein+"(NCBI Protein/Gene) in iCn3D"):s.ParserUtilsCls.setYourNote(e.toUpperCase()+"(AlphaFold) in iCn3D")):(i="https://files.rcsb.org/download/"+e+".pdb",e=e.toUpperCase(),s.ParserUtilsCls.setYourNote(e+"(PDB) in iCn3D"));let r=await n.getAjaxPromise(i,"text",!0,"The ID "+e+" can not be found in the server "+i+"...");if(t){r="HEADER "+e+"\n"+r,await s.opmParserCls.parseAtomData(r,e,void 0,"pdb",void 0)}else await s.opmParserCls.loadOpmData(r,e,void 0,"pdb")}async downloadUrl(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=e.lastIndexOf("/");if(-1!=a){let t=e.lastIndexOf(".");n.filename=e.substr(a+1,t-a-1)}else{let t=e.lastIndexOf(".");n.filename=e.substr(0,t)}let o=await r.getAjaxPromise(e,"text",!0);if(n.InputfileData=n.InputfileData?n.InputfileData+"\nENDMDL\n"+o:o,n.InputfileType=t,n.hAtoms={},n.dAtoms={},n.resetConfig(),n.bResetAnno=!0,n.bResetSets=!0,"pdb"===t){let e=!0,t=s?s.replace(/_/g,"").substr(0,4):void 0;await this.loadPdbData(o,t,void 0,e)}else if("mmcif"===t){let e=!0;await n.opmParserCls.loadOpmData(o,void 0,void 0,"mmcif",void 0,e)}else if("mol2"===t)await n.mol2ParserCls.loadMol2Data(o);else if("sdf"===t)await n.sdfParserCls.loadSdfData(o);else if("xyz"===t)await n.xyzParserCls.loadXyzData(o);else if("mmcif"===t)await n.mmcifParserCls.loadMmcifData(o);else if("icn3dpng"===t)await r.htmlCls.setHtmlCls.loadPng(o,i,!0);else if("pae"===t){r.htmlCls.dialogCls.openDlg("dl_alignerrormap","Show Predicted Aligned Error (PAE) map");let e=!0;n.contactMapCls.processAfErrorMap(JSON.parse(o),e)}n.bSetChainsAdvancedMenu&&n.definedSetsCls.showSets(),n.bResetAnno=!0,n.bAnnoShown&&(await n.showAnnoCls.showAnnotations(),n.annotationCls.resetAnnoTabAll())}async loadPdbData(e,t,i,s,n,r,a,o){let l=this.icn3d,d=l.icn3dui;if(!s&&(void 0===n||"target"===n)){let e=!!l.bCommandLoad;l.bStatefile||l.init(e)}let c=await l.loadPDBCls.loadPDB(e,t,i,void 0,void 0,s,n,o);return void 0===d.cfg.opmid&&l.ParserUtilsCls.transformToOpmOri(t),void 0!==l.biomtMatrices&&l.biomtMatrices.length>1&&(d.bNode||$("#"+l.pre+"assemblyWrapper").show(),l.asuCnt=l.biomtMatrices.length),d.bNode||(void 0!==l.emd?($("#"+l.pre+"mapWrapper1").hide(),$("#"+l.pre+"mapWrapper2").hide(),$("#"+l.pre+"mapWrapper3").hide()):($("#"+l.pre+"emmapWrapper1").hide(),$("#"+l.pre+"emmapWrapper2").hide(),$("#"+l.pre+"emmapWrapper3").hide())),await this.addSecondary(s,a),c}async addSecondary(e,t){let i=this.icn3d,s=i.icn3dui,n=!1;i.bSecondaryStructure&&1==Object.keys(i.structures).length?n=!1:s.cfg.mmtfid||s.cfg.pdbid||s.cfg.opmid||s.cfg.mmdbid||s.cfg.gi||s.cfg.uniprotid||s.cfg.blast_rep_id||s.cfg.cid||s.cfg.mmcifid||s.cfg.align||s.cfg.chainalign||(n=!0),(!i.bSecondaryStructure||n)&&Object.keys(i.proteins).length>0&&!t?await this.applyCommandDssp(e):(await this.loadPdbDataRender(e),s.bNode||await i.ParserUtilsCls.checkMemProteinAndRotate())}async applyCommandDssp(e){let t=this.icn3d,i=t.icn3dui,s=i.utilsCls.isCalphaPhosOnly(i.hashUtilsCls.hash2Atoms(t.proteins,t.atoms));await t.dsspCls.applyDssp(s,e)}async loadPdbDataRender(e){let t=this.icn3d,i=t.icn3dui;if(void 0===i.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),(i.cfg.afid&&!t.bAfMem||t.bEsmfold)&&(t.opts.color="confidence"),t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.hAtoms),await t.ParserUtilsCls.renderStructure(),t.saveFileCls.showTitle(),void 0!==i.cfg.rotate&&t.resizeCanvasCls.rotStruc(i.cfg.rotate,!0),e&&!i.bNode&&t.definedSetsCls.setModeAndDisplay("all"),t.struct_statefile)for(let e=0,i=t.struct_statefile.length;e<i;++e)await this.execStatefile(t.struct_statefile[e].structure,t.struct_statefile[e].statefile)}async execStatefile(e,t){let i=this.icn3d,s=i.icn3dui;if(!t)return;let n=t.trim().split("\n");n=["select $"+e].concat(n),i.STATENUMBER=n.length,i.CURRENTNUMBER=0;let r=s.hashUtilsCls.cloneHash(i.hAtoms),a=i.commands;i.hAtoms={},i.commands=n,await i.loadScriptCls.execCommands(i.CURRENTNUMBER,i.STATENUMBER-1,i.STATENUMBER,!0),i.hAtoms=s.hashUtilsCls.cloneHash(r),i.commands=a.concat(i.commands)}}class Nh{constructor(e){this.icn3d=e}async downloadCid(e){let t=this.icn3d,i=t.icn3dui;t.ParserUtilsCls.setYourNote("PubChem CID "+e+" in iCn3D"),t.bCid=!0;let s="https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+t.inputid+"/cids/JSONP?cids_type=parent",n="https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+(await i.getAjaxPromise(s,"jsonp",!0,"Can not retrieve the parent CID...")).IdentifierList.CID[0]+"/record/SDF/?record_type=3d&response_type=display",r=await i.getAjaxPromise(n,"text",!0,"This CID may not have 3D structure..."),a=this.loadSdfAtomData(r,e);void 0===i.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),a?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==i.cfg.rotate&&t.resizeCanvasCls.rotStruc(i.cfg.rotate,!0)):alert("The SDF of CID "+e+" has the wrong format...")}async downloadSmiles(e){let t=this.icn3d,i=t.icn3dui,s=i.htmlCls.baseUrl+"openbabel/openbabel.cgi?smiles2sdf="+e,n=await i.getAjaxPromise(s,"text");t.init(),t.InputfileData=t.InputfileData?t.InputfileData+"\nENDMDL\n"+n:n,t.InputfileType="sdf",await t.sdfParserCls.loadSdfData(n)}async loadSdfData(e){let t=this.icn3d,i=t.icn3dui,s=this.loadSdfAtomData(e);void 0===i.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),s?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==i.cfg.rotate&&t.resizeCanvasCls.rotStruc(i.cfg.rotate,!0)):alert("The SDF file has the wrong format...")}loadSdfAtomData(e,t){let i=this.icn3d;i.icn3dui;let s=e.split(/\r?\n|\r/);if(s.length<4)return!1;i.init();let n=t||1,r="LIG",a=n,o=n+"_A",l=o+"_1",d=parseInt(s[3].substr(0,3));if(isNaN(d)||d<=0)return!1;let c=parseInt(s[3].substr(3,3)),h=4;if(s.length<h+d+c)return!1;let p,u,m=d,f={},g={},b={},C=1;for(p=0;p<m;p++){u=s[h],h++;let e=u.substr(31,3).trim(),t=parseFloat(u.substr(0,10)),a=parseFloat(u.substr(10,10)),o=parseFloat(u.substr(20,10)),l={het:!0,serial:C,name:e,resn:r,structure:n,chain:"A",resi:1,coord:new mt(t,a,o),b:0,elem:e,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};i.atoms[C]=l,b[C]=1,f[p]=C,++C,"H"==e&&(g[p]=1)}i.dAtoms=b,i.hAtoms=b,i.structures[a]=[o],i.chains[o]=b,i.residues[l]=b,i.residueId2Name[l]=r,void 0===i.chainsSeq[o]&&(i.chainsSeq[o]=[]);let v={resi:1};for(v.name=r,i.chainsSeq[o].push(v),p=0;p<c;p++){u=s[h],h++;let e=parseInt(u.substr(0,3))-1+0,t=parseInt(u.substr(3,3))-1+0,n=u.substr(6,3).trim(),r=f[e],a=f[t];i.atoms[r].bonds.push(a),i.atoms[r].bondOrder.push(n),i.atoms[a].bonds.push(r),i.atoms[a].bondOrder.push(n),g.hasOwnProperty(e)||g.hasOwnProperty(t)||("2"==n?(i.doublebonds[r+"_"+a]=1,i.doublebonds[a+"_"+r]=1):"3"==n&&(i.triplebonds[r+"_"+a]=1,i.triplebonds[a+"_"+r]=1))}let _=!1;for(let e=s.length;h<e;++h)if(-1!=s[h].indexOf("PARTIAL_CHARGES")){_=!0;break}if(_){++h;let e=parseInt(s[h]);for(++h,p=0;p<e;++p,++h){u=s[h];let e=u.split(" "),t=parseInt(e[0]),n=parseFloat(e[1]);i.atoms[t].crg=n}}for(p in i.atoms)"H"!==i.atoms[p].name&&(i.atoms[p].bonds2=i.atoms[p].bonds.concat(),i.atoms[p].bondOrder2=i.atoms[p].bondOrder.concat());return i.ParserUtilsCls.setMaxD(),i.saveFileCls.showTitle(),!0}}class Uh{constructor(e){this.icn3d=e}async loadXyzData(e){let t=this.icn3d,i=t.icn3dui,s=this.loadXyzAtomData(e);void 0===i.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),s?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==i.cfg.rotate&&t.resizeCanvasCls.rotStruc(i.cfg.rotate,!0)):alert("The XYZ file has the wrong format...")}setXyzAtomSeq(e,t,i,s){let n=this.icn3d,r=n.icn3dui;n.dAtoms=r.hashUtilsCls.unionHash(n.dAtoms,e),n.hAtoms=r.hashUtilsCls.unionHash(n.hAtoms,e),n.structures[t]=[i],n.chains[i]=e,n.residues[s]=e,n.residueId2Name[s]="LIG",void 0===n.chainsSeq[i]&&(n.chainsSeq[i]=[]);let a={resi:1,name:"LIG"};n.chainsSeq[i].push(a);let o=Object.keys(e);for(let e=0,t=o.length;e<t;++e){let t=n.atoms[o[e]];for(let i=e+1,s=o.length;i<s;++i){let s=n.atoms[o[i]],a=1.2*(r.parasCls.covalentRadii[t.elem.toUpperCase()]+r.parasCls.covalentRadii[s.elem.toUpperCase()]);Math.abs(t.coord.x-s.coord.x)>a||(Math.abs(t.coord.y-s.coord.y)>a||Math.abs(t.coord.z-s.coord.z)>a||r.utilsCls.hasCovalentBond(t,s)&&(n.atoms[o[e]].bonds.push(o[i]),n.atoms[o[i]].bonds.push(o[e])))}}}loadXyzAtomData(e){let t=this.icn3d;t.icn3dui;let i=e.split(/\r?\n|\r/);if(i.length<3)return!1;t.init();let s,n,r,a={},o=0,l=1;t.molTitle="";for(let e=0,d=i.length;e<d;++e){let d=i[e].trim();if(""===d)continue;if(""===d||isNaN(d)||(0!==e&&this.setXyzAtomSeq(a,o,s,n),++o,a={},r=o,s=r+"_A",n=s+"_1",o>1&&(t.molTitle+="; "),t.molTitle+=i[e+1].trim(),e+=2),d=i[e].trim(),""===d)continue;let c=d.replace(/,/," ").replace(/\s+/g," ").split(" "),h=c[0],p=parseFloat(c[1]),u=parseFloat(c[2]),m=parseFloat(c[3]),f={het:!0,serial:l,name:h,resn:"LIG",structure:r,chain:"A",resi:1,coord:new mt(p,u,m),b:0,elem:h,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};t.atoms[l]=f,a[l]=1,++l}return this.setXyzAtomSeq(a,o,s,n),t.ParserUtilsCls.setMaxD(),t.saveFileCls.showTitle(),!0}}class Hh{constructor(e){this.icn3d=e}async loadMsaData(e,t){let i=this.icn3d,s=i.icn3dui,n=await this.loadMsaSeqData(e,t);void 0===s.cfg.align&&1==Object.keys(i.structures).length&&$("#"+i.pre+"alternateWrapper").hide();let r=t.toUpperCase();if(n){s.cfg.bu=0,await i.chainalignParserCls.downloadMmdbAf(i.struArray.join(",")),s.htmlCls.clickMenuCls.setLogCmd("load mmdbaf0 "+i.struArray.join(","),!0);let e=[];for(let t=0,s=i.inputChainidArray.length;t<s;++t){let s=i.inputChainidArray[t],n=i.inputSeqArray[t].replace(/-/g,""),r="";for(let e=0,t=i.chainsSeq[s].length;e<t;++e)r+=i.chainsSeq[s][e].name;let a=r.toUpperCase().indexOf(n.substr(0,20).toUpperCase());-1==a&&(console.log("The sequence of the aligned chain "+s+" ("+n.toUpperCase()+") is different from the sequence from the structure ("+r.toUpperCase()+"), and is thus not aligned correctly..."),a=0),e.push(a)}let t="",n=i.inputChainidArray[0],r=i.inputSeqArray[0],a=e[0];for(let s=1,o=i.inputChainidArray.length;s<o;++s){let l=i.inputChainidArray[s],d=i.inputSeqArray[s],c=a,h=e[s],p=[],u=[];for(let e=0,t=d.length;e<t;++e){if("-"!=r[e]&&"-"!=d[e]&&i.chainsSeq[n][c]&&i.chainsSeq[l][h]){let e=i.chainsSeq[n][c].resi,t=i.chainsSeq[l][h].resi;i.residues[n+"_"+e]&&i.residues[l+"_"+t]&&(p.push(i.chainsSeq[n][c].resi),u.push(i.chainsSeq[l][h].resi))}"-"!=r[e]&&++c,"-"!=d[e]&&++h}t+=i.resid2specCls.resi2range(p,!0)+" | "+i.resid2specCls.resi2range(u,!0),s<o-1&&(t+=": ")}let o=i.inputChainidArray.join(",");if(t&&o.split(",").length-1!=t.split(": ").length)return void alert("Please make sure the number of chains and the lines of predefined residues are the same...");s.cfg.resdef=t.replace(/:/gi,";");let l=!0,d=!0,c=o.split(",");await i.realignParserCls.realignChainOnSeqAlign(void 0,c,l,d),s.htmlCls.clickMenuCls.setLogCmd("realign predefined "+o+" "+t,!0),i.opts.color="identity",i.setColorCls.setColorByOptions(i.opts,i.hAtoms),s.htmlCls.clickMenuCls.setLogCmd("color identity",!0),i.selectionCls.showSelection(),s.htmlCls.clickMenuCls.setLogCmd("show selection",!0)}else alert("The "+r+" file has the wrong format...")}async loadMsaSeqData(e,t){let i=this.icn3d;i.icn3dui;let s=e.split(/\r?\n|\r/);if(s.length<2)return!1;i.init(),i.molTitle="";let n={},r=!1,a=!1,o="",l="",d=!1;if("clustalw"==t&&"CLUSTAL"!=s[0].substr(0,7))return!1;for(let e="clustalw"==t?1:0,i=s.length;e<i;++e){let i=s[e].trim();if(""!==i){if(!r){if("fasta"==t&&">"!=i.substr(0,1))return!1;r=!0}if("clustalw"==t){if(" "!=i.substr(0,1)&&"\t"!=i.substr(0,1)){let e=i.split(/\s+/),t=e[0].split("|"),s=this.getChainid(t,r&&!a);d=s.bFound,o=s.chainid,d&&(n.hasOwnProperty(o)?n[o]+=e[1]:n[o]=e[1])}}else if("fasta"==t)if(">"==i.substr(0,1)){o&&l&&d&&(n[o]=l),o="",l="";let e=i.indexOf(" "),t=i.substr(1,e).split("|");if(1==t.length)o=t[0];else{let e=this.getChainid(t,!0);d=e.bFound,o=e.chainid}}else l+=i}else r&&(a=!0),r=!1}"fasta"==t&&o&&l&&d&&(n[o]=l),i.inputChainidArray=[],i.inputSeqArray=[],i.struArray=[];let c="";for(let e in n){if("-"!=n[e].substr(0,1)){c=e,await this.processOneChain(e,n);break}}c||(c=Object.keys(n)[0]);for(let e in n)e!=c&&await this.processOneChain(e,n);return!0}async processOneChain(e,t){let i=this.icn3d,s=i.icn3dui;if(i.inputSeqArray.push(t[e]),2==e.lastIndexOf("_")){let t=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?refseq2uniprot="+e,n=await s.getAjaxPromise(t,"jsonp",!1,"The protein accession "+e+" can not be mapped to AlphaFold UniProt ID...");if(n&&n.uniprot){i.uniprot2acc||(i.uniprot2acc={});let t=n.uniprot;i.uniprot2acc[t]=e,i.struArray.push(t),i.inputChainidArray.push(t+"_A")}else console.log("The accession "+refseqid+" can not be mapped to AlphaFold UniProt ID. It will be treated as a UniProt ID instead."),i.struArray.push(e),i.inputChainidArray.push(e+"_A")}else if(-1!=e.indexOf("_")){let t=e.substr(0,e.indexOf("_")).substr(0,4);i.struArray.push(t),i.inputChainidArray.push(e)}else e.length>5&&(i.struArray.push(e),i.inputChainidArray.push(e+"_A"))}getChainid(e,t){this.icn3d.icn3dui;let i=!1,s=e[0];for(let t=0,n=e.length;t<n;++t){if("pdb"==e[t]){s=e[t+1]+"_"+e[t+2],i=!0;break}if("ref"==e[t]){s=e[t+1].split(".")[0],i=!0;break}if("sp"==e[t]||"tr"==e[t]){s=e[t+1],i=!0;break}}return!i&&t&&alert("The sequence ID "+e.join("|")+" does not have the correctly formatted PDB, UniProt or RefSeq ID..."),{chainid:s,bFound:i}}}class Bh{constructor(e){this.icn3d=e}realign(){let e=this.icn3d,t=e.icn3dui;e.selectionCls.saveSelectionPrep();let i="alseq_"+(Object.keys(e.defNames2Atoms).length+Object.keys(e.defNames2Residues).length+1);e.selectionCls.saveSelection(i,i),t.htmlCls.clickMenuCls.setLogCmd("realign",!0);let s={},n={};e.realignResid={};let r="";for(let i in e.hAtoms){let a=e.atoms[i],o=a.structure+"_"+a.chain;if(e.proteins.hasOwnProperty(i)&&"CA"==a.name||e.nucleotides.hasOwnProperty(i)&&("O3'"==a.name||"O3*"==a.name)){if(a.structure+"_"+a.resi==r)continue;s.hasOwnProperty(a.structure)||(s[a.structure]=[]),s[a.structure].push(a.coord.clone()),e.realignResid.hasOwnProperty(o)||(e.realignResid[o]=[]),e.realignResid[o].push({resid:o+"_"+a.resi,resn:t.utilsCls.residueName2Abbr(a.resn.substr(0,3)).substr(0,1)}),n[a.structure]=a.structure+"_"+a.chain,r=a.structure+"_"+a.resi}}let a=Object.keys(s),o=a[0],l=[];e.qt_start_end=[],l.push(n[o]);for(let t=1,i=a.length;t<i;++t){let i=a[t],r=s[i],d=s[o],c=!0;e.ParserUtilsCls.alignCoords(r,d,i,c,n[o],n[i]),l.push(n[i])}e.hAtoms=e.chainalignParserCls.setMsa(l),i="protein_aligned",e.selectionCls.saveSelection(i,i),e.transformCls.zoominSelection(),e.hlUpdateCls.updateHlAll()}async parseChainRealignPredefined(e,t,i,s){let n,r=this.icn3d,a=r.icn3dui,o=e[0].substr(0,e[0].indexOf("_")),l={};r.realignResid={},r.opts.color="grey",r.setColorCls.setColorByOptions(r.opts,r.dAtoms),r.qt_start_end=[];let d={};for(let c=0,h=e.length-1;c<h;++c){let h=e[c+1].substr(0,e[c+1].indexOf("_")),p=o+e[0].substr(e[0].indexOf("_")),u=h+e[c+1].substr(e[c+1].indexOf("_"));d[p]=1,d[u]=1,e[0]=p,e[c+1]=u;let m=p+","+u;if(!t[m])continue;let f=t[m][o],g=t[m][h],b=i[m][o],C=i[m][h],v=s[m][o],_=s[m][h];r.realignResid[p]=[],r.realignResid[u]=[];for(let e=0,t=f.length;e<t;++e)r.realignResid[p].push({resid:v[e],resn:f[e]}),r.realignResid[u].push({resid:_[e],resn:g[e]});let y=!0,S=r.ParserUtilsCls.alignCoords(C,b,h,void 0,p,u,c+1,y);l=a.hashUtilsCls.unionHash(l,S.hAtoms),n=parseFloat(S.rmsd)}if(!a.cfg.usepdbnum&&a.cfg.resdef&&n>5&&a.cfg.chainalign){console.log("RMSD from VAST is larger than 5. Realign the chains with TM-align.");let e=Object.keys(d);e.length>0&&(r.hAtoms=r.definedSetsCls.getAtomsFromNameArray(e)),a.cfg.aligntool="tmalign",await r.realignParserCls.realignOnStructAlign()}else r.hAtoms=r.chainalignParserCls.setMsa(e),r.transformCls.zoominSelection(),await r.chainalignParserCls.downloadChainalignmentPart3(void 0,e,r.hAtoms)}async parseChainRealignData(e,t,i,s,n,r,a){let o=this.icn3d,l=o.icn3dui,d=i[0].substr(0,i[0].indexOf("_"));a||(d=d.toUpperCase());let c={};o.realignResid={},o.opts.color="grey",o.setColorCls.setColorByOptions(o.opts,o.dAtoms),o.qt_start_end=[];for(let t=0,h=e.length;t<h;++t){let h=e[t].value;if(!h)continue;let p=i[t+1].substr(0,i[t+1].indexOf("_"));a||(p=p.toUpperCase());let u=d+i[0].substr(i[0].indexOf("_")),m=p+i[t+1].substr(i[t+1].indexOf("_"));i[0]=u,i[t+1]=m;let f,g,b=s[u],C=s[m],v=n[u],_=n[m],y=r[u],S=r[m];if(void 0!==h.data){f=h.data[0].query;let e=Object.keys(h.data[0].targets)[0];g=h.data[0].targets[e],g=g.hsps[0]}if(void 0!==f&&void 0!==g){let e=[],i=[],s="",n="";o.realignResid[u]=[],o.realignResid[m]=[];let r=g.segs;for(let t=0,a=r.length;t<a;++t){let a=r[t],l="",d="";for(let t=0;t<=a.orito-a.orifrom;++t){let r=y[t+a.orifrom].substr(0,y[t+a.orifrom].lastIndexOf("_")),c=S[t+a.from].substr(0,S[t+a.from].lastIndexOf("_"));v[t+a.orifrom]&&_[t+a.from]&&(e.push(v[t+a.orifrom]),i.push(_[t+a.from]),s+=b[t+a.orifrom],n+=C[t+a.from],(0==t||l==r&&d==c||l!=r&&d!=c)&&(o.realignResid[u].push({resid:y[t+a.orifrom],resn:b[t+a.orifrom]}),o.realignResid[m].push({resid:S[t+a.from],resn:C[t+a.from]})),l=r,d=c)}}let a,h=!0;a=o.bAfMem?o.ParserUtilsCls.alignCoords(i,e,d,void 0,u,m,t+1,h):o.ParserUtilsCls.alignCoords(i,e,p,void 0,u,m,t+1,h),c=l.hashUtilsCls.unionHash(c,a.hAtoms)}else void 0!==p||l.cfg.command?b&&C&&((b.length<6||C.length<6)&&!l.cfg.command?o.bRender&&alert("These sequences are too short for alignment"):b.length>=6&&C.length>=6&&!l.cfg.command&&o.bRender&&alert("These sequences can not be aligned to each other")):o.bRender&&alert("Please do not align residues in the same structure")}if(a){o.hAtoms=o.chainalignParserCls.setMsa(i);let e="protein_aligned";if(o.selectionCls.saveSelection(e,e),o.bAfMem?(o.selectionCls.selectAll_base(),o.opts.chemicals="stick",o.opts.color="confidence",o.setColorCls.setColorByOptions(o.opts,o.atoms)):(o.transformCls.zoominSelection(),o.dAtoms=l.hashUtilsCls.cloneHash(o.hAtoms),o.opts.color="identity",o.setColorCls.setColorByOptions(o.opts,o.hAtoms)),o.drawCls.draw(),o.hlUpdateCls.updateHlAll(),o.bAfMem){let e=new mt(1,0,0),t=-.5*Math.PI;o.transformCls.setRotation(e,t)}}else o.hAtoms=o.chainalignParserCls.setMsa(i),o.transformCls.zoominSelection(),await o.chainalignParserCls.downloadChainalignmentPart3(t,i,o.hAtoms)}async realignOnSeqAlign(e){let t=this.icn3d;t.icn3dui;let i=t.firstAtomObjCls.getChainsFromAtoms(t.hAtoms),s=Object.keys(i),n=[],r="";for(let e=0,t=s.length;e<t;++e)s[e]!=r&&n.push(s[e]),r=s[e];t.qt_start_end=[],await this.realignChainOnSeqAlign(void 0,n,!0)}async realignOnStructAlign(e,t){let i=this.icn3d,s=i.icn3dui,n="tmalign"!=s.cfg.aligntool?3:0,r=[],a=[],o=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",l=s.htmlCls.baseUrl+"tmalign/tmalign.cgi",d={};if(t&&s.cfg.resrange){let e=decodeURIComponent(s.cfg.resrange).split(" | "),t=i.realignParserCls.getSeqCoorResid([e[0]],i.chainidArray[0],!0).hAtoms;for(let n=1,d=i.chainidArray.length;n<d;++n){let d,c=i.realignParserCls.getSeqCoorResid([e[n]],i.chainidArray[n],!0).hAtoms;if("tmalign"!=s.cfg.aligntool){let e={domains1:i.domain3dCls.getDomainJsonForAlign(c),domains2:i.domain3dCls.getDomainJsonForAlign(t)};d=s.getAjaxPostPromise(o,e)}else{let e={pdb_query:i.saveFileCls.getAtomPDB(c),pdb_target:i.saveFileCls.getAtomPDB(t)};d=s.getAjaxPostPromise(l,e)}r.push(d),a.push(i.chainidArray[0]+","+i.chainidArray[n])}}else{for(let e in i.structures){d[e]={};let t=i.structures[e];for(let r=0,a=t.length;r<a;++r){let a=t[r],o=s.hashUtilsCls.intHash(i.hAtoms,i.chains[a]),l=0;for(let t in o)if(i.atoms[t].ssbegin&&++l,l>n){d[e][a]=o;break}}}let t=Object.keys(d);e&&(t=t.reverse());for(let e=0,n=t.length;e<n;++e){let n=t[e],c=Object.keys(d[n]);if(0!=c.length)for(let h=0,p=c.length;h<p;++h){let p=c[h],u=i.domain3dCls.getDomainJsonForAlign(d[n][p]);for(let c=e+1,h=t.length;c<h;++c){let e=t[c],h=Object.keys(d[e]);if(0!=h.length)for(let t=0,c=h.length;t<c;++t){let c,m=h[t];if("tmalign"!=s.cfg.aligntool){let t={domains1:i.domain3dCls.getDomainJsonForAlign(d[e][m]),domains2:u};c=s.getAjaxPostPromise(o,t)}else{let t=i.saveFileCls.getAtomPDB(d[n][p],void 0,void 0,void 0,void 0,n),r={pdb_query:i.saveFileCls.getAtomPDB(d[e][m],void 0,void 0,void 0,void 0,e),pdb_target:t};c=s.getAjaxPostPromise(l,r)}r.push(c),a.push(p+","+m)}}}}}let c=Promise.allSettled(r),h=await c;i.qt_start_end=[],await i.chainalignParserCls.downloadChainalignmentPart2bRealign(h,a,e)}async realignOnStructAlignMsa(e){let t=this.icn3d,i=t.icn3dui,s="tmalign"!=i.cfg.aligntool?3:0,n={};for(let r=0,a=e.length;r<a;++r){let a=e[r],o=i.hashUtilsCls.intHash(t.hAtoms,t.chains[a]),l=0;for(let e in o)if(t.atoms[e].ssbegin&&++l,l>s){n[a]=o;break}}let r=[],a=[],o=[],l=i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",d=i.htmlCls.baseUrl+"tmalign/tmalign.cgi",c=e[0],h=c.substr(0,c.indexOf("_")),p=t.domain3dCls.getDomainJsonForAlign(n[c]);for(let s=1,u=e.length;s<u;++s){let u,m=e[s],f=m.substr(0,m.indexOf("_"));if("tmalign"!=i.cfg.aligntool){let e={domains1:t.domain3dCls.getDomainJsonForAlign(n[m]),domains2:p};u=i.getAjaxPostPromise(l,e)}else{let e=t.saveFileCls.getAtomPDB(t.chains[c],void 0,void 0,void 0,void 0,h),s={pdb_query:t.saveFileCls.getAtomPDB(t.chains[m],void 0,void 0,void 0,void 0,f),pdb_target:e};u=i.getAjaxPostPromise(d,s)}r.push(u),a.push(s-1),o.push(f)}let u=Promise.allSettled(r),m=await u;t.t_trans_add=[],t.q_trans_sub=[],"tmalign"==i.cfg.aligntool&&(t.q_trans_add=[]),t.q_rotation=[],t.qt_start_end=[],await t.chainalignParserCls.downloadChainalignmentPart2b(void 0,e,void 0,m,a,h,o)}async realignChainOnSeqAlign(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=this;r.cfg.aligntool="seqalign";let o,l,d,c,h,p,u={},m={},f={},g=[],b=r.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=chainalign";if(s&&(d=decodeURIComponent(r.cfg.resdef).trim().replace(/\+/gi," ").split("; "),d.length!=t.length-1))alert("Please make sure the number of chains and the lines of predefined residues are the same...");else{for(let e=0,v=t.length;e<v;++e){let v=t[e].indexOf("_"),_=t[e].substr(0,v);0==e&&(o=_);let y=_+t[e].substr(v);if(0==e&&(l=y),n.chainsSeq&&n.chainsSeq[y])if(u.hasOwnProperty(y)||s||(u[y]="",m[y]=[],f[y]=[]),s)if(0==e);else{let t={};c=d[e-1].split(" | ");let i=l+","+y;u[i]||(u[i]={}),m[i]||(m[i]={}),f[i]||(f[i]={}),p=c[0].split(","),h=a.getSeqCoorResid(p,l),t=r.hashUtilsCls.unionHash(t,h.hAtoms),u[i][o]||(u[i][o]=""),m[i][o]||(m[i][o]=[]),f[i][o]||(f[i][o]=[]),u[i][o]+=h.seq,m[i][o]=m[i][o].concat(h.coor),f[i][o]=f[i][o].concat(h.resid),p=c[1].split(","),h=a.getSeqCoorResid(p,y),t=r.hashUtilsCls.unionHash(t,h.hAtoms),u[i][_]||(u[i][_]=""),m[i][_]||(m[i][_]=[]),f[i][_]||(f[i][_]=[]),u[i][_]+=h.seq,m[i][_]=m[i][_].concat(h.coor),f[i][_]=f[i][_].concat(h.resid)}else if(0==e){if(p=[],i){let e=n.firstAtomObjCls.getResiduesFromAtoms(n.hAtoms);for(var C in e){let e=C.substr(C.lastIndexOf("_")+1);C.substr(0,C.lastIndexOf("_"))==y&&p.push(e)}}else r.cfg.resnum&&(p=r.cfg.resnum.split(","));h=a.getSeqCoorResid(p,y),u[y]+=h.seq,m[y]=m[y].concat(h.coor),f[y]=f[y].concat(h.resid)}else{let e=!1;if(i){let t=n.firstAtomObjCls.getResiduesFromAtoms(n.hAtoms);for(var C in t){if(C.substr(0,C.lastIndexOf("_"))==y){e=!0;let t=n.firstAtomObjCls.getFirstAtomObj(n.residues[C]).resn;u[y]+=r.utilsCls.residueName2Abbr(t),m[y]=m[y].concat(this.getResCoorArray(C)),f[y].push(C)}}}if(!e)for(let e=0,t=n.chainsSeq[y].length;e<t;++e){u[y]+=n.chainsSeq[y][e].name;let t=y+"_"+n.chainsSeq[y][e].resi;m[y]=m[y].concat(this.getResCoorArray(t)),f[y].push(t)}let t={targets:u[l],queries:u[y]},s=r.getAjaxPostPromise(b,t);g.push(s)}}if(s)await a.parseChainRealignPredefined(t,u,m,f);else{let s=Promise.allSettled(g);try{let n=await s;await a.parseChainRealignData(n,e,t,u,m,f,i)}catch(e){return void alert("The realignment did not work...")}}}}getSeqCoorResid(e,t,i){let s=this.icn3d,n=s.icn3dui,r="",a=[],o=[],l={};for(let l=0,d=e.length;l<d;++l)if(-1!=e[l].indexOf("-")){let d=e[l].split("-");for(let e=parseInt(d[0]);e<=parseInt(d[1]);++e){let l=i?e:s.setSeqAlignCls.getPosFromResi(t,e);if(!s.chainsSeq[t]||!s.chainsSeq[t][l]||-1==n.parasCls.b62ResArray.indexOf(s.chainsSeq[t][l].name.toUpperCase()))continue;r+=s.chainsSeq[t][l].name.toUpperCase();let d=i?s.ncbi2resid[t+"_"+e]:t+"_"+e;a=a.concat(this.getResCoorArray(d)),o.push(d)}}else if(0==e[l]){let e=s.firstAtomObjCls.getResiduesFromAtoms(s.chains[t]);o=Object.keys(e)}else{let n=e[l],d=i?n:s.setSeqAlignCls.getPosFromResi(t,n);if(!s.chainsSeq[t][d])continue;let c=i?s.ncbi2resid[t+"_"+n]:t+"_"+n,h=this.getResCoorArray(c);r+=s.chainsSeq[t][d].name.toUpperCase(),a=a.concat(h),o.push(c)}for(let e=0,t=o.length;e<t;++e)l=n.hashUtilsCls.unionHash(l,s.residues[o[e]]);return{seq:r,coor:a,resid:o,hAtoms:l}}getResCoorArray(e){let t=this.icn3d;t.icn3dui;let i=[],s=!1;for(let n in t.residues[e]){let e=t.atoms[n];if("CA"==e.name&&"C"==e.elem||("O3'"==e.name||"O3*"==e.name)&&"O"==e.elem){i.push(e.coord.clone()),s=!0;break}}return s||i.push(void 0),i}}class zh{constructor(e){this.icn3d=e}async densityCifParser(e,t,i,s,n){let r,a=this.icn3d,o=a.icn3dui,l=this,d=o.utilsCls.isMobile()||o.cfg.notebook?0:4;if("2fofc"==t||"fofc"==t){let t=a.contactCls.getExtent(a.atoms);r="https://www.ebi.ac.uk/pdbe/volume-server/x-ray/"+e.toLowerCase()+"/box/"+t[0][0]+","+t[0][1]+","+t[0][2]+"/"+t[1][0]+","+t[1][1]+","+t[1][2]+"?detail="+d}else"em"==t&&(d=o.utilsCls.isMobile()||o.cfg.notebook?0:5,r="https://www.ebi.ac.uk/pdbe/densities/emd/"+s.toLowerCase()+"/cell?detail="+d);if("2fofc"==t&&a.bAjax2fofc)a.mapData.sigma2=i,a.setOptionCls.setOption("map",t);else if("fofc"==t&&a.bAjaxfofc)a.mapData.sigma=i,a.setOptionCls.setOption("map",t);else if("em"==t&&a.bAjaxEm)a.mapData.sigmaEm=i,a.setOptionCls.setOption("emmap",t);else{let e=await o.getXMLHttpRqstPromise(r,"GET","arraybuffer",t);l.parseChannels(e,t,i),"2fofc"==t||"fofc"==t?(a.bAjax2fofc=!0,a.bAjaxfofc=!0,a.setOptionCls.setOption("map",t)):"em"==t&&(a.bAjaxEm=!0,a.setOptionCls.setOption("emmap",t))}}async densityCifParserBase(e,t,i,s,n){let r=this.icn3d,a=r.icn3dui,o=this;if("2fofc"==t&&r.bAjax2fofc)r.mapData.sigma2=i,r.setOptionCls.setOption("map",t);else if("fofc"==t&&r.bAjaxfofc)r.mapData.sigma=i,r.setOptionCls.setOption("map",t);else{let s=await a.getXMLHttpRqstPromise(e,"GET","arraybuffer",t);o.parseChannels(s,t,i),"2fofc"==t||"fofc"==t?(r.bAjax2fofc=!0,r.bAjaxfofc=!0,r.setOptionCls.setOption("map",t)):"em"==t&&(r.bAjaxEm=!0,r.setOptionCls.setOption("emmap",t))}}setMatrix(e){this.icn3d.icn3dui;let t=e.box.sampleCount,i={xExtent:t[0],yExtent:t[1],zExtent:t[2],mean:e.valuesInfo.mean,sigma:e.valuesInfo.sigma,max:e.valuesInfo.max,min:e.valuesInfo.min};for(let t=0;t<e.data.length;++t)e.data[t];let s=e.box.origin,n=e.box.dimensions,r=e.spacegroup.basis,a=(new gi).makeScale(n[0]/t[0],n[1]/t[1],n[2]/t[2]),o=(new gi).makeTranslation(s[0],s[1],s[2]);return{matrix:(new gi).set(r.x[0],r.y[0],r.z[0],0,0,r.y[1],r.z[1],0,0,0,r.z[2],0,0,0,0,1).multiply(o).multiply(a),header:i}}parseChannels(e,t,i){let s=this.icn3d;s.icn3dui;let n=this.BinaryParse(e);if("2fofc"==t||"fofc"==t){let e=this.getChannel(n,"2FO-FC"),r=this.getChannel(n,"FO-FC"),a=e,o=this.setMatrix(a);s.mapData.matrix2=o.matrix,s.mapData.header2=o.header,s.mapData.data2=a.data,s.mapData.type2=t,s.mapData.sigma2=i,a=r,o=this.setMatrix(a),s.mapData.matrix=o.matrix,s.mapData.header=o.header,s.mapData.data=a.data,s.mapData.type=t,s.mapData.sigma=i}else if("em"==t){let e=this.getChannel(n,"EM"),r=this.setMatrix(e);s.mapData.matrixEm=r.matrix,s.mapData.headerEm=r.header,s.mapData.dataEm=e.data,s.mapData.typeEm=t,s.mapData.sigmaEm=i}}getChannel(e,t){this.icn3d.icn3dui;let i,s=e.toJSON();for(let n=0,r=s.length;n<r;++n)s[n].id==t&&(i=e.dataBlocks[n]);return this.CIFParse(i)}CIFParse(e){this.icn3d.icn3dui;let t=e.getCategory("_volume_data_3d_info");if(!t)return void conole.log("_volume_data_3d_info category is missing.");if(!e.getCategory("_volume_data_3d"))return void conole.log("_volume_data_3d category is missing.");function i(e){let i=[0,0,0];for(let s=0;s<3;s++)i[s]=t.getColumn(e+"["+s+"]").getFloat(0);return i}function s(e){return t.getColumn(e).getFloat(0)}let n={name:t.getColumn("name").getString(0),axisOrder:i("axis_order"),origin:i("origin"),dimensions:i("dimensions"),sampleCount:i("sample_count"),spacegroupNumber:0|s("spacegroup_number"),cellSize:i("spacegroup_cell_size"),cellAngles:i("spacegroup_cell_angles"),mean:s("mean_sampled"),sigma:s("sigma_sampled")},r=[0,0,0];function a(e){return[e[r[0]],e[r[1]],e[r[2]]]}r[n.axisOrder[0]]=0,r[n.axisOrder[1]]=1,r[n.axisOrder[2]]=2;let o=a(n.sampleCount),l=function(e,t,i,s){let n=new Float32Array(t[0]*t[1]*t[2]),r=[0,0,0],a=s[0],o=s[1],l=s[2],d=i[0],c=i[1],h=i[2];t[0],t[0],t[1];let p=t[2],u=t[1]*t[2],m=0,f=e.getFloat(0),g=f;for(let t=0;t<h;t++){r[2]=t;for(let t=0;t<c;t++){r[1]=t;for(let t=0;t<d;t++){r[0]=t;let i=e.getFloat(m);m+=1,n[r[l]+r[o]*p+r[a]*u]=i,i<f?f=i:i>g&&(g=i)}}}return{data:n,min:f,max:g}}(e.getCategory("_volume_data_3d").getColumn("values"),o,n.sampleCount,r);return{name:n.name,spacegroup:function(e,t,i){let s=Math.PI/180*i[0],n=Math.PI/180*i[1],r=Math.PI/180*i[2],a=t[0],o=t[1],l=t[2],d=Math.cos(n),c=(Math.cos(s)-Math.cos(n)*Math.cos(r))/Math.sin(r),h=Math.sqrt(1-d*d-c*c);return{number:e,size:t,angles:i,basis:{x:[a,0,0],y:[Math.cos(r)*o,Math.sin(r)*o,0],z:[d*l,c*l,h*l]}}}(n.spacegroupNumber,n.cellSize,n.cellAngles),box:{origin:a(n.origin),dimensions:a(n.dimensions),sampleCount:o},data:l.data,valuesInfo:{min:l.min,max:l.max,mean:n.mean,sigma:n.sigma}}}BinaryParse(e){this.icn3d.icn3dui;let t=new Uint8Array(e),i=this.MessagePackParse({buffer:t,offset:0,dataView:new DataView(t.buffer)}),s=function(){function e(e){this.additionalData={},this.header=e.header,this.categoryList=e.categories.map((function(e){return new n(e)})),this.categoryMap=new Map;for(let e=0,t=this.categoryList;e<t.length;e++){let i=t[e];this.categoryMap.set(i.name,i)}}return Object.defineProperty(e.prototype,"categories",{get:function(){return this.categoryList},enumerable:!0,configurable:!0}),e.prototype.getCategory=function(e){return this.categoryMap.get(e)},e.prototype.toJSON=function(){return{id:this.header,categories:this.categoryList.map((function(e){return e.toJSON()})),additionalData:this.additionalData}},e}(),n=function(){function e(e){this.name=e.name,this.columnCount=e.columns.length,this.rowCount=e.rowCount,this.columnNameList=[],this.encodedColumns=new Map;for(let t=0,i=e.columns;t<i.length;t++){let e=i[t];this.encodedColumns.set(e.name,e),this.columnNameList.push(e.name)}}Object.defineProperty(e.prototype,"columnNames",{get:function(){return this.columnNameList},enumerable:!0,configurable:!0});let t=function(){function e(){this.isDefined=!1}return e.prototype.getString=function(e){return null},e.prototype.getInteger=function(e){return 0},e.prototype.getFloat=function(e){return 0},e.prototype.getValuePresence=function(e){return 1},e.prototype.areValuesEqual=function(e,t){return!0},e.prototype.stringEquals=function(e,t){return null===t},e}();return e.prototype.getColumn=function(e){let i=this.encodedColumns.get(e);return i?p(i):t},e.prototype.toJSON=function(){let e=this,t=[],i=this.columnNameList.map((function(t){return{name:t,column:e.getColumn(t)}}));for(let e=0;e<this.rowCount;e++){let s={};for(let t=0,n=i;t<n.length;t++){let i=n[t],r=i.column.getValuePresence(e);s[i.name]=0===r?i.column.getString(e):1===r?".":"?"}t[e]=s}return{name:this.name,columns:this.columnNames,rows:t}},e}();function r(e,t){switch(e){case 1:return new Int8Array(t);case 2:return new Int16Array(t);case 3:return new Int32Array(t);case 4:return new Uint8Array(t);case 5:return new Uint16Array(t);case 6:return new Uint32Array(t);default:throw new Error("Unsupported integer data type.")}}function a(e,t){switch(e){case 32:return new Float32Array(t);case 33:return new Float64Array(t);default:throw new Error("Unsupported floating data type.")}}let o=function(){let e=new ArrayBuffer(2),t=new Uint8Array(e),i=new Uint16Array(e);return t[0]=170,t[1]=187,48042===i[0]}();function l(e,t,i){return new i(o?e.buffer:function(e,t){let i=new ArrayBuffer(e.length),s=new Uint8Array(i);for(let i=0,n=e.length;i<n;i+=t)for(let n=0;n<t;n++)s[i+t-n-1]=e[i+n];return i}(e,t))}function d(e,t){return t.isUnsigned?function(e,t){let i=1===t.byteCount?255:65535,s=e.length,n=new Int32Array(t.srcSize),r=0,a=0;for(;r<s;){let t=0,s=e[r];for(;s===i;)t+=s,r++,s=e[r];t+=s,n[a]=t,r++,a++}return n}(e,t):function(e,t){let i=1===t.byteCount?127:32767,s=-i-1,n=e.length,r=new Int32Array(t.srcSize),a=0,o=0;for(;a<n;){let t=0,n=e[a];for(;n===i||n===s;)t+=n,a++,n=e[a];t+=n,r[o]=t,a++,o++}return r}(e,t)}function c(e,t){switch(t.kind){case"ByteArray":switch(t.type){case 4:return e;case 1:return function(e){return new Int8Array(e.buffer,e.byteOffset)}(e);case 2:return function(e){return l(e,2,Int16Array)}(e);case 5:return function(e){return l(e,2,Uint16Array)}(e);case 3:return function(e){return l(e,4,Int32Array)}(e);case 6:return function(e){return l(e,4,Uint32Array)}(e);case 32:return function(e){return l(e,4,Float32Array)}(e);case 33:return function(e){return l(e,8,Float64Array)}(e);default:throw new Error("Unsupported ByteArray type.")}case"FixedPoint":return function(e,t){let i=e.length,s=a(t.srcType,i),n=1/t.factor;for(let t=0;t<i;t++)s[t]=n*e[t];return s}(e,t);case"IntervalQuantization":return function(e,t){let i=e.length,s=a(t.srcType,i),n=(t.max-t.min)/(t.numSteps-1),r=t.min;for(let t=0;t<i;t++)s[t]=r+n*e[t];return s}(e,t);case"RunLength":return function(e,t){let i=r(t.srcType,t.srcSize),s=0;for(let t=0,n=e.length;t<n;t+=2){let n=e[t],r=e[t+1];for(let e=0;e<r;++e)i[s++]=n}return i}(e,t);case"Delta":return function(e,t){let i=e.length,s=r(t.srcType,i);if(!i)return s;s[0]=e[0]+(0|t.origin);for(let t=1;t<i;++t)s[t]=e[t]+s[t-1];return s}(e,t);case"IntegerPacking":return d(e,t);case"StringArray":return function(e,t){let i=t.stringData,s=h({encoding:t.offsetEncoding,data:t.offsets}),n=h({encoding:t.dataEncoding,data:e}),r=Object.create(null),a=new Array(n.length),o=0;for(let e=0,t=n;e<t.length;e++){let n=t[e];if(n<0){a[o++]=null;continue}let l=r[n];void 0===l&&(l=i.substring(s[n],s[n+1]),r[n]=l),a[o++]=l}return a}(e,t)}}function h(e){let t=e.data;for(let i=e.encoding.length-1;i>=0;i--)t=c(t,e.encoding[i]);return t}function p(e){if(!e.data.data)return _UndefinedColumn;let t,i=h(e.data);return e.mask&&(t=h(e.mask)),i.buffer&&i.byteLength&&i.BYTES_PER_ELEMENT?t?new g(i,t):new f(i):t?new C(i,t):new b(i)}function u(e,t,i){let s=0,n=1;for(45===e.charCodeAt(t)&&(n=-1,t++);t<i;t++){let i=e.charCodeAt(t)-48;if(i>9||i<0)return n*s|0;s=10*s+i|0}return n*s}function m(e,t,i){let s=1,n=0,r=0,a=1;for(45===e.charCodeAt(t)&&(s=-1,++t);t<i;){let o=e.charCodeAt(t)-48;if(!(o>=0&&o<10)){if(-2===o){for(++t;t<i;){if(o=e.charCodeAt(t)-48,!(o>=0&&o<10))return 53===o||21===o?parseScientific(s*(n+r/a),e,t+1,i):s*(n+r/a);r=10*r+o,a*=10,++t}return s*(n+r/a)}if(53===o||21===o)return parseScientific(s*n,e,t+1,i);break}n=10*n+o,++t}return s*n}let f=function(){function e(e){this.data=e,this.isDefined=!0}return e.prototype.getString=function(e){return""+this.data[e]},e.prototype.getInteger=function(e){return 0|this.data[e]},e.prototype.getFloat=function(e){return 1*this.data[e]},e.prototype.stringEquals=function(e,t){return this.data[e]===m(t,0,t.length)},e.prototype.areValuesEqual=function(e,t){return this.data[e]===this.data[t]},e.prototype.getValuePresence=function(e){return 0},e}(),g=function(){function e(e,t){this.data=e,this.mask=t,this.isDefined=!0}return e.prototype.getString=function(e){return 0===this.mask[e]?""+this.data[e]:null},e.prototype.getInteger=function(e){return 0===this.mask[e]?this.data[e]:0},e.prototype.getFloat=function(e){return 0===this.mask[e]?this.data[e]:0},e.prototype.stringEquals=function(e,t){return 0===this.mask[e]?this.data[e]===m(t,0,t.length):null==t},e.prototype.areValuesEqual=function(e,t){return this.data[e]===this.data[t]},e.prototype.getValuePresence=function(e){return this.mask[e]},e}(),b=function(){function e(e){this.data=e,this.isDefined=!0}return e.prototype.getString=function(e){return this.data[e]},e.prototype.getInteger=function(e){let t=this.data[e];return u(t,0,t.length)},e.prototype.getFloat=function(e){let t=this.data[e];return m(t,0,t.length)},e.prototype.stringEquals=function(e,t){return this.data[e]===t},e.prototype.areValuesEqual=function(e,t){return this.data[e]===this.data[t]},e.prototype.getValuePresence=function(e){return 0},e}(),C=function(){function e(e,t){this.data=e,this.mask=t,this.isDefined=!0}return e.prototype.getString=function(e){return 0===this.mask[e]?this.data[e]:null},e.prototype.getInteger=function(e){if(0!==this.mask[e])return 0;let t=this.data[e];return u(t||"",0,(t||"").length)},e.prototype.getFloat=function(e){if(0!==this.mask[e])return 0;let t=this.data[e];return m(t||"",0,(t||"").length)},e.prototype.stringEquals=function(e,t){return this.data[e]===t},e.prototype.areValuesEqual=function(e,t){return this.data[e]===this.data[t]},e.prototype.getValuePresence=function(e){return this.mask[e]},e}(),v=function(){function e(e){this.dataBlocks=e.dataBlocks.map((function(e){return new s(e)}))}return e.prototype.toJSON=function(){return this.dataBlocks.map((function(e){return e.toJSON()}))},e}();return new v(i)}MessagePackParse(e){this.icn3d.icn3dui;let t=this;function i(e,i){let s={};for(let n=0;n<i;n++){s[t.MessagePackParse(e)]=t.MessagePackParse(e)}return s}function s(e,t){let i=new Uint8Array(t),s=e.offset;for(let n=0;n<t;n++)i[n]=e.buffer[n+s];return e.offset+=t,i}function n(e,i){let s=new Array(i);for(let n=0;n<i;n++)s[n]=t.MessagePackParse(e);return s}function r(e,t){let i=function(e,t,i){let s,n=a,r=[],o=512,l=0;for(let a=t,d=t+i;a<d;a++){let t=e[a];128&t?192==(224&t)?r[l++]=n[(15&t)<<6|63&e[++a]]:224==(240&t)?r[l++]=String.fromCharCode((15&t)<<12|(63&e[++a])<<6|63&e[++a]):240==(248&t)?r[l++]=String.fromCharCode((7&t)<<18|(63&e[++a])<<12|(63&e[++a])<<6|63&e[++a]):throwError("Invalid byte "+t.toString(16)):r[l++]=n[t],l===o&&(s=s||[],s[s.length]=r.join(""),l=0)}if(!s)return r.slice(0,l).join("");l>0&&(s[s.length]=r.slice(0,l).join(""));return s.join("")}(e.buffer,e.offset,t);return e.offset+=t,i}let a=function(){let e=[];for(let t=0;t<1024;t++)e[t]=String.fromCharCode(t);return e}();let o,l,d=e.buffer[e.offset];if(!(128&d))return e.offset++,d;if(128==(240&d))return l=15&d,e.offset++,i(e,l);if(144==(240&d))return l=15&d,e.offset++,n(e,l);if(160==(224&d))return l=31&d,e.offset++,r(e,l);if(!(224&~d))return o=e.dataView.getInt8(e.offset),e.offset++,o;switch(d){case 192:return e.offset++,null;case 194:return e.offset++,!1;case 195:return e.offset++,!0;case 196:return l=e.dataView.getUint8(e.offset+1),e.offset+=2,s(e,l);case 197:return l=e.dataView.getUint16(e.offset+1),e.offset+=3,s(e,l);case 198:return l=e.dataView.getUint32(e.offset+1),e.offset+=5,s(e,l);case 202:return o=e.dataView.getFloat32(e.offset+1),e.offset+=5,o;case 203:return o=e.dataView.getFloat64(e.offset+1),e.offset+=9,o;case 204:return o=e.buffer[e.offset+1],e.offset+=2,o;case 205:return o=e.dataView.getUint16(e.offset+1),e.offset+=3,o;case 206:return o=e.dataView.getUint32(e.offset+1),e.offset+=5,o;case 208:return o=e.dataView.getInt8(e.offset+1),e.offset+=2,o;case 209:return o=e.dataView.getInt16(e.offset+1),e.offset+=3,o;case 210:return o=e.dataView.getInt32(e.offset+1),e.offset+=5,o;case 217:return l=e.dataView.getUint8(e.offset+1),e.offset+=2,r(e,l);case 218:return l=e.dataView.getUint16(e.offset+1),e.offset+=3,r(e,l);case 219:return l=e.dataView.getUint32(e.offset+1),e.offset+=5,r(e,l);case 220:return l=e.dataView.getUint16(e.offset+1),e.offset+=3,n(e,l);case 221:return l=e.dataView.getUint32(e.offset+1),e.offset+=5,n(e,l);case 222:return l=e.dataView.getUint16(e.offset+1),e.offset+=3,i(e,l);case 223:return l=e.dataView.getUint32(e.offset+1),e.offset+=5,i(e,l)}}}class qh{constructor(e){this.icn3d=e}alignCoords(e,t,i,s,n,r,a,o){let l,d=this.icn3d,c=d.icn3dui,h=e.length<t.length?e.length:t.length,p={};if(h<4&&alert("Please select at least four residues in each structure..."),h>=4&&(d.bAfMem?d.rmsd_suprTmp=c.rmsdSuprCls.getRmsdSuprCls(t,e,h):d.rmsd_suprTmp=c.rmsdSuprCls.getRmsdSuprCls(e,t,h),void 0!==d.rmsd_suprTmp.rot)){let e=d.rmsd_suprTmp.rot;null===e[0]&&alert("Please select more residues in each structure...");let t=d.rmsd_suprTmp.trans1,s=d.rmsd_suprTmp.trans2;if(l=d.rmsd_suprTmp.rmsd,l){c.htmlCls.clickMenuCls.setLogCmd("realignment RMSD: "+l.toPrecision(4),!1);let e="<br><b>Realignment RMSD</b>: "+l.toPrecision(4)+" Å<br><br>";d.bAfMem&&!c.cfg.chainalign&&(e+=c.utilsCls.getMemDesc()),$("#"+d.pre+"dl_rmsd_html").html(e),c.cfg.bSidebyside||c.htmlCls.dialogCls.openDlg("dl_rmsd","Realignment RMSD")}let a={};for(let n=0,r=d.structures[i].length;n<r;++n){let r=d.structures[i][n];if(!a.hasOwnProperty(r)){for(let i in d.chains[r]){let n=d.atoms[i];n.coord=d.surfaceCls.transformMemPro(n.coord,e,t,s)}a[r]=1}}d.bRealign=!0,o||(d.opts.color="identity",d.setColorCls.setColorByOptions(d.opts,d.hAtoms)),d.qt_start_end||(d.qt_start_end=[]);let h=this.getQtStartEndFromRealignResid(n,r);d.qt_start_end.push(h),p=d.hAtoms}return{hAtoms:p,rmsd:l}}getQtStartEndFromRealignResid(e,t){let i=this.icn3d;i.icn3dui,e.substr(0,e.indexOf("_")),t.substr(0,t.indexOf("_"));let s=[],n={};for(let t=0,s=i.chainsSeq[e].length;t<s;++t){n[i.chainsSeq[e][t].resi]=t+1}let r={};for(let e=0,s=i.chainsSeq[t].length;e<s;++e){r[i.chainsSeq[t][e].resi]=e+1}for(let a=0,o=i.realignResid[e].length;a<o&&a<i.realignResid[t].length;++a){let o=i.realignResid[e][a].resid;if(!o)continue;let l=o.lastIndexOf("_"),d=parseInt(o.substr(l+1)),c=i.realignResid[t][a].resid;if(!c)continue;let h=c.lastIndexOf("_"),p=parseInt(c.substr(h+1)),u=n[d],m=r[p];s.push({q_start:m,q_end:m,t_start:u,t_end:u})}return s}getMissingResidues(e,t,i){let s=this.icn3d,n=s.icn3dui;s.chainsSeq[i]=[];let r=0;if("mmdbid"===t||"align"===t)for(let t=0,i=e.length;t<i;++t)if(0!=e[t][0]){r=e[t][0]-(t+1);break}let a=r;for(let r=0,o=e.length;r<o;++r){let o,l;"mmdbid"===t?(o=e[r][1],l=0):"mmcifid"===t?(o=e[r][1],o=n.utilsCls.residueName2Abbr(o),l=0):"align"===t&&(o=e[r][1],l=0),""===o&&(o="x");let d={};s.bUsePdbNum?d.resi="0"==e[r][l]?parseInt(a)+1:e[r][l]:d.resi=r+1,d.name="align"===t?o.toLowerCase():o,s.chainsSeq[i].push(d),a=d.resi}}async set2DDiagramsForAlign(e,t){let i=this.icn3d,s=i.icn3dui;s.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions");let n=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+e+"&intrac=1",r=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+t+"&intrac=1";void 0!==s.cfg.inpara&&(n+=s.cfg.inpara,r+=s.cfg.inpara);let a=s.getAjaxPromise(n,"jsonp"),o=s.getAjaxPromise(r,"jsonp"),l=Promise.allSettled([a,o]),d=await l;i.interactionData1=d[0].value,i.html2ddgm="",i.diagram2dCls.draw2Ddgm(i.interactionData1,e,0),s.cfg.show2d&&s.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),i.interactionData2=d[1].value,i.diagram2dCls.draw2Ddgm(i.interactionData2,t,1),i.html2ddgm+="<br>"+i.diagram2dCls.set2DdgmNote(!0),$("#"+i.pre+"dl_2ddgm_html").html(i.html2ddgm),i.b2DShown=!0}async set2DDiagramsForChainalign(e){let t=this.icn3d.icn3dui,i=this;t.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions");let s=[];for(let i=0,n=e.length;i<n;++i){let n=e[i].indexOf("_"),r=e[i].substr(0,n).toUpperCase(),a=t.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+r+"&intrac=1";void 0!==t.cfg.inpara&&(a+=t.cfg.inpara);let o=t.getAjaxPromise(a,"jsonp");s.push(o)}let n=Promise.allSettled(s);try{let t=await n;i.parse2DDiagramsData(t,e)}catch(e){}}parse2DDiagramsData(e,t){let i=this.icn3d,s=i.icn3dui;i.html2ddgm="";for(let s=0,n=t.length;s<n;++s){let n=e[s].value,r=t[s].substr(0,t[s].indexOf("_"));i.diagram2dCls.draw2Ddgm(n,r,0)}i.html2ddgm+="<br>"+i.diagram2dCls.set2DdgmNote(!0),i.b2DShown=!0,$("#"+i.pre+"dl_2ddgm_html").html(i.html2ddgm),s.cfg.show2d&&s.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions")}download2Ddgm(e,t){this.set2DDiagrams(e)}set2DDiagrams(e){let t=this.icn3d;t.icn3dui.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),void 0!==t.b2DShown&&t.b2DShown||(t.html2ddgm="",t.diagram2dCls.draw2Ddgm(t.interactionData,e),t.html2ddgm+="<br>"+t.diagram2dCls.set2DdgmNote(),$("#"+t.pre+"dl_2ddgm_html").html(t.html2ddgm)),t.b2DShown=!0}showLoading(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"wait")&&$("#"+e.pre+"wait").show(),$("#"+e.pre+"canvas")&&$("#"+e.pre+"canvas").hide(),$("#"+e.pre+"cmdlog")&&$("#"+e.pre+"cmdlog").hide()}hideLoading(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"wait")&&$("#"+e.pre+"wait").hide(),$("#"+e.pre+"canvas")&&$("#"+e.pre+"canvas").show(),$("#"+e.pre+"cmdlog")&&$("#"+e.pre+"cmdlog").show()}setYourNote(e){let t=this.icn3d,i=t.icn3dui;t.yournote=e,$("#"+t.pre+"yournote").val(t.yournote),i.cfg.shownote&&(document.title=t.yournote)}transformToOpmOri(e){let t=this.icn3d;if(t.icn3dui,void 0!==t.rmsd_supr&&void 0!==t.rmsd_supr.rot){let i=t.rmsd_supr.rot,s=t.rmsd_supr.trans1,n=t.rmsd_supr.trans2;t.rmsd_supr.rmsd;let r=0;for(let e in t.atoms){let a=t.atoms[e];a.coord=t.surfaceCls.transformMemPro(a.coord,i,s,n);let o=a.coord.x*a.coord.x+a.coord.y*a.coord.y;Math.abs(a.coord.z)<=25&&o>r&&(r=o)}this.addMemAtoms(t.halfBilayerSize,e,Math.sqrt(r)),t.bStopRotate=!0,t.bOpm=!0,$("#"+t.pre+"togglememli").show(),$("#"+t.pre+"adjustmemli").show(),$("#"+t.pre+"selectplaneli").show()}else t.bOpm=!1}transformToOpmOriForAlign(e,t,i){let s=this.icn3d,n=s.icn3dui;if(void 0!==t){let r=s.loadPDBCls.getChainCalpha(s.chains,s.atoms,i,e),a=1==Object.keys(r.chainresiCalphaHash).length||1==Object.keys(t.chainresiCalphaHash).length,o=[],l=[];for(let e in r.chainresiCalphaHash)if(t.chainresiCalphaHash.hasOwnProperty(e)){let i=r.chainresiCalphaHash[e],s=t.chainresiCalphaHash[e];if((i.length==s.length||a)&&(o=o.concat(i),l=l.concat(s)),o.length>500)break}let d=o.length<l.length?o.length:l.length;if(d>=4)if(s.rmsd_supr=n.rmsdSuprCls.getRmsdSuprCls(o,l,d),void 0!==s.rmsd_supr.rot&&s.rmsd_supr.rmsd<1){let i=s.rmsd_supr.rot,r=s.rmsd_supr.trans1,a=s.rmsd_supr.trans2,o=s.rmsd_supr.rmsd;n.htmlCls.clickMenuCls.setLogCmd("RMSD of alignment to OPM: "+o.toPrecision(4),!1);let l=0;for(let e in s.atoms){let t=s.atoms[e];t.coord=s.surfaceCls.transformMemPro(t.coord,i,r,a);let n=t.coord.x*t.coord.x+t.coord.y*t.coord.y;Math.abs(t.coord.z)<=25&&n>l&&(l=n)}s.center=t.center,s.oriCenter=s.center.clone(),this.addMemAtoms(s.halfBilayerSize,e,Math.sqrt(l)),s.bStopRotate=!0,s.bOpm=!0,$("#"+s.pre+"togglememli").show(),$("#"+s.pre+"adjustmemli").show(),$("#"+s.pre+"selectplaneli").show()}else s.bOpm=!1;else s.bOpm=!1}}addOneDumAtom(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui,l={het:!0,serial:++r,name:t,alt:void 0,resn:"DUM",structure:e,chain:"MEM",resi:1,coord:new mt(i,s,n),b:void 0,elem:t,bonds:[],ss:"",ssbegin:!1,ssend:!1,color:o.parasCls.atomColors[t]};return a.atoms[r]=l,a.chains[e+"_MEM"][r]=1,a.residues[e+"_MEM_1"][r]=1,a.chemicals[r]=1,a.dAtoms[r]=1,a.hAtoms[r]=1,r}addMemAtoms(e,t,i){let s=this.icn3d;if(s.icn3dui,!t)return;t=t?t.toUpperCase():s.defaultPdbId,s.structures[t].push(t+"_MEM"),s.chains[t+"_MEM"]={},s.residues[t+"_MEM_1"]={},s.chainsSeq[t+"_MEM"]=[{name:"DUM",resi:1}];let n=Object.keys(s.atoms).length;for(let e=0;e<1e3;++e)if(!s.atoms.hasOwnProperty(n+e)){n=n+e-1;break}for(let s=0;s<81;++s)for(let r=0;r<81;++r){let a=2*s-80,o=2*r-80;if(Math.sqrt(a*a+o*o)<i){let i=-e-.4;n=this.addOneDumAtom(t,"N",a,o,i,n),i=e+.4,n=this.addOneDumAtom(t,"O",a,o,i,n)}}}setMaxD(){let e=this.icn3d;e.icn3dui;let t=new mt(9999,9999,9999),i=new mt(-9999,-9999,-9999),s=new mt,n=0;for(let r in e.atoms){let a=e.atoms[r],o=a.coord;s.add(o),t.min(o),i.max(o),++n,a.het&&(0==a.bonds.length?e.ions[a.serial]=1:e.chemicals[a.serial]=1)}e.pmin=t,e.pmax=i,e.cnt=n,e.center=this.getGeoCenter(e.pmin,e.pmax),e.maxD=this.getStructureSize(e.atoms,e.pmin,e.pmax,e.center),e.maxD<5&&(e.maxD=5),e.oriMaxD=e.maxD,e.oriCenter=e.center.clone()}async renderStructure(){let e=this.icn3d,t=e.icn3dui;if(e.bInitial){if(e.bOpm&&(void 0!==t.cfg.align||void 0!==t.cfg.chainalign)){let i=e.selectedPdbid+"_MEM_1";for(let s in e.residues[i]){let i=e.atoms[s];i.style="stick",i.color=t.parasCls.atomColors[i.name],e.atomPrevColors[s]=i.color,e.dAtoms[s]=1}}if(void 0!==t.cfg.command&&""!==t.cfg.command?(e.bRender=!1,e.drawCls.draw()):(e.selectionCls.oneStructurePerWindow(),e.drawCls.draw()),e.bOpm){let t=new mt(1,0,0),i=-.5*Math.PI;e.transformCls.setRotation(t,i)}$("#"+e.pre+"alternate").show()}else e.selectionCls.saveSelectionIfSelected(),e.drawCls.draw();e.bInitial&&t.cfg.showsets&&e.definedSetsCls.showSets(),!e.bCommandLoad&&e.bInitial&&void 0!==t.cfg.command&&""!==t.cfg.command&&this.processCommand(),Object.keys(e.structures).length>=2?$("#"+e.pre+"mn2_alternateWrap").show():$("#"+e.pre+"mn2_alternateWrap").hide(),setTimeout((async function(){if(e.bInitial){if(void 0!==t.cfg.align||void 0!==t.cfg.chainalign){let i=e.pre+"selection";if($("#"+i).show(),$("#"+i+"_expand").hide(),$("#"+i+"_shrink").show(),void 0!==t.cfg.align&&2!=t.cfg.atype){let i=!1,s=t.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(e.alnChains),void 0,void 0,i);$("#"+e.pre+"dl_sequence2").html(s.sequencesHtml),$("#"+e.pre+"dl_sequence2").width(t.htmlCls.RESIDUE_WIDTH*s.maxSeqCnt+200)}}if(t.cfg.showanno){let i="view annotations";t.htmlCls.clickMenuCls.setLogCmd(i,!0),await e.showAnnoCls.showAnnotations()}(t.cfg.closepopup||t.cfg.imageonly)&&e.resizeCanvasCls.closeDialogs(),t.cfg.showlogo||$("#ncbi_logo").hide()}else e.hlUpdateCls.updateHlAll();$("#"+e.pre+"atomsCustom").length>0&&$("#"+e.pre+"atomsCustom")[0].blur(),e.bInitial=!1,t.cfg.imageonly&&e.saveFileCls.saveFile(void 0,"png",void 0,!0)}),0)}processCommand(){let e=this.icn3d,t=e.icn3dui;if(1==Object.keys(e.structures).length){let i=Object.keys(e.structures)[0];t.cfg.command=t.cfg.command.replace(new RegExp("!","g"),i+"_")}}getMassCenter(e,t){return this.icn3d.icn3dui,e.multiplyScalar(1/t)}getGeoCenter(e,t){return this.icn3d.icn3dui,e.clone().add(t).multiplyScalar(.5)}getStructureSize(e,t,i,s){let n=this.icn3d;n.icn3dui;let r=0;for(let a in e){let e=n.atoms[a].coord;if(Math.round(t.x)==Math.round(e.x)||Math.round(t.y)==Math.round(e.y)||Math.round(t.z)==Math.round(e.z)||Math.round(i.x)==Math.round(e.x)||Math.round(i.y)==Math.round(e.y)||Math.round(i.z)==Math.round(e.z)){let t=2*e.distanceTo(s);t>r&&(r=t)}}return r}async checkMemProteinAndRotate(){let e=this.icn3d,t=e.icn3dui;if(!e.bCheckMemProtein){e.bCheckMemProtein=!0;let i=t.cfg.afid?t.cfg.afid:t.cfg.mmdbafid;if(await e.ParserUtilsCls.checkMemProtein(i),t.cfg.url&&-1!=t.cfg.url.indexOf("membranome")){let t=new mt(1,0,0),i=-.5*Math.PI;e.transformCls.setRotation(t,i)}}}async checkMemProtein(e){let t=this.icn3d,i=t.icn3dui;try{let s=i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?afid2mem="+e,n=await i.getAjaxPromise(s,"jsonp");if(n&&n.pdbid){let e='This is a single-spanning (bitopic) transmembrane protein according to the Membranome database. Do you want to align the protein with the model from Membranome? If you click "OK", you can press the letter "a" to alternate the structures.';if(i.bNode)return;if("off"==i.cfg.afmem);else if("on"==i.cfg.afmem||confirm(e))try{let e="https://storage.googleapis.com/membranome-assets/pdb_files/proteins/"+n.pdbid+".pdb",s=await i.getAjaxPromise(e,"text");t.bAfMem=!0,i.bNode||$("#"+i.pre+"togglememli").show();let r=n.pdbid.substr(0,n.pdbid.indexOf("_")),a=!0,o=!0;await t.pdbParserCls.loadPdbData(s,r,a,o),o&&(t.bSetChainsAdvancedMenu&&t.definedSetsCls.showSets(),t.bAnnoShown&&(await t.showAnnoCls.showAnnotations(),t.annotationCls.resetAnnoTabAll()));let l=n.segment.replace(/ /gi,"").split("(")[0];t.afmem_start_end=l.split("-"),t.hAtoms={},t.dAtoms={};for(let e in t.atoms)t.atoms[e].structure!=r&&(t.hAtoms[e]=1),t.dAtoms[e]=1;for(let e=parseInt(t.afmem_start_end[0]);e<=parseInt(t.afmem_start_end[1]);++e)t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[r+"_A_"+e]);await t.realignParserCls.realignOnSeqAlign(r)}catch(e){return void console.log("Error in retrieving matched PDB from Membranome...")}}}catch(e){return void console.log("Error in finding matched PDB in Membranome...")}}getResi(e,t){let i=this.icn3d;i.icn3dui;let s=i.ncbi2resid[e+"_"+(t+1).toString()];return s?s.substr(s.lastIndexOf("_")+1):""}getResiNCBI(e,t){let i=this.icn3d;i.icn3dui;let s=i.resid2ncbi[e+"_"+t];return s?parseInt(s.substr(s.lastIndexOf("_")+1)):0}}class jh{constructor(e){this.icn3d=e}loadAtomDataIn(e,t,i,s,n,r,a,o,l){let d=this.icn3d,c=d.icn3dui;d.pmin=new mt(9999,9999,9999),d.pmax=new mt(-9999,-9999,-9999),d.psum=new mt;let h=e.atoms,p=d.atoms?Object.keys(d.atoms).length:0,u={},m={};d.pmid=e.pubmedId,void 0===d.chainid2title&&(d.chainid2title={}),void 0===d.chainid2sid&&(d.chainid2sid={});let f={},g={};if("align"===i){d.pmid="",d.molTitle="",c.cfg.inpara&&-1!==c.cfg.inpara.indexOf("atype=1")?d.molTitle="Invariant Core Structure Alignment (VAST) of ":c.cfg.inpara&&-1!==c.cfg.inpara.indexOf("atype=2")?d.molTitle="Structure Alignment (TM-align) of ":d.molTitle="Structure Alignment (VAST) of ";let t=!1;for(let i=0,s=e.alignedStructures[0].length;i<s;++i){let s=e.alignedStructures[0][i];1===i&&(d.secondId=s.pdbId);let n=s.pdbId,r=s.mmdbId;for(let e=s.serialInterval[0],t=s.serialInterval[1];e<=t;++e)u[e]=n.toString(),m[r]=n;for(let e=0,t=s.molecules.length;e<t;++e){let t=s.molecules[e].chain;t=t.replace(/_/g,"");let i=s.molecules[e].kind,r=s.molecules[e].name,a=s.molecules[e].sid,o=n+"_"+t;f[o]=i,d.chainid2title[o]=r,void 0!==a&&(d.chainid2sid[o]=a)}d.molTitle+='<a href="'+c.htmlCls.baseUrl+"mmdb/mmdbsrv.cgi?uid="+s.pdbId.toUpperCase()+'" target="_blank">'+s.pdbId.toUpperCase()+"</a>",void 0!==s.descr&&(d.pmid+=s.descr.pubmedid),0===i&&(d.molTitle+=" and ",void 0!==s.descr&&(d.pmid+="_")),t=!0}d.molTitle+=" from VAST+",t||(d.molTitle="")}else if(void 0!==e.descr&&(d.molTitle=e.descr.name),"mmdbid"===i){let i=isNaN(t)?t:e.pdbId,s={};void 0===d.alignmolid2color&&(d.alignmolid2color=[]);let n=1;for(let t in e.moleculeInfor){if(0===Object.keys(e.moleculeInfor[t]).length)continue;let r=e.moleculeInfor[t].chain.trim();r=r.replace(/_/g,"");let a=i+"_"+r;s.hasOwnProperty(r)?(++s[r],a+=s[r]):s[r]=1,void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t);let o=e.moleculeInfor[t].kind,l=e.moleculeInfor[t].color,c=e.moleculeInfor[t].sid;if(f[a]=o,g[a]=l,"protein"==o&&(d.organism=e.moleculeInfor[t].taxonomyName.toLowerCase()),void 0!==c&&(d.chainid2sid[a]=c),void 0===d.pdbid_chain2title&&(d.pdbid_chain2title={}),d.pdbid_chain2title[a]=e.moleculeInfor[t].name,r==a.substr(a.lastIndexOf("_"))){let e={};e[t]=n.toString(),d.alignmolid2color.push(e)}++n}}"mmdbid"===i&&(d.molTitleHash||(d.molTitleHash={}),d.molTitleHash[t]=d.molTitle);let b,C,v,_,y,S={},w="",x="",A="",M="",T="",E="",R=0,k=0,O="",I=!0,P=!1,D="",L=c.utilsCls.isCalphaPhosOnly(h),F=0,N={};for(let e in h){++p,S[e]=p;let s,n=h[e];n.serial=p,"mmdbid"===i||"mmcifid"===i?s=t:"align"===i&&(s=u[p]);let r=!1;if(void 0!==n.chain||"mmdbid"!==i&&"align"!==i)n.chain=""===n.chain?"Misc":n.chain;else if("mmdbid"===i)if(b=n.ids.m,void 0!==d.molid2chain[b]){let e=d.molid2chain[b].indexOf("_");n.chain=d.molid2chain[b].substr(e+1)}else{let e="Misc";("protein"===f[T]&&"nucleotide"===f[T]&&n.resi!=k||"protein"!==f[T]&&"nucleotide"!==f[T]&&(n.resn.substr(0,3)!=O.substr(0,3)||n.resi!=k||"solvent"===f[T]||"HOH"===n.resn))&&++F,n.resi_ori=n.resi,n.resi=F,r=!0,n.chain=e}else if("align"===i)if(b=n.ids.m,void 0!==d.pdbid_molid2chain[s+"_"+b])n.chain=d.pdbid_molid2chain[s+"_"+b];else{let e="Misc";("protein"===f[T]&&"nucleotide"===f[T]&&n.resi!=k||"protein"!==f[T]&&"nucleotide"!==f[T]&&(n.resn.substr(0,3)!=O.substr(0,3)||n.resi!=k||"solvent"===f[T]||"HOH"===n.resn))&&(++F,n.resi_ori=n.resi,n.resi=F,r=!0),n.chain=e}if(n.chain=n.chain.trim(),n.chain=n.chain.replace(/_/g,""),"mmdbid"!==i&&"align"!==i||(n.structure=s,"mmdbid"===i&&void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t)),M=n.structure,T=M+"_"+n.chain,"mmdbid"===i||"align"===i){r||(n.resi_ori=n.resi,d.bUsePdbNum?n.resi=n.resi_ori:n.resi=n.ids.r);let e=n.resn.indexOf(" ");-1!==e&&0!=e&&(n.resn=n.resn.substr(0,e))}T!==x&&(R=0),n.resi!==R&&(T!==x?(v=void 0,y=void 0):(v=C,y=_)),n.coord="mmdbid"===i?new mt(n.coord[0],n.coord[1],n.coord[2]):new mt(n.coord.x,n.coord.y,n.coord.z);let a=c.utilsCls.residueName2Abbr(n.resn.substr(0,3));"mmdbid"!==i&&"align"!==i||!d.bFullUi||(void 0===d.mmdbMolidResid2mmdbChainResi&&(d.mmdbMolidResid2mmdbChainResi={}),d.mmdbMolidResid2mmdbChainResi[s+"_"+n.ids.m+"_"+n.ids.r]=s+"_"+n.chain+"_"+n.resi),d.pmin.min(n.coord),d.pmax.max(n.coord),d.psum.add(n.coord);let o="protein"===f[T],l="nucleotide"===f[T],m="solvent"===f[T],U="ligand"===f[T]||void 0!==f[T]&&-1!==f[T].indexOf("other")||void 0===f[T];if("Misc"!==n.chain&&"other"!==f[T]||"protein"===N[T]||"nucleotide"===N[T]||("CA"===n.name&&"C"===n.elem?N[T]="protein":"P"===n.name&&"P"===n.elem?N[T]="nucleotide":N[T]="chemical"),o||l?(o?(d.proteins[p]=1,"CA"===n.name&&(d.calphas[p]=1),"N"!==n.name&&"H"!==n.name&&"CA"!==n.name&&"HA"!==n.name&&"C"!==n.name&&"O"!==n.name&&(d.sidec[p]=1)):l&&(d.nucleotides[p]=1,("O3'"==n.name||"O3*"==n.name||L&&"P"==n.name)&&(d.nucleotidesO3[p]=1),-1===c.parasCls.nuclMainArray.indexOf(n.name)&&(d.ntbase[p]=1)),n.het=!1):m?(d.water[p]=1,n.het=!0):U&&("HOH"===n.resn||"O"===n.resn?d.water[p]=1:n.elem===n.resn?d.ions[p]=1:d.chemicals[p]=1,n.het=!0),"mmdbid"===i?n.het?n.color=c.parasCls.atomColors[n.elem]||c.parasCls.defaultAtomColor:n.color=void 0!==g[T]?c.parasCls.thr(g[T]):c.parasCls.chargeColors[n.resn]:void 0!==n.color&&(n.color=c.parasCls.thr(n.color))," "!==n.resn.charAt(0)&&" "===n.resn.charAt(1)&&(n.resn=n.resn.charAt(0)),n.het||"C"!==n.name||(C=p),n.het||"O"!==n.name||(_=p),!n.het&&"N"===n.name&&void 0!==v&&void 0!==y){let e=d.atoms[v].coord.distanceTo(d.atoms[y].coord),t=n.coord.x+(d.atoms[v].coord.x-d.atoms[y].coord.x)/e,i=n.coord.y+(d.atoms[v].coord.y-d.atoms[y].coord.y)/e,s=n.coord.z+(d.atoms[v].coord.z-d.atoms[y].coord.z)/e;n.hcoord=new mt(t,i,s)}"HOH"==n.resn&&(d.water[p]=1),d.atoms[p]=n,d.dAtoms[p]=1,d.hAtoms[p]=1;let H=n.structure+"_"+n.chain;void 0===d.chains[H]&&(d.chains[H]={}),d.chains[H][p]=1;let B=H+"_"+n.resi;void 0===d.residues[B]&&(d.residues[B]={}),d.residues[B][p]=1,E=T+"_"+n.resi,E!==A&&T!==x&&(I=!0,""!==w&&(void 0===d.structures[w]&&(d.structures[w]=[]),d.structures[w].push(x))),d.residueId2Name[B]=a;let z="-";if("helix"===n.ss?z="H":"sheet"===n.ss?z="E":n.het||l?z="o":(!n.het&&c.parasCls.residueColors.hasOwnProperty(n.resn.toUpperCase())||"coil"===n.ss)&&(z="c"),d.secondaries[n.structure+"_"+n.chain+"_"+n.resi]=z,(n.resi!=R||b!=D)&&d.bFullUi&&(void 0===d.chainsSeq[H]&&(d.chainsSeq[H]=[],I=!1),!isNaN(n.resi)&&null!==n.resi))if(I&&!P&&void 0!==d.chainsSeq[H][n.resi-1])d.chainsSeq[H][n.resi-1].name=a;else if(!I||!d.chainsSeq[H].hasOwnProperty(n.resi-1)){let e={};e.resi=n.resi,e.name=a,n.resi%10==0&&n.resi.toString(),d.chainsSeq[H].push(e),P=!0}R=n.resi,k=n.resi_ori,O=n.resn,w=M,x=T,A=E,D=b}for(let e in d.chemicals){let t=d.atoms[e];if("P"==t.elem&&t.bonds.length>=4)for(let e=t.bonds.length-1;e>=0;--e){"P"==d.atoms[t.bonds[e]].elem&&t.bonds.splice(e,1)}}for(let e in N)if(!(Object.keys(d.chains[e]).length<10)&&"chemical"!==N[e])for(let t in d.chains[e]){let i=d.atoms[t];delete d.chemicals[t],i.het=!1,"protein"===N[e]?(d.proteins[t]=1,"CA"===i.name&&(d.calphas[t]=1),"N"!==i.name&&"H"!==i.name&&"CA"!==i.name&&"HA"!==i.name&&"C"!==i.name&&"O"!==i.name&&(d.sidec[t]=1)):"nucleotide"===N[e]&&(d.nucleotides[t]=1,("O3'"==i.name||"O3*"==i.name||L&&"P"==i.name)&&(d.nucleotidesO3[t]=1),-1===c.parasCls.nuclMainArray.indexOf(i.name)&&(d.ntbase[t]=1))}if(void 0===d.structures[M]&&(d.structures[M]=[]),d.structures[M].push(T),d.bFullUi)if("mmdbid"===i||"mmcifid"===i)for(let s in e.sequences){let n=e.sequences[s],r=t+"_"+s;void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t),d.ParserUtilsCls.getMissingResidues(n,i,r)}else if("align"===i)for(let e in d.chainid2seq){let t=d.chainid2seq[e];d.ParserUtilsCls.getMissingResidues(t,i,e)}if(d.loadPDBCls.setResidMapping(),"mmcifid"!==i)for(let e in h){let t=S[e],i=void 0===d.atoms[t].bonds?0:d.atoms[t].bonds.length;for(let e=0;e<i;++e)d.atoms[t].bonds[e]=S[d.atoms[t].bonds[e]]}if(e.atoms={},d.cnt=p,(d.cnt>d.maxatomcnt||void 0!==d.biomtMatrices&&d.biomtMatrices.length*d.cnt>10*d.maxatomcnt)&&(d.opts.proteins="c alpha trace",d.opts.nucleotides="o3 trace"),d.center=d.ParserUtilsCls.getGeoCenter(d.pmin,d.pmax),d.maxD=d.ParserUtilsCls.getStructureSize(d.atoms,d.pmin,d.pmax,d.center),d.maxD<5&&(d.maxD=5),d.oriMaxD=d.maxD,("align"===i||o)&&(d.ssbondpnts={},d.loadPDBCls.setSsbond()),"mmdbid"===i&&1==Object.keys(d.structures).length){let t=e.disulfides;if(void 0!==t)for(let e=0,i=t.length;e<i;++e){let i=t[e][0].ca,s=t[e][1].ca,n=d.atoms[i],r=d.atoms[s],a=n.chain,o=r.chain,l=n.structure+"_"+a+"_"+n.resi,c=r.structure+"_"+o+"_"+r.resi;void 0===d.ssbondpnts[n.structure]&&(d.ssbondpnts[n.structure]=[]),d.ssbondpnts[n.structure].push(l),d.ssbondpnts[n.structure].push(c)}}else if("mmcifid"===i&&1==Object.keys(d.structures).length){let i=e.disulfides;if(void 0!==i){void 0===d.ssbondpnts[t]&&(d.ssbondpnts[t]=[]);for(let e=0,s=i.length;e<s;++e){let s=i[e][0],n=i[e][1];d.ssbondpnts[t].push(s),d.ssbondpnts[t].push(n)}let e=Object.keys(d.structures);for(let i=0,s=e.length;i<s;++i){let s=e[i];if(s!=t){void 0===d.ssbondpnts[s]&&(d.ssbondpnts[s]=[]);for(let e=0,i=d.ssbondpnts[t].length;e<i;++e){let i=d.ssbondpnts[t][e],n=i.indexOf("_"),r=s+i.substr(n);d.ssbondpnts[s].push(r)}}}}}("mmcifid"===i||"mmdbid"===i&&void 0===n)&&d.ParserUtilsCls.transformToOpmOri(t);let U={};if("align"===i&&void 0!==s&&d.bFullUi)d.setSeqAlignCls.setSeqAlign(s,e.alignedStructures);else if("mmdbid"!==i||"query"!==n||!d.bFullUi||void 0===d.q_rotation||c.cfg.resnum||c.cfg.resdef||l)U=d.hAtoms;else if(a){d.setSeqAlignCls.setSeqAlignChain(r,a);let e=!1,t=c.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(d.alnChains),void 0,void 0,!1,void 0,e),i=$("#"+d.pre+"dl_sequence2").html();U=d.hAtoms,$("#"+d.pre+"dl_sequence2").html(i+t.sequencesHtml),$("#"+d.pre+"dl_sequence2").width(c.htmlCls.RESIDUE_WIDTH*t.maxSeqCnt+200)}else U=d.hAtoms;if(!c.cfg.mmdbafid&&"mmdbid"===i&&("target"===n||"query"===n)&&void 0===d.q_rotation){if("target"===n||"query"===n)for(let e in h){let t=h[e];t.coord.x-=d.center.x,t.coord.y-=d.center.y,t.coord.z-=d.center.z}"target"===n?(d.oriMaxD=d.maxD,d.center1=d.center):"query"===n&&(d.oriMaxD<d.maxD&&(d.oriMaxD=d.maxD),d.center2=d.center,d.center=new mt(0,0,0))}return d.oriCenter=d.center.clone(),d.saveFileCls.showTitle(),e={},U}}class Gh{constructor(e){this.icn3d=e}setSeqAlign(e,t){let i,s,n=this.icn3d,r=n.icn3dui,a=t[0][0].pdbId,o=t[0][1].pdbId;n.conservedName1=a+"_cons",n.nonConservedName1=a+"_ncons",n.notAlignedName1=a+"_nalign",n.conservedName2=o+"_cons",n.nonConservedName2=o+"_ncons",n.notAlignedName2=o+"_nalign",n.consHash1={},n.nconsHash1={},n.nalignHash1={},n.consHash2={},n.nconsHash2={},n.nalignHash2={};for(let t=0,l=e.length;t<l;++t){let l=e[t][0],d=l.moleculeId,c=n.pdbid_molid2chain[a+"_"+d];i=a+"_"+c;let h={},p=l.sequence.length,u=-1,m=!1;for(let e=0,t=l.sequence.length;e<t;++e){let t=n.bUsePdbNum?n.ParserUtilsCls.getResi(i,l.sequence[e][0]-1):l.sequence[e][0],s="~"===l.sequence[e][2]?"-":l.sequence[e][2];s=" "===s||""===s?"X":s;let r=l.sequence[e][3]?1:0;1==r&&(e<p&&!m&&(p=e,m=!0),e>u&&(u=e)),h[e]={resi:t,resn:s,aligned:r}}l=e[t][1];let f=l.moleculeId,g=n.pdbid_molid2chain[o+"_"+f];s=o+"_"+g,void 0===n.alnChainsAnTtl[i]&&(n.alnChainsAnTtl[i]=[]),void 0===n.alnChainsAnTtl[i][0]&&(n.alnChainsAnTtl[i][0]=[]),void 0===n.alnChainsAnTtl[i][1]&&(n.alnChainsAnTtl[i][1]=[]),void 0===n.alnChainsAnTtl[i][2]&&(n.alnChainsAnTtl[i][2]=[]),void 0===n.alnChainsAnTtl[i][3]&&(n.alnChainsAnTtl[i][3]=[]),void 0===n.alnChainsAnTtl[i][4]&&(n.alnChainsAnTtl[i][4]=[]),void 0===n.alnChainsAnTtl[i][5]&&(n.alnChainsAnTtl[i][5]=[]),void 0===n.alnChainsAnTtl[i][6]&&(n.alnChainsAnTtl[i][6]=[]),n.alnChainsAnTtl[i][0].push(s),n.alnChainsAnTtl[i][1].push(i),n.alnChainsAnTtl[i][2].push(""),n.alnChainsAnTtl[i][3].push(""),n.alnChainsAnTtl[i][4].push(s),n.alnChainsAnTtl[i][5].push(i),n.alnChainsAnTtl[i][6].push("");let b=1;n.chainsMapping[i]||(n.chainsMapping[i]={}),n.chainsMapping[s]||(n.chainsMapping[s]={});for(let e=p;e<=u;++e){let t,d,u,m=n.bUsePdbNum?n.ParserUtilsCls.getResi(s,l.sequence[e][0]-1):l.sequence[e][0],f="~"===l.sequence[e][2]?"-":l.sequence[e][2],C=l.sequence[e][3]?1:0,v=h[e].aligned+C;2===v?(h[e].resn===f?(t="#FF0000",u="icn3d-cons",n.consHash1[i+"_"+h[e].resi]=1,n.consHash2[s+"_"+m]=1):(t="#0000FF",u="icn3d-ncons",n.nconsHash1[i+"_"+h[e].resi]=1,n.nconsHash2[s+"_"+m]=1),n.chainsMapping[i][i+"_"+h[e].resi]=h[e].resn+h[e].resi,n.chainsMapping[s][s+"_"+m]=h[e].resn+h[e].resi,d="#"+n.showAnnoCls.getColorhexFromBlosum62(h[e].resn,f)):(t=r.htmlCls.GREY8,u="icn3d-nalign",n.nalignHash1[i+"_"+h[e].resi]=1,n.nalignHash2[s+"_"+m]=1),void 0===n.alnChainsSeq[i]&&(n.alnChainsSeq[i]=[]);let _={};_.mmdbid=a,_.chain=c,_.resi=h[e].resi,_.resn=""===_.resi||"icn3d-nalign"===u?h[e].resn.toLowerCase():h[e].resn,_.aligned=v,_.color=""===_.resi?r.htmlCls.GREYC:t,_.color2=""===_.resi?r.htmlCls.GREYC:d,_.class=u,n.alnChainsSeq[i].push(_),""!==h[e].resi&&(void 0===n.alnChains[i]&&(n.alnChains[i]={}),$.extend(n.alnChains[i],n.residues[i+"_"+h[e].resi])),void 0===n.alnChainsSeq[s]&&(n.alnChainsSeq[s]=[]),_={},_.mmdbid=o,_.chain=g,_.resi=m,_.resn=""===_.resi||"icn3d-nalign"===u?f.toLowerCase():f,_.aligned=v,_.color=""===_.resi?r.htmlCls.GREYC:t,_.color2=""===_.resi?r.htmlCls.GREYC:d,_.class=u,n.alnChainsSeq[s].push(_),""!==_.resi&&(void 0===n.alnChains[s]&&(n.alnChains[s]={}),$.extend(n.alnChains[s],n.residues[s+"_"+m])),void 0===n.alnChainsAnno[i]&&(n.alnChainsAnno[i]=[]),void 0===n.alnChainsAnno[i][0]&&(n.alnChainsAnno[i][0]=[]),void 0===n.alnChainsAnno[i][1]&&(n.alnChainsAnno[i][1]=[]),void 0===n.alnChainsAnno[i][2]&&(n.alnChainsAnno[i][2]=[]),void 0===n.alnChainsAnno[i][3]&&(n.alnChainsAnno[i][3]=[]),e===p&&(void 0===n.alnChainsAnno[i][4]&&(n.alnChainsAnno[i][4]=[]),void 0===n.alnChainsAnno[i][5]&&(n.alnChainsAnno[i][5]=[]),void 0===n.alnChainsAnno[i][6]&&(n.alnChainsAnno[i][6]=[]),n.alnChainsAnno[i][4].push(n.pdbid_chain2title[s]),n.alnChainsAnno[i][5].push(n.pdbid_chain2title[i]),n.alnChainsAnno[i][6].push(""));let y=i+"_"+h[e].resi,S=s+"_"+m,w=n.secondaries[y],x=n.secondaries[S];x?n.alnChainsAnno[i][0].push(x):n.alnChainsAnno[i][0].push("-"),w?n.alnChainsAnno[i][1].push(w):n.alnChainsAnno[i][1].push("-");let A=".";b%5==0&&(A="*"),b%10==0&&(A="|"),n.alnChainsAnno[i][2].push(A);let M="";b%10==0&&(M=b.toString()),n.alnChainsAnno[i][3].push(M),++b}this.setMsaFormat([i,s])}e={}}getPosFromResi(e,t){let i=this.icn3d;i.icn3dui;let s,n=i.resid2ncbi[e+"_"+t];if(n){s=n.substr(n.lastIndexOf("_")+1)-1}return s}getResnFromResi(e,t){let i=this.icn3d;i.icn3dui;let s=e+"_"+t,n=i.residueId2Name[s];return n||(n="?"),n}getResiAferAlign(e,t,i){let s,n=this.icn3d,r=n.icn3dui;return t&&"tmalign"==r.cfg.aligntool?s=i:(i>n.chainsSeq[e].length-1&&(console.log("Error: the position "+i+" exceeds the max index "+(n.chainsSeq[e].length-1)),i=n.chainsSeq[e].length-1),s=n.chainsSeq[e][i].resi),s}setSeqAlignChain(e,t,i){let s,n,r,a,o,l,d,c,h,p,u,m=this.icn3d,f=m.icn3dui,g={},b=!!i;if(b){if(o=i[1],l=i[0],t=i[2],d=o.indexOf("_"),c=l.indexOf("_"),s=o.substr(0,d).toUpperCase(),n=l.substr(0,c).toUpperCase(),r=o.substr(d+1),a=l.substr(d+1),s==n&&r==a){let e=m.chainsSeq[n+"_"+a].length;m.qt_start_end[t]={q_start:1,q_end:e,t_start:1,t_end:e}}}else{let d=i[0].indexOf("_"),c=e.indexOf("_");if(s=m.mmdbid_t,n=e.substr(0,c).toUpperCase(),r=i[0].substr(d+1),a=e.substr(c+1),s==n&&r==a){let e=m.chainsSeq[m.mmdbid_q+"_"+m.chain_q].length;m.qt_start_end[t]={q_start:1,q_end:e,t_start:1,t_end:e}}o=s+"_"+r,l=n+"_"+a,void 0!==n&&m.mmdbid_t}m.conservedName1=o+"_cons",m.nonConservedName1=o+"_ncons",m.notAlignedName1=o+"_nalign",m.conservedName2=l+"_cons",m.nonConservedName2=l+"_ncons",m.notAlignedName2=l+"_nalign",m.consHash1={},m.nconsHash1={},m.nalignHash1={},m.consHash2={},m.nconsHash2={},m.nalignHash2={},m.alnChains={},m.alnChainsSeq[o]=[],m.alnChains[o]={},m.alnChainsSeq[l]=[],m.alnChains[l]={},m.alnChainsAnno[o]=[],m.alnChainsAnTtl[o]=[],void 0===m.alnChainsAnTtl[o]&&(m.alnChainsAnTtl[o]=[]);for(let e=0;e<7;++e)void 0===m.alnChainsAnTtl[o][e]&&(m.alnChainsAnTtl[o][e]=[]);m.alnChainsAnTtl[o][0].push(l),m.alnChainsAnTtl[o][1].push(o),m.alnChainsAnTtl[o][2].push(""),m.alnChainsAnTtl[o][3].push(""),m.alnChainsAnTtl[o][4].push(l),m.alnChainsAnTtl[o][5].push(o),m.alnChainsAnTtl[o][6].push("");let C=0,v=0;if(void 0===m.qt_start_end[t])return;let _=1;m.chainsMapping[o]||(m.chainsMapping[o]={}),m.chainsMapping[l]||(m.chainsMapping[l]={});for(let e=0,i=m.qt_start_end[t].length;e<i;++e)b&&"tmalign"==f.cfg.aligntool?(parseInt(m.qt_start_end[t][e].t_start),parseInt(m.qt_start_end[t][e].q_start),parseInt(m.qt_start_end[t][e].t_end),parseInt(m.qt_start_end[t][e].q_end)):(parseInt(m.qt_start_end[t][e].t_start-1),parseInt(m.qt_start_end[t][e].q_start-1),parseInt(m.qt_start_end[t][e].t_end-1),parseInt(m.qt_start_end[t][e].q_end-1));for(let e=0,i=m.qt_start_end[t].length;e<i;++e){let i,s,n,r;if(b&&"tmalign"==f.cfg.aligntool?(i=parseInt(m.qt_start_end[t][e].t_start),s=parseInt(m.qt_start_end[t][e].q_start),n=parseInt(m.qt_start_end[t][e].t_end),r=parseInt(m.qt_start_end[t][e].q_end)):(i=parseInt(m.qt_start_end[t][e].t_start-1),s=parseInt(m.qt_start_end[t][e].q_start-1),n=parseInt(m.qt_start_end[t][e].t_end-1),r=parseInt(m.qt_start_end[t][e].q_end-1)),e>0){let e=_;for(let t=C+1,s=i;t<s;++t){let i=this.getResiAferAlign(o,b,t),s=this.getResnFromResi(o,i).toLowerCase();"?"!=s&&(h=f.htmlCls.GREY8,u="icn3d-nalign",m.nalignHash1[o+"_"+i]=1,this.setSeqPerResi(o,o,l,i,s,!1,h,void 0,u,!0,!1,e),++e)}let t=_;for(let e=v+1,i=s;e<i;++e){let i=this.getResiAferAlign(l,b,e),s=this.getResnFromResi(l,i).toLowerCase();"?"!=s&&(h=f.htmlCls.GREY8,u="icn3d-nalign",m.nalignHash2[l+"_"+i]=1,this.setSeqPerResi(l,o,l,i,s,!1,h,void 0,u,!1,!1,t),++t)}if(e<t){_=t;for(let i=0;i<t-e;++i){let t="",s="-";h=f.htmlCls.GREY8,u="icn3d-nalign",this.setSeqPerResi(o,o,l,t,s,!1,h,void 0,u,!0,!1,e+i)}}else{_=e;for(let i=0;i<e-t;++i){let e="",s="-";h=f.htmlCls.GREY8,u="icn3d-nalign",this.setSeqPerResi(l,o,l,e,s,!1,h,void 0,u,!1,!1,t+i)}}}for(let r=0;r<=n-i;++r){let n,a,d,c;if(b&&"tmalign"==f.cfg.aligntool){if(n=m.qt_start_end[t][e].t_start,a=m.qt_start_end[t][e].q_start,d=this.getResnFromResi(o,n).toUpperCase(),c=this.getResnFromResi(l,a).toUpperCase(),"?"==d||"?"==c)continue}else n=this.getResiAferAlign(o,b,r+i),a=this.getResiAferAlign(l,b,r+s),d=this.getResnFromResi(o,n).toUpperCase(),c=this.getResnFromResi(l,a).toUpperCase();d===c?(h="#FF0000",u="icn3d-cons",m.consHash1[o+"_"+n]=1,m.consHash2[l+"_"+a]=1):(h="#0000FF",u="icn3d-ncons",m.nconsHash1[o+"_"+n]=1,m.nconsHash2[l+"_"+a]=1),g=f.hashUtilsCls.unionHash(g,m.residues[o+"_"+n]),g=f.hashUtilsCls.unionHash(g,m.residues[l+"_"+a]),m.chainsMapping[o][o+"_"+n]=d+n,m.chainsMapping[l][l+"_"+a]=d+n,p="#"+m.showAnnoCls.getColorhexFromBlosum62(d,c);let C=0===e&&0===r;this.setSeqPerResi(o,o,l,n,d,!0,h,p,u,!0,C,_),this.setSeqPerResi(l,o,l,a,c,!0,h,p,u,!1,C,_),++_}C=n,v=r}return this.setMsaFormat([o,l]),g}setSeqAlignChainForAll(e,t,i){let s=this.icn3d,n=s.icn3dui,r={},a=e[0];s.alnChainsAnno[a]=[],s.alnChainsAnTtl[a]=[];let o=e.length;void 0===s.alnChainsAnTtl[a]&&(s.alnChainsAnTtl[a]=[]);for(let e=0;e<3+2*o;++e)void 0===s.alnChainsAnTtl[a][e]&&(s.alnChainsAnTtl[a][e]=[]);for(let t=0;t<o;++t)s.alnChainsAnTtl[a][t].push(e[o-1-t]);s.alnChainsAnTtl[a][o].push(""),s.alnChainsAnTtl[a][o+1].push("");for(let t=o+2;t<2*o+2;++t)s.alnChainsAnTtl[a][t].push(e[2*o+1-t]);s.alnChainsAnTtl[a][2*o+2].push(""),s.alnChainsSeq[a]=[],s.alnChains={},s.alnChains[a]={};let l={},d=9999,c=-1;s.chainsSeq[a][0].resi;for(let t=1,i=e.length;t<i;++t){let i=t-1;if(e[t],s.qt_start_end[i])for(let t=0,n=s.qt_start_end[i].length;t<n;++t){let n,r;n=s.ParserUtilsCls.getResiNCBI(a,s.qt_start_end[i][t].t_start)-1,r=s.ParserUtilsCls.getResiNCBI(a,s.qt_start_end[i][t].t_end)-1;for(let t=n;t<=r;++t){let i,n,r=t;i=s.ParserUtilsCls.getResi(e[0],r),n=e[0]+"_"+i,l[n]=1,t<d&&(d=t),t>c&&(c=t)}}}"tmalign"==n.cfg.aligntool&&(i=!0);let h=Object.keys(l);h.sort((function(e,t){return parseInt(e.split("_")[2])-parseInt(t.split("_")[2])}));let p=-999,u=0,m=0,f=[],g=0;for(let e=0,t=h.length;e<t;++e){let t=h[e],i=t.split("_")[2];if(0==e)u=i;else if(e>0&&s.resid2ncbi[i]!=s.resid2ncbi[p]+1&&s.resid2ncbi[i]!=s.resid2ncbi[p]){m=p;for(let e=0,t=f.length;e<t;++e)l[f[e]]={resiStart:u,resiEnd:m,prevResiEnd:g};f=[],u=i,g=m}f.push(t),p=i}m=p;for(let e=0,t=f.length;e<t;++e)l[f[e]]={resiStart:u,resiEnd:m,prevResiEnd:g};for(let t=0,i=e.length;t<i;++t){let i=e[t];s.alnChainsSeq[i]=[],s.alnChains[i]={},s.alnChainsAnno[i]=[]}for(let e=0,t=s.chainsSeq[a].length;e<t;++e){let t=s.chainsSeq[a][e].resi,i=a+"_"+t,o=s.ParserUtilsCls.getResiNCBI(a,t)-1;if(o<d||o>c)continue;let h={},p=a.indexOf("_");h.mmdbid=a.substr(0,p),h.chain=a.substr(p+1),h.resi=t,h.resn=l[i]?s.chainsSeq[a][e].name.toUpperCase():s.chainsSeq[a][e].name.toLowerCase(),h.aligned=!!l[i],h.color=l[i]?"#FF0000":n.htmlCls.GREYC,h.color2=l[i]?"#FF0000":n.htmlCls.GREYC,h.class=l[i]?"icn3d-cons":"icn3d-nalign",s.alnChainsSeq[a].push(h),l[i]&&($.extend(s.alnChains[a],s.residues[a+"_"+h.resi]),r=n.hashUtilsCls.unionHash(r,s.residues[a+"_"+h.resi]))}let b=[0];for(let s=0,a=t.length;s<a;++s){let a=t[s].index;b.push(a);let o=this.mergeTwoSeqForAll(e,a,b,l,d,c,i);r=n.hashUtilsCls.unionHash(r,o)}this.setMsaFormat(e);for(let e=0;e<3+2*o;++e)void 0===s.alnChainsAnno[a][e]&&(s.alnChainsAnno[a][e]=[]);for(let t=0;t<o;++t){let i=e[t];for(let e=0,n=s.alnChainsSeq[i].length;e<n;++e){if("-"==s.alnChainsSeq[i][e].resn)s.alnChainsAnno[a][o-1-t].push("-");else{let n=i+"_"+s.alnChainsSeq[i][e].resi,r=s.secondaries[n];void 0!==r?s.alnChainsAnno[a][o-1-t].push(r):s.alnChainsAnno[a][o-1-t].push("-")}}}for(let e=0,t=s.alnChainsSeq[a].length;e<t;++e){let t=".";e%5==0&&(t="*"),e%10==0&&(t="|"),s.alnChainsAnno[a][o].push(t);let i="";e%10==0&&(i=e.toString()),s.alnChainsAnno[a][o+1].push(i)}for(let t=o+2;t<2*o+2;++t){let i=s.pdbid_chain2title&&s.pdbid_chain2title.hasOwnProperty(e[2*o+1-t])?s.pdbid_chain2title[e[2*o+1-t]]:"";s.alnChainsAnno[a][t].push(i)}return s.alnChainsAnno[a][2*o+2].push(""),r}getResObject(e,t,i,s,n,r){let a=this.icn3d,o=a.icn3dui,l={},d=e.indexOf("_");return l.mmdbid=e.substr(0,d),l.chain=e.substr(d+1),l.resi=t?"":s,l.resn=n?t?"-":i?n.toUpperCase():n.toLowerCase():"-",l.aligned=!t&&i,l.color=t||!i?o.htmlCls.GREYC:n==r?"#FF0000":"#0000FF",l.color2=t||!i?o.htmlCls.GREYC:"#"+a.showAnnoCls.getColorhexFromBlosum62(n,r),l.class=t||!i?"icn3d-nalign":n==r?"icn3d-cons":"icn3d-ncons",l}getResn(e,t){let i,s=this.icn3d;return s.icn3dui,i=s.chainsSeq[e]&&s.chainsSeq[e][t]?s.chainsSeq[e][t].name:"",i}getResiPosInTemplate(e,t){let i=this.icn3d;i.icn3dui;let s,n=0;if(i.alnChainsSeq[e])for(let r=0,a=i.alnChainsSeq[e].length;r<a;++r){if(parseInt(i.alnChainsSeq[e][r].resi)==parseInt(t)){s=r;break}"-"==i.alnChainsSeq[e][r].resn?++n:n=0}return{pos:s,ngap:n}}addGapAllAlnChains(e,t,i,s,n){let r=this.icn3d;r.icn3dui;let a=this.getResiPosInTemplate(i,s);a.ngap;let o=a.pos;for(let i=0,s=t.length-1;i<s;++i){let s=e[t[i]],a=this.getResObject(s,!0);for(let e=0,t=n;e<t;++e)r.alnChainsSeq[s].splice(o,0,a)}}insertNotAlignRes(e,t,i,s){let n=this.icn3d;n.icn3dui;for(let s=0,r=i;s<r;++s){let i=t+s,r=this.getResnFromResi(e,i),a="-",o=!1,l=this.getResObject(e,!1,o,i,r,a);n.alnChainsSeq[e].push(l)}}getTemplatePosFromOriResi(e,t,i,s){this.icn3d.icn3dui;let n=t,r=i,a=this.getResiPosInTemplate(e,n),o=this.getResiPosInTemplate(e,r);return{pos1:a.pos,pos2:o.pos}}mergeTwoSeqForAll(e,t,i,s,n,r,a){let o,l,d,c,h,p,u,m,f,g,b=this.icn3d,C=b.icn3dui,v={},_=e[t],y=t-1;if(u=e[0].indexOf("_"),m=_.indexOf("_"),o=e[0].substr(0,u),l=_.substr(0,m),d=e[0].substr(u+1),c=_.substr(m+1),o==l&&d==c){let e=b.chainsSeq[b.mmdbid_q+"_"+b.chain_q].length;b.qt_start_end[y]={q_start:1,q_end:e,t_start:1,t_end:e}}if(h=o+"_"+d,p=l+"_"+c,void 0!==l&&b.mmdbid_t,b.alnChains[p]={},b.conservedName2=p+"_cons",b.nonConservedName2=p+"_ncons",b.notAlignedName2=p+"_nalign",b.consHash2={},b.nconsHash2={},b.nalignHash2={},void 0===b.qt_start_end[y])return;this.getResObject(h,!0);let S,w=this.getResObject(p,!0);b.chainsMapping[h]||(b.chainsMapping[h]={}),b.chainsMapping[p]||(b.chainsMapping[p]={});for(let t=0,s=b.qt_start_end[y].length;t<s;++t){let s,r,o,l,d,c;if(a&&"tmalign"==C.cfg.aligntool?(s=parseInt(b.qt_start_end[y][t].t_start),r=parseInt(b.qt_start_end[y][t].q_start),o=parseInt(b.qt_start_end[y][t].t_end),l=parseInt(b.qt_start_end[y][t].q_end),d=s,c=this.getPosFromResi(h,b.qt_start_end[y][t].t_start),this.getPosFromResi(h,b.qt_start_end[y][t].t_end)):(s=parseInt(b.qt_start_end[y][t].t_start-1),r=parseInt(b.qt_start_end[y][t].q_start-1),o=parseInt(b.qt_start_end[y][t].t_end-1),l=parseInt(b.qt_start_end[y][t].q_end-1),d=b.ParserUtilsCls.getResi(h,s),c=s),0==t){if(S=this.getTemplatePosFromOriResi(h,n,c,a),u=S.pos1,m=S.pos2,c>n)for(let e=0,t=m-u;e<t;++e)b.alnChainsSeq[p].push(w)}else{S=this.getTemplatePosFromOriResi(h,f,s,a),u=S.pos1,m=S.pos2;let t=m-(u+1),n=r-(g+1);if(this.insertNotAlignRes(p,g+1,n,a),t>=n)for(let e=0,i=t-n;e<i;++e)b.alnChainsSeq[p].push(w);else this.addGapAllAlnChains(e,i,h,d,n-t)}S=this.getTemplatePosFromOriResi(h,s,o,a),u=S.pos1,m=S.pos2;let _=0;b.chainsMapping[h]||(b.chainsMapping[h]={}),b.chainsMapping[p]||(b.chainsMapping[p]={});for(let e=u;e<=m;++e)if("-"==b.alnChainsSeq[h][e].resn)b.alnChainsSeq[p].push(w);else{let t=a?s+_:b.ParserUtilsCls.getResi(h,s+_),i=a?r+_:b.ParserUtilsCls.getResi(p,r+_),n=this.getResnFromResi(h,t),o=this.getResnFromResi(p,i),l=!0,d=this.getResObject(p,!1,l,i,o,n);b.alnChainsSeq[p].push(d),b.alnChainsSeq[h][e].color=d.color,b.chainsMapping[h][h+"_"+t]=n+t,b.chainsMapping[p][p+"_"+i]=n+t,$.extend(b.alnChains[p],b.residues[p+"_"+i]),v=C.hashUtilsCls.unionHash(v,b.residues[p+"_"+i]),++_}f=o,g=l}S=this.getTemplatePosFromOriResi(h,f,r,a),u=S.pos1,m=S.pos2;for(let e=u;e<m;++e)b.alnChainsSeq[p].push(w);return v}mergeTwoSeqForAllSimple(e,t,i,s,n,r,a){let o=this.icn3d;o.icn3dui;let l,d,c,h,p=e,u=t[i];for(let e=0,r=o.qt_start_end[i].length;e<r;++e){let r,m,f,g,b,C,v;if(r=o.qt_start_end[i][e].t_start,m=o.qt_start_end[i][e].q_start,f=o.qt_start_end[i][e].t_end,g=o.qt_start_end[i][e].q_end,b=r,C=r,v=f,0==e){if(l=n,d=C,C>n)for(let e=0,t=d-l;e<t;++e)o.msaSeq[u]+="-"}else{l=c,d=r;let e=d-(l+1),n=m-(h+1);for(let e=0,t=n;e<t;++e){let t=a[i][h+1+e];o.msaSeq[u]+=t}if(e>=n)for(let t=0,i=e-n;t<i;++t)o.msaSeq[u]+="-";else{let i=b;for(let r=0,a=s.length-1;r<a;++r){let a=0==r?p:t[s[r]];for(let t=0,s=n-e;t<s;++t)o.msaSeq[a]=o.msaSeq[a].substr(0,i)+"-"+o.msaSeq[a].substr(i)}}}l=C,d=v;let _=0;for(let e=l;e<=d;++e)if("-"==o.msaSeq[p][e])o.msaSeq[u]+="-";else{let e=a[i][m+_];o.msaSeq[u]+=e,++_}c=f,h=g}l=c,d=r;for(let e=l;e<d;++e)o.msaSeq[u]+="-"}setSeqAlignForRealign(e,t,i){let s=this.icn3d,n=s.icn3dui;s.conservedName1=e+"_cons",s.conservedName2=t+"_cons",s.consHash1={},s.consHash2={},s.alnChainsAnTtl={},s.alnChainsAnno={},void 0===s.alnChainsSeq&&(s.alnChainsSeq={}),s.alnChains={},s.alnChainsSeq[e]=[],s.alnChains[e]={},s.alnChainsAnno[e]=[],s.alnChainsAnTtl[e]=[],s.alnChainsSeq[t]=[],s.alnChains[t]={};let r={};s.chainsMapping[e]||(s.chainsMapping[e]={}),s.chainsMapping[t]||(s.chainsMapping[t]={});for(let i=0,a=s.realignResid[e].length;i<a;++i){let a=s.realignResid[e][i],o=a.resid.lastIndexOf("_"),l=a.resid.substr(0,o),d=a.resid.substr(o+1);a.resi=d,a.aligned=!0;let c,h=s.realignResid[t][i],p=h.resid.lastIndexOf("_"),u=h.resid.substr(0,p),m=h.resid.substr(p+1);h.resi=m,h.aligned=!0,r[a.resid]=1,r[h.resid]=1,c=a.resn.toUpperCase()==h.resn.toUpperCase()?"#FF0000":"#0000FF",s.chainsMapping[e][e+"_"+a.resi]=a.resn+a.resi,s.chainsMapping[t][t+"_"+h.resi]=a.resn+a.resi;let f="#"+s.showAnnoCls.getColorhexFromBlosum62(a.resn,h.resn);a.color=c,h.color=c,a.color2=f,h.color2=f;for(let e in s.residues[a.resid])s.atoms[e].color=n.parasCls.thr(c);for(let e in s.residues[h.resid])s.atoms[e].color=n.parasCls.thr(c);void 0===s.alnChainsAnTtl[l]&&(s.alnChainsAnTtl[l]=[]);for(let e=0;e<3;++e)void 0===s.alnChainsAnTtl[l][e]&&(s.alnChainsAnTtl[l][e]=[]);for(let e=0;e<3;++e)s.alnChainsAnTtl[l][e].push("");void 0===s.alnChainsSeq[l]&&(s.alnChainsSeq[l]=[]),void 0===s.alnChainsSeq[u]&&(s.alnChainsSeq[u]=[]),s.alnChainsSeq[l].push(a),s.alnChainsSeq[u].push(h),void 0===s.alnChains[l]&&(s.alnChains[l]={}),void 0===s.alnChains[u]&&(s.alnChains[u]={}),$.extend(s.alnChains[l],s.residues[l+"_"+a.resi]),$.extend(s.alnChains[u],s.residues[u+"_"+h.resi]),s.consHash1[l+"_"+a.resi]=1,s.consHash2[u+"_"+h.resi]=1,void 0===s.alnChainsAnno[l]&&(s.alnChainsAnno[l]=[]);for(let e=0;e<3;++e)void 0===s.alnChainsAnno[l][e]&&(s.alnChainsAnno[l][e]=[]);let g=".";i%5==0&&(g="*"),i%10==0&&(g="|"),s.alnChainsAnno[l][0].push(g);let b="";i%10==0&&(b=i.toString()),s.alnChainsAnno[l][1].push(b)}let a="select "+s.resid2specCls.residueids2spec(Object.keys(r));s.selectionCls.addCustomSelection(Object.keys(r),"protein_aligned","protein aligned",a,!0)}setSeqPerResi(e,t,i,s,n,r,a,o,l,d,c,h){let p=this.icn3d,u=p.icn3dui;void 0===p.alnChainsSeq[e]&&(p.alnChainsSeq[e]=[]);let m={},f=e.indexOf("_");if(m.mmdbid=e.substr(0,f),m.chain=e.substr(f+1),m.resi=s,m.resn=""===m.resi||"icn3d-nalign"===l?n.toLowerCase():n,m.aligned=r,m.color=""===m.resi?u.htmlCls.GREYC:a,m.color2=""===m.resi?u.htmlCls.GREYC:o,m.class=l,p.alnChainsSeq[e].push(m),""!==m.resi&&(void 0===p.alnChains[e]&&(p.alnChains[e]={}),$.extend(p.alnChains[e],p.residues[e+"_"+m.resi])),d){if(void 0===p.alnChainsAnno[e]&&(p.alnChainsAnno[e]=[]),void 0===p.alnChainsAnno[e][0]&&(p.alnChainsAnno[e][0]=[]),void 0===p.alnChainsAnno[e][1]&&(p.alnChainsAnno[e][1]=[]),void 0===p.alnChainsAnno[e][2]&&(p.alnChainsAnno[e][2]=[]),void 0===p.alnChainsAnno[e][3]&&(p.alnChainsAnno[e][3]=[]),c){void 0===p.alnChainsAnno[e][4]&&(p.alnChainsAnno[e][4]=[]),void 0===p.alnChainsAnno[e][5]&&(p.alnChainsAnno[e][5]=[]),void 0===p.alnChainsAnno[e][6]&&(p.alnChainsAnno[e][6]=[]);let t=p.pdbid_chain2title&&p.pdbid_chain2title.hasOwnProperty(i)?p.pdbid_chain2title[i]:"",s=p.pdbid_chain2title&&p.pdbid_chain2title.hasOwnProperty(e)?p.pdbid_chain2title[e]:"";p.alnChainsAnno[e][4].push(t),p.alnChainsAnno[e][5].push(s),p.alnChainsAnno[e][6].push("")}let t=".";h%5==0&&(t="*"),h%10==0&&(t="|"),p.alnChainsAnno[e][2].push(t);let n="";h%10==0&&(n=h.toString()),p.alnChainsAnno[e][3].push(n);let r=e+"_"+s,a=p.secondaries[r];void 0!==a?p.alnChainsAnno[e][1].push(a):p.alnChainsAnno[e][1].push("-")}else{let i=e+"_"+s,n=p.secondaries[i];p.alnChainsAnno.hasOwnProperty(t)&&p.alnChainsAnno[t].length>0?void 0!==n?p.alnChainsAnno[t][0].push(n):p.alnChainsAnno[t][0].push("-"):console.log("Error: ic.alnChainsAnno[chainid1] is undefined")}}setMsaFormat(e){let t=this.icn3d;t.icn3dui;let i="",s="CLUSTALWW\n\n",n="",r=[],a=[],o=[],l=e[0];for(let s=0,d=e.length;s<d;++s){let c=e[s];i+=">"+c+"\n";let h=[],p=c.padEnd(20," "),u="".padEnd(20," "),m=[],f=[],g=0;for(let e=0,n=t.alnChainsSeq[c].length;e<n;++e){let n=t.alnChainsSeq[c][e].resn;if(i+=n,p+=n,s==d-1){let i=t.alnChainsSeq[c][e].class;u+="icn3d-cons"==i?"*":"icn3d-ncons"==i?".":" "}0==s?o.push(t.alnChainsSeq[c][e].resi):t.alnChainsSeq[c][e].aligned&&t.alnChainsSeq[l][e]&&t.alnChainsSeq[c][e]&&(m.push(t.alnChainsSeq[l][e].resi),f.push(t.alnChainsSeq[c][e].resi)),++g,g%60==0&&(i+="\n",p+=" "+String(60*parseInt(g/60)),h.push(p),p=c.padEnd(20," "),s==d-1&&(a.push(u),u="".padEnd(20," ")))}g%60!=0&&(h.push(p),s==d-1&&a.push(u)),i+="\n",r.push(h),s==d-1&&r.push(a);let b=t.resid2specCls.resi2range(m,!0),C=t.resid2specCls.resi2range(f,!0);s>0&&(n+=b+" | "+C+"\n")}for(let e=0,t=r[0].length;e<t;++e){for(let t=0,i=r.length;t<i;++t)s+=r[t][e]+"\n";s+="\n"}t.msa||(t.msa={}),t.msa.fasta||(t.msa.fasta=[]),t.msa.clustalw||(t.msa.clustalw=[]),t.msa.resbyres||(t.msa.resbyres=[]),t.msa.fasta.push(i),t.msa.clustalw.push(s),t.msa.resbyres.push(n)}}class $h{constructor(e){this.icn3d=e}getStructureId(e,t,i,s){let n=this.icn3d;n.icn3dui;let r=e=s&&n.idNMR?n.idNMR:e;return(e==n.defaultPdbId||i||n.structures.hasOwnProperty(e))&&(r=1===t?e:e+t.toString()),r}loadPDB(e,t,i,s,n,r,a,o){let l,d,c=this.icn3d,h=c.icn3dui,p={},u=!1,m=e.split("\n"),f={},g={};c.atoms||(r=!1),c.statefileArray&&(c.struct_statefile=[]),n||r?(c.oriNStru=c.structures?Object.keys(c.structures).length:0,d=c.oriNStru+1,l=c.atoms?Object.keys(c.atoms).length:0):(c.init(),d=1,l=0);let b,C,v,_,y,S,w,x,A,M=[],T=[],E=[],R=[],k=[],O=[],I="",P="",D="",L={},F=t||c.defaultPdbId,N=F,U=F,H="",B=!1,z=!0;for(let e in m){let a=m[e],q=a.substr(0,6);if("HEADER"!==q||B||t)if("TITLE "===q){let e=a.substr(10).replace(/ALPHAFOLD MONOMER V2.0 PREDICTION FOR /gi,"");c.molTitle+=e.trim()+" ",o&&c.esmTitle&&(c.molTitle=c.esmTitle),c.molTitleHash||(c.molTitleHash={}),c.molTitleHash[U]=c.molTitle}else if("HELIX "===q){c.bSecondaryStructure=!0;let e=""==a.substr(18,2).trim()?"A":a.substr(18,2).trim(),t=parseInt(a.substr(21,4)),i=parseInt(a.substr(33,4));for(let s=t;s<=i;++s){let n=U+"_"+e+"_"+s;R.push(n),s===t&&k.push(n),s===i&&O.push(n)}}else if("SHEET "===q){void 0!==i&&i||(c.bSecondaryStructure=!0);let e=""==a.substr(20,2).trim()?"A":a.substr(20,2).trim(),t=parseInt(a.substr(22,4)),s=parseInt(a.substr(33,4));for(let i=t;i<=s;++i){let n=U+"_"+e+"_"+i;M.push(n),i===t&&T.push(n),i===s&&E.push(n)}}else if("HBOND "===q)void 0!==i&&i||(c.bSecondaryStructure=!0);else if("SSBOND"===q){c.bSsbondProvided=!0;let e=U+"_"+(" "==a.substr(15,1)?"A":a.substr(15,1))+"_"+a.substr(17,4).trim(),t=U+"_"+(" "==a.substr(29,1)?"A":a.substr(29,1))+"_"+a.substr(31,4).trim();void 0===c.ssbondpnts[U]&&(c.ssbondpnts[U]=[]),c.ssbondpnts[U].push(e),c.ssbondpnts[U].push(t)}else if("REMARK"===q){let e=parseInt(a.substr(7,3));if(-1!==a.indexOf("1/2 of bilayer thickness:"))c.halfBilayerSize=parseFloat(a.substr(a.indexOf(":")+1).trim());else if(210==e)"EXPERIMENT TYPE"==a.substr(11,32).trim()&&"NMR"==a.substr(45).trim()&&(u=!0,c.idNMR=N);else if(350==e&&"BIOMT"==a.substr(13,5)){let e=parseInt(a[18])-1,t=parseInt(a.substr(21,2))-1;null==c.biomtMatrices[t]&&(c.biomtMatrices[t]=(new gi).identity()),c.biomtMatrices[t].elements[e]=parseFloat(a.substr(24,9)),c.biomtMatrices[t].elements[e+4]=parseFloat(a.substr(34,9)),c.biomtMatrices[t].elements[e+8]=parseFloat(a.substr(44,9)),c.biomtMatrices[t].elements[e+12]=parseFloat(a.substr(54,14))}else if(465==e&&" "==a.substr(18,1)&&" "==a.substr(20,1)&&"S"!=a.substr(21,1)){let e=a.substr(15,3),t=a.substr(18,2).trim(),i=a.substr(21,5).trim(),s=F+"_"+t;void 0===c.chainMissingResidueArray[s]&&(c.chainMissingResidueArray[s]=[]);let n={};n.resi=i,n.name=h.utilsCls.residueName2Abbr(e).toLowerCase(),""!=H&&t==H&&t!=H||(c.chainMissingResidueArray[s].push(n),H=t)}else 900==e&&void 0===c.emd&&"RELATED DB: EMDB"==a.substr(34).trim()&&(c.emd=a.substr(23,11).trim())}else if("SOURCE"===q&&void 0===c.organism&&"ORGANISM_COMMON"==a.substr(11,15).trim())c.organism=a.substr(28).toLowerCase().trim(),c.organism=c.organism.substr(0,c.organism.length-1);else if("ENDMDL"===q)c.statefileArray&&c.struct_statefile.push({structure:U,statefile:c.statefileArray[d-1]}),++d,F=c.defaultPdbId,U=this.getStructureId(F,d,n,u),u||(M=[],T=[],E=[],R=[],k=[],O=[]),B=!1;else if("JRNL "===q)"PMID"===a.substr(12,4)&&(c.pmid=a.substr(19).trim());else if("ATOM "===q||"HETATM"===q){x=a.substr(72,4).trim(),z?(U=this.getStructureId(F,d,n,u),z=!1):x!=A&&(++d,F=c.defaultPdbId,U=this.getStructureId(F,d,n,u),u||(M=[],T=[],E=[],R=[],k=[],O=[]),B=!1),A=x;let e=a.substr(16,1);++l,L[parseInt(a.substr(6,5))]=l;let t=a.substr(76,2).trim();""===t&&(t=a.substr(12,2).trim());let r=a.substr(12,4).trim(),m=a.substr(17,3),N=a.substr(20,2).trim();""===N&&(N="A");let H=a.substr(22,5).trim(),j=H;if(i&&"DUM"===m&&(t=r,N="MEM",j=1,H=1),s&&"DUM"===m)break;b=U+"_"+N,v=b+"_"+H,C=b+"_"+j;let G=parseFloat(a.substr(30,8)),$=parseFloat(a.substr(38,8)),V=parseFloat(a.substr(46,8)),W=new mt(G,$,V),X=parseFloat(a.substr(60,8));o&&(X*=100);let Y={het:"H"===q[0],serial:l,name:r,alt:e,resn:m,structure:U,chain:N,resi:j,coord:W,b:X,elem:t,bonds:[],ss:"coil",ssbegin:!1,ssend:!1};if(Y.het||"C"!==Y.name||(_=l),Y.het||"O"!==Y.name||(S=l),!Y.het&&"N"===Y.name&&void 0!==y&&void 0!==w){let e=c.atoms[y].coord.distanceTo(c.atoms[w].coord),t=Y.coord.x+(c.atoms[y].coord.x-c.atoms[w].coord.x)/e,i=Y.coord.y+(c.atoms[y].coord.y-c.atoms[w].coord.y)/e,s=Y.coord.z+(c.atoms[y].coord.z-c.atoms[w].coord.z)/e;Y.hcoord=new mt(t,i,s)}c.atoms[l]=Y,c.dAtoms[l]=1,c.hAtoms[l]=1,p[l]=1,this.isSecondary(C,M,u)?(c.atoms[l].ss="sheet",this.isSecondary(C,T,u)&&(c.atoms[l].ssbegin=!0),this.isSecondary(C,E,u)&&(c.atoms[l].ssend=!0)):this.isSecondary(C,R,u)&&(c.atoms[l].ss="helix",this.isSecondary(C,k,u)&&(c.atoms[l].ssbegin=!0),this.isSecondary(C,O,u)&&(c.atoms[l].ssend=!0));let K="-";if(K="helix"===c.atoms[l].ss?"H":"sheet"===c.atoms[l].ss?"E":!c.atoms[l].het&&h.parasCls.residueColors.hasOwnProperty(c.atoms[l].resn.toUpperCase())?"c":"o",c.secondaries[C]=K,v!==D){let e=h.utilsCls.residueName2Abbr(m);if(c.residueId2Name[C]=e,1!==l&&""!==P&&(c.residues[P]=g),C!==P&&(g={}),b!==I){y=void 0,w=void 0,1!==l&&""!==I&&(void 0===c.chains[I]&&(c.chains[I]={}),c.chains[I]=h.hashUtilsCls.unionHash(c.chains[I],f)),f={},void 0===c.structures[U.toString()]&&(c.structures[U.toString()]=[]),c.structures[U.toString()].includes(b)||c.structures[U.toString()].push(b),void 0===c.chainsSeq[b]&&(c.chainsSeq[b]=[]);let t={};t.resi=j,t.name=e,c.chainsSeq[b].push(t)}else{y=_,w=S;let t={};t.resi=j,t.name=e,c.chainsSeq[b].push(t)}}f[l]=1,g[l]=1,I=b,P=C,D=v}else if("CONECT"===q){let e=parseInt(a.substr(6,5));for(let t=0;t<4;++t){let i=parseInt(a.substr([11,16,21,26][t],5));isNaN(i)||void 0!==c.atoms[L[e]]&&c.atoms[L[e]].bonds.push(L[i])}}else q.substr(0,3);else F=a.substr(62).trim(),F=F.replace(/_/g,"-"),N=F,""==F&&(F=r?c.defaultPdbId:c.inputid&&-1==c.inputid.indexOf("/")?c.inputid.substr(0,10):c.defaultPdbId),U=this.getStructureId(F,d,n,u),c.molTitle="",void 0===c.allData&&(c.molTitleHash={}),B=!0}c.residues[C]=g,void 0===c.chains[b]&&(c.chains[b]={}),c.chains[b]=h.hashUtilsCls.unionHash2Atoms(c.chains[b],f,c.atoms),c.statefileArray&&c.struct_statefile.push({structure:U,statefile:c.statefileArray[d-1]}),this.adjustSeq(c.chainMissingResidueArray);let q=Object.keys(c.structures);for(let e=0,t=q.length;e<t;++e){let t=q[e];if(t!=F&&(void 0===c.ssbondpnts[t]&&(c.ssbondpnts[t]=[]),void 0!==c.ssbondpnts[F]))for(let e=0,i=c.ssbondpnts[F].length;e<i;++e){let i=c.ssbondpnts[F][e],s=i.indexOf("_"),n=t+i.substr(s);c.ssbondpnts[t].push(n)}}c.bSsbondProvided||this.setSsbond(),m=null;let j,G,V=[],W=new mt(9999,9999,9999),X=new mt(-9999,-9999,-9999),Y=new mt,K=0,Z={},J=[];for(let e in c.hAtoms){let t=c.atoms[e],i=t.coord;Y.add(i),W.min(i),X.max(i),++K,1==K&&(j=t.chain,G=t.resi,J.push(t)),t.het?t.het&&("HOH"===t.resn||"WAT"===t.resn||"SOL"===t.resn?c.water[t.serial]=1:-1!==$.inArray(t.resn,h.parasCls.ionsArray)||t.elem.trim()===t.resn.trim()?c.ions[t.serial]=1:c.chemicals[t.serial]=1,t.color=h.parasCls.atomColors[t.elem]):-1!==$.inArray(t.resn,h.parasCls.nucleotidesArray)?(c.nucleotides[t.serial]=1,"O3'"!==t.name&&"O3*"!==t.name||(c.nucleotidesO3[t.serial]=1,c.secondaries[t.structure+"_"+t.chain+"_"+t.resi]="o"),-1===h.parasCls.nuclMainArray.indexOf(t.name)&&(c.ntbase[t.serial]=1)):("P"===t.elem&&(Z[t.structure+"_"+t.chain+"_"+t.resi]=1),c.proteins[t.serial]=1,"CA"===t.name&&(c.calphas[t.serial]=1),"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&(c.sidec[t.serial]=1)),j===t.chain&&G===t.resi||(this.refreshBonds(V,J[0]),J.splice(0,1),j=t.chain,G=t.resi,V.length=0),V.push(t),"C"!==t.name&&"O3'"!==t.name||J.push(t)}this.refreshBonds(V,J[0]);for(let e in Z){let t=c.residues[e];for(l in t){let t=c.atoms[l];t.het=!0,c.chemicals[t.serial]=1,c.secondaries[e]="o",delete c.proteins[t.serial],"CA"===t.name&&delete c.calphas[t.serial],"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&delete c.sidec[t.serial]}}return c.pmin=W,c.pmax=X,c.cnt=K,c.center=c.ParserUtilsCls.getGeoCenter(c.pmin,c.pmax),c.maxD=c.ParserUtilsCls.getStructureSize(c.atoms,c.pmin,c.pmax,c.center),c.maxD<5&&(c.maxD=5),c.oriMaxD=c.maxD,c.oriCenter=c.center.clone(),"target"===a?(c.oriMaxD=c.maxD,c.center1=c.center):"query"===a&&(c.oriMaxD<c.maxD&&(c.oriMaxD=c.maxD),c.center2=c.center,c.center=new mt(0,0,0)),s?this.getChainCalpha(c.chains,c.atoms):p}refreshBonds(e,t){let i=this.icn3d.icn3dui,s=e.length;for(let n=0;n<s;++n){let r=e[n];for(let t=n+1;t<s;++t){let s=e[t];r.alt===s.alt&&i.utilsCls.hasCovalentBond(r,s)&&(r.bonds.push(s.serial),s.bonds.push(r.serial))}!t||"C"!==t.name&&"O3'"!==t.name||"N"!==r.name&&"P"!==r.name||!i.utilsCls.hasCovalentBond(r,t)||(r.bonds.push(t.serial),t.bonds.push(r.serial))}}adjustSeq(e){let t=this.icn3d;t.icn3dui;for(let i in t.chainsSeq)void 0!==e[i]&&(t.chainsSeq[i]=this.mergeTwoSequences(e[i],t.chainsSeq[i]));this.setResidMapping()}mergeTwoSequences(e,t){let i=e.length,s=t.length,n=parseInt(e[i-1].resi),r=parseInt(t[s-1].resi),a=n>=r?n:r,o=new Array(i+s),l=0,d=0,c=0,h=!1;for(;l<i&&d<s;){let i=parseInt(e[l].resi),s=parseInt(t[d].resi);i>a&&s>a&&(h=!0),i<=a&&s>a?i>s||h?(o[c]=t[d],d++):(o[c]=e[l],l++):i>a&&s<=a?i<=s||h?(o[c]=e[l],l++):(o[c]=t[d],d++):i<=s?(o[c]=e[l],l++):(o[c]=t[d],d++),c++}if(l<i)for(let t=l;t<i;t++)o[c]=e[t],c++;else for(let e=d;e<s;e++)o[c]=t[e],c++;return o}setResidMapping(){let e=this.icn3d;e.icn3dui;for(let t in e.chainsSeq)for(let i=0,s=e.chainsSeq[t].length;i<s;++i){let s=t+"_"+(i+1).toString(),n=t+"_"+e.chainsSeq[t][i].resi;e.ncbi2resid[s]=n,e.resid2ncbi[n]=s}}setSsbond(e){let t=this.icn3d;t.icn3dui;let i={};for(let s in t.chainsSeq){if(e&&!e.hasOwnProperty(s))continue;let n=t.chainsSeq[s],r=s.substr(0,s.indexOf("_"));for(let e=0,t=n.length;e<t;++e)"C"==n[e].name&&(null==i[r]&&(i[r]=[]),i[r].push(s+"_"+n[e].resi))}for(let e in i){let s=i[e];for(let i=0,n=s.length;i<n;++i)for(let n=i+1,r=s.length;n<r;++n){let r,a,o=s[i],l=s[n];for(let e in t.residues[o])if("S"==t.atoms[e].elem){r=t.atoms[e].coord;break}for(let e in t.residues[l])if("S"==t.atoms[e].elem){a=t.atoms[e].coord;break}void 0!==r&&void 0!==a&&(Math.abs(r.x-a.x)>4||Math.abs(r.y-a.y)>4||Math.abs(r.z-a.z)>4||(r.x-a.x)*(r.x-a.x)+(r.y-a.y)*(r.y-a.y)+(r.z-a.z)*(r.z-a.z)<16&&(void 0===t.ssbondpnts[e]&&(t.ssbondpnts[e]=[]),t.ssbondpnts[e].push(o),t.ssbondpnts[e].push(l)))}}}getChainCalpha(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a={};for(let o in e){if(void 0!==s){if(o.split("_")[0]!==s)continue}let l=Object.keys(e[o]),d=[],c=0,h=0;for(let e=0,s=l.length;e<s;++e){let s=t[l[e]];if(n.proteins.hasOwnProperty(l[e])&&"CA"==s.name||n.nucleotides.hasOwnProperty(l[e])&&("O3'"==s.name||"O3*"==s.name)){if(s.resi==h)continue;let e=s.resn.trim().length>3?s.resn.trim().substr(0,3):s.resn.trim();if(!r.parasCls.chargeColors.hasOwnProperty(e))continue;i?s.resi_ori:s.resi,d.push(s.coord.clone()),++c,h=s.resi}}if(c>0){a[t[l[0]].chain]=d}}return{chainresiCalphaHash:a,center:n.center.clone()}}isSecondary(e,t,i,s){if(this.icn3d.icn3dui,s)return!1;if(i){let i=e.substr(e.indexOf("_")+1),s=!1;for(let e=0,n=t.length;e<n;++e)if(i==t[e].substr(t[e].indexOf("_")+1)){s=!0;break}return s}return-1!=$.inArray(e,t)}}class Vh{constructor(e){this.icn3d=e}loadCIF(e,t,i,s){let n,r,a=this.icn3d,o=a.icn3dui,l={},d=!1,c={},h={};a.atoms||(s=!1),s?(a.oriNStru=a.structures?Object.keys(a.structures).length:0,r=a.oriNStru,n=a.atoms?Object.keys(a.atoms).length:0):(a.init(),r=0,n=0);let p,u,m,f,g,b,C,v=[],_=[],y=[],S=[],w=[],x=[],A="",M="",T="",E=t||a.defaultPdbId,R=E,k=i?e.split("ENDMDL\n"):[e];for(let e=0,t=k.length;e<t;++e){++r,E=a.defaultPdbId,R=a.loadPDBCls.getStructureId(E,r),v=[],_=[],y=[],S=[],w=[],x=[];let t=i?CIFTools.Text.parse(k[e]):CIFTools.Binary.parse(k[e]);if(t.isError)return void alert("The Binary CIF data can NOT be parsed: "+t.toString());let O=t.result.dataBlocks[0];if(O.getCategory("_entry")&&(E=O.getCategory("_entry").getColumn("id").getString(0),E=E.replace(/_/g,"-"),""==E&&(E=s?a.defaultPdbId:a.inputid&&-1==a.inputid.indexOf("/")?a.inputid.substr(0,10):a.defaultPdbId),R=a.loadPDBCls.getStructureId(E,r),a.molTitle="",a.molTitleHash={}),O.getCategory("_struct")){let e=O.getCategory("_struct").getColumn("title").getString(0);e=e.replace(/"/,"'");let t=e.replace(/ALPHAFOLD MONOMER V2.0 PREDICTION FOR /gi,"");a.molTitle+=t.trim()+" ",a.molTitleHash||(a.molTitleHash={}),a.molTitleHash[R]=a.molTitle}if(O.getCategory("_entity_src_gen")&&(a.organism=O.getCategory("_entity_src_gen").getColumn("gene_src_common_name").getString(0)),O.getCategory("_database_2")){let e=O.getCategory("_database_2"),t=e.rowCount;for(let i=0;i<t;++i){let t=e.getColumn("database_id").getString(0),i=e.getColumn("database_code").getString(0);if("EMDB"==t){a.emd=i;break}}}if(O.getCategory("_struct_conf")){a.bSecondaryStructure=!0;let e=O.getCategory("_struct_conf"),t=e.getColumn("conf_type_id"),i=e.getColumn("beg_auth_asym_id"),s=e.getColumn("beg_auth_seq_id");e.getColumn("end_auth_asym_id");let n=e.getColumn("end_auth_seq_id"),r=e.rowCount;for(let e=0;e<r;++e){let r=t.getString(e),a=i.getString(e),o=parseInt(s.getString(e)),l=parseInt(n.getString(e));if("HELX"==r.substr(0,4))for(let e=parseInt(o);e<=parseInt(l);++e){let t=R+"_"+a+"_"+e;S.push(t),e==o&&w.push(t),e==l&&x.push(t)}else if("STRN"==r.substr(0,4))for(let e=o;e<=l;++e){let t=R+"_"+a+"_"+e;v.push(t),e==o&&_.push(t),e==l&&y.push(t)}}t=i=s=n=[]}if(O.getCategory("_struct_sheet_range")){let e=O.getCategory("_struct_sheet_range"),t=e.getColumn("beg_auth_asym_id"),i=e.getColumn("beg_auth_seq_id");e.getColumn("end_auth_asym_id");let s=e.getColumn("end_auth_seq_id"),n=e.rowCount;for(let e=0;e<n;++e){let n=t.getString(e),r=parseInt(i.getString(e)),a=parseInt(s.getString(e));for(let e=r;e<=a;++e){let t=R+"_"+n+"_"+e;v.push(t),e==r&&_.push(t),e==a&&y.push(t)}}t=i=s=[]}if(O.getCategory("_struct_conn")){a.bSsbondProvided=!0;let e=O.getCategory("_struct_conn"),t=e.getColumn("conn_type_id"),i=e.getColumn("ptnr1_auth_asym_id"),s=e.getColumn("ptnr1_label_atom_id"),n=e.getColumn("ptnr1_label_seq_id"),r=e.getColumn("ptnr2_auth_asym_id"),o=e.getColumn("ptnr2_label_atom_id"),l=e.getColumn("ptnr2_label_seq_id"),d=e.rowCount;for(let e=0;e<d;++e){let d=t.getString(e),c=i.getString(e);s.getString(e);let h=R+"_"+c+"_"+n.getString(e),p=r.getString(e);o.getString(e);let u=R+"_"+p+"_"+l.getString(e);"disulf"==d&&(void 0===a.ssbondpnts[R]&&(a.ssbondpnts[R]=[]),a.ssbondpnts[R].push(h),a.ssbondpnts[R].push(u))}t=i=s=n=r=o=l=[]}if(O.getCategory("_exptl")){-1!=O.getCategory("_exptl").getColumn("method").getString(0).indexOf("NMR")&&(d=!0)}if(O.getCategory("_pdbx_struct_oper_list")){let e=O.getCategory("_pdbx_struct_oper_list"),t=e.getColumn("id"),i=e.getColumn("matrix[1][1]"),s=e.getColumn("matrix[1][2]"),n=e.getColumn("matrix[1][3]"),r=e.getColumn("vector[1]"),o=e.getColumn("matrix[2][1]"),l=e.getColumn("matrix[2][2]"),d=e.getColumn("matrix[2][3]"),c=e.getColumn("vector[2]"),h=e.getColumn("matrix[3][1]"),p=e.getColumn("matrix[3][2]"),u=e.getColumn("matrix[3][3]"),m=e.getColumn("vector[3]"),f=e.rowCount;for(let e=0;e<f;++e){"X0"!=t.getString(e)&&(null==a.biomtMatrices[e]&&(a.biomtMatrices[e]=(new gi).identity()),a.biomtMatrices[e].set(i.getString(e),s.getString(e),n.getString(e),r.getString(e),o.getString(e),l.getString(e),d.getString(e),c.getString(e),h.getString(e),p.getString(e),u.getString(e),m.getString(e),0,0,0,1))}t=i=s=n=r=o=l=d=c=h=p=u=m=[]}O.getCategory("_citation")&&(a.pmid=O.getCategory("_citation").getColumn("pdbx_database_id_PubMed").getString(0));let I=O.getCategory("_atom_site"),P=I.rowCount,D=!(P>a.maxatomcnt);D||(a.opts.proteins="c alpha trace",a.opts.nucleotides="o3 trace");let L,F=I.getColumn("group_PDB"),N=I.getColumn("label_comp_id"),U=I.getColumn("type_symbol"),H=I.getColumn("label_atom_id"),B=I.getColumn("auth_asym_id"),z=I.getColumn("label_seq_id"),q=I.getColumn("auth_seq_id"),j=I.getColumn("label_alt_id"),G=I.getColumn("B_iso_or_equiv"),$=I.getColumn("Cartn_x"),V=I.getColumn("Cartn_y"),W=I.getColumn("Cartn_z"),X=I.getColumn("label_asym_id"),Y=I.getColumn("pdbx_PDB_model_num"),K={},Z="",J={},Q="";for(let e=0;e<P;++e){let t=Y.getString(e);e>0&&t!=Q&&(++r,R="1"==t?E:E+t),Q=t;let i,s=F.getString(e),k=N.getString(e),O=U.getString(e),I=H.getString(e),P=B.getString(e),ee=z.getString(e),te=q.getString(e),ie=j.getString(e),se=G.getString(e),ne=X.getString(e);if(ee=te,"ATOM"==s?i=3==k.length?"protein":"nucleotide":"WAT"==k||"HOH"==k?(i="solvent",P="Misc"):(i="ligand",P=k),""===P&&(P="A"),!D&&("protein"==i&&("C"!=O||"CA"!=I)||"nucleotide"==i&&"P"!=I))continue;if("B"==ie)continue;if(J[P]=1,++n,"?"!=ee&&"."!=ee&&"0"!=ee||(ee=te),"solvent"==i||"ligand"==i){let e={};K.hasOwnProperty(P)||(K[P]=[]),3!=k.length||"HOH"==k||"WAT"==k?3==k.length&&("O"!=O||"HOH"!=k&&"WAT"!=k)||(e.resi=ee,e.name=o.utilsCls.residueName2Abbr(k),K[P].push(e)):P+"_"+k==L&&Z==ne||(e.resi=ee,e.name=o.utilsCls.residueName2Abbr(k),K[P].push(e))}p=R+"_"+P,m=p+"_"+te,u=p+"_"+ee;let re=$.getFloat(e),ae=V.getFloat(e),oe=W.getFloat(e),le={het:"HETATM"==s,serial:n,name:I,alt:ie,resn:k,structure:R,chain:P,resi:ee,coord:new mt(re,ae,oe),b:se,elem:O,bonds:[],ss:"coil",ssbegin:!1,ssend:!1};if(le.het||"C"!==le.name||(f=n),le.het||"O"!==le.name||(b=n),!le.het&&"N"===le.name&&void 0!==g&&void 0!==C){let e=a.atoms[g].coord.distanceTo(a.atoms[C].coord),t=le.coord.x+(a.atoms[g].coord.x-a.atoms[C].coord.x)/e,i=le.coord.y+(a.atoms[g].coord.y-a.atoms[C].coord.y)/e,s=le.coord.z+(a.atoms[g].coord.z-a.atoms[C].coord.z)/e;le.hcoord=new mt(t,i,s)}a.atoms[n]=le,a.dAtoms[n]=1,a.hAtoms[n]=1,l[n]=1,a.loadPDBCls.isSecondary(u,v,d,!D)?(a.atoms[n].ss="sheet",a.loadPDBCls.isSecondary(u,_,d,!D)&&(a.atoms[n].ssbegin=!0),a.loadPDBCls.isSecondary(u,y,d,!D)&&(a.atoms[n].ssend=!0)):a.loadPDBCls.isSecondary(u,S,d,!D)&&(a.atoms[n].ss="helix",a.loadPDBCls.isSecondary(u,w,d,!D)&&(a.atoms[n].ssbegin=!0),a.loadPDBCls.isSecondary(u,x,d,!D)&&(a.atoms[n].ssend=!0));let de="-";if(de="helix"===a.atoms[n].ss?"H":"sheet"===a.atoms[n].ss?"E":!a.atoms[n].het&&o.parasCls.residueColors.hasOwnProperty(a.atoms[n].resn.toUpperCase())?"c":"o",a.secondaries[u]=de,m!==T||P+"_"+k!=L||Z!=ne){let e=o.utilsCls.residueName2Abbr(k);if(a.residueId2Name[u]=e,1!==n&&""!==M&&(a.residues[M]=h),u!==M&&(h={}),p!==A){g=void 0,C=void 0,1!==n&&""!==A&&(void 0===a.chains[A]&&(a.chains[A]={}),a.chains[A]=o.hashUtilsCls.unionHash(a.chains[A],c)),c={},void 0===a.structures[R.toString()]&&(a.structures[R.toString()]=[]),a.structures[R.toString()].includes(p)||a.structures[R.toString()].push(p),void 0===a.chainsSeq[p]&&(a.chainsSeq[p]=[]);let t={};t.resi=ee,t.name=e,a.chainsSeq[p].push(t)}else{g=f,C=b;let t={};t.resi=ee,t.name=e,a.chainsSeq[p].push(t)}}c[n]=1,h[n]=1,A=p,M=u,T=m,L=P+"_"+k,Z=ne}a.residues[u]=h,void 0===a.chains[p]&&(a.chains[p]={}),a.chains[p]=o.hashUtilsCls.unionHash2Atoms(a.chains[p],c,a.atoms),F=N=U=H=B=z=q=j=G=$=V=W=X=[];let ee={};if(O.getCategory("_pdbx_poly_seq_scheme")){let e=O.getCategory("_pdbx_poly_seq_scheme"),t=e.getColumn("seq_id"),i=e.getColumn("pdb_seq_num"),s=e.getColumn("mon_id"),n=e.getColumn("pdb_strand_id"),r=e.rowCount,a="",l=[];for(let e=0;e<r;++e){t.getString(e);let r=i.getString(e),d=s.getString(e),c=n.getString(e);c!=a&&e>0&&(ee[a]=l,l=[]),l.push({resi:r,name:o.utilsCls.residueName2Abbr(d)}),a=c}ee[a]=l,t=i=s=n=[]}this.setSeq(R,J,ee,K)}let O=Object.keys(a.structures);for(let e=0,t=O.length;e<t;++e){let t=O[e];if(t!=E&&(void 0===a.ssbondpnts[t]&&(a.ssbondpnts[t]=[]),void 0!==a.ssbondpnts[E]))for(let e=0,i=a.ssbondpnts[E].length;e<i;++e){let i=a.ssbondpnts[E][e],s=i.indexOf("_"),n=t+i.substr(s);a.ssbondpnts[t].push(n)}}a.bSsbondProvided||a.loadPDBCls.setSsbond();let I,P,D=[],L=new mt(9999,9999,9999),F=new mt(-9999,-9999,-9999),N=new mt,U=0,H={},B=[];for(let e in a.hAtoms){let t=a.atoms[e],i=t.coord;N.add(i),L.min(i),F.max(i),++U,1==U&&(I=t.chain,P=t.resi,B.push(t)),t.het?t.het&&("HOH"===t.resn||"WAT"===t.resn||"SOL"===t.resn?a.water[t.serial]=1:-1!==$.inArray(t.resn,o.parasCls.ionsArray)||t.elem.trim()===t.resn.trim()?a.ions[t.serial]=1:a.chemicals[t.serial]=1,t.color=o.parasCls.atomColors[t.elem]):-1!==$.inArray(t.resn,o.parasCls.nucleotidesArray)?(a.nucleotides[t.serial]=1,"O3'"!==t.name&&"O3*"!==t.name||(a.nucleotidesO3[t.serial]=1,a.secondaries[t.structure+"_"+t.chain+"_"+t.resi]="o"),-1===o.parasCls.nuclMainArray.indexOf(t.name)&&(a.ntbase[t.serial]=1)):("P"===t.elem&&(H[t.structure+"_"+t.chain+"_"+t.resi]=1),a.proteins[t.serial]=1,"CA"===t.name&&(a.calphas[t.serial]=1),"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&(a.sidec[t.serial]=1)),I===t.chain&&P===t.resi||(a.loadPDBCls.refreshBonds(D,B[0]),B.splice(0,1),I=t.chain,P=t.resi,D.length=0),D.push(t),"C"!==t.name&&"O3'"!==t.name||B.push(t)}a.loadPDBCls.refreshBonds(D,B[0]);for(let e in H){let t=a.residues[e];for(n in t){let t=a.atoms[n];t.het=!0,a.chemicals[t.serial]=1,a.secondaries[e]="o",delete a.proteins[t.serial],"CA"===t.name&&delete a.calphas[t.serial],"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&delete a.sidec[t.serial]}}return a.pmin=L,a.pmax=F,a.cnt=U,a.center=a.ParserUtilsCls.getGeoCenter(a.pmin,a.pmax),a.maxD=a.ParserUtilsCls.getStructureSize(a.atoms,a.pmin,a.pmax,a.center),a.maxD<5&&(a.maxD=5),a.oriMaxD=a.maxD,a.oriCenter=a.center.clone(),l}setSeq(e,t,i,s){let n=this.icn3d;n.icn3dui;for(let r in t){let t=e+"_"+r;s.hasOwnProperty(r)?n.chainsSeq[t]=s[r]:n.chainsSeq[t]=i[r]}n.loadPDBCls.setResidMapping()}}class Wh{constructor(e){this.icn3d=e}async vastplusAlign(e,t,i){let s=this.icn3d;s.icn3dui;let n=[],r=[];if(2!=e.length)return void console.log("VAST+ needs two input structures...");let a=e[0],o=e[1],l=[],d=[];for(let e=0,t=s.structures[a].length;e<t;++e){let t=s.structures[a][e];s.proteins.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.chains[t]).serial)&&l.push(t)}for(let e=0,t=s.structures[o].length;e<t;++e){let t=s.structures[o][e];s.proteins.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.chains[t]).serial)&&d.push(t)}let c={},h=0;for(let e=0,t=l.length;e<t;++e){let t=l[e];for(let s=0,l=d.length;s<l;++s){let l=d[s];if(e==s){let d=this.setAlignment(a,o,t,l,i);n.push(d),r.push(t+","+l),c[h]=[e,s],++h}}}for(let e=0,t=l.length;e<t;++e){let t=l[e];for(let s=0,l=d.length;s<l;++s){let l=d[s];if(e!=s){let d=this.setAlignment(a,o,t,l,i);n.push(d),r.push(t+","+l),c[h]=[e,s],++h}}}let p=Promise.allSettled(n),u=await p;this.clusterAlignment(u,r,c,t),s.ParserUtilsCls.hideLoading(),await s.pdbParserCls.loadPdbDataRender(!0)}setAlignment(e,t,i,s,n){let r=this.icn3d,a=r.icn3dui,o=a.htmlCls.baseUrl+"tmalign/tmalign.cgi",l=n?a.hashUtilsCls.intHash(r.hAtoms,r.chains[i]):r.chains[i],d=n?a.hashUtilsCls.intHash(r.hAtoms,r.chains[s]):r.chains[s],c=r.saveFileCls.getAtomPDB(l,void 0,void 0,void 0,void 0,e),h={pdb_query:r.saveFileCls.getAtomPDB(d,void 0,void 0,void 0,void 0,t),pdb_target:c};return a.getAjaxPostPromise(o,h)}async realignOnVastplus(){let e=this.icn3d,t=e.icn3dui,i=[];for(let s in e.structures){let n=e.structures[s];for(let s=0,r=n.length;s<r;++s){let r=n[s],a=t.hashUtilsCls.intHash(e.hAtoms,e.chains[r]),o=e.firstAtomObjCls.getFirstAtomObj(a);o&&(i[o.structure]=1)}}t.cfg.aligntool="tmalign",await e.vastplusCls.vastplusAlign(Object.keys(i),2,!0)}getResisFromSegs(e){this.icn3d.icn3dui;let t=[],i=[];for(let s=0,n=e.length;s<n;++s){let n=e[s];t.push(n.t_start+"-"+n.t_end),i.push(n.q_start+"-"+n.q_end)}return{resiArray_t:t,resiArray_q:i}}clusterAlignment(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=[];for(let i=0,s=t.length;i<s;++i){let t=e[i].value;a.push(t)}let o=[],l=0,d=!1;for(let e=0,i=t.length;e<i;++e){let i=[];a[e].length>0&&(d=!0);for(let n=0,r=t.length;n<r;++n){let t=this.RotMatrixTransDist(a[e][0],a[n][0],1,s),r=e==n?0:0==a[e].length||0==a[n].length?1:t;r>l&&(l=r),i.push(r)}o.push(i)}if(!d)return void(n.bRender&&alert("These structures can not be aligned..."));l<1e-6&&(l=1);for(let e=0,i=t.length;e<i;++e)for(let i=0,s=t.length;i<s;++i)o[e][i]=o[e][i]/l;let c=this.clusterLinkage(1,o,!1),h=this.GetChainMappings(c,t),p={};for(let e=0,t=h.length;e<t;++e){let t=h[e].nodeArray,s=t.join(","),n=i[parseInt(t[0])],r=o[n[0]][n[1]];p[s]?r<p[s]&&(p[s]=r):p[s]=r}let u=Object.keys(p).sort(((e,t)=>p[e]<p[t]||parseInt(1e4*p[e])==parseInt(1e4*p[t])&&e<t?-1:1)),m=parseInt($("#"+r.pre+"maxrmsd").val());m||(m=30),d=!1;for(let e=0,i=u.length;e<i;++e){let i=u[e].split(",");n.opts.color="grey",n.setColorCls.setColorByOptions(n.opts,n.atoms);let s,o,l=[],c=[],h={};$("#"+n.pre+"dl_sequence2").html("");for(let e=0,d=i.length;e<d;++e){let d=parseInt(i[e]),p=a[d][0].segs,u=t[d].split(",");s=u[0],o=u[1];let m=this.getResisFromSegs(p),f=m.resiArray_t,g=m.resiArray_q,b=n.realignParserCls.getSeqCoorResid(f,s);l=l.concat(b.coor);let C=n.realignParserCls.getSeqCoorResid(g,o);c=c.concat(C.coor),n.qt_start_end=[],n.qt_start_end.push(p);let v=!0,_=!0,y=n.chainalignParserCls.setMsa(u,v,_);h=r.hashUtilsCls.unionHash(h,y)}n.hAtoms=r.hashUtilsCls.cloneHash(h);let p=c.length<l.length?c.length:l.length;if(!(p<4)&&(p>=4&&(n.rmsd_suprTmp=r.rmsdSuprCls.getRmsdSuprCls(c,l,p),void 0!==n.rmsd_suprTmp.rot))){let e=n.rmsd_suprTmp.rot;if(null===e[0])continue;let s=n.rmsd_suprTmp.trans1,a=n.rmsd_suprTmp.trans2,l=n.rmsd_suprTmp.rmsd;if(l<m){d=!0,r.htmlCls.clickMenuCls.setLogCmd("realignment RMSD: "+l.toPrecision(4),!1),$("#"+n.pre+"dl_rmsd_html").html("<br><b>Realignment RMSD</b>: "+l.toPrecision(4)+" Å<br><br>"),r.cfg.bSidebyside||r.htmlCls.dialogCls.openDlg("dl_rmsd","Realignment RMSD"),n.q_rotation=[],n.q_trans_sub=[],n.t_trans_add=[],n.q_rotation.push({x1:e[0],y1:e[1],z1:e[2],x2:e[3],y2:e[4],z2:e[5],x3:e[6],y3:e[7],z3:e[8]}),n.q_trans_sub.push(s),n.t_trans_add.push({x:-a.x,y:-a.y,z:-a.z}),r.cfg.aligntool="vast";//!= 'tmalign';
|
|
18
|
-
let c=0,h="query",p=o.substr(0,o.indexOf("_")),u=!0;n.chainalignParserCls.transformStructure(p,c,h,u);let m="";for(let e=0,s=i.length;e<s;++e)m+=t[parseInt(i[e])]+"; ";r.bNode||console.log("Selected the alignment: "+m);break}{let e="";for(let s=0,n=i.length;s<n;++s)e+=t[parseInt(i[s])]+"; ";r.bNode||console.log("skipped the alignment: "+e)}}}d||n.bRender&&alert("These structures can not be aligned...")}RotMatrixTransDist(e,t,i,s){this.icn3d.icn3dui;if(!e||!t)return i;let n=this.GetRotMatrix(e,1,s),r=this.GetRotMatrix(t,1,s),a=[],o=[],l=[],d=[];a[0]=n[9],a[1]=n[10],a[2]=n[11],o[0]=n[12],o[1]=n[13],o[2]=n[14],l[0]=r[9],l[1]=r[10],l[2]=r[11],d[0]=r[12],d[1]=r[13],d[2]=r[14];let c=[],h=[];c[0]=o[0]-d[0],c[1]=o[1]-d[1],c[2]=o[2]-d[2],h[0]=a[0]-l[0],h[1]=a[1]-l[1],h[2]=a[2]-l[2];let p,u,m=0;if(m+=Math.pow(c[0],2),m+=Math.pow(c[1],2),m+=Math.pow(c[2],2),p=Math.sqrt(m),m=0,m+=Math.pow(h[0],2),m+=Math.pow(h[1],2),m+=Math.pow(h[2],2),u=Math.sqrt(m),2!=s){if(p<1e-10||u<1e-10)return i}else if(u<1e-10)return i;if(Math.abs(p-u)>8)return i;let f=[];f[0]=n[0]*a[0]+n[1]*a[1]+n[2]*a[2],f[1]=n[3]*a[0]+n[4]*a[1]+n[5]*a[2],f[2]=n[6]*a[0]+n[7]*a[1]+n[8]*a[2],f[0]-=n[0]*l[0]+n[1]*l[1]+n[2]*l[2],f[1]-=n[3]*l[0]+n[4]*l[1]+n[5]*l[2],f[2]-=n[6]*l[0]+n[7]*l[1]+n[8]*l[2];let g=0;return g=c[0]*f[0],g+=c[1]*f[1],g+=c[2]*f[2],g/=p*u,g<.866?i:(f[0]=r[0]*a[0]+r[1]*a[1]+r[2]*a[2],f[1]=r[3]*a[0]+r[4]*a[1]+r[5]*a[2],f[2]=r[6]*a[0]+r[7]*a[1]+r[8]*a[2],f[0]-=r[0]*l[0]+r[1]*l[1]+r[2]*l[2],f[1]-=r[3]*l[0]+r[4]*l[1]+r[5]*l[2],f[2]-=r[6]*l[0]+r[7]*l[1]+r[8]*l[2],g=c[0]*f[0],g+=c[1]*f[1],g+=c[2]*f[2],g/=p*u,g<.866?i:(m=0,m+=Math.pow(e.q_rotation.x1-t.q_rotation.x1,2),m+=Math.pow(e.q_rotation.y1-t.q_rotation.y1,2),m+=Math.pow(e.q_rotation.z1-t.q_rotation.z1,2),m+=Math.pow(e.q_rotation.x2-t.q_rotation.x2,2),m+=Math.pow(e.q_rotation.y2-t.q_rotation.y2,2),m+=Math.pow(e.q_rotation.z2-t.q_rotation.z2,2),m+=Math.pow(e.q_rotation.x3-t.q_rotation.x3,2),m+=Math.pow(e.q_rotation.y3-t.q_rotation.y3,2),m+=Math.pow(e.q_rotation.z3-t.q_rotation.z3,2),Math.sqrt(m)))}GetRotMatrix(e,t,i){this.icn3d.icn3dui;let s=[];return s&&(s[0]=e.q_rotation.x1/t,s[1]=e.q_rotation.y1/t,s[2]=e.q_rotation.z1/t,s[3]=e.q_rotation.x2/t,s[4]=e.q_rotation.y2/t,s[5]=e.q_rotation.z2/t,s[6]=e.q_rotation.x3/t,s[7]=e.q_rotation.y3/t,s[8]=e.q_rotation.z3/t,2!=i?(s[9]=e.t_trans_add.x/t,s[10]=e.t_trans_add.y/t,s[11]=e.t_trans_add.z/t,s[12]=-e.q_trans_sub.x/t,s[13]=-e.q_trans_sub.y/t,s[14]=-e.q_trans_sub.z/t):(s[9]=-e.q_trans_add.x/t,s[10]=-e.q_trans_add.y/t,s[11]=-e.q_trans_add.z/t,s[12]=0,s[13]=0,s[14]=0)),s}cbu_dist(e,t,i){return e<t?i[e][t]:i[t][e]}compareFloat(e,t,i){let s=e[t].dist,n=e[i].dist;return parseInt(1e4*s)==parseInt(1e4*n)?0:parseInt(1e4*s)<parseInt(1e4*n)?-1:1}clusterLinkage(e,t,i){let s,n,r,a,o,l,d,c,h=this.icn3d,p=h.icn3dui,u=[],m=t.length;for(s=0;s<2*m-1;++s)u[s]={},u[s].leaves=[];let f=[];for(s=0;s<2*m-1;++s)for(f[s]=[],n=0;n<2*m-1;++n)f[s][n]=2;for(s=0;s<m;++s)for(n=s;n<m;++n)f[s][n]=t[s][n];let g={},b={},C={};for(a=m,o=m,s=0;s<m;++s){for(d=2,n=0;n<m;++n){let e=i?parseInt(1e4*this.cbu_dist(s,n,f))<=parseInt(1e4*d):parseInt(1e4*this.cbu_dist(s,n,f))<parseInt(1e4*d);n!=s&&e&&(d=this.cbu_dist(s,n,f),a=s,o=n)}g[a]=o,C[a]=d}let v=[];for(l=0;l<m;++l)u[l].child1=-2,u[l].child2=-2,u[l].parent=l,u[l].dist=0,u[l].leaves.push([l]),v[l]=0;let _=Object.keys(h.structures),y=h.structures[_[0]].length,S=h.structures[_[1]].length,w=y<S?y:S;for(l=m;l<2*m-1;++l){for(r in d=2,g)c=C[r],c<d&&(d=c,a=r,o=g[r]);let e=d;for(u[l].child1=a<m?a:-a,u[l].child2=o<m?o:-o,u[l].parent=-1*l,u[a].dist=e-v[a],u[o].dist=e-v[o],v[l]=e,n=0;n<2*m-1;++n){let e=this.cbu_dist(a,n,f),t=this.cbu_dist(o,n,f);l<n?f[l][n]=e<t?e:t:f[n][l]=e<t?e:t}for(n=0;n<2*m-1;++n)a<n?f[a][n]=2:f[n][a]=2,o<n?f[o][n]=2:f[n][o]=2;let t=4;if(u[a].leaves.length<t*w&&u[o].leaves.length<t*w){u[l].leaves=[];for(let e=0,t=u[a].leaves.length;e<t;++e)for(let t=0,i=u[o].leaves.length;t<i;++t)u[l].leaves.push(u[a].leaves[e].concat(u[o].leaves[t])),u[l].leaves.push(u[o].leaves[t].concat(u[a].leaves[e]));u[a].leaves=[],u[o].leaves=[]}for(r in delete g[a],delete g[o],delete C[a],delete C[o],b=p.hashUtilsCls.cloneHash(g),b)b[r]!=a&&b[r]!=o||(delete g[r],g[r]=l);let i=2*m;for(d=2,n=0;n<2*m-1;++n)n!=l&&this.cbu_dist(l,n,f)<d&&(d=this.cbu_dist(l,n,f),i=n);g[l]=i,C[l]=d}return l==2*m-1&&(u[l-1].parent=-1,u[l-1].dist=0),u}GetChainMappings(e,t){this.icn3d.icn3dui;let i,s,n=[];t.length;let r=this.getClusters(e,!0).clusters,a=r.length;for(let e=0;e<a;++e){let a=r[e];for(let e=0,r=a.length;e<r;++e){let r={nodeArray:[]},o={},l={};for(let n=0,d=a[e].length;n<d;++n){let d=a[e][n],c=t[d].split(",");i=c[0],s=c[1],o.hasOwnProperty(i)||l.hasOwnProperty(s)||(r.nodeArray.push(d.toString().padStart(5,"0")),o[i]=1,l[s]=1)}n.push(r)}}return n}getClusters(e,t){this.icn3d.icn3dui;let i=[],s=[],n=0,r=e.length,a=t?0:1;for(;n<r;++n)e[n].leaves.length>a&&(i.push(e[n].leaves),s.push(e[n].dist));return{clusters:i,scores:s}}}class Xh{constructor(e){this.icn3d=e}async applyCommand(e){let t=this.icn3d,i=t.icn3dui;t.bAddCommands=!1;let s=e.split("|||")[0].split("%7C%7C%7C")[0].replace(/\s+/g," ").trim(),n=s.toLowerCase();if("share link"==n)await t.shareLinkCls.shareLink();else if("export state file"==n);else if(0==n.indexOf("export canvas"))setTimeout((async function(){let e=n.substr(13).trim();t.scaleFactor=""===e?1:parseInt(e);let i=""!==e;await t.shareLinkCls.shareLink(!0,i)}),500);else if("export interactions"==n)t.viewInterPairsCls.exportInteractions();else if("export stl file"==n)setTimeout((function(){t.export3DCls.exportStlFile("")}),500);else if("export vrml file"==n)setTimeout((function(){t.export3DCls.exportVrmlFile("")}),500);else if("export stl stabilizer file"==n)setTimeout((function(){t.threeDPrintCls.hideStabilizer(),t.threeDPrintCls.resetAfter3Dprint(),t.threeDPrintCls.addStabilizer(),t.export3DCls.exportStlFile("_stab")}),500);else if("export vrml stabilizer file"==n)setTimeout((function(){t.threeDPrintCls.hideStabilizer(),t.threeDPrintCls.resetAfter3Dprint(),t.threeDPrintCls.addStabilizer(),t.export3DCls.exportVrmlFile("_stab")}),500);else if("export pdb"==n)i.htmlCls.setHtmlCls.exportPdb();else if("export pdb missing atoms"==n)await t.scapCls.exportPdbProfix(!1);else if("export pdb hydrogen"==n)await t.scapCls.exportPdbProfix(!0);else if(-1!=n.indexOf("export refnum ")){let e=n.substr(14);t.refnumCls.exportRefnum(e)}else if("export secondary structure"==n)i.htmlCls.setHtmlCls.exportSecondary();else if("select all"==n)t.selectionCls.selectAll();else if("show all"==n)t.selectionCls.showAll();else if("select complement"==n)t.resid2specCls.selectComplement();else if("set pk atom"==n)t.pk=1,t.opts.pk="atom";else if("set pk off"==n)t.pk=0,t.opts.pk="no",t.drawCls.draw(),t.hlObjectsCls.removeHlObjects();else if("set pk residue"==n)t.pk=2,t.opts.pk="residue";else if("set pk strand"==n)t.pk=3,t.opts.pk="strand";else if("set pk domain"==n)t.pk=4,t.opts.pk="domain";else if("set pk chain"==n)t.pk=5,t.opts.pk="chain";else if("set surface wireframe on"==n)t.opts.wireframe="yes",t.applyMapCls.applySurfaceOptions();else if("set surface wireframe off"==n)t.opts.wireframe="no",t.applyMapCls.applySurfaceOptions();else if("set map wireframe on"==n)t.opts.mapwireframe="yes",t.applyMapCls.applyMapOptions();else if("set map wireframe off"==n)t.opts.mapwireframe="no",t.applyMapCls.applyMapOptions();else if("set emmap wireframe on"==n)t.opts.emmapwireframe="yes",t.applyMapCls.applyEmmapOptions();else if("set emmap wireframe off"==n)t.opts.emmapwireframe="no",t.applyMapCls.applyEmmapOptions();else if("set surface neighbors on"==n)t.bConsiderNeighbors=!0,t.applyMapCls.applySurfaceOptions();else if("set surface neighbors off"==n)t.bConsiderNeighbors=!1,t.applyMapCls.applySurfaceOptions();else if("set axis on"==n)t.opts.axis="yes";else if("set pc1 axis"==n)t.pc1=!0,t.axesCls.setPc1Axes();else if("set axis off"==n)t.opts.axis="no",t.pc1=!1;else if("set fog on"==n)t.opts.fog="yes",t.fogCls.setFog(!0);else if("set fog off"==n)t.opts.fog="no",t.fogCls.setFog(!0);else if("set slab on"==n)t.opts.slab="yes";else if("set slab off"==n)t.opts.slab="no";else if("stereo on"==n)t.opts.effect="stereo";else if("stereo off"==n)t.opts.effect="none";else if("set assembly on"==n)t.bAssembly=!0;else if("set assembly off"==n)t.bAssembly=!1;else if("set chemicalbinding show"==n)t.setOptionCls.setOption("chemicalbinding","show");else if("set chemicalbinding hide"==n)t.setOptionCls.setOption("chemicalbinding","hide");else if("set hbonds off"==n)t.hBondCls.hideHbonds(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("set salt bridge off"==n)t.saltbridgeCls.hideSaltbridge(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("set contact off"==n)t.contactCls.hideContact(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("set halogen pi off"==n)t.piHalogenCls.hideHalogenPi(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("hydrogens"==n)t.showInterCls.showHydrogens(),t.drawCls.draw();else if("set hydrogens off"==n)t.showInterCls.hideHydrogens(),t.drawCls.draw();else if("close popup"==n)t.resizeCanvasCls.closeDialogs();else if("set stabilizer off"==n)t.threeDPrintCls.hideStabilizer(),t.drawCls.draw();else if("set disulfide bonds off"==n)t.opts.ssbonds="no",t.drawCls.draw();else if("set cross linkage off"==n)t.opts.clbonds="no",t.drawCls.draw();else if("set lines off"==n)t.labels.distance=[],t.lines.distance=[],t.drawCls.draw();else if("set labels off"==n){for(let e in t.labels)t.labels[e]=[];t.drawCls.draw()}else if("set mode all"==n)t.definedSetsCls.setModeAndDisplay("all");else if("set mode selection"==n)t.definedSetsCls.setModeAndDisplay("selection");else if("set view detailed view"==n)t.annotationCls.setAnnoViewAndDisplay("detailed view");else if("set view overview"==n)t.annotationCls.setAnnoViewAndDisplay("overview");else if("set annotation custom"==n)t.annotationCls.setAnnoTabCustom();else if("set annotation interaction"==n)t.annotationCls.setAnnoTabInteraction();else if("set annotation ptm"==n)await t.annotationCls.setAnnoTabPTM();else if("set annotation cdd"==n)t.annotationCls.setAnnoTabCdd();else if("set annotation site"==n)t.annotationCls.setAnnoTabSite();else if("set annotation ssbond"==n)t.annotationCls.setAnnoTabSsbond();else if("set annotation crosslink"==n)t.annotationCls.setAnnoTabCrosslink();else if("set annotation transmembrane"==n)await t.annotationCls.setAnnoTabTransmem();else if("set annotation ig"==n)t.bRunRefnumAgain=!0,await t.annotationCls.setAnnoTabIg(),t.bRunRefnumAgain=!1;else if("ig refnum on"==n)t.bRunRefnumAgain=!0,t.bAnnoShown||await t.showAnnoCls.showAnnotations(),await t.annotationCls.setAnnoTabIg(!0),t.bRunRefnumAgain=!1;else if("highlight level up"==n)t.resid2specCls.switchHighlightLevelUp();else if("highlight level down"==n)t.resid2specCls.switchHighlightLevelDown();else if(0==n.indexOf("hide annotation")){let e=n.lastIndexOf(" "),i=n.substr(e+1);"all"==i?t.annotationCls.hideAnnoTabAll():"custom"==i?t.annotationCls.hideAnnoTabCustom():"clinvar"==i?t.annotationCls.hideAnnoTabClinvar():"snp"==i?t.annotationCls.hideAnnoTabSnp():"cdd"==i?t.annotationCls.hideAnnoTabCdd():"3ddomain"==i?t.annotationCls.hideAnnoTab3ddomain():"site"==i?t.annotationCls.hideAnnoTabSite():"ptm"==i?t.annotationCls.hideAnnoTabPTM():"interaction"==i?t.annotationCls.hideAnnoTabInteraction():"ssbond"==i?t.annotationCls.hideAnnoTabSsbond():"crosslink"==i?t.annotationCls.hideAnnoTabCrosslink():"transmembrane"==i&&t.annotationCls.hideAnnoTabTransmem()}else if("add residue labels"==n)t.residueLabelsCls.addResidueLabels(t.hAtoms),t.drawCls.draw();else if("add residue number labels"==n)t.residueLabelsCls.addResidueLabels(t.hAtoms,void 0,void 0,!0),t.drawCls.draw();else if("add reference number labels"==n)t.residueLabelsCls.addResidueLabels(t.hAtoms,void 0,void 0,void 0,!0),t.drawCls.draw();else if("add ig labels"==n)t.residueLabelsCls.addIgLabels(t.hAtoms),t.drawCls.draw();else if("add atom labels"==n)t.residueLabelsCls.addAtomLabels(t.hAtoms),t.drawCls.draw();else if("add element labels"==n)t.residueLabelsCls.addAtomLabels(t.hAtoms,!0),t.drawCls.draw();else if("add chain labels"==n)t.analysisCls.addChainLabels(t.hAtoms),t.drawCls.draw();else if("add terminal labels"==n)t.analysisCls.addTerminiLabels(t.hAtoms),t.drawCls.draw();else if("rotate left"==n)t.bStopRotate=!1,t.ROT_DIR="left",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("left");else if("rotate right"==n)t.bStopRotate=!1,t.ROT_DIR="right",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("right");else if("rotate up"==n)t.bStopRotate=!1,t.ROT_DIR="up",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("up");else if("rotate down"==n)t.bStopRotate=!1,t.ROT_DIR="down",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("down");else if("rotate x"==n){let e=new mt(1,0,0),i=.5*Math.PI;t.transformCls.setRotation(e,i)}else if("rotate y"==n){let e=new mt(0,1,0),i=.5*Math.PI;t.transformCls.setRotation(e,i)}else if("rotate z"==n){let e=new mt(0,0,1),i=.5*Math.PI;t.transformCls.setRotation(e,i)}else if("reset"===n)t.selectionCls.resetAll();else if("reset orientation"===n)t.transformCls.resetOrientation(),t.drawCls.draw();else if("reset thickness"==n)t.threeDPrintCls.resetAfter3Dprint(),t.drawCls.draw();else if("clear selection"==n)t.hlObjectsCls.removeHlObjects(),t.hlUpdateCls.removeHl2D(),t.bSelectResidue=!1;else if("zoom selection"==n)t.transformCls.zoominSelection(),t.drawCls.draw();else if("center selection"==n)t.applyCenterCls.centerSelection(),t.drawCls.draw();else if("show selection"==n)t.selectionCls.showSelection();else if("hide selection"==n)t.selectionCls.hideSelection();else if("output selection"==n)t.threeDPrintCls.outputSelection();else if("toggle selection"==n)t.selectionCls.toggleSelection();else if("toggle highlight"==n)t.hlUpdateCls.toggleHighlight();else if("stabilizer"==n)t.threeDPrintCls.addStabilizer(),t.threeDPrintCls.prepareFor3Dprint();else if("disulfide bonds"==n)t.showInterCls.showSsbonds();else if("cross linkage"==n)t.showInterCls.showClbonds();else if("back"==n)await t.resizeCanvasCls.back();else if("forward"==n)await t.resizeCanvasCls.forward();else if("clear all"==n)t.selectionCls.selectAll();else if("defined sets"==n)t.definedSetsCls.showSets(),t.bDefinedSets=!0;else if("delete selected sets"==n)t.definedSetsCls.deleteSelectedSets();else if("view interactions"==n)void 0===i.cfg.mmdbid&&void 0===i.cfg.gi||t.ParserUtilsCls.set2DDiagrams(t.inputid);else if("show annotations all chains"==n)t.annotationCls.showAnnoAllChains();else if("save color"==n)t.setOptionCls.saveColor();else if("apply saved color"==n)t.setOptionCls.applySavedColor();else if("save style"==n)t.setOptionCls.saveStyle();else if("apply saved style"==n)t.setOptionCls.applySavedStyle();else if("select main chains"==n)t.selectionCls.selectMainChains();else if("select side chains"==n)t.selectionCls.selectSideChains();else if("select main side chains"==n)t.selectionCls.selectMainSideChains();else if("realign"==n)t.realignParserCls.realign();else if(-1!=n.indexOf("realign predefined ")){let e="realign predefined ",n=s.substr(e.length),r=n.indexOf(" "),a=n.substr(0,r).split(",");i.cfg.resdef=n.substr(r+1).replace(/:/gi,";"),await t.realignParserCls.realignChainOnSeqAlign(void 0,a,!0,!0)}else if("area"==n)t.analysisCls.calculateArea();else if("table inter count only"==n)$(".icn3d-border").hide();else if("table inter details"==n)$(".icn3d-border").show();else if("setoption map nothing"==n)t.setOptionCls.setOption("map","nothing");else if("setoption emmap nothing"==n)t.setOptionCls.setOption("emmap","nothing");else if("setoption phimap nothing"==n)t.setOptionCls.setOption("phimap","nothing");else if("setoption phisurface nothing"==n)t.setOptionCls.setOption("phisurface","nothing");else if("clear symd symmetry"==n)t.symdArray=[];else if("show axis"==n)t.bAxisOnly=!0;else if(0==s.indexOf("define helix sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"helix")}else if(0==s.indexOf("define sheet sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"sheet")}else if(0==s.indexOf("define coil sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"coil")}else if(0==s.indexOf("define iganchor sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"iganchor")}else if(0==s.indexOf("define igstrand sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igstrand")}else if(0==s.indexOf("define igloop sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igloop")}else if(0==s.indexOf("select interaction")){let e=s.substr(s.lastIndexOf(" ")+1).split(",");if(null!==e){let i=e[0].split("_")[0];t.b2DShown||t.ParserUtilsCls.download2Ddgm(i.toUpperCase()),t.diagram2dCls.selectInteraction(e[0],e[1])}}else if(0==s.indexOf("select saved atoms")||0==s.indexOf("select sets")){s=s.replace(/aligned_protein/g,"protein_aligned"),t.bDefinedSets||(t.definedSetsCls.setPredefinedInMenu(),t.bDefinedSets=!0);let e=s.split(" | "),i=e[0].replace(/,/g," or "),n=19;0==s.indexOf("select sets")&&(n=12);let r=i.substr(n),a=r;2==e.length&&(a=e[1].substr(5)),t.definedSetsCls.selectCombinedSets(r,a)}else if(-1!==s.indexOf("select chain")){let e=s.substr(s.lastIndexOf(" ")+1).split(",");for(let i=0,s=e.length;i<s;++i)t.selectionCls.selectAChain(e[i],e[i],!1)}else if(-1!==s.indexOf("select alignChain")){let e=s.substr(s.lastIndexOf(" ")+1).split(",");for(let i=0,s=e.length;i<s;++i)t.selectionCls.selectAChain(e[i],"align_"+e[i],!0)}else if(0==s.indexOf("select zone cutoff")){let e=this.getThresholdNameArrays(s);t.showInterCls.pickCustomSphere(e.threshold,e.nameArray2,e.nameArray,e.bHbondCalc),t.bSphereCalc=!0}else if(0==n.indexOf("set surface opacity")){t.transparentRenderOrder=!1;let e=n.substr(n.lastIndexOf(" ")+1);t.opts.opacity=parseFloat(e),t.applyMapCls.applySurfaceOptions(),parseInt(100*e)<100&&(t.bTransparentSurface=!0)}else if(0==n.indexOf("set surface2 opacity")){t.transparentRenderOrder=!0;let e=n.substr(n.lastIndexOf(" ")+1);t.opts.opacity=parseFloat(e),t.applyMapCls.applySurfaceOptions(),parseInt(100*e)<100&&(t.bTransparentSurface=!0)}else if(0==n.indexOf("set label scale")){let e=n.substr(n.lastIndexOf(" ")+1);t.labelScale=parseFloat(e)}else if(0==n.indexOf("set surface")){let e=n.substr(12);t.opts.surface=e,t.applyMapCls.applySurfaceOptions()}else if(0==n.indexOf("set camera")){let e=n.substr(n.lastIndexOf(" ")+1);t.opts.camera=e}else if(0==n.indexOf("set background")){let e=n.substr(n.lastIndexOf(" ")+1);t.opts.background=e,"black"==e?($("#"+t.pre+"title").css("color",i.htmlCls.GREYD),$("#"+t.pre+"titlelink").css("color",i.htmlCls.GREYD)):($("#"+t.pre+"title").css("color","black"),$("#"+t.pre+"titlelink").css("color","black"))}else if(0==n.indexOf("set label color"))t.labelcolor=n.substr(n.lastIndexOf(" ")+1);else if(0==s.indexOf("set thickness")){let e=n.split(" | ");t.bSetThickness=!0;for(let i=1,s=e.length;i<s;++i){let s=e[i].split(" "),n=s[0],r=parseFloat(s[1]);"linerad"!=n||isNaN(r)||(t.lineRadius=r),"coilrad"!=n||isNaN(r)||(t.coilWidth=r),"stickrad"!=n||isNaN(r)||(t.cylinderRadius=r),"crosslinkrad"!=n||isNaN(r)||(t.crosslinkRadius=r),"tracerad"!=n||isNaN(r)||(t.traceRadius=r),"ballscale"!=n||isNaN(r)||(t.dotSphereScale=r),"ribbonthick"!=n||isNaN(r)||(t.ribbonthickness=r),"proteinwidth"!=n||isNaN(r)||(t.helixSheetWidth=r),"nucleotidewidth"!=n||isNaN(r)||(t.nucleicAcidWidth=r)}t.drawCls.draw()}else if(0==s.indexOf("set light")){let e=n.split(" | ");for(let i=1,s=e.length;i<s;++i){let s=e[i].split(" "),n=s[0],r=parseFloat(s[1]);"light1"==n&&(t.light1=r),"light2"==n&&(t.light2=r),"light3"==n&&(t.light3=r)}t.drawCls.draw()}else if(0==s.indexOf("set shininess")){let e=n.lastIndexOf(" ");t.shininess=parseFloat(n.substr(e+1)),t.drawCls.draw()}else if(0==s.indexOf("set glycan")){let e=n.lastIndexOf(" ");t.bGlycansCartoon=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==s.indexOf("set membrane")){let e=n.lastIndexOf(" ");t.bMembrane=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==s.indexOf("set cmdwindow")){let e=n.lastIndexOf(" "),t=parseInt(n.substr(e+1));i.htmlCls.setMenuCls.setLogWindow(!0,t)}else if(0==n.indexOf("set highlight color")){let e=n.substr(20);"yellow"===e?(t.hColor=i.parasCls.thr(16776960),t.matShader=t.setColorCls.setOutlineColor("yellow")):"green"===e?(t.hColor=i.parasCls.thr(65280),t.matShader=t.setColorCls.setOutlineColor("green")):"red"===e&&(t.hColor=i.parasCls.thr(16711680),t.matShader=t.setColorCls.setOutlineColor("red")),t.drawCls.draw()}else if(0==n.indexOf("set highlight style")){let e=n.substr(20);"outline"===e?t.bHighlight=1:"3d"===e&&(t.bHighlight=2),t.drawCls.draw()}else if(0==n.indexOf("add line")){let e=n.split(" | "),i=e[1].split(" "),s=e[2].split(" "),r=e[3].substr(e[3].lastIndexOf(" ")+1),a="true"===e[4].substr(e[4].lastIndexOf(" ")+1),o=e[5].substr(e[5].lastIndexOf(" ")+1),l=e.length>6?e[6].substr(e[6].lastIndexOf(" ")+1):0,d=e.length>7?e[7].substr(e[7].lastIndexOf(" ")+1):1;t.analysisCls.addLine(parseFloat(i[1]),parseFloat(i[3]),parseFloat(i[5]),parseFloat(s[1]),parseFloat(s[3]),parseFloat(s[5]),r,a,o,parseFloat(l),parseFloat(d)),t.drawCls.draw()}else if(0==n.indexOf("add sphere"))this.addShape(s,"sphere"),t.shapeCmdHash[s]=1;else if(0==n.indexOf("add cube"))this.addShape(s,"cube"),t.shapeCmdHash[s]=1;else if(0==n.indexOf("clear shape"))t.shapeCmdHash={};else if(0==n.indexOf("clear line between sets"))t.lines.cylinder=[];else if(0==s.indexOf("add label")){let e,n,r,a,o,l,d,c=s.split(" | "),h=c[0].substr(10),p=!1;for(let t=1,i=c.length;t<i;++t){let i=c[t].split(" ");"x"==i[0]?(p=!0,e=parseFloat(i[1]),n=parseFloat(i[3]),r=parseFloat(i[5])):"size"==i[0]?a=c[t].substr(c[t].lastIndexOf(" ")+1):"color"==i[0]?o=c[t].substr(c[t].lastIndexOf(" ")+1):"background"==i[0]?l=c[t].substr(c[t].lastIndexOf(" ")+1):"type"==i[0]&&(d=c[t].substr(c[t].lastIndexOf(" ")+1))}if(!p){let s=t.applyCenterCls.centerAtoms(i.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms));e=parseFloat(s.center.x),n=parseFloat(s.center.y),r=parseFloat(s.center.z)}t.analysisCls.addLabel(h,e,n,r,a,o,l,d),t.drawCls.draw()}else if(0==s.indexOf("msa")){let e=s.split(" | ")[1].split(" ");t.targetGapHash={};for(let i=0,s=e.length;i<s;++i){let s=e[i].split("_");t.targetGapHash[parseInt(s[0])]={from:parseInt(s[1]),to:parseInt(s[2])}}await t.annotationCls.resetAnnoAll()}else if(0==s.indexOf("add track")){let e,i,n,r=s.split(" | "),a=r[1].substr(8),o=r[2].substr(6),l=r[3].substr(5);r.length>=5&&(e=r[4].substr(5)),r.length>=6&&(i=r[5].substr(6)),r.length>=7&&(n=r[6].substr(4)),$("#"+t.pre+"anno_custom")[0]&&($("#"+t.pre+"anno_custom")[0].checked=!0),$("[id^="+t.pre+"custom]").show(),"0"==i&&(i=void 0),t.addTrackCls.checkGiSeq(a,o,l,e,i,n,0)}else if(0==n.indexOf("remove one stabilizer")){let e=n.split(" | ")[1].split(" "),i=[];i.push(parseInt(e[0])),i.push(parseInt(e[1])),t.threeDPrintCls.removeOneStabilizer(i),t.drawCls.draw()}else if(0==n.indexOf("add one stabilizer")){let e=n.split(" | ")[1].split(" ");void 0===t.pairArray&&(t.pairArray=[]),t.pairArray.push(parseInt(e[0])),t.pairArray.push(parseInt(e[1])),t.drawCls.draw()}else if(0==n.indexOf("select planes z-axis")){let e=n.split(" ");if(5==e.length){let i=parseFloat(e[3]),s=parseFloat(e[4]);t.selectionCls.selectBtwPlanes(i,s)}}else if(0==n.indexOf("adjust membrane z-axis")){let e=n.split(" ");if(5==e.length){let i=parseFloat(e[3]),s=parseFloat(e[4]);t.selectionCls.adjustMembrane(i,s)}}else if(0==n.indexOf("toggle membrane"))t.selectionCls.toggleMembrane();else if(0==s.indexOf("calc buried surface")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),s=i[1].split(",");t.analysisCls.calcBuriedSurface(e,s)}}}else if(0==s.indexOf("dist ")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),s=i[1].split(",");t.analysisCls.measureDistTwoSets(e,s)}}}else if(0==s.indexOf("disttable")){let e=s.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),n=s[1].split(",");t.analysisCls.measureDistManySets(e,n),i.htmlCls.dialogCls.openDlg("dl_disttable","Distances among the sets")}}}else if(0==s.indexOf("angletable")){let e=s.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),n=s[1].split(",");t.analysisCls.measureAngleManySets(e,n),i.htmlCls.dialogCls.openDlg("dl_angletable","Angles among the sets")}}}else if(0==s.indexOf("display interaction 3d")||0==s.indexOf("view interaction pairs")||0==s.indexOf("save1 interaction pairs")||0==s.indexOf("save2 interaction pairs")||0==s.indexOf("line graph interaction pairs")||0==s.indexOf("scatterplot interaction pairs")||0==s.indexOf("ligplot interaction pairs")){let e=s.split(" | ");if(e.length>=3){let i=e[1].split(" ");if(2==i.length){let n,r,a=i[0].split(","),o=i[1].split(","),l=-1!==e[2].indexOf("hbonds"),d=-1!==e[2].indexOf("salt bridge"),c=-1!==e[2].indexOf("interactions"),h=-1!==e[2].indexOf("halogen"),p=-1!==e[2].indexOf("pi-cation"),u=-1!==e[2].indexOf("pi-stacking");if(e.length>=4&&(n="true"==e[3]),e.length>=5){let i=e[4].split(" ");i.length>=4&&($("#"+t.pre+"hbondthreshold").val(i[1]),$("#"+t.pre+"saltbridgethreshold").val(i[2]),$("#"+t.pre+"contactthreshold").val(i[3]),7==i.length&&($("#"+t.pre+"halogenthreshold").val(i[4]),$("#"+t.pre+"picationthreshold").val(i[5]),$("#"+t.pre+"pistackingthreshold").val(i[6])))}0==s.indexOf("display interaction 3d")?r="3d":0==s.indexOf("view interaction pairs")?r="view":0==s.indexOf("save1 interaction pairs")?r="save1":0==s.indexOf("save2 interaction pairs")?r="save2":0==s.indexOf("line graph interaction pairs")?r="linegraph":0==s.indexOf("scatterplot interaction pairs")?r="scatterplot":0==s.indexOf("ligplot interaction pairs")&&(r="ligplot"),await t.viewInterPairsCls.viewInteractionPairs(a,o,n,r,l,d,c,h,p,u)}}}else if(0==s.indexOf("export pairs")){let e=s.split(" | ");if(3==e.length){let s=e[1].split(" ");if(2==s.length){let n=s[0].split(","),r=s[1].split(","),a=e[2].split(" ")[1];t.showInterCls.pickCustomSphere(a,n,r,t.bSphereCalc),t.bSphereCalc=!0;let o=t.viewInterPairsCls.exportSpherePairs(),l=Object.keys(i.utilsCls.getHlStructures()).join(",");t.saveFileCls.saveFile(l+"_sphere_pairs.html","html",o)}}}else if(0==n.indexOf("graph label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+i.svgid+"_label").val(t),$("#"+i.svgid+" text").removeClass(),$("#"+i.svgid+" text").addClass(t)}else if(0==n.indexOf("cartoon label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+i.svgid_ct+"_label").val(t),$("#"+i.svgid_ct+" text").removeClass(),$("#"+i.svgid_ct+" text").addClass(t)}else if(0==n.indexOf("line graph scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.linegraphid+"_scale").val(s),$("#"+i.linegraphid).attr("width",(t.linegraphWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("scatterplot scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.scatterplotid+"_scale").val(s),$("#"+i.scatterplotid).attr("width",(t.scatterplotWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("ligplot scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.ligplotid+"_scale").val(s),t.ligplotScale=parseFloat(s),$("#"+i.ligplotid).attr("width",(t.ligplotWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("contactmap scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.contactmapid+"_scale").val(s),$("#"+i.contactmapid).attr("width",(t.contactmapWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("alignerrormap scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.alignerrormapid+"_scale").val(s),$("#"+i.alignerrormapid).attr("width",(t.alignerrormapWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("graph force")){let e=n.lastIndexOf(" ");i.htmlCls.force=parseInt(n.substr(e+1)),$("#"+i.svgid+"_force").val(i.htmlCls.force),t.getGraphCls.handleForce()}else if(0==n.indexOf("hide edges")){let e=n.lastIndexOf(" ");i.htmlCls.hideedges=parseInt(n.substr(e+1)),$("#"+i.svgid+"_hideedges").val(i.htmlCls.hideedges),i.htmlCls.hideedges?(i.htmlCls.contactInsideColor="FFF",i.htmlCls.hbondInsideColor="FFF",i.htmlCls.ionicInsideColor="FFF"):(i.htmlCls.contactInsideColor="DDD",i.htmlCls.hbondInsideColor="AFA",i.htmlCls.ionicInsideColor="8FF"),void 0!==t.graphStr&&t.bRender&&i.htmlCls.force&&t.drawGraphCls.drawGraph(t.graphStr,t.pre+"dl_graph")}else if(0==n.indexOf("reset interaction pairs"))t.viewInterPairsCls.resetInteractionPairs();else if(0==n.indexOf("side by side")){let e=n.split(" | ")[1],t="_blank";window.open(e,t)}else if(0==s.indexOf("your note")){let e=s.split(" | ");t.yournote=e[1],$("#"+t.pre+"yournote").val(t.yournote),i.cfg.shownote&&(document.title=t.yournote)}else if(0==n.indexOf("cross structure interaction"))t.crossstrucinter=parseInt(n.substr(n.lastIndexOf(" ")+1)),$("#"+t.pre+"crossstrucinter").val(t.crossstrucinter);else if("replay on"==n)await t.resizeCanvasCls.replayon();else if("replay off"==n)await t.resizeCanvasCls.replayoff();else if(0==n.indexOf("contact map")){let e=n.split(" | ");if(3===e.length){let i=parseFloat(e[1].split(" ")[1]),s=e[2].split(" ")[1];await t.contactMapCls.contactMap(i,s)}}else if(0==n.indexOf("pickatom")){let e=parseInt(n.substr(n.lastIndexOf(" ")+1));t.pAtom=t.atoms[e],t.pickingCls.showPicking(t.pAtom)}else if(0==s.indexOf("set color spectrum")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!0;t.setColorCls.setColorAcrossSets(i,s)}}else if(0==s.indexOf("set residues color spectrum")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!0;t.setColorCls.setColorBySets(i,s)}}else if(0==s.indexOf("set color rainbow")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!1;t.setColorCls.setColorAcrossSets(i,s)}}else if(0==s.indexOf("set residues color rainbow")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!1;t.setColorCls.setColorBySets(i,s)}}else if(0==s.indexOf("color")){let e=s.split(" | "),n=e[0].substr(e[0].indexOf(" ")+1);if(t.opts.color=n,"residue custom"==n&&2==e.length){t.customResidueColors=JSON.parse(e[1]);for(let e in t.customResidueColors)t.customResidueColors[e.toUpperCase()]=i.parasCls.thr("#"+t.customResidueColors[e])}else if("align custom"==n&&3==e.length){let i=e[1],s=e[2].split(", ");t.queryresi2score={},t.queryresi2score[i]={};for(let e=0,n=s.length;e<n;++e){let n=s[e].split(" ");t.queryresi2score[i][n[0]]=n[1]}}else"align custom"==n&&e.length>=4?this.setQueryresi2score(e):"area"==n&&2==e.length&&(t.midpercent=e[1],$("#"+t.pre+"midpercent").val(t.midpercent));t.setColorCls.setColorByOptions(t.opts,t.hAtoms),t.hlUpdateCls.updateHlAll()}else if(0==s.indexOf("remove legend"))$("#"+i.pre+"legend").hide();else if(0==s.indexOf("custom tube")){let e=s.split(" | ");this.setQueryresi2score(e),t.setOptionCls.setStyle("proteins","custom tube")}else if(0==n.indexOf("style")){let e=n.substr(n.indexOf(" ")+1),i=e.substr(0,e.indexOf(" ")),s=e.substr(e.indexOf(" ")+1);t.setOptionCls.setStyle(i,s)}else if(0==n.indexOf("window")){let e=n.substr(n.indexOf(" ")+1);setTimeout((function(){"aligned sequences"==e?i.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"):"interaction table"==e?i.htmlCls.dialogCls.openDlg("dl_allinteraction","Show interactions"):"interaction graph"==e?i.htmlCls.dialogCls.openDlg("dl_linegraph","Show interactions between two lines of residue nodes"):"interaction scatterplot"==e?i.htmlCls.dialogCls.openDlg("dl_scatterplot","Show interactions as scatterplot"):"force-directed graph"==e&&i.htmlCls.dialogCls.openDlg("dl_graph","Force-directed graph")}),1e3)}else if(0==n.indexOf("set theme")){let e=n.substr(n.lastIndexOf(" ")+1);i.htmlCls.setMenuCls.setTheme(e)}else if(0==n.indexOf("set double color")){let e=n.substr(n.lastIndexOf(" ")+1);"on"==e?(t.bDoublecolor=!0,t.setOptionCls.setStyle("proteins","ribbon")):"off"==e&&(t.bDoublecolor=!1)}else if(0==n.indexOf("adjust dialog")){let e=n.substr(n.lastIndexOf(" ")+1);t.scapCls.adjust2DWidth(e)}else if(0==n.indexOf("glycans cartoon")){let e=n.substr(n.lastIndexOf(" ")+1);t.bGlycansCartoon="yes"==e}else if(0==n.indexOf("clashed residues")){"show"==n.substr(n.lastIndexOf(" ")+1)?(t.bHideClashed=!1,t.annoDomainCls.showHideClashedResidues()):(t.bHideClashed=!0,i.htmlCls.clickMenuCls.setClashedResidues(),t.annoDomainCls.showHideClashedResidues())}else if(0==n.indexOf("save html")){let e=n.substr(n.lastIndexOf(" ")+1);i.htmlCls.eventsCls.saveHtml(e)}else if(0==n.indexOf("resdef"))i.cfg.resdef=n.substr(n.indexOf(" ")+1);else if(0==n.indexOf("vast_search_chainid")){t.chainidArray=s.substr(s.indexOf(" ")+1).split(",");let e=!0,i=!0;await t.realignParserCls.realignChainOnSeqAlign(void 0,t.chainidArray,e,i)}else if(0==n.indexOf("ig refnum off"))await t.refnumCls.hideIgRefNum();else if(0==n.indexOf("custom refnum")){let e=s.split(" | ")[1].replace(/\\n/g,"\n");await t.refnumCls.parseCustomRefFile(e)}else if(0==n.indexOf("show ref number"))t.bShownRefnum=!0;else if(0==n.indexOf("hide ref number"))t.bShownRefnum=!1;else if(0==n.indexOf("translate pdb")){let e=n.substr(14).split(" ");t.transformCls.translateCoord(t.hAtoms,parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])),t.drawCls.draw()}else if(0==n.indexOf("rotate pdb")){let e=n.substr(11).split(","),i=[];for(let t=0,s=e.length;t<s;++t)i.push(parseFloat(e[t]));t.transformCls.rotateCoord(t.hAtoms,i),t.drawCls.draw()}else if(0==n.indexOf("set dssp sse"))await t.pdbParserCls.applyCommandDssp(),t.bResetAnno=!0,t.bAnnoShown&&(await t.showAnnoCls.showAnnotations(),t.annotationCls.resetAnnoTabAll());else if(-1!==n.indexOf("select displayed set"))t.hAtoms=i.hashUtilsCls.cloneHash(t.viewSelectionAtoms),t.hlUpdateCls.updateHlAll();else if(-1!==n.indexOf("select prop")){let e,i,n=s.split(" | "),r=n[0].substr(12);if(2==n.length){let t=n[1].split("_");e=t[0],i=t[1]}t.resid2specCls.selectProperty(r,e,i)}else if(-1!==n.indexOf("select each residue"))t.selectionCls.saveEachResiInSel();else if(0==n.indexOf("select")&&-1!==n.indexOf("name")){let e=s.split(" | "),i="",n="",r="";for(let t=0,s=e.length;t<s;++t){let s=e[t];-1!==s.indexOf("select")?i=s.substr(s.indexOf(" ")+1):-1!==s.indexOf("name")&&(n=s.substr(s.indexOf(" ")+1))}r=n,await t.selByCommCls.selectByCommand(i,n,r)}else if(-1!==n.indexOf("select $")||-1!==n.indexOf("select .")||-1!==n.indexOf("select :")||-1!==n.indexOf("select %")||-1!==n.indexOf("select @")){let e=s.split(" | "),i=e[0].substr(e[0].indexOf(" ")+1),n="",r="";e.length>1&&(n=e[1].substr(e[1].indexOf(" ")+1)),e.length>2&&(r=e[2].substr(e[2].indexOf(" ")+1)),-1!==i.indexOf(" or ")?await t.selByCommCls.selectByCommand(i,n,r):await t.selByCommCls.selectBySpec(i,n,r)}i.htmlCls.clickMenuCls.setLogCmd(s,!1),t.bAddCommands=!0}setStrengthPara(e){let t=this.icn3d;if(t.icn3dui,e.length>=5){let i=e[4].split(" ");i.length>=4&&($("#"+t.pre+"hbondthreshold").val(i[1]),$("#"+t.pre+"saltbridgethreshold").val(i[2]),$("#"+t.pre+"contactthreshold").val(i[3]),i.length>=7&&($("#"+t.pre+"halogenthreshold").val(i[4]),$("#"+t.pre+"picationthreshold").val(i[5]),$("#"+t.pre+"pistackingthreshold").val(i[6])))}if(6==e.length){let i=e[5].split(" ");i.length>=6&&($("#"+t.pre+"dist_ss").val(i[0]),$("#"+t.pre+"dist_coil").val(i[1]),$("#"+t.pre+"dist_hbond").val(i[2]),$("#"+t.pre+"dist_inter").val(i[3]),$("#"+t.pre+"dist_ssbond").val(i[4]),$("#"+t.pre+"dist_ionic").val(i[5]),9==i.length&&($("#"+t.pre+"dist_halogen").val(i[6]),$("#"+t.pre+"dist_pication").val(i[7]),$("#"+t.pre+"dist_pistacking").val(i[8])))}}getThresholdNameArrays(e){this.icn3d.icn3dui.htmlCls.clickMenuCls.SetChainsAdvancedMenu();let t,i=e.split(" | "),s=parseFloat(i[0].substr(i[0].lastIndexOf(" ")+1)),n=[],r=[];if(i.length>=2&&i[1].length>4){let e=i[1].split(" ");e.length>1&&(r=e[1].split(",")),e.length>2&&(n=e[2].split(","))}else r=["selected"],n=["non-selected"];return 3==i.length&&(t="true"==i[2]),{threshold:s,nameArray2:r,nameArray:n,bHbondCalc:t}}setQueryresi2score(e){let t=this.icn3d,i=t.icn3dui,s=e[1],n=e[2].split(" ")[1].split("_"),r=e[3];void 0===t.queryresi2score&&(t.queryresi2score={}),t.queryresi2score[s]={};let a=100/9;for(let e=parseInt(n[0]),i=0;e<=parseInt(n[1]);++e,++i)"_"!=r[i]&&(t.queryresi2score[s][e]=parseInt(r[i])*a);if(e.length>4){let s=e[4].split(" ");t.startColor=s[1],t.midColor=s[2],t.endColor=s[3];let n=i.htmlCls.clickMenuCls.setLegendHtml();$("#"+i.pre+"dl_legend_html").html(n),i.htmlCls.dialogCls.openDlg("dl_legend","Color Range")}}addShape(e,t){let i=this.icn3d,s=i.icn3dui,n=e.split(" | "),r=n[1].split(" "),a=n[2].substr(n[2].lastIndexOf(" ")+1),o=n[3].substr(n[3].lastIndexOf(" ")+1),l=n[4].substr(n[4].lastIndexOf(" ")+1);a="#"+a.replace(/\#/g,"");let d,c=s.parasCls.thr(a);if("x1"==r[0])d=new mt(parseFloat(r[1]),parseFloat(r[3]),parseFloat(r[5]));else{let e=n[1].split(","),t=i.definedSetsCls.getAtomsFromNameArray(e),s=i.contactCls.getExtent(t);d=new mt(s[2][0],s[2][1],s[2][2])}"sphere"==t?i.sphereCls.createSphereBase(d,c,parseFloat(l),void 0,void 0,void 0,parseFloat(o)):i.boxCls.createBox_base(d,parseFloat(l),c,void 0,void 0,void 0,parseFloat(o))}getMenuFromCmd(e){this.icn3d.icn3dui;let t="Windows > View Sequences & Annotations",i="Analysis > Interactions",s=i+" > 2D Graph(Force-Directed)",n="View > Rotate > Auto Rotation > Rotate ",r="View > Rotate > Rotate 90 deg > ",a="Select > Select on 3D > ",o="Analysis > Label > ",l="File > 3D Printing > ";return 0==(e=e.trim()).indexOf("load")?"File > Retrieve by ID, Align":0==e.indexOf("set map")&&-1==e.indexOf("set map wireframe")?"Style > Electron Density":0==e.indexOf("set emmap")&&-1==e.indexOf("set emmap wireframe")?"Style > EM Density Map":0==e.indexOf("set phi")?"Analysis > Load Potential > URL(CORS) Phi/Cube":0==e.indexOf("set delphi")?"Analysis > DelPhi Potential":0==e.indexOf("setoption map")?"Style > Remove Map":0==e.indexOf("setoption emmap")?"Style > Remove EM Map":0==e.indexOf("view annotations")?t:0==e.indexOf("set annotation all")?t+': "All" checkbox':0==e.indexOf("set annotation clinvar")?t+': "ClinVar" checkbox':0==e.indexOf("set annotation snp")?t+': "SNP" checkbox':0==e.indexOf("set annotation 3ddomain")?t+': "3D Domains" checkbox':0==e.indexOf("view interactions")?"Windows > View 2D Diagram":0==e.indexOf("symmetry")?"Analysis > Symmetry":0==e.indexOf("realign on seq align")?"File > Realign Selection > on Sequence Alignment":0==e.indexOf("realign")?"File > Realign Selection > Residue by Residue":0==e.indexOf("graph interaction pairs")?i+" > 2D Graph(Force-Directed)":0==e.indexOf("export canvas")?"File > Save File > iCn3D PNG Image":"export stl file"==e?l+"STL":"export vrml file"==e?l+"VRML(Color)":"export stl stabilizer file"==e?l+"STL W/ Stabilizers":"export vrml stabilizer file"==e?l+"VRML(Color, W/ Stabilizers)":"select all"==e?'Select > All; or Toggle to "All"(next to "Help")':"show all"==e?"View > View Full Structure":"select complement"==e?"Select > Inverse":"set pk atom"==e?a+"Atom":"set pk residue"==e?a+"Residue":"set pk strand"==e?a+"Strand/Helix":"set pk domain"==e?a+"3D Domain":"set pk chain"==e?a+"Chain":"set surface wireframe on"==e?"Style > Surface Wireframe > Yes":"set surface wireframe off"==e?"Style > Surface Wireframe > No":"set map wireframe on"==e?"Style > Map Wireframe > Yes":"set map wireframe off"==e?"Style > Map Wireframe > No":"set emmap wireframe on"==e?"Style > EM Map Wireframe > Yes":"set emmap wireframe off"==e?"Style > EM Map Wireframe > No":"set surface neighbors on"==e?"Style > Surface Type > ... with Context":"set axis on"==e?"View > XYZ-axes > Show":"set axis off"==e?"View > XYZ-axes > Hide":"set fog on"==e?"View > Fog for Selection > On":"set fog off"==e?"View > Fog for Selection > Off":"set slab on"==e?"View > Slab for Selection > On":"set slab off"==e?"View > Slab for Selection > Off":"set assembly on"==e?"Analysis > Assembly > Biological Assembly":"set assembly off"==e?"Analysis > Assembly > Asymmetric Unit":"set chemicalbinding show"==e?"Analysis > Chem. Binding > Show":"set chemicalbinding hide"==e?"Analysis > Chem. Binding > Hide":"set hbonds off"==e||"set salt bridge off"==e||"set contact off"==e||"set halogen pi off"==e?i+" > Reset":"hydrogens"==e?"Style > Hydrogens > Show":"set hydrogens off"==e?"Style > Hydrogens > Hide":"set stabilizer off"==e?"File > 3D Printing > Remove All Stabilizers":"set disulfide bonds off"==e?"Analysis > Disulfide Bonds > Hide":"set cross linkage off"==e?"Analysis > Cross-Linkages > Hide":"set lines off"==e?"Analysis > Distance > Hide":"set labels off"==e?"Analysis > Label > Remove":"set mode all"==e?'Toggle to "All"(next to "Help")':"set mode selection"==e?'Toggle to "Selection"(next to "Help")':"set view detailed view"==e?t+': "Details" tab':"set view overview"==e?t+': "Summary" tab':"set annotation custom"==e?t+': "Custom" checkbox':"set annotation interaction"==e?t+': "Interactions" checkbox':"set annotation ptm"==e?t+': "PTM" checkbox':"set annotation cdd"==e?t+': "Conserved Domains" checkbox':"set annotation site"==e?t+': "Functional Sites" checkbox':"set annotation ssbond"==e?t+': "Disulfide Bonds" checkbox':"set annotation crosslink"==e?t+': "Cross-Linkages" checkbox':"set annotation transmembrane"==e?t+': "Transmembrane" checkbox':"set annotation ig"==e?t+': "Ig Domains" checkbox':"highlight level up"==e?"Keyboard Arrow Up":"highlight level down"==e?"Keyboard Arrow Down":0==e.indexOf("hide annotation")?t+": checkboxes off":"add residue labels"==e?o+"per Residue":"add residue number labels"==e?o+"per Residue & Number":"add Ig domain labels"==e?o+"per Ig Domain":"add atom labels"==e?o+"per Atom":"add chain labels"==e?o+"per Chain":"add terminal labels"==e?o+"N- & C- Termini":"rotate left"==e?n+"Left; or Key l":"rotate right"==e?n+"Right; or Key j":"rotate up"==e?n+"Up; or Key i":"rotate down"==e?n+"Down; or Key m":"rotate x"==e?r+"X-axis":"rotate y"==e?r+"Y-axis":"rotate z"==e?r+"Z-axis":"reset"==e?"View > Reset > All":"reset orientation"==e?"View > Reset > Orientation":"clear selection"==e?"Select > Clear Selection":"zoom selection"==e?"Select > Zoom in Selection":"center selection"==e?"Select > Center Selection":"show selection"==e?"Select > View Only Selection":"hide selection"==e?"Select > Hide Selection":"output selection"==e?"Select > Clear Selection":"toggle highlight"==e?"Select > Toggle Highlight":"stabilizer"==e?"File > 3D Printing > Add all Stabilizers":"disulfide bonds"==e?"Analysis > Disulfide Bonds > Show":"cross linkage"==e?"Analysis > Cross-Linkages > Show":"back"==e?"View > Undo":"forward"==e?"View > Redo":"clear all"==e?"Select > Clear Selection":"defined sets"==e?"Windows > Defined Sets":"delete selected sets"==e?'Windows > Defined Sets: "Delete Selected Sets" button':"view interactions"==e?"Windows > View Interactions":"show annotations all chains"==e?t+': "Show All Chains" button':"save color"==e?"Color > Save Color":"apply saved color"==e?"Color > Apply Saved Color":"save style"==e?"Style > Save Style":"apply saved style"==e?"Style > Apply Saved Style":"select main chains"==e?"Select > Main Chains":"select side chains"==e?"Select > Side Chains":"select main side chains"==e?"Select > Main & Side Chains":"area"==e?"View > Surface Area":"table inter count only"==e?i+': "Set 1" button: "Show Count Only" button':"table inter details"==e?i+': "Set 1" button: "Show Details" button':0==e.indexOf("define helix sets")?t+': "Helix Sets" button':0==e.indexOf("define sheet sets")?t+': "Sheet Sets" button':0==e.indexOf("define coil sets")?t+': "Coil Sets" button':0==e.indexOf("select interaction")?"Windows > View 2D Diagram: click on edges":0==e.indexOf("select saved atoms")||0==e.indexOf("select sets")?"Windows > Defined Sets: select in menu":-1!==e.indexOf("select chain")?t+": click on chain names":-1!==e.indexOf("select alignChain")?"Windows > View Aligned Sequences: click on chain names":0==e.indexOf("select zone cutoff")?"Select > by Distance":0==e.indexOf("set surface opacity")?"Style > Surface Opacity":0==e.indexOf("set label scale")?"View > Label Scale":0==e.indexOf("set surface")?"Style > Surface Type":0==e.indexOf("set camera")?"View > Camera":0==e.indexOf("set background")?"Style > Background":0==e.indexOf("set thickness")?"File > 3D Printing > Set Thickness":0==e.indexOf("set highlight color")?"Select > Highlight Color":0==e.indexOf("set highlight style")?"Select > Highlight Style":0==e.indexOf("add line")||0==e.indexOf("add label")?"Analysis > Distance > between Two Atoms":0==e.indexOf("dist")?"Analysis > Distance > between Two Sets":0==e.indexOf("msa")?t+': "Add Track" button: "FASTA Alignment" button':0==e.indexOf("add track")?t+': "Add Track" button':0==e.indexOf("remove one stabilizer")?"File > 3D Printing > Remove One Stablizer":0==e.indexOf("add one stabilizer")?"File > 3D Printing > Add One Stablizer":0==e.indexOf("select planes z-axis")?"View > Select between Two X-Y Planes":0==e.indexOf("adjust membrane z-axis")?"View > Adjust Membrane":0==e.indexOf("toggle membrane")?"View > Toggle Membrane":0==e.indexOf("calc buried surface")?i+': "Buried Surface Area" button':0==e.indexOf("display interaction 3d")?i+': "3D Display Interactions" button':0==e.indexOf("view interaction pairs")?i+': "Highlight Interactions in Table" button':0==e.indexOf("save1 interaction pairs")?i+': "Set 1" button':0==e.indexOf("save2 interaction pairs")?i+': "Set 2" button':0==e.indexOf("line graph interaction pairs")?i+': "2D Interaction Network" button':0==e.indexOf("scatterplot interaction pairs")?i+': "2D Interaction Map" button':0==e.indexOf("ligplot interaction pairs")?i+': "2D Interaction for One Ligand/Residue" button':0==e.indexOf("graph label")?s+': "Label Size" menu':0==e.indexOf("graph force")?s+': "Force on Nodes" menu':0==e.indexOf("hide edges")?s+': "Internal Edges" menu':0==e.indexOf("reset interaction pairs")?i+" > Reset":0==e.indexOf("side by side")?"View > Side by Side":0==e.indexOf("your note")?"Windows > Your Notes / Window Title":0==e.indexOf("pickatom")?"Hold Alt key and click on 3D structure":0==e.indexOf("color")?"Color menu":0==e.indexOf("custom tube")?t+': "Custom Color/Tube" button: "Custom Tube" button':0==e.indexOf("style")?"Style menu":-1!==e.indexOf("select displayed set")?"Select > Displayed Set":-1!==e.indexOf("select prop")?"Select > by Property":0==e.indexOf("select")&&-1!==e.indexOf("name")?t+": drag on residues to select":-1!==e.indexOf("select $")||-1!==e.indexOf("select .")||-1!==e.indexOf("select :")||-1!==e.indexOf("select @")?"Select > Advanced; or other selection":-1!==e.indexOf("replay on")?"File > Replay Each Step > On":-1!==e.indexOf("replay off")?"File > Replay Each Step > Off":-1!==e.indexOf("set theme")?"Style > Theme Color":-1!==e.indexOf("set double color")?"Style > Two-color Helix":""}}class Yh{constructor(e){this.icn3d=e}setProtNuclLigInMenu(){let e=this.icn3d;if(e.icn3dui,e.proteins&&Object.keys(e.proteins).length>0&&(e.defNames2Residues.proteins=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.proteins)),e.defNames2Descr.proteins="proteins",e.defNames2Command.proteins="select :proteins"),e.nucleotides&&Object.keys(e.nucleotides).length>0&&(e.defNames2Residues.nucleotides=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.nucleotides)),e.defNames2Descr.nucleotides="nucleotides",e.defNames2Command.nucleotides="select :nucleotides"),e.chemicals&&Object.keys(e.chemicals).length>0)if(e.bOpm){let t={},i={};for(let s in e.chemicals){let n=e.atoms[s],r=n.structure+"_"+n.chain+"_"+n.resi;"DUM"===n.resn?i[r]=1:t[r]=1}Object.keys(t).length>0&&(e.defNames2Residues.chemicals=Object.keys(t),e.defNames2Descr.chemicals="chemicals",e.defNames2Command.chemicals="select :chemicals"),Object.keys(i).length>0&&(e.defNames2Residues.membrane=Object.keys(i),e.defNames2Descr.membrane="membrane",e.defNames2Command.membrane="select :membrane")}else e.defNames2Residues.chemicals=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.chemicals)),e.defNames2Descr.chemicals="chemicals",e.defNames2Command.chemicals="select :chemicals";e.ions&&Object.keys(e.ions).length>0&&(e.defNames2Residues.ions=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.ions)),e.defNames2Descr.ions="ions",e.defNames2Command.ions="select :ions"),e.water&&Object.keys(e.water).length>0&&(e.defNames2Residues.water=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.water)),e.defNames2Descr.water="water",e.defNames2Command.water="select :water"),this.setTransmemInMenu(e.halfBilayerSize,-e.halfBilayerSize)}setPredefinedInMenu(){let e=this.icn3d,t=e.icn3dui;if(this.setProtNuclLigInMenu(),this.setChainsInMenu(),void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi||void 0!==t.cfg.chainalign||void 0!==t.cfg.mmdbafid)for(let t in e.tddomains)e.selectionCls.selectResidueList(e.tddomains[t],t,t,!1,!1);if((void 0!==t.cfg.align||void 0!==t.cfg.chainalign&&2==e.chainidArray.length)&&e.bFullUi){e.selectionCls.selectResidueList(e.consHash1,e.conservedName1,e.conservedName1,!1,!1),e.selectionCls.selectResidueList(e.consHash2,e.conservedName2,e.conservedName2,!1,!1),e.selectionCls.selectResidueList(e.nconsHash1,e.nonConservedName1,e.nonConservedName1,!1,!1),e.selectionCls.selectResidueList(e.nconsHash2,e.nonConservedName2,e.nonConservedName2,!1,!1),e.selectionCls.selectResidueList(e.nalignHash1,e.notAlignedName1,e.notAlignedName1,!1,!1),e.selectionCls.selectResidueList(e.nalignHash2,e.notAlignedName2,e.notAlignedName2,!1,!1);let i={};for(let s in e.alnChains)i=t.hashUtilsCls.unionHash(i,e.alnChains[s]);let s=e.firstAtomObjCls.getResiduesFromAtoms(i),n="protein_aligned",r="aligned protein and nucleotides",a="select "+e.resid2specCls.residueids2spec(Object.keys(s));e.selectionCls.addCustomSelection(Object.keys(s),n,r,a,!0)}}setAtomMenu(e){let t=this.icn3d;t.icn3dui;let i="",s=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues):[],n=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms):[],r=s.concat(n).sort(),a=[];r.forEach((e=>{-1===$.inArray(e,a)&&a.push(e)}));for(let s=0,n=a.length;s<n;++s){let n,r,o=a[s];if(void 0!==t.defNames2Atoms&&t.defNames2Atoms.hasOwnProperty(o)){let e=t.defNames2Atoms[o];e.length>0&&(n=t.atoms[e[0]])}else if(void 0!==t.defNames2Residues&&t.defNames2Residues.hasOwnProperty(o)){let e=t.defNames2Residues[o];e.length>0&&(r=t.residues[e[0]],r&&(n=t.atoms[Object.keys(r)[0]]))}let l=void 0===n||void 0===n.color||"FFFFFF"===n.color.getHexString().toUpperCase()?"DDDDDD":n.color.getHexString(),d=void 0!==n&&void 0!==n.color?l:"000000";-1!=e.indexOf(o)?i+="<option value='"+o+"' style='color:#"+d+"' selected='selected'>"+o+"</option>":i+="<option value='"+o+"' style='color:#"+d+"'>"+o+"</option>"}return i}setChainsInMenu(){let e=this.icn3d,t=e.icn3dui,i={};for(let s in e.chains){let n=e.firstAtomObjCls.getFirstAtomObj(e.chains[s]);if(e.proteins.hasOwnProperty(n.serial)||e.nucleotides.hasOwnProperty(n.serial)){e.defNames2Residues[s]=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.chains[s])),e.defNames2Descr[s]=s;let t=s.indexOf("_"),i=s.substr(0,t),n=s.substr(t+1);e.defNames2Command[s]="select $"+i+"."+n}else{let s=n.structure+"_"+n.chain+"_"+n.resi,r=n.resn.substr(0,3);i[r]?i[r]=t.hashUtilsCls.unionHash(i[n.resn],e.residues[s]):i[r]=e.residues[s]}}for(let t in i)e.defNames2Residues[t]=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(i[t])),e.defNames2Descr[t]=t,e.defNames2Command[t]="select :3"+t;if(e.structures&&1==Object.keys(e.structures)){let t=Object.keys(e.structures)[0];e.defNames2Residues[t]=Object.keys(e.residues),e.defNames2Descr[t]=t,e.defNames2Command[t]="select $"+t}else if(e.residues){let t=Object.keys(e.residues),i={};for(let e=0,s=t.length;e<s;++e){let s=t[e],n=s.indexOf("_"),r=s.substr(0,n);void 0===i[r]&&(i[r]=[]),i[r].push(s)}for(let t in i)e.defNames2Residues[t]=i[t],e.defNames2Descr[t]=t,e.defNames2Command[t]="select $"+t}}setTransmemInMenu(e,t,i){let s=this.icn3d;if(s.icn3dui,s.bOpm){let n={},r={},a={};for(let i in s.atoms){let o=s.atoms[i];if("DUM"===o.resn)continue;let l=o.structure+"_"+o.chain+"_"+o.resi;o.coord.z>e?r[l]=1:o.coord.z<t?a[l]=1:n[l]=1}let o=i?"2":"";Object.keys(n).length>0&&(s.defNames2Residues["transmembrane"+o]=Object.keys(n),s.defNames2Descr["transmembrane"+o]="transmembrane"+o,s.defNames2Command["transmembrane"+o]="select :transmembrane"+o),Object.keys(r).length>0&&(s.defNames2Residues["extracellular"+o]=Object.keys(r),s.defNames2Descr["extracellular"+o]="extracellular"+o,s.defNames2Command["extracellular"+o]="select :extracellular"+o),Object.keys(a).length>0&&(s.defNames2Residues["intracellular"+o]=Object.keys(a),s.defNames2Descr["intracellular"+o]="intracellular"+o,s.defNames2Command["intracellular"+o]="select :intracellular"+o)}}showSets(){let e=this.icn3d,t=e.icn3dui;t.bNode||(t.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+e.pre+"dl_setsmenu").show(),$("#"+e.pre+"dl_setoperations").show(),$("#"+e.pre+"dl_command").hide(),$("#"+e.pre+"atomsCustom").resizable());let i=t.hashUtilsCls.cloneHash(e.hAtoms),s=t.hashUtilsCls.cloneHash(e.dAtoms);void 0!==e.bSetChainsAdvancedMenu&&e.bSetChainsAdvancedMenu&&!e.bResetSets||(this.setPredefinedInMenu(),e.bSetChainsAdvancedMenu=!0),e.hAtoms=t.hashUtilsCls.cloneHash(i),e.dAtoms=t.hashUtilsCls.cloneHash(s),e.hlUpdateCls.updateHlMenus()}clickCustomAtoms(){let e=this.icn3d,t=e.icn3dui,i=this;$("#"+e.pre+"atomsCustom").change((function(e){let s=i.icn3d,n=$(this).val();if(s.nameArray=n,null!==n){let e=!1;i.changeCustomAtoms(n,e),t.htmlCls.clickMenuCls.setLogCmd("select sets "+n.join(" "+s.setOperation+" "),!0),s.bSelectResidue=!1}})),t.myEventCls.onIds("#"+e.pre+"atomsCustom","focus",(function(e){let s=i.icn3d;t.utilsCls.isMobile()&&$("#"+s.pre+"atomsCustom").val("")}))}deleteSelectedSets(){let e=this.icn3d;e.icn3dui;let t=$("#"+e.pre+"atomsCustom").val();for(let i=0;i<t.length;++i){let s=t[i];(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(s)||void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(s))&&(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(s)&&delete e.defNames2Atoms[s],void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(s)&&delete e.defNames2Residues[s])}e.hlUpdateCls.updateHlMenus()}changeCustomAtoms(e,t){let i=this.icn3d,s=i.icn3dui;i.hAtoms={};for(let t=0;t<e.length;++t){let n=e[t];if(void 0!==i.defNames2Atoms&&i.defNames2Atoms.hasOwnProperty(n)||void 0!==i.defNames2Residues&&i.defNames2Residues.hasOwnProperty(n)){if(void 0!==i.defNames2Atoms&&i.defNames2Atoms.hasOwnProperty(n)){let e=i.defNames2Atoms[n];for(let t=0,s=e.length;t<s;++t)i.hAtoms[e[t]]=1}if(void 0!==i.defNames2Residues&&i.defNames2Residues.hasOwnProperty(n)){let e=i.defNames2Residues[n],t={};for(let n=0,r=e.length;n<r;++n)t=s.hashUtilsCls.unionHash(t,i.residues[e[n]]);i.hAtoms=s.hashUtilsCls.unionHash(i.hAtoms,t)}}}i.hlUpdateCls.updateHlAll(e,t),i.annotationCls.showAnnoSelectedChains(),$("#"+i.pre+"command").val(""),$("#"+i.pre+"command_name").val("");for(let t=0,s=e.length;t<s;++t)if(i.defNames2Atoms[e[t]],i.defNames2Residues[e[t]],i.defNames2Descr[e[t]],0===t)$("#"+i.pre+"command").val("saved atoms "+e[t]),$("#"+i.pre+"command_name").val(e[t]);else{let s=$("#"+i.pre+"command").val();$("#"+i.pre+"command").val(s+" "+i.setOperation+" "+e[t]),s=$("#"+i.pre+"command_name").val(),$("#"+i.pre+"command_name").val(s+" "+i.setOperation+" "+e[t])}}setHAtomsFromSets(e,t){let i=this.icn3d;i.icn3dui;for(let s=0;s<e.length;++s){let n=e[s];if(this.setHAtomsFromSets_base(n,t),0==Object.keys(i.hAtoms).length&&("sphere"==n.split(".")[0]||"interactions"==n.split(".")[0])){let e=n.lastIndexOf("-");n=n.split(".")[0]+n.substr(e),this.setHAtomsFromSets_base(n,t)}}}setHAtomsFromSets_base(e,t){let i=this.icn3d,s=i.icn3dui;if(void 0!==i.defNames2Atoms&&i.defNames2Atoms.hasOwnProperty(e)){let n=i.defNames2Atoms[e];if("or"===t)for(let e=0,t=n.length;e<t;++e)i.hAtoms[n[e]]=1;else if("and"===t){let e={};for(let t=0,i=n.length;t<i;++t)e[n[t]]=1;i.hAtoms=s.hashUtilsCls.intHash(i.hAtoms,e)}else if("not"===t){let e={};for(let t=0,i=n.length;t<i;++t)e[n[t]]=1;i.hAtoms=s.hashUtilsCls.exclHash(i.hAtoms,e)}}if(void 0!==i.defNames2Residues&&i.defNames2Residues.hasOwnProperty(e)){let n=i.defNames2Residues[e],r={};for(let e=0,t=n.length;e<t;++e)r=s.hashUtilsCls.unionHash(r,i.residues[n[e]]);"or"===t?i.hAtoms=s.hashUtilsCls.unionHash(i.hAtoms,r):"and"===t?i.hAtoms=s.hashUtilsCls.intHash(i.hAtoms,r):"not"===t&&(i.hAtoms=s.hashUtilsCls.exclHash(i.hAtoms,r))}}updateAdvancedCommands(e,t){let i=this.icn3d;i.icn3dui;let s=" "+t+" ";for(let n=0,r=e.length;n<r;++n)if(0===n&&"or"==t)$("#"+i.pre+"command").val("saved atoms "+e[n]),$("#"+i.pre+"command_name").val(e[n]);else{let t=$("#"+i.pre+"command").val();$("#"+i.pre+"command").val(t+s+e[n]),t=$("#"+i.pre+"command_name").val(),$("#"+i.pre+"command_name").val(t+s+e[n])}}combineSets(e,t,i,s){let n=this.icn3d,r=n.icn3dui;if(n.hAtoms={},this.setHAtomsFromSets(e,"or"),0==Object.keys(n.hAtoms).length&&(n.hAtoms=r.hashUtilsCls.cloneHash(n.dAtoms)),this.setHAtomsFromSets(t,"and"),this.setHAtomsFromSets(i,"not"),n.bInitial||n.hlUpdateCls.updateHlAll(),n.annotationCls.showAnnoSelectedChains(),$("#"+n.pre+"command").val(""),$("#"+n.pre+"command_name").val(""),this.updateAdvancedCommands(e,"or"),this.updateAdvancedCommands(t,"and"),this.updateAdvancedCommands(i,"not"),void 0!==s){let e="select "+$("#"+n.pre+"command").val();$("#"+n.pre+"command_name").val(s),n.selectionCls.addCustomSelection(Object.keys(n.hAtoms),s,s,e,!1)}}async commandSelect(e){let t=this.icn3d,i=t.icn3dui,s=$("#"+t.pre+"command"+e).val(),n=$("#"+t.pre+"command_name"+e).val().replace(/;/g,"_").replace(/\s+/g,"_");s&&(await t.selByCommCls.selectByCommand(s,n,n),i.htmlCls.clickMenuCls.setLogCmd("select "+s+" | name "+n,!0))}clickCommand_apply(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+e.pre+"command_apply","click",(async function(e){i.icn3d,e.preventDefault(),await i.commandSelect("")})),t.myEventCls.onIds("#"+e.pre+"command_apply2","click",(async function(e){i.icn3d,e.preventDefault(),await i.commandSelect("2")}))}selectCombinedSets(e,t){this.icn3d.icn3dui;let i=e.split(" "),s=[],n=[],r=[],a="or";for(let e=0,t=i.length;e<t;++e){let t=i[e].split("_");if(3!=t.length||isNaN(t[2])||(i[e]=t[0]+"_"+t[1]+t[2]),"or"!==i[e]&&"and"!==i[e]&&"not"!==i[e]){let t=["hbonds_","saltbridge_","halogen_","pi-cation_","pi-stacking_"];for(let s=0,n=t.length;s<n;++s){const n=new RegExp("^"+t[s]+"\\d+$");i[e].match(n)&&(i[e]=t[s]+"auto")}"or"===a?s.push(i[e]):"and"===a?n.push(i[e]):"not"===a&&r.push(i[e])}else a=i[e]}null!==i&&this.combineSets(s,n,r,t)}clickModeswitch(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+e.pre+"modeswitch","click",(function(t){void 0!==$("#"+e.pre+"modeswitch")[0]&&$("#"+e.pre+"modeswitch")[0].checked?i.setModeAndDisplay("selection"):i.setModeAndDisplay("all")}))}setModeAndDisplay(e){let t=this.icn3d,i=t.icn3dui;"all"===e?(this.setMode("all"),t.prevHighlightAtoms=i.hashUtilsCls.cloneHash(t.hAtoms),i.htmlCls.clickMenuCls.setLogCmd("set mode all",!0),t.selectionCls.selectAll(),t.drawCls.draw()):(this.setMode("selection"),void 0!==t.prevHighlightAtoms?t.hAtoms=i.hashUtilsCls.cloneHash(t.prevHighlightAtoms):t.selectionCls.selectAll(),i.htmlCls.clickMenuCls.setLogCmd("set mode selection",!0),t.hlUpdateCls.updateHlAll())}setMode(e){let t=this.icn3d;t.icn3dui,"all"===e?($("#"+t.pre+"modeall").show(),$("#"+t.pre+"modeselection").hide(),void 0!==$("#"+t.pre+"modeswitch")[0]&&($("#"+t.pre+"modeswitch")[0].checked=!1),$("#"+t.pre+"style").hasClass("icn3d-modeselection")&&$("#"+t.pre+"style").removeClass("icn3d-modeselection"),$("#"+t.pre+"color").hasClass("icn3d-modeselection")&&$("#"+t.pre+"color").removeClass("icn3d-modeselection")):($("#"+t.pre+"modeall").hide(),$("#"+t.pre+"modeselection").show(),void 0!==$("#"+t.pre+"modeswitch")[0]&&($("#"+t.pre+"modeswitch")[0].checked=!0),$("#"+t.pre+"style").hasClass("icn3d-modeselection")||$("#"+t.pre+"style").addClass("icn3d-modeselection"),$("#"+t.pre+"color").hasClass("icn3d-modeselection")||$("#"+t.pre+"color").addClass("icn3d-modeselection"))}getAtomsFromOneSet(e){let t=this.icn3d,i=t.icn3dui,s={};if(void 0===t.defNames2Residues.proteins&&this.showSets(),-1!==Object.keys(t.chains).indexOf(e))s=i.hashUtilsCls.unionHash(s,t.chains[e]);else{if(void 0!==t.defNames2Residues[e]&&t.defNames2Residues[e].length>0)for(let n=0,r=t.defNames2Residues[e].length;n<r;++n){let r=t.defNames2Residues[e][n];s=i.hashUtilsCls.unionHash(s,t.residues[r])}if(void 0!==t.defNames2Atoms[e]&&t.defNames2Atoms[e].length>0)for(let i=0,n=t.defNames2Atoms[e].length;i<n;++i){s[t.defNames2Atoms[e][i]]=1}}return s}getAtomsFromNameArray(e){let t=this.icn3d,i=t.icn3dui,s={};for(let n=0,r=e.length;n<r;++n)if("non-selected"===e[n]){let e={};for(let i in t.atoms)!t.hAtoms.hasOwnProperty(i)&&t.dAtoms.hasOwnProperty(i)&&(e[i]=t.atoms[i]);s=i.hashUtilsCls.unionHash(s,e)}else s="selected"===e[n]?i.hashUtilsCls.unionHash(s,i.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)):i.hashUtilsCls.unionHash(s,i.hashUtilsCls.hash2Atoms(this.getAtomsFromOneSet(e[n]),t.atoms));return 0==e.length&&(s=t.atoms),s}}class Kh{constructor(e){this.icn3d=e}setAtomMenu(e){let t=this.icn3d;t.icn3dui;let i="";return Object.entries(e).forEach((([e,s],n)=>{let r,[a,o,l,d,c]=s;if(void 0!==t.defNames2Atoms&&t.defNames2Atoms.hasOwnProperty(e)){let i=t.defNames2Atoms[e];i.length>0&&t.atoms[i[0]]}else if(void 0!==t.defNames2Residues&&t.defNames2Residues.hasOwnProperty(e)){let i=t.defNames2Residues[e];i.length>0&&(r=t.residues[i[0]],r&&t.atoms[Object.keys(r)[0]])}i+=0===n?"<option value='"+e+"' selected='selected' data-description='"+l+"'>"+o+"</option>":"<option value='"+e+"' data-description='"+l+"'>"+o+"</option>"})),i}reset(){let e=this.icn3d;e.atoms={},e.proteins={},e.nucleotides={},e.chemicals={},e.ions={},e.water={},e.structures={},e.chains={},e.chainsSeq={},e.residues={},e.defNames2Atoms={},e.defNames2Residues={},e.ssbondpnts={},e.bShowHighlight=void 0,e.bResetSets=!0}dictionaryDifference(e,t){const i={};for(let s in t)s in e||(i[s]=t[s]);return i}clickStructure(e){let t=this.icn3d,i=t.icn3dui,s=this;$("#"+t.pre+"collections_menu").on("change",(async function(t){let n=s.icn3d,r=$(this).val(),a=$(this).find("option:selected").text(),o=Array.from(this.selectedOptions).map((e=>e.index));if(r.reduce(((e,t,i)=>(e[t]=o[i],e)),{}),n.nameArray=r,null!==r){let l=!0;s.reset();for(const d of r)if(!(d in n.allData)){async function c(e){if(await n.resetConfig(),e){let e=!0;0==Object.keys(n.structures).length&&(e=!1),await n.pdbParserCls.loadPdbData(n.pdbCollection[d].join("\n"),void 0,void 0,e)}else await n.chainalignParserCls.downloadMmdbAf(d,void 0,void 0,l)}n.allData.prev=JSON.parse(JSON.stringify(n.allData.all)),n.atoms=n.allData.all.atoms,n.proteins=n.allData.all.proteins,n.nucleotides=n.allData.all.nucleotides,n.chemicals=n.allData.all.chemicals,n.ions=n.allData.all.ions,n.water=n.allData.all.water,n.structures=n.allData.all.structures,n.ssbondpnts=n.allData.all.ssbondpnts,n.residues=n.allData.all.residues,n.chains=n.allData.all.chains,n.chainsSeq=n.allData.all.chainsSeq,n.defalls2Atoms=n.allData.all.defalls2Atoms,n.defalls2Residues=n.allData.all.defalls2Residues,await c(e[d][4]).then((()=>{n.allData.all={atoms:n.atoms,proteins:n.proteins,nucleotides:n.nucleotides,chemicals:n.chemicals,ions:n.ions,water:n.water,structures:n.structures,ssbondpnts:n.ssbondpnts,residues:n.residues,chains:n.chains,chainsSeq:n.chainsSeq,defNames2Atoms:n.defNames2Atoms,defNames2Residues:n.defNames2Residues},n.allData[d]={title:n.molTitle,atoms:s.dictionaryDifference(n.allData.prev.atoms,n.atoms),proteins:s.dictionaryDifference(n.allData.prev.proteins,n.proteins),nucleotides:s.dictionaryDifference(n.allData.prev.nucleotides,n.nucleotides),chemicals:s.dictionaryDifference(n.allData.prev.chemicals,n.chemicals),ions:s.dictionaryDifference(n.allData.prev.ions,n.ions),water:s.dictionaryDifference(n.allData.prev.water,n.water),structures:s.dictionaryDifference(n.allData.prev.structures,n.structures),ssbondpnts:s.dictionaryDifference(n.allData.prev.ssbondpnts,n.ssbondpnts),residues:s.dictionaryDifference(n.allData.prev.residues,n.residues),chains:s.dictionaryDifference(n.allData.prev.chains,n.chains),chainsSeq:s.dictionaryDifference(n.allData.prev.chainsSeq,n.chainsSeq),defNames2Atoms:s.dictionaryDifference(n.allData.prev.defNames2Atoms,n.defNames2Atoms),defNames2Residues:s.dictionaryDifference(n.allData.prev.defNames2Residues,n.defNames2Residues)},s.reset()}))}for(const h of r){if(n.atoms=Object.assign(n.atoms,n.allData[h].atoms),n.proteins=Object.assign(n.proteins,n.allData[h].proteins),n.nucleotides=Object.assign(n.nucleotides,n.allData[h].nucleotides),n.chemicals=Object.assign(n.chemicals,n.allData[h].chemicals),n.ions=Object.assign(n.ions,n.allData[h].ions),n.water=Object.assign(n.water,n.allData[h].water),n.structures=Object.assign(n.structures,n.allData[h].structures),n.ssbondpnts=Object.assign(n.ssbondpnts,n.allData[h].ssbondpnts),n.residues=Object.assign(n.residues,n.allData[h].residues),n.chains=Object.assign(n.chains,n.allData[h].chains),n.chainsSeq=Object.assign(n.chainsSeq,n.allData[h].chainsSeq),n.defNames2Atoms=Object.assign(n.defNames2Atoms,n.allData[h].defNames2Atoms),n.defNames2Residues=Object.assign(n.defNames2Residues,n.allData[h].defNames2Residues),n.dAtoms=i.hashUtilsCls.cloneHash(n.atoms),n.hAtoms=i.hashUtilsCls.cloneHash(n.atoms),n.molTitle=n.allData[h].title,void 0!==e[h][3]&&e[h][3].length>0&&null==n.allData[h].commands){let p=e[h][3];n.allData[h].commands=p}if(void 0!==n.allData[h].commands)for(const u of n.allData[h].commands)i.htmlCls.clickMenuCls.setLogCmd(u,!0),await n.applyCommandCls.applyCommand(u)}n.opts.color=1==Object.keys(n.structures).length?"chain":"structure",n.setColorCls.setColorByOptions(n.opts,n.atoms),n.transformCls.zoominSelection(),n.definedSetsCls.showSets(),n.bResetAnno=!0,n.bAnnoShown&&(await n.showAnnoCls.showAnnotations(),n.hlUpdateCls.updateHlAll(r),n.annotationCls.showAnnoSelectedChains()),await n.drawCls.draw(),n.saveFileCls.showTitle(),i.htmlCls.clickMenuCls.setLogCmd("select structure ["+a+"]",!1),i.htmlCls.clickMenuCls.setLogCmd("load mmdbaf1 "+r,!0)}})),i.myEventCls.onIds("#"+t.pre+"collections_menu","focus",(function(e){let t=s.icn3d;i.utilsCls.isMobile()&&$("#"+t.pre+"collections_menu").val("")}))}}class Zh{constructor(e){this.icn3d=e}async loadScript(e,t,i){let s=this.icn3d;if(s.icn3dui,!e)return;s.bCommandLoad=!0,s.bRender=!1,s.bStopRotate=!0,e=t?e.replace(/\+/g," "):e.replace(/\+/g," ").replace(/;/g,"\n");let n=[];!i&&s.commands.length>0&&(n[0]=s.commands[0]);let r=e.trim().split("\n");s.commands=r;let a=r[0].indexOf("command=");if(t&&-1!=a){let e=r[0].substr(0,a-1);s.commands.splice(0,1,e)}s.STATENUMBER=s.commands.length,s.commands=n.concat(s.commands),s.STATENUMBER=s.commands.length,s.CURRENTNUMBER=0,s.bReplay?await this.replayFirstStep(s.CURRENTNUMBER):await this.execCommands(s.CURRENTNUMBER,s.STATENUMBER-1,s.STATENUMBER,i)}async execCommands(e,t,i,s){let n=this.icn3d;n.icn3dui,n.bRender=!1,s||n.reinitAfterLoad(),await this.execCommandsBase(e,t,i)}getNameArray(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | "),s=[];return 2==i.length&&(s=i[1].split(","),t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(s)),s}updateTransformation(e){let t=this.icn3d;t.icn3dui;let i=t.commands[e-1]?t.commands[e-1].split("|||"):[];t.transformCls.resetOrientation_base(i),t.drawCls.draw()}async execCommandsBase(e,t,i,s){let n,r=this.icn3d,a=r.icn3dui,o=this;for(n=e;n<=t;++n){let s=n===i-1;if(!r.commands[n]||!r.commands[n].trim())continue;if(0==(r.atoms?Object.keys(r.atoms).length:0)&&-1==r.commands[n].indexOf("load"))continue;let l=r.commands[n].split("|||"),d=l[0].trim();if(-1!==d.indexOf("load")){if(0===t&&e===t)return void(r.bNotLoadStructure?(r.hAtoms=a.hashUtilsCls.cloneHash(r.atoms),1===r.commands.length&&(r.bAddCommands=!0),s&&this.renderFinalStep(i)):(await o.applyCommandLoad(r.commands[n]),1===r.commands.length&&(r.bAddCommands=!0),s&&o.renderFinalStep(i)));r.bNotLoadStructure?(r.hAtoms=a.hashUtilsCls.cloneHash(r.atoms),r.backForward&&this.renderFinalStep(1)):(await o.applyCommandLoad(r.commands[n]),r.backForward&&o.renderFinalStep(1))}else if(0==d.indexOf("set map")&&-1==d.indexOf("set map wireframe"))await o.applyCommandMap(l[0].trim());else if(0==d.indexOf("set emmap")&&-1==d.indexOf("set emmap wireframe")){let e=l[0].trim().substr(10).split(" ");2==e.length&&"percentage"==e[0]&&(e[1],await o.applyCommandEmmap(l[0].trim()))}else if(0==d.indexOf("set phi"))await r.delphiCls.applyCommandPhi(l[0].trim());else if(0==d.indexOf("set delphi"))await r.delphiCls.applyCommandDelphi(l[0].trim());else if(0==d.indexOf("view annotations"))Object.keys(r.proteins).length>0&&await o.applyCommandAnnotationsAndCddSite(l[0].trim());else if(0==d.indexOf("set annotation clinvar"))Object.keys(r.proteins).length>0&&await o.applyCommandClinvar(l[0].trim());else if(0==d.indexOf("set annotation snp"))Object.keys(r.proteins).length>0&&await o.applyCommandSnp(l[0].trim());else if(0==d.indexOf("set annotation ptm"))Object.keys(r.proteins).length>0&&await o.applyCommandPTM(l[0].trim());else if(0==d.indexOf("ig template")){let e=d.substr(d.lastIndexOf(" ")+1);await a.htmlCls.clickMenuCls.setIgTemplate(e)}else if(0==d.indexOf("set annotation 3ddomain"))Object.keys(r.proteins).length>0&&o.applyCommand3ddomain(l[0].trim());else if(0==d.indexOf("set annotation all"))Object.keys(r.proteins).length>0&&(await o.applyCommandClinvar(l[0].trim()),await o.applyCommandSnp(l[0].trim()),o.applyCommand3ddomain(l[0].trim())),await r.annotationCls.setAnnoTabAll();else if(0==d.indexOf("view interactions")&&void 0!==a.cfg.align)await o.applyCommandViewinteraction(l[0].trim());else if(0==d.indexOf("view 2d depiction"))await r.ligplotCls.drawLigplot(r.atoms,!0);else if(0==d.indexOf("symmetry")){r.bAxisOnly=!1;let e=d.substr(d.indexOf(" ")+1);r.symmetrytitle="none"===e?void 0:e,"none"!==e&&await r.symdCls.retrieveSymmetry(Object.keys(r.structures)[0]),r.drawCls.draw()}else if(0==d.indexOf("symd symmetry"))r.bAxisOnly=!1,await r.symdCls.applyCommandSymd(d),r.drawCls.draw();else if(0==d.indexOf("scap"))await r.scapCls.applyCommandScap(d);else if(0==d.indexOf("realign on seq align"))this.getNameArray(d),await o.applyCommandRealign(d);else if(0==d.indexOf("realign on structure align msa")){let e=this.getNameArray(d);a.cfg.aligntool="vast",await r.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on structure align"))this.getNameArray(d),a.cfg.aligntool="vast",await r.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on tmalign msa")){let e=this.getNameArray(d);a.cfg.aligntool="tmalign",await r.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on tmalign"))this.getNameArray(d),a.cfg.aligntool="tmalign",await r.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on vastplus"))o.getHAtoms(r.commands[n]),await r.vastplusCls.realignOnVastplus();else if(0==d.indexOf("graph interaction pairs"))await o.applyCommandGraphinteraction(d);else if(0==d.indexOf("cartoon 2d domain"))r.bRender=!0,o.updateTransformation(i),await o.applyCommandCartoon2d(d),r.bRender=!1;else if(0==d.indexOf("set half pae map"))await o.applyCommandAfmap(d);else if(0==d.indexOf("set full pae map"))await o.applyCommandAfmap(d,!0);else if(0==d.indexOf("export pqr"))await a.htmlCls.setHtmlCls.exportPqr();else if(0==d.indexOf("cartoon 2d chain")||0==d.indexOf("cartoon 2d secondary")){let e=d.lastIndexOf(" "),t=d.substr(e+1);r.bRender=!0,o.updateTransformation(i),await r.cartoon2dCls.draw2Dcartoon(t),r.bRender=!1}else if(0==d.indexOf("add msa track")){let e=d.split(" | "),t=e[1].substr(8),i=e[2].substr(9),s=e[3].substr(5),n=e[4].substr(10);$("#"+r.pre+"anno_custom")[0]&&($("#"+r.pre+"anno_custom")[0].checked=!0),$("[id^="+r.pre+"custom]").show(),await r.addTrackCls.addMsaTracks(t,i,s,n)}else if(0==d.indexOf("add exon track")){let e=d.split(" | "),t=e[1].substr(8),i=e[2].substr(7),s=parseInt(e[3].substr(9)),n=e[4].substr(5);$("#"+r.pre+"anno_custom")[0]&&($("#"+r.pre+"anno_custom")[0].checked=!0),$("[id^="+r.pre+"custom]").show(),await r.addTrackCls.addExonTracks(t,i,s,n)}else await r.applyCommandCls.applyCommand(r.commands[n])}(n===i||s)&&this.renderFinalStep(n)}pressCommandtext(){let e=this.icn3d,t=e.icn3dui,i=this;$("#"+e.pre+"logtext").keypress((async function(e){let s=i.icn3d;if(s.bAddLogs=!1,13==(e.keyCode?e.keyCode:e.which)){e.preventDefault();let n=$(this).val();s.bRender=!0;let r=n.split("\n"),a=s.logs.length;for(let e=a,n=r.length;e<n;++e){let n=e==a?r[e].substr(2).trim():r[e].trim();if(""===n)continue;s.logs.push(n);let o={};if(o.factor=s._zoomFactor,o.mouseChange=s.mouseChange,o.quaternion=s.quaternion,s.commands.push(n+"|||"+s.transformCls.getTransformationStr(o)),s.optsHistory.push(t.hashUtilsCls.cloneHash(s.opts)),s.optsHistory[s.optsHistory.length-1].hlatomcount=Object.keys(s.hAtoms).length,t.utilsCls.isSessionStorageSupported()&&s.setStyleCls.saveCommandsToSession(),s.STATENUMBER=s.commands.length,-1!==n.indexOf("load"))await i.applyCommandLoad(n);else if(-1!==n.indexOf("set map")&&-1===n.indexOf("set map wireframe"))await i.applyCommandMap(n);else if(-1!==n.indexOf("set emmap")&&-1===n.indexOf("set emmap wireframe"))await i.applyCommandEmmap(n);else if(-1!==n.indexOf("set phi"))await s.delphiCls.applyCommandPhi(n);else if(-1!==n.indexOf("set delphi"))await s.delphiCls.applyCommandDelphi(n);else if(0==n.indexOf("view annotations"))await i.applyCommandAnnotationsAndCddSite(n);else if(0==n.indexOf("set annotation clinvar"))await i.applyCommandClinvar(n);else if(0==n.indexOf("set annotation snp"))await i.applyCommandSnp(n);else if(0==n.indexOf("set annotation ptm"))await i.applyCommandPTM(n);else if(0==n.indexOf("ig refnum on"))s.bRunRefnumAgain=!0,s.bAnnoShown||await s.showAnnoCls.showAnnotations(),await s.annotationCls.setAnnoTabIg(!0),s.bRunRefnumAgain=!1;else if(0==n.indexOf("set annotation 3ddomain"))i.applyCommand3ddomain(n);else if(0==n.indexOf("set annotation all"))await i.applyCommandClinvar(n),await i.applyCommandSnp(n),i.applyCommand3ddomain(n),await s.annotationCls.setAnnoTabAll();else if(0==n.indexOf("view interactions")&&void 0!==t.cfg.align)await i.applyCommandViewinteraction(n);else if(0==n.indexOf("view 2d depiction"))await s.ligplotCls.drawLigplot(s.atoms,!0);else if(0==n.indexOf("symmetry")){let e=n.substr(n.indexOf(" ")+1);s.symmetrytitle="none"===e?void 0:e,"none"!==e&&void 0===s.symmetryHash&&await s.symdCls.retrieveSymmetry(Object.keys(s.structures)[0])}else if(0==n.indexOf("symd symmetry"))await s.symdCls.applyCommandSymd(n);else if(0==n.indexOf("scap "))await s.scapCls.applyCommandScap(n);else if(0==n.indexOf("realign on seq align")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}await i.applyCommandRealign(n)}else if(0==n.indexOf("realign on structure align")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="vast",await i.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on tmalign")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="tmalign",await i.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on vastplus")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}await s.vastplusCls.realignOnVastplus()}else 0==n.indexOf("graph interaction pairs")?await i.applyCommandGraphinteraction(n):await s.applyCommandCls.applyCommand(n+"|||"+s.transformCls.getTransformationStr(o))}s.selectionCls.saveSelectionIfSelected(),s.drawCls.draw(),$("#"+s.pre+"logtext").val("> "+s.logs.join("\n> ")+"\n> ").scrollTop($("#"+s.pre+"logtext")[0].scrollHeight)}s.bAddLogs=!0}))}async applyCommandLoad(e){let t=this.icn3d,i=t.icn3dui;t.bAddCommands=!1;let s=e.split("|||")[0].replace(/\s\s/g," ").trim();if(-1!==s.indexOf("load")){let e=s.split(" | "),n=e[0];if(e.length>1&&!i.cfg.inpara){let t=e[e.length-1].indexOf(" ");i.cfg.inpara=e[e.length-1].substr(t+1),"undefined"===i.cfg.inpara&&(i.cfg.inpara="")}let r=n.substr(n.lastIndexOf(" ")+1);4==r.length&&(r=r.toUpperCase());let a=r.split(","),o="";for(let e=0,i=a.length;e<i;++e)t.structures&&(t.structures.hasOwnProperty(a[e])||t.structures.hasOwnProperty(a[e].toLowerCase())||t.structures.hasOwnProperty(a[e].toUpperCase()))||(o&&(o+=","),o+=a[e]);if(r=o,t.bInputPNGWithData||!r)return;if(t.inputid=r,-1!==s.indexOf("load mmtf"))i.cfg.mmtfid=r,await t.bcifParserCls.downloadBcif(r);else if(-1!==s.indexOf("load bcif"))i.cfg.bcifid=r,await t.bcifParserCls.downloadBcif(r);else if(-1!==s.indexOf("load pdb"))i.cfg.pdbid=r,await t.pdbParserCls.downloadPdb(r);else if(-1!==s.indexOf("load af"))i.cfg.afid=r,await t.pdbParserCls.downloadPdb(r,!0);else if(-1!==s.indexOf("load opm"))i.cfg.opmid=r,await t.opmParserCls.downloadOpm(r);else if(-1!==s.indexOf("load mmcif"))i.cfg.mmcifid=r,await t.mmcifParserCls.downloadMmcif(r);else if(-1!==s.indexOf("load mmdb ")||-1!==s.indexOf("load mmdb1 "))i.cfg.mmdbid=r,i.cfg.bu=1,await t.mmdbParserCls.downloadMmdb(r);else if(-1!==s.indexOf("load mmdb0"))i.cfg.mmdbid=r,i.cfg.bu=0,await t.mmdbParserCls.downloadMmdb(r);else if(-1!==s.indexOf("load mmdbaf1"))i.cfg.mmdbafid=r,i.cfg.bu=1,await t.chainalignParserCls.downloadMmdbAf(r);else if(-1!==s.indexOf("load mmdbaf0"))i.cfg.mmdbafid=r,i.cfg.bu=0,await t.chainalignParserCls.downloadMmdbAf(r);else if(-1!==s.indexOf("load gi"))i.cfg.gi=r,await t.mmdbParserCls.downloadGi(r);else if(-1!==s.indexOf("load refseq"))i.cfg.refseqid=r,await t.mmdbParserCls.downloadRefseq(r);else if(-1!==s.indexOf("load protein"))i.cfg.protein=r,await t.mmdbParserCls.downloadProteinname(r);else if(-1!==s.indexOf("load seq_struct_ids "))t.bSmithwm=!1,t.bLocalSmithwm=!1,await t.mmdbParserCls.downloadBlast_rep_id(r);else if(-1!==s.indexOf("load seq_struct_ids_smithwm "))t.bSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(r);else if(-1!==s.indexOf("load seq_struct_ids_local_smithwm "))t.bLocalSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(r);else if(-1!==s.indexOf("load cid"))i.cfg.cid=r,await t.sdfParserCls.downloadCid(r);else if(-1!==s.indexOf("load smiles"))i.cfg.smiles=r,await t.sdfParserCls.downloadSmiles(r);else if(-1!==s.indexOf("load alignment"))if(i.cfg.align=r,i.cfg.inpara||-1==i.cfg.inpara.indexOf("atype=2"))await t.alignParserCls.downloadAlignment(i.cfg.align);else{let e=2;await t.chainalignParserCls.downloadMmdbAf(i.cfg.align,void 0,e)}else if(-1!==s.indexOf("load chainalignment")){let e=s.split(" | ");e.length>1&&-1!=e[1].indexOf("resnum")&&(i.cfg.resnum=e[1].substr(e[1].indexOf("resnum")+7)),e.length>2&&-1!=e[2].indexOf("resdef")&&(i.cfg.resdef=e[2].substr(e[2].indexOf("resdef")+7)),e.length>3&&-1!=e[3].indexOf("aligntool")&&(i.cfg.aligntool=e[3].substr(e[3].indexOf("aligntool")+10)),e.length>5&&-1!=e[5].indexOf("resrange")&&(i.cfg.resrange=e[5].substr(e[5].indexOf("resrange")+9)),i.cfg.chainalign=r,await t.chainalignParserCls.downloadChainalignment(r)}else if(-1!==s.indexOf("load url")){let s=e[1],n=void 0!==s?s.indexOf("type "):-1,a="pdb";-1!==n&&(a=s.substr(n+5)),i.cfg.url=r,await t.pdbParserCls.downloadUrl(r,a)}}t.bAddCommands=!0}async applyCommandMap(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | "),s=i[0].substr(8).split(" ");if("sigma"==s[1]){let e=s[2],n=s[0],r="dsn6";if(5==s.length&&(r=s[4]),2==i.length){let s=!0;"dsn6"==r?await t.densityCifParserCls.densityCifParserBase(i[1],n,e,"url",s):"ccp4"==r?await t.ccp4ParserCls.ccp4ParserBase(i[1],n,e,"url",s):"mtz"==r?await t.mtzParserCls.mtzParserBase(i[1],n,e,"url",s):"rcsbmtz"==r&&await t.mtzParserCls.mtzParserBase(i[1],n,e,"url",s,!0)}else await t.densityCifParserCls.densityCifParser(t.inputid,n,e)}}async applyCommandEmmap(e){let t=this.icn3d;t.icn3dui;let i=e.substr(10).split(" ");if(2==i.length&&"percentage"==i[0]){let e=i[1],s="em";await t.densityCifParserCls.densityCifParser(t.inputid,s,e,t.emd)}}async applyCommandRealign(e){let t=this.icn3d;t.icn3dui,await t.realignParserCls.realignOnSeqAlign()}async applyCommandRealignByStruct(e){let t=this.icn3d;t.icn3dui,t.drawCls.draw(),await t.realignParserCls.realignOnStructAlign()}async applyCommandAfmap(e,t){let i=this.icn3d;i.icn3dui;let s=e.substr(e.lastIndexOf(" ")+1);await i.contactMapCls.afErrorMap(s,t)}async applyCommandGraphinteraction(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | ");if(i.length>=3){let e,s=i[1].split(" "),n=s[0].split(","),r=s[1].split(","),a=-1!==i[2].indexOf("hbonds"),o=-1!==i[2].indexOf("salt bridge"),l=-1!==i[2].indexOf("interactions"),d=-1!==i[2].indexOf("halogen"),c=-1!==i[2].indexOf("pi-cation"),h=-1!==i[2].indexOf("pi-stacking");i.length>=4&&(e="true"==i[3]),t.applyCommandCls.setStrengthPara(i),await t.viewInterPairsCls.viewInteractionPairs(n,r,e,"graph",a,o,l,d,c,h)}}async applyCommandCartoon2d(e){let t=this.icn3d;t.icn3dui;let i=e.substr(e.lastIndexOf(" ")+1);await t.cartoon2dCls.draw2Dcartoon(i)}async applyCommandAnnotationsAndCddSite(e){let t=this.icn3d;t.icn3dui,"view annotations"==e&&await t.showAnnoCls.showAnnotations()}async applyCommandClinvar(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" ");e.substr(i+1),await t.annotationCls.setAnnoTabClinvar()}async applyCommandSnp(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" ");e.substr(i+1),await t.annotationCls.setAnnoTabSnp()}async applyCommandPTM(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" ");e.substr(i+1),await t.annotationCls.setAnnoTabPTM()}applyCommand3ddomain(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" "),s=e.substr(i+1);"3ddomain"!=s&&"all"!=s||t.annotationCls.setAnnoTab3ddomain()}async applyCommandViewinteraction(e){let t=this.icn3d,i=t.icn3dui;if(void 0!==i.cfg.align||void 0!==i.cfg.chainalign){let e=Object.keys(t.structures);await t.ParserUtilsCls.set2DDiagramsForAlign(e[0].toUpperCase(),e[1].toUpperCase())}}async renderFinalStep(e){let t=this.icn3d,i=t.icn3dui;t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),e+1===t.commands.length&&(t.bAddCommands=!0),t.bRender=!0;let s=t.commands[e-1]?t.commands[e-1].split("|||"):[];if(2!=s.length||2==s.length&&"{"==s[1].substr(0,1)?t.bSetCamera=!0:t.bSetCamera=!1,2==s.length&&"{"==s[1].substr(0,1)&&(t.bTransformation=!0),t.transformCls.resetOrientation_base(s),t.selectionCls.oneStructurePerWindow(),1===e||t.hAtoms&&t.atoms&&Object.keys(t.hAtoms).length===Object.keys(t.atoms).length||void 0!==t.optsHistory[e-1]&&t.optsHistory[e-1].hasOwnProperty("hlatomcount")&&t.optsHistory[e-1].hlatomcount===Object.keys(t.atoms).length)if(t.optsHistory.length>=e){let i=t.optsHistory[e-1].pk;"no"===i?t.pk=0:"atom"===i?t.pk=1:"residue"===i?t.pk=2:"strand"===i&&(t.pk=3),t.hlUpdateCls.updateHlAll(),t.drawCls.draw()}else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();(i.cfg.closepopup||i.cfg.imageonly)&&(setTimeout((function(){t.resizeCanvasCls.closeDialogs()}),100),t.resizeCanvasCls.resizeCanvas(i.htmlCls.WIDTH,i.htmlCls.HEIGHT,!0)),i.cfg.showlogo||$("#ncbi_logo").hide(),t.bTransparentSurface&&t.bRender&&t.drawCls.render(),i.cfg.imageonly&&t.saveFileCls.saveFile(void 0,"png",void 0,!0)}async replayFirstStep(e){let t=this.icn3d,i=t.icn3dui;t.reinitAfterLoad(),await this.execCommandsBase(e,e,t.STATENUMBER);let s=t.commands[e],n=t.commands[e].indexOf("|");-1!=n&&(s=t.commands[e].substr(0,n));let r=s.length>20?s.substr(0,20)+"...":s,a=t.applyCommandCls.getMenuFromCmd(s);$("#"+t.pre+"replay_cmd").html("Cmd: "+r),$("#"+t.pre+"replay_menu").html("Menu: "+a),i.htmlCls.clickMenuCls.setLogCmd(s,!0),t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),t.bRender=!0,t.drawCls.draw()}getHAtoms(e){let t=this.icn3d;t.icn3dui;let i=e.split("|||")[0].trim().split(" | ");if(2==i.length){let e=i[1].split(",");t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(e)}}}class Jh{constructor(e){this.icn3d=e}async selectByCommand(e,t,i){let s=this.icn3d,n=s.icn3dui;if(0===e.indexOf("saved atoms")){let i=12,n=e.substr(i);s.definedSetsCls.selectCombinedSets(n,t)}else{let r=e.replace(/ AND /g," and ").replace(/ OR /g," or ").replace(/ or and /g," and ").replace(/ and /g," or and ").replace(/ or not /g," not ").replace(/ not /g," or not "),a=("select"===r.trim().substr(0,6)?r.trim().substr(7):r.trim()).split(" or "),o={};for(let e=0,t=a.length;e<t;++e){let t=a[e].trim().replace(/\s+/g," "),i=t.indexOf(" ");s.hAtoms={},"and"===t.substr(0,i).toLowerCase()?(await s.applyCommandCls.applyCommand("select "+t.substr(i+1)),o=n.hashUtilsCls.intHash(o,s.hAtoms)):"not"===t.substr(0,i).toLowerCase()?(await s.applyCommandCls.applyCommand("select "+t.substr(i+1)),o=n.hashUtilsCls.exclHash(o,s.hAtoms)):(await s.applyCommandCls.applyCommand("select "+t),o=n.hashUtilsCls.unionHash(o,s.hAtoms))}s.hAtoms=n.hashUtilsCls.cloneHash(o);let l=Object.keys(s.hAtoms);if(""!==t){s.selectionCls.addCustomSelection(l,t,i,e,!1);let n=[t];s.definedSetsCls.changeCustomAtoms(n)}}}selectBySpec(e,t,i,s,n){let r=this.icn3d,a=r.icn3dui;e="select"===e.trim().substr(0,6)?e.trim().substr(7):e.trim(),r.hAtoms={};let o,l=e.replace(/\s+/g," ").replace(/ AND /g," and ").split(" and "),d={},c={},h=!0;for(let e=0,t=l.length;e<t;++e){let t,i,s,n,o,p=l[e].indexOf("$"),u=l[e].indexOf("."),m=l[e].indexOf(":"),f=l[e].indexOf(":ref_"),g=l[e].indexOf("@"),b=l[e];if(-1===g?o=["*"]:(o=b.substr(g+1).split(","),b=b.substr(0,g)),-1===m&&-1===f)s="*";else if(-1!=f){if(n=b.substr(f+5),b=b.substr(0,f),!n)continue}else if(-1!=m&&(s=b.substr(m+1),b=b.substr(0,m),!s))continue;-1===u?i="*":(i=b.substr(u+1),i=i.replace(/_/g,""),b=b.substr(0,u)),-1===p?t="*":(t=b.substr(p+1),b=b.substr(0,p)),(o.length>1||1==o.length&&"*"!==o[0])&&(h=!1);let C,v,_,y,S=[],w=[];if(S="*"===t?Object.keys(r.structures):t.split(","),"*"===i){let e=Object.keys(r.chains);for(let t=0,i=e.length;t<i;++t){v=e[t],C=v.substr(0,v.indexOf("_")),-1!==S.map((function(e){return e.toLowerCase()})).indexOf(C.toLowerCase())&&w.push(v)}}else for(let e=0,t=S.length;e<t;++e){C=S[e];let t=i.split(",");for(let e in t)w.push(C+"_"+t[e])}let x=!!n,A=x?n.split(","):s.split(",");for(let t=0,i=A.length;t<i;++t){let i,s,n=!1,l=A[t].lastIndexOf("-"),h=!1,p=!1,u=!1;if(-1!==l)_=A[t].substr(0,l),y=A[t].substr(l+1),n=!0;else if(!x&&A[t].length>1&&"3"===A[t][0]&&isNaN(A[t][1])&&"-"!==A[t][0]){s=A[t].toUpperCase().substr(1),u=!0}else if(""===A[t]||isNaN(parseInt(A[t]))){if("*"===A[t])h=!0;else if("proteins"!==A[t]&&"nucleotides"!==A[t]&&"chemicals"!==A[t]&&"ions"!==A[t]&&"water"!==A[t]&&"anchors"!==A[t]&&"strands"!==A[t]&&"loops"!==A[t]){i=A[t].toUpperCase(),p=!0}}else _=A[t],y=_,n=!0;for(let l=0,m=w.length;l<m;++l)if(v=w[l],n){_=isNaN(_)?_:parseInt(_),y=isNaN(y)?y:parseInt(y);for(let t=_;t<=y;++t){let i=[];if(x){let e=r.refnum2residArray[t.toString()]?r.refnum2residArray[t.toString()]:[];for(let t=0,s=e.length;t<s;++t){let s=e[t];s.substr(0,s.lastIndexOf("_"))==v&&i.push(s)}}else{i=[v+"_"+t]}for(let t=0,s=i.length;t<s;++t){let s=i[t];0===e?d[s]=1:d.hasOwnProperty(s)||delete d[s];for(let t in r.residues[s])for(let i=0,s=o.length;i<s;++i){let s=o[i];c=this.processAtomStr(s,c,e,t)}}}}else if(v in r.chains){let n=r.chains[v];for(let i in n){r.atoms[i].resn.substr(0,3).toUpperCase();let s,n,a,l=v+"_"+r.atoms[i].resi;if(x&&(s=r.resid2refnum[l],s&&(n=r.refnumCls.rmStrandFromRefnumlabel(s),a=parseInt(n))),h||"proteins"===A[t]&&i in r.proteins||"nucleotides"===A[t]&&i in r.nucleotides||"chemicals"===A[t]&&i in r.chemicals||"ions"===A[t]&&i in r.ions||"water"===A[t]&&i in r.water||x&&s&&"anchors"===A[t]&&a%100==50||x&&s&&"strands"===A[t]&&!r.residIgLoop.hasOwnProperty(l)||x&&s&&"loops"===A[t]&&r.residIgLoop.hasOwnProperty(l)){0===e?d[l]=1:d.hasOwnProperty(l)||delete d[l];for(let t=0,s=o.length;t<s;++t){let s=o[t];c=this.processAtomStr(s,c,e,i)}}}if(p||u){let t=p?1:3,n=p?i:s,l="",h=[];for(let e=0,t=r.chainsSeq[v].length;e<t;++e){if(p)l+=1==r.chainsSeq[v][e].name.length?r.chainsSeq[v][e].name:" ";else if(u){let t=a.utilsCls.residueAbbr2Name(r.chainsSeq[v][e].name);l+=3==t.length?t:t.padEnd(3,"_")}h.push(r.chainsSeq[v][e].resi)}l=l.toUpperCase();let m=n.replace(/x/gi,"."),f=[],g=new RegExp(m,"i"),b=l,C=b.search(g),_=C/t;for(;-1!==C;)f.push(_),b=b.substr(C+t),C=b.search(g),_+=C/t+1;for(let i=0,s=f.length;i<s;++i){let s=f[i];for(let i=0,a=n.length/t;i<a;i+=t){let n=v+"_"+h[i/t+s];0===e?d[n]=1:d.hasOwnProperty(n)||delete d[n];for(let t in r.residues[n])for(let i=0,s=o.length;i<s;++i){let s=o[i];c=this.processAtomStr(s,c,e,t)}}}}}}}if(r.hAtoms=a.hashUtilsCls.cloneHash(c),0==Object.keys(r.hAtoms).length&&console.log("No residues were selected. Please try another search."),(void 0===s||s)&&r.hlUpdateCls.updateHlAll(),o=h?Object.keys(d):Object.keys(c),""!=t){r.selectionCls.addCustomSelection(o,t,i,e,h);let s=[t];n||r.definedSetsCls.changeCustomAtoms(s)}}processAtomStr(e,t,i,s){let n=this.icn3d;n.icn3dui;let r=e.length;return"*"==e.substr(r-1,1)&&r>1?e.substr(0,r-1)===n.atoms[s].name.substr(0,r-1)&&(0===i?t[s]=1:t.hasOwnProperty(s)||delete t[s]):"*"!==e&&e!==n.atoms[s].name||(0===i?t[s]=1:t.hasOwnProperty(s)||delete t[s]),t}}class Qh{constructor(e){this.icn3d=e}selectAll(){let e=this.icn3d;e.icn3dui,this.selectAll_base(),e.hlObjectsCls.removeHlObjects(),e.hlUpdateCls.removeHl2D(),e.hlUpdateCls.removeHlMenus(),e.bSelectResidue=!1,e.bSelectAlignResidue=!1,e.hlUpdateCls.removeSeqResidueBkgd(),e.hlUpdateCls.update2DdgmContent(),$("#"+e.pre+"dl_annotations > .icn3d-annotation").show(),e.definedSetsCls.setMode("all"),e.saveFileCls.showTitle()}selectAll_base(){let e=this.icn3d,t=e.icn3dui;e.hAtoms={},e.dAtoms={};for(let i in e.structures){let s=e.structures[i];for(let i=0,n=s.length;i<n;++i)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s[i]])}e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.viewSelectionAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.ALTERNATE_STRUCTURE=-1}selectAChain(e,t,i,s){let n=this.icn3d,r=n.icn3dui;t=t.replace(/\s/g,"");let a=void 0!==i||i?"select alignChain "+e:"select chain "+e;void 0!==s&&s?(n.hAtoms=r.hashUtilsCls.unionHash(n.hAtoms,n.chains[e]),void 0===n.nameArray&&(n.nameArray=[])):(n.hAtoms={},n.nameArray=[]),n.nameArray.push(e);let o,l=i?n.alnChainsSeq[e]:n.chainsSeq[e];o=void 0===l?0:l.length;let d={};for(let t=0,i=o;t<i;++t){let i=l[t],s=e+"_"+i.resi,r=i.name;if(""!==r&&"-"!==r){d[s]=1;for(let e in n.residues[s])n.hAtoms[e]=1}}void 0!==n.defNames2Atoms&&n.defNames2Atoms.hasOwnProperty(t)||void 0!==n.defNames2Residues&&n.defNames2Residues.hasOwnProperty(t)||this.addCustomSelection(Object.keys(d),t,t,a,!0);let c=!0;i?n.hlUpdateCls.updateHlAll(void 0,void 0,s,c):n.hlUpdateCls.updateHlAll(n.nameArray,void 0,s,c)}selectResidueList(e,t,i,s,n,r){let a=this.icn3d;if(a.icn3dui,void 0!==e&&Object.keys(e).length>0){if(void 0!==s&&s?void 0===a.nameArray&&(a.nameArray=[]):(a.hAtoms={},a.nameArray=[]),r)for(let t in e)a.hAtoms[t]=1;else for(let t in e)for(let e in a.residues[t])a.hAtoms[e]=1;let o,l;t=t.replace(/\s/g,""),a.nameArray.push(t),r?(o="select "+a.resid2specCls.atoms2spec(a.hAtoms),l=!1):(o="select "+a.resid2specCls.residueids2spec(Object.keys(e)),l=!0);let d=Object.keys(e);this.addCustomSelection(d,t,i,o,l),(void 0===n||n)&&a.hlUpdateCls.updateHlAll(a.nameArray,void 0,s)}}selectMainChains(){let e=this.icn3d,t=e.icn3dui.hashUtilsCls.cloneHash(e.hAtoms);e.hAtoms=e.applyDisplayCls.selectMainChainSubset(t),e.hlUpdateCls.showHighlight()}selectSideChains(){let e=this.icn3d,t=e.icn3dui.hashUtilsCls.cloneHash(e.hAtoms);e.hAtoms=this.getSideAtoms(t),e.hlUpdateCls.showHighlight()}getSideAtoms(e){let t=this.icn3d,i=t.icn3dui,s={};for(let n in e)(t.proteins.hasOwnProperty(n)&&"N"!==t.atoms[n].name&&"H"!==t.atoms[n].name&&"C"!==t.atoms[n].name&&"O"!==t.atoms[n].name&&("CA"!==t.atoms[n].name||"C"!==t.atoms[n].elem)&&"HA"!==t.atoms[n].name||t.nucleotides.hasOwnProperty(n)&&-1===i.parasCls.nuclMainArray.indexOf(t.atoms[n].name))&&(s[n]=1);return s}selectMainSideChains(){let e=this.icn3d,t=e.icn3dui,i=e.firstAtomObjCls.getResiduesFromAtoms(e.hAtoms);e.hAtoms={};for(let s in i)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[s]),e.dAtoms=t.hashUtilsCls.unionHash(e.dAtoms,e.residues[s]);e.drawCls.draw(),e.hlUpdateCls.showHighlight()}clickShow_selected(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds(["#"+e.pre+"show_selected","#"+e.pre+"mn2_show_selected"],"click",(function(e){i.icn3d,i.showSelection(),t.htmlCls.clickMenuCls.setLogCmd("show selection",!0)}))}clickHide_selected(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+e.pre+"mn2_hide_selected","click",(function(e){i.icn3d,i.hideSelection(),t.htmlCls.clickMenuCls.setLogCmd("hide selection",!0)}))}getGraphDataForDisplayed(){let e=this.icn3d;e.icn3dui;let t=JSON.parse(e.graphStr),i=e.firstAtomObjCls.getResiduesFromAtoms(e.dAtoms),s=[],n=[],r={};for(let e=0,n=t.nodes.length;e<n;++e){let n=t.nodes[e],a=n.r.substr(4);i.hasOwnProperty(a)&&(s.push(n),r[n.id]=1)}for(let e=0,i=t.links.length;e<i;++e){let i=t.links[e];r.hasOwnProperty(i.source)&&r.hasOwnProperty(i.target)&&n.push(i)}return t.nodes=s,t.links=n,e.graphStr=JSON.stringify(t),e.graphStr}updateSelectionNameDesc(){let e=this.icn3d;e.icn3dui;let t=Object.keys(e.defNames2Residues).length+Object.keys(e.defNames2Atoms).length;$("#"+e.pre+"seq_command_name").val("seq_"+t),$("#"+e.pre+"seq_command_name2").val("seq_"+t),$("#"+e.pre+"alignseq_command_name").val("alseq_"+t)}addCustomSelection(e,t,i,s,n){let r=this.icn3d;r.icn3dui,n?r.defNames2Residues[t]=e:r.defNames2Atoms[t]=e,r.defNames2Command[t]=s,r.defNames2Descr[t]=i,r.hlUpdateCls.updateHlMenus([t])}showSelection(){let e=this.icn3d,t=e.icn3dui;0==Object.keys(e.hAtoms).length&&(e.hAtoms=t.hashUtilsCls.cloneHash(e.dAtoms)),e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.viewSelectionAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.ALTERNATE_STRUCTURE=-1;let i=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=i.maxD,e.maxD<5&&(e.maxD=5),e.opts.rotationcenter="display center",this.saveSelectionIfSelected(),e.drawCls.draw(),e.hlUpdateCls.update2DdgmContent(),e.hlUpdateCls.updateHl2D(),e.annotationCls.showAnnoSelectedChains(),void 0!==e.graphStr&&(e.graphStr=this.getGraphDataForDisplayed()),e.saveFileCls.showTitle()}hideSelection(){let e=this.icn3d,t=e.icn3dui;e.hAtoms=t.hashUtilsCls.exclHash(e.dAtoms,e.hAtoms),0==Object.keys(e.hAtoms).length&&(e.hAtoms=t.hashUtilsCls.cloneHash(e.dAtoms)),e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms);let i=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=i.maxD,e.maxD<5&&(e.maxD=5),e.opts.rotationcenter="display center",this.saveSelectionIfSelected(),e.drawCls.draw(),e.hlUpdateCls.update2DdgmContent(),e.hlUpdateCls.updateHl2D(),e.annotationCls.showAnnoSelectedChains()}saveSelection(e,t,i){let s=this.icn3d,n=s.icn3dui;if(i||(s.selectedResidues={},s.selectedResidues=s.firstAtomObjCls.getResiduesFromCalphaAtoms(s.hAtoms)),!e){t=e="seq_"+(Object.keys(s.defNames2Atoms).length+Object.keys(s.defNames2Residues).length+1)}if(Object.keys(s.selectedResidues).length>0)if(1==s.pk){let r=!0;this.selectResidueList(s.hAtoms,e,t,void 0,void 0,r),this.updateSelectionNameDesc(),i?n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.atoms2spec(s.hAtoms),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.atoms2spec(s.hAtoms)+" | name "+e,!0)}else this.selectResidueList(s.selectedResidues,e,t,void 0,void 0,void 0),this.updateSelectionNameDesc(),i?n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.residueids2spec(Object.keys(s.selectedResidues)),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.residueids2spec(Object.keys(s.selectedResidues))+" | name "+e,!0)}saveSelInCommand(){let e=this.icn3d,t=e.icn3dui;e.selectedResidues=e.firstAtomObjCls.getResiduesFromCalphaAtoms(e.hAtoms),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(e.selectedResidues)),!0)}saveEachResiInSel(){let e=this.icn3d;e.icn3dui,e.selectionCls.saveSelectionPrep(),e.selectedResidues={},e.selectedResidues=e.firstAtomObjCls.getResiduesFromCalphaAtoms(e.hAtoms);for(let t in e.selectedResidues){let i={};i[t]=1;let s=t+"_"+e.selectedResidues[t];this.selectResidueList(i,s,s)}}removeSelection(){let e=this.icn3d;e.icn3dui,e.bAnnotations||e.hlUpdateCls.removeSeqChainBkgd(),e.bCtrl||e.bShift||(e.hlUpdateCls.removeSeqResidueBkgd(),e.hlUpdateCls.removeSeqChainBkgd()),e.selectedResidues={},e.bSelectResidue=!1,e.hAtoms={},e.hlObjectsCls.removeHlObjects(),e.hlUpdateCls.removeHl2D()}resetAll(){let e=this.icn3d,t=e.icn3dui;e.maxD=e.oriMaxD,e.center=e.oriCenter.clone(),e.opts=t.hashUtilsCls.cloneHash(e.optsOri),e.setOptionCls.setStyle("sidec","nothing"),e.reinitAfterLoad(),e.definedSetsCls.setMode("all"),e.selectionCls.selectAll(),t.htmlCls.clickMenuCls.setLogCmd("reset",!0),e.hlUpdateCls.removeSeqChainBkgd(),e.hlUpdateCls.removeSeqResidueBkgd(),e.hlUpdateCls.removeHl2D(),e.hlUpdateCls.removeHlMenus(),e.loadScriptCls.renderFinalStep(1)}async loadSelection(e){let t=this.icn3d,i=t.icn3dui,s=e.trim().split("\n");for(let e=0,n=s.length;e<n;++e){let n=s[e].replace(/\t/g," "),r=n.indexOf(" "),a=n.substr(0,r),o=n.substr(r+1),l=o.indexOf(" ");await t.selByCommCls.selectByCommand(o.substr(l+1),a,a),i.htmlCls.clickMenuCls.setLogCmd("select "+o.substr(l+1)+" | name "+a,!0)}}oneStructurePerWindow(){let e=this.icn3d,t=e.icn3dui,i=e.structures?Object.keys(e.structures):[];if(t.cfg.bSidebyside&&2==i.length){let s=i[Object.keys(window.icn3duiHash).indexOf(e.divid)],n=e.structures[s],r={};if(n){for(let i=0,s=n.length;i<s;++i)r=t.hashUtilsCls.unionHash(r,e.chains[n[i]]);e.dAtoms=t.hashUtilsCls.intHash(r,e.dAtoms),e.hAtoms=t.hashUtilsCls.cloneHash(e.dAtoms)}}}showAll(){var e=this.icn3d,t=e.icn3dui;e.dAtoms=t.hashUtilsCls.cloneHash(e.atoms),e.maxD=e.oriMaxD,e.drawCls.draw()}saveSelectionIfSelected(e,t){var i=this.icn3d;if(i.icn3dui,i.bSelectResidue||i.bSelectAlignResidue){let e=$("#"+i.pre+"seq_command_name2").val().replace(/\s+/g,"_");""===e&&(e=$("#"+i.pre+"alignseq_command_name").val().replace(/\s+/g,"_")),""!==e&&this.saveSelection(e,e),i.bSelectResidue=!1,i.bSelectAlignResidue=!1}}saveSelectionPrep(e){var t=this.icn3d,i=t.icn3dui;i.cfg.notebook?($("#"+t.pre+"dl_definedsets").show(),$("#"+t.pre+"atomsCustom").resizable()):$("#"+t.pre+"dl_definedsets").hasClass("ui-dialog-content")&&$("#"+t.pre+"dl_definedsets").dialog("isOpen")||(i.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+t.pre+"atomsCustom").resizable()),e||(t.bSelectResidue=!1,t.bSelectAlignResidue=!1)}selectOneResid(e,t){var i=this.icn3d;i.icn3dui;let s=e.split(" "),n=(e=s[1]).indexOf("$"),r=e.indexOf("."),a=e.indexOf(":"),o=e.indexOf("@");-1==o&&(o=e.length);let l=e.substr(n+1,r-n-1),d=e.substr(r+1,a-r-1),c=e.substr(a+1,o-a-1),h=l+"_"+d+"_"+c;for(let e in i.residues[h])t?delete i.hAtoms[e]:i.hAtoms[e]=1;return t?delete i.selectedResidues[h]:i.selectedResidues[h]=1,"$"+l+"."+d+":"+c}toggleSelection(){var e=this.icn3d,t=e.icn3dui;if(e.bHideSelection){for(let t in e.dAtoms)e.hAtoms.hasOwnProperty(t)&&delete e.dAtoms[t];e.bHideSelection=!1}else e.dAtoms=t.hashUtilsCls.unionHash(e.dAtoms,e.hAtoms),e.bHideSelection=!0;e.drawCls.draw()}toggleMembrane(e){var t=this.icn3d,i=t.icn3dui;let s=t.structures?Object.keys(t.structures):[];for(let n=0,r=s.length;n<r;++n){let r=s[n],a=t.residues[r+"_MEM_1"],o=t.firstAtomObjCls.getFirstAtomObj(a);if(void 0===o)continue;let l=o.style;t.dAtoms.hasOwnProperty(o.serial)||(t.dAtoms=i.hashUtilsCls.unionHash(t.dAtoms,a),l="nothing");for(let i in a){let s=t.atoms[i];s.style="nothing"!==l?"nothing":"stick",void 0!==e&&(s.style=e?"stick":"nothing")}}void 0===e&&t.drawCls.draw()}adjustMembrane(e,t){var i=this.icn3d;i.icn3dui;for(let s in i.chains[i.inputid.toUpperCase()+"_MEM"]){let n=i.atoms[s];"O"==n.name?n.coord.z=e:"N"==n.name&&(n.coord.z=t)}i.definedSetsCls.setTransmemInMenu(e,t,!0),i.hlUpdateCls.updateHlMenus(),i.drawCls.draw()}selectBtwPlanes(e,t){var i=this.icn3d;if(i.icn3dui,e<t){let i=t;t=e,e=i}let s={};for(let n in i.atoms){let r=i.atoms[n];if("DUM"!=r.resn&&(r.coord.z>=t&&r.coord.z<=e)){s[r.structure+"_"+r.chain+"_"+r.resi]=1}}let n="z_planes_"+e+"_"+t,r=n;this.selectResidueList(s,n,r,!1)}}class ep{constructor(e){this.icn3d=e}residueids2spec(e){var t=this.icn3d;t.icn3dui;let i="";if(void 0!==e){let s,n,r,a,o,l,d,c=e.sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let i=e.lastIndexOf("_"),s=t.lastIndexOf("_");if(e.substr(0,i)<t.substr(0,s))return-1;if(e.substr(0,i)>t.substr(0,s))return 1;if(e.substr(0,i)==t.substr(0,s)){if(parseInt(e.substr(i+1))<parseInt(t.substr(s+1)))return-1;if(parseInt(e.substr(i+1))>parseInt(t.substr(s+1)))return 1;if(parseInt(e.substr(i+1))==parseInt(t.substr(s+1)))return 0}}})),h="",p=0,u=1!=Object.keys(t.structures).length;for(let e=0,m=c.length;e<m;++e){let m=c[e];if(r=m.lastIndexOf("_"),s=m.substr(0,r),n=m.substr(r+1),a=h.indexOf("_"),o=h.substr(0,a),l=h.substr(a+1),isNaN(n))i+=u?"$"+o+"."+l+":"+n+" or ":"."+l+":"+n+" or ";else{if(h!==s)e>0&&(i+=p===d?u?"$"+o+"."+l+":"+d+" or ":"."+l+":"+d+" or ":u?"$"+o+"."+l+":"+d+"-"+p+" or ":"."+l+":"+d+"-"+p+" or "),d=n;else if(h===s){let e=t.ParserUtilsCls.getResiNCBI(h,p);t.ParserUtilsCls.getResiNCBI(s,n)!=e+1&&(i+=p===d?u?"$"+o+"."+l+":"+d+" or ":"."+l+":"+d+" or ":u?"$"+o+"."+l+":"+d+"-"+p+" or ":"."+l+":"+d+"-"+p+" or ",d=n)}h=s,p=n}}a=h.indexOf("_"),o=h.substr(0,a),l=h.substr(a+1),i+=p===d?u?"$"+o+"."+l+":"+d:"."+l+":"+d:u?"$"+o+"."+l+":"+d+"-"+p:"."+l+":"+d+"-"+p}return i}resi2range(e,t){this.icn3d.icn3dui;let i,s,n=[],r="",a=e,o=a[0];for(let e=0,t=a.length;e<t;++e)s=a[e],0!=e&&parseInt(s)!=parseInt(i)+1&&(n.push(o),n.push(i),r&&(r+=","),r+=o==i?o:o+"-"+i,o=s),i=s;return n.push(o),n.push(i),r&&(r+=","),r+=o==i?o:o+"-"+i,t?r:n}atoms2spec(e){var t=this.icn3d;t.icn3dui;let i,s="",n=0,r={},a={},o={};for(let l in e)i=t.atoms[l],n>0&&(s+=" or "),s+="$"+i.structure+"."+i.chain+":"+i.resi+"@"+i.name,r[i.structure]=1,a[i.structure+"_"+i.chain]=1,o[i.structure+"_"+i.chain+"_"+i.resi]=1,++n;if(1==Object.keys(o).length){let e="\\$"+i.structure+"\\."+i.chain+":"+i.resi;s=s.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(a).length){let e="\\$"+i.structure+"\\."+i.chain;s=s.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(r).length){let e="\\$"+i.structure;s=s.replace(new RegExp(e,"g"),"")}return s}atoms2residues(e){var t=this.icn3d;t.icn3dui;let i={};for(let t=0,s=e.length;t<s;++t)i[e[t]]=1;let s=t.firstAtomObjCls.getResiduesFromAtoms(i);return Object.keys(s)}atoms2structureArray(e){var t=this.icn3d;t.icn3dui;let i={};for(let s in e){i[t.atoms[s].structure]=1}return Object.keys(i)}selectProperty(e,t,i){var s=this.icn3d,n=s.icn3dui;let r=n.hashUtilsCls.cloneHash(s.hAtoms);if("positive"==e){let e=":r,k,h";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e)}else if("negative"==e){let e=":d,e";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e),s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,s.nucleotides)}else if("hydrophobic"==e){let e=":w,f,y,l,i,c,m";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e),s.hAtoms=n.hashUtilsCls.intHash(s.hAtoms,s.proteins)}else if("polar"==e){let e=":g,v,s,t,a,n,p,q";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e),s.hAtoms=n.hashUtilsCls.intHash(s.hAtoms,s.proteins)}else if("b factor"==e){let e=n.hashUtilsCls.cloneHash(s.calphas);e=n.hashUtilsCls.unionHash(e,s.nucleotidesO3),e=n.hashUtilsCls.unionHash(e,s.chemicals),e=n.hashUtilsCls.unionHash(e,s.ions),e=n.hashUtilsCls.unionHash(e,s.water),s.hAtoms={};for(let r in e){let e=s.atoms[r];e.b>=parseInt(t)&&e.b<=parseInt(i)&&(s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,s.residues[e.structure+"_"+e.chain+"_"+e.resi]))}}else if("percent out"==e){s.bCalcArea=!0,s.opts.surface="solvent accessible surface",s.applyMapCls.applySurfaceOptions(),s.bCalcArea=!1,s.hAtoms={};for(let e in s.resid2area){let r=e.lastIndexOf("_"),a=e.substr(r+1);if(n.parasCls.residueArea.hasOwnProperty(a)){let o=parseInt(s.resid2area[e]/n.parasCls.residueArea[a]*100);if(o>=t&&o<=i){let t=e.substr(0,r);s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,s.residues[t])}}}}s.hAtoms=n.hashUtilsCls.intHash(s.hAtoms,r),s.drawCls.draw(),s.hlUpdateCls.updateHlAll()}selectComplement(){let e=this.icn3d,t=e.icn3dui,i={};for(let t in e.atoms)e.hAtoms.hasOwnProperty(t)||(i[t]=1);e.hAtoms=t.hashUtilsCls.cloneHash(i),e.hlUpdateCls.updateHlAll()}switchHighlightLevel(){var e=this.icn3d.icn3dui;if(e.bNode)return;let t=this;document.addEventListener("keydown",(function(i){let s=t.icn3d;38===i.keyCode?(i.preventDefault(),0!=Object.keys(s.pickedAtomList).length&&s.hAtoms.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.pickedAtomList).serial)||(s.pickedAtomList=e.hashUtilsCls.cloneHash(s.hAtoms)),t.switchHighlightLevelUp(),e.htmlCls.clickMenuCls.setLogCmd("highlight level up",!0)):40===i.keyCode&&(i.preventDefault(),0!=Object.keys(s.pickedAtomList).length&&s.hAtoms.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.pickedAtomList).serial)||(s.pickedAtomList=e.hashUtilsCls.cloneHash(s.hAtoms)),t.switchHighlightLevelDown(),e.htmlCls.clickMenuCls.setLogCmd("highlight level down",!0))}))}switchHighlightLevelUp(){var e=this.icn3d,t=e.icn3dui;if(!t.bNode){if(e.bShift||e.bCtrl||e.hlObjectsCls.removeHlObjects(),void 0!==e.pickedAtomList&&0!==Object.keys(e.pickedAtomList).length||(e.pickedAtomList=t.hashUtilsCls.cloneHash(e.hAtoms)),0===Object.keys(e.pickedAtomList).length&&(e.pickedAtomList=e.dAtoms),1===e.highlightlevel){e.highlightlevel=2;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[i.structure+"_"+i.chain+"_"+i.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[i.structure+"_"+i.chain+"_"+i.resi])}else if(2===e.highlightlevel){e.highlightlevel=3;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(i)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(i))}else if(3===e.highlightlevel){let i;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);i=e.pickingCls.select3ddomainFromAtom(s),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,i):e.hAtoms=t.hashUtilsCls.cloneHash(i)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(i).length){e.highlightlevel=5;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i.structure+"_"+i.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[i.structure+"_"+i.chain])}}else if(4===e.highlightlevel){e.highlightlevel=5;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i.structure+"_"+i.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[i.structure+"_"+i.chain])}else if(5===e.highlightlevel||6===e.highlightlevel){e.highlightlevel=6;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl||(e.hAtoms={});let s=e.structures[i.structure];for(let i=0,n=s.length;i<n;++i)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s[i]])}e.hlObjectsCls.addHlObjects(),e.hlUpdateCls.updateHlAll()}}switchHighlightLevelDown(){var e=this.icn3d,t=e.icn3dui;if(!t.bNode){if(e.hlObjectsCls.removeHlObjects(),void 0!==e.pickedAtomList&&0!==Object.keys(e.pickedAtomList).length||(e.pickedAtomList=t.hashUtilsCls.cloneHash(e.hAtoms)),2!==e.highlightlevel&&1!==e.highlightlevel||1!==Object.keys(e.pickedAtomList).length){if(3===e.highlightlevel){let i={};for(let t in e.pickedAtomList)residueid=e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi,i[residueid]=1;if(1===Object.keys(i).length){e.highlightlevel=2;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[i.structure+"_"+i.chain+"_"+i.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[i.structure+"_"+i.chain+"_"+i.resi])}}else if(4===e.highlightlevel){e.highlightlevel=3;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(i)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(i))}else if(5===e.highlightlevel){let i;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);i=e.pickingCls.select3ddomainFromAtom(s),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,i):e.hAtoms=t.hashUtilsCls.cloneHash(i)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(i).length){e.highlightlevel=3;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(i)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(i))}}else if(6===e.highlightlevel){e.highlightlevel=5;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i.structure+"_"+i.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[i.structure+"_"+i.chain])}}else e.highlightlevel=1,e.hAtoms=t.hashUtilsCls.cloneHash(e.pickedAtomList),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickedAtomList):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickedAtomList);e.hlObjectsCls.addHlObjects(),e.hlUpdateCls.updateHlAll()}}}class tp{constructor(e){this.icn3d=e}async CalcPhiUrl(e,t,i,s,n){let r=this.icn3d.icn3dui,a=await r.getXMLHttpRqstPromise(n,"GET","text","PQR");await this.CalcPhi(e,t,i,s,a)}getPdbStr(e){let t=this.icn3d,i=t.icn3dui,s={},n={},r=i.hashUtilsCls.intHash(t.dAtoms,t.hAtoms);for(let e in r)t.atoms[e],t.ions.hasOwnProperty(e)?s[e]=1:n[e]=1;let a=Object.keys(n).length;if(i.utilsCls.isCalphaPhosOnly(i.hashUtilsCls.hash2Atoms(n,t.atoms)))return void(e?console.log("The potential will not be shown because the side chains are missing in the structure..."):alert("The potential will not be shown because the side chains are missing in the structure..."));if(a>3e4)return void(e?console.log("The maximum number of allowed atoms is 30,000. Please try it again with selected chains..."):alert("The maximum number of allowed atoms is 30,000. Please try it again with selected chains..."));let o="",l=!0,d=!0;return o+=i.cfg.cid?t.saveFileCls.getAtomPDB(n,!0,void 0,void 0,void 0,void 0,l,d):t.saveFileCls.getAtomPDB(n,void 0,void 0,void 0,void 0,void 0,l,d),o+=t.saveFileCls.getAtomPDB(s,!0,void 0,!0,void 0,void 0,l,d),o}async CalcPhi(e,t,i,s,n){let r=this.icn3d;r.icn3dui;let a=await this.CalcPhiPrms(e,t,i,s,n);this.loadPhiData(a,i,s),r.bAjaxPhi=!0,s?r.setOptionCls.setOption("phisurface","phi"):r.setOptionCls.setOption("phimap","phi")}CalcPhiPrms(e,t,i,s,n){let r=this.icn3d,a=r.icn3dui;r.loadPhiFrom="delphi";let o=a.htmlCls.baseUrl+"delphi/delphi.cgi",l=a.cfg.cid?a.cfg.cid:Object.keys(r.structures).toString(),d={};if(n)d={pqr2phi:n,gsize:e,salt:t,pdbid:l};else{let i=this.getPdbStr();d={pdb2phi:i,gsize:e,salt:t,pdbid:l}}return new Promise((function(e,t){$.ajax({url:o,type:"POST",data:d,dataType:"binary",responseType:"arraybuffer",cache:!0,beforeSend:function(){r.ParserUtilsCls.showLoading()},complete:function(){r.ParserUtilsCls.hideLoading()},success:function(t){e(t)},error:function(e,t,i){}})}))}async PhiParser(e,t,i,s){let n,r=this.icn3d,a=r.icn3dui,o=this;n="phiurl"==t||"phiurl2"==t?"arraybuffer":"text";let l=await a.getXMLHttpRqstPromise(e,"GET",n,"potential");"phiurl"==t||"phiurl2"==t?o.loadPhiData(l,i,s):o.loadCubeData(l,i,s),r.bAjaxPhi=!0,s?r.setOptionCls.setOption("phisurface","phi"):r.setOptionCls.setOption("phimap","phi")}loadPhiData(e,t,i){let s=this.icn3d;s.icn3dui;let n={filetype:"phi"},r=e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e,a=new Float32Array(r.slice(r.byteLength-24,r.byteLength-8));n.scale=a[0];let o=a[1],l=a[2],d=a[3];n.n=new Int32Array(r.slice(r.byteLength-8,r.byteLength-4)),n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new mt(o-c,l-c,d-c);let h=new Float32Array(r.slice(110,r.byteLength-56));n.bSurface=i,s.mapData.headerPhi=n,s.mapData.dataPhi=h,s.mapData.contourPhi=t;let p=new gi;p.identity(),p.multiply((new gi).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),s.mapData.matrixPhi=p}loadCubeData(e,t,i){let s=this.icn3d;s.icn3dui;let n={filetype:"cube"},r=e.split("\n"),a=[];a.push(parseFloat(r[0].substr(0,10))),a.push(parseFloat(r[0].substr(10,6))),a.push(parseFloat(r[0].substr(16,10))),a.push(parseFloat(r[0].substr(26,10))),a.push(parseFloat(r[0].substr(36,10))),n.scale=a[0];let o=a[2],l=a[3],d=a[4];n.n=a[1],n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new mt(o-c,l-c,d-c);let h=[];for(let e=7,t=r.length;e<t;++e){let t=r[e].split(/\s+/);for(let e=0,i=t.length;e<i;++e){let i=parseFloat(t[e]);isNaN(i)||h.push(i)}}h.length!=n.n*n.n*n.n&&console.log("the data array size "+h.length+" didn't match the grid size "+n.n*n.n*n.n+"..."),n.bSurface=i,s.mapData.headerPhi=n,s.mapData.dataPhi=h,s.mapData.contourPhi=t;let p=new gi;p.identity(),p.multiply((new gi).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),s.mapData.matrixPhi=p}async applyCommandPhi(e){let t=this.icn3d;t.icn3dui;let i=this,s=e.split(" | "),n=s[0].split(" "),r=s[1].split(" "),a=s[2].split(" "),o=s[3].split(" "),l=s[4].split(" "),d=n[2],c=parseFloat(r[1]),h=a[1],p=o[1],u=l[1];if(8==s.length){let e=s[5].split(" "),i=s[6].split(" "),n=s[7].split(" ");t.phisurftype=e[1],t.phisurfop=parseFloat(i[1]),t.phisurfwf=n[1],$("#"+t.pre+"delphisurftype").val(t.phisurftype),$("#"+t.pre+"delphisurfop").val(t.phisurfop),$("#"+t.pre+"delphisurfwf").val(t.phisurfwf)}let m="pqrurl2"==d||"phiurl2"==d||"cubeurl2"==d;"pqrurl"==d||"pqrurl2"==d?await i.CalcPhiUrl(p,u,c,m,h):await i.PhiParser(h,d,c,m)}async applyCommandDelphi(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | "),s=i[0].split(" "),n=i[1].split(" "),r=i[2].split(" "),a=i[3].split(" "),o=s[2],l=n[1],d=r[1],c=a[1];if($("#"+t.pre+"delphi1gsize").val(d),$("#"+t.pre+"delphi1salt").val(c),$("#"+t.pre+"delphi2gsize").val(d),$("#"+t.pre+"delphi2salt").val(c),7==i.length){let e=i[4].split(" "),s=i[5].split(" "),n=i[6].split(" ");t.phisurftype=e[1],t.phisurfop=s[1],t.phisurfwf=n[1],$("#"+t.pre+"delphisurftype").val(t.phisurftype),$("#"+t.pre+"delphisurfop").val(t.phisurfop),$("#"+t.pre+"delphisurfwf").val(t.phisurfwf)}let h="surface"==o;await this.CalcPhi(d,c,l,h)}async loadDelphiFile(e){let t=this.icn3d,i=t.icn3dui,s="delphi2"==e?$("#"+t.pre+"delphi2gsize").val():$("#"+t.pre+"delphi1gsize").val(),n="delphi2"==e?$("#"+t.pre+"delphi2salt").val():$("#"+t.pre+"delphi1gsize").val(),r="delphi2"==e?$("#"+t.pre+"delphicontour2").val():$("#"+t.pre+"delphicontour").val(),a="delphi2"==e;await this.CalcPhi(s,n,r,a);let o="delphi2"==e?"surface":"map";a?i.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+r+" | gsize "+s+" | salt "+n+" | surface "+t.phisurftype+" | opacity "+t.phisurfop+" | wireframe "+t.phisurfwf,!0):i.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+r+" | gsize "+s+" | salt "+n,!0)}loadPhiFile(e){let t,i=this.icn3d,s=i.icn3dui,n=this;"pqr"==e||"phi"==e||"cube"==e?t=$("#"+i.pre+e+"file")[0].files[0]:"pqr2"==e?t=$("#"+i.pre+"pqrfile2")[0].files[0]:"phi2"==e?t=$("#"+i.pre+"phifile2")[0].files[0]:"cube2"==e&&(t=$("#"+i.pre+"cubefile2")[0].files[0]);let r="pqr"==e||"phi"==e||"cube"==e?$("#"+i.pre+"phicontour").val():$("#"+i.pre+"phicontour2").val();if(t){s.utilsCls.checkFileAPI();let i=new FileReader;i.onload=async function(t){let i=n.icn3d,a=t.target.result,o=0,l=0;if("pqr"==e||"pqr2"==e){let t="pqr2"==e;o=$("#"+i.pre+e+"gsize").val(),l=$("#"+i.pre+e+"salt").val(),await n.CalcPhi(o,l,r,t,a)}else if("phi"==e||"phi2"==e){let t="phi2"==e;n.loadPhiData(a,r,t)}else if("cube"==e||"cube2"==e){let t="cube2"==e;n.loadCubeData(a,r,t)}i.bAjaxPhi=!0,bSurface?i.setOptionCls.setOption("phisurface","phi"):i.setOptionCls.setOption("phimap","phi"),bSurface?s.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+r+" | file "+$("#"+i.pre+e+"file").val()+" | gsize "+o+" | salt "+l+" | surface "+i.phisurftype+" | opacity "+i.phisurfop+" | wireframe "+i.phisurfwf,!1):s.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+r+" | file "+$("#"+i.pre+e+"file").val()+" | gsize "+o+" | salt "+l,!1)},"phi"==e||"phi2"==e?i.readAsArrayBuffer(t):i.readAsText(t)}else alert("Please select a file before clicking 'Load'")}async loadPhiFileUrl(e){let t,i=this.icn3d,s=i.icn3dui;"pqrurl"==e||"phiurl"==e||"cubeurl"==e?t=$("#"+i.pre+e+"file").val():"pqrurl2"==e?t=$("#"+i.pre+"pqrurlfile2").val():"phiurl2"==e?t=$("#"+i.pre+"phiurlfile2").val():"cubeurl2"==e&&(t=$("#"+i.pre+"cubeurlfile2").val());let n="pqrurl"==e||"phiurl"==e||"cubeurl"==e?$("#"+i.pre+"phiurlcontour").val():$("#"+i.pre+"phiurlcontour2").val();if(t){let r="pqrurl2"==e||"phiurl2"==e||"cubeurl2"==e,a=0,o=0;"pqrurl"==e||"pqrurl2"==e?(a=$("#"+i.pre+e+"gsize").val(),o=$("#"+i.pre+e+"salt").val(),await this.CalcPhiUrl(a,o,n,r,t)):await this.PhiParser(t,e,n,r),r?s.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+a+" | salt "+o+" | surface "+i.phisurftype+" | opacity "+i.phisurfop+" | wireframe "+i.phisurfwf,!0):s.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+a+" | salt "+o,!0)}else alert("Please input the file URL before clicking 'Load'")}}class ip{constructor(e){this.icn3d=e}async applyDssp(e,t){let i=this.icn3d,s=i.icn3dui,n=this,r=e?"1":"0",a=Object.keys(i.structures),o=[],l=window&&window.location&&-1!=window.location.hostname.indexOf("ncbi.nlm.nih.gov")?"/Structure/mmcifparser/mmcifparser.cgi":s.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi";for(let e=0,t=a.length;e<t;++e){let t="",n={},d=i.structures[a[e]];for(let e=0,t=d.length;e<t;++e)n=s.hashUtilsCls.unionHash(n,i.chains[d[e]]);t+=i.saveFileCls.getAtomPDB(n,void 0,!0);let c={dssp:"t",calphaonly:r,pdbfile:t},h=s.getAjaxPostPromise(l,c);o.push(h)}let d=Promise.allSettled(o);try{let e=await d;await n.parseDsspData(e,a,t),s.bNode||await i.ParserUtilsCls.checkMemProteinAndRotate()}catch(e){console.log("DSSP calculation had a problem with this structure "+a[0]+"..."),await i.pdbParserCls.loadPdbDataRender(t)}}async parseDsspData(e,t,i){let s=this.icn3d;s.icn3dui;for(let i=0,n=e.length;i<n;++i){let n=e[i].value;if(void 0!==n&&-1===JSON.stringify(n).indexOf("Oops there was a problem"))for(let e in s.chainsSeq){let r=e.indexOf("_");if(e.substr(0,r)!=t[i])continue;let a,o=e.substr(r+1),l=s.chainsSeq[e],d="coil";for(let t=0,i=l.length;t<i;++t){let i,r=l[t].resi,c=o+"_"+r,h="c";n.hasOwnProperty(c)?h=n[c]:n.hasOwnProperty(" _"+r)?h=n[" _"+r]:n.hasOwnProperty("_"+r)&&(h=n["_"+r]),i="H"===h?"helix":"E"===h?"sheet":"coil";let p=e+"_"+r;s.secondaries[p]=h;let u,m,f=0;if(i!==d?"coil"===d?(u=!0,m=!1):"coil"===i?(f=2,u=!1,m=!1):("sheet"===d&&"helix"===i||"helix"===d&&"sheet"===i)&&(f=2,u=!0,m=!1):(u=!1,m=!1),1==f){let t=e+"_"+a;for(let e in s.residues[t])s.atoms[e].ssbegin=!0,s.atoms[e].ssend=!1}else if(2==f){let t=e+"_"+a;for(let e in s.residues[t])s.atoms[e].ssbegin=!1,s.atoms[e].ssend=!0}for(let e in s.residues[p])s.atoms[e].ss=i,s.atoms[e].ssbegin=u,s.atoms[e].ssend=m;d=i,a=r}}else console.log("DSSP calculation had a problem with this structure "+t[i]+"...")}await s.pdbParserCls.loadPdbDataRender(i)}}class sp{constructor(e){this.icn3d=e,this.TMThresholdIgType=.85,this.TMThresholdTemplate=.4,this.topClusters=5}async hideIgRefNum(){let e=this.icn3d;e.icn3dui,e.bShowRefnum=!1,e.resid2refnum={},e.annotationCls.hideAnnoTabIg(),e.selectionCls.selectAll_base(),e.opts.color="chain",e.setColorCls.setColorByOptions(e.opts,e.atoms),e.hlUpdateCls.updateHlAll(),e.drawCls.draw(),e.bResetAnno=!0,e.bAnnoShown&&await e.annotationCls.resetAnnoTabAll()}setRefPdbs(){let e=this.icn3d;e.icn3dui,e.refpdbArray=["1InsulinR_8guyE_human_FN3-n1","1Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4","1CoAtomerGamma1_1r4xA_human","1C3_2qkiD_human_n1","1CuZnSuperoxideDismutase_1hl5C_human","1ASF1A_2iijA_human","1FAB-LIGHT_5esv_C1-n2","1CD2_1hnfA_human_C2-n2","1NaCaExchanger_2fwuA_dog_n2","1NaKATPaseTransporterBeta_2zxeB_spurdogshark","1FAB-HEAVY_5esv_V-n1","1PDL1_4z18B_human_V-n1","1BTLA_2aw2A_human_Iset","1LaminAC_1ifrA_human","1CD3g_6jxrg_human_C2","1CD28_1yjdC_human_V","1CD19_6al5A_human-n1"],e.refpdbHash={},e.refpdbHash["1InsulinR_8guyE_human_FN3-n1"]=["InsulinR_8guyE_human_FN3-n1","IL6Rb_1bquB_human_FN3-n3","Sidekick2_1wf5A_human_FN3-n7","InsulinR_8guyE_human_FN3-n2","Contactin1_2ee2A_human_FN3-n9","IL6Rb_1bquB_human_FN3-n2"],e.refpdbHash["1Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4"]=["Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4","ICOS_6x4gA_human_V"],e.refpdbHash["1CoAtomerGamma1_1r4xA_human"]=["CoAtomerGamma1_1r4xA_human","TP34_2o6cA_bacteria"],e.refpdbHash["1C3_2qkiD_human_n1"]=["C3_2qkiD_human_n1","BArrestin1_4jqiA_rat_n1","RBPJ_6py8C_human_Unk-n1"],e.refpdbHash["1CuZnSuperoxideDismutase_1hl5C_human"]=["CuZnSuperoxideDismutase_1hl5C_human","TEAD1_3kysC_human"],e.refpdbHash["1ASF1A_2iijA_human"]=["ASF1A_2iijA_human","RBPJ_6py8C_human_Unk-n2","TP47_1o75A_bacteria"],e.refpdbHash["1FAB-LIGHT_5esv_C1-n2"]=["FAB-LIGHT_5esv_C1-n2","GHR_1axiB_human_C1-n1","VTCN1_Q7Z7D3_human_C1-n2","B2Microglobulin_7phrL_human_C1","FAB-HEAVY_5esv_C1-n2","MHCIa_7phrH_human_C1"],e.refpdbHash["1CD2_1hnfA_human_C2-n2"]=["CD2_1hnfA_human_C2-n2","Siglec3_5j0bB_human_C1-n2"],e.refpdbHash["1NaCaExchanger_2fwuA_dog_n2"]=["NaCaExchanger_2fwuA_dog_n2","ORF7a_1xakA_virus","ECadherin_4zt1A_human_n2"],e.refpdbHash["1NaKATPaseTransporterBeta_2zxeB_spurdogshark"]=["NaKATPaseTransporterBeta_2zxeB_spurdogshark"],e.refpdbHash["1FAB-HEAVY_5esv_V-n1"]=["FAB-HEAVY_5esv_V-n1","FAB-LIGHT_5esv_V-n1","VNAR_1t6vN_shark_V","TCRa_6jxrm_human_V-n1","VISTA_6oilA_human_V","CD8a_1cd8A_human_V","PD1_4zqkB_human_V"],e.refpdbHash["1PDL1_4z18B_human_V-n1"]=["PDL1_4z18B_human_V-n1","CD2_1hnfA_human_V-n1","LAG3_7tzgD_human_V-n1"],e.refpdbHash["1BTLA_2aw2A_human_Iset"]=["BTLA_2aw2A_human_Iset","Palladin_2dm3A_human_Iset-n1","Titin_4uowM_human_Iset-n152","LAG3_7tzgD_human_C1-n2","JAM1_1nbqA_human_Iset-n2","Contactin1_3s97C_human_Iset-n2"],e.refpdbHash["1LaminAC_1ifrA_human"]=["LaminAC_1ifrA_human","CD3d_6jxrd_human_C1"],e.refpdbHash["1CD3g_6jxrg_human_C2"]=["CD3g_6jxrg_human_C2","TCRa_6jxrm_human_C1-n2","IsdA_2iteA_bacteria"],e.refpdbHash["1CD28_1yjdC_human_V"]=["CD28_1yjdC_human_V","MPT63_1lmiA_bacteria","CD3e_6jxrf_human_C1"],e.refpdbHash["1CD19_6al5A_human-n1"]=["CD19_6al5A_human-n1"],e.refpdbHash.all_templates=["ASF1A_2iijA_human","B2Microglobulin_7phrL_human_C1","BArrestin1_4jqiA_rat_n1","BTLA_2aw2A_human_Iset","C3_2qkiD_human_n1","CD19_6al5A_human-n1","CD28_1yjdC_human_V","CD2_1hnfA_human_C2-n2","CD2_1hnfA_human_V-n1","CD3d_6jxrd_human_C1","CD3e_6jxrf_human_C1","CD3g_6jxrg_human_C2","CD8a_1cd8A_human_V","CoAtomerGamma1_1r4xA_human","Contactin1_2ee2A_human_FN3-n9","Contactin1_3s97C_human_Iset-n2","CuZnSuperoxideDismutase_1hl5C_human","ECadherin_4zt1A_human_n2","Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4","FAB-HEAVY_5esv_C1-n2","FAB-HEAVY_5esv_V-n1","FAB-LIGHT_5esv_C1-n2","FAB-LIGHT_5esv_V-n1","GHR_1axiB_human_C1-n1","ICOS_6x4gA_human_V","IL6Rb_1bquB_human_FN3-n2","IL6Rb_1bquB_human_FN3-n3","InsulinR_8guyE_human_FN3-n1","InsulinR_8guyE_human_FN3-n2","IsdA_2iteA_bacteria","JAM1_1nbqA_human_Iset-n2","LAG3_7tzgD_human_C1-n2","LAG3_7tzgD_human_V-n1","LaminAC_1ifrA_human","MHCIa_7phrH_human_C1","MPT63_1lmiA_bacteria","NaCaExchanger_2fwuA_dog_n2","NaKATPaseTransporterBeta_2zxeB_spurdogshark","ORF7a_1xakA_virus","PD1_4zqkB_human_V","PDL1_4z18B_human_V-n1","Palladin_2dm3A_human_Iset-n1","RBPJ_6py8C_human_Unk-n1","RBPJ_6py8C_human_Unk-n2","Sidekick2_1wf5A_human_FN3-n7","Siglec3_5j0bB_human_C1-n2","TCRa_6jxrm_human_C1-n2","TCRa_6jxrm_human_V-n1","TEAD1_3kysC_human","TP34_2o6cA_bacteria","TP47_1o75A_bacteria","Titin_4uowM_human_Iset-n152","VISTA_6oilA_human_V","VNAR_1t6vN_shark_V","VTCN1_Q7Z7D3_human_C1-n2"],e.refpdbHash["5ESV_C"]=["FAB-HEAVY_5esv_V-n1","FAB-HEAVY_5esv_C1-n2"],e.refpdbHash["5ESV_D"]=["FAB-LIGHT_5esv_V-n1","FAB-LIGHT_5esv_C1-n2"],e.refpdbHash["8GUY_E"]=["InsulinR_8guyE_human_FN3-n1","InsulinR_8guyE_human_FN3-n2"],e.refpdbHash["6JXR_m"]=["TCRa_6jxrm_human_V-n1","TCRa_6jxrm_human_C1-n2"],e.refpdbHash["1HNF_A"]=["CD2_1hnfA_human_V-n1","CD2_1hnfA_human_C2-n2"],e.refpdbHash["7TZG_D"]=["LAG3_7tzgD_human_V-n1","LAG3_7tzgD_human_C1-n2"],e.refpdbHash["6PY8_C"]=["RBPJ_6py8C_human_Unk-n1","RBPJ_6py8C_human_Unk-n2"],e.refpdbHash["1BQU_B"]=["IL6Rb_1bquB_human_FN3-n2","IL6Rb_1bquB_human_FN3-n3"],e.refpdbHash["1R4X_A"]=["CoAtomerGamma1_1r4xA_human"],e.refpdbHash["6OIL_A"]=["VISTA_6oilA_human_V"],e.refpdbHash["2ZXE_B"]=["NaKATPaseTransporterBeta_2zxeB_spurdogshark"],e.refpdbHash["1I8A_A"]=["Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4"],e.refpdbHash["2FWU_A"]=["NaCaExchanger_2fwuA_dog_n2"],e.refpdbHash["4JQI_A"]=["BArrestin1_4jqiA_rat_n1"],e.refpdbHash["1NBQ_A"]=["JAM1_1nbqA_human_Iset-n2"],e.refpdbHash["1O75_A"]=["TP47_1o75A_bacteria"],e.refpdbHash["7PHR_H"]=["MHCIa_7phrH_human_C1"],e.refpdbHash["2IIJ_A"]=["ASF1A_2iijA_human"],e.refpdbHash["4Z18_B"]=["PDL1_4z18B_human_V-n1"],e.refpdbHash["1T6V_N"]=["VNAR_1t6vN_shark_V"],e.refpdbHash["2O6C_A"]=["TP34_2o6cA_bacteria"],e.refpdbHash["3KYS_C"]=["TEAD1_3kysC_human"],e.refpdbHash["7PHR_L"]=["B2Microglobulin_7phrL_human_C1"],e.refpdbHash["2AW2_A"]=["BTLA_2aw2A_human_Iset"],e.refpdbHash["1HL5_C"]=["CuZnSuperoxideDismutase_1hl5C_human"],e.refpdbHash["1WF5_A"]=["Sidekick2_1wf5A_human_FN3-n7"],e.refpdbHash["5J0B_B"]=["Siglec3_5j0bB_human_C1-n2"],e.refpdbHash["1IFR_A"]=["LaminAC_1ifrA_human"],e.refpdbHash.Q7Z7D3_A=["VTCN1_Q7Z7D3_human_C1-n2"],e.refpdbHash["4ZQK_B"]=["PD1_4zqkB_human_V"],e.refpdbHash["2DM3_A"]=["Palladin_2dm3A_human_Iset-n1"],e.refpdbHash["2ITE_A"]=["IsdA_2iteA_bacteria"],e.refpdbHash["1XAK_A"]=["ORF7a_1xakA_virus"],e.refpdbHash["4ZT1_A"]=["ECadherin_4zt1A_human_n2"],e.refpdbHash["1LMI_A"]=["MPT63_1lmiA_bacteria"],e.refpdbHash["1CD8_A"]=["CD8a_1cd8A_human_V"],e.refpdbHash["3S97_C"]=["Contactin1_3s97C_human_Iset-n2"],e.refpdbHash["1AXI_B"]=["GHR_1axiB_human_C1-n1"],e.refpdbHash["6X4G_A"]=["ICOS_6x4gA_human_V"],e.refpdbHash["2EE2_A"]=["Contactin1_2ee2A_human_FN3-n9"],e.refpdbHash["4UOW_M"]=["Titin_4uowM_human_Iset-n152"],e.refpdbHash["6A15_A"]=["CD19_6al5A_human-n1"],e.refpdbHash["2QKI_D"]=["C3_2qkiD_human_n1"],e.refpdbHash["1YJD_C"]=["CD28_1yjdC_human_V"],e.refpdbHash["6JXR_d"]=["CD3d_6jxrd_human_C1"],e.refpdbHash["6JXR_f"]=["CD3e_6jxrf_human_C1"],e.refpdbHash["6JXR_g"]=["CD3g_6jxrg_human_C2"],e.ref2igtype={},e.ref2igtype.ASF1A_2iijA_human="IgFN3-like",e.ref2igtype.B2Microglobulin_7phrL_human_C1="IgC1",e.ref2igtype.BArrestin1_4jqiA_rat_n1="IgFN3-like",e.ref2igtype.BTLA_2aw2A_human_Iset="IgI",e.ref2igtype.C3_2qkiD_human_n1="IgFN3-like",e.ref2igtype["CD19_6al5A_human-n1"]="CD19",e.ref2igtype.CD28_1yjdC_human_V="IgV",e.ref2igtype["CD2_1hnfA_human_C2-n2"]="IgC2",e.ref2igtype["CD2_1hnfA_human_V-n1"]="IgV",e.ref2igtype.CD3d_6jxrd_human_C1="IgC1",e.ref2igtype.CD3e_6jxrf_human_C1="IgC1",e.ref2igtype.CD3g_6jxrg_human_C2="IgC2",e.ref2igtype.CD8a_1cd8A_human_V="IgV",e.ref2igtype.CoAtomerGamma1_1r4xA_human="IgE",e.ref2igtype["Contactin1_2ee2A_human_FN3-n9"]="IgFN3",e.ref2igtype["Contactin1_3s97C_human_Iset-n2"]="IgI",e.ref2igtype.CuZnSuperoxideDismutase_1hl5C_human="SOD",e.ref2igtype.ECadherin_4zt1A_human_n2="Cadherin",e.ref2igtype["Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4"]="IgE",e.ref2igtype["FAB-HEAVY_5esv_C1-n2"]="IgC1",e.ref2igtype["FAB-HEAVY_5esv_V-n1"]="IgV",e.ref2igtype["FAB-LIGHT_5esv_C1-n2"]="IgC1",e.ref2igtype["FAB-LIGHT_5esv_V-n1"]="IgV",e.ref2igtype["GHR_1axiB_human_C1-n1"]="IgC1",e.ref2igtype.ICOS_6x4gA_human_V="IgV",e.ref2igtype["IL6Rb_1bquB_human_FN3-n2"]="IgFN3",e.ref2igtype["IL6Rb_1bquB_human_FN3-n3"]="IgFN3",e.ref2igtype["InsulinR_8guyE_human_FN3-n1"]="IgFN3",e.ref2igtype["InsulinR_8guyE_human_FN3-n2"]="IgFN3",e.ref2igtype.IsdA_2iteA_bacteria="IgE",e.ref2igtype["JAM1_1nbqA_human_Iset-n2"]="IgI",e.ref2igtype["LAG3_7tzgD_human_C1-n2"]="IgC1",e.ref2igtype["LAG3_7tzgD_human_V-n1"]="IgV",e.ref2igtype.LaminAC_1ifrA_human="Lamin",e.ref2igtype.MHCIa_7phrH_human_C1="IgC1",e.ref2igtype.MPT63_1lmiA_bacteria="IgFN3-like",e.ref2igtype.NaCaExchanger_2fwuA_dog_n2="IgFN3-like",e.ref2igtype.NaKATPaseTransporterBeta_2zxeB_spurdogshark="IgE",e.ref2igtype.ORF7a_1xakA_virus="ORF",e.ref2igtype.PD1_4zqkB_human_V="IgV",e.ref2igtype["PDL1_4z18B_human_V-n1"]="IgV",e.ref2igtype["Palladin_2dm3A_human_Iset-n1"]="IgI",e.ref2igtype["RBPJ_6py8C_human_Unk-n1"]="IgFN3-like",e.ref2igtype["Sidekick2_1wf5A_human_FN3-n7"]="IgFN3",e.ref2igtype["Siglec3_5j0bB_human_C1-n2"]="IgC1",e.ref2igtype["TCRa_6jxrm_human_C1-n2"]="IgC1",e.ref2igtype["TCRa_6jxrm_human_V-n1"]="IgV",e.ref2igtype.TEAD1_3kysC_human="IgFN3-like",e.ref2igtype.TP34_2o6cA_bacteria="IgE",e.ref2igtype.TP47_1o75A_bacteria="IgE",e.ref2igtype["Titin_4uowM_human_Iset-n152"]="IgI",e.ref2igtype.VISTA_6oilA_human_V="IgV",e.ref2igtype.VNAR_1t6vN_shark_V="IgV",e.ref2igtype["VTCN1_Q7Z7D3_human_C1-n2"]="IgC1"}getPdbAjaxArray(){let e=this.icn3d,t=e.icn3dui,i=[];for(let s=0,n=e.refpdbArray.length;s<n;++s){let n=t.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+e.refpdbArray[s],r=t.getAjaxPromise(n,"text");i.push(r)}return i}async showIgRefNum(e){let t=this.icn3d;t.icn3dui;let i=this;this.setRefPdbs();let s=this.getPdbAjaxArray(),n=0;if(e)await i.parseRefPdbData(void 0,e,void 0,n);else{t.pdbDataArray=await this.promiseWithFixedJobs(s);let r=await i.parseRefPdbData(t.pdbDataArray,e,void 0,n);for(++n;!r&&n<15;){let s=!0;r=await i.parseRefPdbData(t.pdbDataArray,e,s,n),++n}}t.chainid2igtrack||(t.chainid2igtrack={});for(let e in t.chains){let i=t.firstAtomObjCls.getFirstAtomObj(t.chains[e]);if(t.proteins.hasOwnProperty(i.serial)){let i=t.showSeqCls.getSeq(e);t.chainid2igtrack[e]=this.ajdustRefnum(i,e)}}}async parseRefPdbData(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=this,o=Object.keys(n.structures),l=[],d=[],c=r.htmlCls.tmalignUrl;n.resid2domainid||(n.resid2domainid={}),n.domainid2pdb={};let h=!0,p=!1;for(let s=0,a=o.length;s<a;++s){let a=o[s],u=n.structures[a];for(let s=0,o=u.length;s<o;++s){let o=u[s],m=this.getDomainAtomsArray(o,i);if(n.domainid2refpdbname||(n.domainid2refpdbname={}),n.domainid2score||(n.domainid2score={}),0!=m.length){p=!0;for(let i=0,s=m.length;i<s;++i){h=!1;let s=n.saveFileCls.getAtomPDB(m[i],void 0,void 0,void 0,void 0,a),p=n.firstAtomObjCls.getFirstAtomObj(m[i]),u=n.firstAtomObjCls.getLastAtomObj(m[i]),f=o+","+i+"_"+(p.resi+":"+u.resi+":"+Object.keys(m[i]).length);if(delete n.domainid2score[f],n.domainid2pdb[f]=s,t)n.domainid2refpdbname[f]=[t],d.push(f+"|1"+t);else for(let t=0,i=e.length;t<i;++t){let i=n.defaultPdbId+t,a=e[t].value;a="HEADER "+i+"\n"+a;let o={pdb_query:a,pdb_target:s,queryid:n.refpdbArray[t]},h=r.getAjaxPostPromise(c,o);l.push(h),d.push(f+"|"+n.refpdbArray[t])}}}}}if(!p)return h;if(t){r.bNode||console.log("Start alignment with the reference culsters "+JSON.stringify(n.domainid2refpdbname));let e=[],i=[],o=r.htmlCls.tmalignUrl,l=r.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+t,d=r.getAjaxPromise(l,"text"),c=[];c.push(d);let p=await this.promiseWithFixedJobs(c);for(let s in n.domainid2refpdbname){let a=n.domainid2pdb[s];for(let l=0,d=p.length;l<d;++l){let d=n.defaultPdbId+l,c=p[l].value;c="HEADER "+d+"\n"+c;let h={pdb_query:c,pdb_target:a,queryid:t},u=r.getAjaxPostPromise(o,h);e.push(u),i.push(s+"|"+t)}}let u=[];u=await this.promiseWithFixedJobs(e),h=await a.parseAlignData(u,i,void 0,s)}else{let e=[];e=await this.promiseWithFixedJobs(l);let t=!0;h=await a.parseAlignData(e,d,t,s)}return h}getDomainAtomsArray(e,t){let i=this.icn3d,s=i.icn3dui,n=[];if(i.chainid2atomsLeft||(i.chainid2atomsLeft={}),!i.proteins.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.chains[e]).serial)&&!i.proteins.hasOwnProperty(i.firstAtomObjCls.getMiddleAtomObj(i.chains[e]).serial))return n;if(i.chainsSeq[e].length<20)return n;let r=s.hashUtilsCls.intHash(i.chains[e],i.hAtoms);if(0==Object.keys(r).length)return n;if(t){let t={};for(let e in i.resid2domainid)i.resid2domainid[e]&&(t=s.hashUtilsCls.unionHash(t,i.residues[e]));if(r=s.hashUtilsCls.exclHash(r,t),i.chainid2atomsLeft[e]==Object.keys(r).length)return n;if(i.chainid2atomsLeft[e]=Object.keys(r).length,Object.keys(r).length<200)return n}let a=i.domain3dCls.c2b_NewSplitChain(r,void 0).subdomains;if(a.length>=1)for(let t=0,r=a.length;t<r;++t){let r={},o=a[t],l=0;for(let t=0,n=o.length;t<n;t+=2){let n=parseInt(o[t]),a=parseInt(o[t+1]);for(let t=n;t<=a;++t){let n=i.ncbi2resid[e+"_"+t];++l,r=s.hashUtilsCls.unionHash(r,i.residues[n]),delete i.residIgLoop[n],delete i.resid2domainid[n]}}l<20||n.push(r)}return n}getTemplateList(e){let t=this.icn3d;t.icn3dui;let i="",s="",n="",r="";if(i=t.domainid2refpdbname[e][0],t.domainid2score[e]){let i=t.domainid2score[e].split("_");s=i[0],n=i[1],r=i[2]}return{refpdbname:i,score:s,seqid:n,nresAlign:r}}parseAlignData_part1(e,t,i){let s=this.icn3d,n=s.icn3dui,r={},a={};s.chainid2refpdbname||(s.chainid2refpdbname={}),s.domainid2refpdbname||(s.domainid2refpdbname={}),s.domainid2score||(s.domainid2score={}),s.domainid2ig2kabat||(s.domainid2ig2kabat={}),s.domainid2ig2imgt||(s.domainid2ig2imgt={});for(let o=0,l=t.length;o<l;++o){let l=e[o]?e[o].value:void 0;if(!l||0==l.length){n.bNode||console.log("The alignment data for "+t[o]+" is unavailable...");continue}if(void 0===l[0].score)continue;let d=parseFloat(l[0].score),c=t[o].substr(0,t[o].indexOf("|")),h=t[o].substr(t[o].indexOf("|")+1);if(i){if(l[0].score<this.TMThresholdTemplate||l[0].num_res<10)continue}else if(l[0].score<this.TMThresholdTemplate||l[0].num_res<20){n.bNode||console.log("bRound1: "+i+": domainid "+c+" and refpdbname "+h+" were skipped due to a TM-score less than "+this.TMThresholdTemplate);continue}if(i?(n.bNode||console.log("domainid: "+c+" refpdbname "+h+" TM-score: "+l[0].score),a[c]||(a[c]={}),a[c][h]=d):n.bNode||console.log("refpdbname "+h+" TM-score: "+l[0].score),!i&&l[0].segs){let e=!1,t=!1,i=!1,r=!1,a=!0,o=!0,d=!0,p=!0,u=c.split(",")[0];for(let n=0,c=l[0].segs.length;n<c;++n){let c=l[0].segs[n],h=u+"_"+c.t_start,m=parseInt(c.q_start);if(m>2540&&m<2560?e=!0:m>3540&&m<3560?t=!0:m>7540&&m<7560?i=!0:m>8540&&m<8560&&(r=!0),2550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(a=!1)}else if(3550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(o=!1)}else if(7550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(d=!1)}else if(8550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(p=!1)}if(e&&t&&i&&r)break}if(!(e&&t&&i&&r&&a&&o&&d&&p)){n.bNode||e&&t&&i&&r||console.log("Some of the Ig strands B, C, E, F are missing in the domain "+c+"..."),n.bNode||a&&o&&d&&p||console.log("Some of the Ig strands B, C, E, F are not beta sheets..."),s.domainid2refpdbname[c][0]==h&&(delete s.domainid2refpdbname[c],delete s.domainid2score[c]);continue}}i||n.bNode||console.log("domainid: "+c),(!r.hasOwnProperty(c)||d>=parseFloat(s.domainid2score[c].split("_")[0]))&&(s.domainid2score[c]=l[0].score+"_"+l[0].frac_identical+"_"+l[0].num_res,s.domainid2refpdbname[c]=i?d>=this.TMThresholdIgType?[h]:["all_templates"]:[h],r[c]=l[0].segs,s.domainid2ig2kabat[c]=l[0].ig2kabat,s.domainid2ig2imgt[c]=l[0].ig2imgt)}if(i)for(let e in a)if(!n.bNode&&"all_templates"==s.domainid2refpdbname[e][0]){let t=a[e],i=Object.keys(t);i.sort((function(e,i){return t[i]-t[e]})),s.domainid2refpdbname[e]=i.slice(0,this.topClusters)}return r}async parseAlignData(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=!1,o=this.parseAlignData_part1(e,t,i);if(0==Object.keys(o).length)return a=!0,a;if(i){r.bNode||console.log("Start round 2 alignment with the reference culsters "+JSON.stringify(n.domainid2refpdbname));let e=[],t=[],i=r.htmlCls.tmalignUrl;for(let a in n.domainid2refpdbname){let o=[],l=n.domainid2refpdbname[a],d=a.substr(0,a.indexOf(","));n.refpdbHash.hasOwnProperty(d)&&0==s&&(l=[d],r.bNode||console.log("Adjusted refpdbname for domainid "+a+": "+d));let c=[];for(let e=0,t=l.length;e<t;++e){let t=l[e];n.refpdbHash[t]&&(c=c.concat(n.refpdbHash[t]))}if(0==c.length)continue;for(let e=0,t=c.length;e<t;++e){let t=r.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+c[e],i=r.getAjaxPromise(t,"text");o.push(i)}let h=await this.promiseWithFixedJobs(o),p=n.domainid2pdb[a];for(let s=0,o=h.length;s<o;++s){let o=n.defaultPdbId+s,l=h[s].value;l="HEADER "+o+"\n"+l;let d={pdb_query:l,pdb_target:p,queryid:c[s]},u=r.getAjaxPostPromise(i,d);e.push(u),t.push(a+"|"+c[s])}}let o=[];return o=await this.promiseWithFixedJobs(e),a=await this.parseAlignData(o,t,!1,s),a}return this.parseAlignData_part3(o),a}parseAlignData_part3(e){let t=this.icn3d,i=t.icn3dui,s={};for(let e in t.domainid2refpdbname){if("1"==t.domainid2refpdbname[e][0].substr(0,1)){delete t.domainid2refpdbname[e],delete t.domainid2score[e];continue}let i=e.split(",")[0];s.hasOwnProperty(i)||(t.chainid2refpdbname[i]=[]),s[i]=1,t.chainid2refpdbname.hasOwnProperty(i)||(t.chainid2refpdbname[i]=[]),t.chainid2refpdbname[i].push(t.domainid2refpdbname[e][0]+"|"+e)}t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={}),t.domainid2info||(t.domainid2info={});for(let s in e){let n=e[s],r=s.split(",")[0],a=this.getTemplateList(s),o=a.refpdbname,l=a.score,d=a.seqid,c=a.nresAlign;if(o){let e="The reference PDB for domain "+s+" is "+o+". The TM-score is "+l+". The sequence identity is "+d+". The number of aligned residues is "+c+".";i.bNode||(console.log(e),i.htmlCls.clickMenuCls.setLogCmd(e,!1,!0)),t.domainid2info[s]={refpdbname:o,score:l,seqid:d,nresAlign:c}}let h,p,u,m,f,g,b=!1,C=!1,v=!1,_=!1,y=!1,S=[],w=[],x=[],A=[];for(let e=0,s=n.length;e<s;++e){let s=n[e];if(!s)continue;let a=r+"_"+s.t_start;if(-1!=s.q_start.indexOf("3550")?(b=!0,h=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]),f=0):-1!=s.q_start.indexOf("4550")?(C=!0,p=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]),++f):-1!=s.q_start.indexOf("6550")?(_=!0,u=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]),++f):-1!=s.q_start.indexOf("7550")&&(y=!0,m=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a])),s.q_start>=3545&&s.q_start<=3555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]);e&&S.push(e)}else if(s.q_start>=7545&&s.q_start<=7555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]);e&&w.push(e)}if(-1!=s.q_start.indexOf("8550")&&1==f&&h&&m&&(p||u)){let e=999,t=999;for(let t=0,i=S.length;t<i;++t){let i=C?p.coord.distanceTo(S[t].coord):u.coord.distanceTo(S[t].coord);i<e&&(e=i)}for(let e=0,i=w.length;e<i;++e){let i=C?p.coord.distanceTo(w[e].coord):u.coord.distanceTo(w[e].coord);i<t&&(t=i)}e=parseInt(e),t=parseInt(t);let s=C?parseInt(p.resi)-parseInt(h.resi):parseInt(u.resi)-parseInt(h.resi),n=C?parseInt(m.resi)-parseInt(p.resi):parseInt(m.resi)-parseInt(u.resi),r=1;C?(e>t+r||e==t+r&&s>n+r)&&(x.push(p.resi),i.bNode||console.log("Rename strand C' to D: distToC "+e+" distToE "+t+" resiDistToC "+s+" resiDistToE "+n)):_&&(e+r<t||e+r==t&&s+r<n)&&(A.push(u.resi),i.bNode||console.log("Rename strand D to C': distToC "+e+" distToE "+t+" resiDistToC "+s+" resiDistToE "+n))}if(b&&C&&v&&_&&y)break}for(let e=0,i=n.length;e<i;++e){let i=n[e];if(!i)continue;i.q_start;let a=parseInt(i.q_start),o="";isNaN(i.q_start)&&(o=i.q_start.substr(i.q_start.length-1,1));let l=r+"_"+i.t_start,d=a,c=this.getLabelFromRefnum(d,o);g=c?c.replace(new RegExp(d,"g"),""):void 0;let h=g;if("C'"==g&&x.length>0){for(let e=0,t=x.length;e<t;++e)if(parseInt(i.t_start)<parseInt(x[e])+10&&parseInt(i.t_start)>parseInt(x[e])-10){h="D";break}}else if("D"==g&&A.length>0)for(let e=0,t=A.length;e<t;++e)if(parseInt(i.t_start)<parseInt(A[e])+10&&parseInt(i.t_start)>parseInt(A[e])-10){h="C'";break}g!=h&&(c=this.getLabelFromRefnum(d,o,h)),"helix"!=t.firstAtomObjCls.getFirstAtomObj(t.residues[l]).ss&&(t.resid2refnum[l]=c,t.resid2domainid[l]=s)}}Object.keys(t.resid2refnum).length>0?t.bShowRefnum=!0:i.bNode||t.bNoIg||(console.log("No Ig reference numbers are assigned based on the reference structures in iCn3D..."),t.bNoIg=!0)}getStrandFromRefnum(e,t){this.icn3d.icn3dui;let i,s=parseInt(e);return i=s<1e3?void 0:s>=1200&&s<1320?"A---":s>=1320&&s<1420?"A--":s>=1420&&s<1520?"A-":s>=1520&&s<1620?"A":s>=1620&&s<1720?"A+":s>=1720&&s<1820?"A++":s>=1820&&s<2e3?"A'":s>=2e3&&s<3e3?"B":s>=3e3&&s<3420?"C--":s>=3420&&s<3520?"C-":s>=3520&&s<4e3?"C":s>=4e3&&s<5e3?"C'":s>=5e3&&s<6e3?"C''":s>=6e3&&s<7e3?"D":s>=7e3&&s<7620?"E":s>=7620&&s<8e3?"E+":s>=8e3&&s<9e3?"F":s>=9e3&&s<9620?"G":s>=9620&&s<9720?"G+":s>=9720&&s<9820?"G++":s>=9820&&s<9900?"G+++":s>9900?void 0:" ",t&&(i=t),i}getLabelFromRefnum(e,t,i){this.icn3d.icn3dui;let s=this.getStrandFromRefnum(e,i),n=e.toString();return"C'"==i&&"6"==n.substr(0,1)?n="4"+n.substr(1):"D"==i&&"4"==n.substr(0,1)&&(n="6"+n.substr(1)),s?s+n+t:void 0}async parseCustomRefFile(e){let t=this.icn3d;t.icn3dui,t.bShowCustomRefnum=!0;let i=e.split("\n");t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={});let s=[];for(let e=0,t=i.length;e<t;++e){let t=i[e].split(",");s.push(t)}for(let e=1,i=s[0].length;e<i;++e){if(!s[0][e])continue;let i=s[0][e].trim();if(i)for(let n=1,r=s.length;n<r;++n){if(!s[n][e])continue;let r=s[n][0].trim()+"_"+s[n][e].trim();t.refnum2residArray[i]?t.refnum2residArray[i].push(r):t.refnum2residArray[i]=[r]}}for(let e=1,i=s.length;e<i;++e){let i=s[e][0].trim();for(let n=1,r=s[e].length;n<r;++n){if(!s[e][n]||!s[0][n])continue;let r=s[e][n].trim(),a=s[0][n].trim();t.chainsMapping.hasOwnProperty(i)||(t.chainsMapping[i]={});let o=i+"_"+r;r&&a?(t.resid2refnum[o]=a,t.chainsMapping[i][o]=a):t.chainsMapping[i][o]=r}}await t.showAnnoCls.showAnnotations(),t.annotationCls.setAnnoViewAndDisplay("detailed view")}rmStrandFromRefnumlabel(e){return this.icn3d.icn3dui,e&&isNaN(e.substr(0,1))&&e?e.replace(/'/g,"").replace(/\*/g,"").replace(/\^/g,"").replace(/\+/g,"").replace(/\-/g,"").substr(1):e}exportRefnum(e,t){let i=this.icn3d,s=i.icn3dui,n="";if("igstrand"==e||"IgStrand"==e){if(i.bShowRefnum)for(let e in i.chains){let t=i.firstAtomObjCls.getFirstAtomObj(i.chains[e]);if(i.proteins.hasOwnProperty(t.serial)){let t=[];for(let s=0;s<i.chainsSeq[e].length;++s)t.push(i.chainsSeq[e][s].name);i.annoIgCls.showRefNum(t,e)}}let e={};for(let t in i.resid2refnum){let n=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(!n)continue;let r=s.utilsCls.residueName2Abbr(n.resn.substr(0,3)),a=i.resid2domainid[t],o=i.resid2refnum[t];if(o){let e=i.refnumCls.rmStrandFromRefnumlabel(o);i.domainid2ig2kabat[a]&&i.domainid2ig2kabat[a][e]}i.resid2refnum[t]&&(i.residIgLoop.hasOwnProperty(t)?e[t+"_"+r]=i.resid2refnum[t]+"_loop":e[t+"_"+r]=i.resid2refnum[t])}for(let t in i.structures){let s=0,r="";for(let n=0,a=i.structures[t].length;i.bShowRefnum&&n<a;++n){let a=i.structures[t][n],o=i.chain2igArray[a];if(o&&o.length>0){r+='{"'+a+'": {\n';for(let t=0,n=o.length;t<n;++t){let n=o[t].startPosArray,l=o[t].endPosArray,d=o[t].domainid,c=i.domainid2info[d];if(c){r+='"'+d+'": {\n',r+='"refpdbname":"'+c.refpdbname+'", "score":'+c.score+', "seqid":'+c.seqid+', "nresAlign":'+c.nresAlign+', "data": [';for(let t=0,s=n.length;t<s;++t){let s=n[t],o=l[t];for(let t=s;t<=o;++t){const s=a+"_"+i.chainsSeq[a][t].resi+"_"+i.chainsSeq[a][t].name;r+='{"'+s+'": "'+e[s]+'"},\n'}}r+="],\n",r+="},\n",s=1}}r+="}},\n"}}n+='{"'+t+'": {"Ig domain" : '+s+', "igs": [\n',s&&(n+=r),n+="]}},\n"}}else if("kabat"==e||"Kabat"==e){let e={};for(let t in i.resid2refnum){let n,r=i.resid2domainid[t],a=i.resid2refnum[t],o=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(!o)continue;let l=s.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(a){let e=i.refnumCls.rmStrandFromRefnumlabel(a);n=i.domainid2ig2kabat[r]?i.domainid2ig2kabat[r][e]:void 0}e[t+"_"+l]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}else if("imgt"==e||"IMGT"==e){let e={};for(let t in i.resid2refnum){let n,r=i.resid2domainid[t],a=i.resid2refnum[t],o=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(!o)continue;let l=s.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(a){let e=i.refnumCls.rmStrandFromRefnumlabel(a);n=i.domainid2ig2imgt[r]?i.domainid2ig2imgt[r][e]:void 0}e[t+"_"+l]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}if(t||(n="["+n+"]"),s.bNode)return n;{let t=Object.keys(s.utilsCls.getHlStructures()).join(",");i.saveFileCls.saveFile(t+"_refnum_"+e+".txt","text",[n])}}async promiseWithFixedJobs(e){let t=this.icn3d,i=t.icn3dui;i.bNode||i.icn3d.ParserUtilsCls.showLoading();let s=[],n=i.cfg.maxajax?i.cfg.maxajax:6*t.refpdbArray.length;for(let t=0,i=parseInt((e.length-1)/n+1);t<i;++t){let r=[];r=t==i-1?e.slice(t*n,e.length):e.slice(t*n,(t+1)*n);let a=Promise.allSettled(r),o=await a;s=s.concat(o)}return i.bNode||i.icn3d.ParserUtilsCls.hideLoading(),s}ajdustRefnum(e,t){let i=this.icn3d,s=i.icn3dui;if(!i.chainid2refpdbname[t])return!1;let n,r,a,o,l,d,c,h,p="",u="",m="",f=!1,g=!1,b=1,C=!1;if(!s.bNode){let e=s.hashUtilsCls.intHash(i.chains[t],i.hAtoms);i.firstAtomObjCls.getResiduesFromAtoms(e)}let v=[],_={},y=0,S=0,w=0,x=0,A=!1;for(let s=0,M=e.length;s<M;++s,++S,++w,++x){let e,M=i.ParserUtilsCls.getResi(t,s),T=t+"_"+M;n=i.resid2refnum[T];let E=n?n.substr(0,1):"";if(C||!n||"A"!=E&&"B"!=E||(C=!0,S=1,A=!1),"G"!=u.substr(0,1)||n||(C=!1),n){e=i.resid2domainid[T],r=i.refnumCls.rmStrandFromRefnumlabel(n),p=n.replace(new RegExp(r,"g"),""),r.substr(0,1),a=r,d=parseInt(a),c=(d-1e3*parseInt(d/1e3)).toString(),h=(d-100*parseInt(d/100)).toString(),g="9"==c.substr(0,1)||"9"==h.substr(0,1)||"0"==h.substr(0,1)||"1"==h.substr(0,1),g&&(i.residIgLoop[T]=1),l=a.replace(d.toString(),""),o=l+"_"+b;let t=parseInt(d.toString().substr(0,2));if(f="5"!=c.substr(0,1)&&"18"!=t,p&&" "!=p){if(!g||f&&!g){let t=parseInt(d.toString().substr(d.toString().length-2,2));if(p!=u&&p!=m){if(A=!1,_[p+o]&&(++b,o=a.replace(d.toString(),"")+"_"+b),_[p+o]=1,v[y]={},v[y].startResi=M,v[y].startRefnum=d,w=0,v[y].domainid=e,v[y].endResi=M,v[y].endRefnum=d,50==t&&(v[y].anchorRefnum=d,v[y].resCntBfAnchor=w,x=0,A=!0),!A&&t>=46&&t<=54){let e=t-50;v[y].anchorRefnum=d-e,v[y].resCntBfAnchor=w-e,x=e,A=!0}f&&(v[y].anchorRefnum=0),v[y].strandPostfix=l,v[y].strand=p,v[y].postfix=o,v[y].loopResCnt=S-1,++y,S=0}else if(_[p+o]){if(50==t&&(v[y-1].anchorRefnum=d,v[y-1].resCntBfAnchor=w,v[y-1].startRefnum=v[y-1].anchorRefnum-v[y-1].resCntBfAnchor,x=0,A=!0),!A&&(51==t||52==t||53==t||54==t)){let e=t-50;v[y-1].anchorRefnum=d-e,v[y-1].resCntBfAnchor=w-e,v[y-1].startRefnum=v[y-1].anchorRefnum-v[y-1].resCntBfAnchor,x=e,A=!0}f&&(v[y-1].anchorRefnum=0),v[y-1].domainid=e,v[y-1].endResi=M,v[y-1].endRefnum=d,v[y-1].resCntAtAnchor=x,v[y-1].anchorRefnum&&(v[y-1].endRefnum=v[y-1].anchorRefnum+v[y-1].resCntAtAnchor),S=0}}m=p}}u=p}for(let e=0,s=v.length;e<s;++e){let n=i.firstAtomObjCls.getFirstAtomObj(i.residues[t+"_"+v[e].startResi]),r=i.firstAtomObjCls.getFirstAtomObj(i.residues[t+"_"+v[e].endResi]),a=i.setSeqAlignCls.getPosFromResi(t,v[e].startResi),o=i.setSeqAlignCls.getPosFromResi(t,v[e].endResi);if("sheet"==n.ss&&!n.ssbegin)for(let s=1;s<=8;++s){let n=a-s,r=i.ParserUtilsCls.getResi(t,n);if(e>0&&parseInt(r)<=parseInt(v[e-1].endResi))break;let o=t+"_"+r,l=i.firstAtomObjCls.getFirstAtomObj(i.residues[o]),d=i.resid2domainid[o];if(l.ssbegin){let o=v[e].startRefnum;v[e].startResi=r,v[e].startRefnum-=s,v[e].loopResCnt-=s,v[e].loopResCnt<0&&(v[e].loopResCnt=0),v[e].resCntBfAnchor+=s;for(let l=1;l<=s;++l){n=a-l,r=i.ParserUtilsCls.getResi(t,n);let s=t+"_"+r;delete i.residIgLoop[s],i.resid2refnum[s]=v[e].strand+(o-l).toString(),i.resid2domainid[s]=d}break}}if("sheet"==r.ss&&!r.ssend)for(let n=1;n<=8;++n){let r=o+n,a=i.ParserUtilsCls.getResi(t,r);if(e<s-1&&parseInt(a)>=parseInt(v[e+1].startResi))break;let l=t+"_"+a,d=i.firstAtomObjCls.getFirstAtomObj(i.residues[l]),c=i.resid2domainid[l];if(d.ssend){let l=v[e].endRefnum;v[e].endResi=a,v[e].endRefnum+=n,e<s-1&&(v[e+1].loopResCnt-=n,v[e+1].loopResCnt<0&&(v[e+1].loopResCnt=0)),v[e].resCntAtAnchor+=n;for(let s=1;s<=n;++s){r=o+s,a=i.ParserUtilsCls.getResi(t,r);let n=t+"_"+a;delete i.residIgLoop[n],i.resid2refnum[n]=v[e].strand+(l+s).toString(),i.resid2domainid[n]=c}break}}}let M={};for(let e=v.length-1;e>=0;--e){"G"!=v[e].strand&&v[e].endRefnum-v[e].startRefnum+1<3&&(v[e+1]&&(v[e+1].loopResCnt+=v[e].loopResCnt+parseInt(v[e].endResi)-parseInt(v[e].startResi)+1),v[e].startResi,v.splice(e,1))}y=0;let T,E,R=0,k=!0,O=!0,I=0;C=!1;let P=0;if(v.length>0)for(let s=0,r=e.length;s<r;++s,++R,++P){let e,r=i.ParserUtilsCls.getResi(t,s),o=t+"_"+r;if(n=i.resid2refnum[o],p=v[y].strand,n){e=i.resid2domainid[o],a=i.refnumCls.rmStrandFromRefnumlabel(n),E=parseInt(a),T=p+E,p=n.replace(new RegExp(a,"g"),"");let t=n.substr(0,1);C||"A"!=t&&"B"!=t||(C=!0,k=!0,R=0)}let l=i.firstAtomObjCls.getFirstAtomObj(i.residues[o]);if(l&&i.proteins.hasOwnProperty(l.serial)){let t=!1,s=!1,a=!1;if(t=parseInt(r)==parseInt(v[y].startResi)&&r!=v[y].startResi?r<v[y].startResi:parseInt(r)<parseInt(v[y].startResi),a=parseInt(r)==parseInt(v[y].endResi)&&r!=v[y].endResi?r>v[y].endResi:parseInt(r)>parseInt(v[y].endResi),s=!t&&!a,t)if(i.residIgLoop[o]=1,k)C?(E=v[y].startRefnum-v[y].loopResCnt+R,T=v[y].strand+E,n=T+v[y].strandPostfix,e=v[y].domainid):(T=void 0,n=void 0);else if(I>=0&&("G"==v[I].strand.substr(0,1)||"F"==v[I].strand.substr(0,1)&&"G"!=v[y].strand.substr(0,1)))O?C&&i.resid2refnum[o]?(O=!0,E=v[I].endRefnum+R,T=v[I].strand+E,n=T+v[I].strandPostfix,e=v[I].domainid):(C=!1,k=!0,O=!1,T=void 0,n=void 0):(T=void 0,n=void 0);else{O=!0;let t=v[y].loopResCnt;R<=parseInt(t/2+.5)?v[I]&&(E=v[I].endRefnum+R,T=v[I].strand+E,n=T+v[I].strandPostfix,e=v[I].domainid):(E=v[y].startRefnum-t+R-1,T=v[y].strand+E,n=T+v[y].strandPostfix,e=v[y].domainid)}else s?(k=!1,v[y].anchorRefnum&&(r==v[y].startResi?(P=v[y].anchorRefnum-v[y].resCntBfAnchor,v[y].startRefnum=P):r==v[y].endResi&&(v[y].endRefnum=P),T=v[y].strand+P,n=T+v[y].strandPostfix,e=v[y].domainid),r==v[y].endResi&&(++y,R=0,v[y]||--y)):a&&(i.residIgLoop[o]=1,O?i.resid2refnum[o]?(O=!0,E=v[y].endRefnum+R,T=v[y].strand+E,n=T+v[y].strandPostfix,e=v[y].domainid):(O=!1,T=void 0,n=void 0):(T=void 0,n=void 0))}else n=void 0;u=p,I=y-1,M.hasOwnProperty(e)?(delete i.resid2refnum[o],delete i.residIgLoop[o],delete i.resid2domainid[o]):(i.resid2refnum[o]=n,i.resid2domainid[o]=e,a=i.refnumCls.rmStrandFromRefnumlabel(n),i.refnum2residArray.hasOwnProperty(a)?i.refnum2residArray[a].push(o):i.refnum2residArray[a]=[o],i.chainsMapping.hasOwnProperty(t)||(i.chainsMapping[t]={}),i.chainsMapping[t][o]=T||r)}return!0}}class np{constructor(e){this.icn3d=e}async applyCommandScap(e){this.icn3d.icn3dui;let t=e.substr(e.lastIndexOf(" ")+1);0==e.indexOf("scap 3d")?await this.retrieveScap(t):0==e.indexOf("scap interaction")?await this.retrieveScap(t,!0):0==e.indexOf("scap pdb")&&await this.retrieveScap(t,void 0,!0)}adjust2DWidth(e){let t,i,s,n=this.icn3d;if(n.icn3dui,e=n.pre+e,$("#"+n.pre+"dl_selectannotations").hasClass("ui-dialog-content")){t=$("#"+n.pre+"dl_selectannotations").dialog("option","width"),i=.5*$("#"+n.pre+"dl_selectannotations").dialog("option","height"),s=i,$("#"+n.pre+"dl_selectannotations").dialog("option","height",i),$("#"+e).dialog("option","width",t),$("#"+e).dialog("option","height",i);let r={my:"left top",at:"right top+"+s,of:"#"+n.pre+"viewer",collision:"none"};$("#"+e).dialog("option","position",r)}}async retrieveScap(e,t,i){let s=this.icn3d,n=s.icn3dui,r=this;s.bScap=!0;let a="",o=e.split(","),l={},d=[],c={};for(let e=0,t=o.length;e<t;++e){let i=o[e].split("_"),r=i[0]+"_"+i[1]+"_"+i[2];l=n.hashUtilsCls.unionHash(l,s.residues[r]),d.push(r),c[i[1]+"_"+i[2]]="",a+=i[1]+"_"+i[2]+"_"+i[3],e!=t-1&&(a+=",")}let h=s.resid2specCls.residueids2spec(d),p="select "+h,u=s.showInterCls.pickCustomSphere_base(10,l,s.atoms,!1,!1,void 0,p,!1),m=Object.keys(u.residues);s.hAtoms={};for(let e=0,t=m.length;e<t;++e){let t=m[e];for(let e in s.residues[t])s.hAtoms[e]=1}s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,l),s.hAtoms=n.hashUtilsCls.exclHash(s.hAtoms,s.chemicals);let f,g=s.saveFileCls.getAtomPDB(s.hAtoms),b=n.htmlCls.baseUrl+"scap/scap.cgi",C=Object.keys(s.structures)[0],v={pdb:g,snp:a,pdbid:C,v:"2"};f=await n.getAjaxPostPromise(b,v,!0,void 0,void 0,void 0,"text");let _=f.indexOf("\n"),y=f.substr(0,_),S=f.substr(_+1);console.log("free energy: "+y+" kcal/mol");let w=n.hashUtilsCls.cloneHash(s.hAtoms);for(let e in w){let t=s.atoms[e],i=t.structure+"_"+t.chain,r=i+"_"+t.resi;s.chainsMapping.hasOwnProperty(i)||(s.chainsMapping[i]={}),s.chainsMapping[i][r]=n.utilsCls.residueName2Abbr(t.resn)+t.resi}let x=S.split("\n"),A={};for(let e in x){let t=x[e],i=t.substr(0,6);if("ATOM "===i||"HETATM"===i){let e=t.substr(20,2).trim();""===e&&(e="A");let i=e+"_"+t.substr(22,5).trim();c.hasOwnProperty(i)&&(c[i]+=t+"\n"),A[i]=1}}let M=s.saveFileCls.getAtomPDB(s.atoms,!1,!1,!1,c);s.hAtoms={};s.loadPDBCls.loadPDB(M,C,!1,!1,!0,!0);for(let e in s.residues){if(e.substr(0,e.indexOf("_"))==C+"2"){let t=C+e.substr(e.indexOf("_")),i=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(i)for(let t in s.residues[e])s.atoms[t].ss=i.ss,s.atoms[t].ssbegin=i.ssbegin,s.atoms[t].ssend=i.ssend}}for(let e in s.secondaries){if(e.substr(0,e.indexOf("_"))==C+"2"){let t=C+e.substr(e.indexOf("_"));s.secondaries[e]=s.secondaries[t]}}s.setStyleCls.setAtomStyleByOptions(s.opts),s.setColorCls.setColorByOptions(s.opts,s.hAtoms);let T={};for(let e in s.hAtoms){let t=s.atoms[e],i=t.chain+"_"+t.resi;A.hasOwnProperty(i)&&(T[e]=1)}s.hAtoms=n.hashUtilsCls.unionHash(w,T),s.dAtoms=n.hashUtilsCls.cloneHash(s.hAtoms),s.transformCls.zoominSelection(),s.setOptionCls.setStyle("proteins","stick");for(let e in T){let t=s.atoms[e];if(!t.het){let i=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi,n=s.firstAtomObjCls.getFirstAtomObj(s.residues[i]);n&&(s.atoms[e].color=n.color,s.atomPrevColors[e]=n.color)}let i=t.structure+"_"+t.chain,r=i+"_"+t.resi,a=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi;if(s.chainsMapping.hasOwnProperty(i)||(s.chainsMapping[i]={}),s.chainsMapping[i][r]=n.utilsCls.residueName2Abbr(t.resn)+t.resi,-1!=d.indexOf(a)){let e=s.firstAtomObjCls.getFirstAtomObj(s.residues[a]);s.chainsMapping[i][r]=n.utilsCls.residueName2Abbr(e.resn)+e.resi}}if(i)await r.exportPdbProfix(!1,M,a),s.drawCls.draw();else{let e=h,i="snp_"+a;if(await s.selByCommCls.selectByCommand(e,i,i),s.opts.color="atom",s.setColorCls.setColorByOptions(s.opts,s.hAtoms),s.viewInterPairsCls.clearInteractions(),t){let e="linegraph";await s.viewInterPairsCls.viewInteractionPairs(["selected"],["non-selected"],!1,e,!0,!0,!0,!0,!0,!0),r.adjust2DWidth("dl_linegraph")}s.hAtoms=s.dAtoms,s.drawCls.draw(),n.alertAlt||(n.alertAlt=!0,alert('Please press the letter "a" to alternate between wild type and mutant.'))}$("#"+s.pre+"mn2_alternateWrap").show();let E=s.pre+"selection";$("#"+E).show()}async exportPdbProfix(e,t,i){let s,n=this.icn3d,r=n.icn3dui;if(t)s=t;else{let e=r.hashUtilsCls.intHash(n.dAtoms,n.hAtoms),t=!0;s=n.saveFileCls.getAtomPDB(e,void 0,void 0,void 0,void 0,void 0,t)}let a,o=r.htmlCls.baseUrl+"scap/scap.cgi",l={pdb:s,profix:"1",hydrogen:e?"1":"0"};try{a=await r.getAjaxPostPromise(o,l,void 0,void 0,void 0,void 0,"text")}catch(e){return void alert("There are some problems in adding missing atoms or hydrogens...")}if(r.bNode)return a;{let t=Object.keys(r.utilsCls.getHlStructures()).join(","),s=e?"add_hydrogen":"add_missing_atoms";i&&(s=i),n.saveFileCls.saveFile(t+"_icn3d_"+s+".pdb","text",[a])}}}class rp{constructor(e){this.icn3d=e}async applyCommandSymd(e){this.icn3d.icn3dui,await this.retrieveSymd()}async retrieveSymd(){let e=this.icn3d,t=e.icn3dui,i=this,s=t.htmlCls.baseUrl+"symd/symd.cgi",n=t.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);n=t.hashUtilsCls.intHash(n,e.proteins);let r=Object.keys(n).length,a={};for(let t in n){let i=e.atoms[t];a[i.structure+"_"+i.chain+"_"+i.resi]=1}if(r>1e4)return void alert("The maximum number of allowed atoms is 10,000. Please try it again with smaller sets...");let o="";o+=e.saveFileCls.getAtomPDB(n);let l,d={pdb:o,pdbid:Object.keys(e.structures).toString()};try{l=await t.getAjaxPostPromise(s,d,!0);let n,r,o,c=l.rcsb_struct_symmetry,h="none";if(void 0!==c){let s;void 0!==e.rmsd_supr&&void 0!==e.rmsd_supr.rot&&(n=e.rmsd_supr.rot,r=e.rmsd_supr.trans1,o=e.rmsd_supr.trans2),void 0===e.symdArray&&(e.symdArray=[]);for(let t=0,n=c.length;t<n;++t){if("C1"==c[t].symbol)continue;h=c[t].symbol+" ","Pseudo Symmetry"==c[t].kind?h=c[t].symbol+" (pseudo)":"Global Symmetry"==c[t].kind?h=c[t].symbol+" (global)":"Local Symmetry"==c[t].kind&&(h=c[t].symbol+" (local)");let n=c[t].rotation_axes,r=[];for(let e=0,a=n.length;e<a;++e){let a=[],o=new mt(n[e].start[0],n[e].start[1],n[e].start[2]),l=new mt(n[e].end[0],n[e].end[1],n[e].end[2]);s=n[e].order,a.push(o),a.push(l);let d=i.getAxisColor(c[t].symbol,n[e].order),h=i.getPolygonColor(c[t].symbol);a.push(d),a.push(h),a.push(n[e].order),a.push("selection"),r.push(a)}let a={};a[h]=r,e.symdArray.push(a)}if(0==e.symdArray.length)$("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+l.zscore+" from the program <a href='https://symd.nci.nih.gov/' target='_blank'>SymD</a>."),t.htmlCls.dialogCls.openDlg("dl_symd","Dynamically Calculated Symmetry Using SymD");else{let n=l.seqalign.replace(/ /g,"").split(","),r=l.nres,o=l.shift,d=l.rmsd,h=Object.keys(a),p={},u={},m=[],f=[],g=0,b=0,C={};for(let e=0,i=n[0].length;e<i;++e){let i=n[0][e],s=n[1][e];if("-"!=i){if(i==i.toUpperCase()){p[h[g]]=1;let e=t.utilsCls.getIdArray(h[g]);m.push(i+" $"+e[0]+"."+e[1]+":"+e[2]);let s=e[0]+"_"+e[1];C.hasOwnProperty(s)||(C[s]=[]),C[s].push(m.length-1)}++g}if("-"!=s){if(s==s.toUpperCase()){let e=(b+o+r)%r;u[h[e]]=1;let i=t.utilsCls.getIdArray(h[e]);f.push(s+" $"+i[0]+"."+i[1]+":"+i[2])}++b}}let v={},_={},y=[],S=[],w=!1;if(1==Object.keys(C).length){w=!0;let e=parseInt(m.length/s+.5),t=Object.keys(p),i=Object.keys(u);for(let s=0;s<e;++s)v.hasOwnProperty(i[s])||(y.push(m[s]),S.push(f[s]),v[t[s]]=1,_[i[s]]=1)}else{let e,t=0;for(let i in C)C[i].length>t&&(t=C[i].length,e=i);let i=Object.keys(p),s=Object.keys(u);for(let t=0,n=C[e].length;t<n;++t){let n=C[e][t];v.hasOwnProperty(s[n])||(y.push(m[n]),S.push(f[n]),v[i[n]]=1,_[s[n]]=1)}}let x="<br>";x+="The symmetry "+c[0].symbol+" was calculated dynamically using the program <a href='https://symd.nci.nih.gov/' target='_blank'>SymD</a>. The Z score "+l.zscore+" is greater than the threshold Z score 8. The RMSD is "+d+' angstrom. <br><br>The following sequence alignment shows the residue mapping of the best aligned sets: "symOri" and "symPerm", which are also available in the menu "Analysis > Defined Sets".<br>',$("#"+e.pre+"symd_info").html(x),i.setSeqAlignForSymmetry(y,S,w);let A=!1,M=t.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(e.alnChains),void 0,void 0,A,w);x=$("#"+e.pre+"dl_sequence2").html()+M.sequencesHtml,$("#"+e.pre+"dl_sequence2").html(x),$("#"+e.pre+"dl_sequence2").width(t.htmlCls.RESIDUE_WIDTH*M.maxSeqCnt+200),t.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences from SymD");let T=Object.keys(e.defNames2Residues).length+Object.keys(e.defNames2Atoms).length,E="symOri"+T;e.selectionCls.selectResidueList(v,E,E),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(v))+" | name "+E,!1),E="symPerm"+T,e.selectionCls.selectResidueList(_,E,E),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(_))+" | name "+E,!1),E="symBoth"+T,v=t.hashUtilsCls.unionHash(v,_),e.selectionCls.selectResidueList(v,E,E),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(v))+" | name "+E,!1)}}else $("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+l.zscore+" from the program <a href='https://symd.nci.nih.gov/' target='_blank'>SymD</a>."),t.htmlCls.dialogCls.openDlg("dl_symd","Dynamically Calculated Symmetry Using SymD");e.symdtitle="none"===h?void 0:h,e.drawCls.draw()}catch(i){return $("#"+e.pre+"dl_symd").html("<br>The web service can not determine the symmetry of the input set."),t.htmlCls.dialogCls.openDlg("dl_symd","Dynamically Calculated Symmetry Using SymD"),void e.ParserUtilsCls.hideLoading()}}getResObj(e){this.icn3d.icn3dui;let t=e.substr(0,e.indexOf(" ")),i=e.indexOf("$"),s=e.indexOf("."),n=e.indexOf(":"),r=e.substr(i+1,s-i-1),a=e.substr(s+1,n-s-1),o=e.substr(n+1);return{resn:t,resid:r+"_"+a+"_"+o,resi:o,aligned:!0}}setSeqAlignForSymmetry(e,t,i){let s=this.icn3d,n=s.icn3dui;s.conservedName1="symOri_cons",s.conservedName2="symPerm_cons",s.consHash1={},s.consHash2={},s.alnChainsAnTtl={},s.alnChainsAnno={},s.alnChainsSeq={},s.alnChains={},s.alnChainsSeq={};let r={};for(let a=0,o=e.length;a<o;++a){let o,l=this.getResObj(e[a]),d=this.getResObj(t[a]),c=l.resid.substr(0,l.resid.lastIndexOf("_")),h=d.resid.substr(0,d.resid.lastIndexOf("_")),p=h;if(i){p=h.substr(0,h.indexOf("_"))+"2"+h.substr(h.indexOf("_"))}r[l.resid]=1,r[d.resid]=1,o=l.resn==d.resn?"#FF0000":"#0000FF";let u="#"+s.showAnnoCls.getColorhexFromBlosum62(l.resn,d.resn);l.color=o,d.color=o,l.color2=u,d.color2=u;for(let e in s.residues[l.resid])s.atoms[e].color=n.parasCls.thr(o),s.atomPrevColors[e]=n.parasCls.thr(o);for(let e in s.residues[d.resid])s.atoms[e].color=n.parasCls.thr(o),s.atomPrevColors[e]=n.parasCls.thr(o);void 0===s.alnChainsAnTtl[c]&&(s.alnChainsAnTtl[c]=[]);for(let e=0;e<3;++e)void 0===s.alnChainsAnTtl[c][e]&&(s.alnChainsAnTtl[c][e]=[]);for(let e=0;e<3;++e)s.alnChainsAnTtl[c][e].push("");void 0===s.alnChainsSeq[c]&&(s.alnChainsSeq[c]=[]),void 0===s.alnChainsSeq[p]&&(s.alnChainsSeq[p]=[]),s.alnChainsSeq[c].push(l),s.alnChainsSeq[p].push(d),void 0===s.alnChains[c]&&(s.alnChains[c]={}),void 0===s.alnChains[p]&&(s.alnChains[p]={}),$.extend(s.alnChains[c],s.residues[c+"_"+l.resi]),$.extend(s.alnChains[p],s.residues[p+"_"+d.resi]),s.consHash1[c+"_"+l.resi]=1,s.consHash2[p+"_"+d.resi]=1,void 0===s.alnChainsAnno[c]&&(s.alnChainsAnno[c]=[]);for(let e=0;e<3;++e)void 0===s.alnChainsAnno[c][e]&&(s.alnChainsAnno[c][e]=[]);let m=".";a%5==0&&(m="*"),a%10==0&&(m="|"),s.alnChainsAnno[c][0].push(m);let f="";a%10==0&&(f=a.toString()),s.alnChainsAnno[c][1].push(f)}}async retrieveSymmetry(e){let t,i=this.icn3d,s=i.icn3dui,n=this,r="https://data.rcsb.org/rest/v1/core/assembly/"+e+"/1";try{t=await s.getAjaxPromise(r,"json",!1)}catch(e){return $("#"+i.pre+"dl_symmetry").html("<br>This structure has no symmetry."),void s.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}let a,o,l,d=t.rcsb_struct_symmetry;if(void 0!==d){void 0!==i.rmsd_supr&&void 0!==i.rmsd_supr.rot&&(a=i.rmsd_supr.rot,o=i.rmsd_supr.trans1,l=i.rmsd_supr.trans2),i.symmetryHash={};for(let e=0,t=d.length;e<t;++e){if("C1"==d[e].symbol)continue;let t="no title";"Pseudo Symmetry"==d[e].kind?t=d[e].symbol+" (pseudo)":"Global Symmetry"==d[e].kind?t=d[e].symbol+" (global)":"Local Symmetry"==d[e].kind&&(t=d[e].symbol+" (local)");let s=d[e].rotation_axes,r=[];for(let t=0,c=s.length;t<c;++t){let c=[],h=new mt(s[t].start[0],s[t].start[1],s[t].start[2]),p=new mt(s[t].end[0],s[t].end[1],s[t].end[2]);void 0!==i.rmsd_supr&&void 0!==i.rmsd_supr.rot&&(h=i.surfaceCls.transformMemPro(h,a,o,l),p=i.surfaceCls.transformMemPro(p,a,o,l)),c.push(h),c.push(p);let u=n.getAxisColor(d[e].symbol,s[t].order),m=n.getPolygonColor(d[e].symbol);c.push(u),c.push(m),c.push(s[t].order),c.push(d[e].clusters[0].members[0].asym_id),r.push(c)}i.symmetryHash[t]=r}if(0==Object.keys(i.symmetryHash).length)$("#"+i.pre+"dl_symmetry").html("<br>This structure has no symmetry.");else{let e="<option value='none'>None</option>",t=0;for(let s in i.symmetryHash){e+="<option value='"+s+"' "+(0==t?"selected":"")+">"+s+"</option>",++t}$("#"+i.pre+"selectSymmetry").html(e)}}else $("#"+i.pre+"dl_symmetry").html("<br>This structure has no symmetry.");s.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}getPolygonColor(e){let t=this.icn3d.icn3dui,i=e.substr(0,1);return"C"==i?t.parasCls.thr(16747520):"D"==i?t.parasCls.thr(65535):"T"==i?t.parasCls.thr(15631086):"O"==i?t.parasCls.thr(16753920):"I"==i?t.parasCls.thr(65280):t.parasCls.thr(11119017)}getAxisColor(e,t){let i=this.icn3d.icn3dui,s=e.substr(0,1);return"C"==s?i.parasCls.thr(16711680):"D"==s?2==t?i.parasCls.thr(65535):i.parasCls.thr(16711680):"T"==s?2==t?i.parasCls.thr(65535):i.parasCls.thr(65280):"O"==s||"I"==s?2==t?i.parasCls.thr(65535):3==t?i.parasCls.thr(65280):i.parasCls.thr(16711680):i.parasCls.thr(16711680)}}class ap{constructor(e){this.icn3d=e}alignSW(e,t,i,s,n,r,a){this.icn3d.icn3dui;let o=this.bsa_align(a,e,t,[i,s],[n,r]),l="score: "+o[0]+"\n";l+="start: "+o[1]+"\n",l+="cigar: "+this.bsa_cigar2str(o[2])+"\n\n",l+="alignment:\n\n";let d=this.bsa_cigar2gaps(e,t,o[1],o[2]),c={};return c.score=o[0],c.start=o[1],c.cigar=this.bsa_cigar2str(o[2]),c.target=d[0],c.query=d[1],c}bsg_enc_seq(e,t){if(this.icn3d.icn3dui,null==t)return null;let i=[];i.length=e.length;for(let s=0;s<e.length;++s)i[s]=t[e.charCodeAt(s)];return i}bsa_gen_score_matrix(e,t,i){this.icn3d.icn3dui;let s,n,r=[];for(i>0&&(i=-i),s=0;s<e-1;++s){for(r[s]=[],n=0;n<e-1;++n)r[s][n]=s==n?t:i;r[s][n]=0}r[e-1]=[];for(let t=0;t<e;++t)r[e-1][t]=0;return r}bsa_gen_query_profile(e,t,i){this.icn3d.icn3dui;let s,n="string"==typeof e?this.bsg_enc_seq(e,i):e,r=[];if(t.length>=2&&"number"==typeof t[0]&&"number"==typeof t[1]){if(null==i)return null;let e="number"==typeof i?i:i[i.length-1]+1;s=this.bsa_gen_score_matrix(e,t[0],t[1])}else s=t;for(let e=0;e<s.length;++e){let t,i=s[e];t=r[e]=[];for(let e=0;e<n.length;++e)t[e]=i[n[e]]}return r}bsa_align(e,t,i,s,n,r,a){this.icn3d.icn3dui;null==a&&(a=[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,4,1,4,4,4,2,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,0,4,1,4,4,4,2,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4]);let o=this.bsg_enc_seq(t,a),l=this.bsa_gen_query_profile(i,s,a),d=l[0].length,c=d>o.length?d:o.length;r=null==r||r<0?c:r;let h,p,u=o.target>d?o.target-d:d-o.target;r=r>u?r:u,"number"==typeof n?(h=0,p=n>0?n:-n):(h=n[0]>0?n[0]:-n[0],p=n[1]>0?n[1]:-n[1]);let m,f=h+p,g=-1073741824,b=[],C=[],v=[],_=0,y=-1,S=-1;if(e)for(let e=0;e<=d;++e)b[e]=C[e]=0;else{b[0]=0,C[0]=-f-f;for(let e=1;e<=d;++e)e>=r?b[e]=C[e]=g:(b[e]=-(f+p*(e-1)),C[e]=-(f+f+p*e))}for(let t=0;t<o.length;++t){let i,s=0,n=0,a=0,c=-1,h=l[o[t]];i=v[t]=[];let u=t>r?t-r:0,m=t+r+1<d?t+r+1:d;e||(s=u>0?g:-(f+p*t),n=u>0?g:-(f+f+p*t));for(let t=u;t<m;++t){let r,o=C[t],l=b[t];b[t]=s,l+=h[t],r=l>=o?0:1,l=l>=o?l:o,r=l>=n?r:2,l=l>=n?l:n,r=!e||l>0?r:64,s=l,c=a>l?c:t,a=a>l?a:l,l-=f,l=!e||l>0?l:0,o-=p,r|=o>l?4:0,o=o>l?o:l,C[t]=o,n-=p,r|=n>l?32:0,n=n>l?n:l,i[t]=r}b[m]=s,C[m]=e?0:g,a>_&&(_=a,y=t,S=c)}if(e&&0==_)return null;m=e?_:b[d];let w,x,A,M=[],T=0,E=0;for(e?(x=y,A=S,S!=d-1&&this.push_cigar(M,4,d-1-S)):(x=o.length-1,A=(x+r+1<d?x+r+1:d)-1);x>=0&&A>=0&&(w=v[x][A-(x>r?x-r:0)],T=w>>(T<<1)&3,!(0==T&&w>>6));)0==T&&(T=3&w),0==T?(this.push_cigar(M,0,1),--x,--A):1==T?(this.push_cigar(M,2,1),--x):(this.push_cigar(M,1,1),--A);e?(A>=0&&this.push_cigar(M,4,A+1),E=x+1):(x>=0&&this.push_cigar(M,2,x+1),A>=0&&this.push_cigar(M,1,A+1));for(let e=0;e<M.length>>1;++e)w=M[e],M[e]=M[M.length-1-e],M[M.length-1-e]=w;return[m,E,M]}push_cigar(e,t,i){this.icn3d.icn3dui,0==e.length||t!=(15&e[e.length-1])?e.push(i<<4|t):e[e.length-1]+=i<<4}bsa_cigar2gaps(e,t,i,s){this.icn3d.icn3dui;let n="",r="",a="",o=0,l=i;for(let i=0;i<s.length;++i){let a=15&s[i],d=s[i]>>4;0==a?(n+=t.substr(o,d),r+=e.substr(l,d),o+=d,l+=d):1==a?(n+=t.substr(o,d),r+=Array(d+1).join("-"),o+=d):2==a?(n+=Array(d+1).join("-"),r+=e.substr(l,d),l+=d):4==a&&(o+=d)}let d=r.toUpperCase(),c=n.toUpperCase();for(let e=0;e<d.length;++e)a+=d.charAt(e)==c.charAt(e)?"|":" ";return[r,n,a]}bsa_cigar2str(e){this.icn3d.icn3dui;let t=[];for(let i=0;i<e.length;++i)t.push((e[i]>>4).toString()+"MIDNSHP=XB".charAt(15&e[i]));return t.join("")}}class op{constructor(e){this.icn3d=e}calculateArea(){var e=this.icn3d,t=e.icn3dui;e.bCalcArea=!0,e.opts.surface="solvent accessible surface",e.applyMapCls.applySurfaceOptions(),$("#"+e.pre+"areavalue").val(e.areavalue),$("#"+e.pre+"areatable").html(e.areahtml),t.htmlCls.dialogCls.openDlg("dl_area","Surface area calculation"),e.bCalcArea=!1}calcBuriedSurface(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length)alert("Please select the first set");else{let n=s.hashUtilsCls.cloneHash(i.hAtoms),r=i.definedSetsCls.getAtomsFromNameArray(e),a=i.definedSetsCls.getAtomsFromNameArray(t);i.bCalcArea=!0,i.opts.surface="solvent accessible surface",i.hAtoms=s.hashUtilsCls.cloneHash(r),i.applyMapCls.applySurfaceOptions();let o=i.areavalue,l=s.hashUtilsCls.cloneHash(i.resid2area);i.hAtoms=s.hashUtilsCls.cloneHash(a),i.applyMapCls.applySurfaceOptions();let d=i.areavalue,c=s.hashUtilsCls.cloneHash(i.resid2area);i.hAtoms=s.hashUtilsCls.unionHash(i.hAtoms,r),i.applyMapCls.applySurfaceOptions();let h=i.areavalue,p=s.hashUtilsCls.cloneHash(i.resid2area),u=0,m=0,f=0,g=0;for(let e in l)p.hasOwnProperty(e)&&(g+=parseFloat(p[e]));m=(o-g).toFixed(2);for(let e in c)p.hasOwnProperty(e)&&(f+=parseFloat(p[e]));u=(d-f).toFixed(2),i.bCalcArea=!1,i.hAtoms=s.hashUtilsCls.cloneHash(n);let b=(parseFloat(d)+parseFloat(o)-parseFloat(h)).toFixed(2),C="<br>Calculate solvent accessible surface area in the interface:<br><br>";C+="Set 1: "+e+", Surface: "+o+" Å<sup>2</sup><br>",C+="Set 2: "+t+", Surface: "+d+" Å<sup>2</sup><br>",C+="Total Surface: "+h+" Å<sup>2</sup><br>",C+="<b>Buried Surface for Set 1</b>: "+m+" Å<sup>2</sup><br>",C+="<b>Buried Surface for Set 2</b>: "+u+" Å<sup>2</sup><br><br>",$("#"+i.pre+"dl_buriedarea_html").html(C),s.htmlCls.dialogCls.openDlg("dl_buriedarea","Buried solvent accessible surface area in the interface"),s.htmlCls.clickMenuCls.setLogCmd("buried surface "+b,!1)}}measureDistTwoSets(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length||0==t.length)alert("Please select two sets");else{let n=s.hashUtilsCls.cloneHash(i.hAtoms),r=i.definedSetsCls.getAtomsFromNameArray(e),a=i.definedSetsCls.getAtomsFromNameArray(t),o=i.contactCls.getExtent(r),l=i.contactCls.getExtent(a),d=new mt(o[2][0],o[2][1],o[2][2]),c=new mt(l[2][0],l[2][1],l[2][2]);i.hAtoms=s.hashUtilsCls.cloneHash(n),void 0===i.distPnts&&(i.distPnts=[]),i.distPnts.push(d),i.distPnts.push(c);let h=$("#"+i.pre+"distancecolor2").val();this.addLine(d.x,d.y,d.z,c.x,c.y,c.z,h,!0,"distance");let p=0,u=0,m=d.clone().add(c).multiplyScalar(.5),f=(parseInt(10*d.distanceTo(c))/10).toString()+" A";this.addLabel(f,m.x,m.y,m.z,p,h,u,"distance"),i.drawCls.draw()}}measureDistManySets(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for distance calculation...");else{let n=s.hashUtilsCls.cloneHash(i.hAtoms),r={};for(let s=0,n=e.length;s<n;++s){let n=e[s],a=[n];r[n]={};for(let e=0,s=t.length;e<s;++e){let s=t[e],o=[s];if(n==s)continue;let l=i.definedSetsCls.getAtomsFromNameArray(a),d=i.definedSetsCls.getAtomsFromNameArray(o),c=i.contactCls.getExtent(l),h=i.contactCls.getExtent(d),p=new mt(c[2][0],c[2][1],c[2][2]),u=new mt(h[2][0],h[2][1],h[2][2]),m=p.distanceTo(u);r[n][s]=m.toFixed(2)}}i.hAtoms=s.hashUtilsCls.cloneHash(n);let a="Note: Click on the distance to show a dashed line in 3D view.<br><br>";a+="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,i=t.length;e<i;++e){a+="<th><b>"+t[e]+"</b> (Å)</th>"}a+="</tr>";for(let i=0,s=e.length;i<s;++i){let s=e[i];a+="<tr><th><b>"+s+"</b> (Å)</th>";for(let e=0,i=t.length;e<i;++e){let i=t[e];r[s]&&r[s][i]?a+='<td><span class="icn3d-distance" sets="'+s+"|"+i+'">'+r[s][i]+"</span></td>":a+="<td>0</td>"}a+="</tr>"}a+="</table><br><br>",$("#"+s.pre+"dl_disttable_html").html(a)}}measureAngleManySets(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for angleance calculation...");else{let n={};for(let s=0,r=e.length;s<r;++s){let r=e[s],a=[r];n[r]={},i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(a);let o=i.axesCls.setPc1Axes(!0);for(let e=0,s=t.length;e<s;++e){let s=t[e],a=[s];if(r==s)continue;i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(a);let l=i.axesCls.setPc1Axes(!0),d=new mt(parseFloat(o.x),parseFloat(o.y),parseFloat(o.z)).angleTo(new mt(parseFloat(l.x),parseFloat(l.y),parseFloat(l.z)))/3.1416*180;d=Math.abs(d).toFixed(0),d>180&&(d-=180),d>90&&(d=180-d),n[r][s]=d}}let r="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,i=t.length;e<i;++e){r+="<th><b>"+t[e]+"</b> (°)</th>"}r+="</tr>";for(let i=0,s=e.length;i<s;++i){let s=e[i];r+="<tr><th><b>"+s+"</b> (°)</th>";for(let e=0,i=t.length;e<i;++e){let i=t[e];n[s]&&n[s][i]?r+="<td><span>"+n[s][i]+"</span></td>":r+="<td>0</td>"}r+="</tr>"}r+="</table><br><br>",$("#"+s.pre+"dl_angletable_html").html(r)}}addLine(e,t,i,s,n,r,a,o,l,d,c){var h=this.icn3d;h.icn3dui;let p={};p.position1=new mt(e,t,i),p.position2=new mt(s,n,r),p.color=a,p.dashed=o,p.radius=d,p.opacity=c,void 0===h.lines[l]&&(h.lines[l]=[]),void 0!==l?h.lines[l].push(p):(void 0===h.lines.custom&&(h.lines.custom=[]),h.lines.custom.push(p)),h.hlObjectsCls.removeHlObjects()}addLineFromPicking(e){var t=this.icn3d,i=t.icn3dui;let s=$("#"+t.pre+e+"color").val();t.pAtom.coord.x,t.pAtom2.coord.x,t.pAtom.coord.y,t.pAtom2.coord.y,t.pAtom.coord.z,t.pAtom2.coord.z;let n="stabilizer"!=e;i.htmlCls.clickMenuCls.setLogCmd("add line | x1 "+t.pAtom.coord.x.toPrecision(4)+" y1 "+t.pAtom.coord.y.toPrecision(4)+" z1 "+t.pAtom.coord.z.toPrecision(4)+" | x2 "+t.pAtom2.coord.x.toPrecision(4)+" y2 "+t.pAtom2.coord.y.toPrecision(4)+" z2 "+t.pAtom2.coord.z.toPrecision(4)+" | color "+s+" | dashed "+n+" | type "+e,!0),this.addLine(t.pAtom.coord.x,t.pAtom.coord.y,t.pAtom.coord.z,t.pAtom2.coord.x,t.pAtom2.coord.y,t.pAtom2.coord.z,s,n,e),t.pickpair=!1}addLabel(e,t,i,s,n,r,a,o){var l=this.icn3d;l.icn3dui;let d={};"0"!==n&&""!==n&&"undefined"!==n||(n=void 0),"0"!==r&&""!==r&&"undefined"!==r||(r=void 0),"0"!==a&&""!==a&&"undefined"!==a||(a=void 0);let c=new mt;c.x=t,c.y=i,c.z=s,d.position=c,d.text=e,d.size=n,d.color=r,d.background=a,void 0===l.labels[o]&&(l.labels[o]=[]),void 0!==o?l.labels[o].push(d):(void 0===l.labels.custom&&(l.labels.custom=[]),l.labels.custom.push(d)),l.hlObjectsCls.removeHlObjects()}addChainLabels(e){var t=this.icn3d;let i=t.icn3dui.hashUtilsCls.intHash(t.hAtoms,e);void 0===t.labels.chain&&(t.labels.chain=[]);let s=t.firstAtomObjCls.getChainsFromAtoms(i);for(let e in s){let i={};i.position=t.applyCenterCls.centerAtoms(t.chains[e]).center;let s=e.indexOf("_"),n=e.substr(s+1),r=t.showSeqCls.getProteinName(e);r.length>20&&(r=r.substr(0,20)+"..."),i.text="Chain "+n+": "+r,i.size=18,t.firstAtomObjCls.getFirstCalphaAtomObj(t.chains[e]).color.getHexString().toUpperCase(),i.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,i.background="#FFFFFF",t.labels.chain.push(i)}t.hlObjectsCls.removeHlObjects()}addTerminiLabels(e){var t=this.icn3d,i=t.icn3dui;let s,n="#FFFFFF";s=i.hashUtilsCls.unionHash(s,t.proteins),s=i.hashUtilsCls.unionHash(s,t.nucleotides);let r=i.hashUtilsCls.intHash(t.dAtoms,s),a=i.hashUtilsCls.intHash(r,e);void 0===t.labels.chain&&(t.labels.chain=[]);let o=t.firstAtomObjCls.getChainsFromAtoms(a);for(let e in o){let s=i.hashUtilsCls.intHash(r,t.chains[e]),a=Object.keys(s),o=t.atoms[a[0]],l=t.atoms[a[a.length-1]],d={},c={};d.position=o.coord,c.position=l.coord,d.text="N-",c.text="C-",t.nucleotides.hasOwnProperty(o.serial)&&(d.text="5'",c.text="3'"),d.size=18,c.size=18,o.color.getHexString().toUpperCase(),l.color.getHexString().toUpperCase(),d.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,c.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,d.background=n,c.background=n,t.labels.chain.push(d),t.labels.chain.push(c)}t.hlObjectsCls.removeHlObjects()}}class lp{constructor(e){this.icn3d=e}draw2Ddgm(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=.667,o={},l={},d={},c={},h={};if(void 0===e)return"";for(let i in e.moleculeInfor){let s="#"+("000000"+e.moleculeInfor[i].color.toString(16)).slice(-6),r=e.moleculeInfor[i].chain.trim();void 0===h[r]?h[r]=1:++h[r];let a=t+"_"+(1===h[r]?r:r+h[r].toString());void 0!==n.mmdbid_q&&(n.mmdbid_q,n.mmdbid_t),o[i]=a,l[i]=s,d[i]=e.moleculeInfor[i].name,c[a]=i}if(void 0===s||!s)for(let i=0,s=e.intracResidues.length;i<s;++i){let s,r,a=e.intracResidues[i],l=0;for(let e in a){let t;t=o[e],0===l?s=t:r=t,++l}if(void 0!==s&&void 0!==r){l=0;for(let e in a){let i,o,d=a[e];0===l?(i=s,o=r):(i=r,o=s),void 0===n.chainids2resids[i]&&(n.chainids2resids[i]={}),void 0===n.chainids2resids[i][o]&&(n.chainids2resids[i][o]=[]);for(let s=0,r=d.length;s<r;++s){let r=d[s],a=n.mmdbMolidResid2mmdbChainResi[t.toUpperCase()+"_"+e+"_"+r];n.chainids2resids[i][o].push(a)}if(void 0===n.chainname2residues&&(n.chainname2residues={}),r=o,!n.chains.hasOwnProperty(r))continue;let c,h=n.firstAtomObjCls.getFirstCalphaAtomObj(n.chains[r]);n.chemicals.hasOwnProperty(h.serial)?c="chemical":n.nucleotides.hasOwnProperty(h.serial)?c="nucleotide":n.ions.hasOwnProperty(h.serial)?c="ion":n.proteins.hasOwnProperty(h.serial)?c="protein":n.water.hasOwnProperty(h.serial)&&(c="water");let p=r.substr(r.indexOf("_")+1)+"("+c+")";void 0===n.chainname2residues[i]&&(n.chainname2residues[i]={}),n.chainname2residues[i][p]=n.chainids2resids[i][o],++l}}}let p="<div id='#"+n.pre+t+"'>";p+="<b>"+t.toUpperCase()+"</b><br/>",p+="<svg viewBox='0,0,"+r.htmlCls.width2d+","+r.htmlCls.width2d+"'>";let u="#000000",m={},f=[],g="",b="",C={};if(s)for(let e in n.dAtoms){let t=n.atoms[e];C[c[t.structure+"_"+t.chain]]=1}let v=Object.keys(e.moleculeInfor),_=Object.keys(e.intrac),y=[];for(let e=0,t=v.length;e<t;++e)-1===_.indexOf(v[e])&&y.push(v[e]);let S={};if(y.length>0)for(let t in e.intrac){let i=e.intrac[t];for(let e=0,s=i.intrac.length;e<s;++e){let s=i.intrac[e].toString();-1!==y.indexOf(s)&&(void 0===S[s]&&(S[s]=[]),S[s].push(t),f.push([s,t]))}if("rect"===i.shape){let e=i.coords[0]*a,s=i.coords[1]*a,n=i.coords[2]*a-e,r=i.coords[3]*a-s;m[t]=[e+n/2,s+r/2]}else if("circle"===i.shape){let e=i.coords[0]*a,s=i.coords[1]*a;i.coords[2],m[t]=[e,s]}else if("poly"===i.shape){let e=i.coords[0]*a;i.coords[1],i.coords[2];let s=i.coords[3]*a;i.coords[4],i.coords[5],i.coords[6],i.coords[7],m[t]=[e,s]}}let w=0;for(let t=0,r=v.length;t<r;++t){let r=v[t],c=o[r];if(s&&!C.hasOwnProperty(r))continue;let h=e.intrac[r],p="#FFFFFF",u=l[r];if(void 0!==c&&void 0!==n.chains[c]){let e=Object.keys(n.chains[c]);e.length>0&&(u="#"+n.atoms[e[0]].color.getHexString().toUpperCase())}let _="";n.bInitial&&void 0!==i&&(void 0!==n.alignmolid2color&&n.alignmolid2color[i].hasOwnProperty(r)?(_=n.alignmolid2color[i][r],u="#FF0000"):u="#FFFFFF");let x=d[r],A=" ",M=" ";if(void 0!==c){let e=c.indexOf("_");M=c.substr(e+1),A=M.length>1?M.substr(0,1)+"..":M}else c="Misc";void 0===u&&(u="#FFFFFF");let T=1;if(n.bInitial&&void 0!==n.alnChains[c]){let e=0;for(let t in n.alnChains[c]){let i=n.atoms[t].color.getHexString().toUpperCase();"FF0000"!==i&&"00FF00"!==i||++e}T=1*e/Object.keys(n.chains[c]).length}if(T<.2&&(T=.2),-1===y.indexOf(r)){for(let e=0,t=h.intrac.length;e<t;++e)parseInt(r)<parseInt(h.intrac[e])&&f.push([r,h.intrac[e]]);if("rect"===h.shape){let e=h.coords[0]*a,t=h.coords[1]*a,i=h.coords[2]*a-e,s=h.coords[3]*a-t;g+=this.draw2DNucleotide(e+.5*i,t+.5*s,c,M,A,x,_,p,u,a,T),m[r]=[e+i/2,t+s/2]}else if("circle"===h.shape){let e=h.coords[0]*a,t=h.coords[1]*a;g+=this.draw2DProtein(e,t,c,M,A,x,_,p,u,a,T),m[r]=[e,t]}else if("poly"===h.shape){let e=h.coords[0]*a;h.coords[1],h.coords[2];let t=h.coords[3]*a;h.coords[4],h.coords[5],h.coords[6],h.coords[7];let i=e,s=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]),b+=this.draw2DChemical(i,s,c,M,A,x,_,p,u,a,T),m[r]=[e,t]}}else{let e,t,i=300,s=50;if(void 0!==S[r]&&S[r].length>1){let i=0,s=0;for(let e=0,t=S[r].length;e<t;++e){let t=S[r][e];if(m.hasOwnProperty(t)){let e=m[t];i+=e[0],s+=e[1]}}e=i/S[r].length,t=s/S[r].length}else{let n=i/s;w<n-1?(e=(w+1)*s*a,t=.1*i*a):w-(n-1)<n-1?(e=.1*i*a,t=(w-(n-1)+1)*s*a):(e=.25*i*a,t=e),++w}let o=e,l=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]);let d=!0;b+=this.draw2DChemical(o,l,c,M,A,x,_,p,u,a,T,d),m[r]=[o,l]}}for(let e=0,t=f.length;e<t;++e){let t=f[e];if(s&&(!C.hasOwnProperty(t[0])||!C.hasOwnProperty(t[1])))continue;let i,n,r=m[parseInt(t[0])],a=m[parseInt(t[1])];if(void 0===r||void 0===a)continue;i=o[t[0]],n=o[t[1]];let l=i.indexOf("_"),d=n.indexOf("_"),c=i.substr(l+1),h=n.substr(d+1),g=r[0],b=r[1],v=a[0],_=a[1],y=.5*(g+v),S=.5*(b+_);p+="<g class='icn3d-interaction' chainid1='"+i+"' chainid2='"+n+"' >",p+="<title>Interaction of chain "+c+" with chain "+h+"</title>",p+="<line x1='"+g+"' y1='"+b+"' x2='"+y+"' y2='"+S+"' stroke='"+u+"' stroke-width='2' /></g>",p+="<g class='icn3d-interaction' chainid1='"+n+"' chainid2='"+i+"' >",p+="<title>Interaction of chain "+h+" with chain "+c+"</title>",p+="<line x1='"+y+"' y1='"+S+"' x2='"+v+"' y2='"+_+"' stroke='"+u+"' stroke-width='2' /></g>"}return p+=b+g,p+="</svg>",p+="</div>",n.html2ddgm+=p,$("#"+n.pre+"dl_2ddgm_html").html(n.html2ddgm),p}set2DdgmNote(e){let t="<div style='width:150px'><b>Nodes</b>:<br>";return this.icn3d.icn3dui.utilsCls.isMac()?(t+="<span style='margin-right:18px;'>◯</span>Protein<br>",t+="<span style='margin-right:18px;'>▢</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>♢</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>▢</span>Biopolymer<br>"):(t+="<span style='margin-right:18px;'>O</span>Protein<br>",t+="<span style='margin-right:18px;'>▢</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>◇</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>▢</span>Biopolymer<br>"),t+="<br><b>Lines</b>:<br> Interactions at 4 Å<br>",e&&(t+="<b>Numbers in red</b>:<br> Aligned chains"),t+="</div><br/>",t}highlightNode(e,t,i,s){let n=this.icn3d.icn3dui;s<.2&&(s=.2);if("rect"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(i).attr("x")),r=Number($(i).attr("y")),a=Number($(i).attr("width")),o=Number($(i).attr("height"));$(t).attr("x",e+a/2*(1-s)),$(t).attr("y",r+o/2*(1-s)),$(t).attr("width",a*s),$(t).attr("height",o*s)}else if("circle"===e)$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3),$(t).attr("r",Number($(i).attr("r"))*s);else if("polygon"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(i).attr("x")),r=Number($(i).attr("y")),a=Number($(i).attr("x0d")),o=Number($(i).attr("y0d")),l=Number($(i).attr("x1d")),d=Number($(i).attr("y1d")),c=Number($(i).attr("x2d")),h=Number($(i).attr("y2d")),p=Number($(i).attr("x3d")),u=Number($(i).attr("y3d"));$(t).attr("points",(e+a*s).toString()+", "+(r+o*s).toString()+", "+(e+l*s).toString()+", "+(r+d*s).toString()+", "+(e+c*s).toString()+", "+(r+h*s).toString()+", "+(e+p*s).toString()+", "+(r+u*s).toString())}}removeLineGraphSelection(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"dl_linegraph circle").attr("stroke","#000000"),$("#"+e.pre+"dl_linegraph circle").attr("stroke-width",1),$("#"+e.pre+"dl_linegraph svg line.icn3d-hlline").attr("stroke","#FFF")}removeScatterplotSelection(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"dl_scatterplot circle").attr("stroke","#000000"),$("#"+e.pre+"dl_scatterplot circle").attr("stroke-width",1),$("#"+e.pre+"dl_scatterplot rect").attr("stroke","#000000"),$("#"+e.pre+"dl_scatterplot rect").attr("stroke-width",1)}click2Ddgm(){let e=this.icn3d,t=e.icn3dui,i=this;$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-node",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n=$(this).attr("chainid");s.bCtrl||s.bShift||(s.selectionCls.removeSelection(),s.lineArray2d=[]);let r=1;void 0!==s.alnChains[n]&&(r=1*Object.keys(s.alnChains[n]).length/Object.keys(s.chains[n]).length);let a=$(this).find("rect[class='icn3d-hlnode']"),o=$(this).find("rect[class='icn3d-basenode']");i.highlightNode("rect",a,o,r),a=$(this).find("circle[class='icn3d-hlnode']"),o=$(this).find("circle[class='icn3d-basenode']"),i.highlightNode("circle",a,o,r),a=$(this).find("polygon[class='icn3d-hlnode']"),o=$(this).find("polygon[class='icn3d-basenode']"),i.highlightNode("polygon",a,o,r),s.bCtrl||s.bShift?s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.chains[n]):s.hAtoms=t.hashUtilsCls.cloneHash(s.chains[n]),s.bCtrl||s.bShift?(void 0===s.chainArray2d&&(s.chainArray2d=[]),s.chainArray2d.push(n)):s.chainArray2d=[n],s.hlUpdateCls.updateHlAll(s.chainArray2d),s.annotationCls.showAnnoSelectedChains();let l="select chain "+n;t.htmlCls.clickMenuCls.setLogCmd(l,!0),s.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-interaction",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection"),s.bClickInteraction=!0;let n=$(this).attr("chainid1"),r=$(this).attr("chainid2");$(this).find("line").attr("stroke",t.htmlCls.ORANGE),i.selectInteraction(n,r),s.annotationCls.showAnnoSelectedChains();let a="select interaction "+n+","+r;t.htmlCls.clickMenuCls.setLogCmd(a,!0),s.bClickInteraction=!1})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-node",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n=$(this).attr("resid");s.bCtrl||s.bShift||(s.hAtoms={},i.removeLineGraphSelection());$(this).find("circle").attr("stroke",t.htmlCls.ORANGE),$(this).find("circle").attr("stroke-width",2),s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.residues[n]);let r="select "+s.resid2specCls.residueids2spec([n]);s.hlUpdateCls.updateHlAll(),t.htmlCls.clickMenuCls.setLogCmd(r,!0),s.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-interaction",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n=$(this).attr("resid1"),r=$(this).attr("resid2");s.bCtrl||s.bShift||(s.hAtoms={},i.removeLineGraphSelection()),$(this).find("line.icn3d-hlline").attr("stroke",t.htmlCls.ORANGE);$("[resid="+n+"]").find("circle").attr("stroke",t.htmlCls.ORANGE),$("[resid="+n+"]").find("circle").attr("stroke-width",2),$("[resid="+r+"]").find("circle").attr("stroke",t.htmlCls.ORANGE),$("[resid="+r+"]").find("circle").attr("stroke-width",2),s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.residues[n]),s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.residues[r]);let a="select "+s.resid2specCls.residueids2spec([n,r]);s.hlUpdateCls.updateHlAll(),s.transformCls.zoominSelection(),t.htmlCls.clickMenuCls.setLogCmd(a,!0)})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-interaction",(function(e){let t=i.icn3d;e.stopImmediatePropagation(),i.clickInteraction(this),t.transformCls.zoominSelection()})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-interaction",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-interaction",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-interaction",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)}))}clickNode(e){let t=this.icn3d,i=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let s=$(e).attr("resid");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("circle").attr("stroke",i.htmlCls.ORANGE),$(e).find("circle").attr("stroke-width",2),$(e).find("rect").attr("stroke",i.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[s]);let n="select "+t.resid2specCls.residueids2spec([s]);t.hlUpdateCls.updateHlAll(),i.htmlCls.clickMenuCls.setLogCmd(n,!0),t.bSelectResidue=!1}clickInteraction(e){let t=this.icn3d,i=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let s=$(e).attr("resid1"),n=$(e).attr("resid2");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("rect").attr("stroke",i.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[s]),t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[n]);let r="select "+t.resid2specCls.residueids2spec([s,n]);t.hlUpdateCls.updateHlAll(),i.htmlCls.clickMenuCls.setLogCmd(r,!0)}selectInteraction(e,t){let i=this.icn3d;i.icn3dui,i.hlUpdateCls.removeHl2D(),i.hlObjectsCls.removeHlObjects(),i.bCtrl||i.bShift?(void 0===i.lineArray2d&&(i.lineArray2d=[]),i.lineArray2d.push(e),i.lineArray2d.push(t)):i.lineArray2d=[e,t],this.selectInteractionAtoms(e,t),i.hlObjectsCls.addHlObjects(),i.hlUpdateCls.updateHlAll()}selectInteractionAtoms(e,t){let i,s,n=this.icn3d,r=n.icn3dui,a=n.chainids2resids[e][t];n.bCtrl||n.bShift||(n.hAtoms={});for(let e=0,t=a.length;e<t;++e)n.hAtoms=r.hashUtilsCls.unionHash(n.hAtoms,n.residues[a[e]]);if(Object.keys(n.structures).length>1)i="inter_"+e+"_"+t;else{let s=e.indexOf("_"),n=t.indexOf("_");i="inter_"+e.substr(s+1)+"_"+t.substr(n+1)}s="select the atoms in chain "+e+" interacting with chain "+t+" in a distance of 4 angstrom";let o="select interaction "+e+","+t;n.selectionCls.addCustomSelection(a,i,s,o,!0)}draw2DProtein(e,t,i,s,n,r,a,o,l,d,c){this.icn3d.icn3dui;let h="#000000",p=20*d,u="<g class='icn3d-node' chainid='"+i+"' >";return u+="<title>Chain "+s+": "+r+"</title>",u+="<circle class='icn3d-basenode' cx='"+e+"' cy='"+t+"' r='"+p+"' fill='"+o+"' stroke-width='1' stroke='"+h+"' class='icn3d-node' chainid='"+i+"' />",u+="<circle class='icn3d-hlnode' cx='"+e+"' cy='"+t+"' r='"+(p*c).toString()+"' fill='"+l+"' stroke-width='1' stroke='"+h+"' />",u+="<text x='"+(e-0).toString()+"' y='"+(t+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==a&&(u+="<text x='"+(e-0).toString()+"' y='"+(t+p+4+6).toString()+"' style='fill:"+l+"; font-size:8; font-weight:bold; text-anchor:middle' >"+a+"</text>"),u+="</g>",u}draw2DNucleotide(e,t,i,s,n,r,a,o,l,d,c){this.icn3d.icn3dui;let h="#000000",p=30*d,u=30*d,m="<g class='icn3d-node' chainid='"+i+"' >";return m+="<title>Chain "+s+": "+r+"</title>",m+="<rect class='icn3d-basenode' x='"+(e-=.5*p)+"' y='"+(t-=.5*u)+"' width='"+p+"' height='"+u+"' fill='"+o+"' stroke-width='1' stroke='"+h+"' />",m+="<rect class='icn3d-hlnode' x='"+(e+p/2*(1-c)).toString()+"' y='"+(t+u/2*(1-c)).toString()+"' width='"+(p*c).toString()+"' height='"+(u*c).toString()+"' fill='"+l+"' stroke-width='1' stroke='"+h+"' />",m+="<text x='"+(e+p/2-0).toString()+"' y='"+(t+u/2+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==a&&(m+="<text x='"+(e+p/2-0).toString()+"' y='"+(t+u+4+6).toString()+"' style='fill:"+l+"; font-size:8; font-weight:bold; text-anchor:middle' >"+a+"</text>"),m+="</g>",m}draw2DChemical(e,t,i,s,n,r,a,o,l,d,c,h){this.icn3d.icn3dui;let p,u,m,f,g,b,C,v,_="#000000",y=30*d;if(h){let i=.5*y/Math.sqrt(3),s=.5*y;p=e-i,u=t-s,m=e+3*i,f=t-s,g=e+i,b=t+s,C=e-3*i,v=t+s}else{let i=.5*y,s=.5*y;p=e-i,u=t,m=e,f=t+s,g=e+i,b=t,C=e,v=t-s}let S=p-e,w=u-t,x=m-e,A=f-t,M=g-e,T=b-t,E=C-e,R=v-t,k="<g class='icn3d-node' chainid='"+i+"' >";return k+="<title>Chain "+s+": "+r+"</title>",k+="<polygon class='icn3d-basenode' points='"+p+", "+u+","+m+", "+f+","+g+", "+b+","+C+", "+v+"' x='"+e+"' y='"+t+"' x0d='"+S+"' y0d='"+w+"' x1d='"+x+"' y1d='"+A+"' x2d='"+M+"' y2d='"+T+"' x3d='"+E+"' y3d='"+R+"' fill='"+o+"' stroke-width='1' stroke='"+_+"' />",k+="<polygon class='icn3d-hlnode' points='"+(e+S*c).toString()+", "+(t+w*c).toString()+","+(e+x*c).toString()+", "+(t+A*c).toString()+","+(e+M*c).toString()+", "+(t+T*c).toString()+","+(e+E*c).toString()+", "+(t+R*c).toString()+"' fill='"+l+"' stroke-width='1' stroke='"+_+"' />",k+="<text x='"+(e+1).toString()+"' y='"+(t+2).toString()+"' style='fill:#000000; font-size:8; text-anchor:middle' >"+n+"</text>",""!==a&&(k+="<text x='"+(e+1).toString()+"' y='"+(t+2+6).toString()+"' style='fill:"+l+"; font-size:8; font-weight:bold; text-anchor:middle' >"+a+"</text>"),k+="</g>",k}}class dp{constructor(e){this.icn3d=e}async draw2Dcartoon(e,t){let i=this.icn3d,s=i.icn3dui,n=this;if(s.htmlCls.clickMenuCls.setLogCmd("cartoon 2d "+e,!0),i.cartoon2dType=e,t){let t=n.getCartoonSvg(e,i.graphStr);$("#"+s.svgid_ct).html(t)}else{await this.getNodesLinksForSetCartoon(e),i.graphStr=n.getCartoonData(e,i.node_link);let t=n.getCartoonSvg(e,i.graphStr);$("#"+s.svgid_ct).html(t),n.setEventsForCartoon2d(),s.htmlCls.dialogCls.openDlg("dl_2dctn","2D Cartoon")}}getCartoonSvg(e,t){let i=this.icn3d,s=i.icn3dui,n="",r="",a=JSON.parse(t);i.ctnNodeHash={};for(let t=0,s=a.nodes.length;t<s;++t){let s=a.nodes[t];i.ctnNodeHash[s.id]=s,r+="secondary"==e?this.drawHelix(e,s.id,s.ss,s.x,s.y,s.x1,s.y1,s.x2,s.y2,s.len,s.ang,s.c):this.drawOval(e,s.id,s.x,s.y,s.rx,s.ry,s.ang,s.c,s.from,s.to)}i.nodeid2lineid={};for(let t=0,r=a.links.length;t<r;++t){let r=a.links[t].source,o=a.links[t].target,l=i.ctnNodeHash[r].x,d=s.htmlCls.width2d-i.ctnNodeHash[r].y,c=i.ctnNodeHash[o].x,h=s.htmlCls.width2d-i.ctnNodeHash[o].y;"chain"==e?n+="<g class='icn3d-ctinteraction' chainid1='"+i.ctnNodeHash[r].id+"' chainid2='"+i.ctnNodeHash[o].id+"' >":"domain"==e?n+="<g class='icn3d-ctinteraction' from1='"+i.ctnNodeHash[r].from+"' to1='"+i.ctnNodeHash[r].to+"' from2='"+i.ctnNodeHash[o].from+"' to2='"+i.ctnNodeHash[o].to+"' >":"secondary"==e&&(l=i.ctnNodeHash[r].x2,d=s.htmlCls.width2d-i.ctnNodeHash[r].y2,c=i.ctnNodeHash[o].x1,h=s.htmlCls.width2d-i.ctnNodeHash[o].y1,n+="<g class='icn3d-ctinteraction' range1='"+i.ctnNodeHash[r].range+"' range2='"+i.ctnNodeHash[o].range+"' >");let p=r+"--"+o;n+="<title>Interaction of "+e+" "+this.getLabelFromId(r,e)+" with "+e+" "+this.getLabelFromId(o,e)+"</title>",n+="<line class='icn3d-edge' id='"+p+"' x1='"+l+"' y1='"+d+"' x2='"+c+"' y2='"+h+"' stroke='#bbbbbb' stroke-width='1' /></g>",i.nodeid2lineid.hasOwnProperty(r)||(i.nodeid2lineid[r]=[]),i.nodeid2lineid.hasOwnProperty(o)||(i.nodeid2lineid[o]=[]),i.nodeid2lineid[r].push(p),i.nodeid2lineid[o].push(p)}return n+=r,n}setEventsForCartoon2d(){let e=this.icn3d,t=e.icn3dui;$("#"+t.svgid_ct+" .icn3d-ctnode").draggable({start:function(e,t){let i=parseFloat(e.target.getAttribute("cx")),s=parseFloat(e.target.getAttribute("cy"));e.target.setAttribute("cx",i),e.target.setAttribute("cy",s);let n=e.target.getAttribute("ang");if(n)e.target.setAttribute("transform","rotate("+n+","+i+","+s+")");else{let t=parseFloat(e.target.getAttribute("x1")),i=parseFloat(e.target.getAttribute("y1")),s=parseFloat(e.target.getAttribute("x2")),n=parseFloat(e.target.getAttribute("y2"));e.target.setAttribute("x1",t),e.target.setAttribute("y1",i),e.target.setAttribute("x2",s),e.target.setAttribute("y2",n)}},drag:function(i,s){let n=$("#"+t.svgid_ct).offset().left,r=$("#"+t.svgid_ct).offset().top,a=i.target.getAttribute("id"),o=i.target.getAttribute("ang"),l=i.clientX-n,d=i.clientY-r,c=parseFloat(i.target.getAttribute("cx")),h=parseFloat(i.target.getAttribute("cy")),p=(l-c)/e.resizeRatioX,u=(d-h)/e.resizeRatioY,m=parseFloat($("#"+a+"_text").attr("x")),f=parseFloat($("#"+a+"_text").attr("y"));if($("#"+a+"_text").attr("x",m+p),$("#"+a+"_text").attr("y",f+u),i.target.setAttribute("cx",l),i.target.setAttribute("cy",d),o)i.target.setAttribute("transform","rotate("+o+","+l+","+d+")");else{let e=parseFloat(i.target.getAttribute("x1")),t=parseFloat(i.target.getAttribute("y1")),s=parseFloat(i.target.getAttribute("x2")),n=parseFloat(i.target.getAttribute("y2"));if(i.target.setAttribute("x1",e+p),i.target.setAttribute("y1",t+u),i.target.setAttribute("x2",s+p),i.target.setAttribute("y2",n+u),"S"==a.substr(0,1)){let e=parseFloat($("#"+a+"_box").attr("x1")),t=parseFloat($("#"+a+"_box").attr("y1")),i=parseFloat($("#"+a+"_box").attr("x2")),s=parseFloat($("#"+a+"_box").attr("y2"));$("#"+a+"_box").attr("x1",e+p),$("#"+a+"_box").attr("y1",t+u),$("#"+a+"_box").attr("x2",i+p),$("#"+a+"_box").attr("y2",s+u)}}if(e.nodeid2lineid[a])for(let t=0,i=e.nodeid2lineid[a].length;t<i;++t){g(e.nodeid2lineid[a][t],a,o)}function g(e,t,i){if(e&&-1!=e.indexOf(t)){let t=e.split("--");if(2==t.length){let s,n;s=t[1],n=t[0];let r=i?"cx":"x1",a=i?"cy":"y1",o=$("#"+s).attr(r),l=$("#"+s).attr(a);$("#"+e).attr("x1",o),$("#"+e).attr("y1",l);let d=i?"cx":"x2",c=i?"cy":"y2",h=$("#"+n).attr(d),p=$("#"+n).attr(c);$("#"+e).attr("x2",h),$("#"+e).attr("y2",p)}}}}})}getLabelFromId(e,t){let i=e,s=i.indexOf("__");return-1!==s&&(i=i.substr(0,s)),"secondary"==t&&(i=i.substr(0,i.indexOf("-"))),i}drawHelix(e,t,i,s,n,r,a,o,l,d,c,h){let p=this.icn3d.icn3dui,u=this.getLabelFromId(t,e);n=p.htmlCls.width2d-n,a=p.htmlCls.width2d-a,l=p.htmlCls.width2d-l;let m="<g range='"+u.substr(1)+"' >";return m+="<title>"+e+" "+u+"</title>","H"==t.substr(0,1)?m+="<line id='"+t+"' class='icn3d-ctnode' x1='"+r+"' y1='"+a+"' x2='"+o+"' y2='"+l+"' cx='"+.5*(r+o).toFixed(1)+"' cy='"+.5*(a+l).toFixed(1)+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='round' />":(m+="<line id='"+t+"_box' x1='"+r+"' y1='"+a+"' x2='"+o+"' y2='"+l+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='square' />",m+="<line id='"+t+"' class='icn3d-ctnode' x1='"+r+"' y1='"+a+"' x2='"+o+"' y2='"+l+"' cx='"+.5*(r+o).toFixed(1)+"' cy='"+.5*(a+l).toFixed(1)+"' stroke='#FFF' stroke-width='1' stroke-linecap='square' />"),m+="<text id='"+t+"_text' x='"+(s-0).toString()+"' y='"+(n+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text8' >"+u+"</text>",m+="</g>",m}drawOval(e,t,i,s,n,r,a,o,l,d){let c=this.icn3d.icn3dui,h=this.getLabelFromId(t,e);s=c.htmlCls.width2d-s,a=180-a;let p="chain"==e?"<g chainid='"+t+"' >":"<g from='"+l+"' to='"+d+"' >";return p+="<title>"+e+" "+h+"</title>",p+="<defs>",p+="<linearGradient id='"+t+"_g_obj' x1='0%' y1='0%' x2='100%' y2='0%'>",p+=" <stop offset='0%' style='stop-color:rgb(255,255,255);stop-opacity:1' />",p+=" <stop offset='100%' style='stop-color:#"+o+";stop-opacity:1' />",p+="</linearGradient>",p+="</defs>",p+="<ellipse id='"+t+"' class='icn3d-ctnode' cx='"+i.toFixed(0)+"' cy='"+s.toFixed(0)+"' rx='"+n.toFixed(0)+"' ry='"+r.toFixed(0)+"' fill='url(#"+t+"_g_obj)' stroke-width='1' stroke='none' ",p+=" ang='"+a+"' transform='rotate("+a+","+i.toFixed(0)+","+s.toFixed(0)+")'",p+="chain"==e?" chainid='"+t+"' />":" from='"+l+"' to='"+d+"' />",p+="<text id='"+t+"_text' x='"+(i-0).toString()+"' y='"+(s+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text12' >"+h+"</text>",p+="</g>",p}getCartoonData(e,t){let i=this.icn3d;i.icn3dui;let s,n,r=[],a=[];r=t.node;let o=[],l={},d=0;for(let e=0,t=r.length;e<t;++e){let t=r[e],i=JSON.parse(t);l.hasOwnProperty(i.id)||(o.push(i),l[i.id]=d,++d)}let c=[];for(let e=0,t=o.length;e<t;++e){let t=o[e];c.push(JSON.stringify(t))}s=c.join(", "),a=t.link,n=a.join(", "),i.hAtoms;let h='{"nodes": ['+s+'], "links": [';return h+=n+"",h+='], "level": "'+(t.level?t.level:"")+'"}',h}projectTo2d(e){let t=this.icn3d,i=t.icn3dui,s=e.project(t.cam);var n=new mt;return n.x=Math.round((s.x+1)*i.htmlCls.width2d*.5),n.y=Math.round(-s.y*i.htmlCls.width2d*.5),n.z=0,n.y>0?n.y=i.htmlCls.width2d-n.y:n.y=-n.y,n}async getNodesLinksForSetCartoon(e){let t,i,s,n,r,a=this.icn3d,o=a.icn3dui,l=this,d=[],c=[],h=0,p=o.htmlCls.defaultValue,u="",m="",f="",g=!1,b=!0;if("chain"==e){let e={};for(let t in a.hAtoms){let i=a.atoms[t];if("DUM"==i.chain)continue;let s=i.structure+"_"+i.chain;(a.proteins.hasOwnProperty(t)||a.nucleotides.hasOwnProperty(t))&&(e.hasOwnProperty(s)||(e[s]={}),e[s][i.serial]=i)}let t=a.contactCls.getExtent(a.atoms),i=9999,s=9999,n=-9999,l=-9999,h=-9999,p=[];for(let d in e){a.hAtom={},a.hAtoms=o.hashUtilsCls.cloneHash(a.chains[d]);let e=a.axesCls.setPc1Axes(),c=e[0],u=e[1].distanceTo(e[0]),m=e[2].distanceTo(e[0]),f=180*new pt(e[1].x-e[0].x,e[1].y-e[0].y).angle()/Math.PI;f>180&&(f-=180);let g=Object.keys(a.hAtoms)[0],b=a.atoms[g];r=d,c=this.projectTo2d(c);let C=c.x,v=c.y;C<i&&(i=C),C>n&&(n=C),v<s&&(s=v),v>l&&(l=v);let _=.5;u=_*o.htmlCls.width2d*u/(t[1][0]-t[0][0]),m=_*o.htmlCls.width2d*m/(t[1][1]-t[0][1]),u>h&&(h=u),m>h&&(h=m),p.push({id:d,r:r,x:C,y:v,rx:u,ry:m,ang:f,c:b.color.getHexString()})}let u=h+2,m=n-i,f=l-s;for(let e=0,t=p.length;e<t;++e){let t=p[e],n=m<1?.5*o.htmlCls.width2d:(t.x-i)/m*(o.htmlCls.width2d-2*u)+u,r=f<1?.5*o.htmlCls.width2d:(t.y-s)/f*(o.htmlCls.width2d-2*u)+u;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+n.toFixed(0)+', "y": '+r.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}a.hAtoms=o.hashUtilsCls.cloneHash(a.dAtoms),a.node_link={node:d,link:c,level:"chain"}}else if("domain"==e)a.chainid2pssmid||await a.loadScriptCls.applyCommandAnnotationsAndCddSite("view annotations"),l.getNodesLinksForDomains(a.chainid2pssmid);else if("secondary"==e){a.resi2resirange={};let e,l=[];a.contactCls.getExtent(a.atoms);let C="",v=9999,_=9999,y=-9999,S=-9999,w=2,x=[];for(let d in a.hAtoms){let w=a.atoms[d];if("DUM"!=w.chain&&((w.ssbegin||w.ssend)&&"CA"==w.name&&"C"==w.elem)){let d=w.structure+"_"+w.chain+"_"+w.resi;if(b&&w.ssbegin&&(g=!0,b=!1,t=w,C="helix"==w.ss?"H":"S",n=C+w.resi,r="1_1_"+d,f=w.chain),g&&(e=o.utilsCls.residueName2Abbr(w.resn)+w.resi,e+="__"+w.chain,Object.keys(a.structures).length>1&&(e+="__"+w.structure),l.push(e)),f==w.chain&&g&&w.ssend){let o=this.projectTo2d(t.coord.clone()),d=o.x,f=o.y,A=this.projectTo2d(w.coord.clone()),M=A.x,T=A.y;i=.5*(d+M),s=.5*(f+T),d=.5*(i+d),f=.5*(s+f),M=.5*(i+M),T=.5*(s+T),d<v&&(v=d),d>y&&(y=d),f<_&&(_=f),f>S&&(S=f),M<v&&(v=M),M>y&&(y=M),T<_&&(_=T),T>S&&(S=T),g=!1,b=!0,n+="-"+w.resi,r+="-"+w.resi,n+="__"+w.chain,Object.keys(a.structures).length>1&&(n+="__"+w.structure);for(let t=0,i=l.length;t<i;++t)e=l[t],a.resi2resirange[e]=n;l=[],h>0&&u==w.chain&&c.push('{"source": "'+m+'", "target": "'+n+'", "v": '+p+', "c": "'+t.color.getHexString().toUpperCase()+'"}'),x.push({id:n,r:r,ss:C,x:i,y:s,x1:d,y1:f,x2:M,y2:T,c:w.color.getHexString()}),u=w.chain,m=n,++h}}}let A=w+2,M=y-v,T=S-_;for(let e=0,t=x.length;e<t;++e){let t=x[e],i=M<1?.5*o.htmlCls.width2d:(t.x-v)/M*(o.htmlCls.width2d-2*A)+A,s=T<1?.5*o.htmlCls.width2d:(t.y-_)/T*(o.htmlCls.width2d-2*A)+A,n=M<1?.5*o.htmlCls.width2d:(t.x1-v)/M*(o.htmlCls.width2d-2*A)+A,r=T<1?.5*o.htmlCls.width2d:(t.y1-_)/T*(o.htmlCls.width2d-2*A)+A,a=M<1?.5*o.htmlCls.width2d:(t.x2-v)/M*(o.htmlCls.width2d-2*A)+A,l=T<1?.5*o.htmlCls.width2d:(t.y2-_)/T*(o.htmlCls.width2d-2*A)+A;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+i.toFixed(0)+', "y": '+s.toFixed(0)+', "x1": '+n.toFixed(0)+', "y1": '+r.toFixed(0)+', "x2": '+a.toFixed(0)+', "y2": '+l.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}a.node_link={node:d,link:c,level:"secondary"}}}getNodesLinksForDomains(e){let t=this.icn3d,i=t.icn3dui,s=[],n=[],r=i.htmlCls.defaultValue;t.resi2resirange={};let a={};for(let e in t.hAtoms){let i=t.atoms[e];"DUM"!=i.chain&&(a[i.structure+"_"+i.chain]=1)}let o=t.contactCls.getExtent(t.atoms),l=9999,d=9999,c=-9999,h=-9999,p=-9999,u=[];for(let s in a){if(!e.hasOwnProperty(s))continue;let a=e[s].pssmid2name,f=e[s].pssmid2fromArray,g=e[s].pssmid2toArray,b={};for(let e in a){let t=f[e];b[e]=t[0]}var m=Object.keys(b);let C,v;m.sort((function(e,t){return b[e]-b[t]}));for(let e=0,b=m.length;e<b;++e){let b=m[e],_=a[b];_+="__"+s.substr(s.indexOf("_")+1),Object.keys(t.structures).length>1&&(_+="__"+s.substr(0,s.indexOf("_")));let y=f[b],S=g[b];t.hAtoms={};for(let e=0,n=y.length;e<n;++e){let n=parseInt(y[e])+1,r=parseInt(S[e])+1;for(let e=n;e<=r;++e)t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[s+"_"+e])}if(0==Object.keys(t.hAtoms).length)continue;let w=t.axesCls.setPc1Axes(),x=w[0],A=w[1].distanceTo(w[0]),M=w[2].distanceTo(w[0]),T=180*new pt(w[1].x-w[0].x,w[1].y-w[0].y).angle()/Math.PI;T>180&&(T-=180);let E=Object.keys(t.hAtoms)[0],R=t.atoms[E];x=this.projectTo2d(x);let k=x.x,O=x.y;k<l&&(l=k),k>c&&(c=k),O<d&&(d=O),O>h&&(h=O);let I=.5;A=I*i.htmlCls.width2d*A/(o[1][0]-o[0][0]),M=I*i.htmlCls.width2d*M/(o[1][1]-o[0][1]),A>p&&(p=A),M>p&&(p=M),void 0!==C&&n.push('{"source": "'+C+'", "target": "'+_+'", "v": '+r+', "c": "'+v.color.getHexString().toUpperCase()+'"}'),u.push({id:_,from:y+"",to:S+"",x:k,y:O,rx:A,ry:M,ang:T,c:R.color.getHexString()}),C=_,v=R}}let f=p+2,g=c-l,b=h-d;for(let e=0,t=u.length;e<t;++e){let t=u[e],n=g<1?.5*i.htmlCls.width2d:(t.x-l)/g*(i.htmlCls.width2d-2*f)+f,r=b<1?.5*i.htmlCls.width2d:(t.y-d)/b*(i.htmlCls.width2d-2*f)+f;s.push('{"id": "'+t.id+'", "from": "'+t.from+'", "to": "'+t.to+'", "x": '+n.toFixed(0)+', "y": '+r.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}t.hAtoms=i.hashUtilsCls.cloneHash(t.dAtoms),t.node_link={node:s,link:n,level:"domain"}}getSelection(e,t,i){let s=this.icn3d,n=s.icn3dui,r={},a=[],o=t.toString().split(","),l=i.toString().split(","),d=3==e.length?e[2]:Object.keys(s.structures)[0],c=e.length>=2?d+"_"+e[1]:Object.keys(s.chains)[0];for(let e=0,t=o.length;e<t;++e){let t=parseInt(o[e])+1,i=parseInt(l[e])+1;for(let e=t;e<=i;++e){let t=c+"_"+e;r=n.hashUtilsCls.unionHash(r,s.residues[t]),a.push(t)}}return{atomSet:r,residArray:a}}click2Dcartoon(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+t.pre+"2dctn_chain","click",(async function(e){let s=t.icn3d;e.preventDefault(),i.initCartoonSvg(),await s.cartoon2dCls.draw2Dcartoon("chain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_domain","click",(async function(e){let s=t.icn3d;e.preventDefault(),i.initCartoonSvg(),await s.cartoon2dCls.draw2Dcartoon("domain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_secondary","click",(async function(e){let s=t.icn3d;e.preventDefault(),i.initCartoonSvg(),await s.cartoon2dCls.draw2Dcartoon("secondary")})),$(document).on("click","#"+e.pre+"dl_2dctn .icn3d-ctnode",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n,r={},a=[],o=$(this).attr("id"),l=$(this).attr("chainid"),d=$(this).attr("from"),c=$(this).attr("to"),h=$(this).attr("x1");if(void 0!==l)n="chain",r=s.chains[l];else if(void 0!==d){n="domain";let e=o.split("__"),t=i.getSelection(e,d,c);r=t.atomSet,a=t.residArray}else if(void 0!==h){n="secondary";let e=o.split("__"),t=e[0].substr(1).split("-"),s=parseInt(t[0])-1,l=parseInt(t[1])-1,d=i.getSelection(e,s,l);r=d.atomSet,a=d.residArray}s.bCtrl||s.bShift||(s.selectionCls.removeSelection(),s.lineArray2d=[]),void 0!==s.alnChains[l]&&(Object.keys(s.alnChains[l]).length,Object.keys(s.chains[l]).length),s.bCtrl||s.bShift?s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,r):s.hAtoms=t.hashUtilsCls.cloneHash(r),"chain"==n?(s.bCtrl||s.bShift?(void 0===s.chainArray2d&&(s.chainArray2d=[]),s.chainArray2d.push(l)):s.chainArray2d=[l],s.hlUpdateCls.updateHlAll(s.chainArray2d)):s.hlUpdateCls.updateHlAll(),s.annotationCls.showAnnoSelectedChains();let p="chain"==n?"select chain "+l:"select "+s.resid2specCls.residueids2spec(a);t.htmlCls.clickMenuCls.setLogCmd(p,!0),s.bSelectResidue=!1}))}initCartoonSvg(){let e=this.icn3d,t=e.icn3dui;e.resizeRatioX=1,e.resizeRatioY=1,$("#"+t.svgid_ct).empty()}}class cp{constructor(e){this.icn3d=e}async drawLigplot(e,t){let i=this.icn3d,s=i.icn3dui;t?s.htmlCls.dialogCls.openDlg("dl_ligplot","2D Depiction"):s.htmlCls.dialogCls.openDlg("dl_ligplot","Show ligand interactions with atom details");let n,r,a=100,o=100;i.len4ang=80;let l=i.saveFileCls.getAtomPDB(e);l=l.trim(),l=l.replace(/\n\n/g,"\n");let d={pdb2svg:l},c=s.htmlCls.baseUrl+"openbabel/openbabel.cgi",h=(await s.getAjaxPostPromise(c,d,void 0,void 0,void 0,void 0,"text")).split("\n"),p="",u="",m={},f=0,g=0,b=0;i.svgGridSize=i.len4ang,i.gridXY2used={};for(let e=0,t=h.length;e<t;++e){let t=h[e];if(0==t.indexOf("<svg width")){let e=t.indexOf('viewBox="')+9,s=t.substr(e),l=s.substr(0,s.indexOf('"')).split(" ");n=parseFloat(l[2]),r=parseFloat(l[3]),a=n+2*i.len4ang,o=r+2*i.len4ang}else if(0==t.indexOf("<line"))p+=t+"\n";else if(0==t.indexOf("<text"))if(-1!=t.indexOf('font-size="12"')){let e=t.indexOf(">")+1,s=t.substr(e),n=parseInt(s.substr(0,s.indexOf("<")));e=t.indexOf('x="')+3;let r=t.substr(e),a=parseFloat(r.substr(0,r.indexOf('"')));e=t.indexOf('y="')+3;let o=t.substr(e),l=parseFloat(o.substr(0,o.indexOf('"')));m[n]={x:a,y:l};let d=parseInt(a/i.svgGridSize),c=parseInt(l/i.svgGridSize);i.gridXY2used[d+"_"+c]=1,f+=a,g+=l,++b}else u+=t+"\n";else if(0==t.indexOf("</svg>"))break}let C=f/b,v=g/b,_=s.ligplotid;i.ligplotWidth=a;let y=i.ligplotWidth,S=o+30,w=-i.len4ang,x="<svg id='"+_+"' viewBox='"+w+","+w+","+a+","+S+"' width='"+y+"px' font-family='sans-serif' stroke='rgb(0,0,0)' stroke-width='2' stroke-linecap='round'>";if(t)x+=p+u;else{let e=parseInt(n/i.svgGridSize),t=parseInt(r/i.svgGridSize),s=i.viewInterPairsCls.getAllInteractionTable("save1",m,e,t,C,v);x+=p+s.svgHtmlLine,x+=u+s.svgHtmlNode}x+="</svg>",t?$("#"+i.pre+"ligplotDiv").html(x):($("#"+i.pre+"ligplotDiv").html(x),this.setEventsForLigplot())}getSvgPerPair(e,t,i,s,n,r,a,o,l,d,c,h,p){let u=this.icn3d,m=u.icn3dui,f="hbond"==s||"contact"==s||"halogen"==s?u.len4ang:1.5*u.len4ang,g=u.len4ang/2,b="contact"==s?1:2,C=u.getGraphCls.convertLabel2Resid(t),v=u.firstAtomObjCls.getFirstAtomObj(u.residues[C]),_=u.getGraphCls.convertLabel2Resid(i),y=u.firstAtomObjCls.getFirstAtomObj(u.residues[_]),S=0,w=0,x=0,A=v.serial;for(let t=0,i=e.length;t<i;++t){let i=e[t]-A+1;S+=n[i].x,w+=n[i].y,++x}let M,T,E,R=S/x-1,k=w/x- -1;if(u.resid2cnt.hasOwnProperty(t)?++u.resid2cnt[t]:u.resid2cnt[t]=0,!c&&!u.resid2ToXy.hasOwnProperty(_)){let e=parseInt(R/u.svgGridSize),i=parseInt(k/u.svgGridSize),s=[];for(let t=1;t>=-1;--t)for(let n=1;n>=-1;--n)0==t&&0==n||e+t>=0&&e+t<=r&&i+n>=0&&i+n<=a&&s.push(e+t+"_"+(i+n));for(let t=2;t>=-2;--t)for(let n=2;n>=-2;--n)t>=-1&&t<=1&&n>=-1&&n<=1||e+t>=0&&e+t<=r&&i+n>=0&&i+n<=a&&s.push(e+t+"_"+(i+n));let n,d=!1;for(let e=0,t=s.length;e<t;++e)if(!u.gridXY2used[s[e]]){n=s[e].split("_"),M=(parseInt(n[0])+.5)*u.svgGridSize,T=(parseInt(n[1])+.5)*u.svgGridSize;let t=Math.sqrt((R-M)*(R-M)+(k-T)*(k-T));M=f/t*(M-R)+R,T=f/t*(T-k)+k,u.gridXY2used[s[e]]=1,d=!0;break}if(!d){let e=R-o,i=k-l,s=0;s=Math.abs(e)>Math.abs(i)?e>0?0:180:i>0?90:270,E=s-10+30*u.resid2cnt[t],M=R+f*Math.cos(E*Math.PI/180),T=k+f*Math.sin(E*Math.PI/180)}}let O,I=m.utilsCls.residueName2Abbr(y.resn.substr(0,3))+y.resi,P=y.color?y.color.getHexString():"000",D=u.lineGraphCls.getStrokecolor(void 0,s),L="",F="",N=_+"--"+e.join("-")+s;"hbond"==s?O="H-Bonds":"ionic"==s?O="Salt Bridge/Ionic":"halogen"==s?O="Halogen Bonds":"pi-cation"==s?O="π-Cation":"pi-stacking"==s?O="π-Stacking":"contact"==s&&(O="Contacts");let U=_;if(c||u.resid2ToXy.hasOwnProperty(U)){M=u.resid2ToXy.hasOwnProperty(U)?u.resid2ToXy[U].x2:h,T=u.resid2ToXy.hasOwnProperty(U)?u.resid2ToXy[U].y2:p;let e=R,t=k,i=0;if("contact"==s){let s=Math.sqrt((R-M)*(R-M)+(k-T)*(k-T));g<s&&(e=g/s*(R-M)+M,t=g/s*(k-T)+T,i=1)}F+="<g><title>Interaction type: "+O+"; Distance: "+parseFloat(d).toFixed(1)+" Å</title>",F+='<line class="icn3d-interaction" id="'+N+'" resid1="'+C+'" resid2="'+_+'" x1="'+e.toFixed(2)+'" y1="'+t.toFixed(2)+'" x2="'+M.toFixed(2)+'" y2="'+T.toFixed(2)+'" x0="'+R.toFixed(2)+'" y0="'+k.toFixed(2)+'" short="'+i+'" opacity="1.0" stroke="'+D+'" stroke-width="'+b+'" stroke-dasharray="5,5"/>\n',F+="</g>\n"}else{L+="<g><title>"+I+"</title>";let e=28,t=14;L+='<rect id="'+U+'_node" x="'+(M-.5*e).toFixed(2)+'" y="'+(T-.5*t).toFixed(2)+'" width="'+e+'" height="'+t+'" rx="2" ry="2" fill="#'+P+'" stroke-width="1" stroke="'+P+'" resid="'+_+'"/>',L+='<text class="icn3d-ctnode" resid="'+U+'" id="'+U+'" x="'+M.toFixed(2)+'" y="'+T.toFixed(2)+'" fill="#000" stroke="none" text-anchor="middle" alignment-baseline="central" style="font-size:10px">'+I+"</text>",L+="</g>\n",F+="<g><title>Interaction type: "+O+"; Distance: "+parseFloat(d).toFixed(1)+" Å</title>",F+='<line class="icn3d-interaction" id="'+N+'" resid1="'+C+'" resid2="'+_+'" x1="'+R.toFixed(2)+'" y1="'+k.toFixed(2)+'" x2="'+M.toFixed(2)+'" y2="'+T.toFixed(2)+'" opacity="1.0" stroke="'+D+'" stroke-width="'+b+'" stroke-dasharray="5,5"/>',F+="</g>\n","contact"!=s&&(u.resid2ToXy.hasOwnProperty(_)||(u.resid2ToXy[_]={x2:M,y2:T}))}return u.nodeid2lineid.hasOwnProperty(U)||(u.nodeid2lineid[U]=[]),u.nodeid2lineid[U].push(N),{node:L,line:F,x2:M,y2:T}}setEventsForLigplot(){let e=this.icn3d,t=e.icn3dui;$("#"+t.ligplotid+" .icn3d-ctnode").draggable({start:function(e,t){let i=parseFloat(e.target.getAttribute("x")),s=parseFloat(e.target.getAttribute("y"));e.target.setAttribute("x",i),e.target.setAttribute("y",s)},drag:function(i,s){let n=e.ligplotScale?e.ligplotScale:1,r=$("#"+t.ligplotid).offset().left+e.len4ang*n,a=$("#"+t.ligplotid).offset().top+e.len4ang*n,o=i.target.getAttribute("resid"),l=(i.clientX-r)/n,d=(i.clientY-a)/n,c=parseFloat(i.target.getAttribute("x")),h=parseFloat(i.target.getAttribute("y")),p=l-c,u=d-h;if(c=parseFloat($("#"+o+"_node").attr("x")),h=parseFloat($("#"+o+"_node").attr("y")),$("#"+o+"_node").attr("x",c+p),$("#"+o+"_node").attr("y",h+u),i.target.setAttribute("x",l),i.target.setAttribute("y",d),e.nodeid2lineid[o])for(let t=0,i=e.nodeid2lineid[o].length;t<i;++t){m(e.nodeid2lineid[o][t],o)}function m(t,i){if(t&&-1!=t.indexOf(i)){let i=t.split("--");if(2==i.length){let s;i[1],s=i[0];let n=parseFloat($("#"+s).attr("x")),r=parseFloat($("#"+s).attr("y"));$("#"+t).attr("x2",n),$("#"+t).attr("y2",r);let a=$("#"+t).attr("x1"),o=$("#"+t).attr("y1"),l=a,d=o;if(parseInt($("#"+t).attr("short"))){a=$("#"+t).attr("x0"),o=$("#"+t).attr("y0");let i=Math.sqrt((a-n)*(a-n)+(o-r)*(o-r)),s=e.len4ang/2;s<i&&(l=s/i*(a-n)+n,d=s/i*(o-r)+r)}$("#"+t).attr("x1",l),$("#"+t).attr("y1",d)}}}}})}clickLigplot(){let e=this.icn3d;e.icn3dui;let t=this;$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-ctnode",(function(e){let i=t.icn3d;e.stopImmediatePropagation(),i.diagram2dCls.clickNode(this)}))}}class hp{constructor(e){this.icn3d=e}resizeCanvas(e,t,i,s){var n=this.icn3d,r=n.icn3dui;if(i||r.cfg.resize){let i=t;$("#"+n.pre+"canvas").width(e).height(i),$("#"+n.pre+"viewer").width(e).height(t),$("#"+n.divid+" div:has(#"+n.pre+"canvas)").width(e).height(i),n.applyCenterCls.setWidthHeight(e,i),n.structures&&Object.keys(n.structures).length>0&&(void 0===s||s)&&n.drawCls.draw()}}windowResize(){let e=this.icn3d.icn3dui,t=this;e.cfg.resize&&!e.utilsCls.isMobile()&&$(window).resize((function(){let i=t.icn3d;e.utilsCls.setViewerWidthHeight(i.icn3dui);let s=e.htmlCls.WIDTH,n=e.htmlCls.HEIGHT;void 0===i||i.bFullscreen||t.resizeCanvas(s,n)}))}openFullscreen(e){this.icn3d.icn3dui.bNode||document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement||(e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen())}rotStruc(e,t){var i=this.icn3d;i.icn3dui;let s=this;if(i.bStopRotate)return!1;if(i.transformCls.rotateCount>i.transformCls.rotateCountMax)return i.transformCls.resetOrientation(),!1;if(++i.transformCls.rotateCount,t)if("left"===e)i.ROT_DIR="left";else if("right"===e)i.ROT_DIR="right";else if("up"===e)i.ROT_DIR="up";else{if("down"!==e)return!1;i.ROT_DIR="down"}if("left"===e&&"left"===i.ROT_DIR)i.transformCls.rotateLeft(1);else if("right"===e&&"right"===i.ROT_DIR)i.transformCls.rotateRight(1);else if("up"===e&&"up"===i.ROT_DIR)i.transformCls.rotateUp(1);else{if("down"!==e||"down"!==i.ROT_DIR)return!1;i.transformCls.rotateDown(1)}setTimeout((function(){s.rotStruc(e)}),100)}async back(){var e=this.icn3d;e.icn3dui,e.backForward=!0,e.STATENUMBER--,e.bAddCommands=!1,e.bAddLogs=!1,e.bNotLoadStructure=!0,e.STATENUMBER<1?e.STATENUMBER=1:await e.loadScriptCls.execCommands(0,e.STATENUMBER-1,e.STATENUMBER,!0),e.setStyleCls.adjustIcon(),e.bAddCommands=!0,e.bAddLogs=!0}async forward(){var e=this.icn3d;e.icn3dui,e.backForward=!0,e.STATENUMBER++,e.bAddCommands=!1,e.bAddLogs=!1,e.bNotLoadStructure=!0,e.STATENUMBER>e.commands.length?e.STATENUMBER=e.commands.length:await e.loadScriptCls.execCommands(0,e.STATENUMBER-1,e.STATENUMBER,!0),e.setStyleCls.adjustIcon(),e.bAddCommands=!0,e.bAddLogs=!0}async replayon(){var e=this.icn3d;e.icn3dui,e.CURRENTNUMBER=0,e.bReplay=1,$("#"+e.pre+"replay").show(),e.commands.length>0&&await e.loadScriptCls.replayFirstStep(e.CURRENTNUMBER)}async replayoff(){var e=this.icn3d;e.icn3dui,e.bReplay=0,$("#"+e.pre+"replay").hide(),++e.CURRENTNUMBER,await e.loadScriptCls.execCommands(e.CURRENTNUMBER,e.STATENUMBER-1,e.STATENUMBER)}closeDialogs(){var e=this.icn3d,t=e.icn3dui;let i=["dl_2ddgm","dl_2dctn","dl_alignment","dl_sequence2","dl_definedsets","dl_setsmenu","dl_command","dl_setoperations","dl_vast","dl_foldseek","dl_mmtfid","dl_pdbid","dl_afid","dl_opmid","dl_pdbfile","dl_pdbfile_app","dl_rescolorfile","dl_customcolor","dl_align","dl_alignaf","dl_chainalign","dl_chainalign2","dl_chainalign3","dl_mutation","dl_mol2file","dl_sdffile","dl_xyzfile","dl_clustalwfile","dl_fastafile","dl_afmapfile","dl_urlfile","dl_mmciffile","dl_mmcifid","dl_mmdbid","dl_mmdbafid","dl_blast_rep_id","dl_yournote","dl_proteinname","dl_refseqid","dl_cid","dl_pngimage","dl_state","dl_fixedversion","dl_selection","dl_dsn6","dl_dsn6url","dl_clr","dl_symmetry","dl_symd","dl_contact","dl_hbonds","dl_realign","dl_realignbystruct","dl_allinteracton","dl_interactionsorted","dl_linegraph","dl_linegraphcolor","dl_scatterplot","dl_scatterploitcolor","dl_contactmap","dl_alignerrormap","dl_elecmap2fofc","dl_elecmapfofc","dl_emmap","dl_aroundsphere","dl_adjustmem","dl_selectplane","dl_addlabel","dl_addlabelselection","dl_labelColor","dl_distance","dl_stabilizer","dl_disttwosets","dl_distmanysets","dl_stabilizer_rm","dl_thickness","dl_thickness2","dl_addtrack","dl_addtrack_tabs","dl_saveselection","dl_copyurl","dl_selectannotations","dl_annotations_tabs","dl_anno_view_tabs","dl_annotations","dl_graph","dl_svgcolor","dl_area","dl_colorbyarea","dl_rmsd","dl_buriedarea","dl_propbypercentout","dl_propbybfactor","dl_legend","dl_disttable","dl_translate"];for(let s in i){let n=i[s];t.cfg.notebook?$("#"+e.pre+n).hide():$("#"+e.pre+n).hasClass("ui-dialog-content")&&$("#"+e.pre+n).dialog("isOpen")&&$("#"+e.pre+n).dialog("close").remove()}t.cfg.notebook||this.resizeCanvas(t.htmlCls.WIDTH,t.htmlCls.HEIGHT,!0)}}class pp{constructor(e){this.icn3d=e}resetOrientation_base(e){let t=this.icn3d;if(t.icn3dui,2==e.length&&e[1].length>0)if(t.bSetCamera){let i=JSON.parse(e[1]);t._zoomFactor=i.factor,t.mouseChange.x=i.mouseChange.x,t.mouseChange.y=i.mouseChange.y,t.quaternion._x=i.quaternion._x,t.quaternion._y=i.quaternion._y,t.quaternion._z=i.quaternion._z,t.quaternion._w=i.quaternion._w}else{e[1].split("|").forEach((e=>{let i=e.split(":");if("fov"==i[0])t.cam.fov=parseFloat(i[1]);else{let e=i[1].split(",");"pos"==i[0]?t.cam.position.set(parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])):"dir"==i[0]?t.cam.quaternion.setFromUnitVectors(new mt(0,0,-1),new mt(parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2]))):"up"==i[0]&&t.cam.up.set(parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2]))}}))}else t._zoomFactor=1,t.mouseChange=new pt(0,0),t.quaternion=new ut(0,0,0,1)}resetOrientation(){let e=this.icn3d;if(e.icn3dui,e.commands.length>0){let t=e.commands[0].split("|||");this.resetOrientation_base(t)}e.maxD=e.oriMaxD,e.center=e.oriCenter.clone(),"show"==e.ori_chemicalbinding?e.bSkipChemicalbinding=!1:"hide"==e.ori_chemicalbinding&&(e.bSkipChemicalbinding=!0)}rotateLeft(e){let t=this.icn3d,i=t.icn3dui,s=new mt(0,1,0),n=-e/180*Math.PI;t.bControlGl&&!i.bNode?s.applyQuaternion(window.cam.quaternion).normalize():s.applyQuaternion(t.cam.quaternion).normalize();let r=new ut;r.setFromAxisAngle(s,-n);let a={};a.quaternion=r,a.update=!0,t.bControlGl&&!i.bNode?window.controls.update(a):t.controls.update(a),t.bRender&&t.drawCls.render()}rotateRight(e){let t=this.icn3d,i=t.icn3dui,s=new mt(0,1,0),n=e/180*Math.PI;t.bControlGl&&!i.bNode?s.applyQuaternion(window.cam.quaternion).normalize():s.applyQuaternion(t.cam.quaternion).normalize();let r=new ut;r.setFromAxisAngle(s,-n);let a={};a.quaternion=r,a.update=!0,t.bControlGl&&!i.bNode?window.controls.update(a):t.controls.update(a),t.bRender&&t.drawCls.render()}rotateUp(e){this.icn3d.icn3dui,this.rotate_base(-e)}rotateDown(e){this.icn3d.icn3dui,this.rotate_base(e)}rotate_base(e){let t=this.icn3d,i=t.icn3dui,s=new mt(1,0,0),n=e/180*Math.PI;t.bControlGl&&!i.bNode?s.applyQuaternion(window.cam.quaternion).normalize():s.applyQuaternion(t.cam.quaternion).normalize();let r=new ut;r.setFromAxisAngle(s,-n);let a={};a.quaternion=r,a.update=!0,t.bControlGl&&!i.bNode?window.controls.update(a):t.controls.update(a),t.bRender&&t.drawCls.render()}setRotation(e,t){let i=this.icn3d,s=i.icn3dui;if(!e)return;i.bControlGl&&!s.bNode&&window.cam?e.applyQuaternion(window.cam.quaternion).normalize():i.cam&&e.applyQuaternion(i.cam.quaternion).normalize();let n=new ut;n.setFromAxisAngle(e,-t);let r={};r.quaternion=n,r.update=!0,i.bControlGl&&!s.bNode&&window.controls?window.controls.update(r):i.controls&&i.controls.update(r),i.bRender&&i.drawCls.render()}translateLeft(e){this.icn3d.icn3dui,this.translate_base(-e,0)}translateRight(e){this.icn3d.icn3dui,this.translate_base(e,0)}translateUp(e){this.icn3d.icn3dui,this.translate_base(0,-e)}translateDown(e){this.icn3d.icn3dui,this.translate_base(0,e)}translate_base(e,t){let i=this.icn3d,s=i.icn3dui,n=new pt(0,0);n.x+=e/100,n.y+=t/100;let r={};r.mouseChange=n,r.update=!0,i.bControlGl&&!s.bNode?window.controls.update(r):i.controls.update(r),i.bRender&&i.drawCls.render()}translateCoord(e,t,i,s){let n=this.icn3d;n.icn3dui;for(let r in e){let e=n.atoms[r];e.coord.x+=t,e.coord.y+=i,e.coord.z+=s}}rotateCoord(e,t){let i=this.icn3d;i.icn3dui;const s=new gi;s.elements=t;for(let t in e){let e=i.atoms[t];e.coord=e.coord.applyMatrix4(s)}}zoominSelection(e){let t=this.icn3d,i=t.icn3dui,s={};if(s._zoomFactor=1/t._zoomFactor,s.update=!0,t.bControlGl&&!i.bNode?window.controls&&window.controls.update(s):t.controls&&t.controls.update(s),void 0===e&&(e=i.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)),Object.keys(e).length>1){let i=t.applyCenterCls.centerAtoms(e);t.maxD=i.maxD,t.maxD<5&&(t.maxD=5),t.center=i.center,t.applyCenterCls.setCenter(t.center),t.cameraCls.setCamera()}}getTransformationStr(e){var t=this.icn3d;if(t.icn3dui,t.bTransformation){let t={factor:1,mouseChange:{x:0,y:0},quaternion:{_x:0,_y:0,_z:0,_w:1}};return t.factor=parseFloat(e.factor).toPrecision(4),t.mouseChange.x=parseFloat(e.mouseChange.x).toPrecision(4),t.mouseChange.y=parseFloat(e.mouseChange.y).toPrecision(4),t.quaternion._x=parseFloat(e.quaternion._x).toPrecision(4),t.quaternion._y=parseFloat(e.quaternion._y).toPrecision(4),t.quaternion._z=parseFloat(e.quaternion._z).toPrecision(4),t.quaternion._w=parseFloat(e.quaternion._w).toPrecision(4),"1.0000"==t.factor&&(t.factor=1),"0.0000"==t.mouseChange.x&&(t.mouseChange.x=0),"0.0000"==t.mouseChange.y&&(t.mouseChange.y=0),"0.0000"==t.quaternion._x&&(t.quaternion._x=0),"0.0000"==t.quaternion._y&&(t.quaternion._y=0),"0.0000"==t.quaternion._z&&(t.quaternion._z=0),"1.0000"==t.quaternion._w&&(t.quaternion._w=1),JSON.stringify(t)}if(t.cam){let e="";e+="pos:"+t.cam.position.x.toPrecision(4)+","+t.cam.position.y.toPrecision(4)+","+t.cam.position.z.toPrecision(4);let i=new mt(0,0,-1).applyQuaternion(t.cam.quaternion);return e+="|dir:"+i.x.toPrecision(4)+","+i.y.toPrecision(4)+","+i.z.toPrecision(4),e+="|up:"+t.cam.up.x.toPrecision(4)+","+t.cam.up.y.toPrecision(4)+","+t.cam.up.z.toPrecision(4),e+="|fov:"+t.cam.fov.toPrecision(4),e}return""}}class up{constructor(e){this.icn3d=e}async saveFile(e,t,i,s,n){let r,a=this.icn3d,o=a.icn3dui,l=this;if("command"===t){let e=a.loadCmd?a.loadCmd+"\n":"";for(let t=0,i=a.commands.length;t<i;++t){let s=a.commands[t].trim();if(t==i-1){let e=s.split("|||"),t={};t.factor=a._zoomFactor,t.mouseChange=a.mouseChange,t.quaternion=a.quaternion,s=e[0]+"|||"+a.transformCls.getTransformationStr(t)}e+=s+"\n"}let t=decodeURIComponent(e);r=new Blob([t],{type:"text;charset=utf-8;"})}else if("png"===t){let t=$("#"+a.pre+"canvas").width(),i=$("#"+a.pre+"canvas").height();a.applyCenterCls.setWidthHeight(t,i),a.bRender&&a.drawCls.render();let d=!0;if(window.File&&window.FileReader&&window.FileList&&window.Blob||(d=!1),r=o.utilsCls.isIE()?a.renderer.domElement.msToBlob():await this.getBlobFromNonIE(),n)return r;if(!d)return l.saveBlob(r,e,s,t,i),r;{let n=new FileReader;n.onload=function(n){let d=n.target.result,c=a.shareLinkCls.getPngText();return r=o.convertTypeCls.getBlobFromBufferAndText(d,c),l.saveBlob(r,e,s,t,i),r},n.readAsArrayBuffer(r)}a.scaleFactor=1,a.applyCenterCls.setWidthHeight(t,i),a.bRender&&a.drawCls.render()}else if("html"===t){let e=decodeURIComponent(i);r=new Blob([e],{type:"text/html;charset=utf-8;"})}else if("text"===t){r=new Blob(i,{type:"text;charset=utf-8;"})}else if("binary"===t){r=new Blob(i,{type:"application/octet-stream"})}return"png"!==t&&(n||saveAs(r,e)),r}getBlobFromNonIE(){let e=this.icn3d;return e.icn3dui,new Promise((function(t,i){e.renderer.domElement.toBlob((function(e){t(e)}))}))}saveBlob(e,t,i,s,n){let r=this.icn3d;if(r.icn3dui,i){let t=(window.URL||window.webkitURL).createObjectURL(e),i=r.shareLinkCls.shareLinkUrl();i=i.replace(/imageonly=1/g,""),i.length>4e3||0!==i.indexOf("http")||r.bInputfile&&!r.bInputUrlfile?$("#"+r.pre+"viewer").html("<img src='"+t+"'/>"):$("#"+r.pre+"viewer").html("<a href='"+i+"' target='_blank'><img src='"+t+"'/></a>"),$("#"+r.pre+"viewer").width(s),$("#"+r.pre+"viewer").height(n),$("#"+r.pre+"cmdlog").hide(),$("#"+r.pre+"title").hide(),$("#"+r.pre+"mnlist").hide(),$("#"+r.pre+"fullscreen").length>0&&$("#"+r.pre+"fullscreen").hide(),r={}}else saveAs(e,t)}saveSvg(e,t,i,s){let n=this.icn3d;if(n.icn3dui.bNode)return"";let r=$("#"+e).width(),a=$("#"+e).height();i&&(a=r),s&&(r+=n.len4ang,a+=n.len4ang);let o=this.getSvgXml(e,r,a,i,s),l=new Blob([o],{type:"image/svg+xml"});saveAs(l,t)}getSvgXml(e,t,i,s,n){if(this.icn3d.icn3dui.bNode)return"";return(t&&i?'<svg viewBox="'+(n?-30:0)+" "+(n?-30:0)+" "+t+" "+i+'"':"<svg")+' title="graph" xmlns:xl="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xmlns:dc="http://purl.org/dc/elements/1.1/">'+"<style>text {font-family: sans-serif; font-weight: bold; font-size: 18px;}</style>"+document.getElementById(e).innerHTML+"</svg>"}savePng(e,t,i,s){let n=this.icn3d,r=n.icn3dui;if(r.bNode)return"";let a=$("#"+e).width(),o=$("#"+e).height();i&&(o=a);let l=document.getElementById(e),d=l.getBBox(),c=l.cloneNode(!0);s||n.lineGraphCls.copyStylesInline(c,l);let h=document.createElement("CANVAS");h.width=a,h.height=o;let p=h.getContext("2d");p.clearRect(0,0,d.width,d.height);let u=this.getSvgXml(e,a,o,i),m=window.URL||window.webkitURL||window,f=new Blob([u],{type:"image/svg+xml;charset=utf-8"}),g=new Image;g.src=m.createObjectURL(f),g.onload=function(){if(p.drawImage(g,0,0),m.revokeObjectURL(this.src),r.utilsCls.isIE()){let e=h.msToBlob();e&&(saveAs(e,t),h.remove())}else h.toBlob((function(e){e&&(saveAs(e,t),h.remove())}))}}exportCustomAtoms(e){var t=this.icn3d;t.icn3dui;let i="",s=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues).sort():[];for(let n=0,r=s.length;n<r;++n){let r=s[n],a=t.defNames2Residues[r];t.defNames2Descr[r];let o=t.defNames2Command[r];o=o.replace(/,/g,", "),i+=this.exportResidues(r,a,e)}s=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms).sort():[];for(let n=0,r=s.length;n<r;++n){let r=s[n],a=t.defNames2Atoms[r];t.defNames2Descr[r];let o=t.defNames2Command[r];o=o.replace(/,/g,", ");let l=t.resid2specCls.atoms2residues(a);i+=this.exportResidues(r,l,e)}return i}exportResidues(e,t,i){var s=this.icn3d,n=s.icn3dui;let r="";if(t.length>0)if(i){let i={};for(let e=0,r=t.length;e<r;++e){let r=t[e],a=s.firstAtomObjCls.getFirstAtomObj(s.residues[r]);if(!a)continue;let o=a.structure+"_"+a.chain,l=n.utilsCls.residueName2Abbr(a.resn)+a.resi;i.hasOwnProperty(o)||(i[o]=[]),i[o].push(l)}r+=e+":\n";for(let e in i){let t=1==i[e].length?"residue":"residues";r+=e+" ("+i[e].length+" "+t+"): ",r+=i[e].join(", "),r+="\n"}r+="\n"}else r+=e+"\tselect ",r+=s.resid2specCls.residueids2spec(t),r+="\n";return r}printPrevSecondary(e,t,i,s){this.icn3d.icn3dui;let n="";if(i)if(e){let e=1;n+=i.resn.padStart(5," ")+i.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+i.resi.toString().padStart(5," ")+" "+e+s.toString().padStart(36," ")+"\n"}else if(t){let e=0;n+=i.resn.padStart(5," ")+i.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+i.resi.toString().padStart(4," ")+" "+e+"\n"}return n}getAtomPDB(e,t,i,s,n,r,a,o){let l=this.icn3d,d=l.icn3dui,c="",h={},p={};for(let e in l.chemicals){let t=l.atoms[e];if("P"==t.elem){h[e]=1;for(let e=0,i=t.bonds.length;e<i;++e){let i=t.bonds[e];i&&"O"==l.atoms[i].elem&&(p[i]=1)}}}let u,m,f=d.hashUtilsCls.intHash(e,l.calphas),g={};for(let e in l.structures)g[e]="";let b=[];for(let e in f){let t=l.atoms[e];m=t.structure,t.structure,t.chain;let i={};if(i.chain=t.chain,i.resn=t.resn,i.resi=t.resi,parseInt(t.resi)>parseInt(u)+1||t.ssbegin){let e=d.hashUtilsCls.cloneHash(i);e.ss=" ",b.push(e)}"helix"==t.ss?(i.ss="H",b.push(i)):"sheet"==t.ss&&(i.ss="S",b.push(i)),u=t.resi}let C,v,_=0,y=!1,S=!1;for(let e=0,t=b.length;e<t;++e){let t=b[e];t.ss!=C&&(" "!==C&&(g[m]+=this.printPrevSecondary(y,S,v,_)),_=0,y=!1,S=!1,v=void 0," "!==t.ss&&("H"==t.ss?(y=!0,v=t,g[m]+="HELIX".padEnd(15," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(5," ")):"S"==t.ss&&(S=!0,v=t,g[m]+="SHEET".padEnd(17," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(4," "))))," "!==t.ss&&(++_,v=t),C=t.ss}if(g[m]+=this.printPrevSecondary(y,S,v,_),g[m]+="\n",l.biomtMatrices&&Object.keys(e).length==Object.keys(l.atoms).length){let e=Object.keys(l.structures)[0];for(let t=0,i=l.biomtMatrices.length;t<i;++t){let i=t+1;for(let s=0;s<3;++s){let n=s+1;g[e]+="REMARK 350 BIOMT"+n.toString()+" "+i.toString().padStart(2," ")+" "+l.biomtMatrices[t].elements[s+0].toFixed(6).toString().padStart(9," ")+" "+l.biomtMatrices[t].elements[s+4].toFixed(6).toString().padStart(9," ")+" "+l.biomtMatrices[t].elements[s+8].toFixed(6).toString().padStart(9," ")+" "+l.biomtMatrices[t].elements[s+12].toFixed(6).toString().padStart(14," ")+"\n"}}}for(let e in l.chainMissingResidueArray){let t=e.indexOf("_"),i=e.substr(t+1,2),s=e.substr(0,t);for(let t=0,n=l.chainMissingResidueArray[e].length;t<n;++t){let n=l.chainMissingResidueArray[e][t].resi,r=d.utilsCls.residueAbbr2Name(l.chainMissingResidueArray[e][t].name);g[s]+="REMARK 465 "+r.padStart(3," ")+i.padStart(2," ")+" "+n.toString().padStart(5," ")+"\n"}}let w="",x=Object.keys(l.structures).length>1,A=1,M="",T="",E=0,R="",k={};for(let r in e){let e=l.atoms[r];if(i&&e.het)continue;if(e.structure!=M){a&&x||(c+=w,w="",A>1&&(c+="\nENDMDL\n"),x&&(c+="MODEL "+A+"\n"));let t=n?"Mutated chain_residue "+Object.keys(n)+"; ":"";s||a&&x||(c+=this.getPDBHeader(A-1,g,t,e.structure)),++A}e.chain!=T&&e.structure==M&&T&&(c+="TER\n");let u=e.chain+"_"+e.resi;if(n&&n.hasOwnProperty(u)){k.hasOwnProperty(u)||(c+=n[u],k[u]=1);continue}let m="";m+=e.het?"HETATM":"ATOM ",m+=r.toString().padStart(5," "),m+=" ";let f=e.name.trim();isNaN(f.substr(0,1))||(f=f.substr(1)+f.substr(0,1)),4==f.length?m+=f:(m+=" ",f=f.replace(/\*/g,"'"),"O1P"==f?f="OP1":"O2P"==f?f="OP2":"C5M"==f&&(f="C7 "),m+=f.padEnd(3," ")),m+=" ";let b=e.resn;if(m+=b.length<=3?b.padStart(3," "):b.substr(0,3),a&&A>2&&(l.proteins.hasOwnProperty(e.serial)||l.nucleotides.hasOwnProperty(e.serial)))e.structure==M&&e.chain==T||(R=E<36?"abcdefghijklmnopqrstuvwxyz0123456789"[E]:"?",++E),m+=" "+R;else if(e.chain.length>=2){let t=e.chain.replace(/_/gi,"").substr(0,2);o&&(t=" "+t.substr(0,1)),m+=t}else 1==e.chain.length?m+=" "+e.chain.substr(0,1):0==e.chain.length&&(m+=" A");let C=e.resi;!isNaN(C)&&e.chain.length>3&&!isNaN(e.chain.substr(3))&&(C=C-1+parseInt(e.chain.substr(3)));let v=parseInt(C);m+=v.toString().length<=4?v.toString().padStart(4," "):v.toString().substr(0,4);let _=e.resi.toString().substr(e.resi.toString().length-1,1);if(isNaN(_)?m+=_:m+=" ",m+=" ".padStart(3," "),m+=e.coord.x.toFixed(3).toString().padStart(8," "),m+=e.coord.y.toFixed(3).toString().padStart(8," "),m+=e.coord.z.toFixed(3).toString().padStart(8," "),t&&e.het){let t=1.5,i=0;"C"==e.elem?t=1.908:"N"==e.elem?t=1.824:"O"==e.elem?t=1.6612:"H"==e.elem?t=1.25:"S"==e.elem?t=2:"P"==e.elem?t=2.1:d.parasCls.vdwRadii.hasOwnProperty(e.elem)&&(t=d.parasCls.vdwRadii[e.elem]),void 0!==d.cfg.cid&&void 0!==e.crg?i=e.crg:h.hasOwnProperty(r)?i=1.38:p.hasOwnProperty(r)?i=-.595:d.parasCls.ionCharges.hasOwnProperty(e.elem)&&(i=d.parasCls.ionCharges[e.elem]),m+=i.toFixed(4).toString().padStart(8," "),m+=t.toFixed(4).toString().padStart(7," ")}else{m+="1.00".padStart(6," ");let t=" ";m+=e.b?parseFloat(e.b).toFixed(2).toString().padStart(6," "):t.padStart(6," "),m+=" ".padStart(10," "),m+=e.elem.padStart(2," "),m+=" ".padStart(2," ")}if(e.het&&e.bonds.length>0){w+="CONECT"+r.toString().padStart(5," ");let t={};for(let i=0,s=e.bonds.length;i<s;++i)e.bonds[i]&&!t.hasOwnProperty(e.bonds[i])&&(w+=e.bonds[i].toString().padStart(5," "),t[e.bonds[i]]=1);w+="\n"}c+=m+"\n",M=e.structure,T=e.chain}return a&&x||(c+=w,x&&(c+="\nENDMDL\n")),c}getSecondary(e){let t=this.icn3d,i=t.icn3dui,s='{"data": [\n',n="",r="",a={};for(let s in e){let e=t.atoms[s],o=e.structure+"_"+e.chain,l=e.resi,d=i.utilsCls.residueName2Abbr(e.resn),c=this.secondary2Abbr(e.ss);e.ssbegin?c+=" begin":e.ssend&&(c+=" end"),o==n||a[o]||(a[o]={resi:[],resn:[],secondary:[]}),o==n&&l==r||(a[o].resi.push(l),a[o].resn.push(d),a[o].secondary.push(c)),n=o,r=l}let o=Object.keys(a),l=o.length;for(let e=0;e<l;++e){let t=o[e];s+='{"chain": "'+t+'",\n',s+='"resi": "'+a[t].resi.join(",")+'",\n',s+='"resn": "'+a[t].resn.join(",")+'",\n',s+='"secondary": "'+a[t].secondary.join(",")+'"',s+=e<l-1?"},\n":"}\n"}return s+="]}\n",s}secondary2Abbr(e){return this.icn3d.icn3dui,"helix"==e?"H":"sheet"==e?"E":"c"}getSelectedResiduePDB(){let e=this.icn3d,t="",i=e.icn3dui.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);return t+=this.getAtomPDB(i),t}getPDBHeader(e,t,i,s){let n=this.icn3d;n.icn3dui,void 0===e&&(e=0);let r="",a=s||Object.keys(n.structures)[e],o=i?a+"2":a;if(r+="HEADER PDB From iCn3D".padEnd(62," ")+o+"\n",0==e){let e=n.molTitle.length>50?n.molTitle.substr(0,47)+"...":n.molTitle;-1!=e.indexOf('"')&&(e=""),i&&(e=i+e),r+="TITLE "+e+"\n"}return t&&t[a]&&(r+=t[a]),r}showTitle(){var e=this.icn3d,t=e.icn3dui;let i=e.molTitle?e.molTitle:"",s="black"==e.opts.background?t.htmlCls.GREYD:"black";if(void 0===e.inputid)i.length>40&&(i=i.substr(0,40)+"..."),$("#"+e.pre+"title").html(i);else if(void 0!==t.cfg.cid){let t=this.getLinkToStructureSummary();$("#"+e.pre+"title").html("PubChem CID <a id='"+e.pre+"titlelink' href='"+t+"' style='color:"+s+"' target='_blank'>"+e.inputid.toUpperCase()+"</a>: "+i)}else if(void 0!==t.cfg.smiles){let i=decodeURIComponent(t.cfg.smiles);i.length>60&&(i=i.substr(0,60)+"..."),$("#"+e.pre+"title").html("SMILES: "+i)}else if(void 0!==t.cfg.align)i="VAST+ alignment of "+Object.keys(e.structures),$("#"+e.pre+"title").html(i);else if(void 0!==t.cfg.chainalign){i="Dynamic Structure Alignment of Chains: "+t.cfg.chainalign.split(","),$("#"+e.pre+"title").html(i)}else{let n=Object.keys(t.utilsCls.getStructures(e.dAtoms));if(n.length>1){i="Multiple structures: ";for(let e=0,t=n.length;e<t;++e){i+='<a href="'+(isNaN(n[e])&&n[e].length>5?"https://alphafold.ebi.ac.uk/entry/"+n[e]:"https://www.ncbi.nlm.nih.gov/structure/?term="+n[e])+'" style="color:'+s+'" target="_blank">'+n[e]+"</a>",e<t-1&&(i+=", ")}$("#"+e.pre+"title").html(i)}else if(1==n.length){let e=isNaN(n[0])&&n[0].length>5?"https://alphafold.ebi.ac.uk/entry/"+n[0]:"https://www.ncbi.nlm.nih.gov/structure/?term="+n[0];this.setStructureTitle(e,i,s)}}}setStructureTitle(e,t,i){var s=this.icn3d,n=s.icn3dui;t.length>40&&(t=t.substr(0,40)+"...");let r,a,o=s.inputid;if(-1!=o.indexOf("http"))a="Data from",e=o,r=o;else{let e=n.utilsCls.getHlStructures(),i=!1,l=!1;for(let t in e)t.length>5?l=!0:i=!0;let d=Object.keys(e);if(o=d.join(","),r=n.cfg.refseqid||n.cfg.protein?s.inputid:o.toUpperCase(),i&&l?a="AlphaFold/PDB ID":i?a="PDB ID":l&&(a="AlphaFold ID"),d.length>1&&(a+="s"),s.molTitleHash){t="";for(let e=0,i=d.length;e<i;++e)t+=s.molTitleHash[d[e]],e<i-1&&(t+="; ")}}if(n.cfg.refseqid?a="NCBI Protein Acc.":n.cfg.protein&&(a="Protein/Gene Name"),o&&o.substr(0,4)!=s.defaultPdbId)if(n.cfg.blast_rep_id){let e=n.cfg.oriQuery_id?n.cfg.oriQuery_id:n.cfg.query_id,i=n.cfg.oriBlast_rep_id?n.cfg.oriBlast_rep_id:n.cfg.blast_rep_id;e.length>20&&(e=e.substr(0,17)+"..."),r="Query: "+e+"; target: "+i,$("#"+s.pre+"title").html(r+", "+t)}else $("#"+s.pre+"title").html(a+" <a id='"+s.pre+"titlelink' href='"+e+"' style='color:"+i+"' target='_blank'>"+r+"</a>: "+t);else $("#"+s.pre+"title").html(t)}getLinkToStructureSummary(e){var t=this.icn3d,i=t.icn3dui;let s="https://www.ncbi.nlm.nih.gov/structure/?term=";if(s=void 0!==i.cfg.cid?"https://www.ncbi.nlm.nih.gov/pccompound/?term=":void 0!==i.cfg.refseqid?"https://www.ncbi.nlm.nih.gov/protein/":void 0!==i.cfg.afid?"https://alphafold.ebi.ac.uk/search/text/":Object.keys(t.structures).length>1?"https://www.ncbi.nlm.nih.gov/structure/?term=":i.htmlCls.baseUrl+"pdb/",void 0===t.inputid)s="https://www.ncbi.nlm.nih.gov/pccompound/?term="+t.molTitle;else{let n=t.inputid.split("_");1===n.length?(s+=t.inputid,e&&i.htmlCls.clickMenuCls.setLogCmd("link to "+t.inputid+": "+s,!1)):2===n.length&&(i.cfg.afid?s+=n[0]+" "+n[1]:s+=n[0]+" OR "+n[1],e&&i.htmlCls.clickMenuCls.setLogCmd("link to structures "+n[0]+" and "+n[1]+": "+s,!1))}return s}setEntrezLinks(e){var t=this.icn3d,i=t.icn3dui;let s,n=Object.keys(t.structures);if(1===n.length){s="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0],i.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+": "+s,!1);let r=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(s,r)}else if(2===n.length){s="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0]+" OR "+n[1],i.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+" OR "+n[1]+": "+s,!1);let r=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(s,r)}}}class mp{constructor(e){this.icn3d=e}async shareLink(e,t){let i=this.icn3d,s=i.icn3dui,n=this.shareLinkUrl(),r=n.length>4e3||0!==n.indexOf("http"),a=Object.keys(i.structures).join("_");if(a==i.defaultPdbId&&(i.filename?a=i.filename:i.inputid&&(a=i.inputid)),e){if(t||i.bInputfile||r)return void i.saveFileCls.saveFile(a+"_icn3d_loadable.png","png")}else{if(i.bInputfile&&!i.bInputUrlfile)return void alert("Share Link does NOT work when the data are from custom files. Please save 'iCn3D PNG Image' in the File menu and open it in iCn3D.");if(r)return void alert("The url is more than 4000 characters and may not work. Please save 'iCn3D PNG Image' or 'State File' and open them in iCn3D.");s.htmlCls.clickMenuCls.setLogCmd("share link: "+n,!1)}let o="Problem in getting shortened URL";if(!s.cfg.notebook){let t=await this.getShareLinkPrms(n,e);if(void 0!==t.shortLink&&(o=t.shortLink,e)){let e=o.split("/"),t=e[e.length-1];i.saveFileCls.saveFile(a+"-"+t+".png","png");let s='<div style="float:left; border: solid 1px #0000ff; padding: 5px; margin: 10px; text-align:center;">';s+='<a href="https://www.ncbi.nlm.nih.gov/Structure/icn3d/share2.html?'+t+'" target="_blank">',s+='<img style="height:300px" src ="'+a+"-"+t+'.png"><br>\n',s+="\x3c!--Start of your comments==================--\x3e\n";let n=i.yournote?": "+i.yournote.replace(/\n/g,"<br>").replace(/; /g,", "):"";s+="PDB "+a.toUpperCase()+n+"\n",s+="\x3c!--End of your comments====================--\x3e\n",s+="</a>",s+="</div>\n\n",i.saveFileCls.saveFile(a+"-"+t+".html","html",s)}e&&void 0===t.shortLink&&i.saveFileCls.saveFile(a+"_icn3d_loadable.png","png"),o="https://www.ncbi.nlm.nih.gov/Structure/icn3d/share2.html?"+o,$("#"+i.pre+"short_url").val(o),$("#"+i.pre+"short_url_title").val(o+"&t="+i.yournote)}let l=this.shareLinkUrl(void 0,!0),d="view = icn3dpy.view(q='"+(s.cfg.url?"url="+s.cfg.url:s.cfg.idname+"="+s.cfg.idvalue)+"',command='"+l+"')\nview";(s.cfg.url||s.cfg.idname)&&$("#"+i.pre+"jn_commands").val(d),$("#"+i.pre+"ori_url").val(n),e||s.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL or Jupyter Notebook Commands")}getShareLinkPrms(e,t){let i=this.icn3d,s=i.icn3dui,n="https://icn3d.link/?longurl="+encodeURIComponent(e);return new Promise((function(r,a){$.ajax({url:n,dataType:"json",cache:!0,success:function(e){r(e)},error:function(n,r,a){let o="Problem in getting shortened URL";$("#"+i.pre+"ori_url").val(e),$("#"+i.pre+"short_url").val(o),$("#"+i.pre+"short_url_title").val(o+"&t="+i.yournote),t||s.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL")}})}))}shareLinkUrl(e,t,i){let s=this.icn3d,n=s.icn3dui,r=n.htmlCls.baseUrl+"icn3d/full_"+n.REVISION+".html?",a="";if(n.cfg.bSidebyside&&(r=n.htmlCls.baseUrl+"icn3d/full2.html?"),s.bInputUrlfile){r=window.location.href.split("?")[0]+"?"+s.inputurl+"&"}let o,l={};for(let e in s.cfg){let t=s.cfg[e];"inpara"!==e&&"command"!==e&&"usepdbnum"!==e&&"date"!==e&&"v"!==e&&void 0!==t&&("width"===e&&"100%"===t||"height"===e&&"100%"===t||"resize"===e&&!0===t||"showlogo"===e&&!0===t||"showmenu"===e&&!0===t||"showtitle"===e&&!0===t||"showcommand"===e&&!0===t||"mobilemenu"===e&&!1===t||"showanno"===e&&!1===t||"showseq"===e&&!1===t||"showalignseq"===e&&!1===t||"show2d"===e&&!1===t||"showsets"===e&&!1===t||"rotate"===e&&"right"===t||"command"!==e&&("options"===e?Object.keys(t).length>0&&(l[e]=JSON.stringify(t)):!0===t?l[e]=1:!1===t?l[e]=0:""!==t&&(l[e]=t)))}s.bAfMem?l.afmem="on":(n.cfg.afid||1==Object.keys(s.structures).length&&Object.keys(s.structures)[0].length>5)&&(l.afmem="off");let d=-1;void 0!==n.cfg.inpara&&(d=n.cfg.inpara.indexOf("&command=")),o=-1!==d?n.cfg.inpara.substr(0,d):n.cfg.inpara;let c=!1;if(!s.bInputUrlfile){let e=o&&o.substr(1)?o.substr(1).split("&"):[];for(let t=0,i=e.length;t<i;++t){let i=e[t].split("=");2==i.length&&(l[i[0]]=i[1])}n.cfg.idname&&!l[n.cfg.idname]&&(r+=n.cfg.idname+"="+n.cfg.idvalue+"&");for(let e in l)"v"!==e&&("date"===e&&(c=!0),r+=e+"="+l[e]+"&")}let h,p=n.utilsCls.getDateDigitStr();c||(r+="date="+p+"&"),r+="v="+n.REVISION+"&",r+="command=",h=t&&void 0!==o?1:0,(e||s.bInputUrlfile)&&(h=0);let u={};u.factor=s._zoomFactor,u.mouseChange=s.mouseChange,u.quaternion=s.quaternion;let m="",f="",g="toggle highlight",b=0;if(s.commands.length>h){f=s.commands[h].split("|||")[0].split("&command=")[0].trim(),-1!==f.indexOf(g)&&++b}let C,v=h+1,_="";for(let e=s.commands.length;v<e;++v){let e=s.commands[v].split("|||")[0].split("&command=")[0].trim();0==f.indexOf("select sets")&&0===e.indexOf("select sets")&&-1===f.indexOf(" name ")||-1!==f.indexOf("pickatom")&&-1!==e.indexOf("pickatom")||"show selection"==f&&-1!=s.commands.slice(v).toString().indexOf("show selection")||f==e||(-1!==f.indexOf(g)?++b:_+=v===h+1?f:_?"; "+f:f),-1==f.indexOf("load ")&&(m+=f+"\n"),f=e}return f&&(_&&(_+="; "),b>0&&b%2==0&&f!==g&&(_+=g+"; "),_+=f+"|||"+s.transformCls.getTransformationStr(u),m+=f+"|||"+s.transformCls.getTransformationStr(u)+"\n"),r+=_,a=_,m=m.replace(/!/g,Object.keys(s.structures)[0]+"_"),(s.bEsmfold||s.bInputfile&&!s.bInputUrlfile||s.bInputUrlfile&&s.bAppend||r.length>4e3)&&(r=m),void 0!==s.structures&&1==Object.keys(s.structures).length&&void 0!==s.inputid&&(C=Object.keys(s.structures)[0],r=r.replace(new RegExp(C+"_","g"),"!"),a=a.replace(new RegExp(C+"_","g"),"!")),void 0!==n.cfg.blast_rep_id&&(r=r.replace(new RegExp("blast_rep_id=!","g"),"blast_rep_id="+C+"_")),i?m:t?a:r}getPngText(){let e=this.icn3d;e.icn3dui;let t="";t+="\nStart of type file======\n",t+="pdb\n",t+="End of type file======\n",t+="Start of data file======\n",t+=e.saveFileCls.getAtomPDB(e.atoms),t+="End of data file======\n";return t+="Start of state file======\n",t+=this.shareLinkUrl(!0,void 0,!0)+"\n",t+="End of state file======\n",t=t.replace(/!/g,Object.keys(e.structures)[0]+"_"),t}}class fp{constructor(e){this.icn3d=e}setThichknessFor3Dprint(){let e=this.icn3d,t=e.icn3dui;e.lineRadius=1,e.coilWidth=1.2,e.cylinderRadius=.8,e.crosslinkRadius=.8,e.traceRadius=1,e.dotSphereScale=.6,e.sphereRadius=1.5,e.ribbonthickness=1,e.helixSheetWidth=2,e.nucleicAcidWidth=1.4,t.htmlCls.setHtmlCls.setCookieForThickness()}prepareFor3Dprint(){let e=this.icn3d,t=e.icn3dui;if(e.bShowHighlight=!1,e.hlObjectsCls.removeHlObjects(),e.bDashedLines=!1,e.bSetThickness||void 0!==t.cfg.cid||this.setThichknessFor3Dprint(),void 0!==e.lines.hbond)for(let t=0,i=e.lines.hbond.length;t<i;++t){e.lines.hbond[t].dashed=!1,e.bDashedLines=!0}if(void 0!==e.lines.distance)for(let t=0,i=e.lines.distance.length;t<i;++t){e.lines.distance[t].dashed=!1,e.bDashedLines=!0}e.drawCls.draw(),e.bShowHighlight=!0}resetAfter3Dprint(){let e=this.icn3d,t=e.icn3dui;if(void 0!==e.lines.hbond)for(let t=0,i=e.lines.hbond.length;t<i;++t){e.lines.hbond[t].dashed=!0}if(void 0!==e.lines.distance)for(let t=0,i=e.lines.distance.length;t<i;++t){e.lines.distance[t].dashed=!0}e.lineRadius=.1,e.coilWidth=.3,e.cylinderRadius=.4,e.crosslinkRadius=.4,e.traceRadius=.4,e.dotSphereScale=.3,e.sphereRadius=1.5,e.cylinderHelixRadius=1.6,e.ribbonthickness=.2,e.helixSheetWidth=1.3,e.nucleicAcidWidth=.8,t.htmlCls.setHtmlCls.setCookieForThickness()}removeOneStabilizer(e){let t,i=this.icn3d;i.icn3dui;for(let s=0,n=i.pairArray.length;s<n;s+=2){let n=this.getResidueRepAtom(i.pairArray[s]),r=this.getResidueRepAtom(i.pairArray[s+1]);if(null!=e)for(let i=0,a=e.length;i<a;i+=2){let a=this.getResidueRepAtom(e[i]),o=this.getResidueRepAtom(e[i+1]);if(n.serial==a.serial&&r.serial==o.serial||n.serial==o.serial&&r.serial==a.serial){t=s;break}}if(void 0!==t)break}void 0!==t&&i.pairArray.splice(t,2)}outputSelection(){let e=this.icn3d,t=e.icn3dui,i={};for(let t in e.hAtoms){i[e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi]=1}let s=Object.keys(i).sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let i=e.lastIndexOf("_"),s=t.lastIndexOf("_");if(e.substr(0,i)<t.substr(0,i))return-1;if(e.substr(0,i)>t.substr(0,i))return 1;if(e.substr(0,i)==t.substr(0,i)){if(parseInt(e.substr(i+1))<parseInt(t.substr(s+1)))return-1;if(parseInt(e.substr(i+1))>parseInt(t.substr(s+1)))return 1;if(parseInt(e.substr(i+1))==parseInt(t.substr(s+1)))return 0}}})),n="<table><tr><th>Structure</th><th>Chain</th><th>Residue Number</th></tr>";for(let e=0,t=s.length;e<t;++e){let t=s[e].indexOf("_"),i=s[e].lastIndexOf("_");n+="<tr><td>"+s[e].substr(0,t)+"</td><td>"+s[e].substr(t+1,i-t-1)+"</td><td>"+s[e].substr(i+1)+"</td></tr>"}let r=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(r+"_residues.txt","html",n)}addStabilizer(){let e=this.icn3d,t=e.icn3dui,i=3.5;if(Object.keys(e.dAtoms).length>0){let s,n={},r=12.25,a=3.2*3.2;for(let t in e.dAtoms){let i=e.atoms[t];!e.nucleotides.hasOwnProperty(i.serial)||"N1"!==i.name&&"N2"!==i.name&&"N3"!==i.name&&"N4"!==i.name&&"N6"!==i.name&&"O2"!==i.name&&"O6"!==i.name||(s=i.structure+"_"+i.chain+"_"+i.resi+"_"+i.name,n[s]=i)}let o=Object.keys(n),l=o.length;void 0===e.pairArray&&(e.pairArray=[]);for(let t=0;t<l;++t)for(let s=t+1;s<l;++s){let l=o[t],d=o[s],c=Math.abs(n[l].coord.x-n[d].coord.x);if(c>i)continue;let h=Math.abs(n[l].coord.y-n[d].coord.y);if(h>i)continue;let p=Math.abs(n[l].coord.z-n[d].coord.z);if(p>i)continue;let u=c*c+h*h+p*p;u>r||u<a||(e.pairArray.push(n[l].serial),e.pairArray.push(n[d].serial))}let d=6,c={};for(let t in e.dAtoms){let i=e.atoms[t];c[i.structure+"_"+i.chain+"_"+i.resi]=1}let h={};for(let t in e.chemicals){let i=e.atoms[t],s=i.structure+"_"+i.chain+"_"+i.resi;c.hasOwnProperty(s)&&(h[s]=1)}for(let t in e.ions){let i=e.atoms[t],s=i.structure+"_"+i.chain+"_"+i.resi;c.hasOwnProperty(s)&&(h[s]=1)}let p=Object.keys(e.chains);for(let t=0,i=p.length;t<i;++t){let i,s=p[t],n=0,r=0;for(let t=0,a=e.chainsSeq[s].length;t<a;++t)i=s+"_"+e.chainsSeq[s][t].resi,"c"!=e.secondaries[i]&&"E"!=e.secondaries[i]&&"H"!=e.secondaries[i]||(n%3!=0&&e.resid2ncbi[e.chainsSeq[s][t].resi]==e.resid2ncbi[r]+1||c.hasOwnProperty(i)&&(h[i]=1),++n,r=e.chainsSeq[s][t].resi);"c"!=e.secondaries[i]&&"E"!=e.secondaries[i]&&"H"!=e.secondaries[i]||c.hasOwnProperty(i)&&(h[i]=1)}let u=Object.keys(h);void 0===e.pairArray&&(e.pairArray=[]);let m=t.hashUtilsCls.exclHash(e.dAtoms,e.water);for(let i=0,s=u.length;i<s;++i){let s=u[i],n=e.secondaries[s],r=e.contactCls.getNeighboringAtoms(m,t.hashUtilsCls.hash2Atoms(e.residues[s],e.atoms),d),a=Object.keys(r).sort(),o=Object.keys(e.residues[s]).sort(),l=!1;if(e.proteins.hasOwnProperty(o[0])){o=[o[0]],l=!0;let t=s.substr(0,s.lastIndexOf("_")),i=e.ParserUtilsCls.getResiNCBI(t,s.substr(s.lastIndexOf("_")+1)),d={};for(let s in r){if(e.chemicals.hasOwnProperty(s)||e.ions.hasOwnProperty(s))continue;let r=e.atoms[s];if(isNaN(r.resi))continue;let a=e.ParserUtilsCls.getResiNCBI(t,r.resi);("c"==n&&(a>i+1||a<i-1)||"E"==n&&(a>i+2||a<i-2)||"H"==n&&(a>i+4||a<i-4))&&(d[s]=1)}a=Object.keys(d).sort()}if(a.length>0&&o.length>0)if(l){let t=parseInt((a.length+.5)/2);e.pairArray.push(o[0]),e.pairArray.push(a[t])}else{let t=10,i=parseInt(a.length/(t+1));for(let s=0,n=o.length;s<n;++s)if(s%t==0){let n=parseInt(s/t)*i,r=n<a.length?n:a.length-1;e.pairArray.push(o[s]),e.pairArray.push(a[r]),o.length<t+1&&(e.pairArray.push(o[s]),e.pairArray.push(a[a.length-1]))}}}}}hideStabilizer(){let e=this.icn3d;e.icn3dui,e.pairArray=[],e.lines.stabilizer=[],e.stabilizerpnts=[];for(let t in e.water)e.atoms[t].style=e.opts.water}getResidueRepAtom(e){let t=this.icn3d;t.icn3dui;let i,s=t.atoms[e],n=s.structure+"_"+s.chain+"_"+s.resi;if(t.proteins.hasOwnProperty(e)||t.nucleotides.hasOwnProperty(e))for(let e in t.residues[n]){let s=t.atoms[e];if("CA"===s.name||"N3"===s.name){i=t.atoms[e];break}}else i=s;return void 0===i&&(i=s),i}}class gp{constructor(e){this.icn3d=e}exportStlFile(e){let t=this.icn3d,i=t.icn3dui;void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&(t.threshbox=180/Math.pow(t.biomtMatrices.length,.33),t.applyMapCls.removeSurfaces(),t.applyMapCls.applySurfaceOptions(),t.applyMapCls.removeMaps(),t.applyMapCls.applyMapOptions(),t.applyMapCls.removeEmmaps(),t.applyMapCls.applyEmmapOptions());let s=this.saveStlFile(),n=Object.keys(i.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".stl","binary",s),void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length>t.maxAtoms3DMultiFile){alert(t.biomtMatrices.length+" files will be generated for this assembly. Please merge these files using some software and 3D print the merged file.");let i=new gi;i.identity();let r=1;for(let a=0;a<t.biomtMatrices.length;a++){let o=t.biomtMatrices[a];if(void 0===o)continue;if(o.equals(i))continue;let l=100*(a+1);setTimeout(function(i,r){s=this.saveStlFile(i),t.saveFileCls.saveFile(n+e+r+".stl","binary",s),s=""}.bind(this,o,r),l),++r}t.threshbox=180}}exportVrmlFile(e){let t=this.icn3d,i=t.icn3dui;void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&(t.threshbox=180/Math.pow(t.biomtMatrices.length,.33),t.applyMapCls.removeSurfaces(),t.applyMapCls.applySurfaceOptions(),t.applyMapCls.removeMaps(),t.applyMapCls.applyMapOptions(),t.applyMapCls.removeEmmaps(),t.applyMapCls.applyEmmapOptions());let s=this.saveVrmlFile(),n=Object.keys(i.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".wrl","text",s),void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length>t.maxAtoms3DMultiFile){alert(t.biomtMatrices.length+" files will be generated for this assembly. Please merge these files using some software and 3D print the merged file.");let i=new gi;i.identity();let n=1;for(let r=0;r<t.biomtMatrices.length;r++){let a=t.biomtMatrices[r];if(void 0===a)continue;if(a.equals(i))continue;let o=100*(r+1);setTimeout(function(i,n){s=this.saveVrmlFile(i),t.saveFileCls.saveFile(t.inputid+e+n+".wrl","text",s),s=""}.bind(this,a,n),o),++n}t.threshbox=180}}getFaceCnt(e){this.icn3d.icn3dui;let t=0;for(let i=0,s=e.children.length;i<s;++i){let s=e.children[i];"Sprite"!==s.type&&(t+=s.geometry.getIndex().array.length/3)}return t}saveStlFile(e){let t=this.icn3d,i=t.icn3dui;if(Object.keys(t.dAtoms).length>7e4)return alert("Please display a subset of the structure to export 3D files. Then merge the files for 3D printing..."),[""];t.threeDPrintCls.prepareFor3Dprint();let s=0;s+=this.getFaceCnt(t.mdl),s+=this.getFaceCnt(t.mdl_ghost);let n=[],r=new Uint8Array(84),a="STL file for the structure(s) ",o=Object.keys(t.structures);for(let e=0,t=o.length;e<t;++e)a+=o[e],e<t-1&&(a+=", ");a.length>80&&(a=a.substr(0,80));for(let e=0;e<80;++e)e<a.length?r[e]=i.convertTypeCls.passInt8([a.charCodeAt(e)])[0]:r[e]=i.convertTypeCls.passInt8([" ".charCodeAt(0)])[0];if(r=void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile?this.updateArray(r,i.convertTypeCls.passInt32([s*t.biomtMatrices.length]),80):this.updateArray(r,i.convertTypeCls.passInt32([s]),80),n.push(new Blob([r],{type:"application/octet-stream"})),n=this.processStlMeshGroup(t.mdl,n,e),n=this.processStlMeshGroup(t.mdl_ghost,n,e),void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile){let e=new gi;e.identity();for(let i=0;i<t.biomtMatrices.length;i++){let s=t.biomtMatrices[i];void 0!==s&&(s.equals(e)||(n=this.processStlMeshGroup(t.mdl,n,s),n=this.processStlMeshGroup(t.mdl_ghost,n,s)))}}return t.threeDPrintCls.resetAfter3Dprint(),n}updateArray(e,t,i){this.icn3d.icn3dui;for(let s=0,n=t.length;s<n;++s)e[i+s]=t[s];return e}processStlMeshGroup(e,t,i){let s=this.icn3d.icn3dui;for(let n=0,r=e.children.length;n<r;++n){let r=e.children[n];if("Sprite"===r.type)continue;let a=r.geometry,o=a.getAttribute("position").array,l=a.getIndex().array,d=r.position,c=r.scale,h=r.matrix,p=new Uint8Array(l.length/3*50),u=0;for(let e=0,t=l.length;e<t;e+=3){let t,n,r,m=l[e],f=l[e+1],g=l[e+2],b=new mt(o[3*m],o[3*m+1],o[3*m+2]),C=new mt(o[3*f],o[3*f+1],o[3*f+2]),v=new mt(o[3*g],o[3*g+1],o[3*g+2]);"SphereGeometry"==a.type||"BoxGeometry"==a.type?(t=b.clone().multiply(c).add(d),n=C.clone().multiply(c).add(d),r=v.clone().multiply(c).add(d)):"CylinderGeometry"==a.type?(t=b.clone().applyMatrix4(h),n=C.clone().applyMatrix4(h),r=v.clone().applyMatrix4(h)):(t=b.clone(),n=C.clone(),r=v.clone()),p=this.updateArray(p,s.convertTypeCls.passFloat32([0,0,0]),u),u+=12,void 0!==i&&(t.applyMatrix4(i),n.applyMatrix4(i),r.applyMatrix4(i)),p=this.updateArray(p,s.convertTypeCls.passFloat32([t.x,t.y,t.z]),u),u+=12,p=this.updateArray(p,s.convertTypeCls.passFloat32([n.x,n.y,n.z]),u),u+=12,p=this.updateArray(p,s.convertTypeCls.passFloat32([r.x,r.y,r.z]),u),u+=12,t=n=r=void 0,p=this.updateArray(p,s.convertTypeCls.passInt16([0]),u),u+=2}t.push(new Blob([p],{type:"application/octet-stream"})),p=null}return t}saveVrmlFile(e){let t=this.icn3d;if(t.icn3dui,Object.keys(t.dAtoms).length>5e4)return alert("Please display a subset of the structure to export 3D files. Then merge the files for 3D printing..."),[""];t.threeDPrintCls.prepareFor3Dprint();let i=[];i.push("#VRML V2.0 utf8\n");let s=0,n=this.processVrmlMeshGroup(t.mdl,i,s,e);if(i=n.vrmlStrArray,s=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,i,s,e),i=n.vrmlStrArray,s=n.vertexCnt,void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile){let e=new gi;e.identity();for(let r=0;r<t.biomtMatrices.length;r++){let a=t.biomtMatrices[r];void 0!==a&&(a.equals(e)||(n=this.processVrmlMeshGroup(t.mdl,i,s,a),i=n.vrmlStrArray,s=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,i,s,a),i=n.vrmlStrArray,s=n.vertexCnt))}}return i}processVrmlMeshGroup(e,t,i,s){let n=this.icn3d.icn3dui;for(let i=0,r=e.children.length;i<r;++i){let r=e.children[i];if("Sprite"===r.type)continue;let a=r.geometry;r.material.type,a.type;let o=a.getAttribute("position").array,l=a.getAttribute("color")?a.getAttribute("color").array:[],d=a.getIndex().array,c=r.position,h=r.scale,p=r.matrix,u=n.parasCls.thr(1,1,1);"SphereGeometry"!=a.type&&"BoxGeometry"!=a.type&&"CylinderGeometry"!=a.type||void 0!==r.material&&(u=r.material.color),t.push("Shape {\n"),t.push("geometry IndexedFaceSet {\n"),t.push("coord Coordinate { point [ ");let m=[];for(let e=0,i=o.length;e<i;e+=3){let r,l=new mt(o[e],o[e+1],o[e+2]);r="SphereGeometry"==a.type||"BoxGeometry"==a.type?l.clone().multiply(h).add(c):"CylinderGeometry"==a.type?l.clone().applyMatrix4(p):l.clone(),void 0!==s&&r.applyMatrix4(s),t.push(r.x.toPrecision(5)+" "+r.y.toPrecision(5)+" "+r.z.toPrecision(5)),r=void 0,e<i-3&&t.push(", "),m.push(n.parasCls.thr(1,1,1))}t.push(" ] }\n");let f="",g="";for(let e=0,t=d.length;e<t;e+=3){let i,s=d[e],n=d[e+1],r=d[e+2];i="SphereGeometry"==a.type||"BoxGeometry"==a.type||"CylinderGeometry"==a.type?u:new ls(l[3*s],l[3*s+1],l[3*s+2]),f+=s+" "+n+" "+r,e<t-3&&(f+=", -1, "),m[s]=i,m[n]=i,m[r]=i}for(let e=0,t=m.length;e<t;++e){let i=m[e];g+=i.r.toPrecision(3)+" "+i.g.toPrecision(3)+" "+i.b.toPrecision(3),e<t-1&&(g+=", ")}t.push("coordIndex [ "+f+" ]\n"),t.push("color Color { color [ "+g+" ] } colorPerVertex TRUE\n"),t.push(" }\n"),t.push("}\n")}return{vrmlStrArray:t,vertexCnt:i}}}class bp{constructor(e){this.icn3d=e}rayCaster(e,t){let i=this.icn3d;i.icn3dui,i.opts&&"none"!=i.opts.effect||this.rayCasterBase(e,t)}rayCasterBase(e,t){let i=this.icn3d;i.icn3dui;let s=e.pageX,n=e.pageY;e.originalEvent.targetTouches&&e.originalEvent.targetTouches[0]&&(s=e.originalEvent.targetTouches[0].pageX,n=e.originalEvent.targetTouches[0].pageY);let r=i.oriContainer.offset().left,a=i.oriContainer.offset().top,o=i.oriContainer.width(),l=i.oriContainer.height(),d=s-r,c=n-a;i.mouse.x=d/o*2-1,i.mouse.y=-c/l*2+1;let h=new mt;h.x=i.mouse.x,h.y=i.mouse.y,i.cam_z>0?h.z=-1:h.z=1,i.cam===i.perspectiveCamera?(i.cam_z>0?h.z=-1:h.z=1,h.unproject(i.cam),i.raycaster.set(i.cam.position,h.sub(i.cam.position).normalize())):i.cam===i.orthographicCamera&&(i.cam_z>0?h.z=1:h.z=-1,h.unproject(i.cam),i.raycaster.set(h,new mt(0,0,-1).transformDirection(i.cam.matrixWorld)));let p=this.isIntersect(i.objects,i.mdl,t,d,c);p||(p=this.isIntersect(i.objects_ghost,i.mdl_ghost,t,d,c))}isIntersect(e,t,i,s,n){let r=this.icn3d;r.icn3dui;let a=r.raycaster.intersectObjects(e),o=!1,l=t.position;if(a.length>0){a[0].point.sub(l);let e=r.rayThreshold,t=this.getAtomsFromPosition(a[0].point,e);for(;!t&&e<10;)e+=.5,t=this.getAtomsFromPosition(a[0].point,e);t?(o=!0,r.pickpair?i&&(r.pAtomNum%2==0?r.pAtom=t:r.pAtom2=t,++r.pAtomNum):r.pAtom=t,i?r.pickingCls.showPicking(t):r.pickingCls.showPicking(t,s,n)):console.log("No atoms were found in 10 andstrom range")}return o}getAtomsFromPosition(e,t,i){let s,n=this.icn3d,r=n.icn3dui;null==t&&(t=1);let a=i||n.dAtoms;for(s in a){let i=n.atoms[s];if(n.ions.hasOwnProperty(s)&&"sphere"===n.opts.ions){let s=r.parasCls.vdwRadii[i.elem.toUpperCase()];if(Math.abs(i.coord.x-e.x)-s>t)continue;if(Math.abs(i.coord.y-e.y)-s>t)continue;if(Math.abs(i.coord.z-e.z)-s>t)continue}else{if(i.coord.x<e.x-t||i.coord.x>e.x+t)continue;if(i.coord.y<e.y-t||i.coord.y>e.y+t)continue;if(i.coord.z<e.z-t||i.coord.z>e.z+t)continue}return i}return null}}class Cp{constructor(e){this.icn3d=e}setControl(){let e=this.icn3d,t=e.icn3dui;if(t.bNode)return;let i=this;e.WIDTH=e.container.width(),e.HEIGHT=e.container.height(),e.applyCenterCls.setWidthHeight(e.WIDTH,e.HEIGHT),e._zoomFactor=1,e.mouseChange=new pt(0,0),e.quaternion=new ut(0,0,0,1),e.container.bind("contextmenu",(function(e){e.preventDefault()})),e.typetext=!1,$(document).bind("keyup",(function(t){16===t.keyCode&&(e.bShift=!1),17!==t.keyCode&&224!==t.keyCode&&91!==t.keyCode||(e.bCtrl=!1)})),$("input[type=text], textarea").focus((function(){e.typetext=!0})),$("input[type=text], textarea").blur((function(){e.typetext=!1})),$(document).bind("keydown",(async function(i){if((i.shiftKey||16===i.keyCode)&&(e.bShift=!0),(i.ctrlKey||17===i.keyCode||224===i.keyCode||91===i.keyCode)&&(e.bCtrl=!0),!e.bControlGl&&!e.controls||e.bControlGl&&!window.controls)return;e.bStopRotate=!0;let s=e.bShift?90:5;if(!e.typetext)if(90===i.keyCode){let i={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?i._zoomFactor=.9:window.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),i._zoomFactor=.8*e._zoomFactor,i._zoomFactor<.1&&(i._zoomFactor=.1)):e.cam===e.perspectiveCamera?i._zoomFactor=.9:e.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),i._zoomFactor=.8*e._zoomFactor,i._zoomFactor<.1&&(i._zoomFactor=.1)),i.update=!0,e.bControlGl&&!t.bNode?window.controls.update(i):e.controls.update(i),e.bRender&&e.drawCls.render()}else if(88===i.keyCode){let i={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?i._zoomFactor=1.03:window.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),i._zoomFactor=1.01*e._zoomFactor,i._zoomFactor>10&&(i._zoomFactor=10)):e.cam===e.perspectiveCamera?i._zoomFactor=1.03:e.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),i._zoomFactor=1.01*e._zoomFactor,i._zoomFactor>10&&(i._zoomFactor=10)),i.update=!0,e.bControlGl&&!t.bNode?window.controls.update(i):e.controls.update(i),e.bRender&&e.drawCls.render()}else if(76===i.keyCode){let t=new mt(0,1,0),i=-s/180*Math.PI;e.transformCls.setRotation(t,i)}else if(74===i.keyCode){let t=new mt(0,1,0),i=s/180*Math.PI;e.transformCls.setRotation(t,i)}else if(73===i.keyCode){let t=new mt(1,0,0),i=-s/180*Math.PI;e.transformCls.setRotation(t,i)}else if(77===i.keyCode){let t=new mt(1,0,0),i=s/180*Math.PI;e.transformCls.setRotation(t,i)}else 65===i.keyCode&&Object.keys(e.structures).length>1&&await e.alternateCls.alternateWrapper()})),e.container.bind("mouseup",(function(t){e.isDragging=!1})),e.container.bind("touchend",(function(t){e.isDragging=!1})),e.container.bind("mousedown",(function(i){if(e.isDragging=!0,e.scene){if(e.bStopRotate=!0,e.pk&&(i.altKey||i.ctrlKey||i.shiftKey||18===i.keyCode||16===i.keyCode||17===i.keyCode||224===i.keyCode||91===i.keyCode)){e.highlightlevel=e.pk;let t=!0;e.rayCls.rayCaster(i,t)}e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render()}})),e.container.bind("touchstart",(function(i){if(i.preventDefault(),e.isDragging=!0,!e.scene)return;e.bStopRotate=!0,$("#"+e.pre+"popup").hide();e.rayCls.rayCaster(i,!0),e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render()})),e.container.bind("mousemove touchmove",(function(e){i.mouseMove(e)})),e.container.bind("mousewheel",(function(i){i.preventDefault(),e.scene&&(e.bStopRotate=!0,e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render())})),e.container.bind("DOMMouseScroll",(function(i){i.preventDefault(),e.scene&&(e.bStopRotate=!0,e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render())}))}mouseMove(e){let t=this.icn3d,i=t.icn3dui;if(i.bNode)return;if(e.preventDefault(),!t.scene)return;$("#"+t.pre+"popup").hide();if(t.rayCls.rayCaster(e,!1),t.bControlGl&&!i.bNode){window.controls.handleResize(),window.controls.update();for(let e in window.icn3duiHash){let t=window.icn3duiHash[e].icn3d;t.bRender&&t.drawCls.render()}}else t.controls.handleResize(),t.controls.update(),t.bRender&&t.drawCls.render()}}class vp{constructor(e){this.icn3d=e}showPicking(e,t,i){let s=this.icn3d,n=s.icn3dui;if(void 0!==n.cfg.cid&&0!=s.pk&&(s.pk=1),s.highlightlevel=s.pk,this.showPickingBase(e,t,i),0!=s.pk)if(void 0!==t&&void 0!==i){null!=n.cfg.showmenu&&1==n.cfg.showmenu&&(i+=n.htmlCls.MENU_HEIGHT);let r,a=1==s.pk?e.resn+e.resi+"@"+e.name:e.resn+e.resi,o=e.structure+"_"+e.chain;if(void 0!==s.structures&&Object.keys(s.structures).length>1?(a=o+" "+a,r=s.chainid2refpdbname&&s.chainid2refpdbname[o]?240:160,$("#"+s.pre+"popup").css("width",r+"px")):(r=s.chainid2refpdbname&&s.chainid2refpdbname[o]?160:80,$("#"+s.pre+"popup").css("width",r+"px")),s.chainid2refpdbname&&s.chainid2refpdbname[o]){let t=s.resid2refnum[o+"_"+e.resi];t&&(a+=", Ig: "+t)}$("#"+s.pre+"popup").html(a),$("#"+s.pre+"popup").css("top",i).css("left",t+20).show()}else s.hlUpdateCls.updateHlAll(),n.htmlCls.clickMenuCls.setLogCmd("pickatom "+e.serial,!0),s.selectionCls.saveSelInCommand(),s.bSphereCalc=!1,s.bHbondCalc=!1}showPickingBase(e,t,i){this.icn3d.icn3dui,void 0===t&&void 0===i&&this.showPickingHilight(e)}getPickedAtomList(e,t){let i=this.icn3d;i.icn3dui;let s={};if(1===e)s[t.serial]=1;else if(2===e){let e=t.structure+"_"+t.chain+"_"+t.resi;s=i.residues[e]}else if(3===e)s=this.selectStrandHelixFromAtom(t);else if(4===e)s=this.select3ddomainFromAtom(t);else if(5===e){let e=t.structure+"_"+t.chain;s=i.chains[e]}return s}showPickingHilight(e){let t=this.icn3d,i=t.icn3dui;t.bShift||t.bCtrl||t.hlObjectsCls.removeHlObjects(),t.pickedAtomList=this.getPickedAtomList(t.pk,e),0===t.pk?t.bShowHighlight=!1:t.bShowHighlight=!0;let s=Object.keys(t.hAtoms).length==Object.keys(t.atoms).length?{}:i.hashUtilsCls.intHash(t.hAtoms,t.pickedAtomList),n=Object.keys(s).length;if(t.bShift||t.bCtrl)if(t.bShift){if(void 0===t.prevPickedAtomList)t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e=t.firstAtomObjCls.getFirstAtomObj(t.prevPickedAtomList),s=t.firstAtomObjCls.getFirstAtomObj(t.pickedAtomList);if(e.structure+"_"+e.chain!=s.structure+"_"+s.chain)t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e;e=i.hashUtilsCls.unionHash(e,t.prevPickedAtomList),e=i.hashUtilsCls.unionHash(e,t.pickedAtomList);let s=t.firstAtomObjCls.getFirstAtomObj(e),n=t.firstAtomObjCls.getLastAtomObj(e);for(let e=s.serial;e<=n.serial;++e)t.hAtoms[e]=1}}t.prevPickedAtomList=i.hashUtilsCls.cloneHash(t.pickedAtomList)}else t.bCtrl&&(t.hAtoms=n>0?i.hashUtilsCls.exclHash(t.hAtoms,t.pickedAtomList):i.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList));else t.hAtoms=i.hashUtilsCls.cloneHash(t.pickedAtomList);t.hlObjectsCls.removeHlObjects(),t.hlObjectsCls.addHlObjects()}select3ddomainFromAtom(e){let t,i=this.icn3d,s=i.icn3dui,n=e.structure+"_"+e.chain,r=n+"_"+e.resi;for(let e in i.tddomains){let s=e.indexOf("_3d_domain");if(e.substr(0,s)==n&&-1!==Object.keys(i.tddomains[e]).indexOf(r)){t=e;break}}let a={};for(let e in i.tddomains[t])a=s.hashUtilsCls.unionHash(a,i.residues[e]);return a}selectStrandHelixFromAtom(e){let t=this.icn3d,i=t.icn3dui,s=e,n=e,r={},a=s.resi;if(!s.ssbegin&&!isNaN(s.resi)){for(let e=s.resi-1;e>0;--e){let i=s.structure+"_"+s.chain+"_"+e;if(!t.residues.hasOwnProperty(i))break;let n=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[i]);if(a=n.resi,"coil"!==s.ss&&n.ss===s.ss&&n.ssbegin||"coil"===s.ss&&n.ss!==s.ss){"coil"===s.ss&&n.ss!==s.ss&&(a=parseInt(n.resi)+1);break}}for(let e=a;e<=s.resi;++e){let n=s.structure+"_"+s.chain+"_"+e;r=i.hashUtilsCls.unionHash(r,i.hashUtilsCls.hash2Atoms(t.residues[n],t.atoms))}}let o=n.resi,l=t.firstAtomObjCls.getLastAtomObj(t.chains[n.structure+"_"+n.chain]).resi;for(let e=parseInt(n.resi)+1;e<=parseInt(l);++e){let i=n.structure+"_"+n.chain+"_"+e;if(!t.residues.hasOwnProperty(i))break;let s=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[i]);if(o=s.resi,"coil"!==n.ss&&s.ss===n.ss&&s.ssend||"coil"===n.ss&&s.ss!==n.ss){"coil"!==n.ss||s.ss===n.ss||isNaN(s.resi)||(o=s.resi-1);break}}for(let e=parseInt(n.resi)+1;e<=parseInt(o);++e){let s=n.structure+"_"+n.chain+"_"+e;r=i.hashUtilsCls.unionHash(r,i.hashUtilsCls.hash2Atoms(t.residues[s],t.atoms))}return r}}class _p{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t){let i=this.icn3d,s=i.icn3dui;t&&console.error('THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.');const n=document.createElement("button");function r(){n.style.display="",n.style.cursor="auto",n.style.left="calc(33% - 75px)",n.style.width="150px",n.onmouseenter=null,n.onmouseleave=null,n.onclick=null}let a=this;if("xr"in navigator)return n.id=s.pre+"VRButton",n.style.display="none",(o=n).style.position="absolute",o.style.bottom="20px",o.style.padding="12px 6px",o.style.border="1px solid #fff",o.style.borderRadius="4px",o.style.background="#000",o.style.color="#f8b84e",o.style.font="bold 13px sans-serif",o.style.textAlign="center",o.style.opacity="0.8",o.style.outline="none",o.style.zIndex="999",navigator.xr.isSessionSupported("immersive-vr").then((function(t){t?function(){let t=null;async function s(i){i.addEventListener("end",r),await e.xr.setSession(i),n.textContent="EXIT VR",t=i}function r(){i.transformCls.resetOrientation(),i.bVr=!1,i.drawCls.draw(),t.removeEventListener("end",r),n.textContent="ENTER VR",t=null}n.style.display="",n.style.cursor="pointer",n.style.left="calc(33% - 50px)",n.style.width="100px",n.textContent="ENTER VR",n.onmouseenter=function(){n.style.opacity="1.0"},n.onmouseleave=function(){n.style.opacity="0.8"},n.onclick=function(){if(i.bImpo=!1,i.bVr=!0,i.drawCls.draw(i.bVr),null===t){const e={optionalFeatures:["local-floor","bounded-floor","hand-tracking","layers"]};navigator.xr.requestSession("immersive-vr",e).then(s)}else t.end()}}():(r(),n.style.display="none"),t&&a.xrSessionIsGranted&&n.click()})).catch((function(e){r(),console.warn("Exception when trying to call xr.isSessionSupported",e),n.style.display="none"})),n;return document.createElement("span");var o}registerSessionGrantedListener(){"xr"in navigator&&navigator.xr.addEventListener("sessiongranted",(()=>{this.xrSessionIsGranted=!0}))}}class yp{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t={}){let i=this.icn3d,s=i.icn3dui;const n=document.createElement("button");function r(){n.style.display="",n.style.cursor="auto",n.style.left="calc(66% - 50px)",n.style.width="150px",n.onmouseenter=null,n.onmouseleave=null,n.onclick=null}function a(e){e.style.position="absolute",e.style.bottom="20px",e.style.padding="12px 6px",e.style.border="1px solid #fff",e.style.borderRadius="4px",e.style.background="#000",e.style.color="#f8b84e",e.style.font="bold 13px sans-serif",e.style.textAlign="center",e.style.opacity="0.8",e.style.outline="none",e.style.zIndex="999"}if(s.utilsCls.isAndroid()&&s.utilsCls.isChrome()){if("xr"in navigator)return n.id=s.pre+"ARButton",n.style.display="none",a(n),navigator.xr.isSessionSupported("immersive-ar").then((function(s){s?function(){if(void 0===t.domOverlay){const e=document.createElement("div");e.style.display="none",document.body.appendChild(e);const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width",38),i.setAttribute("height",38),i.style.position="absolute",i.style.right="20px",i.style.top="20px",i.addEventListener("click",(function(){s.end()})),e.appendChild(i);const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),n.setAttribute("stroke","#fff"),n.setAttribute("stroke-width",2),i.appendChild(n),void 0===t.optionalFeatures&&(t.optionalFeatures=[]),t.optionalFeatures.push("dom-overlay"),t.domOverlay={root:e}}let s=null;async function r(i){i.addEventListener("end",a),e.xr.setReferenceSpaceType("local"),await e.xr.setSession(i),n.textContent="STOP AR",t.domOverlay.root.style.display="",s=i}function a(){i.transformCls.resetOrientation(),i.bAr=!1,i.drawCls.draw(),s.removeEventListener("end",a),n.textContent="START AR",t.domOverlay.root.style.display="none",s=null}n.style.display="",n.style.cursor="pointer",n.style.left="calc(66% - 50px)",n.style.width="100px",n.textContent="START AR",n.onmouseenter=function(){n.style.opacity="1.0"},n.onmouseleave=function(){n.style.opacity="0.8"},n.onclick=function(){i.bImpo=!1,i.opts.background="transparent",i.bAr=!0,i.drawCls.draw(i.bAr),null===s?navigator.xr.requestSession("immersive-ar",t).then(r):s.end()}}():(r(),n.style.display="none")})).catch((function(e){r(),console.warn("Exception when trying to call xr.isSessionSupported",e),n.style.display="none"})),n;return document.createElement("span")}return n.id=s.pre+"ARButton",n.style.display="none",a(n),r(),n.style.display="none",n}}function Sp(e){var t=this;t.separation=3,t._position=new mt,t._quaternion=new ut,t._scale=new mt,t._cameraL=new Zs,t._cameraR=new Zs,e.autoClear=!1,t.setSize=function(i,s){t._width=i/2,t._height=s,e.setSize(i,s)},t.render=function(i,s){i.updateMatrixWorld(),void 0===s.parent&&s.updateMatrixWorld(),s.matrixWorld.decompose(t._position,t._quaternion,t._scale),t._cameraL.copy(s),t._cameraL.aspect=.5*s.aspect,t._cameraL.updateProjectionMatrix(),t._cameraL.translateX(-t.separation),t._cameraR.copy(s),t._cameraR.aspect=.5*s.aspect,t._cameraR.updateProjectionMatrix(),t._cameraR.translateX(t.separation),e.setViewport(0,0,2*t._width,t._height),e.clear(),e.setViewport(0,0,t._width,t._height),e.render(i,t._cameraL),e.setViewport(t._width,0,t._width,t._height),e.render(i,t._cameraR)}}class wp{constructor(e){let t,i,s,n=e;if(this.icn3dui=e,this.id=this.icn3dui.pre+"canvas",this.pre=this.icn3dui.pre,this.container=$("#"+this.id),this.oriContainer=$("#"+this.id),this.bControlGl=!1,this.maxatomcnt=1e5,this.overdraw=0,this.bDrawn=!1,this.bOpm=!1,this.crossstrucinter=0,this.bSecondaryStructure=!1,this.bHighlight=1,this.renderOrderPicking=-1,this.bInitial=!0,this.bDoublecolor=!1,this.originSize=1,this.ALTERNATE_STRUCTURE=-1,this.bUsePdbNum=!0,this.bSetCamera=!0,!this.icn3dui.bNode){let e=document.createElement("canvas");if(t=!(!window.WebGLRenderingContext||!e.getContext("webgl")&&!e.getContext("experimental-webgl")),e.remove(),e=document.createElement("canvas"),i=!(!window.WebGLRenderingContext||!e.getContext("webgl2")),e.remove(),s="xr"in navigator,t){if(!i)return void alert("Please use a modern browser that supports WebGL2...");this.renderer=new Pl({canvas:this.oriContainer.get(0),antialias:!0,preserveDrawingBuffer:!0,sortObjects:!1,alpha:!0}),s&&(this.renderer.xr.enabled=!0),this.effects={stereo:new Sp(this.renderer),none:this.renderer},this.overdraw=0}else alert("Currently your web browser has a problem on WebGL. If you are using Chrome, open a new tab for the same URL and WebGL may work again.")}this.frac=new ls(.1,.1,.1),this.shininess=40,this.emissive=3355443,this.light1=2,this.light2=1,this.light3=1,this.lineRadius=.1,this.coilWidth=.3,this.cylinderRadius=.4,this.crosslinkRadius=.4,this.traceRadius=.4,this.dotSphereScale=.3,this.sphereRadius=1.5,this.cylinderHelixRadius=1.6,this.ribbonthickness=.2,this.helixSheetWidth=1.3,this.nucleicAcidWidth=.8,this.scaleFactor=1,this.labelScale=1,this.resizeRatioX=1,this.resizeRatioY=1,this.bImpo=!0,this.bInstanced=!0,this.chainMissingResidueArray={},this._zoomFactor=1,this.transparentRenderOrder=!1,this.AFUniprotVersion="v4",this.defaultPdbId="stru",this.icn3dui.bNode||(i&&s?(this.bExtFragDepth=!0,this.bImpo=!0,this.bInstanced=!0):(this.bExtFragDepth=this.renderer.extensions.get("EXT_frag_depth"),this.bExtFragDepth?console.log("EXT_frag_depth is supported. All spheres and cylinders are drawn using shaders."):(this.bImpo=!1,console.log("EXT_frag_depth is NOT supported. All spheres and cylinders are drawn using geometry.")),this.bInstanced=this.renderer.extensions.get("ANGLE_instanced_arrays"),this.bInstanced?console.log("ANGLE_instanced_arrays is supported. Assembly is drawn with one copy of the asymmetric unit using hardware instancing."):console.log("ANGLE_instanced_arrays is NOT supported. Assembly is drawn by making copies of the asymmetric unit."))),this.posArray=new Array,this.colorArray=new Array,this.pos2Array=new Array,this.color2Array=new Array,this.radiusArray=new Array,this.posArraySphere=new Array,this.colorArraySphere=new Array,this.radiusArraySphere=new Array,this.axis=!1,this.pk=1,this.highlightlevel=1,this.pickpair=!1,this.pAtomNum=0,this.pAtom=void 0,this.pAtom2=void 0,this.bCtrl=!1,this.bShift=!1,this.bStopRotate=!1,this.bCalphaOnly=!1,this.bConsiderNeighbors=!1,this.bShowCrossResidueBond=!0,this.bExtrude=!0,this.maxD=500,this.oriMaxD=this.maxD,this.cam_z=2*this.maxD,this.commands=[],this.optsHistory=[],this.logs=[],this.bRender=!0,this.hColor=new ls(16777011),this.sphereGeometry=new ur(1,32,32),this.boxGeometry=new zs(1,1,1),this.cylinderGeometry=new Kn(1,1,1,32,1),this.cylinderGeometryOutline=new Kn(1,1,1,32,1,!0),this.axisDIV=15,this.strandDIV=6,this.tubeDIV=8,this.nucleicAcidStrandDIV=6,this.linewidth=1,this.hlLineRadius=.1,this.threshbox=180,this.maxAtoms3DMultiFile=4e4,this.tsHbond=3.8,this.tsIonic=6,this.tsContact=4,this.tsHalogen=3.8,this.tsPication=6,this.tsPistacking=5.5,this.LABELSIZE=30,this.rayThreshold=.5,this.colorBlackbkgd="#ffff00",this.colorWhitebkgd="#000000",this.optsOri={},this.optsOri.camera="perspective",this.optsOri.effect="none",this.optsOri.background="black",this.optsOri.color="chain",this.optsOri.proteins="ribbon",this.optsOri.sidec="nothing",this.optsOri.nucleotides="nucleotide cartoon",this.optsOri.ntbase="nothing",this.optsOri.surface="nothing",this.optsOri.opacity="1.0",this.optsOri.wireframe="no",this.optsOri.map="nothing",this.optsOri.mapwireframe="yes",this.optsOri.emmap="nothing",this.optsOri.emmapwireframe="yes",this.optsOri.phimap="nothing",this.optsOri.phimapwireframe="yes",this.optsOri.phisurface="nothing",this.optsOri.phisurftype="nothing",this.optsOri.phisurfop="1.0",this.optsOri.phisurfwf="yes",this.optsOri.chemicals="stick",this.optsOri.water="nothing",this.optsOri.ions="sphere",this.optsOri.hbonds="no",this.optsOri.saltbridge="no",this.optsOri.contact="no",this.optsOri.halogen="no",this.optsOri["pi-cation"]="no",this.optsOri["pi-stacking"]="no",this.optsOri.ssbonds="yes",this.optsOri.clbonds="yes",this.optsOri.rotationcenter="molecule center",this.optsOri.axis="no",this.optsOri.fog="no",this.optsOri.slab="no",this.optsOri.pk="residue",this.optsOri.chemicalbinding="hide",this.opts=n.hashUtilsCls.cloneHash(this.optsOri),this.sheetcolor="green",this.bShowHighlight=!0,this.mapData={},this.bFullUi=!0,this.divid=this.icn3dui.cfg.divid,this.inputid="",this.setOperation="or",this.ROT_DIR="right",this.currSelectedSets=[],this.selectedResidues={},this.ncbi2resid={},this.resid2ncbi={},this.shapeCmdHash={},this.bHideSelection=!0,this.bSelectResidue=!1,this.bSelectAlignResidue=!1,this.bAnnoShown=!1,this.bSetChainsAdvancedMenu=!1,this.b2DShown=!1,this.bCrashed=!1,this.bAddCommands=!0,this.bAddLogs=!0,this.bNotLoadStructure=!1,this.InputfileData="",this.bVr=!1,this.bAr=!1,this.startColor="blue",this.midColor="white",this.endColor="red",this.startValue=0,this.midValue=50,this.endValue=100,this.crosslinkRadius=.4,this.sceneCls=new oc(this),this.cameraCls=new cc(this),this.fogCls=new hc(this),this.boxCls=new pc(this),this.brickCls=new uc(this),this.curveStripArrowCls=new mc(this),this.curveCls=new fc(this),this.cylinderCls=new gc(this),this.lineCls=new bc(this),this.reprSubCls=new Cc(this),this.sphereCls=new vc(this),this.stickCls=new _c(this),this.strandCls=new xc(this),this.stripCls=new Sc(this),this.tubeCls=new wc(this),this.cartoonNuclCls=new Ac(this),this.surfaceCls=new Pc(this),this.labelCls=new Tc(this),this.axesCls=new Ec(this),this.glycanCls=new Rc(this),this.applyCenterCls=new Dc(this),this.applyClbondsCls=new Lc(this),this.applyMissingResCls=new Fc(this),this.applyDisplayCls=new Nc(this),this.applyMapCls=new zc(this),this.applyOtherCls=new Uc(this),this.applySsbondsCls=new Hc(this),this.applySymdCls=new Bc(this),this.hlObjectsCls=new bh(this),this.residueLabelsCls=new qc(this),this.alternateCls=new $c(this),this.drawCls=new Vc(this),this.firstAtomObjCls=new yc(this),this.impostorCls=new jc(this),this.instancingCls=new Gc(this),this.contactCls=new Wc(this),this.hBondCls=new Xc(this),this.piHalogenCls=new Yc(this),this.saltbridgeCls=new Kc(this),this.loadPDBCls=new $h(this),this.loadCIFCls=new Vh(this),this.vastplusCls=new Wh(this),this.transformCls=new pp(this),this.setStyleCls=new Zc(this),this.setColorCls=new Jc(this),this.threeDPrintCls=new fp(this),this.export3DCls=new gp(this),this.annoCddSiteCls=new th(this),this.annoContactCls=new ih(this),this.annoPTMCls=new sh(this),this.annoIgCls=new nh(this),this.annoCrossLinkCls=new rh(this),this.annoDomainCls=new ah(this),this.annoSnpClinVarCls=new oh(this),this.annoSsbondCls=new lh(this),this.annoTransMemCls=new dh(this),this.domain3dCls=new ch(this),this.addTrackCls=new hh(this),this.annotationCls=new ph(this),this.showAnnoCls=new uh(this),this.showSeqCls=new mh(this),this.hlSeqCls=new fh(this),this.hlUpdateCls=new gh(this),this.lineGraphCls=new Ch(this),this.getGraphCls=new vh(this),this.showInterCls=new _h(this),this.viewInterPairsCls=new yh(this),this.drawGraphCls=new Sh(this),this.contactMapCls=new wh(this),this.alignParserCls=new xh(this),this.chainalignParserCls=new Ah(this),this.dsn6ParserCls=new Mh(this),this.ccp4ParserCls=new Th(this),this.mtzParserCls=new kh(this),this.mmcifParserCls=new Oh(this),this.mmdbParserCls=new Ih(this),this.bcifParserCls=new Ph(this),this.mol2ParserCls=new Dh(this),this.opmParserCls=new Lh(this),this.pdbParserCls=new Fh(this),this.sdfParserCls=new Nh(this),this.xyzParserCls=new Uh(this),this.msaParserCls=new Hh(this),this.realignParserCls=new Bh(this),this.densityCifParserCls=new zh(this),this.ParserUtilsCls=new qh(this),this.loadAtomDataCls=new jh(this),this.setSeqAlignCls=new Gh(this),this.applyCommandCls=new Xh(this),this.definedSetsCls=new Yh(this),this.selectCollectionsCls=new Kh(this),this.legendTableCls=new eh(this),this.loadScriptCls=new Zh(this),this.selByCommCls=new Jh(this),this.selectionCls=new Qh(this),this.resid2specCls=new ep(this),this.delphiCls=new tp(this),this.dsspCls=new ip(this),this.refnumCls=new sp(this),this.scapCls=new np(this),this.symdCls=new rp(this),this.alignSWCls=new ap(this),this.analysisCls=new op(this),this.resizeCanvasCls=new hp(this),this.saveFileCls=new up(this),this.setOptionCls=new Qc(this),this.shareLinkCls=new mp(this),this.diagram2dCls=new lp(this),this.cartoon2dCls=new dp(this),this.ligplotCls=new cp(this),this.rayCls=new bp(this),this.controlCls=new Cp(this),this.pickingCls=new vp(this),this.VRButtonCls=new _p(this),this.ARButtonCls=new yp(this),this.matShader=this.setColorCls.setOutlineColor("yellow")}}wp.prototype.init=function(e){this.init_base(),this.molTitle="",this.ssbondpnts={},this.clbondpnts={},this.biomtMatrices=[],this.bAssembly=!0,this.bDrawn=!1,this.bSecondaryStructure=!1,this.bHighlight=1,this.axes=[]},wp.prototype.init_base=function(e){this.resetConfig(),this.structures={},this.chains={},this.tddomains={},this.residues={},this.secondaries={},this.alnChains={},this.chainsSeq={},this.chainsColor={},this.chainsGene={},this.chainsAn={},this.chainsAnTitle={},this.chainsMapping={},this.resid2refnum={},this.residIgLoop={},this.refnum2residArray={},this.bShowRefnum=!1,this.alnChainsSeq={},this.alnChainsAnno={},this.alnChainsAnTtl={},this.pickedAtomList={},this.prevHighlightObjects=[],this.prevHighlightObjects_ghost=[],this.prevSurfaces=[],this.prevMaps=[],this.prevEmmaps=[],this.prevPhimaps=[],this.prevOtherMesh=[],this.defNames2Residues={},this.defNames2Atoms={},this.defNames2Descr={},this.defNames2Command={},this.residueId2Name={},this.atoms={},this.dAtoms={},this.hAtoms={},this.proteins={},this.sidec={},this.ntbase={},this.nucleotides={},this.nucleotidesO3={},this.chemicals={},this.ions={},this.water={},this.calphas={},this.hbondpnts=[],this.saltbridgepnts=[],this.contactpnts=[],this.stabilizerpnts=[],this.halogenpnts=[],this.picationpnts=[],this.pistackingpnts=[],this.distPnts=[],this.doublebonds={},this.triplebonds={},this.aromaticbonds={},this.atomPrevColors={},this.style2atoms={},this.labels={},this.lines={},this.resids2inter={},this.resids2interAll={},this.transformCls.rotateCount=0,this.transformCls.rotateCountMax=20,e&&(this.commands=[]),this.axes=[],this.bGlycansCartoon=0,this.bMembrane=1,this.bCmdWindow=0,this.chainMissingResidueArray={},this.nTotalGap=0},wp.prototype.reinitAfterLoad=function(){let e=this,t=e.icn3dui;e.resetConfig(),e.setStyleCls.setAtomStyleByOptions(),e.setColorCls.setColorByOptions(e.opts,e.atoms),e.dAtoms=t.hashUtilsCls.cloneHash(e.atoms),e.hAtoms=t.hashUtilsCls.cloneHash(e.atoms),e.prevHighlightObjects=[],e.prevHighlightObjects_ghost=[],e.prevSurfaces=[],e.prevMaps=[],e.prevEmmaps=[],e.prevPhimaps=[],e.prevOtherMesh=[],e.labels={},e.lines={},e.shapeCmdHash={},e.bAssembly=!0},wp.prototype.resetConfig=function(){let e=this,t=e.icn3dui;if(this.opts=t.hashUtilsCls.cloneHash(this.optsOri),void 0===t.cfg.align&&void 0===t.cfg.chainalign||(this.opts.color="identity",this.opts.proteins="c alpha trace",this.opts.nucleotides="o3 trace"),void 0===t.cfg.cid&&void 0===t.cfg.smiles||(this.opts.color="atom",this.opts.pk="atom",this.opts.chemicals="ball and stick"),(void 0!==t.cfg.afid||e.bEsmfold)&&(this.opts.color="confidence"),void 0!==t.cfg.blast_rep_id&&(this.opts.color="conservation"),void 0!==t.cfg.mmdbafid){let i=t.cfg.mmdbafid.split(",");if(i.length>1)e.opts.color="structure";else if(1==i.length){let t=i[0];isNaN(t)&&t.length>5?this.opts.color="confidence":e.opts.color="chain"}}void 0!==t.cfg.options&&$.extend(this.opts,t.cfg.options)};class xp{constructor(e){this.cfg=e,this.pre=this.cfg.divid+"_",this.REVISION="3.45.1",this.bNode=Object.keys(window).length<3,void 0===this.cfg.command&&(this.cfg.command=""),void 0===this.cfg.width&&(this.cfg.width="100%"),void 0===this.cfg.height&&(this.cfg.height="100%"),void 0===this.cfg.resize&&(this.cfg.resize=!0),void 0===this.cfg.showlogo&&(this.cfg.showlogo=!0),void 0===this.cfg.showmenu&&(this.cfg.showmenu=!0),void 0===this.cfg.showtitle&&(this.cfg.showtitle=!0),void 0===this.cfg.showcommand&&(this.cfg.showcommand=!0),void 0===this.cfg.mobilemenu&&(this.cfg.mobilemenu=!1),void 0===this.cfg.imageonly&&(this.cfg.imageonly=!1),void 0===this.cfg.closepopup&&(this.cfg.closepopup=!1),void 0===this.cfg.showanno&&(this.cfg.showanno=!1),void 0===this.cfg.showseq&&(this.cfg.showseq=!1),void 0===this.cfg.showalignseq&&(this.cfg.showalignseq=!1),void 0===this.cfg.show2d&&(this.cfg.show2d=!1),void 0===this.cfg.showsets&&(this.cfg.showsets=!1),void 0===this.cfg.rotate&&(this.cfg.rotate="right"),void 0===this.cfg.hidelicense&&(this.cfg.hidelicense=!1),this.hashUtilsCls=new Dl(this),this.utilsCls=new Ll(this),this.parasCls=new Fl(this),this.myEventCls=new Nl(this),this.rmsdSuprCls=new Ul(this),this.subdivideCls=new Hl(this),this.convertTypeCls=new Bl(this),this.htmlCls=new Xl(this)}allCustomEvents(){}}xp.prototype.show3DStructure=async function(e){let t=this;t.cfg.menuicon?(t.htmlCls.wifiStr='<i class="icn3d-wifi" title="requires internet"> </i>',t.htmlCls.licenseStr='<i class="icn3d-license" title="requires license"> </i>'):(t.htmlCls.wifiStr="",t.htmlCls.licenseStr=""),t.setIcn3d();let i=t.icn3d;t.utilsCls.isSessionStorageSupported()&&i.setStyleCls.getCommandsBeforeCrash();let s=t.htmlCls.WIDTH,n=t.htmlCls.HEIGHT;t.oriWidth=s,t.oriHeight=n,t.htmlCls.eventsCls.allEventFunctions(),this.allCustomEvents();let r=0;if((null==t.cfg.showmenu||t.cfg.showmenu)&&(r+=t.htmlCls.MENU_HEIGHT),(null==t.cfg.showcommand||t.cfg.showcommand)&&(r+=t.htmlCls.CMD_HEIGHT),null!=t.cfg.showmenu&&0==t.cfg.showmenu?t.htmlCls.setMenuCls.hideMenu():t.htmlCls.setMenuCls.showMenu(),null!=t.cfg.showtitle&&0==t.cfg.showtitle?$("#"+i.pre+"title").hide():$("#"+i.pre+"title").show(),$("#"+i.pre+"viewer").width(s).height(parseInt(n)+r),$("#"+i.pre+"canvas").width(s).height(parseInt(n)),$("#"+i.pre+"canvas").resizable({resize:function(e,s){t.htmlCls.WIDTH=s.size.width,t.htmlCls.HEIGHT=s.size.height,void 0===i||t.icn3d.bFullscreen||i.resizeCanvasCls.resizeCanvas(t.htmlCls.WIDTH,t.htmlCls.HEIGHT,!0)}}),void 0!==t.cfg.usepdbnum?t.icn3d.bUsePdbNum=t.cfg.usepdbnum:void 0!==t.cfg.date?t.icn3d.bUsePdbNum=parseInt(t.cfg.date)>=20201222:"1tup"==t.cfg.mmdbid&&1==t.cfg.showanno&&1==t.cfg.show2d&&1==t.cfg.showsets||"118496"==t.cfg.mmdbid&&0==t.cfg.showanno&&-1!=t.cfg.inpara.indexOf("bu=1")||"163605,1,91105,1,1,1"==t.cfg.align&&-1!=t.cfg.inpara.indexOf("atype=1")?t.icn3d.bUsePdbNum=!1:t.icn3d.bUsePdbNum=!0,t.cfg.replay?(i.bReplay=1,$("#"+i.pre+"replay").show()):(i.bReplay=0,$("#"+i.pre+"replay").hide()),t.utilsCls.isMobile()&&(i.threshbox=60),t.cfg.controlGl&&(i.bControlGl=!0,i.container=i.bControlGl&&!t.bNode?$(document):$("#"+i.id)),i.setStyleCls.handleContextLost(),i.applyCenterCls.setWidthHeight(s,n),i.ori_chemicalbinding=i.opts.chemicalbinding,i.opts=t.hashUtilsCls.cloneHash(i.opts),i.STATENUMBER=i.commands.length,t.utilsCls.isSessionStorageSupported()&&i.bCrashed){i.bCrashed=!1;let e=i.commandsBeforeCrash.split("|||")[0],s=e.substr(e.lastIndexOf(" ")+1);if(s===t.cfg.bcifid||s===t.cfg.mmtfid||s===t.cfg.pdbid||s===t.cfg.opmid||s===t.cfg.mmdbid||s===t.cfg.gi||s===t.cfg.blast_rep_id||s===t.cfg.cid||s===t.cfg.mmcifid||s===t.cfg.align||s===t.cfg.chainalign||s===t.cfg.mmdbafid)return void await i.loadScriptCls.loadScript(i.commandsBeforeCrash,!0)}if(i.molTitle="",i.loadCmd,t.htmlCls.clickMenuCls.getHiddenMenusFromCache(),t.htmlCls.clickMenuCls.applyShownMenus(),e){if(i.init(),i.bInputfile=!0,i.InputfileType="pdb",i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+e:e,await i.pdbParserCls.loadPdbData(e),void 0!==t.cfg.resdef&&void 0!==t.cfg.chains){let e=Object.keys(i.structures),s=t.cfg.chains.split(" | "),n=[];if(e.length==s.length){for(let t=0,i=e.length;t<i;++t)n.push(e[t]+"_"+s[t]);n=i.chainalignParserCls.addPostfixForChainids(n);let t=!0,r=!0;await i.realignParserCls.realignChainOnSeqAlign(void 0,n,t,r)}}else if(void 0!==t.cfg.matchedchains){let e=Object.keys(i.structures)[0]+"_"+t.cfg.masterchain,s=t.cfg.matchedchains.split(","),n=[];for(let e=0,t=s.length;e<t;++e){let t=s[e].lastIndexOf("_"),i=s[e].substr(t+1);isNaN(i)?n.push(s[e]):n.push(s[e].substr(0,t))}let r="";for(let e=0,t=n.length;e<t;++e)e>0&&(r+=","),r+=n[e].substr(0,n[e].indexOf("_"));i.chainidArray=[e].concat(n),i.chainidArray=i.chainalignParserCls.addPostfixForChainids(i.chainidArray),i.loadCmd="vast_search_chainid "+i.chainidArray,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),i.bMmdbafid=!0;let a=!0;await i.chainalignParserCls.downloadMmdbAf(r,a)}}else if(void 0!==t.cfg.url){i.bInputUrlfile=!0;let e=t.cfg.url.split("|"),s=e[0],n=e[1];i.molTitle="",i.inputid=n,i.inputurl="type="+s+"&url="+encodeURIComponent(n),i.loadCmd="load url "+n+" | type "+s,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.pdbParserCls.downloadUrl(n,s,t.cfg.command)}else if(void 0!==t.cfg.mmtfid)i.inputid=t.cfg.mmtfid,i.loadCmd="load mmtf "+t.cfg.mmtfid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.bcifParserCls.downloadBcif(t.cfg.mmtfid);else if(void 0!==t.cfg.bcifid)i.inputid=t.cfg.bcifid,i.loadCmd="load bcif "+t.cfg.bcifid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.bcifParserCls.downloadBcif(t.cfg.bcifid);else if(void 0!==t.cfg.pdbid)i.inputid=t.cfg.pdbid,i.loadCmd="load pdb "+t.cfg.pdbid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.pdbParserCls.downloadPdb(t.cfg.pdbid);else if(void 0!==t.cfg.afid){i.inputid=t.cfg.afid,i.loadCmd="load af "+t.cfg.afid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0);let e=!0;await i.pdbParserCls.downloadPdb(t.cfg.afid,e)}else if(void 0!==t.cfg.opmid)i.inputid=t.cfg.opmid,i.loadCmd="load opm "+t.cfg.opmid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.opmParserCls.downloadOpm(t.cfg.opmid);else if(void 0!==t.cfg.mmdbid)i.inputid=t.cfg.mmdbid,i.loadCmd="load mmdb "+t.cfg.mmdbid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadMmdb(t.cfg.mmdbid);else if(void 0!==t.cfg.gi)i.loadCmd="load gi "+t.cfg.gi,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadGi(t.cfg.gi);else if(void 0!==t.cfg.refseqid)i.inputid=t.cfg.refseqid,i.loadCmd="load refseq "+t.cfg.refseqid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadRefseq(t.cfg.refseqid);else if(void 0!==t.cfg.protein)i.inputid=t.cfg.protein,i.loadCmd="load protein "+t.cfg.protein,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadProteinname(t.cfg.protein);else if(void 0!==t.cfg.blast_rep_id)if(i.inputid=t.cfg.query_id+","+t.cfg.blast_rep_id,t.cfg.oriQuery_id=t.cfg.query_id,t.cfg.oriBlast_rep_id=t.cfg.blast_rep_id,"Query"!==t.cfg.query_id.substr(0,5)&&void 0===t.cfg.rid)"icn3d"==t.cfg.from&&"1TSR_A"==t.cfg.blast_rep_id&&"NP_001108451.1"==t.cfg.query_id&&(t.cfg.command="view annotations; set annotation cdd; set annotation site; set view detailed view; select chain 1TSR_A; show selection"),"smithwm"==t.cfg.alg?(i.loadCmd="load seq_struct_ids_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,i.bSmithwm=!0):"local_smithwm"==t.cfg.alg?(i.loadCmd="load seq_struct_ids_local_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,i.bLocalSmithwm=!0):(i.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,i.bSmithwm=!1,i.bLocalSmithwm=!1),t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadBlast_rep_id(t.cfg.query_id+","+t.cfg.blast_rep_id);else if(void 0!==t.cfg.rid){let e="https://blast.ncbi.nlm.nih.gov/Blast.cgi?RESULTS_FILE=on&FORMAT_TYPE=JSON2_S&FORMAT_OBJECT=Alignment&CMD=Get&RID="+t.cfg.rid,s=await t.getAjaxPromise(e,"json",!1,"The RID "+t.cfg.rid+" may have expired...");for(let e=0,n=s.BlastOutput2.length;e<n;++e){let n,r;if(s.BlastOutput2[e].report.results.iterations){let i=s.BlastOutput2[e].report.results.iterations.length;if(s.BlastOutput2[e].report.results.iterations[i-1].search.query_id!=t.cfg.query_id)continue;n=s.BlastOutput2[e].report.results.iterations[i-1].search.hits}else{if(s.BlastOutput2[e].report.results.search.query_id!=t.cfg.query_id)continue;n=s.BlastOutput2[e].report.results.search.hits}for(let e=0,i=n.length;e<i;++e){let i=n[e],s=!1;for(let e=0,n=i.description.length;e<n;++e){if(i.description[e].accession==t.cfg.blast_rep_id){s=!0;break}}if(s){r=i.hsps[0].qseq,r=r.replace(/-/g,"");break}}void 0!==r&&(t.cfg.query_id=r),i.inputid=t.cfg.query_id+"_"+t.cfg.blast_rep_id,i.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadBlast_rep_id(t.cfg.query_id+","+t.cfg.blast_rep_id);break}}else alert('BLAST "RID" is a required parameter...');else if(void 0!==t.cfg.cid){if(isNaN(t.cfg.cid)){let e=t.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?compound2cid="+t.cfg.cid,i=await t.getAjaxPromise(e,"jsonp");if(!i.cid||!i.cid[0])return void alert("Please input an valid PubChem CID...");t.cfg.cid=i.cid[0]}i.inputid=t.cfg.cid;let e="https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+i.inputid+"/description/jsonp",s=await t.getAjaxPromise(e,"jsonp",!1);void 0!==s.InformationList&&void 0!==s.InformationList.Information&&(i.molTitle=s.InformationList.Information[0].Title),i.loadCmd="load cid "+t.cfg.cid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.sdfParserCls.downloadCid(t.cfg.cid)}else if(void 0!==t.cfg.smiles)i.inputid=t.cfg.smiles,i.loadCmd="load smiles "+t.cfg.smiles,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.sdfParserCls.downloadSmiles(t.cfg.smiles);else if(void 0!==t.cfg.mmcifid)i.inputid=t.cfg.mmcifid,i.loadCmd="load mmcif "+t.cfg.mmcifid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmcifParserCls.downloadMmcif(t.cfg.mmcifid);else if(void 0!==t.cfg.align){-1!=t.cfg.align.indexOf("185055,")&&(t.cfg.align=t.cfg.align.replace("185055,","199731,"));let e=t.cfg.align.split(",");if(6===e.length?i.inputid=e[0]+"_"+e[3]:2===e.length&&(i.inputid=e[0]+"_"+e[1]),i.loadCmd="load alignment "+t.cfg.align+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),t.cfg.inpara&&-1==t.cfg.inpara.indexOf("atype=2"))await i.alignParserCls.downloadAlignment(t.cfg.align);else{let e=2;await i.chainalignParserCls.downloadMmdbAf(t.cfg.align,void 0,e)}}else if(void 0!==t.cfg.chainalign){i.bChainAlign=!0,i.inputid=t.cfg.chainalign;let e=t.cfg.resrange?" | resrange "+decodeURIComponent(t.cfg.resrange):"",s=t.cfg.resdef?t.cfg.resdef:"";i.loadCmd="load chainalignment "+t.cfg.chainalign+" | resnum "+t.cfg.resnum+" | resdef "+s+" | aligntool "+t.cfg.aligntool+" | parameters "+t.cfg.inpara+e,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.chainalignParserCls.downloadChainalignment(t.cfg.chainalign)}else if(void 0!==t.cfg.mmdbafid)t.cfg.mmdbafid=t.cfg.mmdbafid.replace(/\s+/g,"").toUpperCase(),i.bMmdbafid=!0,i.inputid=t.cfg.mmdbafid,1==t.cfg.bu?i.loadCmd="load mmdbaf1 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara:i.loadCmd="load mmdbaf0 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.chainalignParserCls.downloadMmdbAf(t.cfg.mmdbafid);else{if(void 0===t.cfg.command||""===t.cfg.command)return void t.htmlCls.dialogCls.openDlg("dl_mmdbafid","Please input PDB/MMDB/AlphaFold UniProt IDs");-1!==t.cfg.command.indexOf("url=")&&(i.bInputUrlfile=!0)}await i.loadScriptCls.loadScript(t.cfg.command,void 0,!0)},xp.prototype.setIcn3d=function(){let e=this,t="<label class='icn3d-switch'><input id='"+e.pre+"modeswitch' type='checkbox'><div class='icn3d-slider icn3d-round' style='width:34px; height:18px; margin: 6px 0px 0px 3px;' title='Left(\"All atoms\"): Style and color menu options will be applied to all atoms in the structure Right(\"Selection\"): Style and color menu options will be applied only to selected atoms'></div></label>",i="<span id='"+e.pre+"modeall' title='Style and color menu options will be applied to all atoms in the structure'>All atoms </span><span id='"+e.pre+"modeselection' class='icn3d-modeselection' style='display:none;' title='Style and color menu options will be applied only to selected atoms'>Selection </span></div></div></td>";e.utilsCls.setViewerWidthHeight(e),e.utilsCls.isMobile()||e.cfg.mobilemenu?e.htmlCls.setMenuCls.setTopMenusHtmlMobile(e.cfg.divid,t,i):e.htmlCls.setMenuCls.setTopMenusHtml(e.cfg.divid,t,i),e.icn3d=new wp(e),e.icn3d.controlCls.setControl(),e.setDialogAjax()},xp.prototype.getMmtfPromise=function(e){return new Promise((function(t,i){MMTF.fetch(e,(async function(e){t(e)}),(function(e){i("error")}))}))},xp.prototype.getMmtfReducedPromise=function(e){return new Promise((function(t,i){MMTF.fetchReduced(e,(async function(e){t(e)}),(function(e){i("error")}))}))},xp.prototype.getXMLHttpRqstPromise=function(e,t,i,s){let n=this;return new Promise((function(r,a){let o=new XMLHttpRequest;o.open(t,e,!0),o.responseType=i,o.onreadystatechange=function(){if(4==this.readyState)if(200==this.status){let e=o.response;r(e)}else"2fofc"==s||"fofc"==s?alert("Density server at EBI has no corresponding electron density map for this structure."):"em"==s?alert("Density server at EBI has no corresponding EM density map for this structure."):"rcsbEdmaps"==s?alert("RCSB server has no corresponding electron density map for this structure."):console.log("The "+s+" file is unavailable..."),a("error");else n.icn3d.ParserUtilsCls.showLoading()},o.send()}))},xp.prototype.getAjaxPromise=function(e,t,i,s,n,r,a){let o=this;return new Promise((function(a,l){$.ajax({url:e,dataType:t,cache:!0,beforeSend:function(){i&&o.icn3d.ParserUtilsCls.showLoading()},complete:function(){r&&o.icn3d.ParserUtilsCls.hideLoading()},success:function(e){a(e)},error:function(){s&&alert(s),n&&console.log(n),l("error")}})}))},xp.prototype.getAjaxPostPromise=async function(e,t,i,s,n,r,a,o){let l=this;return a=a||"json",new Promise((function(o,d){$.ajax({url:e,type:"POST",data:t,dataType:a,cache:!0,beforeSend:function(){i&&l.icn3d.ParserUtilsCls.showLoading()},complete:function(){r&&l.icn3d.ParserUtilsCls.hideLoading()},success:function(e){o(e)},error:function(){!l.bNode&&s&&console.log(s),!l.bNode&&n&&console.log(n),o("error")}})}))},xp.prototype.setDialogAjax=function(){this.bNode||$.ui.dialog.prototype._makeDraggableBase||($.ui.dialog.prototype._makeDraggableBase=$.ui.dialog.prototype._makeDraggable,$.ui.dialog.prototype._makeDraggable=function(){this._makeDraggableBase(),this.uiDialog.draggable("option","containment",!1)}),$.ajaxTransport("+binary",(function(e,t,i){if(window.FormData&&(e.dataType&&"binary"==e.dataType||e.data&&(window.ArrayBuffer&&e.data instanceof ArrayBuffer||window.Blob&&e.data instanceof Blob)))return{send:function(t,i){let s=new XMLHttpRequest,n=e.url,r=e.type,a=e.async||!0,o=e.responseType||"blob",l=e.data||null;s.addEventListener("load",(function(){let t={};t[e.dataType]=s.response,i(s.status,s.statusText,t,s.getAllResponseHeaders())})),s.open(r,n,a);for(let e in t)s.setRequestHeader(e,t[e]);s.responseType=o,s.send(l)},abort:function(){i.abort()}}}))};return e.ARButton=yp,e.AddTrack=hh,e.AlignParser=xh,e.AlignSW=ap,e.AlignSeq=Vl,e.Alternate=$c,e.Analysis=op,e.AnnoCddSite=th,e.AnnoContact=ih,e.AnnoCrossLink=rh,e.AnnoDomain=ah,e.AnnoSnpClinVar=oh,e.AnnoSsbond=lh,e.AnnoTransMem=dh,e.Annotation=ph,e.ApplyCenter=Dc,e.ApplyClbonds=Lc,e.ApplyCommand=Xh,e.ApplyDisplay=Nc,e.ApplyMap=zc,e.ApplyOther=Uc,e.ApplySsbonds=Hc,e.ApplySymd=Bc,e.Axes=Ec,e.Box=pc,e.Brick=uc,e.Camera=cc,e.CartoonNucl=Ac,e.ChainalignParser=Ah,e.ClickMenu=zl,e.Contact=Wc,e.Control=Cp,e.ConvertTypeCls=Bl,e.Curve=fc,e.CurveStripArrow=mc,e.Cylinder=gc,e.DefinedSets=Yh,e.Delphi=tp,e.DensityCifParser=zh,e.Diagram2d=lp,e.Dialog=jl,e.Domain3d=ch,e.Draw=Vc,e.DrawGraph=Sh,e.Dsn6Parser=Mh,e.Dssp=ip,e.ElectronMap=Ic,e.Events=$l,e.Export3D=gp,e.FirstAtomObj=yc,e.Fog=hc,e.GetGraph=vh,e.Glycan=Rc,e.HBond=Xc,e.HashUtilsCls=Dl,e.HlObjects=bh,e.HlSeq=fh,e.HlUpdate=gh,e.Html=Xl,e.Impostor=jc,e.Instancing=Gc,e.Label=Tc,e.Line=bc,e.LineGraph=Ch,e.LoadAtomData=jh,e.LoadCIF=Vh,e.LoadPDB=$h,e.LoadScript=Zh,e.MarchingCube=kc,e.MmcifParser=Oh,e.MmdbParser=Ih,e.Mol2Parser=Dh,e.MsaParser=Hh,e.MyEventCls=Nl,e.OpmParser=Lh,e.ParasCls=Fl,e.ParserUtils=qh,e.PdbParser=Fh,e.PiHalogen=Yc,e.Picking=vp,e.ProteinSurface=Oc,e.Ray=bp,e.RealignParser=Bh,e.Refnum=sp,e.ReprSub=Cc,e.Resid2spec=ep,e.ResidueLabels=qc,e.ResizeCanvas=hp,e.RmsdSuprCls=Ul,e.Saltbridge=Kc,e.SaveFile=up,e.Scap=np,e.Scene=oc,e.SdfParser=Nh,e.SelectByCommand=Jh,e.Selection=Qh,e.SetColor=Jc,e.SetDialog=Gl,e.SetHtml=Wl,e.SetMenu=ql,e.SetOption=Qc,e.SetSeqAlign=Gh,e.SetStyle=Zc,e.ShareLink=mp,e.ShowAnno=uh,e.ShowInter=_h,e.ShowSeq=mh,e.Sphere=vc,e.Stick=_c,e.Strand=xc,e.Strip=Sc,e.SubdivideCls=Hl,e.Surface=Pc,e.Symd=rp,e.ThreeDPrint=fp,e.Transform=pp,e.Tube=wc,e.UtilsCls=Ll,e.VRButton=_p,e.Vastplus=Wh,e.ViewInterPairs=yh,e.XyzParser=Uh,e.iCn3D=wp,e.iCn3DUI=xp,e.printMsg=class{constructor(){console.log("This is a message from the icn3d package")}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
18
|
+
let c=0,h="query",p=o.substr(0,o.indexOf("_")),u=!0;n.chainalignParserCls.transformStructure(p,c,h,u);let m="";for(let e=0,s=i.length;e<s;++e)m+=t[parseInt(i[e])]+"; ";r.bNode||console.log("Selected the alignment: "+m);break}{let e="";for(let s=0,n=i.length;s<n;++s)e+=t[parseInt(i[s])]+"; ";r.bNode||console.log("skipped the alignment: "+e)}}}d||n.bRender&&alert("These structures can not be aligned...")}RotMatrixTransDist(e,t,i,s){this.icn3d.icn3dui;if(!e||!t)return i;let n=this.GetRotMatrix(e,1,s),r=this.GetRotMatrix(t,1,s),a=[],o=[],l=[],d=[];a[0]=n[9],a[1]=n[10],a[2]=n[11],o[0]=n[12],o[1]=n[13],o[2]=n[14],l[0]=r[9],l[1]=r[10],l[2]=r[11],d[0]=r[12],d[1]=r[13],d[2]=r[14];let c=[],h=[];c[0]=o[0]-d[0],c[1]=o[1]-d[1],c[2]=o[2]-d[2],h[0]=a[0]-l[0],h[1]=a[1]-l[1],h[2]=a[2]-l[2];let p,u,m=0;if(m+=Math.pow(c[0],2),m+=Math.pow(c[1],2),m+=Math.pow(c[2],2),p=Math.sqrt(m),m=0,m+=Math.pow(h[0],2),m+=Math.pow(h[1],2),m+=Math.pow(h[2],2),u=Math.sqrt(m),2!=s){if(p<1e-10||u<1e-10)return i}else if(u<1e-10)return i;if(Math.abs(p-u)>8)return i;let f=[];f[0]=n[0]*a[0]+n[1]*a[1]+n[2]*a[2],f[1]=n[3]*a[0]+n[4]*a[1]+n[5]*a[2],f[2]=n[6]*a[0]+n[7]*a[1]+n[8]*a[2],f[0]-=n[0]*l[0]+n[1]*l[1]+n[2]*l[2],f[1]-=n[3]*l[0]+n[4]*l[1]+n[5]*l[2],f[2]-=n[6]*l[0]+n[7]*l[1]+n[8]*l[2];let g=0;return g=c[0]*f[0],g+=c[1]*f[1],g+=c[2]*f[2],g/=p*u,g<.866?i:(f[0]=r[0]*a[0]+r[1]*a[1]+r[2]*a[2],f[1]=r[3]*a[0]+r[4]*a[1]+r[5]*a[2],f[2]=r[6]*a[0]+r[7]*a[1]+r[8]*a[2],f[0]-=r[0]*l[0]+r[1]*l[1]+r[2]*l[2],f[1]-=r[3]*l[0]+r[4]*l[1]+r[5]*l[2],f[2]-=r[6]*l[0]+r[7]*l[1]+r[8]*l[2],g=c[0]*f[0],g+=c[1]*f[1],g+=c[2]*f[2],g/=p*u,g<.866?i:(m=0,m+=Math.pow(e.q_rotation.x1-t.q_rotation.x1,2),m+=Math.pow(e.q_rotation.y1-t.q_rotation.y1,2),m+=Math.pow(e.q_rotation.z1-t.q_rotation.z1,2),m+=Math.pow(e.q_rotation.x2-t.q_rotation.x2,2),m+=Math.pow(e.q_rotation.y2-t.q_rotation.y2,2),m+=Math.pow(e.q_rotation.z2-t.q_rotation.z2,2),m+=Math.pow(e.q_rotation.x3-t.q_rotation.x3,2),m+=Math.pow(e.q_rotation.y3-t.q_rotation.y3,2),m+=Math.pow(e.q_rotation.z3-t.q_rotation.z3,2),Math.sqrt(m)))}GetRotMatrix(e,t,i){this.icn3d.icn3dui;let s=[];return s&&(s[0]=e.q_rotation.x1/t,s[1]=e.q_rotation.y1/t,s[2]=e.q_rotation.z1/t,s[3]=e.q_rotation.x2/t,s[4]=e.q_rotation.y2/t,s[5]=e.q_rotation.z2/t,s[6]=e.q_rotation.x3/t,s[7]=e.q_rotation.y3/t,s[8]=e.q_rotation.z3/t,2!=i?(s[9]=e.t_trans_add.x/t,s[10]=e.t_trans_add.y/t,s[11]=e.t_trans_add.z/t,s[12]=-e.q_trans_sub.x/t,s[13]=-e.q_trans_sub.y/t,s[14]=-e.q_trans_sub.z/t):(s[9]=-e.q_trans_add.x/t,s[10]=-e.q_trans_add.y/t,s[11]=-e.q_trans_add.z/t,s[12]=0,s[13]=0,s[14]=0)),s}cbu_dist(e,t,i){return e<t?i[e][t]:i[t][e]}compareFloat(e,t,i){let s=e[t].dist,n=e[i].dist;return parseInt(1e4*s)==parseInt(1e4*n)?0:parseInt(1e4*s)<parseInt(1e4*n)?-1:1}clusterLinkage(e,t,i){let s,n,r,a,o,l,d,c,h=this.icn3d,p=h.icn3dui,u=[],m=t.length;for(s=0;s<2*m-1;++s)u[s]={},u[s].leaves=[];let f=[];for(s=0;s<2*m-1;++s)for(f[s]=[],n=0;n<2*m-1;++n)f[s][n]=2;for(s=0;s<m;++s)for(n=s;n<m;++n)f[s][n]=t[s][n];let g={},b={},C={};for(a=m,o=m,s=0;s<m;++s){for(d=2,n=0;n<m;++n){let e=i?parseInt(1e4*this.cbu_dist(s,n,f))<=parseInt(1e4*d):parseInt(1e4*this.cbu_dist(s,n,f))<parseInt(1e4*d);n!=s&&e&&(d=this.cbu_dist(s,n,f),a=s,o=n)}g[a]=o,C[a]=d}let v=[];for(l=0;l<m;++l)u[l].child1=-2,u[l].child2=-2,u[l].parent=l,u[l].dist=0,u[l].leaves.push([l]),v[l]=0;let _=Object.keys(h.structures),y=h.structures[_[0]].length,S=h.structures[_[1]].length,w=y<S?y:S;for(l=m;l<2*m-1;++l){for(r in d=2,g)c=C[r],c<d&&(d=c,a=r,o=g[r]);let e=d;for(u[l].child1=a<m?a:-a,u[l].child2=o<m?o:-o,u[l].parent=-1*l,u[a].dist=e-v[a],u[o].dist=e-v[o],v[l]=e,n=0;n<2*m-1;++n){let e=this.cbu_dist(a,n,f),t=this.cbu_dist(o,n,f);l<n?f[l][n]=e<t?e:t:f[n][l]=e<t?e:t}for(n=0;n<2*m-1;++n)a<n?f[a][n]=2:f[n][a]=2,o<n?f[o][n]=2:f[n][o]=2;let t=4;if(u[a].leaves.length<t*w&&u[o].leaves.length<t*w){u[l].leaves=[];for(let e=0,t=u[a].leaves.length;e<t;++e)for(let t=0,i=u[o].leaves.length;t<i;++t)u[l].leaves.push(u[a].leaves[e].concat(u[o].leaves[t])),u[l].leaves.push(u[o].leaves[t].concat(u[a].leaves[e]));u[a].leaves=[],u[o].leaves=[]}for(r in delete g[a],delete g[o],delete C[a],delete C[o],b=p.hashUtilsCls.cloneHash(g),b)b[r]!=a&&b[r]!=o||(delete g[r],g[r]=l);let i=2*m;for(d=2,n=0;n<2*m-1;++n)n!=l&&this.cbu_dist(l,n,f)<d&&(d=this.cbu_dist(l,n,f),i=n);g[l]=i,C[l]=d}return l==2*m-1&&(u[l-1].parent=-1,u[l-1].dist=0),u}GetChainMappings(e,t){this.icn3d.icn3dui;let i,s,n=[];t.length;let r=this.getClusters(e,!0).clusters,a=r.length;for(let e=0;e<a;++e){let a=r[e];for(let e=0,r=a.length;e<r;++e){let r={nodeArray:[]},o={},l={};for(let n=0,d=a[e].length;n<d;++n){let d=a[e][n],c=t[d].split(",");i=c[0],s=c[1],o.hasOwnProperty(i)||l.hasOwnProperty(s)||(r.nodeArray.push(d.toString().padStart(5,"0")),o[i]=1,l[s]=1)}n.push(r)}}return n}getClusters(e,t){this.icn3d.icn3dui;let i=[],s=[],n=0,r=e.length,a=t?0:1;for(;n<r;++n)e[n].leaves.length>a&&(i.push(e[n].leaves),s.push(e[n].dist));return{clusters:i,scores:s}}}class Xh{constructor(e){this.icn3d=e}async applyCommand(e){let t=this.icn3d,i=t.icn3dui;t.bAddCommands=!1;let s=e.split("|||")[0].split("%7C%7C%7C")[0].replace(/\s+/g," ").trim(),n=s.toLowerCase();if("share link"==n)await t.shareLinkCls.shareLink();else if("export state file"==n);else if(0==n.indexOf("export canvas"))setTimeout((async function(){let e=n.substr(13).trim();t.scaleFactor=""===e?1:parseInt(e);let i=""!==e;await t.shareLinkCls.shareLink(!0,i)}),500);else if("export interactions"==n)t.viewInterPairsCls.exportInteractions();else if("export stl file"==n)setTimeout((function(){t.export3DCls.exportStlFile("")}),500);else if("export vrml file"==n)setTimeout((function(){t.export3DCls.exportVrmlFile("")}),500);else if("export stl stabilizer file"==n)setTimeout((function(){t.threeDPrintCls.hideStabilizer(),t.threeDPrintCls.resetAfter3Dprint(),t.threeDPrintCls.addStabilizer(),t.export3DCls.exportStlFile("_stab")}),500);else if("export vrml stabilizer file"==n)setTimeout((function(){t.threeDPrintCls.hideStabilizer(),t.threeDPrintCls.resetAfter3Dprint(),t.threeDPrintCls.addStabilizer(),t.export3DCls.exportVrmlFile("_stab")}),500);else if("export pdb"==n)i.htmlCls.setHtmlCls.exportPdb();else if("export pdb missing atoms"==n)await t.scapCls.exportPdbProfix(!1);else if("export pdb hydrogen"==n)await t.scapCls.exportPdbProfix(!0);else if(-1!=n.indexOf("export refnum ")){let e=n.substr(14);t.refnumCls.exportRefnum(e)}else if("export secondary structure"==n)i.htmlCls.setHtmlCls.exportSecondary();else if("select all"==n)t.selectionCls.selectAll();else if("show all"==n)t.selectionCls.showAll();else if("select complement"==n)t.resid2specCls.selectComplement();else if("set pk atom"==n)t.pk=1,t.opts.pk="atom";else if("set pk off"==n)t.pk=0,t.opts.pk="no",t.drawCls.draw(),t.hlObjectsCls.removeHlObjects();else if("set pk residue"==n)t.pk=2,t.opts.pk="residue";else if("set pk strand"==n)t.pk=3,t.opts.pk="strand";else if("set pk domain"==n)t.pk=4,t.opts.pk="domain";else if("set pk chain"==n)t.pk=5,t.opts.pk="chain";else if("set surface wireframe on"==n)t.opts.wireframe="yes",t.applyMapCls.applySurfaceOptions();else if("set surface wireframe off"==n)t.opts.wireframe="no",t.applyMapCls.applySurfaceOptions();else if("set map wireframe on"==n)t.opts.mapwireframe="yes",t.applyMapCls.applyMapOptions();else if("set map wireframe off"==n)t.opts.mapwireframe="no",t.applyMapCls.applyMapOptions();else if("set emmap wireframe on"==n)t.opts.emmapwireframe="yes",t.applyMapCls.applyEmmapOptions();else if("set emmap wireframe off"==n)t.opts.emmapwireframe="no",t.applyMapCls.applyEmmapOptions();else if("set surface neighbors on"==n)t.bConsiderNeighbors=!0,t.applyMapCls.applySurfaceOptions();else if("set surface neighbors off"==n)t.bConsiderNeighbors=!1,t.applyMapCls.applySurfaceOptions();else if("set axis on"==n)t.opts.axis="yes";else if("set pc1 axis"==n)t.pc1=!0,t.axesCls.setPc1Axes();else if("set axis off"==n)t.opts.axis="no",t.pc1=!1;else if("set fog on"==n)t.opts.fog="yes",t.fogCls.setFog(!0);else if("set fog off"==n)t.opts.fog="no",t.fogCls.setFog(!0);else if("set slab on"==n)t.opts.slab="yes";else if("set slab off"==n)t.opts.slab="no";else if("stereo on"==n)t.opts.effect="stereo";else if("stereo off"==n)t.opts.effect="none";else if("set assembly on"==n)t.bAssembly=!0;else if("set assembly off"==n)t.bAssembly=!1;else if("set chemicalbinding show"==n)t.setOptionCls.setOption("chemicalbinding","show");else if("set chemicalbinding hide"==n)t.setOptionCls.setOption("chemicalbinding","hide");else if("set hbonds off"==n)t.hBondCls.hideHbonds(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("set salt bridge off"==n)t.saltbridgeCls.hideSaltbridge(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("set contact off"==n)t.contactCls.hideContact(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("set halogen pi off"==n)t.piHalogenCls.hideHalogenPi(),t.showInterCls.hideExtraBonds(),t.drawCls.draw();else if("hydrogens"==n)t.showInterCls.showHydrogens(),t.drawCls.draw();else if("set hydrogens off"==n)t.showInterCls.hideHydrogens(),t.drawCls.draw();else if("close popup"==n)t.resizeCanvasCls.closeDialogs();else if("set stabilizer off"==n)t.threeDPrintCls.hideStabilizer(),t.drawCls.draw();else if("set disulfide bonds off"==n)t.opts.ssbonds="no",t.drawCls.draw();else if("set cross linkage off"==n)t.opts.clbonds="no",t.drawCls.draw();else if("set lines off"==n)t.labels.distance=[],t.lines.distance=[],t.drawCls.draw();else if("set labels off"==n){for(let e in t.labels)t.labels[e]=[];t.drawCls.draw()}else if("set mode all"==n)t.definedSetsCls.setModeAndDisplay("all");else if("set mode selection"==n)t.definedSetsCls.setModeAndDisplay("selection");else if("set view detailed view"==n)t.annotationCls.setAnnoViewAndDisplay("detailed view");else if("set view overview"==n)t.annotationCls.setAnnoViewAndDisplay("overview");else if("set annotation custom"==n)t.annotationCls.setAnnoTabCustom();else if("set annotation interaction"==n)t.annotationCls.setAnnoTabInteraction();else if("set annotation ptm"==n)await t.annotationCls.setAnnoTabPTM();else if("set annotation cdd"==n)t.annotationCls.setAnnoTabCdd();else if("set annotation site"==n)t.annotationCls.setAnnoTabSite();else if("set annotation ssbond"==n)t.annotationCls.setAnnoTabSsbond();else if("set annotation crosslink"==n)t.annotationCls.setAnnoTabCrosslink();else if("set annotation transmembrane"==n)await t.annotationCls.setAnnoTabTransmem();else if("set annotation ig"==n)t.bRunRefnumAgain=!0,await t.annotationCls.setAnnoTabIg(),t.bRunRefnumAgain=!1;else if("ig refnum on"==n)t.bRunRefnumAgain=!0,t.bAnnoShown||await t.showAnnoCls.showAnnotations(),await t.annotationCls.setAnnoTabIg(!0),t.bRunRefnumAgain=!1;else if("highlight level up"==n)t.resid2specCls.switchHighlightLevelUp();else if("highlight level down"==n)t.resid2specCls.switchHighlightLevelDown();else if(0==n.indexOf("hide annotation")){let e=n.lastIndexOf(" "),i=n.substr(e+1);"all"==i?t.annotationCls.hideAnnoTabAll():"custom"==i?t.annotationCls.hideAnnoTabCustom():"clinvar"==i?t.annotationCls.hideAnnoTabClinvar():"snp"==i?t.annotationCls.hideAnnoTabSnp():"cdd"==i?t.annotationCls.hideAnnoTabCdd():"3ddomain"==i?t.annotationCls.hideAnnoTab3ddomain():"site"==i?t.annotationCls.hideAnnoTabSite():"ptm"==i?t.annotationCls.hideAnnoTabPTM():"interaction"==i?t.annotationCls.hideAnnoTabInteraction():"ssbond"==i?t.annotationCls.hideAnnoTabSsbond():"crosslink"==i?t.annotationCls.hideAnnoTabCrosslink():"transmembrane"==i&&t.annotationCls.hideAnnoTabTransmem()}else if("add residue labels"==n)t.residueLabelsCls.addResidueLabels(t.hAtoms),t.drawCls.draw();else if("add residue number labels"==n)t.residueLabelsCls.addResidueLabels(t.hAtoms,void 0,void 0,!0),t.drawCls.draw();else if("add reference number labels"==n)t.residueLabelsCls.addResidueLabels(t.hAtoms,void 0,void 0,void 0,!0),t.drawCls.draw();else if("add ig labels"==n)t.residueLabelsCls.addIgLabels(t.hAtoms),t.drawCls.draw();else if("add atom labels"==n)t.residueLabelsCls.addAtomLabels(t.hAtoms),t.drawCls.draw();else if("add element labels"==n)t.residueLabelsCls.addAtomLabels(t.hAtoms,!0),t.drawCls.draw();else if("add chain labels"==n)t.analysisCls.addChainLabels(t.hAtoms),t.drawCls.draw();else if("add terminal labels"==n)t.analysisCls.addTerminiLabels(t.hAtoms),t.drawCls.draw();else if("rotate left"==n)t.bStopRotate=!1,t.ROT_DIR="left",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("left");else if("rotate right"==n)t.bStopRotate=!1,t.ROT_DIR="right",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("right");else if("rotate up"==n)t.bStopRotate=!1,t.ROT_DIR="up",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("up");else if("rotate down"==n)t.bStopRotate=!1,t.ROT_DIR="down",t.transformCls.rotateCountMax=6e3,t.resizeCanvasCls.rotStruc("down");else if("rotate x"==n){let e=new mt(1,0,0),i=.5*Math.PI;t.transformCls.setRotation(e,i)}else if("rotate y"==n){let e=new mt(0,1,0),i=.5*Math.PI;t.transformCls.setRotation(e,i)}else if("rotate z"==n){let e=new mt(0,0,1),i=.5*Math.PI;t.transformCls.setRotation(e,i)}else if("reset"===n)t.selectionCls.resetAll();else if("reset orientation"===n)t.transformCls.resetOrientation(),t.drawCls.draw();else if("reset thickness"==n)t.threeDPrintCls.resetAfter3Dprint(),t.drawCls.draw();else if("clear selection"==n)t.hlObjectsCls.removeHlObjects(),t.hlUpdateCls.removeHl2D(),t.bSelectResidue=!1;else if("zoom selection"==n)t.transformCls.zoominSelection(),t.drawCls.draw();else if("center selection"==n)t.applyCenterCls.centerSelection(),t.drawCls.draw();else if("show selection"==n)t.selectionCls.showSelection();else if("hide selection"==n)t.selectionCls.hideSelection();else if("output selection"==n)t.threeDPrintCls.outputSelection();else if("toggle selection"==n)t.selectionCls.toggleSelection();else if("toggle highlight"==n)t.hlUpdateCls.toggleHighlight();else if("stabilizer"==n)t.threeDPrintCls.addStabilizer(),t.threeDPrintCls.prepareFor3Dprint();else if("disulfide bonds"==n)t.showInterCls.showSsbonds();else if("cross linkage"==n)t.showInterCls.showClbonds();else if("back"==n)await t.resizeCanvasCls.back();else if("forward"==n)await t.resizeCanvasCls.forward();else if("clear all"==n)t.selectionCls.selectAll();else if("defined sets"==n)t.definedSetsCls.showSets(),t.bDefinedSets=!0;else if("delete selected sets"==n)t.definedSetsCls.deleteSelectedSets();else if("view interactions"==n)void 0===i.cfg.mmdbid&&void 0===i.cfg.gi||t.ParserUtilsCls.set2DDiagrams(t.inputid);else if("show annotations all chains"==n)t.annotationCls.showAnnoAllChains();else if("save color"==n)t.setOptionCls.saveColor();else if("apply saved color"==n)t.setOptionCls.applySavedColor();else if("save style"==n)t.setOptionCls.saveStyle();else if("apply saved style"==n)t.setOptionCls.applySavedStyle();else if("select main chains"==n)t.selectionCls.selectMainChains();else if("select side chains"==n)t.selectionCls.selectSideChains();else if("select main side chains"==n)t.selectionCls.selectMainSideChains();else if("realign"==n)t.realignParserCls.realign();else if(-1!=n.indexOf("realign predefined ")){let e="realign predefined ",n=s.substr(e.length),r=n.indexOf(" "),a=n.substr(0,r).split(",");i.cfg.resdef=n.substr(r+1).replace(/:/gi,";"),await t.realignParserCls.realignChainOnSeqAlign(void 0,a,!0,!0)}else if("area"==n)t.analysisCls.calculateArea();else if("table inter count only"==n)$(".icn3d-border").hide();else if("table inter details"==n)$(".icn3d-border").show();else if("setoption map nothing"==n)t.setOptionCls.setOption("map","nothing");else if("setoption emmap nothing"==n)t.setOptionCls.setOption("emmap","nothing");else if("setoption phimap nothing"==n)t.setOptionCls.setOption("phimap","nothing");else if("setoption phisurface nothing"==n)t.setOptionCls.setOption("phisurface","nothing");else if("clear symd symmetry"==n)t.symdArray=[];else if("show axis"==n)t.bAxisOnly=!0;else if(0==s.indexOf("define helix sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"helix")}else if(0==s.indexOf("define sheet sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"sheet")}else if(0==s.indexOf("define coil sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"coil")}else if(0==s.indexOf("define iganchor sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"iganchor")}else if(0==s.indexOf("define igstrand sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igstrand")}else if(0==s.indexOf("define igloop sets")){let e=s.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igloop")}else if(0==s.indexOf("select interaction")){let e=s.substr(s.lastIndexOf(" ")+1).split(",");if(null!==e){let i=e[0].split("_")[0];t.b2DShown||t.ParserUtilsCls.download2Ddgm(i.toUpperCase()),t.diagram2dCls.selectInteraction(e[0],e[1])}}else if(0==s.indexOf("select saved atoms")||0==s.indexOf("select sets")){s=s.replace(/aligned_protein/g,"protein_aligned"),t.bDefinedSets||(t.definedSetsCls.setPredefinedInMenu(),t.bDefinedSets=!0);let e=s.split(" | "),i=e[0].replace(/,/g," or "),n=19;0==s.indexOf("select sets")&&(n=12);let r=i.substr(n),a=r;2==e.length&&(a=e[1].substr(5)),t.definedSetsCls.selectCombinedSets(r,a)}else if(-1!==s.indexOf("select chain")){let e=s.substr(s.lastIndexOf(" ")+1).split(",");for(let i=0,s=e.length;i<s;++i)t.selectionCls.selectAChain(e[i],e[i],!1)}else if(-1!==s.indexOf("select alignChain")){let e=s.substr(s.lastIndexOf(" ")+1).split(",");for(let i=0,s=e.length;i<s;++i)t.selectionCls.selectAChain(e[i],"align_"+e[i],!0)}else if(0==s.indexOf("select zone cutoff")){let e=this.getThresholdNameArrays(s);t.showInterCls.pickCustomSphere(e.threshold,e.nameArray2,e.nameArray,e.bHbondCalc),t.bSphereCalc=!0}else if(0==n.indexOf("set surface opacity")){t.transparentRenderOrder=!1;let e=n.substr(n.lastIndexOf(" ")+1);t.opts.opacity=parseFloat(e),t.applyMapCls.applySurfaceOptions(),parseInt(100*e)<100&&(t.bTransparentSurface=!0)}else if(0==n.indexOf("set surface2 opacity")){t.transparentRenderOrder=!0;let e=n.substr(n.lastIndexOf(" ")+1);t.opts.opacity=parseFloat(e),t.applyMapCls.applySurfaceOptions(),parseInt(100*e)<100&&(t.bTransparentSurface=!0)}else if(0==n.indexOf("set label scale")){let e=n.substr(n.lastIndexOf(" ")+1);t.labelScale=parseFloat(e)}else if(0==n.indexOf("set surface")){let e=n.substr(12);t.opts.surface=e,t.applyMapCls.applySurfaceOptions()}else if(0==n.indexOf("set camera")){let e=n.substr(n.lastIndexOf(" ")+1);t.opts.camera=e}else if(0==n.indexOf("set background")){let e=n.substr(n.lastIndexOf(" ")+1);t.opts.background=e,"black"==e?($("#"+t.pre+"title").css("color",i.htmlCls.GREYD),$("#"+t.pre+"titlelink").css("color",i.htmlCls.GREYD)):($("#"+t.pre+"title").css("color","black"),$("#"+t.pre+"titlelink").css("color","black"))}else if(0==n.indexOf("set label color"))t.labelcolor=n.substr(n.lastIndexOf(" ")+1);else if(0==s.indexOf("set thickness")){let e=n.split(" | ");t.bSetThickness=!0;for(let i=1,s=e.length;i<s;++i){let s=e[i].split(" "),n=s[0],r=parseFloat(s[1]);"linerad"!=n||isNaN(r)||(t.lineRadius=r),"coilrad"!=n||isNaN(r)||(t.coilWidth=r),"stickrad"!=n||isNaN(r)||(t.cylinderRadius=r),"crosslinkrad"!=n||isNaN(r)||(t.crosslinkRadius=r),"tracerad"!=n||isNaN(r)||(t.traceRadius=r),"ballscale"!=n||isNaN(r)||(t.dotSphereScale=r),"ribbonthick"!=n||isNaN(r)||(t.ribbonthickness=r),"proteinwidth"!=n||isNaN(r)||(t.helixSheetWidth=r),"nucleotidewidth"!=n||isNaN(r)||(t.nucleicAcidWidth=r)}t.drawCls.draw()}else if(0==s.indexOf("set light")){let e=n.split(" | ");for(let i=1,s=e.length;i<s;++i){let s=e[i].split(" "),n=s[0],r=parseFloat(s[1]);"light1"==n&&(t.light1=r),"light2"==n&&(t.light2=r),"light3"==n&&(t.light3=r)}t.drawCls.draw()}else if(0==s.indexOf("set shininess")){let e=n.lastIndexOf(" ");t.shininess=parseFloat(n.substr(e+1)),t.drawCls.draw()}else if(0==s.indexOf("set glycan")){let e=n.lastIndexOf(" ");t.bGlycansCartoon=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==s.indexOf("set membrane")){let e=n.lastIndexOf(" ");t.bMembrane=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==s.indexOf("set cmdwindow")){let e=n.lastIndexOf(" "),t=parseInt(n.substr(e+1));i.htmlCls.setMenuCls.setLogWindow(!0,t)}else if(0==n.indexOf("set highlight color")){let e=n.substr(20);"yellow"===e?(t.hColor=i.parasCls.thr(16776960),t.matShader=t.setColorCls.setOutlineColor("yellow")):"green"===e?(t.hColor=i.parasCls.thr(65280),t.matShader=t.setColorCls.setOutlineColor("green")):"red"===e&&(t.hColor=i.parasCls.thr(16711680),t.matShader=t.setColorCls.setOutlineColor("red")),t.drawCls.draw()}else if(0==n.indexOf("set highlight style")){let e=n.substr(20);"outline"===e?t.bHighlight=1:"3d"===e&&(t.bHighlight=2),t.drawCls.draw()}else if(0==n.indexOf("add line")){let e=n.split(" | "),i=e[1].split(" "),s=e[2].split(" "),r=e[3].substr(e[3].lastIndexOf(" ")+1),a="true"===e[4].substr(e[4].lastIndexOf(" ")+1),o=e[5].substr(e[5].lastIndexOf(" ")+1),l=e.length>6?e[6].substr(e[6].lastIndexOf(" ")+1):0,d=e.length>7?e[7].substr(e[7].lastIndexOf(" ")+1):1;t.analysisCls.addLine(parseFloat(i[1]),parseFloat(i[3]),parseFloat(i[5]),parseFloat(s[1]),parseFloat(s[3]),parseFloat(s[5]),r,a,o,parseFloat(l),parseFloat(d)),t.drawCls.draw()}else if(0==n.indexOf("add sphere"))this.addShape(s,"sphere"),t.shapeCmdHash[s]=1;else if(0==n.indexOf("add cube"))this.addShape(s,"cube"),t.shapeCmdHash[s]=1;else if(0==n.indexOf("clear shape"))t.shapeCmdHash={};else if(0==n.indexOf("clear line between sets"))t.lines.cylinder=[];else if(0==s.indexOf("add label")){let e,n,r,a,o,l,d,c=s.split(" | "),h=c[0].substr(10),p=!1;for(let t=1,i=c.length;t<i;++t){let i=c[t].split(" ");"x"==i[0]?(p=!0,e=parseFloat(i[1]),n=parseFloat(i[3]),r=parseFloat(i[5])):"size"==i[0]?a=c[t].substr(c[t].lastIndexOf(" ")+1):"color"==i[0]?o=c[t].substr(c[t].lastIndexOf(" ")+1):"background"==i[0]?l=c[t].substr(c[t].lastIndexOf(" ")+1):"type"==i[0]&&(d=c[t].substr(c[t].lastIndexOf(" ")+1))}if(!p){let s=t.applyCenterCls.centerAtoms(i.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms));e=parseFloat(s.center.x),n=parseFloat(s.center.y),r=parseFloat(s.center.z)}t.analysisCls.addLabel(h,e,n,r,a,o,l,d),t.drawCls.draw()}else if(0==s.indexOf("msa")){let e=s.split(" | ")[1].split(" ");t.targetGapHash={};for(let i=0,s=e.length;i<s;++i){let s=e[i].split("_");t.targetGapHash[parseInt(s[0])]={from:parseInt(s[1]),to:parseInt(s[2])}}await t.annotationCls.resetAnnoAll()}else if(0==s.indexOf("add track")){let e,i,n,r=s.split(" | "),a=r[1].substr(8),o=r[2].substr(6),l=r[3].substr(5);r.length>=5&&(e=r[4].substr(5)),r.length>=6&&(i=r[5].substr(6)),r.length>=7&&(n=r[6].substr(4)),$("#"+t.pre+"anno_custom")[0]&&($("#"+t.pre+"anno_custom")[0].checked=!0),$("[id^="+t.pre+"custom]").show(),"0"==i&&(i=void 0),t.addTrackCls.checkGiSeq(a,o,l,e,i,n,0)}else if(0==n.indexOf("remove one stabilizer")){let e=n.split(" | ")[1].split(" "),i=[];i.push(parseInt(e[0])),i.push(parseInt(e[1])),t.threeDPrintCls.removeOneStabilizer(i),t.drawCls.draw()}else if(0==n.indexOf("add one stabilizer")){let e=n.split(" | ")[1].split(" ");void 0===t.pairArray&&(t.pairArray=[]),t.pairArray.push(parseInt(e[0])),t.pairArray.push(parseInt(e[1])),t.drawCls.draw()}else if(0==n.indexOf("select planes z-axis")){let e=n.split(" ");if(5==e.length){let i=parseFloat(e[3]),s=parseFloat(e[4]);t.selectionCls.selectBtwPlanes(i,s)}}else if(0==n.indexOf("adjust membrane z-axis")){let e=n.split(" ");if(5==e.length){let i=parseFloat(e[3]),s=parseFloat(e[4]);t.selectionCls.adjustMembrane(i,s)}}else if(0==n.indexOf("toggle membrane"))t.selectionCls.toggleMembrane();else if(0==s.indexOf("calc buried surface")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),s=i[1].split(",");t.analysisCls.calcBuriedSurface(e,s)}}}else if(0==s.indexOf("dist ")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),s=i[1].split(",");t.analysisCls.measureDistTwoSets(e,s)}}}else if(0==s.indexOf("disttable")){let e=s.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),n=s[1].split(",");t.analysisCls.measureDistManySets(e,n),i.htmlCls.dialogCls.openDlg("dl_disttable","Distances among the sets")}}}else if(0==s.indexOf("angletable")){let e=s.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),n=s[1].split(",");t.analysisCls.measureAngleManySets(e,n),i.htmlCls.dialogCls.openDlg("dl_angletable","Angles among the sets")}}}else if(0==s.indexOf("display interaction 3d")||0==s.indexOf("view interaction pairs")||0==s.indexOf("save1 interaction pairs")||0==s.indexOf("save2 interaction pairs")||0==s.indexOf("line graph interaction pairs")||0==s.indexOf("scatterplot interaction pairs")||0==s.indexOf("ligplot interaction pairs")){let e=s.split(" | ");if(e.length>=3){let i=e[1].split(" ");if(2==i.length){let n,r,a=i[0].split(","),o=i[1].split(","),l=-1!==e[2].indexOf("hbonds"),d=-1!==e[2].indexOf("salt bridge"),c=-1!==e[2].indexOf("interactions"),h=-1!==e[2].indexOf("halogen"),p=-1!==e[2].indexOf("pi-cation"),u=-1!==e[2].indexOf("pi-stacking");if(e.length>=4&&(n="true"==e[3]),e.length>=5){let i=e[4].split(" ");i.length>=4&&($("#"+t.pre+"hbondthreshold").val(i[1]),$("#"+t.pre+"saltbridgethreshold").val(i[2]),$("#"+t.pre+"contactthreshold").val(i[3]),7==i.length&&($("#"+t.pre+"halogenthreshold").val(i[4]),$("#"+t.pre+"picationthreshold").val(i[5]),$("#"+t.pre+"pistackingthreshold").val(i[6])))}0==s.indexOf("display interaction 3d")?r="3d":0==s.indexOf("view interaction pairs")?r="view":0==s.indexOf("save1 interaction pairs")?r="save1":0==s.indexOf("save2 interaction pairs")?r="save2":0==s.indexOf("line graph interaction pairs")?r="linegraph":0==s.indexOf("scatterplot interaction pairs")?r="scatterplot":0==s.indexOf("ligplot interaction pairs")&&(r="ligplot"),await t.viewInterPairsCls.viewInteractionPairs(a,o,n,r,l,d,c,h,p,u)}}}else if(0==s.indexOf("export pairs")){let e=s.split(" | ");if(3==e.length){let s=e[1].split(" ");if(2==s.length){let n=s[0].split(","),r=s[1].split(","),a=e[2].split(" ")[1];t.showInterCls.pickCustomSphere(a,n,r,t.bSphereCalc),t.bSphereCalc=!0;let o=t.viewInterPairsCls.exportSpherePairs(),l=Object.keys(i.utilsCls.getHlStructures()).join(",");t.saveFileCls.saveFile(l+"_sphere_pairs.html","html",o)}}}else if(0==n.indexOf("graph label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+i.svgid+"_label").val(t),$("#"+i.svgid+" text").removeClass(),$("#"+i.svgid+" text").addClass(t)}else if(0==n.indexOf("cartoon label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+i.svgid_ct+"_label").val(t),$("#"+i.svgid_ct+" text").removeClass(),$("#"+i.svgid_ct+" text").addClass(t)}else if(0==n.indexOf("line graph scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.linegraphid+"_scale").val(s),$("#"+i.linegraphid).attr("width",(t.linegraphWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("scatterplot scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.scatterplotid+"_scale").val(s),$("#"+i.scatterplotid).attr("width",(t.scatterplotWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("ligplot scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.ligplotid+"_scale").val(s),t.ligplotScale=parseFloat(s),$("#"+i.ligplotid).attr("width",(t.ligplotWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("contactmap scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.contactmapid+"_scale").val(s),$("#"+i.contactmapid).attr("width",(t.contactmapWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("alignerrormap scale")){let e=n.lastIndexOf(" "),s=n.substr(e+1);$("#"+i.alignerrormapid+"_scale").val(s),$("#"+i.alignerrormapid).attr("width",(t.alignerrormapWidth*parseFloat(s)).toString()+"px")}else if(0==n.indexOf("graph force")){let e=n.lastIndexOf(" ");i.htmlCls.force=parseInt(n.substr(e+1)),$("#"+i.svgid+"_force").val(i.htmlCls.force),t.getGraphCls.handleForce()}else if(0==n.indexOf("hide edges")){let e=n.lastIndexOf(" ");i.htmlCls.hideedges=parseInt(n.substr(e+1)),$("#"+i.svgid+"_hideedges").val(i.htmlCls.hideedges),i.htmlCls.hideedges?(i.htmlCls.contactInsideColor="FFF",i.htmlCls.hbondInsideColor="FFF",i.htmlCls.ionicInsideColor="FFF"):(i.htmlCls.contactInsideColor="DDD",i.htmlCls.hbondInsideColor="AFA",i.htmlCls.ionicInsideColor="8FF"),void 0!==t.graphStr&&t.bRender&&i.htmlCls.force&&t.drawGraphCls.drawGraph(t.graphStr,t.pre+"dl_graph")}else if(0==n.indexOf("reset interaction pairs"))t.viewInterPairsCls.resetInteractionPairs();else if(0==n.indexOf("side by side")){let e=n.split(" | ")[1],t="_blank";window.open(e,t)}else if(0==s.indexOf("your note")){let e=s.split(" | ");t.yournote=e[1],$("#"+t.pre+"yournote").val(t.yournote),i.cfg.shownote&&(document.title=t.yournote)}else if(0==n.indexOf("cross structure interaction"))t.crossstrucinter=parseInt(n.substr(n.lastIndexOf(" ")+1)),$("#"+t.pre+"crossstrucinter").val(t.crossstrucinter);else if("replay on"==n)await t.resizeCanvasCls.replayon();else if("replay off"==n)await t.resizeCanvasCls.replayoff();else if(0==n.indexOf("contact map")){let e=n.split(" | ");if(3===e.length){let i=parseFloat(e[1].split(" ")[1]),s=e[2].split(" ")[1];await t.contactMapCls.contactMap(i,s)}}else if(0==n.indexOf("pickatom")){let e=parseInt(n.substr(n.lastIndexOf(" ")+1));t.pAtom=t.atoms[e],t.pickingCls.showPicking(t.pAtom)}else if(0==s.indexOf("set color spectrum")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!0;t.setColorCls.setColorAcrossSets(i,s)}}else if(0==s.indexOf("set residues color spectrum")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!0;t.setColorCls.setColorBySets(i,s)}}else if(0==s.indexOf("set color rainbow")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!1;t.setColorCls.setColorAcrossSets(i,s)}}else if(0==s.indexOf("set residues color rainbow")){let e=s.split(" | ");if(2==e.length){let i=e[1].split(","),s=!1;t.setColorCls.setColorBySets(i,s)}}else if(0==s.indexOf("color")){let e=s.split(" | "),n=e[0].substr(e[0].indexOf(" ")+1);if(t.opts.color=n,"residue custom"==n&&2==e.length){t.customResidueColors=JSON.parse(e[1]);for(let e in t.customResidueColors)t.customResidueColors[e.toUpperCase()]=i.parasCls.thr("#"+t.customResidueColors[e])}else if("align custom"==n&&3==e.length){let i=e[1],s=e[2].split(", ");t.queryresi2score={},t.queryresi2score[i]={};for(let e=0,n=s.length;e<n;++e){let n=s[e].split(" ");t.queryresi2score[i][n[0]]=n[1]}}else"align custom"==n&&e.length>=4?this.setQueryresi2score(e):"area"==n&&2==e.length&&(t.midpercent=e[1],$("#"+t.pre+"midpercent").val(t.midpercent));t.setColorCls.setColorByOptions(t.opts,t.hAtoms),t.hlUpdateCls.updateHlAll()}else if(0==s.indexOf("remove legend"))$("#"+i.pre+"legend").hide();else if(0==s.indexOf("custom tube")){let e=s.split(" | ");this.setQueryresi2score(e),t.setOptionCls.setStyle("proteins","custom tube")}else if(0==n.indexOf("style")){let e=n.substr(n.indexOf(" ")+1),i=e.substr(0,e.indexOf(" ")),s=e.substr(e.indexOf(" ")+1);t.setOptionCls.setStyle(i,s)}else if(0==n.indexOf("window")){let e=n.substr(n.indexOf(" ")+1);setTimeout((function(){"aligned sequences"==e?i.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"):"interaction table"==e?i.htmlCls.dialogCls.openDlg("dl_allinteraction","Show interactions"):"interaction graph"==e?i.htmlCls.dialogCls.openDlg("dl_linegraph","Show interactions between two lines of residue nodes"):"interaction scatterplot"==e?i.htmlCls.dialogCls.openDlg("dl_scatterplot","Show interactions as scatterplot"):"force-directed graph"==e&&i.htmlCls.dialogCls.openDlg("dl_graph","Force-directed graph")}),1e3)}else if(0==n.indexOf("set theme")){let e=n.substr(n.lastIndexOf(" ")+1);i.htmlCls.setMenuCls.setTheme(e)}else if(0==n.indexOf("set double color")){let e=n.substr(n.lastIndexOf(" ")+1);"on"==e?(t.bDoublecolor=!0,t.setOptionCls.setStyle("proteins","ribbon")):"off"==e&&(t.bDoublecolor=!1)}else if(0==n.indexOf("adjust dialog")){let e=n.substr(n.lastIndexOf(" ")+1);t.scapCls.adjust2DWidth(e)}else if(0==n.indexOf("glycans cartoon")){let e=n.substr(n.lastIndexOf(" ")+1);t.bGlycansCartoon="yes"==e}else if(0==n.indexOf("clashed residues")){"show"==n.substr(n.lastIndexOf(" ")+1)?(t.bHideClashed=!1,t.annoDomainCls.showHideClashedResidues()):(t.bHideClashed=!0,i.htmlCls.clickMenuCls.setClashedResidues(),t.annoDomainCls.showHideClashedResidues())}else if(0==n.indexOf("save html")){let e=n.substr(n.lastIndexOf(" ")+1);i.htmlCls.eventsCls.saveHtml(e)}else if(0==n.indexOf("resdef"))i.cfg.resdef=n.substr(n.indexOf(" ")+1);else if(0==n.indexOf("vast_search_chainid")){t.chainidArray=s.substr(s.indexOf(" ")+1).split(",");let e=!0,i=!0;await t.realignParserCls.realignChainOnSeqAlign(void 0,t.chainidArray,e,i)}else if(0==n.indexOf("ig refnum off"))await t.refnumCls.hideIgRefNum();else if(0==n.indexOf("custom refnum")){let e=s.split(" | ")[1].replace(/\\n/g,"\n");await t.refnumCls.parseCustomRefFile(e)}else if(0==n.indexOf("show ref number"))t.bShownRefnum=!0;else if(0==n.indexOf("hide ref number"))t.bShownRefnum=!1;else if(0==n.indexOf("translate pdb")){let e=n.substr(14).split(" ");t.transformCls.translateCoord(t.hAtoms,parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])),t.drawCls.draw()}else if(0==n.indexOf("rotate pdb")){let e=n.substr(11).split(","),i=[];for(let t=0,s=e.length;t<s;++t)i.push(parseFloat(e[t]));t.transformCls.rotateCoord(t.hAtoms,i),t.drawCls.draw()}else if(0==n.indexOf("set dssp sse"))await t.pdbParserCls.applyCommandDssp(),t.bResetAnno=!0,t.bAnnoShown&&(await t.showAnnoCls.showAnnotations(),t.annotationCls.resetAnnoTabAll());else if(-1!==n.indexOf("select displayed set"))t.hAtoms=i.hashUtilsCls.cloneHash(t.viewSelectionAtoms),t.hlUpdateCls.updateHlAll();else if(-1!==n.indexOf("select prop")){let e,i,n=s.split(" | "),r=n[0].substr(12);if(2==n.length){let t=n[1].split("_");e=t[0],i=t[1]}t.resid2specCls.selectProperty(r,e,i)}else if(-1!==n.indexOf("select each residue"))t.selectionCls.saveEachResiInSel();else if(0==n.indexOf("select")&&-1!==n.indexOf("name")){let e=s.split(" | "),i="",n="",r="";for(let t=0,s=e.length;t<s;++t){let s=e[t];-1!==s.indexOf("select")?i=s.substr(s.indexOf(" ")+1):-1!==s.indexOf("name")&&(n=s.substr(s.indexOf(" ")+1))}r=n,await t.selByCommCls.selectByCommand(i,n,r)}else if(-1!==n.indexOf("select $")||-1!==n.indexOf("select .")||-1!==n.indexOf("select :")||-1!==n.indexOf("select %")||-1!==n.indexOf("select @")){let e=s.split(" | "),i=e[0].substr(e[0].indexOf(" ")+1),n="",r="";e.length>1&&(n=e[1].substr(e[1].indexOf(" ")+1)),e.length>2&&(r=e[2].substr(e[2].indexOf(" ")+1)),-1!==i.indexOf(" or ")?await t.selByCommCls.selectByCommand(i,n,r):await t.selByCommCls.selectBySpec(i,n,r)}i.htmlCls.clickMenuCls.setLogCmd(s,!1),t.bAddCommands=!0}setStrengthPara(e){let t=this.icn3d;if(t.icn3dui,e.length>=5){let i=e[4].split(" ");i.length>=4&&($("#"+t.pre+"hbondthreshold").val(i[1]),$("#"+t.pre+"saltbridgethreshold").val(i[2]),$("#"+t.pre+"contactthreshold").val(i[3]),i.length>=7&&($("#"+t.pre+"halogenthreshold").val(i[4]),$("#"+t.pre+"picationthreshold").val(i[5]),$("#"+t.pre+"pistackingthreshold").val(i[6])))}if(6==e.length){let i=e[5].split(" ");i.length>=6&&($("#"+t.pre+"dist_ss").val(i[0]),$("#"+t.pre+"dist_coil").val(i[1]),$("#"+t.pre+"dist_hbond").val(i[2]),$("#"+t.pre+"dist_inter").val(i[3]),$("#"+t.pre+"dist_ssbond").val(i[4]),$("#"+t.pre+"dist_ionic").val(i[5]),9==i.length&&($("#"+t.pre+"dist_halogen").val(i[6]),$("#"+t.pre+"dist_pication").val(i[7]),$("#"+t.pre+"dist_pistacking").val(i[8])))}}getThresholdNameArrays(e){this.icn3d.icn3dui.htmlCls.clickMenuCls.SetChainsAdvancedMenu();let t,i=e.split(" | "),s=parseFloat(i[0].substr(i[0].lastIndexOf(" ")+1)),n=[],r=[];if(i.length>=2&&i[1].length>4){let e=i[1].split(" ");e.length>1&&(r=e[1].split(",")),e.length>2&&(n=e[2].split(","))}else r=["selected"],n=["non-selected"];return 3==i.length&&(t="true"==i[2]),{threshold:s,nameArray2:r,nameArray:n,bHbondCalc:t}}setQueryresi2score(e){let t=this.icn3d,i=t.icn3dui,s=e[1],n=e[2].split(" ")[1].split("_"),r=e[3];void 0===t.queryresi2score&&(t.queryresi2score={}),t.queryresi2score[s]={};let a=100/9;for(let e=parseInt(n[0]),i=0;e<=parseInt(n[1]);++e,++i)"_"!=r[i]&&(t.queryresi2score[s][e]=parseInt(r[i])*a);if(e.length>4){let s=e[4].split(" ");t.startColor=s[1],t.midColor=s[2],t.endColor=s[3];let n=i.htmlCls.clickMenuCls.setLegendHtml();$("#"+i.pre+"dl_legend_html").html(n),i.htmlCls.dialogCls.openDlg("dl_legend","Color Range")}}addShape(e,t){let i=this.icn3d,s=i.icn3dui,n=e.split(" | "),r=n[1].split(" "),a=n[2].substr(n[2].lastIndexOf(" ")+1),o=n[3].substr(n[3].lastIndexOf(" ")+1),l=n[4].substr(n[4].lastIndexOf(" ")+1);a="#"+a.replace(/\#/g,"");let d,c=s.parasCls.thr(a);if("x1"==r[0])d=new mt(parseFloat(r[1]),parseFloat(r[3]),parseFloat(r[5]));else{let e=n[1].split(","),t=i.definedSetsCls.getAtomsFromNameArray(e),s=i.contactCls.getExtent(t);d=new mt(s[2][0],s[2][1],s[2][2])}"sphere"==t?i.sphereCls.createSphereBase(d,c,parseFloat(l),void 0,void 0,void 0,parseFloat(o)):i.boxCls.createBox_base(d,parseFloat(l),c,void 0,void 0,void 0,parseFloat(o))}getMenuFromCmd(e){this.icn3d.icn3dui;let t="Windows > View Sequences & Annotations",i="Analysis > Interactions",s=i+" > 2D Graph(Force-Directed)",n="View > Rotate > Auto Rotation > Rotate ",r="View > Rotate > Rotate 90 deg > ",a="Select > Select on 3D > ",o="Analysis > Label > ",l="File > 3D Printing > ";return 0==(e=e.trim()).indexOf("load")?"File > Retrieve by ID, Align":0==e.indexOf("set map")&&-1==e.indexOf("set map wireframe")?"Style > Electron Density":0==e.indexOf("set emmap")&&-1==e.indexOf("set emmap wireframe")?"Style > EM Density Map":0==e.indexOf("set phi")?"Analysis > Load Potential > URL(CORS) Phi/Cube":0==e.indexOf("set delphi")?"Analysis > DelPhi Potential":0==e.indexOf("setoption map")?"Style > Remove Map":0==e.indexOf("setoption emmap")?"Style > Remove EM Map":0==e.indexOf("view annotations")?t:0==e.indexOf("set annotation all")?t+': "All" checkbox':0==e.indexOf("set annotation clinvar")?t+': "ClinVar" checkbox':0==e.indexOf("set annotation snp")?t+': "SNP" checkbox':0==e.indexOf("set annotation 3ddomain")?t+': "3D Domains" checkbox':0==e.indexOf("view interactions")?"Windows > View 2D Diagram":0==e.indexOf("symmetry")?"Analysis > Symmetry":0==e.indexOf("realign on seq align")?"File > Realign Selection > on Sequence Alignment":0==e.indexOf("realign")?"File > Realign Selection > Residue by Residue":0==e.indexOf("graph interaction pairs")?i+" > 2D Graph(Force-Directed)":0==e.indexOf("export canvas")?"File > Save File > iCn3D PNG Image":"export stl file"==e?l+"STL":"export vrml file"==e?l+"VRML(Color)":"export stl stabilizer file"==e?l+"STL W/ Stabilizers":"export vrml stabilizer file"==e?l+"VRML(Color, W/ Stabilizers)":"select all"==e?'Select > All; or Toggle to "All"(next to "Help")':"show all"==e?"View > View Full Structure":"select complement"==e?"Select > Inverse":"set pk atom"==e?a+"Atom":"set pk residue"==e?a+"Residue":"set pk strand"==e?a+"Strand/Helix":"set pk domain"==e?a+"3D Domain":"set pk chain"==e?a+"Chain":"set surface wireframe on"==e?"Style > Surface Wireframe > Yes":"set surface wireframe off"==e?"Style > Surface Wireframe > No":"set map wireframe on"==e?"Style > Map Wireframe > Yes":"set map wireframe off"==e?"Style > Map Wireframe > No":"set emmap wireframe on"==e?"Style > EM Map Wireframe > Yes":"set emmap wireframe off"==e?"Style > EM Map Wireframe > No":"set surface neighbors on"==e?"Style > Surface Type > ... with Context":"set axis on"==e?"View > XYZ-axes > Show":"set axis off"==e?"View > XYZ-axes > Hide":"set fog on"==e?"View > Fog for Selection > On":"set fog off"==e?"View > Fog for Selection > Off":"set slab on"==e?"View > Slab for Selection > On":"set slab off"==e?"View > Slab for Selection > Off":"set assembly on"==e?"Analysis > Assembly > Biological Assembly":"set assembly off"==e?"Analysis > Assembly > Asymmetric Unit":"set chemicalbinding show"==e?"Analysis > Chem. Binding > Show":"set chemicalbinding hide"==e?"Analysis > Chem. Binding > Hide":"set hbonds off"==e||"set salt bridge off"==e||"set contact off"==e||"set halogen pi off"==e?i+" > Reset":"hydrogens"==e?"Style > Hydrogens > Show":"set hydrogens off"==e?"Style > Hydrogens > Hide":"set stabilizer off"==e?"File > 3D Printing > Remove All Stabilizers":"set disulfide bonds off"==e?"Analysis > Disulfide Bonds > Hide":"set cross linkage off"==e?"Analysis > Cross-Linkages > Hide":"set lines off"==e?"Analysis > Distance > Hide":"set labels off"==e?"Analysis > Label > Remove":"set mode all"==e?'Toggle to "All"(next to "Help")':"set mode selection"==e?'Toggle to "Selection"(next to "Help")':"set view detailed view"==e?t+': "Details" tab':"set view overview"==e?t+': "Summary" tab':"set annotation custom"==e?t+': "Custom" checkbox':"set annotation interaction"==e?t+': "Interactions" checkbox':"set annotation ptm"==e?t+': "PTM" checkbox':"set annotation cdd"==e?t+': "Conserved Domains" checkbox':"set annotation site"==e?t+': "Functional Sites" checkbox':"set annotation ssbond"==e?t+': "Disulfide Bonds" checkbox':"set annotation crosslink"==e?t+': "Cross-Linkages" checkbox':"set annotation transmembrane"==e?t+': "Transmembrane" checkbox':"set annotation ig"==e?t+': "Ig Domains" checkbox':"highlight level up"==e?"Keyboard Arrow Up":"highlight level down"==e?"Keyboard Arrow Down":0==e.indexOf("hide annotation")?t+": checkboxes off":"add residue labels"==e?o+"per Residue":"add residue number labels"==e?o+"per Residue & Number":"add Ig domain labels"==e?o+"per Ig Domain":"add atom labels"==e?o+"per Atom":"add chain labels"==e?o+"per Chain":"add terminal labels"==e?o+"N- & C- Termini":"rotate left"==e?n+"Left; or Key l":"rotate right"==e?n+"Right; or Key j":"rotate up"==e?n+"Up; or Key i":"rotate down"==e?n+"Down; or Key m":"rotate x"==e?r+"X-axis":"rotate y"==e?r+"Y-axis":"rotate z"==e?r+"Z-axis":"reset"==e?"View > Reset > All":"reset orientation"==e?"View > Reset > Orientation":"clear selection"==e?"Select > Clear Selection":"zoom selection"==e?"Select > Zoom in Selection":"center selection"==e?"Select > Center Selection":"show selection"==e?"Select > View Only Selection":"hide selection"==e?"Select > Hide Selection":"output selection"==e?"Select > Clear Selection":"toggle highlight"==e?"Select > Toggle Highlight":"stabilizer"==e?"File > 3D Printing > Add all Stabilizers":"disulfide bonds"==e?"Analysis > Disulfide Bonds > Show":"cross linkage"==e?"Analysis > Cross-Linkages > Show":"back"==e?"View > Undo":"forward"==e?"View > Redo":"clear all"==e?"Select > Clear Selection":"defined sets"==e?"Windows > Defined Sets":"delete selected sets"==e?'Windows > Defined Sets: "Delete Selected Sets" button':"view interactions"==e?"Windows > View Interactions":"show annotations all chains"==e?t+': "Show All Chains" button':"save color"==e?"Color > Save Color":"apply saved color"==e?"Color > Apply Saved Color":"save style"==e?"Style > Save Style":"apply saved style"==e?"Style > Apply Saved Style":"select main chains"==e?"Select > Main Chains":"select side chains"==e?"Select > Side Chains":"select main side chains"==e?"Select > Main & Side Chains":"area"==e?"View > Surface Area":"table inter count only"==e?i+': "Set 1" button: "Show Count Only" button':"table inter details"==e?i+': "Set 1" button: "Show Details" button':0==e.indexOf("define helix sets")?t+': "Helix Sets" button':0==e.indexOf("define sheet sets")?t+': "Sheet Sets" button':0==e.indexOf("define coil sets")?t+': "Coil Sets" button':0==e.indexOf("select interaction")?"Windows > View 2D Diagram: click on edges":0==e.indexOf("select saved atoms")||0==e.indexOf("select sets")?"Windows > Defined Sets: select in menu":-1!==e.indexOf("select chain")?t+": click on chain names":-1!==e.indexOf("select alignChain")?"Windows > View Aligned Sequences: click on chain names":0==e.indexOf("select zone cutoff")?"Select > by Distance":0==e.indexOf("set surface opacity")?"Style > Surface Opacity":0==e.indexOf("set label scale")?"View > Label Scale":0==e.indexOf("set surface")?"Style > Surface Type":0==e.indexOf("set camera")?"View > Camera":0==e.indexOf("set background")?"Style > Background":0==e.indexOf("set thickness")?"File > 3D Printing > Set Thickness":0==e.indexOf("set highlight color")?"Select > Highlight Color":0==e.indexOf("set highlight style")?"Select > Highlight Style":0==e.indexOf("add line")||0==e.indexOf("add label")?"Analysis > Distance > between Two Atoms":0==e.indexOf("dist")?"Analysis > Distance > between Two Sets":0==e.indexOf("msa")?t+': "Add Track" button: "FASTA Alignment" button':0==e.indexOf("add track")?t+': "Add Track" button':0==e.indexOf("remove one stabilizer")?"File > 3D Printing > Remove One Stablizer":0==e.indexOf("add one stabilizer")?"File > 3D Printing > Add One Stablizer":0==e.indexOf("select planes z-axis")?"View > Select between Two X-Y Planes":0==e.indexOf("adjust membrane z-axis")?"View > Adjust Membrane":0==e.indexOf("toggle membrane")?"View > Toggle Membrane":0==e.indexOf("calc buried surface")?i+': "Buried Surface Area" button':0==e.indexOf("display interaction 3d")?i+': "3D Display Interactions" button':0==e.indexOf("view interaction pairs")?i+': "Highlight Interactions in Table" button':0==e.indexOf("save1 interaction pairs")?i+': "Set 1" button':0==e.indexOf("save2 interaction pairs")?i+': "Set 2" button':0==e.indexOf("line graph interaction pairs")?i+': "2D Interaction Network" button':0==e.indexOf("scatterplot interaction pairs")?i+': "2D Interaction Map" button':0==e.indexOf("ligplot interaction pairs")?i+': "2D Interaction for One Ligand/Residue" button':0==e.indexOf("graph label")?s+': "Label Size" menu':0==e.indexOf("graph force")?s+': "Force on Nodes" menu':0==e.indexOf("hide edges")?s+': "Internal Edges" menu':0==e.indexOf("reset interaction pairs")?i+" > Reset":0==e.indexOf("side by side")?"View > Side by Side":0==e.indexOf("your note")?"Windows > Your Notes / Window Title":0==e.indexOf("pickatom")?"Hold Alt key and click on 3D structure":0==e.indexOf("color")?"Color menu":0==e.indexOf("custom tube")?t+': "Custom Color/Tube" button: "Custom Tube" button':0==e.indexOf("style")?"Style menu":-1!==e.indexOf("select displayed set")?"Select > Displayed Set":-1!==e.indexOf("select prop")?"Select > by Property":0==e.indexOf("select")&&-1!==e.indexOf("name")?t+": drag on residues to select":-1!==e.indexOf("select $")||-1!==e.indexOf("select .")||-1!==e.indexOf("select :")||-1!==e.indexOf("select @")?"Select > Advanced; or other selection":-1!==e.indexOf("replay on")?"File > Replay Each Step > On":-1!==e.indexOf("replay off")?"File > Replay Each Step > Off":-1!==e.indexOf("set theme")?"Style > Theme Color":-1!==e.indexOf("set double color")?"Style > Two-color Helix":""}}class Yh{constructor(e){this.icn3d=e}setProtNuclLigInMenu(){let e=this.icn3d;if(e.icn3dui,e.proteins&&Object.keys(e.proteins).length>0&&(e.defNames2Residues.proteins=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.proteins)),e.defNames2Descr.proteins="proteins",e.defNames2Command.proteins="select :proteins"),e.nucleotides&&Object.keys(e.nucleotides).length>0&&(e.defNames2Residues.nucleotides=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.nucleotides)),e.defNames2Descr.nucleotides="nucleotides",e.defNames2Command.nucleotides="select :nucleotides"),e.chemicals&&Object.keys(e.chemicals).length>0)if(e.bOpm){let t={},i={};for(let s in e.chemicals){let n=e.atoms[s],r=n.structure+"_"+n.chain+"_"+n.resi;"DUM"===n.resn?i[r]=1:t[r]=1}Object.keys(t).length>0&&(e.defNames2Residues.chemicals=Object.keys(t),e.defNames2Descr.chemicals="chemicals",e.defNames2Command.chemicals="select :chemicals"),Object.keys(i).length>0&&(e.defNames2Residues.membrane=Object.keys(i),e.defNames2Descr.membrane="membrane",e.defNames2Command.membrane="select :membrane")}else e.defNames2Residues.chemicals=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.chemicals)),e.defNames2Descr.chemicals="chemicals",e.defNames2Command.chemicals="select :chemicals";e.ions&&Object.keys(e.ions).length>0&&(e.defNames2Residues.ions=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.ions)),e.defNames2Descr.ions="ions",e.defNames2Command.ions="select :ions"),e.water&&Object.keys(e.water).length>0&&(e.defNames2Residues.water=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.water)),e.defNames2Descr.water="water",e.defNames2Command.water="select :water"),this.setTransmemInMenu(e.halfBilayerSize,-e.halfBilayerSize)}setPredefinedInMenu(){let e=this.icn3d,t=e.icn3dui;if(this.setProtNuclLigInMenu(),this.setChainsInMenu(),void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi||void 0!==t.cfg.chainalign||void 0!==t.cfg.mmdbafid)for(let t in e.tddomains)e.selectionCls.selectResidueList(e.tddomains[t],t,t,!1,!1);if((void 0!==t.cfg.align||void 0!==t.cfg.chainalign&&2==e.chainidArray.length)&&e.bFullUi){e.selectionCls.selectResidueList(e.consHash1,e.conservedName1,e.conservedName1,!1,!1),e.selectionCls.selectResidueList(e.consHash2,e.conservedName2,e.conservedName2,!1,!1),e.selectionCls.selectResidueList(e.nconsHash1,e.nonConservedName1,e.nonConservedName1,!1,!1),e.selectionCls.selectResidueList(e.nconsHash2,e.nonConservedName2,e.nonConservedName2,!1,!1),e.selectionCls.selectResidueList(e.nalignHash1,e.notAlignedName1,e.notAlignedName1,!1,!1),e.selectionCls.selectResidueList(e.nalignHash2,e.notAlignedName2,e.notAlignedName2,!1,!1);let i={};for(let s in e.alnChains)i=t.hashUtilsCls.unionHash(i,e.alnChains[s]);let s=e.firstAtomObjCls.getResiduesFromAtoms(i),n="protein_aligned",r="aligned protein and nucleotides",a="select "+e.resid2specCls.residueids2spec(Object.keys(s));e.selectionCls.addCustomSelection(Object.keys(s),n,r,a,!0)}}setAtomMenu(e){let t=this.icn3d;t.icn3dui;let i="",s=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues):[],n=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms):[],r=s.concat(n).sort(),a=[];r.forEach((e=>{-1===$.inArray(e,a)&&a.push(e)}));for(let s=0,n=a.length;s<n;++s){let n,r,o=a[s];if(void 0!==t.defNames2Atoms&&t.defNames2Atoms.hasOwnProperty(o)){let e=t.defNames2Atoms[o];e.length>0&&(n=t.atoms[e[0]])}else if(void 0!==t.defNames2Residues&&t.defNames2Residues.hasOwnProperty(o)){let e=t.defNames2Residues[o];e.length>0&&(r=t.residues[e[0]],r&&(n=t.atoms[Object.keys(r)[0]]))}let l=void 0===n||void 0===n.color||"FFFFFF"===n.color.getHexString().toUpperCase()?"DDDDDD":n.color.getHexString(),d=void 0!==n&&void 0!==n.color?l:"000000";-1!=e.indexOf(o)?i+="<option value='"+o+"' style='color:#"+d+"' selected='selected'>"+o+"</option>":i+="<option value='"+o+"' style='color:#"+d+"'>"+o+"</option>"}return i}setChainsInMenu(){let e=this.icn3d,t=e.icn3dui,i={};for(let s in e.chains){let n=e.firstAtomObjCls.getFirstAtomObj(e.chains[s]);if(e.proteins.hasOwnProperty(n.serial)||e.nucleotides.hasOwnProperty(n.serial)){e.defNames2Residues[s]=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.chains[s])),e.defNames2Descr[s]=s;let t=s.indexOf("_"),i=s.substr(0,t),n=s.substr(t+1);e.defNames2Command[s]="select $"+i+"."+n}else{let s=n.structure+"_"+n.chain+"_"+n.resi,r=n.resn.substr(0,3);i[r]?i[r]=t.hashUtilsCls.unionHash(i[n.resn],e.residues[s]):i[r]=e.residues[s]}}for(let t in i)e.defNames2Residues[t]=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(i[t])),e.defNames2Descr[t]=t,e.defNames2Command[t]="select :3"+t;if(e.structures&&1==Object.keys(e.structures)){let t=Object.keys(e.structures)[0];e.defNames2Residues[t]=Object.keys(e.residues),e.defNames2Descr[t]=t,e.defNames2Command[t]="select $"+t}else if(e.residues){let t=Object.keys(e.residues),i={};for(let e=0,s=t.length;e<s;++e){let s=t[e],n=s.indexOf("_"),r=s.substr(0,n);void 0===i[r]&&(i[r]=[]),i[r].push(s)}for(let t in i)e.defNames2Residues[t]=i[t],e.defNames2Descr[t]=t,e.defNames2Command[t]="select $"+t}}setTransmemInMenu(e,t,i){let s=this.icn3d;if(s.icn3dui,s.bOpm){let n={},r={},a={};for(let i in s.atoms){let o=s.atoms[i];if("DUM"===o.resn)continue;let l=o.structure+"_"+o.chain+"_"+o.resi;o.coord.z>e?r[l]=1:o.coord.z<t?a[l]=1:n[l]=1}let o=i?"2":"";Object.keys(n).length>0&&(s.defNames2Residues["transmembrane"+o]=Object.keys(n),s.defNames2Descr["transmembrane"+o]="transmembrane"+o,s.defNames2Command["transmembrane"+o]="select :transmembrane"+o),Object.keys(r).length>0&&(s.defNames2Residues["extracellular"+o]=Object.keys(r),s.defNames2Descr["extracellular"+o]="extracellular"+o,s.defNames2Command["extracellular"+o]="select :extracellular"+o),Object.keys(a).length>0&&(s.defNames2Residues["intracellular"+o]=Object.keys(a),s.defNames2Descr["intracellular"+o]="intracellular"+o,s.defNames2Command["intracellular"+o]="select :intracellular"+o)}}showSets(){let e=this.icn3d,t=e.icn3dui;t.bNode||(t.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+e.pre+"dl_setsmenu").show(),$("#"+e.pre+"dl_setoperations").show(),$("#"+e.pre+"dl_command").hide(),$("#"+e.pre+"atomsCustom").resizable());let i=t.hashUtilsCls.cloneHash(e.hAtoms),s=t.hashUtilsCls.cloneHash(e.dAtoms);void 0!==e.bSetChainsAdvancedMenu&&e.bSetChainsAdvancedMenu&&!e.bResetSets||(this.setPredefinedInMenu(),e.bSetChainsAdvancedMenu=!0),e.hAtoms=t.hashUtilsCls.cloneHash(i),e.dAtoms=t.hashUtilsCls.cloneHash(s),e.hlUpdateCls.updateHlMenus()}clickCustomAtoms(){let e=this.icn3d,t=e.icn3dui,i=this;$("#"+e.pre+"atomsCustom").change((function(e){let s=i.icn3d,n=$(this).val();if(s.nameArray=n,null!==n){let e=!1;i.changeCustomAtoms(n,e),t.htmlCls.clickMenuCls.setLogCmd("select sets "+n.join(" "+s.setOperation+" "),!0),s.bSelectResidue=!1}})),t.myEventCls.onIds("#"+e.pre+"atomsCustom","focus",(function(e){let s=i.icn3d;t.utilsCls.isMobile()&&$("#"+s.pre+"atomsCustom").val("")}))}deleteSelectedSets(){let e=this.icn3d;e.icn3dui;let t=$("#"+e.pre+"atomsCustom").val();for(let i=0;i<t.length;++i){let s=t[i];(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(s)||void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(s))&&(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(s)&&delete e.defNames2Atoms[s],void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(s)&&delete e.defNames2Residues[s])}e.hlUpdateCls.updateHlMenus()}changeCustomAtoms(e,t){let i=this.icn3d,s=i.icn3dui;i.hAtoms={};for(let t=0;t<e.length;++t){let n=e[t];if(void 0!==i.defNames2Atoms&&i.defNames2Atoms.hasOwnProperty(n)||void 0!==i.defNames2Residues&&i.defNames2Residues.hasOwnProperty(n)){if(void 0!==i.defNames2Atoms&&i.defNames2Atoms.hasOwnProperty(n)){let e=i.defNames2Atoms[n];for(let t=0,s=e.length;t<s;++t)i.hAtoms[e[t]]=1}if(void 0!==i.defNames2Residues&&i.defNames2Residues.hasOwnProperty(n)){let e=i.defNames2Residues[n],t={};for(let n=0,r=e.length;n<r;++n)t=s.hashUtilsCls.unionHash(t,i.residues[e[n]]);i.hAtoms=s.hashUtilsCls.unionHash(i.hAtoms,t)}}}i.hlUpdateCls.updateHlAll(e,t),i.annotationCls.showAnnoSelectedChains(),$("#"+i.pre+"command").val(""),$("#"+i.pre+"command_name").val("");for(let t=0,s=e.length;t<s;++t)if(i.defNames2Atoms[e[t]],i.defNames2Residues[e[t]],i.defNames2Descr[e[t]],0===t)$("#"+i.pre+"command").val("saved atoms "+e[t]),$("#"+i.pre+"command_name").val(e[t]);else{let s=$("#"+i.pre+"command").val();$("#"+i.pre+"command").val(s+" "+i.setOperation+" "+e[t]),s=$("#"+i.pre+"command_name").val(),$("#"+i.pre+"command_name").val(s+" "+i.setOperation+" "+e[t])}}setHAtomsFromSets(e,t){let i=this.icn3d;i.icn3dui;for(let s=0;s<e.length;++s){let n=e[s];if(this.setHAtomsFromSets_base(n,t),0==Object.keys(i.hAtoms).length&&("sphere"==n.split(".")[0]||"interactions"==n.split(".")[0])){let e=n.lastIndexOf("-");n=n.split(".")[0]+n.substr(e),this.setHAtomsFromSets_base(n,t)}}}setHAtomsFromSets_base(e,t){let i=this.icn3d,s=i.icn3dui;if(void 0!==i.defNames2Atoms&&i.defNames2Atoms.hasOwnProperty(e)){let n=i.defNames2Atoms[e];if("or"===t)for(let e=0,t=n.length;e<t;++e)i.hAtoms[n[e]]=1;else if("and"===t){let e={};for(let t=0,i=n.length;t<i;++t)e[n[t]]=1;i.hAtoms=s.hashUtilsCls.intHash(i.hAtoms,e)}else if("not"===t){let e={};for(let t=0,i=n.length;t<i;++t)e[n[t]]=1;i.hAtoms=s.hashUtilsCls.exclHash(i.hAtoms,e)}}if(void 0!==i.defNames2Residues&&i.defNames2Residues.hasOwnProperty(e)){let n=i.defNames2Residues[e],r={};for(let e=0,t=n.length;e<t;++e)r=s.hashUtilsCls.unionHash(r,i.residues[n[e]]);"or"===t?i.hAtoms=s.hashUtilsCls.unionHash(i.hAtoms,r):"and"===t?i.hAtoms=s.hashUtilsCls.intHash(i.hAtoms,r):"not"===t&&(i.hAtoms=s.hashUtilsCls.exclHash(i.hAtoms,r))}}updateAdvancedCommands(e,t){let i=this.icn3d;i.icn3dui;let s=" "+t+" ";for(let n=0,r=e.length;n<r;++n)if(0===n&&"or"==t)$("#"+i.pre+"command").val("saved atoms "+e[n]),$("#"+i.pre+"command_name").val(e[n]);else{let t=$("#"+i.pre+"command").val();$("#"+i.pre+"command").val(t+s+e[n]),t=$("#"+i.pre+"command_name").val(),$("#"+i.pre+"command_name").val(t+s+e[n])}}combineSets(e,t,i,s){let n=this.icn3d,r=n.icn3dui;if(n.hAtoms={},this.setHAtomsFromSets(e,"or"),0==Object.keys(n.hAtoms).length&&(n.hAtoms=r.hashUtilsCls.cloneHash(n.dAtoms)),this.setHAtomsFromSets(t,"and"),this.setHAtomsFromSets(i,"not"),n.bInitial||n.hlUpdateCls.updateHlAll(),n.annotationCls.showAnnoSelectedChains(),$("#"+n.pre+"command").val(""),$("#"+n.pre+"command_name").val(""),this.updateAdvancedCommands(e,"or"),this.updateAdvancedCommands(t,"and"),this.updateAdvancedCommands(i,"not"),void 0!==s){let e="select "+$("#"+n.pre+"command").val();$("#"+n.pre+"command_name").val(s),n.selectionCls.addCustomSelection(Object.keys(n.hAtoms),s,s,e,!1)}}async commandSelect(e){let t=this.icn3d,i=t.icn3dui,s=$("#"+t.pre+"command"+e).val(),n=$("#"+t.pre+"command_name"+e).val().replace(/;/g,"_").replace(/\s+/g,"_");s&&(await t.selByCommCls.selectByCommand(s,n,n),i.htmlCls.clickMenuCls.setLogCmd("select "+s+" | name "+n,!0))}clickCommand_apply(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+e.pre+"command_apply","click",(async function(e){i.icn3d,e.preventDefault(),await i.commandSelect("")})),t.myEventCls.onIds("#"+e.pre+"command_apply2","click",(async function(e){i.icn3d,e.preventDefault(),await i.commandSelect("2")}))}selectCombinedSets(e,t){this.icn3d.icn3dui;let i=e.split(" "),s=[],n=[],r=[],a="or";for(let e=0,t=i.length;e<t;++e){let t=i[e].split("_");if(3!=t.length||isNaN(t[2])||(i[e]=t[0]+"_"+t[1]+t[2]),"or"!==i[e]&&"and"!==i[e]&&"not"!==i[e]){let t=["hbonds_","saltbridge_","halogen_","pi-cation_","pi-stacking_"];for(let s=0,n=t.length;s<n;++s){const n=new RegExp("^"+t[s]+"\\d+$");i[e].match(n)&&(i[e]=t[s]+"auto")}"or"===a?s.push(i[e]):"and"===a?n.push(i[e]):"not"===a&&r.push(i[e])}else a=i[e]}null!==i&&this.combineSets(s,n,r,t)}clickModeswitch(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+e.pre+"modeswitch","click",(function(t){void 0!==$("#"+e.pre+"modeswitch")[0]&&$("#"+e.pre+"modeswitch")[0].checked?i.setModeAndDisplay("selection"):i.setModeAndDisplay("all")}))}setModeAndDisplay(e){let t=this.icn3d,i=t.icn3dui;"all"===e?(this.setMode("all"),t.prevHighlightAtoms=i.hashUtilsCls.cloneHash(t.hAtoms),i.htmlCls.clickMenuCls.setLogCmd("set mode all",!0),t.selectionCls.selectAll(),t.drawCls.draw()):(this.setMode("selection"),void 0!==t.prevHighlightAtoms?t.hAtoms=i.hashUtilsCls.cloneHash(t.prevHighlightAtoms):t.selectionCls.selectAll(),i.htmlCls.clickMenuCls.setLogCmd("set mode selection",!0),t.hlUpdateCls.updateHlAll())}setMode(e){let t=this.icn3d;t.icn3dui,"all"===e?($("#"+t.pre+"modeall").show(),$("#"+t.pre+"modeselection").hide(),void 0!==$("#"+t.pre+"modeswitch")[0]&&($("#"+t.pre+"modeswitch")[0].checked=!1),$("#"+t.pre+"style").hasClass("icn3d-modeselection")&&$("#"+t.pre+"style").removeClass("icn3d-modeselection"),$("#"+t.pre+"color").hasClass("icn3d-modeselection")&&$("#"+t.pre+"color").removeClass("icn3d-modeselection")):($("#"+t.pre+"modeall").hide(),$("#"+t.pre+"modeselection").show(),void 0!==$("#"+t.pre+"modeswitch")[0]&&($("#"+t.pre+"modeswitch")[0].checked=!0),$("#"+t.pre+"style").hasClass("icn3d-modeselection")||$("#"+t.pre+"style").addClass("icn3d-modeselection"),$("#"+t.pre+"color").hasClass("icn3d-modeselection")||$("#"+t.pre+"color").addClass("icn3d-modeselection"))}getAtomsFromOneSet(e){let t=this.icn3d,i=t.icn3dui,s={};if(void 0===t.defNames2Residues.proteins&&this.showSets(),-1!==Object.keys(t.chains).indexOf(e))s=i.hashUtilsCls.unionHash(s,t.chains[e]);else{if(void 0!==t.defNames2Residues[e]&&t.defNames2Residues[e].length>0)for(let n=0,r=t.defNames2Residues[e].length;n<r;++n){let r=t.defNames2Residues[e][n];s=i.hashUtilsCls.unionHash(s,t.residues[r])}if(void 0!==t.defNames2Atoms[e]&&t.defNames2Atoms[e].length>0)for(let i=0,n=t.defNames2Atoms[e].length;i<n;++i){s[t.defNames2Atoms[e][i]]=1}}return s}getAtomsFromNameArray(e){let t=this.icn3d,i=t.icn3dui,s={};for(let n=0,r=e.length;n<r;++n)if("non-selected"===e[n]){let e={};for(let i in t.atoms)!t.hAtoms.hasOwnProperty(i)&&t.dAtoms.hasOwnProperty(i)&&(e[i]=t.atoms[i]);s=i.hashUtilsCls.unionHash(s,e)}else s="selected"===e[n]?i.hashUtilsCls.unionHash(s,i.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)):i.hashUtilsCls.unionHash(s,i.hashUtilsCls.hash2Atoms(this.getAtomsFromOneSet(e[n]),t.atoms));return 0==e.length&&(s=t.atoms),s}}class Kh{constructor(e){this.icn3d=e}setAtomMenu(e){let t=this.icn3d;t.icn3dui;let i="";return Object.entries(e).forEach((([e,s],n)=>{let r,[a,o,l,d,c]=s;if(void 0!==t.defNames2Atoms&&t.defNames2Atoms.hasOwnProperty(e)){let i=t.defNames2Atoms[e];i.length>0&&t.atoms[i[0]]}else if(void 0!==t.defNames2Residues&&t.defNames2Residues.hasOwnProperty(e)){let i=t.defNames2Residues[e];i.length>0&&(r=t.residues[i[0]],r&&t.atoms[Object.keys(r)[0]])}i+=0===n?"<option value='"+e+"' selected='selected' data-description='"+l+"'>"+o+"</option>":"<option value='"+e+"' data-description='"+l+"'>"+o+"</option>"})),i}reset(){let e=this.icn3d;e.atoms={},e.proteins={},e.nucleotides={},e.chemicals={},e.ions={},e.water={},e.structures={},e.chains={},e.chainsSeq={},e.residues={},e.defNames2Atoms={},e.defNames2Residues={},e.ssbondpnts={},e.bShowHighlight=void 0,e.bResetSets=!0}dictionaryDifference(e,t){const i={};for(let s in t)s in e||(i[s]=t[s]);return i}clickStructure(e){let t=this.icn3d,i=t.icn3dui,s=this;$("#"+t.pre+"collections_menu").on("change",(async function(t){let n=s.icn3d,r=$(this).val(),a=$(this).find("option:selected").text(),o=Array.from(this.selectedOptions).map((e=>e.index));if(r.reduce(((e,t,i)=>(e[t]=o[i],e)),{}),n.nameArray=r,null!==r){let l=!0;s.reset();for(const d of r)if(!(d in n.allData)){async function c(e){if(await n.resetConfig(),e){let e=!0;0==Object.keys(n.structures).length&&(e=!1),await n.pdbParserCls.loadPdbData(n.pdbCollection[d].join("\n"),void 0,void 0,e)}else await n.chainalignParserCls.downloadMmdbAf(d,void 0,void 0,l)}n.allData.prev=JSON.parse(JSON.stringify(n.allData.all)),n.atoms=n.allData.all.atoms,n.proteins=n.allData.all.proteins,n.nucleotides=n.allData.all.nucleotides,n.chemicals=n.allData.all.chemicals,n.ions=n.allData.all.ions,n.water=n.allData.all.water,n.structures=n.allData.all.structures,n.ssbondpnts=n.allData.all.ssbondpnts,n.residues=n.allData.all.residues,n.chains=n.allData.all.chains,n.chainsSeq=n.allData.all.chainsSeq,n.defalls2Atoms=n.allData.all.defalls2Atoms,n.defalls2Residues=n.allData.all.defalls2Residues,await c(e[d][4]).then((()=>{n.allData.all={atoms:n.atoms,proteins:n.proteins,nucleotides:n.nucleotides,chemicals:n.chemicals,ions:n.ions,water:n.water,structures:n.structures,ssbondpnts:n.ssbondpnts,residues:n.residues,chains:n.chains,chainsSeq:n.chainsSeq,defNames2Atoms:n.defNames2Atoms,defNames2Residues:n.defNames2Residues},n.allData[d]={title:n.molTitle,atoms:s.dictionaryDifference(n.allData.prev.atoms,n.atoms),proteins:s.dictionaryDifference(n.allData.prev.proteins,n.proteins),nucleotides:s.dictionaryDifference(n.allData.prev.nucleotides,n.nucleotides),chemicals:s.dictionaryDifference(n.allData.prev.chemicals,n.chemicals),ions:s.dictionaryDifference(n.allData.prev.ions,n.ions),water:s.dictionaryDifference(n.allData.prev.water,n.water),structures:s.dictionaryDifference(n.allData.prev.structures,n.structures),ssbondpnts:s.dictionaryDifference(n.allData.prev.ssbondpnts,n.ssbondpnts),residues:s.dictionaryDifference(n.allData.prev.residues,n.residues),chains:s.dictionaryDifference(n.allData.prev.chains,n.chains),chainsSeq:s.dictionaryDifference(n.allData.prev.chainsSeq,n.chainsSeq),defNames2Atoms:s.dictionaryDifference(n.allData.prev.defNames2Atoms,n.defNames2Atoms),defNames2Residues:s.dictionaryDifference(n.allData.prev.defNames2Residues,n.defNames2Residues)},s.reset()}))}for(const h of r){if(n.atoms=Object.assign(n.atoms,n.allData[h].atoms),n.proteins=Object.assign(n.proteins,n.allData[h].proteins),n.nucleotides=Object.assign(n.nucleotides,n.allData[h].nucleotides),n.chemicals=Object.assign(n.chemicals,n.allData[h].chemicals),n.ions=Object.assign(n.ions,n.allData[h].ions),n.water=Object.assign(n.water,n.allData[h].water),n.structures=Object.assign(n.structures,n.allData[h].structures),n.ssbondpnts=Object.assign(n.ssbondpnts,n.allData[h].ssbondpnts),n.residues=Object.assign(n.residues,n.allData[h].residues),n.chains=Object.assign(n.chains,n.allData[h].chains),n.chainsSeq=Object.assign(n.chainsSeq,n.allData[h].chainsSeq),n.defNames2Atoms=Object.assign(n.defNames2Atoms,n.allData[h].defNames2Atoms),n.defNames2Residues=Object.assign(n.defNames2Residues,n.allData[h].defNames2Residues),n.dAtoms=i.hashUtilsCls.cloneHash(n.atoms),n.hAtoms=i.hashUtilsCls.cloneHash(n.atoms),n.molTitle=n.allData[h].title,void 0!==e[h][3]&&e[h][3].length>0&&null==n.allData[h].commands){let p=e[h][3];n.allData[h].commands=p}if(void 0!==n.allData[h].commands)for(const u of n.allData[h].commands)i.htmlCls.clickMenuCls.setLogCmd(u,!0),await n.applyCommandCls.applyCommand(u)}n.opts.color=1==Object.keys(n.structures).length?"chain":"structure",n.setColorCls.setColorByOptions(n.opts,n.atoms),n.transformCls.zoominSelection(),n.definedSetsCls.showSets(),n.bResetAnno=!0,n.bAnnoShown&&(await n.showAnnoCls.showAnnotations(),n.hlUpdateCls.updateHlAll(r),n.annotationCls.showAnnoSelectedChains()),await n.drawCls.draw(),n.saveFileCls.showTitle(),i.htmlCls.clickMenuCls.setLogCmd("select structure ["+a+"]",!1),i.htmlCls.clickMenuCls.setLogCmd("load mmdbaf1 "+r,!0)}})),i.myEventCls.onIds("#"+t.pre+"collections_menu","focus",(function(e){let t=s.icn3d;i.utilsCls.isMobile()&&$("#"+t.pre+"collections_menu").val("")}))}}class Zh{constructor(e){this.icn3d=e}async loadScript(e,t,i){let s=this.icn3d;if(s.icn3dui,!e)return;s.bCommandLoad=!0,s.bRender=!1,s.bStopRotate=!0,e=t?e.replace(/\+/g," "):e.replace(/\+/g," ").replace(/;/g,"\n");let n=[];!i&&s.commands.length>0&&(n[0]=s.commands[0]);let r=e.trim().split("\n");s.commands=r;let a=r[0].indexOf("command=");if(t&&-1!=a){let e=r[0].substr(0,a-1);s.commands.splice(0,1,e)}s.STATENUMBER=s.commands.length,s.commands=n.concat(s.commands),s.STATENUMBER=s.commands.length,s.CURRENTNUMBER=0,s.bReplay?await this.replayFirstStep(s.CURRENTNUMBER):await this.execCommands(s.CURRENTNUMBER,s.STATENUMBER-1,s.STATENUMBER,i)}async execCommands(e,t,i,s){let n=this.icn3d;n.icn3dui,n.bRender=!1,s||n.reinitAfterLoad(),await this.execCommandsBase(e,t,i)}getNameArray(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | "),s=[];return 2==i.length&&(s=i[1].split(","),t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(s)),s}updateTransformation(e){let t=this.icn3d;t.icn3dui;let i=t.commands[e-1]?t.commands[e-1].split("|||"):[];t.transformCls.resetOrientation_base(i),t.drawCls.draw()}async execCommandsBase(e,t,i,s){let n,r=this.icn3d,a=r.icn3dui,o=this;for(n=e;n<=t;++n){let s=n===i-1;if(!r.commands[n]||!r.commands[n].trim())continue;if(0==(r.atoms?Object.keys(r.atoms).length:0)&&-1==r.commands[n].indexOf("load"))continue;let l=r.commands[n].split("|||"),d=l[0].trim();if(-1!==d.indexOf("load")){if(0===t&&e===t)return void(r.bNotLoadStructure?(r.hAtoms=a.hashUtilsCls.cloneHash(r.atoms),1===r.commands.length&&(r.bAddCommands=!0),s&&this.renderFinalStep(i)):(await o.applyCommandLoad(r.commands[n]),1===r.commands.length&&(r.bAddCommands=!0),s&&o.renderFinalStep(i)));r.bNotLoadStructure?(r.hAtoms=a.hashUtilsCls.cloneHash(r.atoms),r.backForward&&this.renderFinalStep(1)):(await o.applyCommandLoad(r.commands[n]),r.backForward&&o.renderFinalStep(1))}else if(0==d.indexOf("set map")&&-1==d.indexOf("set map wireframe"))await o.applyCommandMap(l[0].trim());else if(0==d.indexOf("set emmap")&&-1==d.indexOf("set emmap wireframe")){let e=l[0].trim().substr(10).split(" ");2==e.length&&"percentage"==e[0]&&(e[1],await o.applyCommandEmmap(l[0].trim()))}else if(0==d.indexOf("set phi"))await r.delphiCls.applyCommandPhi(l[0].trim());else if(0==d.indexOf("set delphi"))await r.delphiCls.applyCommandDelphi(l[0].trim());else if(0==d.indexOf("view annotations"))Object.keys(r.proteins).length>0&&await o.applyCommandAnnotationsAndCddSite(l[0].trim());else if(0==d.indexOf("set annotation clinvar"))Object.keys(r.proteins).length>0&&await o.applyCommandClinvar(l[0].trim());else if(0==d.indexOf("set annotation snp"))Object.keys(r.proteins).length>0&&await o.applyCommandSnp(l[0].trim());else if(0==d.indexOf("set annotation ptm"))Object.keys(r.proteins).length>0&&await o.applyCommandPTM(l[0].trim());else if(0==d.indexOf("ig template")){let e=d.substr(d.lastIndexOf(" ")+1);await a.htmlCls.clickMenuCls.setIgTemplate(e)}else if(0==d.indexOf("set annotation 3ddomain"))Object.keys(r.proteins).length>0&&o.applyCommand3ddomain(l[0].trim());else if(0==d.indexOf("set annotation all"))Object.keys(r.proteins).length>0&&(await o.applyCommandClinvar(l[0].trim()),await o.applyCommandSnp(l[0].trim()),o.applyCommand3ddomain(l[0].trim())),await r.annotationCls.setAnnoTabAll();else if(0==d.indexOf("view interactions")&&void 0!==a.cfg.align)await o.applyCommandViewinteraction(l[0].trim());else if(0==d.indexOf("view 2d depiction"))await r.ligplotCls.drawLigplot(r.atoms,!0);else if(0==d.indexOf("symmetry")){r.bAxisOnly=!1;let e=d.substr(d.indexOf(" ")+1);r.symmetrytitle="none"===e?void 0:e,"none"!==e&&await r.symdCls.retrieveSymmetry(Object.keys(r.structures)[0]),r.drawCls.draw()}else if(0==d.indexOf("symd symmetry"))r.bAxisOnly=!1,await r.symdCls.applyCommandSymd(d),r.drawCls.draw();else if(0==d.indexOf("scap"))await r.scapCls.applyCommandScap(d);else if(0==d.indexOf("realign on seq align"))this.getNameArray(d),await o.applyCommandRealign(d);else if(0==d.indexOf("realign on structure align msa")){let e=this.getNameArray(d);a.cfg.aligntool="vast",await r.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on structure align"))this.getNameArray(d),a.cfg.aligntool="vast",await r.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on tmalign msa")){let e=this.getNameArray(d);a.cfg.aligntool="tmalign",await r.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on tmalign"))this.getNameArray(d),a.cfg.aligntool="tmalign",await r.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on vastplus"))o.getHAtoms(r.commands[n]),await r.vastplusCls.realignOnVastplus();else if(0==d.indexOf("graph interaction pairs"))await o.applyCommandGraphinteraction(d);else if(0==d.indexOf("cartoon 2d domain"))r.bRender=!0,o.updateTransformation(i),await o.applyCommandCartoon2d(d),r.bRender=!1;else if(0==d.indexOf("set half pae map"))await o.applyCommandAfmap(d);else if(0==d.indexOf("set full pae map"))await o.applyCommandAfmap(d,!0);else if(0==d.indexOf("export pqr"))await a.htmlCls.setHtmlCls.exportPqr();else if(0==d.indexOf("cartoon 2d chain")||0==d.indexOf("cartoon 2d secondary")){let e=d.lastIndexOf(" "),t=d.substr(e+1);r.bRender=!0,o.updateTransformation(i),await r.cartoon2dCls.draw2Dcartoon(t),r.bRender=!1}else if(0==d.indexOf("add msa track")){let e=d.split(" | "),t=e[1].substr(8),i=e[2].substr(9),s=e[3].substr(5),n=e[4].substr(10);$("#"+r.pre+"anno_custom")[0]&&($("#"+r.pre+"anno_custom")[0].checked=!0),$("[id^="+r.pre+"custom]").show(),await r.addTrackCls.addMsaTracks(t,i,s,n)}else if(0==d.indexOf("add exon track")){let e=d.split(" | "),t=e[1].substr(8),i=e[2].substr(7),s=parseInt(e[3].substr(9)),n=e[4].substr(5);$("#"+r.pre+"anno_custom")[0]&&($("#"+r.pre+"anno_custom")[0].checked=!0),$("[id^="+r.pre+"custom]").show(),await r.addTrackCls.addExonTracks(t,i,s,n)}else await r.applyCommandCls.applyCommand(r.commands[n])}(n===i||s)&&this.renderFinalStep(n)}pressCommandtext(){let e=this.icn3d,t=e.icn3dui,i=this;$("#"+e.pre+"logtext").keypress((async function(e){let s=i.icn3d;if(s.bAddLogs=!1,13==(e.keyCode?e.keyCode:e.which)){e.preventDefault();let n=$(this).val();s.bRender=!0;let r=n.split("\n"),a=s.logs.length;for(let e=a,n=r.length;e<n;++e){let n=e==a?r[e].substr(2).trim():r[e].trim();if(""===n)continue;s.logs.push(n);let o={};if(o.factor=s._zoomFactor,o.mouseChange=s.mouseChange,o.quaternion=s.quaternion,s.commands.push(n+"|||"+s.transformCls.getTransformationStr(o)),s.optsHistory.push(t.hashUtilsCls.cloneHash(s.opts)),s.optsHistory[s.optsHistory.length-1].hlatomcount=Object.keys(s.hAtoms).length,t.utilsCls.isSessionStorageSupported()&&s.setStyleCls.saveCommandsToSession(),s.STATENUMBER=s.commands.length,-1!==n.indexOf("load"))await i.applyCommandLoad(n);else if(-1!==n.indexOf("set map")&&-1===n.indexOf("set map wireframe"))await i.applyCommandMap(n);else if(-1!==n.indexOf("set emmap")&&-1===n.indexOf("set emmap wireframe"))await i.applyCommandEmmap(n);else if(-1!==n.indexOf("set phi"))await s.delphiCls.applyCommandPhi(n);else if(-1!==n.indexOf("set delphi"))await s.delphiCls.applyCommandDelphi(n);else if(0==n.indexOf("view annotations"))await i.applyCommandAnnotationsAndCddSite(n);else if(0==n.indexOf("set annotation clinvar"))await i.applyCommandClinvar(n);else if(0==n.indexOf("set annotation snp"))await i.applyCommandSnp(n);else if(0==n.indexOf("set annotation ptm"))await i.applyCommandPTM(n);else if(0==n.indexOf("ig refnum on"))s.bRunRefnumAgain=!0,s.bAnnoShown||await s.showAnnoCls.showAnnotations(),await s.annotationCls.setAnnoTabIg(!0),s.bRunRefnumAgain=!1;else if(0==n.indexOf("set annotation 3ddomain"))i.applyCommand3ddomain(n);else if(0==n.indexOf("set annotation all"))await i.applyCommandClinvar(n),await i.applyCommandSnp(n),i.applyCommand3ddomain(n),await s.annotationCls.setAnnoTabAll();else if(0==n.indexOf("view interactions")&&void 0!==t.cfg.align)await i.applyCommandViewinteraction(n);else if(0==n.indexOf("view 2d depiction"))await s.ligplotCls.drawLigplot(s.atoms,!0);else if(0==n.indexOf("symmetry")){let e=n.substr(n.indexOf(" ")+1);s.symmetrytitle="none"===e?void 0:e,"none"!==e&&void 0===s.symmetryHash&&await s.symdCls.retrieveSymmetry(Object.keys(s.structures)[0])}else if(0==n.indexOf("symd symmetry"))await s.symdCls.applyCommandSymd(n);else if(0==n.indexOf("scap "))await s.scapCls.applyCommandScap(n);else if(0==n.indexOf("realign on seq align")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}await i.applyCommandRealign(n)}else if(0==n.indexOf("realign on structure align")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="vast",await i.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on tmalign")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="tmalign",await i.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on vastplus")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(t)}await s.vastplusCls.realignOnVastplus()}else 0==n.indexOf("graph interaction pairs")?await i.applyCommandGraphinteraction(n):await s.applyCommandCls.applyCommand(n+"|||"+s.transformCls.getTransformationStr(o))}s.selectionCls.saveSelectionIfSelected(),s.drawCls.draw(),$("#"+s.pre+"logtext").val("> "+s.logs.join("\n> ")+"\n> ").scrollTop($("#"+s.pre+"logtext")[0].scrollHeight)}s.bAddLogs=!0}))}async applyCommandLoad(e){let t=this.icn3d,i=t.icn3dui;t.bAddCommands=!1;let s=e.split("|||")[0].replace(/\s\s/g," ").trim();if(-1!==s.indexOf("load")){let e=s.split(" | "),n=e[0];if(e.length>1&&!i.cfg.inpara){let t=e[e.length-1].indexOf(" ");i.cfg.inpara=e[e.length-1].substr(t+1),"undefined"===i.cfg.inpara&&(i.cfg.inpara="")}let r=n.substr(n.lastIndexOf(" ")+1);4==r.length&&(r=r.toUpperCase());let a=r.split(","),o="";for(let e=0,i=a.length;e<i;++e)t.structures&&(t.structures.hasOwnProperty(a[e])||t.structures.hasOwnProperty(a[e].toLowerCase())||t.structures.hasOwnProperty(a[e].toUpperCase()))||(o&&(o+=","),o+=a[e]);if(r=o,t.bInputPNGWithData||!r)return;if(t.inputid=r,-1!==s.indexOf("load mmtf"))i.cfg.mmtfid=r,await t.bcifParserCls.downloadBcif(r);else if(-1!==s.indexOf("load bcif"))i.cfg.bcifid=r,await t.bcifParserCls.downloadBcif(r);else if(-1!==s.indexOf("load pdb"))i.cfg.pdbid=r,await t.pdbParserCls.downloadPdb(r);else if(-1!==s.indexOf("load af"))i.cfg.afid=r,await t.pdbParserCls.downloadPdb(r,!0);else if(-1!==s.indexOf("load opm"))i.cfg.opmid=r,await t.opmParserCls.downloadOpm(r);else if(-1!==s.indexOf("load mmcif"))i.cfg.mmcifid=r,await t.mmcifParserCls.downloadMmcif(r);else if(-1!==s.indexOf("load mmdb ")||-1!==s.indexOf("load mmdb1 "))i.cfg.mmdbid=r,i.cfg.bu=1,await t.mmdbParserCls.downloadMmdb(r);else if(-1!==s.indexOf("load mmdb0"))i.cfg.mmdbid=r,i.cfg.bu=0,await t.mmdbParserCls.downloadMmdb(r);else if(-1!==s.indexOf("load mmdbaf1"))i.cfg.mmdbafid=r,i.cfg.bu=1,await t.chainalignParserCls.downloadMmdbAf(r);else if(-1!==s.indexOf("load mmdbaf0"))i.cfg.mmdbafid=r,i.cfg.bu=0,await t.chainalignParserCls.downloadMmdbAf(r);else if(-1!==s.indexOf("load gi"))i.cfg.gi=r,await t.mmdbParserCls.downloadGi(r);else if(-1!==s.indexOf("load refseq"))i.cfg.refseqid=r,await t.mmdbParserCls.downloadRefseq(r);else if(-1!==s.indexOf("load protein"))i.cfg.protein=r,await t.mmdbParserCls.downloadProteinname(r);else if(-1!==s.indexOf("load seq_struct_ids "))t.bSmithwm=!1,t.bLocalSmithwm=!1,await t.mmdbParserCls.downloadBlast_rep_id(r);else if(-1!==s.indexOf("load seq_struct_ids_smithwm "))t.bSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(r);else if(-1!==s.indexOf("load seq_struct_ids_local_smithwm "))t.bLocalSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(r);else if(-1!==s.indexOf("load cid"))i.cfg.cid=r,await t.sdfParserCls.downloadCid(r);else if(-1!==s.indexOf("load smiles"))i.cfg.smiles=r,await t.sdfParserCls.downloadSmiles(r);else if(-1!==s.indexOf("load alignment"))if(i.cfg.align=r,i.cfg.inpara||-1==i.cfg.inpara.indexOf("atype=2"))await t.alignParserCls.downloadAlignment(i.cfg.align);else{let e=2;await t.chainalignParserCls.downloadMmdbAf(i.cfg.align,void 0,e)}else if(-1!==s.indexOf("load chainalignment")){let e=s.split(" | ");e.length>1&&-1!=e[1].indexOf("resnum")&&(i.cfg.resnum=e[1].substr(e[1].indexOf("resnum")+7)),e.length>2&&-1!=e[2].indexOf("resdef")&&(i.cfg.resdef=e[2].substr(e[2].indexOf("resdef")+7)),e.length>3&&-1!=e[3].indexOf("aligntool")&&(i.cfg.aligntool=e[3].substr(e[3].indexOf("aligntool")+10)),e.length>5&&-1!=e[5].indexOf("resrange")&&(i.cfg.resrange=e[5].substr(e[5].indexOf("resrange")+9)),i.cfg.chainalign=r,await t.chainalignParserCls.downloadChainalignment(r)}else if(-1!==s.indexOf("load url")){let s=e[1],n=void 0!==s?s.indexOf("type "):-1,a="pdb";-1!==n&&(a=s.substr(n+5)),i.cfg.url=r,await t.pdbParserCls.downloadUrl(r,a)}}t.bAddCommands=!0}async applyCommandMap(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | "),s=i[0].substr(8).split(" ");if("sigma"==s[1]){let e=s[2],n=s[0],r="dsn6";if(5==s.length&&(r=s[4]),2==i.length){let s=!0;"dsn6"==r?await t.densityCifParserCls.densityCifParserBase(i[1],n,e,"url",s):"ccp4"==r?await t.ccp4ParserCls.ccp4ParserBase(i[1],n,e,"url",s):"mtz"==r?await t.mtzParserCls.mtzParserBase(i[1],n,e,"url",s):"rcsbmtz"==r&&await t.mtzParserCls.mtzParserBase(i[1],n,e,"url",s,!0)}else await t.densityCifParserCls.densityCifParser(t.inputid,n,e)}}async applyCommandEmmap(e){let t=this.icn3d;t.icn3dui;let i=e.substr(10).split(" ");if(2==i.length&&"percentage"==i[0]){let e=i[1],s="em";await t.densityCifParserCls.densityCifParser(t.inputid,s,e,t.emd)}}async applyCommandRealign(e){let t=this.icn3d;t.icn3dui,await t.realignParserCls.realignOnSeqAlign()}async applyCommandRealignByStruct(e){let t=this.icn3d;t.icn3dui,t.drawCls.draw(),await t.realignParserCls.realignOnStructAlign()}async applyCommandAfmap(e,t){let i=this.icn3d;i.icn3dui;let s=e.substr(e.lastIndexOf(" ")+1);await i.contactMapCls.afErrorMap(s,t)}async applyCommandGraphinteraction(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | ");if(i.length>=3){let e,s=i[1].split(" "),n=s[0].split(","),r=s[1].split(","),a=-1!==i[2].indexOf("hbonds"),o=-1!==i[2].indexOf("salt bridge"),l=-1!==i[2].indexOf("interactions"),d=-1!==i[2].indexOf("halogen"),c=-1!==i[2].indexOf("pi-cation"),h=-1!==i[2].indexOf("pi-stacking");i.length>=4&&(e="true"==i[3]),t.applyCommandCls.setStrengthPara(i),await t.viewInterPairsCls.viewInteractionPairs(n,r,e,"graph",a,o,l,d,c,h)}}async applyCommandCartoon2d(e){let t=this.icn3d;t.icn3dui;let i=e.substr(e.lastIndexOf(" ")+1);await t.cartoon2dCls.draw2Dcartoon(i)}async applyCommandAnnotationsAndCddSite(e){let t=this.icn3d;t.icn3dui,"view annotations"==e&&await t.showAnnoCls.showAnnotations()}async applyCommandClinvar(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" ");e.substr(i+1),await t.annotationCls.setAnnoTabClinvar()}async applyCommandSnp(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" ");e.substr(i+1),await t.annotationCls.setAnnoTabSnp()}async applyCommandPTM(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" ");e.substr(i+1),await t.annotationCls.setAnnoTabPTM()}applyCommand3ddomain(e){let t=this.icn3d;t.icn3dui;let i=e.lastIndexOf(" "),s=e.substr(i+1);"3ddomain"!=s&&"all"!=s||t.annotationCls.setAnnoTab3ddomain()}async applyCommandViewinteraction(e){let t=this.icn3d,i=t.icn3dui;if(void 0!==i.cfg.align||void 0!==i.cfg.chainalign){let e=Object.keys(t.structures);await t.ParserUtilsCls.set2DDiagramsForAlign(e[0].toUpperCase(),e[1].toUpperCase())}}async renderFinalStep(e){let t=this.icn3d,i=t.icn3dui;t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),e+1===t.commands.length&&(t.bAddCommands=!0),t.bRender=!0;let s=t.commands[e-1]?t.commands[e-1].split("|||"):[];if(2!=s.length||2==s.length&&"{"==s[1].substr(0,1)?t.bSetCamera=!0:t.bSetCamera=!1,2==s.length&&"{"==s[1].substr(0,1)&&(t.bTransformation=!0),t.transformCls.resetOrientation_base(s),t.selectionCls.oneStructurePerWindow(),1===e||t.hAtoms&&t.atoms&&Object.keys(t.hAtoms).length===Object.keys(t.atoms).length||void 0!==t.optsHistory[e-1]&&t.optsHistory[e-1].hasOwnProperty("hlatomcount")&&t.optsHistory[e-1].hlatomcount===Object.keys(t.atoms).length)if(t.optsHistory.length>=e){let i=t.optsHistory[e-1].pk;"no"===i?t.pk=0:"atom"===i?t.pk=1:"residue"===i?t.pk=2:"strand"===i&&(t.pk=3),t.hlUpdateCls.updateHlAll(),t.drawCls.draw()}else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();(i.cfg.closepopup||i.cfg.imageonly)&&(setTimeout((function(){t.resizeCanvasCls.closeDialogs()}),100),t.resizeCanvasCls.resizeCanvas(i.htmlCls.WIDTH,i.htmlCls.HEIGHT,!0)),i.cfg.showlogo||$("#ncbi_logo").hide(),t.bTransparentSurface&&t.bRender&&t.drawCls.render(),i.cfg.imageonly&&t.saveFileCls.saveFile(void 0,"png",void 0,!0)}async replayFirstStep(e){let t=this.icn3d,i=t.icn3dui;t.reinitAfterLoad(),await this.execCommandsBase(e,e,t.STATENUMBER);let s=t.commands[e],n=t.commands[e].indexOf("|");-1!=n&&(s=t.commands[e].substr(0,n));let r=s.length>20?s.substr(0,20)+"...":s,a=t.applyCommandCls.getMenuFromCmd(s);$("#"+t.pre+"replay_cmd").html("Cmd: "+r),$("#"+t.pre+"replay_menu").html("Menu: "+a),i.htmlCls.clickMenuCls.setLogCmd(s,!0),t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),t.bRender=!0,t.drawCls.draw()}getHAtoms(e){let t=this.icn3d;t.icn3dui;let i=e.split("|||")[0].trim().split(" | ");if(2==i.length){let e=i[1].split(",");t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(e)}}}class Jh{constructor(e){this.icn3d=e}async selectByCommand(e,t,i){let s=this.icn3d,n=s.icn3dui;if(0===e.indexOf("saved atoms")){let i=12,n=e.substr(i);s.definedSetsCls.selectCombinedSets(n,t)}else{let r=e.replace(/ AND /g," and ").replace(/ OR /g," or ").replace(/ or and /g," and ").replace(/ and /g," or and ").replace(/ or not /g," not ").replace(/ not /g," or not "),a=("select"===r.trim().substr(0,6)?r.trim().substr(7):r.trim()).split(" or "),o={};for(let e=0,t=a.length;e<t;++e){let t=a[e].trim().replace(/\s+/g," "),i=t.indexOf(" ");s.hAtoms={},"and"===t.substr(0,i).toLowerCase()?(await s.applyCommandCls.applyCommand("select "+t.substr(i+1)),o=n.hashUtilsCls.intHash(o,s.hAtoms)):"not"===t.substr(0,i).toLowerCase()?(await s.applyCommandCls.applyCommand("select "+t.substr(i+1)),o=n.hashUtilsCls.exclHash(o,s.hAtoms)):(await s.applyCommandCls.applyCommand("select "+t),o=n.hashUtilsCls.unionHash(o,s.hAtoms))}s.hAtoms=n.hashUtilsCls.cloneHash(o);let l=Object.keys(s.hAtoms);if(""!==t){s.selectionCls.addCustomSelection(l,t,i,e,!1);let n=[t];s.definedSetsCls.changeCustomAtoms(n)}}}selectBySpec(e,t,i,s,n){let r=this.icn3d,a=r.icn3dui;e="select"===e.trim().substr(0,6)?e.trim().substr(7):e.trim(),r.hAtoms={};let o,l=e.replace(/\s+/g," ").replace(/ AND /g," and ").split(" and "),d={},c={},h=!0;for(let e=0,t=l.length;e<t;++e){let t,i,s,n,o,p=l[e].indexOf("$"),u=l[e].indexOf("."),m=l[e].indexOf(":"),f=l[e].indexOf(":ref_"),g=l[e].indexOf("@"),b=l[e];if(-1===g?o=["*"]:(o=b.substr(g+1).split(","),b=b.substr(0,g)),-1===m&&-1===f)s="*";else if(-1!=f){if(n=b.substr(f+5),b=b.substr(0,f),!n)continue}else if(-1!=m&&(s=b.substr(m+1),b=b.substr(0,m),!s))continue;-1===u?i="*":(i=b.substr(u+1),i=i.replace(/_/g,""),b=b.substr(0,u)),-1===p?t="*":(t=b.substr(p+1),b=b.substr(0,p)),(o.length>1||1==o.length&&"*"!==o[0])&&(h=!1);let C,v,_,y,S=[],w=[];if(S="*"===t?Object.keys(r.structures):t.split(","),"*"===i){let e=Object.keys(r.chains);for(let t=0,i=e.length;t<i;++t){v=e[t],C=v.substr(0,v.indexOf("_")),-1!==S.map((function(e){return e.toLowerCase()})).indexOf(C.toLowerCase())&&w.push(v)}}else for(let e=0,t=S.length;e<t;++e){C=S[e];let t=i.split(",");for(let e in t)w.push(C+"_"+t[e])}let x=!!n,A=x?n.split(","):s.split(",");for(let t=0,i=A.length;t<i;++t){let i,s,n=!1,l=A[t].lastIndexOf("-"),h=!1,p=!1,u=!1;if(-1!==l)_=A[t].substr(0,l),y=A[t].substr(l+1),n=!0;else if(!x&&A[t].length>1&&"3"===A[t][0]&&isNaN(A[t][1])&&"-"!==A[t][0]){s=A[t].toUpperCase().substr(1),u=!0}else if(""===A[t]||isNaN(parseInt(A[t]))){if("*"===A[t])h=!0;else if("proteins"!==A[t]&&"nucleotides"!==A[t]&&"chemicals"!==A[t]&&"ions"!==A[t]&&"water"!==A[t]&&"anchors"!==A[t]&&"strands"!==A[t]&&"loops"!==A[t]){i=A[t].toUpperCase(),p=!0}}else _=A[t],y=_,n=!0;for(let l=0,m=w.length;l<m;++l)if(v=w[l],n){_=isNaN(_)?_:parseInt(_),y=isNaN(y)?y:parseInt(y);for(let t=_;t<=y;++t){let i=[];if(x){let e=r.refnum2residArray[t.toString()]?r.refnum2residArray[t.toString()]:[];for(let t=0,s=e.length;t<s;++t){let s=e[t];s.substr(0,s.lastIndexOf("_"))==v&&i.push(s)}}else{i=[v+"_"+t]}for(let t=0,s=i.length;t<s;++t){let s=i[t];0===e?d[s]=1:d.hasOwnProperty(s)||delete d[s];for(let t in r.residues[s])for(let i=0,s=o.length;i<s;++i){let s=o[i];c=this.processAtomStr(s,c,e,t)}}}}else if(v in r.chains){let n=r.chains[v];for(let i in n){r.atoms[i].resn.substr(0,3).toUpperCase();let s,n,a,l=v+"_"+r.atoms[i].resi;if(x&&(s=r.resid2refnum[l],s&&(n=r.refnumCls.rmStrandFromRefnumlabel(s),a=parseInt(n))),h||"proteins"===A[t]&&i in r.proteins||"nucleotides"===A[t]&&i in r.nucleotides||"chemicals"===A[t]&&i in r.chemicals||"ions"===A[t]&&i in r.ions||"water"===A[t]&&i in r.water||x&&s&&"anchors"===A[t]&&a%100==50||x&&s&&"strands"===A[t]&&!r.residIgLoop.hasOwnProperty(l)||x&&s&&"loops"===A[t]&&r.residIgLoop.hasOwnProperty(l)){0===e?d[l]=1:d.hasOwnProperty(l)||delete d[l];for(let t=0,s=o.length;t<s;++t){let s=o[t];c=this.processAtomStr(s,c,e,i)}}}if(p||u){let t=p?1:3,n=p?i:s,l="",h=[];for(let e=0,t=r.chainsSeq[v].length;e<t;++e){if(p)l+=1==r.chainsSeq[v][e].name.length?r.chainsSeq[v][e].name:" ";else if(u){let t=a.utilsCls.residueAbbr2Name(r.chainsSeq[v][e].name);l+=3==t.length?t:t.padEnd(3,"_")}h.push(r.chainsSeq[v][e].resi)}l=l.toUpperCase();let m=n.replace(/x/gi,"."),f=[],g=new RegExp(m,"i"),b=l,C=b.search(g),_=C/t;for(;-1!==C;)f.push(_),b=b.substr(C+t),C=b.search(g),_+=C/t+1;for(let i=0,s=f.length;i<s;++i){let s=f[i];for(let i=0,a=n.length/t;i<a;i+=t){let n=v+"_"+h[i/t+s];0===e?d[n]=1:d.hasOwnProperty(n)||delete d[n];for(let t in r.residues[n])for(let i=0,s=o.length;i<s;++i){let s=o[i];c=this.processAtomStr(s,c,e,t)}}}}}}}if(r.hAtoms=a.hashUtilsCls.cloneHash(c),0==Object.keys(r.hAtoms).length&&console.log("No residues were selected. Please try another search."),(void 0===s||s)&&r.hlUpdateCls.updateHlAll(),o=h?Object.keys(d):Object.keys(c),""!=t){r.selectionCls.addCustomSelection(o,t,i,e,h);let s=[t];n||r.definedSetsCls.changeCustomAtoms(s)}}processAtomStr(e,t,i,s){let n=this.icn3d;n.icn3dui;let r=e.length;return"*"==e.substr(r-1,1)&&r>1?e.substr(0,r-1)===n.atoms[s].name.substr(0,r-1)&&(0===i?t[s]=1:t.hasOwnProperty(s)||delete t[s]):"*"!==e&&e!==n.atoms[s].name||(0===i?t[s]=1:t.hasOwnProperty(s)||delete t[s]),t}}class Qh{constructor(e){this.icn3d=e}selectAll(){let e=this.icn3d;e.icn3dui,this.selectAll_base(),e.hlObjectsCls.removeHlObjects(),e.hlUpdateCls.removeHl2D(),e.hlUpdateCls.removeHlMenus(),e.bSelectResidue=!1,e.bSelectAlignResidue=!1,e.hlUpdateCls.removeSeqResidueBkgd(),e.hlUpdateCls.update2DdgmContent(),$("#"+e.pre+"dl_annotations > .icn3d-annotation").show(),e.definedSetsCls.setMode("all"),e.saveFileCls.showTitle()}selectAll_base(){let e=this.icn3d,t=e.icn3dui;e.hAtoms={},e.dAtoms={};for(let i in e.structures){let s=e.structures[i];for(let i=0,n=s.length;i<n;++i)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s[i]])}e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.viewSelectionAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.ALTERNATE_STRUCTURE=-1}selectAChain(e,t,i,s){let n=this.icn3d,r=n.icn3dui;t=t.replace(/\s/g,"");let a=void 0!==i||i?"select alignChain "+e:"select chain "+e;void 0!==s&&s?(n.hAtoms=r.hashUtilsCls.unionHash(n.hAtoms,n.chains[e]),void 0===n.nameArray&&(n.nameArray=[])):(n.hAtoms={},n.nameArray=[]),n.nameArray.push(e);let o,l=i?n.alnChainsSeq[e]:n.chainsSeq[e];o=void 0===l?0:l.length;let d={};for(let t=0,i=o;t<i;++t){let i=l[t],s=e+"_"+i.resi,r=i.name;if(""!==r&&"-"!==r){d[s]=1;for(let e in n.residues[s])n.hAtoms[e]=1}}void 0!==n.defNames2Atoms&&n.defNames2Atoms.hasOwnProperty(t)||void 0!==n.defNames2Residues&&n.defNames2Residues.hasOwnProperty(t)||this.addCustomSelection(Object.keys(d),t,t,a,!0);let c=!0;i?n.hlUpdateCls.updateHlAll(void 0,void 0,s,c):n.hlUpdateCls.updateHlAll(n.nameArray,void 0,s,c)}selectResidueList(e,t,i,s,n,r){let a=this.icn3d;if(a.icn3dui,void 0!==e&&Object.keys(e).length>0){if(void 0!==s&&s?void 0===a.nameArray&&(a.nameArray=[]):(a.hAtoms={},a.nameArray=[]),r)for(let t in e)a.hAtoms[t]=1;else for(let t in e)for(let e in a.residues[t])a.hAtoms[e]=1;let o,l;t=t.replace(/\s/g,""),a.nameArray.push(t),r?(o="select "+a.resid2specCls.atoms2spec(a.hAtoms),l=!1):(o="select "+a.resid2specCls.residueids2spec(Object.keys(e)),l=!0);let d=Object.keys(e);this.addCustomSelection(d,t,i,o,l),(void 0===n||n)&&a.hlUpdateCls.updateHlAll(a.nameArray,void 0,s)}}selectMainChains(){let e=this.icn3d,t=e.icn3dui.hashUtilsCls.cloneHash(e.hAtoms);e.hAtoms=e.applyDisplayCls.selectMainChainSubset(t),e.hlUpdateCls.showHighlight()}selectSideChains(){let e=this.icn3d,t=e.icn3dui.hashUtilsCls.cloneHash(e.hAtoms);e.hAtoms=this.getSideAtoms(t),e.hlUpdateCls.showHighlight()}getSideAtoms(e){let t=this.icn3d,i=t.icn3dui,s={};for(let n in e)(t.proteins.hasOwnProperty(n)&&"N"!==t.atoms[n].name&&"H"!==t.atoms[n].name&&"C"!==t.atoms[n].name&&"O"!==t.atoms[n].name&&("CA"!==t.atoms[n].name||"C"!==t.atoms[n].elem)&&"HA"!==t.atoms[n].name||t.nucleotides.hasOwnProperty(n)&&-1===i.parasCls.nuclMainArray.indexOf(t.atoms[n].name))&&(s[n]=1);return s}selectMainSideChains(){let e=this.icn3d,t=e.icn3dui,i=e.firstAtomObjCls.getResiduesFromAtoms(e.hAtoms);e.hAtoms={};for(let s in i)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[s]),e.dAtoms=t.hashUtilsCls.unionHash(e.dAtoms,e.residues[s]);e.drawCls.draw(),e.hlUpdateCls.showHighlight()}clickShow_selected(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds(["#"+e.pre+"show_selected","#"+e.pre+"mn2_show_selected"],"click",(function(e){i.icn3d,i.showSelection(),t.htmlCls.clickMenuCls.setLogCmd("show selection",!0)}))}clickHide_selected(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+e.pre+"mn2_hide_selected","click",(function(e){i.icn3d,i.hideSelection(),t.htmlCls.clickMenuCls.setLogCmd("hide selection",!0)}))}getGraphDataForDisplayed(){let e=this.icn3d;e.icn3dui;let t=JSON.parse(e.graphStr),i=e.firstAtomObjCls.getResiduesFromAtoms(e.dAtoms),s=[],n=[],r={};for(let e=0,n=t.nodes.length;e<n;++e){let n=t.nodes[e],a=n.r.substr(4);i.hasOwnProperty(a)&&(s.push(n),r[n.id]=1)}for(let e=0,i=t.links.length;e<i;++e){let i=t.links[e];r.hasOwnProperty(i.source)&&r.hasOwnProperty(i.target)&&n.push(i)}return t.nodes=s,t.links=n,e.graphStr=JSON.stringify(t),e.graphStr}updateSelectionNameDesc(){let e=this.icn3d;e.icn3dui;let t=Object.keys(e.defNames2Residues).length+Object.keys(e.defNames2Atoms).length;$("#"+e.pre+"seq_command_name").val("seq_"+t),$("#"+e.pre+"seq_command_name2").val("seq_"+t),$("#"+e.pre+"alignseq_command_name").val("alseq_"+t)}addCustomSelection(e,t,i,s,n){let r=this.icn3d;r.icn3dui,n?r.defNames2Residues[t]=e:r.defNames2Atoms[t]=e,r.defNames2Command[t]=s,r.defNames2Descr[t]=i,r.hlUpdateCls.updateHlMenus([t])}showSelection(){let e=this.icn3d,t=e.icn3dui;0==Object.keys(e.hAtoms).length&&(e.hAtoms=t.hashUtilsCls.cloneHash(e.dAtoms)),e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.viewSelectionAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.ALTERNATE_STRUCTURE=-1;let i=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=i.maxD,e.maxD<5&&(e.maxD=5),e.opts.rotationcenter="display center",this.saveSelectionIfSelected(),e.drawCls.draw(),e.hlUpdateCls.update2DdgmContent(),e.hlUpdateCls.updateHl2D(),e.annotationCls.showAnnoSelectedChains(),void 0!==e.graphStr&&(e.graphStr=this.getGraphDataForDisplayed()),e.saveFileCls.showTitle()}hideSelection(){let e=this.icn3d,t=e.icn3dui;e.hAtoms=t.hashUtilsCls.exclHash(e.dAtoms,e.hAtoms),0==Object.keys(e.hAtoms).length&&(e.hAtoms=t.hashUtilsCls.cloneHash(e.dAtoms)),e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms);let i=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=i.maxD,e.maxD<5&&(e.maxD=5),e.opts.rotationcenter="display center",this.saveSelectionIfSelected(),e.drawCls.draw(),e.hlUpdateCls.update2DdgmContent(),e.hlUpdateCls.updateHl2D(),e.annotationCls.showAnnoSelectedChains()}saveSelection(e,t,i){let s=this.icn3d,n=s.icn3dui;if(i||(s.selectedResidues={},s.selectedResidues=s.firstAtomObjCls.getResiduesFromCalphaAtoms(s.hAtoms)),!e){t=e="seq_"+(Object.keys(s.defNames2Atoms).length+Object.keys(s.defNames2Residues).length+1)}if(Object.keys(s.selectedResidues).length>0)if(1==s.pk){let r=!0;this.selectResidueList(s.hAtoms,e,t,void 0,void 0,r),this.updateSelectionNameDesc(),i?n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.atoms2spec(s.hAtoms),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.atoms2spec(s.hAtoms)+" | name "+e,!0)}else this.selectResidueList(s.selectedResidues,e,t,void 0,void 0,void 0),this.updateSelectionNameDesc(),i?n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.residueids2spec(Object.keys(s.selectedResidues)),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+s.resid2specCls.residueids2spec(Object.keys(s.selectedResidues))+" | name "+e,!0)}saveSelInCommand(){let e=this.icn3d,t=e.icn3dui;e.selectedResidues=e.firstAtomObjCls.getResiduesFromCalphaAtoms(e.hAtoms),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(e.selectedResidues)),!0)}saveEachResiInSel(){let e=this.icn3d;e.icn3dui,e.selectionCls.saveSelectionPrep(),e.selectedResidues={},e.selectedResidues=e.firstAtomObjCls.getResiduesFromCalphaAtoms(e.hAtoms);for(let t in e.selectedResidues){let i={};i[t]=1;let s=t+"_"+e.selectedResidues[t];this.selectResidueList(i,s,s)}}removeSelection(){let e=this.icn3d;e.icn3dui,e.bAnnotations||e.hlUpdateCls.removeSeqChainBkgd(),e.bCtrl||e.bShift||(e.hlUpdateCls.removeSeqResidueBkgd(),e.hlUpdateCls.removeSeqChainBkgd()),e.selectedResidues={},e.bSelectResidue=!1,e.hAtoms={},e.hlObjectsCls.removeHlObjects(),e.hlUpdateCls.removeHl2D()}resetAll(){let e=this.icn3d,t=e.icn3dui;e.maxD=e.oriMaxD,e.center=e.oriCenter.clone(),e.opts=t.hashUtilsCls.cloneHash(e.optsOri),e.setOptionCls.setStyle("sidec","nothing"),e.reinitAfterLoad(),e.definedSetsCls.setMode("all"),e.selectionCls.selectAll(),t.htmlCls.clickMenuCls.setLogCmd("reset",!0),e.hlUpdateCls.removeSeqChainBkgd(),e.hlUpdateCls.removeSeqResidueBkgd(),e.hlUpdateCls.removeHl2D(),e.hlUpdateCls.removeHlMenus(),e.loadScriptCls.renderFinalStep(1)}async loadSelection(e){let t=this.icn3d,i=t.icn3dui,s=e.trim().split("\n");for(let e=0,n=s.length;e<n;++e){let n=s[e].replace(/\t/g," "),r=n.indexOf(" "),a=n.substr(0,r),o=n.substr(r+1),l=o.indexOf(" ");await t.selByCommCls.selectByCommand(o.substr(l+1),a,a),i.htmlCls.clickMenuCls.setLogCmd("select "+o.substr(l+1)+" | name "+a,!0)}}oneStructurePerWindow(){let e=this.icn3d,t=e.icn3dui,i=e.structures?Object.keys(e.structures):[];if(t.cfg.bSidebyside&&2==i.length){let s=i[Object.keys(window.icn3duiHash).indexOf(e.divid)],n=e.structures[s],r={};if(n){for(let i=0,s=n.length;i<s;++i)r=t.hashUtilsCls.unionHash(r,e.chains[n[i]]);e.dAtoms=t.hashUtilsCls.intHash(r,e.dAtoms),e.hAtoms=t.hashUtilsCls.cloneHash(e.dAtoms)}}}showAll(){var e=this.icn3d,t=e.icn3dui;e.dAtoms=t.hashUtilsCls.cloneHash(e.atoms),e.maxD=e.oriMaxD,e.drawCls.draw()}saveSelectionIfSelected(e,t){var i=this.icn3d;if(i.icn3dui,i.bSelectResidue||i.bSelectAlignResidue){let e=$("#"+i.pre+"seq_command_name2").val().replace(/\s+/g,"_");""===e&&(e=$("#"+i.pre+"alignseq_command_name").val().replace(/\s+/g,"_")),""!==e&&this.saveSelection(e,e),i.bSelectResidue=!1,i.bSelectAlignResidue=!1}}saveSelectionPrep(e){var t=this.icn3d,i=t.icn3dui;i.cfg.notebook?($("#"+t.pre+"dl_definedsets").show(),$("#"+t.pre+"atomsCustom").resizable()):$("#"+t.pre+"dl_definedsets").hasClass("ui-dialog-content")&&$("#"+t.pre+"dl_definedsets").dialog("isOpen")||(i.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+t.pre+"atomsCustom").resizable()),e||(t.bSelectResidue=!1,t.bSelectAlignResidue=!1)}selectOneResid(e,t){var i=this.icn3d;i.icn3dui;let s=e.split(" "),n=(e=s[1]).indexOf("$"),r=e.indexOf("."),a=e.indexOf(":"),o=e.indexOf("@");-1==o&&(o=e.length);let l=e.substr(n+1,r-n-1),d=e.substr(r+1,a-r-1),c=e.substr(a+1,o-a-1),h=l+"_"+d+"_"+c;for(let e in i.residues[h])t?delete i.hAtoms[e]:i.hAtoms[e]=1;return t?delete i.selectedResidues[h]:i.selectedResidues[h]=1,"$"+l+"."+d+":"+c}toggleSelection(){var e=this.icn3d,t=e.icn3dui;if(e.bHideSelection){for(let t in e.dAtoms)e.hAtoms.hasOwnProperty(t)&&delete e.dAtoms[t];e.bHideSelection=!1}else e.dAtoms=t.hashUtilsCls.unionHash(e.dAtoms,e.hAtoms),e.bHideSelection=!0;e.drawCls.draw()}toggleMembrane(e){var t=this.icn3d,i=t.icn3dui;let s=t.structures?Object.keys(t.structures):[];for(let n=0,r=s.length;n<r;++n){let r=s[n],a=t.residues[r+"_MEM_1"],o=t.firstAtomObjCls.getFirstAtomObj(a);if(void 0===o)continue;let l=o.style;t.dAtoms.hasOwnProperty(o.serial)||(t.dAtoms=i.hashUtilsCls.unionHash(t.dAtoms,a),l="nothing");for(let i in a){let s=t.atoms[i];s.style="nothing"!==l?"nothing":"stick",void 0!==e&&(s.style=e?"stick":"nothing")}}void 0===e&&t.drawCls.draw()}adjustMembrane(e,t){var i=this.icn3d;i.icn3dui;for(let s in i.chains[i.inputid.toUpperCase()+"_MEM"]){let n=i.atoms[s];"O"==n.name?n.coord.z=e:"N"==n.name&&(n.coord.z=t)}i.definedSetsCls.setTransmemInMenu(e,t,!0),i.hlUpdateCls.updateHlMenus(),i.drawCls.draw()}selectBtwPlanes(e,t){var i=this.icn3d;if(i.icn3dui,e<t){let i=t;t=e,e=i}let s={};for(let n in i.atoms){let r=i.atoms[n];if("DUM"!=r.resn&&(r.coord.z>=t&&r.coord.z<=e)){s[r.structure+"_"+r.chain+"_"+r.resi]=1}}let n="z_planes_"+e+"_"+t,r=n;this.selectResidueList(s,n,r,!1)}}class ep{constructor(e){this.icn3d=e}residueids2spec(e){var t=this.icn3d;t.icn3dui;let i="";if(void 0!==e){let s,n,r,a,o,l,d,c=e.sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let i=e.lastIndexOf("_"),s=t.lastIndexOf("_");if(e.substr(0,i)<t.substr(0,s))return-1;if(e.substr(0,i)>t.substr(0,s))return 1;if(e.substr(0,i)==t.substr(0,s)){if(parseInt(e.substr(i+1))<parseInt(t.substr(s+1)))return-1;if(parseInt(e.substr(i+1))>parseInt(t.substr(s+1)))return 1;if(parseInt(e.substr(i+1))==parseInt(t.substr(s+1)))return 0}}})),h="",p=0,u=1!=Object.keys(t.structures).length;for(let e=0,m=c.length;e<m;++e){let m=c[e];if(r=m.lastIndexOf("_"),s=m.substr(0,r),n=m.substr(r+1),a=h.indexOf("_"),o=h.substr(0,a),l=h.substr(a+1),isNaN(n))i+=u?"$"+o+"."+l+":"+n+" or ":"."+l+":"+n+" or ";else{if(h!==s)e>0&&(i+=p===d?u?"$"+o+"."+l+":"+d+" or ":"."+l+":"+d+" or ":u?"$"+o+"."+l+":"+d+"-"+p+" or ":"."+l+":"+d+"-"+p+" or "),d=n;else if(h===s){let e=t.ParserUtilsCls.getResiNCBI(h,p);t.ParserUtilsCls.getResiNCBI(s,n)!=e+1&&(i+=p===d?u?"$"+o+"."+l+":"+d+" or ":"."+l+":"+d+" or ":u?"$"+o+"."+l+":"+d+"-"+p+" or ":"."+l+":"+d+"-"+p+" or ",d=n)}h=s,p=n}}a=h.indexOf("_"),o=h.substr(0,a),l=h.substr(a+1),i+=p===d?u?"$"+o+"."+l+":"+d:"."+l+":"+d:u?"$"+o+"."+l+":"+d+"-"+p:"."+l+":"+d+"-"+p}return i}resi2range(e,t){this.icn3d.icn3dui;let i,s,n=[],r="",a=e,o=a[0];for(let e=0,t=a.length;e<t;++e)s=a[e],0!=e&&parseInt(s)!=parseInt(i)+1&&(n.push(o),n.push(i),r&&(r+=","),r+=o==i?o:o+"-"+i,o=s),i=s;return n.push(o),n.push(i),r&&(r+=","),r+=o==i?o:o+"-"+i,t?r:n}atoms2spec(e){var t=this.icn3d;t.icn3dui;let i,s="",n=0,r={},a={},o={};for(let l in e)i=t.atoms[l],n>0&&(s+=" or "),s+="$"+i.structure+"."+i.chain+":"+i.resi+"@"+i.name,r[i.structure]=1,a[i.structure+"_"+i.chain]=1,o[i.structure+"_"+i.chain+"_"+i.resi]=1,++n;if(1==Object.keys(o).length){let e="\\$"+i.structure+"\\."+i.chain+":"+i.resi;s=s.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(a).length){let e="\\$"+i.structure+"\\."+i.chain;s=s.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(r).length){let e="\\$"+i.structure;s=s.replace(new RegExp(e,"g"),"")}return s}atoms2residues(e){var t=this.icn3d;t.icn3dui;let i={};for(let t=0,s=e.length;t<s;++t)i[e[t]]=1;let s=t.firstAtomObjCls.getResiduesFromAtoms(i);return Object.keys(s)}atoms2structureArray(e){var t=this.icn3d;t.icn3dui;let i={};for(let s in e){i[t.atoms[s].structure]=1}return Object.keys(i)}selectProperty(e,t,i){var s=this.icn3d,n=s.icn3dui;let r=n.hashUtilsCls.cloneHash(s.hAtoms);if("positive"==e){let e=":r,k,h";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e)}else if("negative"==e){let e=":d,e";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e),s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,s.nucleotides)}else if("hydrophobic"==e){let e=":w,f,y,l,i,c,m";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e),s.hAtoms=n.hashUtilsCls.intHash(s.hAtoms,s.proteins)}else if("polar"==e){let e=":g,v,s,t,a,n,p,q";s.hAtoms={},s.selByCommCls.selectBySpec(e,e,e),s.hAtoms=n.hashUtilsCls.intHash(s.hAtoms,s.proteins)}else if("b factor"==e){let e=n.hashUtilsCls.cloneHash(s.calphas);e=n.hashUtilsCls.unionHash(e,s.nucleotidesO3),e=n.hashUtilsCls.unionHash(e,s.chemicals),e=n.hashUtilsCls.unionHash(e,s.ions),e=n.hashUtilsCls.unionHash(e,s.water),s.hAtoms={};for(let r in e){let e=s.atoms[r];e.b>=parseInt(t)&&e.b<=parseInt(i)&&(s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,s.residues[e.structure+"_"+e.chain+"_"+e.resi]))}}else if("percent out"==e){s.bCalcArea=!0,s.opts.surface="solvent accessible surface",s.applyMapCls.applySurfaceOptions(),s.bCalcArea=!1,s.hAtoms={};for(let e in s.resid2area){let r=e.lastIndexOf("_"),a=e.substr(r+1);if(n.parasCls.residueArea.hasOwnProperty(a)){let o=parseInt(s.resid2area[e]/n.parasCls.residueArea[a]*100);if(o>=t&&o<=i){let t=e.substr(0,r);s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,s.residues[t])}}}}s.hAtoms=n.hashUtilsCls.intHash(s.hAtoms,r),s.drawCls.draw(),s.hlUpdateCls.updateHlAll()}selectComplement(){let e=this.icn3d,t=e.icn3dui,i={};for(let t in e.atoms)e.hAtoms.hasOwnProperty(t)||(i[t]=1);e.hAtoms=t.hashUtilsCls.cloneHash(i),e.hlUpdateCls.updateHlAll()}switchHighlightLevel(){var e=this.icn3d.icn3dui;if(e.bNode)return;let t=this;document.addEventListener("keydown",(function(i){let s=t.icn3d;38===i.keyCode?(i.preventDefault(),0!=Object.keys(s.pickedAtomList).length&&s.hAtoms.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.pickedAtomList).serial)||(s.pickedAtomList=e.hashUtilsCls.cloneHash(s.hAtoms)),t.switchHighlightLevelUp(),e.htmlCls.clickMenuCls.setLogCmd("highlight level up",!0)):40===i.keyCode&&(i.preventDefault(),0!=Object.keys(s.pickedAtomList).length&&s.hAtoms.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.pickedAtomList).serial)||(s.pickedAtomList=e.hashUtilsCls.cloneHash(s.hAtoms)),t.switchHighlightLevelDown(),e.htmlCls.clickMenuCls.setLogCmd("highlight level down",!0))}))}switchHighlightLevelUp(){var e=this.icn3d,t=e.icn3dui;if(!t.bNode){if(e.bShift||e.bCtrl||e.hlObjectsCls.removeHlObjects(),void 0!==e.pickedAtomList&&0!==Object.keys(e.pickedAtomList).length||(e.pickedAtomList=t.hashUtilsCls.cloneHash(e.hAtoms)),0===Object.keys(e.pickedAtomList).length&&(e.pickedAtomList=e.dAtoms),1===e.highlightlevel){e.highlightlevel=2;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[i.structure+"_"+i.chain+"_"+i.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[i.structure+"_"+i.chain+"_"+i.resi])}else if(2===e.highlightlevel){e.highlightlevel=3;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(i)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(i))}else if(3===e.highlightlevel){let i;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);i=e.pickingCls.select3ddomainFromAtom(s),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,i):e.hAtoms=t.hashUtilsCls.cloneHash(i)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(i).length){e.highlightlevel=5;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i.structure+"_"+i.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[i.structure+"_"+i.chain])}}else if(4===e.highlightlevel){e.highlightlevel=5;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i.structure+"_"+i.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[i.structure+"_"+i.chain])}else if(5===e.highlightlevel||6===e.highlightlevel){e.highlightlevel=6;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl||(e.hAtoms={});let s=e.structures[i.structure];for(let i=0,n=s.length;i<n;++i)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s[i]])}e.hlObjectsCls.addHlObjects(),e.hlUpdateCls.updateHlAll()}}switchHighlightLevelDown(){var e=this.icn3d,t=e.icn3dui;if(!t.bNode){if(e.hlObjectsCls.removeHlObjects(),void 0!==e.pickedAtomList&&0!==Object.keys(e.pickedAtomList).length||(e.pickedAtomList=t.hashUtilsCls.cloneHash(e.hAtoms)),2!==e.highlightlevel&&1!==e.highlightlevel||1!==Object.keys(e.pickedAtomList).length){if(3===e.highlightlevel){let i={};for(let t in e.pickedAtomList)residueid=e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi,i[residueid]=1;if(1===Object.keys(i).length){e.highlightlevel=2;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[i.structure+"_"+i.chain+"_"+i.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[i.structure+"_"+i.chain+"_"+i.resi])}}else if(4===e.highlightlevel){e.highlightlevel=3;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(i)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(i))}else if(5===e.highlightlevel){let i;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);i=e.pickingCls.select3ddomainFromAtom(s),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,i):e.hAtoms=t.hashUtilsCls.cloneHash(i)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(i).length){e.highlightlevel=3;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(i)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(i))}}else if(6===e.highlightlevel){e.highlightlevel=5;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i.structure+"_"+i.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[i.structure+"_"+i.chain])}}else e.highlightlevel=1,e.hAtoms=t.hashUtilsCls.cloneHash(e.pickedAtomList),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickedAtomList):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickedAtomList);e.hlObjectsCls.addHlObjects(),e.hlUpdateCls.updateHlAll()}}}class tp{constructor(e){this.icn3d=e}async CalcPhiUrl(e,t,i,s,n){let r=this.icn3d.icn3dui,a=await r.getXMLHttpRqstPromise(n,"GET","text","PQR");await this.CalcPhi(e,t,i,s,a)}getPdbStr(e){let t=this.icn3d,i=t.icn3dui,s={},n={},r=i.hashUtilsCls.intHash(t.dAtoms,t.hAtoms);for(let e in r)t.atoms[e],t.ions.hasOwnProperty(e)?s[e]=1:n[e]=1;let a=Object.keys(n).length;if(i.utilsCls.isCalphaPhosOnly(i.hashUtilsCls.hash2Atoms(n,t.atoms)))return void(e?console.log("The potential will not be shown because the side chains are missing in the structure..."):alert("The potential will not be shown because the side chains are missing in the structure..."));if(a>3e4)return void(e?console.log("The maximum number of allowed atoms is 30,000. Please try it again with selected chains..."):alert("The maximum number of allowed atoms is 30,000. Please try it again with selected chains..."));let o="",l=!0,d=!0;return o+=i.cfg.cid?t.saveFileCls.getAtomPDB(n,!0,void 0,void 0,void 0,void 0,l,d):t.saveFileCls.getAtomPDB(n,void 0,void 0,void 0,void 0,void 0,l,d),o+=t.saveFileCls.getAtomPDB(s,!0,void 0,!0,void 0,void 0,l,d),o}async CalcPhi(e,t,i,s,n){let r=this.icn3d;r.icn3dui;let a=await this.CalcPhiPrms(e,t,i,s,n);this.loadPhiData(a,i,s),r.bAjaxPhi=!0,s?r.setOptionCls.setOption("phisurface","phi"):r.setOptionCls.setOption("phimap","phi")}CalcPhiPrms(e,t,i,s,n){let r=this.icn3d,a=r.icn3dui;r.loadPhiFrom="delphi";let o=a.htmlCls.baseUrl+"delphi/delphi.cgi",l=a.cfg.cid?a.cfg.cid:Object.keys(r.structures).toString(),d={};if(n)d={pqr2phi:n,gsize:e,salt:t,pdbid:l};else{let i=this.getPdbStr();d={pdb2phi:i,gsize:e,salt:t,pdbid:l}}return new Promise((function(e,t){$.ajax({url:o,type:"POST",data:d,dataType:"binary",responseType:"arraybuffer",cache:!0,beforeSend:function(){r.ParserUtilsCls.showLoading()},complete:function(){r.ParserUtilsCls.hideLoading()},success:function(t){e(t)},error:function(e,t,i){}})}))}async PhiParser(e,t,i,s){let n,r=this.icn3d,a=r.icn3dui,o=this;n="phiurl"==t||"phiurl2"==t?"arraybuffer":"text";let l=await a.getXMLHttpRqstPromise(e,"GET",n,"potential");"phiurl"==t||"phiurl2"==t?o.loadPhiData(l,i,s):o.loadCubeData(l,i,s),r.bAjaxPhi=!0,s?r.setOptionCls.setOption("phisurface","phi"):r.setOptionCls.setOption("phimap","phi")}loadPhiData(e,t,i){let s=this.icn3d;s.icn3dui;let n={filetype:"phi"},r=e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e,a=new Float32Array(r.slice(r.byteLength-24,r.byteLength-8));n.scale=a[0];let o=a[1],l=a[2],d=a[3];n.n=new Int32Array(r.slice(r.byteLength-8,r.byteLength-4)),n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new mt(o-c,l-c,d-c);let h=new Float32Array(r.slice(110,r.byteLength-56));n.bSurface=i,s.mapData.headerPhi=n,s.mapData.dataPhi=h,s.mapData.contourPhi=t;let p=new gi;p.identity(),p.multiply((new gi).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),s.mapData.matrixPhi=p}loadCubeData(e,t,i){let s=this.icn3d;s.icn3dui;let n={filetype:"cube"},r=e.split("\n"),a=[];a.push(parseFloat(r[0].substr(0,10))),a.push(parseFloat(r[0].substr(10,6))),a.push(parseFloat(r[0].substr(16,10))),a.push(parseFloat(r[0].substr(26,10))),a.push(parseFloat(r[0].substr(36,10))),n.scale=a[0];let o=a[2],l=a[3],d=a[4];n.n=a[1],n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new mt(o-c,l-c,d-c);let h=[];for(let e=7,t=r.length;e<t;++e){let t=r[e].split(/\s+/);for(let e=0,i=t.length;e<i;++e){let i=parseFloat(t[e]);isNaN(i)||h.push(i)}}h.length!=n.n*n.n*n.n&&console.log("the data array size "+h.length+" didn't match the grid size "+n.n*n.n*n.n+"..."),n.bSurface=i,s.mapData.headerPhi=n,s.mapData.dataPhi=h,s.mapData.contourPhi=t;let p=new gi;p.identity(),p.multiply((new gi).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),s.mapData.matrixPhi=p}async applyCommandPhi(e){let t=this.icn3d;t.icn3dui;let i=this,s=e.split(" | "),n=s[0].split(" "),r=s[1].split(" "),a=s[2].split(" "),o=s[3].split(" "),l=s[4].split(" "),d=n[2],c=parseFloat(r[1]),h=a[1],p=o[1],u=l[1];if(8==s.length){let e=s[5].split(" "),i=s[6].split(" "),n=s[7].split(" ");t.phisurftype=e[1],t.phisurfop=parseFloat(i[1]),t.phisurfwf=n[1],$("#"+t.pre+"delphisurftype").val(t.phisurftype),$("#"+t.pre+"delphisurfop").val(t.phisurfop),$("#"+t.pre+"delphisurfwf").val(t.phisurfwf)}let m="pqrurl2"==d||"phiurl2"==d||"cubeurl2"==d;"pqrurl"==d||"pqrurl2"==d?await i.CalcPhiUrl(p,u,c,m,h):await i.PhiParser(h,d,c,m)}async applyCommandDelphi(e){let t=this.icn3d;t.icn3dui;let i=e.split(" | "),s=i[0].split(" "),n=i[1].split(" "),r=i[2].split(" "),a=i[3].split(" "),o=s[2],l=n[1],d=r[1],c=a[1];if($("#"+t.pre+"delphi1gsize").val(d),$("#"+t.pre+"delphi1salt").val(c),$("#"+t.pre+"delphi2gsize").val(d),$("#"+t.pre+"delphi2salt").val(c),7==i.length){let e=i[4].split(" "),s=i[5].split(" "),n=i[6].split(" ");t.phisurftype=e[1],t.phisurfop=s[1],t.phisurfwf=n[1],$("#"+t.pre+"delphisurftype").val(t.phisurftype),$("#"+t.pre+"delphisurfop").val(t.phisurfop),$("#"+t.pre+"delphisurfwf").val(t.phisurfwf)}let h="surface"==o;await this.CalcPhi(d,c,l,h)}async loadDelphiFile(e){let t=this.icn3d,i=t.icn3dui,s="delphi2"==e?$("#"+t.pre+"delphi2gsize").val():$("#"+t.pre+"delphi1gsize").val(),n="delphi2"==e?$("#"+t.pre+"delphi2salt").val():$("#"+t.pre+"delphi1gsize").val(),r="delphi2"==e?$("#"+t.pre+"delphicontour2").val():$("#"+t.pre+"delphicontour").val(),a="delphi2"==e;await this.CalcPhi(s,n,r,a);let o="delphi2"==e?"surface":"map";a?i.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+r+" | gsize "+s+" | salt "+n+" | surface "+t.phisurftype+" | opacity "+t.phisurfop+" | wireframe "+t.phisurfwf,!0):i.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+r+" | gsize "+s+" | salt "+n,!0)}loadPhiFile(e){let t,i=this.icn3d,s=i.icn3dui,n=this;"pqr"==e||"phi"==e||"cube"==e?t=$("#"+i.pre+e+"file")[0].files[0]:"pqr2"==e?t=$("#"+i.pre+"pqrfile2")[0].files[0]:"phi2"==e?t=$("#"+i.pre+"phifile2")[0].files[0]:"cube2"==e&&(t=$("#"+i.pre+"cubefile2")[0].files[0]);let r="pqr"==e||"phi"==e||"cube"==e?$("#"+i.pre+"phicontour").val():$("#"+i.pre+"phicontour2").val();if(t){s.utilsCls.checkFileAPI();let i=new FileReader;i.onload=async function(t){let i=n.icn3d,a=t.target.result,o=0,l=0;if("pqr"==e||"pqr2"==e){let t="pqr2"==e;o=$("#"+i.pre+e+"gsize").val(),l=$("#"+i.pre+e+"salt").val(),await n.CalcPhi(o,l,r,t,a)}else if("phi"==e||"phi2"==e){let t="phi2"==e;n.loadPhiData(a,r,t)}else if("cube"==e||"cube2"==e){let t="cube2"==e;n.loadCubeData(a,r,t)}i.bAjaxPhi=!0,bSurface?i.setOptionCls.setOption("phisurface","phi"):i.setOptionCls.setOption("phimap","phi"),bSurface?s.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+r+" | file "+$("#"+i.pre+e+"file").val()+" | gsize "+o+" | salt "+l+" | surface "+i.phisurftype+" | opacity "+i.phisurfop+" | wireframe "+i.phisurfwf,!1):s.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+r+" | file "+$("#"+i.pre+e+"file").val()+" | gsize "+o+" | salt "+l,!1)},"phi"==e||"phi2"==e?i.readAsArrayBuffer(t):i.readAsText(t)}else alert("Please select a file before clicking 'Load'")}async loadPhiFileUrl(e){let t,i=this.icn3d,s=i.icn3dui;"pqrurl"==e||"phiurl"==e||"cubeurl"==e?t=$("#"+i.pre+e+"file").val():"pqrurl2"==e?t=$("#"+i.pre+"pqrurlfile2").val():"phiurl2"==e?t=$("#"+i.pre+"phiurlfile2").val():"cubeurl2"==e&&(t=$("#"+i.pre+"cubeurlfile2").val());let n="pqrurl"==e||"phiurl"==e||"cubeurl"==e?$("#"+i.pre+"phiurlcontour").val():$("#"+i.pre+"phiurlcontour2").val();if(t){let r="pqrurl2"==e||"phiurl2"==e||"cubeurl2"==e,a=0,o=0;"pqrurl"==e||"pqrurl2"==e?(a=$("#"+i.pre+e+"gsize").val(),o=$("#"+i.pre+e+"salt").val(),await this.CalcPhiUrl(a,o,n,r,t)):await this.PhiParser(t,e,n,r),r?s.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+a+" | salt "+o+" | surface "+i.phisurftype+" | opacity "+i.phisurfop+" | wireframe "+i.phisurfwf,!0):s.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+a+" | salt "+o,!0)}else alert("Please input the file URL before clicking 'Load'")}}class ip{constructor(e){this.icn3d=e}async applyDssp(e,t){let i=this.icn3d,s=i.icn3dui,n=this,r=e?"1":"0",a=Object.keys(i.structures),o=[],l=window&&window.location&&-1!=window.location.hostname.indexOf("ncbi.nlm.nih.gov")?"/Structure/mmcifparser/mmcifparser.cgi":s.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi";for(let e=0,t=a.length;e<t;++e){let t="",n={},d=i.structures[a[e]];for(let e=0,t=d.length;e<t;++e)n=s.hashUtilsCls.unionHash(n,i.chains[d[e]]);t+=i.saveFileCls.getAtomPDB(n,void 0,!0);let c={dssp:"t",calphaonly:r,pdbfile:t},h=s.getAjaxPostPromise(l,c);o.push(h)}let d=Promise.allSettled(o);try{let e=await d;await n.parseDsspData(e,a,t),s.bNode||await i.ParserUtilsCls.checkMemProteinAndRotate()}catch(e){console.log("DSSP calculation had a problem with this structure "+a[0]+"..."),await i.pdbParserCls.loadPdbDataRender(t)}}async parseDsspData(e,t,i){let s=this.icn3d;s.icn3dui;for(let i=0,n=e.length;i<n;++i){let n=e[i].value;if(void 0!==n&&-1===JSON.stringify(n).indexOf("Oops there was a problem"))for(let e in s.chainsSeq){let r=e.indexOf("_");if(e.substr(0,r)!=t[i])continue;let a,o=e.substr(r+1),l=s.chainsSeq[e],d="coil";for(let t=0,i=l.length;t<i;++t){let i,r=l[t].resi,c=o+"_"+r,h="c";n.hasOwnProperty(c)?h=n[c]:n.hasOwnProperty(" _"+r)?h=n[" _"+r]:n.hasOwnProperty("_"+r)&&(h=n["_"+r]),i="H"===h?"helix":"E"===h?"sheet":"coil";let p=e+"_"+r;s.secondaries[p]=h;let u,m,f=0;if(i!==d?"coil"===d?(u=!0,m=!1):"coil"===i?(f=2,u=!1,m=!1):("sheet"===d&&"helix"===i||"helix"===d&&"sheet"===i)&&(f=2,u=!0,m=!1):(u=!1,m=!1),1==f){let t=e+"_"+a;for(let e in s.residues[t])s.atoms[e].ssbegin=!0,s.atoms[e].ssend=!1}else if(2==f){let t=e+"_"+a;for(let e in s.residues[t])s.atoms[e].ssbegin=!1,s.atoms[e].ssend=!0}for(let e in s.residues[p])s.atoms[e].ss=i,s.atoms[e].ssbegin=u,s.atoms[e].ssend=m;d=i,a=r}}else console.log("DSSP calculation had a problem with this structure "+t[i]+"...")}await s.pdbParserCls.loadPdbDataRender(i)}}class sp{constructor(e){this.icn3d=e,this.TMThresholdIgType=.85,this.TMThresholdTemplate=.4,this.topClusters=5}async hideIgRefNum(){let e=this.icn3d;e.icn3dui,e.bShowRefnum=!1,e.resid2refnum={},e.annotationCls.hideAnnoTabIg(),e.selectionCls.selectAll_base(),e.opts.color="chain",e.setColorCls.setColorByOptions(e.opts,e.atoms),e.hlUpdateCls.updateHlAll(),e.drawCls.draw(),e.bResetAnno=!0,e.bAnnoShown&&await e.annotationCls.resetAnnoTabAll()}setRefPdbs(){let e=this.icn3d;e.icn3dui,e.refpdbArray=["1InsulinR_8guyE_human_FN3-n1","1Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4","1CoAtomerGamma1_1r4xA_human","1C3_2qkiD_human_n1","1CuZnSuperoxideDismutase_1hl5C_human","1ASF1A_2iijA_human","1FAB-LIGHT_5esv_C1-n2","1CD2_1hnfA_human_C2-n2","1NaCaExchanger_2fwuA_dog_n2","1NaKATPaseTransporterBeta_2zxeB_spurdogshark","1FAB-HEAVY_5esv_V-n1","1PDL1_4z18B_human_V-n1","1BTLA_2aw2A_human_Iset","1LaminAC_1ifrA_human","1CD3g_6jxrg_human_C2","1CD28_1yjdC_human_V","1CD19_6al5A_human-n1"],e.refpdbHash={},e.refpdbHash["1InsulinR_8guyE_human_FN3-n1"]=["InsulinR_8guyE_human_FN3-n1","IL6Rb_1bquB_human_FN3-n3","Sidekick2_1wf5A_human_FN3-n7","InsulinR_8guyE_human_FN3-n2","Contactin1_2ee2A_human_FN3-n9","IL6Rb_1bquB_human_FN3-n2"],e.refpdbHash["1Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4"]=["Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4","ICOS_6x4gA_human_V"],e.refpdbHash["1CoAtomerGamma1_1r4xA_human"]=["CoAtomerGamma1_1r4xA_human","TP34_2o6cA_bacteria"],e.refpdbHash["1C3_2qkiD_human_n1"]=["C3_2qkiD_human_n1","BArrestin1_4jqiA_rat_n1","RBPJ_6py8C_human_Unk-n1"],e.refpdbHash["1CuZnSuperoxideDismutase_1hl5C_human"]=["CuZnSuperoxideDismutase_1hl5C_human","TEAD1_3kysC_human"],e.refpdbHash["1ASF1A_2iijA_human"]=["ASF1A_2iijA_human","RBPJ_6py8C_human_Unk-n2","TP47_1o75A_bacteria"],e.refpdbHash["1FAB-LIGHT_5esv_C1-n2"]=["FAB-LIGHT_5esv_C1-n2","GHR_1axiB_human_C1-n1","VTCN1_Q7Z7D3_human_C1-n2","B2Microglobulin_7phrL_human_C1","FAB-HEAVY_5esv_C1-n2","MHCIa_7phrH_human_C1"],e.refpdbHash["1CD2_1hnfA_human_C2-n2"]=["CD2_1hnfA_human_C2-n2","Siglec3_5j0bB_human_C1-n2"],e.refpdbHash["1NaCaExchanger_2fwuA_dog_n2"]=["NaCaExchanger_2fwuA_dog_n2","ORF7a_1xakA_virus","ECadherin_4zt1A_human_n2"],e.refpdbHash["1NaKATPaseTransporterBeta_2zxeB_spurdogshark"]=["NaKATPaseTransporterBeta_2zxeB_spurdogshark"],e.refpdbHash["1FAB-HEAVY_5esv_V-n1"]=["FAB-HEAVY_5esv_V-n1","FAB-LIGHT_5esv_V-n1","VNAR_1t6vN_shark_V","TCRa_6jxrm_human_V-n1","VISTA_6oilA_human_V","CD8a_1cd8A_human_V","PD1_4zqkB_human_V"],e.refpdbHash["1PDL1_4z18B_human_V-n1"]=["PDL1_4z18B_human_V-n1","CD2_1hnfA_human_V-n1","LAG3_7tzgD_human_V-n1"],e.refpdbHash["1BTLA_2aw2A_human_Iset"]=["BTLA_2aw2A_human_Iset","Palladin_2dm3A_human_Iset-n1","Titin_4uowM_human_Iset-n152","LAG3_7tzgD_human_C1-n2","JAM1_1nbqA_human_Iset-n2","Contactin1_3s97C_human_Iset-n2"],e.refpdbHash["1LaminAC_1ifrA_human"]=["LaminAC_1ifrA_human","CD3d_6jxrd_human_C1"],e.refpdbHash["1CD3g_6jxrg_human_C2"]=["CD3g_6jxrg_human_C2","TCRa_6jxrm_human_C1-n2","IsdA_2iteA_bacteria"],e.refpdbHash["1CD28_1yjdC_human_V"]=["CD28_1yjdC_human_V","MPT63_1lmiA_bacteria","CD3e_6jxrf_human_C1"],e.refpdbHash["1CD19_6al5A_human-n1"]=["CD19_6al5A_human-n1"],e.refpdbHash.all_templates=["ASF1A_2iijA_human","B2Microglobulin_7phrL_human_C1","BArrestin1_4jqiA_rat_n1","BTLA_2aw2A_human_Iset","C3_2qkiD_human_n1","CD19_6al5A_human-n1","CD28_1yjdC_human_V","CD2_1hnfA_human_C2-n2","CD2_1hnfA_human_V-n1","CD3d_6jxrd_human_C1","CD3e_6jxrf_human_C1","CD3g_6jxrg_human_C2","CD8a_1cd8A_human_V","CoAtomerGamma1_1r4xA_human","Contactin1_2ee2A_human_FN3-n9","Contactin1_3s97C_human_Iset-n2","CuZnSuperoxideDismutase_1hl5C_human","ECadherin_4zt1A_human_n2","Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4","FAB-HEAVY_5esv_C1-n2","FAB-HEAVY_5esv_V-n1","FAB-LIGHT_5esv_C1-n2","FAB-LIGHT_5esv_V-n1","GHR_1axiB_human_C1-n1","ICOS_6x4gA_human_V","IL6Rb_1bquB_human_FN3-n2","IL6Rb_1bquB_human_FN3-n3","InsulinR_8guyE_human_FN3-n1","InsulinR_8guyE_human_FN3-n2","IsdA_2iteA_bacteria","JAM1_1nbqA_human_Iset-n2","LAG3_7tzgD_human_C1-n2","LAG3_7tzgD_human_V-n1","LaminAC_1ifrA_human","MHCIa_7phrH_human_C1","MPT63_1lmiA_bacteria","NaCaExchanger_2fwuA_dog_n2","NaKATPaseTransporterBeta_2zxeB_spurdogshark","ORF7a_1xakA_virus","PD1_4zqkB_human_V","PDL1_4z18B_human_V-n1","Palladin_2dm3A_human_Iset-n1","RBPJ_6py8C_human_Unk-n1","RBPJ_6py8C_human_Unk-n2","Sidekick2_1wf5A_human_FN3-n7","Siglec3_5j0bB_human_C1-n2","TCRa_6jxrm_human_C1-n2","TCRa_6jxrm_human_V-n1","TEAD1_3kysC_human","TP34_2o6cA_bacteria","TP47_1o75A_bacteria","Titin_4uowM_human_Iset-n152","VISTA_6oilA_human_V","VNAR_1t6vN_shark_V","VTCN1_Q7Z7D3_human_C1-n2"],e.refpdbHash["5ESV_C"]=["FAB-HEAVY_5esv_V-n1","FAB-HEAVY_5esv_C1-n2"],e.refpdbHash["5ESV_D"]=["FAB-LIGHT_5esv_V-n1","FAB-LIGHT_5esv_C1-n2"],e.refpdbHash["8GUY_E"]=["InsulinR_8guyE_human_FN3-n1","InsulinR_8guyE_human_FN3-n2"],e.refpdbHash["6JXR_m"]=["TCRa_6jxrm_human_V-n1","TCRa_6jxrm_human_C1-n2"],e.refpdbHash["1HNF_A"]=["CD2_1hnfA_human_V-n1","CD2_1hnfA_human_C2-n2"],e.refpdbHash["7TZG_D"]=["LAG3_7tzgD_human_V-n1","LAG3_7tzgD_human_C1-n2"],e.refpdbHash["6PY8_C"]=["RBPJ_6py8C_human_Unk-n1","RBPJ_6py8C_human_Unk-n2"],e.refpdbHash["1BQU_B"]=["IL6Rb_1bquB_human_FN3-n2","IL6Rb_1bquB_human_FN3-n3"],e.refpdbHash["1R4X_A"]=["CoAtomerGamma1_1r4xA_human"],e.refpdbHash["6OIL_A"]=["VISTA_6oilA_human_V"],e.refpdbHash["2ZXE_B"]=["NaKATPaseTransporterBeta_2zxeB_spurdogshark"],e.refpdbHash["1I8A_A"]=["Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4"],e.refpdbHash["2FWU_A"]=["NaCaExchanger_2fwuA_dog_n2"],e.refpdbHash["4JQI_A"]=["BArrestin1_4jqiA_rat_n1"],e.refpdbHash["1NBQ_A"]=["JAM1_1nbqA_human_Iset-n2"],e.refpdbHash["1O75_A"]=["TP47_1o75A_bacteria"],e.refpdbHash["7PHR_H"]=["MHCIa_7phrH_human_C1"],e.refpdbHash["2IIJ_A"]=["ASF1A_2iijA_human"],e.refpdbHash["4Z18_B"]=["PDL1_4z18B_human_V-n1"],e.refpdbHash["1T6V_N"]=["VNAR_1t6vN_shark_V"],e.refpdbHash["2O6C_A"]=["TP34_2o6cA_bacteria"],e.refpdbHash["3KYS_C"]=["TEAD1_3kysC_human"],e.refpdbHash["7PHR_L"]=["B2Microglobulin_7phrL_human_C1"],e.refpdbHash["2AW2_A"]=["BTLA_2aw2A_human_Iset"],e.refpdbHash["1HL5_C"]=["CuZnSuperoxideDismutase_1hl5C_human"],e.refpdbHash["1WF5_A"]=["Sidekick2_1wf5A_human_FN3-n7"],e.refpdbHash["5J0B_B"]=["Siglec3_5j0bB_human_C1-n2"],e.refpdbHash["1IFR_A"]=["LaminAC_1ifrA_human"],e.refpdbHash.Q7Z7D3_A=["VTCN1_Q7Z7D3_human_C1-n2"],e.refpdbHash["4ZQK_B"]=["PD1_4zqkB_human_V"],e.refpdbHash["2DM3_A"]=["Palladin_2dm3A_human_Iset-n1"],e.refpdbHash["2ITE_A"]=["IsdA_2iteA_bacteria"],e.refpdbHash["1XAK_A"]=["ORF7a_1xakA_virus"],e.refpdbHash["4ZT1_A"]=["ECadherin_4zt1A_human_n2"],e.refpdbHash["1LMI_A"]=["MPT63_1lmiA_bacteria"],e.refpdbHash["1CD8_A"]=["CD8a_1cd8A_human_V"],e.refpdbHash["3S97_C"]=["Contactin1_3s97C_human_Iset-n2"],e.refpdbHash["1AXI_B"]=["GHR_1axiB_human_C1-n1"],e.refpdbHash["6X4G_A"]=["ICOS_6x4gA_human_V"],e.refpdbHash["2EE2_A"]=["Contactin1_2ee2A_human_FN3-n9"],e.refpdbHash["4UOW_M"]=["Titin_4uowM_human_Iset-n152"],e.refpdbHash["6A15_A"]=["CD19_6al5A_human-n1"],e.refpdbHash["2QKI_D"]=["C3_2qkiD_human_n1"],e.refpdbHash["1YJD_C"]=["CD28_1yjdC_human_V"],e.refpdbHash["6JXR_d"]=["CD3d_6jxrd_human_C1"],e.refpdbHash["6JXR_f"]=["CD3e_6jxrf_human_C1"],e.refpdbHash["6JXR_g"]=["CD3g_6jxrg_human_C2"],e.ref2igtype={},e.ref2igtype.ASF1A_2iijA_human="IgFN3-like",e.ref2igtype.B2Microglobulin_7phrL_human_C1="IgC1",e.ref2igtype.BArrestin1_4jqiA_rat_n1="IgFN3-like",e.ref2igtype.BTLA_2aw2A_human_Iset="IgI",e.ref2igtype.C3_2qkiD_human_n1="IgFN3-like",e.ref2igtype["CD19_6al5A_human-n1"]="CD19",e.ref2igtype.CD28_1yjdC_human_V="IgV",e.ref2igtype["CD2_1hnfA_human_C2-n2"]="IgC2",e.ref2igtype["CD2_1hnfA_human_V-n1"]="IgV",e.ref2igtype.CD3d_6jxrd_human_C1="IgC1",e.ref2igtype.CD3e_6jxrf_human_C1="IgC1",e.ref2igtype.CD3g_6jxrg_human_C2="IgC2",e.ref2igtype.CD8a_1cd8A_human_V="IgV",e.ref2igtype.CoAtomerGamma1_1r4xA_human="IgE",e.ref2igtype["Contactin1_2ee2A_human_FN3-n9"]="IgFN3",e.ref2igtype["Contactin1_3s97C_human_Iset-n2"]="IgI",e.ref2igtype.CuZnSuperoxideDismutase_1hl5C_human="SOD",e.ref2igtype.ECadherin_4zt1A_human_n2="Cadherin",e.ref2igtype["Endo-1,4-BetaXylanase10A_1i8aA_bacteria_n4"]="IgE",e.ref2igtype["FAB-HEAVY_5esv_C1-n2"]="IgC1",e.ref2igtype["FAB-HEAVY_5esv_V-n1"]="IgV",e.ref2igtype["FAB-LIGHT_5esv_C1-n2"]="IgC1",e.ref2igtype["FAB-LIGHT_5esv_V-n1"]="IgV",e.ref2igtype["GHR_1axiB_human_C1-n1"]="IgC1",e.ref2igtype.ICOS_6x4gA_human_V="IgV",e.ref2igtype["IL6Rb_1bquB_human_FN3-n2"]="IgFN3",e.ref2igtype["IL6Rb_1bquB_human_FN3-n3"]="IgFN3",e.ref2igtype["InsulinR_8guyE_human_FN3-n1"]="IgFN3",e.ref2igtype["InsulinR_8guyE_human_FN3-n2"]="IgFN3",e.ref2igtype.IsdA_2iteA_bacteria="IgE",e.ref2igtype["JAM1_1nbqA_human_Iset-n2"]="IgI",e.ref2igtype["LAG3_7tzgD_human_C1-n2"]="IgC1",e.ref2igtype["LAG3_7tzgD_human_V-n1"]="IgV",e.ref2igtype.LaminAC_1ifrA_human="Lamin",e.ref2igtype.MHCIa_7phrH_human_C1="IgC1",e.ref2igtype.MPT63_1lmiA_bacteria="IgFN3-like",e.ref2igtype.NaCaExchanger_2fwuA_dog_n2="IgFN3-like",e.ref2igtype.NaKATPaseTransporterBeta_2zxeB_spurdogshark="IgE",e.ref2igtype.ORF7a_1xakA_virus="ORF",e.ref2igtype.PD1_4zqkB_human_V="IgV",e.ref2igtype["PDL1_4z18B_human_V-n1"]="IgV",e.ref2igtype["Palladin_2dm3A_human_Iset-n1"]="IgI",e.ref2igtype["RBPJ_6py8C_human_Unk-n1"]="IgFN3-like",e.ref2igtype["Sidekick2_1wf5A_human_FN3-n7"]="IgFN3",e.ref2igtype["Siglec3_5j0bB_human_C1-n2"]="IgC1",e.ref2igtype["TCRa_6jxrm_human_C1-n2"]="IgC1",e.ref2igtype["TCRa_6jxrm_human_V-n1"]="IgV",e.ref2igtype.TEAD1_3kysC_human="IgFN3-like",e.ref2igtype.TP34_2o6cA_bacteria="IgE",e.ref2igtype.TP47_1o75A_bacteria="IgE",e.ref2igtype["Titin_4uowM_human_Iset-n152"]="IgI",e.ref2igtype.VISTA_6oilA_human_V="IgV",e.ref2igtype.VNAR_1t6vN_shark_V="IgV",e.ref2igtype["VTCN1_Q7Z7D3_human_C1-n2"]="IgC1"}getPdbAjaxArray(){let e=this.icn3d,t=e.icn3dui,i=[];for(let s=0,n=e.refpdbArray.length;s<n;++s){let n=t.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+e.refpdbArray[s],r=t.getAjaxPromise(n,"text");i.push(r)}return i}async showIgRefNum(e){let t=this.icn3d;t.icn3dui;let i=this;this.setRefPdbs();let s=this.getPdbAjaxArray(),n=0;if(e)await i.parseRefPdbData(void 0,e,void 0,n);else{t.pdbDataArray=await this.promiseWithFixedJobs(s);let r=await i.parseRefPdbData(t.pdbDataArray,e,void 0,n);for(++n;!r&&n<15;){let s=!0;r=await i.parseRefPdbData(t.pdbDataArray,e,s,n),++n}}t.chainid2igtrack||(t.chainid2igtrack={});for(let e in t.chains){let i=t.firstAtomObjCls.getFirstAtomObj(t.chains[e]);if(t.proteins.hasOwnProperty(i.serial)){let i=t.showSeqCls.getSeq(e);t.chainid2igtrack[e]=this.ajdustRefnum(i,e)}}}async parseRefPdbData(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=this,o=Object.keys(n.structures),l=[],d=[],c=r.htmlCls.tmalignUrl;n.resid2domainid||(n.resid2domainid={}),n.domainid2pdb={};let h=!0,p=!1;for(let s=0,a=o.length;s<a;++s){let a=o[s],u=n.structures[a];for(let s=0,o=u.length;s<o;++s){let o=u[s],m=this.getDomainAtomsArray(o,i);if(n.domainid2refpdbname||(n.domainid2refpdbname={}),n.domainid2score||(n.domainid2score={}),0!=m.length){p=!0;for(let i=0,s=m.length;i<s;++i){h=!1;let s=n.saveFileCls.getAtomPDB(m[i],void 0,void 0,void 0,void 0,a),p=n.firstAtomObjCls.getFirstAtomObj(m[i]),u=n.firstAtomObjCls.getLastAtomObj(m[i]),f=o+","+i+"_"+(p.resi+":"+u.resi+":"+Object.keys(m[i]).length);if(delete n.domainid2score[f],n.domainid2pdb[f]=s,t)n.domainid2refpdbname[f]=[t],d.push(f+"|1"+t);else for(let t=0,i=e.length;t<i;++t){let i=n.defaultPdbId+t,a=e[t].value;a="HEADER "+i+"\n"+a;let o={pdb_query:a,pdb_target:s,queryid:n.refpdbArray[t]},h=r.getAjaxPostPromise(c,o);l.push(h),d.push(f+"|"+n.refpdbArray[t])}}}}}if(!p)return h;if(t){r.bNode||console.log("Start alignment with the reference culsters "+JSON.stringify(n.domainid2refpdbname));let e=[],i=[],o=r.htmlCls.tmalignUrl,l=r.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+t,d=r.getAjaxPromise(l,"text"),c=[];c.push(d);let p=await this.promiseWithFixedJobs(c);for(let s in n.domainid2refpdbname){let a=n.domainid2pdb[s];for(let l=0,d=p.length;l<d;++l){let d=n.defaultPdbId+l,c=p[l].value;c="HEADER "+d+"\n"+c;let h={pdb_query:c,pdb_target:a,queryid:t},u=r.getAjaxPostPromise(o,h);e.push(u),i.push(s+"|"+t)}}let u=[];u=await this.promiseWithFixedJobs(e),h=await a.parseAlignData(u,i,void 0,s)}else{let e=[];e=await this.promiseWithFixedJobs(l);let t=!0;h=await a.parseAlignData(e,d,t,s)}return h}getDomainAtomsArray(e,t){let i=this.icn3d,s=i.icn3dui,n=[];if(i.chainid2atomsLeft||(i.chainid2atomsLeft={}),!i.proteins.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.chains[e]).serial)&&!i.proteins.hasOwnProperty(i.firstAtomObjCls.getMiddleAtomObj(i.chains[e]).serial))return n;if(i.chainsSeq[e].length<20)return n;let r=s.hashUtilsCls.intHash(i.chains[e],i.hAtoms);if(0==Object.keys(r).length)return n;if(t){let t={};for(let e in i.resid2domainid)i.resid2domainid[e]&&(t=s.hashUtilsCls.unionHash(t,i.residues[e]));if(r=s.hashUtilsCls.exclHash(r,t),i.chainid2atomsLeft[e]==Object.keys(r).length)return n;if(i.chainid2atomsLeft[e]=Object.keys(r).length,Object.keys(r).length<200)return n}let a=i.domain3dCls.c2b_NewSplitChain(r,void 0).subdomains;if(a.length>=1)for(let t=0,r=a.length;t<r;++t){let r={},o=a[t],l=0;for(let t=0,n=o.length;t<n;t+=2){let n=parseInt(o[t]),a=parseInt(o[t+1]);for(let t=n;t<=a;++t){let n=i.ncbi2resid[e+"_"+t];++l,r=s.hashUtilsCls.unionHash(r,i.residues[n]),delete i.residIgLoop[n],delete i.resid2domainid[n]}}l<20||n.push(r)}return n}getTemplateList(e){let t=this.icn3d;t.icn3dui;let i="",s="",n="",r="";if(i=t.domainid2refpdbname[e][0],t.domainid2score[e]){let i=t.domainid2score[e].split("_");s=i[0],n=i[1],r=i[2]}return{refpdbname:i,score:s,seqid:n,nresAlign:r}}parseAlignData_part1(e,t,i){let s=this.icn3d,n=s.icn3dui,r={},a={};s.chainid2refpdbname||(s.chainid2refpdbname={}),s.domainid2refpdbname||(s.domainid2refpdbname={}),s.domainid2score||(s.domainid2score={}),s.domainid2ig2kabat||(s.domainid2ig2kabat={}),s.domainid2ig2imgt||(s.domainid2ig2imgt={});for(let o=0,l=t.length;o<l;++o){let l=e[o]?e[o].value:void 0;if(!l||0==l.length){n.bNode||console.log("The alignment data for "+t[o]+" is unavailable...");continue}if(void 0===l[0].score)continue;let d=parseFloat(l[0].score),c=t[o].substr(0,t[o].indexOf("|")),h=t[o].substr(t[o].indexOf("|")+1);if(i){if(l[0].score<this.TMThresholdTemplate||l[0].num_res<10)continue}else if(l[0].score<this.TMThresholdTemplate||l[0].num_res<20){n.bNode||console.log("bRound1: "+i+": domainid "+c+" and refpdbname "+h+" were skipped due to a TM-score less than "+this.TMThresholdTemplate);continue}if(i?(n.bNode||console.log("domainid: "+c+" refpdbname "+h+" TM-score: "+l[0].score),a[c]||(a[c]={}),a[c][h]=d):n.bNode||console.log("refpdbname "+h+" TM-score: "+l[0].score),!i&&l[0].segs){let e=!1,t=!1,i=!1,r=!1,a=!0,o=!0,d=!0,p=!0,u=c.split(",")[0];for(let n=0,c=l[0].segs.length;n<c;++n){let c=l[0].segs[n],h=u+"_"+c.t_start,m=parseInt(c.q_start);if(m>2540&&m<2560?e=!0:m>3540&&m<3560?t=!0:m>7540&&m<7560?i=!0:m>8540&&m<8560&&(r=!0),2550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(a=!1)}else if(3550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(o=!1)}else if(7550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(d=!1)}else if(8550==m){"helix"==s.firstAtomObjCls.getFirstAtomObj(s.residues[h]).ss&&(p=!1)}if(e&&t&&i&&r)break}if(!(e&&t&&i&&r&&a&&o&&d&&p)){n.bNode||e&&t&&i&&r||console.log("Some of the Ig strands B, C, E, F are missing in the domain "+c+"..."),n.bNode||a&&o&&d&&p||console.log("Some of the Ig strands B, C, E, F are not beta sheets..."),s.domainid2refpdbname[c][0]==h&&(delete s.domainid2refpdbname[c],delete s.domainid2score[c]);continue}}i||n.bNode||console.log("domainid: "+c),(!r.hasOwnProperty(c)||d>=parseFloat(s.domainid2score[c].split("_")[0]))&&(s.domainid2score[c]=l[0].score+"_"+l[0].frac_identical+"_"+l[0].num_res,s.domainid2refpdbname[c]=i?d>=this.TMThresholdIgType?[h]:["all_templates"]:[h],r[c]=l[0].segs,s.domainid2ig2kabat[c]=l[0].ig2kabat,s.domainid2ig2imgt[c]=l[0].ig2imgt)}if(i)for(let e in a)if(!n.bNode&&"all_templates"==s.domainid2refpdbname[e][0]){let t=a[e],i=Object.keys(t);i.sort((function(e,i){return t[i]-t[e]})),s.domainid2refpdbname[e]=i.slice(0,this.topClusters)}return r}async parseAlignData(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=!1,o=this.parseAlignData_part1(e,t,i);if(0==Object.keys(o).length)return a=!0,a;if(i){r.bNode||console.log("Start round 2 alignment with the reference culsters "+JSON.stringify(n.domainid2refpdbname));let e=[],t=[],i=r.htmlCls.tmalignUrl;for(let a in n.domainid2refpdbname){let o=[],l=n.domainid2refpdbname[a],d=a.substr(0,a.indexOf(","));n.refpdbHash.hasOwnProperty(d)&&0==s&&(l=[d],r.bNode||console.log("Adjusted refpdbname for domainid "+a+": "+d));let c=[];for(let e=0,t=l.length;e<t;++e){let t=l[e];n.refpdbHash[t]&&(c=c.concat(n.refpdbHash[t]))}if(0==c.length)continue;for(let e=0,t=c.length;e<t;++e){let t=r.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+c[e],i=r.getAjaxPromise(t,"text");o.push(i)}let h=await this.promiseWithFixedJobs(o),p=n.domainid2pdb[a];for(let s=0,o=h.length;s<o;++s){let o=n.defaultPdbId+s,l=h[s].value;l="HEADER "+o+"\n"+l;let d={pdb_query:l,pdb_target:p,queryid:c[s]},u=r.getAjaxPostPromise(i,d);e.push(u),t.push(a+"|"+c[s])}}let o=[];return o=await this.promiseWithFixedJobs(e),a=await this.parseAlignData(o,t,!1,s),a}return this.parseAlignData_part3(o),a}parseAlignData_part3(e){let t=this.icn3d,i=t.icn3dui,s={};for(let e in t.domainid2refpdbname){if("1"==t.domainid2refpdbname[e][0].substr(0,1)){delete t.domainid2refpdbname[e],delete t.domainid2score[e];continue}let i=e.split(",")[0];s.hasOwnProperty(i)||(t.chainid2refpdbname[i]=[]),s[i]=1,t.chainid2refpdbname.hasOwnProperty(i)||(t.chainid2refpdbname[i]=[]),t.chainid2refpdbname[i].push(t.domainid2refpdbname[e][0]+"|"+e)}t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={}),t.domainid2info||(t.domainid2info={});for(let s in e){let n=e[s],r=s.split(",")[0],a=this.getTemplateList(s),o=a.refpdbname,l=a.score,d=a.seqid,c=a.nresAlign;if(o){let e="The reference PDB for domain "+s+" is "+o+". The TM-score is "+l+". The sequence identity is "+d+". The number of aligned residues is "+c+".";i.bNode||(console.log(e),i.htmlCls.clickMenuCls.setLogCmd(e,!1,!0)),t.domainid2info[s]={refpdbname:o,score:l,seqid:d,nresAlign:c}}let h,p,u,m,f,g,b=!1,C=!1,v=!1,_=!1,y=!1,S=[],w=[],x=[],A=[];for(let e=0,s=n.length;e<s;++e){let s=n[e];if(!s)continue;let a=r+"_"+s.t_start;if(-1!=s.q_start.indexOf("3550")?(b=!0,h=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]),f=0):-1!=s.q_start.indexOf("4550")?(C=!0,p=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]),++f):-1!=s.q_start.indexOf("6550")?(_=!0,u=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]),++f):-1!=s.q_start.indexOf("7550")&&(y=!0,m=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a])),s.q_start>=3545&&s.q_start<=3555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]);e&&S.push(e)}else if(s.q_start>=7545&&s.q_start<=7555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[a]);e&&w.push(e)}if(-1!=s.q_start.indexOf("8550")&&1==f&&h&&m&&(p||u)){let e=999,t=999;for(let t=0,i=S.length;t<i;++t){let i=C?p.coord.distanceTo(S[t].coord):u.coord.distanceTo(S[t].coord);i<e&&(e=i)}for(let e=0,i=w.length;e<i;++e){let i=C?p.coord.distanceTo(w[e].coord):u.coord.distanceTo(w[e].coord);i<t&&(t=i)}e=parseInt(e),t=parseInt(t);let s=C?parseInt(p.resi)-parseInt(h.resi):parseInt(u.resi)-parseInt(h.resi),n=C?parseInt(m.resi)-parseInt(p.resi):parseInt(m.resi)-parseInt(u.resi),r=1;C?(e>t+r||e==t+r&&s>n+r)&&(x.push(p.resi),i.bNode||console.log("Rename strand C' to D: distToC "+e+" distToE "+t+" resiDistToC "+s+" resiDistToE "+n)):_&&(e+r<t||e+r==t&&s+r<n)&&(A.push(u.resi),i.bNode||console.log("Rename strand D to C': distToC "+e+" distToE "+t+" resiDistToC "+s+" resiDistToE "+n))}if(b&&C&&v&&_&&y)break}for(let e=0,i=n.length;e<i;++e){let i=n[e];if(!i)continue;i.q_start;let a=parseInt(i.q_start),o="";isNaN(i.q_start)&&(o=i.q_start.substr(i.q_start.length-1,1));let l=r+"_"+i.t_start,d=a,c=this.getLabelFromRefnum(d,o);g=c?c.replace(new RegExp(d,"g"),""):void 0;let h=g;if("C'"==g&&x.length>0){for(let e=0,t=x.length;e<t;++e)if(parseInt(i.t_start)<parseInt(x[e])+10&&parseInt(i.t_start)>parseInt(x[e])-10){h="D";break}}else if("D"==g&&A.length>0)for(let e=0,t=A.length;e<t;++e)if(parseInt(i.t_start)<parseInt(A[e])+10&&parseInt(i.t_start)>parseInt(A[e])-10){h="C'";break}g!=h&&(c=this.getLabelFromRefnum(d,o,h)),"helix"!=t.firstAtomObjCls.getFirstAtomObj(t.residues[l]).ss&&(t.resid2refnum[l]=c,t.resid2domainid[l]=s)}}Object.keys(t.resid2refnum).length>0?t.bShowRefnum=!0:i.bNode||t.bNoIg||(console.log("No Ig reference numbers are assigned based on the reference structures in iCn3D..."),t.bNoIg=!0)}getStrandFromRefnum(e,t){this.icn3d.icn3dui;let i,s=parseInt(e);return i=s<1e3?void 0:s>=1200&&s<1320?"A---":s>=1320&&s<1420?"A--":s>=1420&&s<1520?"A-":s>=1520&&s<1620?"A":s>=1620&&s<1720?"A+":s>=1720&&s<1820?"A++":s>=1820&&s<2e3?"A'":s>=2e3&&s<3e3?"B":s>=3e3&&s<3420?"C--":s>=3420&&s<3520?"C-":s>=3520&&s<4e3?"C":s>=4e3&&s<5e3?"C'":s>=5e3&&s<6e3?"C''":s>=6e3&&s<7e3?"D":s>=7e3&&s<7620?"E":s>=7620&&s<8e3?"E+":s>=8e3&&s<9e3?"F":s>=9e3&&s<9620?"G":s>=9620&&s<9720?"G+":s>=9720&&s<9820?"G++":s>=9820&&s<9900?"G+++":s>9900?void 0:" ",t&&(i=t),i}getLabelFromRefnum(e,t,i){this.icn3d.icn3dui;let s=this.getStrandFromRefnum(e,i),n=e.toString();return"C'"==i&&"6"==n.substr(0,1)?n="4"+n.substr(1):"D"==i&&"4"==n.substr(0,1)&&(n="6"+n.substr(1)),s?s+n+t:void 0}async parseCustomRefFile(e){let t=this.icn3d;t.icn3dui,t.bShowCustomRefnum=!0;let i=e.split("\n");t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={});let s=[];for(let e=0,t=i.length;e<t;++e){let t=i[e].split(",");s.push(t)}for(let e=1,i=s[0].length;e<i;++e){if(!s[0][e])continue;let i=s[0][e].trim();if(i)for(let n=1,r=s.length;n<r;++n){if(!s[n][e])continue;let r=s[n][0].trim()+"_"+s[n][e].trim();t.refnum2residArray[i]?t.refnum2residArray[i].push(r):t.refnum2residArray[i]=[r]}}for(let e=1,i=s.length;e<i;++e){let i=s[e][0].trim();for(let n=1,r=s[e].length;n<r;++n){if(!s[e][n]||!s[0][n])continue;let r=s[e][n].trim(),a=s[0][n].trim();t.chainsMapping.hasOwnProperty(i)||(t.chainsMapping[i]={});let o=i+"_"+r;r&&a?(t.resid2refnum[o]=a,t.chainsMapping[i][o]=a):t.chainsMapping[i][o]=r}}await t.showAnnoCls.showAnnotations(),t.annotationCls.setAnnoViewAndDisplay("detailed view")}rmStrandFromRefnumlabel(e){return this.icn3d.icn3dui,e&&isNaN(e.substr(0,1))&&e?e.replace(/'/g,"").replace(/\*/g,"").replace(/\^/g,"").replace(/\+/g,"").replace(/\-/g,"").substr(1):e}exportRefnum(e,t){let i=this.icn3d,s=i.icn3dui,n="";if("igstrand"==e||"IgStrand"==e){if(i.bShowRefnum)for(let e in i.chains){let t=i.firstAtomObjCls.getFirstAtomObj(i.chains[e]);if(i.proteins.hasOwnProperty(t.serial)){let t=[];for(let s=0;s<i.chainsSeq[e].length;++s)t.push(i.chainsSeq[e][s].name);i.annoIgCls.showRefNum(t,e)}}let e={};for(let t in i.resid2refnum){let n=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(!n)continue;let r=s.utilsCls.residueName2Abbr(n.resn.substr(0,3)),a=i.resid2domainid[t],o=i.resid2refnum[t];if(o){let e=i.refnumCls.rmStrandFromRefnumlabel(o);i.domainid2ig2kabat[a]&&i.domainid2ig2kabat[a][e]}i.resid2refnum[t]&&(i.residIgLoop.hasOwnProperty(t)?e[t+"_"+r]=i.resid2refnum[t]+"_loop":e[t+"_"+r]=i.resid2refnum[t])}for(let t in i.structures){let s=0,r="";for(let n=0,a=i.structures[t].length;i.bShowRefnum&&n<a;++n){let a=i.structures[t][n],o=i.chain2igArray[a];if(o&&o.length>0){r+='{"'+a+'": {\n';for(let t=0,n=o.length;t<n;++t){let n=o[t].startPosArray,l=o[t].endPosArray,d=o[t].domainid,c=i.domainid2info[d];if(c){r+='"'+d+'": {\n',r+='"refpdbname":"'+c.refpdbname+'", "score":'+c.score+', "seqid":'+c.seqid+', "nresAlign":'+c.nresAlign+', "data": [';for(let t=0,s=n.length;t<s;++t){let s=n[t],o=l[t];for(let t=s;t<=o;++t){const s=a+"_"+i.chainsSeq[a][t].resi+"_"+i.chainsSeq[a][t].name;r+='{"'+s+'": "'+e[s]+'"},\n'}}r+="],\n",r+="},\n",s=1}}r+="}},\n"}}n+='{"'+t+'": {"Ig domain" : '+s+', "igs": [\n',s&&(n+=r),n+="]}},\n"}}else if("kabat"==e||"Kabat"==e){let e={};for(let t in i.resid2refnum){let n,r=i.resid2domainid[t],a=i.resid2refnum[t],o=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(!o)continue;let l=s.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(a){let e=i.refnumCls.rmStrandFromRefnumlabel(a);n=i.domainid2ig2kabat[r]?i.domainid2ig2kabat[r][e]:void 0}e[t+"_"+l]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}else if("imgt"==e||"IMGT"==e){let e={};for(let t in i.resid2refnum){let n,r=i.resid2domainid[t],a=i.resid2refnum[t],o=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(!o)continue;let l=s.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(a){let e=i.refnumCls.rmStrandFromRefnumlabel(a);n=i.domainid2ig2imgt[r]?i.domainid2ig2imgt[r][e]:void 0}e[t+"_"+l]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}if(t||(n="["+n+"]"),s.bNode)return n;{let t=Object.keys(s.utilsCls.getHlStructures()).join(",");i.saveFileCls.saveFile(t+"_refnum_"+e+".txt","text",[n])}}async promiseWithFixedJobs(e){let t=this.icn3d,i=t.icn3dui;i.bNode||i.icn3d.ParserUtilsCls.showLoading();let s=[],n=i.cfg.maxajax?i.cfg.maxajax:6*t.refpdbArray.length;for(let t=0,i=parseInt((e.length-1)/n+1);t<i;++t){let r=[];r=t==i-1?e.slice(t*n,e.length):e.slice(t*n,(t+1)*n);let a=Promise.allSettled(r),o=await a;s=s.concat(o)}return i.bNode||i.icn3d.ParserUtilsCls.hideLoading(),s}ajdustRefnum(e,t){let i=this.icn3d,s=i.icn3dui;if(!i.chainid2refpdbname[t])return!1;let n,r,a,o,l,d,c,h,p="",u="",m="",f=!1,g=!1,b=1,C=!1;if(!s.bNode){let e=s.hashUtilsCls.intHash(i.chains[t],i.hAtoms);i.firstAtomObjCls.getResiduesFromAtoms(e)}let v=[],_={},y=0,S=0,w=0,x=0,A=!1;for(let s=0,M=e.length;s<M;++s,++S,++w,++x){let e,M=i.ParserUtilsCls.getResi(t,s),T=t+"_"+M;n=i.resid2refnum[T];let E=n?n.substr(0,1):"";if(C||!n||"A"!=E&&"B"!=E||(C=!0,S=1,A=!1),"G"!=u.substr(0,1)||n||(C=!1),n){e=i.resid2domainid[T],r=i.refnumCls.rmStrandFromRefnumlabel(n),p=n.replace(new RegExp(r,"g"),""),r.substr(0,1),a=r,d=parseInt(a),c=(d-1e3*parseInt(d/1e3)).toString(),h=(d-100*parseInt(d/100)).toString(),g="9"==c.substr(0,1)||"9"==h.substr(0,1)||"0"==h.substr(0,1)||"1"==h.substr(0,1),g&&(i.residIgLoop[T]=1),l=a.replace(d.toString(),""),o=l+"_"+b;let t=parseInt(d.toString().substr(0,2));if(f="5"!=c.substr(0,1)&&"18"!=t,p&&" "!=p){if(!g||f&&!g){let t=parseInt(d.toString().substr(d.toString().length-2,2));if(p!=u&&p!=m){if(A=!1,_[p+o]&&(++b,o=a.replace(d.toString(),"")+"_"+b),_[p+o]=1,v[y]={},v[y].startResi=M,v[y].startRefnum=d,w=0,v[y].domainid=e,v[y].endResi=M,v[y].endRefnum=d,50==t&&(v[y].anchorRefnum=d,v[y].resCntBfAnchor=w,x=0,A=!0),!A&&t>=46&&t<=54){let e=t-50;v[y].anchorRefnum=d-e,v[y].resCntBfAnchor=w-e,x=e,A=!0}f&&(v[y].anchorRefnum=0),v[y].strandPostfix=l,v[y].strand=p,v[y].postfix=o,v[y].loopResCnt=S-1,++y,S=0}else if(_[p+o]){if(50==t&&(v[y-1].anchorRefnum=d,v[y-1].resCntBfAnchor=w,v[y-1].startRefnum=v[y-1].anchorRefnum-v[y-1].resCntBfAnchor,x=0,A=!0),!A&&(51==t||52==t||53==t||54==t)){let e=t-50;v[y-1].anchorRefnum=d-e,v[y-1].resCntBfAnchor=w-e,v[y-1].startRefnum=v[y-1].anchorRefnum-v[y-1].resCntBfAnchor,x=e,A=!0}f&&(v[y-1].anchorRefnum=0),v[y-1].domainid=e,v[y-1].endResi=M,v[y-1].endRefnum=d,v[y-1].resCntAtAnchor=x,v[y-1].anchorRefnum&&(v[y-1].endRefnum=v[y-1].anchorRefnum+v[y-1].resCntAtAnchor),S=0}}m=p}}u=p}for(let e=0,s=v.length;e<s;++e){let n=i.firstAtomObjCls.getFirstAtomObj(i.residues[t+"_"+v[e].startResi]),r=i.firstAtomObjCls.getFirstAtomObj(i.residues[t+"_"+v[e].endResi]),a=i.setSeqAlignCls.getPosFromResi(t,v[e].startResi),o=i.setSeqAlignCls.getPosFromResi(t,v[e].endResi);if("sheet"==n.ss&&!n.ssbegin)for(let s=1;s<=8;++s){let n=a-s,r=i.ParserUtilsCls.getResi(t,n);if(e>0&&parseInt(r)<=parseInt(v[e-1].endResi))break;let o=t+"_"+r,l=i.firstAtomObjCls.getFirstAtomObj(i.residues[o]),d=i.resid2domainid[o];if(l.ssbegin){let o=v[e].startRefnum;v[e].startResi=r,v[e].startRefnum-=s,v[e].loopResCnt-=s,v[e].loopResCnt<0&&(v[e].loopResCnt=0),v[e].resCntBfAnchor+=s;for(let l=1;l<=s;++l){n=a-l,r=i.ParserUtilsCls.getResi(t,n);let s=t+"_"+r;delete i.residIgLoop[s],i.resid2refnum[s]=v[e].strand+(o-l).toString(),i.resid2domainid[s]=d}break}}if("sheet"==r.ss&&!r.ssend)for(let n=1;n<=8;++n){let r=o+n,a=i.ParserUtilsCls.getResi(t,r);if(e<s-1&&parseInt(a)>=parseInt(v[e+1].startResi))break;let l=t+"_"+a,d=i.firstAtomObjCls.getFirstAtomObj(i.residues[l]),c=i.resid2domainid[l];if(d.ssend){let l=v[e].endRefnum;v[e].endResi=a,v[e].endRefnum+=n,e<s-1&&(v[e+1].loopResCnt-=n,v[e+1].loopResCnt<0&&(v[e+1].loopResCnt=0)),v[e].resCntAtAnchor+=n;for(let s=1;s<=n;++s){r=o+s,a=i.ParserUtilsCls.getResi(t,r);let n=t+"_"+a;delete i.residIgLoop[n],i.resid2refnum[n]=v[e].strand+(l+s).toString(),i.resid2domainid[n]=c}break}}}let M={};for(let e=v.length-1;e>=0;--e){"G"!=v[e].strand&&v[e].endRefnum-v[e].startRefnum+1<3&&(v[e+1]&&(v[e+1].loopResCnt+=v[e].loopResCnt+parseInt(v[e].endResi)-parseInt(v[e].startResi)+1),v[e].startResi,v.splice(e,1))}y=0;let T,E,R=0,k=!0,O=!0,I=0;C=!1;let P=0;if(v.length>0)for(let s=0,r=e.length;s<r;++s,++R,++P){let e,r=i.ParserUtilsCls.getResi(t,s),o=t+"_"+r;if(n=i.resid2refnum[o],p=v[y].strand,n){e=i.resid2domainid[o],a=i.refnumCls.rmStrandFromRefnumlabel(n),E=parseInt(a),T=p+E,p=n.replace(new RegExp(a,"g"),"");let t=n.substr(0,1);C||"A"!=t&&"B"!=t||(C=!0,k=!0,R=0)}let l=i.firstAtomObjCls.getFirstAtomObj(i.residues[o]);if(l&&i.proteins.hasOwnProperty(l.serial)){let t=!1,s=!1,a=!1;if(t=parseInt(r)==parseInt(v[y].startResi)&&r!=v[y].startResi?r<v[y].startResi:parseInt(r)<parseInt(v[y].startResi),a=parseInt(r)==parseInt(v[y].endResi)&&r!=v[y].endResi?r>v[y].endResi:parseInt(r)>parseInt(v[y].endResi),s=!t&&!a,t)if(i.residIgLoop[o]=1,k)C?(E=v[y].startRefnum-v[y].loopResCnt+R,T=v[y].strand+E,n=T+v[y].strandPostfix,e=v[y].domainid):(T=void 0,n=void 0);else if(I>=0&&("G"==v[I].strand.substr(0,1)||"F"==v[I].strand.substr(0,1)&&"G"!=v[y].strand.substr(0,1)))O?C&&i.resid2refnum[o]?(O=!0,E=v[I].endRefnum+R,T=v[I].strand+E,n=T+v[I].strandPostfix,e=v[I].domainid):(C=!1,k=!0,O=!1,T=void 0,n=void 0):(T=void 0,n=void 0);else{O=!0;let t=v[y].loopResCnt;R<=parseInt(t/2+.5)?v[I]&&(E=v[I].endRefnum+R,T=v[I].strand+E,n=T+v[I].strandPostfix,e=v[I].domainid):(E=v[y].startRefnum-t+R-1,T=v[y].strand+E,n=T+v[y].strandPostfix,e=v[y].domainid)}else s?(k=!1,v[y].anchorRefnum&&(r==v[y].startResi?(P=v[y].anchorRefnum-v[y].resCntBfAnchor,v[y].startRefnum=P):r==v[y].endResi&&(v[y].endRefnum=P),T=v[y].strand+P,n=T+v[y].strandPostfix,e=v[y].domainid),r==v[y].endResi&&(++y,R=0,v[y]||--y)):a&&(i.residIgLoop[o]=1,O?i.resid2refnum[o]?(O=!0,E=v[y].endRefnum+R,T=v[y].strand+E,n=T+v[y].strandPostfix,e=v[y].domainid):(O=!1,T=void 0,n=void 0):(T=void 0,n=void 0))}else n=void 0;u=p,I=y-1,M.hasOwnProperty(e)?(delete i.resid2refnum[o],delete i.residIgLoop[o],delete i.resid2domainid[o]):(i.resid2refnum[o]=n,i.resid2domainid[o]=e,a=i.refnumCls.rmStrandFromRefnumlabel(n),i.refnum2residArray.hasOwnProperty(a)?i.refnum2residArray[a].push(o):i.refnum2residArray[a]=[o],i.chainsMapping.hasOwnProperty(t)||(i.chainsMapping[t]={}),i.chainsMapping[t][o]=T||r)}return!0}}class np{constructor(e){this.icn3d=e}async applyCommandScap(e){this.icn3d.icn3dui;let t=e.substr(e.lastIndexOf(" ")+1);0==e.indexOf("scap 3d")?await this.retrieveScap(t):0==e.indexOf("scap interaction")?await this.retrieveScap(t,!0):0==e.indexOf("scap pdb")&&await this.retrieveScap(t,void 0,!0)}adjust2DWidth(e){let t,i,s,n=this.icn3d;if(n.icn3dui,e=n.pre+e,$("#"+n.pre+"dl_selectannotations").hasClass("ui-dialog-content")){t=$("#"+n.pre+"dl_selectannotations").dialog("option","width"),i=.5*$("#"+n.pre+"dl_selectannotations").dialog("option","height"),s=i,$("#"+n.pre+"dl_selectannotations").dialog("option","height",i),$("#"+e).dialog("option","width",t),$("#"+e).dialog("option","height",i);let r={my:"left top",at:"right top+"+s,of:"#"+n.pre+"viewer",collision:"none"};$("#"+e).dialog("option","position",r)}}async retrieveScap(e,t,i){let s=this.icn3d,n=s.icn3dui,r=this;s.bScap=!0;let a="",o=e.split(","),l={},d=[],c={};for(let e=0,t=o.length;e<t;++e){let i=o[e].split("_"),r=i[0]+"_"+i[1]+"_"+i[2];l=n.hashUtilsCls.unionHash(l,s.residues[r]),d.push(r),c[i[1]+"_"+i[2]]="",a+=i[1]+"_"+i[2]+"_"+i[3],e!=t-1&&(a+=",")}let h=s.resid2specCls.residueids2spec(d),p="select "+h,u=s.showInterCls.pickCustomSphere_base(10,l,s.atoms,!1,!1,void 0,p,!1),m=Object.keys(u.residues);s.hAtoms={};for(let e=0,t=m.length;e<t;++e){let t=m[e];for(let e in s.residues[t])s.hAtoms[e]=1}s.hAtoms=n.hashUtilsCls.unionHash(s.hAtoms,l),s.hAtoms=n.hashUtilsCls.exclHash(s.hAtoms,s.chemicals);let f,g=s.saveFileCls.getAtomPDB(s.hAtoms),b=n.htmlCls.baseUrl+"scap/scap.cgi",C=Object.keys(s.structures)[0],v={pdb:g,snp:a,pdbid:C,v:"2"};f=await n.getAjaxPostPromise(b,v,!0,void 0,void 0,void 0,"text");let _=f.indexOf("\n"),y=f.substr(0,_),S=f.substr(_+1);console.log("free energy: "+y+" kcal/mol");let w=n.hashUtilsCls.cloneHash(s.hAtoms);for(let e in w){let t=s.atoms[e],i=t.structure+"_"+t.chain,r=i+"_"+t.resi;s.chainsMapping.hasOwnProperty(i)||(s.chainsMapping[i]={}),s.chainsMapping[i][r]=n.utilsCls.residueName2Abbr(t.resn)+t.resi}let x=S.split("\n"),A={};for(let e in x){let t=x[e],i=t.substr(0,6);if("ATOM "===i||"HETATM"===i){let e=t.substr(20,2).trim();""===e&&(e="A");let i=e+"_"+t.substr(22,5).trim();c.hasOwnProperty(i)&&(c[i]+=t+"\n"),A[i]=1}}let M=s.saveFileCls.getAtomPDB(s.atoms,!1,!1,!1,c);s.hAtoms={};s.loadPDBCls.loadPDB(M,C,!1,!1,!0,!0);for(let e in s.residues){if(e.substr(0,e.indexOf("_"))==C+"2"){let t=C+e.substr(e.indexOf("_")),i=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(i)for(let t in s.residues[e])s.atoms[t].ss=i.ss,s.atoms[t].ssbegin=i.ssbegin,s.atoms[t].ssend=i.ssend}}for(let e in s.secondaries){if(e.substr(0,e.indexOf("_"))==C+"2"){let t=C+e.substr(e.indexOf("_"));s.secondaries[e]=s.secondaries[t]}}s.setStyleCls.setAtomStyleByOptions(s.opts),s.setColorCls.setColorByOptions(s.opts,s.hAtoms);let T={};for(let e in s.hAtoms){let t=s.atoms[e],i=t.chain+"_"+t.resi;A.hasOwnProperty(i)&&(T[e]=1)}s.hAtoms=n.hashUtilsCls.unionHash(w,T),s.dAtoms=n.hashUtilsCls.cloneHash(s.hAtoms),s.transformCls.zoominSelection(),s.setOptionCls.setStyle("proteins","stick");for(let e in T){let t=s.atoms[e];if(!t.het){let i=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi,n=s.firstAtomObjCls.getFirstAtomObj(s.residues[i]);n&&(s.atoms[e].color=n.color,s.atomPrevColors[e]=n.color)}let i=t.structure+"_"+t.chain,r=i+"_"+t.resi,a=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi;if(s.chainsMapping.hasOwnProperty(i)||(s.chainsMapping[i]={}),s.chainsMapping[i][r]=n.utilsCls.residueName2Abbr(t.resn)+t.resi,-1!=d.indexOf(a)){let e=s.firstAtomObjCls.getFirstAtomObj(s.residues[a]);s.chainsMapping[i][r]=n.utilsCls.residueName2Abbr(e.resn)+e.resi}}if(i)await r.exportPdbProfix(!1,M,a),s.drawCls.draw();else{let e=h,i="snp_"+a;if(await s.selByCommCls.selectByCommand(e,i,i),s.opts.color="atom",s.setColorCls.setColorByOptions(s.opts,s.hAtoms),s.viewInterPairsCls.clearInteractions(),t){let e="linegraph";await s.viewInterPairsCls.viewInteractionPairs(["selected"],["non-selected"],!1,e,!0,!0,!0,!0,!0,!0),r.adjust2DWidth("dl_linegraph")}s.hAtoms=s.dAtoms,s.drawCls.draw(),n.alertAlt||(n.alertAlt=!0,alert('Please press the letter "a" to alternate between wild type and mutant.'))}$("#"+s.pre+"mn2_alternateWrap").show();let E=s.pre+"selection";$("#"+E).show()}async exportPdbProfix(e,t,i){let s,n=this.icn3d,r=n.icn3dui;if(t)s=t;else{let e=r.hashUtilsCls.intHash(n.dAtoms,n.hAtoms),t=!0;s=n.saveFileCls.getAtomPDB(e,void 0,void 0,void 0,void 0,void 0,t)}let a,o=r.htmlCls.baseUrl+"scap/scap.cgi",l={pdb:s,profix:"1",hydrogen:e?"1":"0"};try{a=await r.getAjaxPostPromise(o,l,void 0,void 0,void 0,void 0,"text")}catch(e){return void alert("There are some problems in adding missing atoms or hydrogens...")}if(r.bNode)return a;{let t=Object.keys(r.utilsCls.getHlStructures()).join(","),s=e?"add_hydrogen":"add_missing_atoms";i&&(s=i),n.saveFileCls.saveFile(t+"_icn3d_"+s+".pdb","text",[a])}}}class rp{constructor(e){this.icn3d=e}async applyCommandSymd(e){this.icn3d.icn3dui,await this.retrieveSymd()}async retrieveSymd(){let e=this.icn3d,t=e.icn3dui,i=this,s=t.htmlCls.baseUrl+"symd/symd.cgi",n=t.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);n=t.hashUtilsCls.intHash(n,e.proteins);let r=Object.keys(n).length,a={};for(let t in n){let i=e.atoms[t];a[i.structure+"_"+i.chain+"_"+i.resi]=1}if(r>1e4)return void alert("The maximum number of allowed atoms is 10,000. Please try it again with smaller sets...");let o="";o+=e.saveFileCls.getAtomPDB(n);let l,d={pdb:o,pdbid:Object.keys(e.structures).toString()};try{l=await t.getAjaxPostPromise(s,d,!0);let n,r,o,c=l.rcsb_struct_symmetry,h="none";if(void 0!==c){let s;void 0!==e.rmsd_supr&&void 0!==e.rmsd_supr.rot&&(n=e.rmsd_supr.rot,r=e.rmsd_supr.trans1,o=e.rmsd_supr.trans2),void 0===e.symdArray&&(e.symdArray=[]);for(let t=0,n=c.length;t<n;++t){if("C1"==c[t].symbol)continue;h=c[t].symbol+" ","Pseudo Symmetry"==c[t].kind?h=c[t].symbol+" (pseudo)":"Global Symmetry"==c[t].kind?h=c[t].symbol+" (global)":"Local Symmetry"==c[t].kind&&(h=c[t].symbol+" (local)");let n=c[t].rotation_axes,r=[];for(let e=0,a=n.length;e<a;++e){let a=[],o=new mt(n[e].start[0],n[e].start[1],n[e].start[2]),l=new mt(n[e].end[0],n[e].end[1],n[e].end[2]);s=n[e].order,a.push(o),a.push(l);let d=i.getAxisColor(c[t].symbol,n[e].order),h=i.getPolygonColor(c[t].symbol);a.push(d),a.push(h),a.push(n[e].order),a.push("selection"),r.push(a)}let a={};a[h]=r,e.symdArray.push(a)}if(0==e.symdArray.length)$("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+l.zscore+" from the program <a href='https://symd.nci.nih.gov/' target='_blank'>SymD</a>."),t.htmlCls.dialogCls.openDlg("dl_symd","Dynamically Calculated Symmetry Using SymD");else{let n=l.seqalign.replace(/ /g,"").split(","),r=l.nres,o=l.shift,d=l.rmsd,h=Object.keys(a),p={},u={},m=[],f=[],g=0,b=0,C={};for(let e=0,i=n[0].length;e<i;++e){let i=n[0][e],s=n[1][e];if("-"!=i){if(i==i.toUpperCase()){p[h[g]]=1;let e=t.utilsCls.getIdArray(h[g]);m.push(i+" $"+e[0]+"."+e[1]+":"+e[2]);let s=e[0]+"_"+e[1];C.hasOwnProperty(s)||(C[s]=[]),C[s].push(m.length-1)}++g}if("-"!=s){if(s==s.toUpperCase()){let e=(b+o+r)%r;u[h[e]]=1;let i=t.utilsCls.getIdArray(h[e]);f.push(s+" $"+i[0]+"."+i[1]+":"+i[2])}++b}}let v={},_={},y=[],S=[],w=!1;if(1==Object.keys(C).length){w=!0;let e=parseInt(m.length/s+.5),t=Object.keys(p),i=Object.keys(u);for(let s=0;s<e;++s)v.hasOwnProperty(i[s])||(y.push(m[s]),S.push(f[s]),v[t[s]]=1,_[i[s]]=1)}else{let e,t=0;for(let i in C)C[i].length>t&&(t=C[i].length,e=i);let i=Object.keys(p),s=Object.keys(u);for(let t=0,n=C[e].length;t<n;++t){let n=C[e][t];v.hasOwnProperty(s[n])||(y.push(m[n]),S.push(f[n]),v[i[n]]=1,_[s[n]]=1)}}let x="<br>";x+="The symmetry "+c[0].symbol+" was calculated dynamically using the program <a href='https://symd.nci.nih.gov/' target='_blank'>SymD</a>. The Z score "+l.zscore+" is greater than the threshold Z score 8. The RMSD is "+d+' angstrom. <br><br>The following sequence alignment shows the residue mapping of the best aligned sets: "symOri" and "symPerm", which are also available in the menu "Analysis > Defined Sets".<br>',$("#"+e.pre+"symd_info").html(x),i.setSeqAlignForSymmetry(y,S,w);let A=!1,M=t.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(e.alnChains),void 0,void 0,A,w);x=$("#"+e.pre+"dl_sequence2").html()+M.sequencesHtml,$("#"+e.pre+"dl_sequence2").html(x),$("#"+e.pre+"dl_sequence2").width(t.htmlCls.RESIDUE_WIDTH*M.maxSeqCnt+200),t.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences from SymD");let T=Object.keys(e.defNames2Residues).length+Object.keys(e.defNames2Atoms).length,E="symOri"+T;e.selectionCls.selectResidueList(v,E,E),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(v))+" | name "+E,!1),E="symPerm"+T,e.selectionCls.selectResidueList(_,E,E),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(_))+" | name "+E,!1),E="symBoth"+T,v=t.hashUtilsCls.unionHash(v,_),e.selectionCls.selectResidueList(v,E,E),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(v))+" | name "+E,!1)}}else $("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+l.zscore+" from the program <a href='https://symd.nci.nih.gov/' target='_blank'>SymD</a>."),t.htmlCls.dialogCls.openDlg("dl_symd","Dynamically Calculated Symmetry Using SymD");e.symdtitle="none"===h?void 0:h,e.drawCls.draw()}catch(i){return $("#"+e.pre+"dl_symd").html("<br>The web service can not determine the symmetry of the input set."),t.htmlCls.dialogCls.openDlg("dl_symd","Dynamically Calculated Symmetry Using SymD"),void e.ParserUtilsCls.hideLoading()}}getResObj(e){this.icn3d.icn3dui;let t=e.substr(0,e.indexOf(" ")),i=e.indexOf("$"),s=e.indexOf("."),n=e.indexOf(":"),r=e.substr(i+1,s-i-1),a=e.substr(s+1,n-s-1),o=e.substr(n+1);return{resn:t,resid:r+"_"+a+"_"+o,resi:o,aligned:!0}}setSeqAlignForSymmetry(e,t,i){let s=this.icn3d,n=s.icn3dui;s.conservedName1="symOri_cons",s.conservedName2="symPerm_cons",s.consHash1={},s.consHash2={},s.alnChainsAnTtl={},s.alnChainsAnno={},s.alnChainsSeq={},s.alnChains={},s.alnChainsSeq={};let r={};for(let a=0,o=e.length;a<o;++a){let o,l=this.getResObj(e[a]),d=this.getResObj(t[a]),c=l.resid.substr(0,l.resid.lastIndexOf("_")),h=d.resid.substr(0,d.resid.lastIndexOf("_")),p=h;if(i){p=h.substr(0,h.indexOf("_"))+"2"+h.substr(h.indexOf("_"))}r[l.resid]=1,r[d.resid]=1,o=l.resn==d.resn?"#FF0000":"#0000FF";let u="#"+s.showAnnoCls.getColorhexFromBlosum62(l.resn,d.resn);l.color=o,d.color=o,l.color2=u,d.color2=u;for(let e in s.residues[l.resid])s.atoms[e].color=n.parasCls.thr(o),s.atomPrevColors[e]=n.parasCls.thr(o);for(let e in s.residues[d.resid])s.atoms[e].color=n.parasCls.thr(o),s.atomPrevColors[e]=n.parasCls.thr(o);void 0===s.alnChainsAnTtl[c]&&(s.alnChainsAnTtl[c]=[]);for(let e=0;e<3;++e)void 0===s.alnChainsAnTtl[c][e]&&(s.alnChainsAnTtl[c][e]=[]);for(let e=0;e<3;++e)s.alnChainsAnTtl[c][e].push("");void 0===s.alnChainsSeq[c]&&(s.alnChainsSeq[c]=[]),void 0===s.alnChainsSeq[p]&&(s.alnChainsSeq[p]=[]),s.alnChainsSeq[c].push(l),s.alnChainsSeq[p].push(d),void 0===s.alnChains[c]&&(s.alnChains[c]={}),void 0===s.alnChains[p]&&(s.alnChains[p]={}),$.extend(s.alnChains[c],s.residues[c+"_"+l.resi]),$.extend(s.alnChains[p],s.residues[p+"_"+d.resi]),s.consHash1[c+"_"+l.resi]=1,s.consHash2[p+"_"+d.resi]=1,void 0===s.alnChainsAnno[c]&&(s.alnChainsAnno[c]=[]);for(let e=0;e<3;++e)void 0===s.alnChainsAnno[c][e]&&(s.alnChainsAnno[c][e]=[]);let m=".";a%5==0&&(m="*"),a%10==0&&(m="|"),s.alnChainsAnno[c][0].push(m);let f="";a%10==0&&(f=a.toString()),s.alnChainsAnno[c][1].push(f)}}async retrieveSymmetry(e){let t,i=this.icn3d,s=i.icn3dui,n=this,r="https://data.rcsb.org/rest/v1/core/assembly/"+e+"/1";try{t=await s.getAjaxPromise(r,"json",!1)}catch(e){return $("#"+i.pre+"dl_symmetry").html("<br>This structure has no symmetry."),void s.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}let a,o,l,d=t.rcsb_struct_symmetry;if(void 0!==d){void 0!==i.rmsd_supr&&void 0!==i.rmsd_supr.rot&&(a=i.rmsd_supr.rot,o=i.rmsd_supr.trans1,l=i.rmsd_supr.trans2),i.symmetryHash={};for(let e=0,t=d.length;e<t;++e){if("C1"==d[e].symbol)continue;let t="no title";"Pseudo Symmetry"==d[e].kind?t=d[e].symbol+" (pseudo)":"Global Symmetry"==d[e].kind?t=d[e].symbol+" (global)":"Local Symmetry"==d[e].kind&&(t=d[e].symbol+" (local)");let s=d[e].rotation_axes,r=[];for(let t=0,c=s.length;t<c;++t){let c=[],h=new mt(s[t].start[0],s[t].start[1],s[t].start[2]),p=new mt(s[t].end[0],s[t].end[1],s[t].end[2]);void 0!==i.rmsd_supr&&void 0!==i.rmsd_supr.rot&&(h=i.surfaceCls.transformMemPro(h,a,o,l),p=i.surfaceCls.transformMemPro(p,a,o,l)),c.push(h),c.push(p);let u=n.getAxisColor(d[e].symbol,s[t].order),m=n.getPolygonColor(d[e].symbol);c.push(u),c.push(m),c.push(s[t].order),c.push(d[e].clusters[0].members[0].asym_id),r.push(c)}i.symmetryHash[t]=r}if(0==Object.keys(i.symmetryHash).length)$("#"+i.pre+"dl_symmetry").html("<br>This structure has no symmetry.");else{let e="<option value='none'>None</option>",t=0;for(let s in i.symmetryHash){e+="<option value='"+s+"' "+(0==t?"selected":"")+">"+s+"</option>",++t}$("#"+i.pre+"selectSymmetry").html(e)}}else $("#"+i.pre+"dl_symmetry").html("<br>This structure has no symmetry.");s.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}getPolygonColor(e){let t=this.icn3d.icn3dui,i=e.substr(0,1);return"C"==i?t.parasCls.thr(16747520):"D"==i?t.parasCls.thr(65535):"T"==i?t.parasCls.thr(15631086):"O"==i?t.parasCls.thr(16753920):"I"==i?t.parasCls.thr(65280):t.parasCls.thr(11119017)}getAxisColor(e,t){let i=this.icn3d.icn3dui,s=e.substr(0,1);return"C"==s?i.parasCls.thr(16711680):"D"==s?2==t?i.parasCls.thr(65535):i.parasCls.thr(16711680):"T"==s?2==t?i.parasCls.thr(65535):i.parasCls.thr(65280):"O"==s||"I"==s?2==t?i.parasCls.thr(65535):3==t?i.parasCls.thr(65280):i.parasCls.thr(16711680):i.parasCls.thr(16711680)}}class ap{constructor(e){this.icn3d=e}alignSW(e,t,i,s,n,r,a){this.icn3d.icn3dui;let o=this.bsa_align(a,e,t,[i,s],[n,r]),l="score: "+o[0]+"\n";l+="start: "+o[1]+"\n",l+="cigar: "+this.bsa_cigar2str(o[2])+"\n\n",l+="alignment:\n\n";let d=this.bsa_cigar2gaps(e,t,o[1],o[2]),c={};return c.score=o[0],c.start=o[1],c.cigar=this.bsa_cigar2str(o[2]),c.target=d[0],c.query=d[1],c}bsg_enc_seq(e,t){if(this.icn3d.icn3dui,null==t)return null;let i=[];i.length=e.length;for(let s=0;s<e.length;++s)i[s]=t[e.charCodeAt(s)];return i}bsa_gen_score_matrix(e,t,i){this.icn3d.icn3dui;let s,n,r=[];for(i>0&&(i=-i),s=0;s<e-1;++s){for(r[s]=[],n=0;n<e-1;++n)r[s][n]=s==n?t:i;r[s][n]=0}r[e-1]=[];for(let t=0;t<e;++t)r[e-1][t]=0;return r}bsa_gen_query_profile(e,t,i){this.icn3d.icn3dui;let s,n="string"==typeof e?this.bsg_enc_seq(e,i):e,r=[];if(t.length>=2&&"number"==typeof t[0]&&"number"==typeof t[1]){if(null==i)return null;let e="number"==typeof i?i:i[i.length-1]+1;s=this.bsa_gen_score_matrix(e,t[0],t[1])}else s=t;for(let e=0;e<s.length;++e){let t,i=s[e];t=r[e]=[];for(let e=0;e<n.length;++e)t[e]=i[n[e]]}return r}bsa_align(e,t,i,s,n,r,a){this.icn3d.icn3dui;null==a&&(a=[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,4,1,4,4,4,2,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,0,4,1,4,4,4,2,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4]);let o=this.bsg_enc_seq(t,a),l=this.bsa_gen_query_profile(i,s,a),d=l[0].length,c=d>o.length?d:o.length;r=null==r||r<0?c:r;let h,p,u=o.target>d?o.target-d:d-o.target;r=r>u?r:u,"number"==typeof n?(h=0,p=n>0?n:-n):(h=n[0]>0?n[0]:-n[0],p=n[1]>0?n[1]:-n[1]);let m,f=h+p,g=-1073741824,b=[],C=[],v=[],_=0,y=-1,S=-1;if(e)for(let e=0;e<=d;++e)b[e]=C[e]=0;else{b[0]=0,C[0]=-f-f;for(let e=1;e<=d;++e)e>=r?b[e]=C[e]=g:(b[e]=-(f+p*(e-1)),C[e]=-(f+f+p*e))}for(let t=0;t<o.length;++t){let i,s=0,n=0,a=0,c=-1,h=l[o[t]];i=v[t]=[];let u=t>r?t-r:0,m=t+r+1<d?t+r+1:d;e||(s=u>0?g:-(f+p*t),n=u>0?g:-(f+f+p*t));for(let t=u;t<m;++t){let r,o=C[t],l=b[t];b[t]=s,l+=h[t],r=l>=o?0:1,l=l>=o?l:o,r=l>=n?r:2,l=l>=n?l:n,r=!e||l>0?r:64,s=l,c=a>l?c:t,a=a>l?a:l,l-=f,l=!e||l>0?l:0,o-=p,r|=o>l?4:0,o=o>l?o:l,C[t]=o,n-=p,r|=n>l?32:0,n=n>l?n:l,i[t]=r}b[m]=s,C[m]=e?0:g,a>_&&(_=a,y=t,S=c)}if(e&&0==_)return null;m=e?_:b[d];let w,x,A,M=[],T=0,E=0;for(e?(x=y,A=S,S!=d-1&&this.push_cigar(M,4,d-1-S)):(x=o.length-1,A=(x+r+1<d?x+r+1:d)-1);x>=0&&A>=0&&(w=v[x][A-(x>r?x-r:0)],T=w>>(T<<1)&3,!(0==T&&w>>6));)0==T&&(T=3&w),0==T?(this.push_cigar(M,0,1),--x,--A):1==T?(this.push_cigar(M,2,1),--x):(this.push_cigar(M,1,1),--A);e?(A>=0&&this.push_cigar(M,4,A+1),E=x+1):(x>=0&&this.push_cigar(M,2,x+1),A>=0&&this.push_cigar(M,1,A+1));for(let e=0;e<M.length>>1;++e)w=M[e],M[e]=M[M.length-1-e],M[M.length-1-e]=w;return[m,E,M]}push_cigar(e,t,i){this.icn3d.icn3dui,0==e.length||t!=(15&e[e.length-1])?e.push(i<<4|t):e[e.length-1]+=i<<4}bsa_cigar2gaps(e,t,i,s){this.icn3d.icn3dui;let n="",r="",a="",o=0,l=i;for(let i=0;i<s.length;++i){let a=15&s[i],d=s[i]>>4;0==a?(n+=t.substr(o,d),r+=e.substr(l,d),o+=d,l+=d):1==a?(n+=t.substr(o,d),r+=Array(d+1).join("-"),o+=d):2==a?(n+=Array(d+1).join("-"),r+=e.substr(l,d),l+=d):4==a&&(o+=d)}let d=r.toUpperCase(),c=n.toUpperCase();for(let e=0;e<d.length;++e)a+=d.charAt(e)==c.charAt(e)?"|":" ";return[r,n,a]}bsa_cigar2str(e){this.icn3d.icn3dui;let t=[];for(let i=0;i<e.length;++i)t.push((e[i]>>4).toString()+"MIDNSHP=XB".charAt(15&e[i]));return t.join("")}}class op{constructor(e){this.icn3d=e}calculateArea(){var e=this.icn3d,t=e.icn3dui;e.bCalcArea=!0,e.opts.surface="solvent accessible surface",e.applyMapCls.applySurfaceOptions(),$("#"+e.pre+"areavalue").val(e.areavalue),$("#"+e.pre+"areatable").html(e.areahtml),t.htmlCls.dialogCls.openDlg("dl_area","Surface area calculation"),e.bCalcArea=!1}calcBuriedSurface(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length)alert("Please select the first set");else{let n=s.hashUtilsCls.cloneHash(i.hAtoms),r=i.definedSetsCls.getAtomsFromNameArray(e),a=i.definedSetsCls.getAtomsFromNameArray(t);i.bCalcArea=!0,i.opts.surface="solvent accessible surface",i.hAtoms=s.hashUtilsCls.cloneHash(r),i.applyMapCls.applySurfaceOptions();let o=i.areavalue,l=s.hashUtilsCls.cloneHash(i.resid2area);i.hAtoms=s.hashUtilsCls.cloneHash(a),i.applyMapCls.applySurfaceOptions();let d=i.areavalue,c=s.hashUtilsCls.cloneHash(i.resid2area);i.hAtoms=s.hashUtilsCls.unionHash(i.hAtoms,r),i.applyMapCls.applySurfaceOptions();let h=i.areavalue,p=s.hashUtilsCls.cloneHash(i.resid2area),u=0,m=0,f=0,g=0;for(let e in l)p.hasOwnProperty(e)&&(g+=parseFloat(p[e]));m=(o-g).toFixed(2);for(let e in c)p.hasOwnProperty(e)&&(f+=parseFloat(p[e]));u=(d-f).toFixed(2),i.bCalcArea=!1,i.hAtoms=s.hashUtilsCls.cloneHash(n);let b=(parseFloat(d)+parseFloat(o)-parseFloat(h)).toFixed(2),C="<br>Calculate solvent accessible surface area in the interface:<br><br>";C+="Set 1: "+e+", Surface: "+o+" Å<sup>2</sup><br>",C+="Set 2: "+t+", Surface: "+d+" Å<sup>2</sup><br>",C+="Total Surface: "+h+" Å<sup>2</sup><br>",C+="<b>Buried Surface for Set 1</b>: "+m+" Å<sup>2</sup><br>",C+="<b>Buried Surface for Set 2</b>: "+u+" Å<sup>2</sup><br><br>",$("#"+i.pre+"dl_buriedarea_html").html(C),s.htmlCls.dialogCls.openDlg("dl_buriedarea","Buried solvent accessible surface area in the interface"),s.htmlCls.clickMenuCls.setLogCmd("buried surface "+b,!1)}}measureDistTwoSets(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length||0==t.length)alert("Please select two sets");else{let n=s.hashUtilsCls.cloneHash(i.hAtoms),r=i.definedSetsCls.getAtomsFromNameArray(e),a=i.definedSetsCls.getAtomsFromNameArray(t),o=i.contactCls.getExtent(r),l=i.contactCls.getExtent(a),d=new mt(o[2][0],o[2][1],o[2][2]),c=new mt(l[2][0],l[2][1],l[2][2]);i.hAtoms=s.hashUtilsCls.cloneHash(n),void 0===i.distPnts&&(i.distPnts=[]),i.distPnts.push(d),i.distPnts.push(c);let h=$("#"+i.pre+"distancecolor2").val();this.addLine(d.x,d.y,d.z,c.x,c.y,c.z,h,!0,"distance");let p=0,u=0,m=d.clone().add(c).multiplyScalar(.5),f=(parseInt(10*d.distanceTo(c))/10).toString()+" A";this.addLabel(f,m.x,m.y,m.z,p,h,u,"distance"),i.drawCls.draw()}}measureDistManySets(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for distance calculation...");else{let n=s.hashUtilsCls.cloneHash(i.hAtoms),r={};for(let s=0,n=e.length;s<n;++s){let n=e[s],a=[n];r[n]={};for(let e=0,s=t.length;e<s;++e){let s=t[e],o=[s];if(n==s)continue;let l=i.definedSetsCls.getAtomsFromNameArray(a),d=i.definedSetsCls.getAtomsFromNameArray(o),c=i.contactCls.getExtent(l),h=i.contactCls.getExtent(d),p=new mt(c[2][0],c[2][1],c[2][2]),u=new mt(h[2][0],h[2][1],h[2][2]),m=p.distanceTo(u);r[n][s]=m.toFixed(2)}}i.hAtoms=s.hashUtilsCls.cloneHash(n);let a="Note: Click on the distance to show a dashed line in 3D view.<br><br>";a+="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,i=t.length;e<i;++e){a+="<th><b>"+t[e]+"</b> (Å)</th>"}a+="</tr>";for(let i=0,s=e.length;i<s;++i){let s=e[i];a+="<tr><th><b>"+s+"</b> (Å)</th>";for(let e=0,i=t.length;e<i;++e){let i=t[e];r[s]&&r[s][i]?a+='<td><span class="icn3d-distance" sets="'+s+"|"+i+'">'+r[s][i]+"</span></td>":a+="<td>0</td>"}a+="</tr>"}a+="</table><br><br>",$("#"+s.pre+"dl_disttable_html").html(a)}}measureAngleManySets(e,t){var i=this.icn3d,s=i.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for angleance calculation...");else{let n={};for(let s=0,r=e.length;s<r;++s){let r=e[s],a=[r];n[r]={},i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(a);let o=i.axesCls.setPc1Axes(!0);for(let e=0,s=t.length;e<s;++e){let s=t[e],a=[s];if(r==s)continue;i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(a);let l=i.axesCls.setPc1Axes(!0),d=new mt(parseFloat(o.x),parseFloat(o.y),parseFloat(o.z)).angleTo(new mt(parseFloat(l.x),parseFloat(l.y),parseFloat(l.z)))/3.1416*180;d=Math.abs(d).toFixed(0),d>180&&(d-=180),d>90&&(d=180-d),n[r][s]=d}}let r="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,i=t.length;e<i;++e){r+="<th><b>"+t[e]+"</b> (°)</th>"}r+="</tr>";for(let i=0,s=e.length;i<s;++i){let s=e[i];r+="<tr><th><b>"+s+"</b> (°)</th>";for(let e=0,i=t.length;e<i;++e){let i=t[e];n[s]&&n[s][i]?r+="<td><span>"+n[s][i]+"</span></td>":r+="<td>0</td>"}r+="</tr>"}r+="</table><br><br>",$("#"+s.pre+"dl_angletable_html").html(r)}}addLine(e,t,i,s,n,r,a,o,l,d,c){var h=this.icn3d;h.icn3dui;let p={};p.position1=new mt(e,t,i),p.position2=new mt(s,n,r),p.color=a,p.dashed=o,p.radius=d,p.opacity=c,void 0===h.lines[l]&&(h.lines[l]=[]),void 0!==l?h.lines[l].push(p):(void 0===h.lines.custom&&(h.lines.custom=[]),h.lines.custom.push(p)),h.hlObjectsCls.removeHlObjects()}addLineFromPicking(e){var t=this.icn3d,i=t.icn3dui;let s=$("#"+t.pre+e+"color").val();t.pAtom.coord.x,t.pAtom2.coord.x,t.pAtom.coord.y,t.pAtom2.coord.y,t.pAtom.coord.z,t.pAtom2.coord.z;let n="stabilizer"!=e;i.htmlCls.clickMenuCls.setLogCmd("add line | x1 "+t.pAtom.coord.x.toPrecision(4)+" y1 "+t.pAtom.coord.y.toPrecision(4)+" z1 "+t.pAtom.coord.z.toPrecision(4)+" | x2 "+t.pAtom2.coord.x.toPrecision(4)+" y2 "+t.pAtom2.coord.y.toPrecision(4)+" z2 "+t.pAtom2.coord.z.toPrecision(4)+" | color "+s+" | dashed "+n+" | type "+e,!0),this.addLine(t.pAtom.coord.x,t.pAtom.coord.y,t.pAtom.coord.z,t.pAtom2.coord.x,t.pAtom2.coord.y,t.pAtom2.coord.z,s,n,e),t.pickpair=!1}addLabel(e,t,i,s,n,r,a,o){var l=this.icn3d;l.icn3dui;let d={};"0"!==n&&""!==n&&"undefined"!==n||(n=void 0),"0"!==r&&""!==r&&"undefined"!==r||(r=void 0),"0"!==a&&""!==a&&"undefined"!==a||(a=void 0);let c=new mt;c.x=t,c.y=i,c.z=s,d.position=c,d.text=e,d.size=n,d.color=r,d.background=a,void 0===l.labels[o]&&(l.labels[o]=[]),void 0!==o?l.labels[o].push(d):(void 0===l.labels.custom&&(l.labels.custom=[]),l.labels.custom.push(d)),l.hlObjectsCls.removeHlObjects()}addChainLabels(e){var t=this.icn3d;let i=t.icn3dui.hashUtilsCls.intHash(t.hAtoms,e);void 0===t.labels.chain&&(t.labels.chain=[]);let s=t.firstAtomObjCls.getChainsFromAtoms(i);for(let e in s){let i={};i.position=t.applyCenterCls.centerAtoms(t.chains[e]).center;let s=e.indexOf("_"),n=e.substr(s+1),r=t.showSeqCls.getProteinName(e);r.length>20&&(r=r.substr(0,20)+"..."),i.text="Chain "+n+": "+r,i.size=18,t.firstAtomObjCls.getFirstCalphaAtomObj(t.chains[e]).color.getHexString().toUpperCase(),i.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,i.background="#FFFFFF",t.labels.chain.push(i)}t.hlObjectsCls.removeHlObjects()}addTerminiLabels(e){var t=this.icn3d,i=t.icn3dui;let s,n="#FFFFFF";s=i.hashUtilsCls.unionHash(s,t.proteins),s=i.hashUtilsCls.unionHash(s,t.nucleotides);let r=i.hashUtilsCls.intHash(t.dAtoms,s),a=i.hashUtilsCls.intHash(r,e);void 0===t.labels.chain&&(t.labels.chain=[]);let o=t.firstAtomObjCls.getChainsFromAtoms(a);for(let e in o){let s=i.hashUtilsCls.intHash(r,t.chains[e]),a=Object.keys(s),o=t.atoms[a[0]],l=t.atoms[a[a.length-1]],d={},c={};d.position=o.coord,c.position=l.coord,d.text="N-",c.text="C-",t.nucleotides.hasOwnProperty(o.serial)&&(d.text="5'",c.text="3'"),d.size=18,c.size=18,o.color.getHexString().toUpperCase(),l.color.getHexString().toUpperCase(),d.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,c.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,d.background=n,c.background=n,t.labels.chain.push(d),t.labels.chain.push(c)}t.hlObjectsCls.removeHlObjects()}}class lp{constructor(e){this.icn3d=e}draw2Ddgm(e,t,i,s){let n=this.icn3d,r=n.icn3dui,a=.667,o={},l={},d={},c={},h={};if(void 0===e)return"";for(let i in e.moleculeInfor){let s="#"+("000000"+e.moleculeInfor[i].color.toString(16)).slice(-6),r=e.moleculeInfor[i].chain.trim();void 0===h[r]?h[r]=1:++h[r];let a=t+"_"+(1===h[r]?r:r+h[r].toString());void 0!==n.mmdbid_q&&(n.mmdbid_q,n.mmdbid_t),o[i]=a,l[i]=s,d[i]=e.moleculeInfor[i].name,c[a]=i}if(void 0===s||!s)for(let i=0,s=e.intracResidues.length;i<s;++i){let s,r,a=e.intracResidues[i],l=0;for(let e in a){let t;t=o[e],0===l?s=t:r=t,++l}if(void 0!==s&&void 0!==r){l=0;for(let e in a){let i,o,d=a[e];0===l?(i=s,o=r):(i=r,o=s),void 0===n.chainids2resids[i]&&(n.chainids2resids[i]={}),void 0===n.chainids2resids[i][o]&&(n.chainids2resids[i][o]=[]);for(let s=0,r=d.length;s<r;++s){let r=d[s],a=n.mmdbMolidResid2mmdbChainResi[t.toUpperCase()+"_"+e+"_"+r];n.chainids2resids[i][o].push(a)}if(void 0===n.chainname2residues&&(n.chainname2residues={}),r=o,!n.chains.hasOwnProperty(r))continue;let c,h=n.firstAtomObjCls.getFirstCalphaAtomObj(n.chains[r]);n.chemicals.hasOwnProperty(h.serial)?c="chemical":n.nucleotides.hasOwnProperty(h.serial)?c="nucleotide":n.ions.hasOwnProperty(h.serial)?c="ion":n.proteins.hasOwnProperty(h.serial)?c="protein":n.water.hasOwnProperty(h.serial)&&(c="water");let p=r.substr(r.indexOf("_")+1)+"("+c+")";void 0===n.chainname2residues[i]&&(n.chainname2residues[i]={}),n.chainname2residues[i][p]=n.chainids2resids[i][o],++l}}}let p="<div id='#"+n.pre+t+"'>";p+="<b>"+t.toUpperCase()+"</b><br/>",p+="<svg viewBox='0,0,"+r.htmlCls.width2d+","+r.htmlCls.width2d+"'>";let u="#000000",m={},f=[],g="",b="",C={};if(s)for(let e in n.dAtoms){let t=n.atoms[e];C[c[t.structure+"_"+t.chain]]=1}let v=Object.keys(e.moleculeInfor),_=Object.keys(e.intrac),y=[];for(let e=0,t=v.length;e<t;++e)-1===_.indexOf(v[e])&&y.push(v[e]);let S={};if(y.length>0)for(let t in e.intrac){let i=e.intrac[t];for(let e=0,s=i.intrac.length;e<s;++e){let s=i.intrac[e].toString();-1!==y.indexOf(s)&&(void 0===S[s]&&(S[s]=[]),S[s].push(t),f.push([s,t]))}if("rect"===i.shape){let e=i.coords[0]*a,s=i.coords[1]*a,n=i.coords[2]*a-e,r=i.coords[3]*a-s;m[t]=[e+n/2,s+r/2]}else if("circle"===i.shape){let e=i.coords[0]*a,s=i.coords[1]*a;i.coords[2],m[t]=[e,s]}else if("poly"===i.shape){let e=i.coords[0]*a;i.coords[1],i.coords[2];let s=i.coords[3]*a;i.coords[4],i.coords[5],i.coords[6],i.coords[7],m[t]=[e,s]}}let w=0;for(let t=0,r=v.length;t<r;++t){let r=v[t],c=o[r];if(s&&!C.hasOwnProperty(r))continue;let h=e.intrac[r],p="#FFFFFF",u=l[r];if(void 0!==c&&void 0!==n.chains[c]){let e=Object.keys(n.chains[c]);e.length>0&&(u="#"+n.atoms[e[0]].color.getHexString().toUpperCase())}let _="";n.bInitial&&void 0!==i&&(void 0!==n.alignmolid2color&&n.alignmolid2color[i].hasOwnProperty(r)?(_=n.alignmolid2color[i][r],u="#FF0000"):u="#FFFFFF");let x=d[r],A=" ",M=" ";if(void 0!==c){let e=c.indexOf("_");M=c.substr(e+1),A=M.length>1?M.substr(0,1)+"..":M}else c="Misc";void 0===u&&(u="#FFFFFF");let T=1;if(n.bInitial&&void 0!==n.alnChains[c]){let e=0;for(let t in n.alnChains[c]){let i=n.atoms[t].color.getHexString().toUpperCase();"FF0000"!==i&&"00FF00"!==i||++e}T=1*e/Object.keys(n.chains[c]).length}if(T<.2&&(T=.2),-1===y.indexOf(r)){for(let e=0,t=h.intrac.length;e<t;++e)parseInt(r)<parseInt(h.intrac[e])&&f.push([r,h.intrac[e]]);if("rect"===h.shape){let e=h.coords[0]*a,t=h.coords[1]*a,i=h.coords[2]*a-e,s=h.coords[3]*a-t;g+=this.draw2DNucleotide(e+.5*i,t+.5*s,c,M,A,x,_,p,u,a,T),m[r]=[e+i/2,t+s/2]}else if("circle"===h.shape){let e=h.coords[0]*a,t=h.coords[1]*a;g+=this.draw2DProtein(e,t,c,M,A,x,_,p,u,a,T),m[r]=[e,t]}else if("poly"===h.shape){let e=h.coords[0]*a;h.coords[1],h.coords[2];let t=h.coords[3]*a;h.coords[4],h.coords[5],h.coords[6],h.coords[7];let i=e,s=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]),b+=this.draw2DChemical(i,s,c,M,A,x,_,p,u,a,T),m[r]=[e,t]}}else{let e,t,i=300,s=50;if(void 0!==S[r]&&S[r].length>1){let i=0,s=0;for(let e=0,t=S[r].length;e<t;++e){let t=S[r][e];if(m.hasOwnProperty(t)){let e=m[t];i+=e[0],s+=e[1]}}e=i/S[r].length,t=s/S[r].length}else{let n=i/s;w<n-1?(e=(w+1)*s*a,t=.1*i*a):w-(n-1)<n-1?(e=.1*i*a,t=(w-(n-1)+1)*s*a):(e=.25*i*a,t=e),++w}let o=e,l=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]);let d=!0;b+=this.draw2DChemical(o,l,c,M,A,x,_,p,u,a,T,d),m[r]=[o,l]}}for(let e=0,t=f.length;e<t;++e){let t=f[e];if(s&&(!C.hasOwnProperty(t[0])||!C.hasOwnProperty(t[1])))continue;let i,n,r=m[parseInt(t[0])],a=m[parseInt(t[1])];if(void 0===r||void 0===a)continue;i=o[t[0]],n=o[t[1]];let l=i.indexOf("_"),d=n.indexOf("_"),c=i.substr(l+1),h=n.substr(d+1),g=r[0],b=r[1],v=a[0],_=a[1],y=.5*(g+v),S=.5*(b+_);p+="<g class='icn3d-interaction' chainid1='"+i+"' chainid2='"+n+"' >",p+="<title>Interaction of chain "+c+" with chain "+h+"</title>",p+="<line x1='"+g+"' y1='"+b+"' x2='"+y+"' y2='"+S+"' stroke='"+u+"' stroke-width='2' /></g>",p+="<g class='icn3d-interaction' chainid1='"+n+"' chainid2='"+i+"' >",p+="<title>Interaction of chain "+h+" with chain "+c+"</title>",p+="<line x1='"+y+"' y1='"+S+"' x2='"+v+"' y2='"+_+"' stroke='"+u+"' stroke-width='2' /></g>"}return p+=b+g,p+="</svg>",p+="</div>",n.html2ddgm+=p,$("#"+n.pre+"dl_2ddgm_html").html(n.html2ddgm),p}set2DdgmNote(e){let t="<div style='width:150px'><b>Nodes</b>:<br>";return this.icn3d.icn3dui.utilsCls.isMac()?(t+="<span style='margin-right:18px;'>◯</span>Protein<br>",t+="<span style='margin-right:18px;'>▢</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>♢</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>▢</span>Biopolymer<br>"):(t+="<span style='margin-right:18px;'>O</span>Protein<br>",t+="<span style='margin-right:18px;'>▢</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>◇</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>▢</span>Biopolymer<br>"),t+="<br><b>Lines</b>:<br> Interactions at 4 Å<br>",e&&(t+="<b>Numbers in red</b>:<br> Aligned chains"),t+="</div><br/>",t}highlightNode(e,t,i,s){let n=this.icn3d.icn3dui;s<.2&&(s=.2);if("rect"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(i).attr("x")),r=Number($(i).attr("y")),a=Number($(i).attr("width")),o=Number($(i).attr("height"));$(t).attr("x",e+a/2*(1-s)),$(t).attr("y",r+o/2*(1-s)),$(t).attr("width",a*s),$(t).attr("height",o*s)}else if("circle"===e)$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3),$(t).attr("r",Number($(i).attr("r"))*s);else if("polygon"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(i).attr("x")),r=Number($(i).attr("y")),a=Number($(i).attr("x0d")),o=Number($(i).attr("y0d")),l=Number($(i).attr("x1d")),d=Number($(i).attr("y1d")),c=Number($(i).attr("x2d")),h=Number($(i).attr("y2d")),p=Number($(i).attr("x3d")),u=Number($(i).attr("y3d"));$(t).attr("points",(e+a*s).toString()+", "+(r+o*s).toString()+", "+(e+l*s).toString()+", "+(r+d*s).toString()+", "+(e+c*s).toString()+", "+(r+h*s).toString()+", "+(e+p*s).toString()+", "+(r+u*s).toString())}}removeLineGraphSelection(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"dl_linegraph circle").attr("stroke","#000000"),$("#"+e.pre+"dl_linegraph circle").attr("stroke-width",1),$("#"+e.pre+"dl_linegraph svg line.icn3d-hlline").attr("stroke","#FFF")}removeScatterplotSelection(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"dl_scatterplot circle").attr("stroke","#000000"),$("#"+e.pre+"dl_scatterplot circle").attr("stroke-width",1),$("#"+e.pre+"dl_scatterplot rect").attr("stroke","#000000"),$("#"+e.pre+"dl_scatterplot rect").attr("stroke-width",1)}click2Ddgm(){let e=this.icn3d,t=e.icn3dui,i=this;$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-node",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n=$(this).attr("chainid");s.bCtrl||s.bShift||(s.selectionCls.removeSelection(),s.lineArray2d=[]);let r=1;void 0!==s.alnChains[n]&&(r=1*Object.keys(s.alnChains[n]).length/Object.keys(s.chains[n]).length);let a=$(this).find("rect[class='icn3d-hlnode']"),o=$(this).find("rect[class='icn3d-basenode']");i.highlightNode("rect",a,o,r),a=$(this).find("circle[class='icn3d-hlnode']"),o=$(this).find("circle[class='icn3d-basenode']"),i.highlightNode("circle",a,o,r),a=$(this).find("polygon[class='icn3d-hlnode']"),o=$(this).find("polygon[class='icn3d-basenode']"),i.highlightNode("polygon",a,o,r),s.bCtrl||s.bShift?s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.chains[n]):s.hAtoms=t.hashUtilsCls.cloneHash(s.chains[n]),s.bCtrl||s.bShift?(void 0===s.chainArray2d&&(s.chainArray2d=[]),s.chainArray2d.push(n)):s.chainArray2d=[n],s.hlUpdateCls.updateHlAll(s.chainArray2d),s.annotationCls.showAnnoSelectedChains();let l="select chain "+n;t.htmlCls.clickMenuCls.setLogCmd(l,!0),s.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-interaction",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection"),s.bClickInteraction=!0;let n=$(this).attr("chainid1"),r=$(this).attr("chainid2");$(this).find("line").attr("stroke",t.htmlCls.ORANGE),i.selectInteraction(n,r),s.annotationCls.showAnnoSelectedChains();let a="select interaction "+n+","+r;t.htmlCls.clickMenuCls.setLogCmd(a,!0),s.bClickInteraction=!1})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-node",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n=$(this).attr("resid");s.bCtrl||s.bShift||(s.hAtoms={},i.removeLineGraphSelection());$(this).find("circle").attr("stroke",t.htmlCls.ORANGE),$(this).find("circle").attr("stroke-width",2),s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.residues[n]);let r="select "+s.resid2specCls.residueids2spec([n]);s.hlUpdateCls.updateHlAll(),t.htmlCls.clickMenuCls.setLogCmd(r,!0),s.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-interaction",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n=$(this).attr("resid1"),r=$(this).attr("resid2");s.bCtrl||s.bShift||(s.hAtoms={},i.removeLineGraphSelection()),$(this).find("line.icn3d-hlline").attr("stroke",t.htmlCls.ORANGE);$("[resid="+n+"]").find("circle").attr("stroke",t.htmlCls.ORANGE),$("[resid="+n+"]").find("circle").attr("stroke-width",2),$("[resid="+r+"]").find("circle").attr("stroke",t.htmlCls.ORANGE),$("[resid="+r+"]").find("circle").attr("stroke-width",2),s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.residues[n]),s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,s.residues[r]);let a="select "+s.resid2specCls.residueids2spec([n,r]);s.hlUpdateCls.updateHlAll(),s.transformCls.zoominSelection(),t.htmlCls.clickMenuCls.setLogCmd(a,!0)})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-interaction",(function(e){let t=i.icn3d;e.stopImmediatePropagation(),i.clickInteraction(this),t.transformCls.zoominSelection()})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-interaction",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-interaction",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-interaction",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-node",(function(e){i.icn3d,e.stopImmediatePropagation(),i.clickNode(this)}))}clickNode(e){let t=this.icn3d,i=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let s=$(e).attr("resid");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("circle").attr("stroke",i.htmlCls.ORANGE),$(e).find("circle").attr("stroke-width",2),$(e).find("rect").attr("stroke",i.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[s]);let n="select "+t.resid2specCls.residueids2spec([s]);t.hlUpdateCls.updateHlAll(),i.htmlCls.clickMenuCls.setLogCmd(n,!0),t.bSelectResidue=!1}clickInteraction(e){let t=this.icn3d,i=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let s=$(e).attr("resid1"),n=$(e).attr("resid2");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("rect").attr("stroke",i.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[s]),t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[n]);let r="select "+t.resid2specCls.residueids2spec([s,n]);t.hlUpdateCls.updateHlAll(),i.htmlCls.clickMenuCls.setLogCmd(r,!0)}selectInteraction(e,t){let i=this.icn3d;i.icn3dui,i.hlUpdateCls.removeHl2D(),i.hlObjectsCls.removeHlObjects(),i.bCtrl||i.bShift?(void 0===i.lineArray2d&&(i.lineArray2d=[]),i.lineArray2d.push(e),i.lineArray2d.push(t)):i.lineArray2d=[e,t],this.selectInteractionAtoms(e,t),i.hlObjectsCls.addHlObjects(),i.hlUpdateCls.updateHlAll()}selectInteractionAtoms(e,t){let i,s,n=this.icn3d,r=n.icn3dui,a=n.chainids2resids[e][t];n.bCtrl||n.bShift||(n.hAtoms={});for(let e=0,t=a.length;e<t;++e)n.hAtoms=r.hashUtilsCls.unionHash(n.hAtoms,n.residues[a[e]]);if(Object.keys(n.structures).length>1)i="inter_"+e+"_"+t;else{let s=e.indexOf("_"),n=t.indexOf("_");i="inter_"+e.substr(s+1)+"_"+t.substr(n+1)}s="select the atoms in chain "+e+" interacting with chain "+t+" in a distance of 4 angstrom";let o="select interaction "+e+","+t;n.selectionCls.addCustomSelection(a,i,s,o,!0)}draw2DProtein(e,t,i,s,n,r,a,o,l,d,c){this.icn3d.icn3dui;let h="#000000",p=20*d,u="<g class='icn3d-node' chainid='"+i+"' >";return u+="<title>Chain "+s+": "+r+"</title>",u+="<circle class='icn3d-basenode' cx='"+e+"' cy='"+t+"' r='"+p+"' fill='"+o+"' stroke-width='1' stroke='"+h+"' class='icn3d-node' chainid='"+i+"' />",u+="<circle class='icn3d-hlnode' cx='"+e+"' cy='"+t+"' r='"+(p*c).toString()+"' fill='"+l+"' stroke-width='1' stroke='"+h+"' />",u+="<text x='"+(e-0).toString()+"' y='"+(t+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==a&&(u+="<text x='"+(e-0).toString()+"' y='"+(t+p+4+6).toString()+"' style='fill:"+l+"; font-size:8; font-weight:bold; text-anchor:middle' >"+a+"</text>"),u+="</g>",u}draw2DNucleotide(e,t,i,s,n,r,a,o,l,d,c){this.icn3d.icn3dui;let h="#000000",p=30*d,u=30*d,m="<g class='icn3d-node' chainid='"+i+"' >";return m+="<title>Chain "+s+": "+r+"</title>",m+="<rect class='icn3d-basenode' x='"+(e-=.5*p)+"' y='"+(t-=.5*u)+"' width='"+p+"' height='"+u+"' fill='"+o+"' stroke-width='1' stroke='"+h+"' />",m+="<rect class='icn3d-hlnode' x='"+(e+p/2*(1-c)).toString()+"' y='"+(t+u/2*(1-c)).toString()+"' width='"+(p*c).toString()+"' height='"+(u*c).toString()+"' fill='"+l+"' stroke-width='1' stroke='"+h+"' />",m+="<text x='"+(e+p/2-0).toString()+"' y='"+(t+u/2+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==a&&(m+="<text x='"+(e+p/2-0).toString()+"' y='"+(t+u+4+6).toString()+"' style='fill:"+l+"; font-size:8; font-weight:bold; text-anchor:middle' >"+a+"</text>"),m+="</g>",m}draw2DChemical(e,t,i,s,n,r,a,o,l,d,c,h){this.icn3d.icn3dui;let p,u,m,f,g,b,C,v,_="#000000",y=30*d;if(h){let i=.5*y/Math.sqrt(3),s=.5*y;p=e-i,u=t-s,m=e+3*i,f=t-s,g=e+i,b=t+s,C=e-3*i,v=t+s}else{let i=.5*y,s=.5*y;p=e-i,u=t,m=e,f=t+s,g=e+i,b=t,C=e,v=t-s}let S=p-e,w=u-t,x=m-e,A=f-t,M=g-e,T=b-t,E=C-e,R=v-t,k="<g class='icn3d-node' chainid='"+i+"' >";return k+="<title>Chain "+s+": "+r+"</title>",k+="<polygon class='icn3d-basenode' points='"+p+", "+u+","+m+", "+f+","+g+", "+b+","+C+", "+v+"' x='"+e+"' y='"+t+"' x0d='"+S+"' y0d='"+w+"' x1d='"+x+"' y1d='"+A+"' x2d='"+M+"' y2d='"+T+"' x3d='"+E+"' y3d='"+R+"' fill='"+o+"' stroke-width='1' stroke='"+_+"' />",k+="<polygon class='icn3d-hlnode' points='"+(e+S*c).toString()+", "+(t+w*c).toString()+","+(e+x*c).toString()+", "+(t+A*c).toString()+","+(e+M*c).toString()+", "+(t+T*c).toString()+","+(e+E*c).toString()+", "+(t+R*c).toString()+"' fill='"+l+"' stroke-width='1' stroke='"+_+"' />",k+="<text x='"+(e+1).toString()+"' y='"+(t+2).toString()+"' style='fill:#000000; font-size:8; text-anchor:middle' >"+n+"</text>",""!==a&&(k+="<text x='"+(e+1).toString()+"' y='"+(t+2+6).toString()+"' style='fill:"+l+"; font-size:8; font-weight:bold; text-anchor:middle' >"+a+"</text>"),k+="</g>",k}}class dp{constructor(e){this.icn3d=e}async draw2Dcartoon(e,t){let i=this.icn3d,s=i.icn3dui,n=this;if(s.htmlCls.clickMenuCls.setLogCmd("cartoon 2d "+e,!0),i.cartoon2dType=e,t){let t=n.getCartoonSvg(e,i.graphStr);$("#"+s.svgid_ct).html(t)}else{await this.getNodesLinksForSetCartoon(e),i.graphStr=n.getCartoonData(e,i.node_link);let t=n.getCartoonSvg(e,i.graphStr);$("#"+s.svgid_ct).html(t),n.setEventsForCartoon2d(),s.htmlCls.dialogCls.openDlg("dl_2dctn","2D Cartoon")}}getCartoonSvg(e,t){let i=this.icn3d,s=i.icn3dui,n="",r="",a=JSON.parse(t);i.ctnNodeHash={};for(let t=0,s=a.nodes.length;t<s;++t){let s=a.nodes[t];i.ctnNodeHash[s.id]=s,r+="secondary"==e?this.drawHelix(e,s.id,s.ss,s.x,s.y,s.x1,s.y1,s.x2,s.y2,s.len,s.ang,s.c):this.drawOval(e,s.id,s.x,s.y,s.rx,s.ry,s.ang,s.c,s.from,s.to)}i.nodeid2lineid={};for(let t=0,r=a.links.length;t<r;++t){let r=a.links[t].source,o=a.links[t].target,l=i.ctnNodeHash[r].x,d=s.htmlCls.width2d-i.ctnNodeHash[r].y,c=i.ctnNodeHash[o].x,h=s.htmlCls.width2d-i.ctnNodeHash[o].y;"chain"==e?n+="<g class='icn3d-ctinteraction' chainid1='"+i.ctnNodeHash[r].id+"' chainid2='"+i.ctnNodeHash[o].id+"' >":"domain"==e?n+="<g class='icn3d-ctinteraction' from1='"+i.ctnNodeHash[r].from+"' to1='"+i.ctnNodeHash[r].to+"' from2='"+i.ctnNodeHash[o].from+"' to2='"+i.ctnNodeHash[o].to+"' >":"secondary"==e&&(l=i.ctnNodeHash[r].x2,d=s.htmlCls.width2d-i.ctnNodeHash[r].y2,c=i.ctnNodeHash[o].x1,h=s.htmlCls.width2d-i.ctnNodeHash[o].y1,n+="<g class='icn3d-ctinteraction' range1='"+i.ctnNodeHash[r].range+"' range2='"+i.ctnNodeHash[o].range+"' >");let p=r+"--"+o;n+="<title>Interaction of "+e+" "+this.getLabelFromId(r,e)+" with "+e+" "+this.getLabelFromId(o,e)+"</title>",n+="<line class='icn3d-edge' id='"+p+"' x1='"+l+"' y1='"+d+"' x2='"+c+"' y2='"+h+"' stroke='#bbbbbb' stroke-width='1' /></g>",i.nodeid2lineid.hasOwnProperty(r)||(i.nodeid2lineid[r]=[]),i.nodeid2lineid.hasOwnProperty(o)||(i.nodeid2lineid[o]=[]),i.nodeid2lineid[r].push(p),i.nodeid2lineid[o].push(p)}return n+=r,n}setEventsForCartoon2d(){let e=this.icn3d,t=e.icn3dui;$("#"+t.svgid_ct+" .icn3d-ctnode").draggable({start:function(e,t){let i=parseFloat(e.target.getAttribute("cx")),s=parseFloat(e.target.getAttribute("cy"));e.target.setAttribute("cx",i),e.target.setAttribute("cy",s);let n=e.target.getAttribute("ang");if(n)e.target.setAttribute("transform","rotate("+n+","+i+","+s+")");else{let t=parseFloat(e.target.getAttribute("x1")),i=parseFloat(e.target.getAttribute("y1")),s=parseFloat(e.target.getAttribute("x2")),n=parseFloat(e.target.getAttribute("y2"));e.target.setAttribute("x1",t),e.target.setAttribute("y1",i),e.target.setAttribute("x2",s),e.target.setAttribute("y2",n)}},drag:function(i,s){let n=$("#"+t.svgid_ct).offset().left,r=$("#"+t.svgid_ct).offset().top,a=i.target.getAttribute("id"),o=i.target.getAttribute("ang"),l=i.clientX-n,d=i.clientY-r,c=parseFloat(i.target.getAttribute("cx")),h=parseFloat(i.target.getAttribute("cy")),p=(l-c)/e.resizeRatioX,u=(d-h)/e.resizeRatioY,m=parseFloat($("#"+a+"_text").attr("x")),f=parseFloat($("#"+a+"_text").attr("y"));if($("#"+a+"_text").attr("x",m+p),$("#"+a+"_text").attr("y",f+u),i.target.setAttribute("cx",l),i.target.setAttribute("cy",d),o)i.target.setAttribute("transform","rotate("+o+","+l+","+d+")");else{let e=parseFloat(i.target.getAttribute("x1")),t=parseFloat(i.target.getAttribute("y1")),s=parseFloat(i.target.getAttribute("x2")),n=parseFloat(i.target.getAttribute("y2"));if(i.target.setAttribute("x1",e+p),i.target.setAttribute("y1",t+u),i.target.setAttribute("x2",s+p),i.target.setAttribute("y2",n+u),"S"==a.substr(0,1)){let e=parseFloat($("#"+a+"_box").attr("x1")),t=parseFloat($("#"+a+"_box").attr("y1")),i=parseFloat($("#"+a+"_box").attr("x2")),s=parseFloat($("#"+a+"_box").attr("y2"));$("#"+a+"_box").attr("x1",e+p),$("#"+a+"_box").attr("y1",t+u),$("#"+a+"_box").attr("x2",i+p),$("#"+a+"_box").attr("y2",s+u)}}if(e.nodeid2lineid[a])for(let t=0,i=e.nodeid2lineid[a].length;t<i;++t){g(e.nodeid2lineid[a][t],a,o)}function g(e,t,i){if(e&&-1!=e.indexOf(t)){let t=e.split("--");if(2==t.length){let s,n;s=t[1],n=t[0];let r=i?"cx":"x1",a=i?"cy":"y1",o=$("#"+s).attr(r),l=$("#"+s).attr(a);$("#"+e).attr("x1",o),$("#"+e).attr("y1",l);let d=i?"cx":"x2",c=i?"cy":"y2",h=$("#"+n).attr(d),p=$("#"+n).attr(c);$("#"+e).attr("x2",h),$("#"+e).attr("y2",p)}}}}})}getLabelFromId(e,t){let i=e,s=i.indexOf("__");return-1!==s&&(i=i.substr(0,s)),"secondary"==t&&(i=i.substr(0,i.indexOf("-"))),i}drawHelix(e,t,i,s,n,r,a,o,l,d,c,h){let p=this.icn3d.icn3dui,u=this.getLabelFromId(t,e);n=p.htmlCls.width2d-n,a=p.htmlCls.width2d-a,l=p.htmlCls.width2d-l;let m="<g range='"+u.substr(1)+"' >";return m+="<title>"+e+" "+u+"</title>","H"==t.substr(0,1)?m+="<line id='"+t+"' class='icn3d-ctnode' x1='"+r+"' y1='"+a+"' x2='"+o+"' y2='"+l+"' cx='"+.5*(r+o).toFixed(1)+"' cy='"+.5*(a+l).toFixed(1)+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='round' />":(m+="<line id='"+t+"_box' x1='"+r+"' y1='"+a+"' x2='"+o+"' y2='"+l+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='square' />",m+="<line id='"+t+"' class='icn3d-ctnode' x1='"+r+"' y1='"+a+"' x2='"+o+"' y2='"+l+"' cx='"+.5*(r+o).toFixed(1)+"' cy='"+.5*(a+l).toFixed(1)+"' stroke='#FFF' stroke-width='1' stroke-linecap='square' />"),m+="<text id='"+t+"_text' x='"+(s-0).toString()+"' y='"+(n+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text8' >"+u+"</text>",m+="</g>",m}drawOval(e,t,i,s,n,r,a,o,l,d){let c=this.icn3d.icn3dui,h=this.getLabelFromId(t,e);s=c.htmlCls.width2d-s,a=180-a;let p="chain"==e?"<g chainid='"+t+"' >":"<g from='"+l+"' to='"+d+"' >";return p+="<title>"+e+" "+h+"</title>",p+="<defs>",p+="<linearGradient id='"+t+"_g_obj' x1='0%' y1='0%' x2='100%' y2='0%'>",p+=" <stop offset='0%' style='stop-color:rgb(255,255,255);stop-opacity:1' />",p+=" <stop offset='100%' style='stop-color:#"+o+";stop-opacity:1' />",p+="</linearGradient>",p+="</defs>",p+="<ellipse id='"+t+"' class='icn3d-ctnode' cx='"+i.toFixed(0)+"' cy='"+s.toFixed(0)+"' rx='"+n.toFixed(0)+"' ry='"+r.toFixed(0)+"' fill='url(#"+t+"_g_obj)' stroke-width='1' stroke='none' ",p+=" ang='"+a+"' transform='rotate("+a+","+i.toFixed(0)+","+s.toFixed(0)+")'",p+="chain"==e?" chainid='"+t+"' />":" from='"+l+"' to='"+d+"' />",p+="<text id='"+t+"_text' x='"+(i-0).toString()+"' y='"+(s+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text12' >"+h+"</text>",p+="</g>",p}getCartoonData(e,t){let i=this.icn3d;i.icn3dui;let s,n,r=[],a=[];r=t.node;let o=[],l={},d=0;for(let e=0,t=r.length;e<t;++e){let t=r[e],i=JSON.parse(t);l.hasOwnProperty(i.id)||(o.push(i),l[i.id]=d,++d)}let c=[];for(let e=0,t=o.length;e<t;++e){let t=o[e];c.push(JSON.stringify(t))}s=c.join(", "),a=t.link,n=a.join(", "),i.hAtoms;let h='{"nodes": ['+s+'], "links": [';return h+=n+"",h+='], "level": "'+(t.level?t.level:"")+'"}',h}projectTo2d(e){let t=this.icn3d,i=t.icn3dui,s=e.project(t.cam);var n=new mt;return n.x=Math.round((s.x+1)*i.htmlCls.width2d*.5),n.y=Math.round(-s.y*i.htmlCls.width2d*.5),n.z=0,n.y>0?n.y=i.htmlCls.width2d-n.y:n.y=-n.y,n}async getNodesLinksForSetCartoon(e){let t,i,s,n,r,a=this.icn3d,o=a.icn3dui,l=this,d=[],c=[],h=0,p=o.htmlCls.defaultValue,u="",m="",f="",g=!1,b=!0;if("chain"==e){let e={};for(let t in a.hAtoms){let i=a.atoms[t];if("DUM"==i.chain)continue;let s=i.structure+"_"+i.chain;(a.proteins.hasOwnProperty(t)||a.nucleotides.hasOwnProperty(t))&&(e.hasOwnProperty(s)||(e[s]={}),e[s][i.serial]=i)}let t=a.contactCls.getExtent(a.atoms),i=9999,s=9999,n=-9999,l=-9999,h=-9999,p=[];for(let d in e){a.hAtom={},a.hAtoms=o.hashUtilsCls.cloneHash(a.chains[d]);let e=a.axesCls.setPc1Axes(),c=e[0],u=e[1].distanceTo(e[0]),m=e[2].distanceTo(e[0]),f=180*new pt(e[1].x-e[0].x,e[1].y-e[0].y).angle()/Math.PI;f>180&&(f-=180);let g=Object.keys(a.hAtoms)[0],b=a.atoms[g];r=d,c=this.projectTo2d(c);let C=c.x,v=c.y;C<i&&(i=C),C>n&&(n=C),v<s&&(s=v),v>l&&(l=v);let _=.5;u=_*o.htmlCls.width2d*u/(t[1][0]-t[0][0]),m=_*o.htmlCls.width2d*m/(t[1][1]-t[0][1]),u>h&&(h=u),m>h&&(h=m),p.push({id:d,r:r,x:C,y:v,rx:u,ry:m,ang:f,c:b.color.getHexString()})}let u=h+2,m=n-i,f=l-s;for(let e=0,t=p.length;e<t;++e){let t=p[e],n=m<1?.5*o.htmlCls.width2d:(t.x-i)/m*(o.htmlCls.width2d-2*u)+u,r=f<1?.5*o.htmlCls.width2d:(t.y-s)/f*(o.htmlCls.width2d-2*u)+u;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+n.toFixed(0)+', "y": '+r.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}a.hAtoms=o.hashUtilsCls.cloneHash(a.dAtoms),a.node_link={node:d,link:c,level:"chain"}}else if("domain"==e)a.chainid2pssmid||await a.loadScriptCls.applyCommandAnnotationsAndCddSite("view annotations"),l.getNodesLinksForDomains(a.chainid2pssmid);else if("secondary"==e){a.resi2resirange={};let e,l=[];a.contactCls.getExtent(a.atoms);let C="",v=9999,_=9999,y=-9999,S=-9999,w=2,x=[];for(let d in a.hAtoms){let w=a.atoms[d];if("DUM"!=w.chain&&((w.ssbegin||w.ssend)&&"CA"==w.name&&"C"==w.elem)){let d=w.structure+"_"+w.chain+"_"+w.resi;if(b&&w.ssbegin&&(g=!0,b=!1,t=w,C="helix"==w.ss?"H":"S",n=C+w.resi,r="1_1_"+d,f=w.chain),g&&(e=o.utilsCls.residueName2Abbr(w.resn)+w.resi,e+="__"+w.chain,Object.keys(a.structures).length>1&&(e+="__"+w.structure),l.push(e)),f==w.chain&&g&&w.ssend){let o=this.projectTo2d(t.coord.clone()),d=o.x,f=o.y,A=this.projectTo2d(w.coord.clone()),M=A.x,T=A.y;i=.5*(d+M),s=.5*(f+T),d=.5*(i+d),f=.5*(s+f),M=.5*(i+M),T=.5*(s+T),d<v&&(v=d),d>y&&(y=d),f<_&&(_=f),f>S&&(S=f),M<v&&(v=M),M>y&&(y=M),T<_&&(_=T),T>S&&(S=T),g=!1,b=!0,n+="-"+w.resi,r+="-"+w.resi,n+="__"+w.chain,Object.keys(a.structures).length>1&&(n+="__"+w.structure);for(let t=0,i=l.length;t<i;++t)e=l[t],a.resi2resirange[e]=n;l=[],h>0&&u==w.chain&&c.push('{"source": "'+m+'", "target": "'+n+'", "v": '+p+', "c": "'+t.color.getHexString().toUpperCase()+'"}'),x.push({id:n,r:r,ss:C,x:i,y:s,x1:d,y1:f,x2:M,y2:T,c:w.color.getHexString()}),u=w.chain,m=n,++h}}}let A=w+2,M=y-v,T=S-_;for(let e=0,t=x.length;e<t;++e){let t=x[e],i=M<1?.5*o.htmlCls.width2d:(t.x-v)/M*(o.htmlCls.width2d-2*A)+A,s=T<1?.5*o.htmlCls.width2d:(t.y-_)/T*(o.htmlCls.width2d-2*A)+A,n=M<1?.5*o.htmlCls.width2d:(t.x1-v)/M*(o.htmlCls.width2d-2*A)+A,r=T<1?.5*o.htmlCls.width2d:(t.y1-_)/T*(o.htmlCls.width2d-2*A)+A,a=M<1?.5*o.htmlCls.width2d:(t.x2-v)/M*(o.htmlCls.width2d-2*A)+A,l=T<1?.5*o.htmlCls.width2d:(t.y2-_)/T*(o.htmlCls.width2d-2*A)+A;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+i.toFixed(0)+', "y": '+s.toFixed(0)+', "x1": '+n.toFixed(0)+', "y1": '+r.toFixed(0)+', "x2": '+a.toFixed(0)+', "y2": '+l.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}a.node_link={node:d,link:c,level:"secondary"}}}getNodesLinksForDomains(e){let t=this.icn3d,i=t.icn3dui,s=[],n=[],r=i.htmlCls.defaultValue;t.resi2resirange={};let a={};for(let e in t.hAtoms){let i=t.atoms[e];"DUM"!=i.chain&&(a[i.structure+"_"+i.chain]=1)}let o=t.contactCls.getExtent(t.atoms),l=9999,d=9999,c=-9999,h=-9999,p=-9999,u=[];for(let s in a){if(!e.hasOwnProperty(s))continue;let a=e[s].pssmid2name,f=e[s].pssmid2fromArray,g=e[s].pssmid2toArray,b={};for(let e in a){let t=f[e];b[e]=t[0]}var m=Object.keys(b);let C,v;m.sort((function(e,t){return b[e]-b[t]}));for(let e=0,b=m.length;e<b;++e){let b=m[e],_=a[b];_+="__"+s.substr(s.indexOf("_")+1),Object.keys(t.structures).length>1&&(_+="__"+s.substr(0,s.indexOf("_")));let y=f[b],S=g[b];t.hAtoms={};for(let e=0,n=y.length;e<n;++e){let n=parseInt(y[e])+1,r=parseInt(S[e])+1;for(let e=n;e<=r;++e)t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.residues[s+"_"+e])}if(0==Object.keys(t.hAtoms).length)continue;let w=t.axesCls.setPc1Axes(),x=w[0],A=w[1].distanceTo(w[0]),M=w[2].distanceTo(w[0]),T=180*new pt(w[1].x-w[0].x,w[1].y-w[0].y).angle()/Math.PI;T>180&&(T-=180);let E=Object.keys(t.hAtoms)[0],R=t.atoms[E];x=this.projectTo2d(x);let k=x.x,O=x.y;k<l&&(l=k),k>c&&(c=k),O<d&&(d=O),O>h&&(h=O);let I=.5;A=I*i.htmlCls.width2d*A/(o[1][0]-o[0][0]),M=I*i.htmlCls.width2d*M/(o[1][1]-o[0][1]),A>p&&(p=A),M>p&&(p=M),void 0!==C&&n.push('{"source": "'+C+'", "target": "'+_+'", "v": '+r+', "c": "'+v.color.getHexString().toUpperCase()+'"}'),u.push({id:_,from:y+"",to:S+"",x:k,y:O,rx:A,ry:M,ang:T,c:R.color.getHexString()}),C=_,v=R}}let f=p+2,g=c-l,b=h-d;for(let e=0,t=u.length;e<t;++e){let t=u[e],n=g<1?.5*i.htmlCls.width2d:(t.x-l)/g*(i.htmlCls.width2d-2*f)+f,r=b<1?.5*i.htmlCls.width2d:(t.y-d)/b*(i.htmlCls.width2d-2*f)+f;s.push('{"id": "'+t.id+'", "from": "'+t.from+'", "to": "'+t.to+'", "x": '+n.toFixed(0)+', "y": '+r.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}t.hAtoms=i.hashUtilsCls.cloneHash(t.dAtoms),t.node_link={node:s,link:n,level:"domain"}}getSelection(e,t,i){let s=this.icn3d,n=s.icn3dui,r={},a=[],o=t.toString().split(","),l=i.toString().split(","),d=3==e.length?e[2]:Object.keys(s.structures)[0],c=e.length>=2?d+"_"+e[1]:Object.keys(s.chains)[0];for(let e=0,t=o.length;e<t;++e){let t=parseInt(o[e])+1,i=parseInt(l[e])+1;for(let e=t;e<=i;++e){let t=c+"_"+e;r=n.hashUtilsCls.unionHash(r,s.residues[t]),a.push(t)}}return{atomSet:r,residArray:a}}click2Dcartoon(){let e=this.icn3d,t=e.icn3dui,i=this;t.myEventCls.onIds("#"+t.pre+"2dctn_chain","click",(async function(e){let s=t.icn3d;e.preventDefault(),i.initCartoonSvg(),await s.cartoon2dCls.draw2Dcartoon("chain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_domain","click",(async function(e){let s=t.icn3d;e.preventDefault(),i.initCartoonSvg(),await s.cartoon2dCls.draw2Dcartoon("domain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_secondary","click",(async function(e){let s=t.icn3d;e.preventDefault(),i.initCartoonSvg(),await s.cartoon2dCls.draw2Dcartoon("secondary")})),$(document).on("click","#"+e.pre+"dl_2dctn .icn3d-ctnode",(function(e){let s=i.icn3d;e.stopImmediatePropagation(),Object.keys(s.hAtoms).length<Object.keys(s.atoms).length&&s.definedSetsCls.setMode("selection");let n,r={},a=[],o=$(this).attr("id"),l=$(this).attr("chainid"),d=$(this).attr("from"),c=$(this).attr("to"),h=$(this).attr("x1");if(void 0!==l)n="chain",r=s.chains[l];else if(void 0!==d){n="domain";let e=o.split("__"),t=i.getSelection(e,d,c);r=t.atomSet,a=t.residArray}else if(void 0!==h){n="secondary";let e=o.split("__"),t=e[0].substr(1).split("-"),s=parseInt(t[0])-1,l=parseInt(t[1])-1,d=i.getSelection(e,s,l);r=d.atomSet,a=d.residArray}s.bCtrl||s.bShift||(s.selectionCls.removeSelection(),s.lineArray2d=[]),void 0!==s.alnChains[l]&&(Object.keys(s.alnChains[l]).length,Object.keys(s.chains[l]).length),s.bCtrl||s.bShift?s.hAtoms=t.hashUtilsCls.unionHash(s.hAtoms,r):s.hAtoms=t.hashUtilsCls.cloneHash(r),"chain"==n?(s.bCtrl||s.bShift?(void 0===s.chainArray2d&&(s.chainArray2d=[]),s.chainArray2d.push(l)):s.chainArray2d=[l],s.hlUpdateCls.updateHlAll(s.chainArray2d)):s.hlUpdateCls.updateHlAll(),s.annotationCls.showAnnoSelectedChains();let p="chain"==n?"select chain "+l:"select "+s.resid2specCls.residueids2spec(a);t.htmlCls.clickMenuCls.setLogCmd(p,!0),s.bSelectResidue=!1}))}initCartoonSvg(){let e=this.icn3d,t=e.icn3dui;e.resizeRatioX=1,e.resizeRatioY=1,$("#"+t.svgid_ct).empty()}}class cp{constructor(e){this.icn3d=e}async drawLigplot(e,t){let i=this.icn3d,s=i.icn3dui;t?s.htmlCls.dialogCls.openDlg("dl_ligplot","2D Depiction"):s.htmlCls.dialogCls.openDlg("dl_ligplot","Show ligand interactions with atom details");let n,r,a=100,o=100;i.len4ang=80;let l=i.saveFileCls.getAtomPDB(e);l=l.trim(),l=l.replace(/\n\n/g,"\n");let d={pdb2svg:l},c=s.htmlCls.baseUrl+"openbabel/openbabel.cgi",h=(await s.getAjaxPostPromise(c,d,void 0,void 0,void 0,void 0,"text")).split("\n"),p="",u="",m={},f=0,g=0,b=0;i.svgGridSize=i.len4ang,i.gridXY2used={};for(let e=0,t=h.length;e<t;++e){let t=h[e];if(0==t.indexOf("<svg width")){let e=t.indexOf('viewBox="')+9,s=t.substr(e),l=s.substr(0,s.indexOf('"')).split(" ");n=parseFloat(l[2]),r=parseFloat(l[3]),a=n+2*i.len4ang,o=r+2*i.len4ang}else if(0==t.indexOf("<line"))p+=t+"\n";else if(0==t.indexOf("<text"))if(-1!=t.indexOf('font-size="12"')){let e=t.indexOf(">")+1,s=t.substr(e),n=parseInt(s.substr(0,s.indexOf("<")));e=t.indexOf('x="')+3;let r=t.substr(e),a=parseFloat(r.substr(0,r.indexOf('"')));e=t.indexOf('y="')+3;let o=t.substr(e),l=parseFloat(o.substr(0,o.indexOf('"')));m[n]={x:a,y:l};let d=parseInt(a/i.svgGridSize),c=parseInt(l/i.svgGridSize);i.gridXY2used[d+"_"+c]=1,f+=a,g+=l,++b}else u+=t+"\n";else if(0==t.indexOf("</svg>"))break}let C=f/b,v=g/b,_=s.ligplotid;i.ligplotWidth=a;let y=i.ligplotWidth,S=o+30,w=-i.len4ang,x="<svg id='"+_+"' viewBox='"+w+","+w+","+a+","+S+"' width='"+y+"px' font-family='sans-serif' stroke='rgb(0,0,0)' stroke-width='2' stroke-linecap='round'>";if(t)x+=p+u;else{let e=parseInt(n/i.svgGridSize),t=parseInt(r/i.svgGridSize),s=i.viewInterPairsCls.getAllInteractionTable("save1",m,e,t,C,v);x+=p+s.svgHtmlLine,x+=u+s.svgHtmlNode}x+="</svg>",t?$("#"+i.pre+"ligplotDiv").html(x):($("#"+i.pre+"ligplotDiv").html(x),this.setEventsForLigplot())}getSvgPerPair(e,t,i,s,n,r,a,o,l,d,c,h,p){let u=this.icn3d,m=u.icn3dui,f="hbond"==s||"contact"==s||"halogen"==s?u.len4ang:1.5*u.len4ang,g=u.len4ang/2,b="contact"==s?1:2,C=u.getGraphCls.convertLabel2Resid(t),v=u.firstAtomObjCls.getFirstAtomObj(u.residues[C]),_=u.getGraphCls.convertLabel2Resid(i),y=u.firstAtomObjCls.getFirstAtomObj(u.residues[_]),S=0,w=0,x=0,A=v.serial;for(let t=0,i=e.length;t<i;++t){let i=e[t]-A+1;S+=n[i].x,w+=n[i].y,++x}let M,T,E,R=S/x-1,k=w/x- -1;if(u.resid2cnt.hasOwnProperty(t)?++u.resid2cnt[t]:u.resid2cnt[t]=0,!c&&!u.resid2ToXy.hasOwnProperty(_)){let e=parseInt(R/u.svgGridSize),i=parseInt(k/u.svgGridSize),s=[];for(let t=1;t>=-1;--t)for(let n=1;n>=-1;--n)0==t&&0==n||e+t>=0&&e+t<=r&&i+n>=0&&i+n<=a&&s.push(e+t+"_"+(i+n));for(let t=2;t>=-2;--t)for(let n=2;n>=-2;--n)t>=-1&&t<=1&&n>=-1&&n<=1||e+t>=0&&e+t<=r&&i+n>=0&&i+n<=a&&s.push(e+t+"_"+(i+n));let n,d=!1;for(let e=0,t=s.length;e<t;++e)if(!u.gridXY2used[s[e]]){n=s[e].split("_"),M=(parseInt(n[0])+.5)*u.svgGridSize,T=(parseInt(n[1])+.5)*u.svgGridSize;let t=Math.sqrt((R-M)*(R-M)+(k-T)*(k-T));M=f/t*(M-R)+R,T=f/t*(T-k)+k,u.gridXY2used[s[e]]=1,d=!0;break}if(!d){let e=R-o,i=k-l,s=0;s=Math.abs(e)>Math.abs(i)?e>0?0:180:i>0?90:270,E=s-10+30*u.resid2cnt[t],M=R+f*Math.cos(E*Math.PI/180),T=k+f*Math.sin(E*Math.PI/180)}}let O,I=m.utilsCls.residueName2Abbr(y.resn.substr(0,3))+y.resi,P=y.color?y.color.getHexString():"000",D=u.lineGraphCls.getStrokecolor(void 0,s),L="",F="",N=_+"--"+e.join("-")+s;"hbond"==s?O="H-Bonds":"ionic"==s?O="Salt Bridge/Ionic":"halogen"==s?O="Halogen Bonds":"pi-cation"==s?O="π-Cation":"pi-stacking"==s?O="π-Stacking":"contact"==s&&(O="Contacts");let U=_;if(c||u.resid2ToXy.hasOwnProperty(U)){M=u.resid2ToXy.hasOwnProperty(U)?u.resid2ToXy[U].x2:h,T=u.resid2ToXy.hasOwnProperty(U)?u.resid2ToXy[U].y2:p;let e=R,t=k,i=0;if("contact"==s){let s=Math.sqrt((R-M)*(R-M)+(k-T)*(k-T));g<s&&(e=g/s*(R-M)+M,t=g/s*(k-T)+T,i=1)}F+="<g><title>Interaction type: "+O+"; Distance: "+parseFloat(d).toFixed(1)+" Å</title>",F+='<line class="icn3d-interaction" id="'+N+'" resid1="'+C+'" resid2="'+_+'" x1="'+e.toFixed(2)+'" y1="'+t.toFixed(2)+'" x2="'+M.toFixed(2)+'" y2="'+T.toFixed(2)+'" x0="'+R.toFixed(2)+'" y0="'+k.toFixed(2)+'" short="'+i+'" opacity="1.0" stroke="'+D+'" stroke-width="'+b+'" stroke-dasharray="5,5"/>\n',F+="</g>\n"}else{L+="<g><title>"+I+"</title>";let e=28,t=14;L+='<rect id="'+U+'_node" x="'+(M-.5*e).toFixed(2)+'" y="'+(T-.5*t).toFixed(2)+'" width="'+e+'" height="'+t+'" rx="2" ry="2" fill="#'+P+'" stroke-width="1" stroke="'+P+'" resid="'+_+'"/>',L+='<text class="icn3d-ctnode" resid="'+U+'" id="'+U+'" x="'+M.toFixed(2)+'" y="'+T.toFixed(2)+'" fill="#000" stroke="none" text-anchor="middle" alignment-baseline="central" style="font-size:10px">'+I+"</text>",L+="</g>\n",F+="<g><title>Interaction type: "+O+"; Distance: "+parseFloat(d).toFixed(1)+" Å</title>",F+='<line class="icn3d-interaction" id="'+N+'" resid1="'+C+'" resid2="'+_+'" x1="'+R.toFixed(2)+'" y1="'+k.toFixed(2)+'" x2="'+M.toFixed(2)+'" y2="'+T.toFixed(2)+'" opacity="1.0" stroke="'+D+'" stroke-width="'+b+'" stroke-dasharray="5,5"/>',F+="</g>\n","contact"!=s&&(u.resid2ToXy.hasOwnProperty(_)||(u.resid2ToXy[_]={x2:M,y2:T}))}return u.nodeid2lineid.hasOwnProperty(U)||(u.nodeid2lineid[U]=[]),u.nodeid2lineid[U].push(N),{node:L,line:F,x2:M,y2:T}}setEventsForLigplot(){let e=this.icn3d,t=e.icn3dui;$("#"+t.ligplotid+" .icn3d-ctnode").draggable({start:function(e,t){let i=parseFloat(e.target.getAttribute("x")),s=parseFloat(e.target.getAttribute("y"));e.target.setAttribute("x",i),e.target.setAttribute("y",s)},drag:function(i,s){let n=e.ligplotScale?e.ligplotScale:1,r=$("#"+t.ligplotid).offset().left+e.len4ang*n,a=$("#"+t.ligplotid).offset().top+e.len4ang*n,o=i.target.getAttribute("resid"),l=(i.clientX-r)/n,d=(i.clientY-a)/n,c=parseFloat(i.target.getAttribute("x")),h=parseFloat(i.target.getAttribute("y")),p=l-c,u=d-h;if(c=parseFloat($("#"+o+"_node").attr("x")),h=parseFloat($("#"+o+"_node").attr("y")),$("#"+o+"_node").attr("x",c+p),$("#"+o+"_node").attr("y",h+u),i.target.setAttribute("x",l),i.target.setAttribute("y",d),e.nodeid2lineid[o])for(let t=0,i=e.nodeid2lineid[o].length;t<i;++t){m(e.nodeid2lineid[o][t],o)}function m(t,i){if(t&&-1!=t.indexOf(i)){let i=t.split("--");if(2==i.length){let s;i[1],s=i[0];let n=parseFloat($("#"+s).attr("x")),r=parseFloat($("#"+s).attr("y"));$("#"+t).attr("x2",n),$("#"+t).attr("y2",r);let a=$("#"+t).attr("x1"),o=$("#"+t).attr("y1"),l=a,d=o;if(parseInt($("#"+t).attr("short"))){a=$("#"+t).attr("x0"),o=$("#"+t).attr("y0");let i=Math.sqrt((a-n)*(a-n)+(o-r)*(o-r)),s=e.len4ang/2;s<i&&(l=s/i*(a-n)+n,d=s/i*(o-r)+r)}$("#"+t).attr("x1",l),$("#"+t).attr("y1",d)}}}}})}clickLigplot(){let e=this.icn3d;e.icn3dui;let t=this;$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-ctnode",(function(e){let i=t.icn3d;e.stopImmediatePropagation(),i.diagram2dCls.clickNode(this)}))}}class hp{constructor(e){this.icn3d=e}resizeCanvas(e,t,i,s){var n=this.icn3d,r=n.icn3dui;if(i||r.cfg.resize){let i=t;$("#"+n.pre+"canvas").width(e).height(i),$("#"+n.pre+"viewer").width(e).height(t),$("#"+n.divid+" div:has(#"+n.pre+"canvas)").width(e).height(i),n.applyCenterCls.setWidthHeight(e,i),n.structures&&Object.keys(n.structures).length>0&&(void 0===s||s)&&n.drawCls.draw()}}windowResize(){let e=this.icn3d.icn3dui,t=this;e.cfg.resize&&!e.utilsCls.isMobile()&&$(window).resize((function(){let i=t.icn3d;e.utilsCls.setViewerWidthHeight(i.icn3dui);let s=e.htmlCls.WIDTH,n=e.htmlCls.HEIGHT;void 0===i||i.bFullscreen||t.resizeCanvas(s,n)}))}openFullscreen(e){this.icn3d.icn3dui.bNode||document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement||(e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen())}rotStruc(e,t){var i=this.icn3d;i.icn3dui;let s=this;if(i.bStopRotate)return!1;if(i.transformCls.rotateCount>i.transformCls.rotateCountMax)return i.transformCls.resetOrientation(),!1;if(++i.transformCls.rotateCount,t)if("left"===e)i.ROT_DIR="left";else if("right"===e)i.ROT_DIR="right";else if("up"===e)i.ROT_DIR="up";else{if("down"!==e)return!1;i.ROT_DIR="down"}if("left"===e&&"left"===i.ROT_DIR)i.transformCls.rotateLeft(1);else if("right"===e&&"right"===i.ROT_DIR)i.transformCls.rotateRight(1);else if("up"===e&&"up"===i.ROT_DIR)i.transformCls.rotateUp(1);else{if("down"!==e||"down"!==i.ROT_DIR)return!1;i.transformCls.rotateDown(1)}setTimeout((function(){s.rotStruc(e)}),100)}async back(){var e=this.icn3d;e.icn3dui,e.backForward=!0,e.STATENUMBER--,e.bAddCommands=!1,e.bAddLogs=!1,e.bNotLoadStructure=!0,e.STATENUMBER<1?e.STATENUMBER=1:await e.loadScriptCls.execCommands(0,e.STATENUMBER-1,e.STATENUMBER,!0),e.setStyleCls.adjustIcon(),e.bAddCommands=!0,e.bAddLogs=!0}async forward(){var e=this.icn3d;e.icn3dui,e.backForward=!0,e.STATENUMBER++,e.bAddCommands=!1,e.bAddLogs=!1,e.bNotLoadStructure=!0,e.STATENUMBER>e.commands.length?e.STATENUMBER=e.commands.length:await e.loadScriptCls.execCommands(0,e.STATENUMBER-1,e.STATENUMBER,!0),e.setStyleCls.adjustIcon(),e.bAddCommands=!0,e.bAddLogs=!0}async replayon(){var e=this.icn3d;e.icn3dui,e.CURRENTNUMBER=0,e.bReplay=1,$("#"+e.pre+"replay").show(),e.commands.length>0&&await e.loadScriptCls.replayFirstStep(e.CURRENTNUMBER)}async replayoff(){var e=this.icn3d;e.icn3dui,e.bReplay=0,$("#"+e.pre+"replay").hide(),++e.CURRENTNUMBER,await e.loadScriptCls.execCommands(e.CURRENTNUMBER,e.STATENUMBER-1,e.STATENUMBER)}closeDialogs(){var e=this.icn3d,t=e.icn3dui;let i=["dl_2ddgm","dl_2dctn","dl_alignment","dl_sequence2","dl_definedsets","dl_setsmenu","dl_command","dl_setoperations","dl_vast","dl_foldseek","dl_mmtfid","dl_pdbid","dl_afid","dl_opmid","dl_pdbfile","dl_pdbfile_app","dl_rescolorfile","dl_customcolor","dl_align","dl_alignaf","dl_chainalign","dl_chainalign2","dl_chainalign3","dl_mutation","dl_mol2file","dl_sdffile","dl_xyzfile","dl_clustalwfile","dl_fastafile","dl_afmapfile","dl_urlfile","dl_mmciffile","dl_mmcifid","dl_mmdbid","dl_mmdbafid","dl_blast_rep_id","dl_yournote","dl_proteinname","dl_refseqid","dl_cid","dl_pngimage","dl_state","dl_fixedversion","dl_selection","dl_dsn6","dl_dsn6url","dl_clr","dl_symmetry","dl_symd","dl_contact","dl_hbonds","dl_realign","dl_realignbystruct","dl_allinteracton","dl_interactionsorted","dl_linegraph","dl_linegraphcolor","dl_scatterplot","dl_scatterploitcolor","dl_contactmap","dl_alignerrormap","dl_elecmap2fofc","dl_elecmapfofc","dl_emmap","dl_aroundsphere","dl_adjustmem","dl_selectplane","dl_addlabel","dl_addlabelselection","dl_labelColor","dl_distance","dl_stabilizer","dl_disttwosets","dl_distmanysets","dl_stabilizer_rm","dl_thickness","dl_thickness2","dl_addtrack","dl_addtrack_tabs","dl_saveselection","dl_copyurl","dl_selectannotations","dl_annotations_tabs","dl_anno_view_tabs","dl_annotations","dl_graph","dl_svgcolor","dl_area","dl_colorbyarea","dl_rmsd","dl_buriedarea","dl_propbypercentout","dl_propbybfactor","dl_legend","dl_disttable","dl_translate"];for(let s in i){let n=i[s];t.cfg.notebook?$("#"+e.pre+n).hide():$("#"+e.pre+n).hasClass("ui-dialog-content")&&$("#"+e.pre+n).dialog("isOpen")&&$("#"+e.pre+n).dialog("close").remove()}t.cfg.notebook||this.resizeCanvas(t.htmlCls.WIDTH,t.htmlCls.HEIGHT,!0)}}class pp{constructor(e){this.icn3d=e}resetOrientation_base(e){let t=this.icn3d;if(t.icn3dui,2==e.length&&e[1].length>0)if(t.bSetCamera){let i=JSON.parse(e[1]);t._zoomFactor=i.factor,t.mouseChange.x=i.mouseChange.x,t.mouseChange.y=i.mouseChange.y,t.quaternion._x=i.quaternion._x,t.quaternion._y=i.quaternion._y,t.quaternion._z=i.quaternion._z,t.quaternion._w=i.quaternion._w}else{e[1].split("|").forEach((e=>{let i=e.split(":");if("fov"==i[0])t.cam.fov=parseFloat(i[1]);else{let e=i[1].split(",");"pos"==i[0]?t.cam.position.set(parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2])):"dir"==i[0]?t.cam.quaternion.setFromUnitVectors(new mt(0,0,-1),new mt(parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2]))):"up"==i[0]&&t.cam.up.set(parseFloat(e[0]),parseFloat(e[1]),parseFloat(e[2]))}}))}else t._zoomFactor=1,t.mouseChange=new pt(0,0),t.quaternion=new ut(0,0,0,1)}resetOrientation(){let e=this.icn3d;if(e.icn3dui,e.commands.length>0){let t=e.commands[0].split("|||");this.resetOrientation_base(t)}e.maxD=e.oriMaxD,e.center=e.oriCenter.clone(),"show"==e.ori_chemicalbinding?e.bSkipChemicalbinding=!1:"hide"==e.ori_chemicalbinding&&(e.bSkipChemicalbinding=!0)}rotateLeft(e){let t=this.icn3d,i=t.icn3dui,s=new mt(0,1,0),n=-e/180*Math.PI;t.bControlGl&&!i.bNode?s.applyQuaternion(window.cam.quaternion).normalize():s.applyQuaternion(t.cam.quaternion).normalize();let r=new ut;r.setFromAxisAngle(s,-n);let a={};a.quaternion=r,a.update=!0,t.bControlGl&&!i.bNode?window.controls.update(a):t.controls.update(a),t.bRender&&t.drawCls.render()}rotateRight(e){let t=this.icn3d,i=t.icn3dui,s=new mt(0,1,0),n=e/180*Math.PI;t.bControlGl&&!i.bNode?s.applyQuaternion(window.cam.quaternion).normalize():s.applyQuaternion(t.cam.quaternion).normalize();let r=new ut;r.setFromAxisAngle(s,-n);let a={};a.quaternion=r,a.update=!0,t.bControlGl&&!i.bNode?window.controls.update(a):t.controls.update(a),t.bRender&&t.drawCls.render()}rotateUp(e){this.icn3d.icn3dui,this.rotate_base(-e)}rotateDown(e){this.icn3d.icn3dui,this.rotate_base(e)}rotate_base(e){let t=this.icn3d,i=t.icn3dui,s=new mt(1,0,0),n=e/180*Math.PI;t.bControlGl&&!i.bNode?s.applyQuaternion(window.cam.quaternion).normalize():s.applyQuaternion(t.cam.quaternion).normalize();let r=new ut;r.setFromAxisAngle(s,-n);let a={};a.quaternion=r,a.update=!0,t.bControlGl&&!i.bNode?window.controls.update(a):t.controls.update(a),t.bRender&&t.drawCls.render()}setRotation(e,t){let i=this.icn3d,s=i.icn3dui;if(!e)return;i.bControlGl&&!s.bNode&&window.cam?e.applyQuaternion(window.cam.quaternion).normalize():i.cam&&e.applyQuaternion(i.cam.quaternion).normalize();let n=new ut;n.setFromAxisAngle(e,-t);let r={};r.quaternion=n,r.update=!0,i.bControlGl&&!s.bNode&&window.controls?window.controls.update(r):i.controls&&i.controls.update(r),i.bRender&&i.drawCls.render()}translateLeft(e){this.icn3d.icn3dui,this.translate_base(-e,0)}translateRight(e){this.icn3d.icn3dui,this.translate_base(e,0)}translateUp(e){this.icn3d.icn3dui,this.translate_base(0,-e)}translateDown(e){this.icn3d.icn3dui,this.translate_base(0,e)}translate_base(e,t){let i=this.icn3d,s=i.icn3dui,n=new pt(0,0);n.x+=e/100,n.y+=t/100;let r={};r.mouseChange=n,r.update=!0,i.bControlGl&&!s.bNode?window.controls.update(r):i.controls.update(r),i.bRender&&i.drawCls.render()}translateCoord(e,t,i,s){let n=this.icn3d;n.icn3dui;for(let r in e){let e=n.atoms[r];e.coord.x+=t,e.coord.y+=i,e.coord.z+=s}}rotateCoord(e,t){let i=this.icn3d;i.icn3dui;const s=new gi;s.elements=t;for(let t in e){let e=i.atoms[t];e.coord=e.coord.applyMatrix4(s)}}zoominSelection(e){let t=this.icn3d,i=t.icn3dui,s={};if(s._zoomFactor=1/t._zoomFactor,s.update=!0,t.bControlGl&&!i.bNode?window.controls&&window.controls.update(s):t.controls&&t.controls.update(s),void 0===e&&(e=i.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)),Object.keys(e).length>1){let i=t.applyCenterCls.centerAtoms(e);t.maxD=i.maxD,t.maxD<5&&(t.maxD=5),t.center=i.center,t.applyCenterCls.setCenter(t.center),t.cameraCls.setCamera()}}getTransformationStr(e){var t=this.icn3d;if(t.icn3dui,t.bTransformation){let t={factor:1,mouseChange:{x:0,y:0},quaternion:{_x:0,_y:0,_z:0,_w:1}};return t.factor=parseFloat(e.factor).toPrecision(4),t.mouseChange.x=parseFloat(e.mouseChange.x).toPrecision(4),t.mouseChange.y=parseFloat(e.mouseChange.y).toPrecision(4),t.quaternion._x=parseFloat(e.quaternion._x).toPrecision(4),t.quaternion._y=parseFloat(e.quaternion._y).toPrecision(4),t.quaternion._z=parseFloat(e.quaternion._z).toPrecision(4),t.quaternion._w=parseFloat(e.quaternion._w).toPrecision(4),"1.0000"==t.factor&&(t.factor=1),"0.0000"==t.mouseChange.x&&(t.mouseChange.x=0),"0.0000"==t.mouseChange.y&&(t.mouseChange.y=0),"0.0000"==t.quaternion._x&&(t.quaternion._x=0),"0.0000"==t.quaternion._y&&(t.quaternion._y=0),"0.0000"==t.quaternion._z&&(t.quaternion._z=0),"1.0000"==t.quaternion._w&&(t.quaternion._w=1),JSON.stringify(t)}if(t.cam){let e="";e+="pos:"+t.cam.position.x.toPrecision(4)+","+t.cam.position.y.toPrecision(4)+","+t.cam.position.z.toPrecision(4);let i=new mt(0,0,-1).applyQuaternion(t.cam.quaternion);return e+="|dir:"+i.x.toPrecision(4)+","+i.y.toPrecision(4)+","+i.z.toPrecision(4),e+="|up:"+t.cam.up.x.toPrecision(4)+","+t.cam.up.y.toPrecision(4)+","+t.cam.up.z.toPrecision(4),e+="|fov:"+t.cam.fov.toPrecision(4),e}return""}}class up{constructor(e){this.icn3d=e}async saveFile(e,t,i,s,n){let r,a=this.icn3d,o=a.icn3dui,l=this;if("command"===t){let e=a.loadCmd?a.loadCmd+"\n":"";for(let t=0,i=a.commands.length;t<i;++t){let s=a.commands[t].trim();if(t==i-1){let e=s.split("|||"),t={};t.factor=a._zoomFactor,t.mouseChange=a.mouseChange,t.quaternion=a.quaternion,s=e[0]+"|||"+a.transformCls.getTransformationStr(t)}e+=s+"\n"}let t=decodeURIComponent(e);r=new Blob([t],{type:"text;charset=utf-8;"})}else if("png"===t){let t=$("#"+a.pre+"canvas").width(),i=$("#"+a.pre+"canvas").height();a.applyCenterCls.setWidthHeight(t,i),a.bRender&&a.drawCls.render();let d=!0;if(window.File&&window.FileReader&&window.FileList&&window.Blob||(d=!1),r=o.utilsCls.isIE()?a.renderer.domElement.msToBlob():await this.getBlobFromNonIE(),n)return r;if(!d)return l.saveBlob(r,e,s,t,i),r;{let n=new FileReader;n.onload=function(n){let d=n.target.result,c=a.shareLinkCls.getPngText();return r=o.convertTypeCls.getBlobFromBufferAndText(d,c),l.saveBlob(r,e,s,t,i),r},n.readAsArrayBuffer(r)}a.scaleFactor=1,a.applyCenterCls.setWidthHeight(t,i),a.bRender&&a.drawCls.render()}else if("html"===t){let e=decodeURIComponent(i);r=new Blob([e],{type:"text/html;charset=utf-8;"})}else if("text"===t){r=new Blob(i,{type:"text;charset=utf-8;"})}else if("binary"===t){r=new Blob(i,{type:"application/octet-stream"})}return"png"!==t&&(n||saveAs(r,e)),r}getBlobFromNonIE(){let e=this.icn3d;return e.icn3dui,new Promise((function(t,i){e.renderer.domElement.toBlob((function(e){t(e)}))}))}saveBlob(e,t,i,s,n){let r=this.icn3d;if(r.icn3dui,i){let t=(window.URL||window.webkitURL).createObjectURL(e),i=r.shareLinkCls.shareLinkUrl();i=i.replace(/imageonly=1/g,""),i.length>4e3||0!==i.indexOf("http")||r.bInputfile&&!r.bInputUrlfile?$("#"+r.pre+"viewer").html("<img src='"+t+"'/>"):$("#"+r.pre+"viewer").html("<a href='"+i+"' target='_blank'><img src='"+t+"'/></a>"),$("#"+r.pre+"viewer").width(s),$("#"+r.pre+"viewer").height(n),$("#"+r.pre+"cmdlog").hide(),$("#"+r.pre+"title").hide(),$("#"+r.pre+"mnlist").hide(),$("#"+r.pre+"fullscreen").length>0&&$("#"+r.pre+"fullscreen").hide(),r={}}else saveAs(e,t)}saveSvg(e,t,i,s){let n=this.icn3d;if(n.icn3dui.bNode)return"";let r=$("#"+e).width(),a=$("#"+e).height();i&&(a=r),s&&(r+=n.len4ang,a+=n.len4ang);let o=this.getSvgXml(e,r,a,i,s),l=new Blob([o],{type:"image/svg+xml"});saveAs(l,t)}getSvgXml(e,t,i,s,n){if(this.icn3d.icn3dui.bNode)return"";return(t&&i?'<svg viewBox="'+(n?-30:0)+" "+(n?-30:0)+" "+t+" "+i+'"':"<svg")+' title="graph" xmlns:xl="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xmlns:dc="http://purl.org/dc/elements/1.1/">'+"<style>text {font-family: sans-serif; font-weight: bold; font-size: 18px;}</style>"+document.getElementById(e).innerHTML+"</svg>"}savePng(e,t,i,s){let n=this.icn3d,r=n.icn3dui;if(r.bNode)return"";let a=$("#"+e).width(),o=$("#"+e).height();i&&(o=a);let l=document.getElementById(e),d=l.getBBox(),c=l.cloneNode(!0);s||n.lineGraphCls.copyStylesInline(c,l);let h=document.createElement("CANVAS");h.width=a,h.height=o;let p=h.getContext("2d");p.clearRect(0,0,d.width,d.height);let u=this.getSvgXml(e,a,o,i),m=window.URL||window.webkitURL||window,f=new Blob([u],{type:"image/svg+xml;charset=utf-8"}),g=new Image;g.src=m.createObjectURL(f),g.onload=function(){if(p.drawImage(g,0,0),m.revokeObjectURL(this.src),r.utilsCls.isIE()){let e=h.msToBlob();e&&(saveAs(e,t),h.remove())}else h.toBlob((function(e){e&&(saveAs(e,t),h.remove())}))}}exportCustomAtoms(e){var t=this.icn3d;t.icn3dui;let i="",s=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues).sort():[];for(let n=0,r=s.length;n<r;++n){let r=s[n],a=t.defNames2Residues[r];t.defNames2Descr[r];let o=t.defNames2Command[r];o=o.replace(/,/g,", "),i+=this.exportResidues(r,a,e)}s=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms).sort():[];for(let n=0,r=s.length;n<r;++n){let r=s[n],a=t.defNames2Atoms[r];t.defNames2Descr[r];let o=t.defNames2Command[r];o=o.replace(/,/g,", ");let l=t.resid2specCls.atoms2residues(a);i+=this.exportResidues(r,l,e)}return i}exportResidues(e,t,i){var s=this.icn3d,n=s.icn3dui;let r="";if(t.length>0)if(i){let i={};for(let e=0,r=t.length;e<r;++e){let r=t[e],a=s.firstAtomObjCls.getFirstAtomObj(s.residues[r]);if(!a)continue;let o=a.structure+"_"+a.chain,l=n.utilsCls.residueName2Abbr(a.resn)+a.resi;i.hasOwnProperty(o)||(i[o]=[]),i[o].push(l)}r+=e+":\n";for(let e in i){let t=1==i[e].length?"residue":"residues";r+=e+" ("+i[e].length+" "+t+"): ",r+=i[e].join(", "),r+="\n"}r+="\n"}else r+=e+"\tselect ",r+=s.resid2specCls.residueids2spec(t),r+="\n";return r}printPrevSecondary(e,t,i,s){this.icn3d.icn3dui;let n="";if(i)if(e){let e=1;n+=i.resn.padStart(5," ")+i.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+i.resi.toString().padStart(5," ")+" "+e+s.toString().padStart(36," ")+"\n"}else if(t){let e=0;n+=i.resn.padStart(5," ")+i.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+i.resi.toString().padStart(4," ")+" "+e+"\n"}return n}getAtomPDB(e,t,i,s,n,r,a,o){let l=this.icn3d,d=l.icn3dui,c="",h={},p={};for(let e in l.chemicals){let t=l.atoms[e];if("P"==t.elem){h[e]=1;for(let e=0,i=t.bonds.length;e<i;++e){let i=t.bonds[e];i&&"O"==l.atoms[i].elem&&(p[i]=1)}}}let u,m,f=d.hashUtilsCls.intHash(e,l.calphas),g={};for(let e in l.structures)g[e]="";let b=[];for(let e in f){let t=l.atoms[e];m=t.structure,t.structure,t.chain;let i={};if(i.chain=t.chain,i.resn=t.resn,i.resi=t.resi,parseInt(t.resi)>parseInt(u)+1||t.ssbegin){let e=d.hashUtilsCls.cloneHash(i);e.ss=" ",b.push(e)}"helix"==t.ss?(i.ss="H",b.push(i)):"sheet"==t.ss&&(i.ss="S",b.push(i)),u=t.resi}let C,v,_=0,y=!1,S=!1;for(let e=0,t=b.length;e<t;++e){let t=b[e];t.ss!=C&&(" "!==C&&(g[m]+=this.printPrevSecondary(y,S,v,_)),_=0,y=!1,S=!1,v=void 0," "!==t.ss&&("H"==t.ss?(y=!0,v=t,g[m]+="HELIX".padEnd(15," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(5," ")):"S"==t.ss&&(S=!0,v=t,g[m]+="SHEET".padEnd(17," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(4," "))))," "!==t.ss&&(++_,v=t),C=t.ss}if(g[m]+=this.printPrevSecondary(y,S,v,_),g[m]+="\n",l.biomtMatrices&&Object.keys(e).length==Object.keys(l.atoms).length){let e=Object.keys(l.structures)[0];for(let t=0,i=l.biomtMatrices.length;t<i;++t){let i=t+1;for(let s=0;s<3;++s){let n=s+1;g[e]+="REMARK 350 BIOMT"+n.toString()+" "+i.toString().padStart(2," ")+" "+l.biomtMatrices[t].elements[s+0].toFixed(6).toString().padStart(9," ")+" "+l.biomtMatrices[t].elements[s+4].toFixed(6).toString().padStart(9," ")+" "+l.biomtMatrices[t].elements[s+8].toFixed(6).toString().padStart(9," ")+" "+l.biomtMatrices[t].elements[s+12].toFixed(6).toString().padStart(14," ")+"\n"}}}for(let e in l.chainMissingResidueArray){let t=e.indexOf("_"),i=e.substr(t+1,2),s=e.substr(0,t);for(let t=0,n=l.chainMissingResidueArray[e].length;t<n;++t){let n=l.chainMissingResidueArray[e][t].resi,r=d.utilsCls.residueAbbr2Name(l.chainMissingResidueArray[e][t].name);g[s]+="REMARK 465 "+r.padStart(3," ")+i.padStart(2," ")+" "+n.toString().padStart(5," ")+"\n"}}let w="",x=Object.keys(l.structures).length>1,A=1,M="",T="",E=0,R="",k={};for(let r in e){let e=l.atoms[r];if(i&&e.het)continue;if(e.structure!=M){a&&x||(c+=w,w="",A>1&&(c+="\nENDMDL\n"),x&&(c+="MODEL "+A+"\n"));let t=n?"Mutated chain_residue "+Object.keys(n)+"; ":"";s||a&&x||(c+=this.getPDBHeader(A-1,g,t,e.structure)),++A}e.chain!=T&&e.structure==M&&T&&(c+="TER\n");let u=e.chain+"_"+e.resi;if(n&&n.hasOwnProperty(u)){k.hasOwnProperty(u)||(c+=n[u],k[u]=1);continue}let m="";m+=e.het?"HETATM":"ATOM ",m+=r.toString().padStart(5," "),m+=" ";let f=e.name.trim();isNaN(f.substr(0,1))||(f=f.substr(1)+f.substr(0,1)),4==f.length?m+=f:(m+=" ",f=f.replace(/\*/g,"'"),"O1P"==f?f="OP1":"O2P"==f?f="OP2":"C5M"==f&&(f="C7 "),m+=f.padEnd(3," ")),m+=" ";let b=e.resn;if(m+=b.length<=3?b.padStart(3," "):b.substr(0,3),a&&A>2&&(l.proteins.hasOwnProperty(e.serial)||l.nucleotides.hasOwnProperty(e.serial)))e.structure==M&&e.chain==T||(R=E<36?"abcdefghijklmnopqrstuvwxyz0123456789"[E]:"?",++E),m+=" "+R;else if(e.chain.length>=2){let t=e.chain.replace(/_/gi,"").substr(0,2);o&&(t=" "+t.substr(0,1)),m+=t}else 1==e.chain.length?m+=" "+e.chain.substr(0,1):0==e.chain.length&&(m+=" A");let C=e.resi;!isNaN(C)&&e.chain.length>3&&!isNaN(e.chain.substr(3))&&(C=C-1+parseInt(e.chain.substr(3)));let v=parseInt(C);m+=v.toString().length<=4?v.toString().padStart(4," "):v.toString().substr(0,4);let _=e.resi.toString().substr(e.resi.toString().length-1,1);if(isNaN(_)?m+=_:m+=" ",m+=" ".padStart(3," "),m+=e.coord.x.toFixed(3).toString().padStart(8," "),m+=e.coord.y.toFixed(3).toString().padStart(8," "),m+=e.coord.z.toFixed(3).toString().padStart(8," "),t&&e.het){let t=1.5,i=0;"C"==e.elem?t=1.908:"N"==e.elem?t=1.824:"O"==e.elem?t=1.6612:"H"==e.elem?t=1.25:"S"==e.elem?t=2:"P"==e.elem?t=2.1:d.parasCls.vdwRadii.hasOwnProperty(e.elem)&&(t=d.parasCls.vdwRadii[e.elem]),void 0!==d.cfg.cid&&void 0!==e.crg?i=e.crg:h.hasOwnProperty(r)?i=1.38:p.hasOwnProperty(r)?i=-.595:d.parasCls.ionCharges.hasOwnProperty(e.elem)&&(i=d.parasCls.ionCharges[e.elem]),m+=i.toFixed(4).toString().padStart(8," "),m+=t.toFixed(4).toString().padStart(7," ")}else{m+="1.00".padStart(6," ");let t=" ";m+=e.b?parseFloat(e.b).toFixed(2).toString().padStart(6," "):t.padStart(6," "),m+=" ".padStart(10," "),m+=e.elem.padStart(2," "),m+=" ".padStart(2," ")}if(e.het&&e.bonds.length>0){w+="CONECT"+r.toString().padStart(5," ");let t={};for(let i=0,s=e.bonds.length;i<s;++i)e.bonds[i]&&!t.hasOwnProperty(e.bonds[i])&&(w+=e.bonds[i].toString().padStart(5," "),t[e.bonds[i]]=1);w+="\n"}c+=m+"\n",M=e.structure,T=e.chain}return a&&x||(c+=w,x&&(c+="\nENDMDL\n")),c}getSecondary(e){let t=this.icn3d,i=t.icn3dui,s='{"data": [\n',n="",r="",a={};for(let s in e){let e=t.atoms[s],o=e.structure+"_"+e.chain,l=e.resi,d=i.utilsCls.residueName2Abbr(e.resn),c=this.secondary2Abbr(e.ss);e.ssbegin?c+=" begin":e.ssend&&(c+=" end"),o==n||a[o]||(a[o]={resi:[],resn:[],secondary:[]}),o==n&&l==r||(a[o].resi.push(l),a[o].resn.push(d),a[o].secondary.push(c)),n=o,r=l}let o=Object.keys(a),l=o.length;for(let e=0;e<l;++e){let t=o[e];s+='{"chain": "'+t+'",\n',s+='"resi": "'+a[t].resi.join(",")+'",\n',s+='"resn": "'+a[t].resn.join(",")+'",\n',s+='"secondary": "'+a[t].secondary.join(",")+'"',s+=e<l-1?"},\n":"}\n"}return s+="]}\n",s}secondary2Abbr(e){return this.icn3d.icn3dui,"helix"==e?"H":"sheet"==e?"E":"c"}getSelectedResiduePDB(){let e=this.icn3d,t="",i=e.icn3dui.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);return t+=this.getAtomPDB(i),t}getPDBHeader(e,t,i,s){let n=this.icn3d;n.icn3dui,void 0===e&&(e=0);let r="",a=s||Object.keys(n.structures)[e],o=i?a+"2":a;if(r+="HEADER PDB From iCn3D".padEnd(62," ")+o+"\n",0==e){let e=n.molTitle.length>50?n.molTitle.substr(0,47)+"...":n.molTitle;-1!=e.indexOf('"')&&(e=""),i&&(e=i+e),r+="TITLE "+e+"\n"}return t&&t[a]&&(r+=t[a]),r}showTitle(){var e=this.icn3d,t=e.icn3dui;let i=e.molTitle?e.molTitle:"",s="black"==e.opts.background?t.htmlCls.GREYD:"black";if(void 0===e.inputid)i.length>40&&(i=i.substr(0,40)+"..."),$("#"+e.pre+"title").html(i);else if(void 0!==t.cfg.cid){let t=this.getLinkToStructureSummary();$("#"+e.pre+"title").html("PubChem CID <a id='"+e.pre+"titlelink' href='"+t+"' style='color:"+s+"' target='_blank'>"+e.inputid.toUpperCase()+"</a>: "+i)}else if(void 0!==t.cfg.smiles){let i=decodeURIComponent(t.cfg.smiles);i.length>60&&(i=i.substr(0,60)+"..."),$("#"+e.pre+"title").html("SMILES: "+i)}else if(void 0!==t.cfg.align)i="VAST+ alignment of "+Object.keys(e.structures),$("#"+e.pre+"title").html(i);else if(void 0!==t.cfg.chainalign){i="Dynamic Structure Alignment of Chains: "+t.cfg.chainalign.split(","),$("#"+e.pre+"title").html(i)}else{let n=Object.keys(t.utilsCls.getStructures(e.dAtoms));if(n.length>1){i="Multiple structures: ";for(let e=0,t=n.length;e<t;++e){i+='<a href="'+(isNaN(n[e])&&n[e].length>5?"https://alphafold.ebi.ac.uk/entry/"+n[e]:"https://www.ncbi.nlm.nih.gov/structure/?term="+n[e])+'" style="color:'+s+'" target="_blank">'+n[e]+"</a>",e<t-1&&(i+=", ")}$("#"+e.pre+"title").html(i)}else if(1==n.length){let e=isNaN(n[0])&&n[0].length>5?"https://alphafold.ebi.ac.uk/entry/"+n[0]:"https://www.ncbi.nlm.nih.gov/structure/?term="+n[0];this.setStructureTitle(e,i,s)}}}setStructureTitle(e,t,i){var s=this.icn3d,n=s.icn3dui;t.length>40&&(t=t.substr(0,40)+"...");let r,a,o=s.inputid;if(-1!=o.indexOf("http"))a="Data from",e=o,r=o;else{let e=n.utilsCls.getHlStructures(),i=!1,l=!1;for(let t in e)t.length>5?l=!0:i=!0;let d=Object.keys(e);if(o=d.join(","),r=n.cfg.refseqid||n.cfg.protein?s.inputid:o.toUpperCase(),i&&l?a="AlphaFold/PDB ID":i?a="PDB ID":l&&(a="AlphaFold ID"),d.length>1&&(a+="s"),s.molTitleHash){t="";for(let e=0,i=d.length;e<i;++e)t+=s.molTitleHash[d[e]],e<i-1&&(t+="; ")}}if(n.cfg.refseqid?a="NCBI Protein Acc.":n.cfg.protein&&(a="Protein/Gene Name"),o&&o.substr(0,4)!=s.defaultPdbId)if(n.cfg.blast_rep_id){let e=n.cfg.oriQuery_id?n.cfg.oriQuery_id:n.cfg.query_id,i=n.cfg.oriBlast_rep_id?n.cfg.oriBlast_rep_id:n.cfg.blast_rep_id;e.length>20&&(e=e.substr(0,17)+"..."),r="Query: "+e+"; target: "+i,$("#"+s.pre+"title").html(r+", "+t)}else $("#"+s.pre+"title").html(a+" <a id='"+s.pre+"titlelink' href='"+e+"' style='color:"+i+"' target='_blank'>"+r+"</a>: "+t);else $("#"+s.pre+"title").html(t)}getLinkToStructureSummary(e){var t=this.icn3d,i=t.icn3dui;let s="https://www.ncbi.nlm.nih.gov/structure/?term=";if(s=void 0!==i.cfg.cid?"https://www.ncbi.nlm.nih.gov/pccompound/?term=":void 0!==i.cfg.refseqid?"https://www.ncbi.nlm.nih.gov/protein/":void 0!==i.cfg.afid?"https://alphafold.ebi.ac.uk/search/text/":Object.keys(t.structures).length>1?"https://www.ncbi.nlm.nih.gov/structure/?term=":i.htmlCls.baseUrl+"pdb/",void 0===t.inputid)s="https://www.ncbi.nlm.nih.gov/pccompound/?term="+t.molTitle;else{let n=t.inputid.split("_");1===n.length?(s+=t.inputid,e&&i.htmlCls.clickMenuCls.setLogCmd("link to "+t.inputid+": "+s,!1)):2===n.length&&(i.cfg.afid?s+=n[0]+" "+n[1]:s+=n[0]+" OR "+n[1],e&&i.htmlCls.clickMenuCls.setLogCmd("link to structures "+n[0]+" and "+n[1]+": "+s,!1))}return s}setEntrezLinks(e){var t=this.icn3d,i=t.icn3dui;let s,n=Object.keys(t.structures);if(1===n.length){s="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0],i.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+": "+s,!1);let r=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(s,r)}else if(2===n.length){s="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0]+" OR "+n[1],i.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+" OR "+n[1]+": "+s,!1);let r=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(s,r)}}}class mp{constructor(e){this.icn3d=e}async shareLink(e,t){let i=this.icn3d,s=i.icn3dui,n=this.shareLinkUrl(),r=n.length>4e3||0!==n.indexOf("http"),a=Object.keys(i.structures).join("_");if(a==i.defaultPdbId&&(i.filename?a=i.filename:i.inputid&&(a=i.inputid)),e){if(t||i.bInputfile||r)return void i.saveFileCls.saveFile(a+"_icn3d_loadable.png","png")}else{if(i.bInputfile&&!i.bInputUrlfile)return void alert("Share Link does NOT work when the data are from custom files. Please save 'iCn3D PNG Image' in the File menu and open it in iCn3D.");if(r)return void alert("The url is more than 4000 characters and may not work. Please save 'iCn3D PNG Image' or 'State File' and open them in iCn3D.");s.htmlCls.clickMenuCls.setLogCmd("share link: "+n,!1)}let o="Problem in getting shortened URL";if(!s.cfg.notebook){let t=await this.getShareLinkPrms(n,e);if(void 0!==t.shortLink&&(o=t.shortLink,e)){let e=o.split("/"),t=e[e.length-1];i.saveFileCls.saveFile(a+"-"+t+".png","png");let s='<div style="float:left; border: solid 1px #0000ff; padding: 5px; margin: 10px; text-align:center;">';s+='<a href="https://www.ncbi.nlm.nih.gov/Structure/icn3d/share2.html?'+t+'" target="_blank">',s+='<img style="height:300px" src ="'+a+"-"+t+'.png"><br>\n',s+="\x3c!--Start of your comments==================--\x3e\n";let n=i.yournote?": "+i.yournote.replace(/\n/g,"<br>").replace(/; /g,", "):"";s+="PDB "+a.toUpperCase()+n+"\n",s+="\x3c!--End of your comments====================--\x3e\n",s+="</a>",s+="</div>\n\n",i.saveFileCls.saveFile(a+"-"+t+".html","html",s)}e&&void 0===t.shortLink&&i.saveFileCls.saveFile(a+"_icn3d_loadable.png","png"),o="https://www.ncbi.nlm.nih.gov/Structure/icn3d/share2.html?"+o,$("#"+i.pre+"short_url").val(o),$("#"+i.pre+"short_url_title").val(o+"&t="+i.yournote)}let l=this.shareLinkUrl(void 0,!0),d="view = icn3dpy.view(q='"+(s.cfg.url?"url="+s.cfg.url:s.cfg.idname+"="+s.cfg.idvalue)+"',command='"+l+"')\nview";(s.cfg.url||s.cfg.idname)&&$("#"+i.pre+"jn_commands").val(d),$("#"+i.pre+"ori_url").val(n),e||s.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL or Jupyter Notebook Commands")}getShareLinkPrms(e,t){let i=this.icn3d,s=i.icn3dui,n="https://icn3d.link/?longurl="+encodeURIComponent(e);return new Promise((function(r,a){$.ajax({url:n,dataType:"json",cache:!0,success:function(e){r(e)},error:function(n,r,a){let o="Problem in getting shortened URL";$("#"+i.pre+"ori_url").val(e),$("#"+i.pre+"short_url").val(o),$("#"+i.pre+"short_url_title").val(o+"&t="+i.yournote),t||s.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL")}})}))}shareLinkUrl(e,t,i){let s=this.icn3d,n=s.icn3dui,r=n.htmlCls.baseUrl+"icn3d/full_"+n.REVISION+".html?",a="";if(n.cfg.bSidebyside&&(r=n.htmlCls.baseUrl+"icn3d/full2.html?"),s.bInputUrlfile){r=window.location.href.split("?")[0]+"?"+s.inputurl+"&"}let o,l={};for(let e in s.cfg){let t=s.cfg[e];"inpara"!==e&&"command"!==e&&"usepdbnum"!==e&&"date"!==e&&"v"!==e&&void 0!==t&&("width"===e&&"100%"===t||"height"===e&&"100%"===t||"resize"===e&&!0===t||"showlogo"===e&&!0===t||"showmenu"===e&&!0===t||"showtitle"===e&&!0===t||"showcommand"===e&&!0===t||"mobilemenu"===e&&!1===t||"showanno"===e&&!1===t||"showseq"===e&&!1===t||"showalignseq"===e&&!1===t||"show2d"===e&&!1===t||"showsets"===e&&!1===t||"rotate"===e&&"right"===t||"command"!==e&&("options"===e?Object.keys(t).length>0&&(l[e]=JSON.stringify(t)):!0===t?l[e]=1:!1===t?l[e]=0:""!==t&&(l[e]=t)))}s.bAfMem?l.afmem="on":(n.cfg.afid||1==Object.keys(s.structures).length&&Object.keys(s.structures)[0].length>5)&&(l.afmem="off");let d=-1;void 0!==n.cfg.inpara&&(d=n.cfg.inpara.indexOf("&command=")),o=-1!==d?n.cfg.inpara.substr(0,d):n.cfg.inpara;let c=!1;if(!s.bInputUrlfile){let e=o&&o.substr(1)?o.substr(1).split("&"):[];for(let t=0,i=e.length;t<i;++t){let i=e[t].split("=");2==i.length&&(l[i[0]]=i[1])}n.cfg.idname&&!l[n.cfg.idname]&&(r+=n.cfg.idname+"="+n.cfg.idvalue+"&");for(let e in l)"v"!==e&&("date"===e&&(c=!0),r+=e+"="+l[e]+"&")}let h,p=n.utilsCls.getDateDigitStr();c||(r+="date="+p+"&"),r+="v="+n.REVISION+"&",r+="command=",h=t&&void 0!==o?1:0,(e||s.bInputUrlfile)&&(h=0);let u={};u.factor=s._zoomFactor,u.mouseChange=s.mouseChange,u.quaternion=s.quaternion;let m="",f="",g="toggle highlight",b=0;if(s.commands.length>h){f=s.commands[h].split("|||")[0].split("&command=")[0].trim(),-1!==f.indexOf(g)&&++b}let C,v=h+1,_="";for(let e=s.commands.length;v<e;++v){let e=s.commands[v].split("|||")[0].split("&command=")[0].trim();0==f.indexOf("select sets")&&0===e.indexOf("select sets")&&-1===f.indexOf(" name ")||-1!==f.indexOf("pickatom")&&-1!==e.indexOf("pickatom")||"show selection"==f&&-1!=s.commands.slice(v).toString().indexOf("show selection")||f==e||(-1!==f.indexOf(g)?++b:_+=v===h+1?f:_?"; "+f:f),-1==f.indexOf("load ")&&(m+=f+"\n"),f=e}return f&&(_&&(_+="; "),b>0&&b%2==0&&f!==g&&(_+=g+"; "),_+=f+"|||"+s.transformCls.getTransformationStr(u),m+=f+"|||"+s.transformCls.getTransformationStr(u)+"\n"),r+=_,a=_,m=m.replace(/!/g,Object.keys(s.structures)[0]+"_"),(s.bEsmfold||s.bInputfile&&!s.bInputUrlfile||s.bInputUrlfile&&s.bAppend||r.length>4e3)&&(r=m),void 0!==s.structures&&1==Object.keys(s.structures).length&&void 0!==s.inputid&&(C=Object.keys(s.structures)[0],r=r.replace(new RegExp(C+"_","g"),"!"),a=a.replace(new RegExp(C+"_","g"),"!")),void 0!==n.cfg.blast_rep_id&&(r=r.replace(new RegExp("blast_rep_id=!","g"),"blast_rep_id="+C+"_")),i?m:t?a:r}getPngText(){let e=this.icn3d;e.icn3dui;let t="";t+="\nStart of type file======\n",t+="pdb\n",t+="End of type file======\n",t+="Start of data file======\n",t+=e.saveFileCls.getAtomPDB(e.atoms),t+="End of data file======\n";return t+="Start of state file======\n",t+=this.shareLinkUrl(!0,void 0,!0)+"\n",t+="End of state file======\n",t=t.replace(/!/g,Object.keys(e.structures)[0]+"_"),t}}class fp{constructor(e){this.icn3d=e}setThichknessFor3Dprint(){let e=this.icn3d,t=e.icn3dui;e.lineRadius=1,e.coilWidth=1.2,e.cylinderRadius=.8,e.crosslinkRadius=.8,e.traceRadius=1,e.dotSphereScale=.6,e.sphereRadius=1.5,e.ribbonthickness=1,e.helixSheetWidth=2,e.nucleicAcidWidth=1.4,t.htmlCls.setHtmlCls.setCookieForThickness()}prepareFor3Dprint(){let e=this.icn3d,t=e.icn3dui;if(e.bShowHighlight=!1,e.hlObjectsCls.removeHlObjects(),e.bDashedLines=!1,e.bSetThickness||void 0!==t.cfg.cid||this.setThichknessFor3Dprint(),void 0!==e.lines.hbond)for(let t=0,i=e.lines.hbond.length;t<i;++t){e.lines.hbond[t].dashed=!1,e.bDashedLines=!0}if(void 0!==e.lines.distance)for(let t=0,i=e.lines.distance.length;t<i;++t){e.lines.distance[t].dashed=!1,e.bDashedLines=!0}e.drawCls.draw(),e.bShowHighlight=!0}resetAfter3Dprint(){let e=this.icn3d,t=e.icn3dui;if(void 0!==e.lines.hbond)for(let t=0,i=e.lines.hbond.length;t<i;++t){e.lines.hbond[t].dashed=!0}if(void 0!==e.lines.distance)for(let t=0,i=e.lines.distance.length;t<i;++t){e.lines.distance[t].dashed=!0}e.lineRadius=.1,e.coilWidth=.3,e.cylinderRadius=.4,e.crosslinkRadius=.4,e.traceRadius=.4,e.dotSphereScale=.3,e.sphereRadius=1.5,e.cylinderHelixRadius=1.6,e.ribbonthickness=.2,e.helixSheetWidth=1.3,e.nucleicAcidWidth=.8,t.htmlCls.setHtmlCls.setCookieForThickness()}removeOneStabilizer(e){let t,i=this.icn3d;i.icn3dui;for(let s=0,n=i.pairArray.length;s<n;s+=2){let n=this.getResidueRepAtom(i.pairArray[s]),r=this.getResidueRepAtom(i.pairArray[s+1]);if(null!=e)for(let i=0,a=e.length;i<a;i+=2){let a=this.getResidueRepAtom(e[i]),o=this.getResidueRepAtom(e[i+1]);if(n.serial==a.serial&&r.serial==o.serial||n.serial==o.serial&&r.serial==a.serial){t=s;break}}if(void 0!==t)break}void 0!==t&&i.pairArray.splice(t,2)}outputSelection(){let e=this.icn3d,t=e.icn3dui,i={};for(let t in e.hAtoms){i[e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi]=1}let s=Object.keys(i).sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let i=e.lastIndexOf("_"),s=t.lastIndexOf("_");if(e.substr(0,i)<t.substr(0,i))return-1;if(e.substr(0,i)>t.substr(0,i))return 1;if(e.substr(0,i)==t.substr(0,i)){if(parseInt(e.substr(i+1))<parseInt(t.substr(s+1)))return-1;if(parseInt(e.substr(i+1))>parseInt(t.substr(s+1)))return 1;if(parseInt(e.substr(i+1))==parseInt(t.substr(s+1)))return 0}}})),n="<table><tr><th>Structure</th><th>Chain</th><th>Residue Number</th></tr>";for(let e=0,t=s.length;e<t;++e){let t=s[e].indexOf("_"),i=s[e].lastIndexOf("_");n+="<tr><td>"+s[e].substr(0,t)+"</td><td>"+s[e].substr(t+1,i-t-1)+"</td><td>"+s[e].substr(i+1)+"</td></tr>"}let r=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(r+"_residues.txt","html",n)}addStabilizer(){let e=this.icn3d,t=e.icn3dui,i=3.5;if(Object.keys(e.dAtoms).length>0){let s,n={},r=12.25,a=3.2*3.2;for(let t in e.dAtoms){let i=e.atoms[t];!e.nucleotides.hasOwnProperty(i.serial)||"N1"!==i.name&&"N2"!==i.name&&"N3"!==i.name&&"N4"!==i.name&&"N6"!==i.name&&"O2"!==i.name&&"O6"!==i.name||(s=i.structure+"_"+i.chain+"_"+i.resi+"_"+i.name,n[s]=i)}let o=Object.keys(n),l=o.length;void 0===e.pairArray&&(e.pairArray=[]);for(let t=0;t<l;++t)for(let s=t+1;s<l;++s){let l=o[t],d=o[s],c=Math.abs(n[l].coord.x-n[d].coord.x);if(c>i)continue;let h=Math.abs(n[l].coord.y-n[d].coord.y);if(h>i)continue;let p=Math.abs(n[l].coord.z-n[d].coord.z);if(p>i)continue;let u=c*c+h*h+p*p;u>r||u<a||(e.pairArray.push(n[l].serial),e.pairArray.push(n[d].serial))}let d=6,c={};for(let t in e.dAtoms){let i=e.atoms[t];c[i.structure+"_"+i.chain+"_"+i.resi]=1}let h={};for(let t in e.chemicals){let i=e.atoms[t],s=i.structure+"_"+i.chain+"_"+i.resi;c.hasOwnProperty(s)&&(h[s]=1)}for(let t in e.ions){let i=e.atoms[t],s=i.structure+"_"+i.chain+"_"+i.resi;c.hasOwnProperty(s)&&(h[s]=1)}let p=Object.keys(e.chains);for(let t=0,i=p.length;t<i;++t){let i,s=p[t],n=0,r=0;for(let t=0,a=e.chainsSeq[s].length;t<a;++t)i=s+"_"+e.chainsSeq[s][t].resi,"c"!=e.secondaries[i]&&"E"!=e.secondaries[i]&&"H"!=e.secondaries[i]||(n%3!=0&&e.resid2ncbi[e.chainsSeq[s][t].resi]==e.resid2ncbi[r]+1||c.hasOwnProperty(i)&&(h[i]=1),++n,r=e.chainsSeq[s][t].resi);"c"!=e.secondaries[i]&&"E"!=e.secondaries[i]&&"H"!=e.secondaries[i]||c.hasOwnProperty(i)&&(h[i]=1)}let u=Object.keys(h);void 0===e.pairArray&&(e.pairArray=[]);let m=t.hashUtilsCls.exclHash(e.dAtoms,e.water);for(let i=0,s=u.length;i<s;++i){let s=u[i],n=e.secondaries[s],r=e.contactCls.getNeighboringAtoms(m,t.hashUtilsCls.hash2Atoms(e.residues[s],e.atoms),d),a=Object.keys(r).sort(),o=Object.keys(e.residues[s]).sort(),l=!1;if(e.proteins.hasOwnProperty(o[0])){o=[o[0]],l=!0;let t=s.substr(0,s.lastIndexOf("_")),i=e.ParserUtilsCls.getResiNCBI(t,s.substr(s.lastIndexOf("_")+1)),d={};for(let s in r){if(e.chemicals.hasOwnProperty(s)||e.ions.hasOwnProperty(s))continue;let r=e.atoms[s];if(isNaN(r.resi))continue;let a=e.ParserUtilsCls.getResiNCBI(t,r.resi);("c"==n&&(a>i+1||a<i-1)||"E"==n&&(a>i+2||a<i-2)||"H"==n&&(a>i+4||a<i-4))&&(d[s]=1)}a=Object.keys(d).sort()}if(a.length>0&&o.length>0)if(l){let t=parseInt((a.length+.5)/2);e.pairArray.push(o[0]),e.pairArray.push(a[t])}else{let t=10,i=parseInt(a.length/(t+1));for(let s=0,n=o.length;s<n;++s)if(s%t==0){let n=parseInt(s/t)*i,r=n<a.length?n:a.length-1;e.pairArray.push(o[s]),e.pairArray.push(a[r]),o.length<t+1&&(e.pairArray.push(o[s]),e.pairArray.push(a[a.length-1]))}}}}}hideStabilizer(){let e=this.icn3d;e.icn3dui,e.pairArray=[],e.lines.stabilizer=[],e.stabilizerpnts=[];for(let t in e.water)e.atoms[t].style=e.opts.water}getResidueRepAtom(e){let t=this.icn3d;t.icn3dui;let i,s=t.atoms[e],n=s.structure+"_"+s.chain+"_"+s.resi;if(t.proteins.hasOwnProperty(e)||t.nucleotides.hasOwnProperty(e))for(let e in t.residues[n]){let s=t.atoms[e];if("CA"===s.name||"N3"===s.name){i=t.atoms[e];break}}else i=s;return void 0===i&&(i=s),i}}class gp{constructor(e){this.icn3d=e}exportStlFile(e){let t=this.icn3d,i=t.icn3dui;void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&(t.threshbox=180/Math.pow(t.biomtMatrices.length,.33),t.applyMapCls.removeSurfaces(),t.applyMapCls.applySurfaceOptions(),t.applyMapCls.removeMaps(),t.applyMapCls.applyMapOptions(),t.applyMapCls.removeEmmaps(),t.applyMapCls.applyEmmapOptions());let s=this.saveStlFile(),n=Object.keys(i.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".stl","binary",s),void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length>t.maxAtoms3DMultiFile){alert(t.biomtMatrices.length+" files will be generated for this assembly. Please merge these files using some software and 3D print the merged file.");let i=new gi;i.identity();let r=1;for(let a=0;a<t.biomtMatrices.length;a++){let o=t.biomtMatrices[a];if(void 0===o)continue;if(o.equals(i))continue;let l=100*(a+1);setTimeout(function(i,r){s=this.saveStlFile(i),t.saveFileCls.saveFile(n+e+r+".stl","binary",s),s=""}.bind(this,o,r),l),++r}t.threshbox=180}}exportVrmlFile(e){let t=this.icn3d,i=t.icn3dui;void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&(t.threshbox=180/Math.pow(t.biomtMatrices.length,.33),t.applyMapCls.removeSurfaces(),t.applyMapCls.applySurfaceOptions(),t.applyMapCls.removeMaps(),t.applyMapCls.applyMapOptions(),t.applyMapCls.removeEmmaps(),t.applyMapCls.applyEmmapOptions());let s=this.saveVrmlFile(),n=Object.keys(i.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".wrl","text",s),void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length>t.maxAtoms3DMultiFile){alert(t.biomtMatrices.length+" files will be generated for this assembly. Please merge these files using some software and 3D print the merged file.");let i=new gi;i.identity();let n=1;for(let r=0;r<t.biomtMatrices.length;r++){let a=t.biomtMatrices[r];if(void 0===a)continue;if(a.equals(i))continue;let o=100*(r+1);setTimeout(function(i,n){s=this.saveVrmlFile(i),t.saveFileCls.saveFile(t.inputid+e+n+".wrl","text",s),s=""}.bind(this,a,n),o),++n}t.threshbox=180}}getFaceCnt(e){this.icn3d.icn3dui;let t=0;for(let i=0,s=e.children.length;i<s;++i){let s=e.children[i];"Sprite"!==s.type&&(t+=s.geometry.getIndex().array.length/3)}return t}saveStlFile(e){let t=this.icn3d,i=t.icn3dui;if(Object.keys(t.dAtoms).length>7e4)return alert("Please display a subset of the structure to export 3D files. Then merge the files for 3D printing..."),[""];t.threeDPrintCls.prepareFor3Dprint();let s=0;s+=this.getFaceCnt(t.mdl),s+=this.getFaceCnt(t.mdl_ghost);let n=[],r=new Uint8Array(84),a="STL file for the structure(s) ",o=Object.keys(t.structures);for(let e=0,t=o.length;e<t;++e)a+=o[e],e<t-1&&(a+=", ");a.length>80&&(a=a.substr(0,80));for(let e=0;e<80;++e)e<a.length?r[e]=i.convertTypeCls.passInt8([a.charCodeAt(e)])[0]:r[e]=i.convertTypeCls.passInt8([" ".charCodeAt(0)])[0];if(r=void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile?this.updateArray(r,i.convertTypeCls.passInt32([s*t.biomtMatrices.length]),80):this.updateArray(r,i.convertTypeCls.passInt32([s]),80),n.push(new Blob([r],{type:"application/octet-stream"})),n=this.processStlMeshGroup(t.mdl,n,e),n=this.processStlMeshGroup(t.mdl_ghost,n,e),void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile){let e=new gi;e.identity();for(let i=0;i<t.biomtMatrices.length;i++){let s=t.biomtMatrices[i];void 0!==s&&(s.equals(e)||(n=this.processStlMeshGroup(t.mdl,n,s),n=this.processStlMeshGroup(t.mdl_ghost,n,s)))}}return t.threeDPrintCls.resetAfter3Dprint(),n}updateArray(e,t,i){this.icn3d.icn3dui;for(let s=0,n=t.length;s<n;++s)e[i+s]=t[s];return e}processStlMeshGroup(e,t,i){let s=this.icn3d.icn3dui;for(let n=0,r=e.children.length;n<r;++n){let r=e.children[n];if("Sprite"===r.type)continue;let a=r.geometry,o=a.getAttribute("position").array,l=a.getIndex().array,d=r.position,c=r.scale,h=r.matrix,p=new Uint8Array(l.length/3*50),u=0;for(let e=0,t=l.length;e<t;e+=3){let t,n,r,m=l[e],f=l[e+1],g=l[e+2],b=new mt(o[3*m],o[3*m+1],o[3*m+2]),C=new mt(o[3*f],o[3*f+1],o[3*f+2]),v=new mt(o[3*g],o[3*g+1],o[3*g+2]);"SphereGeometry"==a.type||"BoxGeometry"==a.type?(t=b.clone().multiply(c).add(d),n=C.clone().multiply(c).add(d),r=v.clone().multiply(c).add(d)):"CylinderGeometry"==a.type?(t=b.clone().applyMatrix4(h),n=C.clone().applyMatrix4(h),r=v.clone().applyMatrix4(h)):(t=b.clone(),n=C.clone(),r=v.clone()),p=this.updateArray(p,s.convertTypeCls.passFloat32([0,0,0]),u),u+=12,void 0!==i&&(t.applyMatrix4(i),n.applyMatrix4(i),r.applyMatrix4(i)),p=this.updateArray(p,s.convertTypeCls.passFloat32([t.x,t.y,t.z]),u),u+=12,p=this.updateArray(p,s.convertTypeCls.passFloat32([n.x,n.y,n.z]),u),u+=12,p=this.updateArray(p,s.convertTypeCls.passFloat32([r.x,r.y,r.z]),u),u+=12,t=n=r=void 0,p=this.updateArray(p,s.convertTypeCls.passInt16([0]),u),u+=2}t.push(new Blob([p],{type:"application/octet-stream"})),p=null}return t}saveVrmlFile(e){let t=this.icn3d;if(t.icn3dui,Object.keys(t.dAtoms).length>5e4)return alert("Please display a subset of the structure to export 3D files. Then merge the files for 3D printing..."),[""];t.threeDPrintCls.prepareFor3Dprint();let i=[];i.push("#VRML V2.0 utf8\n");let s=0,n=this.processVrmlMeshGroup(t.mdl,i,s,e);if(i=n.vrmlStrArray,s=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,i,s,e),i=n.vrmlStrArray,s=n.vertexCnt,void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile){let e=new gi;e.identity();for(let r=0;r<t.biomtMatrices.length;r++){let a=t.biomtMatrices[r];void 0!==a&&(a.equals(e)||(n=this.processVrmlMeshGroup(t.mdl,i,s,a),i=n.vrmlStrArray,s=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,i,s,a),i=n.vrmlStrArray,s=n.vertexCnt))}}return i}processVrmlMeshGroup(e,t,i,s){let n=this.icn3d.icn3dui;for(let i=0,r=e.children.length;i<r;++i){let r=e.children[i];if("Sprite"===r.type)continue;let a=r.geometry;r.material.type,a.type;let o=a.getAttribute("position").array,l=a.getAttribute("color")?a.getAttribute("color").array:[],d=a.getIndex().array,c=r.position,h=r.scale,p=r.matrix,u=n.parasCls.thr(1,1,1);"SphereGeometry"!=a.type&&"BoxGeometry"!=a.type&&"CylinderGeometry"!=a.type||void 0!==r.material&&(u=r.material.color),t.push("Shape {\n"),t.push("geometry IndexedFaceSet {\n"),t.push("coord Coordinate { point [ ");let m=[];for(let e=0,i=o.length;e<i;e+=3){let r,l=new mt(o[e],o[e+1],o[e+2]);r="SphereGeometry"==a.type||"BoxGeometry"==a.type?l.clone().multiply(h).add(c):"CylinderGeometry"==a.type?l.clone().applyMatrix4(p):l.clone(),void 0!==s&&r.applyMatrix4(s),t.push(r.x.toPrecision(5)+" "+r.y.toPrecision(5)+" "+r.z.toPrecision(5)),r=void 0,e<i-3&&t.push(", "),m.push(n.parasCls.thr(1,1,1))}t.push(" ] }\n");let f="",g="";for(let e=0,t=d.length;e<t;e+=3){let i,s=d[e],n=d[e+1],r=d[e+2];i="SphereGeometry"==a.type||"BoxGeometry"==a.type||"CylinderGeometry"==a.type?u:new ls(l[3*s],l[3*s+1],l[3*s+2]),f+=s+" "+n+" "+r,e<t-3&&(f+=", -1, "),m[s]=i,m[n]=i,m[r]=i}for(let e=0,t=m.length;e<t;++e){let i=m[e];g+=i.r.toPrecision(3)+" "+i.g.toPrecision(3)+" "+i.b.toPrecision(3),e<t-1&&(g+=", ")}t.push("coordIndex [ "+f+" ]\n"),t.push("color Color { color [ "+g+" ] } colorPerVertex TRUE\n"),t.push(" }\n"),t.push("}\n")}return{vrmlStrArray:t,vertexCnt:i}}}class bp{constructor(e){this.icn3d=e}rayCaster(e,t){let i=this.icn3d;i.icn3dui,i.opts&&"none"!=i.opts.effect||this.rayCasterBase(e,t)}rayCasterBase(e,t){let i=this.icn3d;i.icn3dui;let s=e.pageX,n=e.pageY;e.originalEvent.targetTouches&&e.originalEvent.targetTouches[0]&&(s=e.originalEvent.targetTouches[0].pageX,n=e.originalEvent.targetTouches[0].pageY);let r=i.oriContainer.offset().left,a=i.oriContainer.offset().top,o=i.oriContainer.width(),l=i.oriContainer.height(),d=s-r,c=n-a;i.mouse.x=d/o*2-1,i.mouse.y=-c/l*2+1;let h=new mt;h.x=i.mouse.x,h.y=i.mouse.y,i.cam_z>0?h.z=-1:h.z=1,i.cam===i.perspectiveCamera?(i.cam_z>0?h.z=-1:h.z=1,h.unproject(i.cam),i.raycaster.set(i.cam.position,h.sub(i.cam.position).normalize())):i.cam===i.orthographicCamera&&(i.cam_z>0?h.z=1:h.z=-1,h.unproject(i.cam),i.raycaster.set(h,new mt(0,0,-1).transformDirection(i.cam.matrixWorld)));let p=this.isIntersect(i.objects,i.mdl,t,d,c);p||(p=this.isIntersect(i.objects_ghost,i.mdl_ghost,t,d,c))}isIntersect(e,t,i,s,n){let r=this.icn3d;r.icn3dui;let a=r.raycaster.intersectObjects(e),o=!1,l=t.position;if(a.length>0){a[0].point.sub(l);let e=r.rayThreshold,t=this.getAtomsFromPosition(a[0].point,e);for(;!t&&e<10;)e+=.5,t=this.getAtomsFromPosition(a[0].point,e);t?(o=!0,r.pickpair?i&&(r.pAtomNum%2==0?r.pAtom=t:r.pAtom2=t,++r.pAtomNum):r.pAtom=t,i?r.pickingCls.showPicking(t):r.pickingCls.showPicking(t,s,n)):console.log("No atoms were found in 10 andstrom range")}return o}getAtomsFromPosition(e,t,i){let s,n=this.icn3d,r=n.icn3dui;null==t&&(t=1);let a=i||n.dAtoms;for(s in a){let i=n.atoms[s];if(n.ions.hasOwnProperty(s)&&"sphere"===n.opts.ions){let s=r.parasCls.vdwRadii[i.elem.toUpperCase()];if(Math.abs(i.coord.x-e.x)-s>t)continue;if(Math.abs(i.coord.y-e.y)-s>t)continue;if(Math.abs(i.coord.z-e.z)-s>t)continue}else{if(i.coord.x<e.x-t||i.coord.x>e.x+t)continue;if(i.coord.y<e.y-t||i.coord.y>e.y+t)continue;if(i.coord.z<e.z-t||i.coord.z>e.z+t)continue}return i}return null}}class Cp{constructor(e){this.icn3d=e}setControl(){let e=this.icn3d,t=e.icn3dui;if(t.bNode)return;let i=this;e.WIDTH=e.container.width(),e.HEIGHT=e.container.height(),e.applyCenterCls.setWidthHeight(e.WIDTH,e.HEIGHT),e._zoomFactor=1,e.mouseChange=new pt(0,0),e.quaternion=new ut(0,0,0,1),e.container.bind("contextmenu",(function(e){e.preventDefault()})),e.typetext=!1,$(document).bind("keyup",(function(t){16===t.keyCode&&(e.bShift=!1),17!==t.keyCode&&224!==t.keyCode&&91!==t.keyCode||(e.bCtrl=!1)})),$("input[type=text], textarea").focus((function(){e.typetext=!0})),$("input[type=text], textarea").blur((function(){e.typetext=!1})),$(document).bind("keydown",(async function(i){if((i.shiftKey||16===i.keyCode)&&(e.bShift=!0),(i.ctrlKey||17===i.keyCode||224===i.keyCode||91===i.keyCode)&&(e.bCtrl=!0),!e.bControlGl&&!e.controls||e.bControlGl&&!window.controls)return;e.bStopRotate=!0;let s=e.bShift?90:5;if(!e.typetext)if(90===i.keyCode){let i={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?i._zoomFactor=.9:window.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),i._zoomFactor=.8*e._zoomFactor,i._zoomFactor<.1&&(i._zoomFactor=.1)):e.cam===e.perspectiveCamera?i._zoomFactor=.9:e.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),i._zoomFactor=.8*e._zoomFactor,i._zoomFactor<.1&&(i._zoomFactor=.1)),i.update=!0,e.bControlGl&&!t.bNode?window.controls.update(i):e.controls.update(i),e.bRender&&e.drawCls.render()}else if(88===i.keyCode){let i={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?i._zoomFactor=1.03:window.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),i._zoomFactor=1.01*e._zoomFactor,i._zoomFactor>10&&(i._zoomFactor=10)):e.cam===e.perspectiveCamera?i._zoomFactor=1.03:e.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),i._zoomFactor=1.01*e._zoomFactor,i._zoomFactor>10&&(i._zoomFactor=10)),i.update=!0,e.bControlGl&&!t.bNode?window.controls.update(i):e.controls.update(i),e.bRender&&e.drawCls.render()}else if(76===i.keyCode){let t=new mt(0,1,0),i=-s/180*Math.PI;e.transformCls.setRotation(t,i)}else if(74===i.keyCode){let t=new mt(0,1,0),i=s/180*Math.PI;e.transformCls.setRotation(t,i)}else if(73===i.keyCode){let t=new mt(1,0,0),i=-s/180*Math.PI;e.transformCls.setRotation(t,i)}else if(77===i.keyCode){let t=new mt(1,0,0),i=s/180*Math.PI;e.transformCls.setRotation(t,i)}else 65===i.keyCode&&Object.keys(e.structures).length>1&&await e.alternateCls.alternateWrapper()})),e.container.bind("mouseup",(function(t){e.isDragging=!1})),e.container.bind("touchend",(function(t){e.isDragging=!1})),e.container.bind("mousedown",(function(i){if(e.isDragging=!0,e.scene){if(e.bStopRotate=!0,e.pk&&(i.altKey||i.ctrlKey||i.shiftKey||18===i.keyCode||16===i.keyCode||17===i.keyCode||224===i.keyCode||91===i.keyCode)){e.highlightlevel=e.pk;let t=!0;e.rayCls.rayCaster(i,t)}e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render()}})),e.container.bind("touchstart",(function(i){if(i.preventDefault(),e.isDragging=!0,!e.scene)return;e.bStopRotate=!0,$("#"+e.pre+"popup").hide();e.rayCls.rayCaster(i,!0),e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render()})),e.container.bind("mousemove touchmove",(function(e){i.mouseMove(e)})),e.container.bind("mousewheel",(function(i){i.preventDefault(),e.scene&&(e.bStopRotate=!0,e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render())})),e.container.bind("DOMMouseScroll",(function(i){i.preventDefault(),e.scene&&(e.bStopRotate=!0,e.bControlGl&&!t.bNode?(window.controls.handleResize(),window.controls.update()):(e.controls.handleResize(),e.controls.update()),e.bRender&&e.drawCls.render())}))}mouseMove(e){let t=this.icn3d,i=t.icn3dui;if(i.bNode)return;if(e.preventDefault(),!t.scene)return;$("#"+t.pre+"popup").hide();if(t.rayCls.rayCaster(e,!1),t.bControlGl&&!i.bNode){window.controls.handleResize(),window.controls.update();for(let e in window.icn3duiHash){let t=window.icn3duiHash[e].icn3d;t.bRender&&t.drawCls.render()}}else t.controls.handleResize(),t.controls.update(),t.bRender&&t.drawCls.render()}}class vp{constructor(e){this.icn3d=e}showPicking(e,t,i){let s=this.icn3d,n=s.icn3dui;if(void 0!==n.cfg.cid&&0!=s.pk&&(s.pk=1),s.highlightlevel=s.pk,this.showPickingBase(e,t,i),0!=s.pk)if(void 0!==t&&void 0!==i){null!=n.cfg.showmenu&&1==n.cfg.showmenu&&(i+=n.htmlCls.MENU_HEIGHT);let r,a=1==s.pk?e.resn+e.resi+"@"+e.name:e.resn+e.resi,o=e.structure+"_"+e.chain;if(void 0!==s.structures&&Object.keys(s.structures).length>1?(a=o+" "+a,r=s.chainid2refpdbname&&s.chainid2refpdbname[o]?240:160,$("#"+s.pre+"popup").css("width",r+"px")):(r=s.chainid2refpdbname&&s.chainid2refpdbname[o]?160:80,$("#"+s.pre+"popup").css("width",r+"px")),s.chainid2refpdbname&&s.chainid2refpdbname[o]){let t=s.resid2refnum[o+"_"+e.resi];t&&(a+=", Ig: "+t)}$("#"+s.pre+"popup").html(a),$("#"+s.pre+"popup").css("top",i).css("left",t+20).show()}else s.hlUpdateCls.updateHlAll(),n.htmlCls.clickMenuCls.setLogCmd("pickatom "+e.serial,!0),s.selectionCls.saveSelInCommand(),s.bSphereCalc=!1,s.bHbondCalc=!1}showPickingBase(e,t,i){this.icn3d.icn3dui,void 0===t&&void 0===i&&this.showPickingHilight(e)}getPickedAtomList(e,t){let i=this.icn3d;i.icn3dui;let s={};if(1===e)s[t.serial]=1;else if(2===e){let e=t.structure+"_"+t.chain+"_"+t.resi;s=i.residues[e]}else if(3===e)s=this.selectStrandHelixFromAtom(t);else if(4===e)s=this.select3ddomainFromAtom(t);else if(5===e){let e=t.structure+"_"+t.chain;s=i.chains[e]}return s}showPickingHilight(e){let t=this.icn3d,i=t.icn3dui;t.bShift||t.bCtrl||t.hlObjectsCls.removeHlObjects(),t.pickedAtomList=this.getPickedAtomList(t.pk,e),0===t.pk?t.bShowHighlight=!1:t.bShowHighlight=!0;let s=Object.keys(t.hAtoms).length==Object.keys(t.atoms).length?{}:i.hashUtilsCls.intHash(t.hAtoms,t.pickedAtomList),n=Object.keys(s).length;if(t.bShift||t.bCtrl)if(t.bShift){if(void 0===t.prevPickedAtomList)t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e=t.firstAtomObjCls.getFirstAtomObj(t.prevPickedAtomList),s=t.firstAtomObjCls.getFirstAtomObj(t.pickedAtomList);if(e.structure+"_"+e.chain!=s.structure+"_"+s.chain)t.hAtoms=i.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e;e=i.hashUtilsCls.unionHash(e,t.prevPickedAtomList),e=i.hashUtilsCls.unionHash(e,t.pickedAtomList);let s=t.firstAtomObjCls.getFirstAtomObj(e),n=t.firstAtomObjCls.getLastAtomObj(e);for(let e=s.serial;e<=n.serial;++e)t.hAtoms[e]=1}}t.prevPickedAtomList=i.hashUtilsCls.cloneHash(t.pickedAtomList)}else t.bCtrl&&(t.hAtoms=n>0?i.hashUtilsCls.exclHash(t.hAtoms,t.pickedAtomList):i.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList));else t.hAtoms=i.hashUtilsCls.cloneHash(t.pickedAtomList);t.hlObjectsCls.removeHlObjects(),t.hlObjectsCls.addHlObjects()}select3ddomainFromAtom(e){let t,i=this.icn3d,s=i.icn3dui,n=e.structure+"_"+e.chain,r=n+"_"+e.resi;for(let e in i.tddomains){let s=e.indexOf("_3d_domain");if(e.substr(0,s)==n&&-1!==Object.keys(i.tddomains[e]).indexOf(r)){t=e;break}}let a={};for(let e in i.tddomains[t])a=s.hashUtilsCls.unionHash(a,i.residues[e]);return a}selectStrandHelixFromAtom(e){let t=this.icn3d,i=t.icn3dui,s=e,n=e,r={},a=s.resi;if(!s.ssbegin&&!isNaN(s.resi)){for(let e=s.resi-1;e>0;--e){let i=s.structure+"_"+s.chain+"_"+e;if(!t.residues.hasOwnProperty(i))break;let n=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[i]);if(a=n.resi,"coil"!==s.ss&&n.ss===s.ss&&n.ssbegin||"coil"===s.ss&&n.ss!==s.ss){"coil"===s.ss&&n.ss!==s.ss&&(a=parseInt(n.resi)+1);break}}for(let e=a;e<=s.resi;++e){let n=s.structure+"_"+s.chain+"_"+e;r=i.hashUtilsCls.unionHash(r,i.hashUtilsCls.hash2Atoms(t.residues[n],t.atoms))}}let o=n.resi,l=t.firstAtomObjCls.getLastAtomObj(t.chains[n.structure+"_"+n.chain]).resi;for(let e=parseInt(n.resi)+1;e<=parseInt(l);++e){let i=n.structure+"_"+n.chain+"_"+e;if(!t.residues.hasOwnProperty(i))break;let s=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[i]);if(o=s.resi,"coil"!==n.ss&&s.ss===n.ss&&s.ssend||"coil"===n.ss&&s.ss!==n.ss){"coil"!==n.ss||s.ss===n.ss||isNaN(s.resi)||(o=s.resi-1);break}}for(let e=parseInt(n.resi)+1;e<=parseInt(o);++e){let s=n.structure+"_"+n.chain+"_"+e;r=i.hashUtilsCls.unionHash(r,i.hashUtilsCls.hash2Atoms(t.residues[s],t.atoms))}return r}}class _p{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t){let i=this.icn3d,s=i.icn3dui;t&&console.error('THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.');const n=document.createElement("button");function r(){n.style.display="",n.style.cursor="auto",n.style.left="calc(33% - 75px)",n.style.width="150px",n.onmouseenter=null,n.onmouseleave=null,n.onclick=null}let a=this;if("xr"in navigator)return n.id=s.pre+"VRButton",n.style.display="none",(o=n).style.position="absolute",o.style.bottom="20px",o.style.padding="12px 6px",o.style.border="1px solid #fff",o.style.borderRadius="4px",o.style.background="#000",o.style.color="#f8b84e",o.style.font="bold 13px sans-serif",o.style.textAlign="center",o.style.opacity="0.8",o.style.outline="none",o.style.zIndex="999",navigator.xr.isSessionSupported("immersive-vr").then((function(t){t?function(){let t=null;async function s(i){i.addEventListener("end",r),await e.xr.setSession(i),n.textContent="EXIT VR",t=i}function r(){i.transformCls.resetOrientation(),i.bVr=!1,i.drawCls.draw(),t.removeEventListener("end",r),n.textContent="ENTER VR",t=null}n.style.display="",n.style.cursor="pointer",n.style.left="calc(33% - 50px)",n.style.width="100px",n.textContent="ENTER VR",n.onmouseenter=function(){n.style.opacity="1.0"},n.onmouseleave=function(){n.style.opacity="0.8"},n.onclick=function(){if(i.bImpo=!1,i.bVr=!0,i.drawCls.draw(i.bVr),null===t){const e={optionalFeatures:["local-floor","bounded-floor","hand-tracking","layers"]};navigator.xr.requestSession("immersive-vr",e).then(s)}else t.end()}}():(r(),n.style.display="none"),t&&a.xrSessionIsGranted&&n.click()})).catch((function(e){r(),console.warn("Exception when trying to call xr.isSessionSupported",e),n.style.display="none"})),n;return document.createElement("span");var o}registerSessionGrantedListener(){"xr"in navigator&&navigator.xr.addEventListener("sessiongranted",(()=>{this.xrSessionIsGranted=!0}))}}class yp{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t={}){let i=this.icn3d,s=i.icn3dui;const n=document.createElement("button");function r(){n.style.display="",n.style.cursor="auto",n.style.left="calc(66% - 50px)",n.style.width="150px",n.onmouseenter=null,n.onmouseleave=null,n.onclick=null}function a(e){e.style.position="absolute",e.style.bottom="20px",e.style.padding="12px 6px",e.style.border="1px solid #fff",e.style.borderRadius="4px",e.style.background="#000",e.style.color="#f8b84e",e.style.font="bold 13px sans-serif",e.style.textAlign="center",e.style.opacity="0.8",e.style.outline="none",e.style.zIndex="999"}if(s.utilsCls.isAndroid()&&s.utilsCls.isChrome()){if("xr"in navigator)return n.id=s.pre+"ARButton",n.style.display="none",a(n),navigator.xr.isSessionSupported("immersive-ar").then((function(s){s?function(){if(void 0===t.domOverlay){const e=document.createElement("div");e.style.display="none",document.body.appendChild(e);const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width",38),i.setAttribute("height",38),i.style.position="absolute",i.style.right="20px",i.style.top="20px",i.addEventListener("click",(function(){s.end()})),e.appendChild(i);const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),n.setAttribute("stroke","#fff"),n.setAttribute("stroke-width",2),i.appendChild(n),void 0===t.optionalFeatures&&(t.optionalFeatures=[]),t.optionalFeatures.push("dom-overlay"),t.domOverlay={root:e}}let s=null;async function r(i){i.addEventListener("end",a),e.xr.setReferenceSpaceType("local"),await e.xr.setSession(i),n.textContent="STOP AR",t.domOverlay.root.style.display="",s=i}function a(){i.transformCls.resetOrientation(),i.bAr=!1,i.drawCls.draw(),s.removeEventListener("end",a),n.textContent="START AR",t.domOverlay.root.style.display="none",s=null}n.style.display="",n.style.cursor="pointer",n.style.left="calc(66% - 50px)",n.style.width="100px",n.textContent="START AR",n.onmouseenter=function(){n.style.opacity="1.0"},n.onmouseleave=function(){n.style.opacity="0.8"},n.onclick=function(){i.bImpo=!1,i.opts.background="transparent",i.bAr=!0,i.drawCls.draw(i.bAr),null===s?navigator.xr.requestSession("immersive-ar",t).then(r):s.end()}}():(r(),n.style.display="none")})).catch((function(e){r(),console.warn("Exception when trying to call xr.isSessionSupported",e),n.style.display="none"})),n;return document.createElement("span")}return n.id=s.pre+"ARButton",n.style.display="none",a(n),r(),n.style.display="none",n}}function Sp(e){var t=this;t.separation=3,t._position=new mt,t._quaternion=new ut,t._scale=new mt,t._cameraL=new Zs,t._cameraR=new Zs,e.autoClear=!1,t.setSize=function(i,s){t._width=i/2,t._height=s,e.setSize(i,s)},t.render=function(i,s){i.updateMatrixWorld(),void 0===s.parent&&s.updateMatrixWorld(),s.matrixWorld.decompose(t._position,t._quaternion,t._scale),t._cameraL.copy(s),t._cameraL.aspect=.5*s.aspect,t._cameraL.updateProjectionMatrix(),t._cameraL.translateX(-t.separation),t._cameraR.copy(s),t._cameraR.aspect=.5*s.aspect,t._cameraR.updateProjectionMatrix(),t._cameraR.translateX(t.separation),e.setViewport(0,0,2*t._width,t._height),e.clear(),e.setViewport(0,0,t._width,t._height),e.render(i,t._cameraL),e.setViewport(t._width,0,t._width,t._height),e.render(i,t._cameraR)}}class wp{constructor(e){let t,i,s,n=e;if(this.icn3dui=e,this.id=this.icn3dui.pre+"canvas",this.pre=this.icn3dui.pre,this.container=$("#"+this.id),this.oriContainer=$("#"+this.id),this.bControlGl=!1,this.maxatomcnt=1e5,this.overdraw=0,this.bDrawn=!1,this.bOpm=!1,this.crossstrucinter=0,this.bSecondaryStructure=!1,this.bHighlight=1,this.renderOrderPicking=-1,this.bInitial=!0,this.bDoublecolor=!1,this.originSize=1,this.ALTERNATE_STRUCTURE=-1,this.bUsePdbNum=!0,this.bSetCamera=!0,!this.icn3dui.bNode){let e=document.createElement("canvas");if(t=!(!window.WebGLRenderingContext||!e.getContext("webgl")&&!e.getContext("experimental-webgl")),e.remove(),e=document.createElement("canvas"),i=!(!window.WebGLRenderingContext||!e.getContext("webgl2")),e.remove(),s="xr"in navigator,t){if(!i)return void alert("Please use a modern browser that supports WebGL2...");this.renderer=new Pl({canvas:this.oriContainer.get(0),antialias:!0,preserveDrawingBuffer:!0,sortObjects:!1,alpha:!0}),s&&(this.renderer.xr.enabled=!0),this.effects={stereo:new Sp(this.renderer),none:this.renderer},this.overdraw=0}else alert("Currently your web browser has a problem on WebGL. If you are using Chrome, open a new tab for the same URL and WebGL may work again.")}this.frac=new ls(.1,.1,.1),this.shininess=40,this.emissive=3355443,this.light1=2,this.light2=1,this.light3=1,this.lineRadius=.1,this.coilWidth=.3,this.cylinderRadius=.4,this.crosslinkRadius=.4,this.traceRadius=.4,this.dotSphereScale=.3,this.sphereRadius=1.5,this.cylinderHelixRadius=1.6,this.ribbonthickness=.2,this.helixSheetWidth=1.3,this.nucleicAcidWidth=.8,this.scaleFactor=1,this.labelScale=1,this.resizeRatioX=1,this.resizeRatioY=1,this.bImpo=!0,this.bInstanced=!0,this.chainMissingResidueArray={},this._zoomFactor=1,this.transparentRenderOrder=!1,this.AFUniprotVersion="v4",this.defaultPdbId="stru",this.icn3dui.bNode||(i&&s?(this.bExtFragDepth=!0,this.bImpo=!0,this.bInstanced=!0):(this.bExtFragDepth=this.renderer.extensions.get("EXT_frag_depth"),this.bExtFragDepth?console.log("EXT_frag_depth is supported. All spheres and cylinders are drawn using shaders."):(this.bImpo=!1,console.log("EXT_frag_depth is NOT supported. All spheres and cylinders are drawn using geometry.")),this.bInstanced=this.renderer.extensions.get("ANGLE_instanced_arrays"),this.bInstanced?console.log("ANGLE_instanced_arrays is supported. Assembly is drawn with one copy of the asymmetric unit using hardware instancing."):console.log("ANGLE_instanced_arrays is NOT supported. Assembly is drawn by making copies of the asymmetric unit."))),this.posArray=new Array,this.colorArray=new Array,this.pos2Array=new Array,this.color2Array=new Array,this.radiusArray=new Array,this.posArraySphere=new Array,this.colorArraySphere=new Array,this.radiusArraySphere=new Array,this.axis=!1,this.pk=1,this.highlightlevel=1,this.pickpair=!1,this.pAtomNum=0,this.pAtom=void 0,this.pAtom2=void 0,this.bCtrl=!1,this.bShift=!1,this.bStopRotate=!1,this.bCalphaOnly=!1,this.bConsiderNeighbors=!1,this.bShowCrossResidueBond=!0,this.bExtrude=!0,this.maxD=500,this.oriMaxD=this.maxD,this.cam_z=2*this.maxD,this.commands=[],this.optsHistory=[],this.logs=[],this.bRender=!0,this.hColor=new ls(16777011),this.sphereGeometry=new ur(1,32,32),this.boxGeometry=new zs(1,1,1),this.cylinderGeometry=new Kn(1,1,1,32,1),this.cylinderGeometryOutline=new Kn(1,1,1,32,1,!0),this.axisDIV=15,this.strandDIV=6,this.tubeDIV=8,this.nucleicAcidStrandDIV=6,this.linewidth=1,this.hlLineRadius=.1,this.threshbox=180,this.maxAtoms3DMultiFile=4e4,this.tsHbond=3.8,this.tsIonic=6,this.tsContact=4,this.tsHalogen=3.8,this.tsPication=6,this.tsPistacking=5.5,this.LABELSIZE=30,this.rayThreshold=.5,this.colorBlackbkgd="#ffff00",this.colorWhitebkgd="#000000",this.optsOri={},this.optsOri.camera="perspective",this.optsOri.effect="none",this.optsOri.background="black",this.optsOri.color="chain",this.optsOri.proteins="ribbon",this.optsOri.sidec="nothing",this.optsOri.nucleotides="nucleotide cartoon",this.optsOri.ntbase="nothing",this.optsOri.surface="nothing",this.optsOri.opacity="1.0",this.optsOri.wireframe="no",this.optsOri.map="nothing",this.optsOri.mapwireframe="yes",this.optsOri.emmap="nothing",this.optsOri.emmapwireframe="yes",this.optsOri.phimap="nothing",this.optsOri.phimapwireframe="yes",this.optsOri.phisurface="nothing",this.optsOri.phisurftype="nothing",this.optsOri.phisurfop="1.0",this.optsOri.phisurfwf="yes",this.optsOri.chemicals="stick",this.optsOri.water="nothing",this.optsOri.ions="sphere",this.optsOri.hbonds="no",this.optsOri.saltbridge="no",this.optsOri.contact="no",this.optsOri.halogen="no",this.optsOri["pi-cation"]="no",this.optsOri["pi-stacking"]="no",this.optsOri.ssbonds="yes",this.optsOri.clbonds="yes",this.optsOri.rotationcenter="molecule center",this.optsOri.axis="no",this.optsOri.fog="no",this.optsOri.slab="no",this.optsOri.pk="residue",this.optsOri.chemicalbinding="hide",this.opts=n.hashUtilsCls.cloneHash(this.optsOri),this.sheetcolor="green",this.bShowHighlight=!0,this.mapData={},this.bFullUi=!0,this.divid=this.icn3dui.cfg.divid,this.inputid="",this.setOperation="or",this.ROT_DIR="right",this.currSelectedSets=[],this.selectedResidues={},this.ncbi2resid={},this.resid2ncbi={},this.shapeCmdHash={},this.bHideSelection=!0,this.bSelectResidue=!1,this.bSelectAlignResidue=!1,this.bAnnoShown=!1,this.bSetChainsAdvancedMenu=!1,this.b2DShown=!1,this.bCrashed=!1,this.bAddCommands=!0,this.bAddLogs=!0,this.bNotLoadStructure=!1,this.InputfileData="",this.bVr=!1,this.bAr=!1,this.startColor="blue",this.midColor="white",this.endColor="red",this.startValue=0,this.midValue=50,this.endValue=100,this.crosslinkRadius=.4,this.sceneCls=new oc(this),this.cameraCls=new cc(this),this.fogCls=new hc(this),this.boxCls=new pc(this),this.brickCls=new uc(this),this.curveStripArrowCls=new mc(this),this.curveCls=new fc(this),this.cylinderCls=new gc(this),this.lineCls=new bc(this),this.reprSubCls=new Cc(this),this.sphereCls=new vc(this),this.stickCls=new _c(this),this.strandCls=new xc(this),this.stripCls=new Sc(this),this.tubeCls=new wc(this),this.cartoonNuclCls=new Ac(this),this.surfaceCls=new Pc(this),this.labelCls=new Tc(this),this.axesCls=new Ec(this),this.glycanCls=new Rc(this),this.applyCenterCls=new Dc(this),this.applyClbondsCls=new Lc(this),this.applyMissingResCls=new Fc(this),this.applyDisplayCls=new Nc(this),this.applyMapCls=new zc(this),this.applyOtherCls=new Uc(this),this.applySsbondsCls=new Hc(this),this.applySymdCls=new Bc(this),this.hlObjectsCls=new bh(this),this.residueLabelsCls=new qc(this),this.alternateCls=new $c(this),this.drawCls=new Vc(this),this.firstAtomObjCls=new yc(this),this.impostorCls=new jc(this),this.instancingCls=new Gc(this),this.contactCls=new Wc(this),this.hBondCls=new Xc(this),this.piHalogenCls=new Yc(this),this.saltbridgeCls=new Kc(this),this.loadPDBCls=new $h(this),this.loadCIFCls=new Vh(this),this.vastplusCls=new Wh(this),this.transformCls=new pp(this),this.setStyleCls=new Zc(this),this.setColorCls=new Jc(this),this.threeDPrintCls=new fp(this),this.export3DCls=new gp(this),this.annoCddSiteCls=new th(this),this.annoContactCls=new ih(this),this.annoPTMCls=new sh(this),this.annoIgCls=new nh(this),this.annoCrossLinkCls=new rh(this),this.annoDomainCls=new ah(this),this.annoSnpClinVarCls=new oh(this),this.annoSsbondCls=new lh(this),this.annoTransMemCls=new dh(this),this.domain3dCls=new ch(this),this.addTrackCls=new hh(this),this.annotationCls=new ph(this),this.showAnnoCls=new uh(this),this.showSeqCls=new mh(this),this.hlSeqCls=new fh(this),this.hlUpdateCls=new gh(this),this.lineGraphCls=new Ch(this),this.getGraphCls=new vh(this),this.showInterCls=new _h(this),this.viewInterPairsCls=new yh(this),this.drawGraphCls=new Sh(this),this.contactMapCls=new wh(this),this.alignParserCls=new xh(this),this.chainalignParserCls=new Ah(this),this.dsn6ParserCls=new Mh(this),this.ccp4ParserCls=new Th(this),this.mtzParserCls=new kh(this),this.mmcifParserCls=new Oh(this),this.mmdbParserCls=new Ih(this),this.bcifParserCls=new Ph(this),this.mol2ParserCls=new Dh(this),this.opmParserCls=new Lh(this),this.pdbParserCls=new Fh(this),this.sdfParserCls=new Nh(this),this.xyzParserCls=new Uh(this),this.msaParserCls=new Hh(this),this.realignParserCls=new Bh(this),this.densityCifParserCls=new zh(this),this.ParserUtilsCls=new qh(this),this.loadAtomDataCls=new jh(this),this.setSeqAlignCls=new Gh(this),this.applyCommandCls=new Xh(this),this.definedSetsCls=new Yh(this),this.selectCollectionsCls=new Kh(this),this.legendTableCls=new eh(this),this.loadScriptCls=new Zh(this),this.selByCommCls=new Jh(this),this.selectionCls=new Qh(this),this.resid2specCls=new ep(this),this.delphiCls=new tp(this),this.dsspCls=new ip(this),this.refnumCls=new sp(this),this.scapCls=new np(this),this.symdCls=new rp(this),this.alignSWCls=new ap(this),this.analysisCls=new op(this),this.resizeCanvasCls=new hp(this),this.saveFileCls=new up(this),this.setOptionCls=new Qc(this),this.shareLinkCls=new mp(this),this.diagram2dCls=new lp(this),this.cartoon2dCls=new dp(this),this.ligplotCls=new cp(this),this.rayCls=new bp(this),this.controlCls=new Cp(this),this.pickingCls=new vp(this),this.VRButtonCls=new _p(this),this.ARButtonCls=new yp(this),this.matShader=this.setColorCls.setOutlineColor("yellow")}}wp.prototype.init=function(e){this.init_base(),this.molTitle="",this.ssbondpnts={},this.clbondpnts={},this.biomtMatrices=[],this.bAssembly=!0,this.bDrawn=!1,this.bSecondaryStructure=!1,this.bHighlight=1,this.axes=[]},wp.prototype.init_base=function(e){this.resetConfig(),this.structures={},this.chains={},this.tddomains={},this.residues={},this.secondaries={},this.alnChains={},this.chainsSeq={},this.chainsColor={},this.chainsGene={},this.chainsAn={},this.chainsAnTitle={},this.chainsMapping={},this.resid2refnum={},this.residIgLoop={},this.refnum2residArray={},this.bShowRefnum=!1,this.alnChainsSeq={},this.alnChainsAnno={},this.alnChainsAnTtl={},this.pickedAtomList={},this.prevHighlightObjects=[],this.prevHighlightObjects_ghost=[],this.prevSurfaces=[],this.prevMaps=[],this.prevEmmaps=[],this.prevPhimaps=[],this.prevOtherMesh=[],this.defNames2Residues={},this.defNames2Atoms={},this.defNames2Descr={},this.defNames2Command={},this.residueId2Name={},this.atoms={},this.dAtoms={},this.hAtoms={},this.proteins={},this.sidec={},this.ntbase={},this.nucleotides={},this.nucleotidesO3={},this.chemicals={},this.ions={},this.water={},this.calphas={},this.hbondpnts=[],this.saltbridgepnts=[],this.contactpnts=[],this.stabilizerpnts=[],this.halogenpnts=[],this.picationpnts=[],this.pistackingpnts=[],this.distPnts=[],this.doublebonds={},this.triplebonds={},this.aromaticbonds={},this.atomPrevColors={},this.style2atoms={},this.labels={},this.lines={},this.resids2inter={},this.resids2interAll={},this.transformCls.rotateCount=0,this.transformCls.rotateCountMax=20,e&&(this.commands=[]),this.axes=[],this.bGlycansCartoon=0,this.bMembrane=1,this.bCmdWindow=0,this.chainMissingResidueArray={},this.nTotalGap=0},wp.prototype.reinitAfterLoad=function(){let e=this,t=e.icn3dui;e.resetConfig(),e.setStyleCls.setAtomStyleByOptions(),e.setColorCls.setColorByOptions(e.opts,e.atoms),e.dAtoms=t.hashUtilsCls.cloneHash(e.atoms),e.hAtoms=t.hashUtilsCls.cloneHash(e.atoms),e.prevHighlightObjects=[],e.prevHighlightObjects_ghost=[],e.prevSurfaces=[],e.prevMaps=[],e.prevEmmaps=[],e.prevPhimaps=[],e.prevOtherMesh=[],e.labels={},e.lines={},e.shapeCmdHash={},e.bAssembly=!0},wp.prototype.resetConfig=function(){let e=this,t=e.icn3dui;if(this.opts=t.hashUtilsCls.cloneHash(this.optsOri),void 0===t.cfg.align&&void 0===t.cfg.chainalign||(this.opts.color="identity",this.opts.proteins="c alpha trace",this.opts.nucleotides="o3 trace"),void 0===t.cfg.cid&&void 0===t.cfg.smiles||(this.opts.color="atom",this.opts.pk="atom",this.opts.chemicals="ball and stick"),(void 0!==t.cfg.afid||e.bEsmfold)&&(this.opts.color="confidence"),void 0!==t.cfg.blast_rep_id&&(this.opts.color="conservation"),void 0!==t.cfg.mmdbafid){let i=t.cfg.mmdbafid.split(",");if(i.length>1)e.opts.color="structure";else if(1==i.length){let t=i[0];isNaN(t)&&t.length>5?this.opts.color="confidence":e.opts.color="chain"}}void 0!==t.cfg.options&&$.extend(this.opts,t.cfg.options)};class xp{constructor(e){this.cfg=e,this.pre=this.cfg.divid+"_",this.REVISION="3.45.2",this.bNode=Object.keys(window).length<3,void 0===this.cfg.command&&(this.cfg.command=""),void 0===this.cfg.width&&(this.cfg.width="100%"),void 0===this.cfg.height&&(this.cfg.height="100%"),void 0===this.cfg.resize&&(this.cfg.resize=!0),void 0===this.cfg.showlogo&&(this.cfg.showlogo=!0),void 0===this.cfg.showmenu&&(this.cfg.showmenu=!0),void 0===this.cfg.showtitle&&(this.cfg.showtitle=!0),void 0===this.cfg.showcommand&&(this.cfg.showcommand=!0),void 0===this.cfg.mobilemenu&&(this.cfg.mobilemenu=!1),void 0===this.cfg.imageonly&&(this.cfg.imageonly=!1),void 0===this.cfg.closepopup&&(this.cfg.closepopup=!1),void 0===this.cfg.showanno&&(this.cfg.showanno=!1),void 0===this.cfg.showseq&&(this.cfg.showseq=!1),void 0===this.cfg.showalignseq&&(this.cfg.showalignseq=!1),void 0===this.cfg.show2d&&(this.cfg.show2d=!1),void 0===this.cfg.showsets&&(this.cfg.showsets=!1),void 0===this.cfg.rotate&&(this.cfg.rotate="right"),void 0===this.cfg.hidelicense&&(this.cfg.hidelicense=!1),this.hashUtilsCls=new Dl(this),this.utilsCls=new Ll(this),this.parasCls=new Fl(this),this.myEventCls=new Nl(this),this.rmsdSuprCls=new Ul(this),this.subdivideCls=new Hl(this),this.convertTypeCls=new Bl(this),this.htmlCls=new Xl(this)}allCustomEvents(){}}xp.prototype.show3DStructure=async function(e){let t=this;t.cfg.menuicon?(t.htmlCls.wifiStr='<i class="icn3d-wifi" title="requires internet"> </i>',t.htmlCls.licenseStr='<i class="icn3d-license" title="requires license"> </i>'):(t.htmlCls.wifiStr="",t.htmlCls.licenseStr=""),t.setIcn3d();let i=t.icn3d;t.utilsCls.isSessionStorageSupported()&&i.setStyleCls.getCommandsBeforeCrash();let s=t.htmlCls.WIDTH,n=t.htmlCls.HEIGHT;t.oriWidth=s,t.oriHeight=n,t.htmlCls.eventsCls.allEventFunctions(),this.allCustomEvents();let r=0;if((null==t.cfg.showmenu||t.cfg.showmenu)&&(r+=t.htmlCls.MENU_HEIGHT),(null==t.cfg.showcommand||t.cfg.showcommand)&&(r+=t.htmlCls.CMD_HEIGHT),null!=t.cfg.showmenu&&0==t.cfg.showmenu?t.htmlCls.setMenuCls.hideMenu():t.htmlCls.setMenuCls.showMenu(),null!=t.cfg.showtitle&&0==t.cfg.showtitle?$("#"+i.pre+"title").hide():$("#"+i.pre+"title").show(),$("#"+i.pre+"viewer").width(s).height(parseInt(n)+r),$("#"+i.pre+"canvas").width(s).height(parseInt(n)),$("#"+i.pre+"canvas").resizable({resize:function(e,s){t.htmlCls.WIDTH=s.size.width,t.htmlCls.HEIGHT=s.size.height,void 0===i||t.icn3d.bFullscreen||i.resizeCanvasCls.resizeCanvas(t.htmlCls.WIDTH,t.htmlCls.HEIGHT,!0)}}),void 0!==t.cfg.usepdbnum?t.icn3d.bUsePdbNum=t.cfg.usepdbnum:void 0!==t.cfg.date?t.icn3d.bUsePdbNum=parseInt(t.cfg.date)>=20201222:"1tup"==t.cfg.mmdbid&&1==t.cfg.showanno&&1==t.cfg.show2d&&1==t.cfg.showsets||"118496"==t.cfg.mmdbid&&0==t.cfg.showanno&&-1!=t.cfg.inpara.indexOf("bu=1")||"163605,1,91105,1,1,1"==t.cfg.align&&-1!=t.cfg.inpara.indexOf("atype=1")?t.icn3d.bUsePdbNum=!1:t.icn3d.bUsePdbNum=!0,t.cfg.replay?(i.bReplay=1,$("#"+i.pre+"replay").show()):(i.bReplay=0,$("#"+i.pre+"replay").hide()),t.utilsCls.isMobile()&&(i.threshbox=60),t.cfg.controlGl&&(i.bControlGl=!0,i.container=i.bControlGl&&!t.bNode?$(document):$("#"+i.id)),i.setStyleCls.handleContextLost(),i.applyCenterCls.setWidthHeight(s,n),i.ori_chemicalbinding=i.opts.chemicalbinding,i.opts=t.hashUtilsCls.cloneHash(i.opts),i.STATENUMBER=i.commands.length,t.utilsCls.isSessionStorageSupported()&&i.bCrashed){i.bCrashed=!1;let e=i.commandsBeforeCrash.split("|||")[0],s=e.substr(e.lastIndexOf(" ")+1);if(s===t.cfg.bcifid||s===t.cfg.mmtfid||s===t.cfg.pdbid||s===t.cfg.opmid||s===t.cfg.mmdbid||s===t.cfg.gi||s===t.cfg.blast_rep_id||s===t.cfg.cid||s===t.cfg.mmcifid||s===t.cfg.align||s===t.cfg.chainalign||s===t.cfg.mmdbafid)return void await i.loadScriptCls.loadScript(i.commandsBeforeCrash,!0)}if(i.molTitle="",i.loadCmd,t.htmlCls.clickMenuCls.getHiddenMenusFromCache(),t.htmlCls.clickMenuCls.applyShownMenus(),e){if(i.init(),i.bInputfile=!0,i.InputfileType="pdb",i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+e:e,await i.pdbParserCls.loadPdbData(e),void 0!==t.cfg.resdef&&void 0!==t.cfg.chains){let e=Object.keys(i.structures),s=t.cfg.chains.split(" | "),n=[];if(e.length==s.length){for(let t=0,i=e.length;t<i;++t)n.push(e[t]+"_"+s[t]);n=i.chainalignParserCls.addPostfixForChainids(n);let t=!0,r=!0;await i.realignParserCls.realignChainOnSeqAlign(void 0,n,t,r)}}else if(void 0!==t.cfg.matchedchains){let e=Object.keys(i.structures)[0]+"_"+t.cfg.masterchain,s=t.cfg.matchedchains.split(","),n=[];for(let e=0,t=s.length;e<t;++e){let t=s[e].lastIndexOf("_"),i=s[e].substr(t+1);isNaN(i)?n.push(s[e]):n.push(s[e].substr(0,t))}let r="";for(let e=0,t=n.length;e<t;++e)e>0&&(r+=","),r+=n[e].substr(0,n[e].indexOf("_"));i.chainidArray=[e].concat(n),i.chainidArray=i.chainalignParserCls.addPostfixForChainids(i.chainidArray),i.loadCmd="vast_search_chainid "+i.chainidArray,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),i.bMmdbafid=!0;let a=!0;await i.chainalignParserCls.downloadMmdbAf(r,a)}}else if(void 0!==t.cfg.url){i.bInputUrlfile=!0;let e=t.cfg.url.split("|"),s=e[0],n=e[1];i.molTitle="",i.inputid=n,i.inputurl="type="+s+"&url="+encodeURIComponent(n),i.loadCmd="load url "+n+" | type "+s,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.pdbParserCls.downloadUrl(n,s,t.cfg.command)}else if(void 0!==t.cfg.mmtfid)i.inputid=t.cfg.mmtfid,i.loadCmd="load mmtf "+t.cfg.mmtfid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.bcifParserCls.downloadBcif(t.cfg.mmtfid);else if(void 0!==t.cfg.bcifid)i.inputid=t.cfg.bcifid,i.loadCmd="load bcif "+t.cfg.bcifid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.bcifParserCls.downloadBcif(t.cfg.bcifid);else if(void 0!==t.cfg.pdbid)i.inputid=t.cfg.pdbid,i.loadCmd="load pdb "+t.cfg.pdbid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.pdbParserCls.downloadPdb(t.cfg.pdbid);else if(void 0!==t.cfg.afid){i.inputid=t.cfg.afid,i.loadCmd="load af "+t.cfg.afid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0);let e=!0;await i.pdbParserCls.downloadPdb(t.cfg.afid,e)}else if(void 0!==t.cfg.opmid)i.inputid=t.cfg.opmid,i.loadCmd="load opm "+t.cfg.opmid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.opmParserCls.downloadOpm(t.cfg.opmid);else if(void 0!==t.cfg.mmdbid)i.inputid=t.cfg.mmdbid,i.loadCmd="load mmdb "+t.cfg.mmdbid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadMmdb(t.cfg.mmdbid);else if(void 0!==t.cfg.gi)i.loadCmd="load gi "+t.cfg.gi,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadGi(t.cfg.gi);else if(void 0!==t.cfg.refseqid)i.inputid=t.cfg.refseqid,i.loadCmd="load refseq "+t.cfg.refseqid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadRefseq(t.cfg.refseqid);else if(void 0!==t.cfg.protein)i.inputid=t.cfg.protein,i.loadCmd="load protein "+t.cfg.protein,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadProteinname(t.cfg.protein);else if(void 0!==t.cfg.blast_rep_id)if(i.inputid=t.cfg.query_id+","+t.cfg.blast_rep_id,t.cfg.oriQuery_id=t.cfg.query_id,t.cfg.oriBlast_rep_id=t.cfg.blast_rep_id,"Query"!==t.cfg.query_id.substr(0,5)&&void 0===t.cfg.rid)"icn3d"==t.cfg.from&&"1TSR_A"==t.cfg.blast_rep_id&&"NP_001108451.1"==t.cfg.query_id&&(t.cfg.command="view annotations; set annotation cdd; set annotation site; set view detailed view; select chain 1TSR_A; show selection"),"smithwm"==t.cfg.alg?(i.loadCmd="load seq_struct_ids_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,i.bSmithwm=!0):"local_smithwm"==t.cfg.alg?(i.loadCmd="load seq_struct_ids_local_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,i.bLocalSmithwm=!0):(i.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,i.bSmithwm=!1,i.bLocalSmithwm=!1),t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadBlast_rep_id(t.cfg.query_id+","+t.cfg.blast_rep_id);else if(void 0!==t.cfg.rid){let e="https://blast.ncbi.nlm.nih.gov/Blast.cgi?RESULTS_FILE=on&FORMAT_TYPE=JSON2_S&FORMAT_OBJECT=Alignment&CMD=Get&RID="+t.cfg.rid,s=await t.getAjaxPromise(e,"json",!1,"The RID "+t.cfg.rid+" may have expired...");for(let e=0,n=s.BlastOutput2.length;e<n;++e){let n,r;if(s.BlastOutput2[e].report.results.iterations){let i=s.BlastOutput2[e].report.results.iterations.length;if(s.BlastOutput2[e].report.results.iterations[i-1].search.query_id!=t.cfg.query_id)continue;n=s.BlastOutput2[e].report.results.iterations[i-1].search.hits}else{if(s.BlastOutput2[e].report.results.search.query_id!=t.cfg.query_id)continue;n=s.BlastOutput2[e].report.results.search.hits}for(let e=0,i=n.length;e<i;++e){let i=n[e],s=!1;for(let e=0,n=i.description.length;e<n;++e){if(i.description[e].accession==t.cfg.blast_rep_id){s=!0;break}}if(s){r=i.hsps[0].qseq,r=r.replace(/-/g,"");break}}void 0!==r&&(t.cfg.query_id=r),i.inputid=t.cfg.query_id+"_"+t.cfg.blast_rep_id,i.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmdbParserCls.downloadBlast_rep_id(t.cfg.query_id+","+t.cfg.blast_rep_id);break}}else alert('BLAST "RID" is a required parameter...');else if(void 0!==t.cfg.cid){if(isNaN(t.cfg.cid)){let e=t.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?compound2cid="+t.cfg.cid,i=await t.getAjaxPromise(e,"jsonp");if(!i.cid||!i.cid[0])return void alert("Please input an valid PubChem CID...");t.cfg.cid=i.cid[0]}i.inputid=t.cfg.cid;let e="https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+i.inputid+"/description/jsonp",s=await t.getAjaxPromise(e,"jsonp",!1);void 0!==s.InformationList&&void 0!==s.InformationList.Information&&(i.molTitle=s.InformationList.Information[0].Title),i.loadCmd="load cid "+t.cfg.cid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.sdfParserCls.downloadCid(t.cfg.cid)}else if(void 0!==t.cfg.smiles)i.inputid=t.cfg.smiles,i.loadCmd="load smiles "+t.cfg.smiles,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.sdfParserCls.downloadSmiles(t.cfg.smiles);else if(void 0!==t.cfg.mmcifid)i.inputid=t.cfg.mmcifid,i.loadCmd="load mmcif "+t.cfg.mmcifid,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.mmcifParserCls.downloadMmcif(t.cfg.mmcifid);else if(void 0!==t.cfg.align){-1!=t.cfg.align.indexOf("185055,")&&(t.cfg.align=t.cfg.align.replace("185055,","199731,"));let e=t.cfg.align.split(",");if(6===e.length?i.inputid=e[0]+"_"+e[3]:2===e.length&&(i.inputid=e[0]+"_"+e[1]),i.loadCmd="load alignment "+t.cfg.align+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),t.cfg.inpara&&-1==t.cfg.inpara.indexOf("atype=2"))await i.alignParserCls.downloadAlignment(t.cfg.align);else{let e=2;await i.chainalignParserCls.downloadMmdbAf(t.cfg.align,void 0,e)}}else if(void 0!==t.cfg.chainalign){i.bChainAlign=!0,i.inputid=t.cfg.chainalign;let e=t.cfg.resrange?" | resrange "+decodeURIComponent(t.cfg.resrange):"",s=t.cfg.resdef?t.cfg.resdef:"";i.loadCmd="load chainalignment "+t.cfg.chainalign+" | resnum "+t.cfg.resnum+" | resdef "+s+" | aligntool "+t.cfg.aligntool+" | parameters "+t.cfg.inpara+e,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.chainalignParserCls.downloadChainalignment(t.cfg.chainalign)}else if(void 0!==t.cfg.mmdbafid)t.cfg.mmdbafid=t.cfg.mmdbafid.replace(/\s+/g,"").toUpperCase(),i.bMmdbafid=!0,i.inputid=t.cfg.mmdbafid,1==t.cfg.bu?i.loadCmd="load mmdbaf1 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara:i.loadCmd="load mmdbaf0 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(i.loadCmd,!0),await i.chainalignParserCls.downloadMmdbAf(t.cfg.mmdbafid);else{if(void 0===t.cfg.command||""===t.cfg.command)return void t.htmlCls.dialogCls.openDlg("dl_mmdbafid","Please input PDB/MMDB/AlphaFold UniProt IDs");-1!==t.cfg.command.indexOf("url=")&&(i.bInputUrlfile=!0)}await i.loadScriptCls.loadScript(t.cfg.command,void 0,!0)},xp.prototype.setIcn3d=function(){let e=this,t="<label class='icn3d-switch'><input id='"+e.pre+"modeswitch' type='checkbox'><div class='icn3d-slider icn3d-round' style='width:34px; height:18px; margin: 6px 0px 0px 3px;' title='Left(\"All atoms\"): Style and color menu options will be applied to all atoms in the structure Right(\"Selection\"): Style and color menu options will be applied only to selected atoms'></div></label>",i="<span id='"+e.pre+"modeall' title='Style and color menu options will be applied to all atoms in the structure'>All atoms </span><span id='"+e.pre+"modeselection' class='icn3d-modeselection' style='display:none;' title='Style and color menu options will be applied only to selected atoms'>Selection </span></div></div></td>";e.utilsCls.setViewerWidthHeight(e),e.utilsCls.isMobile()||e.cfg.mobilemenu?e.htmlCls.setMenuCls.setTopMenusHtmlMobile(e.cfg.divid,t,i):e.htmlCls.setMenuCls.setTopMenusHtml(e.cfg.divid,t,i),e.icn3d=new wp(e),e.icn3d.controlCls.setControl(),e.setDialogAjax()},xp.prototype.getMmtfPromise=function(e){return new Promise((function(t,i){MMTF.fetch(e,(async function(e){t(e)}),(function(e){i("error")}))}))},xp.prototype.getMmtfReducedPromise=function(e){return new Promise((function(t,i){MMTF.fetchReduced(e,(async function(e){t(e)}),(function(e){i("error")}))}))},xp.prototype.getXMLHttpRqstPromise=function(e,t,i,s){let n=this;return new Promise((function(r,a){let o=new XMLHttpRequest;o.open(t,e,!0),o.responseType=i,o.onreadystatechange=function(){if(4==this.readyState)if(200==this.status){let e=o.response;r(e)}else"2fofc"==s||"fofc"==s?alert("Density server at EBI has no corresponding electron density map for this structure."):"em"==s?alert("Density server at EBI has no corresponding EM density map for this structure."):"rcsbEdmaps"==s?alert("RCSB server has no corresponding electron density map for this structure."):console.log("The "+s+" file is unavailable..."),a("error");else n.icn3d.ParserUtilsCls.showLoading()},o.send()}))},xp.prototype.getAjaxPromise=function(e,t,i,s,n,r,a){let o=this;return new Promise((function(a,l){$.ajax({url:e,dataType:t,cache:!0,beforeSend:function(){i&&o.icn3d.ParserUtilsCls.showLoading()},complete:function(){r&&o.icn3d.ParserUtilsCls.hideLoading()},success:function(e){a(e)},error:function(){s&&alert(s),n&&console.log(n),l("error")}})}))},xp.prototype.getAjaxPostPromise=async function(e,t,i,s,n,r,a,o){let l=this;return a=a||"json",new Promise((function(o,d){$.ajax({url:e,type:"POST",data:t,dataType:a,cache:!0,beforeSend:function(){i&&l.icn3d.ParserUtilsCls.showLoading()},complete:function(){r&&l.icn3d.ParserUtilsCls.hideLoading()},success:function(e){o(e)},error:function(){!l.bNode&&s&&console.log(s),!l.bNode&&n&&console.log(n),o("error")}})}))},xp.prototype.setDialogAjax=function(){this.bNode||$.ui.dialog.prototype._makeDraggableBase||($.ui.dialog.prototype._makeDraggableBase=$.ui.dialog.prototype._makeDraggable,$.ui.dialog.prototype._makeDraggable=function(){this._makeDraggableBase(),this.uiDialog.draggable("option","containment",!1)}),$.ajaxTransport("+binary",(function(e,t,i){if(window.FormData&&(e.dataType&&"binary"==e.dataType||e.data&&(window.ArrayBuffer&&e.data instanceof ArrayBuffer||window.Blob&&e.data instanceof Blob)))return{send:function(t,i){let s=new XMLHttpRequest,n=e.url,r=e.type,a=e.async||!0,o=e.responseType||"blob",l=e.data||null;s.addEventListener("load",(function(){let t={};t[e.dataType]=s.response,i(s.status,s.statusText,t,s.getAllResponseHeaders())})),s.open(r,n,a);for(let e in t)s.setRequestHeader(e,t[e]);s.responseType=o,s.send(l)},abort:function(){i.abort()}}}))};return e.ARButton=yp,e.AddTrack=hh,e.AlignParser=xh,e.AlignSW=ap,e.AlignSeq=Vl,e.Alternate=$c,e.Analysis=op,e.AnnoCddSite=th,e.AnnoContact=ih,e.AnnoCrossLink=rh,e.AnnoDomain=ah,e.AnnoSnpClinVar=oh,e.AnnoSsbond=lh,e.AnnoTransMem=dh,e.Annotation=ph,e.ApplyCenter=Dc,e.ApplyClbonds=Lc,e.ApplyCommand=Xh,e.ApplyDisplay=Nc,e.ApplyMap=zc,e.ApplyOther=Uc,e.ApplySsbonds=Hc,e.ApplySymd=Bc,e.Axes=Ec,e.Box=pc,e.Brick=uc,e.Camera=cc,e.CartoonNucl=Ac,e.ChainalignParser=Ah,e.ClickMenu=zl,e.Contact=Wc,e.Control=Cp,e.ConvertTypeCls=Bl,e.Curve=fc,e.CurveStripArrow=mc,e.Cylinder=gc,e.DefinedSets=Yh,e.Delphi=tp,e.DensityCifParser=zh,e.Diagram2d=lp,e.Dialog=jl,e.Domain3d=ch,e.Draw=Vc,e.DrawGraph=Sh,e.Dsn6Parser=Mh,e.Dssp=ip,e.ElectronMap=Ic,e.Events=$l,e.Export3D=gp,e.FirstAtomObj=yc,e.Fog=hc,e.GetGraph=vh,e.Glycan=Rc,e.HBond=Xc,e.HashUtilsCls=Dl,e.HlObjects=bh,e.HlSeq=fh,e.HlUpdate=gh,e.Html=Xl,e.Impostor=jc,e.Instancing=Gc,e.Label=Tc,e.Line=bc,e.LineGraph=Ch,e.LoadAtomData=jh,e.LoadCIF=Vh,e.LoadPDB=$h,e.LoadScript=Zh,e.MarchingCube=kc,e.MmcifParser=Oh,e.MmdbParser=Ih,e.Mol2Parser=Dh,e.MsaParser=Hh,e.MyEventCls=Nl,e.OpmParser=Lh,e.ParasCls=Fl,e.ParserUtils=qh,e.PdbParser=Fh,e.PiHalogen=Yc,e.Picking=vp,e.ProteinSurface=Oc,e.Ray=bp,e.RealignParser=Bh,e.Refnum=sp,e.ReprSub=Cc,e.Resid2spec=ep,e.ResidueLabels=qc,e.ResizeCanvas=hp,e.RmsdSuprCls=Ul,e.Saltbridge=Kc,e.SaveFile=up,e.Scap=np,e.Scene=oc,e.SdfParser=Nh,e.SelectByCommand=Jh,e.Selection=Qh,e.SetColor=Jc,e.SetDialog=Gl,e.SetHtml=Wl,e.SetMenu=ql,e.SetOption=Qc,e.SetSeqAlign=Gh,e.SetStyle=Zc,e.ShareLink=mp,e.ShowAnno=uh,e.ShowInter=_h,e.ShowSeq=mh,e.Sphere=vc,e.Stick=_c,e.Strand=xc,e.Strip=Sc,e.SubdivideCls=Hl,e.Surface=Pc,e.Symd=rp,e.ThreeDPrint=fp,e.Transform=pp,e.Tube=wc,e.UtilsCls=Ll,e.VRButton=_p,e.Vastplus=Wh,e.ViewInterPairs=yh,e.XyzParser=Uh,e.iCn3D=wp,e.iCn3DUI=xp,e.printMsg=class{constructor(){console.log("This is a message from the icn3d package")}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|