icn3d 3.38.1 → 3.38.2

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.min.js CHANGED
@@ -3,5 +3,5 @@ var icn3d=function(e){"use strict";class t{constructor(e){this.icn3dui=e}cloneHa
3
3
  //!!!ic.bShowHighlight = false;
4
4
  }hideHydrogens(){let e=this.icn3d;e.icn3dui;for(let t in e.hAtoms){let s=e.atoms[t];if("H"===s.elem.substr(0,1)){if(e.atoms[s.serial].bonds.length>0){let t=e.atoms[s.serial].bonds[0],i=e.atoms[t].bonds?e.atoms[t].bonds.indexOf(s.serial):-1;-1!==i&&(e.atoms[t].bonds.splice(i,1),e.atoms[t].bondOrder&&e.atoms[t].bondOrder.splice(i,1))}delete e.dAtoms[s.serial],delete e.hAtoms[s.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,s="set hbonds off";t.htmlCls.clickMenuCls.setLogCmd(s,!0),e.hBondCls.hideHbonds(),s="set salt bridge off",t.htmlCls.clickMenuCls.setLogCmd(s,!0),e.saltbridgeCls.hideSaltbridge(),s="set contact off",t.htmlCls.clickMenuCls.setLogCmd(s,!0),e.contactCls.hideContact(),s="set halogen pi off",t.htmlCls.clickMenuCls.setLogCmd(s,!0),e.piHalogenCls.hideHalogenPi(),this.hideExtraBonds()}showIonicInteractions(e,t,s,i,n,l){let r,o,a,d,c=this.icn3d,h=c.icn3dui;if(!i&&(r="saltbridge",o="salt bridge "+e+" | sets "+t+" "+s+" | "+i,c.opts.saltbridge="yes",a=c.definedSetsCls.getAtomsFromNameArray(t),d=c.definedSetsCls.getAtomsFromNameArray(s),c.firstAtomObjCls.getFirstAtomObj(a),Object.keys(d).length>0&&Object.keys(a).length>0)){let t,s=c.saltbridgeCls.calculateIonicInteractions(h.hashUtilsCls.hash2Atoms(d,c.atoms),h.hashUtilsCls.hash2Atoms(a,c.atoms),parseFloat(e),n);c.resid2ResidhashSaltbridge=h.hashUtilsCls.cloneHash(c.resid2Residhash),t="all atoms that have ionic interactions with the selected atoms";let i={};for(let e in s){i[c.atoms[e].structure+"_"+c.atoms[e].chain+"_"+c.atoms[e].resi]=1}c.hAtoms={};for(let e in i)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 l="saltbridge_auto";c.selectionCls.addCustomSelection(Object.keys(i),l,t,o,!0),c.selectionCls.saveSelectionIfSelected(),c.drawCls.draw()}}showHalogenPi(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui;if(i)return;let a,d,c=l+" "+e+" | sets "+t+" "+s+" | "+i;if(r.opts[l]="yes",a=r.definedSetsCls.getAtomsFromNameArray(t),d=r.definedSetsCls.getAtomsFromNameArray(s),r.firstAtomObjCls.getFirstAtomObj(a),Object.keys(d).length>0&&Object.keys(a).length>0){let t,s=r.piHalogenCls.calculateHalogenPiInteractions(o.hashUtilsCls.hash2Atoms(a,r.atoms),o.hashUtilsCls.hash2Atoms(d,r.atoms),parseFloat(e),n,l);"halogen"==l?(r.resid2ResidhashHalogen=o.hashUtilsCls.cloneHash(r.resid2Residhash),t="all atoms that have halogen bonds with the selected atoms"):"pi-cation"==l?(r.resid2ResidhashPication=o.hashUtilsCls.cloneHash(r.resid2Residhash),t="all atoms that have pi-cation interactions with the selected atoms"):"pi-stacking"==l&&(r.resid2ResidhashPistacking=o.hashUtilsCls.cloneHash(r.resid2Residhash),t="all atoms that have pi-stacking with the selected atoms");let i={};for(let e in s){i[r.atoms[e].structure+"_"+r.atoms[e].chain+"_"+r.atoms[e].resi]=1}r.hAtoms={};for(let e in i)for(let t in r.residues[e])r.hAtoms[t]=1,r.atoms[t].style2="stick",r.ions.hasOwnProperty(t)&&(r.atoms[t].style2="sphere");let h=l+"_auto";r.selectionCls.addCustomSelection(Object.keys(i),h,t,c,!0),r.selectionCls.saveSelectionIfSelected(),r.drawCls.draw()}}showClbonds(){let e=this.icn3d,t=e.icn3dui;e.opts.clbonds="yes";let s=e.applyClbondsCls.applyClbondsOptions();for(let i in s)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[i]);if(Object.keys(s).length>0){let t="clbonds",i="all atoms that have cross-linkages";e.selectionCls.addCustomSelection(Object.keys(s),t,i,"cross linkage",!0),e.selectionCls.saveSelectionIfSelected(),e.drawCls.draw()}}showSsbonds(){let e=this.icn3d,t=e.icn3dui;e.opts.ssbonds="yes";let s={},i=Object.keys(e.structures);for(let n=0,l=i.length;n<l;++n){let l=i[n];if(void 0!==e.ssbondpnts[l])for(let i=0,n=Math.floor(e.ssbondpnts[l].length/2);i<n;i++){let n=e.ssbondpnts[l][2*i],r=e.ssbondpnts[l][2*i+1];s[n]=1,s[r]=1,e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[n]),e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[r])}}if(Object.keys(s).length>0){let t="ssbonds",i="all atoms that have disulfide bonds";e.selectionCls.addCustomSelection(Object.keys(s),t,i,"disulfide bonds",!0),e.selectionCls.saveSelectionIfSelected(),e.drawCls.draw()}}pickCustomSphere(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui;if(i)return;let a,d,c="select zone cutoff "+e+" | sets "+t+" "+s+" | "+i;n&&(c="interactions "+e+" | sets "+t+" "+s+" | "+i,r.opts.contact="yes"),a=r.definedSetsCls.getAtomsFromNameArray(t),d=r.definedSetsCls.getAtomsFromNameArray(s);let h,p,m=this.pickCustomSphere_base(e,a,d,i,n,l,c,!0),u=Object.keys(m.residues);r.hAtoms={};for(let e=0,t=u.length;e<t;++e){let t=u[e];for(let e in r.residues[t])r.hAtoms[e]=1}let g=r.firstAtomObjCls.getFirstAtomObj(a);void 0!==g&&(h="sphere."+g.chain+":"+o.utilsCls.residueName2Abbr(g.resn.substr(0,3)).trim()+g.resi+"-"+e+"A",n&&(h="interactions."+g.chain+":"+o.utilsCls.residueName2Abbr(g.resn.substr(0,3)).trim()+g.resi+"-"+$("#"+r.pre+"contactthreshold").val()+"A"),p=h,r.selectionCls.addCustomSelection(u,h,p,c,!0)),r.selectionCls.saveSelectionIfSelected(),r.drawCls.draw()}pickCustomSphere_base(e,t,s,i,n,l,r,o,a){let d,c=this.icn3d,h=c.icn3dui;n?(d=c.contactCls.getAtomsWithinAtom(h.hashUtilsCls.hash2Atoms(s,c.atoms),h.hashUtilsCls.hash2Atoms(t,c.atoms),parseFloat(e),o,n,void 0,a),c.resid2ResidhashInteractions=h.hashUtilsCls.cloneHash(c.resid2Residhash)):(d=c.contactCls.getAtomsWithinAtom(s,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 Ut{constructor(e){this.icn3d=e}async viewInteractionPairs(e,t,s,i,n,l,r,o,a,d,c){let h,p=this.icn3d,m=p.icn3dui;s||(p.hbondpnts=[],p.saltbridgepnts=[],p.contactpnts=[],p.halogenpnts=[],p.picationpnts=[],p.pistackingpnts=[]),p.bRender=!1;let u,g={},f=m.hashUtilsCls.cloneHash(p.hAtoms),C="calpha"==i||"cbeta"==i||"heavyatoms"==i,b={},y={};if(C)for(let e in p.hAtoms){let t=p.atoms[e];"HOH"!=t.resn&&"WAT"!=t.resn&&"SOL"!=t.resn&&(("calpha"==i&&(t.het||"CA"==t.name||"O3'"==t.name||"O3*"==t.name)||"cbeta"==i&&(t.het||"CB"==t.name||"O3'"==t.name||"O3*"==t.name)||"heavyatoms"==i&&"H"!=t.elem)&&(b[e]=t,y[e]=t))}else b=p.definedSetsCls.getAtomsFromNameArray(e),y=p.definedSetsCls.getAtomsFromNameArray(t);let v=0,_=0;for(let e in p.structures){for(let t=0,s=p.structures[e].length;t<s;++t){let s=p.structures[e][t];for(let e in p.chains[s])if(b.hasOwnProperty(e)||y.hasOwnProperty(e)){++v;break}}++_}u=_>1?"structure":v>1?"chain":"residue";let w=[];if(n&&w.push("hbonds"),l&&w.push("salt bridge"),r&&w.push("interactions"),o&&w.push("halogen"),a&&w.push("pi-cation"),d&&w.push("pi-stacking"),s||(p.resids2inter={},p.resids2interAll={}),l){let n=parseFloat($("#"+p.pre+"saltbridgethreshold").val());n&&!isNaN(n)||(n=p.tsIonic),s||(p.hAtoms=m.hashUtilsCls.cloneHash(f),p.showInterCls.showIonicInteractions(n,e,t,s,!0,i)),g=m.hashUtilsCls.unionHash(g,p.hAtoms)}if(n){let n=parseFloat($("#"+p.pre+"hbondthreshold").val());n&&!isNaN(n)||(n=p.tsHbond),s||(p.hAtoms=m.hashUtilsCls.cloneHash(f),p.showInterCls.showHbonds(n,e,t,s,void 0,i)),g=m.hashUtilsCls.unionHash(g,p.hAtoms)}let S,A,x,k,O="";if(n&&(O+=this.exportHbondPairs(i,u)),l&&(O+=this.exportSaltbridgePairs(i,u)),o){let n=parseFloat($("#"+p.pre+"halogenthreshold").val());n&&!isNaN(n)||(n=p.tsHalogen),s||(p.hAtoms=m.hashUtilsCls.cloneHash(f),p.showInterCls.showHalogenPi(n,e,t,s,i,"halogen")),g=m.hashUtilsCls.unionHash(g,p.hAtoms),O+=this.exportHalogenPiPairs(i,u,"halogen")}if(a){let n=parseFloat($("#"+p.pre+"picationthreshold").val());n&&!isNaN(n)||(n=p.tsPication),s||(p.hAtoms=m.hashUtilsCls.cloneHash(f),p.showInterCls.showHalogenPi(n,e,t,s,i,"pi-cation")),g=m.hashUtilsCls.unionHash(g,p.hAtoms),O+=this.exportHalogenPiPairs(i,u,"pi-cation")}if(d){let n=parseFloat($("#"+p.pre+"pistackingthreshold").val());n&&!isNaN(n)||(n=p.tsPistacking),s||(p.hAtoms=m.hashUtilsCls.cloneHash(f),p.showInterCls.showHalogenPi(n,e,t,s,i,"pi-stacking")),g=m.hashUtilsCls.unionHash(g,p.hAtoms),O+=this.exportHalogenPiPairs(i,u,"pi-stacking")}if(r){let n=C?c:parseFloat($("#"+p.pre+"contactthreshold").val());if(n&&!isNaN(n)||(n=p.tsContact),1!=e.length||1!=t.length||e[0]!=t[0])s||(p.hAtoms=m.hashUtilsCls.cloneHash(f),p.showInterCls.pickCustomSphere(n,e,t,s,!0,i)),g=m.hashUtilsCls.unionHash(g,p.hAtoms),O+=this.exportSpherePairs(!0,i,u);else{if(!s){let l={},o={};if(C){let e=!0,t=p.showInterCls.pickCustomSphere_base(n,b,y,s,!0,void 0,void 0,!0,e);l=m.hashUtilsCls.unionHash(l,t.residues);for(let e in t.resid2Residhash)o[e]=m.hashUtilsCls.unionHash(o[e],t.resid2Residhash[e])}else{let r=[],a="",d="",c={};for(let e in b){let t=p.atoms[e];t.ss==a&&t.chain==d||(Object.keys(c).length>0&&r.push(c),c={}),c[t.serial]=1,a=t.ss,d=t.chain}Object.keys(c).length>0&&r.push(c);let h=r.length,u="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=m.hashUtilsCls.cloneHash(f);let a=p.showInterCls.pickCustomSphere_base(n,r[e],r[t],s,!0,i,u,!0);l=m.hashUtilsCls.unionHash(l,a.residues);for(let e in a.resid2Residhash)o[e]=m.hashUtilsCls.unionHash(o[e],a.resid2Residhash[e])}}p.resid2ResidhashInteractions=o;let a,d,c=Object.keys(l);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(l);void 0!==h&&(a="sphere."+h.chain+":"+m.utilsCls.residueName2Abbr(h.resn.substr(0,3)).trim()+h.resi+"-"+radius+"A",r&&(a="interactions."+h.chain+":"+m.utilsCls.residueName2Abbr(h.resn.substr(0,3)).trim()+h.resi+"-"+$("#"+p.pre+"contactthreshold").val()+"A"),d=a,p.selectionCls.addCustomSelection(c,a,d,A,!0)),p.selectionCls.saveSelectionIfSelected(),p.drawCls.draw()}g=m.hashUtilsCls.unionHash(g,p.hAtoms),O+=this.exportSpherePairs(!0,i,u)}}p.hAtoms=m.hashUtilsCls.cloneHash(g),p.bRender=!0,p.drawCls.draw(),S=p.firstAtomObjCls.getResiduesFromAtoms(g),A="select "+p.resid2specCls.residueids2spec(Object.keys(S)),x="interface_all",k=x,p.selectionCls.addCustomSelection(Object.keys(S),x,k,A,!0);let R=m.hashUtilsCls.intHash(g,b);S=p.firstAtomObjCls.getResiduesFromAtoms(R),A="select "+p.resid2specCls.residueids2spec(Object.keys(S)),x="interface_1",k=x,p.selectionCls.addCustomSelection(Object.keys(S),x,k,A,!0);let I=m.hashUtilsCls.intHash(g,y);S=p.firstAtomObjCls.getResiduesFromAtoms(I),A="select "+p.resid2specCls.residueids2spec(Object.keys(S)),x="interface_2",k=x,p.selectionCls.addCustomSelection(Object.keys(S),x,k,A,!0);let E='<div style="text-align:center"><b>'+w.join(", ")+" between Two Sets:</b><br>",T=p.resid2specCls.atoms2residues(Object.keys(b)),P=p.resid2specCls.atoms2residues(Object.keys(y)),D="select "+p.resid2specCls.residueids2spec(T),M="select "+p.resid2specCls.residueids2spec(P);E+="Set 1: "+e+' <button class="'+p.pre+'selset" cmd="'+D+'">Highlight in 3D</button><br>',E+="Set 2: "+t+' <button class="'+p.pre+'selset" cmd="'+M+'">Highlight in 3D</button><br><br></div>',E+='<div style="text-align:center"><b>The interfaces are:</b><br>';let F=p.resid2specCls.atoms2residues(Object.keys(R)),H=p.resid2specCls.atoms2residues(Object.keys(I)),L="select "+p.resid2specCls.residueids2spec(F),N="select "+p.resid2specCls.residueids2spec(H);E+='interface_1 <button class="'+p.pre+'selset" cmd="'+L+'">Highlight in 3D</button><br>',E+='interface_2 <button class="'+p.pre+'selset" cmd="'+N+'">Highlight in 3D</button><br><br></div>',E+='<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 q=E;if(("graph"==i||"linegraph"==i||"scatterplot"==i||C)&&(E=""),E+=O,"save1"==i||"save2"==i){E=q;let e="";"save1"==i?e="Set 1":"save2"==i&&(e="Set 2"),E+='<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(i);E+=t.html,h=t.bondCnt,$("#"+p.pre+"dl_interactionsorted_html").html(E),m.htmlCls.dialogCls.openDlg("dl_interactionsorted","Show sorted interactions")}else if("view"==i)$("#"+p.pre+"dl_allinteraction_html").html(E),m.htmlCls.dialogCls.openDlg("dl_allinteraction","Show interactions");else if("linegraph"==i){m.htmlCls.dialogCls.openDlg("dl_linegraph","Show interactions between two lines of residue nodes"),p.graphStr=p.getGraphCls.getGraphData(b,y,e,t,E,u),p.bLinegraph=!0;let s=p.lineGraphCls.drawLineGraph(p.graphStr);$("#"+p.pre+"linegraphDiv").html(s)}else if("scatterplot"==i){m.htmlCls.dialogCls.openDlg("dl_scatterplot","Show interactions as scatterplot"),p.graphStr=p.getGraphCls.getGraphData(b,y,e,t,E,u),p.bScatterplot=!0;let s=p.lineGraphCls.drawLineGraph(p.graphStr,!0);$("#"+p.pre+"scatterplotDiv").html(s)}else if("ligplot"==i)await p.ligplotCls.drawLigplot(b);else if(C){m.htmlCls.dialogCls.openDlg("dl_contactmap","Show contact map");let s=!0,i=p.getGraphCls.getGraphData(b,y,e,t,E,u,s);p.bContactMap=!0;let n=p.contactMapCls.drawContactMap(i);$("#"+p.pre+"contactmapDiv").html(n)}else if("graph"==i){if(p.graphStr=p.getGraphCls.getGraphData(b,y,e,t,E,u),p.bGraph=!0,Object.keys(y).length+Object.keys(b).length>Object.keys(p.dAtoms).length&&(p.graphStr=p.selectionCls.getGraphDataForDisplayed()),void 0===p.bD3){let e="./script/d3v4-force-all.min.js";await m.getAjaxPromise(e,"script"),p.bD3=!0}$("#"+m.svgid).empty(),m.htmlCls.dialogCls.openDlg("dl_graph","Force-directed graph"),p.drawGraphCls.drawGraph(p.graphStr,p.pre+"dl_graph")}return{interactionTypes:w.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 s=Object.keys(e.structures);if(2==t.cfg.atype){let t=!0;await e.alignParserCls.downloadAlignment(s[0]+","+s[1],t)}await e.ParserUtilsCls.set2DDiagramsForAlign(s[0].toUpperCase(),s[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,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a="",d="",c=[],h=Object.keys(r.resids2inter);("save1"==e||"save2"==e)&&h.sort((function(t,s){return o.utilsCls.compResid(t,s,e)}));let p,m,u="",g="",f="",C="",b="",y="",v="",_="",w="",S=0,A=0,x=0,k=0,O=0,R=0,I="";for(let o=0,E=h.length;o<E;++o){let E=h[o],T=E.split(",");p="save1"==e?T[0]:T[1],m="save1"==e?T[1]:T[0];let P,D,M=p.split("_");o>0&&p!=g&&(c.push({res1:g,res2:I,cntHbond:S,cntIonic:A,cntContact:x,cntHalegen:k,cntPication:O,cntPistacking:R}),u+=this.getInteractionPerResidue(f,C,b,y,v,_,w,S,A,x,k,O,R),C="",b="",y="",v="",_="",w="",S=0,A=0,x=0,k=0,O=0,R=0,I=""),P=r.resids2inter[E].hbond,D=this.getInteractionPairDetails(P,e,"hbond",t,s,i,n,l),C+=D.html,S+=D.cnt,a+=D.svgHtmlNode,d+=D.svgHtmlLine,D.cnt>0&&(I+=m+":hbond_"+D.cnt+" "),P=r.resids2inter[E].ionic,D=this.getInteractionPairDetails(P,e,"ionic",t,s,i,n,l),b+=D.html,A+=D.cnt,a+=D.svgHtmlNode,d+=D.svgHtmlLine,D.cnt>0&&(I+=m+":ionic_"+D.cnt+" "),P=r.resids2inter[E].halogen,D=this.getInteractionPairDetails(P,e,"halogen",t,s,i,n,l),v+=D.html,k+=D.cnt,a+=D.svgHtmlNode,d+=D.svgHtmlLine,D.cnt>0&&(I+=m+":halogen_"+D.cnt+" "),P=r.resids2inter[E]["pi-cation"],D=this.getInteractionPairDetails(P,e,"pi-cation",t,s,i,n,l),_+=D.html,O+=D.cnt,a+=D.svgHtmlNode,d+=D.svgHtmlLine,D.cnt>0&&(I+=m+":pi-cation_"+D.cnt+" "),P=r.resids2inter[E]["pi-stacking"],D=this.getInteractionPairDetails(P,e,"pi-stacking",t,s,i,n,l),w+=D.html,R+=D.cnt,a+=D.svgHtmlNode,d+=D.svgHtmlLine,D.cnt>0&&(I+=m+":pi-stacking_"+D.cnt+" "),P=r.resids2inter[E].contact,D=this.getContactPairDetails(P,e,"contact",t,s,i,n,l),y+=D.html,x+=D.cnt,a+=D.svgHtmlNode,d+=D.svgHtmlLine,D.cnt>0&&(I+=m+":contact_"+D.cnt+" "),g=p,f=M}c.push({res1:g,res2:I,cntHbond:S,cntIonic:A,cntContact:x,cntHalegen:k,cntPication:O,cntPistacking:R}),u+=this.getInteractionPerResidue(f,C,b,y,v,_,w,S,A,x,k,O,R);let E="";if(h.length>0){E+='<br><table class="icn3d-sticky" align=center border=1 cellpadding=10 cellspacing=0><thead>',E+="<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>",E+="<th rowspan=2># Halogen<br>Bond</th><th rowspan=2># &pi;-Cation</th><th rowspan=2># &pi;-Stacking</th>",E+="<th>Hydrogen Bond (backbone atoms: @CA, @N, @C, @O)</th><th>Salt Bridge/Ionic Interaction</th><th>Contact</th>",E+="<th>Halogen Bond</th><th>&pi;-Cation</th><th>&pi;-Stacking</th></tr>",E+="<tr>";let e='<td><table width="100%" class="icn3d-border"><tr><td>Atom1</td><td>Atom2</td><td>Distance(&#8491;)</td><td>Highlight in 3D</td></tr></table></td>';E+=e,E+=e,E+='<td><table width="100%" class="icn3d-border"><tr><td>Atom1</td><td>Atom2</td><td># Contacts</td><td>Min Distance(&#8491;)</td><td>C-alpha Distance(&#8491;)</td><td>Highlight in 3D</td></tr></table></td>',E+=e,E+=e,E+=e,E+="</tr>",E+="</thead><tbody>",E+=u,E+="</tbody></table><br/>"}return{html:E,bondCnt:c,svgHtmlNode:a,svgHtmlLine:d}}getInteractionPerResidue(e,t,s,i,n,l,r,o,a,d,c,h,p){this.icn3d.icn3dui;let m="";m+='<tr align="center"><th>'+e[3]+e[2]+"</th><td>"+o+"</td><td>"+a+"</td><td>"+d+"</td><td>"+c+"</td><td>"+h+"</td><td>"+p+"</td>";let u=[t,s,i,n,l,r];for(let e in u){m+='<td valign="top"><table width="100%" class="icn3d-border">'+u[e]+"</table></td>"}return m+="</tr>",m}getInteractionPairDetails(e,t,s,i,n,l,r,o){let a=this.icn3d;a.icn3dui;let d="",c="",h="",p=0,m=' <span style="background-color:#',u='">&nbsp;&nbsp;&nbsp;</span>';if(void 0!==e){a.resid2cnt||(a.resid2cnt={}),a.resid2ToXy||(a.resid2ToXy={}),a.nodeid2lineid||(a.nodeid2lineid={});for(let g in e){let f=g.split("|"),C="save1"==t?f[0]:f[1],b="save1"==t?f[1]:f[0],y=C.lastIndexOf(" "),v=b.lastIndexOf(" "),_=C.substr(0,y),w=b.substr(0,v),S=a.getGraphCls.convertLabel2Resid(_),A=a.firstAtomObjCls.getFirstAtomObj(a.residues[S]),x=A.color?A.color.getHexString():"",k=a.getGraphCls.convertLabel2Resid(w),O=a.firstAtomObjCls.getFirstAtomObj(a.residues[k]),R=O.color?O.color.getHexString():"",I=Math.sqrt(e[g]).toFixed(1);if(h+='<tr><td><span style="white-space:nowrap"><input type="checkbox" class="'+a.pre+'seloneres" id="'+a.pre+s+"2_"+p+'a" resid="'+_+'"/> '+_+m+x+u+'</span></td><td><span style="white-space:nowrap"><input type="checkbox" class="'+a.pre+'seloneres" id="'+a.pre+s+"2_"+p+'b" resid="'+w+'"/> '+w+m+R+u+'</span></td><td align="center">'+I+"</td>",h+='<td align="center"><button class="'+a.pre+'selres" resid="'+_+"|"+w+'">Highlight</button></td>',h+="</tr>",++p,i){let e=C.substr(y+1).split(","),t=a.ligplotCls.getSvgPerPair(e,_,w,s,i,n,l,r,o,I);d+=t.node,c+=t.line}}}return{html:h,cnt:p,svgHtmlNode:d,svgHtmlLine:c}}getContactPairDetails(e,t,s,i,n,l,r,o){let a=this.icn3d;a.icn3dui;let d="",c="",h="",p=0,m=' <span style="background-color:#',u='">&nbsp;&nbsp;&nbsp;</span>';if(void 0!==e){let g={};a.resid2cnt||(a.resid2cnt={}),a.resid2ToXy||(a.resid2ToXy={}),a.nodeid2lineid||(a.nodeid2lineid={});for(let s in e){let n=s.split("|"),l="save1"==t?n[0]:n[1],r="save1"==t?n[1]:n[0],o=l.lastIndexOf(" "),d=r.lastIndexOf(" "),c=l.substr(o+1).split(","),h=l.substr(0,o);i&&(h+="@"+a.atoms[c[0]].name);let p=r.substr(0,d),m=h+"|"+p,u=a.getGraphCls.convertLabel2Resid(h);a.firstAtomObjCls.getFirstAtomObj(a.residues[u]);let f=a.getGraphCls.convertLabel2Resid(p);a.firstAtomObjCls.getFirstAtomObj(a.residues[f]);let C=e[s].split("_"),b=parseFloat(C[0]),y=parseInt(C[4]);g.hasOwnProperty(m)?(g[m].cnt+=y,b<g[m].dist1&&(g[m].dist1=b,g[m].dist1_dist2_atom1_atom2=C,g[m].serialArray1=c)):g[m]={dist1:b,dist1_dist2_atom1_atom2:C,cnt:y,serialArray1:c}}let f={};for(let e in g){let t=e.split("|"),s=t[0],i=t[1];f.hasOwnProperty(i)?f[i].push(s):f[i]=[s];let n=a.getGraphCls.convertLabel2Resid(s),l=a.firstAtomObjCls.getFirstAtomObj(a.residues[n]),r=l.color?l.color.getHexString():"",o=a.getGraphCls.convertLabel2Resid(i),d=a.firstAtomObjCls.getFirstAtomObj(a.residues[o]),c=d.color?d.color.getHexString():"",C=g[e].dist1_dist2_atom1_atom2,b=C[0],y=C[1],v=C[2],_=C[3],w=1;h+='<tr><td><span style="white-space:nowrap"><input type="checkbox" class="'+a.pre+'seloneres" id="'+a.pre+"inter2_"+p+'a" resid="'+s+'"/> '+s+"@"+v+m+r+u+'</span></td><td><span style="white-space:nowrap"><input type="checkbox" class="'+a.pre+'seloneres" id="'+a.pre+"inter2_"+p+'b" resid="'+i+'"/> '+i+"@"+_+m+c+u+'</span></td><td align="center">'+w+'</td><td align="center">'+b+'</td><td align="center">'+y+"</td>",h+='<td align="center"><button class="'+a.pre+'selres" resid="'+s+"|"+i+'">Highlight</button></td>',h+="</tr>",p+=parseInt(w)}if(i)for(let e in f){let t,h,p=f[e];for(let m=0,u=p.length;m<u;++m){let u=p[m],f=u+"|"+e,C=g[f].serialArray1,b=g[f].dist1_dist2_atom1_atom2,y=b[0];b[1];let v=0!=m,_=a.ligplotCls.getSvgPerPair(C,u,e,s,i,n,l,r,o,y,v,t,h);d+=_.node,c+=_.line,t=_.x2,h=_.y2}}}return{html:h,cnt:p,svgHtmlNode:d,svgHtmlLine:c}}exportInteractions(){var e=this.icn3d,t=e.icn3dui;let s='<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 i in e.chainname2residues[t]){let n=t.substr(0,t.indexOf("_"))+"_"+i.substr(0,i.indexOf(" "));s+="<tr><td>"+t+": ",s+=e.resid2specCls.residueids2spec(e.chainname2residues[t][i]),s+="</td><td>"+n+"</td></tr>"}s+="</table><br/></div></body></html>";let i=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(i+"_interactions.html","html",s)}exportSsbondPairs(){var e=this.icn3d,t=e.icn3dui;let s="",i=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){s+="<tr><td>"+n[e]+" Cys</td><td>"+n[e+1]+" Cys</td></tr>",++i}}let n='<html><body><div style="text-align:center"><br><b>'+i+" 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+=s,n+="</table><br/></div></body></html>";let l=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(l+"_disulfide_pairs.html","html",n)}exportClbondPairs(){var e=this.icn3d,t=e.icn3dui;let s="",i=0,n={};for(let t in e.structures){let l=e.clbondpnts[t];if(void 0===l)break;for(let t=0,r=l.length;t<r;t+=2){let r=l[t],o=l[t+1];if(!n.hasOwnProperty(r+"_"+o)){let t=e.firstAtomObjCls.getFirstAtomObj(e.residues[r]),n=e.firstAtomObjCls.getFirstAtomObj(e.residues[o]);s+="<tr><td>"+r+" "+t.resn+"</td><td>"+o+" "+n.resn+"</td></tr>",++i}n[r+"_"+o]=1,n[o+"_"+r]=1}}let l='<html><body><div style="text-align:center"><br><b>'+i+" 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>";l+=s,l+="</table><br/></div></body></html>";let r=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(r+"_crosslinkage_pairs.html","html",l)}exportHbondPairs(e,t){var s=this.icn3d,i=s.icn3dui;let n="",l=0,r=' <span style="background-color:#',o='">&nbsp;&nbsp;&nbsp;</span>';for(let t in s.resid2ResidhashHbond){let i=s.getGraphCls.convertLabel2Resid(t),a=s.firstAtomObjCls.getFirstAtomObj(s.residues[i]),d=a.color?a.color.getHexString():"";for(let i in s.resid2ResidhashHbond[t]){let a=s.getGraphCls.convertLabel2Resid(i),c=s.firstAtomObjCls.getFirstAtomObj(s.residues[a]),h=c.color?c.color.getHexString():"",p=Math.sqrt(s.resid2ResidhashHbond[t][i]).toFixed(1);n+='<tr><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"hbond_"+l+'a" resid="'+t+'"/> '+t+r+d+o+'</td><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"hbond_"+l+'b" resid="'+i+'"/> '+i+r+h+o+'</td><td align="center">'+p+"</td>","view"==e&&(n+='<td align="center"><button class="'+s.pre+'selres" resid="'+t+"|"+i+'">Highlight</button></td>'),n+="</tr>",++l}}let a='<div style="text-align:center"><br><b>'+l+" hydrogen bond pairs</b> (backbone atoms: @CA, @N, @C, @O):</div><br>";if(l>0&&(a+="<br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Atom 1</th><th>Atom 2</th><th>Distance(&#8491;)</th>","view"==e&&(a+='<th align="center">Highlight in 3D</th>'),a+="</tr>",a+=n,a+="</table><br/>"),"graph"==e||"linegraph"==e||"scatterplot"==e){return s.getGraphCls.getGraphLinks(s.resid2ResidhashHbond,s.resid2ResidhashHbond,i.htmlCls.hbondColor,t,i.htmlCls.hbondValue)}return a}exportSaltbridgePairs(e,t){var s=this.icn3d,i=s.icn3dui;let n="",l=0,r=' <span style="background-color:#',o='">&nbsp;&nbsp;&nbsp;</span>';for(let t in s.resid2ResidhashSaltbridge){let i=s.getGraphCls.convertLabel2Resid(t),a=s.firstAtomObjCls.getFirstAtomObj(s.residues[i]),d=a.color?a.color.getHexString():"";for(let i in s.resid2ResidhashSaltbridge[t]){let a=s.getGraphCls.convertLabel2Resid(i),c=s.firstAtomObjCls.getFirstAtomObj(s.residues[a]),h=c.color?c.color.getHexString():"",p=Math.sqrt(s.resid2ResidhashSaltbridge[t][i]).toFixed(1);n+='<tr><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"saltb_"+l+'a" resid="'+t+'"/> '+t+r+d+o+'</td><td><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"saltb_"+l+'b" resid="'+i+'"/> '+i+r+h+o+'</td><td align="center">'+p+"</td>","view"==e&&(n+='<td align="center"><button class="'+s.pre+'selres" resid="'+t+"|"+i+'">Highlight</button></td>'),n+="</tr>",++l}}let a='<div style="text-align:center"><br><b>'+l+" salt bridge/ionic interaction pairs</b>:</div><br>";if(l>0&&(a+="<br><table align=center border=1 cellpadding=10 cellspacing=0><tr><th>Atom 1</th><th>Atom 2</th><th>Distance(&#8491;)</th>","view"==e&&(a+='<th align="center">Highlight in 3D</th>'),a+="</tr>",a+=n,a+="</table><br/>"),"graph"==e||"linegraph"==e||"scatterplot"==e){return s.getGraphCls.getGraphLinks(s.resid2ResidhashSaltbridge,s.resid2ResidhashSaltbridge,i.htmlCls.ionicColor,t,i.htmlCls.ionicValue)}return a}exportHalogenPiPairs(e,t,s){var i=this.icn3d,n=i.icn3dui;let l,r,o,a="",d=0,c=' <span style="background-color:#',h='">&nbsp;&nbsp;&nbsp;</span>';"halogen"==s?(l=i.resid2ResidhashHalogen,r=n.htmlCls.halogenColor,o=n.htmlCls.halogenValue):"pi-cation"==s?(l=i.resid2ResidhashPication,r=n.htmlCls.picationColor,o=n.htmlCls.picationValue):"pi-stacking"==s&&(l=i.resid2ResidhashPistacking,r=n.htmlCls.pistackingColor,o=n.htmlCls.pistackingValue);for(let t in l){let n=i.getGraphCls.convertLabel2Resid(t),r=i.firstAtomObjCls.getFirstAtomObj(i.residues[n]),o=r.color?r.color.getHexString():"";for(let n in l[t]){let r=i.getGraphCls.convertLabel2Resid(n),p=i.firstAtomObjCls.getFirstAtomObj(i.residues[r]),m=p.color?p.color.getHexString():"",u=Math.sqrt(l[t][n]).toFixed(1);a+='<tr><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+s+"_"+d+'a" resid="'+t+'"/> '+t+c+o+h+'</td><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+s+"_"+d+'b" resid="'+n+'"/> '+n+c+m+h+'</td><td align="center">'+u+"</td>","view"==e&&(a+='<td align="center"><button class="'+i.pre+'selres" resid="'+t+"|"+n+'">Highlight</button></td>'),a+="</tr>",++d}}let p='<div style="text-align:center"><br><b>'+d+" "+s+" 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(&#8491;)</th>","view"==e&&(p+='<th align="center">Highlight in 3D</th>'),p+="</tr>",p+=a,p+="</table><br/>"),"graph"==e||"linegraph"==e||"scatterplot"==e){return i.getGraphCls.getGraphLinks(l,l,r,t,o)}return p}exportSpherePairs(e,t,s){var i=this.icn3d,n=i.icn3dui;let l="",r=0,o=e?i.resid2ResidhashInteractions:i.resid2ResidhashSphere,a=' <span style="background-color:#',d='">&nbsp;&nbsp;&nbsp;</span>';for(let s in o){let n=i.getGraphCls.convertLabel2Resid(s),c=i.firstAtomObjCls.getFirstAtomObj(i.residues[n]),h=c.color?c.color.getHexString():"";for(let n in o[s]){let p=i.getGraphCls.convertLabel2Resid(n),m=i.firstAtomObjCls.getFirstAtomObj(i.residues[p]),u=m.color?m.color.getHexString():"",g=o[s][n].split("_"),f=g[0],C=g[1];c=g[2],m=g[3];let b=g[4];e?(l+='<tr><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+"inter_"+r+'a" resid="'+s+'"/> '+s+"@"+c+a+h+d+'</td><td><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+"inter_"+r+'b" resid="'+n+'"/> '+n+"@"+m+a+u+d+'</td><td align="center">'+b+'</td><td align="center">'+f+'</td><td align="center">'+C+"</td>","view"==t&&(l+='<td align="center"><button class="'+i.pre+'selres" resid="'+s+"|"+n+'">Highlight</button></td>'),l+="</tr>"):l+="<tr><td>"+s+"</td><td>"+n+'</td><td align="center">'+b+'</td><td align="center">'+f+'</td><td align="center">'+C+"</td></tr>",++r}}let c='<div style="text-align:center"><br><b>'+r+" residue pairs in "+(e?"the contacts":"sphere")+"</b>:</div><br>";if(r>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(&#8491;)</th><th align="center">C-alpha Distance(&#8491;)</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(&#8491;)</th><th align="center">C-alpha Distance(&#8491;)</th></tr>',c+=l,c+="</table><br/>"),"graph"==t||"linegraph"==t||"scatterplot"==t||"calpha"==t||"cbeta"==t||"heavyatoms"==t){return i.getGraphCls.getGraphLinks(o,o,n.htmlCls.contactColor,s,n.htmlCls.contactValue)}return c}}class $t{constructor(e){this.icn3d=e}drawGraph(e,t){var s=this.icn3d,i=s.icn3dui;if(void 0===n)var n=d3;var l=JSON.parse(e),r=$("#"+t).width(),o=$("#"+t).height(),a=isNaN(r)?300:1*r,d=isNaN(o)?300:1*o,c=r,h=o,p=d3.select("#"+i.svgid).attr("width",r).attr("height",o).attr("viewBox","0,0,"+a+","+d);p.selectAll(".g-main").remove();var m=p.append("g").classed("g-main",!0),u=m.append("rect").attr("width",c).attr("height",h).style("fill","#FFF"),g=m.append("g"),f=n.zoom().on("zoom",(function(){g.attr("transform",n.event.transform)}));if(m.call(f),l.links){for(var C=[],b={},y=0,v=l.nodes.length;y<v;++y){b[(R=l.nodes[y]).id]=1}var _=!1;for(y=0,v=l.links.length;y<v;++y){var w=l.links[y];b.hasOwnProperty(w.source)&&b.hasOwnProperty(w.target)?C.push(w):(b.hasOwnProperty(w.source)||console.log("The node "+w.source+" is not found... "),b.hasOwnProperty(w.target)||console.log("The node "+w.target+" is not found... "),_=!0)}_&&console.log(JSON.stringify(l)),l.links=C;var S={};for(y=0;y<l.nodes.length;y++)i.htmlCls.force||(l.nodes[y].x*=10,l.nodes[y].y*=10),S[l.nodes[y].id]=l.nodes[y],l.nodes[y].weight=1.01;if(i.htmlCls.hideedges&&!i.htmlCls.force){var A=[];for(y=0;y<l.links.length;y++)"FFF"!=l.links[y].c&&A.push(l.links[y]);l.links=A}var x=g.append("g"),k=null,O=(w=g.append("g").attr("class","link").selectAll("line").data(l.links).enter().append("line").attr("stroke",(function(e){return e.v==i.htmlCls.contactInsideValue?"#"+i.htmlCls.contactInsideColor:e.v==i.htmlCls.hbondInsideValue?"#"+i.htmlCls.hbondInsideColor:e.v==i.htmlCls.ionicInsideValue?"#"+i.htmlCls.ionicInsideColor:e.v==i.htmlCls.halogenInsideValue?"#"+i.htmlCls.halogenInsideColor:e.v==i.htmlCls.picationInsideValue?"#"+i.htmlCls.picationInsideColor:e.v==i.htmlCls.pistackingInsideValue?"#"+i.htmlCls.pistackingInsideColor:"#"+e.c})).attr("stroke-width",(function(e){return e.v==i.htmlCls.contactValue||e.v==i.htmlCls.contactInsideValue||e.v==i.htmlCls.hbondInsideValue||e.v==i.htmlCls.ionicInsideValue||e.v==i.htmlCls.halogenInsideValue||e.v==i.htmlCls.picationInsideValue||e.v==i.htmlCls.pistackingInsideValue?"1px":e.v==i.htmlCls.hbondValue||e.v==i.htmlCls.ionicValue||e.v==i.htmlCls.halogenValue||e.v==i.htmlCls.picationValue||e.v==i.htmlCls.pistackingValue?"2px":e.v==i.htmlCls.ssbondValue||e.v==i.htmlCls.clbondValue?"3px":e.v+"px"})),g.append("g").attr("class","node")),R=O.selectAll("circle").data(l.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||i.htmlCls.simulation.alphaTarget(.9).restart();e.selected||q||R.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})),R.filter((function(e){return e.selected})).each((function(e){e.fx=e.x,e.fy=e.y}))})).on("drag",(function(e){R.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||i.htmlCls.simulation.alphaTarget(0);e.fx=null,e.fy=null,R.filter((function(e){return e.selected})).each((function(e){e.fx=null,e.fy=null}))}))),I=O.selectAll("text").data(l.nodes).enter().append("text").text((function(e){var t=e.id,s=t.indexOf(".");return-1!==s&&(t=t.substr(0,s)),t})).attr("fill",(function(e){return"#"+e.c})).attr("stroke","none").attr("class","icn3d-node-text8");R.append("title").text((function(e){return e.id}));var E=parseInt($("#"+s.pre+"dist_ss").val()),T=parseInt($("#"+s.pre+"dist_coil").val()),P=parseInt($("#"+s.pre+"dist_hbond").val()),D=parseInt($("#"+s.pre+"dist_inter").val()),M=parseInt($("#"+s.pre+"dist_ssbond").val()),F=parseInt($("#"+s.pre+"dist_ionic").val()),H=parseInt($("#"+s.pre+"dist_halogen").val()),L=parseInt($("#"+s.pre+"dist_pication").val()),N=parseInt($("#"+s.pre+"dist_pistacking").val());i.htmlCls.simulation=n.forceSimulation().force("link",n.forceLink().id((function(e){return e.id})).distance((function(e){return 30})).strength((function(e){return i.htmlCls.force?e.v==i.htmlCls.ssValue?isNaN(E)?1:E/100:e.v==i.htmlCls.coilValue||e.v==i.htmlCls.clbondValue?isNaN(T)?.5:T/100:e.v==i.htmlCls.hbondValue||e.v==i.htmlCls.hbondInsideValue?isNaN(P)?.5:P/100:e.v==i.htmlCls.contactValue||e.v==i.htmlCls.contactInsideValue?isNaN(D)?.25:D/100:e.v==i.htmlCls.ssbondValue?isNaN(M)?.5:M/100:e.v==i.htmlCls.ionicValue||e.v==i.htmlCls.ionicInsideValue?isNaN(F)?.5:F/100:e.v==i.htmlCls.halogenValue||e.v==i.htmlCls.halogenInsideValue?isNaN(H)?.5:H/100:e.v==i.htmlCls.picationValue||e.v==i.htmlCls.picationInsideValue?isNaN(L)?.5:L/100:e.v==i.htmlCls.pistackingValue||e.v==i.htmlCls.pistackingInsideValue?isNaN(N)?.5:N/100:0:0}))).force("center",n.forceCenter(c/2,h/2)),i.htmlCls.force&&i.htmlCls.simulation.force("charge",n.forceManyBody()),1==i.htmlCls.force?i.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==i.htmlCls.force?i.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==i.htmlCls.force?i.htmlCls.simulation.force("r",n.forceRadial((function(e){return"a"==e.s?200:100}),c/2,h/2).strength((function(e){return.8}))):i.htmlCls.force,i.htmlCls.simulation.nodes(l.nodes).on("tick",(function(){w.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})),R.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})),I.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}))})),i.htmlCls.simulation.force("link").links(l.links);var q,U=!1,B=!1,j=n.brush().on("start",(function(){B=!0,R.each((function(e){e.previouslySelected=q&&e.selected}))})).on("brush",(function(){if(!n.event.sourceEvent)return;if(!n.event.selection)return;var e=n.event.selection;R.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(!k)return;k.call(j.move,null),U||(k.remove(),k=null);B=!1}));return u.on("click",(function(){R.each((function(e){e.selected=!1,e.previouslySelected=!1})),R.classed("selected",!1)})),n.select("body").on("keydown",(function(){if(q=n.event.ctrlKey){if(k)return;U=!0,k||(k=x.append("g")).call(j)}})),n.select("body").on("keyup",(function(){if(q=!1,U=!1,!k)return;B||(k.remove(),k=null)})),l}console.log("Graph is missing links")}}class Bt{constructor(e){this.icn3d=e}async contactMap(e,t){let s=this.icn3d;s.icn3dui;let i=["selected"],n=["selected"];if(0==n.length)alert("Please select the first set");else{s.definedSetsCls.setMode("selection");let l=!1,r=!1,o=!0,a=!1,d=!1,c=!1;await s.viewInterPairsCls.viewInteractionPairs(n,i,!1,t,l,r,o,a,d,c,e)}}async afErrorMap(e,t){let s=this.icn3d,i=s.icn3dui;i.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_"+s.AFUniprotVersion+".json",l=await i.getAjaxPromise(n,"json",!1,"There are some problems in loading the PAE file...");this.processAfErrorMap(l,t)}processAfErrorMap(e,t){let s=this.icn3d,i=s.icn3dui,n=e[0]?e[0]:e,l=n.predicted_aligned_error||n.pae,r=n.max_predicted_aligned_error||n.max_pae;if(!l||!r)return void alert("The PAE file didn't have the right format...");let o,a='"nodes": [',d='"links": [',c=!1,h=!1;s.chains&&0!=Object.keys(s.chains).length?o=!0:(o=!1,s.init_base());let p=l.length,m=0,u={};for(let e in s.chains)for(let t=0,i=s.chainsSeq[e].length;t<i;++t)u[m]=s.chainsSeq[e][t],u[m].chainid=e,++m;m=0;for(let e=0;e<p;++e){let n=o?u[e].resi:e+1,g=o?u[e].name:"*",f=o?u[e].chainid:"stru_A",C=f+"_"+n,b=s.residues[C]?s.firstAtomObjCls.getFirstAtomObj(s.residues[C]):{color:i.parasCls.thr(8947848)},y=f.substr(f.indexOf("_")+1),v=b.color.getHexString();c&&(a+=", ");let _=g+n+"."+y;a+='{"id":"'+_+'","r":"1_1_'+C+'","s":"a","c":"'+v+'"}\n',a+=', {"id":"'+_+'.","r":"1_1_'+C+'","s":"b","c":"'+v+'"}',c=!0;for(let s=t?0:e;s<p;++s){m=e*p+s;let t=o?u[s].resi:s+1,i=o?u[s].name:"*",n=o?u[s].chainid:"stru_A",a=i+t+"."+n.substr(n.indexOf("_")+1),c=l[e][s]?l[e][s]/r:0,g=parseInt(255*c).toString(16),f=parseInt(255*(.698*c+.302)).toString(16),C=1==g.length?"0"+g:g;h&&(d+=", "),d+='{"source": "'+_+'", "target": "'+a+'.", "v": 11, "c": "'+(C+(1==f.length?"0"+f:f)+C)+'", "pae": '+parseInt(l[e][s])+"}\n",h=!0}}e={};let g="{"+a+"], "+d+"]}";this.drawContactMap(g,!0,r)}drawContactMap(e,t,s){let i,n=this.icn3d,l=n.icn3dui,r=JSON.parse(e),o=r.links,a=[],d=[],c={};for(let e=0,t=r.nodes.length;e<t;++e){let t=r.nodes[e];t&&(c[t.id]=t,"a"==t.s?a.push(t):"b"==t.s?d.push(t):"ab"==t.s&&(a.push(t),d.push(t)))}a.sort((function(e,t){return n.getGraphCls.compNode(e,t)})),d.sort((function(e,t){return n.getGraphCls.compNode(e,t)}));let h,p,m,u,g="{\n",f=Object.keys(n.structures).length>0?n.structures[0]:n.defaultPdbId;p=10*(a.length+2)+20+30,h=10*(d.length+2)+20+30,t?(n.alignerrormapWidth=2*h,u=n.alignerrormapWidth,m=l.alignerrormapid):(n.contactmapWidth=2*h,u=n.contactmapWidth,m=l.contactmapid),i=o.length>0?"":"No interactions found for these two sets<br><br>",i+="<svg xmlns='http://www.w3.org/2000/svg' id='"+m+"' viewBox='0,0,"+h+","+p+"' width='"+u+"px'>";if(t){n.hex2id={};let e=29/s;n.hex2skip={};let t=1e3;for(let s=0;s<t;++s){let i=1*s/t,r=parseInt(255*i).toString(16),o=parseInt(255*(.698*i+.302)).toString(16),a=1==r.length?"0"+r:r,d=a+(1==o.length?"0"+o:o)+a,c=l.pre+"afmap_"+s;n.hex2id[d]=c,i>e&&(n.hex2skip[d]=c)}}if(i+=n.lineGraphCls.drawScatterplot_base(a,d,o,c,0,!0,void 0,void 0,t),g+=n.getGraphCls.updateGraphJson(f,1,a,d,o),i+="</svg>",g+="}\n",t){n.alignerrormapStr=g,$("#"+n.pre+"alignerrormapDiv").html(i);let e=$("#"+l.alignerrormapid+"_scale").val();$("#"+l.alignerrormapid).attr("width",(n.alignerrormapWidth*parseFloat(e)).toString()+"px")}else n.contactmapStr=g,$("#"+n.pre+"contactmapDiv").html(i);return i}}class jt{constructor(e){this.icn3d=e}async downloadAlignment(e,t){let s=this.icn3d,i=s.icn3dui,n=this;s.opts.proteins="c alpha trace";let l=e.split(","),r="ids="+e,o=i.htmlCls.baseUrl+"vastplus/vastplus.cgi?v=3&cmd=c&b=1&s=1&w3d&"+r;void 0!==i.cfg.inpara&&(o+=i.cfg.inpara),s.pdbid_chain2title={},void 0===s.chainids2resids&&(s.chainids2resids={});let a={},d="These two MMDB IDs "+l+' 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 i.getAjaxPromise(o,"jsonp",!0,d);if(a=c.seqalign,void 0===a)return alert(d),!1;s.pdbid_molid2chain={},s.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,l={};for(let e=0,r=t.molecules.length;e<r;++e){let r=t.molecules[e],o=r.moleculeId,a=r.chain.trim().replace(/_/g,"");void 0===l[a]?l[a]=1:++l[a];let d=1===l[a]?a:a+l[a].toString();s.pdbid_molid2chain[n+"_"+o]=d,"p"!==r.kind&&"n"!==r.kind||(s.chainsColor[n+"_"+d]=i.parasCls.thr(i.htmlCls.GREY8))}}s.mmdbidArray=[];for(let e=0,t=2;e<t;++e){let t=c.alignedStructures[0][e],i=t.pdbId;s.mmdbidArray.push(i);let n=t.molecules;for(let e in n){let t=n[e].chain;s.pdbid_chain2title[i+"_"+t]=n[e].name}}s.alignmolid2color=[],i.parasCls.stdChainColors.length;for(let e=0,t=a.length;e<t;++e){let t=a[e][0].moleculeId,i=a[e][1].moleculeId,n={};n[t]=(e+1).toString(),s.alignmolid2color.push(n),n={},n[i]=(e+1).toString(),s.alignmolid2color.push(n)}if(!t){let e=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+i.cfg.bu+"&uid="+s.mmdbidArray[0],t=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+i.cfg.bu+"&uid="+s.mmdbidArray[1],l=i.getAjaxPromise(e,"jsonp",!0),r=i.getAjaxPromise(t,"jsonp",!0),o=Promise.allSettled([l,r]),d=await o,h=c,p=d[0].value,m=d[1].value;if(void 0===p.atoms||void 0===m.atoms)return alert("invalid atoms data."),!1;{s.ParserUtilsCls.setYourNote((s.mmdbidArray[0]+","+s.mmdbidArray[1]).toUpperCase()+"(VAST+) in iCn3D");let e=1,t=h.transform.translate.master,i=new THREE.Vector3(t[0]/e,t[1]/e,t[2]/e),l=h.transform.translate.slave,r=new THREE.Vector3(l[0]/e,l[1]/e,l[2]/e),o=h.transform.rotate,d=[];for(let t=0,s=o.length;t<s;++t)d.push(o[t]/e);s.chainid2seq={};for(let e in p.sequences){let t=s.mmdbidArray[0]+"_"+e;s.chainid2seq[t]=p.sequences[e]}for(let e in m.sequences){let t=s.mmdbidArray[1]+"_"+e;s.chainid2seq[t]=m.sequences[e]}let c=p.atoms,u=m.atoms,g=p.atomCount,f=m.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(g)):1==e&&(t.serialInterval.push(g+1),t.serialInterval.push(g+f))}let C={};for(let e in c){let t=c[e];t.coord=new THREE.Vector3(t.coord[0],t.coord[1],t.coord[2]),t.coord.add(i);let s=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],l=t.coord.x*d[6]+t.coord.y*d[7]+t.coord.z*d[8];t.coord.x=s,t.coord.y=n,t.coord.z=l,C[e]=t}for(let e in u){let t=u[e];t.coord=new THREE.Vector3(t.coord[0],t.coord[1],t.coord[2]),t.coord.add(r);for(let e=0,s=t.bonds.length;e<s;++e)t.bonds[e]+=g;C[(parseInt(e)+g).toString()]=t}let b={};b.alignedStructures=h.alignedStructures,b.alignment=h.alignment,b.atoms=C,await n.loadOpmDataForAlign(b,a,s.mmdbidArray)}}}async downloadAlignmentPart2(e,t,s){let i=this.icn3d,n=i.icn3dui;i.loadAtomDataCls.loadAtomDataIn(e,void 0,"align",t),void 0===n.cfg.align&&1==Object.keys(i.structures).length&&$("#"+i.pre+"alternateWrapper").hide();let l={};for(let e in i.atoms)l[e]=1;i.dAtoms=l,i.hAtoms=l,i.setStyleCls.setAtomStyleByOptions(i.opts),i.setColorCls.setColorByOptions(i.opts,i.atoms),void 0!==s&&i.ParserUtilsCls.transformToOpmOriForAlign(i.selectedPdbid,s,!0),await i.ParserUtilsCls.renderStructure(),void 0!==n.cfg.rotate&&i.resizeCanvasCls.rotStruc(n.cfg.rotate,!0),i.html2ddgm="",n.cfg.showalignseq&&n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),n.cfg.show2d&&i.bFullUi&&await i.ParserUtilsCls.set2DDiagramsForAlign(i.mmdbidArray[0].toUpperCase(),i.mmdbidArray[1].toUpperCase())}async loadOpmDataForAlign(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this,r="https://opm-assets.storage.googleapis.com/pdb/"+s[0].toLowerCase()+".pdb",o=n.getAjaxPromise(r,"text"),a="https://opm-assets.storage.googleapis.com/pdb/"+s[1].toLowerCase()+".pdb",d=n.getAjaxPromise(a,"text"),c=Promise.allSettled([o,d]);try{let n=await c,r=!1;for(let o=0,a=n.length;o<a;++o){let a=n[o].value;if(!a)continue;i.selectedPdbid=s[o],i.bOpm=!0;let d=!0,c=i.loadPDBCls.loadPDB(a,s[o],i.bOpm,d);$("#"+i.pre+"selectplane_z1").val(i.halfBilayerSize),$("#"+i.pre+"selectplane_z2").val(-i.halfBilayerSize),$("#"+i.pre+"extra_mem_z").val(i.halfBilayerSize),$("#"+i.pre+"intra_mem_z").val(-i.halfBilayerSize),i.init(),await l.downloadAlignmentPart2(e,t,c),r=!0;break}r||(i.init(),await l.downloadAlignmentPart2(e,t))}catch(s){return i.init(),void await l.downloadAlignmentPart2(e,t)}}}class zt{constructor(e){this.icn3d=e}async downloadChainalignmentPart2(e,t,s,i){let n,l,r=this.icn3d,o=r.icn3dui,a=this,d={},c={};n=i[0].substr(0,i[0].indexOf("_"));let h=!1;if(n.length>5){let t=!1,s=!0;d=await r.pdbParserCls.loadPdbData(e,n,!1,t,"target",h,s)}else{let t=!0;d=await r.mmdbParserCls.parseMmdbData(e,"target",i[0],0,h,t)}for(let e=0,s=t.length;e<s;++e){if(e==t.length-1&&(h=!0),l=i[e+1].substr(0,i[e+1].indexOf("_")),l.length>5){let s=!0,i=!0;c=await r.pdbParserCls.loadPdbData(t[e],l,!1,s,"query",h,i)}else{let s=!0;c=await r.mmdbParserCls.parseMmdbData(t[e],"query",i[e+1],e,h,s)}d=o.hashUtilsCls.unionHash(d,c)}if(o.cfg.resnum)await r.realignParserCls.realignChainOnSeqAlign(s,i);else if(o.cfg.resdef)await r.realignParserCls.realignChainOnSeqAlign(s,i,void 0,!0);else{await r.pdbParserCls.applyCommandDssp(!0);
5
5
  //!!!
6
- let e=[],t=[],c=[],h=o.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",p=o.htmlCls.baseUrl+"tmalign/tmalign.cgi",m=o.cfg.resrange?o.cfg.resrange.split(","):[],u=o.cfg.resrange?r.realignParserCls.getSeqCoorResid([m[0]],i[0],!0).hAtoms:r.chains[i[0]];for(let s=1,n=i.length;s<n;++s){let n,a=o.cfg.resrange?r.realignParserCls.getSeqCoorResid([m[s]],i[s],!0).hAtoms:r.chains[i[s]];if("tmalign"!=o.cfg.aligntool){let e={domains1:r.domain3dCls.getDomainJsonForAlign(a),domains2:r.domain3dCls.getDomainJsonForAlign(u)};n=o.getAjaxPostPromise(h,e)}else{let e={pdb_query:r.saveFileCls.getAtomPDB(a),pdb_target:r.saveFileCls.getAtomPDB(u)};n=o.getAjaxPostPromise(p,e)}e.push(n),t.push(s-1),c.push(l)}let g=Promise.allSettled(e),f=await g;await a.downloadChainalignmentPart2b(s,i,d,f,t,n,c)}}async downloadChainalignmentPart2b(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui;for(let e=0,t=i.length;e<t;++e){let t=i[e].value,s=r[e],o=n[e],d=s==l,c=!1,h={};a.htmlCls.clickMenuCls.setLogCmd("Align "+l+" with "+s,!1),this.processAlign(t,o,h,d,c)}for(let e=0,t=i.length;e<t;++e){let t=r[e],s=n[e];this.transformStructure(t,s,"query")}let d={};!o.bFullUi||void 0===o.q_rotation||a.cfg.resnum||a.cfg.resdef||(d=this.setMsa(t)),o.hAtoms=a.hashUtilsCls.cloneHash(d),o.transformCls.zoominSelection(),await this.downloadChainalignmentPart3(e,t,o.hAtoms)}setMsa(e,t,s){let i=this.icn3d,n=i.icn3dui,l=[];for(let t=1,s=e.length;t<s;++t){let e=0;if(i.qt_start_end&&i.qt_start_end[t-1])for(let s=0,n=i.qt_start_end[t-1].length;s<n;++s)e+=parseInt(i.qt_start_end[t-1][s].q_end)-parseInt(i.qt_start_end[t-1][s].q_start)+1;l.push({index:t,alignLen:e})}l.sort((function(e,t){return t.alignLen-e.alignLen}));let r=i.setSeqAlignCls.setSeqAlignChainForAll(e,l,s);t&&(i.opts.color="identity",i.setColorCls.setColorByOptions(i.opts,r));let o=n.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(i.alnChains),void 0,void 0,!1,void 0,!1),a=$("#"+i.pre+"dl_sequence2").html();return $("#"+i.pre+"dl_sequence2").html(a+o.sequencesHtml),$("#"+i.pre+"dl_sequence2").width(n.htmlCls.RESIDUE_WIDTH*o.maxSeqCnt+200),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),r}async downloadChainalignmentPart2bRealign(e,t,s){let i=this.icn3d,n=i.icn3dui;i.t_trans_add=[],i.q_trans_sub=[],"tmalign"==n.cfg.aligntool&&(i.q_trans_add=[]),i.q_rotation=[],i.qt_start_end=[];let l={},r={},o=!1;for(let s=0,i=e.length;s<i;++s){let i=e[s].value,a=!1,d=!1,c={},h=t[s].split(","),p=h[0].substr(0,h[0].indexOf("_")),m=h[1].substr(0,h[1].indexOf("_"));if(r.hasOwnProperty(p+"_"+m))continue;n.htmlCls.clickMenuCls.setLogCmd("Align "+p+" with "+m,!1);let u=!0;this.processAlign(i,s,c,a,d,u)&&(o=!0,l[p]=void 0===l[p]?1:++l[p],l[m]=void 0===l[m]?1:++l[m],r[p+"_"+m]=h+","+s)}if(!o)return s?"tmalign"==n.cfg.aligntool?void(i.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 i.realignParserCls.realignOnStructAlign()):void i.realignParserCls.realignOnStructAlign(!0);let a,d,c=0;for(let e in r){let t=e.split("_");l[t[0]]>c&&(c=l[t[0]],a=t[0]),l[t[1]]>c&&(c=l[t[1]],a=t[1])}let h={},p={},m={},u={};for(let e in r){let t,s,i=e.split("_"),n=r[e].split(","),l=n[2];if(a==i[0]?(t=i[0],s=i[1]):a==i[1]?(t=i[1],s=i[0]):(t=i[0],s=i[1]),m[t]=1,m.hasOwnProperty(s))continue;m[s]=1,u[e]=r[e],d="target";let o=!0;this.transformStructure(t,l,d,o),d="query",this.transformStructure(s,l,d,o),h[n[0]]=1,h[n[1]]=1}for(let e in u)if(void 0!==i.q_rotation){let t=u[e].split(","),s=[t[1],t[0],t[2]],l=i.setSeqAlignCls.setSeqAlignChain(void 0,void 0,s);p=n.hashUtilsCls.unionHash(p,l);let r=!1,o=n.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(i.alnChains),void 0,void 0,!1,void 0,r),a=$("#"+i.pre+"dl_sequence2").html();$("#"+i.pre+"dl_sequence2").html(a+o.sequencesHtml),$("#"+i.pre+"dl_sequence2").width(n.htmlCls.RESIDUE_WIDTH*o.maxSeqCnt+200)}i.dAtoms=n.hashUtilsCls.cloneHash(p),i.hAtoms=n.hashUtilsCls.cloneHash(p);let g="protein_aligned";i.selectionCls.saveSelection(g,g),i.opts.color="identity",i.setColorCls.setColorByOptions(i.opts,i.hAtoms),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),i.drawCls.draw(),i.transformCls.zoominSelection(),i.hlUpdateCls.updateHlAll()}transformStructure(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=n.structures[e];for(let e=0,o=r.length;e<o;++e)for(let o in n.chains[r[e]]){let e=n.atoms[o];void 0===n.q_rotation||!i&&(l.cfg.resnum||l.cfg.resdef)||(e=this.transformAtom(e,t,s))}}transformAtom(e,t,s){let i=this.icn3d,n=i.icn3dui;if("target"===s);else if("query"===s){"tmalign"!=n.cfg.aligntool&&(e.coord.x-=i.q_trans_sub[t].x,e.coord.y-=i.q_trans_sub[t].y,e.coord.z-=i.q_trans_sub[t].z);let s=e.coord.x*i.q_rotation[t].x1+e.coord.y*i.q_rotation[t].y1+e.coord.z*i.q_rotation[t].z1,l=e.coord.x*i.q_rotation[t].x2+e.coord.y*i.q_rotation[t].y2+e.coord.z*i.q_rotation[t].z2,r=e.coord.x*i.q_rotation[t].x3+e.coord.y*i.q_rotation[t].y3+e.coord.z*i.q_rotation[t].z3;"tmalign"!=n.cfg.aligntool?(s-=i.t_trans_add[t].x,l-=i.t_trans_add[t].y,r-=i.t_trans_add[t].z):(s+=i.q_trans_add[t].x,l+=i.q_trans_add[t].y,r+=i.q_trans_add[t].z),e.coord.x=s,e.coord.y=l,e.coord.z=r}return e}async downloadChainalignmentPart3(e,t,s){let i=this.icn3d,n=i.icn3dui,l={};for(let e in i.atoms)l[e]=1;if(i.dAtoms=l,i.hAtoms=l,i.setStyleCls.setAtomStyleByOptions(i.opts),i.opts.color="identity",i.setColorCls.setColorByOptions(i.opts,i.atoms),void 0!==e&&i.ParserUtilsCls.transformToOpmOriForAlign(i.selectedPdbid,e,!0),i.hAtoms=n.hashUtilsCls.cloneHash(s),i.dAtoms=n.hashUtilsCls.cloneHash(s),await i.ParserUtilsCls.renderStructure(),t.length>2){let e=i.firstAtomObjCls.getResiduesFromAtoms(s),t="protein_aligned",n="protein aligned",l="select "+i.resid2specCls.residueids2spec(Object.keys(e));i.selectionCls.addCustomSelection(Object.keys(e),t,n,l,!0)}i.hlUpdateCls.updateHlAll(),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),void 0!==n.cfg.rotate&&i.resizeCanvasCls.rotStruc(n.cfg.rotate,!0),i.html2ddgm="",n.cfg.show2d&&i.bFullUi&&(n.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),i.bFullUi&&(i.bChainAlign?await i.ParserUtilsCls.set2DDiagramsForChainalign(t):i.ParserUtilsCls.download2Ddgm(i.inputid.toUpperCase())))}addPostfixForChainids(e){this.icn3d.icn3dui;let t={};for(let s=0,i=e.length;s<i;++s){let i=e[s],n=i.indexOf("_"),l=i.substr(0,n);t.hasOwnProperty(l)?++t[l]:t[l]=1,l=1==t[l]?l:l+t[l],e[s]=l+i.substr(n)}return e}async downloadChainalignment(e){let t=this.icn3d,s=t.icn3dui;t.opts.proteins="c alpha trace";let i=e.split(","),n=s.cfg.domainids?s.cfg.domainids.split(","):[];n.length<i.length&&(n=[]),t.chainidArray=this.addPostfixForChainids(i);let l=i[0].indexOf("_");t.mmdbid_t=i[0].substr(0,l).toUpperCase(),t.chain_t=i[0].substr(l+1);let r,o,a=[];t.mmdbid_t.length>5?(o="https://alphafold.ebi.ac.uk/files/AF-"+t.mmdbid_t+"-F1-model_"+t.AFUniprotVersion+".pdb",r=s.getAjaxPromise(o,"text")):(o=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+s.cfg.bu+"&uid="+t.mmdbid_t,void 0!==s.cfg.inpara&&(o+=s.cfg.inpara),r=s.getAjaxPromise(o,"jsonp")),a.push(r),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=i.length;e<n;++e){let n,l,r=i[e].indexOf("_"),o=i[e].substr(0,r).toUpperCase();t.mmdbid_q=5==o.length?o.substr(0,4):o,t.chain_q=i[e].substr(r+1),t.mmdbid_q.length>5?(n="https://alphafold.ebi.ac.uk/files/AF-"+t.mmdbid_q+"-F1-model_"+t.AFUniprotVersion+".pdb",l=s.getAjaxPromise(n,"text")):(n=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+s.cfg.bu+"&uid="+t.mmdbid_q,void 0!==s.cfg.inpara&&(n+=s.cfg.inpara),l=s.getAjaxPromise(n,"jsonp")),a.push(l)}for(let e=1,l=i.length;e<l;++e){let l=i[e].indexOf("_"),r=i[e].substr(0,l).toUpperCase();if(t.mmdbid_q=5==r.length?r.substr(0,4):r,t.chain_q=i[e].substr(l+1),!s.cfg.resnum&&!s.cfg.resdef){let i=t.mmdbid_q+"_"+t.chain_q+","+t.mmdbid_t+"_"+t.chain_t,l=n.length>0?n[e]+","+n[0]:void 0;if("tmalign"!=s.cfg.aligntool&&4==t.mmdbid_t.length&&4==t.mmdbid_q.length){let o;o=n.length>0?s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?domainpairs="+l:s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?chainpairs="+i;let d=s.getAjaxPromise(o,"jsonp");a.push(d),t.pdbChainIndexHash[e]=r+"_"+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(a),c=await d;await this.parseChainAlignData(c,i,t.mmdbid_t,t.chain_t)}async parseChainAlignData(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=e[0].value,o="HEADER "+s+"\n";isNaN(s)&&s.length>5&&(r=o+r),n.t_trans_add=[],n.q_trans_sub=[],"tmalign"==l.cfg.aligntool&&(n.q_trans_add=[]),n.q_rotation=[],n.qt_start_end=[],n.mmdbidArray=[],n.mmdbidArray.push(s);let a=[];for(let s=1,i=t.length;s<i;++s){let i=e[s].value,l=t[s].indexOf("_"),r=t[s].substr(0,l).toUpperCase(),o="HEADER "+r+"\n";if(isNaN(r)&&r.length>5&&(i=o+i),void 0===i||-1!==JSON.stringify(i).indexOf("Oops there was a problem"))return void alert("The coordinate data can NOT be retrieved for the structure "+r+"...");n.mmdbidArray.push(r),a.push(i)}let d=0;for(let r=1,o=t.length;r<o;++r){let o=a[r-1],c=t[r].indexOf("_"),h=t[r].substr(0,c).toUpperCase(),p=t[r].substr(c+1);if(!l.cfg.resnum&&!l.cfg.resdef){let a=t.length+r-1;if(n.afChainIndexHash.hasOwnProperty(r))++d,"tmalign"==l.cfg.aligntool?n.q_trans_add[r-1]={x:0,y:0,z:0}:(n.t_trans_add[r-1]={x:0,y:0,z:0},n.q_trans_sub[r-1]={x:0,y:0,z:0}),n.q_rotation[r-1]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},n.qt_start_end[r-1]=void 0;else{let t=e[a-d].value,n=h==s,c=p==i;l.htmlCls.clickMenuCls.setLogCmd("Align "+s+" with "+h,!1),this.processAlign(t,r-1,o,n,c)}}}n.mmdb_data_q=a,await this.loadOpmDataForChainalign(r,a,t,n.mmdbidArray)}processAlign(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a=!1;if(!(e&&0!=e.length||l)){let e="tmalign"==o.cfg.aligntool?"TM-align":"VAST";return r.bRender&&alert("These chains can not be aligned by "+e+"."),a}if(void 0!==s&&-1===JSON.stringify(s).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)&&i&&n)r.t_trans_add[t]={x:0,y:0,z:0},r.q_trans_sub[t]={x:0,y:0,z:0},r.q_rotation[t]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},r.qt_start_end[t]=void 0;else if("error"===e||void 0===e||0==e.length)o.cfg.command||l||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.'),r.t_trans_add[t]={x:0,y:0,z:0},r.q_trans_sub[t]={x:0,y:0,z:0},r.q_rotation[t]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},r.qt_start_end[t]=void 0,o.cfg.showanno=1,o.cfg.showalignseq=0;else{"tmalign"==o.cfg.aligntool?r.q_trans_add[t]=e[0].q_trans_add:(r.t_trans_add[t]=e[0].t_trans_add,r.q_trans_sub[t]=e[0].q_trans_sub),r.q_rotation[t]=e[0].q_rotation,r.qt_start_end[t]=e[0].segs;let s=e[0].super_rmsd,i=s?s.toPrecision(4):s,n=e[0].score?e[0].score.toPrecision(4):e[0].score,l="alignment RMSD: "+i;"tmalign"==o.cfg.aligntool&&(l+="; TM-score: "+n),o.htmlCls.clickMenuCls.setLogCmd(l,!1);let d="<br><b>Alignment RMSD</b>: "+i+" &#8491;<br>";"tmalign"==o.cfg.aligntool&&(d+="<b>TM-score</b>: "+n+"<br><br>",r.tmscore=n),$("#"+r.pre+"dl_rmsd_html").html(d),o.cfg.bSidebyside||o.htmlCls.dialogCls.openDlg("dl_rmsd","RMSD of alignment"),a=!0}return a}async loadOpmDataForChainalign(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=this;if(l.cfg.resnum||l.cfg.resdef||l.cfg.resrange)n.bCommandLoad||n.init(),await this.downloadChainalignmentPart2(e,t,void 0,s);else{let o=l.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?mmdbids2opm="+i.join("','"),a=await l.getAjaxPromise(o,"jsonp");if(a&&a.mmdbid){let i=a.mmdbid;n.selectedPdbid=i;let o="https://opm-assets.storage.googleapis.com/pdb/"+i.toLowerCase()+".pdb",d=await l.getAjaxPromise(o,"text");n.bOpm=!0;let c=!0,h=n.loadPDBCls.loadPDB(d,i,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 r.downloadChainalignmentPart2(e,t,h,s)}else n.bCommandLoad||n.init(),await r.downloadChainalignmentPart2(e,t,void 0,s)}}async downloadMmdbAf(e,t,s,i){let n=this.icn3d,l=n.icn3dui;n.structArray=n.structures?Object.keys(n.structures):[],0==n.structArray.length?n.init():(n.bResetAnno=!0,n.bResetSets=!0);let r=e.split(","),o=[];for(let e=0,t=r.length;e<t;++e){let t=r[e].toUpperCase();n.structures.hasOwnProperty(t)||-1!=o.indexOf(t)?i||o.push(r[e]+l.htmlCls.postfix):o.push(r[e])}if(0==o.length)return;n.structArray=n.structArray.concat(o);let a=[];for(let e=0,t=o.length;e<t;++e){let t,s,i=o[e];if(isNaN(i)&&i.length>5)t="https://alphafold.ebi.ac.uk/files/AF-"+i+"-F1-model_"+n.AFUniprotVersion+".pdb",s=l.getAjaxPromise(t,"text");else{let e=i;5==i.length&&(e=i.substr(0,4)),t=l.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+l.cfg.bu+"&uid="+e,void 0!==l.cfg.inpara&&(t+=l.cfg.inpara),s=l.getAjaxPromise(t,"jsonp")}a.push(s)}n.ParserUtilsCls.setYourNote(n.structArray+" in iCn3D"),n.ParserUtilsCls.showLoading();let d=Promise.allSettled(a),c=await d;await this.parseMMdbAfData(c,o,t,s),void 0===s&&n.ParserUtilsCls.hideLoading()}async parseMMdbAfData(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=[];for(let s=0,i=t.length;s<i;++s){let i=e[s].value,n="HEADER "+t[s]+"\n";if(isNaN(t[s])&&t[s].length>5&&(i=n+i),void 0===i||-1!==JSON.stringify(i).indexOf("Oops there was a problem"))return void alert("The coordinate data can NOT be retrieved for the structure "+t[s]+"...");r.push(i)}let o=!1;for(let e=0,i=t.length;e<i;++e){let i,l;if(e==t.length-1&&(o=!0),0!=e||s||n.structArray.length!=t.length?(i="query",l=!0):(i="target",l=!1),isNaN(t[e])&&t[e].length>5){let s=!1;await n.pdbParserCls.loadPdbData(r[e],t[e],!1,l,i,o,s)}else{let s=!0,l=t[e];await n.mmdbParserCls.parseMmdbData(r[e],i,void 0,void 0,o,s,l)}}let a=Object.keys(n.structures);if(n.opts.color=a.length>1?"structure":a[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!==l.cfg.rotate&&n.resizeCanvasCls.rotStruc(l.cfg.rotate,!0),s&&l.cfg.matchedchains)n.hAtoms=n.definedSetsCls.getAtomsFromNameArray(n.chainidArray),await n.realignParserCls.realignOnStructAlign(),$("#"+n.pre+"dl_annotations").html(""),n.bAnnoShown=!1,$("#"+l.pre+"dl_selectannotations").hasClass("ui-dialog-content")&&$("#"+n.pre+"dl_selectannotations").dialog("isOpen")&&$("#"+n.pre+"dl_selectannotations").dialog("close");else if(void 0!==i){let e=Object.keys(n.structures);2==i&&(l.cfg.aligntool="tmalign"),await n.vastplusCls.vastplusAlign(e,i)}}}class Gt{constructor(e){this.icn3d=e}async dsn6Parser(e,t,s){this.icn3d.icn3dui;let i="https://edmaps.rcsb.org/maps/"+e.toLowerCase()+"_"+t+".dsn6";await this.dsn6ParserBase(i,t,s,"url",!0)}async dsn6ParserBase(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=this;if("2fofc"==t&&l.bAjax2fofc)l.mapData.sigma2=s,l.setOptionCls.setOption("map",t);else if("fofc"==t&&l.bAjaxfofc)l.mapData.sigma=s,l.setOptionCls.setOption("map",t);else{let a=await r.getXMLHttpRqstPromise(e,"GET","arraybuffer","rcsbEdmaps");s=o.loadDsn6Data(a,t,s,i,n),"2fofc"==t?l.bAjax2fofc=!0:"fofc"==t&&(l.bAjaxfofc=!0),l.setOptionCls.setOption("map",t)}return s}loadDsn6Data(e,t,s,i,n){let l,r,o=this.icn3d,a=o.icn3dui,d={},c=e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e,h=new Int16Array(c),p=new Uint8Array(c),m=String.fromCharCode.apply(null,p.subarray(0,512));if(0==m.indexOf(":-)"))d.xStart=parseInt(m.substr(10,5)),d.yStart=parseInt(m.substr(15,5)),d.zStart=parseInt(m.substr(20,5)),d.xExtent=parseInt(m.substr(32,5)),d.yExtent=parseInt(m.substr(38,5)),d.zExtent=parseInt(m.substr(42,5)),d.xRate=parseInt(m.substr(52,5)),d.yRate=parseInt(m.substr(58,5)),d.zRate=parseInt(m.substr(62,5)),d.xlen=1*parseFloat(m.substr(73,10)),d.ylen=1*parseFloat(m.substr(83,10)),d.zlen=1*parseFloat(m.substr(93,10)),d.alpha=parseFloat(m.substr(103,10)),d.beta=parseFloat(m.substr(113,10)),d.gamma=parseFloat(m.substr(123,10)),l=parseFloat(m.substr(138,12))/100,r=parseInt(m.substr(155,8)),d.sigma=100*parseFloat(m.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,l=h[15]/h[18],r=h[16]}a.bNode||console.log("header: "+JSON.stringify(d));let u=new Float32Array(d.xExtent*d.yExtent*d.zExtent),g=512,f=Math.ceil(d.xExtent/8),C=Math.ceil(d.yExtent/8),b=Math.ceil(d.zExtent/8),y=-999;for(let e=0;e<b;++e)for(let t=0;t<C;++t)for(let s=0;s<f;++s)for(let i=0;i<8;++i){let n=8*e+i;for(let e=0;e<8;++e){let i=8*t+e;for(let e=0;e<8;++e){let t=8*s+e;if(!(t<d.xExtent&&i<d.yExtent&&n<d.zExtent)){g+=8-e;break}{let e=(t*d.yExtent+i)*d.zExtent+n;u[e]=(p[g]-r)/l,u[e]>y&&(y=u[e]),++g}}}}return n||(s=this.setSigma(y,i,t,s)),"2fofc"==t?(o.mapData.header2=d,o.mapData.data2=u,o.mapData.matrix2=this.getMatrix(d),o.mapData.type2=t,o.mapData.sigma2=s):(o.mapData.header=d,o.mapData.data=u,o.mapData.matrix=this.getMatrix(d),o.mapData.type=t,o.mapData.sigma=s),s}setSigma(e,t,s,i){let n,l=this.icn3d.icn3dui;"file"==t?n="dsn6sigma"+s:"url"==t&&(n="dsn6sigmaurl"+s);return n&&($("#"+l.pre+n).val()?i=$("#"+l.pre+n).val():(i=(.2*e).toFixed(2),$("#"+l.pre+n).val(i))),i}getMatrix(e){this.icn3d.icn3dui;let t=e,s=[t.xlen,0,0],i=[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 l=[[],s,i,n],r=[0,t.xRate,t.yRate,t.zRate],o=[0,1,2,3],a=new THREE.Matrix4;return a.set(l[o[1]][0]/r[o[1]],l[o[2]][0]/r[o[2]],l[o[3]][0]/r[o[3]],0,l[o[1]][1]/r[o[1]],l[o[2]][1]/r[o[2]],l[o[3]][1]/r[o[3]],0,l[o[1]][2]/r[o[1]],l[o[2]][2]/r[o[2]],l[o[3]][2]/r[o[3]],0,0,0,0,1),a.multiply((new THREE.Matrix4).makeTranslation(t.xStart,t.yStart,t.zStart)),a}loadDsn6File(e){var t=this.icn3d,s=t.icn3dui;let i=this,n=$("#"+t.pre+"dsn6file"+e)[0].files[0],l=$("#"+t.pre+"dsn6sigma"+e).val();if(n){s.utilsCls.checkFileAPI();let t=new FileReader;t.onload=function(t){let n=i.icn3d,r=t.target.result;l=i.loadDsn6Data(r,e,l,"file"),"2fofc"==e?n.bAjax2fofc=!0:"fofc"==e&&(n.bAjaxfofc=!0),n.setOptionCls.setOption("map",e),s.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+n.pre+"dsn6file"+e).val()+" with sigma "+l,!1)},t.readAsArrayBuffer(n)}else alert("Please select a file before clicking 'Load'")}loadDsn6FileUrl(e){var t=this.icn3d,s=t.icn3dui;let i=$("#"+t.pre+"dsn6fileurl"+e).val(),n=$("#"+t.pre+"dsn6sigmaurl"+e).val();i?(n=this.dsn6ParserBase(i,e,n,"url"),s.htmlCls.clickMenuCls.setLogCmd("set map "+e+" sigma "+n+" file dsn6 | "+encodeURIComponent(i),!0)):alert("Please input the file URL before clicking 'Load'")}}class Vt{constructor(e){this.icn3d=e}async ccp4ParserBase(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=await l.getXMLHttpRqstPromise(e,"GET","arraybuffer","");return s=this.load_map_from_buffer(r,t,s,i,!0),n.setOptionCls.setOption("map",t),s}load_map_from_buffer(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui,e.byteLength<1024)throw Error("File shorter than 1024 bytes.");const r=new Int32Array(e,0,256);if(542130509!==r[52])throw Error("not a CCP4 map");const o=[r[0],r[1],r[2]],a=r[3];let d;if(2===a)d=4;else{if(0!==a)throw Error("Only Mode 2 and Mode 0 of CCP4 map is supported.");d=1}const c=[r[4],r[5],r[6]],h=[r[7],r[8],r[9]],p=r[23];if(1024+p+d*o[0]*o[1]*o[2]!==e.byteLength)throw Error("ccp4 file too short or too long");const m=new Float32Array(e,0,e.byteLength/4),u=new Yt(h),g=new Wt(m[10],m[11],m[12],m[13],m[14],m[15]),f=[r[16],r[17],r[18]],C=f.indexOf(1),b=f.indexOf(2),y=f.indexOf(3),v=m[19],_=m[20];if(p%4!=0)throw Error("CCP4 map with NSYMBT not divisible by 4 is not supported.");let w;w=2===a?m:new Int8Array(e);let S=(1024+p)/d|0,A=1,x=0;0===a&&-128===r[39]&&127===r[40]&&(A=(_-v)/255,x=.5*(v+_+A));const k=[c[0]+o[0],c[1]+o[1],c[2]+o[2]];let O=[0,0,0],R=-999;for(O[2]=c[2];O[2]<k[2];O[2]++)for(O[1]=c[1];O[1]<k[1];O[1]++)for(O[0]=c[0];O[0]<k[0];O[0]++){let e=A*w[S]+x;u.set_grid_value(O[C],O[b],O[y],e),e>R&&(R=e),S++}return n||(s=l.dsn6ParserCls.setSigma(R,i,t,s)),"2fofc"==t?(l.mapData.ccp4=1,l.mapData.grid2=u,l.mapData.unit_cell2=g,l.mapData.type2=t,l.mapData.sigma2=s):(l.mapData.ccp4=1,l.mapData.grid=u,l.mapData.unit_cell=g,l.mapData.type=t,l.mapData.sigma=s),s}load_maps_from_mtz_buffer(e,t,s,i,n,l){let r=this.icn3d;r.icn3dui;let o="fofc"==t,a=e.calculate_map(o),d=e.cell;const c=new Wt(d.a,d.b,d.c,d.alpha,d.beta,d.gamma);let h=-999;for(let e=0,t=a.length;e<t;++e)a[e]>h&&(h=a[e]);if(n||(s=r.dsn6ParserCls.setSigma(h,i,t,s)),l){r.mapData.ccp4=0;let i={xExtent:e.nx,yExtent:e.ny,zExtent:e.nz,mean:void 0,sigma:s,ccp4:1,xStart:0,yStart:0,zStart:0};i.xRate=e.nx,i.yRate=e.ny,i.zRate=e.nz,i.xlen=d.a,i.ylen=d.b,i.zlen=d.c,i.alpha=d.alpha,i.beta=d.beta,i.gamma=d.gamma,"2fofc"==t?(r.mapData.header2=i,r.mapData.data2=a,r.mapData.matrix2=r.dsn6ParserCls.getMatrix(i),r.mapData.type2=t,r.mapData.sigma2=s):(r.mapData.header=i,r.mapData.data=a,r.mapData.matrix=r.dsn6ParserCls.getMatrix(i),r.mapData.type=t,r.mapData.sigma=s)}else{const i=new Yt([e.nx,e.ny,e.nz]);i.values.set(a),"2fofc"==t?(r.mapData.ccp4=1,r.mapData.grid2=i,r.mapData.unit_cell2=c,r.mapData.type2=t,r.mapData.sigma2=s):(r.mapData.ccp4=1,r.mapData.grid=i,r.mapData.unit_cell=c,r.mapData.type=t,r.mapData.sigma=s)}return e.delete(),s}parse_symop(e){const t=e.toLowerCase().replace(/\s+/g,"").split(",");if(3!==t.length)throw Error("Unexpected symop: "+e);let s=[];for(let i=0;i<3;i++){const n=t[i].split(/(?=[+-])/);let l=[0,0,0,0];for(let t=0;t<n.length;t++){const s="-"===n[t][0]?-1:1;let i=n[t].match(/^[+-]?([xyz])$/);if(i){l[{x:0,y:1,z:2}[i[1]]]=s}else{if(i=n[t].match(/^[+-]?(\d)\/(\d)$/),!i)throw Error("What is "+n[t]+" in "+e);l[3]=s*Number(i[1])/Number(i[2])}}s.push(l)}return s}loadCcp4File(e){let t=this.icn3d,s=t.icn3dui,i=this,n=$("#"+t.pre+"dsn6file"+e)[0].files[0],l=$("#"+t.pre+"dsn6sigma"+e).val();if(n){s.utilsCls.checkFileAPI();let t=new FileReader;t.onload=function(t){let n=i.icn3d,r=t.target.result;l=i.load_map_from_buffer(r,e,l,"file"),n.setOptionCls.setOption("map",e),s.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+n.pre+"dsn6file"+e).val()+" with sigma "+l,!1)},t.readAsArrayBuffer(n)}else alert("Please select a file before clicking 'Load'")}async loadCcp4FileUrl(e){let t=this.icn3d,s=t.icn3dui,i=$("#"+t.pre+"dsn6fileurl"+e).val(),n=$("#"+t.pre+"dsn6sigmaurl"+e).val();i?(n=await this.ccp4ParserBase(i,e,n,"file"),s.htmlCls.clickMenuCls.setLogCmd("set map "+e+" sigma "+n+" file ccp4 | "+encodeURIComponent(i),!0)):alert("Please input the file URL before clicking 'Load'")}extract_block(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui,null==e||null==t)return;let r=t.fractionalize(i),o=[s/t.parameters[0],s/t.parameters[1],s/t.parameters[2]],a=e.frac2grid([r[0]-o[0],r[1]-o[1],r[2]-o[2]]),d=e.frac2grid([r[0]+o[0],r[1]+o[1],r[2]+o[2]]),c=[d[0]-a[0]+1,d[1]-a[1]+1,d[2]-a[2]+1],h=[],p=[],m=l.hAtoms&&Object.keys(l.hAtoms).length>0;for(let s=a[0];s<=d[0];s++)for(let i=a[1];i<=d[1];i++)for(let r=a[2];r<=d[2];r++){let o=e.grid2frac(s,i,r),a=t.orthogonalize(o);h.push(a);let d=new THREE.Vector3(a[0],a[1],a[2]),c=l.rayCls.getAtomsFromPosition(d,1,l.hAtoms)||!m?e.get_grid_value(s,i,r):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,s,i,n){this.icn3d.icn3dui;const l=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]),r="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 a=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],m=[p,p,p,p,p,p,p,p];const u=e[0],g=e[1],f=e[2];if(null==t||null==s)return;let C=[],b=[],y=0;for(let e=0;e<u-1;e++)for(let n=0;n<g-1;n++)for(let p=0;p<f-1;p++){const u=p+f*(n+g*e);let v,_,w=0;for(v=0;v<8;++v)_=u+d[v],w|=t[_]<i?1<<v:0;if(0===w||255===w)continue;for(v=0;v<8;++v)_=u+d[v],h[v]=t[_],m[v]=s[_];const S=l[w];for(v=0;v<12;++v)if(0!=(S&1<<v)){const e=c[v];let t=(i-h[e[0]])/(h[e[1]]-h[e[0]]);!0===r&&(t>.85?t=1:t<.15&&(t=0));const s=m[e[0]],n=m[e[1]];C.push(s[0]+(n[0]-s[0])*t,s[1]+(n[1]-s[1])*t,s[2]+(n[2]-s[2])*t),a[v]=y++}const A=o[w];for(v=0;v<A.length;v++)b.push(a[A[v]])}return{vertices:C,segments:b}}calculateVertOffsets(e){this.icn3d.icn3dui;let t=[];const s=[[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 i=0;i<8;++i){const n=s[i];t.push(n[0]+e[2]*(n[1]+e[1]*n[2]))}return t}makeChickenWire(e,t){let s=this.icn3d,i=s.icn3dui,n=new THREE.BufferGeometry,l=new Float32Array(e.vertices);n.setAttribute("position",new THREE.BufferAttribute(l,3));let r=e.vertices.length<196608?new Uint16Array(e.segments):new Uint32Array(e.segments);n.setIndex(new THREE.BufferAttribute(r,1));let o=i.parasCls.thr("#00FFFF"),a=i.parasCls.thr("#00FF00"),d=i.parasCls.thr("#ff0000"),c="2fofc"==t?o:"fofc_pos"==t?a:d,h=new THREE.LineBasicMaterial({linewidth:1,color:c}),p=new THREE.LineSegments(n,h);s.mdl.add(p),s.prevMaps.push(p)}}class Wt{constructor(e,t,s,i,n,l){if(e<=0||t<=0||s<=0||i<=0||n<=0||l<=0)throw Error("Zero or negative unit cell parameter(s).");this.parameters=[e,t,s,i,n,l];const r=Math.PI/180,o=Math.cos(r*i),a=Math.cos(r*n),d=Math.cos(r*l),c=Math.sin(r*i),h=Math.sin(r*n),p=Math.sin(r*l);if(0===c||0===h||0===p)throw Error("Impossible angle - N*180deg.");const m=(a*d-o)/p,u=m/h,g=Math.sqrt(1-u*u);this.orth=[e,t*d,s*a,0,t*p,-s*m,0,0,s*h*g],this.frac=[1/e,-d/(p*e),-(d*m+a*p)/(h*g*p*e),0,1/(p*t),u/(g*p*t),0,0,1/(h*g*s)]}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 Yt{constructor(e){this.dim=e,this.values=new Float32Array(e[0]*e[1]*e[2])}modulo(e,t){const s=e%t;return s>=0?s:s+t}grid2index(e,t,s){return e=this.modulo(e,this.dim[0]),t=this.modulo(t,this.dim[1]),s=this.modulo(s,this.dim[2]),this.dim[2]*(this.dim[1]*e+t)+s}grid2index_unchecked(e,t,s){return this.dim[2]*(this.dim[1]*e+t)+s}grid2frac(e,t,s){return[e/this.dim[0],t/this.dim[1],s/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,s,i){const n=this.grid2index(e,t,s);this.values[n]=i}get_grid_value(e,t,s){const i=this.grid2index(e,t,s);return this.values[i]}}class Xt{constructor(e){this.icn3d=e}async mtzParserBase(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a=await o.getXMLHttpRqstPromise(e,"GET","arraybuffer","");return s=await this.loadMtzFileBase(a,t,s,i,n,e,l),r.setOptionCls.setOption("map",t),s}loadMtzFile(e,t){var s=this.icn3d,i=s.icn3dui;let n=this,l=$("#"+s.pre+"dsn6file"+e)[0].files[0],r=$("#"+s.pre+"dsn6sigma"+e).val();if(l){i.utilsCls.checkFileAPI();let s=new FileReader;s.onload=async function(s){let l=n.icn3d;r=await n.loadMtzFileBase(s.target.result,e,r,"file",void 0,void 0,t),i.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+l.pre+"dsn6file"+e).val()+" with sigma "+r,!1)},s.readAsArrayBuffer(l)}else alert("Please select a file before clicking 'Load'")}async loadMtzFileBase(e,t,s,i,n,l,r){var o=this.icn3d,a=o.icn3dui;if(void 0===o.bMtz){let e="./script/mtz.js";await a.getAjaxPromise(e,"script"),o.bMtz=!0}GemmiMtz().then((function(d){let c=d.readMtz(e);s=o.ccp4ParserCls.load_maps_from_mtz_buffer(c,t,s,i,n,r),o.setOptionCls.setOption("map",t);let h=r?"rcsbmtz":"mtz";return l&&a.htmlCls.clickMenuCls.setLogCmd("set map "+t+" sigma "+s+" file "+h+" | "+encodeURIComponent(l),!0),s}))}async loadMtzFileUrl(e,t){var s=this.icn3d;s.icn3dui;let i=$("#"+s.pre+"dsn6fileurl"+e).val(),n=$("#"+s.pre+"dsn6sigmaurl"+e).val();i?n=await this.mtzParserBase(i,e,n,"url",void 0,t):alert("Please input the file URL before clicking 'Load'")}}class Kt{constructor(e){this.icn3d=e}async downloadMmcif(e){let t=this.icn3d,s=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(MMCIF) in iCn3D");let i="https://files.rcsb.org/download/"+e+".cif",n=await s.getAjaxPromise(i,"text",!0);await t.opmParserCls.loadOpmData(n,e,void 0,"mmcif",void 0,!0)}async downloadMmcifSymmetry(e,t){let s=this.icn3d,i=s.icn3dui;try{let n="https://models.rcsb.org/"+e+".bcif",l=await i.getXMLHttpRqstPromise(n,"GET","arraybuffer","bcif"),r=!1,o=!0,a=s.bcifParserCls.getBcifJson(l,e,r,o),d=JSON.parse(a);if(void 0!==d.emd&&(s.emd=d.emd),void 0!==d.organism&&(s.organism=d.organism),s.bAssemblyUseAsu){for(let e=0,t=d.assembly.length;e<t;++e){let t=new THREE.Matrix4;t.fromArray(d.assembly[e]),s.biomtMatrices[e]=t}s.asuCnt=s.biomtMatrices.length,1==i.cfg.bu&&Object.keys(s.atoms).length*s.asuCnt>s.maxatomcnt&&(s.bAssembly=!0)}if("mmtfid"===t&&void 0!==d.missingseq){let t=0,n="";for(let l=0,r=d.missingseq.length;l<r;++l){let r=d.missingseq[l].resn,o=d.missingseq[l].chain,a=d.missingseq[l].resi,c=e+"_"+o;void 0===s.chainMissingResidueArray[c]&&(s.chainMissingResidueArray[c]=[]);let h={};h.resi=a,h.name=i.utilsCls.residueName2Abbr(r).toLowerCase(),o!=n&&(t=0),!isNaN(a)&&(""==n||o!=n||o==n&&a>t)&&(s.chainMissingResidueArray[c].push(h),t=a,n=o)}s.loadPDBCls.adjustSeq(s.chainMissingResidueArray)}}catch(e){return void(i.bNode||console.log("mmcifparser.cgi issues: "+e))}}async loadMmcifData(e,t){let s=this.icn3d;if(s.icn3dui,t||(t=e.mmcif),t||(t=s.defaultPdbId),void 0===e.atoms)return!1;s.init(),void 0!==e.emd&&(s.emd=e.emd),void 0!==e.organism&&(s.organism=e.organism),await s.opmParserCls.loadOpmData(e,t,void 0,"mmcif"),s.opmParserCls.modifyUIMapAssembly()}async loadMultipleMmcifData(e,t,s){let i=this.icn3d;i.icn3dui;i.loadCIFCls.loadCIF(e,t,!0,s),Object.keys(i.structures).length>1&&(i.opts.color="structure"),i.opmParserCls.modifyUIMapAssembly(),i.pdbParserCls.addSecondary(s)}}class Jt{constructor(e){this.icn3d=e}async downloadMmdb(e,t){let s,i=this.icn3d,n=i.icn3dui;try{if(s=await this.loadMmdbPrms(e,t),!s||s.error)return void this.getNoData(e,t)}catch(s){return void this.getNoData(e,t)}if(0!=Object.keys(s.atoms).length)if(n.utilsCls.isCalphaPhosOnly(s.atoms)||s.atomCount<=i.maxatomcnt)await this.parseMmdbData(s);else{let s;try{s=await this.loadMmdbPrms(e,t,!0)}catch(s){return void this.getNoData(e,t)}await this.parseMmdbData(s)}else{let e=s.pdbId;await i.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,s=t.icn3dui,i=e.split(",");s.cfg.query_id=i[0],s.cfg.blast_rep_id=i[1];let n=s.cfg.blast_rep_id.split("_")[0];4==n.length?await this.downloadMmdb(n):(t.blastAcxn=s.cfg.blast_rep_id.split(".")[0],await this.downloadRefseq(t.blastAcxn,!0))}async downloadRefseq(e,t){let s=this.icn3d,i=s.icn3dui,n=i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?refseq2uniprot="+e;i.cfg.refseqid=e;let l=await i.getAjaxPromise(n,"jsonp",!1,"The protein accession "+e+" can not be mapped to AlphaFold UniProt ID...");if(!l||!l.uniprot)return void alert("The accession "+e+" can not be mapped to AlphaFold UniProt ID. It will be treated as a UniProt ID instead.");i.cfg.afid=l.uniprot,s.uniprot2acc||(s.uniprot2acc={}),s.uniprot2acc[l.uniprot]=e,t&&(i.cfg.blast_rep_id=i.cfg.afid+"_A");await s.pdbParserCls.downloadPdb(i.cfg.afid,!0)}async downloadProteinname(e){let t=this.icn3d,s=t.icn3dui;s.icn3d.bCid=void 0;let i=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?protein2acc="+e,n=(await s.getAjaxPromise(i,"jsonp")).acc;if(0==n.length)return void(s.bNode||alert("The protein/gene name "+e+" can not be mapped to RefSeq proteins..."));let l=[];for(let e=0,t=n.length;e<t;++e){let t=n[e];i=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?refseq2uniprot="+t;let r=s.getAjaxPromise(i,"jsonp");l.push(r)}let r=Promise.allSettled(l),o=await r;l=[];let a=[];for(let e=0,n=o.length;e<n;++e){let n=o[e].value;if(n&&n.uniprot){let e=n.uniprot;i="https://alphafold.ebi.ac.uk/files/AF-"+e+"-F1-model_"+t.AFUniprotVersion+".pdb",t.ParserUtilsCls.setYourNote(s.cfg.protein+"(NCBI Protein/Gene) in iCn3D");let r=s.getAjaxPromise(i,"text",!0);l.push(r),a.push(e)}}r=Promise.allSettled(l),o=await r;for(let e=0,i=o.length;e<i;++e){let i=o[e].value;if(s.cfg.afid=a[e],i){i="HEADER "+s.cfg.afid+"\n"+i,await t.opmParserCls.parseAtomData(i,s.cfg.afid,void 0,"pdb",void 0);break}}s.cfg.afid||s.bNode||alert("The protein/gene name "+e+" can not be mapped to AlphaFold structures...")}getNoData(e,t){let s=this.icn3d.icn3dui;t?alert("This gi "+e+" has no corresponding 3D structure..."):alert("This mmdbid "+e+" with the parameters "+s.cfg.inpara+" may not have 3D structure data. Please visit the summary page for details: "+s.htmlCls.baseUrl+"pdb/"+e)}async parseMmdbData(e,t,s,i,n,l,r){let o,a=this.icn3d,d=a.icn3dui,c=void 0!==e.pdbId?e.pdbId:e.mmdbId;if(r&&(c=r),this.parseMmdbDataPart1(e,t),void 0===t?(void 0!==e.opm&&void 0!==e.opm.rot&&(a.bOpm=!0,a.opmParserCls.setOpmData(e)),o=a.loadAtomDataCls.loadAtomDataIn(e,c,"mmdbid",void 0,t)):(s&&(c=s.substr(0,s.indexOf("_"))),o=a.loadAtomDataCls.loadAtomDataIn(e,c,"mmdbid",void 0,t,s,i,n,l)),d.cfg.ligand)for(let e in a.chainid2sid)if(a.chainid2sid[e]==d.cfg.ligand.substr(3)){let t=a.firstAtomObjCls.getResiduesFromAtoms(a.chains[e]),s=Object.keys(t)[0].split("_"),i="."+s[1]+":"+s[2];await a.selByCommCls.selectByCommand(i,d.cfg.ligand,d.cfg.ligand);break}a.hAtoms=o;let h=e.pdbId;void 0===t&&a.ParserUtilsCls.setYourNote(h.toUpperCase()+"(MMDB) in iCn3D");for(let t in e.domains){let s=e.domains[t].chain,i=h+"_"+s,n=e.domains[t].domains;for(let e=0,t=n.length;e<t;++e){let t=h+"_"+s+"_3d_domain_"+(e+1).toString();a.tddomains[t]={};let l=n[e].intervals,r={},o={};for(let e=0,s=l.length;e<s;++e){let s=Math.round(l[e][0])-1,n=Math.round(l[e][1])-1;if(!r.hasOwnProperty(s)&&!o.hasOwnProperty(n)){r[s]=1,o[n]=1;for(let e=s;e<=n;++e){let s,n=i+"_"+(e+1).toString();s=a.ncbi2resid[n],s&&(a.tddomains[t][s]=1)}}}}}return a.bAssemblyUseAsu=void 0!==e.asuAtomCount,void 0!==t?a.bAssemblyUseAsu=!1:await a.mmcifParserCls.downloadMmcifSymmetry(c),a.bAssemblyUseAsu&&$("#"+a.pre+"assemblyWrapper").show(),void 0!==a.emd?($("#"+a.pre+"mapWrapper1").hide(),$("#"+a.pre+"mapWrapper2").hide(),$("#"+a.pre+"mapWrapper3").hide()):($("#"+a.pre+"emmapWrapper1").hide(),$("#"+a.pre+"emmapWrapper2").hide(),$("#"+a.pre+"emmapWrapper3").hide()),a.setStyleCls.setAtomStyleByOptions(a.opts),void 0!==d.cfg.blast_rep_id?a.setColorCls.setColorByOptions(a.opts,a.atoms):a.setColorCls.setColorByOptions(a.opts,a.atoms,!0),void 0===t&&(await a.ParserUtilsCls.renderStructure(),void 0!==d.cfg.rotate&&a.resizeCanvasCls.rotStruc(d.cfg.rotate,!0),a.html2ddgm="",d.cfg.show2d&&(d.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),a.bFullUi&&a.ParserUtilsCls.download2Ddgm(a.inputid.toUpperCase()))),void 0!==d.cfg.align&&void 0!==d.cfg.chainalign&&void 0!==d.cfg.mmdbafid||1!=Object.keys(a.structures).length||null!==$("#"+a.pre+"alternateWrapper")&&$("#"+a.pre+"alternateWrapper").hide(),o}parseMmdbDataPart1(e,t){let s=this.icn3d,i=s.icn3dui;if(void 0===e.atoms&&void 0===e.molid2rescount)return alert("invalid MMDB data."),!1;if(void 0===t||"target"===t){let e=!!s.bCommandLoad;s.bStatefile||s.init(e),s.chainsColor={},s.chainsGene={}}"query"===t||(s.interactionData={moleculeInfor:e.moleculeInfor,intrac:e.intrac,intracResidues:e.intracResidues}),"query"===t||(s.mmdb_data=e);let n=void 0!==e.pdbId?e.pdbId:e.mmdbId;"query"===t?s.inputid2=n:s.inputid=n;let l=e.moleculeInfor,r={},o={},a={},d={};for(let e in l){if(0===Object.keys(l[e]).length)continue;let c=void 0===l[e].color?"#CCCCCC":"#"+("000000"+l[e].color.toString(16)).slice(-6),h=void 0===l[e].chain?"":l[e].chain.trim();h=h.replace(/_/g,""),void 0===d[h]?d[h]=1:++d[h];let p=n+"_"+(1===d[h]?h:h+d[h].toString());r[e]=c,o[p]=e,a[e]=p,(void 0===t||i.cfg.mmdbafid)&&(s.chainsColor[p]=i.parasCls.thr(c));let m=void 0===l[e].geneId?"":l[e].geneId,u=void 0===l[e].geneSymbol?"":l[e].geneSymbol,g=void 0===l[e].geneDesc?"":l[e].geneDesc;s.chainsGene[p]={geneId:m,geneSymbol:u,geneDesc:g}}s.molid2chain=a,$("#"+s.pre+"accordion5").show()}loadMmdbPrms(e,t,s){let i,n=this.icn3d,l=n.icn3dui;return i=t?l.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+l.cfg.bu+"&simple=1&gi="+e:l.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+l.cfg.bu+"&simple=1&uid="+e,void 0!==l.cfg.blast_rep_id&&(i+="&bu=0"),void 0!==l.cfg.inpara&&(i+=l.cfg.inpara),s&&(i+="&complexity=2"),void 0===n.chainids2resids&&(n.chainids2resids={}),l.getAjaxPromise(i,"jsonp",!0)}}class Zt{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,s=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(BCIF) in iCn3D");let i="https://models.rcsb.org/"+e+".bcif",n=await s.getXMLHttpRqstPromise(i,"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,s,i){let n=this.icn3d,l=n.icn3dui,r="",o="",a="",d="",c="",h="",p=s?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 m=p.result.dataBlocks[0];t||(m.getCategory("_entry")&&(t=m.getCategory("_entry").getColumn("id").getString(0)),""==t&&(t="stru")),m.getCategory("_citation")&&(o=m.getCategory("_citation").getColumn("pdbx_database_id_PubMed").getString(0)),m.getCategory("_struct")&&(a=m.getCategory("_struct").getColumn("title").getString(0),a=a.replace(/"/,"'")),m.getCategory("_struct_keywords")&&(d=m.getCategory("_struct_keywords").getColumn("pdbx_keywords").getString(0)),m.getCategory("_entity_src_gen")&&(h=m.getCategory("_entity_src_gen").getColumn("gene_src_common_name").getString(0));let u={},g={},f={};if(m.getCategory("_database_2")){let e=m.getCategory("_database_2"),t=e.rowCount;for(let s=0;s<t;++s){let t=e.getColumn("database_id").getString(s),i=e.getColumn("database_code").getString(s);if("EMDB"==t){c=i;break}}}if(m.getCategory("_struct_conf")){let e=m.getCategory("_struct_conf"),t=e.getColumn("conf_type_id"),s=e.getColumn("beg_auth_asym_id"),i=e.getColumn("beg_auth_seq_id"),n=e.getColumn("end_auth_asym_id"),l=e.getColumn("end_auth_seq_id"),r=e.rowCount;for(let e=0;e<r;++e){let r,o=t.getString(e),a=s.getString(e),d=i.getString(e),c=a+"_"+d,h=n.getString(e),p=l.getString(e),m=h+"_"+p;if("HELX"==o.substr(0,4)?(r="helix",u[c]=1,g[m]=1):"STRN"==o.substr(0,4)&&(r="sheet",u[c]=1,g[m]=1),"helix"==r||"sheet"==r)for(let e=parseInt(d);e<=parseInt(p);++e){f[a+"_"+e]=r}}t=s=i=n=l=[]}if(m.getCategory("_struct_sheet_range")){let e=m.getCategory("_struct_sheet_range"),t=e.getColumn("beg_auth_asym_id"),s=e.getColumn("beg_auth_seq_id"),i=e.getColumn("end_auth_asym_id"),n=e.getColumn("end_auth_seq_id"),l=e.rowCount;for(let e=0;e<l;++e){let l=t.getString(e),r=s.getString(e);u[l+"_"+r]=1;let o=i.getString(e),a=n.getString(e);g[o+"_"+a]=1;let d="sheet";for(let e=parseInt(r);e<=parseInt(a);++e){f[l+"_"+e]=d}}t=s=i=n=[]}let C={},b=[],y=[];if(m.getCategory("_struct_conn")){let e=m.getCategory("_struct_conn"),s=e.getColumn("conn_type_id"),i=e.getColumn("ptnr1_auth_asym_id"),n=e.getColumn("ptnr1_label_atom_id"),l=e.getColumn("ptnr1_label_seq_id"),r=e.getColumn("ptnr2_auth_asym_id"),o=e.getColumn("ptnr2_label_atom_id"),a=e.getColumn("ptnr2_label_seq_id"),d=e.rowCount;for(let e=0;e<d;++e){let d=s.getString(e),c=i.getString(e),h=n.getString(e),p=l.getString(e),m=c+"_"+p+"_"+h,u=r.getString(e),g=o.getString(e),f=a.getString(e),C=u+"_"+f+"_"+g;"covale"==d?(b.push(m),b.push(C)):"disulf"==d&&(y.push(t+"_"+c+"_"+p),y.push(t+"_"+u+"_"+f))}s=i=n=l=r=o=a=[]}let v,_,w,S,A,x,k,O,R,I,E,T,P,D,M,F=m.getCategory("_atom_site"),H={},L={id:""},N="",q={},U={},$="",B=F.rowCount,j=1,z=!(10*B>n.maxatomcnt);if(!i){_=F.getColumn("group_PDB"),w=F.getColumn("label_comp_id"),S=F.getColumn("type_symbol"),A=F.getColumn("label_atom_id"),x=F.getColumn("auth_asym_id"),k=F.getColumn("label_seq_id"),O=F.getColumn("auth_seq_id"),R=F.getColumn("label_alt_id"),I=F.getColumn("B_iso_or_equiv"),E=F.getColumn("Cartn_x"),T=F.getColumn("Cartn_y"),P=F.getColumn("Cartn_z"),D=F.getColumn("label_asym_id"),M=F.getColumn("pdbx_PDB_model_num");let e={},t="";for(let s=0;s<B;++s){let i,n=_.getString(s),r=w.getString(s),o=S.getString(s),a=A.getString(s),d=x.getString(s),c=k.getString(s),h=O.getString(s),p=R.getString(s),m=D.getString(s);if(c=h,"ATOM"==n?i=3==r.length?"protein":"nucleotide":"WAT"==r||"HOH"==r?(i="solvent",d="Misc"):(i="ligand",d=r),!z&&("protein"==i&&("C"!=o||"CA"!=a)||"nucleotide"==i&&"P"!=a))continue;if("B"==p)continue;if(U[d]=1,"?"!=c&&"."!=c&&"0"!=c||(c=h),"solvent"==i||"ligand"==i){let s={};e.hasOwnProperty(d)||(e[d]=[]),3!=r.length||"HOH"==r||"WAT"==r?3==r.length&&("O"!=o||"HOH"!=r&&"WAT"!=r)||(s.resi=c,s.name=l.utilsCls.residueName2Abbr(r),e[d].push(s)):d+"_"+r==$&&t==m||(s.resi=c,s.name=l.utilsCls.residueName2Abbr(r),e[d].push(s))}let u=E.getFloat(s),g=T.getFloat(s),f=P.getFloat(s),b=j.toString();H[d+"_"+c+"_"+a]=b;let y={};y.id=b,y.elem=o,y.x=u,y.y=g,y.z=f,y.alt=p,v=d+"_"+c;let I=1.3;if(v!=N||t!=m)q={},q[v]={},q[v][y.id]=y;else{for(let e in q[v])this.hasCovalentBond(y,q[v][e],I)&&(C.hasOwnProperty(y.id)||(C[y.id]={}),C.hasOwnProperty(q[v][e].id)||(C[q[v][e].id]={}),C[y.id][q[v][e].id]=1,C[q[v][e].id][y.id]=1);q[v][y.id]=y}"N"==a&&""!=L.id&&this.hasCovalentBond(y,L,I)&&(C.hasOwnProperty(y.id)||(C[y.id]={}),C.hasOwnProperty(L.id)||(C[L.id]={}),C[y.id][L.id]=1,C[L.id][y.id]=1),"C"==a&&(L=y),N=v,$=d+"_"+r,t=m,++j}for(let e=0;e<b.length;e+=2){let t=H[b[e]],s=H[b[e+1]];C.hasOwnProperty(t)||(C[t]={}),C.hasOwnProperty(s)||(C[s]={}),C[t][s]=1,C[s][t]=1}}if(r+='{"bcif":"'+t+'", '+(""!=c?'"emd":"'+c+'",':"")+(""!=h?'"organism":"'+h+'",':"")+'"pubmedid":"'+o+'", "descr": {"name": "'+a+'", "class": "'+d+'"}',!i){r+=', "atoms":[\n',$="",j=1;let e=t;for(let s=0;s<B;++s){let i=M.getString(s);"1"!=i&&""!=i&&(e=t+i);let n,l=_.getString(s),o=w.getString(s),a=S.getString(s),d=A.getString(s),c=x.getString(s),h=k.getString(s),p=O.getString(s),m=R.getString(s),b=D.getString(s);if(h=p,"ATOM"==l?n=3==o.length?"protein":"nucleotide":"WAT"==o||"HOH"==o?(n="solvent",c="Misc"):(n="ligand",c=o),!z&&("protein"==n&&("C"!=a||"CA"!=d)||"nucleotide"==n&&"P"!=d))continue;if("B"==m)continue;"?"!=h&&"."!=h&&"0"!=h||(h=p);let y=I.getString(s),v=E.getFloat(s),F=T.getFloat(s),H=P.getFloat(s),L=j.toString(),N=c+"_"+h;r+="{",r+='"het":'+("HETATM"==l?"1":"0")+", ",r+='"serial":'+j+", ",r+='"name":"'+d+'", ',r+='"resn":"'+o+'", ',r+='"structure":"'+e+'", ',r+='"chain":"'+c+'", ',r+='"resi":'+h+", ",r+='"coord":{"x":'+v+', "y":'+F+', "z":'+H+"}, ",r+='"b":"'+y+'", ',r+='"elem":"'+a+'", ',r+='"bonds":[';let q={};C.hasOwnProperty(L)&&(q=C[L]);let U=Object.keys(q);for(let e=0,t=U.length;e<t;++e)"undefined"!==U[e]&&(r+=U[e],r+=", ");if(U.length>0&&(r=r.substr(0,r.length-2)),r+="], ",f.hasOwnProperty(N)){r+='"ss":"'+f[N]+'", '}else r+='"ss":"coil", ';u.hasOwnProperty(N)?r+='"ssbegin":1, ':r+='"ssbegin":0, ',g.hasOwnProperty(N)?r+='"ssend":1, ':r+='"ssend":0, ',r+='"mt":"'+n+'"',r+="}",r+=",\n",$=c+"_"+o,prevAutochain=b,++j}j>1&&(r=r.substr(0,r.length-2)),r+="]"}_=w=S=A=x=k=O=R=I=E=T=P=D=[];let G={};if(m.getCategory("_pdbx_poly_seq_scheme")){let e=m.getCategory("_pdbx_poly_seq_scheme"),t=e.getColumn("seq_id"),s=e.getColumn("pdb_seq_num"),i=e.getColumn("mon_id"),n=e.getColumn("pdb_strand_id"),l=e.rowCount,r="",o="";for(let e=0;e<l;++e){t.getString(e);let a=s.getString(e),d=i.getString(e),c=n.getString(e);c!=r&&(0==e||(o=o.substr(0,o.length-2),o+="]",G[r]=o),o="["),o+="["+a+', "'+d+'"]',e<l-1&&(o+=", "),r=c}o+="]",G[r]=o,t=s=i=n=[]}r+=', "sequences":{';let V=!1;for(let e in U){let t;t=ligSeqHash.hasOwnProperty(e)?"["+ligSeqHash[e]+"]":G[e],""!==t&&void 0!==t&&(r+='"'+e+'": '+t+", ",V=!0)}if(V&&(r=r.substr(0,r.length-2)),r+="}",m.getCategory("_pdbx_struct_oper_list")){let e=m.getCategory("_pdbx_struct_oper_list");r+=', "assembly":[';let t=', "pmatrix":',s=!1,i=e.rowCount;for(let n=0;n<i;++n){let l=e.getColumn("id").getString(n);if("X0"==l)continue;let o=e.getColumn("matrix[1][1]").getFloat(n),a=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),m=e.getColumn("matrix[2][3]").getFloat(n),u=e.getColumn("vector[2]").getFloat(n),g="["+o+","+h+","+e.getColumn("matrix[3][1]").getFloat(n)+", 0, "+a+","+p+","+e.getColumn("matrix[3][2]").getFloat(n)+", 0, "+d+","+m+","+e.getColumn("matrix[3][3]").getFloat(n)+", 0, "+c+","+u+","+e.getColumn("vector[3]").getFloat(n)+", 1]";"P"==l?(t+=g,s=!0):(r+=g,n<i-1&&(r+=", "))}r+="]",s&&(r+=t)}if(y.length>0){r+=', "disulfides":[';for(let e=0;e<y.length;e+=2)r+="[",r+='"'+y[e]+'", "'+y[e+1]+'"',r+="]",e<y.length-2&&(r+=", ");r+="]"}return r+="}",r}hasCovalentBond(e,t,s){this.icn3d.icn3dui;let i=this.mElem2Radius[e.elem]+this.mElem2Radius[t.elem],n=e.x-t.x,l=e.y-t.y,r=e.z-t.z;return n*n+l*l+r*r<s*i*i}}class Qt{constructor(e){this.icn3d=e}async loadMol2Data(e){let t=this.icn3d,s=t.icn3dui,i=this.loadMol2AtomData(e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),i?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The Mol2 file has the wrong format...")}loadMol2AtomData(e){let t=this.icn3d;t.icn3dui;let s=e.split(/\r?\n|\r/);if(s.length<4)return!1;t.init();let i,n,l="LIG",r={},o="1_A",a=0,d=0,c=1,h=!1,p=!1,m={},u={};for(let e=0,o=s.length;e<o;++e){let o=s[e].trim();if(""!==o&&"#"!==o.substr(0,1)){if("@<TRIPOS>MOLECULE"==o){t.molTitle=s[e+1].trim();let l=s[e+2].trim().replace(/\s+/g," ").split(" ");i=l[0],n=l[1],e+=4}else"@<TRIPOS>ATOM"==o?(c=1,h=!0,++e):"@<TRIPOS>BOND"==o?(p=!0,h=!1,++e):"@<TRIPOS>SUBSTRUCTURE"==o&&(p=!1,++e);if(o=s[e].trim(),""!==o&&"#"!==o.substr(0,1)){if(h&&a<i){let e=o.replace(/\s+/g," ").split(" "),s=parseInt(e[0]);m[s]=c;let i,n=e[1],d=parseFloat(e[2]),h=parseFloat(e[3]),p=parseFloat(e[4]),g=new THREE.Vector3(d,h,p),f=e[5],C=f.indexOf(".");if(i=-1===C?f:f.substr(0,C),"H"===i&&i===f)u[s]=1;else{let e={het:!0,serial:c,name:n,resn:l,structure:1,chain:"A",resi:1,coord:g,b:0,elem:i,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};t.atoms[c]=e,r[c]=1,++c}++a}if(p&&d<n){let e=o.replace(/\s+/g," ").split(" "),s=parseInt(e[1]),i=parseInt(e[2]),n=e[3],l=n;if("am"===n&&(l="1"),"ar"===n&&(l="1.5"),!(u.hasOwnProperty(s)||u.hasOwnProperty(i)||"1"!==l&&"2"!==l&&"3"!==l&&"1.5"!==l)){let e=l,n=m[s],r=m[i];t.atoms[n].bonds.push(r),t.atoms[n].bondOrder.push(e),t.atoms[r].bonds.push(n),t.atoms[r].bondOrder.push(e),"2"==e?(t.doublebonds[n+"_"+r]=1,t.doublebonds[r+"_"+n]=1):"3"==e?(t.triplebonds[n+"_"+r]=1,t.triplebonds[r+"_"+n]=1):"1.5"==e&&(t.aromaticbonds[n+"_"+r]=1,t.aromaticbonds[r+"_"+n]=1)}++d}}}}t.dAtoms=r,t.hAtoms=r,t.structures[1]=[o],t.chains["1_A"]=r,t.residues["1_A_1"]=r,t.residueId2Name["1_A_1"]=l,void 0===t.chainsSeq["1_A"]&&(t.chainsSeq["1_A"]=[]);let g={resi:1};return g.name=l,t.chainsSeq["1_A"].push(g),t.ParserUtilsCls.setMaxD(),t.saveFileCls.showTitle(),!0}}class es{constructor(e){this.icn3d=e}async downloadOpm(e){let t=this.icn3d,s=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(OPM) in iCn3D"),t.bStopRotate=!0;let i="https://opm-assets.storage.googleapis.com/pdb/"+e.toLowerCase()+".pdb",n=await s.getAjaxPromise(i,"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,s,i,n,l){let r=this.icn3d,o=r.icn3dui;try{t||(t=r.defaultPdbId);let a=o.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&opm&uid="+t.toLowerCase(),d=await o.getAjaxPromise(a,"jsonp",!1);this.setOpmData(d),await this.parseAtomData(e,t,s,i,n,l)}catch(r){await this.parseAtomData(e,t,s,i,n,l)}}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 THREE.Vector3(e.opm.trans1[0],e.opm.trans1[1],e.opm.trans1[2]),t.rmsd_supr.trans2=new THREE.Vector3(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,s,i,n,l){let r=this.icn3d,o=r.icn3dui;"mmcif"===i||"bcif"===i?(r.loadCIFCls.loadCIF(e,t,l),this.modifyUIMapAssembly(),r.setStyleCls.setAtomStyleByOptions(r.opts),r.setColorCls.setColorByOptions(r.opts,r.atoms),await r.ParserUtilsCls.renderStructure(),void 0!==o.cfg.rotate&&r.resizeCanvasCls.rotStruc(o.cfg.rotate,!0)):"pdb"===i?await r.pdbParserCls.loadPdbData(e,t):"align"===i&&(r.bOpm?await r.alignParserCls.downloadAlignmentPart2(t):void 0!==n?await this.loadOpmData(e,n,s,i):await r.alignParserCls.downloadAlignmentPart2(t))}}class ts{constructor(e){this.icn3d=e}async downloadPdb(e,t){let s,i=this.icn3d,n=i.icn3dui;t?(s="https://alphafold.ebi.ac.uk/files/AF-"+e+"-F1-model_"+i.AFUniprotVersion+".pdb",n.cfg.refseqid?i.ParserUtilsCls.setYourNote(n.cfg.refseqid.toUpperCase()+"(NCBI Protein Acc.) in iCn3D"):n.cfg.protein?i.ParserUtilsCls.setYourNote(n.cfg.protein+"(NCBI Protein/Gene) in iCn3D"):i.ParserUtilsCls.setYourNote(e.toUpperCase()+"(AlphaFold) in iCn3D")):(s="https://files.rcsb.org/download/"+e+".pdb",e=e.toUpperCase(),i.ParserUtilsCls.setYourNote(e+"(PDB) in iCn3D"));let l=await n.getAjaxPromise(s,"text",!0,"The ID "+e+" can not be found in the server "+s+"...");if(t){l="HEADER "+e+"\n"+l,await i.opmParserCls.parseAtomData(l,e,void 0,"pdb",void 0)}else await i.opmParserCls.loadOpmData(l,e,void 0,"pdb")}async downloadUrl(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=e.lastIndexOf("/");if(-1!=r){let t=e.lastIndexOf(".");n.filename=e.substr(r+1,t-r-1)}else{let t=e.lastIndexOf(".");n.filename=e.substr(0,t)}let o=await l.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=i?i.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 l.htmlCls.setHtmlCls.loadPng(o,s,!0);else if("pae"===t){l.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,s,i,n,l,r,o){let a=this.icn3d,d=a.icn3dui;if(!i&&(void 0===n||"target"===n)){let e=!!a.bCommandLoad;a.bStatefile||a.init(e)}let c=await a.loadPDBCls.loadPDB(e,t,s,void 0,void 0,i,n,o);return void 0===d.cfg.opmid&&a.ParserUtilsCls.transformToOpmOri(t),void 0!==a.biomtMatrices&&a.biomtMatrices.length>1&&(d.bNode||$("#"+a.pre+"assemblyWrapper").show(),a.asuCnt=a.biomtMatrices.length),d.bNode||(void 0!==a.emd?($("#"+a.pre+"mapWrapper1").hide(),$("#"+a.pre+"mapWrapper2").hide(),$("#"+a.pre+"mapWrapper3").hide()):($("#"+a.pre+"emmapWrapper1").hide(),$("#"+a.pre+"emmapWrapper2").hide(),$("#"+a.pre+"emmapWrapper3").hide())),await this.addSecondary(i,r),c}async addSecondary(e,t){let s=this.icn3d,i=s.icn3dui,n=!1;s.bSecondaryStructure&&1==Object.keys(s.structures).length?n=!1:i.cfg.mmtfid||i.cfg.pdbid||i.cfg.opmid||i.cfg.mmdbid||i.cfg.gi||i.cfg.uniprotid||i.cfg.blast_rep_id||i.cfg.cid||i.cfg.mmcifid||i.cfg.align||i.cfg.chainalign||(n=!0),(!s.bSecondaryStructure||n)&&Object.keys(s.proteins).length>0&&!t?await this.applyCommandDssp(e):(await this.loadPdbDataRender(e),i.bNode||await s.ParserUtilsCls.checkMemProteinAndRotate())}async applyCommandDssp(e){let t=this.icn3d,s=t.icn3dui,i=s.utilsCls.isCalphaPhosOnly(s.hashUtilsCls.hash2Atoms(t.proteins,t.atoms));await t.dsspCls.applyDssp(i,e)}async loadPdbDataRender(e){let t=this.icn3d,s=t.icn3dui;if(void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),(s.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!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0),e&&!s.bNode&&t.definedSetsCls.setModeAndDisplay("all"),t.struct_statefile)for(let e=0,s=t.struct_statefile.length;e<s;++e)await this.execStatefile(t.struct_statefile[e].structure,t.struct_statefile[e].statefile)}async execStatefile(e,t){let s=this.icn3d,i=s.icn3dui;if(!t)return;let n=t.trim().split("\n");n=["select $"+e].concat(n),s.STATENUMBER=n.length,s.CURRENTNUMBER=0;let l=i.hashUtilsCls.cloneHash(s.hAtoms),r=s.commands;s.hAtoms={},s.commands=n,await s.loadScriptCls.execCommands(s.CURRENTNUMBER,s.STATENUMBER-1,s.STATENUMBER,!0),s.hAtoms=i.hashUtilsCls.cloneHash(l),s.commands=r.concat(s.commands)}}class ss{constructor(e){this.icn3d=e}async downloadCid(e){let t=this.icn3d,s=t.icn3dui;t.ParserUtilsCls.setYourNote("PubChem CID "+e+" in iCn3D"),t.bCid=!0;let i="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 s.getAjaxPromise(i,"jsonp",!0,"Can not retrieve the parent CID...")).IdentifierList.CID[0]+"/record/SDF/?record_type=3d&response_type=display",l=await s.getAjaxPromise(n,"text",!0,"This CID may not have 3D structure..."),r=this.loadSdfAtomData(l,e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),r?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The SDF of CID "+e+" has the wrong format...")}async downloadSmiles(e){let t=this.icn3d,s=t.icn3dui,i=s.htmlCls.baseUrl+"openbabel/openbabel.cgi?smiles2pdb="+e,n=await s.getAjaxPromise(i,"text");t.init(),t.bInputfile=!0,t.InputfileType="pdb",t.InputfileData=t.InputfileData?t.InputfileData+"\nENDMDL\n"+n:n,await t.pdbParserCls.loadPdbData(n)}async loadSdfData(e){let t=this.icn3d,s=t.icn3dui,i=this.loadSdfAtomData(e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),i?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The SDF file has the wrong format...")}loadSdfAtomData(e,t){let s=this.icn3d;s.icn3dui;let i=e.split(/\r?\n|\r/);if(i.length<4)return!1;s.init();let n=t||1,l="LIG",r=n,o=n+"_A",a=o+"_1",d=parseInt(i[3].substr(0,3));if(isNaN(d)||d<=0)return!1;let c=parseInt(i[3].substr(3,3)),h=4;if(i.length<h+d+c)return!1;let p,m,u=d,g={},f={},C={},b=1;for(p=0;p<u;p++){m=i[h],h++;let e=m.substr(31,3).trim(),t=parseFloat(m.substr(0,10)),r=parseFloat(m.substr(10,10)),o=parseFloat(m.substr(20,10)),a={het:!0,serial:b,name:e,resn:l,structure:n,chain:"A",resi:1,coord:new THREE.Vector3(t,r,o),b:0,elem:e,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};s.atoms[b]=a,C[b]=1,g[p]=b,++b,"H"==e&&(f[p]=1)}s.dAtoms=C,s.hAtoms=C,s.structures[r]=[o],s.chains[o]=C,s.residues[a]=C,s.residueId2Name[a]=l,void 0===s.chainsSeq[o]&&(s.chainsSeq[o]=[]);let y={resi:1};for(y.name=l,s.chainsSeq[o].push(y),p=0;p<c;p++){m=i[h],h++;let e=parseInt(m.substr(0,3))-1+0,t=parseInt(m.substr(3,3))-1+0,n=m.substr(6,3).trim(),l=g[e],r=g[t];s.atoms[l].bonds.push(r),s.atoms[l].bondOrder.push(n),s.atoms[r].bonds.push(l),s.atoms[r].bondOrder.push(n),f.hasOwnProperty(e)||f.hasOwnProperty(t)||("2"==n?(s.doublebonds[l+"_"+r]=1,s.doublebonds[r+"_"+l]=1):"3"==n&&(s.triplebonds[l+"_"+r]=1,s.triplebonds[r+"_"+l]=1))}let v=!1;for(let e=i.length;h<e;++h)if(-1!=i[h].indexOf("PARTIAL_CHARGES")){v=!0;break}if(v){++h;let e=parseInt(i[h]);for(++h,p=0;p<e;++p,++h){m=i[h];let e=m.split(" "),t=parseInt(e[0]),n=parseFloat(e[1]);s.atoms[t].crg=n}}for(p in s.atoms)"H"!==s.atoms[p].name&&(s.atoms[p].bonds2=s.atoms[p].bonds.concat(),s.atoms[p].bondOrder2=s.atoms[p].bondOrder.concat());return s.ParserUtilsCls.setMaxD(),s.saveFileCls.showTitle(),!0}}class is{constructor(e){this.icn3d=e}async loadXyzData(e){let t=this.icn3d,s=t.icn3dui,i=this.loadXyzAtomData(e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),i?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The XYZ file has the wrong format...")}setXyzAtomSeq(e,t,s,i){let n=this.icn3d,l=n.icn3dui;n.dAtoms=l.hashUtilsCls.unionHash(n.dAtoms,e),n.hAtoms=l.hashUtilsCls.unionHash(n.hAtoms,e),n.structures[t]=[s],n.chains[s]=e,n.residues[i]=e,n.residueId2Name[i]="LIG",void 0===n.chainsSeq[s]&&(n.chainsSeq[s]=[]);let r={resi:1,name:"LIG"};n.chainsSeq[s].push(r);let o=Object.keys(e);for(let e=0,t=o.length;e<t;++e){let t=n.atoms[o[e]];for(let s=e+1,i=o.length;s<i;++s){let i=n.atoms[o[s]],r=1.2*(l.parasCls.covalentRadii[t.elem.toUpperCase()]+l.parasCls.covalentRadii[i.elem.toUpperCase()]);Math.abs(t.coord.x-i.coord.x)>r||(Math.abs(t.coord.y-i.coord.y)>r||Math.abs(t.coord.z-i.coord.z)>r||l.utilsCls.hasCovalentBond(t,i)&&(n.atoms[o[e]].bonds.push(o[s]),n.atoms[o[s]].bonds.push(o[e])))}}}loadXyzAtomData(e){let t=this.icn3d;t.icn3dui;let s=e.split(/\r?\n|\r/);if(s.length<3)return!1;t.init();let i,n,l,r={},o=0,a=1;t.molTitle="";for(let e=0,d=s.length;e<d;++e){let d=s[e].trim();if(""===d)continue;if(""===d||isNaN(d)||(0!==e&&this.setXyzAtomSeq(r,o,i,n),++o,r={},l=o,i=l+"_A",n=i+"_1",o>1&&(t.molTitle+="; "),t.molTitle+=s[e+1].trim(),e+=2),d=s[e].trim(),""===d)continue;let c=d.replace(/,/," ").replace(/\s+/g," ").split(" "),h=c[0],p=parseFloat(c[1]),m=parseFloat(c[2]),u=parseFloat(c[3]),g={het:!0,serial:a,name:h,resn:"LIG",structure:l,chain:"A",resi:1,coord:new THREE.Vector3(p,m,u),b:0,elem:h,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};t.atoms[a]=g,r[a]=1,++a}return this.setXyzAtomSeq(r,o,i,n),t.ParserUtilsCls.setMaxD(),t.saveFileCls.showTitle(),!0}}class ns{constructor(e){this.icn3d=e}realign(){let e=this.icn3d,t=e.icn3dui;e.selectionCls.saveSelectionPrep();let s="alseq_"+(Object.keys(e.defNames2Atoms).length+Object.keys(e.defNames2Residues).length+1);e.selectionCls.saveSelection(s,s),t.htmlCls.clickMenuCls.setLogCmd("realign",!0);let i={},n={};e.realignResid={};let l="";for(let s in e.hAtoms){let r=e.atoms[s],o=r.structure+"_"+r.chain;if(e.proteins.hasOwnProperty(s)&&"CA"==r.name||e.nucleotides.hasOwnProperty(s)&&("O3'"==r.name||"O3*"==r.name)){if(r.structure+"_"+r.resi==l)continue;i.hasOwnProperty(r.structure)||(i[r.structure]=[]),i[r.structure].push(r.coord.clone()),e.realignResid.hasOwnProperty(o)||(e.realignResid[o]=[]),e.realignResid[o].push({resid:o+"_"+r.resi,resn:t.utilsCls.residueName2Abbr(r.resn.substr(0,3)).substr(0,1)}),n[r.structure]=r.structure+"_"+r.chain,l=r.structure+"_"+r.resi}}let r=Object.keys(i),o=r[0],a=[];e.qt_start_end=[],a.push(n[o]);for(let t=1,s=r.length;t<s;++t){let s=r[t],l=i[s],d=i[o],c=!0;e.ParserUtilsCls.alignCoords(l,d,s,c,n[o],n[s]),a.push(n[s])}e.hAtoms=e.chainalignParserCls.setMsa(a),s="protein_aligned",e.selectionCls.saveSelection(s,s),e.transformCls.zoominSelection(),e.hlUpdateCls.updateHlAll()}async parseChainRealignPredefined(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=e[0].substr(0,e[0].indexOf("_")),a={};l.realignResid={},l.opts.color="grey",l.setColorCls.setColorByOptions(l.opts,l.dAtoms),l.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("_")),m=h+e[c+1].substr(e[c+1].indexOf("_"));d[p]=1,d[m]=1,e[0]=p,e[c+1]=m;let u=p+","+m;if(!t[u])continue;let g=t[u][o],f=t[u][h],C=s[u][o],b=s[u][h],y=i[u][o],v=i[u][h];l.realignResid[p]=[],l.realignResid[m]=[];for(let e=0,t=g.length;e<t;++e)l.realignResid[p].push({resid:y[e],resn:g[e]}),l.realignResid[m].push({resid:v[e],resn:f[e]});let _=!0,w=l.ParserUtilsCls.alignCoords(b,C,h,void 0,p,m,c+1,_);a=r.hashUtilsCls.unionHash(a,w.hAtoms),n=parseFloat(w.rmsd)}if(!r.cfg.usepdbnum&&r.cfg.resdef&&n>5){console.log("RMSD from VAST is larger than 5. Realign the chains with TM-align.");let e=Object.keys(d);e.length>0&&(l.hAtoms=l.definedSetsCls.getAtomsFromNameArray(e)),r.cfg.aligntool="tmalign",await l.realignParserCls.realignOnStructAlign()}else l.hAtoms=l.chainalignParserCls.setMsa(e),l.transformCls.zoominSelection(),await l.chainalignParserCls.downloadChainalignmentPart3(void 0,e,l.hAtoms)}async parseChainRealignData(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui,d=s[0].substr(0,s[0].indexOf("_"));r||(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=s[t+1].substr(0,s[t+1].indexOf("_"));r||(p=p.toUpperCase());let m=d+s[0].substr(s[0].indexOf("_")),u=p+s[t+1].substr(s[t+1].indexOf("_"));s[0]=m,s[t+1]=u;let g,f,C=i[m],b=i[u],y=n[m],v=n[u],_=l[m],w=l[u];if(void 0!==h.data){g=h.data[0].query;let e=Object.keys(h.data[0].targets)[0];f=h.data[0].targets[e],f=f.hsps[0]}if(void 0!==g&&void 0!==f){let e=[],s=[],i="",n="";o.realignResid[m]=[],o.realignResid[u]=[];let l=f.segs;for(let t=0,r=l.length;t<r;++t){let r=l[t],a="",d="";for(let t=0;t<=r.orito-r.orifrom;++t){let l=_[t+r.orifrom].substr(0,_[t+r.orifrom].lastIndexOf("_")),c=w[t+r.from].substr(0,w[t+r.from].lastIndexOf("_"));y[t+r.orifrom]&&v[t+r.from]&&(e.push(y[t+r.orifrom]),s.push(v[t+r.from]),i+=C[t+r.orifrom],n+=b[t+r.from],(0==t||a==l&&d==c||a!=l&&d!=c)&&(o.realignResid[m].push({resid:_[t+r.orifrom],resn:C[t+r.orifrom]}),o.realignResid[u].push({resid:w[t+r.from],resn:b[t+r.from]})),a=l,d=c)}}let r,h=!0;r=o.bAfMem?o.ParserUtilsCls.alignCoords(s,e,d,void 0,m,u,t+1,h):o.ParserUtilsCls.alignCoords(s,e,p,void 0,m,u,t+1,h),c=a.hashUtilsCls.unionHash(c,r.hAtoms)}else void 0!==p||a.cfg.command?C&&b&&((C.length<6||b.length<6)&&!a.cfg.command?o.bRender&&alert("These sequences are too short for alignment"):C.length>=6&&b.length>=6&&!a.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(r){o.hAtoms=o.chainalignParserCls.setMsa(s);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=a.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 THREE.Vector3(1,0,0),t=-.5*Math.PI;o.transformCls.setRotation(e,t)}}else o.hAtoms=o.chainalignParserCls.setMsa(s),o.transformCls.zoominSelection(),await o.chainalignParserCls.downloadChainalignmentPart3(t,s,o.hAtoms)}async realignOnSeqAlign(e){let t=this.icn3d;t.icn3dui;let s=t.firstAtomObjCls.getChainsFromAtoms(t.hAtoms),i=Object.keys(s),n=[],l="";for(let e=0,t=i.length;e<t;++e)i[e]!=l&&n.push(i[e]),l=i[e];t.qt_start_end=[],await this.realignChainOnSeqAlign(void 0,n,!0)}async realignOnStructAlign(e){let t=this.icn3d,s=t.icn3dui,i="tmalign"!=s.cfg.aligntool?3:0,n={};for(let e in t.structures){n[e]={};let l=t.structures[e];for(let r=0,o=l.length;r<o;++r){let o=l[r],a=s.hashUtilsCls.intHash(t.hAtoms,t.chains[o]),d=0;for(let s in a)if(t.atoms[s].ssbegin&&++d,d>i){n[e][o]=a;break}}}let l=[],r=[],o=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",a=s.htmlCls.baseUrl+"tmalign/tmalign.cgi",d=Object.keys(n);e&&(d=d.reverse());for(let e=0,i=d.length;e<i;++e){let i=d[e],c=Object.keys(n[i]);if(0!=c.length)for(let h=0,p=c.length;h<p;++h){let p=c[h],m=t.domain3dCls.getDomainJsonForAlign(n[i][p]);for(let c=e+1,h=d.length;c<h;++c){let e=d[c],h=Object.keys(n[e]);if(0!=h.length)for(let d=0,c=h.length;d<c;++d){let c,u=h[d];if("tmalign"!=s.cfg.aligntool){let i={domains1:t.domain3dCls.getDomainJsonForAlign(n[e][u]),domains2:m};c=s.getAjaxPostPromise(o,i)}else{let l=t.saveFileCls.getAtomPDB(n[i][p],void 0,void 0,void 0,void 0,i),r={pdb_query:t.saveFileCls.getAtomPDB(n[e][u],void 0,void 0,void 0,void 0,e),pdb_target:l};c=s.getAjaxPostPromise(a,r)}l.push(c),r.push(p+","+u)}}}}let c=Promise.allSettled(l),h=await c;t.qt_start_end=[],await t.chainalignParserCls.downloadChainalignmentPart2bRealign(h,r,e)}async realignOnStructAlignMsa(e){let t=this.icn3d,s=t.icn3dui,i="tmalign"!=s.cfg.aligntool?3:0,n={};for(let l=0,r=e.length;l<r;++l){let r=e[l],o=s.hashUtilsCls.intHash(t.hAtoms,t.chains[r]),a=0;for(let e in o)if(t.atoms[e].ssbegin&&++a,a>i){n[r]=o;break}}let l=[],r=[],o=[],a=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",d=s.htmlCls.baseUrl+"tmalign/tmalign.cgi",c=e[0],h=c.substr(0,c.indexOf("_")),p=t.domain3dCls.getDomainJsonForAlign(n[c]);for(let i=1,m=e.length;i<m;++i){let m,u=e[i],g=u.substr(0,u.indexOf("_"));if("tmalign"!=s.cfg.aligntool){let e={domains1:t.domain3dCls.getDomainJsonForAlign(n[u]),domains2:p};m=s.getAjaxPostPromise(a,e)}else{let e=t.saveFileCls.getAtomPDB(t.chains[c],void 0,void 0,void 0,void 0,h),i={pdb_query:t.saveFileCls.getAtomPDB(t.chains[u],void 0,void 0,void 0,void 0,g),pdb_target:e};m=s.getAjaxPostPromise(d,i)}l.push(m),r.push(i-1),o.push(g)}let m=Promise.allSettled(l),u=await m;t.t_trans_add=[],t.q_trans_sub=[],"tmalign"==s.cfg.aligntool&&(t.q_trans_add=[]),t.q_rotation=[],t.qt_start_end=[],await t.chainalignParserCls.downloadChainalignmentPart2b(void 0,e,void 0,u,r,h,o)}async realignChainOnSeqAlign(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=this;l.cfg.aligntool="seqalign";let o,a,d,c,h,p,m={},u={},g={},f=[],C=l.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=chainalign";if(i&&(d=l.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,y=t.length;e<y;++e){let y=t[e].indexOf("_"),v=t[e].substr(0,y);0==e&&(o=v);let _=v+t[e].substr(y);if(0==e&&(a=_),n.chainsSeq&&n.chainsSeq[_])if(m.hasOwnProperty(_)||i||(m[_]="",u[_]=[],g[_]=[]),i)if(0==e);else{let t={};c=d[e-1].split(" | ");let s=a+","+_;m[s]||(m[s]={}),u[s]||(u[s]={}),g[s]||(g[s]={}),p=c[0].split(","),h=r.getSeqCoorResid(p,a),t=l.hashUtilsCls.unionHash(t,h.hAtoms),m[s][o]||(m[s][o]=""),u[s][o]||(u[s][o]=[]),g[s][o]||(g[s][o]=[]),m[s][o]+=h.seq,u[s][o]=u[s][o].concat(h.coor),g[s][o]=g[s][o].concat(h.resid),p=c[1].split(","),h=r.getSeqCoorResid(p,_),t=l.hashUtilsCls.unionHash(t,h.hAtoms),m[s][v]||(m[s][v]=""),u[s][v]||(u[s][v]=[]),g[s][v]||(g[s][v]=[]),m[s][v]+=h.seq,u[s][v]=u[s][v].concat(h.coor),g[s][v]=g[s][v].concat(h.resid)}else if(0==e){if(p=[],s){let e=n.firstAtomObjCls.getResiduesFromAtoms(n.hAtoms);for(var b in e){let e=b.substr(b.lastIndexOf("_")+1);b.substr(0,b.lastIndexOf("_"))==_&&p.push(e)}}else l.cfg.resnum&&(p=l.cfg.resnum.split(","));h=r.getSeqCoorResid(p,_),m[_]+=h.seq,u[_]=u[_].concat(h.coor),g[_]=g[_].concat(h.resid)}else{let e=!1;if(s){let t=n.firstAtomObjCls.getResiduesFromAtoms(n.hAtoms);for(var b in t){if(b.substr(0,b.lastIndexOf("_"))==_){e=!0;let t=n.firstAtomObjCls.getFirstAtomObj(n.residues[b]).resn;m[_]+=l.utilsCls.residueName2Abbr(t),u[_]=u[_].concat(this.getResCoorArray(b)),g[_].push(b)}}}if(!e)for(let e=0,t=n.chainsSeq[_].length;e<t;++e){m[_]+=n.chainsSeq[_][e].name;let t=_+"_"+n.chainsSeq[_][e].resi;u[_]=u[_].concat(this.getResCoorArray(t)),g[_].push(t)}let t={targets:m[a],queries:m[_]},i=l.getAjaxPostPromise(C,t);f.push(i)}}if(i)await r.parseChainRealignPredefined(t,m,u,g);else{let i=Promise.allSettled(f);try{let n=await i;await r.parseChainRealignData(n,e,t,m,u,g,s)}catch(e){return void alert("The realignment did not work...")}}}}getSeqCoorResid(e,t,s){let i=this.icn3d,n=i.icn3dui,l="",r=[],o=[],a={};for(let a=0,d=e.length;a<d;++a)if(-1!=e[a].indexOf("-")){let d=e[a].split("-");for(let e=parseInt(d[0]);e<=parseInt(d[1]);++e){let a=s?e:i.setSeqAlignCls.getPosFromResi(t,e);i.chainsSeq[t]&&i.chainsSeq[t][a]&&-1!=n.parasCls.b62ResArray.indexOf(i.chainsSeq[t][a].name.toUpperCase())&&(l+=i.chainsSeq[t][a].name.toUpperCase(),r=r.concat(this.getResCoorArray(t+"_"+e)),o.push(t+"_"+e))}}else if(0==e[a]){let e=i.firstAtomObjCls.getResiduesFromAtoms(i.chains[t]);o=Object.keys(e)}else{let n=e[a],d=s?n:i.setSeqAlignCls.getPosFromResi(t,n);if(!i.chainsSeq[t][d])continue;let c=this.getResCoorArray(t+"_"+n);l+=i.chainsSeq[t][d].name.toUpperCase(),r=r.concat(c),o.push(t+"_"+n)}for(let e=0,t=o.length;e<t;++e)a=n.hashUtilsCls.unionHash(a,i.residues[o[e]]);return{seq:l,coor:r,resid:o,hAtoms:a}}getResCoorArray(e){let t=this.icn3d;t.icn3dui;let s=[],i=!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){s.push(e.coord.clone()),i=!0;break}}return i||s.push(void 0),s}}class ls{constructor(e){this.icn3d=e}async densityCifParser(e,t,s,i,n){let l,r=this.icn3d,o=r.icn3dui,a=this,d=o.utilsCls.isMobile()||o.cfg.notebook?0:4;if("2fofc"==t||"fofc"==t?(d=0,l="https://www.ebi.ac.uk/pdbe/densities/x-ray/"+e.toLowerCase()+"/cell?detail="+d):"em"==t&&(l="https://www.ebi.ac.uk/pdbe/densities/emd/"+i.toLowerCase()+"/cell?detail="+d),"2fofc"==t&&r.bAjax2fofc)r.mapData.sigma2=s,r.setOptionCls.setOption("map",t);else if("fofc"==t&&r.bAjaxfofc)r.mapData.sigma=s,r.setOptionCls.setOption("map",t);else if("em"==t&&r.bAjaxEm)r.mapData.sigmaEm=s,r.setOptionCls.setOption("emmap",t);else{let e=await o.getXMLHttpRqstPromise(l,"GET","arraybuffer",t);a.parseChannels(e,t,s),"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))}}async densityCifParserBase(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=this;if("2fofc"==t&&l.bAjax2fofc)l.mapData.sigma2=s,l.setOptionCls.setOption("map",t);else if("fofc"==t&&l.bAjaxfofc)l.mapData.sigma=s,l.setOptionCls.setOption("map",t);else{let i=await r.getXMLHttpRqstPromise(e,"GET","arraybuffer",t);o.parseChannels(i,t,s),"2fofc"==t||"fofc"==t?(l.bAjax2fofc=!0,l.bAjaxfofc=!0,l.setOptionCls.setOption("map",t)):"em"==t&&(l.bAjaxEm=!0,l.setOptionCls.setOption("emmap",t))}}parseChannels(e,t,s){let i=this.icn3d;i.icn3dui;let n=this.BinaryParse(e);if("2fofc"==t||"fofc"==t){let e=this.getChannel(n,"2FO-FC"),l=this.getChannel(n,"FO-FC"),r=e,o=r.box.sampleCount,a={xExtent:o[0],yExtent:o[1],zExtent:o[2],mean:r.valuesInfo.mean,sigma:r.valuesInfo.sigma};i.mapData.header2=a,i.mapData.data2=r.data;for(let e=0;e<r.data.length;++e)r.data[e];let d=r.box.origin,c=r.box.dimensions,h=r.spacegroup.basis,p=(new THREE.Matrix4).makeScale(c[0]/o[0],c[1]/o[1],c[2]/o[2]),m=(new THREE.Matrix4).makeTranslation(d[0],d[1],d[2]),u=(new THREE.Matrix4).set(h.x[0],h.y[0],h.z[0],0,0,h.y[1],h.z[1],0,0,0,h.z[2],0,0,0,0,1),g=u.multiply(m).multiply(p);i.mapData.matrix2=g,i.mapData.type2=t,i.mapData.sigma2=s,r=l,o=r.box.sampleCount,a={xExtent:o[0],yExtent:o[1],zExtent:o[2],mean:r.valuesInfo.mean,sigma:r.valuesInfo.sigma},i.mapData.header=a,i.mapData.data=r.data,d=r.box.origin,c=r.box.dimensions,h=r.spacegroup.basis,p=(new THREE.Matrix4).makeScale(c[0]/o[0],c[1]/o[1],c[2]/o[2]),m=(new THREE.Matrix4).makeTranslation(d[0],d[1],d[2]),u=(new THREE.Matrix4).set(h.x[0],h.y[0],h.z[0],0,0,h.y[1],h.z[1],0,0,0,h.z[2],0,0,0,0,1),g=u.multiply(m).multiply(p),i.mapData.matrix=g,i.mapData.type=t,i.mapData.sigma=s}else if("em"==t){let e=this.getChannel(n,"EM"),l=e.box.sampleCount,r={xExtent:l[0],yExtent:l[1],zExtent:l[2],max:e.valuesInfo.max,min:e.valuesInfo.min};i.mapData.headerEm=r,i.mapData.dataEm=e.data;let o=e.box.origin,a=e.box.dimensions,d=e.spacegroup.basis,c=(new THREE.Matrix4).makeScale(a[0]/l[0],a[1]/l[1],a[2]/l[2]),h=(new THREE.Matrix4).makeTranslation(o[0],o[1],o[2]),p=(new THREE.Matrix4).set(d.x[0],d.y[0],d.z[0],0,0,d.y[1],d.z[1],0,0,0,d.z[2],0,0,0,0,1).multiply(h).multiply(c);i.mapData.matrixEm=p,i.mapData.typeEm=t,i.mapData.sigmaEm=s}}getChannel(e,t){this.icn3d.icn3dui;let s,i=e.toJSON();for(let n=0,l=i.length;n<l;++n)i[n].id==t&&(s=e.dataBlocks[n]);return this.CIFParse(s)}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 s(e){let s=[0,0,0];for(let i=0;i<3;i++)s[i]=t.getColumn(e+"["+i+"]").getFloat(0);return s}function i(e){return t.getColumn(e).getFloat(0)}let n={name:t.getColumn("name").getString(0),axisOrder:s("axis_order"),origin:s("origin"),dimensions:s("dimensions"),sampleCount:s("sample_count"),spacegroupNumber:0|i("spacegroup_number"),cellSize:s("spacegroup_cell_size"),cellAngles:s("spacegroup_cell_angles"),mean:i("mean_sampled"),sigma:i("sigma_sampled")},l=[0,0,0];function r(e){return[e[l[0]],e[l[1]],e[l[2]]]}l[n.axisOrder[0]]=0,l[n.axisOrder[1]]=1,l[n.axisOrder[2]]=2;let o=r(n.sampleCount),a=function(e,t,s,i){let n=new Float32Array(t[0]*t[1]*t[2]),l=[0,0,0],r=i[0],o=i[1],a=i[2],d=s[0],c=s[1],h=s[2];t[0],t[0],t[1];let p=t[2],m=t[1]*t[2],u=0,g=e.getFloat(0),f=g;for(let t=0;t<h;t++){l[2]=t;for(let t=0;t<c;t++){l[1]=t;for(let t=0;t<d;t++){l[0]=t;let s=e.getFloat(u);u+=1,n[l[a]+l[o]*p+l[r]*m]=s,s<g?g=s:s>f&&(f=s)}}}return{data:n,min:g,max:f}}(e.getCategory("_volume_data_3d").getColumn("values"),o,n.sampleCount,l);return{name:n.name,spacegroup:function(e,t,s){let i=Math.PI/180*s[0],n=Math.PI/180*s[1],l=Math.PI/180*s[2],r=t[0],o=t[1],a=t[2],d=Math.cos(n),c=(Math.cos(i)-Math.cos(n)*Math.cos(l))/Math.sin(l),h=Math.sqrt(1-d*d-c*c);return{number:e,size:t,angles:s,basis:{x:[r,0,0],y:[Math.cos(l)*o,Math.sin(l)*o,0],z:[d*a,c*a,h*a]}}}(n.spacegroupNumber,n.cellSize,n.cellAngles),box:{origin:r(n.origin),dimensions:r(n.dimensions),sampleCount:o},data:a.data,valuesInfo:{min:a.min,max:a.max,mean:n.mean,sigma:n.sigma}}}BinaryParse(e){this.icn3d.icn3dui;let t=new Uint8Array(e),s=this.MessagePackParse({buffer:t,offset:0,dataView:new DataView(t.buffer)}),i=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 s=t[e];this.categoryMap.set(s.name,s)}}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,s=e.columns;t<s.length;t++){let e=s[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 s=this.encodedColumns.get(e);return s?p(s):t},e.prototype.toJSON=function(){let e=this,t=[],s=this.columnNameList.map((function(t){return{name:t,column:e.getColumn(t)}}));for(let e=0;e<this.rowCount;e++){let i={};for(let t=0,n=s;t<n.length;t++){let s=n[t],l=s.column.getValuePresence(e);i[s.name]=0===l?s.column.getString(e):1===l?".":"?"}t[e]=i}return{name:this.name,columns:this.columnNames,rows:t}},e}();function l(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 r(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),s=new Uint16Array(e);return t[0]=170,t[1]=187,48042===s[0]}();function a(e,t,s){return new s(o?e.buffer:function(e,t){let s=new ArrayBuffer(e.length),i=new Uint8Array(s);for(let s=0,n=e.length;s<n;s+=t)for(let n=0;n<t;n++)i[s+t-n-1]=e[s+n];return s}(e,t))}function d(e,t){return t.isUnsigned?function(e,t){let s=1===t.byteCount?255:65535,i=e.length,n=new Int32Array(t.srcSize),l=0,r=0;for(;l<i;){let t=0,i=e[l];for(;i===s;)t+=i,l++,i=e[l];t+=i,n[r]=t,l++,r++}return n}(e,t):function(e,t){let s=1===t.byteCount?127:32767,i=-s-1,n=e.length,l=new Int32Array(t.srcSize),r=0,o=0;for(;r<n;){let t=0,n=e[r];for(;n===s||n===i;)t+=n,r++,n=e[r];t+=n,l[o]=t,r++,o++}return l}(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 a(e,2,Int16Array)}(e);case 5:return function(e){return a(e,2,Uint16Array)}(e);case 3:return function(e){return a(e,4,Int32Array)}(e);case 6:return function(e){return a(e,4,Uint32Array)}(e);case 32:return function(e){return a(e,4,Float32Array)}(e);case 33:return function(e){return a(e,8,Float64Array)}(e);default:throw new Error("Unsupported ByteArray type.")}case"FixedPoint":return function(e,t){let s=e.length,i=r(t.srcType,s),n=1/t.factor;for(let t=0;t<s;t++)i[t]=n*e[t];return i}(e,t);case"IntervalQuantization":return function(e,t){let s=e.length,i=r(t.srcType,s),n=(t.max-t.min)/(t.numSteps-1),l=t.min;for(let t=0;t<s;t++)i[t]=l+n*e[t];return i}(e,t);case"RunLength":return function(e,t){let s=l(t.srcType,t.srcSize),i=0;for(let t=0,n=e.length;t<n;t+=2){let n=e[t],l=e[t+1];for(let e=0;e<l;++e)s[i++]=n}return s}(e,t);case"Delta":return function(e,t){let s=e.length,i=l(t.srcType,s);if(!s)return i;i[0]=e[0]+(0|t.origin);for(let t=1;t<s;++t)i[t]=e[t]+i[t-1];return i}(e,t);case"IntegerPacking":return d(e,t);case"StringArray":return function(e,t){let s=t.stringData,i=h({encoding:t.offsetEncoding,data:t.offsets}),n=h({encoding:t.dataEncoding,data:e}),l=Object.create(null),r=new Array(n.length),o=0;for(let e=0,t=n;e<t.length;e++){let n=t[e];if(n<0){r[o++]=null;continue}let a=l[n];void 0===a&&(a=s.substring(i[n],i[n+1]),l[n]=a),r[o++]=a}return r}(e,t)}}function h(e){let t=e.data;for(let s=e.encoding.length-1;s>=0;s--)t=c(t,e.encoding[s]);return t}function p(e){if(!e.data.data)return _UndefinedColumn;let t,s=h(e.data);return e.mask&&(t=h(e.mask)),s.buffer&&s.byteLength&&s.BYTES_PER_ELEMENT?t?new f(s,t):new g(s):t?new b(s,t):new C(s)}function m(e,t,s){let i=0,n=1;for(45===e.charCodeAt(t)&&(n=-1,t++);t<s;t++){let s=e.charCodeAt(t)-48;if(s>9||s<0)return n*i|0;i=10*i+s|0}return n*i}function u(e,t,s){let i=1,n=0,l=0,r=1;for(45===e.charCodeAt(t)&&(i=-1,++t);t<s;){let o=e.charCodeAt(t)-48;if(!(o>=0&&o<10)){if(-2===o){for(++t;t<s;){if(o=e.charCodeAt(t)-48,!(o>=0&&o<10))return 53===o||21===o?parseScientific(i*(n+l/r),e,t+1,s):i*(n+l/r);l=10*l+o,r*=10,++t}return i*(n+l/r)}if(53===o||21===o)return parseScientific(i*n,e,t+1,s);break}n=10*n+o,++t}return i*n}let g=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]===u(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}(),f=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]===u(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}(),C=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 m(t,0,t.length)},e.prototype.getFloat=function(e){let t=this.data[e];return u(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}(),b=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 m(t||"",0,(t||"").length)},e.prototype.getFloat=function(e){if(0!==this.mask[e])return 0;let t=this.data[e];return u(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}(),y=function(){function e(e){this.dataBlocks=e.dataBlocks.map((function(e){return new i(e)}))}return e.prototype.toJSON=function(){return this.dataBlocks.map((function(e){return e.toJSON()}))},e}();return new y(s)}MessagePackParse(e){this.icn3d.icn3dui;let t=this;function s(e,s){let i={};for(let n=0;n<s;n++){i[t.MessagePackParse(e)]=t.MessagePackParse(e)}return i}function i(e,t){let s=new Uint8Array(t),i=e.offset;for(let n=0;n<t;n++)s[n]=e.buffer[n+i];return e.offset+=t,s}function n(e,s){let i=new Array(s);for(let n=0;n<s;n++)i[n]=t.MessagePackParse(e);return i}function l(e,t){let s=function(e,t,s){let i,n=r,l=[],o=512,a=0;for(let r=t,d=t+s;r<d;r++){let t=e[r];0==(128&t)?l[a++]=n[t]:192==(224&t)?l[a++]=n[(15&t)<<6|63&e[++r]]:224==(240&t)?l[a++]=String.fromCharCode((15&t)<<12|(63&e[++r])<<6|(63&e[++r])<<0):240==(248&t)?l[a++]=String.fromCharCode((7&t)<<18|(63&e[++r])<<12|(63&e[++r])<<6|(63&e[++r])<<0):throwError("Invalid byte "+t.toString(16)),a===o&&(i=i||[],i[i.length]=l.join(""),a=0)}if(!i)return l.slice(0,a).join("");a>0&&(i[i.length]=l.slice(0,a).join(""));return i.join("")}(e.buffer,e.offset,t);return e.offset+=t,s}let r=function(){let e=[];for(let t=0;t<1024;t++)e[t]=String.fromCharCode(t);return e}();let o,a,d=e.buffer[e.offset];if(0==(128&d))return e.offset++,d;if(128==(240&d))return a=15&d,e.offset++,s(e,a);if(144==(240&d))return a=15&d,e.offset++,n(e,a);if(160==(224&d))return a=31&d,e.offset++,l(e,a);if(224==(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 a=e.dataView.getUint8(e.offset+1),e.offset+=2,i(e,a);case 197:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,i(e,a);case 198:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,i(e,a);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 a=e.dataView.getUint8(e.offset+1),e.offset+=2,l(e,a);case 218:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,l(e,a);case 219:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,l(e,a);case 220:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,n(e,a);case 221:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,n(e,a);case 222:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,s(e,a);case 223:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,s(e,a)}}}class rs{constructor(e){this.icn3d=e}alignCoords(e,t,s,i,n,l,r,o){let a,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,i=d.rmsd_suprTmp.trans2;if(a=d.rmsd_suprTmp.rmsd,a){c.htmlCls.clickMenuCls.setLogCmd("realignment RMSD: "+a.toPrecision(4),!1);let e="<br><b>Realignment RMSD</b>: "+a.toPrecision(4)+" &#8491;<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 r={};for(let n=0,l=d.structures[s].length;n<l;++n){let l=d.structures[s][n];if(!r.hasOwnProperty(l)){for(let s in d.chains[l]){let n=d.atoms[s];n.coord=d.surfaceCls.transformMemPro(n.coord,e,t,i)}r[l]=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,l);d.qt_start_end.push(h),p=d.hAtoms}return{hAtoms:p,rmsd:a}}getQtStartEndFromRealignResid(e,t){let s=this.icn3d;s.icn3dui,e.substr(0,e.indexOf("_")),t.substr(0,t.indexOf("_"));let i=[],n={};for(let t=0,i=s.chainsSeq[e].length;t<i;++t){n[s.chainsSeq[e][t].resi]=t+1}let l={};for(let e=0,i=s.chainsSeq[t].length;e<i;++e){l[s.chainsSeq[t][e].resi]=e+1}for(let r=0,o=s.realignResid[e].length;r<o&&r<s.realignResid[t].length;++r){let o=s.realignResid[e][r].resid;if(!o)continue;let a=o.lastIndexOf("_"),d=parseInt(o.substr(a+1)),c=s.realignResid[t][r].resid;if(!c)continue;let h=c.lastIndexOf("_"),p=parseInt(c.substr(h+1)),m=n[d],u=l[p];i.push({q_start:u,q_end:u,t_start:m,t_end:m})}return i}getMissingResidues(e,t,s){let i=this.icn3d,n=i.icn3dui;i.chainsSeq[s]=[];let l=0;if("mmdbid"===t||"align"===t)for(let t=0,s=e.length;t<s;++t)if(0!=e[t][0]){l=e[t][0]-(t+1);break}let r=l;for(let l=0,o=e.length;l<o;++l){let o,a;"mmdbid"===t?(o=e[l][1],a=0):"mmcifid"===t?(o=e[l][1],o=n.utilsCls.residueName2Abbr(o),a=0):"align"===t&&(o=e[l][1],a=0),""===o&&(o="x");let d={};i.bUsePdbNum?d.resi="0"==e[l][a]?parseInt(r)+1:e[l][a]:d.resi=l+1,d.name="align"===t?o.toLowerCase():o,i.chainsSeq[s].push(d),r=d.resi}}async set2DDiagramsForAlign(e,t){let s=this.icn3d,i=s.icn3dui;i.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions");let n=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+e+"&intrac=1",l=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+t+"&intrac=1";void 0!==i.cfg.inpara&&(n+=i.cfg.inpara,l+=i.cfg.inpara);let r=i.getAjaxPromise(n,"jsonp"),o=i.getAjaxPromise(l,"jsonp"),a=Promise.allSettled([r,o]),d=await a;s.interactionData1=d[0].value,s.html2ddgm="",s.diagram2dCls.draw2Ddgm(s.interactionData1,e,0),i.cfg.show2d&&i.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),s.interactionData2=d[1].value,s.diagram2dCls.draw2Ddgm(s.interactionData2,t,1),s.html2ddgm+="<br>"+s.diagram2dCls.set2DdgmNote(!0),$("#"+s.pre+"dl_2ddgm_html").html(s.html2ddgm),s.b2DShown=!0}async set2DDiagramsForChainalign(e){let t=this.icn3d.icn3dui,s=this;t.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions");let i=[];for(let s=0,n=e.length;s<n;++s){let n=e[s].indexOf("_"),l=e[s].substr(0,n).toUpperCase(),r=t.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+l+"&intrac=1";void 0!==t.cfg.inpara&&(r+=t.cfg.inpara);let o=t.getAjaxPromise(r,"jsonp");i.push(o)}let n=Promise.allSettled(i);try{let t=await n;s.parse2DDiagramsData(t,e)}catch(e){}}parse2DDiagramsData(e,t){let s=this.icn3d,i=s.icn3dui;s.html2ddgm="";for(let i=0,n=t.length;i<n;++i){let n=e[i].value,l=t[i].substr(0,t[i].indexOf("_"));s.diagram2dCls.draw2Ddgm(n,l,0)}s.html2ddgm+="<br>"+s.diagram2dCls.set2DdgmNote(!0),s.b2DShown=!0,$("#"+s.pre+"dl_2ddgm_html").html(s.html2ddgm),i.cfg.show2d&&i.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,s=t.icn3dui;t.yournote=e,$("#"+t.pre+"yournote").val(t.yournote),s.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 s=t.rmsd_supr.rot,i=t.rmsd_supr.trans1,n=t.rmsd_supr.trans2;t.rmsd_supr.rmsd;let l=0;for(let e in t.atoms){let r=t.atoms[e];r.coord=t.surfaceCls.transformMemPro(r.coord,s,i,n);let o=r.coord.x*r.coord.x+r.coord.y*r.coord.y;Math.abs(r.coord.z)<=25&&o>l&&(l=o)}this.addMemAtoms(t.halfBilayerSize,e,Math.sqrt(l)),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,s){let i=this.icn3d,n=i.icn3dui;if(void 0!==t){let l=i.loadPDBCls.getChainCalpha(i.chains,i.atoms,s,e),r=1==Object.keys(l.chainresiCalphaHash).length||1==Object.keys(t.chainresiCalphaHash).length,o=[],a=[];for(let e in l.chainresiCalphaHash)if(t.chainresiCalphaHash.hasOwnProperty(e)){let s=l.chainresiCalphaHash[e],i=t.chainresiCalphaHash[e];if((s.length==i.length||r)&&(o=o.concat(s),a=a.concat(i)),o.length>500)break}let d=o.length<a.length?o.length:a.length;if(d>=4)if(i.rmsd_supr=n.rmsdSuprCls.getRmsdSuprCls(o,a,d),void 0!==i.rmsd_supr.rot&&i.rmsd_supr.rmsd<.1){let s=i.rmsd_supr.rot,l=i.rmsd_supr.trans1,r=i.rmsd_supr.trans2,o=i.rmsd_supr.rmsd;n.htmlCls.clickMenuCls.setLogCmd("RMSD of alignment to OPM: "+o.toPrecision(4),!1);let a=0;for(let e in i.atoms){let t=i.atoms[e];t.coord=i.surfaceCls.transformMemPro(t.coord,s,l,r);let n=t.coord.x*t.coord.x+t.coord.y*t.coord.y;Math.abs(t.coord.z)<=25&&n>a&&(a=n)}i.center=t.center,i.oriCenter=i.center.clone(),this.addMemAtoms(i.halfBilayerSize,e,Math.sqrt(a)),i.bStopRotate=!0,i.bOpm=!0,$("#"+i.pre+"togglememli").show(),$("#"+i.pre+"adjustmemli").show(),$("#"+i.pre+"selectplaneli").show()}else i.bOpm=!1;else i.bOpm=!1}}addOneDumAtom(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a={het:!0,serial:++l,name:t,alt:void 0,resn:"DUM",structure:e,chain:"MEM",resi:1,coord:new THREE.Vector3(s,i,n),b:void 0,elem:t,bonds:[],ss:"",ssbegin:!1,ssend:!1,color:o.parasCls.atomColors[t]};return r.atoms[l]=a,r.chains[e+"_MEM"][l]=1,r.residues[e+"_MEM_1"][l]=1,r.chemicals[l]=1,r.dAtoms[l]=1,r.hAtoms[l]=1,l}addMemAtoms(e,t,s){let i=this.icn3d;if(i.icn3dui,!t)return;t=t?t.toUpperCase():i.defaultPdbId,i.structures[t].push(t+"_MEM"),i.chains[t+"_MEM"]={},i.residues[t+"_MEM_1"]={},i.chainsSeq[t+"_MEM"]=[{name:"DUM",resi:1}];let n=Object.keys(i.atoms).length;for(let e=0;e<1e3;++e)if(!i.atoms.hasOwnProperty(n+e)){n=n+e-1;break}for(let i=0;i<81;++i)for(let l=0;l<81;++l){let r=2*i-80,o=2*l-80;if(Math.sqrt(r*r+o*o)<s){let s=-e-.4;n=this.addOneDumAtom(t,"N",r,o,s,n),s=e+.4,n=this.addOneDumAtom(t,"O",r,o,s,n)}}}setMaxD(){let e=this.icn3d;e.icn3dui;let t=new THREE.Vector3(9999,9999,9999),s=new THREE.Vector3(-9999,-9999,-9999),i=new THREE.Vector3,n=0;for(let l in e.atoms){let r=e.atoms[l],o=r.coord;i.add(o),t.min(o),s.max(o),++n,r.het&&(0==r.bonds.length?e.ions[r.serial]=1:e.chemicals[r.serial]=1)}e.pmin=t,e.pmax=s,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 s=e.selectedPdbid+"_MEM_1";for(let i in e.residues[s]){let s=e.atoms[i];s.style="stick",s.color=t.parasCls.atomColors[s.name],e.atomPrevColors[i]=s.color,e.dAtoms[i]=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 THREE.Vector3(1,0,0),s=-.5*Math.PI;e.transformCls.setRotation(t,s)}$("#"+e.pre+"alternate").show()}else e.selectionCls.saveSelectionIfSelected(),e.drawCls.draw();if(e.bInitial){if(t.cfg.mobilemenu){t.htmlCls.shownMenus=t.hashUtilsCls.cloneHash(t.htmlCls.simpleMenus);let e=!0;t.htmlCls.clickMenuCls.applyShownMenus(e)}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 s=e.pre+"selection";if($("#"+s).show(),$("#"+s+"_expand").hide(),$("#"+s+"_shrink").show(),void 0!==t.cfg.align&&2!=t.cfg.atype){let s=!1,i=t.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(e.alnChains),void 0,void 0,s);$("#"+e.pre+"dl_sequence2").html(i.sequencesHtml),$("#"+e.pre+"dl_sequence2").width(t.htmlCls.RESIDUE_WIDTH*i.maxSeqCnt+200)}}if(t.cfg.showanno){let s="view annotations";t.htmlCls.clickMenuCls.setLogCmd(s,!0),await e.showAnnoCls.showAnnotations()}(t.cfg.closepopup||t.cfg.imageonly)&&e.resizeCanvasCls.closeDialogs()}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 s=Object.keys(e.structures)[0];t.cfg.command=t.cfg.command.replace(new RegExp("!","g"),s+"_")}}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,s,i){let n=this.icn3d;n.icn3dui;let l=0;for(let r in e){let e=n.atoms[r].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(s.x)==Math.round(e.x)||Math.round(s.y)==Math.round(e.y)||Math.round(s.z)==Math.round(e.z)){let t=2*e.distanceTo(i);t>l&&(l=t)}}return l}async checkMemProteinAndRotate(){let e=this.icn3d,t=e.icn3dui;if(!e.bCheckMemProtein){e.bCheckMemProtein=!0;let s=t.cfg.afid?t.cfg.afid:t.cfg.mmdbafid;if(await e.ParserUtilsCls.checkMemProtein(s),t.cfg.url&&-1!=t.cfg.url.indexOf("membranome")){let t=new THREE.Vector3(1,0,0),s=-.5*Math.PI;e.transformCls.setRotation(t,s)}}}async checkMemProtein(e){let t=this.icn3d,s=t.icn3dui;try{let i=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?afid2mem="+e,n=await s.getAjaxPromise(i,"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(s.bNode)return;if("off"==s.cfg.afmem);else if("on"==s.cfg.afmem||confirm(e))try{let e="https://storage.googleapis.com/membranome-assets/pdb_files/proteins/"+n.pdbid+".pdb",i=await s.getAjaxPromise(e,"text");t.bAfMem=!0,s.bNode||$("#"+s.pre+"togglememli").show();let l=n.pdbid.substr(0,n.pdbid.indexOf("_")),r=!0,o=!0;await t.pdbParserCls.loadPdbData(i,l,r,o),o&&(t.bSetChainsAdvancedMenu&&t.definedSetsCls.showSets(),t.bAnnoShown&&(await t.showAnnoCls.showAnnotations(),t.annotationCls.resetAnnoTabAll()));let a=n.segment.replace(/ /gi,"").split("(")[0];t.afmem_start_end=a.split("-"),t.hAtoms={},t.dAtoms={};for(let e in t.atoms)t.atoms[e].structure!=l&&(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=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[l+"_A_"+e]);await t.realignParserCls.realignOnSeqAlign(l)}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 s=this.icn3d;s.icn3dui;let i=s.ncbi2resid[e+"_"+(t+1).toString()];return i?i.substr(i.lastIndexOf("_")+1):""}getResiNCBI(e,t){let s=this.icn3d;s.icn3dui;let i=s.resid2ncbi[e+"_"+t];return i?parseInt(i.substr(i.lastIndexOf("_")+1)):0}}class os{constructor(e){this.icn3d=e}loadAtomDataIn(e,t,s,i,n,l,r,o,a){let d=this.icn3d,c=d.icn3dui;d.pmin=new THREE.Vector3(9999,9999,9999),d.pmax=new THREE.Vector3(-9999,-9999,-9999),d.psum=new THREE.Vector3;let h=e.atoms,p=d.atoms?Object.keys(d.atoms).length:0,m={},u={};d.pmid=e.pubmedId,void 0===d.chainid2title&&(d.chainid2title={}),void 0===d.chainid2sid&&(d.chainid2sid={});let g={},f={};if("align"===s){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 s=0,i=e.alignedStructures[0].length;s<i;++s){let i=e.alignedStructures[0][s];1===s&&(d.secondId=i.pdbId);let n=i.pdbId,l=i.mmdbId;for(let e=i.serialInterval[0],t=i.serialInterval[1];e<=t;++e)m[e]=n.toString(),u[l]=n;for(let e=0,t=i.molecules.length;e<t;++e){let t=i.molecules[e].chain;t=t.replace(/_/g,"");let s=i.molecules[e].kind,l=i.molecules[e].name,r=i.molecules[e].sid,o=n+"_"+t;g[o]=s,d.chainid2title[o]=l,void 0!==r&&(d.chainid2sid[o]=r)}d.molTitle+='<a href="'+c.htmlCls.baseUrl+"mmdb/mmdbsrv.cgi?uid="+i.pdbId.toUpperCase()+'" target="_blank">'+i.pdbId.toUpperCase()+"</a>",void 0!==i.descr&&(d.pmid+=i.descr.pubmedid),0===s&&(d.molTitle+=" and ",void 0!==i.descr&&(d.pmid+="_")),t=!0}d.molTitle+=" from VAST+",t||(d.molTitle="")}else if(void 0!==e.descr&&(d.molTitle=e.descr.name),"mmdbid"===s){let s=isNaN(t)?t:e.pdbId,i={};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 l=e.moleculeInfor[t].chain.trim();l=l.replace(/_/g,"");let r=s+"_"+l;i.hasOwnProperty(l)?(++i[l],r+=i[l]):i[l]=1,void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t);let o=e.moleculeInfor[t].kind,a=e.moleculeInfor[t].color,c=e.moleculeInfor[t].sid;if(g[r]=o,f[r]=a,"protein"==o&&(d.organism=e.moleculeInfor[t].taxonomyName.toLowerCase()),void 0!==c&&(d.chainid2sid[r]=c),void 0===d.pdbid_chain2title&&(d.pdbid_chain2title={}),d.pdbid_chain2title[r]=e.moleculeInfor[t].name,l==r.substr(r.lastIndexOf("_"))){let e={};e[t]=n.toString(),d.alignmolid2color.push(e)}++n}}"mmdbid"===s&&(d.molTitleHash||(d.molTitleHash={}),d.molTitleHash[t]=d.molTitle);let C,b,y,v,_,w={},S="",A="",x="",k="",O="",R="",I=0,E=0,T="",P=!0,D=!1,M="",F=c.utilsCls.isCalphaPhosOnly(h),H=0,L={};for(let e in h){++p,w[e]=p;let i,n=h[e];n.serial=p,"mmdbid"===s||"mmcifid"===s?i=t:"align"===s&&(i=m[p]);let l=!1;if(void 0!==n.chain||"mmdbid"!==s&&"align"!==s)n.chain=""===n.chain?"Misc":n.chain;else if("mmdbid"===s)if(C=n.ids.m,void 0!==d.molid2chain[C]){let e=d.molid2chain[C].indexOf("_");n.chain=d.molid2chain[C].substr(e+1)}else{let e="Misc";("protein"===g[O]&&"nucleotide"===g[O]&&n.resi!=E||"protein"!==g[O]&&"nucleotide"!==g[O]&&(n.resn.substr(0,3)!=T.substr(0,3)||n.resi!=E||"solvent"===g[O]||"HOH"===n.resn))&&++H,n.resi_ori=n.resi,n.resi=H,l=!0,n.chain=e}else if("align"===s)if(C=n.ids.m,void 0!==d.pdbid_molid2chain[i+"_"+C])n.chain=d.pdbid_molid2chain[i+"_"+C];else{let e="Misc";("protein"===g[O]&&"nucleotide"===g[O]&&n.resi!=E||"protein"!==g[O]&&"nucleotide"!==g[O]&&(n.resn.substr(0,3)!=T.substr(0,3)||n.resi!=E||"solvent"===g[O]||"HOH"===n.resn))&&(++H,n.resi_ori=n.resi,n.resi=H,l=!0),n.chain=e}if(n.chain=n.chain.trim(),n.chain=n.chain.replace(/_/g,""),"mmdbid"!==s&&"align"!==s||(n.structure=i,"mmdbid"===s&&void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t)),k=n.structure,O=k+"_"+n.chain,"mmdbid"===s||"align"===s){l||(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))}O!==A&&(I=0),n.resi!==I&&(O!==A?(y=void 0,_=void 0):(y=b,_=v)),n.coord="mmdbid"===s?new THREE.Vector3(n.coord[0],n.coord[1],n.coord[2]):new THREE.Vector3(n.coord.x,n.coord.y,n.coord.z);let r=c.utilsCls.residueName2Abbr(n.resn.substr(0,3));"mmdbid"!==s&&"align"!==s||!d.bFullUi||(void 0===d.mmdbMolidResid2mmdbChainResi&&(d.mmdbMolidResid2mmdbChainResi={}),d.mmdbMolidResid2mmdbChainResi[i+"_"+n.ids.m+"_"+n.ids.r]=i+"_"+n.chain+"_"+n.resi),d.pmin.min(n.coord),d.pmax.max(n.coord),d.psum.add(n.coord);let o="protein"===g[O],a="nucleotide"===g[O],u="solvent"===g[O],N="ligand"===g[O]||void 0!==g[O]&&-1!==g[O].indexOf("other")||void 0===g[O];if("Misc"!==n.chain&&"other"!==g[O]||"protein"===L[O]||"nucleotide"===L[O]||("CA"===n.name&&"C"===n.elem?L[O]="protein":"P"===n.name&&"P"===n.elem?L[O]="nucleotide":L[O]="chemical"),o||a?(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)):a&&(d.nucleotides[p]=1,("O3'"==n.name||"O3*"==n.name||F&&"P"==n.name)&&(d.nucleotidesO3[p]=1),-1===c.parasCls.nuclMainArray.indexOf(n.name)&&(d.ntbase[p]=1)),n.het=!1):u?(d.water[p]=1,n.het=!0):N&&("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"===s?n.het?n.color=c.parasCls.atomColors[n.elem]||c.parasCls.defaultAtomColor:n.color=void 0!==f[O]?c.parasCls.thr(f[O]):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||(b=p),n.het||"O"!==n.name||(v=p),!n.het&&"N"===n.name&&void 0!==y&&void 0!==_){let e=d.atoms[y].coord.distanceTo(d.atoms[_].coord),t=n.coord.x+(d.atoms[y].coord.x-d.atoms[_].coord.x)/e,s=n.coord.y+(d.atoms[y].coord.y-d.atoms[_].coord.y)/e,i=n.coord.z+(d.atoms[y].coord.z-d.atoms[_].coord.z)/e;n.hcoord=new THREE.Vector3(t,s,i)}"HOH"==n.resn&&(d.water[p]=1),d.atoms[p]=n,d.dAtoms[p]=1,d.hAtoms[p]=1;let q=n.structure+"_"+n.chain;void 0===d.chains[q]&&(d.chains[q]={}),d.chains[q][p]=1;let U=q+"_"+n.resi;void 0===d.residues[U]&&(d.residues[U]={}),d.residues[U][p]=1,R=O+"_"+n.resi,R!==x&&O!==A&&(P=!0,""!==S&&(void 0===d.structures[S]&&(d.structures[S]=[]),d.structures[S].push(A))),d.residueId2Name[U]=r;let $="-";if("helix"===n.ss?$="H":"sheet"===n.ss?$="E":n.het||a?$="o":(!n.het&&c.parasCls.residueColors.hasOwnProperty(n.resn.toUpperCase())||"coil"===n.ss)&&($="c"),d.secondaries[n.structure+"_"+n.chain+"_"+n.resi]=$,(n.resi!=I||C!=M)&&d.bFullUi&&(void 0===d.chainsSeq[q]&&(d.chainsSeq[q]=[],P=!1),!isNaN(n.resi)&&null!==n.resi))if(P&&!D&&void 0!==d.chainsSeq[q][n.resi-1])d.chainsSeq[q][n.resi-1].name=r;else if(!P||!d.chainsSeq[q].hasOwnProperty(n.resi-1)){let e={};e.resi=n.resi,e.name=r,n.resi%10==0&&n.resi.toString(),d.chainsSeq[q].push(e),D=!0}I=n.resi,E=n.resi_ori,T=n.resn,S=k,A=O,x=R,M=C}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 L)if(!(Object.keys(d.chains[e]).length<10)&&"chemical"!==L[e])for(let t in d.chains[e]){let s=d.atoms[t];delete d.chemicals[t],s.het=!1,"protein"===L[e]?(d.proteins[t]=1,"CA"===s.name&&(d.calphas[t]=1),"N"!==s.name&&"H"!==s.name&&"CA"!==s.name&&"HA"!==s.name&&"C"!==s.name&&"O"!==s.name&&(d.sidec[t]=1)):"nucleotide"===L[e]&&(d.nucleotides[t]=1,("O3'"==s.name||"O3*"==s.name||F&&"P"==s.name)&&(d.nucleotidesO3[t]=1),-1===c.parasCls.nuclMainArray.indexOf(s.name)&&(d.ntbase[t]=1))}if(void 0===d.structures[k]&&(d.structures[k]=[]),d.structures[k].push(O),d.bFullUi)if("mmdbid"===s||"mmcifid"===s)for(let i in e.sequences){let n=e.sequences[i],l=t+"_"+i;void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t),d.ParserUtilsCls.getMissingResidues(n,s,l)}else if("align"===s)for(let e in d.chainid2seq){let t=d.chainid2seq[e];d.ParserUtilsCls.getMissingResidues(t,s,e)}if(d.loadPDBCls.setResidMapping(),"mmcifid"!==s)for(let e in h){let t=w[e],s=void 0===d.atoms[t].bonds?0:d.atoms[t].bonds.length;for(let e=0;e<s;++e)d.atoms[t].bonds[e]=w[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"===s||o)&&(d.ssbondpnts={},d.loadPDBCls.setSsbond()),"mmdbid"===s&&1==Object.keys(d.structures).length){let t=e.disulfides;if(void 0!==t)for(let e=0,s=t.length;e<s;++e){let s=t[e][0].ca,i=t[e][1].ca,n=d.atoms[s],l=d.atoms[i],r=n.chain,o=l.chain,a=n.structure+"_"+r+"_"+n.resi,c=l.structure+"_"+o+"_"+l.resi;void 0===d.ssbondpnts[n.structure]&&(d.ssbondpnts[n.structure]=[]),d.ssbondpnts[n.structure].push(a),d.ssbondpnts[n.structure].push(c)}}else if("mmcifid"===s&&1==Object.keys(d.structures).length){let s=e.disulfides;if(void 0!==s){void 0===d.ssbondpnts[t]&&(d.ssbondpnts[t]=[]);for(let e=0,i=s.length;e<i;++e){let i=s[e][0],n=s[e][1];d.ssbondpnts[t].push(i),d.ssbondpnts[t].push(n)}let e=Object.keys(d.structures);for(let s=0,i=e.length;s<i;++s){let i=e[s];if(i!=t){void 0===d.ssbondpnts[i]&&(d.ssbondpnts[i]=[]);for(let e=0,s=d.ssbondpnts[t].length;e<s;++e){let s=d.ssbondpnts[t][e],n=s.indexOf("_"),l=i+s.substr(n);d.ssbondpnts[i].push(l)}}}}}("mmcifid"===s||"mmdbid"===s&&void 0===n)&&d.ParserUtilsCls.transformToOpmOri(t);let N={};if("align"===s&&void 0!==i&&d.bFullUi)d.setSeqAlignCls.setSeqAlign(i,e.alignedStructures);else if("mmdbid"!==s||"query"!==n||!d.bFullUi||void 0===d.q_rotation||c.cfg.resnum||c.cfg.resdef||a)N=d.hAtoms;else if(r){d.setSeqAlignCls.setSeqAlignChain(l,r);let e=!1,t=c.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(d.alnChains),void 0,void 0,!1,void 0,e),s=$("#"+d.pre+"dl_sequence2").html();N=d.hAtoms,$("#"+d.pre+"dl_sequence2").html(s+t.sequencesHtml),$("#"+d.pre+"dl_sequence2").width(c.htmlCls.RESIDUE_WIDTH*t.maxSeqCnt+200)}else N=d.hAtoms;if(!c.cfg.mmdbafid&&"mmdbid"===s&&("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 THREE.Vector3(0,0,0))}return d.oriCenter=d.center.clone(),d.saveFileCls.showTitle(),e={},N}}class as{constructor(e){this.icn3d=e}setSeqAlign(e,t){let s=this.icn3d,i=s.icn3dui,n=t[0][0].pdbId,l=t[0][1].pdbId;s.conservedName1=n+"_cons",s.nonConservedName1=n+"_ncons",s.notAlignedName1=n+"_nalign",s.conservedName2=l+"_cons",s.nonConservedName2=l+"_ncons",s.notAlignedName2=l+"_nalign",s.consHash1={},s.nconsHash1={},s.nalignHash1={},s.consHash2={},s.nconsHash2={},s.nalignHash2={};for(let t=0,r=e.length;t<r;++t){let r=e[t][0],o=r.moleculeId,a=s.pdbid_molid2chain[n+"_"+o],d=n+"_"+a,c={},h=r.sequence.length,p=-1,m=!1;for(let e=0,t=r.sequence.length;e<t;++e){let t=s.bUsePdbNum?s.ParserUtilsCls.getResi(d,r.sequence[e][0]-1):r.sequence[e][0],i="~"===r.sequence[e][2]?"-":r.sequence[e][2];i=" "===i||""===i?"X":i;let n=r.sequence[e][3]?1:0;1==n&&(e<h&&!m&&(h=e,m=!0),e>p&&(p=e)),c[e]={resi:t,resn:i,aligned:n}}r=e[t][1];let u=r.moleculeId,g=s.pdbid_molid2chain[l+"_"+u],f=l+"_"+g;void 0===s.alnChainsAnTtl[d]&&(s.alnChainsAnTtl[d]=[]),void 0===s.alnChainsAnTtl[d][0]&&(s.alnChainsAnTtl[d][0]=[]),void 0===s.alnChainsAnTtl[d][1]&&(s.alnChainsAnTtl[d][1]=[]),void 0===s.alnChainsAnTtl[d][2]&&(s.alnChainsAnTtl[d][2]=[]),void 0===s.alnChainsAnTtl[d][3]&&(s.alnChainsAnTtl[d][3]=[]),void 0===s.alnChainsAnTtl[d][4]&&(s.alnChainsAnTtl[d][4]=[]),void 0===s.alnChainsAnTtl[d][5]&&(s.alnChainsAnTtl[d][5]=[]),void 0===s.alnChainsAnTtl[d][6]&&(s.alnChainsAnTtl[d][6]=[]),s.alnChainsAnTtl[d][0].push(f),s.alnChainsAnTtl[d][1].push(d),s.alnChainsAnTtl[d][2].push(""),s.alnChainsAnTtl[d][3].push(""),s.alnChainsAnTtl[d][4].push(f),s.alnChainsAnTtl[d][5].push(d),s.alnChainsAnTtl[d][6].push("");let C=1;s.chainsMapping[d]||(s.chainsMapping[d]={}),s.chainsMapping[f]||(s.chainsMapping[f]={});for(let e=h;e<=p;++e){let t,o,p,m=s.bUsePdbNum?s.ParserUtilsCls.getResi(f,r.sequence[e][0]-1):r.sequence[e][0],u="~"===r.sequence[e][2]?"-":r.sequence[e][2],b=r.sequence[e][3]?1:0,y=c[e].aligned+b;2===y?(c[e].resn===u?(t="#FF0000",p="icn3d-cons",s.consHash1[d+"_"+c[e].resi]=1,s.consHash2[f+"_"+m]=1):(t="#0000FF",p="icn3d-ncons",s.nconsHash1[d+"_"+c[e].resi]=1,s.nconsHash2[f+"_"+m]=1),s.chainsMapping[d][d+"_"+c[e].resi]=c[e].resn+c[e].resi,s.chainsMapping[f][f+"_"+m]=c[e].resn+c[e].resi,o="#"+s.showAnnoCls.getColorhexFromBlosum62(c[e].resn,u)):(t=i.htmlCls.GREY8,p="icn3d-nalign",s.nalignHash1[d+"_"+c[e].resi]=1,s.nalignHash2[f+"_"+m]=1),void 0===s.alnChainsSeq[d]&&(s.alnChainsSeq[d]=[]);let v={};v.mmdbid=n,v.chain=a,v.resi=c[e].resi,v.resn=""===v.resi||"icn3d-nalign"===p?c[e].resn.toLowerCase():c[e].resn,v.aligned=y,v.color=""===v.resi?i.htmlCls.GREYC:t,v.color2=""===v.resi?i.htmlCls.GREYC:o,v.class=p,s.alnChainsSeq[d].push(v),""!==c[e].resi&&(void 0===s.alnChains[d]&&(s.alnChains[d]={}),$.extend(s.alnChains[d],s.residues[d+"_"+c[e].resi])),void 0===s.alnChainsSeq[f]&&(s.alnChainsSeq[f]=[]),v={},v.mmdbid=l,v.chain=g,v.resi=m,v.resn=""===v.resi||"icn3d-nalign"===p?u.toLowerCase():u,v.aligned=y,v.color=""===v.resi?i.htmlCls.GREYC:t,v.color2=""===v.resi?i.htmlCls.GREYC:o,v.class=p,s.alnChainsSeq[f].push(v),""!==v.resi&&(void 0===s.alnChains[f]&&(s.alnChains[f]={}),$.extend(s.alnChains[f],s.residues[f+"_"+m])),void 0===s.alnChainsAnno[d]&&(s.alnChainsAnno[d]=[]),void 0===s.alnChainsAnno[d][0]&&(s.alnChainsAnno[d][0]=[]),void 0===s.alnChainsAnno[d][1]&&(s.alnChainsAnno[d][1]=[]),void 0===s.alnChainsAnno[d][2]&&(s.alnChainsAnno[d][2]=[]),void 0===s.alnChainsAnno[d][3]&&(s.alnChainsAnno[d][3]=[]),e===h&&(void 0===s.alnChainsAnno[d][4]&&(s.alnChainsAnno[d][4]=[]),void 0===s.alnChainsAnno[d][5]&&(s.alnChainsAnno[d][5]=[]),void 0===s.alnChainsAnno[d][6]&&(s.alnChainsAnno[d][6]=[]),s.alnChainsAnno[d][4].push(s.pdbid_chain2title[f]),s.alnChainsAnno[d][5].push(s.pdbid_chain2title[d]),s.alnChainsAnno[d][6].push(""));let _=d+"_"+c[e].resi,w=f+"_"+m,S=s.secondaries[_],A=s.secondaries[w];A?s.alnChainsAnno[d][0].push(A):s.alnChainsAnno[d][0].push("-"),S?s.alnChainsAnno[d][1].push(S):s.alnChainsAnno[d][1].push("-");let x=".";C%5==0&&(x="*"),C%10==0&&(x="|"),s.alnChainsAnno[d][2].push(x);let k="";C%10==0&&(k=C.toString()),s.alnChainsAnno[d][3].push(k),++C}}e={}}getPosFromResi(e,t){let s=this.icn3d;s.icn3dui;let i,n=s.resid2ncbi[e+"_"+t];if(n){i=n.substr(n.lastIndexOf("_")+1)-1}return i}getResnFromResi(e,t){let s=this.icn3d;s.icn3dui;let i=e+"_"+t,n=s.residueId2Name[i];return n||(n="?"),n}getResiAferAlign(e,t,s){let i,n=this.icn3d,l=n.icn3dui;return t&&"tmalign"==l.cfg.aligntool?i=s:(s>n.chainsSeq[e].length-1&&(console.log("Error: the position "+s+" exceeds the max index "+(n.chainsSeq[e].length-1)),s=n.chainsSeq[e].length-1),i=n.chainsSeq[e][s].resi),i}setSeqAlignChain(e,t,s){let i,n,l,r,o,a,d,c,h,p,m,u=this.icn3d,g=u.icn3dui,f={},C=!!s;if(C){if(o=s[1],a=s[0],t=s[2],d=o.indexOf("_"),c=a.indexOf("_"),i=o.substr(0,d).toUpperCase(),n=a.substr(0,c).toUpperCase(),l=o.substr(d+1),r=a.substr(d+1),i==n&&l==r){let e=u.chainsSeq[n+"_"+r].length;u.qt_start_end[t]={q_start:1,q_end:e,t_start:1,t_end:e}}}else{let d=s[0].indexOf("_"),c=e.indexOf("_");if(i=u.mmdbid_t,n=e.substr(0,c).toUpperCase(),l=s[0].substr(d+1),r=e.substr(c+1),i==n&&l==r){let e=u.chainsSeq[u.mmdbid_q+"_"+u.chain_q].length;u.qt_start_end[t]={q_start:1,q_end:e,t_start:1,t_end:e}}o=i+"_"+l,a=n+"_"+r,void 0!==n&&u.mmdbid_t}u.conservedName1=o+"_cons",u.nonConservedName1=o+"_ncons",u.notAlignedName1=o+"_nalign",u.conservedName2=a+"_cons",u.nonConservedName2=a+"_ncons",u.notAlignedName2=a+"_nalign",u.consHash1={},u.nconsHash1={},u.nalignHash1={},u.consHash2={},u.nconsHash2={},u.nalignHash2={},u.alnChains={},u.alnChainsSeq[o]=[],u.alnChains[o]={},u.alnChainsSeq[a]=[],u.alnChains[a]={},u.alnChainsAnno[o]=[],u.alnChainsAnTtl[o]=[],void 0===u.alnChainsAnTtl[o]&&(u.alnChainsAnTtl[o]=[]);for(let e=0;e<7;++e)void 0===u.alnChainsAnTtl[o][e]&&(u.alnChainsAnTtl[o][e]=[]);u.alnChainsAnTtl[o][0].push(a),u.alnChainsAnTtl[o][1].push(o),u.alnChainsAnTtl[o][2].push(""),u.alnChainsAnTtl[o][3].push(""),u.alnChainsAnTtl[o][4].push(a),u.alnChainsAnTtl[o][5].push(o),u.alnChainsAnTtl[o][6].push("");let b=0,y=0;if(void 0===u.qt_start_end[t])return;let v=1;u.chainsMapping[o]||(u.chainsMapping[o]={}),u.chainsMapping[a]||(u.chainsMapping[a]={});let _={},w={};for(let e=0,s=u.qt_start_end[t].length;e<s;++e){let s,i,n,l;C&&"tmalign"==g.cfg.aligntool?(s=parseInt(u.qt_start_end[t][e].t_start),i=parseInt(u.qt_start_end[t][e].q_start),n=parseInt(u.qt_start_end[t][e].t_end),l=parseInt(u.qt_start_end[t][e].q_end)):(s=parseInt(u.qt_start_end[t][e].t_start-1),i=parseInt(u.qt_start_end[t][e].q_start-1),n=parseInt(u.qt_start_end[t][e].t_end-1),l=parseInt(u.qt_start_end[t][e].q_end-1)),_[s]=1,_[n]=1,w[i]=1,w[l]=1}for(let e=0,s=u.qt_start_end[t].length;e<s;++e){let s,i,n,l;if(C&&"tmalign"==g.cfg.aligntool?(s=parseInt(u.qt_start_end[t][e].t_start),i=parseInt(u.qt_start_end[t][e].q_start),n=parseInt(u.qt_start_end[t][e].t_end),l=parseInt(u.qt_start_end[t][e].q_end)):(s=parseInt(u.qt_start_end[t][e].t_start-1),i=parseInt(u.qt_start_end[t][e].q_start-1),n=parseInt(u.qt_start_end[t][e].t_end-1),l=parseInt(u.qt_start_end[t][e].q_end-1)),e>0){let e=v;for(let t=b+1,i=s;t<i;++t){_[t]=1;let s=this.getResiAferAlign(o,C,t),i=this.getResnFromResi(o,s).toLowerCase();"?"!=i&&(h=g.htmlCls.GREY8,m="icn3d-nalign",u.nalignHash1[o+"_"+s]=1,this.setSeqPerResi(o,o,a,s,i,!1,h,void 0,m,!0,!1,e),++e)}let t=v;for(let e=y+1,s=i;e<s;++e){w[e]=1;let s=this.getResiAferAlign(a,C,e),i=this.getResnFromResi(a,s).toLowerCase();"?"!=i&&(h=g.htmlCls.GREY8,m="icn3d-nalign",u.nalignHash2[a+"_"+s]=1,this.setSeqPerResi(a,o,a,s,i,!1,h,void 0,m,!1,!1,t),++t)}if(e<t){v=t;for(let s=0;s<t-e;++s){let t="",i="-";h=g.htmlCls.GREY8,m="icn3d-nalign",this.setSeqPerResi(o,o,a,t,i,!1,h,void 0,m,!0,!1,e+s)}}else{v=e;for(let s=0;s<e-t;++s){let e="",i="-";h=g.htmlCls.GREY8,m="icn3d-nalign",this.setSeqPerResi(a,o,a,e,i,!1,h,void 0,m,!1,!1,t+s)}}}for(let l=0;l<=n-s;++l){let n,r,d,c;if(C&&"tmalign"==g.cfg.aligntool){if(n=u.qt_start_end[t][e].t_start,r=u.qt_start_end[t][e].q_start,d=this.getResnFromResi(o,n).toUpperCase(),c=this.getResnFromResi(a,r).toUpperCase(),"?"==d||"?"==c)continue}else n=this.getResiAferAlign(o,C,l+s),r=this.getResiAferAlign(a,C,l+i),d=this.getResnFromResi(o,n).toUpperCase(),c=this.getResnFromResi(a,r).toUpperCase();d===c?(h="#FF0000",m="icn3d-cons",u.consHash1[o+"_"+n]=1,u.consHash2[a+"_"+r]=1):(h="#0000FF",m="icn3d-ncons",u.nconsHash1[o+"_"+n]=1,u.nconsHash2[a+"_"+r]=1),f=g.hashUtilsCls.unionHash(f,u.residues[o+"_"+n]),f=g.hashUtilsCls.unionHash(f,u.residues[a+"_"+r]),u.chainsMapping[o][o+"_"+n]=d+n,u.chainsMapping[a][a+"_"+r]=d+n,p="#"+u.showAnnoCls.getColorhexFromBlosum62(d,c);let b=0===e&&0===l;this.setSeqPerResi(o,o,a,n,d,!0,h,p,m,!0,b,v),this.setSeqPerResi(a,o,a,r,c,!0,h,p,m,!1,b,v),++v}b=n,y=l}return f}setSeqAlignChainForAll(e,t,s){let i=this.icn3d,n=i.icn3dui,l={},r=e[0];i.alnChainsAnno[r]=[],i.alnChainsAnTtl[r]=[];let o=e.length;void 0===i.alnChainsAnTtl[r]&&(i.alnChainsAnTtl[r]=[]);for(let e=0;e<3+2*o;++e)void 0===i.alnChainsAnTtl[r][e]&&(i.alnChainsAnTtl[r][e]=[]);for(let t=0;t<o;++t)i.alnChainsAnTtl[r][t].push(e[o-1-t]);i.alnChainsAnTtl[r][o].push(""),i.alnChainsAnTtl[r][o+1].push("");for(let t=o+2;t<2*o+2;++t)i.alnChainsAnTtl[r][t].push(e[2*o+1-t]);i.alnChainsAnTtl[r][2*o+2].push(""),i.alnChainsSeq[r]=[],i.alnChains={},i.alnChains[r]={};let a={},d=9999,c=-1,h=i.chainsSeq[r][0].resi-1;for(let t=1,s=e.length;t<s;++t){let s=t-1;if(e[t],i.qt_start_end[s])for(let t=0,l=i.qt_start_end[s].length;t<l;++t){let l,r;l=parseInt(i.qt_start_end[s][t].t_start)-1,r=parseInt(i.qt_start_end[s][t].t_end)-1;for(let t=l;t<=r;++t){let s,l,r;r="tmalign"==n.cfg.aligntool?t-h:t,s=i.ParserUtilsCls.getResi(e[0],r),l=e[0]+"_"+s,a[l]=1,t<d&&(d=t),t>c&&(c=t)}}}"tmalign"==n.cfg.aligntool&&(s=!0);let p=Object.keys(a);p.sort((function(e,t){return parseInt(e.split("_")[2])-parseInt(t.split("_")[2])}));let m=-999,u=0,g=0,f=[],C=0;for(let e=0,t=p.length;e<t;++e){let t=p[e],s=t.split("_")[2];if(0==e)u=s;else if(e>0&&i.resid2ncbi[s]!=i.resid2ncbi[m]+1&&i.resid2ncbi[s]!=i.resid2ncbi[m]){g=m;for(let e=0,t=f.length;e<t;++e)a[f[e]]={resiStart:u,resiEnd:g,prevResiEnd:C};f=[],u=s,C=g}f.push(t),m=s}g=m;for(let e=0,t=f.length;e<t;++e)a[f[e]]={resiStart:u,resiEnd:g,prevResiEnd:C};for(let t=0,s=e.length;t<s;++t){let s=e[t];i.alnChainsSeq[s]=[],i.alnChains[s]={},i.alnChainsAnno[s]=[]}for(let e=0,t=i.chainsSeq[r].length;e<t;++e){let t=i.chainsSeq[r][e].resi,s=r+"_"+t,o="tmalign"!=n.cfg.aligntool?e:e+h;if(o<d||o>c)continue;let p={},m=r.indexOf("_");p.mmdbid=r.substr(0,m),p.chain=r.substr(m+1),p.resi=t,p.resn=a[s]?i.chainsSeq[r][e].name.toUpperCase():i.chainsSeq[r][e].name.toLowerCase(),p.aligned=!!a[s],p.color=a[s]?"#FF0000":n.htmlCls.GREYC,p.color2=a[s]?"#FF0000":n.htmlCls.GREYC,p.class=a[s]?"icn3d-align":"icn3d-nalign",i.alnChainsSeq[r].push(p),a[s]&&($.extend(i.alnChains[r],i.residues[r+"_"+p.resi]),l=n.hashUtilsCls.unionHash(l,i.residues[r+"_"+p.resi]))}let b=[0];for(let i=0,r=t.length;i<r;++i){let r=t[i].index;b.push(r);let o=this.mergeTwoSeqForAll(e,r,b,a,d,c,s);l=n.hashUtilsCls.unionHash(l,o)}for(let e=0;e<3+2*o;++e)void 0===i.alnChainsAnno[r][e]&&(i.alnChainsAnno[r][e]=[]);for(let t=0;t<o;++t){let s=e[t];for(let e=0,n=i.alnChainsSeq[s].length;e<n;++e){if("-"==i.alnChainsSeq[s][e].resn)i.alnChainsAnno[r][o-1-t].push("-");else{let n=s+"_"+i.alnChainsSeq[s][e].resi,l=i.secondaries[n];void 0!==l?i.alnChainsAnno[r][o-1-t].push(l):i.alnChainsAnno[r][o-1-t].push("-")}}}for(let e=0,t=i.alnChainsSeq[r].length;e<t;++e){let t=".";e%5==0&&(t="*"),e%10==0&&(t="|"),i.alnChainsAnno[r][o].push(t);let s="";e%10==0&&(s=e.toString()),i.alnChainsAnno[r][o+1].push(s)}for(let t=o+2;t<2*o+2;++t){let s=i.pdbid_chain2title&&i.pdbid_chain2title.hasOwnProperty(e[2*o+1-t])?i.pdbid_chain2title[e[2*o+1-t]]:"";i.alnChainsAnno[r][t].push(s)}return i.alnChainsAnno[r][2*o+2].push(""),l}getResObject(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a={},d=e.indexOf("_");return a.mmdbid=e.substr(0,d),a.chain=e.substr(d+1),a.resi=t?"":i,a.resn=n?t?"-":s?n.toUpperCase():n.toLowerCase():"-",a.aligned=!t&&s,a.color=t||!s?o.htmlCls.GREYC:n==l?"#FF0000":"#0000FF",a.color2=t||!s?o.htmlCls.GREYC:"#"+r.showAnnoCls.getColorhexFromBlosum62(n,l),a.class=t||!s?"icn3d-nalign":"icn3d-align",a}getResn(e,t){let s,i=this.icn3d;return i.icn3dui,s=i.chainsSeq[e]&&i.chainsSeq[e][t]?i.chainsSeq[e][t].name:"",s}getResiPosInTemplate(e,t){let s=this.icn3d;s.icn3dui;let i,n=0;if(s.alnChainsSeq[e])for(let l=0,r=s.alnChainsSeq[e].length;l<r;++l){if(parseInt(s.alnChainsSeq[e][l].resi)==parseInt(t)){i=l;break}"-"==s.alnChainsSeq[e][l].resn?++n:n=0}return{pos:i,ngap:n}}addGapAllAlnChains(e,t,s,i,n){let l=this.icn3d;l.icn3dui;let r=this.getResiPosInTemplate(s,i);r.ngap;let o=r.pos;for(let s=0,i=t.length-1;s<i;++s){let i=e[t[s]],r=this.getResObject(i,!0);for(let e=0,t=n;e<t;++e)l.alnChainsSeq[i].splice(o,0,r)}}insertNotAlignRes(e,t,s,i){let n=this.icn3d;n.icn3dui;for(let i=0,l=s;i<l;++i){let s=n.ParserUtilsCls.getResi(e,t+i),l=this.getResn(e,t+i),r="-",o=!1,a=this.getResObject(e,!1,o,s,l,r);n.alnChainsSeq[e].push(a)}}getTemplatePosFromOriPos(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=n.ParserUtilsCls.getResi(e,t),r=n.ParserUtilsCls.getResi(e,s),o=this.getResiPosInTemplate(e,l),a=this.getResiPosInTemplate(e,r);return{pos1:o.pos,pos2:a.pos}}mergeTwoSeqForAll(e,t,s,i,n,l,r){let o,a,d,c,h,p,m,u,g,f,C=this.icn3d,b=C.icn3dui,y={},v=e[t],_=t-1;if(m=e[0].indexOf("_"),u=v.indexOf("_"),o=e[0].substr(0,m),a=v.substr(0,u),d=e[0].substr(m+1),c=v.substr(u+1),o==a&&d==c){let e=C.chainsSeq[C.mmdbid_q+"_"+C.chain_q].length;C.qt_start_end[_]={q_start:1,q_end:e,t_start:1,t_end:e}}if(h=o+"_"+d,p=a+"_"+c,void 0!==a&&C.mmdbid_t,C.alnChains[p]={},C.conservedName2=p+"_cons",C.nonConservedName2=p+"_ncons",C.notAlignedName2=p+"_nalign",C.consHash2={},C.nconsHash2={},C.nalignHash2={},void 0===C.qt_start_end[_])return;this.getResObject(h,!0);let w,S=this.getResObject(p,!0);C.chainsMapping[h]||(C.chainsMapping[h]={}),C.chainsMapping[p]||(C.chainsMapping[p]={});for(let t=0,i=C.qt_start_end[_].length;t<i;++t){let i,l,o,a,d,c,v;if(r&&"tmalign"==b.cfg.aligntool?(i=parseInt(C.qt_start_end[_][t].t_start),l=parseInt(C.qt_start_end[_][t].q_start),o=parseInt(C.qt_start_end[_][t].t_end),a=parseInt(C.qt_start_end[_][t].q_end),d=i,c=this.getPosFromResi(h,C.qt_start_end[_][t].t_start),v=this.getPosFromResi(h,C.qt_start_end[_][t].t_end)):(i=parseInt(C.qt_start_end[_][t].t_start-1),l=parseInt(C.qt_start_end[_][t].q_start-1),o=parseInt(C.qt_start_end[_][t].t_end-1),a=parseInt(C.qt_start_end[_][t].q_end-1),d=C.ParserUtilsCls.getResi(h,i),c=i,v=o),0==t){if(w=this.getTemplatePosFromOriPos(h,n,c,r),m=w.pos1,u=w.pos2,c>n)for(let e=0,t=u-m;e<t;++e)C.alnChainsSeq[p].push(S)}else{w=this.getTemplatePosFromOriPos(h,g,i,r),m=w.pos1,u=w.pos2;let t=u-(m+1),n=l-(f+1);if(this.insertNotAlignRes(p,f+1,n,r),t>=n)for(let e=0,s=t-n;e<s;++e)C.alnChainsSeq[p].push(S);else this.addGapAllAlnChains(e,s,h,d,n-t)}w=this.getTemplatePosFromOriPos(h,c,v,r),m=w.pos1,u=w.pos2;let A=0;C.chainsMapping[h]||(C.chainsMapping[h]={}),C.chainsMapping[p]||(C.chainsMapping[p]={});for(let e=m;e<=u;++e)if("-"==C.alnChainsSeq[h][e].resn)C.alnChainsSeq[p].push(S);else{let t=r?i+A:C.ParserUtilsCls.getResi(h,i+A),s=r?l+A:C.ParserUtilsCls.getResi(p,l+A),n=this.getResnFromResi(h,t),o=this.getResnFromResi(p,s),a=!0,d=this.getResObject(p,!1,a,s,o,n);C.alnChainsSeq[p].push(d),C.alnChainsSeq[h][e].color=d.color,C.chainsMapping[h][h+"_"+t]=n+t,C.chainsMapping[p][p+"_"+s]=n+t,$.extend(C.alnChains[p],C.residues[p+"_"+s]),y=b.hashUtilsCls.unionHash(y,C.residues[p+"_"+s]),++A}g=o,f=a}w=this.getTemplatePosFromOriPos(h,g,l,r),m=w.pos1,u=w.pos2;for(let e=m;e<u;++e)C.alnChainsSeq[p].push(S);return y}mergeTwoSeqForAllSimple(e,t,s,i,n,l,r){let o=this.icn3d;o.icn3dui;let a,d,c,h,p=e,m=t[s];for(let e=0,l=o.qt_start_end[s].length;e<l;++e){let l,u,g,f,C,b,y;if(l=o.qt_start_end[s][e].t_start,u=o.qt_start_end[s][e].q_start,g=o.qt_start_end[s][e].t_end,f=o.qt_start_end[s][e].q_end,C=l,b=l,y=g,0==e){if(a=n,d=b,b>n)for(let e=0,t=d-a;e<t;++e)o.msaSeq[m]+="-"}else{a=c,d=l;let e=d-(a+1),n=u-(h+1);for(let e=0,t=n;e<t;++e){let t=r[s][h+1+e];o.msaSeq[m]+=t}if(e>=n)for(let t=0,s=e-n;t<s;++t)o.msaSeq[m]+="-";else{let s=C;for(let l=0,r=i.length-1;l<r;++l){let r=0==l?p:t[i[l]];for(let t=0,i=n-e;t<i;++t)o.msaSeq[r]=o.msaSeq[r].substr(0,s)+"-"+o.msaSeq[r].substr(s)}}}a=b,d=y;let v=0;for(let e=a;e<=d;++e)if("-"==o.msaSeq[p][e])o.msaSeq[m]+="-";else{let e=r[s][u+v];o.msaSeq[m]+=e,++v}c=g,h=f}a=c,d=l;for(let e=a;e<d;++e)o.msaSeq[m]+="-"}setSeqAlignForRealign(e,t,s){let i=this.icn3d,n=i.icn3dui;i.conservedName1=e+"_cons",i.conservedName2=t+"_cons",i.consHash1={},i.consHash2={},i.alnChainsAnTtl={},i.alnChainsAnno={},void 0===i.alnChainsSeq&&(i.alnChainsSeq={}),i.alnChains={},i.alnChainsSeq[e]=[],i.alnChains[e]={},i.alnChainsAnno[e]=[],i.alnChainsAnTtl[e]=[],i.alnChainsSeq[t]=[],i.alnChains[t]={};let l={};i.chainsMapping[e]||(i.chainsMapping[e]={}),i.chainsMapping[t]||(i.chainsMapping[t]={});for(let s=0,r=i.realignResid[e].length;s<r;++s){let r=i.realignResid[e][s],o=r.resid.lastIndexOf("_"),a=r.resid.substr(0,o),d=r.resid.substr(o+1);r.resi=d,r.aligned=!0;let c,h=i.realignResid[t][s],p=h.resid.lastIndexOf("_"),m=h.resid.substr(0,p),u=h.resid.substr(p+1);h.resi=u,h.aligned=!0,l[r.resid]=1,l[h.resid]=1,c=r.resn.toUpperCase()==h.resn.toUpperCase()?"#FF0000":"#0000FF",i.chainsMapping[e][e+"_"+r.resi]=r.resn+r.resi,i.chainsMapping[t][t+"_"+h.resi]=r.resn+r.resi;let g="#"+i.showAnnoCls.getColorhexFromBlosum62(r.resn,h.resn);r.color=c,h.color=c,r.color2=g,h.color2=g;for(let e in i.residues[r.resid])i.atoms[e].color=n.parasCls.thr(c);for(let e in i.residues[h.resid])i.atoms[e].color=n.parasCls.thr(c);void 0===i.alnChainsAnTtl[a]&&(i.alnChainsAnTtl[a]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnTtl[a][e]&&(i.alnChainsAnTtl[a][e]=[]);for(let e=0;e<3;++e)i.alnChainsAnTtl[a][e].push("");void 0===i.alnChainsSeq[a]&&(i.alnChainsSeq[a]=[]),void 0===i.alnChainsSeq[m]&&(i.alnChainsSeq[m]=[]),i.alnChainsSeq[a].push(r),i.alnChainsSeq[m].push(h),void 0===i.alnChains[a]&&(i.alnChains[a]={}),void 0===i.alnChains[m]&&(i.alnChains[m]={}),$.extend(i.alnChains[a],i.residues[a+"_"+r.resi]),$.extend(i.alnChains[m],i.residues[m+"_"+h.resi]),i.consHash1[a+"_"+r.resi]=1,i.consHash2[m+"_"+h.resi]=1,void 0===i.alnChainsAnno[a]&&(i.alnChainsAnno[a]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnno[a][e]&&(i.alnChainsAnno[a][e]=[]);let f=".";s%5==0&&(f="*"),s%10==0&&(f="|"),i.alnChainsAnno[a][0].push(f);let C="";s%10==0&&(C=s.toString()),i.alnChainsAnno[a][1].push(C)}let r="select "+i.resid2specCls.residueids2spec(Object.keys(l));i.selectionCls.addCustomSelection(Object.keys(l),"protein_aligned","protein aligned",r,!0)}setSeqPerResi(e,t,s,i,n,l,r,o,a,d,c,h){let p=this.icn3d,m=p.icn3dui;void 0===p.alnChainsSeq[e]&&(p.alnChainsSeq[e]=[]);let u={},g=e.indexOf("_");if(u.mmdbid=e.substr(0,g),u.chain=e.substr(g+1),u.resi=i,u.resn=""===u.resi||"icn3d-nalign"===a?n.toLowerCase():n,u.aligned=l,u.color=""===u.resi?m.htmlCls.GREYC:r,u.color2=""===u.resi?m.htmlCls.GREYC:o,u.class=a,p.alnChainsSeq[e].push(u),""!==u.resi&&(void 0===p.alnChains[e]&&(p.alnChains[e]={}),$.extend(p.alnChains[e],p.residues[e+"_"+u.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(s)?p.pdbid_chain2title[s]:"",i=p.pdbid_chain2title&&p.pdbid_chain2title.hasOwnProperty(e)?p.pdbid_chain2title[e]:"";p.alnChainsAnno[e][4].push(t),p.alnChainsAnno[e][5].push(i),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 l=e+"_"+i,r=p.secondaries[l];void 0!==r?p.alnChainsAnno[e][1].push(r):p.alnChainsAnno[e][1].push("-")}else{let s=e+"_"+i,n=p.secondaries[s];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")}}}class ds{constructor(e){this.icn3d=e}getStructureId(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=e=i&&n.idNMR?n.idNMR:e;return(e==n.defaultPdbId||s||n.structures.hasOwnProperty(e))&&(l=1===t?e:e+t.toString()),l}async loadPDB(e,t,s,i,n,l,r,o){let a,d,c=this.icn3d,h=c.icn3dui,p={},m=!1,u=e.split("\n"),g={},f={};c.atoms||(l=!1),c.statefileArray&&(c.struct_statefile=[]),n||l?(c.oriNStru=c.structures?Object.keys(c.structures).length:0,d=c.oriNStru+1,a=c.atoms?Object.keys(c.atoms).length:0):(c.init(),d=1,a=0);let C,b,y,v,_,w,S,A,x,k=[],O=[],R=[],I=[],E=[],T=[],P="",D="",M="",F={},H=t||c.defaultPdbId,L=H,N=H,q="",U=!1,B=!0;for(let e in u){let r=u[e],$=r.substr(0,6);if("HEADER"!==$||U||t)if("TITLE "===$){let e=r.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[N]=c.molTitle}else if("HELIX "===$){c.bSecondaryStructure=!0;let e=""==r.substr(18,2).trim()?"A":r.substr(18,2).trim(),t=parseInt(r.substr(21,4)),s=parseInt(r.substr(33,4));for(let i=t;i<=s;++i){let n=N+"_"+e+"_"+i;I.push(n),i===t&&E.push(n),i===s&&T.push(n)}}else if("SHEET "===$){void 0!==s&&s||(c.bSecondaryStructure=!0);let e=""==r.substr(20,2).trim()?"A":r.substr(20,2).trim(),t=parseInt(r.substr(22,4)),i=parseInt(r.substr(33,4));for(let s=t;s<=i;++s){let n=N+"_"+e+"_"+s;k.push(n),s===t&&O.push(n),s===i&&R.push(n)}}else if("HBOND "===$)void 0!==s&&s||(c.bSecondaryStructure=!0);else if("SSBOND"===$){c.bSsbondProvided=!0;let e=N+"_"+(" "==r.substr(15,1)?"A":r.substr(15,1))+"_"+r.substr(17,4).trim(),t=N+"_"+(" "==r.substr(29,1)?"A":r.substr(29,1))+"_"+r.substr(31,4).trim();void 0===c.ssbondpnts[N]&&(c.ssbondpnts[N]=[]),c.ssbondpnts[N].push(e),c.ssbondpnts[N].push(t)}else if("REMARK"===$){let e=parseInt(r.substr(7,3));if(-1!==r.indexOf("1/2 of bilayer thickness:"))c.halfBilayerSize=parseFloat(r.substr(r.indexOf(":")+1).trim());else if(210==e)"EXPERIMENT TYPE"==r.substr(11,32).trim()&&"NMR"==r.substr(45).trim()&&(m=!0,c.idNMR=L);else if(350==e&&"BIOMT"==r.substr(13,5)){let e=parseInt(r[18])-1,t=parseInt(r.substr(21,2))-1;null==c.biomtMatrices[t]&&(c.biomtMatrices[t]=(new THREE.Matrix4).identity()),c.biomtMatrices[t].elements[e]=parseFloat(r.substr(24,9)),c.biomtMatrices[t].elements[e+4]=parseFloat(r.substr(34,9)),c.biomtMatrices[t].elements[e+8]=parseFloat(r.substr(44,9)),c.biomtMatrices[t].elements[e+12]=parseFloat(r.substr(54,14))}else if(465==e&&" "==r.substr(18,1)&&" "==r.substr(20,1)&&"S"!=r.substr(21,1)){let e=r.substr(15,3),t=r.substr(18,2).trim(),s=r.substr(21,5).trim(),i=H+"_"+t;void 0===c.chainMissingResidueArray[i]&&(c.chainMissingResidueArray[i]=[]);let n={};n.resi=s,n.name=h.utilsCls.residueName2Abbr(e).toLowerCase(),""!=q&&t==q&&t!=q||(c.chainMissingResidueArray[i].push(n),q=t)}else 900==e&&void 0===c.emd&&"RELATED DB: EMDB"==r.substr(34).trim()&&(c.emd=r.substr(23,11).trim())}else if("SOURCE"===$&&void 0===c.organism&&"ORGANISM_COMMON"==r.substr(11,15).trim())c.organism=r.substr(28).toLowerCase().trim(),c.organism=c.organism.substr(0,c.organism.length-1);else if("ENDMDL"===$)c.statefileArray&&c.struct_statefile.push({structure:N,statefile:c.statefileArray[d-1]}),++d,H=c.defaultPdbId,N=this.getStructureId(H,d,n,m),m||(k=[],O=[],R=[],I=[],E=[],T=[]),U=!1;else if("JRNL "===$)"PMID"===r.substr(12,4)&&(c.pmid=r.substr(19).trim());else if("ATOM "===$||"HETATM"===$){A=r.substr(72,4).trim(),B?(N=this.getStructureId(H,d,n,m),B=!1):A!=x&&(++d,H=c.defaultPdbId,N=this.getStructureId(H,d,n,m),m||(k=[],O=[],R=[],I=[],E=[],T=[]),U=!1),x=A;let e=r.substr(16,1);++a,F[parseInt(r.substr(6,5))]=a;let t=r.substr(76,2).trim();""===t&&(t=r.substr(12,2).trim());let l=r.substr(12,4).trim(),u=r.substr(17,3),L=r.substr(20,2).trim();""===L&&(L="A");let q=r.substr(22,5).trim(),j=q;if(s&&"DUM"===u&&(t=l,L="MEM",j=1,q=1),i&&"DUM"===u)break;C=N+"_"+L,y=C+"_"+q,b=C+"_"+j;let z=parseFloat(r.substr(30,8)),G=parseFloat(r.substr(38,8)),V=parseFloat(r.substr(46,8)),W=new THREE.Vector3(z,G,V),Y=parseFloat(r.substr(60,8));o&&(Y*=100);let X={het:"H"===$[0],serial:a,name:l,alt:e,resn:u,structure:N,chain:L,resi:j,coord:W,b:Y,elem:t,bonds:[],ss:"coil",ssbegin:!1,ssend:!1};if(X.het||"C"!==X.name||(v=a),X.het||"O"!==X.name||(w=a),!X.het&&"N"===X.name&&void 0!==_&&void 0!==S){let e=c.atoms[_].coord.distanceTo(c.atoms[S].coord),t=X.coord.x+(c.atoms[_].coord.x-c.atoms[S].coord.x)/e,s=X.coord.y+(c.atoms[_].coord.y-c.atoms[S].coord.y)/e,i=X.coord.z+(c.atoms[_].coord.z-c.atoms[S].coord.z)/e;X.hcoord=new THREE.Vector3(t,s,i)}c.atoms[a]=X,c.dAtoms[a]=1,c.hAtoms[a]=1,p[a]=1,this.isSecondary(b,k,m)?(c.atoms[a].ss="sheet",this.isSecondary(b,O,m)&&(c.atoms[a].ssbegin=!0),this.isSecondary(b,R,m)&&(c.atoms[a].ssend=!0)):this.isSecondary(b,I,m)&&(c.atoms[a].ss="helix",this.isSecondary(b,E,m)&&(c.atoms[a].ssbegin=!0),this.isSecondary(b,T,m)&&(c.atoms[a].ssend=!0));let K="-";if(K="helix"===c.atoms[a].ss?"H":"sheet"===c.atoms[a].ss?"E":!c.atoms[a].het&&h.parasCls.residueColors.hasOwnProperty(c.atoms[a].resn.toUpperCase())?"c":"o",c.secondaries[b]=K,y!==M){let e=h.utilsCls.residueName2Abbr(u);if(c.residueId2Name[b]=e,1!==a&&""!==D&&(c.residues[D]=f),b!==D&&(f={}),C!==P){_=void 0,S=void 0,1!==a&&""!==P&&(void 0===c.chains[P]&&(c.chains[P]={}),c.chains[P]=h.hashUtilsCls.unionHash(c.chains[P],g)),g={},void 0===c.structures[N.toString()]&&(c.structures[N.toString()]=[]),c.structures[N.toString()].includes(C)||c.structures[N.toString()].push(C),void 0===c.chainsSeq[C]&&(c.chainsSeq[C]=[]);let t={};t.resi=j,t.name=e,c.chainsSeq[C].push(t)}else{_=v,S=w;let t={};t.resi=j,t.name=e,c.chainsSeq[C].push(t)}}g[a]=1,f[a]=1,P=C,D=b,M=y}else if("CONECT"===$){let e=parseInt(r.substr(6,5));for(let t=0;t<4;++t){let s=parseInt(r.substr([11,16,21,26][t],5));isNaN(s)||void 0!==c.atoms[F[e]]&&c.atoms[F[e]].bonds.push(F[s])}}else $.substr(0,3);else H=r.substr(62).trim(),L=H,""==H&&(H=l?c.defaultPdbId:c.inputid&&-1==c.inputid.indexOf("/")?c.inputid.substr(0,10):c.defaultPdbId),N=this.getStructureId(H,d,n,m),c.molTitle="",c.molTitleHash={},U=!0}c.residues[b]=f,void 0===c.chains[C]&&(c.chains[C]={}),c.chains[C]=h.hashUtilsCls.unionHash2Atoms(c.chains[C],g,c.atoms),c.statefileArray&&c.struct_statefile.push({structure:N,statefile:c.statefileArray[d-1]}),this.adjustSeq(c.chainMissingResidueArray);let j=Object.keys(c.structures);for(let e=0,t=j.length;e<t;++e){let t=j[e];if(t!=H&&(void 0===c.ssbondpnts[t]&&(c.ssbondpnts[t]=[]),void 0!==c.ssbondpnts[H]))for(let e=0,s=c.ssbondpnts[H].length;e<s;++e){let s=c.ssbondpnts[H][e],i=s.indexOf("_"),n=t+s.substr(i);c.ssbondpnts[t].push(n)}}c.bSsbondProvided||this.setSsbond(),u=null;let z,G,V=[],W=new THREE.Vector3(9999,9999,9999),Y=new THREE.Vector3(-9999,-9999,-9999),X=new THREE.Vector3,K=0,J={},Z=[];for(let e in c.hAtoms){let t=c.atoms[e],s=t.coord;X.add(s),W.min(s),Y.max(s),++K,1==K&&(z=t.chain,G=t.resi,Z.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&&(J[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)),z===t.chain&&G===t.resi||(this.refreshBonds(V,Z[0]),Z.splice(0,1),z=t.chain,G=t.resi,V.length=0),V.push(t),"C"!==t.name&&"O3'"!==t.name||Z.push(t)}this.refreshBonds(V,Z[0]);for(let e in J){let t=c.residues[e];for(a in t){let t=c.atoms[a];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=Y,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"===r?(c.oriMaxD=c.maxD,c.center1=c.center):"query"===r&&(c.oriMaxD<c.maxD&&(c.oriMaxD=c.maxD),c.center2=c.center,c.center=new THREE.Vector3(0,0,0)),i?this.getChainCalpha(c.chains,c.atoms):p}refreshBonds(e,t){let s=this.icn3d.icn3dui,i=e.length;for(let n=0;n<i;++n){let l=e[n];for(let t=n+1;t<i;++t){let i=e[t];l.alt===i.alt&&s.utilsCls.hasCovalentBond(l,i)&&(l.bonds.push(i.serial),i.bonds.push(l.serial))}!t||"C"!==t.name&&"O3'"!==t.name||"N"!==l.name&&"P"!==l.name||!s.utilsCls.hasCovalentBond(l,t)||(l.bonds.push(t.serial),t.bonds.push(l.serial))}}adjustSeq(e){let t=this.icn3d;t.icn3dui;for(let s in t.chainsSeq)void 0!==e[s]&&(t.chainsSeq[s]=this.mergeTwoSequences(e[s],t.chainsSeq[s]));this.setResidMapping()}mergeTwoSequences(e,t){let s=e.length,i=t.length,n=parseInt(e[s-1].resi),l=parseInt(t[i-1].resi),r=n>=l?n:l,o=new Array(s+i),a=0,d=0,c=0,h=!1;for(;a<s&&d<i;){let s=parseInt(e[a].resi),i=parseInt(t[d].resi);s>r&&i>r&&(h=!0),s<=r&&i>r?s>i||h?(o[c]=t[d],d++):(o[c]=e[a],a++):s>r&&i<=r?s<=i||h?(o[c]=e[a],a++):(o[c]=t[d],d++):s<=i?(o[c]=e[a],a++):(o[c]=t[d],d++),c++}if(a<s)for(let t=a;t<s;t++)o[c]=e[t],c++;else for(let e=d;e<i;e++)o[c]=t[e],c++;return o}setResidMapping(){let e=this.icn3d;e.icn3dui;for(let t in e.chainsSeq)for(let s=0,i=e.chainsSeq[t].length;s<i;++s){let i=t+"_"+(s+1).toString(),n=t+"_"+e.chainsSeq[t][s].resi;e.ncbi2resid[i]=n,e.resid2ncbi[n]=i}}setSsbond(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in t.chainsSeq){if(e&&!e.hasOwnProperty(i))continue;let n=t.chainsSeq[i],l=i.substr(0,i.indexOf("_"));for(let e=0,t=n.length;e<t;++e)"C"==n[e].name&&(null==s[l]&&(s[l]=[]),s[l].push(i+"_"+n[e].resi))}for(let e in s){let i=s[e];for(let s=0,n=i.length;s<n;++s)for(let n=s+1,l=i.length;n<l;++n){let l,r,o=i[s],a=i[n];for(let e in t.residues[o])if("S"==t.atoms[e].elem){l=t.atoms[e].coord;break}for(let e in t.residues[a])if("S"==t.atoms[e].elem){r=t.atoms[e].coord;break}void 0!==l&&void 0!==r&&(Math.abs(l.x-r.x)>4||Math.abs(l.y-r.y)>4||Math.abs(l.z-r.z)>4||(l.x-r.x)*(l.x-r.x)+(l.y-r.y)*(l.y-r.y)+(l.z-r.z)*(l.z-r.z)<16&&(void 0===t.ssbondpnts[e]&&(t.ssbondpnts[e]=[]),t.ssbondpnts[e].push(o),t.ssbondpnts[e].push(a)))}}}getChainCalpha(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r={};for(let o in e){if(void 0!==i){if(o.split("_")[0]!==i)continue}let a=Object.keys(e[o]),d=[],c=0,h=0;for(let e=0,i=a.length;e<i;++e){let i=t[a[e]];if(n.proteins.hasOwnProperty(a[e])&&"CA"==i.name||n.nucleotides.hasOwnProperty(a[e])&&("O3'"==i.name||"O3*"==i.name)){if(i.resi==h)continue;let e=i.resn.trim().length>3?i.resn.trim().substr(0,3):i.resn.trim();if(!l.parasCls.chargeColors.hasOwnProperty(e))continue;s?i.resi_ori:i.resi,d.push(i.coord.clone()),++c,h=i.resi}}if(c>0){r[t[a[0]].chain]=d}}return{chainresiCalphaHash:r,center:n.center.clone()}}isSecondary(e,t,s,i){if(this.icn3d.icn3dui,i)return!1;if(s){let s=e.substr(e.indexOf("_")+1),i=!1;for(let e=0,n=t.length;e<n;++e)if(s==t[e].substr(t[e].indexOf("_")+1)){i=!0;break}return i}return-1!=$.inArray(e,t)}}class cs{constructor(e){this.icn3d=e}loadCIF(e,t,s,i){let n,l,r=this.icn3d,o=r.icn3dui,a={},d=!1,c={},h={};r.atoms||(i=!1),i?(r.oriNStru=r.structures?Object.keys(r.structures).length:0,l=r.oriNStru,n=r.atoms?Object.keys(r.atoms).length:0):(r.init(),l=0,n=0);let p,m,u,g,f,C,b,y=[],v=[],_=[],w=[],S=[],A=[],x="",k="",O="",R=t||r.defaultPdbId,I=R,E=s?e.split("ENDMDL\n"):[e];for(let e=0,t=E.length;e<t;++e){++l,R=r.defaultPdbId,I=r.loadPDBCls.getStructureId(R,l),y=[],v=[],_=[],w=[],S=[],A=[];let t=s?CIFTools.Text.parse(E[e]):CIFTools.Binary.parse(E[e]);if(t.isError)return void alert("The Binary CIF data can NOT be parsed: "+t.toString());let T=t.result.dataBlocks[0];if(T.getCategory("_entry")&&(R=T.getCategory("_entry").getColumn("id").getString(0),""==R&&(R=i?r.defaultPdbId:r.inputid&&-1==r.inputid.indexOf("/")?r.inputid.substr(0,10):r.defaultPdbId),I=r.loadPDBCls.getStructureId(R,l),r.molTitle="",r.molTitleHash={}),T.getCategory("_struct")){let e=T.getCategory("_struct").getColumn("title").getString(0);e=e.replace(/"/,"'");let t=e.replace(/ALPHAFOLD MONOMER V2.0 PREDICTION FOR /gi,"");r.molTitle+=t.trim()+" ",r.molTitleHash||(r.molTitleHash={}),r.molTitleHash[I]=r.molTitle}if(T.getCategory("_entity_src_gen")&&(r.organism=T.getCategory("_entity_src_gen").getColumn("gene_src_common_name").getString(0)),T.getCategory("_database_2")){let e=T.getCategory("_database_2"),t=e.rowCount;for(let s=0;s<t;++s){let t=e.getColumn("database_id").getString(0),s=e.getColumn("database_code").getString(0);if("EMDB"==t){r.emd=s;break}}}if(T.getCategory("_struct_conf")){r.bSecondaryStructure=!0;let e=T.getCategory("_struct_conf"),t=e.getColumn("conf_type_id"),s=e.getColumn("beg_auth_asym_id"),i=e.getColumn("beg_auth_seq_id");e.getColumn("end_auth_asym_id");let n=e.getColumn("end_auth_seq_id"),l=e.rowCount;for(let e=0;e<l;++e){let l=t.getString(e),r=s.getString(e),o=parseInt(i.getString(e)),a=parseInt(n.getString(e));if("HELX"==l.substr(0,4))for(let e=parseInt(o);e<=parseInt(a);++e){let t=I+"_"+r+"_"+e;w.push(t),e==o&&S.push(t),e==a&&A.push(t)}else if("STRN"==l.substr(0,4))for(let e=o;e<=a;++e){let t=I+"_"+r+"_"+e;y.push(t),e==o&&v.push(t),e==a&&_.push(t)}}t=s=i=n=[]}if(T.getCategory("_struct_sheet_range")){let e=T.getCategory("_struct_sheet_range"),t=e.getColumn("beg_auth_asym_id"),s=e.getColumn("beg_auth_seq_id");e.getColumn("end_auth_asym_id");let i=e.getColumn("end_auth_seq_id"),n=e.rowCount;for(let e=0;e<n;++e){let n=t.getString(e),l=parseInt(s.getString(e)),r=parseInt(i.getString(e));for(let e=l;e<=r;++e){let t=I+"_"+n+"_"+e;y.push(t),e==l&&v.push(t),e==r&&_.push(t)}}t=s=i=[]}if(T.getCategory("_struct_conn")){r.bSsbondProvided=!0;let e=T.getCategory("_struct_conn"),t=e.getColumn("conn_type_id"),s=e.getColumn("ptnr1_auth_asym_id"),i=e.getColumn("ptnr1_label_atom_id"),n=e.getColumn("ptnr1_label_seq_id"),l=e.getColumn("ptnr2_auth_asym_id"),o=e.getColumn("ptnr2_label_atom_id"),a=e.getColumn("ptnr2_label_seq_id"),d=e.rowCount;for(let e=0;e<d;++e){let d=t.getString(e),c=s.getString(e);i.getString(e);let h=I+"_"+c+"_"+n.getString(e),p=l.getString(e);o.getString(e);let m=I+"_"+p+"_"+a.getString(e);"disulf"==d&&(void 0===r.ssbondpnts[I]&&(r.ssbondpnts[I]=[]),r.ssbondpnts[I].push(h),r.ssbondpnts[I].push(m))}t=s=i=n=l=o=a=[]}if(T.getCategory("_exptl")){-1!=T.getCategory("_exptl").getColumn("method").getString(0).indexOf("NMR")&&(d=!0)}if(T.getCategory("_pdbx_struct_oper_list")){let e=T.getCategory("_pdbx_struct_oper_list"),t=e.getColumn("id"),s=e.getColumn("matrix[1][1]"),i=e.getColumn("matrix[1][2]"),n=e.getColumn("matrix[1][3]"),l=e.getColumn("vector[1]"),o=e.getColumn("matrix[2][1]"),a=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]"),m=e.getColumn("matrix[3][3]"),u=e.getColumn("vector[3]"),g=e.rowCount;for(let e=0;e<g;++e){"X0"!=t.getString(e)&&(null==r.biomtMatrices[e]&&(r.biomtMatrices[e]=(new THREE.Matrix4).identity()),r.biomtMatrices[e].set(s.getString(e),i.getString(e),n.getString(e),l.getString(e),o.getString(e),a.getString(e),d.getString(e),c.getString(e),h.getString(e),p.getString(e),m.getString(e),u.getString(e),0,0,0,1))}t=s=i=n=l=o=a=d=c=h=p=m=u=[]}T.getCategory("_citation")&&(r.pmid=T.getCategory("_citation").getColumn("pdbx_database_id_PubMed").getString(0));let P=T.getCategory("_atom_site"),D=P.rowCount,M=!(D>r.maxatomcnt);M||(r.opts.proteins="c alpha trace",r.opts.nucleotides="o3 trace");let F,H=P.getColumn("group_PDB"),L=P.getColumn("label_comp_id"),N=P.getColumn("type_symbol"),q=P.getColumn("label_atom_id"),U=P.getColumn("auth_asym_id"),$=P.getColumn("label_seq_id"),B=P.getColumn("auth_seq_id"),j=P.getColumn("label_alt_id"),z=P.getColumn("B_iso_or_equiv"),G=P.getColumn("Cartn_x"),V=P.getColumn("Cartn_y"),W=P.getColumn("Cartn_z"),Y=P.getColumn("label_asym_id"),X=P.getColumn("pdbx_PDB_model_num"),K={},J="",Z={},Q="";for(let e=0;e<D;++e){let t=X.getString(e);e>0&&t!=Q&&(++l,I="1"==t?R:R+t),Q=t;let s,i=H.getString(e),E=L.getString(e),T=N.getString(e),P=q.getString(e),D=U.getString(e),ee=$.getString(e),te=B.getString(e),se=j.getString(e),ie=z.getString(e),ne=Y.getString(e);if(ee=te,"ATOM"==i?s=3==E.length?"protein":"nucleotide":"WAT"==E||"HOH"==E?(s="solvent",D="Misc"):(s="ligand",D=E),""===D&&(D="A"),!M&&("protein"==s&&("C"!=T||"CA"!=P)||"nucleotide"==s&&"P"!=P))continue;if("B"==se)continue;if(Z[D]=1,++n,"?"!=ee&&"."!=ee&&"0"!=ee||(ee=te),"solvent"==s||"ligand"==s){let e={};K.hasOwnProperty(D)||(K[D]=[]),3!=E.length||"HOH"==E||"WAT"==E?3==E.length&&("O"!=T||"HOH"!=E&&"WAT"!=E)||(e.resi=ee,e.name=o.utilsCls.residueName2Abbr(E),K[D].push(e)):D+"_"+E==F&&J==ne||(e.resi=ee,e.name=o.utilsCls.residueName2Abbr(E),K[D].push(e))}p=I+"_"+D,u=p+"_"+te,m=p+"_"+ee;let le=G.getFloat(e),re=V.getFloat(e),oe=W.getFloat(e),ae={het:"HETATM"==i,serial:n,name:P,alt:se,resn:E,structure:I,chain:D,resi:ee,coord:new THREE.Vector3(le,re,oe),b:ie,elem:T,bonds:[],ss:"coil",ssbegin:!1,ssend:!1};if(ae.het||"C"!==ae.name||(g=n),ae.het||"O"!==ae.name||(C=n),!ae.het&&"N"===ae.name&&void 0!==f&&void 0!==b){let e=r.atoms[f].coord.distanceTo(r.atoms[b].coord),t=ae.coord.x+(r.atoms[f].coord.x-r.atoms[b].coord.x)/e,s=ae.coord.y+(r.atoms[f].coord.y-r.atoms[b].coord.y)/e,i=ae.coord.z+(r.atoms[f].coord.z-r.atoms[b].coord.z)/e;ae.hcoord=new THREE.Vector3(t,s,i)}r.atoms[n]=ae,r.dAtoms[n]=1,r.hAtoms[n]=1,a[n]=1,r.loadPDBCls.isSecondary(m,y,d,!M)?(r.atoms[n].ss="sheet",r.loadPDBCls.isSecondary(m,v,d,!M)&&(r.atoms[n].ssbegin=!0),r.loadPDBCls.isSecondary(m,_,d,!M)&&(r.atoms[n].ssend=!0)):r.loadPDBCls.isSecondary(m,w,d,!M)&&(r.atoms[n].ss="helix",r.loadPDBCls.isSecondary(m,S,d,!M)&&(r.atoms[n].ssbegin=!0),r.loadPDBCls.isSecondary(m,A,d,!M)&&(r.atoms[n].ssend=!0));let de="-";if(de="helix"===r.atoms[n].ss?"H":"sheet"===r.atoms[n].ss?"E":!r.atoms[n].het&&o.parasCls.residueColors.hasOwnProperty(r.atoms[n].resn.toUpperCase())?"c":"o",r.secondaries[m]=de,u!==O||D+"_"+E!=F||J!=ne){let e=o.utilsCls.residueName2Abbr(E);if(r.residueId2Name[m]=e,1!==n&&""!==k&&(r.residues[k]=h),m!==k&&(h={}),p!==x){f=void 0,b=void 0,1!==n&&""!==x&&(void 0===r.chains[x]&&(r.chains[x]={}),r.chains[x]=o.hashUtilsCls.unionHash(r.chains[x],c)),c={},void 0===r.structures[I.toString()]&&(r.structures[I.toString()]=[]),r.structures[I.toString()].includes(p)||r.structures[I.toString()].push(p),void 0===r.chainsSeq[p]&&(r.chainsSeq[p]=[]);let t={};t.resi=ee,t.name=e,r.chainsSeq[p].push(t)}else{f=g,b=C;let t={};t.resi=ee,t.name=e,r.chainsSeq[p].push(t)}}c[n]=1,h[n]=1,x=p,k=m,O=u,F=D+"_"+E,J=ne}r.residues[m]=h,void 0===r.chains[p]&&(r.chains[p]={}),r.chains[p]=o.hashUtilsCls.unionHash2Atoms(r.chains[p],c,r.atoms),H=L=N=q=U=$=B=j=z=G=V=W=Y=[];let ee={};if(T.getCategory("_pdbx_poly_seq_scheme")){let e=T.getCategory("_pdbx_poly_seq_scheme"),t=e.getColumn("seq_id"),s=e.getColumn("pdb_seq_num"),i=e.getColumn("mon_id"),n=e.getColumn("pdb_strand_id"),l=e.rowCount,r="",a=[];for(let e=0;e<l;++e){t.getString(e);let l=s.getString(e),d=i.getString(e),c=n.getString(e);c!=r&&e>0&&(ee[r]=a,a=[]),a.push({resi:l,name:o.utilsCls.residueName2Abbr(d)}),r=c}ee[r]=a,t=s=i=n=[]}this.setSeq(I,Z,ee,K)}let T=Object.keys(r.structures);for(let e=0,t=T.length;e<t;++e){let t=T[e];if(t!=R&&(void 0===r.ssbondpnts[t]&&(r.ssbondpnts[t]=[]),void 0!==r.ssbondpnts[R]))for(let e=0,s=r.ssbondpnts[R].length;e<s;++e){let s=r.ssbondpnts[R][e],i=s.indexOf("_"),n=t+s.substr(i);r.ssbondpnts[t].push(n)}}r.bSsbondProvided||r.loadPDBCls.setSsbond();let P,D,M=[],F=new THREE.Vector3(9999,9999,9999),H=new THREE.Vector3(-9999,-9999,-9999),L=new THREE.Vector3,N=0,q={},U=[];for(let e in r.hAtoms){let t=r.atoms[e],s=t.coord;L.add(s),F.min(s),H.max(s),++N,1==N&&(P=t.chain,D=t.resi,U.push(t)),t.het?t.het&&("HOH"===t.resn||"WAT"===t.resn||"SOL"===t.resn?r.water[t.serial]=1:-1!==$.inArray(t.resn,o.parasCls.ionsArray)||t.elem.trim()===t.resn.trim()?r.ions[t.serial]=1:r.chemicals[t.serial]=1,t.color=o.parasCls.atomColors[t.elem]):-1!==$.inArray(t.resn,o.parasCls.nucleotidesArray)?(r.nucleotides[t.serial]=1,"O3'"!==t.name&&"O3*"!==t.name||(r.nucleotidesO3[t.serial]=1,r.secondaries[t.structure+"_"+t.chain+"_"+t.resi]="o"),-1===o.parasCls.nuclMainArray.indexOf(t.name)&&(r.ntbase[t.serial]=1)):("P"===t.elem&&(q[t.structure+"_"+t.chain+"_"+t.resi]=1),r.proteins[t.serial]=1,"CA"===t.name&&(r.calphas[t.serial]=1),"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&(r.sidec[t.serial]=1)),P===t.chain&&D===t.resi||(r.loadPDBCls.refreshBonds(M,U[0]),U.splice(0,1),P=t.chain,D=t.resi,M.length=0),M.push(t),"C"!==t.name&&"O3'"!==t.name||U.push(t)}r.loadPDBCls.refreshBonds(M,U[0]);for(let e in q){let t=r.residues[e];for(n in t){let t=r.atoms[n];t.het=!0,r.chemicals[t.serial]=1,r.secondaries[e]="o",delete r.proteins[t.serial],"CA"===t.name&&delete r.calphas[t.serial],"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&delete r.sidec[t.serial]}}return r.pmin=F,r.pmax=H,r.cnt=N,r.center=r.ParserUtilsCls.getGeoCenter(r.pmin,r.pmax),r.maxD=r.ParserUtilsCls.getStructureSize(r.atoms,r.pmin,r.pmax,r.center),r.maxD<5&&(r.maxD=5),r.oriMaxD=r.maxD,r.oriCenter=r.center.clone(),a}setSeq(e,t,s,i){let n=this.icn3d;n.icn3dui;for(let l in t){let t=e+"_"+l;i.hasOwnProperty(l)?n.chainsSeq[t]=i[l]:n.chainsSeq[t]=s[l]}n.loadPDBCls.setResidMapping()}}class hs{constructor(e){this.icn3d=e}async vastplusAlign(e,t,s){let i=this.icn3d;i.icn3dui;let n=this,l=[],r=[];if(2!=e.length)return void console.log("VAST+ needs two input structures...");let o=e[0],a=e[1],d=[],c=[];for(let e=0,t=i.structures[o].length;e<t;++e){let t=i.structures[o][e];i.proteins.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.chains[t]).serial)&&d.push(t)}for(let e=0,t=i.structures[a].length;e<t;++e){let t=i.structures[a][e];i.proteins.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.chains[t]).serial)&&c.push(t)}let h={},p=0;for(let e=0,t=d.length;e<t;++e){let t=d[e];for(let i=0,n=c.length;i<n;++i){let n=c[i];if(e==i){let d=this.setAlignment(o,a,t,n,s);l.push(d),r.push(t+","+n),h[p]=[e,i],++p}}}for(let e=0,t=d.length;e<t;++e){let t=d[e];for(let i=0,n=c.length;i<n;++i){let n=c[i];if(e!=i){let d=this.setAlignment(o,a,t,n,s);l.push(d),r.push(t+","+n),h[p]=[e,i],++p}}}let m=Promise.allSettled(l);try{let e=await m;n.clusterAlignment(e,r,h,t),i.ParserUtilsCls.hideLoading(),await i.pdbParserCls.loadPdbDataRender(!0)}catch(e){alert("There are some problems in aligning the chains...")}}setAlignment(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=r.htmlCls.baseUrl+"tmalign/tmalign.cgi",a=n?r.hashUtilsCls.intHash(l.hAtoms,l.chains[s]):l.chains[s],d=n?r.hashUtilsCls.intHash(l.hAtoms,l.chains[i]):l.chains[i],c=l.saveFileCls.getAtomPDB(a,void 0,void 0,void 0,void 0,e),h={pdb_query:l.saveFileCls.getAtomPDB(d,void 0,void 0,void 0,void 0,t),pdb_target:c};return r.getAjaxPostPromise(o,h)}async realignOnVastplus(){let e=this.icn3d,t=e.icn3dui,s=[];for(let i in e.structures){let n=e.structures[i];for(let i=0,l=n.length;i<l;++i){let l=n[i],r=t.hashUtilsCls.intHash(e.hAtoms,e.chains[l]),o=e.firstAtomObjCls.getFirstAtomObj(r);o&&(s[o.structure]=1)}}t.cfg.aligntool="tmalign",await e.vastplusCls.vastplusAlign(Object.keys(s),2,!0)}getResisFromSegs(e){this.icn3d.icn3dui;let t=[],s=[];for(let i=0,n=e.length;i<n;++i){let n=e[i];t.push(n.t_start+"-"+n.t_end),s.push(n.q_start+"-"+n.q_end)}return{resiArray_t:t,resiArray_q:s}}clusterAlignment(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=[];for(let s=0,i=t.length;s<i;++s){let t=e[s].value;r.push(t)}let o=[],a=0,d=!1;for(let e=0,s=t.length;e<s;++e){let s=[];r[e].length>0&&(d=!0);for(let n=0,l=t.length;n<l;++n){let t=this.RotMatrixTransDist(r[e][0],r[n][0],1,i),l=e==n?0:0==r[e].length||0==r[n].length?1:t;l>a&&(a=l),s.push(l)}o.push(s)}if(!d)return void(n.bRender&&alert("These structures can not be aligned..."));a<1e-6&&(a=1);for(let e=0,s=t.length;e<s;++e)for(let s=0,i=t.length;s<i;++s)o[e][s]=o[e][s]/a;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,i=t.join(","),n=s[parseInt(t[0])],l=o[n[0]][n[1]];p[i]?l<p[i]&&(p[i]=l):p[i]=l}let m=Object.keys(p).sort(((e,t)=>p[e]<p[t]||parseInt(1e4*p[e])==parseInt(1e4*p[t])&&e<t?-1:1)),u=parseInt($("#"+l.pre+"maxrmsd").val());u||(u=30),d=!1;for(let e=0,s=m.length;e<s;++e){let s=m[e].split(",");n.opts.color="grey",n.setColorCls.setColorByOptions(n.opts,n.atoms);let i,o,a=[],c=[],h={};$("#"+n.pre+"dl_sequence2").html("");for(let e=0,d=s.length;e<d;++e){let d=parseInt(s[e]),p=r[d][0].segs,m=t[d].split(",");i=m[0],o=m[1];let u=this.getResisFromSegs(p),g=u.resiArray_t,f=u.resiArray_q,C=n.realignParserCls.getSeqCoorResid(g,i);a=a.concat(C.coor);let b=n.realignParserCls.getSeqCoorResid(f,o);c=c.concat(b.coor),n.qt_start_end=[],n.qt_start_end.push(p);let y=!0,v=!0,_=n.chainalignParserCls.setMsa(m,y,v);h=l.hashUtilsCls.unionHash(h,_)}n.hAtoms=l.hashUtilsCls.cloneHash(h);let p=c.length<a.length?c.length:a.length;if(!(p<4)&&(p>=4&&(n.rmsd_suprTmp=l.rmsdSuprCls.getRmsdSuprCls(c,a,p),void 0!==n.rmsd_suprTmp.rot))){let e=n.rmsd_suprTmp.rot;if(null===e[0])continue;let i=n.rmsd_suprTmp.trans1,r=n.rmsd_suprTmp.trans2,a=n.rmsd_suprTmp.rmsd;if(a<u){d=!0,l.htmlCls.clickMenuCls.setLogCmd("realignment RMSD: "+a.toPrecision(4),!1),$("#"+n.pre+"dl_rmsd_html").html("<br><b>Realignment RMSD</b>: "+a.toPrecision(4)+" &#8491;<br><br>"),l.cfg.bSidebyside||l.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(i),n.t_trans_add.push({x:-r.x,y:-r.y,z:-r.z}),l.cfg.aligntool="vast";//!= 'tmalign';
7
- let c=0,h="query",p=o.substr(0,o.indexOf("_")),m=!0;n.chainalignParserCls.transformStructure(p,c,h,m);let u="";for(let e=0,i=s.length;e<i;++e)u+=t[parseInt(s[e])]+"; ";l.bNode||console.log("Selected the alignment: "+u);break}{let e="";for(let i=0,n=s.length;i<n;++i)e+=t[parseInt(s[i])]+"; ";l.bNode||console.log("skipped the alignment: "+e)}}}d||n.bRender&&alert("These structures can not be aligned...")}RotMatrixTransDist(e,t,s,i){this.icn3d.icn3dui;if(!e||!t)return s;let n=this.GetRotMatrix(e,1,i),l=this.GetRotMatrix(t,1,i),r=[],o=[],a=[],d=[];r[0]=n[9],r[1]=n[10],r[2]=n[11],o[0]=n[12],o[1]=n[13],o[2]=n[14],a[0]=l[9],a[1]=l[10],a[2]=l[11],d[0]=l[12],d[1]=l[13],d[2]=l[14];let c=[],h=[];c[0]=o[0]-d[0],c[1]=o[1]-d[1],c[2]=o[2]-d[2],h[0]=r[0]-a[0],h[1]=r[1]-a[1],h[2]=r[2]-a[2];let p,m,u=0;if(u+=Math.pow(c[0],2),u+=Math.pow(c[1],2),u+=Math.pow(c[2],2),p=Math.sqrt(u),u=0,u+=Math.pow(h[0],2),u+=Math.pow(h[1],2),u+=Math.pow(h[2],2),m=Math.sqrt(u),2!=i){if(p<1e-10||m<1e-10)return s}else if(m<1e-10)return s;if(Math.abs(p-m)>8)return s;let g=[];g[0]=n[0]*r[0]+n[1]*r[1]+n[2]*r[2],g[1]=n[3]*r[0]+n[4]*r[1]+n[5]*r[2],g[2]=n[6]*r[0]+n[7]*r[1]+n[8]*r[2],g[0]-=n[0]*a[0]+n[1]*a[1]+n[2]*a[2],g[1]-=n[3]*a[0]+n[4]*a[1]+n[5]*a[2],g[2]-=n[6]*a[0]+n[7]*a[1]+n[8]*a[2];let f=0;return f=c[0]*g[0],f+=c[1]*g[1],f+=c[2]*g[2],f/=p*m,f<.866?s:(g[0]=l[0]*r[0]+l[1]*r[1]+l[2]*r[2],g[1]=l[3]*r[0]+l[4]*r[1]+l[5]*r[2],g[2]=l[6]*r[0]+l[7]*r[1]+l[8]*r[2],g[0]-=l[0]*a[0]+l[1]*a[1]+l[2]*a[2],g[1]-=l[3]*a[0]+l[4]*a[1]+l[5]*a[2],g[2]-=l[6]*a[0]+l[7]*a[1]+l[8]*a[2],f=c[0]*g[0],f+=c[1]*g[1],f+=c[2]*g[2],f/=p*m,f<.866?s:(u=0,u+=Math.pow(e.q_rotation.x1-t.q_rotation.x1,2),u+=Math.pow(e.q_rotation.y1-t.q_rotation.y1,2),u+=Math.pow(e.q_rotation.z1-t.q_rotation.z1,2),u+=Math.pow(e.q_rotation.x2-t.q_rotation.x2,2),u+=Math.pow(e.q_rotation.y2-t.q_rotation.y2,2),u+=Math.pow(e.q_rotation.z2-t.q_rotation.z2,2),u+=Math.pow(e.q_rotation.x3-t.q_rotation.x3,2),u+=Math.pow(e.q_rotation.y3-t.q_rotation.y3,2),u+=Math.pow(e.q_rotation.z3-t.q_rotation.z3,2),Math.sqrt(u)))}GetRotMatrix(e,t,s){this.icn3d.icn3dui;let i=[];return i&&(i[0]=e.q_rotation.x1/t,i[1]=e.q_rotation.y1/t,i[2]=e.q_rotation.z1/t,i[3]=e.q_rotation.x2/t,i[4]=e.q_rotation.y2/t,i[5]=e.q_rotation.z2/t,i[6]=e.q_rotation.x3/t,i[7]=e.q_rotation.y3/t,i[8]=e.q_rotation.z3/t,2!=s?(i[9]=e.t_trans_add.x/t,i[10]=e.t_trans_add.y/t,i[11]=e.t_trans_add.z/t,i[12]=-e.q_trans_sub.x/t,i[13]=-e.q_trans_sub.y/t,i[14]=-e.q_trans_sub.z/t):(i[9]=-e.q_trans_add.x/t,i[10]=-e.q_trans_add.y/t,i[11]=-e.q_trans_add.z/t,i[12]=0,i[13]=0,i[14]=0)),i}cbu_dist(e,t,s){return e<t?s[e][t]:s[t][e]}compareFloat(e,t,s){let i=e[t].dist,n=e[s].dist;return parseInt(1e4*i)==parseInt(1e4*n)?0:parseInt(1e4*i)<parseInt(1e4*n)?-1:1}clusterLinkage(e,t,s){let i,n,l,r,o,a,d,c,h=this.icn3d,p=h.icn3dui,m=[],u=t.length;for(i=0;i<2*u-1;++i)m[i]={},m[i].leaves=[];let g=[];for(i=0;i<2*u-1;++i)for(g[i]=[],n=0;n<2*u-1;++n)g[i][n]=2;for(i=0;i<u;++i)for(n=i;n<u;++n)g[i][n]=t[i][n];let f={},C={},b={};for(r=u,o=u,i=0;i<u;++i){for(d=2,n=0;n<u;++n){let e=s?parseInt(1e4*this.cbu_dist(i,n,g))<=parseInt(1e4*d):parseInt(1e4*this.cbu_dist(i,n,g))<parseInt(1e4*d);n!=i&&e&&(d=this.cbu_dist(i,n,g),r=i,o=n)}f[r]=o,b[r]=d}let y=[];for(a=0;a<u;++a)m[a].child1=-2,m[a].child2=-2,m[a].parent=a,m[a].dist=0,m[a].leaves.push([a]),y[a]=0;let v=Object.keys(h.structures),_=h.structures[v[0]].length,w=h.structures[v[1]].length,S=_<w?_:w;for(a=u;a<2*u-1;++a){for(l in d=2,f)c=b[l],c<d&&(d=c,r=l,o=f[l]);let e=d;for(m[a].child1=r<u?r:-r,m[a].child2=o<u?o:-o,m[a].parent=-1*a,m[r].dist=e-y[r],m[o].dist=e-y[o],y[a]=e,n=0;n<2*u-1;++n){let e=this.cbu_dist(r,n,g),t=this.cbu_dist(o,n,g);a<n?g[a][n]=e<t?e:t:g[n][a]=e<t?e:t}for(n=0;n<2*u-1;++n)r<n?g[r][n]=2:g[n][r]=2,o<n?g[o][n]=2:g[n][o]=2;let t=4;if(m[r].leaves.length<t*S&&m[o].leaves.length<t*S){m[a].leaves=[];for(let e=0,t=m[r].leaves.length;e<t;++e)for(let t=0,s=m[o].leaves.length;t<s;++t)m[a].leaves.push(m[r].leaves[e].concat(m[o].leaves[t])),m[a].leaves.push(m[o].leaves[t].concat(m[r].leaves[e]));m[r].leaves=[],m[o].leaves=[]}for(l in delete f[r],delete f[o],delete b[r],delete b[o],C=p.hashUtilsCls.cloneHash(f),C)C[l]!=r&&C[l]!=o||(delete f[l],f[l]=a);let s=2*u;for(d=2,n=0;n<2*u-1;++n)n!=a&&this.cbu_dist(a,n,g)<d&&(d=this.cbu_dist(a,n,g),s=n);f[a]=s,b[a]=d}return a==2*u-1&&(m[a-1].parent=-1,m[a-1].dist=0),m}GetChainMappings(e,t){this.icn3d.icn3dui;let s,i,n=[];t.length;let l=this.getClusters(e,!0).clusters,r=l.length;for(let e=0;e<r;++e){let r=l[e];for(let e=0,l=r.length;e<l;++e){let l={nodeArray:[]},o={},a={};for(let n=0,d=r[e].length;n<d;++n){let d=r[e][n],c=t[d].split(",");s=c[0],i=c[1],o.hasOwnProperty(s)||a.hasOwnProperty(i)||(l.nodeArray.push(d.toString().padStart(5,"0")),o[s]=1,a[i]=1)}n.push(l)}}return n}getClusters(e,t){this.icn3d.icn3dui;let s=[],i=[],n=0,l=e.length,r=t?0:1;for(;n<l;++n)e[n].leaves.length>r&&(s.push(e[n].leaves),i.push(e[n].dist));return{clusters:s,scores:i}}}class ps{constructor(e){this.icn3d=e}async applyCommand(e){let t=this.icn3d,s=t.icn3dui;t.bAddCommands=!1;let i=e.split("|||")[0].split("%7C%7C%7C")[0].replace(/\s+/g," ").trim(),n=i.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 s=""!==e;await t.shareLinkCls.shareLink(!0,s)}),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)s.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)s.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("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(" "),s=n.substr(e+1);"all"==s?t.annotationCls.hideAnnoTabAll():"custom"==s?t.annotationCls.hideAnnoTabCustom():"clinvar"==s?t.annotationCls.hideAnnoTabClinvar():"snp"==s?t.annotationCls.hideAnnoTabSnp():"cdd"==s?t.annotationCls.hideAnnoTabCdd():"3ddomain"==s?t.annotationCls.hideAnnoTab3ddomain():"site"==s?t.annotationCls.hideAnnoTabSite():"ptm"==s?t.annotationCls.hideAnnoTabPTM():"interaction"==s?t.annotationCls.hideAnnoTabInteraction():"ssbond"==s?t.annotationCls.hideAnnoTabSsbond():"crosslink"==s?t.annotationCls.hideAnnoTabCrosslink():"transmembrane"==s&&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 THREE.Vector3(1,0,0),s=.5*Math.PI;t.transformCls.setRotation(e,s)}else if("rotate y"==n){let e=new THREE.Vector3(0,1,0),s=.5*Math.PI;t.transformCls.setRotation(e,s)}else if("rotate z"==n){let e=new THREE.Vector3(0,0,1),s=.5*Math.PI;t.transformCls.setRotation(e,s)}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===s.cfg.mmdbid&&void 0===s.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=i.substr(e.length),l=n.indexOf(" "),r=n.substr(0,l).split(",");s.cfg.resdef=n.substr(l+1).replace(/:/gi,";"),await t.realignParserCls.realignChainOnSeqAlign(void 0,r,!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==i.indexOf("define helix sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"helix")}else if(0==i.indexOf("define sheet sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"sheet")}else if(0==i.indexOf("define coil sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"coil")}else if(0==i.indexOf("define iganchor sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"iganchor")}else if(0==i.indexOf("define igstrand sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igstrand")}else if(0==i.indexOf("define igloop sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igloop")}else if(0==i.indexOf("select interaction")){let e=i.substr(i.lastIndexOf(" ")+1).split(",");if(null!==e){let s=e[0].split("_")[0];t.b2DShown||t.ParserUtilsCls.download2Ddgm(s.toUpperCase()),t.diagram2dCls.selectInteraction(e[0],e[1])}}else if(0==i.indexOf("select saved atoms")||0==i.indexOf("select sets")){i=i.replace(/aligned_protein/g,"protein_aligned"),t.bDefinedSets||(t.definedSetsCls.setPredefinedInMenu(),t.bDefinedSets=!0);let e=i.split(" | "),s=e[0].replace(/,/g," or "),n=19;0==i.indexOf("select sets")&&(n=12);let l=s.substr(n),r=l;2==e.length&&(r=e[1].substr(5)),t.definedSetsCls.selectCombinedSets(l,r)}else if(-1!==i.indexOf("select chain")){let e=i.substr(i.lastIndexOf(" ")+1).split(",");for(let s=0,i=e.length;s<i;++s)t.selectionCls.selectAChain(e[s],e[s],!1)}else if(-1!==i.indexOf("select alignChain")){let e=i.substr(i.lastIndexOf(" ")+1).split(",");for(let s=0,i=e.length;s<i;++s)t.selectionCls.selectAChain(e[s],"align_"+e[s],!0)}else if(0==i.indexOf("select zone cutoff")){let e=this.getThresholdNameArrays(i);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",s.htmlCls.GREYD),$("#"+t.pre+"titlelink").css("color",s.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==i.indexOf("set thickness")){let e=n.split(" | ");t.bSetThickness=!0;for(let s=1,i=e.length;s<i;++s){let i=e[s].split(" "),n=i[0],l=parseFloat(i[1]);"linerad"!=n||isNaN(l)||(t.lineRadius=l),"coilrad"!=n||isNaN(l)||(t.coilWidth=l),"stickrad"!=n||isNaN(l)||(t.cylinderRadius=l),"crosslinkrad"!=n||isNaN(l)||(t.crosslinkRadius=l),"tracerad"!=n||isNaN(l)||(t.traceRadius=l),"ballscale"!=n||isNaN(l)||(t.dotSphereScale=l),"ribbonthick"!=n||isNaN(l)||(t.ribbonthickness=l),"proteinwidth"!=n||isNaN(l)||(t.helixSheetWidth=l),"nucleotidewidth"!=n||isNaN(l)||(t.nucleicAcidWidth=l)}t.drawCls.draw()}else if(0==i.indexOf("set light")){let e=n.split(" | ");for(let s=1,i=e.length;s<i;++s){let i=e[s].split(" "),n=i[0],l=parseFloat(i[1]);"light1"==n&&(t.light1=l),"light2"==n&&(t.light2=l),"light3"==n&&(t.light3=l)}t.drawCls.draw()}else if(0==i.indexOf("set shininess")){let e=n.lastIndexOf(" ");t.shininess=parseFloat(n.substr(e+1)),t.drawCls.draw()}else if(0==i.indexOf("set glycan")){let e=n.lastIndexOf(" ");t.bGlycansCartoon=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==i.indexOf("set membrane")){let e=n.lastIndexOf(" ");t.bMembrane=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==i.indexOf("set cmdwindow")){let e=n.lastIndexOf(" "),t=parseInt(n.substr(e+1));s.htmlCls.setMenuCls.setLogWindow(!0,t)}else if(0==n.indexOf("set highlight color")){let e=n.substr(20);"yellow"===e?(t.hColor=s.parasCls.thr(16776960),t.matShader=t.setColorCls.setOutlineColor("yellow")):"green"===e?(t.hColor=s.parasCls.thr(65280),t.matShader=t.setColorCls.setOutlineColor("green")):"red"===e&&(t.hColor=s.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(" | "),s=e[1].split(" "),i=e[2].split(" "),l=e[3].substr(e[3].lastIndexOf(" ")+1),r="true"===e[4].substr(e[4].lastIndexOf(" ")+1),o=e[5].substr(e[5].lastIndexOf(" ")+1),a=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(s[1]),parseFloat(s[3]),parseFloat(s[5]),parseFloat(i[1]),parseFloat(i[3]),parseFloat(i[5]),l,r,o,parseFloat(a),parseFloat(d)),t.drawCls.draw()}else if(0==n.indexOf("add sphere"))this.addShape(i,"sphere"),t.shapeCmdHash[i]=1;else if(0==n.indexOf("add cube"))this.addShape(i,"cube"),t.shapeCmdHash[i]=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==i.indexOf("add label")){let e,n,l,r,o,a,d,c=i.split(" | "),h=c[0].substr("add label".length+1),p=!1;for(let t=1,s=c.length;t<s;++t){let s=c[t].split(" ");"x"==s[0]?(p=!0,e=parseFloat(s[1]),n=parseFloat(s[3]),l=parseFloat(s[5])):"size"==s[0]?r=c[t].substr(c[t].lastIndexOf(" ")+1):"color"==s[0]?o=c[t].substr(c[t].lastIndexOf(" ")+1):"background"==s[0]?a=c[t].substr(c[t].lastIndexOf(" ")+1):"type"==s[0]&&(d=c[t].substr(c[t].lastIndexOf(" ")+1))}if(!p){let i=t.applyCenterCls.centerAtoms(s.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms));e=parseFloat(i.center.x),n=parseFloat(i.center.y),l=parseFloat(i.center.z)}t.analysisCls.addLabel(h,e,n,l,r,o,a,d),t.drawCls.draw()}else if(0==i.indexOf("msa")){let e=i.split(" | ")[1].split(" ");t.targetGapHash={};for(let s=0,i=e.length;s<i;++s){let i=e[s].split("_");t.targetGapHash[parseInt(i[0])]={from:parseInt(i[1]),to:parseInt(i[2])}}await t.annotationCls.resetAnnoAll()}else if(0==i.indexOf("add track")){let e,s,n,l=i.split(" | "),r=l[1].substr(8),o=l[2].substr(6),a=l[3].substr(5);l.length>=5&&(e=l[4].substr(5)),l.length>=6&&(s=l[5].substr(6)),l.length>=7&&(n=l[6].substr(4)),$("#"+t.pre+"anno_custom")[0]&&($("#"+t.pre+"anno_custom")[0].checked=!0),$("[id^="+t.pre+"custom]").show(),"0"==s&&(s=void 0),t.addTrackCls.checkGiSeq(r,o,a,e,s,n,0)}else if(0==n.indexOf("remove one stabilizer")){let e=n.split(" | ")[1].split(" "),s=[];s.push(parseInt(e[0])),s.push(parseInt(e[1])),t.threeDPrintCls.removeOneStabilizer(s),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 s=parseFloat(e[3]),i=parseFloat(e[4]);t.selectionCls.selectBtwPlanes(s,i)}}else if(0==n.indexOf("adjust membrane z-axis")){let e=n.split(" ");if(5==e.length){let s=parseFloat(e[3]),i=parseFloat(e[4]);t.selectionCls.adjustMembrane(s,i)}}else if(0==n.indexOf("toggle membrane"))t.selectionCls.toggleMembrane();else if(0==i.indexOf("calc buried surface")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),i=s[1].split(",");t.analysisCls.calcBuriedSurface(e,i)}}}else if(0==i.indexOf("dist ")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),i=s[1].split(",");t.analysisCls.measureDistTwoSets(e,i)}}}else if(0==i.indexOf("disttable")){let e=i.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),n=i[1].split(",");t.analysisCls.measureDistManySets(e,n),s.htmlCls.dialogCls.openDlg("dl_disttable","Distances among the sets")}}}else if(0==i.indexOf("angletable")){let e=i.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),n=i[1].split(",");t.analysisCls.measureAngleManySets(e,n),s.htmlCls.dialogCls.openDlg("dl_angletable","Angles among the sets")}}}else if(0==i.indexOf("display interaction 3d")||0==i.indexOf("view interaction pairs")||0==i.indexOf("save1 interaction pairs")||0==i.indexOf("save2 interaction pairs")||0==i.indexOf("line graph interaction pairs")||0==i.indexOf("scatterplot interaction pairs")||0==i.indexOf("ligplot interaction pairs")){let e=i.split(" | ");if(e.length>=3){let s=e[1].split(" ");if(2==s.length){let n,l,r=s[0].split(","),o=s[1].split(","),a=-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"),m=-1!==e[2].indexOf("pi-stacking");if(e.length>=4&&(n="true"==e[3]),e.length>=5){let s=e[4].split(" ");s.length>=4&&($("#"+t.pre+"hbondthreshold").val(s[1]),$("#"+t.pre+"saltbridgethreshold").val(s[2]),$("#"+t.pre+"contactthreshold").val(s[3]),7==s.length&&($("#"+t.pre+"halogenthreshold").val(s[4]),$("#"+t.pre+"picationthreshold").val(s[5]),$("#"+t.pre+"pistackingthreshold").val(s[6])))}0==i.indexOf("display interaction 3d")?l="3d":0==i.indexOf("view interaction pairs")?l="view":0==i.indexOf("save1 interaction pairs")?l="save1":0==i.indexOf("save2 interaction pairs")?l="save2":0==i.indexOf("line graph interaction pairs")?l="linegraph":0==i.indexOf("scatterplot interaction pairs")?l="scatterplot":0==i.indexOf("ligplot interaction pairs")&&(l="ligplot"),await t.viewInterPairsCls.viewInteractionPairs(r,o,n,l,a,d,c,h,p,m)}}}else if(0==i.indexOf("export pairs")){let e=i.split(" | ");if(3==e.length){let i=e[1].split(" ");if(2==i.length){let n=i[0].split(","),l=i[1].split(","),r=e[2].split(" ")[1];t.showInterCls.pickCustomSphere(r,n,l,t.bSphereCalc),t.bSphereCalc=!0;let o=t.viewInterPairsCls.exportSpherePairs(),a=Object.keys(s.utilsCls.getHlStructures()).join(",");t.saveFileCls.saveFile(a+"_sphere_pairs.html","html",o)}}}else if(0==n.indexOf("graph label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+s.svgid+"_label").val(t),$("#"+s.svgid+" text").removeClass(),$("#"+s.svgid+" text").addClass(t)}else if(0==n.indexOf("cartoon label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+s.svgid_ct+"_label").val(t),$("#"+s.svgid_ct+" text").removeClass(),$("#"+s.svgid_ct+" text").addClass(t)}else if(0==n.indexOf("line graph scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.linegraphid+"_scale").val(i),$("#"+s.linegraphid).attr("width",(t.linegraphWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("scatterplot scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.scatterplotid+"_scale").val(i),$("#"+s.scatterplotid).attr("width",(t.scatterplotWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("ligplot scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.ligplotid+"_scale").val(i),t.ligplotScale=parseFloat(i),$("#"+s.ligplotid).attr("width",(t.ligplotWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("contactmap scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.contactmapid+"_scale").val(i),$("#"+s.contactmapid).attr("width",(t.contactmapWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("alignerrormap scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.alignerrormapid+"_scale").val(i),$("#"+s.alignerrormapid).attr("width",(t.alignerrormapWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("graph force")){let e=n.lastIndexOf(" ");s.htmlCls.force=parseInt(n.substr(e+1)),$("#"+s.svgid+"_force").val(s.htmlCls.force),t.getGraphCls.handleForce()}else if(0==n.indexOf("hide edges")){let e=n.lastIndexOf(" ");s.htmlCls.hideedges=parseInt(n.substr(e+1)),$("#"+s.svgid+"_hideedges").val(s.htmlCls.hideedges),s.htmlCls.hideedges?(s.htmlCls.contactInsideColor="FFF",s.htmlCls.hbondInsideColor="FFF",s.htmlCls.ionicInsideColor="FFF"):(s.htmlCls.contactInsideColor="DDD",s.htmlCls.hbondInsideColor="AFA",s.htmlCls.ionicInsideColor="8FF"),void 0!==t.graphStr&&t.bRender&&s.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==i.indexOf("your note")){let e=i.split(" | ");t.yournote=e[1],$("#"+t.pre+"yournote").val(t.yournote),s.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 s=parseFloat(e[1].split(" ")[1]),i=e[2].split(" ")[1];await t.contactMapCls.contactMap(s,i)}}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==i.indexOf("set color spectrum")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!0;t.setColorCls.setColorAcrossSets(s,i)}}else if(0==i.indexOf("set residues color spectrum")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!0;t.setColorCls.setColorBySets(s,i)}}else if(0==i.indexOf("set color rainbow")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!1;t.setColorCls.setColorAcrossSets(s,i)}}else if(0==i.indexOf("set residues color rainbow")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!1;t.setColorCls.setColorBySets(s,i)}}else if(0==i.indexOf("color")){let e=i.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()]=s.parasCls.thr("#"+t.customResidueColors[e])}else if("align custom"==n&&3==e.length){let s=e[1],i=e[2].split(", ");t.queryresi2score={},t.queryresi2score[s]={};for(let e=0,n=i.length;e<n;++e){let n=i[e].split(" ");t.queryresi2score[s][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==i.indexOf("remove legend"))$("#"+s.pre+"legend").hide();else if(0==i.indexOf("custom tube")){let e=i.split(" | ");this.setQueryresi2score(e),t.setOptionCls.setStyle("proteins","custom tube")}else if(0==n.indexOf("style")){let e=n.substr(n.indexOf(" ")+1),s=e.substr(0,e.indexOf(" ")),i=e.substr(e.indexOf(" ")+1);t.setOptionCls.setStyle(s,i)}else if(0==n.indexOf("window")){let e=n.substr(n.indexOf(" ")+1);setTimeout((function(){"aligned sequences"==e?s.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"):"interaction table"==e?s.htmlCls.dialogCls.openDlg("dl_allinteraction","Show interactions"):"interaction graph"==e?s.htmlCls.dialogCls.openDlg("dl_linegraph","Show interactions between two lines of residue nodes"):"interaction scatterplot"==e?s.htmlCls.dialogCls.openDlg("dl_scatterplot","Show interactions as scatterplot"):"force-directed graph"==e&&s.htmlCls.dialogCls.openDlg("dl_graph","Force-directed graph")}),1e3)}else if(0==n.indexOf("set theme")){let e=n.substr(n.lastIndexOf(" ")+1);s.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,s.htmlCls.clickMenuCls.setClashedResidues(),t.annoDomainCls.showHideClashedResidues())}else if(0==n.indexOf("save html")){let e=n.substr(n.lastIndexOf(" ")+1);s.htmlCls.eventsCls.saveHtml(e)}else if(0==n.indexOf("resdef"))s.cfg.resdef=n.substr(n.indexOf(" ")+1);else if(0==n.indexOf("vast_search_chainid")){t.chainidArray=i.substr(i.indexOf(" ")+1).split(",");let e=!0,s=!0;await t.realignParserCls.realignChainOnSeqAlign(void 0,t.chainidArray,e,s)}else if(0==n.indexOf("ig refnum off"))await t.refnumCls.hideIgRefNum();else if(0==n.indexOf("custom refnum")){let e=i.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(","),s=[];for(let t=0,i=e.length;t<i;++t)s.push(parseFloat(e[t]));t.transformCls.rotateCoord(t.hAtoms,s),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=s.hashUtilsCls.cloneHash(t.viewSelectionAtoms),t.hlUpdateCls.updateHlAll();else if(-1!==n.indexOf("select prop")){let e,s,n=i.split(" | "),l=n[0].substr("select prop".length+1);if(2==n.length){let t=n[1].split("_");e=t[0],s=t[1]}t.resid2specCls.selectProperty(l,e,s)}else if(-1!==n.indexOf("select each residue"))t.selectionCls.saveEachResiInSel();else if(0==n.indexOf("select")&&-1!==n.indexOf("name")){let e=i.split(" | "),s="",n="",l="";for(let t=0,i=e.length;t<i;++t){let i=e[t];-1!==i.indexOf("select")?s=i.substr(i.indexOf(" ")+1):-1!==i.indexOf("name")&&(n=i.substr(i.indexOf(" ")+1))}l=n,await t.selByCommCls.selectByCommand(s,n,l)}else if(-1!==n.indexOf("select $")||-1!==n.indexOf("select .")||-1!==n.indexOf("select :")||-1!==n.indexOf("select %")||-1!==n.indexOf("select @")){let e=i.split(" | "),s=e[0].substr(e[0].indexOf(" ")+1),n="",l="";e.length>1&&(n=e[1].substr(e[1].indexOf(" ")+1)),e.length>2&&(l=e[2].substr(e[2].indexOf(" ")+1)),-1!==s.indexOf(" or ")?await t.selByCommCls.selectByCommand(s,n,l):await t.selByCommCls.selectBySpec(s,n,l)}s.htmlCls.clickMenuCls.setLogCmd(i,!1),t.bAddCommands=!0}setStrengthPara(e){let t=this.icn3d;if(t.icn3dui,e.length>=5){let s=e[4].split(" ");s.length>=4&&($("#"+t.pre+"hbondthreshold").val(s[1]),$("#"+t.pre+"saltbridgethreshold").val(s[2]),$("#"+t.pre+"contactthreshold").val(s[3]),s.length>=7&&($("#"+t.pre+"halogenthreshold").val(s[4]),$("#"+t.pre+"picationthreshold").val(s[5]),$("#"+t.pre+"pistackingthreshold").val(s[6])))}if(6==e.length){let s=e[5].split(" ");s.length>=6&&($("#"+t.pre+"dist_ss").val(s[0]),$("#"+t.pre+"dist_coil").val(s[1]),$("#"+t.pre+"dist_hbond").val(s[2]),$("#"+t.pre+"dist_inter").val(s[3]),$("#"+t.pre+"dist_ssbond").val(s[4]),$("#"+t.pre+"dist_ionic").val(s[5]),9==s.length&&($("#"+t.pre+"dist_halogen").val(s[6]),$("#"+t.pre+"dist_pication").val(s[7]),$("#"+t.pre+"dist_pistacking").val(s[8])))}}getThresholdNameArrays(e){this.icn3d.icn3dui.htmlCls.clickMenuCls.SetChainsAdvancedMenu();let t,s=e.split(" | "),i=parseFloat(s[0].substr(s[0].lastIndexOf(" ")+1)),n=[],l=[];if(s.length>=2&&s[1].length>4){let e=s[1].split(" ");e.length>1&&(l=e[1].split(",")),e.length>2&&(n=e[2].split(","))}else l=["selected"],n=["non-selected"];return 3==s.length&&(t="true"==s[2]),{threshold:i,nameArray2:l,nameArray:n,bHbondCalc:t}}setQueryresi2score(e){let t=this.icn3d,s=t.icn3dui,i=e[1],n=e[2].split(" ")[1].split("_"),l=e[3];void 0===t.queryresi2score&&(t.queryresi2score={}),t.queryresi2score[i]={};for(let e=parseInt(n[0]),s=0;e<=parseInt(n[1]);++e,++s)"_"!=l[s]&&(t.queryresi2score[i][e]=11.11111111111111*parseInt(l[s]));if(e.length>4){let i=e[4].split(" ");t.startColor=i[1],t.midColor=i[2],t.endColor=i[3];let n=s.htmlCls.clickMenuCls.setLegendHtml();$("#"+s.pre+"dl_legend_html").html(n),s.htmlCls.dialogCls.openDlg("dl_legend","Color Range")}}addShape(e,t){let s=this.icn3d,i=s.icn3dui,n=e.split(" | "),l=n[1].split(" "),r=n[2].substr(n[2].lastIndexOf(" ")+1),o=n[3].substr(n[3].lastIndexOf(" ")+1),a=n[4].substr(n[4].lastIndexOf(" ")+1);r="#"+r.replace(/\#/g,"");let d,c=i.parasCls.thr(r);if("x1"==l[0])d=new THREE.Vector3(parseFloat(l[1]),parseFloat(l[3]),parseFloat(l[5]));else{let e=n[1].split(","),t=s.definedSetsCls.getAtomsFromNameArray(e),i=s.contactCls.getExtent(t);d=new THREE.Vector3(i[2][0],i[2][1],i[2][2])}"sphere"==t?s.sphereCls.createSphereBase(d,c,parseFloat(a),void 0,void 0,void 0,parseFloat(o)):s.boxCls.createBox_base(d,parseFloat(a),c,void 0,void 0,void 0,parseFloat(o))}getMenuFromCmd(e){this.icn3d.icn3dui;let t="Windows > View Sequences & Annotations",s="Analysis > Interactions",i=s+" > 2D Graph(Force-Directed)",n="View > Rotate > Auto Rotation > Rotate ",l="View > Rotate > Rotate 90 deg > ",r="Select > Select on 3D > ",o="Analysis > Label > ",a="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")?s+" > 2D Graph(Force-Directed)":0==e.indexOf("export canvas")?"File > Save File > iCn3D PNG Image":"export stl file"==e?a+"STL":"export vrml file"==e?a+"VRML(Color)":"export stl stabilizer file"==e?a+"STL W/ Stabilizers":"export vrml stabilizer file"==e?a+"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?r+"Atom":"set pk residue"==e?r+"Residue":"set pk strand"==e?r+"Strand/Helix":"set pk domain"==e?r+"3D Domain":"set pk chain"==e?r+"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?s+" > 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?l+"X-axis":"rotate y"==e?l+"Y-axis":"rotate z"==e?l+"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?s+': "Set 1" button: "Show Count Only" button':"table inter details"==e?s+': "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")?s+': "Buried Surface Area" button':0==e.indexOf("display interaction 3d")?s+': "3D Display Interactions" button':0==e.indexOf("view interaction pairs")?s+': "Highlight Interactions in Table" button':0==e.indexOf("save1 interaction pairs")?s+': "Set 1" button':0==e.indexOf("save2 interaction pairs")?s+': "Set 2" button':0==e.indexOf("line graph interaction pairs")?s+': "2D Interaction Network" button':0==e.indexOf("scatterplot interaction pairs")?s+': "2D Interaction Map" button':0==e.indexOf("ligplot interaction pairs")?s+': "2D Interaction for One Ligand/Residue" button':0==e.indexOf("graph label")?i+': "Label Size" menu':0==e.indexOf("graph force")?i+': "Force on Nodes" menu':0==e.indexOf("hide edges")?i+': "Internal Edges" menu':0==e.indexOf("reset interaction pairs")?s+" > 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 ms{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={},s={};for(let i in e.chemicals){let n=e.atoms[i],l=n.structure+"_"+n.chain+"_"+n.resi;"DUM"===n.resn?s[l]=1:t[l]=1}Object.keys(t).length>0&&(e.defNames2Residues.chemicals=Object.keys(t),e.defNames2Descr.chemicals="chemicals",e.defNames2Command.chemicals="select :chemicals"),Object.keys(s).length>0&&(e.defNames2Residues.membrane=Object.keys(s),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.setChainsInMenu(),this.setProtNuclLigInMenu(),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 s={};for(let i in e.alnChains)s=t.hashUtilsCls.unionHash(s,e.alnChains[i]);let i=e.firstAtomObjCls.getResiduesFromAtoms(s),n="protein_aligned",l="aligned protein and nucleotides",r="select "+e.resid2specCls.residueids2spec(Object.keys(i));e.selectionCls.addCustomSelection(Object.keys(i),n,l,r,!0)}}setAtomMenu(e){let t=this.icn3d;t.icn3dui;let s="",i=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues):[],n=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms):[],l=i.concat(n).sort(),r=[];l.forEach((e=>{-1===$.inArray(e,r)&&r.push(e)}));for(let i=0,n=r.length;i<n;++i){let n,l,o=r[i];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&&(l=t.residues[e[0]],l&&(n=t.atoms[Object.keys(l)[0]]))}let a=void 0===n||void 0===n.color||"FFFFFF"===n.color.getHexString().toUpperCase()?"DDDDDD":n.color.getHexString(),d=void 0!==n&&void 0!==n.color?a:"000000";-1!=e.indexOf(o)?s+="<option value='"+o+"' style='color:#"+d+"' selected='selected'>"+o+"</option>":s+="<option value='"+o+"' style='color:#"+d+"'>"+o+"</option>"}return s}setChainsInMenu(){let e=this.icn3d;e.icn3dui;for(let t in e.chains)if(e.chainsSeq[t]&&e.chainsSeq[t].length>1){e.defNames2Residues[t]=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.chains[t])),e.defNames2Descr[t]=t;let s=t.indexOf("_"),i=t.substr(0,s),n=t.substr(s+1);e.defNames2Command[t]="select $"+i+"."+n}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),s={};for(let e=0,i=t.length;e<i;++e){let i=t[e],n=i.indexOf("_"),l=i.substr(0,n);void 0===s[l]&&(s[l]=[]),s[l].push(i)}for(let t in s)e.defNames2Residues[t]=s[t],e.defNames2Descr[t]=t,e.defNames2Command[t]="select $"+t}}setTransmemInMenu(e,t,s){let i=this.icn3d;if(i.icn3dui,i.bOpm){let n={},l={},r={};for(let s in i.atoms){let o=i.atoms[s];if("DUM"===o.resn)continue;let a=o.structure+"_"+o.chain+"_"+o.resi;o.coord.z>e?l[a]=1:o.coord.z<t?r[a]=1:n[a]=1}let o=s?"2":"";Object.keys(n).length>0&&(i.defNames2Residues["transmembrane"+o]=Object.keys(n),i.defNames2Descr["transmembrane"+o]="transmembrane"+o,i.defNames2Command["transmembrane"+o]="select :transmembrane"+o),Object.keys(l).length>0&&(i.defNames2Residues["extracellular"+o]=Object.keys(l),i.defNames2Descr["extracellular"+o]="extracellular"+o,i.defNames2Command["extracellular"+o]="select :extracellular"+o),Object.keys(r).length>0&&(i.defNames2Residues["intracellular"+o]=Object.keys(r),i.defNames2Descr["intracellular"+o]="intracellular"+o,i.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 s=t.hashUtilsCls.cloneHash(e.hAtoms),i=t.hashUtilsCls.cloneHash(e.dAtoms);void 0!==e.bSetChainsAdvancedMenu&&e.bSetChainsAdvancedMenu&&!e.bResetSets||(this.setPredefinedInMenu(),e.bSetChainsAdvancedMenu=!0),e.hAtoms=t.hashUtilsCls.cloneHash(s),e.dAtoms=t.hashUtilsCls.cloneHash(i),e.hlUpdateCls.updateHlMenus()}clickCustomAtoms(){let e=this.icn3d,t=e.icn3dui,s=this;$("#"+e.pre+"atomsCustom").change((function(e){let i=s.icn3d,n=$(this).val();if(i.nameArray=n,null!==n){let e=!1;s.changeCustomAtoms(n,e),t.htmlCls.clickMenuCls.setLogCmd("select sets "+n.join(" "+i.setOperation+" "),!0),i.bSelectResidue=!1}})),t.myEventCls.onIds("#"+e.pre+"atomsCustom","focus",(function(e){let i=s.icn3d;t.utilsCls.isMobile()&&$("#"+i.pre+"atomsCustom").val("")}))}deleteSelectedSets(){let e=this.icn3d;e.icn3dui;let t=$("#"+e.pre+"atomsCustom").val();for(let s=0;s<t.length;++s){let i=t[s];(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(i)||void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(i))&&(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(i)&&delete e.defNames2Atoms[i],void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(i)&&delete e.defNames2Residues[i])}e.hlUpdateCls.updateHlMenus()}changeCustomAtoms(e,t){let s=this.icn3d,i=s.icn3dui;s.hAtoms={};for(let t=0;t<e.length;++t){let n=e[t];if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(n)||void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(n)){if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(n)){let e=s.defNames2Atoms[n];for(let t=0,i=e.length;t<i;++t)s.hAtoms[e[t]]=1}if(void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(n)){let e=s.defNames2Residues[n],t={};for(let n=0,l=e.length;n<l;++n)t=i.hashUtilsCls.unionHash(t,s.residues[e[n]]);s.hAtoms=i.hashUtilsCls.unionHash(s.hAtoms,t)}}}s.hlUpdateCls.updateHlAll(e,t),s.annotationCls.showAnnoSelectedChains(),$("#"+s.pre+"command").val(""),$("#"+s.pre+"command_name").val("");for(let t=0,i=e.length;t<i;++t)if(s.defNames2Atoms[e[t]],s.defNames2Residues[e[t]],s.defNames2Descr[e[t]],0===t)$("#"+s.pre+"command").val("saved atoms "+e[t]),$("#"+s.pre+"command_name").val(e[t]);else{let i=$("#"+s.pre+"command").val();$("#"+s.pre+"command").val(i+" "+s.setOperation+" "+e[t]),i=$("#"+s.pre+"command_name").val(),$("#"+s.pre+"command_name").val(i+" "+s.setOperation+" "+e[t])}}setHAtomsFromSets(e,t){let s=this.icn3d,i=s.icn3dui;for(let n=0;n<e.length;++n){let l=e[n];if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(l)||void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(l)){if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(l)){let e=s.defNames2Atoms[l];if("or"===t)for(let t=0,i=e.length;t<i;++t)s.hAtoms[e[t]]=1;else if("and"===t){let t={};for(let s=0,i=e.length;s<i;++s)t[e[s]]=1;s.hAtoms=i.hashUtilsCls.intHash(s.hAtoms,t)}else if("not"===t){let t={};for(let s=0,i=e.length;s<i;++s)t[e[s]]=1;s.hAtoms=i.hashUtilsCls.exclHash(s.hAtoms,t)}}if(void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(l)){let e=s.defNames2Residues[l],n={};for(let t=0,l=e.length;t<l;++t)n=i.hashUtilsCls.unionHash(n,s.residues[e[t]]);"or"===t?s.hAtoms=i.hashUtilsCls.unionHash(s.hAtoms,n):"and"===t?s.hAtoms=i.hashUtilsCls.intHash(s.hAtoms,n):"not"===t&&(s.hAtoms=i.hashUtilsCls.exclHash(s.hAtoms,n))}}}}updateAdvancedCommands(e,t){let s=this.icn3d;s.icn3dui;let i=" "+t+" ";for(let n=0,l=e.length;n<l;++n)if(0===n&&"or"==t)$("#"+s.pre+"command").val("saved atoms "+e[n]),$("#"+s.pre+"command_name").val(e[n]);else{let t=$("#"+s.pre+"command").val();$("#"+s.pre+"command").val(t+i+e[n]),t=$("#"+s.pre+"command_name").val(),$("#"+s.pre+"command_name").val(t+i+e[n])}}combineSets(e,t,s,i){let n=this.icn3d,l=n.icn3dui;if(n.hAtoms={},this.setHAtomsFromSets(e,"or"),0==Object.keys(n.hAtoms).length&&(n.hAtoms=l.hashUtilsCls.cloneHash(n.dAtoms)),this.setHAtomsFromSets(t,"and"),this.setHAtomsFromSets(s,"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(s,"not"),void 0!==i){let e="select "+$("#"+n.pre+"command").val();$("#"+n.pre+"command_name").val(i),n.selectionCls.addCustomSelection(Object.keys(n.hAtoms),i,i,e,!1)}}async commandSelect(e){let t=this.icn3d,s=t.icn3dui,i=$("#"+t.pre+"command"+e).val(),n=$("#"+t.pre+"command_name"+e).val().replace(/;/g,"_").replace(/\s+/g,"_");i&&(await t.selByCommCls.selectByCommand(i,n,n),s.htmlCls.clickMenuCls.setLogCmd("select "+i+" | name "+n,!0))}clickCommand_apply(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+e.pre+"command_apply","click",(async function(e){s.icn3d,e.preventDefault(),await s.commandSelect("")})),t.myEventCls.onIds("#"+e.pre+"command_apply2","click",(async function(e){s.icn3d,e.preventDefault(),await s.commandSelect("2")}))}selectCombinedSets(e,t){this.icn3d.icn3dui;let s=e.split(" "),i=[],n=[],l=[],r="or";for(let e=0,t=s.length;e<t;++e){let t=s[e].split("_");if(3!=t.length||isNaN(t[2])||(s[e]=t[0]+"_"+t[1]+t[2]),"or"!==s[e]&&"and"!==s[e]&&"not"!==s[e]){let t=["hbonds_","saltbridge_","halogen_","pi-cation_","pi-stacking_"];for(let i=0,n=t.length;i<n;++i){const n=new RegExp("^"+t[i]+"\\d+$");s[e].match(n)&&(s[e]=t[i]+"auto")}"or"===r?i.push(s[e]):"and"===r?n.push(s[e]):"not"===r&&l.push(s[e])}else r=s[e]}null!==s&&this.combineSets(i,n,l,t)}clickModeswitch(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+e.pre+"modeswitch","click",(function(t){void 0!==$("#"+e.pre+"modeswitch")[0]&&$("#"+e.pre+"modeswitch")[0].checked?s.setModeAndDisplay("selection"):s.setModeAndDisplay("all")}))}setModeAndDisplay(e){let t=this.icn3d,s=t.icn3dui;"all"===e?(this.setMode("all"),t.prevHighlightAtoms=s.hashUtilsCls.cloneHash(t.hAtoms),s.htmlCls.clickMenuCls.setLogCmd("set mode all",!0),t.selectionCls.selectAll(),t.drawCls.draw()):(this.setMode("selection"),void 0!==t.prevHighlightAtoms?t.hAtoms=s.hashUtilsCls.cloneHash(t.prevHighlightAtoms):t.selectionCls.selectAll(),s.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,s=t.icn3dui,i={};if(void 0===t.defNames2Residues.proteins&&this.showSets(),-1!==Object.keys(t.chains).indexOf(e))i=s.hashUtilsCls.unionHash(i,t.chains[e]);else{if(void 0!==t.defNames2Residues[e]&&t.defNames2Residues[e].length>0)for(let n=0,l=t.defNames2Residues[e].length;n<l;++n){let l=t.defNames2Residues[e][n];i=s.hashUtilsCls.unionHash(i,t.residues[l])}if(void 0!==t.defNames2Atoms[e]&&t.defNames2Atoms[e].length>0)for(let s=0,n=t.defNames2Atoms[e].length;s<n;++s){i[t.defNames2Atoms[e][s]]=1}}return i}getAtomsFromNameArray(e){let t=this.icn3d,s=t.icn3dui,i={};for(let n=0,l=e.length;n<l;++n)if("non-selected"===e[n]){let e={};for(let s in t.atoms)!t.hAtoms.hasOwnProperty(s)&&t.dAtoms.hasOwnProperty(s)&&(e[s]=t.atoms[s]);i=s.hashUtilsCls.unionHash(i,e)}else i="selected"===e[n]?s.hashUtilsCls.unionHash(i,s.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)):s.hashUtilsCls.unionHash(i,s.hashUtilsCls.hash2Atoms(this.getAtomsFromOneSet(e[n]),t.atoms));return 0==e.length&&(i=t.atoms),i}}class us{constructor(e){this.icn3d=e}setAtomMenu(e,t){let s=this.icn3d;s.icn3dui;let i="",n=[e[0]];for(let l=0,r=e.length;l<r;++l){let r,o=e[l],a=t[l];if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(o)){let e=s.defNames2Atoms[o];e.length>0&&s.atoms[e[0]]}else if(void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(o)){let e=s.defNames2Residues[o];e.length>0&&(r=s.residues[e[0]],r&&s.atoms[Object.keys(r)[0]])}-1!=n.indexOf(o)?i+="<option value='"+o+"' selected='selected'>"+a+"</option>":i+="<option value='"+o+"'>"+a+"</option>"}return 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 s={};for(let i in t)i in e||(s[i]=t[i]);return s}clickStructure(){let e=this.icn3d,t=e.icn3dui,s=this;null==e.allData&&(e.allData={},e.allData.all={atoms:{},proteins:{},nucleotides:{},chemicals:{},ions:{},water:{},structures:{},ssbondpnts:{},residues:{},chains:{},chainsSeq:{},defNames2Atoms:{},defNames2Residues:{}},e.allData.prev={}),$("#"+e.pre+"collections_menu").change((async function(e){let i=s.icn3d,n=$(this).val(),l=$(this).find("option:selected").text();if(i.nameArray=n,null!==n){let e=!0;s.reset();for(const t of n)t in i.allData||(i.allData.prev=JSON.parse(JSON.stringify(i.allData.all)),i.atoms=i.allData.all.atoms,i.proteins=i.allData.all.proteins,i.nucleotides=i.allData.all.nucleotides,i.chemicals=i.allData.all.chemicals,i.ions=i.allData.all.ions,i.water=i.allData.all.water,i.structures=i.allData.all.structures,i.ssbondpnts=i.allData.all.ssbondpnts,i.residues=i.allData.all.residues,i.chains=i.allData.all.chains,i.chainsSeq=i.allData.all.chainsSeq,i.defalls2Atoms=i.allData.all.defalls2Atoms,i.defalls2Residues=i.allData.all.defalls2Residues,await i.chainalignParserCls.downloadMmdbAf(t,void 0,void 0,e).then((()=>{i.allData.all={atoms:i.atoms,proteins:i.proteins,nucleotides:i.nucleotides,chemicals:i.chemicals,ions:i.ions,water:i.water,structures:i.structures,ssbondpnts:i.ssbondpnts,residues:i.residues,chains:i.chains,chainsSeq:i.chainsSeq,defNames2Atoms:i.defNames2Atoms,defNames2Residues:i.defNames2Residues},i.allData[t]={atoms:s.dictionaryDifference(i.allData.prev.atoms,i.atoms),proteins:s.dictionaryDifference(i.allData.prev.proteins,i.proteins),nucleotides:s.dictionaryDifference(i.allData.prev.nucleotides,i.nucleotides),chemicals:s.dictionaryDifference(i.allData.prev.chemicals,i.chemicals),ions:s.dictionaryDifference(i.allData.prev.ions,i.ions),water:s.dictionaryDifference(i.allData.prev.water,i.water),structures:s.dictionaryDifference(i.allData.prev.structures,i.structures),ssbondpnts:s.dictionaryDifference(i.allData.prev.ssbondpnts,i.ssbondpnts),residues:s.dictionaryDifference(i.allData.prev.residues,i.residues),chains:s.dictionaryDifference(i.allData.prev.chains,i.chains),chainsSeq:s.dictionaryDifference(i.allData.prev.chainsSeq,i.chainsSeq),defNames2Atoms:s.dictionaryDifference(i.allData.prev.defNames2Atoms,i.defNames2Atoms),defNames2Residues:s.dictionaryDifference(i.allData.prev.defNames2Residues,i.defNames2Residues)},s.reset()})));for(const e of n)i.atoms=Object.assign(i.atoms,i.allData[e].atoms),i.proteins=Object.assign(i.proteins,i.allData[e].proteins),i.nucleotides=Object.assign(i.nucleotides,i.allData[e].nucleotides),i.chemicals=Object.assign(i.chemicals,i.allData[e].chemicals),i.ions=Object.assign(i.ions,i.allData[e].ions),i.water=Object.assign(i.water,i.allData[e].water),i.structures=Object.assign(i.structures,i.allData[e].structures),i.ssbondpnts=Object.assign(i.ssbondpnts,i.allData[e].ssbondpnts),i.residues=Object.assign(i.residues,i.allData[e].residues),i.chains=Object.assign(i.chains,i.allData[e].chains),i.chainsSeq=Object.assign(i.chainsSeq,i.allData[e].chainsSeq),i.defNames2Atoms=Object.assign(i.defNames2Atoms,i.allData[e].defNames2Atoms),i.defNames2Residues=Object.assign(i.defNames2Residues,i.allData[e].defNames2Residues),i.dAtoms=t.hashUtilsCls.cloneHash(i.atoms),i.hAtoms=t.hashUtilsCls.cloneHash(i.atoms);i.opts.color=1==Object.keys(i.structures).length?"chain":"structure",i.setColorCls.setColorByOptions(i.opts,i.atoms),i.transformCls.zoominSelection(),i.definedSetsCls.showSets(),i.bResetAnno=!0,i.bAnnoShown&&(await i.showAnnoCls.showAnnotations(),i.hlUpdateCls.updateHlAll(n),i.annotationCls.showAnnoSelectedChains()),await i.drawCls.draw(),i.saveFileCls.showTitle(),t.htmlCls.clickMenuCls.setLogCmd("select structure ["+l+"]",!0)}})),t.myEventCls.onIds("#"+e.pre+"collections_menu","focus",(function(e){let i=s.icn3d;t.utilsCls.isMobile()&&$("#"+i.pre+"collections_menu").val("")}))}}class gs{constructor(e){this.icn3d=e}async loadScript(e,t,s){let i=this.icn3d;if(i.icn3dui,!e)return;i.bCommandLoad=!0,i.bRender=!1,i.bStopRotate=!0,e=t?e.replace(/\+/g," "):e.replace(/\+/g," ").replace(/;/g,"\n");let n=[];!s&&i.commands.length>0&&(n[0]=i.commands[0]);let l=e.trim().split("\n");i.commands=l;let r=l[0].indexOf("command=");if(t&&-1!=r){let e=l[0].substr(0,r-1);i.commands.splice(0,1,e)}i.STATENUMBER=i.commands.length,i.commands=n.concat(i.commands),i.STATENUMBER=i.commands.length,i.CURRENTNUMBER=0,i.bReplay?await this.replayFirstStep(i.CURRENTNUMBER):await this.execCommands(i.CURRENTNUMBER,i.STATENUMBER-1,i.STATENUMBER,s)}async execCommands(e,t,s,i){let n=this.icn3d;n.icn3dui,n.bRender=!1,i||n.reinitAfterLoad(),await this.execCommandsBase(e,t,s)}getNameArray(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | "),i=[];return 2==s.length&&(i=s[1].split(","),t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(i)),i}updateTransformation(e){let t=this.icn3d;t.icn3dui;let s=t.commands[e-1]?t.commands[e-1].split("|||"):[];if(2==s.length){let e=JSON.parse(s[1]);t._zoomFactor=e.factor,t.mouseChange.x=e.mouseChange.x,t.mouseChange.y=e.mouseChange.y,t.quaternion._x=e.quaternion._x,t.quaternion._y=e.quaternion._y,t.quaternion._z=e.quaternion._z,t.quaternion._w=e.quaternion._w}t.drawCls.draw()}async execCommandsBase(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=this;for(n=e;n<=t;++n){let i=n===s-1;if(!l.commands[n]||!l.commands[n].trim())continue;if(0==(l.atoms?Object.keys(l.atoms).length:0)&&-1==l.commands[n].indexOf("load"))continue;let a=l.commands[n].split("|||"),d=a[0].trim();if(-1!==d.indexOf("load")){if(0===t&&e===t)return void(l.bNotLoadStructure?(l.hAtoms=r.hashUtilsCls.cloneHash(l.atoms),1===l.commands.length&&(l.bAddCommands=!0),i&&this.renderFinalStep(s)):(await o.applyCommandLoad(l.commands[n]),1===l.commands.length&&(l.bAddCommands=!0),i&&o.renderFinalStep(s)));l.bNotLoadStructure?(l.hAtoms=r.hashUtilsCls.cloneHash(l.atoms),l.backForward&&this.renderFinalStep(1)):(await o.applyCommandLoad(l.commands[n]),l.backForward&&o.renderFinalStep(1))}else if(0==d.indexOf("set map")&&-1==d.indexOf("set map wireframe"))await o.applyCommandMap(a[0].trim());else if(0==d.indexOf("set emmap")&&-1==d.indexOf("set emmap wireframe")){let e=a[0].trim().substr(10).split(" ");2==e.length&&"percentage"==e[0]&&(e[1],await o.applyCommandEmmap(a[0].trim()))}else if(0==d.indexOf("set phi"))await l.delphiCls.applyCommandPhi(a[0].trim());else if(0==d.indexOf("set delphi"))await l.delphiCls.applyCommandDelphi(a[0].trim());else if(0==d.indexOf("view annotations"))Object.keys(l.proteins).length>0&&await o.applyCommandAnnotationsAndCddSite(a[0].trim());else if(0==d.indexOf("set annotation clinvar"))Object.keys(l.proteins).length>0&&await o.applyCommandClinvar(a[0].trim());else if(0==d.indexOf("set annotation snp"))Object.keys(l.proteins).length>0&&await o.applyCommandSnp(a[0].trim());else if(0==d.indexOf("set annotation ptm"))Object.keys(l.proteins).length>0&&await o.applyCommandPTM(a[0].trim());else if(0==d.indexOf("ig template")){let e=d.substr(d.lastIndexOf(" ")+1);await r.htmlCls.clickMenuCls.setIgTemplate(e)}else if(0==d.indexOf("set annotation 3ddomain"))Object.keys(l.proteins).length>0&&o.applyCommand3ddomain(a[0].trim());else if(0==d.indexOf("set annotation all"))Object.keys(l.proteins).length>0&&(await o.applyCommandClinvar(a[0].trim()),await o.applyCommandSnp(a[0].trim()),o.applyCommand3ddomain(a[0].trim())),await l.annotationCls.setAnnoTabAll();else if(0==d.indexOf("view interactions")&&void 0!==r.cfg.align)await o.applyCommandViewinteraction(a[0].trim());else if(0==d.indexOf("symmetry")){l.bAxisOnly=!1;let e=d.substr(d.indexOf(" ")+1);l.symmetrytitle="none"===e?void 0:e,"none"!==e&&await l.symdCls.retrieveSymmetry(Object.keys(l.structures)[0]),l.drawCls.draw()}else if(0==d.indexOf("symd symmetry"))l.bAxisOnly=!1,await l.symdCls.applyCommandSymd(d),l.drawCls.draw();else if(0==d.indexOf("scap"))await l.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);r.cfg.aligntool="vast",await l.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on structure align"))this.getNameArray(d),r.cfg.aligntool="vast",await l.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on tmalign msa")){let e=this.getNameArray(d);r.cfg.aligntool="tmalign",await l.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on tmalign"))this.getNameArray(d),r.cfg.aligntool="tmalign",await l.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on vastplus"))o.getHAtoms(l.commands[n]),await l.vastplusCls.realignOnVastplus();else if(0==d.indexOf("graph interaction pairs"))await o.applyCommandGraphinteraction(d);else if(0==d.indexOf("cartoon 2d domain"))l.bRender=!0,o.updateTransformation(s),await o.applyCommandCartoon2d(d),l.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 r.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);l.bRender=!0,o.updateTransformation(s),await l.cartoon2dCls.draw2Dcartoon(t),l.bRender=!1}else if(0==d.indexOf("add msa track")){let e=d.split(" | "),t=e[1].substr(8),s=e[2].substr(9),i=e[3].substr(5),n=e[4].substr(10);$("#"+l.pre+"anno_custom")[0]&&($("#"+l.pre+"anno_custom")[0].checked=!0),$("[id^="+l.pre+"custom]").show(),await l.addTrackCls.addMsaTracks(t,s,i,n)}else if(0==d.indexOf("add exon track")){let e=d.split(" | "),t=e[1].substr(8),s=e[2].substr(7),i=parseInt(e[3].substr(9)),n=e[4].substr(5);$("#"+l.pre+"anno_custom")[0]&&($("#"+l.pre+"anno_custom")[0].checked=!0),$("[id^="+l.pre+"custom]").show(),await l.addTrackCls.addExonTracks(t,s,i,n)}else await l.applyCommandCls.applyCommand(l.commands[n])}(n===s||i)&&this.renderFinalStep(n)}pressCommandtext(){let e=this.icn3d,t=e.icn3dui,s=this;$("#"+e.pre+"logtext").keypress((async function(e){let i=s.icn3d;if(i.bAddLogs=!1,13==(e.keyCode?e.keyCode:e.which)){e.preventDefault();let n=$(this).val();i.bRender=!0;let l=n.split("\n"),r=i.logs.length;for(let e=r,n=l.length;e<n;++e){let n=e==r?l[e].substr(2).trim():l[e].trim();if(""===n)continue;i.logs.push(n);let o={};if(o.factor=i._zoomFactor,o.mouseChange=i.mouseChange,o.quaternion=i.quaternion,i.commands.push(n+"|||"+i.transformCls.getTransformationStr(o)),i.optsHistory.push(t.hashUtilsCls.cloneHash(i.opts)),i.optsHistory[i.optsHistory.length-1].hlatomcount=Object.keys(i.hAtoms).length,t.utilsCls.isSessionStorageSupported()&&i.setStyleCls.saveCommandsToSession(),i.STATENUMBER=i.commands.length,-1!==n.indexOf("load"))await s.applyCommandLoad(n);else if(-1!==n.indexOf("set map")&&-1===n.indexOf("set map wireframe"))await s.applyCommandMap(n);else if(-1!==n.indexOf("set emmap")&&-1===n.indexOf("set emmap wireframe"))await s.applyCommandEmmap(n);else if(-1!==n.indexOf("set phi"))await i.delphiCls.applyCommandPhi(n);else if(-1!==n.indexOf("set delphi"))await i.delphiCls.applyCommandDelphi(n);else if(0==n.indexOf("view annotations"))await s.applyCommandAnnotationsAndCddSite(n);else if(0==n.indexOf("set annotation clinvar"))await s.applyCommandClinvar(n);else if(0==n.indexOf("set annotation snp"))await s.applyCommandSnp(n);else if(0==n.indexOf("set annotation ptm"))await s.applyCommandPTM(n);else if(0==n.indexOf("ig refnum on"))i.bRunRefnumAgain=!0,i.bAnnoShown||await i.showAnnoCls.showAnnotations(),await i.annotationCls.setAnnoTabIg(!0),i.bRunRefnumAgain=!1;else if(0==n.indexOf("set annotation 3ddomain"))s.applyCommand3ddomain(n);else if(0==n.indexOf("set annotation all"))await s.applyCommandClinvar(n),await s.applyCommandSnp(n),s.applyCommand3ddomain(n),await i.annotationCls.setAnnoTabAll();else if(0==n.indexOf("view interactions")&&void 0!==t.cfg.align)await s.applyCommandViewinteraction(n);else if(0==n.indexOf("symmetry")){let e=n.substr(n.indexOf(" ")+1);i.symmetrytitle="none"===e?void 0:e,"none"!==e&&void 0===i.symmetryHash&&await i.symdCls.retrieveSymmetry(Object.keys(i.structures)[0])}else if(0==n.indexOf("symd symmetry"))await i.symdCls.applyCommandSymd(n);else if(0==n.indexOf("scap "))await i.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(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}await s.applyCommandRealign(n)}else if(0==n.indexOf("realign on structure align")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="vast",await s.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on tmalign")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="tmalign",await s.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on vastplus")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}await i.vastplusCls.realignOnVastplus()}else 0==n.indexOf("graph interaction pairs")?await s.applyCommandGraphinteraction(n):await i.applyCommandCls.applyCommand(n+"|||"+i.transformCls.getTransformationStr(o))}i.selectionCls.saveSelectionIfSelected(),i.drawCls.draw(),$("#"+i.pre+"logtext").val("> "+i.logs.join("\n> ")+"\n> ").scrollTop($("#"+i.pre+"logtext")[0].scrollHeight)}i.bAddLogs=!0}))}async applyCommandLoad(e){let t=this.icn3d,s=t.icn3dui;t.bAddCommands=!1;let i=e.split("|||")[0].replace(/\s\s/g," ").trim();if(-1!==i.indexOf("load")){let e=i.split(" | "),n=e[0];if(e.length>1&&!s.cfg.inpara){let t=e[e.length-1].indexOf(" ");s.cfg.inpara=e[e.length-1].substr(t+1),"undefined"===s.cfg.inpara&&(s.cfg.inpara="")}let l=n.substr(n.lastIndexOf(" ")+1);4==l.length&&(l=l.toUpperCase());let r=l.split(","),o="";for(let e=0,s=r.length;e<s;++e)t.structures&&(t.structures.hasOwnProperty(r[e])||t.structures.hasOwnProperty(r[e].toLowerCase())||t.structures.hasOwnProperty(r[e].toUpperCase()))||(o&&(o+=","),o+=r[e]);if(l=o,t.bInputPNGWithData||!l)return;if(t.inputid=l,-1!==i.indexOf("load mmtf"))s.cfg.mmtfid=l,await t.bcifParserCls.downloadBcif(l);else if(-1!==i.indexOf("load bcif"))s.cfg.bcifid=l,await t.bcifParserCls.downloadBcif(l);else if(-1!==i.indexOf("load pdb"))s.cfg.pdbid=l,await t.pdbParserCls.downloadPdb(l);else if(-1!==i.indexOf("load af"))s.cfg.afid=l,await t.pdbParserCls.downloadPdb(l,!0);else if(-1!==i.indexOf("load opm"))s.cfg.opmid=l,await t.opmParserCls.downloadOpm(l);else if(-1!==i.indexOf("load mmcif"))s.cfg.mmcifid=l,await t.mmcifParserCls.downloadMmcif(l);else if(-1!==i.indexOf("load mmdb ")||-1!==i.indexOf("load mmdb1 "))s.cfg.mmdbid=l,s.cfg.bu=1,await t.mmdbParserCls.downloadMmdb(l);else if(-1!==i.indexOf("load mmdb0"))s.cfg.mmdbid=l,s.cfg.bu=0,await t.mmdbParserCls.downloadMmdb(l);else if(-1!==i.indexOf("load mmdbaf1"))s.cfg.mmdbafid=l,s.cfg.bu=1,await t.chainalignParserCls.downloadMmdbAf(l);else if(-1!==i.indexOf("load mmdbaf0"))s.cfg.mmdbafid=l,s.cfg.bu=0,await t.chainalignParserCls.downloadMmdbAf(l);else if(-1!==i.indexOf("load gi"))s.cfg.gi=l,await t.mmdbParserCls.downloadGi(l);else if(-1!==i.indexOf("load refseq"))s.cfg.refseqid=l,await t.mmdbParserCls.downloadRefseq(l);else if(-1!==i.indexOf("load protein"))s.cfg.protein=l,await t.mmdbParserCls.downloadProteinname(l);else if(-1!==i.indexOf("load seq_struct_ids "))t.bSmithwm=!1,t.bLocalSmithwm=!1,await t.mmdbParserCls.downloadBlast_rep_id(l);else if(-1!==i.indexOf("load seq_struct_ids_smithwm "))t.bSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(l);else if(-1!==i.indexOf("load seq_struct_ids_local_smithwm "))t.bLocalSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(l);else if(-1!==i.indexOf("load cid"))s.cfg.cid=l,await t.sdfParserCls.downloadCid(l);else if(-1!==i.indexOf("load smiles"))s.cfg.smiles=l,await t.sdfParserCls.downloadSmiles(l);else if(-1!==i.indexOf("load alignment"))if(s.cfg.align=l,s.cfg.inpara||-1==s.cfg.inpara.indexOf("atype=2"))await t.alignParserCls.downloadAlignment(s.cfg.align);else{let e=2;await t.chainalignParserCls.downloadMmdbAf(s.cfg.align,void 0,e)}else if(-1!==i.indexOf("load chainalignment")){let e=i.split(" | ");e.length>1&&-1!=e[1].indexOf("resnum")&&(s.cfg.resnum=e[1].substr(e[1].indexOf("resnum")+7)),e.length>2&&-1!=e[2].indexOf("resdef")&&(s.cfg.resdef=e[2].substr(e[2].indexOf("resdef")+7)),e.length>3&&-1!=e[3].indexOf("aligntool")&&(s.cfg.aligntool=e[3].substr(e[3].indexOf("aligntool")+10)),e.length>5&&-1!=e[5].indexOf("resrange")&&(s.cfg.resrange=e[5].substr(e[5].indexOf("resrange")+9)),s.cfg.chainalign=l,await t.chainalignParserCls.downloadChainalignment(l)}else if(-1!==i.indexOf("load url")){let i=e[1],n=void 0!==i?i.indexOf("type "):-1,r="pdb";-1!==n&&(r=i.substr(n+5)),s.cfg.url=l,await t.pdbParserCls.downloadUrl(l,r)}}t.bAddCommands=!0}async applyCommandMap(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | "),i=s[0].substr(8).split(" ");if("sigma"==i[1]){let e=i[2],n=i[0],l="dsn6";if(5==i.length&&(l=i[4]),2==s.length){let i=!0;"dsn6"==l?await t.densityCifParserCls.densityCifParserBase(s[1],n,e,"url",i):"ccp4"==l?await t.ccp4ParserCls.ccp4ParserBase(s[1],n,e,"url",i):"mtz"==l?await t.mtzParserCls.mtzParserBase(s[1],n,e,"url",i):"rcsbmtz"==l&&await t.mtzParserCls.mtzParserBase(s[1],n,e,"url",i,!0)}else await t.densityCifParserCls.densityCifParser(t.inputid,n,e)}}async applyCommandEmmap(e){let t=this.icn3d;t.icn3dui;let s=e.substr(10).split(" ");if(2==s.length&&"percentage"==s[0]){let e=s[1],i="em";await t.densityCifParserCls.densityCifParser(t.inputid,i,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 s=this.icn3d;s.icn3dui;let i=e.substr(e.lastIndexOf(" ")+1);await s.contactMapCls.afErrorMap(i,t)}async applyCommandGraphinteraction(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | ");if(s.length>=3){let e,i=s[1].split(" "),n=i[0].split(","),l=i[1].split(","),r=-1!==s[2].indexOf("hbonds"),o=-1!==s[2].indexOf("salt bridge"),a=-1!==s[2].indexOf("interactions"),d=-1!==s[2].indexOf("halogen"),c=-1!==s[2].indexOf("pi-cation"),h=-1!==s[2].indexOf("pi-stacking");s.length>=4&&(e="true"==s[3]),t.applyCommandCls.setStrengthPara(s),await t.viewInterPairsCls.viewInteractionPairs(n,l,e,"graph",r,o,a,d,c,h)}}async applyCommandCartoon2d(e){let t=this.icn3d;t.icn3dui;let s=e.substr(e.lastIndexOf(" ")+1);await t.cartoon2dCls.draw2Dcartoon(s)}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 s=e.lastIndexOf(" ");e.substr(s+1),await t.annotationCls.setAnnoTabClinvar()}async applyCommandSnp(e){let t=this.icn3d;t.icn3dui;let s=e.lastIndexOf(" ");e.substr(s+1),await t.annotationCls.setAnnoTabSnp()}async applyCommandPTM(e){let t=this.icn3d;t.icn3dui;let s=e.lastIndexOf(" ");e.substr(s+1),await t.annotationCls.setAnnoTabPTM()}applyCommand3ddomain(e){let t=this.icn3d;t.icn3dui;let s=e.lastIndexOf(" "),i=e.substr(s+1);"3ddomain"!=i&&"all"!=i||t.annotationCls.setAnnoTab3ddomain()}async applyCommandViewinteraction(e){let t=this.icn3d,s=t.icn3dui;if(void 0!==s.cfg.align||void 0!==s.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,s=t.icn3dui;t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),e+1===t.commands.length&&(t.bAddCommands=!0),t.bRender=!0;let i=t.commands[e-1]?t.commands[e-1].split("|||"):[];if(2==i.length){let e=JSON.parse(i[1]);t._zoomFactor=e.factor,t.mouseChange.x=e.mouseChange.x,t.mouseChange.y=e.mouseChange.y,t.quaternion._x=e.quaternion._x,t.quaternion._y=e.quaternion._y,t.quaternion._z=e.quaternion._z,t.quaternion._w=e.quaternion._w}if(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 s=t.optsHistory[e-1].pk;"no"===s?t.pk=0:"atom"===s?t.pk=1:"residue"===s?t.pk=2:"strand"===s&&(t.pk=3),t.hlUpdateCls.updateHlAll(),t.drawCls.draw()}else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();(s.cfg.closepopup||s.cfg.imageonly)&&(setTimeout((function(){t.resizeCanvasCls.closeDialogs()}),100),t.resizeCanvasCls.resizeCanvas(s.htmlCls.WIDTH,s.htmlCls.HEIGHT,!0)),t.bTransparentSurface&&t.bRender&&t.drawCls.render(),s.cfg.imageonly&&t.saveFileCls.saveFile(void 0,"png",void 0,!0)}async replayFirstStep(e){let t=this.icn3d,s=t.icn3dui;t.reinitAfterLoad(),await this.execCommandsBase(e,e,t.STATENUMBER);let i=t.commands[e],n=t.commands[e].indexOf("|");-1!=n&&(i=t.commands[e].substr(0,n));let l=i.length>20?i.substr(0,20)+"...":i,r=t.applyCommandCls.getMenuFromCmd(i);$("#"+t.pre+"replay_cmd").html("Cmd: "+l),$("#"+t.pre+"replay_menu").html("Menu: "+r),s.htmlCls.clickMenuCls.setLogCmd(i,!0),t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),t.bRender=!0,t.drawCls.draw()}getHAtoms(e){let t=this.icn3d;t.icn3dui;let s=e.split("|||")[0].trim().split(" | ");if(2==s.length){let e=s[1].split(",");t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(e)}}}class fs{constructor(e){this.icn3d=e}async selectByCommand(e,t,s){let i=this.icn3d,n=i.icn3dui;if(0===e.indexOf("saved atoms")){let s=12,n=e.substr(s);i.definedSetsCls.selectCombinedSets(n,t)}else{let l=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 "),r=("select"===l.trim().substr(0,6)?l.trim().substr(7):l.trim()).split(" or "),o={};for(let e=0,t=r.length;e<t;++e){let t=r[e].trim().replace(/\s+/g," "),s=t.indexOf(" ");i.hAtoms={},"and"===t.substr(0,s).toLowerCase()?(await i.applyCommandCls.applyCommand("select "+t.substr(s+1)),o=n.hashUtilsCls.intHash(o,i.hAtoms)):"not"===t.substr(0,s).toLowerCase()?(await i.applyCommandCls.applyCommand("select "+t.substr(s+1)),o=n.hashUtilsCls.exclHash(o,i.hAtoms)):(await i.applyCommandCls.applyCommand("select "+t),o=n.hashUtilsCls.unionHash(o,i.hAtoms))}i.hAtoms=n.hashUtilsCls.cloneHash(o);let a=Object.keys(i.hAtoms);if(""!==t){i.selectionCls.addCustomSelection(a,t,s,e,!1);let n=[t];i.definedSetsCls.changeCustomAtoms(n)}}}selectBySpec(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui;e="select"===e.trim().substr(0,6)?e.trim().substr(7):e.trim(),l.hAtoms={};let o,a=e.replace(/\s+/g," ").replace(/ AND /g," and ").split(" and "),d={},c={},h=!0;for(let e=0,t=a.length;e<t;++e){let t,s,i,n,o,p=a[e].indexOf("$"),m=a[e].indexOf("."),u=a[e].indexOf(":"),g=a[e].indexOf(":ref_"),f=a[e].indexOf("@"),C=a[e];if(-1===f?o=["*"]:(o=C.substr(f+1).split(","),C=C.substr(0,f)),-1===u&&-1===g)i="*";else if(-1!=g){if(n=C.substr(g+5),C=C.substr(0,g),!n)continue}else if(-1!=u&&(i=C.substr(u+1),C=C.substr(0,u),!i))continue;-1===m?s="*":(s=C.substr(m+1),s=s.replace(/_/g,""),C=C.substr(0,m)),-1===p?t="*":(t=C.substr(p+1),C=C.substr(0,p)),(o.length>1||1==o.length&&"*"!==o[0])&&(h=!1);let b,y,v,_,w=[],S=[];if(w="*"===t?Object.keys(l.structures):t.split(","),"*"===s){let e=Object.keys(l.chains);for(let t=0,s=e.length;t<s;++t){y=e[t],b=y.substr(0,y.indexOf("_")),-1!==w.map((function(e){return e.toLowerCase()})).indexOf(b.toLowerCase())&&S.push(y)}}else for(let e=0,t=w.length;e<t;++e){b=w[e];let t=s.split(",");for(let e in t)S.push(b+"_"+t[e])}let A=!!n,x=A?n.split(","):i.split(",");for(let t=0,s=x.length;t<s;++t){let s,i,n=!1,a=x[t].lastIndexOf("-"),h=!1,p=!1,m=!1;if(-1!==a)v=x[t].substr(0,a),_=x[t].substr(a+1),n=!0;else if(!A&&x[t].length>1&&"3"===x[t][0]&&isNaN(x[t][1])&&"-"!==x[t][0]){i=x[t].toUpperCase().substr(1),m=!0}else if(""===x[t]||isNaN(parseInt(x[t]))){if("*"===x[t])h=!0;else if("proteins"!==x[t]&&"nucleotides"!==x[t]&&"chemicals"!==x[t]&&"ions"!==x[t]&&"water"!==x[t]&&"anchors"!==x[t]&&"strands"!==x[t]&&"loops"!==x[t]){s=x[t].toUpperCase(),p=!0}}else v=x[t],_=v,n=!0;for(let a=0,u=S.length;a<u;++a)if(y=S[a],n){v=isNaN(v)?v:parseInt(v),_=isNaN(_)?_:parseInt(_);for(let t=v;t<=_;++t){let s=[];if(A){let e=l.refnum2residArray[t.toString()]?l.refnum2residArray[t.toString()]:[];for(let t=0,i=e.length;t<i;++t){let i=e[t];i.substr(0,i.lastIndexOf("_"))==y&&s.push(i)}}else{s=[y+"_"+t]}for(let t=0,i=s.length;t<i;++t){let i=s[t];0===e?d[i]=1:d.hasOwnProperty(i)||delete d[i];for(let t in l.residues[i])for(let s=0,i=o.length;s<i;++s){let i=o[s];c=this.processAtomStr(i,c,e,t)}}}}else if(y in l.chains){let n=l.chains[y];for(let s in n){l.atoms[s].resn.substr(0,3).toUpperCase();let i,n,r,a=y+"_"+l.atoms[s].resi;if(A&&(i=l.resid2refnum[a],i&&(n=l.refnumCls.rmStrandFromRefnumlabel(i),r=parseInt(n))),h||"proteins"===x[t]&&s in l.proteins||"nucleotides"===x[t]&&s in l.nucleotides||"chemicals"===x[t]&&s in l.chemicals||"ions"===x[t]&&s in l.ions||"water"===x[t]&&s in l.water||A&&i&&"anchors"===x[t]&&r%100==50||A&&i&&"strands"===x[t]&&!l.residIgLoop.hasOwnProperty(a)||A&&i&&"loops"===x[t]&&l.residIgLoop.hasOwnProperty(a)){0===e?d[a]=1:d.hasOwnProperty(a)||delete d[a];for(let t=0,i=o.length;t<i;++t){let i=o[t];c=this.processAtomStr(i,c,e,s)}}}if(p||m){let t=p?1:3,n=p?s:i,a="",h=[];for(let e=0,t=l.chainsSeq[y].length;e<t;++e){if(p)a+=1==l.chainsSeq[y][e].name.length?l.chainsSeq[y][e].name:" ";else if(m){let t=r.utilsCls.residueAbbr2Name(l.chainsSeq[y][e].name);a+=3==t.length?t:t.padEnd(3,"_")}h.push(l.chainsSeq[y][e].resi)}a=a.toUpperCase();let u=n.replace(/x/gi,"."),g=[],f=new RegExp(u,"i"),C=a,b=C.search(f),v=b/t;for(;-1!==b;)g.push(v),C=C.substr(b+t),b=C.search(f),v+=b/t+1;for(let s=0,i=g.length;s<i;++s){let i=g[s];for(let s=0,r=n.length/t;s<r;s+=t){let n=y+"_"+h[s/t+i];0===e?d[n]=1:d.hasOwnProperty(n)||delete d[n];for(let t in l.residues[n])for(let s=0,i=o.length;s<i;++s){let i=o[s];c=this.processAtomStr(i,c,e,t)}}}}}}}if(l.hAtoms=r.hashUtilsCls.cloneHash(c),0==Object.keys(l.hAtoms).length&&console.log("No residues were selected. Please try another search."),(void 0===i||i)&&l.hlUpdateCls.updateHlAll(),o=h?Object.keys(d):Object.keys(c),""!=t){l.selectionCls.addCustomSelection(o,t,s,e,h);let i=[t];n||l.definedSetsCls.changeCustomAtoms(i)}}processAtomStr(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=e.length;return"*"==e.substr(l-1,1)&&l>1?e.substr(0,l-1)===n.atoms[i].name.substr(0,l-1)&&(0===s?t[i]=1:t.hasOwnProperty(i)||delete t[i]):"*"!==e&&e!==n.atoms[i].name||(0===s?t[i]=1:t.hasOwnProperty(i)||delete t[i]),t}}class Cs{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 s in e.structures){let i=e.structures[s];for(let s=0,n=i.length;s<n;++s)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i[s]])}e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.viewSelectionAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.ALTERNATE_STRUCTURE=-1}selectAChain(e,t,s,i){let n=this.icn3d,l=n.icn3dui;t=t.replace(/\s/g,"");let r=void 0!==s||s?"select alignChain "+e:"select chain "+e;void 0!==i&&i?(n.hAtoms=l.hashUtilsCls.unionHash(n.hAtoms,n.chains[e]),void 0===n.nameArray&&(n.nameArray=[])):(n.hAtoms={},n.nameArray=[]),n.nameArray.push(e);let o,a=s?n.alnChainsSeq[e]:n.chainsSeq[e];o=void 0===a?0:a.length;let d={};for(let t=0,s=o;t<s;++t){let s=a[t],i=e+"_"+s.resi,l=s.name;if(""!==l&&"-"!==l){d[i]=1;for(let e in n.residues[i])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,r,!0);s?n.hlUpdateCls.updateHlAll(void 0,void 0,i,true):n.hlUpdateCls.updateHlAll(n.nameArray,void 0,i,true)}selectResidueList(e,t,s,i,n,l){let r=this.icn3d;if(r.icn3dui,void 0!==e&&Object.keys(e).length>0){if(void 0!==i&&i?void 0===r.nameArray&&(r.nameArray=[]):(r.hAtoms={},r.nameArray=[]),l)for(let t in e)r.hAtoms[t]=1;else for(let t in e)for(let e in r.residues[t])r.hAtoms[e]=1;let o,a;t=t.replace(/\s/g,""),r.nameArray.push(t),l?(o="select "+r.resid2specCls.atoms2spec(r.hAtoms),a=!1):(o="select "+r.resid2specCls.residueids2spec(Object.keys(e)),a=!0);let d=Object.keys(e);this.addCustomSelection(d,t,s,o,a),(void 0===n||n)&&r.hlUpdateCls.updateHlAll(r.nameArray,void 0,i)}}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,s=t.hashUtilsCls.cloneHash(e.hAtoms);e.hAtoms={};for(let i in s)(e.proteins.hasOwnProperty(i)&&"N"!==e.atoms[i].name&&"H"!==e.atoms[i].name&&"C"!==e.atoms[i].name&&"O"!==e.atoms[i].name&&("CA"!==e.atoms[i].name||"C"!==e.atoms[i].elem)&&"HA"!==e.atoms[i].name||e.nucleotides.hasOwnProperty(i)&&-1===t.parasCls.nuclMainArray.indexOf(e.atoms[i].name))&&(e.hAtoms[i]=1);e.hlUpdateCls.showHighlight()}selectMainSideChains(){let e=this.icn3d,t=e.icn3dui,s=e.firstAtomObjCls.getResiduesFromAtoms(e.hAtoms);e.hAtoms={};for(let i in s)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[i]),e.dAtoms=t.hashUtilsCls.unionHash(e.dAtoms,e.residues[i]);e.drawCls.draw(),e.hlUpdateCls.showHighlight()}clickShow_selected(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds(["#"+e.pre+"show_selected","#"+e.pre+"mn2_show_selected"],"click",(function(e){s.icn3d,s.showSelection(),t.htmlCls.clickMenuCls.setLogCmd("show selection",!0)}))}clickHide_selected(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+e.pre+"mn2_hide_selected","click",(function(e){s.icn3d,s.hideSelection(),t.htmlCls.clickMenuCls.setLogCmd("hide selection",!0)}))}getGraphDataForDisplayed(){let e=this.icn3d;e.icn3dui;let t=JSON.parse(e.graphStr),s=e.firstAtomObjCls.getResiduesFromAtoms(e.dAtoms),i=[],n=[],l={};for(let e=0,n=t.nodes.length;e<n;++e){let n=t.nodes[e],r=n.r.substr(4);s.hasOwnProperty(r)&&(i.push(n),l[n.id]=1)}for(let e=0,s=t.links.length;e<s;++e){let s=t.links[e];l.hasOwnProperty(s.source)&&l.hasOwnProperty(s.target)&&n.push(s)}return t.nodes=i,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,s,i,n){let l=this.icn3d;l.icn3dui,n?l.defNames2Residues[t]=e:l.defNames2Atoms[t]=e,l.defNames2Command[t]=i,l.defNames2Descr[t]=s,l.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 s=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=s.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 s=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=s.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,s){let i=this.icn3d,n=i.icn3dui;if(s||(i.selectedResidues={},i.selectedResidues=i.firstAtomObjCls.getResiduesFromCalphaAtoms(i.hAtoms)),!e){t=e="seq_"+(Object.keys(i.defNames2Atoms).length+Object.keys(i.defNames2Residues).length+1)}if(Object.keys(i.selectedResidues).length>0)if(1==i.pk){let l=!0;this.selectResidueList(i.hAtoms,e,t,void 0,void 0,l),this.updateSelectionNameDesc(),s?n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.atoms2spec(i.hAtoms),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.atoms2spec(i.hAtoms)+" | name "+e,!0)}else this.selectResidueList(i.selectedResidues,e,t,void 0,void 0,void 0),this.updateSelectionNameDesc(),s?n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.residueids2spec(Object.keys(i.selectedResidues)),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.residueids2spec(Object.keys(i.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 s={};s[t]=1;let i=t+"_"+e.selectedResidues[t];this.selectResidueList(s,i,i)}}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,s=t.icn3dui,i=e.trim().split("\n");for(let e=0,n=i.length;e<n;++e){let n=i[e].replace(/\t/g," "),l=n.indexOf(" "),r=n.substr(0,l),o=n.substr(l+1),a=o.indexOf(" ");await t.selByCommCls.selectByCommand(o.substr(a+1),r,r),s.htmlCls.clickMenuCls.setLogCmd("select "+o.substr(a+1)+" | name "+r,!0)}}oneStructurePerWindow(){let e=this.icn3d,t=e.icn3dui,s=e.structures?Object.keys(e.structures):[];if(t.cfg.bSidebyside&&2==s.length){let i=s[Object.keys(window.icn3duiHash).indexOf(e.divid)],n=e.structures[i],l={};if(n){for(let s=0,i=n.length;s<i;++s)l=t.hashUtilsCls.unionHash(l,e.chains[n[s]]);e.dAtoms=t.hashUtilsCls.intHash(l,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 s=this.icn3d;if(s.icn3dui,s.bSelectResidue||s.bSelectAlignResidue){let e=$("#"+s.pre+"seq_command_name2").val().replace(/\s+/g,"_");""===e&&(e=$("#"+s.pre+"alignseq_command_name").val().replace(/\s+/g,"_")),""!==e&&this.saveSelection(e,e),s.bSelectResidue=!1,s.bSelectAlignResidue=!1}}saveSelectionPrep(e){var t=this.icn3d,s=t.icn3dui;s.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")||(s.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+t.pre+"atomsCustom").resizable()),e||(t.bSelectResidue=!1,t.bSelectAlignResidue=!1)}selectOneResid(e,t){var s=this.icn3d;s.icn3dui;let i=e.indexOf("$"),n=e.indexOf("."),l=e.indexOf(":"),r=e.indexOf("@");-1==r&&(r=e.length);let o=e.substr(i+1,n-i-1),a=e.substr(n+1,l-n-1),d=e.substr(l+1,r-l-1),c=o+"_"+a+"_"+d;for(let e in s.residues[c])t?delete s.hAtoms[e]:s.hAtoms[e]=1;return t?delete s.selectedResidues[c]:s.selectedResidues[c]=1,"$"+o+"."+a+":"+d}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,s=t.icn3dui;let i=t.structures?Object.keys(t.structures):[];for(let n=0,l=i.length;n<l;++n){let l=i[n],r=t.residues[l+"_MEM_1"],o=t.firstAtomObjCls.getFirstAtomObj(r);if(void 0===o)continue;let a=o.style;t.dAtoms.hasOwnProperty(o.serial)||(t.dAtoms=s.hashUtilsCls.unionHash(t.dAtoms,r),a="nothing");for(let s in r){let i=t.atoms[s];i.style="nothing"!==a?"nothing":"stick",void 0!==e&&(i.style=e?"stick":"nothing")}}void 0===e&&t.drawCls.draw()}adjustMembrane(e,t){var s=this.icn3d;s.icn3dui;for(let i in s.chains[s.inputid.toUpperCase()+"_MEM"]){let n=s.atoms[i];"O"==n.name?n.coord.z=e:"N"==n.name&&(n.coord.z=t)}s.definedSetsCls.setTransmemInMenu(e,t,!0),s.hlUpdateCls.updateHlMenus(),s.drawCls.draw()}selectBtwPlanes(e,t){var s=this.icn3d;if(s.icn3dui,e<t){let s=t;t=e,e=s}let i={};for(let n in s.atoms){let l=s.atoms[n];if("DUM"!=l.resn&&(l.coord.z>=t&&l.coord.z<=e)){i[l.structure+"_"+l.chain+"_"+l.resi]=1}}let n="z_planes_"+e+"_"+t,l=n;this.selectResidueList(i,n,l,!1)}}class bs{constructor(e){this.icn3d=e}residueids2spec(e){var t=this.icn3d;t.icn3dui;let s="";if(void 0!==e){let i,n,l,r,o,a,d,c=e.sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let s=e.lastIndexOf("_"),i=t.lastIndexOf("_");if(e.substr(0,s)<t.substr(0,i))return-1;if(e.substr(0,s)>t.substr(0,i))return 1;if(e.substr(0,s)==t.substr(0,i)){if(parseInt(e.substr(s+1))<parseInt(t.substr(i+1)))return-1;if(parseInt(e.substr(s+1))>parseInt(t.substr(i+1)))return 1;if(parseInt(e.substr(s+1))==parseInt(t.substr(i+1)))return 0}}})),h="",p=0,m=1!=Object.keys(t.structures).length;for(let e=0,u=c.length;e<u;++e){let u=c[e];if(l=u.lastIndexOf("_"),i=u.substr(0,l),n=u.substr(l+1),r=h.indexOf("_"),o=h.substr(0,r),a=h.substr(r+1),isNaN(n))s+=m?"$"+o+"."+a+":"+n+" or ":"."+a+":"+n+" or ";else{if(h!==i)e>0&&(s+=p===d?m?"$"+o+"."+a+":"+d+" or ":"."+a+":"+d+" or ":m?"$"+o+"."+a+":"+d+"-"+p+" or ":"."+a+":"+d+"-"+p+" or "),d=n;else if(h===i){let e=t.ParserUtilsCls.getResiNCBI(h,p);t.ParserUtilsCls.getResiNCBI(i,n)!=e+1&&(s+=p===d?m?"$"+o+"."+a+":"+d+" or ":"."+a+":"+d+" or ":m?"$"+o+"."+a+":"+d+"-"+p+" or ":"."+a+":"+d+"-"+p+" or ",d=n)}h=i,p=n}}r=h.indexOf("_"),o=h.substr(0,r),a=h.substr(r+1),s+=p===d?m?"$"+o+"."+a+":"+d:"."+a+":"+d:m?"$"+o+"."+a+":"+d+"-"+p:"."+a+":"+d+"-"+p}return s}resi2range(e){this.icn3d.icn3dui;let t,s,i=[],n=e.sort((function(e,t){return parseInt(e)-parseInt(t)})),l=n[0];for(let e=0,r=n.length;e<r;++e)s=n[e],0!=e&&s!=t+1&&(i.push(l),i.push(t),l=s),t=s;return i.push(l),i.push(t),i}atoms2spec(e){var t=this.icn3d;t.icn3dui;let s,i="",n=0,l={},r={},o={};for(let a in e)s=t.atoms[a],n>0&&(i+=" or "),i+="$"+s.structure+"."+s.chain+":"+s.resi+"@"+s.name,l[s.structure]=1,r[s.structure+"_"+s.chain]=1,o[s.structure+"_"+s.chain+"_"+s.resi]=1,++n;if(1==Object.keys(o).length){let e="\\$"+s.structure+"\\."+s.chain+":"+s.resi;i=i.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(r).length){let e="\\$"+s.structure+"\\."+s.chain;i=i.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(l).length){let e="\\$"+s.structure;i=i.replace(new RegExp(e,"g"),"")}return i}atoms2residues(e){var t=this.icn3d;t.icn3dui;let s={};for(let t=0,i=e.length;t<i;++t)s[e[t]]=1;let i=t.firstAtomObjCls.getResiduesFromAtoms(s);return Object.keys(i)}atoms2structureArray(e){var t=this.icn3d;t.icn3dui;let s={};for(let i in e){s[t.atoms[i].structure]=1}return Object.keys(s)}selectProperty(e,t,s){var i=this.icn3d,n=i.icn3dui;let l=n.hashUtilsCls.cloneHash(i.hAtoms);if("positive"==e){let e=":r,k,h";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e)}else if("negative"==e){let e=":d,e";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e),i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,i.nucleotides)}else if("hydrophobic"==e){let e=":w,f,y,l,i,c,m";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e),i.hAtoms=n.hashUtilsCls.intHash(i.hAtoms,i.proteins)}else if("polar"==e){let e=":g,v,s,t,a,n,p,q";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e),i.hAtoms=n.hashUtilsCls.intHash(i.hAtoms,i.proteins)}else if("b factor"==e){let e=n.hashUtilsCls.cloneHash(i.calphas);e=n.hashUtilsCls.unionHash(e,i.nucleotidesO3),e=n.hashUtilsCls.unionHash(e,i.chemicals),e=n.hashUtilsCls.unionHash(e,i.ions),e=n.hashUtilsCls.unionHash(e,i.water),i.hAtoms={};for(let l in e){let e=i.atoms[l];e.b>=parseInt(t)&&e.b<=parseInt(s)&&(i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,i.residues[e.structure+"_"+e.chain+"_"+e.resi]))}}else if("percent out"==e){i.bCalcArea=!0,i.opts.surface="solvent accessible surface",i.applyMapCls.applySurfaceOptions(),i.bCalcArea=!1,i.hAtoms={};for(let e in i.resid2area){let l=e.lastIndexOf("_"),r=e.substr(l+1);if(n.parasCls.residueArea.hasOwnProperty(r)){let o=parseInt(i.resid2area[e]/n.parasCls.residueArea[r]*100);if(o>=t&&o<=s){let t=e.substr(0,l);i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,i.residues[t])}}}}i.hAtoms=n.hashUtilsCls.intHash(i.hAtoms,l),i.drawCls.draw(),i.hlUpdateCls.updateHlAll()}selectComplement(){let e=this.icn3d,t=e.icn3dui,s={};for(let t in e.atoms)e.hAtoms.hasOwnProperty(t)||(s[t]=1);e.hAtoms=t.hashUtilsCls.cloneHash(s),e.hlUpdateCls.updateHlAll()}switchHighlightLevel(){var e=this.icn3d.icn3dui;if(e.bNode)return;let t=this;document.addEventListener("keydown",(function(s){let i=t.icn3d;38===s.keyCode?(s.preventDefault(),0!=Object.keys(i.pickedAtomList).length&&i.hAtoms.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.pickedAtomList).serial)||(i.pickedAtomList=e.hashUtilsCls.cloneHash(i.hAtoms)),t.switchHighlightLevelUp(),e.htmlCls.clickMenuCls.setLogCmd("highlight level up",!0)):40===s.keyCode&&(s.preventDefault(),0!=Object.keys(i.pickedAtomList).length&&i.hAtoms.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.pickedAtomList).serial)||(i.pickedAtomList=e.hashUtilsCls.cloneHash(i.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 s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[s.structure+"_"+s.chain+"_"+s.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[s.structure+"_"+s.chain+"_"+s.resi])}else if(2===e.highlightlevel){e.highlightlevel=3;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(s)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(s))}else if(3===e.highlightlevel){let s;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);s=e.pickingCls.select3ddomainFromAtom(i),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,s):e.hAtoms=t.hashUtilsCls.cloneHash(s)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(s).length){e.highlightlevel=5;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s.structure+"_"+s.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[s.structure+"_"+s.chain])}}else if(4===e.highlightlevel){e.highlightlevel=5;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s.structure+"_"+s.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[s.structure+"_"+s.chain])}else if(5===e.highlightlevel||6===e.highlightlevel){e.highlightlevel=6;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl||(e.hAtoms={});let i=e.structures[s.structure];for(let s=0,n=i.length;s<n;++s)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i[s]])}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 s={};for(let t in e.pickedAtomList)residueid=e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi,s[residueid]=1;if(1===Object.keys(s).length){e.highlightlevel=2;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[s.structure+"_"+s.chain+"_"+s.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[s.structure+"_"+s.chain+"_"+s.resi])}}else if(4===e.highlightlevel){e.highlightlevel=3;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(s)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(s))}else if(5===e.highlightlevel){let s;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);s=e.pickingCls.select3ddomainFromAtom(i),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,s):e.hAtoms=t.hashUtilsCls.cloneHash(s)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(s).length){e.highlightlevel=3;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(s)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(s))}}else if(6===e.highlightlevel){e.highlightlevel=5;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s.structure+"_"+s.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[s.structure+"_"+s.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 ys{constructor(e){this.icn3d=e}getFirstAtomObj(e){let t=this.icn3d;if(t.icn3dui,void 0===e||0===Object.keys(e).length)return;let s=Object.keys(e)[0];return t.atoms[s]}getMiddleAtomObj(e,t){let s=this.icn3d;if(s.icn3dui,void 0===e||0===Object.keys(e).length)return;let i=Object.keys(e),n=t&&t<i.length?i[t]:i[parseInt(i.length/2)];return s.atoms[n]}getFirstCalphaAtomObj(e){let t,s=this.icn3d;if(s.icn3dui,void 0!==e&&0!==Object.keys(e).length){for(let i in e)if("CA"==s.atoms[i].name){t=i;break}if(!t)for(let i in e)if("O3'"==s.atoms[i].name||"O3*"==s.atoms[i].name){t=i;break}return void 0!==t?s.atoms[t]:this.getFirstAtomObj(e)}}getFirstAtomObjByName(e,t){let s,i=this.icn3d;if(i.icn3dui,void 0===e||0===Object.keys(e).length)return i.atoms[0];for(let n in e)if(i.atoms[n].name==t){s=n;break}return void 0!==s?i.atoms[s]:void 0}getLastAtomObj(e){let t=this.icn3d;if(t.icn3dui,void 0===e||0===Object.keys(e).length)return t.atoms[0];let s=Object.keys(e),i=s[s.length-1];return t.atoms[i]}getResiduesFromAtoms(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in e){s[t.atoms[i].structure+"_"+t.atoms[i].chain+"_"+t.atoms[i].resi]=1}return s}getResiduesFromCalphaAtoms(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in e)if("CA"==t.atoms[i].name&&t.proteins.hasOwnProperty(i)||!t.proteins.hasOwnProperty(i)){s[t.atoms[i].structure+"_"+t.atoms[i].chain+"_"+t.atoms[i].resi]=t.atoms[i].resn}return s}getChainsFromAtoms(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in e){let e=t.atoms[i];s[e.structure+"_"+e.chain]=1}return s}getAtomFromResi(e,t){let s=this.icn3d;if(s.icn3dui,s.residues.hasOwnProperty(e))for(let i in s.residues[e])if(s.atoms[i].name===t&&!s.atoms[i].het)return s.atoms[i]}getAtomCoordFromResi(e,t){this.icn3d.icn3dui;let s=this.getAtomFromResi(e,t);if(void 0!==s){return void 0!==s.coord2?s.coord2:s.coord}}}class vs{constructor(e){this.icn3d=e}async CalcPhiUrl(e,t,s,i,n){let l=this.icn3d.icn3dui,r=await l.getXMLHttpRqstPromise(n,"GET","text","PQR");await this.CalcPhi(e,t,s,i,r)}getPdbStr(e){let t=this.icn3d,s=t.icn3dui,i={},n={},l=s.hashUtilsCls.intHash(t.dAtoms,t.hAtoms);for(let e in l)t.atoms[e],t.ions.hasOwnProperty(e)?i[e]=1:n[e]=1;let r=Object.keys(n).length;if(s.utilsCls.isCalphaPhosOnly(s.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(r>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="";return o+=s.cfg.cid?t.saveFileCls.getAtomPDB(n,!0,void 0,void 0,void 0,void 0,true):t.saveFileCls.getAtomPDB(n,void 0,void 0,void 0,void 0,void 0,true),o+=t.saveFileCls.getAtomPDB(i,!0,void 0,!0),o}async CalcPhi(e,t,s,i,n){let l=this.icn3d;l.icn3dui;let r=await this.CalcPhiPrms(e,t,s,i,n);this.loadPhiData(r,s,i),l.bAjaxPhi=!0,i?l.setOptionCls.setOption("phisurface","phi"):l.setOptionCls.setOption("phimap","phi")}CalcPhiPrms(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui;l.loadPhiFrom="delphi";let o=r.htmlCls.baseUrl+"delphi/delphi.cgi",a=r.cfg.cid?r.cfg.cid:Object.keys(l.structures).toString(),d={};if(n)d={pqr2phi:n,gsize:e,salt:t,pdbid:a};else{let s=this.getPdbStr();d={pdb2phi:s,gsize:e,salt:t,pdbid:a}}return new Promise((function(e,t){$.ajax({url:o,type:"POST",data:d,dataType:"binary",responseType:"arraybuffer",cache:!0,beforeSend:function(){l.ParserUtilsCls.showLoading()},complete:function(){l.ParserUtilsCls.hideLoading()},success:function(t){e(t)},error:function(e,t,s){}})}))}async PhiParser(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=this;n="phiurl"==t||"phiurl2"==t?"arraybuffer":"text";let a=await r.getXMLHttpRqstPromise(e,"GET",n,"potential");"phiurl"==t||"phiurl2"==t?o.loadPhiData(a,s,i):o.loadCubeData(a,s,i),l.bAjaxPhi=!0,i?l.setOptionCls.setOption("phisurface","phi"):l.setOptionCls.setOption("phimap","phi")}loadPhiData(e,t,s){let i=this.icn3d;i.icn3dui;let n={filetype:"phi"},l=e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e,r=new Float32Array(l.slice(l.byteLength-24,l.byteLength-8));n.scale=r[0];let o=r[1],a=r[2],d=r[3];n.n=new Int32Array(l.slice(l.byteLength-8,l.byteLength-4)),n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new THREE.Vector3(o-c,a-c,d-c);let h=new Float32Array(l.slice(110,l.byteLength-56));n.bSurface=s,i.mapData.headerPhi=n,i.mapData.dataPhi=h,i.mapData.contourPhi=t;let p=new THREE.Matrix4;p.identity(),p.multiply((new THREE.Matrix4).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),i.mapData.matrixPhi=p}loadCubeData(e,t,s){let i=this.icn3d;i.icn3dui;let n={filetype:"cube"},l=e.split("\n"),r=[];r.push(parseFloat(l[0].substr(0,10))),r.push(parseFloat(l[0].substr(10,6))),r.push(parseFloat(l[0].substr(16,10))),r.push(parseFloat(l[0].substr(26,10))),r.push(parseFloat(l[0].substr(36,10))),n.scale=r[0];let o=r[2],a=r[3],d=r[4];n.n=r[1],n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new THREE.Vector3(o-c,a-c,d-c);let h=[];for(let e=7,t=l.length;e<t;++e){let t=l[e].split(/\s+/);for(let e=0,s=t.length;e<s;++e){let s=parseFloat(t[e]);isNaN(s)||h.push(s)}}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=s,i.mapData.headerPhi=n,i.mapData.dataPhi=h,i.mapData.contourPhi=t;let p=new THREE.Matrix4;p.identity(),p.multiply((new THREE.Matrix4).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),i.mapData.matrixPhi=p}async applyCommandPhi(e){let t=this.icn3d;t.icn3dui;let s=this,i=e.split(" | "),n=i[0].split(" "),l=i[1].split(" "),r=i[2].split(" "),o=i[3].split(" "),a=i[4].split(" "),d=n[2],c=parseFloat(l[1]),h=r[1],p=o[1],m=a[1];if(8==i.length){let e=i[5].split(" "),s=i[6].split(" "),n=i[7].split(" ");t.phisurftype=e[1],t.phisurfop=parseFloat(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 u="pqrurl2"==d||"phiurl2"==d||"cubeurl2"==d;"pqrurl"==d||"pqrurl2"==d?await s.CalcPhiUrl(p,m,c,u,h):await s.PhiParser(h,d,c,u)}async applyCommandDelphi(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | "),i=s[0].split(" "),n=s[1].split(" "),l=s[2].split(" "),r=s[3].split(" "),o=i[2],a=n[1],d=l[1],c=r[1];if($("#"+t.pre+"delphi1gsize").val(d),$("#"+t.pre+"delphi1salt").val(c),$("#"+t.pre+"delphi2gsize").val(d),$("#"+t.pre+"delphi2salt").val(c),7==s.length){let e=s[4].split(" "),i=s[5].split(" "),n=s[6].split(" ");t.phisurftype=e[1],t.phisurfop=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 h="surface"==o;await this.CalcPhi(d,c,a,h)}async loadDelphiFile(e){let t=this.icn3d,s=t.icn3dui,i="delphi2"==e?$("#"+t.pre+"delphi2gsize").val():$("#"+t.pre+"delphi1gsize").val(),n="delphi2"==e?$("#"+t.pre+"delphi2salt").val():$("#"+t.pre+"delphi1gsize").val(),l="delphi2"==e?$("#"+t.pre+"delphicontour2").val():$("#"+t.pre+"delphicontour").val(),r="delphi2"==e;await this.CalcPhi(i,n,l,r);let o="delphi2"==e?"surface":"map";r?s.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+l+" | gsize "+i+" | salt "+n+" | surface "+t.phisurftype+" | opacity "+t.phisurfop+" | wireframe "+t.phisurfwf,!0):s.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+l+" | gsize "+i+" | salt "+n,!0)}loadPhiFile(e){let t,s=this.icn3d,i=s.icn3dui,n=this;"pqr"==e||"phi"==e||"cube"==e?t=$("#"+s.pre+e+"file")[0].files[0]:"pqr2"==e?t=$("#"+s.pre+"pqrfile2")[0].files[0]:"phi2"==e?t=$("#"+s.pre+"phifile2")[0].files[0]:"cube2"==e&&(t=$("#"+s.pre+"cubefile2")[0].files[0]);let l="pqr"==e||"phi"==e||"cube"==e?$("#"+s.pre+"phicontour").val():$("#"+s.pre+"phicontour2").val();if(t){i.utilsCls.checkFileAPI();let s=new FileReader;s.onload=async function(t){let s=n.icn3d,r=t.target.result,o=0,a=0;if("pqr"==e||"pqr2"==e){let t="pqr2"==e;o=$("#"+s.pre+e+"gsize").val(),a=$("#"+s.pre+e+"salt").val(),await n.CalcPhi(o,a,l,t,r)}else if("phi"==e||"phi2"==e){let t="phi2"==e;n.loadPhiData(r,l,t)}else if("cube"==e||"cube2"==e){let t="cube2"==e;n.loadCubeData(r,l,t)}s.bAjaxPhi=!0,bSurface?s.setOptionCls.setOption("phisurface","phi"):s.setOptionCls.setOption("phimap","phi"),bSurface?i.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+l+" | file "+$("#"+s.pre+e+"file").val()+" | gsize "+o+" | salt "+a+" | surface "+s.phisurftype+" | opacity "+s.phisurfop+" | wireframe "+s.phisurfwf,!1):i.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+l+" | file "+$("#"+s.pre+e+"file").val()+" | gsize "+o+" | salt "+a,!1)},"phi"==e||"phi2"==e?s.readAsArrayBuffer(t):s.readAsText(t)}else alert("Please select a file before clicking 'Load'")}async loadPhiFileUrl(e){let t,s=this.icn3d,i=s.icn3dui;"pqrurl"==e||"phiurl"==e||"cubeurl"==e?t=$("#"+s.pre+e+"file").val():"pqrurl2"==e?t=$("#"+s.pre+"pqrurlfile2").val():"phiurl2"==e?t=$("#"+s.pre+"phiurlfile2").val():"cubeurl2"==e&&(t=$("#"+s.pre+"cubeurlfile2").val());let n="pqrurl"==e||"phiurl"==e||"cubeurl"==e?$("#"+s.pre+"phiurlcontour").val():$("#"+s.pre+"phiurlcontour2").val();if(t){let l="pqrurl2"==e||"phiurl2"==e||"cubeurl2"==e,r=0,o=0;"pqrurl"==e||"pqrurl2"==e?(r=$("#"+s.pre+e+"gsize").val(),o=$("#"+s.pre+e+"salt").val(),await this.CalcPhiUrl(r,o,n,l,t)):await this.PhiParser(t,e,n,l),l?i.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+r+" | salt "+o+" | surface "+s.phisurftype+" | opacity "+s.phisurfop+" | wireframe "+s.phisurfwf,!0):i.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+r+" | salt "+o,!0)}else alert("Please input the file URL before clicking 'Load'")}}class _s{constructor(e){this.icn3d=e}async applyDssp(e,t){let s=this.icn3d,i=s.icn3dui,n=this,l=e?"1":"0",r=Object.keys(s.structures),o=[],a=window&&window.location&&-1!=window.location.hostname.indexOf("ncbi.nlm.nih.gov")?"/Structure/mmcifparser/mmcifparser.cgi":i.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi";for(let e=0,t=r.length;e<t;++e){let t="",n={},d=s.structures[r[e]];for(let e=0,t=d.length;e<t;++e)n=i.hashUtilsCls.unionHash(n,s.chains[d[e]]);t+=s.saveFileCls.getAtomPDB(n,void 0,!0);let c={dssp:"t",calphaonly:l,pdbfile:t},h=i.getAjaxPostPromise(a,c);o.push(h)}let d=Promise.allSettled(o);try{let e=await d;await n.parseDsspData(e,r,t),i.bNode||await s.ParserUtilsCls.checkMemProteinAndRotate()}catch(e){console.log("DSSP calculation had a problem with this structure "+r[0]+"..."),await s.pdbParserCls.loadPdbDataRender(t)}}async parseDsspData(e,t,s){let i=this.icn3d;i.icn3dui;for(let s=0,n=e.length;s<n;++s){let n=e[s].value;if(void 0!==n&&-1===JSON.stringify(n).indexOf("Oops there was a problem"))for(let e in i.chainsSeq){let l=e.indexOf("_");if(e.substr(0,l)!=t[s])continue;let r,o=e.substr(l+1),a=i.chainsSeq[e],d="coil";for(let t=0,s=a.length;t<s;++t){let s,l=a[t].resi,c=o+"_"+l,h="c";n.hasOwnProperty(c)?h=n[c]:n.hasOwnProperty(" _"+l)?h=n[" _"+l]:n.hasOwnProperty("_"+l)&&(h=n["_"+l]),s="H"===h?"helix":"E"===h?"sheet":"coil";let p=e+"_"+l;i.secondaries[p]=h;let m,u,g=0;if(s!==d?"coil"===d?(m=!0,u=!1):"coil"===s?(g=2,m=!1,u=!1):("sheet"===d&&"helix"===s||"helix"===d&&"sheet"===s)&&(g=2,m=!0,u=!1):(m=!1,u=!1),1==g){let t=e+"_"+r;for(let e in i.residues[t])i.atoms[e].ssbegin=!0,i.atoms[e].ssend=!1}else if(2==g){let t=e+"_"+r;for(let e in i.residues[t])i.atoms[e].ssbegin=!1,i.atoms[e].ssend=!0}for(let e in i.residues[p])i.atoms[e].ss=s,i.atoms[e].ssbegin=m,i.atoms[e].ssend=u;d=s,r=l}}else console.log("DSSP calculation had a problem with this structure "+t[s]+"...")}await i.pdbParserCls.loadPdbDataRender(s)}}class ws{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="IgE",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="IgE",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["RBPJ_6py8C_human_Unk-n2"]="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="IgE",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,s=[];for(let i=0,n=e.refpdbArray.length;i<n;++i){let n=t.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+e.refpdbArray[i],l=t.getAjaxPromise(n,"text");s.push(l)}return s}async showIgRefNum(e){let t=this.icn3d;t.icn3dui;let s=this;this.setRefPdbs();let i=this.getPdbAjaxArray();if(e)await s.parseRefPdbData(void 0,e);else{t.pdbDataArray=await this.promiseWithFixedJobs(i);let n=await s.parseRefPdbData(t.pdbDataArray,e),l=0;for(;!n&&l<15;){let i=!0;n=await s.parseRefPdbData(t.pdbDataArray,e,i),++l}}}async parseRefPdbData(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this,r=Object.keys(i.structures),o=[],a=[],d=n.htmlCls.tmalignUrl;i.resid2domainid||(i.resid2domainid={}),i.domainid2pdb={};let c=!0,h=!1;for(let l=0,p=r.length;l<p;++l){let p=r[l],m=i.structures[p];for(let l=0,r=m.length;l<r;++l){let r=m[l],u=this.getDomainAtomsArray(r,s);if(i.domainid2refpdbname||(i.domainid2refpdbname={}),i.domainid2score||(i.domainid2score={}),0!=u.length){h=!0;for(let s=0,l=u.length;s<l;++s){c=!1;let l=i.saveFileCls.getAtomPDB(u[s],void 0,void 0,void 0,void 0,p),h=i.firstAtomObjCls.getFirstAtomObj(u[s]),m=i.firstAtomObjCls.getLastAtomObj(u[s]),g=r+","+s+"_"+(h.resi+":"+m.resi+":"+Object.keys(u[s]).length);if(delete i.domainid2score[g],i.domainid2pdb[g]=l,t)i.domainid2refpdbname[g]=[t],a.push(g+"|1"+t);else for(let t=0,s=e.length;t<s;++t){let s=i.defaultPdbId+t,r=e[t].value;r="HEADER "+s+"\n"+r;let c={pdb_query:r,pdb_target:l,queryid:i.refpdbArray[t]},h=n.getAjaxPostPromise(d,c);o.push(h),a.push(g+"|"+i.refpdbArray[t])}}}}}if(!h)return c;if(t){n.bNode||console.log("Start alignment with the reference culsters "+JSON.stringify(i.domainid2refpdbname));let e=[],s=[],r=n.htmlCls.tmalignUrl,o=n.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+t,a=n.getAjaxPromise(o,"text"),d=[];d.push(a);let h=await this.promiseWithFixedJobs(d);for(let l in i.domainid2refpdbname){let o=i.domainid2pdb[l];for(let a=0,d=h.length;a<d;++a){let d=i.defaultPdbId+a,c=h[a].value;c="HEADER "+d+"\n"+c;let p={pdb_query:c,pdb_target:o,queryid:t},m=n.getAjaxPostPromise(r,p);e.push(m),s.push(l+"|"+t)}}let p=[];p=await this.promiseWithFixedJobs(e),c=await l.parseAlignData(p,s)}else{let e=[];e=await this.promiseWithFixedJobs(o);let t=!0;c=await l.parseAlignData(e,a,t)}return c}getDomainAtomsArray(e,t){let s=this.icn3d,i=s.icn3dui,n=[];if(s.chainid2atomsLeft||(s.chainid2atomsLeft={}),!s.proteins.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.chains[e]).serial)&&!s.proteins.hasOwnProperty(s.firstAtomObjCls.getMiddleAtomObj(s.chains[e]).serial))return n;if(s.chainsSeq[e].length<20)return n;let l=i.hashUtilsCls.intHash(s.chains[e],s.hAtoms);if(0==Object.keys(l).length)return n;if(t){let t={};for(let e in s.resid2domainid)s.resid2domainid[e]&&(t=i.hashUtilsCls.unionHash(t,s.residues[e]));if(l=i.hashUtilsCls.exclHash(l,t),s.chainid2atomsLeft[e]==Object.keys(l).length)return n;if(s.chainid2atomsLeft[e]=Object.keys(l).length,Object.keys(l).length<200)return n}let r=s.domain3dCls.c2b_NewSplitChain(l,void 0).subdomains;if(r.length>=1)for(let t=0,l=r.length;t<l;++t){let l={},o=r[t],a=0;for(let t=0,n=o.length;t<n;t+=2){let n=parseInt(o[t]),r=parseInt(o[t+1]);for(let t=n;t<=r;++t){let n=s.ncbi2resid[e+"_"+t];++a,l=i.hashUtilsCls.unionHash(l,s.residues[n]),delete s.residIgLoop[n],delete s.resid2domainid[n]}}a<20||n.push(l)}return n}getTemplateList(e){let t=this.icn3d;t.icn3dui;let s="",i="",n="",l="";if(s=t.domainid2refpdbname[e][0],t.domainid2score[e]){let s=t.domainid2score[e].split("_");i=s[0],n=s[1],l=s[2]}return{refpdbname:s,score:i,seqid:n,nresAlign:l}}parseAlignData_part1(e,t,s){let i=this.icn3d,n=i.icn3dui,l={},r={};i.chainid2refpdbname||(i.chainid2refpdbname={}),i.domainid2refpdbname||(i.domainid2refpdbname={}),i.domainid2score||(i.domainid2score={}),i.domainid2ig2kabat||(i.domainid2ig2kabat={}),i.domainid2ig2imgt||(i.domainid2ig2imgt={});for(let o=0,a=t.length;o<a;++o){let a=e[o]?e[o].value:void 0;if(!a||0==a.length){n.bNode||console.log("The alignment data for "+t[o]+" is unavailable...");continue}if(void 0===a[0].score)continue;let d=parseFloat(a[0].score),c=t[o].substr(0,t[o].indexOf("|")),h=t[o].substr(t[o].indexOf("|")+1);if(s){if(a[0].score<this.TMThresholdTemplate||a[0].num_res<10)continue}else if(a[0].score<this.TMThresholdTemplate||a[0].num_res<20){n.bNode||console.log("bRound1: "+s+": domainid "+c+" and refpdbname "+h+" were skipped due to a TM-score less than "+this.TMThresholdTemplate);continue}if(s?(n.bNode||console.log("domainid: "+c+" refpdbname "+h+" TM-score: "+a[0].score),r[c]||(r[c]={}),r[c][h]=d):n.bNode||console.log("refpdbname "+h+" TM-score: "+a[0].score),!s&&a[0].segs){let e=!1,t=!1,s=!1,l=!1,r=!0,o=!0,d=!0,p=!0,m=c.split(",")[0];for(let n=0,c=a[0].segs.length;n<c;++n){let c=a[0].segs[n],h=m+"_"+c.t_start,u=parseInt(c.q_start);if(u>2540&&u<2560?e=!0:u>3540&&u<3560?t=!0:u>7540&&u<7560?s=!0:u>8540&&u<8560&&(l=!0),2550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(r=!1)}else if(3550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(o=!1)}else if(7550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(d=!1)}else if(8550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(p=!1)}if(e&&t&&s&&l)break}if(!(e&&t&&s&&l&&r&&o&&d&&p)){n.bNode||e&&t&&s&&l||console.log("Some of the Ig strands B, C, E, F are missing in the domain "+c+"..."),n.bNode||r&&o&&d&&p||console.log("Some of the Ig strands B, C, E, F are not beta sheets..."),i.domainid2refpdbname[c][0]==h&&(delete i.domainid2refpdbname[c],delete i.domainid2score[c]);continue}}s||n.bNode||console.log("domainid: "+c),(!l.hasOwnProperty(c)||d>=parseFloat(i.domainid2score[c].split("_")[0]))&&(i.domainid2score[c]=a[0].score+"_"+a[0].frac_identical+"_"+a[0].num_res,i.domainid2refpdbname[c]=s?d>=this.TMThresholdIgType?[h]:["all_templates"]:[h],l[c]=a[0].segs,i.domainid2ig2kabat[c]=a[0].ig2kabat,i.domainid2ig2imgt[c]=a[0].ig2imgt)}if(s)for(let e in r)if(!n.bNode&&"all_templates"==i.domainid2refpdbname[e][0]){let t=r[e],s=Object.keys(t);s.sort((function(e,s){return t[s]-t[e]})),i.domainid2refpdbname[e]=s.slice(0,this.topClusters)}return l}async parseAlignData(e,t,s){let i=this.icn3d,n=i.icn3dui,l=!1,r=this.parseAlignData_part1(e,t,s);if(0==Object.keys(r).length)return l=!0,l;if(s){n.bNode||console.log("Start round 2 alignment with the reference culsters "+JSON.stringify(i.domainid2refpdbname));let e=[],t=[],s=n.htmlCls.tmalignUrl;for(let l in i.domainid2refpdbname){let r=[],o=i.domainid2refpdbname[l],a=l.substr(0,l.indexOf(","));i.refpdbHash.hasOwnProperty(a)&&(o=[a],n.bNode||console.log("Adjusted refpdbname for domainid "+l+": "+a));let d=[];for(let e=0,t=o.length;e<t;++e){let t=o[e];i.refpdbHash[t]&&(d=d.concat(i.refpdbHash[t]))}if(0==d.length)continue;for(let e=0,t=d.length;e<t;++e){let t=n.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+d[e],s=n.getAjaxPromise(t,"text");r.push(s)}let c=await this.promiseWithFixedJobs(r),h=i.domainid2pdb[l];for(let r=0,o=c.length;r<o;++r){let o=i.defaultPdbId+r,a=c[r].value;a="HEADER "+o+"\n"+a;let p={pdb_query:a,pdb_target:h,queryid:d[r]},m=n.getAjaxPostPromise(s,p);e.push(m),t.push(l+"|"+d[r])}}let r=[];return r=await this.promiseWithFixedJobs(e),l=await this.parseAlignData(r,t,!1),l}return this.parseAlignData_part3(r),l}parseAlignData_part3(e){let t=this.icn3d,s=t.icn3dui,i={};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 s=e.split(",")[0];i.hasOwnProperty(s)||(t.chainid2refpdbname[s]=[]),i[s]=1,t.chainid2refpdbname.hasOwnProperty(s)||(t.chainid2refpdbname[s]=[]),t.chainid2refpdbname[s].push(t.domainid2refpdbname[e][0]+"|"+e)}t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={}),t.domainid2info||(t.domainid2info={});for(let i in e){let n=e[i],l=i.split(",")[0],r=this.getTemplateList(i),o=r.refpdbname,a=r.score,d=r.seqid,c=r.nresAlign;if(o){let e="The reference PDB for domain "+i+" is "+o+". The TM-score is "+a+". The sequence identity is "+d+". The number of aligned residues is "+c+".";s.bNode||(console.log(e),s.htmlCls.clickMenuCls.setLogCmd(e,!1,!0)),t.domainid2info[i]={refpdbname:o,score:a,seqid:d,nresAlign:c}}let h,p,m,u,g,f,C=!1,b=!1,y=!1,v=!1,_=!1,w=[],S=[],A=[],x=[];for(let e=0,i=n.length;e<i;++e){let i=n[e];if(!i)continue;let r=l+"_"+i.t_start;if(-1!=i.q_start.indexOf("3550")?(C=!0,h=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]),g=0):-1!=i.q_start.indexOf("4550")?(b=!0,p=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]),++g):-1!=i.q_start.indexOf("6550")?(v=!0,m=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]),++g):-1!=i.q_start.indexOf("7550")&&(_=!0,u=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r])),i.q_start>=3545&&i.q_start<=3555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]);e&&w.push(e)}else if(i.q_start>=7545&&i.q_start<=7555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]);e&&S.push(e)}if(-1!=i.q_start.indexOf("8550")&&1==g&&h&&u&&(p||m)){let e=999,t=999;for(let t=0,s=w.length;t<s;++t){let s=b?p.coord.distanceTo(w[t].coord):m.coord.distanceTo(w[t].coord);s<e&&(e=s)}for(let e=0,s=S.length;e<s;++e){let s=b?p.coord.distanceTo(S[e].coord):m.coord.distanceTo(S[e].coord);s<t&&(t=s)}e=parseInt(e),t=parseInt(t);let i=b?parseInt(p.resi)-parseInt(h.resi):parseInt(m.resi)-parseInt(h.resi),n=b?parseInt(u.resi)-parseInt(p.resi):parseInt(u.resi)-parseInt(m.resi),l=1;b?(e>t+l||e==t+l&&i>n+l)&&(A.push(p.resi),s.bNode||console.log("Rename strand C' to D: distToC "+e+" distToE "+t+" resiDistToC "+i+" resiDistToE "+n)):v&&(e+l<t||e+l==t&&i+l<n)&&(x.push(m.resi),s.bNode||console.log("Rename strand D to C': distToC "+e+" distToE "+t+" resiDistToC "+i+" resiDistToE "+n))}if(C&&b&&y&&v&&_)break}for(let e=0,s=n.length;e<s;++e){let s=n[e];if(!s)continue;s.q_start;let r=parseInt(s.q_start),o="";isNaN(s.q_start)&&(o=s.q_start.substr(s.q_start.length-1,1));let a=l+"_"+s.t_start,d=r,c=this.getLabelFromRefnum(d,o);f=c?c.replace(new RegExp(d,"g"),""):void 0;let h=f;if("C'"==f&&A.length>0){for(let e=0,t=A.length;e<t;++e)if(parseInt(s.t_start)<parseInt(A[e])+10&&parseInt(s.t_start)>parseInt(A[e])-10){h="D";break}}else if("D"==f&&x.length>0)for(let e=0,t=x.length;e<t;++e)if(parseInt(s.t_start)<parseInt(x[e])+10&&parseInt(s.t_start)>parseInt(x[e])-10){h="C'";break}f!=h&&(c=this.getLabelFromRefnum(d,o,h)),"helix"!=t.firstAtomObjCls.getFirstAtomObj(t.residues[a]).ss&&(t.resid2refnum[a]=c,t.resid2domainid[a]=i)}}Object.keys(t.resid2refnum).length>0?t.bShowRefnum=!0:s.bNode||t.bNoIg||(console.log("No Ig reference numbers are assigned based on the reference structures in iCn3D..."),t.bNoIg=!0),t.chainid2igtrack||(t.chainid2igtrack={});for(let e in t.chains){let s=t.firstAtomObjCls.getFirstAtomObj(t.chains[e]);if(t.proteins.hasOwnProperty(s.serial)){let s=t.showSeqCls.getSeq(e);t.chainid2igtrack[e]=this.ajdustRefnum(s,e)}}}getStrandFromRefnum(e,t){this.icn3d.icn3dui;let s,i=parseInt(e);return s=i<1e3?void 0:i>=1200&&i<1320?"A---":i>=1320&&i<1420?"A--":i>=1420&&i<1520?"A-":i>=1520&&i<1620?"A":i>=1620&&i<1720?"A+":i>=1720&&i<1820?"A++":i>=1820&&i<2e3?"A'":i>=2e3&&i<3e3?"B":i>=3e3&&i<3420?"C--":i>=3420&&i<3520?"C-":i>=3520&&i<4e3?"C":i>=4e3&&i<5e3?"C'":i>=5e3&&i<6e3?"C''":i>=6e3&&i<7e3?"D":i>=7e3&&i<7620?"E":i>=7620&&i<8e3?"E+":i>=8e3&&i<9e3?"F":i>=9e3&&i<9620?"G":i>=9620&&i<9720?"G+":i>=9720&&i<9820?"G++":i>=9820&&i<9900?"G+++":i>9900?void 0:" ",t&&(s=t),s}getLabelFromRefnum(e,t,s){this.icn3d.icn3dui;let i=this.getStrandFromRefnum(e,s),n=e.toString();return"C'"==s&&"6"==n.substr(0,1)?n="4"+n.substr(1):"D"==s&&"4"==n.substr(0,1)&&(n="6"+n.substr(1)),i?i+n+t:void 0}async parseCustomRefFile(e){let t=this.icn3d;t.icn3dui,t.bShowCustomRefnum=!0;let s=e.split("\n");t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={});let i=[];for(let e=0,t=s.length;e<t;++e){let t=s[e].split(",");i.push(t)}for(let e=1,s=i[0].length;e<s;++e){if(!i[0][e])continue;let s=i[0][e].trim();if(s)for(let n=1,l=i.length;n<l;++n){if(!i[n][e])continue;let l=i[n][0].trim()+"_"+i[n][e].trim();t.refnum2residArray[s]?t.refnum2residArray[s].push(l):t.refnum2residArray[s]=[l]}}for(let e=1,s=i.length;e<s;++e){let s=i[e][0].trim();for(let n=1,l=i[e].length;n<l;++n){if(!i[e][n]||!i[0][n])continue;let l=i[e][n].trim(),r=i[0][n].trim();t.chainsMapping.hasOwnProperty(s)||(t.chainsMapping[s]={});let o=s+"_"+l;l&&r?(t.resid2refnum[o]=r,t.chainsMapping[s][o]=r):t.chainsMapping[s][o]=l}}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 s=this.icn3d,i=s.icn3dui,n="";if("igstrand"==e||"IgStrand"==e){if(s.bShowRefnum)for(let e in s.chains){let t=s.firstAtomObjCls.getFirstAtomObj(s.chains[e]);if(s.proteins.hasOwnProperty(t.serial)){let t=[];for(let i=0;i<s.chainsSeq[e].length;++i)t.push(s.chainsSeq[e][i].name);s.annoIgCls.showRefNum(t,e)}}let e={};for(let t in s.resid2refnum){let n=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(!n)continue;let l=i.utilsCls.residueName2Abbr(n.resn.substr(0,3)),r=s.resid2domainid[t],o=s.resid2refnum[t];if(o){let e=s.refnumCls.rmStrandFromRefnumlabel(o);s.domainid2ig2kabat[r]&&s.domainid2ig2kabat[r][e]}s.resid2refnum[t]&&(s.residIgLoop.hasOwnProperty(t)?e[t+"_"+l]=s.resid2refnum[t]+"_loop":e[t+"_"+l]=s.resid2refnum[t])}for(let t in s.structures){let i=0,l="";for(let n=0,r=s.structures[t].length;s.bShowRefnum&&n<r;++n){let r=s.structures[t][n],o=s.chain2igArray[r];if(o&&o.length>0){l+='{"'+r+'": {\n';for(let t=0,n=o.length;t<n;++t){let n=o[t].startPosArray,a=o[t].endPosArray,d=o[t].domainid,c=s.domainid2info[d];if(c){l+='"'+d+'": {\n',l+='"refpdbname":"'+c.refpdbname+'", "score":'+c.score+', "seqid":'+c.seqid+', "nresAlign":'+c.nresAlign+', "data": [';for(let t=0,i=n.length;t<i;++t){let i=n[t],o=a[t];for(let t=i;t<=o;++t){const i=r+"_"+s.chainsSeq[r][t].resi+"_"+s.chainsSeq[r][t].name;l+='{"'+i+'": "'+e[i]+'"},\n'}}l+="],\n",l+="},\n",i=1}}l+="}},\n"}}n+='{"'+t+'": {"Ig domain" : '+i+', "igs": [\n',i&&(n+=l),n+="]}},\n"}}else if("kabat"==e||"Kabat"==e){let e={};for(let t in s.resid2refnum){let n,l=s.resid2domainid[t],r=s.resid2refnum[t],o=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(!o)continue;let a=i.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(r){let e=s.refnumCls.rmStrandFromRefnumlabel(r);n=s.domainid2ig2kabat[l]?s.domainid2ig2kabat[l][e]:void 0}e[t+"_"+a]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}else if("imgt"==e||"IMGT"==e){let e={};for(let t in s.resid2refnum){let n,l=s.resid2domainid[t],r=s.resid2refnum[t],o=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(!o)continue;let a=i.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(r){let e=s.refnumCls.rmStrandFromRefnumlabel(r);n=s.domainid2ig2imgt[l]?s.domainid2ig2imgt[l][e]:void 0}e[t+"_"+a]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}if(t||(n="["+n+"]"),i.bNode)return n;{let t=Object.keys(i.utilsCls.getHlStructures()).join(",");s.saveFileCls.saveFile(t+"_refnum_"+e+".txt","text",[n])}}async promiseWithFixedJobs(e){let t=this.icn3d,s=t.icn3dui;s.bNode||s.icn3d.ParserUtilsCls.showLoading();let i=[],n=s.cfg.maxajax?s.cfg.maxajax:6*t.refpdbArray.length;for(let t=0,s=parseInt((e.length-1)/n+1);t<s;++t){let l=[];l=t==s-1?e.slice(t*n,e.length):e.slice(t*n,(t+1)*n);let r=Promise.allSettled(l),o=await r;i=i.concat(o)}return s.bNode||s.icn3d.ParserUtilsCls.hideLoading(),i}ajdustRefnum(e,t){let s=this.icn3d,i=s.icn3dui;if(!s.chainid2refpdbname[t])return!1;let n,l,r,o,a,d,c,h,p="",m="",u="",g=!1,f=!1,C=1,b=!1;if(!i.bNode){let e=i.hashUtilsCls.intHash(s.chains[t],s.hAtoms);s.firstAtomObjCls.getResiduesFromAtoms(e)}let y=[],v={},_=0,w=0,S=0,A=0,x=!1;for(let i=0,k=e.length;i<k;++i,++w,++S,++A){let e,k=s.ParserUtilsCls.getResi(t,i),O=t+"_"+k;n=s.resid2refnum[O];let R=n?n.substr(0,1):"";if(b||!n||"A"!=R&&"B"!=R||(b=!0,w=1,x=!1),"G"!=m.substr(0,1)||n||(b=!1),n){e=s.resid2domainid[O],l=s.refnumCls.rmStrandFromRefnumlabel(n),p=n.replace(new RegExp(l,"g"),""),l.substr(0,1),r=l,d=parseInt(r),c=(d-1e3*parseInt(d/1e3)).toString(),h=(d-100*parseInt(d/100)).toString(),f="9"==c.substr(0,1)||"9"==h.substr(0,1)||"0"==h.substr(0,1)||"1"==h.substr(0,1),f&&(s.residIgLoop[O]=1),a=r.replace(d.toString(),""),o=a+"_"+C;let t=parseInt(d.toString().substr(0,2));if(g="5"!=c.substr(0,1)&&"18"!=t,p&&" "!=p){if(!f||g&&!f){let t=parseInt(d.toString().substr(d.toString().length-2,2));if(p!=m&&p!=u){if(x=!1,v[p+o]&&(++C,o=r.replace(d.toString(),"")+"_"+C),v[p+o]=1,y[_]={},y[_].startResi=k,y[_].startRefnum=d,S=0,y[_].domainid=e,y[_].endResi=k,y[_].endRefnum=d,50==t&&(y[_].anchorRefnum=d,y[_].resCntBfAnchor=S,A=0,x=!0),!x&&t>=46&&t<=54){let e=t-50;y[_].anchorRefnum=d-e,y[_].resCntBfAnchor=S-e,A=e,x=!0}g&&(y[_].anchorRefnum=0),y[_].strandPostfix=a,y[_].strand=p,y[_].postfix=o,y[_].loopResCnt=w-1,++_,w=0}else if(v[p+o]){if(50==t&&(y[_-1].anchorRefnum=d,y[_-1].resCntBfAnchor=S,y[_-1].startRefnum=y[_-1].anchorRefnum-y[_-1].resCntBfAnchor,A=0,x=!0),!x&&(51==t||52==t||53==t||54==t)){let e=t-50;y[_-1].anchorRefnum=d-e,y[_-1].resCntBfAnchor=S-e,y[_-1].startRefnum=y[_-1].anchorRefnum-y[_-1].resCntBfAnchor,A=e,x=!0}g&&(y[_-1].anchorRefnum=0),y[_-1].domainid=e,y[_-1].endResi=k,y[_-1].endRefnum=d,y[_-1].resCntAtAnchor=A,y[_-1].anchorRefnum&&(y[_-1].endRefnum=y[_-1].anchorRefnum+y[_-1].resCntAtAnchor),w=0}}u=p}}m=p}for(let e=0,i=y.length;e<i;++e){let n=s.firstAtomObjCls.getFirstAtomObj(s.residues[t+"_"+y[e].startResi]),l=s.firstAtomObjCls.getFirstAtomObj(s.residues[t+"_"+y[e].endResi]),r=s.setSeqAlignCls.getPosFromResi(t,y[e].startResi),o=s.setSeqAlignCls.getPosFromResi(t,y[e].endResi);if("sheet"==n.ss&&!n.ssbegin)for(let i=1;i<=8;++i){let n=r-i,l=s.ParserUtilsCls.getResi(t,n);if(e>0&&parseInt(l)<=parseInt(y[e-1].endResi))break;let o=t+"_"+l,a=s.firstAtomObjCls.getFirstAtomObj(s.residues[o]),d=s.resid2domainid[o];if(a.ssbegin){let o=y[e].startRefnum;y[e].startResi=l,y[e].startRefnum-=i,y[e].loopResCnt-=i,y[e].loopResCnt<0&&(y[e].loopResCnt=0),y[e].resCntBfAnchor+=i;for(let a=1;a<=i;++a){n=r-a,l=s.ParserUtilsCls.getResi(t,n);let i=t+"_"+l;delete s.residIgLoop[i],s.resid2refnum[i]=y[e].strand+(o-a).toString(),s.resid2domainid[i]=d}break}}if("sheet"==l.ss&&!l.ssend)for(let n=1;n<=8;++n){let l=o+n,r=s.ParserUtilsCls.getResi(t,l);if(e<i-1&&parseInt(r)>=parseInt(y[e+1].startResi))break;let a=t+"_"+r,d=s.firstAtomObjCls.getFirstAtomObj(s.residues[a]),c=s.resid2domainid[a];if(d.ssend){let a=y[e].endRefnum;y[e].endResi=r,y[e].endRefnum+=n,e<i-1&&(y[e+1].loopResCnt-=n,y[e+1].loopResCnt<0&&(y[e+1].loopResCnt=0)),y[e].resCntAtAnchor+=n;for(let i=1;i<=n;++i){l=o+i,r=s.ParserUtilsCls.getResi(t,l);let n=t+"_"+r;delete s.residIgLoop[n],s.resid2refnum[n]=y[e].strand+(a+i).toString(),s.resid2domainid[n]=c}break}}}let k={};for(let e=y.length-1;e>=0;--e){"G"!=y[e].strand&&y[e].endRefnum-y[e].startRefnum+1<3&&(y[e+1]&&(y[e+1].loopResCnt+=y[e].loopResCnt+parseInt(y[e].endResi)-parseInt(y[e].startResi)+1),y[e].startResi,y.splice(e,1))}_=0;let O,R,I=0,E=!0,T=!0,P=0;b=!1;let D=0;if(y.length>0)for(let i=0,l=e.length;i<l;++i,++I,++D){let e,l=s.ParserUtilsCls.getResi(t,i),o=t+"_"+l;if(n=s.resid2refnum[o],p=y[_].strand,n){e=s.resid2domainid[o],r=s.refnumCls.rmStrandFromRefnumlabel(n),R=parseInt(r),O=p+R,p=n.replace(new RegExp(r,"g"),"");let t=n.substr(0,1);b||"A"!=t&&"B"!=t||(b=!0,E=!0,I=0)}let a=s.firstAtomObjCls.getFirstAtomObj(s.residues[o]);if(a&&s.proteins.hasOwnProperty(a.serial)){let t=!1,i=!1,r=!1;if(t=parseInt(l)==parseInt(y[_].startResi)&&l!=y[_].startResi?l<y[_].startResi:parseInt(l)<parseInt(y[_].startResi),r=parseInt(l)==parseInt(y[_].endResi)&&l!=y[_].endResi?l>y[_].endResi:parseInt(l)>parseInt(y[_].endResi),i=!t&&!r,t)if(s.residIgLoop[o]=1,E)b?(R=y[_].startRefnum-y[_].loopResCnt+I,O=y[_].strand+R,n=O+y[_].strandPostfix,e=y[_].domainid):(O=void 0,n=void 0);else if(P>=0&&("G"==y[P].strand.substr(0,1)||"F"==y[P].strand.substr(0,1)&&"G"!=y[_].strand.substr(0,1)))T?b&&s.resid2refnum[o]?(T=!0,R=y[P].endRefnum+I,O=y[P].strand+R,n=O+y[P].strandPostfix,e=y[P].domainid):(b=!1,E=!0,T=!1,O=void 0,n=void 0):(O=void 0,n=void 0);else{T=!0;let t=y[_].loopResCnt;I<=parseInt(t/2+.5)?y[P]&&(R=y[P].endRefnum+I,O=y[P].strand+R,n=O+y[P].strandPostfix,e=y[P].domainid):(R=y[_].startRefnum-t+I-1,O=y[_].strand+R,n=O+y[_].strandPostfix,e=y[_].domainid)}else i?(E=!1,y[_].anchorRefnum&&(l==y[_].startResi?(D=y[_].anchorRefnum-y[_].resCntBfAnchor,y[_].startRefnum=D):l==y[_].endResi&&(y[_].endRefnum=D),O=y[_].strand+D,n=O+y[_].strandPostfix,e=y[_].domainid),l==y[_].endResi&&(++_,I=0,y[_]||--_)):r&&(s.residIgLoop[o]=1,T?s.resid2refnum[o]?(T=!0,R=y[_].endRefnum+I,O=y[_].strand+R,n=O+y[_].strandPostfix,e=y[_].domainid):(T=!1,O=void 0,n=void 0):(O=void 0,n=void 0))}else n=void 0;m=p,P=_-1,k.hasOwnProperty(e)?(delete s.resid2refnum[o],delete s.residIgLoop[o],delete s.resid2domainid[o]):(s.resid2refnum[o]=n,s.resid2domainid[o]=e,r=s.refnumCls.rmStrandFromRefnumlabel(n),s.refnum2residArray.hasOwnProperty(r)?s.refnum2residArray[r].push(o):s.refnum2residArray[r]=[o],s.chainsMapping.hasOwnProperty(t)||(s.chainsMapping[t]={}),s.chainsMapping[t][o]=O||l)}return!0}}class Ss{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,s,i,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"),s=.5*$("#"+n.pre+"dl_selectannotations").dialog("option","height"),i=s,$("#"+n.pre+"dl_selectannotations").dialog("option","height",s),$("#"+e).dialog("option","width",t),$("#"+e).dialog("option","height",s);let l={my:"left top",at:"right top+"+i,of:"#"+n.pre+"viewer",collision:"none"};$("#"+e).dialog("option","position",l)}}async retrieveScap(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this;i.bScap=!0;let r="",o=e.split(","),a={},d=[],c={};for(let e=0,t=o.length;e<t;++e){let s=o[e].split("_"),l=s[0]+"_"+s[1]+"_"+s[2];a=n.hashUtilsCls.unionHash(a,i.residues[l]),d.push(l),c[s[1]+"_"+s[2]]="",r+=s[1]+"_"+s[2]+"_"+s[3],e!=t-1&&(r+=",")}let h=i.resid2specCls.residueids2spec(d),p="select "+h,m=i.showInterCls.pickCustomSphere_base(10,a,i.atoms,!1,!1,void 0,p,!1),u=Object.keys(m.residues);i.hAtoms={};for(let e=0,t=u.length;e<t;++e){let t=u[e];for(let e in i.residues[t])i.hAtoms[e]=1}i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,a),i.hAtoms=n.hashUtilsCls.exclHash(i.hAtoms,i.chemicals);let g,f=i.saveFileCls.getAtomPDB(i.hAtoms),C=n.htmlCls.baseUrl+"scap/scap.cgi",b=Object.keys(i.structures)[0],y={pdb:f,snp:r,pdbid:b,v:"2"};g=await n.getAjaxPostPromise(C,y,!0,void 0,void 0,void 0,"text");let v=g.indexOf("\n"),_=g.substr(0,v),w=g.substr(v+1);console.log("free energy: "+_+" kcal/mol");let S=n.hashUtilsCls.cloneHash(i.hAtoms);for(let e in S){let t=i.atoms[e],s=t.structure+"_"+t.chain,l=s+"_"+t.resi;i.chainsMapping.hasOwnProperty(s)||(i.chainsMapping[s]={}),i.chainsMapping[s][l]=n.utilsCls.residueName2Abbr(t.resn)+t.resi}let A=w.split("\n"),x={};for(let e in A){let t=A[e],s=t.substr(0,6);if("ATOM "===s||"HETATM"===s){let e=t.substr(20,2).trim();""===e&&(e="A");let s=e+"_"+t.substr(22,5).trim();c.hasOwnProperty(s)&&(c[s]+=t+"\n"),x[s]=1}}let k=i.saveFileCls.getAtomPDB(i.atoms,!1,!1,!1,c);i.hAtoms={};i.loadPDBCls.loadPDB(k,b,!1,!1,!0,!0);for(let e in i.residues){if(e.substr(0,e.indexOf("_"))==b+"2"){let t=b+e.substr(e.indexOf("_")),s=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(s)for(let t in i.residues[e])i.atoms[t].ss=s.ss,i.atoms[t].ssbegin=s.ssbegin,i.atoms[t].ssend=s.ssend}}for(let e in i.secondaries){if(e.substr(0,e.indexOf("_"))==b+"2"){let t=b+e.substr(e.indexOf("_"));i.secondaries[e]=i.secondaries[t]}}i.setStyleCls.setAtomStyleByOptions(i.opts),i.setColorCls.setColorByOptions(i.opts,i.hAtoms);let O={};for(let e in i.hAtoms){let t=i.atoms[e],s=t.chain+"_"+t.resi;x.hasOwnProperty(s)&&(O[e]=1)}i.hAtoms=n.hashUtilsCls.unionHash(S,O),i.dAtoms=n.hashUtilsCls.cloneHash(i.hAtoms),i.transformCls.zoominSelection(),i.setOptionCls.setStyle("proteins","stick");for(let e in O){let t=i.atoms[e];if(!t.het){let s=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi,n=i.firstAtomObjCls.getFirstAtomObj(i.residues[s]);n&&(i.atoms[e].color=n.color,i.atomPrevColors[e]=n.color)}let s=t.structure+"_"+t.chain,l=s+"_"+t.resi,r=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi;if(i.chainsMapping.hasOwnProperty(s)||(i.chainsMapping[s]={}),i.chainsMapping[s][l]=n.utilsCls.residueName2Abbr(t.resn)+t.resi,-1!=d.indexOf(r)){let e=i.firstAtomObjCls.getFirstAtomObj(i.residues[r]);i.chainsMapping[s][l]=n.utilsCls.residueName2Abbr(e.resn)+e.resi}}if(s)await l.exportPdbProfix(!1,k,r),i.drawCls.draw();else{let e=h,s="snp_"+r;if(await i.selByCommCls.selectByCommand(e,s,s),i.opts.color="atom",i.setColorCls.setColorByOptions(i.opts,i.hAtoms),i.viewInterPairsCls.clearInteractions(),t){let e="linegraph";await i.viewInterPairsCls.viewInteractionPairs(["selected"],["non-selected"],!1,e,!0,!0,!0,!0,!0,!0),l.adjust2DWidth("dl_linegraph")}i.hAtoms=i.dAtoms,i.drawCls.draw(),n.alertAlt||(n.alertAlt=!0,alert('Please press the letter "a" to alternate between wild type and mutant.'))}$("#"+i.pre+"mn2_alternateWrap").show();let R=i.pre+"selection";$("#"+R).show()}async exportPdbProfix(e,t,s){let i,n=this.icn3d,l=n.icn3dui;if(t)i=t;else{let e=l.hashUtilsCls.intHash(n.dAtoms,n.hAtoms),t=!0;i=n.saveFileCls.getAtomPDB(e,void 0,void 0,void 0,void 0,void 0,t)}let r,o=l.htmlCls.baseUrl+"scap/scap.cgi",a={pdb:i,profix:"1",hydrogen:e?"1":"0"};try{r=await l.getAjaxPostPromise(o,a,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(l.bNode)return r;{let t=Object.keys(l.utilsCls.getHlStructures()).join(","),i=e?"add_hydrogen":"add_missing_atoms";s&&(i=s),n.saveFileCls.saveFile(t+"_icn3d_"+i+".pdb","text",[r])}}}class As{constructor(e){this.icn3d=e}async applyCommandSymd(e){this.icn3d.icn3dui,await this.retrieveSymd()}async retrieveSymd(){let e=this.icn3d,t=e.icn3dui,s=this,i=t.htmlCls.baseUrl+"symd/symd.cgi",n=t.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);n=t.hashUtilsCls.intHash(n,e.proteins);let l=Object.keys(n).length,r={};for(let t in n){let s=e.atoms[t];r[s.structure+"_"+s.chain+"_"+s.resi]=1}if(l>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 a,d={pdb:o,pdbid:Object.keys(e.structures).toString()};try{a=await t.getAjaxPostPromise(i,d,!0);let n,l,o,c=a.rcsb_struct_symmetry,h="none";if(void 0!==c){let i;void 0!==e.rmsd_supr&&void 0!==e.rmsd_supr.rot&&(n=e.rmsd_supr.rot,l=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,l=[];for(let e=0,r=n.length;e<r;++e){let r=[],o=new THREE.Vector3(n[e].start[0],n[e].start[1],n[e].start[2]),a=new THREE.Vector3(n[e].end[0],n[e].end[1],n[e].end[2]);i=n[e].order,r.push(o),r.push(a);let d=s.getAxisColor(c[t].symbol,n[e].order),h=s.getPolygonColor(c[t].symbol);r.push(d),r.push(h),r.push(n[e].order),r.push("selection"),l.push(r)}let r={};r[h]=l,e.symdArray.push(r)}if(0==e.symdArray.length)$("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+a.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=a.seqalign.replace(/ /g,"").split(","),l=a.nres,o=a.shift,d=a.rmsd,h=Object.keys(r),p={},m={},u=[],g=[],f=0,C=0,b={};for(let e=0,s=n[0].length;e<s;++e){let s=n[0][e],i=n[1][e];if("-"!=s){if(s==s.toUpperCase()){p[h[f]]=1;let e=t.utilsCls.getIdArray(h[f]);u.push(s+" $"+e[0]+"."+e[1]+":"+e[2]);let i=e[0]+"_"+e[1];b.hasOwnProperty(i)||(b[i]=[]),b[i].push(u.length-1)}++f}if("-"!=i){if(i==i.toUpperCase()){let e=(C+o+l)%l;m[h[e]]=1;let s=t.utilsCls.getIdArray(h[e]);g.push(i+" $"+s[0]+"."+s[1]+":"+s[2])}++C}}let y={},v={},_=[],w=[],S=!1;if(1==Object.keys(b).length){S=!0;let e=parseInt(u.length/i+.5),t=Object.keys(p),s=Object.keys(m);for(let i=0;i<e;++i)y.hasOwnProperty(s[i])||(_.push(u[i]),w.push(g[i]),y[t[i]]=1,v[s[i]]=1)}else{let e,t=0;for(let s in b)b[s].length>t&&(t=b[s].length,e=s);let s=Object.keys(p),i=Object.keys(m);for(let t=0,n=b[e].length;t<n;++t){let n=b[e][t];y.hasOwnProperty(i[n])||(_.push(u[n]),w.push(g[n]),y[s[n]]=1,v[i[n]]=1)}}let A="<br>";A+="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 "+a.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(A),s.setSeqAlignForSymmetry(_,w,S);let x=!1,k=t.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(e.alnChains),void 0,void 0,x,S);A=$("#"+e.pre+"dl_sequence2").html()+k.sequencesHtml,$("#"+e.pre+"dl_sequence2").html(A),$("#"+e.pre+"dl_sequence2").width(t.htmlCls.RESIDUE_WIDTH*k.maxSeqCnt+200),t.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences from SymD");let O=Object.keys(e.defNames2Residues).length+Object.keys(e.defNames2Atoms).length,R="symOri"+O;e.selectionCls.selectResidueList(y,R,R),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(y))+" | name "+R,!1),R="symPerm"+O,e.selectionCls.selectResidueList(v,R,R),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(v))+" | name "+R,!1),R="symBoth"+O,y=t.hashUtilsCls.unionHash(y,v),e.selectionCls.selectResidueList(y,R,R),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(y))+" | name "+R,!1)}}else $("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+a.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(s){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(" ")),s=e.indexOf("$"),i=e.indexOf("."),n=e.indexOf(":"),l=e.substr(s+1,i-s-1),r=e.substr(i+1,n-i-1),o=e.substr(n+1);return{resn:t,resid:l+"_"+r+"_"+o,resi:o,aligned:!0}}setSeqAlignForSymmetry(e,t,s){let i=this.icn3d,n=i.icn3dui;i.conservedName1="symOri_cons",i.conservedName2="symPerm_cons",i.consHash1={},i.consHash2={},i.alnChainsAnTtl={},i.alnChainsAnno={},i.alnChainsSeq={},i.alnChains={},i.alnChainsSeq={};let l={};for(let r=0,o=e.length;r<o;++r){let o,a=this.getResObj(e[r]),d=this.getResObj(t[r]),c=a.resid.substr(0,a.resid.lastIndexOf("_")),h=d.resid.substr(0,d.resid.lastIndexOf("_")),p=h;if(s){p=h.substr(0,h.indexOf("_"))+"2"+h.substr(h.indexOf("_"))}l[a.resid]=1,l[d.resid]=1,o=a.resn==d.resn?"#FF0000":"#0000FF";let m="#"+i.showAnnoCls.getColorhexFromBlosum62(a.resn,d.resn);a.color=o,d.color=o,a.color2=m,d.color2=m;for(let e in i.residues[a.resid])i.atoms[e].color=n.parasCls.thr(o),i.atomPrevColors[e]=n.parasCls.thr(o);for(let e in i.residues[d.resid])i.atoms[e].color=n.parasCls.thr(o),i.atomPrevColors[e]=n.parasCls.thr(o);void 0===i.alnChainsAnTtl[c]&&(i.alnChainsAnTtl[c]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnTtl[c][e]&&(i.alnChainsAnTtl[c][e]=[]);for(let e=0;e<3;++e)i.alnChainsAnTtl[c][e].push("");void 0===i.alnChainsSeq[c]&&(i.alnChainsSeq[c]=[]),void 0===i.alnChainsSeq[p]&&(i.alnChainsSeq[p]=[]),i.alnChainsSeq[c].push(a),i.alnChainsSeq[p].push(d),void 0===i.alnChains[c]&&(i.alnChains[c]={}),void 0===i.alnChains[p]&&(i.alnChains[p]={}),$.extend(i.alnChains[c],i.residues[c+"_"+a.resi]),$.extend(i.alnChains[p],i.residues[p+"_"+d.resi]),i.consHash1[c+"_"+a.resi]=1,i.consHash2[p+"_"+d.resi]=1,void 0===i.alnChainsAnno[c]&&(i.alnChainsAnno[c]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnno[c][e]&&(i.alnChainsAnno[c][e]=[]);let u=".";r%5==0&&(u="*"),r%10==0&&(u="|"),i.alnChainsAnno[c][0].push(u);let g="";r%10==0&&(g=r.toString()),i.alnChainsAnno[c][1].push(g)}}async retrieveSymmetry(e){let t,s=this.icn3d,i=s.icn3dui,n=this,l="https://data.rcsb.org/rest/v1/core/assembly/"+e+"/1";try{t=await i.getAjaxPromise(l,"json",!1)}catch(e){return $("#"+s.pre+"dl_symmetry").html("<br>This structure has no symmetry."),void i.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}let r,o,a,d=t.rcsb_struct_symmetry;if(void 0!==d){void 0!==s.rmsd_supr&&void 0!==s.rmsd_supr.rot&&(r=s.rmsd_supr.rot,o=s.rmsd_supr.trans1,a=s.rmsd_supr.trans2),s.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 i=d[e].rotation_axes,l=[];for(let t=0,c=i.length;t<c;++t){let c=[],h=new THREE.Vector3(i[t].start[0],i[t].start[1],i[t].start[2]),p=new THREE.Vector3(i[t].end[0],i[t].end[1],i[t].end[2]);void 0!==s.rmsd_supr&&void 0!==s.rmsd_supr.rot&&(h=s.surfaceCls.transformMemPro(h,r,o,a),p=s.surfaceCls.transformMemPro(p,r,o,a)),c.push(h),c.push(p);let m=n.getAxisColor(d[e].symbol,i[t].order),u=n.getPolygonColor(d[e].symbol);c.push(m),c.push(u),c.push(i[t].order),c.push(d[e].clusters[0].members[0].asym_id),l.push(c)}s.symmetryHash[t]=l}if(0==Object.keys(s.symmetryHash).length)$("#"+s.pre+"dl_symmetry").html("<br>This structure has no symmetry.");else{let e="<option value='none'>None</option>",t=0;for(let i in s.symmetryHash){e+="<option value='"+i+"' "+(0==t?"selected":"")+">"+i+"</option>",++t}$("#"+s.pre+"selectSymmetry").html(e)}}else $("#"+s.pre+"dl_symmetry").html("<br>This structure has no symmetry.");i.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}getPolygonColor(e){let t=this.icn3d.icn3dui,s=e.substr(0,1);return"C"==s?t.parasCls.thr(16747520):"D"==s?t.parasCls.thr(65535):"T"==s?t.parasCls.thr(15631086):"O"==s?t.parasCls.thr(16753920):"I"==s?t.parasCls.thr(65280):t.parasCls.thr(11119017)}getAxisColor(e,t){let s=this.icn3d.icn3dui,i=e.substr(0,1);return"C"==i?s.parasCls.thr(16711680):"D"==i?2==t?s.parasCls.thr(65535):s.parasCls.thr(16711680):"T"==i?2==t?s.parasCls.thr(65535):s.parasCls.thr(65280):"O"==i||"I"==i?2==t?s.parasCls.thr(65535):3==t?s.parasCls.thr(65280):s.parasCls.thr(16711680):s.parasCls.thr(16711680)}}class xs{constructor(e){this.icn3d=e}alignSW(e,t,s,i,n,l,r){this.icn3d.icn3dui;let o=this.bsa_align(r,e,t,[s,i],[n,l]),a="score: "+o[0]+"\n";a+="start: "+o[1]+"\n",a+="cigar: "+this.bsa_cigar2str(o[2])+"\n\n",a+="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 s=[];s.length=e.length;for(let i=0;i<e.length;++i)s[i]=t[e.charCodeAt(i)];return s}bsa_gen_score_matrix(e,t,s){this.icn3d.icn3dui;let i,n,l=[];for(s>0&&(s=-s),i=0;i<e-1;++i){for(l[i]=[],n=0;n<e-1;++n)l[i][n]=i==n?t:s;l[i][n]=0}l[e-1]=[];for(let t=0;t<e;++t)l[e-1][t]=0;return l}bsa_gen_query_profile(e,t,s){this.icn3d.icn3dui;let i,n="string"==typeof e?this.bsg_enc_seq(e,s):e,l=[];if(t.length>=2&&"number"==typeof t[0]&&"number"==typeof t[1]){if(null==s)return null;let e="number"==typeof s?s:s[s.length-1]+1;i=this.bsa_gen_score_matrix(e,t[0],t[1])}else i=t;for(let e=0;e<i.length;++e){let t,s=i[e];t=l[e]=[];for(let e=0;e<n.length;++e)t[e]=s[n[e]]}return l}bsa_align(e,t,s,i,n,l,r){this.icn3d.icn3dui;null==r&&(r=[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,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,r),a=this.bsa_gen_query_profile(s,i,r),d=a[0].length,c=d>o.length?d:o.length;l=null==l||l<0?c:l;let h,p,m=o.target>d?o.target-d:d-o.target;l=l>m?l:m,"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 u,g=h+p,f=-1073741824,C=[],b=[],y=[],v=0,_=-1,w=-1;if(e)for(let e=0;e<=d;++e)C[e]=b[e]=0;else{C[0]=0,b[0]=-g-g;for(let e=1;e<=d;++e)e>=l?C[e]=b[e]=f:(C[e]=-(g+p*(e-1)),b[e]=-(g+g+p*e))}for(let t=0;t<o.length;++t){let s,i=0,n=0,r=0,c=-1,h=a[o[t]];s=y[t]=[];let m=t>l?t-l:0,u=t+l+1<d?t+l+1:d;e||(i=m>0?f:-(g+p*t),n=m>0?f:-(g+g+p*t));for(let t=m;t<u;++t){let l,o=b[t],a=C[t];C[t]=i,a+=h[t],l=a>=o?0:1,a=a>=o?a:o,l=a>=n?l:2,a=a>=n?a:n,l=!e||a>0?l:64,i=a,c=r>a?c:t,r=r>a?r:a,a-=g,a=!e||a>0?a:0,o-=p,l|=o>a?4:0,o=o>a?o:a,b[t]=o,n-=p,l|=n>a?32:0,n=n>a?n:a,s[t]=l}C[u]=i,b[u]=e?0:f,r>v&&(v=r,_=t,w=c)}if(e&&0==v)return null;u=e?v:C[d];let S,A,x,k=[],O=0,R=0;for(e?(A=_,x=w,w!=d-1&&this.push_cigar(k,4,d-1-w)):(A=o.length-1,x=(A+l+1<d?A+l+1:d)-1);A>=0&&x>=0&&(S=y[A][x-(A>l?A-l:0)],O=S>>(O<<1)&3,!(0==O&&S>>6));)0==O&&(O=3&S),0==O?(this.push_cigar(k,0,1),--A,--x):1==O?(this.push_cigar(k,2,1),--A):(this.push_cigar(k,1,1),--x);e?(x>=0&&this.push_cigar(k,4,x+1),R=A+1):(A>=0&&this.push_cigar(k,2,A+1),x>=0&&this.push_cigar(k,1,x+1));for(let e=0;e<k.length>>1;++e)S=k[e],k[e]=k[k.length-1-e],k[k.length-1-e]=S;return[u,R,k]}push_cigar(e,t,s){this.icn3d.icn3dui,0==e.length||t!=(15&e[e.length-1])?e.push(s<<4|t):e[e.length-1]+=s<<4}bsa_cigar2gaps(e,t,s,i){this.icn3d.icn3dui;let n="",l="",r="",o=0,a=s;for(let s=0;s<i.length;++s){let r=15&i[s],d=i[s]>>4;0==r?(n+=t.substr(o,d),l+=e.substr(a,d),o+=d,a+=d):1==r?(n+=t.substr(o,d),l+=Array(d+1).join("-"),o+=d):2==r?(n+=Array(d+1).join("-"),l+=e.substr(a,d),a+=d):4==r&&(o+=d)}let d=l.toUpperCase(),c=n.toUpperCase();for(let e=0;e<d.length;++e)r+=d.charAt(e)==c.charAt(e)?"|":" ";return[l,n,r]}bsa_cigar2str(e){this.icn3d.icn3dui;let t=[];for(let s=0;s<e.length;++s)t.push((e[s]>>4).toString()+"MIDNSHP=XB".charAt(15&e[s]));return t.join("")}}class ks{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 s=this.icn3d,i=s.icn3dui;if(0==e.length)alert("Please select the first set");else{let n=i.hashUtilsCls.cloneHash(s.hAtoms),l=s.definedSetsCls.getAtomsFromNameArray(e),r=s.definedSetsCls.getAtomsFromNameArray(t);s.bCalcArea=!0,s.opts.surface="solvent accessible surface",s.hAtoms=i.hashUtilsCls.cloneHash(l),s.applyMapCls.applySurfaceOptions();let o=s.areavalue,a=i.hashUtilsCls.cloneHash(s.resid2area);s.hAtoms=i.hashUtilsCls.cloneHash(r),s.applyMapCls.applySurfaceOptions();let d=s.areavalue,c=i.hashUtilsCls.cloneHash(s.resid2area);s.hAtoms=i.hashUtilsCls.unionHash(s.hAtoms,l),s.applyMapCls.applySurfaceOptions();let h=s.areavalue,p=i.hashUtilsCls.cloneHash(s.resid2area),m=0,u=0,g=0,f=0;for(let e in a)p.hasOwnProperty(e)&&(f+=parseFloat(p[e]));u=(o-f).toFixed(2);for(let e in c)p.hasOwnProperty(e)&&(g+=parseFloat(p[e]));m=(d-g).toFixed(2),s.bCalcArea=!1,s.hAtoms=i.hashUtilsCls.cloneHash(n);let C=(parseFloat(d)+parseFloat(o)-parseFloat(h)).toFixed(2),b="<br>Calculate solvent accessible surface area in the interface:<br><br>";b+="Set 1: "+e+", Surface: "+o+" &#8491;<sup>2</sup><br>",b+="Set 2: "+t+", Surface: "+d+" &#8491;<sup>2</sup><br>",b+="Total Surface: "+h+" &#8491;<sup>2</sup><br>",b+="<b>Buried Surface for Set 1</b>: "+u+" &#8491;<sup>2</sup><br>",b+="<b>Buried Surface for Set 2</b>: "+m+" &#8491;<sup>2</sup><br><br>",$("#"+s.pre+"dl_buriedarea_html").html(b),i.htmlCls.dialogCls.openDlg("dl_buriedarea","Buried solvent accessible surface area in the interface"),i.htmlCls.clickMenuCls.setLogCmd("buried surface "+C,!1)}}measureDistTwoSets(e,t){var s=this.icn3d,i=s.icn3dui;if(0==e.length||0==t.length)alert("Please select two sets");else{let n=i.hashUtilsCls.cloneHash(s.hAtoms),l=s.definedSetsCls.getAtomsFromNameArray(e),r=s.definedSetsCls.getAtomsFromNameArray(t),o=s.contactCls.getExtent(l),a=s.contactCls.getExtent(r),d=new THREE.Vector3(o[2][0],o[2][1],o[2][2]),c=new THREE.Vector3(a[2][0],a[2][1],a[2][2]);s.hAtoms=i.hashUtilsCls.cloneHash(n),void 0===s.distPnts&&(s.distPnts=[]),s.distPnts.push(d),s.distPnts.push(c);let h=$("#"+s.pre+"distancecolor2").val();this.addLine(d.x,d.y,d.z,c.x,c.y,c.z,h,!0,"distance");let p=0,m=0,u=d.clone().add(c).multiplyScalar(.5),g=(parseInt(10*d.distanceTo(c))/10).toString()+" A";this.addLabel(g,u.x,u.y,u.z,p,h,m,"distance"),s.drawCls.draw()}}measureDistManySets(e,t){var s=this.icn3d,i=s.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for distance calculation...");else{let n=i.hashUtilsCls.cloneHash(s.hAtoms),l={};for(let i=0,n=e.length;i<n;++i){let n=e[i],r=[n];l[n]={};for(let e=0,i=t.length;e<i;++e){let i=t[e],o=[i];if(n==i)continue;let a=s.definedSetsCls.getAtomsFromNameArray(r),d=s.definedSetsCls.getAtomsFromNameArray(o),c=s.contactCls.getExtent(a),h=s.contactCls.getExtent(d),p=new THREE.Vector3(c[2][0],c[2][1],c[2][2]),m=new THREE.Vector3(h[2][0],h[2][1],h[2][2]),u=p.distanceTo(m);l[n][i]=u.toFixed(2)}}s.hAtoms=i.hashUtilsCls.cloneHash(n);let r="Note: Click on the distance to show a dashed line in 3D view.<br><br>";r+="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,s=t.length;e<s;++e){r+="<th><b>"+t[e]+"</b> (&#8491;)</th>"}r+="</tr>";for(let s=0,i=e.length;s<i;++s){let i=e[s];r+="<tr><th><b>"+i+"</b> (&#8491;)</th>";for(let e=0,s=t.length;e<s;++e){let s=t[e];l[i]&&l[i][s]?r+='<td><span class="icn3d-distance" sets="'+i+"|"+s+'">'+l[i][s]+"</span></td>":r+="<td>0</td>"}r+="</tr>"}r+="</table><br><br>",$("#"+i.pre+"dl_disttable_html").html(r)}}measureAngleManySets(e,t){var s=this.icn3d,i=s.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for angleance calculation...");else{let n={};for(let i=0,l=e.length;i<l;++i){let l=e[i],r=[l];n[l]={},s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(r);let o=s.axesCls.setPc1Axes(!0);for(let e=0,i=t.length;e<i;++e){let i=t[e],r=[i];if(l==i)continue;s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(r);let a=s.axesCls.setPc1Axes(!0),d=new THREE.Vector3(parseFloat(o.x),parseFloat(o.y),parseFloat(o.z)).angleTo(new THREE.Vector3(parseFloat(a.x),parseFloat(a.y),parseFloat(a.z)))/3.1416*180;d=Math.abs(d).toFixed(0),d>180&&(d-=180),d>90&&(d=180-d),n[l][i]=d}}let l="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,s=t.length;e<s;++e){l+="<th><b>"+t[e]+"</b> (&deg;)</th>"}l+="</tr>";for(let s=0,i=e.length;s<i;++s){let i=e[s];l+="<tr><th><b>"+i+"</b> (&deg;)</th>";for(let e=0,s=t.length;e<s;++e){let s=t[e];n[i]&&n[i][s]?l+="<td><span>"+n[i][s]+"</span></td>":l+="<td>0</td>"}l+="</tr>"}l+="</table><br><br>",$("#"+i.pre+"dl_angletable_html").html(l)}}addLine(e,t,s,i,n,l,r,o,a,d,c){var h=this.icn3d;h.icn3dui;let p={};p.position1=new THREE.Vector3(e,t,s),p.position2=new THREE.Vector3(i,n,l),p.color=r,p.dashed=o,p.radius=d,p.opacity=c,void 0===h.lines[a]&&(h.lines[a]=[]),void 0!==a?h.lines[a].push(p):(void 0===h.lines.custom&&(h.lines.custom=[]),h.lines.custom.push(p)),h.hlObjectsCls.removeHlObjects()}addLineFromPicking(e){var t=this.icn3d,s=t.icn3dui;let i=$("#"+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;s.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 "+i+" | 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,i,n,e),t.pickpair=!1}addLabel(e,t,s,i,n,l,r,o){var a=this.icn3d;a.icn3dui;let d={};"0"!==n&&""!==n&&"undefined"!==n||(n=void 0),"0"!==l&&""!==l&&"undefined"!==l||(l=void 0),"0"!==r&&""!==r&&"undefined"!==r||(r=void 0);let c=new THREE.Vector3;c.x=t,c.y=s,c.z=i,d.position=c,d.text=e,d.size=n,d.color=l,d.background=r,void 0===a.labels[o]&&(a.labels[o]=[]),void 0!==o?a.labels[o].push(d):(void 0===a.labels.custom&&(a.labels.custom=[]),a.labels.custom.push(d)),a.hlObjectsCls.removeHlObjects()}addChainLabels(e){var t=this.icn3d;let s=t.icn3dui.hashUtilsCls.intHash(t.hAtoms,e);void 0===t.labels.chain&&(t.labels.chain=[]);let i=t.firstAtomObjCls.getChainsFromAtoms(s);for(let e in i){let s={};s.position=t.applyCenterCls.centerAtoms(t.chains[e]).center;let i=e.indexOf("_"),n=e.substr(i+1),l=t.showSeqCls.getProteinName(e);l.length>20&&(l=l.substr(0,20)+"..."),s.text="Chain "+n+": "+l,s.size=18,t.firstAtomObjCls.getFirstCalphaAtomObj(t.chains[e]).color.getHexString().toUpperCase(),s.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,s.background="#FFFFFF",t.labels.chain.push(s)}t.hlObjectsCls.removeHlObjects()}addTerminiLabels(e){var t=this.icn3d,s=t.icn3dui;let i,n="#FFFFFF";i=s.hashUtilsCls.unionHash(i,t.proteins),i=s.hashUtilsCls.unionHash(i,t.nucleotides);let l=s.hashUtilsCls.intHash(t.dAtoms,i),r=s.hashUtilsCls.intHash(l,e);void 0===t.labels.chain&&(t.labels.chain=[]);let o=t.firstAtomObjCls.getChainsFromAtoms(r);for(let e in o){let i=s.hashUtilsCls.intHash(l,t.chains[e]),r=Object.keys(i),o=t.atoms[r[0]],a=t.atoms[r[r.length-1]],d={},c={};d.position=o.coord,c.position=a.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(),a.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 Os{constructor(e){this.icn3d=e}draw2Ddgm(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=.667,o={},a={},d={},c={},h={};if(void 0===e)return"";for(let s in e.moleculeInfor){let i="#"+("000000"+e.moleculeInfor[s].color.toString(16)).slice(-6),l=e.moleculeInfor[s].chain.trim();void 0===h[l]?h[l]=1:++h[l];let r=t+"_"+(1===h[l]?l:l+h[l].toString());void 0!==n.mmdbid_q&&(n.mmdbid_q,n.mmdbid_t),o[s]=r,a[s]=i,d[s]=e.moleculeInfor[s].name,c[r]=s}if(void 0===i||!i)for(let s=0,i=e.intracResidues.length;s<i;++s){let i,l,r=e.intracResidues[s],a=0;for(let e in r){let t;t=o[e],0===a?i=t:l=t,++a}if(void 0!==i&&void 0!==l){a=0;for(let e in r){let s,o,d=r[e];0===a?(s=i,o=l):(s=l,o=i),void 0===n.chainids2resids[s]&&(n.chainids2resids[s]={}),void 0===n.chainids2resids[s][o]&&(n.chainids2resids[s][o]=[]);for(let i=0,l=d.length;i<l;++i){let l=d[i],r=n.mmdbMolidResid2mmdbChainResi[t.toUpperCase()+"_"+e+"_"+l];n.chainids2resids[s][o].push(r)}if(void 0===n.chainname2residues&&(n.chainname2residues={}),l=o,!n.chains.hasOwnProperty(l))continue;let c,h=n.firstAtomObjCls.getFirstCalphaAtomObj(n.chains[l]);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=l.substr(l.indexOf("_")+1)+"("+c+")";void 0===n.chainname2residues[s]&&(n.chainname2residues[s]={}),n.chainname2residues[s][p]=n.chainids2resids[s][o],++a}}}let p="<div id='#"+n.pre+t+"'>";p+="<b>"+t.toUpperCase()+"</b><br/>",p+="<svg viewBox='0,0,"+l.htmlCls.width2d+","+l.htmlCls.width2d+"'>";let m={},u=[],g="",f="",C={};if(i)for(let e in n.dAtoms){let t=n.atoms[e];C[c[t.structure+"_"+t.chain]]=1}let b=Object.keys(e.moleculeInfor),y=Object.keys(e.intrac),v=[];for(let e=0,t=b.length;e<t;++e)-1===y.indexOf(b[e])&&v.push(b[e]);let _={};if(v.length>0)for(let t in e.intrac){let s=e.intrac[t];for(let e=0,i=s.intrac.length;e<i;++e){let i=s.intrac[e].toString();-1!==v.indexOf(i)&&(void 0===_[i]&&(_[i]=[]),_[i].push(t),u.push([i,t]))}if("rect"===s.shape){let e=s.coords[0]*r,i=s.coords[1]*r,n=s.coords[2]*r-e,l=s.coords[3]*r-i;m[t]=[e+n/2,i+l/2]}else if("circle"===s.shape){let e=s.coords[0]*r,i=s.coords[1]*r;s.coords[2],m[t]=[e,i]}else if("poly"===s.shape){let e=s.coords[0]*r;s.coords[1],s.coords[2];let i=s.coords[3]*r;s.coords[4],s.coords[5],s.coords[6],s.coords[7],m[t]=[e,i]}}let w=0;for(let t=0,l=b.length;t<l;++t){let l=b[t],c=o[l];if(i&&!C.hasOwnProperty(l))continue;let h=e.intrac[l],p="#FFFFFF",y=a[l];if(void 0!==c&&void 0!==n.chains[c]){let e=Object.keys(n.chains[c]);e.length>0&&(y="#"+n.atoms[e[0]].color.getHexString().toUpperCase())}let S="";n.bInitial&&void 0!==s&&(void 0!==n.alignmolid2color&&n.alignmolid2color[s].hasOwnProperty(l)?(S=n.alignmolid2color[s][l],y="#FF0000"):y="#FFFFFF");let A=d[l],x=" ",k=" ";if(void 0!==c){let e=c.indexOf("_");k=c.substr(e+1),x=k.length>1?k.substr(0,1)+"..":k}else c="Misc";void 0===y&&(y="#FFFFFF");let O=1;if(n.bInitial&&void 0!==n.alnChains[c]){let e=0;for(let t in n.alnChains[c]){let s=n.atoms[t].color.getHexString().toUpperCase();"FF0000"!==s&&"00FF00"!==s||++e}O=1*e/Object.keys(n.chains[c]).length}if(O<.2&&(O=.2),-1===v.indexOf(l)){for(let e=0,t=h.intrac.length;e<t;++e)parseInt(l)<parseInt(h.intrac[e])&&u.push([l,h.intrac[e]]);if("rect"===h.shape){let e=h.coords[0]*r,t=h.coords[1]*r,s=h.coords[2]*r-e,i=h.coords[3]*r-t;g+=this.draw2DNucleotide(e+.5*s,t+.5*i,c,k,x,A,S,p,y,r,O),m[l]=[e+s/2,t+i/2]}else if("circle"===h.shape){let e=h.coords[0]*r,t=h.coords[1]*r;g+=this.draw2DProtein(e,t,c,k,x,A,S,p,y,r,O),m[l]=[e,t]}else if("poly"===h.shape){let e=h.coords[0]*r;h.coords[1],h.coords[2];let t=h.coords[3]*r;h.coords[4],h.coords[5],h.coords[6],h.coords[7];let s=e,i=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]),f+=this.draw2DChemical(s,i,c,k,x,A,S,p,y,r,O),m[l]=[e,t]}}else{let e,t,s=300,i=50;if(void 0!==_[l]&&_[l].length>1){let s=0,i=0;for(let e=0,t=_[l].length;e<t;++e){let t=_[l][e];if(m.hasOwnProperty(t)){let e=m[t];s+=e[0],i+=e[1]}}e=s/_[l].length,t=i/_[l].length}else{let n=s/i;w<n-1?(e=(w+1)*i*r,t=.1*s*r):w-(n-1)<n-1?(e=.1*s*r,t=(w-(n-1)+1)*i*r):(e=.25*s*r,t=e),++w}let o=e,a=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]);let d=!0;f+=this.draw2DChemical(o,a,c,k,x,A,S,p,y,r,O,d),m[l]=[o,a]}}for(let e=0,t=u.length;e<t;++e){let t=u[e];if(i&&(!C.hasOwnProperty(t[0])||!C.hasOwnProperty(t[1])))continue;let s,n,l=m[parseInt(t[0])],r=m[parseInt(t[1])];if(void 0===l||void 0===r)continue;s=o[t[0]],n=o[t[1]];let a=s.indexOf("_"),d=n.indexOf("_"),c=s.substr(a+1),h=n.substr(d+1),g=l[0],f=l[1],b=r[0],y=r[1],v=.5*(g+b),_=.5*(f+y);p+="<g class='icn3d-interaction' chainid1='"+s+"' chainid2='"+n+"' >",p+="<title>Interaction of chain "+c+" with chain "+h+"</title>",p+="<line x1='"+g+"' y1='"+f+"' x2='"+v+"' y2='"+_+"' stroke='"+"#000000' stroke-width='2' /></g>",p+="<g class='icn3d-interaction' chainid1='"+n+"' chainid2='"+s+"' >",p+="<title>Interaction of chain "+h+" with chain "+c+"</title>",p+="<line x1='"+v+"' y1='"+_+"' x2='"+b+"' y2='"+y+"' stroke='"+"#000000' stroke-width='2' /></g>"}return p+=f+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;'>&#9711;</span>Protein<br>",t+="<span style='margin-right:18px;'>&#9634;</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>&#9826;</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>&#9634;</span>Biopolymer<br>"):(t+="<span style='margin-right:18px;'>O</span>Protein<br>",t+="<span style='margin-right:18px;'>&#9634;</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>&#9671;</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>&#9634;</span>Biopolymer<br>"),t+="<br><b>Lines</b>:<br> Interactions at 4 &#197;<br>",e&&(t+="<b>Numbers in red</b>:<br> Aligned chains"),t+="</div><br/>",t}highlightNode(e,t,s,i){let n=this.icn3d.icn3dui;i<.2&&(i=.2);if("rect"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(s).attr("x")),l=Number($(s).attr("y")),r=Number($(s).attr("width")),o=Number($(s).attr("height"));$(t).attr("x",e+r/2*(1-i)),$(t).attr("y",l+o/2*(1-i)),$(t).attr("width",r*i),$(t).attr("height",o*i)}else if("circle"===e)$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3),$(t).attr("r",Number($(s).attr("r"))*i);else if("polygon"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(s).attr("x")),l=Number($(s).attr("y")),r=Number($(s).attr("x0d")),o=Number($(s).attr("y0d")),a=Number($(s).attr("x1d")),d=Number($(s).attr("y1d")),c=Number($(s).attr("x2d")),h=Number($(s).attr("y2d")),p=Number($(s).attr("x3d")),m=Number($(s).attr("y3d"));$(t).attr("points",(e+r*i).toString()+", "+(l+o*i).toString()+", "+(e+a*i).toString()+", "+(l+d*i).toString()+", "+(e+c*i).toString()+", "+(l+h*i).toString()+", "+(e+p*i).toString()+", "+(l+m*i).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,s=this;$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-node",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n=$(this).attr("chainid");i.bCtrl||i.bShift||(i.selectionCls.removeSelection(),i.lineArray2d=[]);let l=1;void 0!==i.alnChains[n]&&(l=1*Object.keys(i.alnChains[n]).length/Object.keys(i.chains[n]).length);let r=$(this).find("rect[class='icn3d-hlnode']"),o=$(this).find("rect[class='icn3d-basenode']");s.highlightNode("rect",r,o,l),r=$(this).find("circle[class='icn3d-hlnode']"),o=$(this).find("circle[class='icn3d-basenode']"),s.highlightNode("circle",r,o,l),r=$(this).find("polygon[class='icn3d-hlnode']"),o=$(this).find("polygon[class='icn3d-basenode']"),s.highlightNode("polygon",r,o,l),i.bCtrl||i.bShift?i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.chains[n]):i.hAtoms=t.hashUtilsCls.cloneHash(i.chains[n]),i.bCtrl||i.bShift?(void 0===i.chainArray2d&&(i.chainArray2d=[]),i.chainArray2d.push(n)):i.chainArray2d=[n],i.hlUpdateCls.updateHlAll(i.chainArray2d),i.annotationCls.showAnnoSelectedChains();let a="select chain "+n;t.htmlCls.clickMenuCls.setLogCmd(a,!0),i.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-interaction",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection"),i.bClickInteraction=!0;let n=$(this).attr("chainid1"),l=$(this).attr("chainid2");$(this).find("line").attr("stroke",t.htmlCls.ORANGE),s.selectInteraction(n,l),i.annotationCls.showAnnoSelectedChains();let r="select interaction "+n+","+l;t.htmlCls.clickMenuCls.setLogCmd(r,!0),i.bClickInteraction=!1})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-node",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n=$(this).attr("resid");i.bCtrl||i.bShift||(i.hAtoms={},s.removeLineGraphSelection());$(this).find("circle").attr("stroke",t.htmlCls.ORANGE),$(this).find("circle").attr("stroke-width",2),i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.residues[n]);let l="select "+i.resid2specCls.residueids2spec([n]);i.hlUpdateCls.updateHlAll(),t.htmlCls.clickMenuCls.setLogCmd(l,!0),i.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-interaction",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n=$(this).attr("resid1"),l=$(this).attr("resid2");i.bCtrl||i.bShift||(i.hAtoms={},s.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="+l+"]").find("circle").attr("stroke",t.htmlCls.ORANGE),$("[resid="+l+"]").find("circle").attr("stroke-width",2),i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.residues[n]),i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.residues[l]);let r="select "+i.resid2specCls.residueids2spec([n,l]);i.hlUpdateCls.updateHlAll(),i.transformCls.zoominSelection(),t.htmlCls.clickMenuCls.setLogCmd(r,!0)})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-interaction",(function(e){let t=s.icn3d;e.stopImmediatePropagation(),s.clickInteraction(this),t.transformCls.zoominSelection()})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-interaction",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-interaction",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-interaction",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)}))}clickNode(e){let t=this.icn3d,s=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let i=$(e).attr("resid");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("circle").attr("stroke",s.htmlCls.ORANGE),$(e).find("circle").attr("stroke-width",2),$(e).find("rect").attr("stroke",s.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[i]);let n="select "+t.resid2specCls.residueids2spec([i]);t.hlUpdateCls.updateHlAll(),s.htmlCls.clickMenuCls.setLogCmd(n,!0),t.bSelectResidue=!1}clickInteraction(e){let t=this.icn3d,s=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let i=$(e).attr("resid1"),n=$(e).attr("resid2");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("rect").attr("stroke",s.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[i]),t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[n]);let l="select "+t.resid2specCls.residueids2spec([i,n]);t.hlUpdateCls.updateHlAll(),s.htmlCls.clickMenuCls.setLogCmd(l,!0)}selectInteraction(e,t){let s=this.icn3d;s.icn3dui,s.hlUpdateCls.removeHl2D(),s.hlObjectsCls.removeHlObjects(),s.bCtrl||s.bShift?(void 0===s.lineArray2d&&(s.lineArray2d=[]),s.lineArray2d.push(e),s.lineArray2d.push(t)):s.lineArray2d=[e,t],this.selectInteractionAtoms(e,t),s.hlObjectsCls.addHlObjects(),s.hlUpdateCls.updateHlAll()}selectInteractionAtoms(e,t){let s,i,n=this.icn3d,l=n.icn3dui,r=n.chainids2resids[e][t];n.bCtrl||n.bShift||(n.hAtoms={});for(let e=0,t=r.length;e<t;++e)n.hAtoms=l.hashUtilsCls.unionHash(n.hAtoms,n.residues[r[e]]);if(Object.keys(n.structures).length>1)s="inter_"+e+"_"+t;else{let i=e.indexOf("_"),n=t.indexOf("_");s="inter_"+e.substr(i+1)+"_"+t.substr(n+1)}i="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(r,s,i,o,!0)}draw2DProtein(e,t,s,i,n,l,r,o,a,d,c){this.icn3d.icn3dui;let h=20*d,p="<g class='icn3d-node' chainid='"+s+"' >";return p+="<title>Chain "+i+": "+l+"</title>",p+="<circle class='icn3d-basenode' cx='"+e+"' cy='"+t+"' r='"+h+"' fill='"+o+"' stroke-width='1' stroke='"+"#000000' class='icn3d-node' chainid='"+s+"' />",p+="<circle class='icn3d-hlnode' cx='"+e+"' cy='"+t+"' r='"+(h*c).toString()+"' fill='"+a+"' stroke-width='1' stroke='"+"#000000' />",p+="<text x='"+(e-0).toString()+"' y='"+(t+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==r&&(p+="<text x='"+(e-0).toString()+"' y='"+(t+h+4+6).toString()+"' style='fill:"+a+"; font-size:8; font-weight:bold; text-anchor:middle' >"+r+"</text>"),p+="</g>",p}draw2DNucleotide(e,t,s,i,n,l,r,o,a,d,c){this.icn3d.icn3dui;let h=30*d,p=30*d,m="<g class='icn3d-node' chainid='"+s+"' >";return m+="<title>Chain "+i+": "+l+"</title>",m+="<rect class='icn3d-basenode' x='"+(e-=.5*h)+"' y='"+(t-=.5*p)+"' width='"+h+"' height='"+p+"' fill='"+o+"' stroke-width='1' stroke='"+"#000000' />",m+="<rect class='icn3d-hlnode' x='"+(e+h/2*(1-c)).toString()+"' y='"+(t+p/2*(1-c)).toString()+"' width='"+(h*c).toString()+"' height='"+(p*c).toString()+"' fill='"+a+"' stroke-width='1' stroke='"+"#000000' />",m+="<text x='"+(e+h/2-0).toString()+"' y='"+(t+p/2+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==r&&(m+="<text x='"+(e+h/2-0).toString()+"' y='"+(t+p+4+6).toString()+"' style='fill:"+a+"; font-size:8; font-weight:bold; text-anchor:middle' >"+r+"</text>"),m+="</g>",m}draw2DChemical(e,t,s,i,n,l,r,o,a,d,c,h){this.icn3d.icn3dui;let p,m,u,g,f,C,b,y,v=30*d;if(h){let s=.5*v/Math.sqrt(3),i=.5*v;p=e-s,m=t-i,u=e+3*s,g=t-i,f=e+s,C=t+i,b=e-3*s,y=t+i}else{let s=.5*v,i=.5*v;p=e-s,m=t,u=e,g=t+i,f=e+s,C=t,b=e,y=t-i}let _=p-e,w=m-t,S=u-e,A=g-t,x=f-e,k=C-t,O=b-e,R=y-t,I="<g class='icn3d-node' chainid='"+s+"' >";return I+="<title>Chain "+i+": "+l+"</title>",I+="<polygon class='icn3d-basenode' points='"+p+", "+m+","+u+", "+g+","+f+", "+C+","+b+", "+y+"' x='"+e+"' y='"+t+"' x0d='"+_+"' y0d='"+w+"' x1d='"+S+"' y1d='"+A+"' x2d='"+x+"' y2d='"+k+"' x3d='"+O+"' y3d='"+R+"' fill='"+o+"' stroke-width='1' stroke='"+"#000000' />",I+="<polygon class='icn3d-hlnode' points='"+(e+_*c).toString()+", "+(t+w*c).toString()+","+(e+S*c).toString()+", "+(t+A*c).toString()+","+(e+x*c).toString()+", "+(t+k*c).toString()+","+(e+O*c).toString()+", "+(t+R*c).toString()+"' fill='"+a+"' stroke-width='1' stroke='"+"#000000' />",I+="<text x='"+(e+1).toString()+"' y='"+(t+2).toString()+"' style='fill:#000000; font-size:8; text-anchor:middle' >"+n+"</text>",""!==r&&(I+="<text x='"+(e+1).toString()+"' y='"+(t+2+6).toString()+"' style='fill:"+a+"; font-size:8; font-weight:bold; text-anchor:middle' >"+r+"</text>"),I+="</g>",I}}class Rs{constructor(e){this.icn3d=e}async draw2Dcartoon(e,t){let s=this.icn3d,i=s.icn3dui,n=this;if(i.htmlCls.clickMenuCls.setLogCmd("cartoon 2d "+e,!0),s.cartoon2dType=e,t){let t=n.getCartoonSvg(e,s.graphStr);$("#"+i.svgid_ct).html(t)}else{await this.getNodesLinksForSetCartoon(e),s.graphStr=n.getCartoonData(e,s.node_link);let t=n.getCartoonSvg(e,s.graphStr);$("#"+i.svgid_ct).html(t),n.setEventsForCartoon2d(),i.htmlCls.dialogCls.openDlg("dl_2dctn","2D Cartoon")}}getCartoonSvg(e,t){let s=this.icn3d,i=s.icn3dui,n="",l="",r=JSON.parse(t);s.ctnNodeHash={};for(let t=0,i=r.nodes.length;t<i;++t){let i=r.nodes[t];s.ctnNodeHash[i.id]=i,l+="secondary"==e?this.drawHelix(e,i.id,i.ss,i.x,i.y,i.x1,i.y1,i.x2,i.y2,i.len,i.ang,i.c):this.drawOval(e,i.id,i.x,i.y,i.rx,i.ry,i.ang,i.c,i.from,i.to)}s.nodeid2lineid={};for(let t=0,l=r.links.length;t<l;++t){let l=r.links[t].source,o=r.links[t].target,a=s.ctnNodeHash[l].x,d=i.htmlCls.width2d-s.ctnNodeHash[l].y,c=s.ctnNodeHash[o].x,h=i.htmlCls.width2d-s.ctnNodeHash[o].y;"chain"==e?n+="<g class='icn3d-ctinteraction' chainid1='"+s.ctnNodeHash[l].id+"' chainid2='"+s.ctnNodeHash[o].id+"' >":"domain"==e?n+="<g class='icn3d-ctinteraction' from1='"+s.ctnNodeHash[l].from+"' to1='"+s.ctnNodeHash[l].to+"' from2='"+s.ctnNodeHash[o].from+"' to2='"+s.ctnNodeHash[o].to+"' >":"secondary"==e&&(a=s.ctnNodeHash[l].x2,d=i.htmlCls.width2d-s.ctnNodeHash[l].y2,c=s.ctnNodeHash[o].x1,h=i.htmlCls.width2d-s.ctnNodeHash[o].y1,n+="<g class='icn3d-ctinteraction' range1='"+s.ctnNodeHash[l].range+"' range2='"+s.ctnNodeHash[o].range+"' >");let p=l+"--"+o;n+="<title>Interaction of "+e+" "+this.getLabelFromId(l,e)+" with "+e+" "+this.getLabelFromId(o,e)+"</title>",n+="<line class='icn3d-edge' id='"+p+"' x1='"+a+"' y1='"+d+"' x2='"+c+"' y2='"+h+"' stroke='#bbbbbb' stroke-width='1' /></g>",s.nodeid2lineid.hasOwnProperty(l)||(s.nodeid2lineid[l]=[]),s.nodeid2lineid.hasOwnProperty(o)||(s.nodeid2lineid[o]=[]),s.nodeid2lineid[l].push(p),s.nodeid2lineid[o].push(p)}return n+=l,n}setEventsForCartoon2d(){let e=this.icn3d,t=e.icn3dui;$("#"+t.svgid_ct+" .icn3d-ctnode").draggable({start:function(e,t){let s=parseFloat(e.target.getAttribute("cx")),i=parseFloat(e.target.getAttribute("cy"));e.target.setAttribute("cx",s),e.target.setAttribute("cy",i);let n=e.target.getAttribute("ang");if(n)e.target.setAttribute("transform","rotate("+n+","+s+","+i+")");else{let t=parseFloat(e.target.getAttribute("x1")),s=parseFloat(e.target.getAttribute("y1")),i=parseFloat(e.target.getAttribute("x2")),n=parseFloat(e.target.getAttribute("y2"));e.target.setAttribute("x1",t),e.target.setAttribute("y1",s),e.target.setAttribute("x2",i),e.target.setAttribute("y2",n)}},drag:function(s,i){let n=$("#"+t.svgid_ct).offset().left,l=$("#"+t.svgid_ct).offset().top,r=s.target.getAttribute("id"),o=s.target.getAttribute("ang"),a=s.clientX-n,d=s.clientY-l,c=parseFloat(s.target.getAttribute("cx")),h=parseFloat(s.target.getAttribute("cy")),p=(a-c)/e.resizeRatioX,m=(d-h)/e.resizeRatioY,u=parseFloat($("#"+r+"_text").attr("x")),g=parseFloat($("#"+r+"_text").attr("y"));if($("#"+r+"_text").attr("x",u+p),$("#"+r+"_text").attr("y",g+m),s.target.setAttribute("cx",a),s.target.setAttribute("cy",d),o)s.target.setAttribute("transform","rotate("+o+","+a+","+d+")");else{let e=parseFloat(s.target.getAttribute("x1")),t=parseFloat(s.target.getAttribute("y1")),i=parseFloat(s.target.getAttribute("x2")),n=parseFloat(s.target.getAttribute("y2"));if(s.target.setAttribute("x1",e+p),s.target.setAttribute("y1",t+m),s.target.setAttribute("x2",i+p),s.target.setAttribute("y2",n+m),"S"==r.substr(0,1)){let e=parseFloat($("#"+r+"_box").attr("x1")),t=parseFloat($("#"+r+"_box").attr("y1")),s=parseFloat($("#"+r+"_box").attr("x2")),i=parseFloat($("#"+r+"_box").attr("y2"));$("#"+r+"_box").attr("x1",e+p),$("#"+r+"_box").attr("y1",t+m),$("#"+r+"_box").attr("x2",s+p),$("#"+r+"_box").attr("y2",i+m)}}if(e.nodeid2lineid[r])for(let t=0,s=e.nodeid2lineid[r].length;t<s;++t){f(e.nodeid2lineid[r][t],r,o)}function f(e,t,s){if(e&&-1!=e.indexOf(t)){let t=e.split("--");if(2==t.length){let i,n;i=t[1],n=t[0];let l=s?"cx":"x1",r=s?"cy":"y1",o=$("#"+i).attr(l),a=$("#"+i).attr(r);$("#"+e).attr("x1",o),$("#"+e).attr("y1",a);let d=s?"cx":"x2",c=s?"cy":"y2",h=$("#"+n).attr(d),p=$("#"+n).attr(c);$("#"+e).attr("x2",h),$("#"+e).attr("y2",p)}}}}})}getLabelFromId(e,t){let s=e,i=s.indexOf("__");return-1!==i&&(s=s.substr(0,i)),s="secondary"==t?s.substr(0,s.indexOf("-")):s,s}drawHelix(e,t,s,i,n,l,r,o,a,d,c,h){let p=this.icn3d.icn3dui,m=this.getLabelFromId(t,e);n=p.htmlCls.width2d-n,r=p.htmlCls.width2d-r,a=p.htmlCls.width2d-a;let u="<g range='"+m.substr(1)+"' >";return u+="<title>"+e+" "+m+"</title>","H"==t.substr(0,1)?u+="<line id='"+t+"' class='icn3d-ctnode' x1='"+l+"' y1='"+r+"' x2='"+o+"' y2='"+a+"' cx='"+.5*(l+o).toFixed(1)+"' cy='"+.5*(r+a).toFixed(1)+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='round' />":(u+="<line id='"+t+"_box' x1='"+l+"' y1='"+r+"' x2='"+o+"' y2='"+a+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='square' />",u+="<line id='"+t+"' class='icn3d-ctnode' x1='"+l+"' y1='"+r+"' x2='"+o+"' y2='"+a+"' cx='"+.5*(l+o).toFixed(1)+"' cy='"+.5*(r+a).toFixed(1)+"' stroke='#FFF' stroke-width='1' stroke-linecap='square' />"),u+="<text id='"+t+"_text' x='"+(i-0).toString()+"' y='"+(n+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text8' >"+m+"</text>",u+="</g>",u}drawOval(e,t,s,i,n,l,r,o,a,d){let c=this.icn3d.icn3dui,h=this.getLabelFromId(t,e);i=c.htmlCls.width2d-i,r=180-r;let p="chain"==e?"<g chainid='"+t+"' >":"<g from='"+a+"' 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='"+s.toFixed(0)+"' cy='"+i.toFixed(0)+"' rx='"+n.toFixed(0)+"' ry='"+l.toFixed(0)+"' fill='url(#"+t+"_g_obj)' stroke-width='1' stroke='none' ",p+=" ang='"+r+"' transform='rotate("+r+","+s.toFixed(0)+","+i.toFixed(0)+")'",p+="chain"==e?" chainid='"+t+"' />":" from='"+a+"' to='"+d+"' />",p+="<text id='"+t+"_text' x='"+(s-0).toString()+"' y='"+(i+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text12' >"+h+"</text>",p+="</g>",p}getCartoonData(e,t){let s=this.icn3d;s.icn3dui;let i,n,l=[],r=[];l=t.node;let o=[],a={},d=0;for(let e=0,t=l.length;e<t;++e){let t=l[e],s=JSON.parse(t);a.hasOwnProperty(s.id)||(o.push(s),a[s.id]=d,++d)}let c=[];for(let e=0,t=o.length;e<t;++e){let t=o[e];c.push(JSON.stringify(t))}i=c.join(", "),r=t.link,n=r.join(", "),s.hAtoms;let h='{"nodes": ['+i+'], "links": [';return h+=n+"",h+='], "level": "'+(t.level?t.level:"")+'"}',h}projectTo2d(e){let t=this.icn3d,s=t.icn3dui,i=e.project(t.cam);var n=new THREE.Vector3;return n.x=Math.round((i.x+1)*s.htmlCls.width2d*.5),n.y=Math.round(-i.y*s.htmlCls.width2d*.5),n.z=0,n.y>0?n.y=s.htmlCls.width2d-n.y:n.y=-n.y,n}async getNodesLinksForSetCartoon(e){let t,s,i,n,l,r=this.icn3d,o=r.icn3dui,a=this,d=[],c=[],h=0,p=o.htmlCls.defaultValue,m="",u="",g="",f=!1,C=!0;if("chain"==e){let e={};for(let t in r.hAtoms){let s=r.atoms[t];if("DUM"==s.chain)continue;let i=s.structure+"_"+s.chain;(r.proteins.hasOwnProperty(t)||r.nucleotides.hasOwnProperty(t))&&(e.hasOwnProperty(i)||(e[i]={}),e[i][s.serial]=s)}let t=r.contactCls.getExtent(r.atoms),s=9999,i=9999,n=-9999,a=-9999,h=-9999,p=[];for(let d in e){r.hAtom={},r.hAtoms=o.hashUtilsCls.cloneHash(r.chains[d]);let e=r.axesCls.setPc1Axes(),c=e[0],m=e[1].distanceTo(e[0]),u=e[2].distanceTo(e[0]),g=180*new THREE.Vector2(e[1].x-e[0].x,e[1].y-e[0].y).angle()/Math.PI;g>180&&(g-=180);let f=Object.keys(r.hAtoms)[0],C=r.atoms[f];l=d,c=this.projectTo2d(c);let b=c.x,y=c.y;b<s&&(s=b),b>n&&(n=b),y<i&&(i=y),y>a&&(a=y);let v=.5;m=v*o.htmlCls.width2d*m/(t[1][0]-t[0][0]),u=v*o.htmlCls.width2d*u/(t[1][1]-t[0][1]),m>h&&(h=m),u>h&&(h=u),p.push({id:d,r:l,x:b,y:y,rx:m,ry:u,ang:g,c:C.color.getHexString()})}let m=h+2,u=n-s,g=a-i;for(let e=0,t=p.length;e<t;++e){let t=p[e],n=u<1?.5*o.htmlCls.width2d:(t.x-s)/u*(o.htmlCls.width2d-2*m)+m,l=g<1?.5*o.htmlCls.width2d:(t.y-i)/g*(o.htmlCls.width2d-2*m)+m;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+n.toFixed(0)+', "y": '+l.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}r.hAtoms=o.hashUtilsCls.cloneHash(r.dAtoms),r.node_link={node:d,link:c,level:"chain"}}else if("domain"==e)r.chainid2pssmid||await r.loadScriptCls.applyCommandAnnotationsAndCddSite("view annotations"),a.getNodesLinksForDomains(r.chainid2pssmid);else if("secondary"==e){r.resi2resirange={};let e,a=[];r.contactCls.getExtent(r.atoms);let b="",y=9999,v=9999,_=-9999,w=-9999,S=2,A=[];for(let d in r.hAtoms){let S=r.atoms[d];if("DUM"!=S.chain&&((S.ssbegin||S.ssend)&&"CA"==S.name&&"C"==S.elem)){let d=S.structure+"_"+S.chain+"_"+S.resi;if(C&&S.ssbegin&&(f=!0,C=!1,t=S,b="helix"==S.ss?"H":"S",n=b+S.resi,l="1_1_"+d,g=S.chain),f&&(e=o.utilsCls.residueName2Abbr(S.resn)+S.resi,e+="__"+S.chain,Object.keys(r.structures).length>1&&(e+="__"+S.structure),a.push(e)),g==S.chain&&f&&S.ssend){let o=this.projectTo2d(t.coord.clone()),d=o.x,g=o.y,x=this.projectTo2d(S.coord.clone()),k=x.x,O=x.y;s=.5*(d+k),i=.5*(g+O),d=.5*(s+d),g=.5*(i+g),k=.5*(s+k),O=.5*(i+O),d<y&&(y=d),d>_&&(_=d),g<v&&(v=g),g>w&&(w=g),k<y&&(y=k),k>_&&(_=k),O<v&&(v=O),O>w&&(w=O),f=!1,C=!0,n+="-"+S.resi,l+="-"+S.resi,n+="__"+S.chain,Object.keys(r.structures).length>1&&(n+="__"+S.structure);for(let t=0,s=a.length;t<s;++t)e=a[t],r.resi2resirange[e]=n;a=[],h>0&&m==S.chain&&c.push('{"source": "'+u+'", "target": "'+n+'", "v": '+p+', "c": "'+t.color.getHexString().toUpperCase()+'"}'),A.push({id:n,r:l,ss:b,x:s,y:i,x1:d,y1:g,x2:k,y2:O,c:S.color.getHexString()}),m=S.chain,u=n,++h}}}let x=S+2,k=_-y,O=w-v;for(let e=0,t=A.length;e<t;++e){let t=A[e],s=k<1?.5*o.htmlCls.width2d:(t.x-y)/k*(o.htmlCls.width2d-2*x)+x,i=O<1?.5*o.htmlCls.width2d:(t.y-v)/O*(o.htmlCls.width2d-2*x)+x,n=k<1?.5*o.htmlCls.width2d:(t.x1-y)/k*(o.htmlCls.width2d-2*x)+x,l=O<1?.5*o.htmlCls.width2d:(t.y1-v)/O*(o.htmlCls.width2d-2*x)+x,r=k<1?.5*o.htmlCls.width2d:(t.x2-y)/k*(o.htmlCls.width2d-2*x)+x,a=O<1?.5*o.htmlCls.width2d:(t.y2-v)/O*(o.htmlCls.width2d-2*x)+x;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+s.toFixed(0)+', "y": '+i.toFixed(0)+', "x1": '+n.toFixed(0)+', "y1": '+l.toFixed(0)+', "x2": '+r.toFixed(0)+', "y2": '+a.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}r.node_link={node:d,link:c,level:"secondary"}}}getNodesLinksForDomains(e){let t=this.icn3d,s=t.icn3dui,i=[],n=[],l=s.htmlCls.defaultValue;t.resi2resirange={};let r={};for(let e in t.hAtoms){let s=t.atoms[e];"DUM"!=s.chain&&(r[s.structure+"_"+s.chain]=1)}let o=t.contactCls.getExtent(t.atoms),a=9999,d=9999,c=-9999,h=-9999,p=-9999,m=[];for(let i in r){if(!e.hasOwnProperty(i))continue;let r=e[i].pssmid2name,g=e[i].pssmid2fromArray,f=e[i].pssmid2toArray,C={};for(let e in r){let t=g[e];C[e]=t[0]}var u=Object.keys(C);let b,y;u.sort((function(e,t){return C[e]-C[t]}));for(let e=0,C=u.length;e<C;++e){let C=u[e],v=r[C];v+="__"+i.substr(i.indexOf("_")+1),Object.keys(t.structures).length>1&&(v+="__"+i.substr(0,i.indexOf("_")));let _=g[C],w=f[C];t.hAtoms={};for(let e=0,n=_.length;e<n;++e){let n=parseInt(_[e])+1,l=parseInt(w[e])+1;for(let e=n;e<=l;++e)t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[i+"_"+e])}if(0==Object.keys(t.hAtoms).length)continue;let S=t.axesCls.setPc1Axes(),A=S[0],x=S[1].distanceTo(S[0]),k=S[2].distanceTo(S[0]),O=180*new THREE.Vector2(S[1].x-S[0].x,S[1].y-S[0].y).angle()/Math.PI;O>180&&(O-=180);let R=Object.keys(t.hAtoms)[0],I=t.atoms[R];A=this.projectTo2d(A);let E=A.x,T=A.y;E<a&&(a=E),E>c&&(c=E),T<d&&(d=T),T>h&&(h=T);let P=.5;x=P*s.htmlCls.width2d*x/(o[1][0]-o[0][0]),k=P*s.htmlCls.width2d*k/(o[1][1]-o[0][1]),x>p&&(p=x),k>p&&(p=k),void 0!==b&&n.push('{"source": "'+b+'", "target": "'+v+'", "v": '+l+', "c": "'+y.color.getHexString().toUpperCase()+'"}'),m.push({id:v,from:_+"",to:w+"",x:E,y:T,rx:x,ry:k,ang:O,c:I.color.getHexString()}),b=v,y=I}}let g=p+2,f=c-a,C=h-d;for(let e=0,t=m.length;e<t;++e){let t=m[e],n=f<1?.5*s.htmlCls.width2d:(t.x-a)/f*(s.htmlCls.width2d-2*g)+g,l=C<1?.5*s.htmlCls.width2d:(t.y-d)/C*(s.htmlCls.width2d-2*g)+g;i.push('{"id": "'+t.id+'", "from": "'+t.from+'", "to": "'+t.to+'", "x": '+n.toFixed(0)+', "y": '+l.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}t.hAtoms=s.hashUtilsCls.cloneHash(t.dAtoms),t.node_link={node:i,link:n,level:"domain"}}getSelection(e,t,s){let i=this.icn3d,n=i.icn3dui,l={},r=[],o=t.toString().split(","),a=s.toString().split(","),d=3==e.length?e[2]:Object.keys(i.structures)[0],c=e.length>=2?d+"_"+e[1]:Object.keys(i.chains)[0];for(let e=0,t=o.length;e<t;++e){let t=parseInt(o[e])+1,s=parseInt(a[e])+1;for(let e=t;e<=s;++e){let t=c+"_"+e;l=n.hashUtilsCls.unionHash(l,i.residues[t]),r.push(t)}}return{atomSet:l,residArray:r}}click2Dcartoon(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+t.pre+"2dctn_chain","click",(async function(e){let i=t.icn3d;e.preventDefault(),s.initCartoonSvg(),await i.cartoon2dCls.draw2Dcartoon("chain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_domain","click",(async function(e){let i=t.icn3d;e.preventDefault(),s.initCartoonSvg(),await i.cartoon2dCls.draw2Dcartoon("domain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_secondary","click",(async function(e){let i=t.icn3d;e.preventDefault(),s.initCartoonSvg(),await i.cartoon2dCls.draw2Dcartoon("secondary")})),$(document).on("click","#"+e.pre+"dl_2dctn .icn3d-ctnode",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n,l={},r=[],o=$(this).attr("id"),a=$(this).attr("chainid"),d=$(this).attr("from"),c=$(this).attr("to"),h=$(this).attr("x1");if(void 0!==a)n="chain",l=i.chains[a];else if(void 0!==d){n="domain";let e=o.split("__"),t=s.getSelection(e,d,c);l=t.atomSet,r=t.residArray}else if(void 0!==h){n="secondary";let e=o.split("__"),t=e[0].substr(1).split("-"),i=parseInt(t[0])-1,a=parseInt(t[1])-1,d=s.getSelection(e,i,a);l=d.atomSet,r=d.residArray}i.bCtrl||i.bShift||(i.selectionCls.removeSelection(),i.lineArray2d=[]),void 0!==i.alnChains[a]&&(Object.keys(i.alnChains[a]).length,Object.keys(i.chains[a]).length),i.bCtrl||i.bShift?i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,l):i.hAtoms=t.hashUtilsCls.cloneHash(l),"chain"==n?(i.bCtrl||i.bShift?(void 0===i.chainArray2d&&(i.chainArray2d=[]),i.chainArray2d.push(a)):i.chainArray2d=[a],i.hlUpdateCls.updateHlAll(i.chainArray2d)):i.hlUpdateCls.updateHlAll(),i.annotationCls.showAnnoSelectedChains();let p="chain"==n?"select chain "+a:"select "+i.resid2specCls.residueids2spec(r);t.htmlCls.clickMenuCls.setLogCmd(p,!0),i.bSelectResidue=!1}))}initCartoonSvg(){let e=this.icn3d,t=e.icn3dui;e.resizeRatioX=1,e.resizeRatioY=1,$("#"+t.svgid_ct).empty()}}class Is{constructor(e){this.icn3d=e}async drawLigplot(e){let t=this.icn3d,s=t.icn3dui;s.htmlCls.dialogCls.openDlg("dl_ligplot","Show ligand interactions with atom details");let i,n,l=100,r=100;t.len4ang=80;let o=t.saveFileCls.getAtomPDB(e);o=o.trim(),o=o.replace(/\n\n/g,"\n");let a={pdb2svg:o},d=s.htmlCls.baseUrl+"openbabel/openbabel.cgi",c=(await s.getAjaxPostPromise(d,a,void 0,void 0,void 0,void 0,"text")).split("\n"),h="",p="",m={},u=0,g=0,f=0;t.svgGridSize=t.len4ang,t.gridXY2used={};for(let e=0,s=c.length;e<s;++e){let s=c[e];if(0==s.indexOf("<svg width")){let e=s.indexOf('viewBox="')+9,o=s.substr(e),a=o.substr(0,o.indexOf('"')).split(" ");i=parseFloat(a[2]),n=parseFloat(a[3]),l=i+2*t.len4ang,r=n+2*t.len4ang}else if(0==s.indexOf("<line"))h+=s+"\n";else if(0==s.indexOf("<text"))if(-1!=s.indexOf('font-size="12"')){let e=s.indexOf(">")+1,i=s.substr(e),n=parseInt(i.substr(0,i.indexOf("<")));e=s.indexOf('x="')+3;let l=s.substr(e),r=parseFloat(l.substr(0,l.indexOf('"')));e=s.indexOf('y="')+3;let o=s.substr(e),a=parseFloat(o.substr(0,o.indexOf('"')));m[n]={x:r,y:a};let d=parseInt(r/t.svgGridSize),c=parseInt(a/t.svgGridSize);t.gridXY2used[d+"_"+c]=1,u+=r,g+=a,++f}else p+=s+"\n";else if(0==s.indexOf("</svg>"))break}let C=u/f,b=g/f,y=s.ligplotid;t.ligplotWidth=l;let v=t.ligplotWidth,_=r+30,w=-t.len4ang,S="<svg id='"+y+"' viewBox='"+w+","+w+","+l+","+_+"' width='"+v+"px' font-family='sans-serif' stroke='rgb(0,0,0)' stroke-width='2' stroke-linecap='round'>",A=parseInt(i/t.svgGridSize),x=parseInt(n/t.svgGridSize),k=t.viewInterPairsCls.getAllInteractionTable("save1",m,A,x,C,b);t.bLigplot=!0,S+=h+k.svgHtmlLine,S+=p+k.svgHtmlNode,S+="</svg>",$("#"+t.pre+"ligplotDiv").html(S),this.setEventsForLigplot()}getSvgPerPair(e,t,s,i,n,l,r,o,a,d,c,h,p){let m=this.icn3d,u=m.icn3dui,g="hbond"==i||"contact"==i||"halogen"==i?m.len4ang:1.5*m.len4ang,f=m.len4ang/2,C="contact"==i?1:2,b=m.getGraphCls.convertLabel2Resid(t),y=m.firstAtomObjCls.getFirstAtomObj(m.residues[b]),v=m.getGraphCls.convertLabel2Resid(s),_=m.firstAtomObjCls.getFirstAtomObj(m.residues[v]),w=0,S=0,A=0,x=y.serial;for(let t=0,s=e.length;t<s;++t){let s=e[t]-x+1;w+=n[s].x,S+=n[s].y,++A}let k,O,R,I=w/A-1,E=S/A- -1;if(m.resid2cnt.hasOwnProperty(t)?++m.resid2cnt[t]:m.resid2cnt[t]=0,!c&&!m.resid2ToXy.hasOwnProperty(v)){let e=parseInt(I/m.svgGridSize),s=parseInt(E/m.svgGridSize),i=[];for(let t=1;t>=-1;--t)for(let n=1;n>=-1;--n)0==t&&0==n||e+t>=0&&e+t<=l&&s+n>=0&&s+n<=r&&i.push(e+t+"_"+(s+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<=l&&s+n>=0&&s+n<=r&&i.push(e+t+"_"+(s+n));let n,d=!1;for(let e=0,t=i.length;e<t;++e)if(!m.gridXY2used[i[e]]){n=i[e].split("_"),k=(parseInt(n[0])+.5)*m.svgGridSize,O=(parseInt(n[1])+.5)*m.svgGridSize;let t=Math.sqrt((I-k)*(I-k)+(E-O)*(E-O));k=g/t*(k-I)+I,O=g/t*(O-E)+E,m.gridXY2used[i[e]]=1,d=!0;break}if(!d){let e=I-o,s=E-a,i=0;i=Math.abs(e)>Math.abs(s)?e>0?0:180:s>0?90:270,R=i-10+30*m.resid2cnt[t],k=I+g*Math.cos(R*Math.PI/180),O=E+g*Math.sin(R*Math.PI/180)}}let T,P=u.utilsCls.residueName2Abbr(_.resn.substr(0,3))+_.resi,D=_.color?_.color.getHexString():"000",M=m.lineGraphCls.getStrokecolor(void 0,i),F="",H="",L=v+"--"+e.join("-")+i;"hbond"==i?T="H-Bonds":"ionic"==i?T="Salt Bridge/Ionic":"halogen"==i?T="Halogen Bonds":"pi-cation"==i?T="&pi;-Cation":"pi-stacking"==i?T="&pi;-Stacking":"contact"==i&&(T="Contacts");let N=v;if(c||m.resid2ToXy.hasOwnProperty(N)){k=m.resid2ToXy.hasOwnProperty(N)?m.resid2ToXy[N].x2:h,O=m.resid2ToXy.hasOwnProperty(N)?m.resid2ToXy[N].y2:p;let e=I,t=E,s=0;if("contact"==i){let i=Math.sqrt((I-k)*(I-k)+(E-O)*(E-O));f<i&&(e=f/i*(I-k)+k,t=f/i*(E-O)+O,s=1)}H+="<g><title>Interaction type: "+T+"; Distance: "+parseFloat(d).toFixed(1)+" &#197;</title>",H+='<line class="icn3d-interaction" id="'+L+'" resid1="'+b+'" resid2="'+v+'" x1="'+e.toFixed(2)+'" y1="'+t.toFixed(2)+'" x2="'+k.toFixed(2)+'" y2="'+O.toFixed(2)+'" x0="'+I.toFixed(2)+'" y0="'+E.toFixed(2)+'" short="'+s+'" opacity="1.0" stroke="'+M+'" stroke-width="'+C+'" stroke-dasharray="5,5"/>\n',H+="</g>\n"}else{F+="<g><title>"+P+"</title>";let e=28,t=14;F+='<rect id="'+N+'_node" x="'+(k-.5*e).toFixed(2)+'" y="'+(O-.5*t).toFixed(2)+'" width="'+e+'" height="'+t+'" rx="2" ry="2" fill="#'+D+'" stroke-width="1" stroke="'+D+'" resid="'+v+'"/>',F+='<text class="icn3d-ctnode" resid="'+N+'" id="'+N+'" x="'+k.toFixed(2)+'" y="'+O.toFixed(2)+'" fill="#000" stroke="none" text-anchor="middle" alignment-baseline="central" style="font-size:10px">'+P+"</text>",F+="</g>\n",H+="<g><title>Interaction type: "+T+"; Distance: "+parseFloat(d).toFixed(1)+" &#197;</title>",H+='<line class="icn3d-interaction" id="'+L+'" resid1="'+b+'" resid2="'+v+'" x1="'+I.toFixed(2)+'" y1="'+E.toFixed(2)+'" x2="'+k.toFixed(2)+'" y2="'+O.toFixed(2)+'" opacity="1.0" stroke="'+M+'" stroke-width="'+C+'" stroke-dasharray="5,5"/>',H+="</g>\n","contact"!=i&&(m.resid2ToXy.hasOwnProperty(v)||(m.resid2ToXy[v]={x2:k,y2:O}))}return m.nodeid2lineid.hasOwnProperty(N)||(m.nodeid2lineid[N]=[]),m.nodeid2lineid[N].push(L),{node:F,line:H,x2:k,y2:O}}setEventsForLigplot(){let e=this.icn3d,t=e.icn3dui;$("#"+t.ligplotid+" .icn3d-ctnode").draggable({start:function(e,t){let s=parseFloat(e.target.getAttribute("x")),i=parseFloat(e.target.getAttribute("y"));e.target.setAttribute("x",s),e.target.setAttribute("y",i)},drag:function(s,i){let n=e.ligplotScale?e.ligplotScale:1,l=$("#"+t.ligplotid).offset().left+e.len4ang*n,r=$("#"+t.ligplotid).offset().top+e.len4ang*n,o=s.target.getAttribute("resid"),a=(s.clientX-l)/n,d=(s.clientY-r)/n,c=parseFloat(s.target.getAttribute("x")),h=parseFloat(s.target.getAttribute("y")),p=a-c,m=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+m),s.target.setAttribute("x",a),s.target.setAttribute("y",d),e.nodeid2lineid[o])for(let t=0,s=e.nodeid2lineid[o].length;t<s;++t){u(e.nodeid2lineid[o][t],o)}function u(t,s){if(t&&-1!=t.indexOf(s)){let s=t.split("--");if(2==s.length){let i;i=s[0];let n=parseFloat($("#"+i).attr("x")),l=parseFloat($("#"+i).attr("y"));$("#"+t).attr("x2",n),$("#"+t).attr("y2",l);let r=$("#"+t).attr("x1"),o=$("#"+t).attr("y1"),a=r,d=o;if(parseInt($("#"+t).attr("short"))){r=$("#"+t).attr("x0"),o=$("#"+t).attr("y0");let s=Math.sqrt((r-n)*(r-n)+(o-l)*(o-l)),i=e.len4ang/2;i<s&&(a=i/s*(r-n)+n,d=i/s*(o-l)+l)}$("#"+t).attr("x1",a),$("#"+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 s=t.icn3d;e.stopImmediatePropagation(),s.diagram2dCls.clickNode(this)}))}}class Es{constructor(e){this.icn3d=e}resizeCanvas(e,t,s,i){var n=this.icn3d,l=n.icn3dui;if(s||l.cfg.resize){let s=t;$("#"+n.pre+"canvas").width(e).height(s),$("#"+n.pre+"viewer").width(e).height(t),$("#"+n.divid+" div:has(#"+n.pre+"canvas)").width(e).height(s),n.applyCenterCls.setWidthHeight(e,s),n.structures&&Object.keys(n.structures).length>0&&(void 0===i||i)&&n.drawCls.draw()}}windowResize(){let e=this.icn3d.icn3dui,t=this;e.cfg.resize&&!e.utilsCls.isMobile()&&$(window).resize((function(){let s=t.icn3d;e.utilsCls.setViewerWidthHeight(s.icn3dui);let i=e.htmlCls.WIDTH,n=e.htmlCls.HEIGHT;void 0===s||s.bFullscreen||t.resizeCanvas(i,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 s=this.icn3d;s.icn3dui;let i=this;if(s.bStopRotate)return!1;if(s.transformCls.rotateCount>s.transformCls.rotateCountMax)return s.transformCls.resetOrientation(),!1;if(++s.transformCls.rotateCount,t)if("left"===e)s.ROT_DIR="left";else if("right"===e)s.ROT_DIR="right";else if("up"===e)s.ROT_DIR="up";else{if("down"!==e)return!1;s.ROT_DIR="down"}if("left"===e&&"left"===s.ROT_DIR)s.transformCls.rotateLeft(1);else if("right"===e&&"right"===s.ROT_DIR)s.transformCls.rotateRight(1);else if("up"===e&&"up"===s.ROT_DIR)s.transformCls.rotateUp(1);else{if("down"!==e||"down"!==s.ROT_DIR)return!1;s.transformCls.rotateDown(1)}setTimeout((function(){i.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 s=["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_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 i in s){let n=s[i];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 Ts{constructor(e){this.icn3d=e}resetOrientation(){let e=this.icn3d;e.icn3dui;let t=!1;if(e.commands.length>0){let s=e.commands[0].split("|||");if(2==s.length){let i=JSON.parse(s[1]);e._zoomFactor=i.factor,e.mouseChange.x=i.mouseChange.x,e.mouseChange.y=i.mouseChange.y,e.quaternion._x=i.quaternion._x,e.quaternion._y=i.quaternion._y,e.quaternion._z=i.quaternion._z,e.quaternion._w=i.quaternion._w,t=!0}}t||(e._zoomFactor=1,e.mouseChange=new THREE.Vector2(0,0),e.quaternion=new THREE.Quaternion(0,0,0,1)),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,s=t.icn3dui,i=new THREE.Vector3(0,1,0),n=-e/180*Math.PI;t.bControlGl&&!s.bNode?i.applyQuaternion(window.cam.quaternion).normalize():i.applyQuaternion(t.cam.quaternion).normalize();let l=new THREE.Quaternion;l.setFromAxisAngle(i,-n);let r={};r.quaternion=l,r.update=!0,t.bControlGl&&!s.bNode?window.controls.update(r):t.controls.update(r),t.bRender&&t.drawCls.render()}rotateRight(e){let t=this.icn3d,s=t.icn3dui,i=new THREE.Vector3(0,1,0),n=e/180*Math.PI;t.bControlGl&&!s.bNode?i.applyQuaternion(window.cam.quaternion).normalize():i.applyQuaternion(t.cam.quaternion).normalize();let l=new THREE.Quaternion;l.setFromAxisAngle(i,-n);let r={};r.quaternion=l,r.update=!0,t.bControlGl&&!s.bNode?window.controls.update(r):t.controls.update(r),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,s=t.icn3dui,i=new THREE.Vector3(1,0,0),n=e/180*Math.PI;t.bControlGl&&!s.bNode?i.applyQuaternion(window.cam.quaternion).normalize():i.applyQuaternion(t.cam.quaternion).normalize();let l=new THREE.Quaternion;l.setFromAxisAngle(i,-n);let r={};r.quaternion=l,r.update=!0,t.bControlGl&&!s.bNode?window.controls.update(r):t.controls.update(r),t.bRender&&t.drawCls.render()}setRotation(e,t){let s=this.icn3d,i=s.icn3dui;if(!e)return;s.bControlGl&&!i.bNode&&window.cam?e.applyQuaternion(window.cam.quaternion).normalize():s.cam&&e.applyQuaternion(s.cam.quaternion).normalize();let n=new THREE.Quaternion;n.setFromAxisAngle(e,-t);let l={};l.quaternion=n,l.update=!0,s.bControlGl&&!i.bNode&&window.controls?window.controls.update(l):s.controls&&s.controls.update(l),s.bRender&&s.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 s=this.icn3d,i=s.icn3dui,n=new THREE.Vector2(0,0);n.x+=e/100,n.y+=t/100;let l={};l.mouseChange=n,l.update=!0,s.bControlGl&&!i.bNode?window.controls.update(l):s.controls.update(l),s.bRender&&s.drawCls.render()}translateCoord(e,t,s,i){let n=this.icn3d;n.icn3dui;for(let l in e){let e=n.atoms[l];e.coord.x+=t,e.coord.y+=s,e.coord.z+=i}}rotateCoord(e,t){let s=this.icn3d;s.icn3dui;const i=new THREE.Matrix4;i.elements=t;for(let t in e){let e=s.atoms[t];e.coord=e.coord.applyMatrix4(i)}}zoominSelection(e){let t=this.icn3d,s=t.icn3dui,i={};if(i._zoomFactor=1/t._zoomFactor,i.update=!0,t.bControlGl&&!s.bNode?window.controls&&window.controls.update(i):t.controls&&t.controls.update(i),void 0===e&&(e=s.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)),Object.keys(e).length>1){let s=t.applyCenterCls.centerAtoms(e);t.maxD=s.maxD,t.maxD<5&&(t.maxD=5),t.center=s.center,t.applyCenterCls.setCenter(t.center),t.cameraCls.setCamera()}}getTransformationStr(e){this.icn3d.icn3dui;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)}}class Ps{constructor(e){this.icn3d=e}saveFile(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=this;if("command"===t){let e=l.loadCmd?l.loadCmd+"\n":"";for(let t=0,s=l.commands.length;t<s;++t){let i=l.commands[t].trim();if(t==s-1){let e=i.split("|||"),t={};t.factor=l._zoomFactor,t.mouseChange=l.mouseChange,t.quaternion=l.quaternion,i=e[0]+"|||"+l.transformCls.getTransformationStr(t)}e+=i+"\n"}let t=decodeURIComponent(e);n=new Blob([t],{type:"text;charset=utf-8;"})}else if("png"===t){let t=$("#"+l.pre+"canvas").width(),s=$("#"+l.pre+"canvas").height();l.applyCenterCls.setWidthHeight(t,s),l.bRender&&l.drawCls.render();let a=!0;if(window.File&&window.FileReader&&window.FileList&&window.Blob||(a=!1),r.utilsCls.isIE()){if(n=l.renderer.domElement.msToBlob(),!a)return o.saveBlob(n,e,i,t,s),n;{let a=new FileReader;a.onload=function(a){let d=a.target.result,c=l.shareLinkCls.getPngText();return n=r.convertTypeCls.getBlobFromBufferAndText(d,c),o.saveBlob(n,e,i,t,s),n},a.readAsArrayBuffer(n)}}else l.renderer.domElement.toBlob((function(d){if(!a)return n=d,o.saveBlob(n,e,i,t,s),n;{let a=new FileReader;a.onload=function(a){let d=a.target.result,c=l.shareLinkCls.getPngText();return n=r.convertTypeCls.getBlobFromBufferAndText(d,c),o.saveBlob(n,e,i,t,s),n},a.readAsArrayBuffer(d)}}));l.scaleFactor=1,l.applyCenterCls.setWidthHeight(t,s),l.bRender&&l.drawCls.render()}else if("html"===t){let e=decodeURIComponent(s);n=new Blob([e],{type:"text/html;charset=utf-8;"})}else if("text"===t){n=new Blob(s,{type:"text;charset=utf-8;"})}else if("binary"===t){n=new Blob(s,{type:"application/octet-stream"})}return"png"!==t&&saveAs(n,e),n}saveBlob(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui,s){let t=(window.URL||window.webkitURL).createObjectURL(e),s=l.shareLinkCls.shareLinkUrl();s=s.replace(/imageonly=1/g,""),s.length>4e3||0!==s.indexOf("http")||l.bInputfile&&!l.bInputUrlfile?$("#"+l.pre+"viewer").html("<img src='"+t+"'/>"):$("#"+l.pre+"viewer").html("<a href='"+s+"' target='_blank'><img src='"+t+"'/></a>"),$("#"+l.pre+"viewer").width(i),$("#"+l.pre+"viewer").height(n),$("#"+l.pre+"cmdlog").hide(),$("#"+l.pre+"title").hide(),$("#"+l.pre+"mnlist").hide(),$("#"+l.pre+"fullscreen").length>0&&$("#"+l.pre+"fullscreen").hide(),l={}}else saveAs(e,t)}saveSvg(e,t,s,i){let n=this.icn3d;if(n.icn3dui.bNode)return"";let l=$("#"+e).width(),r=$("#"+e).height();s&&(r=l),i&&(l+=n.len4ang,r+=n.len4ang);let o=this.getSvgXml(e,l,r,s,i),a=new Blob([o],{type:"image/svg+xml"});saveAs(a,t)}getSvgXml(e,t,s,i,n){if(this.icn3d.icn3dui.bNode)return"";return(t&&s?'<svg viewBox="'+(n?-30:0)+" "+(n?-30:0)+" "+t+" "+s+'"':"<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,s,i){let n=this.icn3d,l=n.icn3dui;if(l.bNode)return"";let r=$("#"+e).width(),o=$("#"+e).height();s&&(o=r);let a=document.getElementById(e),d=a.getBBox(),c=a.cloneNode(!0);i||n.lineGraphCls.copyStylesInline(c,a);let h=document.createElement("CANVAS");h.width=r,h.height=o;let p=h.getContext("2d");p.clearRect(0,0,d.width,d.height);let m=this.getSvgXml(e,r,o,s),u=window.URL||window.webkitURL||window,g=new Blob([m],{type:"image/svg+xml;charset=utf-8"}),f=new Image;f.src=u.createObjectURL(g),f.onload=function(){if(p.drawImage(f,0,0),u.revokeObjectURL(this.src),l.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 s="",i=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues).sort():[];for(let n=0,l=i.length;n<l;++n){let l=i[n],r=t.defNames2Residues[l];t.defNames2Descr[l];let o=t.defNames2Command[l];o=o.replace(/,/g,", "),s+=this.exportResidues(l,r,e)}i=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms).sort():[];for(let n=0,l=i.length;n<l;++n){let l=i[n],r=t.defNames2Atoms[l];t.defNames2Descr[l];let o=t.defNames2Command[l];o=o.replace(/,/g,", ");let a=t.resid2specCls.atoms2residues(r);s+=this.exportResidues(l,a,e)}return s}exportResidues(e,t,s){var i=this.icn3d,n=i.icn3dui;let l="";if(t.length>0)if(s){let s={};for(let e=0,l=t.length;e<l;++e){let l=t[e],r=i.firstAtomObjCls.getFirstAtomObj(i.residues[l]),o=r.structure+"_"+r.chain,a=n.utilsCls.residueName2Abbr(r.resn)+r.resi;s.hasOwnProperty(o)||(s[o]=[]),s[o].push(a)}l+=e+":\n";for(let e in s){let t=1==s[e].length?"residue":"residues";l+=e+" ("+s[e].length+" "+t+"): ",l+=s[e].join(", "),l+="\n"}l+="\n"}else l+=e+"\tselect ",l+=i.resid2specCls.residueids2spec(t),l+="\n";return l}printPrevSecondary(e,t,s,i){this.icn3d.icn3dui;let n="";if(s)if(e){let e=1;n+=s.resn.padStart(5," ")+s.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+s.resi.toString().padStart(5," ")+" "+e+i.toString().padStart(36," ")+"\n"}else if(t){let e=0;n+=s.resn.padStart(5," ")+s.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+s.resi.toString().padStart(4," ")+" "+e+"\n"}return n}getAtomPDB(e,t,s,i,n,l,r,o){let a=this.icn3d,d=a.icn3dui,c="",h={},p={};for(let e in a.chemicals){let t=a.atoms[e];if("P"==t.elem){h[e]=1;for(let e=0,s=t.bonds.length;e<s;++e){let s=t.bonds[e];s&&"O"==a.atoms[s].elem&&(p[s]=1)}}}let m,u,g=d.hashUtilsCls.intHash(e,a.calphas),f={};for(let e in a.structures)f[e]="";let C=[];for(let e in g){let t=a.atoms[e];u=t.structure,t.structure,t.chain;let s={};if(s.chain=t.chain,s.resn=t.resn,s.resi=t.resi,parseInt(t.resi)>parseInt(m)+1&&(s.ss=" ",C.push(s)),"helix"==t.ss?(s.ss="H",C.push(s)):"sheet"==t.ss&&(s.ss="S",C.push(s)),t.ssend){let e=d.hashUtilsCls.cloneHash(s);e.ss=" ",C.push(e)}m=t.resi}let b,y,v=0,_=!1,w=!1;for(let e=0,t=C.length;e<t;++e){let t=C[e];(t.ss!=b||t.ssbegin)&&(f[u]+=this.printPrevSecondary(_,w,y,v),v=0,_=!1,w=!1,y=void 0," "!=t.ss&&("H"==t.ss?(_=!0,y=t,f[u]+="HELIX".padEnd(15," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(5," ")):"S"==t.ss&&(w=!0,y=t,f[u]+="SHEET".padEnd(17," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(4," "))))," "!=t.ss&&(++v,y=t),b=t.ss}if(f[u]+=this.printPrevSecondary(_,w,y,v),f[u]+="\n",a.biomtMatrices&&Object.keys(e).length==Object.keys(a.atoms).length){let e=Object.keys(a.structures)[0];for(let t=0,s=a.biomtMatrices.length;t<s;++t){let s=t+1;for(let i=0;i<3;++i){let n=i+1;f[e]+="REMARK 350 BIOMT"+n.toString()+" "+s.toString().padStart(2," ")+" "+a.biomtMatrices[t].elements[i+0].toFixed(6).toString().padStart(9," ")+" "+a.biomtMatrices[t].elements[i+4].toFixed(6).toString().padStart(9," ")+" "+a.biomtMatrices[t].elements[i+8].toFixed(6).toString().padStart(9," ")+" "+a.biomtMatrices[t].elements[i+12].toFixed(6).toString().padStart(14," ")+"\n"}}}for(let e in a.chainMissingResidueArray){let t=e.indexOf("_"),s=e.substr(t+1,2),i=e.substr(0,t);for(let t=0,n=a.chainMissingResidueArray[e].length;t<n;++t){let n=a.chainMissingResidueArray[e][t].resi,l=d.utilsCls.residueAbbr2Name(a.chainMissingResidueArray[e][t].name);f[i]+="REMARK 465 "+l.padStart(3," ")+s.padStart(2," ")+" "+n.toString().padStart(5," ")+"\n"}}let S="",A=Object.keys(a.structures).length>1,x=1,k="",O="",R=0,I="",E={};for(let l in e){let e=a.atoms[l];if(s&&e.het)continue;if(e.structure!=k){r&&A||(c+=S,S="",x>1&&(c+="\nENDMDL\n"),A&&(c+="MODEL "+x+"\n"));let t=n?"Mutated chain_residue "+Object.keys(n)+"; ":"";i||r&&A||(c+=this.getPDBHeader(x-1,f,t,e.structure)),++x}e.chain!=O&&e.structure==k&&O&&(c+="TER\n");let m=e.chain+"_"+e.resi;if(n&&n.hasOwnProperty(m)){E.hasOwnProperty(m)||(c+=n[m],E[m]=1);continue}let u="";u+=e.het?"HETATM":"ATOM ",u+=l.toString().padStart(5," "),u+=" ";let g=e.name.trim();isNaN(g.substr(0,1))||(g=g.substr(1)+g.substr(0,1)),4==g.length?u+=g:(u+=" ",g=g.replace(/\*/g,"'"),"O1P"==g?g="OP1":"O2P"==g?g="OP2":"C5M"==g&&(g="C7 "),u+=g.padEnd(3," ")),u+=" ";let C=e.resn;if(u+=C.length<=3?C.padStart(3," "):C.substr(0,3),r&&x>2&&(a.proteins.hasOwnProperty(e.serial)||a.nucleotides.hasOwnProperty(e.serial)))e.structure==k&&e.chain==O||(I=R<36?"abcdefghijklmnopqrstuvwxyz0123456789"[R]:"?",++R),u+=" "+I;else if(e.chain.length>=2){let t=e.chain.replace(/_/gi,"").substr(0,2);o&&(t=" "+t.substr(0,1)),u+=t}else 1==e.chain.length?u+=" "+e.chain.substr(0,1):0==e.chain.length&&(u+=" A");let b=e.resi;!isNaN(b)&&e.chain.length>3&&!isNaN(e.chain.substr(3))&&(b=b-1+parseInt(e.chain.substr(3)));let y=parseInt(b);u+=y.toString().length<=4?y.toString().padStart(4," "):y.toString().substr(0,4);let v=e.resi.toString().substr(e.resi.toString().length-1,1);if(isNaN(v)?u+=v:u+=" ",u+=" ".padStart(3," "),u+=e.coord.x.toFixed(3).toString().padStart(8," "),u+=e.coord.y.toFixed(3).toString().padStart(8," "),u+=e.coord.z.toFixed(3).toString().padStart(8," "),t&&e.het){let t=1.5,s=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?s=e.crg:h.hasOwnProperty(l)?s=1.38:p.hasOwnProperty(l)?s=-.595:d.parasCls.ionCharges.hasOwnProperty(e.elem)&&(s=d.parasCls.ionCharges[e.elem]),u+=s.toFixed(4).toString().padStart(8," "),u+=t.toFixed(4).toString().padStart(7," ")}else{u+="1.00".padStart(6," ");let t=o?"1.0":" ";u+=e.b?parseFloat(e.b).toFixed(2).toString().padStart(6," "):t.padStart(6," "),u+=" ".padStart(10," "),u+=e.elem.padStart(2," "),u+=" ".padStart(2," ")}if(e.het&&e.bonds.length>0){S+="CONECT"+l.toString().padStart(5," ");let t={};for(let s=0,i=e.bonds.length;s<i;++s)e.bonds[s]&&!t.hasOwnProperty(e.bonds[s])&&(S+=e.bonds[s].toString().padStart(5," "),t[e.bonds[s]]=1);S+="\n"}c+=u+"\n",k=e.structure,O=e.chain}return r&&A||(c+=S,A&&(c+="\nENDMDL\n")),c}getSecondary(e){let t=this.icn3d,s=t.icn3dui,i='{"data": [\n',n="",l="",r={};for(let i in e){let e=t.atoms[i],o=e.structure+"_"+e.chain,a=e.resi,d=s.utilsCls.residueName2Abbr(e.resn),c=this.secondary2Abbr(e.ss);o!=n&&(r[o]={resi:[],resn:[],secondary:[]}),o==n&&a==l||(r[o].resi.push(a),r[o].resn.push(d),r[o].secondary.push(c)),n=o,l=a}let o=Object.keys(r),a=o.length;for(let e=0;e<a;++e){let t=o[e];i+='{"chain": "'+t+'",\n',i+='"resi": "'+r[t].resi.join(",")+'",\n',i+='"resn": "'+r[t].resn.join("")+'",\n',i+='"secondary": "'+r[t].secondary.join("")+'"',i+=e<a-1?"},\n":"}\n"}return i+="]}\n",i}secondary2Abbr(e){return this.icn3d.icn3dui,"helix"==e?"H":"sheet"==e?"E":"c"}getSelectedResiduePDB(){let e=this.icn3d,t="",s=e.icn3dui.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);return t+=this.getAtomPDB(s),t}getPDBHeader(e,t,s,i){let n=this.icn3d;n.icn3dui,void 0===e&&(e=0);let l="",r=i||Object.keys(n.structures)[e],o=s?r+"2":r;if(l+="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=""),s&&(e=s+e),l+="TITLE "+e+"\n"}return t&&t[r]&&(l+=t[r]),l}showTitle(){var e=this.icn3d,t=e.icn3dui;let s=e.molTitle?e.molTitle:"",i="black"==e.opts.background?t.htmlCls.GREYD:"black";if(void 0===e.inputid)s.length>40&&(s=s.substr(0,40)+"..."),$("#"+e.pre+"title").html(s);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:"+i+"' target='_blank'>"+e.inputid.toUpperCase()+"</a>: "+s)}else if(void 0!==t.cfg.align)s="VAST+ alignment of "+Object.keys(e.structures),$("#"+e.pre+"title").html(s);else if(void 0!==t.cfg.chainalign){s="Dynamic Structure Alignment of Chains: "+t.cfg.chainalign.split(","),$("#"+e.pre+"title").html(s)}else{let n=Object.keys(t.utilsCls.getStructures(e.dAtoms));if(n.length>1){s="Multiple structures: ";for(let e=0,t=n.length;e<t;++e){s+='<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:'+i+'" target="_blank">'+n[e]+"</a>",e<t-1&&(s+=", ")}$("#"+e.pre+"title").html(s)}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,s,i)}}}setStructureTitle(e,t,s){var i=this.icn3d,n=i.icn3dui;t.length>40&&(t=t.substr(0,40)+"...");let l,r,o=i.inputid;if(-1!=o.indexOf("http"))r="Data from",e=o,l=o;else{let e=n.utilsCls.getHlStructures(),s=!1,a=!1;for(let t in e)t.length>5?a=!0:s=!0;let d=Object.keys(e);if(o=d.join(","),l=n.cfg.refseqid||n.cfg.protein?i.inputid:o.toUpperCase(),s&&a?r="AlphaFold/PDB ID":s?r="PDB ID":a&&(r="AlphaFold ID"),d.length>1&&(r+="s"),i.molTitleHash){t="";for(let e=0,s=d.length;e<s;++e)t+=i.molTitleHash[d[e]],e<s-1&&(t+="; ")}}if(n.cfg.refseqid?r="NCBI Protein Acc.":n.cfg.protein&&(r="Protein/Gene Name"),o&&o.substr(0,4)!=i.defaultPdbId)if(n.cfg.blast_rep_id){let e=n.cfg.oriQuery_id?n.cfg.oriQuery_id:n.cfg.query_id,s=n.cfg.oriBlast_rep_id?n.cfg.oriBlast_rep_id:n.cfg.blast_rep_id;e.length>20&&(e=e.substr(0,17)+"..."),l="Query: "+e+"; target: "+s,$("#"+i.pre+"title").html(l+", "+t)}else $("#"+i.pre+"title").html(r+" <a id='"+i.pre+"titlelink' href='"+e+"' style='color:"+s+"' target='_blank'>"+l+"</a>: "+t);else $("#"+i.pre+"title").html(t)}getLinkToStructureSummary(e){var t=this.icn3d,s=t.icn3dui;let i="https://www.ncbi.nlm.nih.gov/structure/?term=";if(i=void 0!==s.cfg.cid?"https://www.ncbi.nlm.nih.gov/pccompound/?term=":void 0!==s.cfg.refseqid?"https://www.ncbi.nlm.nih.gov/protein/":void 0!==s.cfg.afid?"https://alphafold.ebi.ac.uk/search/text/":Object.keys(t.structures).length>1?"https://www.ncbi.nlm.nih.gov/structure/?term=":s.htmlCls.baseUrl+"pdb/",void 0===t.inputid)i="https://www.ncbi.nlm.nih.gov/pccompound/?term="+t.molTitle;else{let n=t.inputid.split("_");1===n.length?(i+=t.inputid,e&&s.htmlCls.clickMenuCls.setLogCmd("link to "+t.inputid+": "+i,!1)):2===n.length&&(s.cfg.afid?i+=n[0]+" "+n[1]:i+=n[0]+" OR "+n[1],e&&s.htmlCls.clickMenuCls.setLogCmd("link to structures "+n[0]+" and "+n[1]+": "+i,!1))}return i}setEntrezLinks(e){var t=this.icn3d,s=t.icn3dui;let i,n=Object.keys(t.structures);if(1===n.length){i="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0],s.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+": "+i,!1);let l=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(i,l)}else if(2===n.length){i="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0]+" OR "+n[1],s.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+" OR "+n[1]+": "+i,!1);let l=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(i,l)}}}class Ds{constructor(e){this.icn3d=e}async shareLink(e,t){let s=this.icn3d,i=s.icn3dui,n=this.shareLinkUrl(),l=n.length>4e3||0!==n.indexOf("http"),r=Object.keys(s.structures).join("_");if(r==s.defaultPdbId&&(s.filename?r=s.filename:s.inputid&&(r=s.inputid)),e){if(t||s.bInputfile||l)return void s.saveFileCls.saveFile(r+"_icn3d_loadable.png","png")}else{if(s.bInputfile&&!s.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(l)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.");i.htmlCls.clickMenuCls.setLogCmd("share link: "+n,!1)}let o="Problem in getting shortened URL";if(!i.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];s.saveFileCls.saveFile(r+"-"+t+".png","png");let i='<div style="float:left; border: solid 1px #0000ff; padding: 5px; margin: 10px; text-align:center;">';i+='<a href="https://structure.ncbi.nlm.nih.gov/icn3d/share.html?'+t+'" target="_blank">',i+='<img style="height:300px" src ="'+r+"-"+t+'.png"><br>\n',i+="\x3c!--Start of your comments==================--\x3e\n";let n=s.yournote?": "+s.yournote.replace(/\n/g,"<br>").replace(/; /g,", "):"";i+="PDB "+r.toUpperCase()+n+"\n",i+="\x3c!--End of your comments====================--\x3e\n",i+="</a>",i+="</div>\n\n",s.saveFileCls.saveFile(r+"-"+t+".html","html",i)}e&&void 0===t.shortLink&&s.saveFileCls.saveFile(r+"_icn3d_loadable.png","png");let i=o.split("page.link/");2==i.length&&(o="https://structure.ncbi.nlm.nih.gov/icn3d/share.html?"+i[1]),$("#"+s.pre+"short_url").val(o),$("#"+s.pre+"short_url_title").val(o+"&t="+s.yournote)}let a=this.shareLinkUrl(void 0,!0),d="view = icn3dpy.view(q='"+(i.cfg.url?"url="+i.cfg.url:i.cfg.idname+"="+i.cfg.idvalue)+"',command='"+a+"')\nview";(i.cfg.url||i.cfg.idname)&&$("#"+s.pre+"jn_commands").val(d),$("#"+s.pre+"ori_url").val(n),e||i.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL or Jupyter Notebook Commands")}getShareLinkPrms(e,t){let s=this.icn3d,i=s.icn3dui;return new Promise((function(n,l){$.ajax({url:"https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=AIzaSyBxl9CgM0dY5lagHL4UOhEpLWE1fuwdnvc",type:"POST",data:{longDynamicLink:"https://icn3d.page.link/?link="+encodeURIComponent(e)},dataType:"json",success:function(e){n(e)},error:function(n,l,r){let o="Problem in getting shortened URL";$("#"+s.pre+"ori_url").val(e),$("#"+s.pre+"short_url").val(o),$("#"+s.pre+"short_url_title").val(o+"&t="+s.yournote),t||i.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL")}})}))}shareLinkUrl(e,t,s){let i=this.icn3d,n=i.icn3dui,l=n.htmlCls.baseUrl+"icn3d/full_"+n.REVISION+".html?",r="";if(n.cfg.bSidebyside&&(l=n.htmlCls.baseUrl+"icn3d/full2.html?"),i.bInputUrlfile){l=window.location.href.split("?")[0]+"?"+i.inputurl+"&"}let o,a={};for(let e in i.cfg){let t=i.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||"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&&(a[e]=JSON.stringify(t)):!0===t?a[e]=1:!1===t?a[e]=0:""!==t&&(a[e]=t)))}i.bAfMem?a.afmem="on":(n.cfg.afid||1==Object.keys(i.structures).length&&Object.keys(i.structures)[0].length>5)&&(a.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(!i.bInputUrlfile){let e=o&&o.substr(1)?o.substr(1).split("&"):[];for(let t=0,s=e.length;t<s;++t){let s=e[t].split("=");2==s.length&&(a[s[0]]=s[1])}n.cfg.idname&&!a[n.cfg.idname]&&(l+=n.cfg.idname+"="+n.cfg.idvalue+"&");for(let e in a)"v"!==e&&("date"===e&&(c=!0),l+=e+"="+a[e]+"&")}let h,p=n.utilsCls.getDateDigitStr();c||(l+="date="+p+"&"),l+="v="+n.REVISION+"&",l+="command=",h=t&&void 0!==o?1:0,(e||i.bInputUrlfile)&&(h=0);let m={};m.factor=i._zoomFactor,m.mouseChange=i.mouseChange,m.quaternion=i.quaternion;let u="",g="",f="toggle highlight",C=0;if(i.commands.length>h){g=i.commands[h].split("|||")[0].split("&command=")[0].trim(),-1!==g.indexOf(f)&&++C}let b,y=h+1,v="";for(let e=i.commands.length;y<e;++y){let e=i.commands[y].split("|||")[0].split("&command=")[0].trim();0==g.indexOf("select sets")&&0===e.indexOf("select sets")&&-1===g.indexOf(" name ")||-1!==g.indexOf("pickatom")&&-1!==e.indexOf("pickatom")||"show selection"==g&&-1!=i.commands.slice(y).toString().indexOf("show selection")||g==e||(-1!==g.indexOf(f)?++C:v+=y===h+1?g:v?"; "+g:g),-1==g.indexOf("load ")&&(u+=g+"\n"),g=e}return g&&(v&&(v+="; "),C>0&&C%2==0&&g!==f&&(v+=f+"; "),v+=g+"|||"+i.transformCls.getTransformationStr(m),u+=g+"|||"+i.transformCls.getTransformationStr(m)+"\n"),l+=v,r=v,u=u.replace(/!/g,Object.keys(i.structures)[0]+"_"),(i.bEsmfold||i.bInputfile&&!i.bInputUrlfile||i.bInputUrlfile&&i.bAppend||l.length>4e3)&&(l=u),void 0!==i.structures&&1==Object.keys(i.structures).length&&void 0!==i.inputid&&(b=Object.keys(i.structures)[0],l=l.replace(new RegExp(b+"_","g"),"!"),r=r.replace(new RegExp(b+"_","g"),"!")),void 0!==n.cfg.blast_rep_id&&(l=l.replace(new RegExp("blast_rep_id=!","g"),"blast_rep_id="+b+"_")),s?u:t?r:l}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 Ms{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,s=e.lines.hbond.length;t<s;++t){e.lines.hbond[t].dashed=!1,e.bDashedLines=!0}if(void 0!==e.lines.distance)for(let t=0,s=e.lines.distance.length;t<s;++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,s=e.lines.hbond.length;t<s;++t){e.lines.hbond[t].dashed=!0}if(void 0!==e.lines.distance)for(let t=0,s=e.lines.distance.length;t<s;++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,s=this.icn3d;s.icn3dui;for(let i=0,n=s.pairArray.length;i<n;i+=2){let n=this.getResidueRepAtom(s.pairArray[i]),l=this.getResidueRepAtom(s.pairArray[i+1]);if(null!=e)for(let s=0,r=e.length;s<r;s+=2){let r=this.getResidueRepAtom(e[s]),o=this.getResidueRepAtom(e[s+1]);if(n.serial==r.serial&&l.serial==o.serial||n.serial==o.serial&&l.serial==r.serial){t=i;break}}if(void 0!==t)break}void 0!==t&&s.pairArray.splice(t,2)}outputSelection(){let e=this.icn3d,t=e.icn3dui,s={};for(let t in e.hAtoms){s[e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi]=1}let i=Object.keys(s).sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let s=e.lastIndexOf("_"),i=t.lastIndexOf("_");if(e.substr(0,s)<t.substr(0,s))return-1;if(e.substr(0,s)>t.substr(0,s))return 1;if(e.substr(0,s)==t.substr(0,s)){if(parseInt(e.substr(s+1))<parseInt(t.substr(i+1)))return-1;if(parseInt(e.substr(s+1))>parseInt(t.substr(i+1)))return 1;if(parseInt(e.substr(s+1))==parseInt(t.substr(i+1)))return 0}}})),n="<table><tr><th>Structure</th><th>Chain</th><th>Residue Number</th></tr>";for(let e=0,t=i.length;e<t;++e){let t=i[e].indexOf("_"),s=i[e].lastIndexOf("_");n+="<tr><td>"+i[e].substr(0,t)+"</td><td>"+i[e].substr(t+1,s-t-1)+"</td><td>"+i[e].substr(s+1)+"</td></tr>"}let l=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(l+"_residues.txt","html",n)}addStabilizer(){let e=this.icn3d,t=e.icn3dui,s=3.5;if(Object.keys(e.dAtoms).length>0){let i,n={},l=12.25,r=3.2*3.2;for(let t in e.dAtoms){let s=e.atoms[t];!e.nucleotides.hasOwnProperty(s.serial)||"N1"!==s.name&&"N2"!==s.name&&"N3"!==s.name&&"N4"!==s.name&&"N6"!==s.name&&"O2"!==s.name&&"O6"!==s.name||(i=s.structure+"_"+s.chain+"_"+s.resi+"_"+s.name,n[i]=s)}let o=Object.keys(n),a=o.length;void 0===e.pairArray&&(e.pairArray=[]);for(let t=0;t<a;++t)for(let i=t+1;i<a;++i){let a=o[t],d=o[i],c=Math.abs(n[a].coord.x-n[d].coord.x);if(c>s)continue;let h=Math.abs(n[a].coord.y-n[d].coord.y);if(h>s)continue;let p=Math.abs(n[a].coord.z-n[d].coord.z);if(p>s)continue;let m=c*c+h*h+p*p;m>l||m<r||(e.pairArray.push(n[a].serial),e.pairArray.push(n[d].serial))}let d=6,c={};for(let t in e.dAtoms){let s=e.atoms[t];c[s.structure+"_"+s.chain+"_"+s.resi]=1}let h={};for(let t in e.chemicals){let s=e.atoms[t],i=s.structure+"_"+s.chain+"_"+s.resi;c.hasOwnProperty(i)&&(h[i]=1)}for(let t in e.ions){let s=e.atoms[t],i=s.structure+"_"+s.chain+"_"+s.resi;c.hasOwnProperty(i)&&(h[i]=1)}let p=Object.keys(e.chains);for(let t=0,s=p.length;t<s;++t){let s,i=p[t],n=0,l=0;for(let t=0,r=e.chainsSeq[i].length;t<r;++t)s=i+"_"+e.chainsSeq[i][t].resi,"c"!=e.secondaries[s]&&"E"!=e.secondaries[s]&&"H"!=e.secondaries[s]||(n%3!=0&&e.resid2ncbi[e.chainsSeq[i][t].resi]==e.resid2ncbi[l]+1||c.hasOwnProperty(s)&&(h[s]=1),++n,l=e.chainsSeq[i][t].resi);"c"!=e.secondaries[s]&&"E"!=e.secondaries[s]&&"H"!=e.secondaries[s]||c.hasOwnProperty(s)&&(h[s]=1)}let m=Object.keys(h);void 0===e.pairArray&&(e.pairArray=[]);let u=t.hashUtilsCls.exclHash(e.dAtoms,e.water);for(let s=0,i=m.length;s<i;++s){let i=m[s],n=e.secondaries[i],l=e.contactCls.getNeighboringAtoms(u,t.hashUtilsCls.hash2Atoms(e.residues[i],e.atoms),d),r=Object.keys(l).sort(),o=Object.keys(e.residues[i]).sort(),a=!1;if(e.proteins.hasOwnProperty(o[0])){o=[o[0]],a=!0;let t=i.substr(0,i.lastIndexOf("_")),s=e.ParserUtilsCls.getResiNCBI(t,i.substr(i.lastIndexOf("_")+1)),d={};for(let i in l){if(e.chemicals.hasOwnProperty(i)||e.ions.hasOwnProperty(i))continue;let l=e.atoms[i];if(isNaN(l.resi))continue;let r=e.ParserUtilsCls.getResiNCBI(t,l.resi);("c"==n&&(r>s+1||r<s-1)||"E"==n&&(r>s+2||r<s-2)||"H"==n&&(r>s+4||r<s-4))&&(d[i]=1)}r=Object.keys(d).sort()}if(r.length>0&&o.length>0)if(a){let t=parseInt((r.length+.5)/2);e.pairArray.push(o[0]),e.pairArray.push(r[t])}else{let t=10,s=parseInt(r.length/(t+1));for(let i=0,n=o.length;i<n;++i)if(i%t==0){let n=parseInt(i/t)*s,l=n<r.length?n:r.length-1;e.pairArray.push(o[i]),e.pairArray.push(r[l]),o.length<t+1&&(e.pairArray.push(o[i]),e.pairArray.push(r[r.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 s,i=t.atoms[e],n=i.structure+"_"+i.chain+"_"+i.resi;if(t.proteins.hasOwnProperty(e)||t.nucleotides.hasOwnProperty(e))for(let e in t.residues[n]){let i=t.atoms[e];if("CA"===i.name||"N3"===i.name){s=t.atoms[e];break}}else s=i;return void 0===s&&(s=i),s}}class Fs{constructor(e){this.icn3d=e}exportStlFile(e){let t=this.icn3d,s=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 i=this.saveStlFile(),n=Object.keys(s.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".stl","binary",i),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 s=new THREE.Matrix4;s.identity();let l=1;for(let r=0;r<t.biomtMatrices.length;r++){let o=t.biomtMatrices[r];if(void 0===o)continue;if(o.equals(s))continue;let a=100*(r+1);setTimeout(function(s,l){i=this.saveStlFile(s),t.saveFileCls.saveFile(n+e+l+".stl","binary",i),i=""}.bind(this,o,l),a),++l}t.threshbox=180}}exportVrmlFile(e){let t=this.icn3d,s=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 i=this.saveVrmlFile(),n=Object.keys(s.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".wrl","text",i),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 s=new THREE.Matrix4;s.identity();let n=1;for(let l=0;l<t.biomtMatrices.length;l++){let r=t.biomtMatrices[l];if(void 0===r)continue;if(r.equals(s))continue;let o=100*(l+1);setTimeout(function(s,n){i=this.saveVrmlFile(s),t.saveFileCls.saveFile(t.inputid+e+n+".wrl","text",i),i=""}.bind(this,r,n),o),++n}t.threshbox=180}}getFaceCnt(e){this.icn3d.icn3dui;let t=0;for(let s=0,i=e.children.length;s<i;++s){let i=e.children[s];"Sprite"!==i.type&&(t+=i.geometry.getIndex().array.length/3)}return t}saveStlFile(e){let t=this.icn3d,s=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 i=0;i+=this.getFaceCnt(t.mdl),i+=this.getFaceCnt(t.mdl_ghost);let n=[],l=new Uint8Array(84),r="STL file for the structure(s) ",o=Object.keys(t.structures);for(let e=0,t=o.length;e<t;++e)r+=o[e],e<t-1&&(r+=", ");r.length>80&&(r=r.substr(0,80));for(let e=0;e<80;++e)e<r.length?l[e]=s.convertTypeCls.passInt8([r.charCodeAt(e)])[0]:l[e]=s.convertTypeCls.passInt8([" ".charCodeAt(0)])[0];if(l=void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile?this.updateArray(l,s.convertTypeCls.passInt32([i*t.biomtMatrices.length]),80):this.updateArray(l,s.convertTypeCls.passInt32([i]),80),n.push(new Blob([l],{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 THREE.Matrix4;e.identity();for(let s=0;s<t.biomtMatrices.length;s++){let i=t.biomtMatrices[s];void 0!==i&&(i.equals(e)||(n=this.processStlMeshGroup(t.mdl,n,i),n=this.processStlMeshGroup(t.mdl_ghost,n,i)))}}return t.threeDPrintCls.resetAfter3Dprint(),n}updateArray(e,t,s){this.icn3d.icn3dui;for(let i=0,n=t.length;i<n;++i)e[s+i]=t[i];return e}processStlMeshGroup(e,t,s){let i=this.icn3d.icn3dui;for(let n=0,l=e.children.length;n<l;++n){let l=e.children[n];if("Sprite"===l.type)continue;let r=l.geometry,o=r.getAttribute("position").array,a=r.getIndex().array,d=l.position,c=l.scale,h=l.matrix,p=new Uint8Array(a.length/3*50),m=0;for(let e=0,t=a.length;e<t;e+=3){let t,n,l,u=a[e],g=a[e+1],f=a[e+2],C=new THREE.Vector3(o[3*u],o[3*u+1],o[3*u+2]),b=new THREE.Vector3(o[3*g],o[3*g+1],o[3*g+2]),y=new THREE.Vector3(o[3*f],o[3*f+1],o[3*f+2]);"SphereGeometry"==r.type||"BoxGeometry"==r.type?(t=C.clone().multiply(c).add(d),n=b.clone().multiply(c).add(d),l=y.clone().multiply(c).add(d)):"CylinderGeometry"==r.type?(t=C.clone().applyMatrix4(h),n=b.clone().applyMatrix4(h),l=y.clone().applyMatrix4(h)):(t=C.clone(),n=b.clone(),l=y.clone()),p=this.updateArray(p,i.convertTypeCls.passFloat32([0,0,0]),m),m+=12,void 0!==s&&(t.applyMatrix4(s),n.applyMatrix4(s),l.applyMatrix4(s)),p=this.updateArray(p,i.convertTypeCls.passFloat32([t.x,t.y,t.z]),m),m+=12,p=this.updateArray(p,i.convertTypeCls.passFloat32([n.x,n.y,n.z]),m),m+=12,p=this.updateArray(p,i.convertTypeCls.passFloat32([l.x,l.y,l.z]),m),m+=12,t=n=l=void 0,p=this.updateArray(p,i.convertTypeCls.passInt16([0]),m),m+=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 s=[];s.push("#VRML V2.0 utf8\n");let i=0,n=this.processVrmlMeshGroup(t.mdl,s,i,e);if(s=n.vrmlStrArray,i=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,s,i,e),s=n.vrmlStrArray,i=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 THREE.Matrix4;e.identity();for(let l=0;l<t.biomtMatrices.length;l++){let r=t.biomtMatrices[l];void 0!==r&&(r.equals(e)||(n=this.processVrmlMeshGroup(t.mdl,s,i,r),s=n.vrmlStrArray,i=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,s,i,r),s=n.vrmlStrArray,i=n.vertexCnt))}}return s}processVrmlMeshGroup(e,t,s,i){let n=this.icn3d.icn3dui;for(let s=0,l=e.children.length;s<l;++s){let l=e.children[s];if("Sprite"===l.type)continue;let r=l.geometry;l.material.type,r.type;let o=r.getAttribute("position").array,a=r.getAttribute("color")?r.getAttribute("color").array:[],d=r.getIndex().array,c=l.position,h=l.scale,p=l.matrix,m=n.parasCls.thr(1,1,1);"SphereGeometry"!=r.type&&"BoxGeometry"!=r.type&&"CylinderGeometry"!=r.type||void 0!==l.material&&(m=l.material.color),t.push("Shape {\n"),t.push("geometry IndexedFaceSet {\n"),t.push("coord Coordinate { point [ ");let u=[];for(let e=0,s=o.length;e<s;e+=3){let l,a=new THREE.Vector3(o[e],o[e+1],o[e+2]);l="SphereGeometry"==r.type||"BoxGeometry"==r.type?a.clone().multiply(h).add(c):"CylinderGeometry"==r.type?a.clone().applyMatrix4(p):a.clone(),void 0!==i&&l.applyMatrix4(i),t.push(l.x.toPrecision(5)+" "+l.y.toPrecision(5)+" "+l.z.toPrecision(5)),l=void 0,e<s-3&&t.push(", "),u.push(n.parasCls.thr(1,1,1))}t.push(" ] }\n");let g="",f="";for(let e=0,t=d.length;e<t;e+=3){let s,i=d[e],n=d[e+1],l=d[e+2];s="SphereGeometry"==r.type||"BoxGeometry"==r.type||"CylinderGeometry"==r.type?m:new THREE.Color(a[3*i],a[3*i+1],a[3*i+2]),g+=i+" "+n+" "+l,e<t-3&&(g+=", -1, "),u[i]=s,u[n]=s,u[l]=s}for(let e=0,t=u.length;e<t;++e){let s=u[e];f+=s.r.toPrecision(3)+" "+s.g.toPrecision(3)+" "+s.b.toPrecision(3),e<t-1&&(f+=", ")}t.push("coordIndex [ "+g+" ]\n"),t.push("color Color { color [ "+f+" ] } colorPerVertex TRUE\n"),t.push(" }\n"),t.push("}\n")}return{vrmlStrArray:t,vertexCnt:s}}}class Hs{constructor(e){this.icn3d=e}rayCaster(e,t){this.rayCasterBase(e,t)}rayCasterBase(e,t){let s=this.icn3d;s.icn3dui;let i=e.pageX,n=e.pageY;e.originalEvent.targetTouches&&e.originalEvent.targetTouches[0]&&(i=e.originalEvent.targetTouches[0].pageX,n=e.originalEvent.targetTouches[0].pageY);let l=s.oriContainer.offset().left,r=s.oriContainer.offset().top,o=s.oriContainer.width(),a=s.oriContainer.height(),d=i-l,c=n-r;s.mouse.x=d/o*2-1,s.mouse.y=-c/a*2+1;let h=new THREE.Vector3;h.x=s.mouse.x,h.y=s.mouse.y,s.cam_z>0?h.z=-1:h.z=1,s.cam===s.perspectiveCamera?(s.cam_z>0?h.z=-1:h.z=1,h.unproject(s.cam),s.raycaster.set(s.cam.position,h.sub(s.cam.position).normalize())):s.cam===s.orthographicCamera&&(s.cam_z>0?h.z=1:h.z=-1,h.unproject(s.cam),s.raycaster.set(h,new THREE.Vector3(0,0,-1).transformDirection(s.cam.matrixWorld)));let p=this.isIntersect(s.objects,s.mdl,t,d,c);p||(p=this.isIntersect(s.objects_ghost,s.mdl_ghost,t,d,c))}isIntersect(e,t,s,i,n){let l=this.icn3d;l.icn3dui;let r=l.raycaster.intersectObjects(e),o=!1,a=t.position;if(r.length>0){r[0].point.sub(a);let e=l.rayThreshold,t=this.getAtomsFromPosition(r[0].point,e);for(;!t&&e<10;)e+=.5,t=this.getAtomsFromPosition(r[0].point,e);t?(o=!0,l.pickpair?s&&(l.pAtomNum%2==0?l.pAtom=t:l.pAtom2=t,++l.pAtomNum):l.pAtom=t,s?l.pickingCls.showPicking(t):l.pickingCls.showPicking(t,i,n)):console.log("No atoms were found in 10 andstrom range")}return o}getAtomsFromPosition(e,t,s){let i,n=this.icn3d,l=n.icn3dui;null==t&&(t=1);let r=s||n.dAtoms;for(i in r){let s=n.atoms[i];if(n.ions.hasOwnProperty(i)&&"sphere"===n.opts.ions){let i=l.parasCls.vdwRadii[s.elem.toUpperCase()];if(Math.abs(s.coord.x-e.x)-i>t)continue;if(Math.abs(s.coord.y-e.y)-i>t)continue;if(Math.abs(s.coord.z-e.z)-i>t)continue}else{if(s.coord.x<e.x-t||s.coord.x>e.x+t)continue;if(s.coord.y<e.y-t||s.coord.y>e.y+t)continue;if(s.coord.z<e.z-t||s.coord.z>e.z+t)continue}return s}return null}}class Ls{constructor(e){this.icn3d=e}setControl(){let e=this.icn3d,t=e.icn3dui;if(t.bNode)return;let s=this;e.WIDTH=e.container.width(),e.HEIGHT=e.container.height(),e.applyCenterCls.setWidthHeight(e.WIDTH,e.HEIGHT),e._zoomFactor=1,e.mouseChange=new THREE.Vector2(0,0),e.quaternion=new THREE.Quaternion(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(s){if((s.shiftKey||16===s.keyCode)&&(e.bShift=!0),(s.ctrlKey||17===s.keyCode||224===s.keyCode||91===s.keyCode)&&(e.bCtrl=!0),!e.bControlGl&&!e.controls||e.bControlGl&&!window.controls)return;e.bStopRotate=!0;let i=e.bShift?90:5;if(!e.typetext)if(90===s.keyCode){let s={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?s._zoomFactor=.9:window.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),s._zoomFactor=.8*e._zoomFactor,s._zoomFactor<.1&&(s._zoomFactor=.1)):e.cam===e.perspectiveCamera?s._zoomFactor=.9:e.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),s._zoomFactor=.8*e._zoomFactor,s._zoomFactor<.1&&(s._zoomFactor=.1)),s.update=!0,e.bControlGl&&!t.bNode?window.controls.update(s):e.controls.update(s),e.bRender&&e.drawCls.render()}else if(88===s.keyCode){let s={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?s._zoomFactor=1.03:window.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),s._zoomFactor=1.01*e._zoomFactor,s._zoomFactor>10&&(s._zoomFactor=10)):e.cam===e.perspectiveCamera?s._zoomFactor=1.03:e.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),s._zoomFactor=1.01*e._zoomFactor,s._zoomFactor>10&&(s._zoomFactor=10)),s.update=!0,e.bControlGl&&!t.bNode?window.controls.update(s):e.controls.update(s),e.bRender&&e.drawCls.render()}else if(76===s.keyCode){let t=new THREE.Vector3(0,1,0),s=-i/180*Math.PI;e.transformCls.setRotation(t,s)}else if(74===s.keyCode){let t=new THREE.Vector3(0,1,0),s=i/180*Math.PI;e.transformCls.setRotation(t,s)}else if(73===s.keyCode){let t=new THREE.Vector3(1,0,0),s=-i/180*Math.PI;e.transformCls.setRotation(t,s)}else if(77===s.keyCode){let t=new THREE.Vector3(1,0,0),s=i/180*Math.PI;e.transformCls.setRotation(t,s)}else 65===s.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(s){if(e.isDragging=!0,e.scene){if(e.bStopRotate=!0,e.pk&&(s.altKey||s.ctrlKey||s.shiftKey||18===s.keyCode||16===s.keyCode||17===s.keyCode||224===s.keyCode||91===s.keyCode)){e.highlightlevel=e.pk;let t=!0;e.rayCls.rayCaster(s,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(s){if(s.preventDefault(),e.isDragging=!0,!e.scene)return;e.bStopRotate=!0,$("#"+e.pre+"popup").hide();e.rayCls.rayCaster(s,!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){s.mouseMove(e)})),e.container.bind("mousewheel",(function(s){s.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(s){s.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,s=t.icn3dui;if(s.bNode)return;if(e.preventDefault(),!t.scene)return;$("#"+t.pre+"popup").hide();if(t.rayCls.rayCaster(e,!1),t.bControlGl&&!s.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 Ns{constructor(e){this.icn3d=e}showPicking(e,t,s){let i=this.icn3d,n=i.icn3dui;if(void 0!==n.cfg.cid&&0!=i.pk&&(i.pk=1),i.highlightlevel=i.pk,this.showPickingBase(e,t,s),0!=i.pk)if(void 0!==t&&void 0!==s){null!=n.cfg.showmenu&&1==n.cfg.showmenu&&(s+=n.htmlCls.MENU_HEIGHT);let l,r=1==i.pk?e.resn+e.resi+"@"+e.name:e.resn+e.resi,o=e.structure+"_"+e.chain;if(void 0!==i.structures&&Object.keys(i.structures).length>1?(r=o+" "+r,l=i.chainid2refpdbname&&i.chainid2refpdbname[o]?240:160,$("#"+i.pre+"popup").css("width",l+"px")):(l=i.chainid2refpdbname&&i.chainid2refpdbname[o]?160:80,$("#"+i.pre+"popup").css("width",l+"px")),i.chainid2refpdbname&&i.chainid2refpdbname[o]){let t=i.resid2refnum[o+"_"+e.resi];t&&(r+=", Ig: "+t)}$("#"+i.pre+"popup").html(r),$("#"+i.pre+"popup").css("top",s).css("left",t+20).show()}else{i.hlUpdateCls.updateHlAll();let t={};t.factor=i._zoomFactor,t.mouseChange=i.mouseChange,t.quaternion={},t.quaternion._x=parseFloat(i.quaternion._x).toPrecision(5),t.quaternion._y=parseFloat(i.quaternion._y).toPrecision(5),t.quaternion._z=parseFloat(i.quaternion._z).toPrecision(5),t.quaternion._w=parseFloat(i.quaternion._w).toPrecision(5),n.htmlCls.clickMenuCls.setLogCmd("pickatom "+e.serial,!0),i.selectionCls.saveSelInCommand(),i.bSphereCalc=!1,i.bHbondCalc=!1}}showPickingBase(e,t,s){this.icn3d.icn3dui,void 0===t&&void 0===s&&this.showPickingHilight(e)}getPickedAtomList(e,t){let s=this.icn3d;s.icn3dui;let i={};if(1===e)i[t.serial]=1;else if(2===e){let e=t.structure+"_"+t.chain+"_"+t.resi;i=s.residues[e]}else if(3===e)i=this.selectStrandHelixFromAtom(t);else if(4===e)i=this.select3ddomainFromAtom(t);else if(5===e){let e=t.structure+"_"+t.chain;i=s.chains[e]}return i}showPickingHilight(e){let t=this.icn3d,s=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 i=Object.keys(t.hAtoms).length==Object.keys(t.atoms).length?{}:s.hashUtilsCls.intHash(t.hAtoms,t.pickedAtomList),n=Object.keys(i).length;if(t.bShift||t.bCtrl)if(t.bShift){if(void 0===t.prevPickedAtomList)t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e=t.firstAtomObjCls.getFirstAtomObj(t.prevPickedAtomList),i=t.firstAtomObjCls.getFirstAtomObj(t.pickedAtomList);if(e.structure+"_"+e.chain!=i.structure+"_"+i.chain)t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e;e=s.hashUtilsCls.unionHash(e,t.prevPickedAtomList),e=s.hashUtilsCls.unionHash(e,t.pickedAtomList);let i=t.firstAtomObjCls.getFirstAtomObj(e),n=t.firstAtomObjCls.getLastAtomObj(e);for(let e=i.serial;e<=n.serial;++e)t.hAtoms[e]=1}}t.prevPickedAtomList=s.hashUtilsCls.cloneHash(t.pickedAtomList)}else t.bCtrl&&(t.hAtoms=n>0?s.hashUtilsCls.exclHash(t.hAtoms,t.pickedAtomList):s.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList));else t.hAtoms=s.hashUtilsCls.cloneHash(t.pickedAtomList);t.hlObjectsCls.removeHlObjects(),t.hlObjectsCls.addHlObjects()}select3ddomainFromAtom(e){let t,s=this.icn3d,i=s.icn3dui,n=e.structure+"_"+e.chain,l=n+"_"+e.resi;for(let e in s.tddomains){let i=e.indexOf("_3d_domain");if(e.substr(0,i)==n&&-1!==Object.keys(s.tddomains[e]).indexOf(l)){t=e;break}}let r={};for(let e in s.tddomains[t])r=i.hashUtilsCls.unionHash(r,s.residues[e]);return r}selectStrandHelixFromAtom(e){let t=this.icn3d,s=t.icn3dui,i=e,n=e,l={},r=i.resi;if(!i.ssbegin&&!isNaN(i.resi)){for(let e=i.resi-1;e>0;--e){let s=i.structure+"_"+i.chain+"_"+e;if(!t.residues.hasOwnProperty(s))break;let n=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[s]);if(r=n.resi,"coil"!==i.ss&&n.ss===i.ss&&n.ssbegin||"coil"===i.ss&&n.ss!==i.ss){"coil"===i.ss&&n.ss!==i.ss&&(r=parseInt(n.resi)+1);break}}for(let e=r;e<=i.resi;++e){let n=i.structure+"_"+i.chain+"_"+e;l=s.hashUtilsCls.unionHash(l,s.hashUtilsCls.hash2Atoms(t.residues[n],t.atoms))}}let o=n.resi,a=t.firstAtomObjCls.getLastAtomObj(t.chains[n.structure+"_"+n.chain]).resi;for(let e=parseInt(n.resi)+1;e<=parseInt(a);++e){let s=n.structure+"_"+n.chain+"_"+e;if(!t.residues.hasOwnProperty(s))break;let i=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[s]);if(o=i.resi,"coil"!==n.ss&&i.ss===n.ss&&i.ssend||"coil"===n.ss&&i.ss!==n.ss){"coil"!==n.ss||i.ss===n.ss||isNaN(i.resi)||(o=i.resi-1);break}}for(let e=parseInt(n.resi)+1;e<=parseInt(o);++e){let i=n.structure+"_"+n.chain+"_"+e;l=s.hashUtilsCls.unionHash(l,s.hashUtilsCls.hash2Atoms(t.residues[i],t.atoms))}return l}}class qs{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t){let s=this.icn3d,i=s.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 l(){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 r=this;if("xr"in navigator)return n.id=i.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 i(s){s.addEventListener("end",l),await e.xr.setSession(s),n.textContent="EXIT VR",t=s}function l(){s.transformCls.resetOrientation(),s.bVr=!1,s.drawCls.draw(),t.removeEventListener("end",l),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(s.bImpo=!1,s.bVr=!0,s.drawCls.draw(s.bVr),null===t){const e={optionalFeatures:["local-floor","bounded-floor","hand-tracking","layers"]};navigator.xr.requestSession("immersive-vr",e).then(i)}else t.end()}}():(l(),n.style.display="none"),t&&r.xrSessionIsGranted&&n.click()})).catch((function(e){l(),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 Us{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t={}){let s=this.icn3d,i=s.icn3dui;const n=document.createElement("button");function l(){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 r(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(i.utilsCls.isAndroid()&&i.utilsCls.isChrome()){if("xr"in navigator)return n.id=i.pre+"ARButton",n.style.display="none",r(n),navigator.xr.isSessionSupported("immersive-ar").then((function(i){i?function(){if(void 0===t.domOverlay){const e=document.createElement("div");e.style.display="none",document.body.appendChild(e);const s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("width",38),s.setAttribute("height",38),s.style.position="absolute",s.style.right="20px",s.style.top="20px",s.addEventListener("click",(function(){i.end()})),e.appendChild(s);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),s.appendChild(n),void 0===t.optionalFeatures&&(t.optionalFeatures=[]),t.optionalFeatures.push("dom-overlay"),t.domOverlay={root:e}}let i=null;async function l(s){s.addEventListener("end",r),e.xr.setReferenceSpaceType("local"),await e.xr.setSession(s),n.textContent="STOP AR",t.domOverlay.root.style.display="",i=s}function r(){s.transformCls.resetOrientation(),s.bAr=!1,s.drawCls.draw(),i.removeEventListener("end",r),n.textContent="START AR",t.domOverlay.root.style.display="none",i=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(){s.bImpo=!1,s.opts.background="transparent",s.bAr=!0,s.drawCls.draw(s.bAr),null===i?navigator.xr.requestSession("immersive-ar",t).then(l):i.end()}}():(l(),n.style.display="none")})).catch((function(e){l(),console.warn("Exception when trying to call xr.isSessionSupported",e),n.style.display="none"})),n;return document.createElement("span")}return n.id=i.pre+"ARButton",n.style.display="none",r(n),l(),n.style.display="none",n}}class $s{constructor(e){let t,s,i,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.icn3dui.bNode){let e=document.createElement("canvas");t=!(!window.WebGLRenderingContext||!e.getContext("webgl")&&!e.getContext("experimental-webgl")),e.remove(),e=document.createElement("canvas"),s=!(!window.WebGLRenderingContext||!e.getContext("webgl2")),e.remove(),i="xr"in navigator,t?(s&&i?(this.renderer=new THREE.WebGLRenderer({canvas:this.oriContainer.get(0),antialias:!0,preserveDrawingBuffer:!0,sortObjects:!1,alpha:!0}),this.renderer.xr.enabled=!0):this.renderer=new THREE.WebGL1Renderer({canvas:this.oriContainer.get(0),antialias:!0,preserveDrawingBuffer:!0,sortObjects:!1,alpha:!0}),this.overdraw=0):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 THREE.Color(.1,.1,.1),this.shininess=40,this.emissive=1118481,this.light1=.8,this.light2=.4,this.light3=.2,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||(s&&i?(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.effects={none:this.renderer},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 THREE.Color(16777011),this.sphereGeometry=new THREE.SphereGeometry(1,32,32),this.boxGeometry=new THREE.BoxGeometry(1,1,1),this.cylinderGeometry=new THREE.CylinderGeometry(1,1,1,32,1),this.cylinderGeometryOutline=new THREE.CylinderGeometry(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.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 Ie(this),this.cameraCls=new Ee(this),this.fogCls=new Te(this),this.boxCls=new Pe(this),this.brickCls=new De(this),this.curveStripArrowCls=new Me(this),this.curveCls=new Fe(this),this.cylinderCls=new He(this),this.lineCls=new Le(this),this.reprSubCls=new Ne(this),this.sphereCls=new qe(this),this.stickCls=new Ue(this),this.strandCls=new $e(this),this.stripCls=new Be(this),this.tubeCls=new je(this),this.cartoonNuclCls=new ze(this),this.surfaceCls=new Ze(this),this.labelCls=new Ve(this),this.axesCls=new We(this),this.glycanCls=new Ye(this),this.applyCenterCls=new Qe(this),this.applyClbondsCls=new et(this),this.applyMissingResCls=new tt(this),this.applyDisplayCls=new st(this),this.applyMapCls=new rt(this),this.applyOtherCls=new it(this),this.applySsbondsCls=new nt(this),this.applySymdCls=new lt(this),this.hlObjectsCls=new Ht(this),this.residueLabelsCls=new ot(this),this.alternateCls=new ct(this),this.drawCls=new ht(this),this.firstAtomObjCls=new ys(this),this.impostorCls=new at(this),this.instancingCls=new dt(this),this.contactCls=new pt(this),this.hBondCls=new mt(this),this.piHalogenCls=new ut(this),this.saltbridgeCls=new gt(this),this.loadPDBCls=new ds(this),this.loadCIFCls=new cs(this),this.vastplusCls=new hs(this),this.transformCls=new Ts(this),this.setStyleCls=new ft(this),this.setColorCls=new Ct(this),this.threeDPrintCls=new Ms(this),this.export3DCls=new Fs(this),this.annoCddSiteCls=new vt(this),this.annoContactCls=new _t(this),this.annoPTMCls=new wt(this),this.annoIgCls=new St(this),this.annoCrossLinkCls=new At(this),this.annoDomainCls=new xt(this),this.annoSnpClinVarCls=new kt(this),this.annoSsbondCls=new Ot(this),this.annoTransMemCls=new Rt(this),this.domain3dCls=new It(this),this.addTrackCls=new Et(this),this.annotationCls=new Tt(this),this.showAnnoCls=new Pt(this),this.showSeqCls=new Dt(this),this.hlSeqCls=new Mt(this),this.hlUpdateCls=new Ft(this),this.lineGraphCls=new Lt(this),this.getGraphCls=new Nt(this),this.showInterCls=new qt(this),this.viewInterPairsCls=new Ut(this),this.drawGraphCls=new $t(this),this.contactMapCls=new Bt(this),this.alignParserCls=new jt(this),this.chainalignParserCls=new zt(this),this.dsn6ParserCls=new Gt(this),this.ccp4ParserCls=new Vt(this),this.mtzParserCls=new Xt(this),this.mmcifParserCls=new Kt(this),this.mmdbParserCls=new Jt(this),this.bcifParserCls=new Zt(this),this.mol2ParserCls=new Qt(this),this.opmParserCls=new es(this),this.pdbParserCls=new ts(this),this.sdfParserCls=new ss(this),this.xyzParserCls=new is(this),this.realignParserCls=new ns(this),this.densityCifParserCls=new ls(this),this.ParserUtilsCls=new rs(this),this.loadAtomDataCls=new os(this),this.setSeqAlignCls=new as(this),this.applyCommandCls=new ps(this),this.definedSetsCls=new ms(this),this.selectCollectionsCls=new us(this),this.legendTableCls=new yt(this),this.loadScriptCls=new gs(this),this.selByCommCls=new fs(this),this.selectionCls=new Cs(this),this.resid2specCls=new bs(this),this.delphiCls=new vs(this),this.dsspCls=new _s(this),this.refnumCls=new ws(this),this.scapCls=new Ss(this),this.symdCls=new As(this),this.alignSWCls=new xs(this),this.analysisCls=new ks(this),this.resizeCanvasCls=new Es(this),this.saveFileCls=new Ps(this),this.setOptionCls=new bt(this),this.shareLinkCls=new Ds(this),this.diagram2dCls=new Os(this),this.cartoon2dCls=new Rs(this),this.ligplotCls=new Is(this),this.rayCls=new Hs(this),this.controlCls=new Ls(this),this.pickingCls=new Ns(this),this.VRButtonCls=new qs(this),this.ARButtonCls=new Us(this),this.matShader=this.setColorCls.setOutlineColor("yellow")}}$s.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=[]},$s.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},$s.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},$s.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 s=t.cfg.mmdbafid.split(",");if(s.length>1)e.opts.color="structure";else if(1==s.length){let t=s[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 Bs{constructor(e){this.cfg=e,this.pre=this.cfg.divid+"_",this.REVISION="3.38.0",this.bNode=Object.keys(window).length<2,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.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 t(this),this.utilsCls=new s(this),this.parasCls=new i(this),this.myEventCls=new n(this),this.rmsdSuprCls=new l(this),this.subdivideCls=new r(this),this.convertTypeCls=new o(this),this.htmlCls=new g(this)}allCustomEvents(){}}Bs.prototype.show3DStructure=async function(e){let t=this;t.cfg.menuicon?(t.htmlCls.wifiStr='<i class="icn3d-wifi" title="requires internet">&nbsp;</i>',t.htmlCls.licenseStr='<i class="icn3d-license" title="requires license">&nbsp;</i>'):(t.htmlCls.wifiStr="",t.htmlCls.licenseStr=""),t.setIcn3d();let s=t.icn3d;t.utilsCls.isSessionStorageSupported()&&s.setStyleCls.getCommandsBeforeCrash();let i=t.htmlCls.WIDTH,n=t.htmlCls.HEIGHT;t.oriWidth=i,t.oriHeight=n,t.htmlCls.eventsCls.allEventFunctions(),this.allCustomEvents();let l=0;if((null==t.cfg.showmenu||t.cfg.showmenu)&&(l+=t.htmlCls.MENU_HEIGHT),(null==t.cfg.showcommand||t.cfg.showcommand)&&(l+=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?$("#"+s.pre+"title").hide():$("#"+s.pre+"title").show(),$("#"+s.pre+"viewer").width(i).height(parseInt(n)+l),$("#"+s.pre+"canvas").width(i).height(parseInt(n)),$("#"+s.pre+"canvas").resizable({resize:function(e,i){t.htmlCls.WIDTH=i.size.width,t.htmlCls.HEIGHT=i.size.height,void 0===s||t.icn3d.bFullscreen||s.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?(s.bReplay=1,$("#"+s.pre+"replay").show()):(s.bReplay=0,$("#"+s.pre+"replay").hide()),t.utilsCls.isMobile()&&(s.threshbox=60),t.cfg.controlGl&&(s.bControlGl=!0,s.container=s.bControlGl&&!t.bNode?$(document):$("#"+s.id)),s.setStyleCls.handleContextLost(),s.applyCenterCls.setWidthHeight(i,n),s.ori_chemicalbinding=s.opts.chemicalbinding,s.opts=t.hashUtilsCls.cloneHash(s.opts),s.STATENUMBER=s.commands.length,t.utilsCls.isSessionStorageSupported()&&s.bCrashed){s.bCrashed=!1;let e=s.commandsBeforeCrash.split("|||")[0],i=e.substr(e.lastIndexOf(" ")+1);if(i===t.cfg.bcifid||i===t.cfg.mmtfid||i===t.cfg.pdbid||i===t.cfg.opmid||i===t.cfg.mmdbid||i===t.cfg.gi||i===t.cfg.blast_rep_id||i===t.cfg.cid||i===t.cfg.mmcifid||i===t.cfg.align||i===t.cfg.chainalign||i===t.cfg.mmdbafid)return void await s.loadScriptCls.loadScript(s.commandsBeforeCrash,!0)}if(s.molTitle="",s.loadCmd,t.htmlCls.clickMenuCls.getHiddenMenusFromCache(),t.htmlCls.clickMenuCls.applyShownMenus(),e){if(s.init(),s.bInputfile=!0,s.InputfileType="pdb",s.InputfileData=s.InputfileData?s.InputfileData+"\nENDMDL\n"+e:e,await s.pdbParserCls.loadPdbData(e),void 0!==t.cfg.resdef&&void 0!==t.cfg.chains){let e=Object.keys(s.structures),i=t.cfg.chains.split(" | "),n=[];if(e.length==i.length){for(let t=0,s=e.length;t<s;++t)n.push(e[t]+"_"+i[t]);n=s.chainalignParserCls.addPostfixForChainids(n);let t=!0,l=!0;await s.realignParserCls.realignChainOnSeqAlign(void 0,n,t,l)}}else if(void 0!==t.cfg.matchedchains){let e=Object.keys(s.structures)[0]+"_"+t.cfg.masterchain,i=t.cfg.matchedchains.split(","),n=[];for(let e=0,t=i.length;e<t;++e){let t=i[e].lastIndexOf("_"),s=i[e].substr(t+1);isNaN(s)?n.push(i[e]):n.push(i[e].substr(0,t))}let l="";for(let e=0,t=n.length;e<t;++e)e>0&&(l+=","),l+=n[e].substr(0,n[e].indexOf("_"));s.chainidArray=[e].concat(n),s.chainidArray=s.chainalignParserCls.addPostfixForChainids(s.chainidArray),s.loadCmd="vast_search_chainid "+s.chainidArray,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),s.bMmdbafid=!0;let r=!0;await s.chainalignParserCls.downloadMmdbAf(l,r)}}else if(void 0!==t.cfg.url){s.bInputUrlfile=!0;let e=t.cfg.url.split("|"),i=e[0],n=e[1];s.molTitle="",s.inputid=n,s.inputurl="type="+i+"&url="+encodeURIComponent(n),s.loadCmd="load url "+n+" | type "+i,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.pdbParserCls.downloadUrl(n,i,t.cfg.command)}else if(void 0!==t.cfg.mmtfid)s.inputid=t.cfg.mmtfid,s.loadCmd="load mmtf "+t.cfg.mmtfid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.bcifParserCls.downloadBcif(t.cfg.mmtfid);else if(void 0!==t.cfg.bcifid)s.inputid=t.cfg.bcifid,s.loadCmd="load bcif "+t.cfg.bcifid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.bcifParserCls.downloadBcif(t.cfg.bcifid);else if(void 0!==t.cfg.pdbid)s.inputid=t.cfg.pdbid,s.loadCmd="load pdb "+t.cfg.pdbid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.pdbParserCls.downloadPdb(t.cfg.pdbid);else if(void 0!==t.cfg.afid){s.inputid=t.cfg.afid,s.loadCmd="load af "+t.cfg.afid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0);let e=!0;await s.pdbParserCls.downloadPdb(t.cfg.afid,e)}else if(void 0!==t.cfg.opmid)s.inputid=t.cfg.opmid,s.loadCmd="load opm "+t.cfg.opmid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.opmParserCls.downloadOpm(t.cfg.opmid);else if(void 0!==t.cfg.mmdbid)s.inputid=t.cfg.mmdbid,s.loadCmd="load mmdb "+t.cfg.mmdbid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadMmdb(t.cfg.mmdbid);else if(void 0!==t.cfg.gi)s.loadCmd="load gi "+t.cfg.gi,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadGi(t.cfg.gi);else if(void 0!==t.cfg.refseqid)s.inputid=t.cfg.refseqid,s.loadCmd="load refseq "+t.cfg.refseqid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadRefseq(t.cfg.refseqid);else if(void 0!==t.cfg.protein)s.inputid=t.cfg.protein,s.loadCmd="load protein "+t.cfg.protein,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadProteinname(t.cfg.protein);else if(void 0!==t.cfg.blast_rep_id)if(s.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?(s.loadCmd="load seq_struct_ids_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,s.bSmithwm=!0):"local_smithwm"==t.cfg.alg?(s.loadCmd="load seq_struct_ids_local_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,s.bLocalSmithwm=!0):(s.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,s.bSmithwm=!1,s.bLocalSmithwm=!1),t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.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,i=await t.getAjaxPromise(e,"json",!1,"The RID "+t.cfg.rid+" may have expired...");for(let e=0,n=i.BlastOutput2.length;e<n;++e){let n,l;if(i.BlastOutput2[e].report.results.iterations){let s=i.BlastOutput2[e].report.results.iterations.length;if(i.BlastOutput2[e].report.results.iterations[s-1].search.query_id!=t.cfg.query_id)continue;n=i.BlastOutput2[e].report.results.iterations[s-1].search.hits}else{if(i.BlastOutput2[e].report.results.search.query_id!=t.cfg.query_id)continue;n=i.BlastOutput2[e].report.results.search.hits}for(let e=0,s=n.length;e<s;++e){let s=n[e],i=!1;for(let e=0,n=s.description.length;e<n;++e){if(s.description[e].accession==t.cfg.blast_rep_id){i=!0;break}}if(i){l=s.hsps[0].qseq,l=l.replace(/-/g,"");break}}void 0!==l&&(t.cfg.query_id=l),s.inputid=t.cfg.query_id+"_"+t.cfg.blast_rep_id,s.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.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,s=await t.getAjaxPromise(e,"jsonp");if(!s.cid||!s.cid[0])return void alert("Please input an valid PubChem CID...");t.cfg.cid=s.cid[0]}s.inputid=t.cfg.cid;let e="https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+s.inputid+"/description/jsonp",i=await t.getAjaxPromise(e,"jsonp",!1);void 0!==i.InformationList&&void 0!==i.InformationList.Information&&(s.molTitle=i.InformationList.Information[0].Title),s.loadCmd="load cid "+t.cfg.cid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.sdfParserCls.downloadCid(t.cfg.cid)}else if(void 0!==t.cfg.smiles)s.inputid=t.cfg.smiles,s.loadCmd="load smiles "+t.cfg.smiles,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.sdfParserCls.downloadSmiles(t.cfg.smiles);else if(void 0!==t.cfg.mmcifid)s.inputid=t.cfg.mmcifid,s.loadCmd="load mmcif "+t.cfg.mmcifid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmcifParserCls.downloadMmcif(t.cfg.mmcifid);else if(void 0!==t.cfg.align){let e=t.cfg.align.split(",");if(6===e.length?s.inputid=e[0]+"_"+e[3]:2===e.length&&(s.inputid=e[0]+"_"+e[1]),s.loadCmd="load alignment "+t.cfg.align+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),t.cfg.inpara&&-1==t.cfg.inpara.indexOf("atype=2"))await s.alignParserCls.downloadAlignment(t.cfg.align);else{let e=2;await s.chainalignParserCls.downloadMmdbAf(t.cfg.align,void 0,e)}}else if(void 0!==t.cfg.chainalign){s.bChainAlign=!0,s.inputid=t.cfg.chainalign;let e=t.cfg.resrange?" | resrange "+t.cfg.resrange:"",i=t.cfg.resdef?t.cfg.resdef:"";s.loadCmd="load chainalignment "+t.cfg.chainalign+" | resnum "+t.cfg.resnum+" | resdef "+i+" | aligntool "+t.cfg.aligntool+" | parameters "+t.cfg.inpara+e,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.chainalignParserCls.downloadChainalignment(t.cfg.chainalign)}else if(void 0!==t.cfg.mmdbafid)t.cfg.mmdbafid=t.cfg.mmdbafid.replace(/\s+/g,"").toUpperCase(),s.bMmdbafid=!0,s.inputid=t.cfg.mmdbafid,1==t.cfg.bu?s.loadCmd="load mmdbaf1 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara:s.loadCmd="load mmdbaf0 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.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=")&&(s.bInputUrlfile=!0)}await s.loadScriptCls.loadScript(t.cfg.command,void 0,!0)},Bs.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&#13;Right(\"Selection\"): Style and color menu options will be applied only to selected atoms'></div></label>",s="<span id='"+e.pre+"modeall' title='Style and color menu options will be applied to all atoms in the structure'>All atoms&nbsp;&nbsp;</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&nbsp;&nbsp;</span></div></div></td>";e.utilsCls.setViewerWidthHeight(e),e.utilsCls.isMobile()||e.cfg.mobilemenu?e.htmlCls.setMenuCls.setTopMenusHtmlMobile(e.cfg.divid,t,s):e.htmlCls.setMenuCls.setTopMenusHtml(e.cfg.divid,t,s),e.icn3d=new $s(e),e.icn3d.controlCls.setControl(),e.setDialogAjax()},Bs.prototype.getMmtfPromise=function(e){return new Promise((function(t,s){MMTF.fetch(e,(async function(e){t(e)}),(function(e){s("error")}))}))},Bs.prototype.getMmtfReducedPromise=function(e){return new Promise((function(t,s){MMTF.fetchReduced(e,(async function(e){t(e)}),(function(e){s("error")}))}))},Bs.prototype.getXMLHttpRqstPromise=function(e,t,s,i){let n=this;return new Promise((function(l,r){let o=new XMLHttpRequest;o.open(t,e,!0),o.responseType=s,o.onreadystatechange=function(){if(4==this.readyState)if(200==this.status){let e=o.response;l(e)}else"2fofc"==i||"fofc"==i?alert("Density server at EBI has no corresponding electron density map for this structure."):"em"==i?alert("Density server at EBI has no corresponding EM density map for this structure."):"rcsbEdmaps"==i?alert("RCSB server has no corresponding electron density map for this structure."):alert("The "+i+" file is unavailable..."),r("error");else n.icn3d.ParserUtilsCls.showLoading()},o.send()}))},Bs.prototype.getAjaxPromise=function(e,t,s,i,n,l,r){let o=this;return new Promise((function(r,a){$.ajax({url:e,dataType:t,cache:!0,beforeSend:function(){s&&o.icn3d.ParserUtilsCls.showLoading()},complete:function(){l&&o.icn3d.ParserUtilsCls.hideLoading()},success:function(e){r(e)},error:function(){i&&alert(i),n&&console.log(n),a("error")}})}))},Bs.prototype.getAjaxPostPromise=async function(e,t,s,i,n,l,r,o){let a=this;return r=r||"json",new Promise((function(o,d){$.ajax({url:e,type:"POST",data:t,dataType:r,cache:!0,beforeSend:function(){s&&a.icn3d.ParserUtilsCls.showLoading()},complete:function(){l&&a.icn3d.ParserUtilsCls.hideLoading()},success:function(e){o(e)},error:function(){!a.bNode&&i&&console.log(i),!a.bNode&&n&&console.log(n),o("error")}})}))},Bs.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,s){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,s){let i=new XMLHttpRequest,n=e.url,l=e.type,r=e.async||!0,o=e.responseType||"blob",a=e.data||null;i.addEventListener("load",(function(){let t={};t[e.dataType]=i.response,s(i.status,i.statusText,t,i.getAllResponseHeaders())})),i.open(l,n,r);for(let e in t)i.setRequestHeader(e,t[e]);i.responseType=o,i.send(a)},abort:function(){s.abort()}}}))};return e.ARButton=Us,e.AddTrack=Et,e.AlignParser=jt,e.AlignSW=xs,e.AlignSeq=m,e.Alternate=ct,e.Analysis=ks,e.AnnoCddSite=vt,e.AnnoContact=_t,e.AnnoCrossLink=At,e.AnnoDomain=xt,e.AnnoSnpClinVar=kt,e.AnnoSsbond=Ot,e.AnnoTransMem=Rt,e.Annotation=Tt,e.ApplyCenter=Qe,e.ApplyClbonds=et,e.ApplyCommand=ps,e.ApplyDisplay=st,e.ApplyMap=rt,e.ApplyOther=it,e.ApplySsbonds=nt,e.ApplySymd=lt,e.Axes=We,e.Box=Pe,e.Brick=De,e.Camera=Ee,e.CartoonNucl=ze,e.ChainalignParser=zt,e.ClickMenu=a,e.Contact=pt,e.Control=Ls,e.ConvertTypeCls=o,e.Curve=Fe,e.CurveStripArrow=Me,e.Cylinder=He,e.DefinedSets=ms,e.Delphi=vs,e.DensityCifParser=ls,e.Diagram2d=Os,e.Dialog=c,e.Domain3d=It,e.Draw=ht,e.DrawGraph=$t,e.Dsn6Parser=Gt,e.Dssp=_s,e.ElectronMap=Je,e.Events=p,e.Export3D=Fs,e.FirstAtomObj=ys,e.Fog=Te,e.GetGraph=Nt,e.Glycan=Ye,e.HBond=mt,e.HashUtilsCls=t,e.HlObjects=Ht,e.HlSeq=Mt,e.HlUpdate=Ft,e.Html=g,e.Impostor=at,e.Instancing=dt,e.Label=Ve,e.Line=Le,e.LineGraph=Lt,e.LoadAtomData=os,e.LoadCIF=cs,e.LoadPDB=ds,e.LoadScript=gs,e.MarchingCube=Xe,e.MmcifParser=Kt,e.MmdbParser=Jt,e.Mol2Parser=Qt,e.MyEventCls=n,e.OpmParser=es,e.ParasCls=i,e.ParserUtils=rs,e.PdbParser=ts,e.PiHalogen=ut,e.Picking=Ns,e.ProteinSurface=Ke,e.Ray=Hs,e.RealignParser=ns,e.Refnum=ws,e.ReprSub=Ne,e.Resid2spec=bs,e.ResidueLabels=ot,e.ResizeCanvas=Es,e.RmsdSuprCls=l,e.Saltbridge=gt,e.SaveFile=Ps,e.Scap=Ss,e.Scene=Ie,e.SdfParser=ss,e.SelectByCommand=fs,e.Selection=Cs,e.SetColor=Ct,e.SetDialog=h,e.SetHtml=u,e.SetMenu=d,e.SetOption=bt,e.SetSeqAlign=as,e.SetStyle=ft,e.ShareLink=Ds,e.ShowAnno=Pt,e.ShowInter=qt,e.ShowSeq=Dt,e.Sphere=qe,e.Stick=Ue,e.Strand=$e,e.Strip=Be,e.SubdivideCls=r,e.Surface=Ze,e.Symd=As,e.ThreeDPrint=Ms,e.Transform=Ts,e.Tube=je,e.UtilsCls=s,e.VRButton=qs,e.Vastplus=hs,e.ViewInterPairs=Ut,e.XyzParser=is,e.iCn3D=$s,e.iCn3DUI=Bs,e.printMsg=class{constructor(){console.log("This is a message from the icn3d package")}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
6
+ let e=[],t=[],c=[],h=o.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",p=o.htmlCls.baseUrl+"tmalign/tmalign.cgi",m=o.cfg.resrange?o.cfg.resrange.split(","):[],u=o.cfg.resrange?r.realignParserCls.getSeqCoorResid([m[0]],i[0],!0).hAtoms:r.chains[i[0]];for(let s=1,n=i.length;s<n;++s){let n,a=o.cfg.resrange?r.realignParserCls.getSeqCoorResid([m[s]],i[s],!0).hAtoms:r.chains[i[s]];if("tmalign"!=o.cfg.aligntool){let e={domains1:r.domain3dCls.getDomainJsonForAlign(a),domains2:r.domain3dCls.getDomainJsonForAlign(u)};n=o.getAjaxPostPromise(h,e)}else{let e={pdb_query:r.saveFileCls.getAtomPDB(a),pdb_target:r.saveFileCls.getAtomPDB(u)};n=o.getAjaxPostPromise(p,e)}e.push(n),t.push(s-1),c.push(l)}let g=Promise.allSettled(e),f=await g;await a.downloadChainalignmentPart2b(s,i,d,f,t,n,c)}}async downloadChainalignmentPart2b(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui;for(let e=0,t=i.length;e<t;++e){let t=i[e].value,s=r[e],o=n[e],d=s==l,c=!1,h={};a.htmlCls.clickMenuCls.setLogCmd("Align "+l+" with "+s,!1),this.processAlign(t,o,h,d,c)}for(let e=0,t=i.length;e<t;++e){let t=r[e],s=n[e];this.transformStructure(t,s,"query")}let d={};!o.bFullUi||void 0===o.q_rotation||a.cfg.resnum||a.cfg.resdef||(d=this.setMsa(t)),o.hAtoms=a.hashUtilsCls.cloneHash(d),o.transformCls.zoominSelection(),await this.downloadChainalignmentPart3(e,t,o.hAtoms)}setMsa(e,t,s){let i=this.icn3d,n=i.icn3dui,l=[];for(let t=1,s=e.length;t<s;++t){let e=0;if(i.qt_start_end&&i.qt_start_end[t-1])for(let s=0,n=i.qt_start_end[t-1].length;s<n;++s)e+=parseInt(i.qt_start_end[t-1][s].q_end)-parseInt(i.qt_start_end[t-1][s].q_start)+1;l.push({index:t,alignLen:e})}l.sort((function(e,t){return t.alignLen-e.alignLen}));let r=i.setSeqAlignCls.setSeqAlignChainForAll(e,l,s);t&&(i.opts.color="identity",i.setColorCls.setColorByOptions(i.opts,r));let o=n.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(i.alnChains),void 0,void 0,!1,void 0,!1),a=$("#"+i.pre+"dl_sequence2").html();return $("#"+i.pre+"dl_sequence2").html(a+o.sequencesHtml),$("#"+i.pre+"dl_sequence2").width(n.htmlCls.RESIDUE_WIDTH*o.maxSeqCnt+200),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),r}async downloadChainalignmentPart2bRealign(e,t,s){let i=this.icn3d,n=i.icn3dui;i.t_trans_add=[],i.q_trans_sub=[],"tmalign"==n.cfg.aligntool&&(i.q_trans_add=[]),i.q_rotation=[],i.qt_start_end=[];let l={},r={},o=!1;for(let s=0,i=e.length;s<i;++s){let i=e[s].value,a=!1,d=!1,c={},h=t[s].split(","),p=h[0].substr(0,h[0].indexOf("_")),m=h[1].substr(0,h[1].indexOf("_"));if(r.hasOwnProperty(p+"_"+m))continue;n.htmlCls.clickMenuCls.setLogCmd("Align "+p+" with "+m,!1);let u=!0;this.processAlign(i,s,c,a,d,u)&&(o=!0,l[p]=void 0===l[p]?1:++l[p],l[m]=void 0===l[m]?1:++l[m],r[p+"_"+m]=h+","+s)}if(!o)return s?"tmalign"==n.cfg.aligntool?void(i.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 i.realignParserCls.realignOnStructAlign()):void i.realignParserCls.realignOnStructAlign(!0);let a,d,c=0;for(let e in r){let t=e.split("_");l[t[0]]>c&&(c=l[t[0]],a=t[0]),l[t[1]]>c&&(c=l[t[1]],a=t[1])}let h={},p={},m={},u={};for(let e in r){let t,s,i=e.split("_"),n=r[e].split(","),l=n[2];if(a==i[0]?(t=i[0],s=i[1]):a==i[1]?(t=i[1],s=i[0]):(t=i[0],s=i[1]),m[t]=1,m.hasOwnProperty(s))continue;m[s]=1,u[e]=r[e],d="target";let o=!0;this.transformStructure(t,l,d,o),d="query",this.transformStructure(s,l,d,o),h[n[0]]=1,h[n[1]]=1}for(let e in u)if(void 0!==i.q_rotation){let t=u[e].split(","),s=[t[1],t[0],t[2]],l=i.setSeqAlignCls.setSeqAlignChain(void 0,void 0,s);p=n.hashUtilsCls.unionHash(p,l);let r=!1,o=n.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(i.alnChains),void 0,void 0,!1,void 0,r),a=$("#"+i.pre+"dl_sequence2").html();$("#"+i.pre+"dl_sequence2").html(a+o.sequencesHtml),$("#"+i.pre+"dl_sequence2").width(n.htmlCls.RESIDUE_WIDTH*o.maxSeqCnt+200)}i.dAtoms=n.hashUtilsCls.cloneHash(p),i.hAtoms=n.hashUtilsCls.cloneHash(p);let g="protein_aligned";i.selectionCls.saveSelection(g,g),i.opts.color="identity",i.setColorCls.setColorByOptions(i.opts,i.hAtoms),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),i.drawCls.draw(),i.transformCls.zoominSelection(),i.hlUpdateCls.updateHlAll()}transformStructure(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=n.structures[e];for(let e=0,o=r.length;e<o;++e)for(let o in n.chains[r[e]]){let e=n.atoms[o];void 0===n.q_rotation||!i&&(l.cfg.resnum||l.cfg.resdef)||(e=this.transformAtom(e,t,s))}}transformAtom(e,t,s){let i=this.icn3d,n=i.icn3dui;if("target"===s);else if("query"===s){"tmalign"!=n.cfg.aligntool&&(e.coord.x-=i.q_trans_sub[t].x,e.coord.y-=i.q_trans_sub[t].y,e.coord.z-=i.q_trans_sub[t].z);let s=e.coord.x*i.q_rotation[t].x1+e.coord.y*i.q_rotation[t].y1+e.coord.z*i.q_rotation[t].z1,l=e.coord.x*i.q_rotation[t].x2+e.coord.y*i.q_rotation[t].y2+e.coord.z*i.q_rotation[t].z2,r=e.coord.x*i.q_rotation[t].x3+e.coord.y*i.q_rotation[t].y3+e.coord.z*i.q_rotation[t].z3;"tmalign"!=n.cfg.aligntool?(s-=i.t_trans_add[t].x,l-=i.t_trans_add[t].y,r-=i.t_trans_add[t].z):(s+=i.q_trans_add[t].x,l+=i.q_trans_add[t].y,r+=i.q_trans_add[t].z),e.coord.x=s,e.coord.y=l,e.coord.z=r}return e}async downloadChainalignmentPart3(e,t,s){let i=this.icn3d,n=i.icn3dui,l={};for(let e in i.atoms)l[e]=1;if(i.dAtoms=l,i.hAtoms=l,i.setStyleCls.setAtomStyleByOptions(i.opts),i.opts.color="identity",i.setColorCls.setColorByOptions(i.opts,i.atoms),void 0!==e&&i.ParserUtilsCls.transformToOpmOriForAlign(i.selectedPdbid,e,!0),i.hAtoms=n.hashUtilsCls.cloneHash(s),i.dAtoms=n.hashUtilsCls.cloneHash(s),await i.ParserUtilsCls.renderStructure(),t.length>2){let e=i.firstAtomObjCls.getResiduesFromAtoms(s),t="protein_aligned",n="protein aligned",l="select "+i.resid2specCls.residueids2spec(Object.keys(e));i.selectionCls.addCustomSelection(Object.keys(e),t,n,l,!0)}i.hlUpdateCls.updateHlAll(),n.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"),void 0!==n.cfg.rotate&&i.resizeCanvasCls.rotStruc(n.cfg.rotate,!0),i.html2ddgm="",n.cfg.show2d&&i.bFullUi&&(n.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),i.bFullUi&&(i.bChainAlign?await i.ParserUtilsCls.set2DDiagramsForChainalign(t):i.ParserUtilsCls.download2Ddgm(i.inputid.toUpperCase())))}addPostfixForChainids(e){this.icn3d.icn3dui;let t={};for(let s=0,i=e.length;s<i;++s){let i=e[s],n=i.indexOf("_"),l=i.substr(0,n);t.hasOwnProperty(l)?++t[l]:t[l]=1,l=1==t[l]?l:l+t[l],e[s]=l+i.substr(n)}return e}async downloadChainalignment(e){let t=this.icn3d,s=t.icn3dui;t.opts.proteins="c alpha trace";let i=e.split(","),n=s.cfg.domainids?s.cfg.domainids.split(","):[];n.length<i.length&&(n=[]),t.chainidArray=this.addPostfixForChainids(i);let l=i[0].indexOf("_");t.mmdbid_t=i[0].substr(0,l).toUpperCase(),t.chain_t=i[0].substr(l+1);let r,o,a=[];t.mmdbid_t.length>5?(o="https://alphafold.ebi.ac.uk/files/AF-"+t.mmdbid_t+"-F1-model_"+t.AFUniprotVersion+".pdb",r=s.getAjaxPromise(o,"text")):(o=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+s.cfg.bu+"&uid="+t.mmdbid_t,void 0!==s.cfg.inpara&&(o+=s.cfg.inpara),r=s.getAjaxPromise(o,"jsonp")),a.push(r),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=i.length;e<n;++e){let n,l,r=i[e].indexOf("_"),o=i[e].substr(0,r).toUpperCase();t.mmdbid_q=5==o.length?o.substr(0,4):o,t.chain_q=i[e].substr(r+1),t.mmdbid_q.length>5?(n="https://alphafold.ebi.ac.uk/files/AF-"+t.mmdbid_q+"-F1-model_"+t.AFUniprotVersion+".pdb",l=s.getAjaxPromise(n,"text")):(n=s.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+s.cfg.bu+"&uid="+t.mmdbid_q,void 0!==s.cfg.inpara&&(n+=s.cfg.inpara),l=s.getAjaxPromise(n,"jsonp")),a.push(l)}for(let e=1,l=i.length;e<l;++e){let l=i[e].indexOf("_"),r=i[e].substr(0,l).toUpperCase();if(t.mmdbid_q=5==r.length?r.substr(0,4):r,t.chain_q=i[e].substr(l+1),!s.cfg.resnum&&!s.cfg.resdef){let i=t.mmdbid_q+"_"+t.chain_q+","+t.mmdbid_t+"_"+t.chain_t,l=n.length>0?n[e]+","+n[0]:void 0;if("tmalign"!=s.cfg.aligntool&&4==t.mmdbid_t.length&&4==t.mmdbid_q.length){let o;o=n.length>0?s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?domainpairs="+l:s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?chainpairs="+i;let d=s.getAjaxPromise(o,"jsonp");a.push(d),t.pdbChainIndexHash[e]=r+"_"+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(a),c=await d;await this.parseChainAlignData(c,i,t.mmdbid_t,t.chain_t)}async parseChainAlignData(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=e[0].value,o="HEADER "+s+"\n";isNaN(s)&&s.length>5&&(r=o+r),n.t_trans_add=[],n.q_trans_sub=[],"tmalign"==l.cfg.aligntool&&(n.q_trans_add=[]),n.q_rotation=[],n.qt_start_end=[],n.mmdbidArray=[],n.mmdbidArray.push(s);let a=[];for(let s=1,i=t.length;s<i;++s){let i=e[s].value,l=t[s].indexOf("_"),r=t[s].substr(0,l).toUpperCase(),o="HEADER "+r+"\n";if(isNaN(r)&&r.length>5&&(i=o+i),void 0===i||-1!==JSON.stringify(i).indexOf("Oops there was a problem"))return void alert("The coordinate data can NOT be retrieved for the structure "+r+"...");n.mmdbidArray.push(r),a.push(i)}let d=0;for(let r=1,o=t.length;r<o;++r){let o=a[r-1],c=t[r].indexOf("_"),h=t[r].substr(0,c).toUpperCase(),p=t[r].substr(c+1);if(!l.cfg.resnum&&!l.cfg.resdef){let a=t.length+r-1;if(n.afChainIndexHash.hasOwnProperty(r))++d,"tmalign"==l.cfg.aligntool?n.q_trans_add[r-1]={x:0,y:0,z:0}:(n.t_trans_add[r-1]={x:0,y:0,z:0},n.q_trans_sub[r-1]={x:0,y:0,z:0}),n.q_rotation[r-1]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},n.qt_start_end[r-1]=void 0;else{let t=e[a-d].value,n=h==s,c=p==i;l.htmlCls.clickMenuCls.setLogCmd("Align "+s+" with "+h,!1),this.processAlign(t,r-1,o,n,c)}}}n.mmdb_data_q=a,await this.loadOpmDataForChainalign(r,a,t,n.mmdbidArray)}processAlign(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a=!1;if(!(e&&0!=e.length||l)){let e="tmalign"==o.cfg.aligntool?"TM-align":"VAST";return r.bRender&&alert("These chains can not be aligned by "+e+"."),a}if(void 0!==s&&-1===JSON.stringify(s).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)&&i&&n)r.t_trans_add[t]={x:0,y:0,z:0},r.q_trans_sub[t]={x:0,y:0,z:0},r.q_rotation[t]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},r.qt_start_end[t]=void 0;else if("error"===e||void 0===e||0==e.length)o.cfg.command||l||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.'),r.t_trans_add[t]={x:0,y:0,z:0},r.q_trans_sub[t]={x:0,y:0,z:0},r.q_rotation[t]={x1:1,y1:0,z1:0,x2:0,y2:1,z2:0,x3:0,y3:0,z3:1},r.qt_start_end[t]=void 0,o.cfg.showanno=1,o.cfg.showalignseq=0;else{"tmalign"==o.cfg.aligntool?r.q_trans_add[t]=e[0].q_trans_add:(r.t_trans_add[t]=e[0].t_trans_add,r.q_trans_sub[t]=e[0].q_trans_sub),r.q_rotation[t]=e[0].q_rotation,r.qt_start_end[t]=e[0].segs;let s=e[0].super_rmsd,i=s?s.toPrecision(4):s,n=e[0].score?e[0].score.toPrecision(4):e[0].score,l="alignment RMSD: "+i;"tmalign"==o.cfg.aligntool&&(l+="; TM-score: "+n),o.htmlCls.clickMenuCls.setLogCmd(l,!1);let d="<br><b>Alignment RMSD</b>: "+i+" &#8491;<br>";"tmalign"==o.cfg.aligntool&&(d+="<b>TM-score</b>: "+n+"<br><br>",r.tmscore=n),$("#"+r.pre+"dl_rmsd_html").html(d),o.cfg.bSidebyside||o.htmlCls.dialogCls.openDlg("dl_rmsd","RMSD of alignment"),a=!0}return a}async loadOpmDataForChainalign(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=this;if(l.cfg.resnum||l.cfg.resdef||l.cfg.resrange)n.bCommandLoad||n.init(),await this.downloadChainalignmentPart2(e,t,void 0,s);else{let o=l.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?mmdbids2opm="+i.join("','"),a=await l.getAjaxPromise(o,"jsonp");if(a&&a.mmdbid){let i=a.mmdbid;n.selectedPdbid=i;let o="https://opm-assets.storage.googleapis.com/pdb/"+i.toLowerCase()+".pdb",d=await l.getAjaxPromise(o,"text");n.bOpm=!0;let c=!0,h=n.loadPDBCls.loadPDB(d,i,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 r.downloadChainalignmentPart2(e,t,h,s)}else n.bCommandLoad||n.init(),await r.downloadChainalignmentPart2(e,t,void 0,s)}}async downloadMmdbAf(e,t,s,i){let n=this.icn3d,l=n.icn3dui;n.structArray=n.structures?Object.keys(n.structures):[],0==n.structArray.length?n.init():(n.bResetAnno=!0,n.bResetSets=!0);let r=e.split(","),o=[];for(let e=0,t=r.length;e<t;++e){let t=r[e].toUpperCase();n.structures.hasOwnProperty(t)||-1!=o.indexOf(t)?i||o.push(r[e]+l.htmlCls.postfix):o.push(r[e])}if(0==o.length)return;n.structArray=n.structArray.concat(o);let a=[];for(let e=0,t=o.length;e<t;++e){let t,s,i=o[e];if(isNaN(i)&&i.length>5)t="https://alphafold.ebi.ac.uk/files/AF-"+i+"-F1-model_"+n.AFUniprotVersion+".pdb",s=l.getAjaxPromise(t,"text");else{let e=i;5==i.length&&(e=i.substr(0,4)),t=l.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+l.cfg.bu+"&uid="+e,void 0!==l.cfg.inpara&&(t+=l.cfg.inpara),s=l.getAjaxPromise(t,"jsonp")}a.push(s)}n.ParserUtilsCls.setYourNote(n.structArray+" in iCn3D"),n.ParserUtilsCls.showLoading();let d=Promise.allSettled(a),c=await d;await this.parseMMdbAfData(c,o,t,s),void 0===s&&n.ParserUtilsCls.hideLoading()}async parseMMdbAfData(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=[];for(let s=0,i=t.length;s<i;++s){let i=e[s].value,n="HEADER "+t[s]+"\n";if(isNaN(t[s])&&t[s].length>5&&(i=n+i),void 0===i||-1!==JSON.stringify(i).indexOf("Oops there was a problem"))return void alert("The coordinate data can NOT be retrieved for the structure "+t[s]+"...");r.push(i)}let o=!1;for(let e=0,i=t.length;e<i;++e){let i,l;if(e==t.length-1&&(o=!0),0!=e||s||n.structArray.length!=t.length?(i="query",l=!0):(i="target",l=!1),isNaN(t[e])&&t[e].length>5){let s=!1;await n.pdbParserCls.loadPdbData(r[e],t[e],!1,l,i,o,s)}else{let s=!0,l=t[e];await n.mmdbParserCls.parseMmdbData(r[e],i,void 0,void 0,o,s,l)}}let a=Object.keys(n.structures);if(n.opts.color=a.length>1?"structure":a[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!==l.cfg.rotate&&n.resizeCanvasCls.rotStruc(l.cfg.rotate,!0),s&&l.cfg.matchedchains)n.hAtoms=n.definedSetsCls.getAtomsFromNameArray(n.chainidArray),await n.realignParserCls.realignOnStructAlign(),$("#"+n.pre+"dl_annotations").html(""),n.bAnnoShown=!1,$("#"+l.pre+"dl_selectannotations").hasClass("ui-dialog-content")&&$("#"+n.pre+"dl_selectannotations").dialog("isOpen")&&$("#"+n.pre+"dl_selectannotations").dialog("close");else if(void 0!==i){let e=Object.keys(n.structures);2==i&&(l.cfg.aligntool="tmalign"),await n.vastplusCls.vastplusAlign(e,i)}}}class Gt{constructor(e){this.icn3d=e}async dsn6Parser(e,t,s){this.icn3d.icn3dui;let i="https://edmaps.rcsb.org/maps/"+e.toLowerCase()+"_"+t+".dsn6";await this.dsn6ParserBase(i,t,s,"url",!0)}async dsn6ParserBase(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=this;if("2fofc"==t&&l.bAjax2fofc)l.mapData.sigma2=s,l.setOptionCls.setOption("map",t);else if("fofc"==t&&l.bAjaxfofc)l.mapData.sigma=s,l.setOptionCls.setOption("map",t);else{let a=await r.getXMLHttpRqstPromise(e,"GET","arraybuffer","rcsbEdmaps");s=o.loadDsn6Data(a,t,s,i,n),"2fofc"==t?l.bAjax2fofc=!0:"fofc"==t&&(l.bAjaxfofc=!0),l.setOptionCls.setOption("map",t)}return s}loadDsn6Data(e,t,s,i,n){let l,r,o=this.icn3d,a=o.icn3dui,d={},c=e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e,h=new Int16Array(c),p=new Uint8Array(c),m=String.fromCharCode.apply(null,p.subarray(0,512));if(0==m.indexOf(":-)"))d.xStart=parseInt(m.substr(10,5)),d.yStart=parseInt(m.substr(15,5)),d.zStart=parseInt(m.substr(20,5)),d.xExtent=parseInt(m.substr(32,5)),d.yExtent=parseInt(m.substr(38,5)),d.zExtent=parseInt(m.substr(42,5)),d.xRate=parseInt(m.substr(52,5)),d.yRate=parseInt(m.substr(58,5)),d.zRate=parseInt(m.substr(62,5)),d.xlen=1*parseFloat(m.substr(73,10)),d.ylen=1*parseFloat(m.substr(83,10)),d.zlen=1*parseFloat(m.substr(93,10)),d.alpha=parseFloat(m.substr(103,10)),d.beta=parseFloat(m.substr(113,10)),d.gamma=parseFloat(m.substr(123,10)),l=parseFloat(m.substr(138,12))/100,r=parseInt(m.substr(155,8)),d.sigma=100*parseFloat(m.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,l=h[15]/h[18],r=h[16]}a.bNode||console.log("header: "+JSON.stringify(d));let u=new Float32Array(d.xExtent*d.yExtent*d.zExtent),g=512,f=Math.ceil(d.xExtent/8),C=Math.ceil(d.yExtent/8),b=Math.ceil(d.zExtent/8),y=-999;for(let e=0;e<b;++e)for(let t=0;t<C;++t)for(let s=0;s<f;++s)for(let i=0;i<8;++i){let n=8*e+i;for(let e=0;e<8;++e){let i=8*t+e;for(let e=0;e<8;++e){let t=8*s+e;if(!(t<d.xExtent&&i<d.yExtent&&n<d.zExtent)){g+=8-e;break}{let e=(t*d.yExtent+i)*d.zExtent+n;u[e]=(p[g]-r)/l,u[e]>y&&(y=u[e]),++g}}}}return n||(s=this.setSigma(y,i,t,s)),"2fofc"==t?(o.mapData.header2=d,o.mapData.data2=u,o.mapData.matrix2=this.getMatrix(d),o.mapData.type2=t,o.mapData.sigma2=s):(o.mapData.header=d,o.mapData.data=u,o.mapData.matrix=this.getMatrix(d),o.mapData.type=t,o.mapData.sigma=s),s}setSigma(e,t,s,i){let n,l=this.icn3d.icn3dui;"file"==t?n="dsn6sigma"+s:"url"==t&&(n="dsn6sigmaurl"+s);return n&&($("#"+l.pre+n).val()?i=$("#"+l.pre+n).val():(i=(.2*e).toFixed(2),$("#"+l.pre+n).val(i))),i}getMatrix(e){this.icn3d.icn3dui;let t=e,s=[t.xlen,0,0],i=[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 l=[[],s,i,n],r=[0,t.xRate,t.yRate,t.zRate],o=[0,1,2,3],a=new THREE.Matrix4;return a.set(l[o[1]][0]/r[o[1]],l[o[2]][0]/r[o[2]],l[o[3]][0]/r[o[3]],0,l[o[1]][1]/r[o[1]],l[o[2]][1]/r[o[2]],l[o[3]][1]/r[o[3]],0,l[o[1]][2]/r[o[1]],l[o[2]][2]/r[o[2]],l[o[3]][2]/r[o[3]],0,0,0,0,1),a.multiply((new THREE.Matrix4).makeTranslation(t.xStart,t.yStart,t.zStart)),a}loadDsn6File(e){var t=this.icn3d,s=t.icn3dui;let i=this,n=$("#"+t.pre+"dsn6file"+e)[0].files[0],l=$("#"+t.pre+"dsn6sigma"+e).val();if(n){s.utilsCls.checkFileAPI();let t=new FileReader;t.onload=function(t){let n=i.icn3d,r=t.target.result;l=i.loadDsn6Data(r,e,l,"file"),"2fofc"==e?n.bAjax2fofc=!0:"fofc"==e&&(n.bAjaxfofc=!0),n.setOptionCls.setOption("map",e),s.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+n.pre+"dsn6file"+e).val()+" with sigma "+l,!1)},t.readAsArrayBuffer(n)}else alert("Please select a file before clicking 'Load'")}loadDsn6FileUrl(e){var t=this.icn3d,s=t.icn3dui;let i=$("#"+t.pre+"dsn6fileurl"+e).val(),n=$("#"+t.pre+"dsn6sigmaurl"+e).val();i?(n=this.dsn6ParserBase(i,e,n,"url"),s.htmlCls.clickMenuCls.setLogCmd("set map "+e+" sigma "+n+" file dsn6 | "+encodeURIComponent(i),!0)):alert("Please input the file URL before clicking 'Load'")}}class Vt{constructor(e){this.icn3d=e}async ccp4ParserBase(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=await l.getXMLHttpRqstPromise(e,"GET","arraybuffer","");return s=this.load_map_from_buffer(r,t,s,i,!0),n.setOptionCls.setOption("map",t),s}load_map_from_buffer(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui,e.byteLength<1024)throw Error("File shorter than 1024 bytes.");const r=new Int32Array(e,0,256);if(542130509!==r[52])throw Error("not a CCP4 map");const o=[r[0],r[1],r[2]],a=r[3];let d;if(2===a)d=4;else{if(0!==a)throw Error("Only Mode 2 and Mode 0 of CCP4 map is supported.");d=1}const c=[r[4],r[5],r[6]],h=[r[7],r[8],r[9]],p=r[23];if(1024+p+d*o[0]*o[1]*o[2]!==e.byteLength)throw Error("ccp4 file too short or too long");const m=new Float32Array(e,0,e.byteLength/4),u=new Yt(h),g=new Wt(m[10],m[11],m[12],m[13],m[14],m[15]),f=[r[16],r[17],r[18]],C=f.indexOf(1),b=f.indexOf(2),y=f.indexOf(3),v=m[19],_=m[20];if(p%4!=0)throw Error("CCP4 map with NSYMBT not divisible by 4 is not supported.");let w;w=2===a?m:new Int8Array(e);let S=(1024+p)/d|0,A=1,x=0;0===a&&-128===r[39]&&127===r[40]&&(A=(_-v)/255,x=.5*(v+_+A));const k=[c[0]+o[0],c[1]+o[1],c[2]+o[2]];let O=[0,0,0],R=-999;for(O[2]=c[2];O[2]<k[2];O[2]++)for(O[1]=c[1];O[1]<k[1];O[1]++)for(O[0]=c[0];O[0]<k[0];O[0]++){let e=A*w[S]+x;u.set_grid_value(O[C],O[b],O[y],e),e>R&&(R=e),S++}return n||(s=l.dsn6ParserCls.setSigma(R,i,t,s)),"2fofc"==t?(l.mapData.ccp4=1,l.mapData.grid2=u,l.mapData.unit_cell2=g,l.mapData.type2=t,l.mapData.sigma2=s):(l.mapData.ccp4=1,l.mapData.grid=u,l.mapData.unit_cell=g,l.mapData.type=t,l.mapData.sigma=s),s}load_maps_from_mtz_buffer(e,t,s,i,n,l){let r=this.icn3d;r.icn3dui;let o="fofc"==t,a=e.calculate_map(o),d=e.cell;const c=new Wt(d.a,d.b,d.c,d.alpha,d.beta,d.gamma);let h=-999;for(let e=0,t=a.length;e<t;++e)a[e]>h&&(h=a[e]);if(n||(s=r.dsn6ParserCls.setSigma(h,i,t,s)),l){r.mapData.ccp4=0;let i={xExtent:e.nx,yExtent:e.ny,zExtent:e.nz,mean:void 0,sigma:s,ccp4:1,xStart:0,yStart:0,zStart:0};i.xRate=e.nx,i.yRate=e.ny,i.zRate=e.nz,i.xlen=d.a,i.ylen=d.b,i.zlen=d.c,i.alpha=d.alpha,i.beta=d.beta,i.gamma=d.gamma,"2fofc"==t?(r.mapData.header2=i,r.mapData.data2=a,r.mapData.matrix2=r.dsn6ParserCls.getMatrix(i),r.mapData.type2=t,r.mapData.sigma2=s):(r.mapData.header=i,r.mapData.data=a,r.mapData.matrix=r.dsn6ParserCls.getMatrix(i),r.mapData.type=t,r.mapData.sigma=s)}else{const i=new Yt([e.nx,e.ny,e.nz]);i.values.set(a),"2fofc"==t?(r.mapData.ccp4=1,r.mapData.grid2=i,r.mapData.unit_cell2=c,r.mapData.type2=t,r.mapData.sigma2=s):(r.mapData.ccp4=1,r.mapData.grid=i,r.mapData.unit_cell=c,r.mapData.type=t,r.mapData.sigma=s)}return e.delete(),s}parse_symop(e){const t=e.toLowerCase().replace(/\s+/g,"").split(",");if(3!==t.length)throw Error("Unexpected symop: "+e);let s=[];for(let i=0;i<3;i++){const n=t[i].split(/(?=[+-])/);let l=[0,0,0,0];for(let t=0;t<n.length;t++){const s="-"===n[t][0]?-1:1;let i=n[t].match(/^[+-]?([xyz])$/);if(i){l[{x:0,y:1,z:2}[i[1]]]=s}else{if(i=n[t].match(/^[+-]?(\d)\/(\d)$/),!i)throw Error("What is "+n[t]+" in "+e);l[3]=s*Number(i[1])/Number(i[2])}}s.push(l)}return s}loadCcp4File(e){let t=this.icn3d,s=t.icn3dui,i=this,n=$("#"+t.pre+"dsn6file"+e)[0].files[0],l=$("#"+t.pre+"dsn6sigma"+e).val();if(n){s.utilsCls.checkFileAPI();let t=new FileReader;t.onload=function(t){let n=i.icn3d,r=t.target.result;l=i.load_map_from_buffer(r,e,l,"file"),n.setOptionCls.setOption("map",e),s.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+n.pre+"dsn6file"+e).val()+" with sigma "+l,!1)},t.readAsArrayBuffer(n)}else alert("Please select a file before clicking 'Load'")}async loadCcp4FileUrl(e){let t=this.icn3d,s=t.icn3dui,i=$("#"+t.pre+"dsn6fileurl"+e).val(),n=$("#"+t.pre+"dsn6sigmaurl"+e).val();i?(n=await this.ccp4ParserBase(i,e,n,"file"),s.htmlCls.clickMenuCls.setLogCmd("set map "+e+" sigma "+n+" file ccp4 | "+encodeURIComponent(i),!0)):alert("Please input the file URL before clicking 'Load'")}extract_block(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui,null==e||null==t)return;let r=t.fractionalize(i),o=[s/t.parameters[0],s/t.parameters[1],s/t.parameters[2]],a=e.frac2grid([r[0]-o[0],r[1]-o[1],r[2]-o[2]]),d=e.frac2grid([r[0]+o[0],r[1]+o[1],r[2]+o[2]]),c=[d[0]-a[0]+1,d[1]-a[1]+1,d[2]-a[2]+1],h=[],p=[],m=l.hAtoms&&Object.keys(l.hAtoms).length>0;for(let s=a[0];s<=d[0];s++)for(let i=a[1];i<=d[1];i++)for(let r=a[2];r<=d[2];r++){let o=e.grid2frac(s,i,r),a=t.orthogonalize(o);h.push(a);let d=new THREE.Vector3(a[0],a[1],a[2]),c=l.rayCls.getAtomsFromPosition(d,1,l.hAtoms)||!m?e.get_grid_value(s,i,r):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,s,i,n){this.icn3d.icn3dui;const l=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]),r="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 a=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],m=[p,p,p,p,p,p,p,p];const u=e[0],g=e[1],f=e[2];if(null==t||null==s)return;let C=[],b=[],y=0;for(let e=0;e<u-1;e++)for(let n=0;n<g-1;n++)for(let p=0;p<f-1;p++){const u=p+f*(n+g*e);let v,_,w=0;for(v=0;v<8;++v)_=u+d[v],w|=t[_]<i?1<<v:0;if(0===w||255===w)continue;for(v=0;v<8;++v)_=u+d[v],h[v]=t[_],m[v]=s[_];const S=l[w];for(v=0;v<12;++v)if(0!=(S&1<<v)){const e=c[v];let t=(i-h[e[0]])/(h[e[1]]-h[e[0]]);!0===r&&(t>.85?t=1:t<.15&&(t=0));const s=m[e[0]],n=m[e[1]];C.push(s[0]+(n[0]-s[0])*t,s[1]+(n[1]-s[1])*t,s[2]+(n[2]-s[2])*t),a[v]=y++}const A=o[w];for(v=0;v<A.length;v++)b.push(a[A[v]])}return{vertices:C,segments:b}}calculateVertOffsets(e){this.icn3d.icn3dui;let t=[];const s=[[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 i=0;i<8;++i){const n=s[i];t.push(n[0]+e[2]*(n[1]+e[1]*n[2]))}return t}makeChickenWire(e,t){let s=this.icn3d,i=s.icn3dui,n=new THREE.BufferGeometry,l=new Float32Array(e.vertices);n.setAttribute("position",new THREE.BufferAttribute(l,3));let r=e.vertices.length<196608?new Uint16Array(e.segments):new Uint32Array(e.segments);n.setIndex(new THREE.BufferAttribute(r,1));let o=i.parasCls.thr("#00FFFF"),a=i.parasCls.thr("#00FF00"),d=i.parasCls.thr("#ff0000"),c="2fofc"==t?o:"fofc_pos"==t?a:d,h=new THREE.LineBasicMaterial({linewidth:1,color:c}),p=new THREE.LineSegments(n,h);s.mdl.add(p),s.prevMaps.push(p)}}class Wt{constructor(e,t,s,i,n,l){if(e<=0||t<=0||s<=0||i<=0||n<=0||l<=0)throw Error("Zero or negative unit cell parameter(s).");this.parameters=[e,t,s,i,n,l];const r=Math.PI/180,o=Math.cos(r*i),a=Math.cos(r*n),d=Math.cos(r*l),c=Math.sin(r*i),h=Math.sin(r*n),p=Math.sin(r*l);if(0===c||0===h||0===p)throw Error("Impossible angle - N*180deg.");const m=(a*d-o)/p,u=m/h,g=Math.sqrt(1-u*u);this.orth=[e,t*d,s*a,0,t*p,-s*m,0,0,s*h*g],this.frac=[1/e,-d/(p*e),-(d*m+a*p)/(h*g*p*e),0,1/(p*t),u/(g*p*t),0,0,1/(h*g*s)]}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 Yt{constructor(e){this.dim=e,this.values=new Float32Array(e[0]*e[1]*e[2])}modulo(e,t){const s=e%t;return s>=0?s:s+t}grid2index(e,t,s){return e=this.modulo(e,this.dim[0]),t=this.modulo(t,this.dim[1]),s=this.modulo(s,this.dim[2]),this.dim[2]*(this.dim[1]*e+t)+s}grid2index_unchecked(e,t,s){return this.dim[2]*(this.dim[1]*e+t)+s}grid2frac(e,t,s){return[e/this.dim[0],t/this.dim[1],s/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,s,i){const n=this.grid2index(e,t,s);this.values[n]=i}get_grid_value(e,t,s){const i=this.grid2index(e,t,s);return this.values[i]}}class Xt{constructor(e){this.icn3d=e}async mtzParserBase(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a=await o.getXMLHttpRqstPromise(e,"GET","arraybuffer","");return s=await this.loadMtzFileBase(a,t,s,i,n,e,l),r.setOptionCls.setOption("map",t),s}loadMtzFile(e,t){var s=this.icn3d,i=s.icn3dui;let n=this,l=$("#"+s.pre+"dsn6file"+e)[0].files[0],r=$("#"+s.pre+"dsn6sigma"+e).val();if(l){i.utilsCls.checkFileAPI();let s=new FileReader;s.onload=async function(s){let l=n.icn3d;r=await n.loadMtzFileBase(s.target.result,e,r,"file",void 0,void 0,t),i.htmlCls.clickMenuCls.setLogCmd("load map file "+$("#"+l.pre+"dsn6file"+e).val()+" with sigma "+r,!1)},s.readAsArrayBuffer(l)}else alert("Please select a file before clicking 'Load'")}async loadMtzFileBase(e,t,s,i,n,l,r){var o=this.icn3d,a=o.icn3dui;if(void 0===o.bMtz){let e="./script/mtz.js";await a.getAjaxPromise(e,"script"),o.bMtz=!0}GemmiMtz().then((function(d){let c=d.readMtz(e);s=o.ccp4ParserCls.load_maps_from_mtz_buffer(c,t,s,i,n,r),o.setOptionCls.setOption("map",t);let h=r?"rcsbmtz":"mtz";return l&&a.htmlCls.clickMenuCls.setLogCmd("set map "+t+" sigma "+s+" file "+h+" | "+encodeURIComponent(l),!0),s}))}async loadMtzFileUrl(e,t){var s=this.icn3d;s.icn3dui;let i=$("#"+s.pre+"dsn6fileurl"+e).val(),n=$("#"+s.pre+"dsn6sigmaurl"+e).val();i?n=await this.mtzParserBase(i,e,n,"url",void 0,t):alert("Please input the file URL before clicking 'Load'")}}class Kt{constructor(e){this.icn3d=e}async downloadMmcif(e){let t=this.icn3d,s=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(MMCIF) in iCn3D");let i="https://files.rcsb.org/download/"+e+".cif",n=await s.getAjaxPromise(i,"text",!0);await t.opmParserCls.loadOpmData(n,e,void 0,"mmcif",void 0,!0)}async downloadMmcifSymmetry(e,t){let s=this.icn3d,i=s.icn3dui;try{let n="https://models.rcsb.org/"+e+".bcif",l=await i.getXMLHttpRqstPromise(n,"GET","arraybuffer","bcif"),r=!1,o=!0,a=s.bcifParserCls.getBcifJson(l,e,r,o),d=JSON.parse(a);if(void 0!==d.emd&&(s.emd=d.emd),void 0!==d.organism&&(s.organism=d.organism),s.bAssemblyUseAsu){for(let e=0,t=d.assembly.length;e<t;++e){let t=new THREE.Matrix4;t.fromArray(d.assembly[e]),s.biomtMatrices[e]=t}s.asuCnt=s.biomtMatrices.length,1==i.cfg.bu&&Object.keys(s.atoms).length*s.asuCnt>s.maxatomcnt&&(s.bAssembly=!0)}if("mmtfid"===t&&void 0!==d.missingseq){let t=0,n="";for(let l=0,r=d.missingseq.length;l<r;++l){let r=d.missingseq[l].resn,o=d.missingseq[l].chain,a=d.missingseq[l].resi,c=e+"_"+o;void 0===s.chainMissingResidueArray[c]&&(s.chainMissingResidueArray[c]=[]);let h={};h.resi=a,h.name=i.utilsCls.residueName2Abbr(r).toLowerCase(),o!=n&&(t=0),!isNaN(a)&&(""==n||o!=n||o==n&&a>t)&&(s.chainMissingResidueArray[c].push(h),t=a,n=o)}s.loadPDBCls.adjustSeq(s.chainMissingResidueArray)}}catch(e){return void(i.bNode||console.log("mmcifparser.cgi issues: "+e))}}async loadMmcifData(e,t){let s=this.icn3d;if(s.icn3dui,t||(t=e.mmcif),t||(t=s.defaultPdbId),void 0===e.atoms)return!1;s.init(),void 0!==e.emd&&(s.emd=e.emd),void 0!==e.organism&&(s.organism=e.organism),await s.opmParserCls.loadOpmData(e,t,void 0,"mmcif"),s.opmParserCls.modifyUIMapAssembly()}async loadMultipleMmcifData(e,t,s){let i=this.icn3d;i.icn3dui;i.loadCIFCls.loadCIF(e,t,!0,s),Object.keys(i.structures).length>1&&(i.opts.color="structure"),i.opmParserCls.modifyUIMapAssembly(),i.pdbParserCls.addSecondary(s)}}class Jt{constructor(e){this.icn3d=e}async downloadMmdb(e,t){let s,i=this.icn3d,n=i.icn3dui;try{if(s=await this.loadMmdbPrms(e,t),!s||s.error)return void this.getNoData(e,t)}catch(s){return void this.getNoData(e,t)}if(0!=Object.keys(s.atoms).length)if(n.utilsCls.isCalphaPhosOnly(s.atoms)||s.atomCount<=i.maxatomcnt)await this.parseMmdbData(s);else{let s;try{s=await this.loadMmdbPrms(e,t,!0)}catch(s){return void this.getNoData(e,t)}await this.parseMmdbData(s)}else{let e=s.pdbId;await i.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,s=t.icn3dui,i=e.split(",");s.cfg.query_id=i[0],s.cfg.blast_rep_id=i[1];let n=s.cfg.blast_rep_id.split("_")[0];4==n.length?await this.downloadMmdb(n):(t.blastAcxn=s.cfg.blast_rep_id.split(".")[0],await this.downloadRefseq(t.blastAcxn,!0))}async downloadRefseq(e,t){let s=this.icn3d,i=s.icn3dui,n=i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?refseq2uniprot="+e;i.cfg.refseqid=e;let l=await i.getAjaxPromise(n,"jsonp",!1,"The protein accession "+e+" can not be mapped to AlphaFold UniProt ID...");if(!l||!l.uniprot)return void alert("The accession "+e+" can not be mapped to AlphaFold UniProt ID. It will be treated as a UniProt ID instead.");i.cfg.afid=l.uniprot,s.uniprot2acc||(s.uniprot2acc={}),s.uniprot2acc[l.uniprot]=e,t&&(i.cfg.blast_rep_id=i.cfg.afid+"_A");await s.pdbParserCls.downloadPdb(i.cfg.afid,!0)}async downloadProteinname(e){let t=this.icn3d,s=t.icn3dui;s.icn3d.bCid=void 0;let i=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?protein2acc="+e,n=(await s.getAjaxPromise(i,"jsonp")).acc;if(0==n.length)return void(s.bNode||alert("The protein/gene name "+e+" can not be mapped to RefSeq proteins..."));let l=[];for(let e=0,t=n.length;e<t;++e){let t=n[e];i=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?refseq2uniprot="+t;let r=s.getAjaxPromise(i,"jsonp");l.push(r)}let r=Promise.allSettled(l),o=await r;l=[];let a=[];for(let e=0,n=o.length;e<n;++e){let n=o[e].value;if(n&&n.uniprot){let e=n.uniprot;i="https://alphafold.ebi.ac.uk/files/AF-"+e+"-F1-model_"+t.AFUniprotVersion+".pdb",t.ParserUtilsCls.setYourNote(s.cfg.protein+"(NCBI Protein/Gene) in iCn3D");let r=s.getAjaxPromise(i,"text",!0);l.push(r),a.push(e)}}r=Promise.allSettled(l),o=await r;for(let e=0,i=o.length;e<i;++e){let i=o[e].value;if(s.cfg.afid=a[e],i){i="HEADER "+s.cfg.afid+"\n"+i,await t.opmParserCls.parseAtomData(i,s.cfg.afid,void 0,"pdb",void 0);break}}s.cfg.afid||s.bNode||alert("The protein/gene name "+e+" can not be mapped to AlphaFold structures...")}getNoData(e,t){let s=this.icn3d.icn3dui;t?alert("This gi "+e+" has no corresponding 3D structure..."):alert("This mmdbid "+e+" with the parameters "+s.cfg.inpara+" may not have 3D structure data. Please visit the summary page for details: "+s.htmlCls.baseUrl+"pdb/"+e)}async parseMmdbData(e,t,s,i,n,l,r){let o,a=this.icn3d,d=a.icn3dui,c=void 0!==e.pdbId?e.pdbId:e.mmdbId;if(r&&(c=r),this.parseMmdbDataPart1(e,t),void 0===t?(void 0!==e.opm&&void 0!==e.opm.rot&&(a.bOpm=!0,a.opmParserCls.setOpmData(e)),o=a.loadAtomDataCls.loadAtomDataIn(e,c,"mmdbid",void 0,t)):(s&&(c=s.substr(0,s.indexOf("_"))),o=a.loadAtomDataCls.loadAtomDataIn(e,c,"mmdbid",void 0,t,s,i,n,l)),d.cfg.ligand)for(let e in a.chainid2sid)if(a.chainid2sid[e]==d.cfg.ligand.substr(3)){let t=a.firstAtomObjCls.getResiduesFromAtoms(a.chains[e]),s=Object.keys(t)[0].split("_"),i="."+s[1]+":"+s[2];await a.selByCommCls.selectByCommand(i,d.cfg.ligand,d.cfg.ligand);break}a.hAtoms=o;let h=e.pdbId;void 0===t&&a.ParserUtilsCls.setYourNote(h.toUpperCase()+"(MMDB) in iCn3D");for(let t in e.domains){let s=e.domains[t].chain,i=h+"_"+s,n=e.domains[t].domains;for(let e=0,t=n.length;e<t;++e){let t=h+"_"+s+"_3d_domain_"+(e+1).toString();a.tddomains[t]={};let l=n[e].intervals,r={},o={};for(let e=0,s=l.length;e<s;++e){let s=Math.round(l[e][0])-1,n=Math.round(l[e][1])-1;if(!r.hasOwnProperty(s)&&!o.hasOwnProperty(n)){r[s]=1,o[n]=1;for(let e=s;e<=n;++e){let s,n=i+"_"+(e+1).toString();s=a.ncbi2resid[n],s&&(a.tddomains[t][s]=1)}}}}}return a.bAssemblyUseAsu=void 0!==e.asuAtomCount,void 0!==t?a.bAssemblyUseAsu=!1:await a.mmcifParserCls.downloadMmcifSymmetry(c),a.bAssemblyUseAsu&&$("#"+a.pre+"assemblyWrapper").show(),void 0!==a.emd?($("#"+a.pre+"mapWrapper1").hide(),$("#"+a.pre+"mapWrapper2").hide(),$("#"+a.pre+"mapWrapper3").hide()):($("#"+a.pre+"emmapWrapper1").hide(),$("#"+a.pre+"emmapWrapper2").hide(),$("#"+a.pre+"emmapWrapper3").hide()),a.setStyleCls.setAtomStyleByOptions(a.opts),void 0!==d.cfg.blast_rep_id?a.setColorCls.setColorByOptions(a.opts,a.atoms):a.setColorCls.setColorByOptions(a.opts,a.atoms,!0),void 0===t&&(await a.ParserUtilsCls.renderStructure(),void 0!==d.cfg.rotate&&a.resizeCanvasCls.rotStruc(d.cfg.rotate,!0),a.html2ddgm="",d.cfg.show2d&&(d.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),a.bFullUi&&a.ParserUtilsCls.download2Ddgm(a.inputid.toUpperCase()))),void 0!==d.cfg.align&&void 0!==d.cfg.chainalign&&void 0!==d.cfg.mmdbafid||1!=Object.keys(a.structures).length||null!==$("#"+a.pre+"alternateWrapper")&&$("#"+a.pre+"alternateWrapper").hide(),o}parseMmdbDataPart1(e,t){let s=this.icn3d,i=s.icn3dui;if(void 0===e.atoms&&void 0===e.molid2rescount)return alert("invalid MMDB data."),!1;if(void 0===t||"target"===t){let e=!!s.bCommandLoad;s.bStatefile||s.init(e),s.chainsColor={},s.chainsGene={}}"query"===t||(s.interactionData={moleculeInfor:e.moleculeInfor,intrac:e.intrac,intracResidues:e.intracResidues}),"query"===t||(s.mmdb_data=e);let n=void 0!==e.pdbId?e.pdbId:e.mmdbId;"query"===t?s.inputid2=n:s.inputid=n;let l=e.moleculeInfor,r={},o={},a={},d={};for(let e in l){if(0===Object.keys(l[e]).length)continue;let c=void 0===l[e].color?"#CCCCCC":"#"+("000000"+l[e].color.toString(16)).slice(-6),h=void 0===l[e].chain?"":l[e].chain.trim();h=h.replace(/_/g,""),void 0===d[h]?d[h]=1:++d[h];let p=n+"_"+(1===d[h]?h:h+d[h].toString());r[e]=c,o[p]=e,a[e]=p,(void 0===t||i.cfg.mmdbafid)&&(s.chainsColor[p]=i.parasCls.thr(c));let m=void 0===l[e].geneId?"":l[e].geneId,u=void 0===l[e].geneSymbol?"":l[e].geneSymbol,g=void 0===l[e].geneDesc?"":l[e].geneDesc;s.chainsGene[p]={geneId:m,geneSymbol:u,geneDesc:g}}s.molid2chain=a,$("#"+s.pre+"accordion5").show()}loadMmdbPrms(e,t,s){let i,n=this.icn3d,l=n.icn3dui;return i=t?l.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+l.cfg.bu+"&simple=1&gi="+e:l.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+l.cfg.bu+"&simple=1&uid="+e,void 0!==l.cfg.blast_rep_id&&(i+="&bu=0"),void 0!==l.cfg.inpara&&(i+=l.cfg.inpara),s&&(i+="&complexity=2"),void 0===n.chainids2resids&&(n.chainids2resids={}),l.getAjaxPromise(i,"jsonp",!0)}}class Zt{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,s=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(BCIF) in iCn3D");let i="https://models.rcsb.org/"+e+".bcif",n=await s.getXMLHttpRqstPromise(i,"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,s,i){let n=this.icn3d,l=n.icn3dui,r="",o="",a="",d="",c="",h="",p=s?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 m=p.result.dataBlocks[0];t||(m.getCategory("_entry")&&(t=m.getCategory("_entry").getColumn("id").getString(0)),""==t&&(t="stru")),m.getCategory("_citation")&&(o=m.getCategory("_citation").getColumn("pdbx_database_id_PubMed").getString(0)),m.getCategory("_struct")&&(a=m.getCategory("_struct").getColumn("title").getString(0),a=a.replace(/"/,"'")),m.getCategory("_struct_keywords")&&(d=m.getCategory("_struct_keywords").getColumn("pdbx_keywords").getString(0)),m.getCategory("_entity_src_gen")&&(h=m.getCategory("_entity_src_gen").getColumn("gene_src_common_name").getString(0));let u={},g={},f={};if(m.getCategory("_database_2")){let e=m.getCategory("_database_2"),t=e.rowCount;for(let s=0;s<t;++s){let t=e.getColumn("database_id").getString(s),i=e.getColumn("database_code").getString(s);if("EMDB"==t){c=i;break}}}if(m.getCategory("_struct_conf")){let e=m.getCategory("_struct_conf"),t=e.getColumn("conf_type_id"),s=e.getColumn("beg_auth_asym_id"),i=e.getColumn("beg_auth_seq_id"),n=e.getColumn("end_auth_asym_id"),l=e.getColumn("end_auth_seq_id"),r=e.rowCount;for(let e=0;e<r;++e){let r,o=t.getString(e),a=s.getString(e),d=i.getString(e),c=a+"_"+d,h=n.getString(e),p=l.getString(e),m=h+"_"+p;if("HELX"==o.substr(0,4)?(r="helix",u[c]=1,g[m]=1):"STRN"==o.substr(0,4)&&(r="sheet",u[c]=1,g[m]=1),"helix"==r||"sheet"==r)for(let e=parseInt(d);e<=parseInt(p);++e){f[a+"_"+e]=r}}t=s=i=n=l=[]}if(m.getCategory("_struct_sheet_range")){let e=m.getCategory("_struct_sheet_range"),t=e.getColumn("beg_auth_asym_id"),s=e.getColumn("beg_auth_seq_id"),i=e.getColumn("end_auth_asym_id"),n=e.getColumn("end_auth_seq_id"),l=e.rowCount;for(let e=0;e<l;++e){let l=t.getString(e),r=s.getString(e);u[l+"_"+r]=1;let o=i.getString(e),a=n.getString(e);g[o+"_"+a]=1;let d="sheet";for(let e=parseInt(r);e<=parseInt(a);++e){f[l+"_"+e]=d}}t=s=i=n=[]}let C={},b=[],y=[];if(m.getCategory("_struct_conn")){let e=m.getCategory("_struct_conn"),s=e.getColumn("conn_type_id"),i=e.getColumn("ptnr1_auth_asym_id"),n=e.getColumn("ptnr1_label_atom_id"),l=e.getColumn("ptnr1_label_seq_id"),r=e.getColumn("ptnr2_auth_asym_id"),o=e.getColumn("ptnr2_label_atom_id"),a=e.getColumn("ptnr2_label_seq_id"),d=e.rowCount;for(let e=0;e<d;++e){let d=s.getString(e),c=i.getString(e),h=n.getString(e),p=l.getString(e),m=c+"_"+p+"_"+h,u=r.getString(e),g=o.getString(e),f=a.getString(e),C=u+"_"+f+"_"+g;"covale"==d?(b.push(m),b.push(C)):"disulf"==d&&(y.push(t+"_"+c+"_"+p),y.push(t+"_"+u+"_"+f))}s=i=n=l=r=o=a=[]}let v,_,w,S,A,x,k,O,R,I,E,T,P,D,M,F=m.getCategory("_atom_site"),H={},L={id:""},N="",q={},U={},$="",B=F.rowCount,j=1,z=!(10*B>n.maxatomcnt);if(!i){_=F.getColumn("group_PDB"),w=F.getColumn("label_comp_id"),S=F.getColumn("type_symbol"),A=F.getColumn("label_atom_id"),x=F.getColumn("auth_asym_id"),k=F.getColumn("label_seq_id"),O=F.getColumn("auth_seq_id"),R=F.getColumn("label_alt_id"),I=F.getColumn("B_iso_or_equiv"),E=F.getColumn("Cartn_x"),T=F.getColumn("Cartn_y"),P=F.getColumn("Cartn_z"),D=F.getColumn("label_asym_id"),M=F.getColumn("pdbx_PDB_model_num");let e={},t="";for(let s=0;s<B;++s){let i,n=_.getString(s),r=w.getString(s),o=S.getString(s),a=A.getString(s),d=x.getString(s),c=k.getString(s),h=O.getString(s),p=R.getString(s),m=D.getString(s);if(c=h,"ATOM"==n?i=3==r.length?"protein":"nucleotide":"WAT"==r||"HOH"==r?(i="solvent",d="Misc"):(i="ligand",d=r),!z&&("protein"==i&&("C"!=o||"CA"!=a)||"nucleotide"==i&&"P"!=a))continue;if("B"==p)continue;if(U[d]=1,"?"!=c&&"."!=c&&"0"!=c||(c=h),"solvent"==i||"ligand"==i){let s={};e.hasOwnProperty(d)||(e[d]=[]),3!=r.length||"HOH"==r||"WAT"==r?3==r.length&&("O"!=o||"HOH"!=r&&"WAT"!=r)||(s.resi=c,s.name=l.utilsCls.residueName2Abbr(r),e[d].push(s)):d+"_"+r==$&&t==m||(s.resi=c,s.name=l.utilsCls.residueName2Abbr(r),e[d].push(s))}let u=E.getFloat(s),g=T.getFloat(s),f=P.getFloat(s),b=j.toString();H[d+"_"+c+"_"+a]=b;let y={};y.id=b,y.elem=o,y.x=u,y.y=g,y.z=f,y.alt=p,v=d+"_"+c;let I=1.3;if(v!=N||t!=m)q={},q[v]={},q[v][y.id]=y;else{for(let e in q[v])this.hasCovalentBond(y,q[v][e],I)&&(C.hasOwnProperty(y.id)||(C[y.id]={}),C.hasOwnProperty(q[v][e].id)||(C[q[v][e].id]={}),C[y.id][q[v][e].id]=1,C[q[v][e].id][y.id]=1);q[v][y.id]=y}"N"==a&&""!=L.id&&this.hasCovalentBond(y,L,I)&&(C.hasOwnProperty(y.id)||(C[y.id]={}),C.hasOwnProperty(L.id)||(C[L.id]={}),C[y.id][L.id]=1,C[L.id][y.id]=1),"C"==a&&(L=y),N=v,$=d+"_"+r,t=m,++j}for(let e=0;e<b.length;e+=2){let t=H[b[e]],s=H[b[e+1]];C.hasOwnProperty(t)||(C[t]={}),C.hasOwnProperty(s)||(C[s]={}),C[t][s]=1,C[s][t]=1}}if(r+='{"bcif":"'+t+'", '+(""!=c?'"emd":"'+c+'",':"")+(""!=h?'"organism":"'+h+'",':"")+'"pubmedid":"'+o+'", "descr": {"name": "'+a+'", "class": "'+d+'"}',!i){r+=', "atoms":[\n',$="",j=1;let e=t;for(let s=0;s<B;++s){let i=M.getString(s);"1"!=i&&""!=i&&(e=t+i);let n,l=_.getString(s),o=w.getString(s),a=S.getString(s),d=A.getString(s),c=x.getString(s),h=k.getString(s),p=O.getString(s),m=R.getString(s),b=D.getString(s);if(h=p,"ATOM"==l?n=3==o.length?"protein":"nucleotide":"WAT"==o||"HOH"==o?(n="solvent",c="Misc"):(n="ligand",c=o),!z&&("protein"==n&&("C"!=a||"CA"!=d)||"nucleotide"==n&&"P"!=d))continue;if("B"==m)continue;"?"!=h&&"."!=h&&"0"!=h||(h=p);let y=I.getString(s),v=E.getFloat(s),F=T.getFloat(s),H=P.getFloat(s),L=j.toString(),N=c+"_"+h;r+="{",r+='"het":'+("HETATM"==l?"1":"0")+", ",r+='"serial":'+j+", ",r+='"name":"'+d+'", ',r+='"resn":"'+o+'", ',r+='"structure":"'+e+'", ',r+='"chain":"'+c+'", ',r+='"resi":'+h+", ",r+='"coord":{"x":'+v+', "y":'+F+', "z":'+H+"}, ",r+='"b":"'+y+'", ',r+='"elem":"'+a+'", ',r+='"bonds":[';let q={};C.hasOwnProperty(L)&&(q=C[L]);let U=Object.keys(q);for(let e=0,t=U.length;e<t;++e)"undefined"!==U[e]&&(r+=U[e],r+=", ");if(U.length>0&&(r=r.substr(0,r.length-2)),r+="], ",f.hasOwnProperty(N)){r+='"ss":"'+f[N]+'", '}else r+='"ss":"coil", ';u.hasOwnProperty(N)?r+='"ssbegin":1, ':r+='"ssbegin":0, ',g.hasOwnProperty(N)?r+='"ssend":1, ':r+='"ssend":0, ',r+='"mt":"'+n+'"',r+="}",r+=",\n",$=c+"_"+o,prevAutochain=b,++j}j>1&&(r=r.substr(0,r.length-2)),r+="]"}_=w=S=A=x=k=O=R=I=E=T=P=D=[];let G={};if(m.getCategory("_pdbx_poly_seq_scheme")){let e=m.getCategory("_pdbx_poly_seq_scheme"),t=e.getColumn("seq_id"),s=e.getColumn("pdb_seq_num"),i=e.getColumn("mon_id"),n=e.getColumn("pdb_strand_id"),l=e.rowCount,r="",o="";for(let e=0;e<l;++e){t.getString(e);let a=s.getString(e),d=i.getString(e),c=n.getString(e);c!=r&&(0==e||(o=o.substr(0,o.length-2),o+="]",G[r]=o),o="["),o+="["+a+', "'+d+'"]',e<l-1&&(o+=", "),r=c}o+="]",G[r]=o,t=s=i=n=[]}r+=', "sequences":{';let V=!1;for(let e in U){let t;t=ligSeqHash.hasOwnProperty(e)?"["+ligSeqHash[e]+"]":G[e],""!==t&&void 0!==t&&(r+='"'+e+'": '+t+", ",V=!0)}if(V&&(r=r.substr(0,r.length-2)),r+="}",m.getCategory("_pdbx_struct_oper_list")){let e=m.getCategory("_pdbx_struct_oper_list");r+=', "assembly":[';let t=', "pmatrix":',s=!1,i=e.rowCount;for(let n=0;n<i;++n){let l=e.getColumn("id").getString(n);if("X0"==l)continue;let o=e.getColumn("matrix[1][1]").getFloat(n),a=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),m=e.getColumn("matrix[2][3]").getFloat(n),u=e.getColumn("vector[2]").getFloat(n),g="["+o+","+h+","+e.getColumn("matrix[3][1]").getFloat(n)+", 0, "+a+","+p+","+e.getColumn("matrix[3][2]").getFloat(n)+", 0, "+d+","+m+","+e.getColumn("matrix[3][3]").getFloat(n)+", 0, "+c+","+u+","+e.getColumn("vector[3]").getFloat(n)+", 1]";"P"==l?(t+=g,s=!0):(r+=g,n<i-1&&(r+=", "))}r+="]",s&&(r+=t)}if(y.length>0){r+=', "disulfides":[';for(let e=0;e<y.length;e+=2)r+="[",r+='"'+y[e]+'", "'+y[e+1]+'"',r+="]",e<y.length-2&&(r+=", ");r+="]"}return r+="}",r}hasCovalentBond(e,t,s){this.icn3d.icn3dui;let i=this.mElem2Radius[e.elem]+this.mElem2Radius[t.elem],n=e.x-t.x,l=e.y-t.y,r=e.z-t.z;return n*n+l*l+r*r<s*i*i}}class Qt{constructor(e){this.icn3d=e}async loadMol2Data(e){let t=this.icn3d,s=t.icn3dui,i=this.loadMol2AtomData(e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),i?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The Mol2 file has the wrong format...")}loadMol2AtomData(e){let t=this.icn3d;t.icn3dui;let s=e.split(/\r?\n|\r/);if(s.length<4)return!1;t.init();let i,n,l="LIG",r={},o="1_A",a=0,d=0,c=1,h=!1,p=!1,m={},u={};for(let e=0,o=s.length;e<o;++e){let o=s[e].trim();if(""!==o&&"#"!==o.substr(0,1)){if("@<TRIPOS>MOLECULE"==o){t.molTitle=s[e+1].trim();let l=s[e+2].trim().replace(/\s+/g," ").split(" ");i=l[0],n=l[1],e+=4}else"@<TRIPOS>ATOM"==o?(c=1,h=!0,++e):"@<TRIPOS>BOND"==o?(p=!0,h=!1,++e):"@<TRIPOS>SUBSTRUCTURE"==o&&(p=!1,++e);if(o=s[e].trim(),""!==o&&"#"!==o.substr(0,1)){if(h&&a<i){let e=o.replace(/\s+/g," ").split(" "),s=parseInt(e[0]);m[s]=c;let i,n=e[1],d=parseFloat(e[2]),h=parseFloat(e[3]),p=parseFloat(e[4]),g=new THREE.Vector3(d,h,p),f=e[5],C=f.indexOf(".");if(i=-1===C?f:f.substr(0,C),"H"===i&&i===f)u[s]=1;else{let e={het:!0,serial:c,name:n,resn:l,structure:1,chain:"A",resi:1,coord:g,b:0,elem:i,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};t.atoms[c]=e,r[c]=1,++c}++a}if(p&&d<n){let e=o.replace(/\s+/g," ").split(" "),s=parseInt(e[1]),i=parseInt(e[2]),n=e[3],l=n;if("am"===n&&(l="1"),"ar"===n&&(l="1.5"),!(u.hasOwnProperty(s)||u.hasOwnProperty(i)||"1"!==l&&"2"!==l&&"3"!==l&&"1.5"!==l)){let e=l,n=m[s],r=m[i];t.atoms[n].bonds.push(r),t.atoms[n].bondOrder.push(e),t.atoms[r].bonds.push(n),t.atoms[r].bondOrder.push(e),"2"==e?(t.doublebonds[n+"_"+r]=1,t.doublebonds[r+"_"+n]=1):"3"==e?(t.triplebonds[n+"_"+r]=1,t.triplebonds[r+"_"+n]=1):"1.5"==e&&(t.aromaticbonds[n+"_"+r]=1,t.aromaticbonds[r+"_"+n]=1)}++d}}}}t.dAtoms=r,t.hAtoms=r,t.structures[1]=[o],t.chains["1_A"]=r,t.residues["1_A_1"]=r,t.residueId2Name["1_A_1"]=l,void 0===t.chainsSeq["1_A"]&&(t.chainsSeq["1_A"]=[]);let g={resi:1};return g.name=l,t.chainsSeq["1_A"].push(g),t.ParserUtilsCls.setMaxD(),t.saveFileCls.showTitle(),!0}}class es{constructor(e){this.icn3d=e}async downloadOpm(e){let t=this.icn3d,s=t.icn3dui;t.ParserUtilsCls.setYourNote(e.toUpperCase()+"(OPM) in iCn3D"),t.bStopRotate=!0;let i="https://opm-assets.storage.googleapis.com/pdb/"+e.toLowerCase()+".pdb",n=await s.getAjaxPromise(i,"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,s,i,n,l){let r=this.icn3d,o=r.icn3dui;try{t||(t=r.defaultPdbId);let a=o.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&opm&uid="+t.toLowerCase(),d=await o.getAjaxPromise(a,"jsonp",!1);this.setOpmData(d),await this.parseAtomData(e,t,s,i,n,l)}catch(r){await this.parseAtomData(e,t,s,i,n,l)}}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 THREE.Vector3(e.opm.trans1[0],e.opm.trans1[1],e.opm.trans1[2]),t.rmsd_supr.trans2=new THREE.Vector3(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,s,i,n,l){let r=this.icn3d,o=r.icn3dui;"mmcif"===i||"bcif"===i?(r.loadCIFCls.loadCIF(e,t,l),this.modifyUIMapAssembly(),r.setStyleCls.setAtomStyleByOptions(r.opts),r.setColorCls.setColorByOptions(r.opts,r.atoms),await r.ParserUtilsCls.renderStructure(),void 0!==o.cfg.rotate&&r.resizeCanvasCls.rotStruc(o.cfg.rotate,!0)):"pdb"===i?await r.pdbParserCls.loadPdbData(e,t):"align"===i&&(r.bOpm?await r.alignParserCls.downloadAlignmentPart2(t):void 0!==n?await this.loadOpmData(e,n,s,i):await r.alignParserCls.downloadAlignmentPart2(t))}}class ts{constructor(e){this.icn3d=e}async downloadPdb(e,t){let s,i=this.icn3d,n=i.icn3dui;t?(s="https://alphafold.ebi.ac.uk/files/AF-"+e+"-F1-model_"+i.AFUniprotVersion+".pdb",n.cfg.refseqid?i.ParserUtilsCls.setYourNote(n.cfg.refseqid.toUpperCase()+"(NCBI Protein Acc.) in iCn3D"):n.cfg.protein?i.ParserUtilsCls.setYourNote(n.cfg.protein+"(NCBI Protein/Gene) in iCn3D"):i.ParserUtilsCls.setYourNote(e.toUpperCase()+"(AlphaFold) in iCn3D")):(s="https://files.rcsb.org/download/"+e+".pdb",e=e.toUpperCase(),i.ParserUtilsCls.setYourNote(e+"(PDB) in iCn3D"));let l=await n.getAjaxPromise(s,"text",!0,"The ID "+e+" can not be found in the server "+s+"...");if(t){l="HEADER "+e+"\n"+l,await i.opmParserCls.parseAtomData(l,e,void 0,"pdb",void 0)}else await i.opmParserCls.loadOpmData(l,e,void 0,"pdb")}async downloadUrl(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=e.lastIndexOf("/");if(-1!=r){let t=e.lastIndexOf(".");n.filename=e.substr(r+1,t-r-1)}else{let t=e.lastIndexOf(".");n.filename=e.substr(0,t)}let o=await l.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=i?i.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 l.htmlCls.setHtmlCls.loadPng(o,s,!0);else if("pae"===t){l.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,s,i,n,l,r,o){let a=this.icn3d,d=a.icn3dui;if(!i&&(void 0===n||"target"===n)){let e=!!a.bCommandLoad;a.bStatefile||a.init(e)}let c=await a.loadPDBCls.loadPDB(e,t,s,void 0,void 0,i,n,o);return void 0===d.cfg.opmid&&a.ParserUtilsCls.transformToOpmOri(t),void 0!==a.biomtMatrices&&a.biomtMatrices.length>1&&(d.bNode||$("#"+a.pre+"assemblyWrapper").show(),a.asuCnt=a.biomtMatrices.length),d.bNode||(void 0!==a.emd?($("#"+a.pre+"mapWrapper1").hide(),$("#"+a.pre+"mapWrapper2").hide(),$("#"+a.pre+"mapWrapper3").hide()):($("#"+a.pre+"emmapWrapper1").hide(),$("#"+a.pre+"emmapWrapper2").hide(),$("#"+a.pre+"emmapWrapper3").hide())),await this.addSecondary(i,r),c}async addSecondary(e,t){let s=this.icn3d,i=s.icn3dui,n=!1;s.bSecondaryStructure&&1==Object.keys(s.structures).length?n=!1:i.cfg.mmtfid||i.cfg.pdbid||i.cfg.opmid||i.cfg.mmdbid||i.cfg.gi||i.cfg.uniprotid||i.cfg.blast_rep_id||i.cfg.cid||i.cfg.mmcifid||i.cfg.align||i.cfg.chainalign||(n=!0),(!s.bSecondaryStructure||n)&&Object.keys(s.proteins).length>0&&!t?await this.applyCommandDssp(e):(await this.loadPdbDataRender(e),i.bNode||await s.ParserUtilsCls.checkMemProteinAndRotate())}async applyCommandDssp(e){let t=this.icn3d,s=t.icn3dui,i=s.utilsCls.isCalphaPhosOnly(s.hashUtilsCls.hash2Atoms(t.proteins,t.atoms));await t.dsspCls.applyDssp(i,e)}async loadPdbDataRender(e){let t=this.icn3d,s=t.icn3dui;if(void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),(s.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!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0),e&&!s.bNode&&t.definedSetsCls.setModeAndDisplay("all"),t.struct_statefile)for(let e=0,s=t.struct_statefile.length;e<s;++e)await this.execStatefile(t.struct_statefile[e].structure,t.struct_statefile[e].statefile)}async execStatefile(e,t){let s=this.icn3d,i=s.icn3dui;if(!t)return;let n=t.trim().split("\n");n=["select $"+e].concat(n),s.STATENUMBER=n.length,s.CURRENTNUMBER=0;let l=i.hashUtilsCls.cloneHash(s.hAtoms),r=s.commands;s.hAtoms={},s.commands=n,await s.loadScriptCls.execCommands(s.CURRENTNUMBER,s.STATENUMBER-1,s.STATENUMBER,!0),s.hAtoms=i.hashUtilsCls.cloneHash(l),s.commands=r.concat(s.commands)}}class ss{constructor(e){this.icn3d=e}async downloadCid(e){let t=this.icn3d,s=t.icn3dui;t.ParserUtilsCls.setYourNote("PubChem CID "+e+" in iCn3D"),t.bCid=!0;let i="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 s.getAjaxPromise(i,"jsonp",!0,"Can not retrieve the parent CID...")).IdentifierList.CID[0]+"/record/SDF/?record_type=3d&response_type=display",l=await s.getAjaxPromise(n,"text",!0,"This CID may not have 3D structure..."),r=this.loadSdfAtomData(l,e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),r?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The SDF of CID "+e+" has the wrong format...")}async downloadSmiles(e){let t=this.icn3d,s=t.icn3dui,i=s.htmlCls.baseUrl+"openbabel/openbabel.cgi?smiles2sdf="+e,n=await s.getAjaxPromise(i,"text");t.init(),t.bInputfile=!0,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,s=t.icn3dui,i=this.loadSdfAtomData(e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),i?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The SDF file has the wrong format...")}loadSdfAtomData(e,t){let s=this.icn3d;s.icn3dui;let i=e.split(/\r?\n|\r/);if(i.length<4)return!1;s.init();let n=t||1,l="LIG",r=n,o=n+"_A",a=o+"_1",d=parseInt(i[3].substr(0,3));if(isNaN(d)||d<=0)return!1;let c=parseInt(i[3].substr(3,3)),h=4;if(i.length<h+d+c)return!1;let p,m,u=d,g={},f={},C={},b=1;for(p=0;p<u;p++){m=i[h],h++;let e=m.substr(31,3).trim(),t=parseFloat(m.substr(0,10)),r=parseFloat(m.substr(10,10)),o=parseFloat(m.substr(20,10)),a={het:!0,serial:b,name:e,resn:l,structure:n,chain:"A",resi:1,coord:new THREE.Vector3(t,r,o),b:0,elem:e,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};s.atoms[b]=a,C[b]=1,g[p]=b,++b,"H"==e&&(f[p]=1)}s.dAtoms=C,s.hAtoms=C,s.structures[r]=[o],s.chains[o]=C,s.residues[a]=C,s.residueId2Name[a]=l,void 0===s.chainsSeq[o]&&(s.chainsSeq[o]=[]);let y={resi:1};for(y.name=l,s.chainsSeq[o].push(y),p=0;p<c;p++){m=i[h],h++;let e=parseInt(m.substr(0,3))-1+0,t=parseInt(m.substr(3,3))-1+0,n=m.substr(6,3).trim(),l=g[e],r=g[t];s.atoms[l].bonds.push(r),s.atoms[l].bondOrder.push(n),s.atoms[r].bonds.push(l),s.atoms[r].bondOrder.push(n),f.hasOwnProperty(e)||f.hasOwnProperty(t)||("2"==n?(s.doublebonds[l+"_"+r]=1,s.doublebonds[r+"_"+l]=1):"3"==n&&(s.triplebonds[l+"_"+r]=1,s.triplebonds[r+"_"+l]=1))}let v=!1;for(let e=i.length;h<e;++h)if(-1!=i[h].indexOf("PARTIAL_CHARGES")){v=!0;break}if(v){++h;let e=parseInt(i[h]);for(++h,p=0;p<e;++p,++h){m=i[h];let e=m.split(" "),t=parseInt(e[0]),n=parseFloat(e[1]);s.atoms[t].crg=n}}for(p in s.atoms)"H"!==s.atoms[p].name&&(s.atoms[p].bonds2=s.atoms[p].bonds.concat(),s.atoms[p].bondOrder2=s.atoms[p].bondOrder.concat());return s.ParserUtilsCls.setMaxD(),s.saveFileCls.showTitle(),!0}}class is{constructor(e){this.icn3d=e}async loadXyzData(e){let t=this.icn3d,s=t.icn3dui,i=this.loadXyzAtomData(e);void 0===s.cfg.align&&1==Object.keys(t.structures).length&&$("#"+t.pre+"alternateWrapper").hide(),i?(t.setStyleCls.setAtomStyleByOptions(t.opts),t.setColorCls.setColorByOptions(t.opts,t.atoms),await t.ParserUtilsCls.renderStructure(),void 0!==s.cfg.rotate&&t.resizeCanvasCls.rotStruc(s.cfg.rotate,!0)):alert("The XYZ file has the wrong format...")}setXyzAtomSeq(e,t,s,i){let n=this.icn3d,l=n.icn3dui;n.dAtoms=l.hashUtilsCls.unionHash(n.dAtoms,e),n.hAtoms=l.hashUtilsCls.unionHash(n.hAtoms,e),n.structures[t]=[s],n.chains[s]=e,n.residues[i]=e,n.residueId2Name[i]="LIG",void 0===n.chainsSeq[s]&&(n.chainsSeq[s]=[]);let r={resi:1,name:"LIG"};n.chainsSeq[s].push(r);let o=Object.keys(e);for(let e=0,t=o.length;e<t;++e){let t=n.atoms[o[e]];for(let s=e+1,i=o.length;s<i;++s){let i=n.atoms[o[s]],r=1.2*(l.parasCls.covalentRadii[t.elem.toUpperCase()]+l.parasCls.covalentRadii[i.elem.toUpperCase()]);Math.abs(t.coord.x-i.coord.x)>r||(Math.abs(t.coord.y-i.coord.y)>r||Math.abs(t.coord.z-i.coord.z)>r||l.utilsCls.hasCovalentBond(t,i)&&(n.atoms[o[e]].bonds.push(o[s]),n.atoms[o[s]].bonds.push(o[e])))}}}loadXyzAtomData(e){let t=this.icn3d;t.icn3dui;let s=e.split(/\r?\n|\r/);if(s.length<3)return!1;t.init();let i,n,l,r={},o=0,a=1;t.molTitle="";for(let e=0,d=s.length;e<d;++e){let d=s[e].trim();if(""===d)continue;if(""===d||isNaN(d)||(0!==e&&this.setXyzAtomSeq(r,o,i,n),++o,r={},l=o,i=l+"_A",n=i+"_1",o>1&&(t.molTitle+="; "),t.molTitle+=s[e+1].trim(),e+=2),d=s[e].trim(),""===d)continue;let c=d.replace(/,/," ").replace(/\s+/g," ").split(" "),h=c[0],p=parseFloat(c[1]),m=parseFloat(c[2]),u=parseFloat(c[3]),g={het:!0,serial:a,name:h,resn:"LIG",structure:l,chain:"A",resi:1,coord:new THREE.Vector3(p,m,u),b:0,elem:h,bonds:[],ss:"coil",ssbegin:!1,ssend:!1,bondOrder:[]};t.atoms[a]=g,r[a]=1,++a}return this.setXyzAtomSeq(r,o,i,n),t.ParserUtilsCls.setMaxD(),t.saveFileCls.showTitle(),!0}}class ns{constructor(e){this.icn3d=e}realign(){let e=this.icn3d,t=e.icn3dui;e.selectionCls.saveSelectionPrep();let s="alseq_"+(Object.keys(e.defNames2Atoms).length+Object.keys(e.defNames2Residues).length+1);e.selectionCls.saveSelection(s,s),t.htmlCls.clickMenuCls.setLogCmd("realign",!0);let i={},n={};e.realignResid={};let l="";for(let s in e.hAtoms){let r=e.atoms[s],o=r.structure+"_"+r.chain;if(e.proteins.hasOwnProperty(s)&&"CA"==r.name||e.nucleotides.hasOwnProperty(s)&&("O3'"==r.name||"O3*"==r.name)){if(r.structure+"_"+r.resi==l)continue;i.hasOwnProperty(r.structure)||(i[r.structure]=[]),i[r.structure].push(r.coord.clone()),e.realignResid.hasOwnProperty(o)||(e.realignResid[o]=[]),e.realignResid[o].push({resid:o+"_"+r.resi,resn:t.utilsCls.residueName2Abbr(r.resn.substr(0,3)).substr(0,1)}),n[r.structure]=r.structure+"_"+r.chain,l=r.structure+"_"+r.resi}}let r=Object.keys(i),o=r[0],a=[];e.qt_start_end=[],a.push(n[o]);for(let t=1,s=r.length;t<s;++t){let s=r[t],l=i[s],d=i[o],c=!0;e.ParserUtilsCls.alignCoords(l,d,s,c,n[o],n[s]),a.push(n[s])}e.hAtoms=e.chainalignParserCls.setMsa(a),s="protein_aligned",e.selectionCls.saveSelection(s,s),e.transformCls.zoominSelection(),e.hlUpdateCls.updateHlAll()}async parseChainRealignPredefined(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=e[0].substr(0,e[0].indexOf("_")),a={};l.realignResid={},l.opts.color="grey",l.setColorCls.setColorByOptions(l.opts,l.dAtoms),l.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("_")),m=h+e[c+1].substr(e[c+1].indexOf("_"));d[p]=1,d[m]=1,e[0]=p,e[c+1]=m;let u=p+","+m;if(!t[u])continue;let g=t[u][o],f=t[u][h],C=s[u][o],b=s[u][h],y=i[u][o],v=i[u][h];l.realignResid[p]=[],l.realignResid[m]=[];for(let e=0,t=g.length;e<t;++e)l.realignResid[p].push({resid:y[e],resn:g[e]}),l.realignResid[m].push({resid:v[e],resn:f[e]});let _=!0,w=l.ParserUtilsCls.alignCoords(b,C,h,void 0,p,m,c+1,_);a=r.hashUtilsCls.unionHash(a,w.hAtoms),n=parseFloat(w.rmsd)}if(!r.cfg.usepdbnum&&r.cfg.resdef&&n>5){console.log("RMSD from VAST is larger than 5. Realign the chains with TM-align.");let e=Object.keys(d);e.length>0&&(l.hAtoms=l.definedSetsCls.getAtomsFromNameArray(e)),r.cfg.aligntool="tmalign",await l.realignParserCls.realignOnStructAlign()}else l.hAtoms=l.chainalignParserCls.setMsa(e),l.transformCls.zoominSelection(),await l.chainalignParserCls.downloadChainalignmentPart3(void 0,e,l.hAtoms)}async parseChainRealignData(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui,d=s[0].substr(0,s[0].indexOf("_"));r||(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=s[t+1].substr(0,s[t+1].indexOf("_"));r||(p=p.toUpperCase());let m=d+s[0].substr(s[0].indexOf("_")),u=p+s[t+1].substr(s[t+1].indexOf("_"));s[0]=m,s[t+1]=u;let g,f,C=i[m],b=i[u],y=n[m],v=n[u],_=l[m],w=l[u];if(void 0!==h.data){g=h.data[0].query;let e=Object.keys(h.data[0].targets)[0];f=h.data[0].targets[e],f=f.hsps[0]}if(void 0!==g&&void 0!==f){let e=[],s=[],i="",n="";o.realignResid[m]=[],o.realignResid[u]=[];let l=f.segs;for(let t=0,r=l.length;t<r;++t){let r=l[t],a="",d="";for(let t=0;t<=r.orito-r.orifrom;++t){let l=_[t+r.orifrom].substr(0,_[t+r.orifrom].lastIndexOf("_")),c=w[t+r.from].substr(0,w[t+r.from].lastIndexOf("_"));y[t+r.orifrom]&&v[t+r.from]&&(e.push(y[t+r.orifrom]),s.push(v[t+r.from]),i+=C[t+r.orifrom],n+=b[t+r.from],(0==t||a==l&&d==c||a!=l&&d!=c)&&(o.realignResid[m].push({resid:_[t+r.orifrom],resn:C[t+r.orifrom]}),o.realignResid[u].push({resid:w[t+r.from],resn:b[t+r.from]})),a=l,d=c)}}let r,h=!0;r=o.bAfMem?o.ParserUtilsCls.alignCoords(s,e,d,void 0,m,u,t+1,h):o.ParserUtilsCls.alignCoords(s,e,p,void 0,m,u,t+1,h),c=a.hashUtilsCls.unionHash(c,r.hAtoms)}else void 0!==p||a.cfg.command?C&&b&&((C.length<6||b.length<6)&&!a.cfg.command?o.bRender&&alert("These sequences are too short for alignment"):C.length>=6&&b.length>=6&&!a.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(r){o.hAtoms=o.chainalignParserCls.setMsa(s);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=a.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 THREE.Vector3(1,0,0),t=-.5*Math.PI;o.transformCls.setRotation(e,t)}}else o.hAtoms=o.chainalignParserCls.setMsa(s),o.transformCls.zoominSelection(),await o.chainalignParserCls.downloadChainalignmentPart3(t,s,o.hAtoms)}async realignOnSeqAlign(e){let t=this.icn3d;t.icn3dui;let s=t.firstAtomObjCls.getChainsFromAtoms(t.hAtoms),i=Object.keys(s),n=[],l="";for(let e=0,t=i.length;e<t;++e)i[e]!=l&&n.push(i[e]),l=i[e];t.qt_start_end=[],await this.realignChainOnSeqAlign(void 0,n,!0)}async realignOnStructAlign(e){let t=this.icn3d,s=t.icn3dui,i="tmalign"!=s.cfg.aligntool?3:0,n={};for(let e in t.structures){n[e]={};let l=t.structures[e];for(let r=0,o=l.length;r<o;++r){let o=l[r],a=s.hashUtilsCls.intHash(t.hAtoms,t.chains[o]),d=0;for(let s in a)if(t.atoms[s].ssbegin&&++d,d>i){n[e][o]=a;break}}}let l=[],r=[],o=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",a=s.htmlCls.baseUrl+"tmalign/tmalign.cgi",d=Object.keys(n);e&&(d=d.reverse());for(let e=0,i=d.length;e<i;++e){let i=d[e],c=Object.keys(n[i]);if(0!=c.length)for(let h=0,p=c.length;h<p;++h){let p=c[h],m=t.domain3dCls.getDomainJsonForAlign(n[i][p]);for(let c=e+1,h=d.length;c<h;++c){let e=d[c],h=Object.keys(n[e]);if(0!=h.length)for(let d=0,c=h.length;d<c;++d){let c,u=h[d];if("tmalign"!=s.cfg.aligntool){let i={domains1:t.domain3dCls.getDomainJsonForAlign(n[e][u]),domains2:m};c=s.getAjaxPostPromise(o,i)}else{let l=t.saveFileCls.getAtomPDB(n[i][p],void 0,void 0,void 0,void 0,i),r={pdb_query:t.saveFileCls.getAtomPDB(n[e][u],void 0,void 0,void 0,void 0,e),pdb_target:l};c=s.getAjaxPostPromise(a,r)}l.push(c),r.push(p+","+u)}}}}let c=Promise.allSettled(l),h=await c;t.qt_start_end=[],await t.chainalignParserCls.downloadChainalignmentPart2bRealign(h,r,e)}async realignOnStructAlignMsa(e){let t=this.icn3d,s=t.icn3dui,i="tmalign"!=s.cfg.aligntool?3:0,n={};for(let l=0,r=e.length;l<r;++l){let r=e[l],o=s.hashUtilsCls.intHash(t.hAtoms,t.chains[r]),a=0;for(let e in o)if(t.atoms[e].ssbegin&&++a,a>i){n[r]=o;break}}let l=[],r=[],o=[],a=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",d=s.htmlCls.baseUrl+"tmalign/tmalign.cgi",c=e[0],h=c.substr(0,c.indexOf("_")),p=t.domain3dCls.getDomainJsonForAlign(n[c]);for(let i=1,m=e.length;i<m;++i){let m,u=e[i],g=u.substr(0,u.indexOf("_"));if("tmalign"!=s.cfg.aligntool){let e={domains1:t.domain3dCls.getDomainJsonForAlign(n[u]),domains2:p};m=s.getAjaxPostPromise(a,e)}else{let e=t.saveFileCls.getAtomPDB(t.chains[c],void 0,void 0,void 0,void 0,h),i={pdb_query:t.saveFileCls.getAtomPDB(t.chains[u],void 0,void 0,void 0,void 0,g),pdb_target:e};m=s.getAjaxPostPromise(d,i)}l.push(m),r.push(i-1),o.push(g)}let m=Promise.allSettled(l),u=await m;t.t_trans_add=[],t.q_trans_sub=[],"tmalign"==s.cfg.aligntool&&(t.q_trans_add=[]),t.q_rotation=[],t.qt_start_end=[],await t.chainalignParserCls.downloadChainalignmentPart2b(void 0,e,void 0,u,r,h,o)}async realignChainOnSeqAlign(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=this;l.cfg.aligntool="seqalign";let o,a,d,c,h,p,m={},u={},g={},f=[],C=l.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=chainalign";if(i&&(d=l.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,y=t.length;e<y;++e){let y=t[e].indexOf("_"),v=t[e].substr(0,y);0==e&&(o=v);let _=v+t[e].substr(y);if(0==e&&(a=_),n.chainsSeq&&n.chainsSeq[_])if(m.hasOwnProperty(_)||i||(m[_]="",u[_]=[],g[_]=[]),i)if(0==e);else{let t={};c=d[e-1].split(" | ");let s=a+","+_;m[s]||(m[s]={}),u[s]||(u[s]={}),g[s]||(g[s]={}),p=c[0].split(","),h=r.getSeqCoorResid(p,a),t=l.hashUtilsCls.unionHash(t,h.hAtoms),m[s][o]||(m[s][o]=""),u[s][o]||(u[s][o]=[]),g[s][o]||(g[s][o]=[]),m[s][o]+=h.seq,u[s][o]=u[s][o].concat(h.coor),g[s][o]=g[s][o].concat(h.resid),p=c[1].split(","),h=r.getSeqCoorResid(p,_),t=l.hashUtilsCls.unionHash(t,h.hAtoms),m[s][v]||(m[s][v]=""),u[s][v]||(u[s][v]=[]),g[s][v]||(g[s][v]=[]),m[s][v]+=h.seq,u[s][v]=u[s][v].concat(h.coor),g[s][v]=g[s][v].concat(h.resid)}else if(0==e){if(p=[],s){let e=n.firstAtomObjCls.getResiduesFromAtoms(n.hAtoms);for(var b in e){let e=b.substr(b.lastIndexOf("_")+1);b.substr(0,b.lastIndexOf("_"))==_&&p.push(e)}}else l.cfg.resnum&&(p=l.cfg.resnum.split(","));h=r.getSeqCoorResid(p,_),m[_]+=h.seq,u[_]=u[_].concat(h.coor),g[_]=g[_].concat(h.resid)}else{let e=!1;if(s){let t=n.firstAtomObjCls.getResiduesFromAtoms(n.hAtoms);for(var b in t){if(b.substr(0,b.lastIndexOf("_"))==_){e=!0;let t=n.firstAtomObjCls.getFirstAtomObj(n.residues[b]).resn;m[_]+=l.utilsCls.residueName2Abbr(t),u[_]=u[_].concat(this.getResCoorArray(b)),g[_].push(b)}}}if(!e)for(let e=0,t=n.chainsSeq[_].length;e<t;++e){m[_]+=n.chainsSeq[_][e].name;let t=_+"_"+n.chainsSeq[_][e].resi;u[_]=u[_].concat(this.getResCoorArray(t)),g[_].push(t)}let t={targets:m[a],queries:m[_]},i=l.getAjaxPostPromise(C,t);f.push(i)}}if(i)await r.parseChainRealignPredefined(t,m,u,g);else{let i=Promise.allSettled(f);try{let n=await i;await r.parseChainRealignData(n,e,t,m,u,g,s)}catch(e){return void alert("The realignment did not work...")}}}}getSeqCoorResid(e,t,s){let i=this.icn3d,n=i.icn3dui,l="",r=[],o=[],a={};for(let a=0,d=e.length;a<d;++a)if(-1!=e[a].indexOf("-")){let d=e[a].split("-");for(let e=parseInt(d[0]);e<=parseInt(d[1]);++e){let a=s?e:i.setSeqAlignCls.getPosFromResi(t,e);i.chainsSeq[t]&&i.chainsSeq[t][a]&&-1!=n.parasCls.b62ResArray.indexOf(i.chainsSeq[t][a].name.toUpperCase())&&(l+=i.chainsSeq[t][a].name.toUpperCase(),r=r.concat(this.getResCoorArray(t+"_"+e)),o.push(t+"_"+e))}}else if(0==e[a]){let e=i.firstAtomObjCls.getResiduesFromAtoms(i.chains[t]);o=Object.keys(e)}else{let n=e[a],d=s?n:i.setSeqAlignCls.getPosFromResi(t,n);if(!i.chainsSeq[t][d])continue;let c=this.getResCoorArray(t+"_"+n);l+=i.chainsSeq[t][d].name.toUpperCase(),r=r.concat(c),o.push(t+"_"+n)}for(let e=0,t=o.length;e<t;++e)a=n.hashUtilsCls.unionHash(a,i.residues[o[e]]);return{seq:l,coor:r,resid:o,hAtoms:a}}getResCoorArray(e){let t=this.icn3d;t.icn3dui;let s=[],i=!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){s.push(e.coord.clone()),i=!0;break}}return i||s.push(void 0),s}}class ls{constructor(e){this.icn3d=e}async densityCifParser(e,t,s,i,n){let l,r=this.icn3d,o=r.icn3dui,a=this,d=o.utilsCls.isMobile()||o.cfg.notebook?0:4;if("2fofc"==t||"fofc"==t?(d=0,l="https://www.ebi.ac.uk/pdbe/densities/x-ray/"+e.toLowerCase()+"/cell?detail="+d):"em"==t&&(l="https://www.ebi.ac.uk/pdbe/densities/emd/"+i.toLowerCase()+"/cell?detail="+d),"2fofc"==t&&r.bAjax2fofc)r.mapData.sigma2=s,r.setOptionCls.setOption("map",t);else if("fofc"==t&&r.bAjaxfofc)r.mapData.sigma=s,r.setOptionCls.setOption("map",t);else if("em"==t&&r.bAjaxEm)r.mapData.sigmaEm=s,r.setOptionCls.setOption("emmap",t);else{let e=await o.getXMLHttpRqstPromise(l,"GET","arraybuffer",t);a.parseChannels(e,t,s),"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))}}async densityCifParserBase(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=this;if("2fofc"==t&&l.bAjax2fofc)l.mapData.sigma2=s,l.setOptionCls.setOption("map",t);else if("fofc"==t&&l.bAjaxfofc)l.mapData.sigma=s,l.setOptionCls.setOption("map",t);else{let i=await r.getXMLHttpRqstPromise(e,"GET","arraybuffer",t);o.parseChannels(i,t,s),"2fofc"==t||"fofc"==t?(l.bAjax2fofc=!0,l.bAjaxfofc=!0,l.setOptionCls.setOption("map",t)):"em"==t&&(l.bAjaxEm=!0,l.setOptionCls.setOption("emmap",t))}}parseChannels(e,t,s){let i=this.icn3d;i.icn3dui;let n=this.BinaryParse(e);if("2fofc"==t||"fofc"==t){let e=this.getChannel(n,"2FO-FC"),l=this.getChannel(n,"FO-FC"),r=e,o=r.box.sampleCount,a={xExtent:o[0],yExtent:o[1],zExtent:o[2],mean:r.valuesInfo.mean,sigma:r.valuesInfo.sigma};i.mapData.header2=a,i.mapData.data2=r.data;for(let e=0;e<r.data.length;++e)r.data[e];let d=r.box.origin,c=r.box.dimensions,h=r.spacegroup.basis,p=(new THREE.Matrix4).makeScale(c[0]/o[0],c[1]/o[1],c[2]/o[2]),m=(new THREE.Matrix4).makeTranslation(d[0],d[1],d[2]),u=(new THREE.Matrix4).set(h.x[0],h.y[0],h.z[0],0,0,h.y[1],h.z[1],0,0,0,h.z[2],0,0,0,0,1),g=u.multiply(m).multiply(p);i.mapData.matrix2=g,i.mapData.type2=t,i.mapData.sigma2=s,r=l,o=r.box.sampleCount,a={xExtent:o[0],yExtent:o[1],zExtent:o[2],mean:r.valuesInfo.mean,sigma:r.valuesInfo.sigma},i.mapData.header=a,i.mapData.data=r.data,d=r.box.origin,c=r.box.dimensions,h=r.spacegroup.basis,p=(new THREE.Matrix4).makeScale(c[0]/o[0],c[1]/o[1],c[2]/o[2]),m=(new THREE.Matrix4).makeTranslation(d[0],d[1],d[2]),u=(new THREE.Matrix4).set(h.x[0],h.y[0],h.z[0],0,0,h.y[1],h.z[1],0,0,0,h.z[2],0,0,0,0,1),g=u.multiply(m).multiply(p),i.mapData.matrix=g,i.mapData.type=t,i.mapData.sigma=s}else if("em"==t){let e=this.getChannel(n,"EM"),l=e.box.sampleCount,r={xExtent:l[0],yExtent:l[1],zExtent:l[2],max:e.valuesInfo.max,min:e.valuesInfo.min};i.mapData.headerEm=r,i.mapData.dataEm=e.data;let o=e.box.origin,a=e.box.dimensions,d=e.spacegroup.basis,c=(new THREE.Matrix4).makeScale(a[0]/l[0],a[1]/l[1],a[2]/l[2]),h=(new THREE.Matrix4).makeTranslation(o[0],o[1],o[2]),p=(new THREE.Matrix4).set(d.x[0],d.y[0],d.z[0],0,0,d.y[1],d.z[1],0,0,0,d.z[2],0,0,0,0,1).multiply(h).multiply(c);i.mapData.matrixEm=p,i.mapData.typeEm=t,i.mapData.sigmaEm=s}}getChannel(e,t){this.icn3d.icn3dui;let s,i=e.toJSON();for(let n=0,l=i.length;n<l;++n)i[n].id==t&&(s=e.dataBlocks[n]);return this.CIFParse(s)}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 s(e){let s=[0,0,0];for(let i=0;i<3;i++)s[i]=t.getColumn(e+"["+i+"]").getFloat(0);return s}function i(e){return t.getColumn(e).getFloat(0)}let n={name:t.getColumn("name").getString(0),axisOrder:s("axis_order"),origin:s("origin"),dimensions:s("dimensions"),sampleCount:s("sample_count"),spacegroupNumber:0|i("spacegroup_number"),cellSize:s("spacegroup_cell_size"),cellAngles:s("spacegroup_cell_angles"),mean:i("mean_sampled"),sigma:i("sigma_sampled")},l=[0,0,0];function r(e){return[e[l[0]],e[l[1]],e[l[2]]]}l[n.axisOrder[0]]=0,l[n.axisOrder[1]]=1,l[n.axisOrder[2]]=2;let o=r(n.sampleCount),a=function(e,t,s,i){let n=new Float32Array(t[0]*t[1]*t[2]),l=[0,0,0],r=i[0],o=i[1],a=i[2],d=s[0],c=s[1],h=s[2];t[0],t[0],t[1];let p=t[2],m=t[1]*t[2],u=0,g=e.getFloat(0),f=g;for(let t=0;t<h;t++){l[2]=t;for(let t=0;t<c;t++){l[1]=t;for(let t=0;t<d;t++){l[0]=t;let s=e.getFloat(u);u+=1,n[l[a]+l[o]*p+l[r]*m]=s,s<g?g=s:s>f&&(f=s)}}}return{data:n,min:g,max:f}}(e.getCategory("_volume_data_3d").getColumn("values"),o,n.sampleCount,l);return{name:n.name,spacegroup:function(e,t,s){let i=Math.PI/180*s[0],n=Math.PI/180*s[1],l=Math.PI/180*s[2],r=t[0],o=t[1],a=t[2],d=Math.cos(n),c=(Math.cos(i)-Math.cos(n)*Math.cos(l))/Math.sin(l),h=Math.sqrt(1-d*d-c*c);return{number:e,size:t,angles:s,basis:{x:[r,0,0],y:[Math.cos(l)*o,Math.sin(l)*o,0],z:[d*a,c*a,h*a]}}}(n.spacegroupNumber,n.cellSize,n.cellAngles),box:{origin:r(n.origin),dimensions:r(n.dimensions),sampleCount:o},data:a.data,valuesInfo:{min:a.min,max:a.max,mean:n.mean,sigma:n.sigma}}}BinaryParse(e){this.icn3d.icn3dui;let t=new Uint8Array(e),s=this.MessagePackParse({buffer:t,offset:0,dataView:new DataView(t.buffer)}),i=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 s=t[e];this.categoryMap.set(s.name,s)}}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,s=e.columns;t<s.length;t++){let e=s[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 s=this.encodedColumns.get(e);return s?p(s):t},e.prototype.toJSON=function(){let e=this,t=[],s=this.columnNameList.map((function(t){return{name:t,column:e.getColumn(t)}}));for(let e=0;e<this.rowCount;e++){let i={};for(let t=0,n=s;t<n.length;t++){let s=n[t],l=s.column.getValuePresence(e);i[s.name]=0===l?s.column.getString(e):1===l?".":"?"}t[e]=i}return{name:this.name,columns:this.columnNames,rows:t}},e}();function l(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 r(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),s=new Uint16Array(e);return t[0]=170,t[1]=187,48042===s[0]}();function a(e,t,s){return new s(o?e.buffer:function(e,t){let s=new ArrayBuffer(e.length),i=new Uint8Array(s);for(let s=0,n=e.length;s<n;s+=t)for(let n=0;n<t;n++)i[s+t-n-1]=e[s+n];return s}(e,t))}function d(e,t){return t.isUnsigned?function(e,t){let s=1===t.byteCount?255:65535,i=e.length,n=new Int32Array(t.srcSize),l=0,r=0;for(;l<i;){let t=0,i=e[l];for(;i===s;)t+=i,l++,i=e[l];t+=i,n[r]=t,l++,r++}return n}(e,t):function(e,t){let s=1===t.byteCount?127:32767,i=-s-1,n=e.length,l=new Int32Array(t.srcSize),r=0,o=0;for(;r<n;){let t=0,n=e[r];for(;n===s||n===i;)t+=n,r++,n=e[r];t+=n,l[o]=t,r++,o++}return l}(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 a(e,2,Int16Array)}(e);case 5:return function(e){return a(e,2,Uint16Array)}(e);case 3:return function(e){return a(e,4,Int32Array)}(e);case 6:return function(e){return a(e,4,Uint32Array)}(e);case 32:return function(e){return a(e,4,Float32Array)}(e);case 33:return function(e){return a(e,8,Float64Array)}(e);default:throw new Error("Unsupported ByteArray type.")}case"FixedPoint":return function(e,t){let s=e.length,i=r(t.srcType,s),n=1/t.factor;for(let t=0;t<s;t++)i[t]=n*e[t];return i}(e,t);case"IntervalQuantization":return function(e,t){let s=e.length,i=r(t.srcType,s),n=(t.max-t.min)/(t.numSteps-1),l=t.min;for(let t=0;t<s;t++)i[t]=l+n*e[t];return i}(e,t);case"RunLength":return function(e,t){let s=l(t.srcType,t.srcSize),i=0;for(let t=0,n=e.length;t<n;t+=2){let n=e[t],l=e[t+1];for(let e=0;e<l;++e)s[i++]=n}return s}(e,t);case"Delta":return function(e,t){let s=e.length,i=l(t.srcType,s);if(!s)return i;i[0]=e[0]+(0|t.origin);for(let t=1;t<s;++t)i[t]=e[t]+i[t-1];return i}(e,t);case"IntegerPacking":return d(e,t);case"StringArray":return function(e,t){let s=t.stringData,i=h({encoding:t.offsetEncoding,data:t.offsets}),n=h({encoding:t.dataEncoding,data:e}),l=Object.create(null),r=new Array(n.length),o=0;for(let e=0,t=n;e<t.length;e++){let n=t[e];if(n<0){r[o++]=null;continue}let a=l[n];void 0===a&&(a=s.substring(i[n],i[n+1]),l[n]=a),r[o++]=a}return r}(e,t)}}function h(e){let t=e.data;for(let s=e.encoding.length-1;s>=0;s--)t=c(t,e.encoding[s]);return t}function p(e){if(!e.data.data)return _UndefinedColumn;let t,s=h(e.data);return e.mask&&(t=h(e.mask)),s.buffer&&s.byteLength&&s.BYTES_PER_ELEMENT?t?new f(s,t):new g(s):t?new b(s,t):new C(s)}function m(e,t,s){let i=0,n=1;for(45===e.charCodeAt(t)&&(n=-1,t++);t<s;t++){let s=e.charCodeAt(t)-48;if(s>9||s<0)return n*i|0;i=10*i+s|0}return n*i}function u(e,t,s){let i=1,n=0,l=0,r=1;for(45===e.charCodeAt(t)&&(i=-1,++t);t<s;){let o=e.charCodeAt(t)-48;if(!(o>=0&&o<10)){if(-2===o){for(++t;t<s;){if(o=e.charCodeAt(t)-48,!(o>=0&&o<10))return 53===o||21===o?parseScientific(i*(n+l/r),e,t+1,s):i*(n+l/r);l=10*l+o,r*=10,++t}return i*(n+l/r)}if(53===o||21===o)return parseScientific(i*n,e,t+1,s);break}n=10*n+o,++t}return i*n}let g=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]===u(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}(),f=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]===u(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}(),C=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 m(t,0,t.length)},e.prototype.getFloat=function(e){let t=this.data[e];return u(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}(),b=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 m(t||"",0,(t||"").length)},e.prototype.getFloat=function(e){if(0!==this.mask[e])return 0;let t=this.data[e];return u(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}(),y=function(){function e(e){this.dataBlocks=e.dataBlocks.map((function(e){return new i(e)}))}return e.prototype.toJSON=function(){return this.dataBlocks.map((function(e){return e.toJSON()}))},e}();return new y(s)}MessagePackParse(e){this.icn3d.icn3dui;let t=this;function s(e,s){let i={};for(let n=0;n<s;n++){i[t.MessagePackParse(e)]=t.MessagePackParse(e)}return i}function i(e,t){let s=new Uint8Array(t),i=e.offset;for(let n=0;n<t;n++)s[n]=e.buffer[n+i];return e.offset+=t,s}function n(e,s){let i=new Array(s);for(let n=0;n<s;n++)i[n]=t.MessagePackParse(e);return i}function l(e,t){let s=function(e,t,s){let i,n=r,l=[],o=512,a=0;for(let r=t,d=t+s;r<d;r++){let t=e[r];0==(128&t)?l[a++]=n[t]:192==(224&t)?l[a++]=n[(15&t)<<6|63&e[++r]]:224==(240&t)?l[a++]=String.fromCharCode((15&t)<<12|(63&e[++r])<<6|(63&e[++r])<<0):240==(248&t)?l[a++]=String.fromCharCode((7&t)<<18|(63&e[++r])<<12|(63&e[++r])<<6|(63&e[++r])<<0):throwError("Invalid byte "+t.toString(16)),a===o&&(i=i||[],i[i.length]=l.join(""),a=0)}if(!i)return l.slice(0,a).join("");a>0&&(i[i.length]=l.slice(0,a).join(""));return i.join("")}(e.buffer,e.offset,t);return e.offset+=t,s}let r=function(){let e=[];for(let t=0;t<1024;t++)e[t]=String.fromCharCode(t);return e}();let o,a,d=e.buffer[e.offset];if(0==(128&d))return e.offset++,d;if(128==(240&d))return a=15&d,e.offset++,s(e,a);if(144==(240&d))return a=15&d,e.offset++,n(e,a);if(160==(224&d))return a=31&d,e.offset++,l(e,a);if(224==(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 a=e.dataView.getUint8(e.offset+1),e.offset+=2,i(e,a);case 197:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,i(e,a);case 198:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,i(e,a);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 a=e.dataView.getUint8(e.offset+1),e.offset+=2,l(e,a);case 218:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,l(e,a);case 219:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,l(e,a);case 220:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,n(e,a);case 221:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,n(e,a);case 222:return a=e.dataView.getUint16(e.offset+1),e.offset+=3,s(e,a);case 223:return a=e.dataView.getUint32(e.offset+1),e.offset+=5,s(e,a)}}}class rs{constructor(e){this.icn3d=e}alignCoords(e,t,s,i,n,l,r,o){let a,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,i=d.rmsd_suprTmp.trans2;if(a=d.rmsd_suprTmp.rmsd,a){c.htmlCls.clickMenuCls.setLogCmd("realignment RMSD: "+a.toPrecision(4),!1);let e="<br><b>Realignment RMSD</b>: "+a.toPrecision(4)+" &#8491;<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 r={};for(let n=0,l=d.structures[s].length;n<l;++n){let l=d.structures[s][n];if(!r.hasOwnProperty(l)){for(let s in d.chains[l]){let n=d.atoms[s];n.coord=d.surfaceCls.transformMemPro(n.coord,e,t,i)}r[l]=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,l);d.qt_start_end.push(h),p=d.hAtoms}return{hAtoms:p,rmsd:a}}getQtStartEndFromRealignResid(e,t){let s=this.icn3d;s.icn3dui,e.substr(0,e.indexOf("_")),t.substr(0,t.indexOf("_"));let i=[],n={};for(let t=0,i=s.chainsSeq[e].length;t<i;++t){n[s.chainsSeq[e][t].resi]=t+1}let l={};for(let e=0,i=s.chainsSeq[t].length;e<i;++e){l[s.chainsSeq[t][e].resi]=e+1}for(let r=0,o=s.realignResid[e].length;r<o&&r<s.realignResid[t].length;++r){let o=s.realignResid[e][r].resid;if(!o)continue;let a=o.lastIndexOf("_"),d=parseInt(o.substr(a+1)),c=s.realignResid[t][r].resid;if(!c)continue;let h=c.lastIndexOf("_"),p=parseInt(c.substr(h+1)),m=n[d],u=l[p];i.push({q_start:u,q_end:u,t_start:m,t_end:m})}return i}getMissingResidues(e,t,s){let i=this.icn3d,n=i.icn3dui;i.chainsSeq[s]=[];let l=0;if("mmdbid"===t||"align"===t)for(let t=0,s=e.length;t<s;++t)if(0!=e[t][0]){l=e[t][0]-(t+1);break}let r=l;for(let l=0,o=e.length;l<o;++l){let o,a;"mmdbid"===t?(o=e[l][1],a=0):"mmcifid"===t?(o=e[l][1],o=n.utilsCls.residueName2Abbr(o),a=0):"align"===t&&(o=e[l][1],a=0),""===o&&(o="x");let d={};i.bUsePdbNum?d.resi="0"==e[l][a]?parseInt(r)+1:e[l][a]:d.resi=l+1,d.name="align"===t?o.toLowerCase():o,i.chainsSeq[s].push(d),r=d.resi}}async set2DDiagramsForAlign(e,t){let s=this.icn3d,i=s.icn3dui;i.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions");let n=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+e+"&intrac=1",l=i.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+t+"&intrac=1";void 0!==i.cfg.inpara&&(n+=i.cfg.inpara,l+=i.cfg.inpara);let r=i.getAjaxPromise(n,"jsonp"),o=i.getAjaxPromise(l,"jsonp"),a=Promise.allSettled([r,o]),d=await a;s.interactionData1=d[0].value,s.html2ddgm="",s.diagram2dCls.draw2Ddgm(s.interactionData1,e,0),i.cfg.show2d&&i.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions"),s.interactionData2=d[1].value,s.diagram2dCls.draw2Ddgm(s.interactionData2,t,1),s.html2ddgm+="<br>"+s.diagram2dCls.set2DdgmNote(!0),$("#"+s.pre+"dl_2ddgm_html").html(s.html2ddgm),s.b2DShown=!0}async set2DDiagramsForChainalign(e){let t=this.icn3d.icn3dui,s=this;t.htmlCls.dialogCls.openDlg("dl_2ddgm","Interactions");let i=[];for(let s=0,n=e.length;s<n;++s){let n=e[s].indexOf("_"),l=e[s].substr(0,n).toUpperCase(),r=t.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&uid="+l+"&intrac=1";void 0!==t.cfg.inpara&&(r+=t.cfg.inpara);let o=t.getAjaxPromise(r,"jsonp");i.push(o)}let n=Promise.allSettled(i);try{let t=await n;s.parse2DDiagramsData(t,e)}catch(e){}}parse2DDiagramsData(e,t){let s=this.icn3d,i=s.icn3dui;s.html2ddgm="";for(let i=0,n=t.length;i<n;++i){let n=e[i].value,l=t[i].substr(0,t[i].indexOf("_"));s.diagram2dCls.draw2Ddgm(n,l,0)}s.html2ddgm+="<br>"+s.diagram2dCls.set2DdgmNote(!0),s.b2DShown=!0,$("#"+s.pre+"dl_2ddgm_html").html(s.html2ddgm),i.cfg.show2d&&i.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,s=t.icn3dui;t.yournote=e,$("#"+t.pre+"yournote").val(t.yournote),s.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 s=t.rmsd_supr.rot,i=t.rmsd_supr.trans1,n=t.rmsd_supr.trans2;t.rmsd_supr.rmsd;let l=0;for(let e in t.atoms){let r=t.atoms[e];r.coord=t.surfaceCls.transformMemPro(r.coord,s,i,n);let o=r.coord.x*r.coord.x+r.coord.y*r.coord.y;Math.abs(r.coord.z)<=25&&o>l&&(l=o)}this.addMemAtoms(t.halfBilayerSize,e,Math.sqrt(l)),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,s){let i=this.icn3d,n=i.icn3dui;if(void 0!==t){let l=i.loadPDBCls.getChainCalpha(i.chains,i.atoms,s,e),r=1==Object.keys(l.chainresiCalphaHash).length||1==Object.keys(t.chainresiCalphaHash).length,o=[],a=[];for(let e in l.chainresiCalphaHash)if(t.chainresiCalphaHash.hasOwnProperty(e)){let s=l.chainresiCalphaHash[e],i=t.chainresiCalphaHash[e];if((s.length==i.length||r)&&(o=o.concat(s),a=a.concat(i)),o.length>500)break}let d=o.length<a.length?o.length:a.length;if(d>=4)if(i.rmsd_supr=n.rmsdSuprCls.getRmsdSuprCls(o,a,d),void 0!==i.rmsd_supr.rot&&i.rmsd_supr.rmsd<.1){let s=i.rmsd_supr.rot,l=i.rmsd_supr.trans1,r=i.rmsd_supr.trans2,o=i.rmsd_supr.rmsd;n.htmlCls.clickMenuCls.setLogCmd("RMSD of alignment to OPM: "+o.toPrecision(4),!1);let a=0;for(let e in i.atoms){let t=i.atoms[e];t.coord=i.surfaceCls.transformMemPro(t.coord,s,l,r);let n=t.coord.x*t.coord.x+t.coord.y*t.coord.y;Math.abs(t.coord.z)<=25&&n>a&&(a=n)}i.center=t.center,i.oriCenter=i.center.clone(),this.addMemAtoms(i.halfBilayerSize,e,Math.sqrt(a)),i.bStopRotate=!0,i.bOpm=!0,$("#"+i.pre+"togglememli").show(),$("#"+i.pre+"adjustmemli").show(),$("#"+i.pre+"selectplaneli").show()}else i.bOpm=!1;else i.bOpm=!1}}addOneDumAtom(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a={het:!0,serial:++l,name:t,alt:void 0,resn:"DUM",structure:e,chain:"MEM",resi:1,coord:new THREE.Vector3(s,i,n),b:void 0,elem:t,bonds:[],ss:"",ssbegin:!1,ssend:!1,color:o.parasCls.atomColors[t]};return r.atoms[l]=a,r.chains[e+"_MEM"][l]=1,r.residues[e+"_MEM_1"][l]=1,r.chemicals[l]=1,r.dAtoms[l]=1,r.hAtoms[l]=1,l}addMemAtoms(e,t,s){let i=this.icn3d;if(i.icn3dui,!t)return;t=t?t.toUpperCase():i.defaultPdbId,i.structures[t].push(t+"_MEM"),i.chains[t+"_MEM"]={},i.residues[t+"_MEM_1"]={},i.chainsSeq[t+"_MEM"]=[{name:"DUM",resi:1}];let n=Object.keys(i.atoms).length;for(let e=0;e<1e3;++e)if(!i.atoms.hasOwnProperty(n+e)){n=n+e-1;break}for(let i=0;i<81;++i)for(let l=0;l<81;++l){let r=2*i-80,o=2*l-80;if(Math.sqrt(r*r+o*o)<s){let s=-e-.4;n=this.addOneDumAtom(t,"N",r,o,s,n),s=e+.4,n=this.addOneDumAtom(t,"O",r,o,s,n)}}}setMaxD(){let e=this.icn3d;e.icn3dui;let t=new THREE.Vector3(9999,9999,9999),s=new THREE.Vector3(-9999,-9999,-9999),i=new THREE.Vector3,n=0;for(let l in e.atoms){let r=e.atoms[l],o=r.coord;i.add(o),t.min(o),s.max(o),++n,r.het&&(0==r.bonds.length?e.ions[r.serial]=1:e.chemicals[r.serial]=1)}e.pmin=t,e.pmax=s,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 s=e.selectedPdbid+"_MEM_1";for(let i in e.residues[s]){let s=e.atoms[i];s.style="stick",s.color=t.parasCls.atomColors[s.name],e.atomPrevColors[i]=s.color,e.dAtoms[i]=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 THREE.Vector3(1,0,0),s=-.5*Math.PI;e.transformCls.setRotation(t,s)}$("#"+e.pre+"alternate").show()}else e.selectionCls.saveSelectionIfSelected(),e.drawCls.draw();if(e.bInitial){if(t.cfg.mobilemenu){t.htmlCls.shownMenus=t.hashUtilsCls.cloneHash(t.htmlCls.simpleMenus);let e=!0;t.htmlCls.clickMenuCls.applyShownMenus(e)}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 s=e.pre+"selection";if($("#"+s).show(),$("#"+s+"_expand").hide(),$("#"+s+"_shrink").show(),void 0!==t.cfg.align&&2!=t.cfg.atype){let s=!1,i=t.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(e.alnChains),void 0,void 0,s);$("#"+e.pre+"dl_sequence2").html(i.sequencesHtml),$("#"+e.pre+"dl_sequence2").width(t.htmlCls.RESIDUE_WIDTH*i.maxSeqCnt+200)}}if(t.cfg.showanno){let s="view annotations";t.htmlCls.clickMenuCls.setLogCmd(s,!0),await e.showAnnoCls.showAnnotations()}(t.cfg.closepopup||t.cfg.imageonly)&&e.resizeCanvasCls.closeDialogs()}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 s=Object.keys(e.structures)[0];t.cfg.command=t.cfg.command.replace(new RegExp("!","g"),s+"_")}}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,s,i){let n=this.icn3d;n.icn3dui;let l=0;for(let r in e){let e=n.atoms[r].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(s.x)==Math.round(e.x)||Math.round(s.y)==Math.round(e.y)||Math.round(s.z)==Math.round(e.z)){let t=2*e.distanceTo(i);t>l&&(l=t)}}return l}async checkMemProteinAndRotate(){let e=this.icn3d,t=e.icn3dui;if(!e.bCheckMemProtein){e.bCheckMemProtein=!0;let s=t.cfg.afid?t.cfg.afid:t.cfg.mmdbafid;if(await e.ParserUtilsCls.checkMemProtein(s),t.cfg.url&&-1!=t.cfg.url.indexOf("membranome")){let t=new THREE.Vector3(1,0,0),s=-.5*Math.PI;e.transformCls.setRotation(t,s)}}}async checkMemProtein(e){let t=this.icn3d,s=t.icn3dui;try{let i=s.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?afid2mem="+e,n=await s.getAjaxPromise(i,"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(s.bNode)return;if("off"==s.cfg.afmem);else if("on"==s.cfg.afmem||confirm(e))try{let e="https://storage.googleapis.com/membranome-assets/pdb_files/proteins/"+n.pdbid+".pdb",i=await s.getAjaxPromise(e,"text");t.bAfMem=!0,s.bNode||$("#"+s.pre+"togglememli").show();let l=n.pdbid.substr(0,n.pdbid.indexOf("_")),r=!0,o=!0;await t.pdbParserCls.loadPdbData(i,l,r,o),o&&(t.bSetChainsAdvancedMenu&&t.definedSetsCls.showSets(),t.bAnnoShown&&(await t.showAnnoCls.showAnnotations(),t.annotationCls.resetAnnoTabAll()));let a=n.segment.replace(/ /gi,"").split("(")[0];t.afmem_start_end=a.split("-"),t.hAtoms={},t.dAtoms={};for(let e in t.atoms)t.atoms[e].structure!=l&&(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=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[l+"_A_"+e]);await t.realignParserCls.realignOnSeqAlign(l)}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 s=this.icn3d;s.icn3dui;let i=s.ncbi2resid[e+"_"+(t+1).toString()];return i?i.substr(i.lastIndexOf("_")+1):""}getResiNCBI(e,t){let s=this.icn3d;s.icn3dui;let i=s.resid2ncbi[e+"_"+t];return i?parseInt(i.substr(i.lastIndexOf("_")+1)):0}}class os{constructor(e){this.icn3d=e}loadAtomDataIn(e,t,s,i,n,l,r,o,a){let d=this.icn3d,c=d.icn3dui;d.pmin=new THREE.Vector3(9999,9999,9999),d.pmax=new THREE.Vector3(-9999,-9999,-9999),d.psum=new THREE.Vector3;let h=e.atoms,p=d.atoms?Object.keys(d.atoms).length:0,m={},u={};d.pmid=e.pubmedId,void 0===d.chainid2title&&(d.chainid2title={}),void 0===d.chainid2sid&&(d.chainid2sid={});let g={},f={};if("align"===s){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 s=0,i=e.alignedStructures[0].length;s<i;++s){let i=e.alignedStructures[0][s];1===s&&(d.secondId=i.pdbId);let n=i.pdbId,l=i.mmdbId;for(let e=i.serialInterval[0],t=i.serialInterval[1];e<=t;++e)m[e]=n.toString(),u[l]=n;for(let e=0,t=i.molecules.length;e<t;++e){let t=i.molecules[e].chain;t=t.replace(/_/g,"");let s=i.molecules[e].kind,l=i.molecules[e].name,r=i.molecules[e].sid,o=n+"_"+t;g[o]=s,d.chainid2title[o]=l,void 0!==r&&(d.chainid2sid[o]=r)}d.molTitle+='<a href="'+c.htmlCls.baseUrl+"mmdb/mmdbsrv.cgi?uid="+i.pdbId.toUpperCase()+'" target="_blank">'+i.pdbId.toUpperCase()+"</a>",void 0!==i.descr&&(d.pmid+=i.descr.pubmedid),0===s&&(d.molTitle+=" and ",void 0!==i.descr&&(d.pmid+="_")),t=!0}d.molTitle+=" from VAST+",t||(d.molTitle="")}else if(void 0!==e.descr&&(d.molTitle=e.descr.name),"mmdbid"===s){let s=isNaN(t)?t:e.pdbId,i={};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 l=e.moleculeInfor[t].chain.trim();l=l.replace(/_/g,"");let r=s+"_"+l;i.hasOwnProperty(l)?(++i[l],r+=i[l]):i[l]=1,void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t);let o=e.moleculeInfor[t].kind,a=e.moleculeInfor[t].color,c=e.moleculeInfor[t].sid;if(g[r]=o,f[r]=a,"protein"==o&&(d.organism=e.moleculeInfor[t].taxonomyName.toLowerCase()),void 0!==c&&(d.chainid2sid[r]=c),void 0===d.pdbid_chain2title&&(d.pdbid_chain2title={}),d.pdbid_chain2title[r]=e.moleculeInfor[t].name,l==r.substr(r.lastIndexOf("_"))){let e={};e[t]=n.toString(),d.alignmolid2color.push(e)}++n}}"mmdbid"===s&&(d.molTitleHash||(d.molTitleHash={}),d.molTitleHash[t]=d.molTitle);let C,b,y,v,_,w={},S="",A="",x="",k="",O="",R="",I=0,E=0,T="",P=!0,D=!1,M="",F=c.utilsCls.isCalphaPhosOnly(h),H=0,L={};for(let e in h){++p,w[e]=p;let i,n=h[e];n.serial=p,"mmdbid"===s||"mmcifid"===s?i=t:"align"===s&&(i=m[p]);let l=!1;if(void 0!==n.chain||"mmdbid"!==s&&"align"!==s)n.chain=""===n.chain?"Misc":n.chain;else if("mmdbid"===s)if(C=n.ids.m,void 0!==d.molid2chain[C]){let e=d.molid2chain[C].indexOf("_");n.chain=d.molid2chain[C].substr(e+1)}else{let e="Misc";("protein"===g[O]&&"nucleotide"===g[O]&&n.resi!=E||"protein"!==g[O]&&"nucleotide"!==g[O]&&(n.resn.substr(0,3)!=T.substr(0,3)||n.resi!=E||"solvent"===g[O]||"HOH"===n.resn))&&++H,n.resi_ori=n.resi,n.resi=H,l=!0,n.chain=e}else if("align"===s)if(C=n.ids.m,void 0!==d.pdbid_molid2chain[i+"_"+C])n.chain=d.pdbid_molid2chain[i+"_"+C];else{let e="Misc";("protein"===g[O]&&"nucleotide"===g[O]&&n.resi!=E||"protein"!==g[O]&&"nucleotide"!==g[O]&&(n.resn.substr(0,3)!=T.substr(0,3)||n.resi!=E||"solvent"===g[O]||"HOH"===n.resn))&&(++H,n.resi_ori=n.resi,n.resi=H,l=!0),n.chain=e}if(n.chain=n.chain.trim(),n.chain=n.chain.replace(/_/g,""),"mmdbid"!==s&&"align"!==s||(n.structure=i,"mmdbid"===s&&void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t)),k=n.structure,O=k+"_"+n.chain,"mmdbid"===s||"align"===s){l||(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))}O!==A&&(I=0),n.resi!==I&&(O!==A?(y=void 0,_=void 0):(y=b,_=v)),n.coord="mmdbid"===s?new THREE.Vector3(n.coord[0],n.coord[1],n.coord[2]):new THREE.Vector3(n.coord.x,n.coord.y,n.coord.z);let r=c.utilsCls.residueName2Abbr(n.resn.substr(0,3));"mmdbid"!==s&&"align"!==s||!d.bFullUi||(void 0===d.mmdbMolidResid2mmdbChainResi&&(d.mmdbMolidResid2mmdbChainResi={}),d.mmdbMolidResid2mmdbChainResi[i+"_"+n.ids.m+"_"+n.ids.r]=i+"_"+n.chain+"_"+n.resi),d.pmin.min(n.coord),d.pmax.max(n.coord),d.psum.add(n.coord);let o="protein"===g[O],a="nucleotide"===g[O],u="solvent"===g[O],N="ligand"===g[O]||void 0!==g[O]&&-1!==g[O].indexOf("other")||void 0===g[O];if("Misc"!==n.chain&&"other"!==g[O]||"protein"===L[O]||"nucleotide"===L[O]||("CA"===n.name&&"C"===n.elem?L[O]="protein":"P"===n.name&&"P"===n.elem?L[O]="nucleotide":L[O]="chemical"),o||a?(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)):a&&(d.nucleotides[p]=1,("O3'"==n.name||"O3*"==n.name||F&&"P"==n.name)&&(d.nucleotidesO3[p]=1),-1===c.parasCls.nuclMainArray.indexOf(n.name)&&(d.ntbase[p]=1)),n.het=!1):u?(d.water[p]=1,n.het=!0):N&&("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"===s?n.het?n.color=c.parasCls.atomColors[n.elem]||c.parasCls.defaultAtomColor:n.color=void 0!==f[O]?c.parasCls.thr(f[O]):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||(b=p),n.het||"O"!==n.name||(v=p),!n.het&&"N"===n.name&&void 0!==y&&void 0!==_){let e=d.atoms[y].coord.distanceTo(d.atoms[_].coord),t=n.coord.x+(d.atoms[y].coord.x-d.atoms[_].coord.x)/e,s=n.coord.y+(d.atoms[y].coord.y-d.atoms[_].coord.y)/e,i=n.coord.z+(d.atoms[y].coord.z-d.atoms[_].coord.z)/e;n.hcoord=new THREE.Vector3(t,s,i)}"HOH"==n.resn&&(d.water[p]=1),d.atoms[p]=n,d.dAtoms[p]=1,d.hAtoms[p]=1;let q=n.structure+"_"+n.chain;void 0===d.chains[q]&&(d.chains[q]={}),d.chains[q][p]=1;let U=q+"_"+n.resi;void 0===d.residues[U]&&(d.residues[U]={}),d.residues[U][p]=1,R=O+"_"+n.resi,R!==x&&O!==A&&(P=!0,""!==S&&(void 0===d.structures[S]&&(d.structures[S]=[]),d.structures[S].push(A))),d.residueId2Name[U]=r;let $="-";if("helix"===n.ss?$="H":"sheet"===n.ss?$="E":n.het||a?$="o":(!n.het&&c.parasCls.residueColors.hasOwnProperty(n.resn.toUpperCase())||"coil"===n.ss)&&($="c"),d.secondaries[n.structure+"_"+n.chain+"_"+n.resi]=$,(n.resi!=I||C!=M)&&d.bFullUi&&(void 0===d.chainsSeq[q]&&(d.chainsSeq[q]=[],P=!1),!isNaN(n.resi)&&null!==n.resi))if(P&&!D&&void 0!==d.chainsSeq[q][n.resi-1])d.chainsSeq[q][n.resi-1].name=r;else if(!P||!d.chainsSeq[q].hasOwnProperty(n.resi-1)){let e={};e.resi=n.resi,e.name=r,n.resi%10==0&&n.resi.toString(),d.chainsSeq[q].push(e),D=!0}I=n.resi,E=n.resi_ori,T=n.resn,S=k,A=O,x=R,M=C}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 L)if(!(Object.keys(d.chains[e]).length<10)&&"chemical"!==L[e])for(let t in d.chains[e]){let s=d.atoms[t];delete d.chemicals[t],s.het=!1,"protein"===L[e]?(d.proteins[t]=1,"CA"===s.name&&(d.calphas[t]=1),"N"!==s.name&&"H"!==s.name&&"CA"!==s.name&&"HA"!==s.name&&"C"!==s.name&&"O"!==s.name&&(d.sidec[t]=1)):"nucleotide"===L[e]&&(d.nucleotides[t]=1,("O3'"==s.name||"O3*"==s.name||F&&"P"==s.name)&&(d.nucleotidesO3[t]=1),-1===c.parasCls.nuclMainArray.indexOf(s.name)&&(d.ntbase[t]=1))}if(void 0===d.structures[k]&&(d.structures[k]=[]),d.structures[k].push(O),d.bFullUi)if("mmdbid"===s||"mmcifid"===s)for(let i in e.sequences){let n=e.sequences[i],l=t+"_"+i;void 0!==d.mmdbid_q&&(d.mmdbid_q,d.mmdbid_t),d.ParserUtilsCls.getMissingResidues(n,s,l)}else if("align"===s)for(let e in d.chainid2seq){let t=d.chainid2seq[e];d.ParserUtilsCls.getMissingResidues(t,s,e)}if(d.loadPDBCls.setResidMapping(),"mmcifid"!==s)for(let e in h){let t=w[e],s=void 0===d.atoms[t].bonds?0:d.atoms[t].bonds.length;for(let e=0;e<s;++e)d.atoms[t].bonds[e]=w[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"===s||o)&&(d.ssbondpnts={},d.loadPDBCls.setSsbond()),"mmdbid"===s&&1==Object.keys(d.structures).length){let t=e.disulfides;if(void 0!==t)for(let e=0,s=t.length;e<s;++e){let s=t[e][0].ca,i=t[e][1].ca,n=d.atoms[s],l=d.atoms[i],r=n.chain,o=l.chain,a=n.structure+"_"+r+"_"+n.resi,c=l.structure+"_"+o+"_"+l.resi;void 0===d.ssbondpnts[n.structure]&&(d.ssbondpnts[n.structure]=[]),d.ssbondpnts[n.structure].push(a),d.ssbondpnts[n.structure].push(c)}}else if("mmcifid"===s&&1==Object.keys(d.structures).length){let s=e.disulfides;if(void 0!==s){void 0===d.ssbondpnts[t]&&(d.ssbondpnts[t]=[]);for(let e=0,i=s.length;e<i;++e){let i=s[e][0],n=s[e][1];d.ssbondpnts[t].push(i),d.ssbondpnts[t].push(n)}let e=Object.keys(d.structures);for(let s=0,i=e.length;s<i;++s){let i=e[s];if(i!=t){void 0===d.ssbondpnts[i]&&(d.ssbondpnts[i]=[]);for(let e=0,s=d.ssbondpnts[t].length;e<s;++e){let s=d.ssbondpnts[t][e],n=s.indexOf("_"),l=i+s.substr(n);d.ssbondpnts[i].push(l)}}}}}("mmcifid"===s||"mmdbid"===s&&void 0===n)&&d.ParserUtilsCls.transformToOpmOri(t);let N={};if("align"===s&&void 0!==i&&d.bFullUi)d.setSeqAlignCls.setSeqAlign(i,e.alignedStructures);else if("mmdbid"!==s||"query"!==n||!d.bFullUi||void 0===d.q_rotation||c.cfg.resnum||c.cfg.resdef||a)N=d.hAtoms;else if(r){d.setSeqAlignCls.setSeqAlignChain(l,r);let e=!1,t=c.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(d.alnChains),void 0,void 0,!1,void 0,e),s=$("#"+d.pre+"dl_sequence2").html();N=d.hAtoms,$("#"+d.pre+"dl_sequence2").html(s+t.sequencesHtml),$("#"+d.pre+"dl_sequence2").width(c.htmlCls.RESIDUE_WIDTH*t.maxSeqCnt+200)}else N=d.hAtoms;if(!c.cfg.mmdbafid&&"mmdbid"===s&&("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 THREE.Vector3(0,0,0))}return d.oriCenter=d.center.clone(),d.saveFileCls.showTitle(),e={},N}}class as{constructor(e){this.icn3d=e}setSeqAlign(e,t){let s=this.icn3d,i=s.icn3dui,n=t[0][0].pdbId,l=t[0][1].pdbId;s.conservedName1=n+"_cons",s.nonConservedName1=n+"_ncons",s.notAlignedName1=n+"_nalign",s.conservedName2=l+"_cons",s.nonConservedName2=l+"_ncons",s.notAlignedName2=l+"_nalign",s.consHash1={},s.nconsHash1={},s.nalignHash1={},s.consHash2={},s.nconsHash2={},s.nalignHash2={};for(let t=0,r=e.length;t<r;++t){let r=e[t][0],o=r.moleculeId,a=s.pdbid_molid2chain[n+"_"+o],d=n+"_"+a,c={},h=r.sequence.length,p=-1,m=!1;for(let e=0,t=r.sequence.length;e<t;++e){let t=s.bUsePdbNum?s.ParserUtilsCls.getResi(d,r.sequence[e][0]-1):r.sequence[e][0],i="~"===r.sequence[e][2]?"-":r.sequence[e][2];i=" "===i||""===i?"X":i;let n=r.sequence[e][3]?1:0;1==n&&(e<h&&!m&&(h=e,m=!0),e>p&&(p=e)),c[e]={resi:t,resn:i,aligned:n}}r=e[t][1];let u=r.moleculeId,g=s.pdbid_molid2chain[l+"_"+u],f=l+"_"+g;void 0===s.alnChainsAnTtl[d]&&(s.alnChainsAnTtl[d]=[]),void 0===s.alnChainsAnTtl[d][0]&&(s.alnChainsAnTtl[d][0]=[]),void 0===s.alnChainsAnTtl[d][1]&&(s.alnChainsAnTtl[d][1]=[]),void 0===s.alnChainsAnTtl[d][2]&&(s.alnChainsAnTtl[d][2]=[]),void 0===s.alnChainsAnTtl[d][3]&&(s.alnChainsAnTtl[d][3]=[]),void 0===s.alnChainsAnTtl[d][4]&&(s.alnChainsAnTtl[d][4]=[]),void 0===s.alnChainsAnTtl[d][5]&&(s.alnChainsAnTtl[d][5]=[]),void 0===s.alnChainsAnTtl[d][6]&&(s.alnChainsAnTtl[d][6]=[]),s.alnChainsAnTtl[d][0].push(f),s.alnChainsAnTtl[d][1].push(d),s.alnChainsAnTtl[d][2].push(""),s.alnChainsAnTtl[d][3].push(""),s.alnChainsAnTtl[d][4].push(f),s.alnChainsAnTtl[d][5].push(d),s.alnChainsAnTtl[d][6].push("");let C=1;s.chainsMapping[d]||(s.chainsMapping[d]={}),s.chainsMapping[f]||(s.chainsMapping[f]={});for(let e=h;e<=p;++e){let t,o,p,m=s.bUsePdbNum?s.ParserUtilsCls.getResi(f,r.sequence[e][0]-1):r.sequence[e][0],u="~"===r.sequence[e][2]?"-":r.sequence[e][2],b=r.sequence[e][3]?1:0,y=c[e].aligned+b;2===y?(c[e].resn===u?(t="#FF0000",p="icn3d-cons",s.consHash1[d+"_"+c[e].resi]=1,s.consHash2[f+"_"+m]=1):(t="#0000FF",p="icn3d-ncons",s.nconsHash1[d+"_"+c[e].resi]=1,s.nconsHash2[f+"_"+m]=1),s.chainsMapping[d][d+"_"+c[e].resi]=c[e].resn+c[e].resi,s.chainsMapping[f][f+"_"+m]=c[e].resn+c[e].resi,o="#"+s.showAnnoCls.getColorhexFromBlosum62(c[e].resn,u)):(t=i.htmlCls.GREY8,p="icn3d-nalign",s.nalignHash1[d+"_"+c[e].resi]=1,s.nalignHash2[f+"_"+m]=1),void 0===s.alnChainsSeq[d]&&(s.alnChainsSeq[d]=[]);let v={};v.mmdbid=n,v.chain=a,v.resi=c[e].resi,v.resn=""===v.resi||"icn3d-nalign"===p?c[e].resn.toLowerCase():c[e].resn,v.aligned=y,v.color=""===v.resi?i.htmlCls.GREYC:t,v.color2=""===v.resi?i.htmlCls.GREYC:o,v.class=p,s.alnChainsSeq[d].push(v),""!==c[e].resi&&(void 0===s.alnChains[d]&&(s.alnChains[d]={}),$.extend(s.alnChains[d],s.residues[d+"_"+c[e].resi])),void 0===s.alnChainsSeq[f]&&(s.alnChainsSeq[f]=[]),v={},v.mmdbid=l,v.chain=g,v.resi=m,v.resn=""===v.resi||"icn3d-nalign"===p?u.toLowerCase():u,v.aligned=y,v.color=""===v.resi?i.htmlCls.GREYC:t,v.color2=""===v.resi?i.htmlCls.GREYC:o,v.class=p,s.alnChainsSeq[f].push(v),""!==v.resi&&(void 0===s.alnChains[f]&&(s.alnChains[f]={}),$.extend(s.alnChains[f],s.residues[f+"_"+m])),void 0===s.alnChainsAnno[d]&&(s.alnChainsAnno[d]=[]),void 0===s.alnChainsAnno[d][0]&&(s.alnChainsAnno[d][0]=[]),void 0===s.alnChainsAnno[d][1]&&(s.alnChainsAnno[d][1]=[]),void 0===s.alnChainsAnno[d][2]&&(s.alnChainsAnno[d][2]=[]),void 0===s.alnChainsAnno[d][3]&&(s.alnChainsAnno[d][3]=[]),e===h&&(void 0===s.alnChainsAnno[d][4]&&(s.alnChainsAnno[d][4]=[]),void 0===s.alnChainsAnno[d][5]&&(s.alnChainsAnno[d][5]=[]),void 0===s.alnChainsAnno[d][6]&&(s.alnChainsAnno[d][6]=[]),s.alnChainsAnno[d][4].push(s.pdbid_chain2title[f]),s.alnChainsAnno[d][5].push(s.pdbid_chain2title[d]),s.alnChainsAnno[d][6].push(""));let _=d+"_"+c[e].resi,w=f+"_"+m,S=s.secondaries[_],A=s.secondaries[w];A?s.alnChainsAnno[d][0].push(A):s.alnChainsAnno[d][0].push("-"),S?s.alnChainsAnno[d][1].push(S):s.alnChainsAnno[d][1].push("-");let x=".";C%5==0&&(x="*"),C%10==0&&(x="|"),s.alnChainsAnno[d][2].push(x);let k="";C%10==0&&(k=C.toString()),s.alnChainsAnno[d][3].push(k),++C}}e={}}getPosFromResi(e,t){let s=this.icn3d;s.icn3dui;let i,n=s.resid2ncbi[e+"_"+t];if(n){i=n.substr(n.lastIndexOf("_")+1)-1}return i}getResnFromResi(e,t){let s=this.icn3d;s.icn3dui;let i=e+"_"+t,n=s.residueId2Name[i];return n||(n="?"),n}getResiAferAlign(e,t,s){let i,n=this.icn3d,l=n.icn3dui;return t&&"tmalign"==l.cfg.aligntool?i=s:(s>n.chainsSeq[e].length-1&&(console.log("Error: the position "+s+" exceeds the max index "+(n.chainsSeq[e].length-1)),s=n.chainsSeq[e].length-1),i=n.chainsSeq[e][s].resi),i}setSeqAlignChain(e,t,s){let i,n,l,r,o,a,d,c,h,p,m,u=this.icn3d,g=u.icn3dui,f={},C=!!s;if(C){if(o=s[1],a=s[0],t=s[2],d=o.indexOf("_"),c=a.indexOf("_"),i=o.substr(0,d).toUpperCase(),n=a.substr(0,c).toUpperCase(),l=o.substr(d+1),r=a.substr(d+1),i==n&&l==r){let e=u.chainsSeq[n+"_"+r].length;u.qt_start_end[t]={q_start:1,q_end:e,t_start:1,t_end:e}}}else{let d=s[0].indexOf("_"),c=e.indexOf("_");if(i=u.mmdbid_t,n=e.substr(0,c).toUpperCase(),l=s[0].substr(d+1),r=e.substr(c+1),i==n&&l==r){let e=u.chainsSeq[u.mmdbid_q+"_"+u.chain_q].length;u.qt_start_end[t]={q_start:1,q_end:e,t_start:1,t_end:e}}o=i+"_"+l,a=n+"_"+r,void 0!==n&&u.mmdbid_t}u.conservedName1=o+"_cons",u.nonConservedName1=o+"_ncons",u.notAlignedName1=o+"_nalign",u.conservedName2=a+"_cons",u.nonConservedName2=a+"_ncons",u.notAlignedName2=a+"_nalign",u.consHash1={},u.nconsHash1={},u.nalignHash1={},u.consHash2={},u.nconsHash2={},u.nalignHash2={},u.alnChains={},u.alnChainsSeq[o]=[],u.alnChains[o]={},u.alnChainsSeq[a]=[],u.alnChains[a]={},u.alnChainsAnno[o]=[],u.alnChainsAnTtl[o]=[],void 0===u.alnChainsAnTtl[o]&&(u.alnChainsAnTtl[o]=[]);for(let e=0;e<7;++e)void 0===u.alnChainsAnTtl[o][e]&&(u.alnChainsAnTtl[o][e]=[]);u.alnChainsAnTtl[o][0].push(a),u.alnChainsAnTtl[o][1].push(o),u.alnChainsAnTtl[o][2].push(""),u.alnChainsAnTtl[o][3].push(""),u.alnChainsAnTtl[o][4].push(a),u.alnChainsAnTtl[o][5].push(o),u.alnChainsAnTtl[o][6].push("");let b=0,y=0;if(void 0===u.qt_start_end[t])return;let v=1;u.chainsMapping[o]||(u.chainsMapping[o]={}),u.chainsMapping[a]||(u.chainsMapping[a]={});let _={},w={};for(let e=0,s=u.qt_start_end[t].length;e<s;++e){let s,i,n,l;C&&"tmalign"==g.cfg.aligntool?(s=parseInt(u.qt_start_end[t][e].t_start),i=parseInt(u.qt_start_end[t][e].q_start),n=parseInt(u.qt_start_end[t][e].t_end),l=parseInt(u.qt_start_end[t][e].q_end)):(s=parseInt(u.qt_start_end[t][e].t_start-1),i=parseInt(u.qt_start_end[t][e].q_start-1),n=parseInt(u.qt_start_end[t][e].t_end-1),l=parseInt(u.qt_start_end[t][e].q_end-1)),_[s]=1,_[n]=1,w[i]=1,w[l]=1}for(let e=0,s=u.qt_start_end[t].length;e<s;++e){let s,i,n,l;if(C&&"tmalign"==g.cfg.aligntool?(s=parseInt(u.qt_start_end[t][e].t_start),i=parseInt(u.qt_start_end[t][e].q_start),n=parseInt(u.qt_start_end[t][e].t_end),l=parseInt(u.qt_start_end[t][e].q_end)):(s=parseInt(u.qt_start_end[t][e].t_start-1),i=parseInt(u.qt_start_end[t][e].q_start-1),n=parseInt(u.qt_start_end[t][e].t_end-1),l=parseInt(u.qt_start_end[t][e].q_end-1)),e>0){let e=v;for(let t=b+1,i=s;t<i;++t){_[t]=1;let s=this.getResiAferAlign(o,C,t),i=this.getResnFromResi(o,s).toLowerCase();"?"!=i&&(h=g.htmlCls.GREY8,m="icn3d-nalign",u.nalignHash1[o+"_"+s]=1,this.setSeqPerResi(o,o,a,s,i,!1,h,void 0,m,!0,!1,e),++e)}let t=v;for(let e=y+1,s=i;e<s;++e){w[e]=1;let s=this.getResiAferAlign(a,C,e),i=this.getResnFromResi(a,s).toLowerCase();"?"!=i&&(h=g.htmlCls.GREY8,m="icn3d-nalign",u.nalignHash2[a+"_"+s]=1,this.setSeqPerResi(a,o,a,s,i,!1,h,void 0,m,!1,!1,t),++t)}if(e<t){v=t;for(let s=0;s<t-e;++s){let t="",i="-";h=g.htmlCls.GREY8,m="icn3d-nalign",this.setSeqPerResi(o,o,a,t,i,!1,h,void 0,m,!0,!1,e+s)}}else{v=e;for(let s=0;s<e-t;++s){let e="",i="-";h=g.htmlCls.GREY8,m="icn3d-nalign",this.setSeqPerResi(a,o,a,e,i,!1,h,void 0,m,!1,!1,t+s)}}}for(let l=0;l<=n-s;++l){let n,r,d,c;if(C&&"tmalign"==g.cfg.aligntool){if(n=u.qt_start_end[t][e].t_start,r=u.qt_start_end[t][e].q_start,d=this.getResnFromResi(o,n).toUpperCase(),c=this.getResnFromResi(a,r).toUpperCase(),"?"==d||"?"==c)continue}else n=this.getResiAferAlign(o,C,l+s),r=this.getResiAferAlign(a,C,l+i),d=this.getResnFromResi(o,n).toUpperCase(),c=this.getResnFromResi(a,r).toUpperCase();d===c?(h="#FF0000",m="icn3d-cons",u.consHash1[o+"_"+n]=1,u.consHash2[a+"_"+r]=1):(h="#0000FF",m="icn3d-ncons",u.nconsHash1[o+"_"+n]=1,u.nconsHash2[a+"_"+r]=1),f=g.hashUtilsCls.unionHash(f,u.residues[o+"_"+n]),f=g.hashUtilsCls.unionHash(f,u.residues[a+"_"+r]),u.chainsMapping[o][o+"_"+n]=d+n,u.chainsMapping[a][a+"_"+r]=d+n,p="#"+u.showAnnoCls.getColorhexFromBlosum62(d,c);let b=0===e&&0===l;this.setSeqPerResi(o,o,a,n,d,!0,h,p,m,!0,b,v),this.setSeqPerResi(a,o,a,r,c,!0,h,p,m,!1,b,v),++v}b=n,y=l}return f}setSeqAlignChainForAll(e,t,s){let i=this.icn3d,n=i.icn3dui,l={},r=e[0];i.alnChainsAnno[r]=[],i.alnChainsAnTtl[r]=[];let o=e.length;void 0===i.alnChainsAnTtl[r]&&(i.alnChainsAnTtl[r]=[]);for(let e=0;e<3+2*o;++e)void 0===i.alnChainsAnTtl[r][e]&&(i.alnChainsAnTtl[r][e]=[]);for(let t=0;t<o;++t)i.alnChainsAnTtl[r][t].push(e[o-1-t]);i.alnChainsAnTtl[r][o].push(""),i.alnChainsAnTtl[r][o+1].push("");for(let t=o+2;t<2*o+2;++t)i.alnChainsAnTtl[r][t].push(e[2*o+1-t]);i.alnChainsAnTtl[r][2*o+2].push(""),i.alnChainsSeq[r]=[],i.alnChains={},i.alnChains[r]={};let a={},d=9999,c=-1,h=i.chainsSeq[r][0].resi-1;for(let t=1,s=e.length;t<s;++t){let s=t-1;if(e[t],i.qt_start_end[s])for(let t=0,l=i.qt_start_end[s].length;t<l;++t){let l,r;l=parseInt(i.qt_start_end[s][t].t_start)-1,r=parseInt(i.qt_start_end[s][t].t_end)-1;for(let t=l;t<=r;++t){let s,l,r;r="tmalign"==n.cfg.aligntool?t-h:t,s=i.ParserUtilsCls.getResi(e[0],r),l=e[0]+"_"+s,a[l]=1,t<d&&(d=t),t>c&&(c=t)}}}"tmalign"==n.cfg.aligntool&&(s=!0);let p=Object.keys(a);p.sort((function(e,t){return parseInt(e.split("_")[2])-parseInt(t.split("_")[2])}));let m=-999,u=0,g=0,f=[],C=0;for(let e=0,t=p.length;e<t;++e){let t=p[e],s=t.split("_")[2];if(0==e)u=s;else if(e>0&&i.resid2ncbi[s]!=i.resid2ncbi[m]+1&&i.resid2ncbi[s]!=i.resid2ncbi[m]){g=m;for(let e=0,t=f.length;e<t;++e)a[f[e]]={resiStart:u,resiEnd:g,prevResiEnd:C};f=[],u=s,C=g}f.push(t),m=s}g=m;for(let e=0,t=f.length;e<t;++e)a[f[e]]={resiStart:u,resiEnd:g,prevResiEnd:C};for(let t=0,s=e.length;t<s;++t){let s=e[t];i.alnChainsSeq[s]=[],i.alnChains[s]={},i.alnChainsAnno[s]=[]}for(let e=0,t=i.chainsSeq[r].length;e<t;++e){let t=i.chainsSeq[r][e].resi,s=r+"_"+t,o="tmalign"!=n.cfg.aligntool?e:e+h;if(o<d||o>c)continue;let p={},m=r.indexOf("_");p.mmdbid=r.substr(0,m),p.chain=r.substr(m+1),p.resi=t,p.resn=a[s]?i.chainsSeq[r][e].name.toUpperCase():i.chainsSeq[r][e].name.toLowerCase(),p.aligned=!!a[s],p.color=a[s]?"#FF0000":n.htmlCls.GREYC,p.color2=a[s]?"#FF0000":n.htmlCls.GREYC,p.class=a[s]?"icn3d-align":"icn3d-nalign",i.alnChainsSeq[r].push(p),a[s]&&($.extend(i.alnChains[r],i.residues[r+"_"+p.resi]),l=n.hashUtilsCls.unionHash(l,i.residues[r+"_"+p.resi]))}let b=[0];for(let i=0,r=t.length;i<r;++i){let r=t[i].index;b.push(r);let o=this.mergeTwoSeqForAll(e,r,b,a,d,c,s);l=n.hashUtilsCls.unionHash(l,o)}for(let e=0;e<3+2*o;++e)void 0===i.alnChainsAnno[r][e]&&(i.alnChainsAnno[r][e]=[]);for(let t=0;t<o;++t){let s=e[t];for(let e=0,n=i.alnChainsSeq[s].length;e<n;++e){if("-"==i.alnChainsSeq[s][e].resn)i.alnChainsAnno[r][o-1-t].push("-");else{let n=s+"_"+i.alnChainsSeq[s][e].resi,l=i.secondaries[n];void 0!==l?i.alnChainsAnno[r][o-1-t].push(l):i.alnChainsAnno[r][o-1-t].push("-")}}}for(let e=0,t=i.alnChainsSeq[r].length;e<t;++e){let t=".";e%5==0&&(t="*"),e%10==0&&(t="|"),i.alnChainsAnno[r][o].push(t);let s="";e%10==0&&(s=e.toString()),i.alnChainsAnno[r][o+1].push(s)}for(let t=o+2;t<2*o+2;++t){let s=i.pdbid_chain2title&&i.pdbid_chain2title.hasOwnProperty(e[2*o+1-t])?i.pdbid_chain2title[e[2*o+1-t]]:"";i.alnChainsAnno[r][t].push(s)}return i.alnChainsAnno[r][2*o+2].push(""),l}getResObject(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a={},d=e.indexOf("_");return a.mmdbid=e.substr(0,d),a.chain=e.substr(d+1),a.resi=t?"":i,a.resn=n?t?"-":s?n.toUpperCase():n.toLowerCase():"-",a.aligned=!t&&s,a.color=t||!s?o.htmlCls.GREYC:n==l?"#FF0000":"#0000FF",a.color2=t||!s?o.htmlCls.GREYC:"#"+r.showAnnoCls.getColorhexFromBlosum62(n,l),a.class=t||!s?"icn3d-nalign":"icn3d-align",a}getResn(e,t){let s,i=this.icn3d;return i.icn3dui,s=i.chainsSeq[e]&&i.chainsSeq[e][t]?i.chainsSeq[e][t].name:"",s}getResiPosInTemplate(e,t){let s=this.icn3d;s.icn3dui;let i,n=0;if(s.alnChainsSeq[e])for(let l=0,r=s.alnChainsSeq[e].length;l<r;++l){if(parseInt(s.alnChainsSeq[e][l].resi)==parseInt(t)){i=l;break}"-"==s.alnChainsSeq[e][l].resn?++n:n=0}return{pos:i,ngap:n}}addGapAllAlnChains(e,t,s,i,n){let l=this.icn3d;l.icn3dui;let r=this.getResiPosInTemplate(s,i);r.ngap;let o=r.pos;for(let s=0,i=t.length-1;s<i;++s){let i=e[t[s]],r=this.getResObject(i,!0);for(let e=0,t=n;e<t;++e)l.alnChainsSeq[i].splice(o,0,r)}}insertNotAlignRes(e,t,s,i){let n=this.icn3d;n.icn3dui;for(let i=0,l=s;i<l;++i){let s=n.ParserUtilsCls.getResi(e,t+i),l=this.getResn(e,t+i),r="-",o=!1,a=this.getResObject(e,!1,o,s,l,r);n.alnChainsSeq[e].push(a)}}getTemplatePosFromOriPos(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=n.ParserUtilsCls.getResi(e,t),r=n.ParserUtilsCls.getResi(e,s),o=this.getResiPosInTemplate(e,l),a=this.getResiPosInTemplate(e,r);return{pos1:o.pos,pos2:a.pos}}mergeTwoSeqForAll(e,t,s,i,n,l,r){let o,a,d,c,h,p,m,u,g,f,C=this.icn3d,b=C.icn3dui,y={},v=e[t],_=t-1;if(m=e[0].indexOf("_"),u=v.indexOf("_"),o=e[0].substr(0,m),a=v.substr(0,u),d=e[0].substr(m+1),c=v.substr(u+1),o==a&&d==c){let e=C.chainsSeq[C.mmdbid_q+"_"+C.chain_q].length;C.qt_start_end[_]={q_start:1,q_end:e,t_start:1,t_end:e}}if(h=o+"_"+d,p=a+"_"+c,void 0!==a&&C.mmdbid_t,C.alnChains[p]={},C.conservedName2=p+"_cons",C.nonConservedName2=p+"_ncons",C.notAlignedName2=p+"_nalign",C.consHash2={},C.nconsHash2={},C.nalignHash2={},void 0===C.qt_start_end[_])return;this.getResObject(h,!0);let w,S=this.getResObject(p,!0);C.chainsMapping[h]||(C.chainsMapping[h]={}),C.chainsMapping[p]||(C.chainsMapping[p]={});for(let t=0,i=C.qt_start_end[_].length;t<i;++t){let i,l,o,a,d,c,v;if(r&&"tmalign"==b.cfg.aligntool?(i=parseInt(C.qt_start_end[_][t].t_start),l=parseInt(C.qt_start_end[_][t].q_start),o=parseInt(C.qt_start_end[_][t].t_end),a=parseInt(C.qt_start_end[_][t].q_end),d=i,c=this.getPosFromResi(h,C.qt_start_end[_][t].t_start),v=this.getPosFromResi(h,C.qt_start_end[_][t].t_end)):(i=parseInt(C.qt_start_end[_][t].t_start-1),l=parseInt(C.qt_start_end[_][t].q_start-1),o=parseInt(C.qt_start_end[_][t].t_end-1),a=parseInt(C.qt_start_end[_][t].q_end-1),d=C.ParserUtilsCls.getResi(h,i),c=i,v=o),0==t){if(w=this.getTemplatePosFromOriPos(h,n,c,r),m=w.pos1,u=w.pos2,c>n)for(let e=0,t=u-m;e<t;++e)C.alnChainsSeq[p].push(S)}else{w=this.getTemplatePosFromOriPos(h,g,i,r),m=w.pos1,u=w.pos2;let t=u-(m+1),n=l-(f+1);if(this.insertNotAlignRes(p,f+1,n,r),t>=n)for(let e=0,s=t-n;e<s;++e)C.alnChainsSeq[p].push(S);else this.addGapAllAlnChains(e,s,h,d,n-t)}w=this.getTemplatePosFromOriPos(h,c,v,r),m=w.pos1,u=w.pos2;let A=0;C.chainsMapping[h]||(C.chainsMapping[h]={}),C.chainsMapping[p]||(C.chainsMapping[p]={});for(let e=m;e<=u;++e)if("-"==C.alnChainsSeq[h][e].resn)C.alnChainsSeq[p].push(S);else{let t=r?i+A:C.ParserUtilsCls.getResi(h,i+A),s=r?l+A:C.ParserUtilsCls.getResi(p,l+A),n=this.getResnFromResi(h,t),o=this.getResnFromResi(p,s),a=!0,d=this.getResObject(p,!1,a,s,o,n);C.alnChainsSeq[p].push(d),C.alnChainsSeq[h][e].color=d.color,C.chainsMapping[h][h+"_"+t]=n+t,C.chainsMapping[p][p+"_"+s]=n+t,$.extend(C.alnChains[p],C.residues[p+"_"+s]),y=b.hashUtilsCls.unionHash(y,C.residues[p+"_"+s]),++A}g=o,f=a}w=this.getTemplatePosFromOriPos(h,g,l,r),m=w.pos1,u=w.pos2;for(let e=m;e<u;++e)C.alnChainsSeq[p].push(S);return y}mergeTwoSeqForAllSimple(e,t,s,i,n,l,r){let o=this.icn3d;o.icn3dui;let a,d,c,h,p=e,m=t[s];for(let e=0,l=o.qt_start_end[s].length;e<l;++e){let l,u,g,f,C,b,y;if(l=o.qt_start_end[s][e].t_start,u=o.qt_start_end[s][e].q_start,g=o.qt_start_end[s][e].t_end,f=o.qt_start_end[s][e].q_end,C=l,b=l,y=g,0==e){if(a=n,d=b,b>n)for(let e=0,t=d-a;e<t;++e)o.msaSeq[m]+="-"}else{a=c,d=l;let e=d-(a+1),n=u-(h+1);for(let e=0,t=n;e<t;++e){let t=r[s][h+1+e];o.msaSeq[m]+=t}if(e>=n)for(let t=0,s=e-n;t<s;++t)o.msaSeq[m]+="-";else{let s=C;for(let l=0,r=i.length-1;l<r;++l){let r=0==l?p:t[i[l]];for(let t=0,i=n-e;t<i;++t)o.msaSeq[r]=o.msaSeq[r].substr(0,s)+"-"+o.msaSeq[r].substr(s)}}}a=b,d=y;let v=0;for(let e=a;e<=d;++e)if("-"==o.msaSeq[p][e])o.msaSeq[m]+="-";else{let e=r[s][u+v];o.msaSeq[m]+=e,++v}c=g,h=f}a=c,d=l;for(let e=a;e<d;++e)o.msaSeq[m]+="-"}setSeqAlignForRealign(e,t,s){let i=this.icn3d,n=i.icn3dui;i.conservedName1=e+"_cons",i.conservedName2=t+"_cons",i.consHash1={},i.consHash2={},i.alnChainsAnTtl={},i.alnChainsAnno={},void 0===i.alnChainsSeq&&(i.alnChainsSeq={}),i.alnChains={},i.alnChainsSeq[e]=[],i.alnChains[e]={},i.alnChainsAnno[e]=[],i.alnChainsAnTtl[e]=[],i.alnChainsSeq[t]=[],i.alnChains[t]={};let l={};i.chainsMapping[e]||(i.chainsMapping[e]={}),i.chainsMapping[t]||(i.chainsMapping[t]={});for(let s=0,r=i.realignResid[e].length;s<r;++s){let r=i.realignResid[e][s],o=r.resid.lastIndexOf("_"),a=r.resid.substr(0,o),d=r.resid.substr(o+1);r.resi=d,r.aligned=!0;let c,h=i.realignResid[t][s],p=h.resid.lastIndexOf("_"),m=h.resid.substr(0,p),u=h.resid.substr(p+1);h.resi=u,h.aligned=!0,l[r.resid]=1,l[h.resid]=1,c=r.resn.toUpperCase()==h.resn.toUpperCase()?"#FF0000":"#0000FF",i.chainsMapping[e][e+"_"+r.resi]=r.resn+r.resi,i.chainsMapping[t][t+"_"+h.resi]=r.resn+r.resi;let g="#"+i.showAnnoCls.getColorhexFromBlosum62(r.resn,h.resn);r.color=c,h.color=c,r.color2=g,h.color2=g;for(let e in i.residues[r.resid])i.atoms[e].color=n.parasCls.thr(c);for(let e in i.residues[h.resid])i.atoms[e].color=n.parasCls.thr(c);void 0===i.alnChainsAnTtl[a]&&(i.alnChainsAnTtl[a]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnTtl[a][e]&&(i.alnChainsAnTtl[a][e]=[]);for(let e=0;e<3;++e)i.alnChainsAnTtl[a][e].push("");void 0===i.alnChainsSeq[a]&&(i.alnChainsSeq[a]=[]),void 0===i.alnChainsSeq[m]&&(i.alnChainsSeq[m]=[]),i.alnChainsSeq[a].push(r),i.alnChainsSeq[m].push(h),void 0===i.alnChains[a]&&(i.alnChains[a]={}),void 0===i.alnChains[m]&&(i.alnChains[m]={}),$.extend(i.alnChains[a],i.residues[a+"_"+r.resi]),$.extend(i.alnChains[m],i.residues[m+"_"+h.resi]),i.consHash1[a+"_"+r.resi]=1,i.consHash2[m+"_"+h.resi]=1,void 0===i.alnChainsAnno[a]&&(i.alnChainsAnno[a]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnno[a][e]&&(i.alnChainsAnno[a][e]=[]);let f=".";s%5==0&&(f="*"),s%10==0&&(f="|"),i.alnChainsAnno[a][0].push(f);let C="";s%10==0&&(C=s.toString()),i.alnChainsAnno[a][1].push(C)}let r="select "+i.resid2specCls.residueids2spec(Object.keys(l));i.selectionCls.addCustomSelection(Object.keys(l),"protein_aligned","protein aligned",r,!0)}setSeqPerResi(e,t,s,i,n,l,r,o,a,d,c,h){let p=this.icn3d,m=p.icn3dui;void 0===p.alnChainsSeq[e]&&(p.alnChainsSeq[e]=[]);let u={},g=e.indexOf("_");if(u.mmdbid=e.substr(0,g),u.chain=e.substr(g+1),u.resi=i,u.resn=""===u.resi||"icn3d-nalign"===a?n.toLowerCase():n,u.aligned=l,u.color=""===u.resi?m.htmlCls.GREYC:r,u.color2=""===u.resi?m.htmlCls.GREYC:o,u.class=a,p.alnChainsSeq[e].push(u),""!==u.resi&&(void 0===p.alnChains[e]&&(p.alnChains[e]={}),$.extend(p.alnChains[e],p.residues[e+"_"+u.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(s)?p.pdbid_chain2title[s]:"",i=p.pdbid_chain2title&&p.pdbid_chain2title.hasOwnProperty(e)?p.pdbid_chain2title[e]:"";p.alnChainsAnno[e][4].push(t),p.alnChainsAnno[e][5].push(i),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 l=e+"_"+i,r=p.secondaries[l];void 0!==r?p.alnChainsAnno[e][1].push(r):p.alnChainsAnno[e][1].push("-")}else{let s=e+"_"+i,n=p.secondaries[s];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")}}}class ds{constructor(e){this.icn3d=e}getStructureId(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=e=i&&n.idNMR?n.idNMR:e;return(e==n.defaultPdbId||s||n.structures.hasOwnProperty(e))&&(l=1===t?e:e+t.toString()),l}async loadPDB(e,t,s,i,n,l,r,o){let a,d,c=this.icn3d,h=c.icn3dui,p={},m=!1,u=e.split("\n"),g={},f={};c.atoms||(l=!1),c.statefileArray&&(c.struct_statefile=[]),n||l?(c.oriNStru=c.structures?Object.keys(c.structures).length:0,d=c.oriNStru+1,a=c.atoms?Object.keys(c.atoms).length:0):(c.init(),d=1,a=0);let C,b,y,v,_,w,S,A,x,k=[],O=[],R=[],I=[],E=[],T=[],P="",D="",M="",F={},H=t||c.defaultPdbId,L=H,N=H,q="",U=!1,B=!0;for(let e in u){let r=u[e],$=r.substr(0,6);if("HEADER"!==$||U||t)if("TITLE "===$){let e=r.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[N]=c.molTitle}else if("HELIX "===$){c.bSecondaryStructure=!0;let e=""==r.substr(18,2).trim()?"A":r.substr(18,2).trim(),t=parseInt(r.substr(21,4)),s=parseInt(r.substr(33,4));for(let i=t;i<=s;++i){let n=N+"_"+e+"_"+i;I.push(n),i===t&&E.push(n),i===s&&T.push(n)}}else if("SHEET "===$){void 0!==s&&s||(c.bSecondaryStructure=!0);let e=""==r.substr(20,2).trim()?"A":r.substr(20,2).trim(),t=parseInt(r.substr(22,4)),i=parseInt(r.substr(33,4));for(let s=t;s<=i;++s){let n=N+"_"+e+"_"+s;k.push(n),s===t&&O.push(n),s===i&&R.push(n)}}else if("HBOND "===$)void 0!==s&&s||(c.bSecondaryStructure=!0);else if("SSBOND"===$){c.bSsbondProvided=!0;let e=N+"_"+(" "==r.substr(15,1)?"A":r.substr(15,1))+"_"+r.substr(17,4).trim(),t=N+"_"+(" "==r.substr(29,1)?"A":r.substr(29,1))+"_"+r.substr(31,4).trim();void 0===c.ssbondpnts[N]&&(c.ssbondpnts[N]=[]),c.ssbondpnts[N].push(e),c.ssbondpnts[N].push(t)}else if("REMARK"===$){let e=parseInt(r.substr(7,3));if(-1!==r.indexOf("1/2 of bilayer thickness:"))c.halfBilayerSize=parseFloat(r.substr(r.indexOf(":")+1).trim());else if(210==e)"EXPERIMENT TYPE"==r.substr(11,32).trim()&&"NMR"==r.substr(45).trim()&&(m=!0,c.idNMR=L);else if(350==e&&"BIOMT"==r.substr(13,5)){let e=parseInt(r[18])-1,t=parseInt(r.substr(21,2))-1;null==c.biomtMatrices[t]&&(c.biomtMatrices[t]=(new THREE.Matrix4).identity()),c.biomtMatrices[t].elements[e]=parseFloat(r.substr(24,9)),c.biomtMatrices[t].elements[e+4]=parseFloat(r.substr(34,9)),c.biomtMatrices[t].elements[e+8]=parseFloat(r.substr(44,9)),c.biomtMatrices[t].elements[e+12]=parseFloat(r.substr(54,14))}else if(465==e&&" "==r.substr(18,1)&&" "==r.substr(20,1)&&"S"!=r.substr(21,1)){let e=r.substr(15,3),t=r.substr(18,2).trim(),s=r.substr(21,5).trim(),i=H+"_"+t;void 0===c.chainMissingResidueArray[i]&&(c.chainMissingResidueArray[i]=[]);let n={};n.resi=s,n.name=h.utilsCls.residueName2Abbr(e).toLowerCase(),""!=q&&t==q&&t!=q||(c.chainMissingResidueArray[i].push(n),q=t)}else 900==e&&void 0===c.emd&&"RELATED DB: EMDB"==r.substr(34).trim()&&(c.emd=r.substr(23,11).trim())}else if("SOURCE"===$&&void 0===c.organism&&"ORGANISM_COMMON"==r.substr(11,15).trim())c.organism=r.substr(28).toLowerCase().trim(),c.organism=c.organism.substr(0,c.organism.length-1);else if("ENDMDL"===$)c.statefileArray&&c.struct_statefile.push({structure:N,statefile:c.statefileArray[d-1]}),++d,H=c.defaultPdbId,N=this.getStructureId(H,d,n,m),m||(k=[],O=[],R=[],I=[],E=[],T=[]),U=!1;else if("JRNL "===$)"PMID"===r.substr(12,4)&&(c.pmid=r.substr(19).trim());else if("ATOM "===$||"HETATM"===$){A=r.substr(72,4).trim(),B?(N=this.getStructureId(H,d,n,m),B=!1):A!=x&&(++d,H=c.defaultPdbId,N=this.getStructureId(H,d,n,m),m||(k=[],O=[],R=[],I=[],E=[],T=[]),U=!1),x=A;let e=r.substr(16,1);++a,F[parseInt(r.substr(6,5))]=a;let t=r.substr(76,2).trim();""===t&&(t=r.substr(12,2).trim());let l=r.substr(12,4).trim(),u=r.substr(17,3),L=r.substr(20,2).trim();""===L&&(L="A");let q=r.substr(22,5).trim(),j=q;if(s&&"DUM"===u&&(t=l,L="MEM",j=1,q=1),i&&"DUM"===u)break;C=N+"_"+L,y=C+"_"+q,b=C+"_"+j;let z=parseFloat(r.substr(30,8)),G=parseFloat(r.substr(38,8)),V=parseFloat(r.substr(46,8)),W=new THREE.Vector3(z,G,V),Y=parseFloat(r.substr(60,8));o&&(Y*=100);let X={het:"H"===$[0],serial:a,name:l,alt:e,resn:u,structure:N,chain:L,resi:j,coord:W,b:Y,elem:t,bonds:[],ss:"coil",ssbegin:!1,ssend:!1};if(X.het||"C"!==X.name||(v=a),X.het||"O"!==X.name||(w=a),!X.het&&"N"===X.name&&void 0!==_&&void 0!==S){let e=c.atoms[_].coord.distanceTo(c.atoms[S].coord),t=X.coord.x+(c.atoms[_].coord.x-c.atoms[S].coord.x)/e,s=X.coord.y+(c.atoms[_].coord.y-c.atoms[S].coord.y)/e,i=X.coord.z+(c.atoms[_].coord.z-c.atoms[S].coord.z)/e;X.hcoord=new THREE.Vector3(t,s,i)}c.atoms[a]=X,c.dAtoms[a]=1,c.hAtoms[a]=1,p[a]=1,this.isSecondary(b,k,m)?(c.atoms[a].ss="sheet",this.isSecondary(b,O,m)&&(c.atoms[a].ssbegin=!0),this.isSecondary(b,R,m)&&(c.atoms[a].ssend=!0)):this.isSecondary(b,I,m)&&(c.atoms[a].ss="helix",this.isSecondary(b,E,m)&&(c.atoms[a].ssbegin=!0),this.isSecondary(b,T,m)&&(c.atoms[a].ssend=!0));let K="-";if(K="helix"===c.atoms[a].ss?"H":"sheet"===c.atoms[a].ss?"E":!c.atoms[a].het&&h.parasCls.residueColors.hasOwnProperty(c.atoms[a].resn.toUpperCase())?"c":"o",c.secondaries[b]=K,y!==M){let e=h.utilsCls.residueName2Abbr(u);if(c.residueId2Name[b]=e,1!==a&&""!==D&&(c.residues[D]=f),b!==D&&(f={}),C!==P){_=void 0,S=void 0,1!==a&&""!==P&&(void 0===c.chains[P]&&(c.chains[P]={}),c.chains[P]=h.hashUtilsCls.unionHash(c.chains[P],g)),g={},void 0===c.structures[N.toString()]&&(c.structures[N.toString()]=[]),c.structures[N.toString()].includes(C)||c.structures[N.toString()].push(C),void 0===c.chainsSeq[C]&&(c.chainsSeq[C]=[]);let t={};t.resi=j,t.name=e,c.chainsSeq[C].push(t)}else{_=v,S=w;let t={};t.resi=j,t.name=e,c.chainsSeq[C].push(t)}}g[a]=1,f[a]=1,P=C,D=b,M=y}else if("CONECT"===$){let e=parseInt(r.substr(6,5));for(let t=0;t<4;++t){let s=parseInt(r.substr([11,16,21,26][t],5));isNaN(s)||void 0!==c.atoms[F[e]]&&c.atoms[F[e]].bonds.push(F[s])}}else $.substr(0,3);else H=r.substr(62).trim(),L=H,""==H&&(H=l?c.defaultPdbId:c.inputid&&-1==c.inputid.indexOf("/")?c.inputid.substr(0,10):c.defaultPdbId),N=this.getStructureId(H,d,n,m),c.molTitle="",c.molTitleHash={},U=!0}c.residues[b]=f,void 0===c.chains[C]&&(c.chains[C]={}),c.chains[C]=h.hashUtilsCls.unionHash2Atoms(c.chains[C],g,c.atoms),c.statefileArray&&c.struct_statefile.push({structure:N,statefile:c.statefileArray[d-1]}),this.adjustSeq(c.chainMissingResidueArray);let j=Object.keys(c.structures);for(let e=0,t=j.length;e<t;++e){let t=j[e];if(t!=H&&(void 0===c.ssbondpnts[t]&&(c.ssbondpnts[t]=[]),void 0!==c.ssbondpnts[H]))for(let e=0,s=c.ssbondpnts[H].length;e<s;++e){let s=c.ssbondpnts[H][e],i=s.indexOf("_"),n=t+s.substr(i);c.ssbondpnts[t].push(n)}}c.bSsbondProvided||this.setSsbond(),u=null;let z,G,V=[],W=new THREE.Vector3(9999,9999,9999),Y=new THREE.Vector3(-9999,-9999,-9999),X=new THREE.Vector3,K=0,J={},Z=[];for(let e in c.hAtoms){let t=c.atoms[e],s=t.coord;X.add(s),W.min(s),Y.max(s),++K,1==K&&(z=t.chain,G=t.resi,Z.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&&(J[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)),z===t.chain&&G===t.resi||(this.refreshBonds(V,Z[0]),Z.splice(0,1),z=t.chain,G=t.resi,V.length=0),V.push(t),"C"!==t.name&&"O3'"!==t.name||Z.push(t)}this.refreshBonds(V,Z[0]);for(let e in J){let t=c.residues[e];for(a in t){let t=c.atoms[a];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=Y,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"===r?(c.oriMaxD=c.maxD,c.center1=c.center):"query"===r&&(c.oriMaxD<c.maxD&&(c.oriMaxD=c.maxD),c.center2=c.center,c.center=new THREE.Vector3(0,0,0)),i?this.getChainCalpha(c.chains,c.atoms):p}refreshBonds(e,t){let s=this.icn3d.icn3dui,i=e.length;for(let n=0;n<i;++n){let l=e[n];for(let t=n+1;t<i;++t){let i=e[t];l.alt===i.alt&&s.utilsCls.hasCovalentBond(l,i)&&(l.bonds.push(i.serial),i.bonds.push(l.serial))}!t||"C"!==t.name&&"O3'"!==t.name||"N"!==l.name&&"P"!==l.name||!s.utilsCls.hasCovalentBond(l,t)||(l.bonds.push(t.serial),t.bonds.push(l.serial))}}adjustSeq(e){let t=this.icn3d;t.icn3dui;for(let s in t.chainsSeq)void 0!==e[s]&&(t.chainsSeq[s]=this.mergeTwoSequences(e[s],t.chainsSeq[s]));this.setResidMapping()}mergeTwoSequences(e,t){let s=e.length,i=t.length,n=parseInt(e[s-1].resi),l=parseInt(t[i-1].resi),r=n>=l?n:l,o=new Array(s+i),a=0,d=0,c=0,h=!1;for(;a<s&&d<i;){let s=parseInt(e[a].resi),i=parseInt(t[d].resi);s>r&&i>r&&(h=!0),s<=r&&i>r?s>i||h?(o[c]=t[d],d++):(o[c]=e[a],a++):s>r&&i<=r?s<=i||h?(o[c]=e[a],a++):(o[c]=t[d],d++):s<=i?(o[c]=e[a],a++):(o[c]=t[d],d++),c++}if(a<s)for(let t=a;t<s;t++)o[c]=e[t],c++;else for(let e=d;e<i;e++)o[c]=t[e],c++;return o}setResidMapping(){let e=this.icn3d;e.icn3dui;for(let t in e.chainsSeq)for(let s=0,i=e.chainsSeq[t].length;s<i;++s){let i=t+"_"+(s+1).toString(),n=t+"_"+e.chainsSeq[t][s].resi;e.ncbi2resid[i]=n,e.resid2ncbi[n]=i}}setSsbond(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in t.chainsSeq){if(e&&!e.hasOwnProperty(i))continue;let n=t.chainsSeq[i],l=i.substr(0,i.indexOf("_"));for(let e=0,t=n.length;e<t;++e)"C"==n[e].name&&(null==s[l]&&(s[l]=[]),s[l].push(i+"_"+n[e].resi))}for(let e in s){let i=s[e];for(let s=0,n=i.length;s<n;++s)for(let n=s+1,l=i.length;n<l;++n){let l,r,o=i[s],a=i[n];for(let e in t.residues[o])if("S"==t.atoms[e].elem){l=t.atoms[e].coord;break}for(let e in t.residues[a])if("S"==t.atoms[e].elem){r=t.atoms[e].coord;break}void 0!==l&&void 0!==r&&(Math.abs(l.x-r.x)>4||Math.abs(l.y-r.y)>4||Math.abs(l.z-r.z)>4||(l.x-r.x)*(l.x-r.x)+(l.y-r.y)*(l.y-r.y)+(l.z-r.z)*(l.z-r.z)<16&&(void 0===t.ssbondpnts[e]&&(t.ssbondpnts[e]=[]),t.ssbondpnts[e].push(o),t.ssbondpnts[e].push(a)))}}}getChainCalpha(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r={};for(let o in e){if(void 0!==i){if(o.split("_")[0]!==i)continue}let a=Object.keys(e[o]),d=[],c=0,h=0;for(let e=0,i=a.length;e<i;++e){let i=t[a[e]];if(n.proteins.hasOwnProperty(a[e])&&"CA"==i.name||n.nucleotides.hasOwnProperty(a[e])&&("O3'"==i.name||"O3*"==i.name)){if(i.resi==h)continue;let e=i.resn.trim().length>3?i.resn.trim().substr(0,3):i.resn.trim();if(!l.parasCls.chargeColors.hasOwnProperty(e))continue;s?i.resi_ori:i.resi,d.push(i.coord.clone()),++c,h=i.resi}}if(c>0){r[t[a[0]].chain]=d}}return{chainresiCalphaHash:r,center:n.center.clone()}}isSecondary(e,t,s,i){if(this.icn3d.icn3dui,i)return!1;if(s){let s=e.substr(e.indexOf("_")+1),i=!1;for(let e=0,n=t.length;e<n;++e)if(s==t[e].substr(t[e].indexOf("_")+1)){i=!0;break}return i}return-1!=$.inArray(e,t)}}class cs{constructor(e){this.icn3d=e}loadCIF(e,t,s,i){let n,l,r=this.icn3d,o=r.icn3dui,a={},d=!1,c={},h={};r.atoms||(i=!1),i?(r.oriNStru=r.structures?Object.keys(r.structures).length:0,l=r.oriNStru,n=r.atoms?Object.keys(r.atoms).length:0):(r.init(),l=0,n=0);let p,m,u,g,f,C,b,y=[],v=[],_=[],w=[],S=[],A=[],x="",k="",O="",R=t||r.defaultPdbId,I=R,E=s?e.split("ENDMDL\n"):[e];for(let e=0,t=E.length;e<t;++e){++l,R=r.defaultPdbId,I=r.loadPDBCls.getStructureId(R,l),y=[],v=[],_=[],w=[],S=[],A=[];let t=s?CIFTools.Text.parse(E[e]):CIFTools.Binary.parse(E[e]);if(t.isError)return void alert("The Binary CIF data can NOT be parsed: "+t.toString());let T=t.result.dataBlocks[0];if(T.getCategory("_entry")&&(R=T.getCategory("_entry").getColumn("id").getString(0),""==R&&(R=i?r.defaultPdbId:r.inputid&&-1==r.inputid.indexOf("/")?r.inputid.substr(0,10):r.defaultPdbId),I=r.loadPDBCls.getStructureId(R,l),r.molTitle="",r.molTitleHash={}),T.getCategory("_struct")){let e=T.getCategory("_struct").getColumn("title").getString(0);e=e.replace(/"/,"'");let t=e.replace(/ALPHAFOLD MONOMER V2.0 PREDICTION FOR /gi,"");r.molTitle+=t.trim()+" ",r.molTitleHash||(r.molTitleHash={}),r.molTitleHash[I]=r.molTitle}if(T.getCategory("_entity_src_gen")&&(r.organism=T.getCategory("_entity_src_gen").getColumn("gene_src_common_name").getString(0)),T.getCategory("_database_2")){let e=T.getCategory("_database_2"),t=e.rowCount;for(let s=0;s<t;++s){let t=e.getColumn("database_id").getString(0),s=e.getColumn("database_code").getString(0);if("EMDB"==t){r.emd=s;break}}}if(T.getCategory("_struct_conf")){r.bSecondaryStructure=!0;let e=T.getCategory("_struct_conf"),t=e.getColumn("conf_type_id"),s=e.getColumn("beg_auth_asym_id"),i=e.getColumn("beg_auth_seq_id");e.getColumn("end_auth_asym_id");let n=e.getColumn("end_auth_seq_id"),l=e.rowCount;for(let e=0;e<l;++e){let l=t.getString(e),r=s.getString(e),o=parseInt(i.getString(e)),a=parseInt(n.getString(e));if("HELX"==l.substr(0,4))for(let e=parseInt(o);e<=parseInt(a);++e){let t=I+"_"+r+"_"+e;w.push(t),e==o&&S.push(t),e==a&&A.push(t)}else if("STRN"==l.substr(0,4))for(let e=o;e<=a;++e){let t=I+"_"+r+"_"+e;y.push(t),e==o&&v.push(t),e==a&&_.push(t)}}t=s=i=n=[]}if(T.getCategory("_struct_sheet_range")){let e=T.getCategory("_struct_sheet_range"),t=e.getColumn("beg_auth_asym_id"),s=e.getColumn("beg_auth_seq_id");e.getColumn("end_auth_asym_id");let i=e.getColumn("end_auth_seq_id"),n=e.rowCount;for(let e=0;e<n;++e){let n=t.getString(e),l=parseInt(s.getString(e)),r=parseInt(i.getString(e));for(let e=l;e<=r;++e){let t=I+"_"+n+"_"+e;y.push(t),e==l&&v.push(t),e==r&&_.push(t)}}t=s=i=[]}if(T.getCategory("_struct_conn")){r.bSsbondProvided=!0;let e=T.getCategory("_struct_conn"),t=e.getColumn("conn_type_id"),s=e.getColumn("ptnr1_auth_asym_id"),i=e.getColumn("ptnr1_label_atom_id"),n=e.getColumn("ptnr1_label_seq_id"),l=e.getColumn("ptnr2_auth_asym_id"),o=e.getColumn("ptnr2_label_atom_id"),a=e.getColumn("ptnr2_label_seq_id"),d=e.rowCount;for(let e=0;e<d;++e){let d=t.getString(e),c=s.getString(e);i.getString(e);let h=I+"_"+c+"_"+n.getString(e),p=l.getString(e);o.getString(e);let m=I+"_"+p+"_"+a.getString(e);"disulf"==d&&(void 0===r.ssbondpnts[I]&&(r.ssbondpnts[I]=[]),r.ssbondpnts[I].push(h),r.ssbondpnts[I].push(m))}t=s=i=n=l=o=a=[]}if(T.getCategory("_exptl")){-1!=T.getCategory("_exptl").getColumn("method").getString(0).indexOf("NMR")&&(d=!0)}if(T.getCategory("_pdbx_struct_oper_list")){let e=T.getCategory("_pdbx_struct_oper_list"),t=e.getColumn("id"),s=e.getColumn("matrix[1][1]"),i=e.getColumn("matrix[1][2]"),n=e.getColumn("matrix[1][3]"),l=e.getColumn("vector[1]"),o=e.getColumn("matrix[2][1]"),a=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]"),m=e.getColumn("matrix[3][3]"),u=e.getColumn("vector[3]"),g=e.rowCount;for(let e=0;e<g;++e){"X0"!=t.getString(e)&&(null==r.biomtMatrices[e]&&(r.biomtMatrices[e]=(new THREE.Matrix4).identity()),r.biomtMatrices[e].set(s.getString(e),i.getString(e),n.getString(e),l.getString(e),o.getString(e),a.getString(e),d.getString(e),c.getString(e),h.getString(e),p.getString(e),m.getString(e),u.getString(e),0,0,0,1))}t=s=i=n=l=o=a=d=c=h=p=m=u=[]}T.getCategory("_citation")&&(r.pmid=T.getCategory("_citation").getColumn("pdbx_database_id_PubMed").getString(0));let P=T.getCategory("_atom_site"),D=P.rowCount,M=!(D>r.maxatomcnt);M||(r.opts.proteins="c alpha trace",r.opts.nucleotides="o3 trace");let F,H=P.getColumn("group_PDB"),L=P.getColumn("label_comp_id"),N=P.getColumn("type_symbol"),q=P.getColumn("label_atom_id"),U=P.getColumn("auth_asym_id"),$=P.getColumn("label_seq_id"),B=P.getColumn("auth_seq_id"),j=P.getColumn("label_alt_id"),z=P.getColumn("B_iso_or_equiv"),G=P.getColumn("Cartn_x"),V=P.getColumn("Cartn_y"),W=P.getColumn("Cartn_z"),Y=P.getColumn("label_asym_id"),X=P.getColumn("pdbx_PDB_model_num"),K={},J="",Z={},Q="";for(let e=0;e<D;++e){let t=X.getString(e);e>0&&t!=Q&&(++l,I="1"==t?R:R+t),Q=t;let s,i=H.getString(e),E=L.getString(e),T=N.getString(e),P=q.getString(e),D=U.getString(e),ee=$.getString(e),te=B.getString(e),se=j.getString(e),ie=z.getString(e),ne=Y.getString(e);if(ee=te,"ATOM"==i?s=3==E.length?"protein":"nucleotide":"WAT"==E||"HOH"==E?(s="solvent",D="Misc"):(s="ligand",D=E),""===D&&(D="A"),!M&&("protein"==s&&("C"!=T||"CA"!=P)||"nucleotide"==s&&"P"!=P))continue;if("B"==se)continue;if(Z[D]=1,++n,"?"!=ee&&"."!=ee&&"0"!=ee||(ee=te),"solvent"==s||"ligand"==s){let e={};K.hasOwnProperty(D)||(K[D]=[]),3!=E.length||"HOH"==E||"WAT"==E?3==E.length&&("O"!=T||"HOH"!=E&&"WAT"!=E)||(e.resi=ee,e.name=o.utilsCls.residueName2Abbr(E),K[D].push(e)):D+"_"+E==F&&J==ne||(e.resi=ee,e.name=o.utilsCls.residueName2Abbr(E),K[D].push(e))}p=I+"_"+D,u=p+"_"+te,m=p+"_"+ee;let le=G.getFloat(e),re=V.getFloat(e),oe=W.getFloat(e),ae={het:"HETATM"==i,serial:n,name:P,alt:se,resn:E,structure:I,chain:D,resi:ee,coord:new THREE.Vector3(le,re,oe),b:ie,elem:T,bonds:[],ss:"coil",ssbegin:!1,ssend:!1};if(ae.het||"C"!==ae.name||(g=n),ae.het||"O"!==ae.name||(C=n),!ae.het&&"N"===ae.name&&void 0!==f&&void 0!==b){let e=r.atoms[f].coord.distanceTo(r.atoms[b].coord),t=ae.coord.x+(r.atoms[f].coord.x-r.atoms[b].coord.x)/e,s=ae.coord.y+(r.atoms[f].coord.y-r.atoms[b].coord.y)/e,i=ae.coord.z+(r.atoms[f].coord.z-r.atoms[b].coord.z)/e;ae.hcoord=new THREE.Vector3(t,s,i)}r.atoms[n]=ae,r.dAtoms[n]=1,r.hAtoms[n]=1,a[n]=1,r.loadPDBCls.isSecondary(m,y,d,!M)?(r.atoms[n].ss="sheet",r.loadPDBCls.isSecondary(m,v,d,!M)&&(r.atoms[n].ssbegin=!0),r.loadPDBCls.isSecondary(m,_,d,!M)&&(r.atoms[n].ssend=!0)):r.loadPDBCls.isSecondary(m,w,d,!M)&&(r.atoms[n].ss="helix",r.loadPDBCls.isSecondary(m,S,d,!M)&&(r.atoms[n].ssbegin=!0),r.loadPDBCls.isSecondary(m,A,d,!M)&&(r.atoms[n].ssend=!0));let de="-";if(de="helix"===r.atoms[n].ss?"H":"sheet"===r.atoms[n].ss?"E":!r.atoms[n].het&&o.parasCls.residueColors.hasOwnProperty(r.atoms[n].resn.toUpperCase())?"c":"o",r.secondaries[m]=de,u!==O||D+"_"+E!=F||J!=ne){let e=o.utilsCls.residueName2Abbr(E);if(r.residueId2Name[m]=e,1!==n&&""!==k&&(r.residues[k]=h),m!==k&&(h={}),p!==x){f=void 0,b=void 0,1!==n&&""!==x&&(void 0===r.chains[x]&&(r.chains[x]={}),r.chains[x]=o.hashUtilsCls.unionHash(r.chains[x],c)),c={},void 0===r.structures[I.toString()]&&(r.structures[I.toString()]=[]),r.structures[I.toString()].includes(p)||r.structures[I.toString()].push(p),void 0===r.chainsSeq[p]&&(r.chainsSeq[p]=[]);let t={};t.resi=ee,t.name=e,r.chainsSeq[p].push(t)}else{f=g,b=C;let t={};t.resi=ee,t.name=e,r.chainsSeq[p].push(t)}}c[n]=1,h[n]=1,x=p,k=m,O=u,F=D+"_"+E,J=ne}r.residues[m]=h,void 0===r.chains[p]&&(r.chains[p]={}),r.chains[p]=o.hashUtilsCls.unionHash2Atoms(r.chains[p],c,r.atoms),H=L=N=q=U=$=B=j=z=G=V=W=Y=[];let ee={};if(T.getCategory("_pdbx_poly_seq_scheme")){let e=T.getCategory("_pdbx_poly_seq_scheme"),t=e.getColumn("seq_id"),s=e.getColumn("pdb_seq_num"),i=e.getColumn("mon_id"),n=e.getColumn("pdb_strand_id"),l=e.rowCount,r="",a=[];for(let e=0;e<l;++e){t.getString(e);let l=s.getString(e),d=i.getString(e),c=n.getString(e);c!=r&&e>0&&(ee[r]=a,a=[]),a.push({resi:l,name:o.utilsCls.residueName2Abbr(d)}),r=c}ee[r]=a,t=s=i=n=[]}this.setSeq(I,Z,ee,K)}let T=Object.keys(r.structures);for(let e=0,t=T.length;e<t;++e){let t=T[e];if(t!=R&&(void 0===r.ssbondpnts[t]&&(r.ssbondpnts[t]=[]),void 0!==r.ssbondpnts[R]))for(let e=0,s=r.ssbondpnts[R].length;e<s;++e){let s=r.ssbondpnts[R][e],i=s.indexOf("_"),n=t+s.substr(i);r.ssbondpnts[t].push(n)}}r.bSsbondProvided||r.loadPDBCls.setSsbond();let P,D,M=[],F=new THREE.Vector3(9999,9999,9999),H=new THREE.Vector3(-9999,-9999,-9999),L=new THREE.Vector3,N=0,q={},U=[];for(let e in r.hAtoms){let t=r.atoms[e],s=t.coord;L.add(s),F.min(s),H.max(s),++N,1==N&&(P=t.chain,D=t.resi,U.push(t)),t.het?t.het&&("HOH"===t.resn||"WAT"===t.resn||"SOL"===t.resn?r.water[t.serial]=1:-1!==$.inArray(t.resn,o.parasCls.ionsArray)||t.elem.trim()===t.resn.trim()?r.ions[t.serial]=1:r.chemicals[t.serial]=1,t.color=o.parasCls.atomColors[t.elem]):-1!==$.inArray(t.resn,o.parasCls.nucleotidesArray)?(r.nucleotides[t.serial]=1,"O3'"!==t.name&&"O3*"!==t.name||(r.nucleotidesO3[t.serial]=1,r.secondaries[t.structure+"_"+t.chain+"_"+t.resi]="o"),-1===o.parasCls.nuclMainArray.indexOf(t.name)&&(r.ntbase[t.serial]=1)):("P"===t.elem&&(q[t.structure+"_"+t.chain+"_"+t.resi]=1),r.proteins[t.serial]=1,"CA"===t.name&&(r.calphas[t.serial]=1),"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&(r.sidec[t.serial]=1)),P===t.chain&&D===t.resi||(r.loadPDBCls.refreshBonds(M,U[0]),U.splice(0,1),P=t.chain,D=t.resi,M.length=0),M.push(t),"C"!==t.name&&"O3'"!==t.name||U.push(t)}r.loadPDBCls.refreshBonds(M,U[0]);for(let e in q){let t=r.residues[e];for(n in t){let t=r.atoms[n];t.het=!0,r.chemicals[t.serial]=1,r.secondaries[e]="o",delete r.proteins[t.serial],"CA"===t.name&&delete r.calphas[t.serial],"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&delete r.sidec[t.serial]}}return r.pmin=F,r.pmax=H,r.cnt=N,r.center=r.ParserUtilsCls.getGeoCenter(r.pmin,r.pmax),r.maxD=r.ParserUtilsCls.getStructureSize(r.atoms,r.pmin,r.pmax,r.center),r.maxD<5&&(r.maxD=5),r.oriMaxD=r.maxD,r.oriCenter=r.center.clone(),a}setSeq(e,t,s,i){let n=this.icn3d;n.icn3dui;for(let l in t){let t=e+"_"+l;i.hasOwnProperty(l)?n.chainsSeq[t]=i[l]:n.chainsSeq[t]=s[l]}n.loadPDBCls.setResidMapping()}}class hs{constructor(e){this.icn3d=e}async vastplusAlign(e,t,s){let i=this.icn3d;i.icn3dui;let n=this,l=[],r=[];if(2!=e.length)return void console.log("VAST+ needs two input structures...");let o=e[0],a=e[1],d=[],c=[];for(let e=0,t=i.structures[o].length;e<t;++e){let t=i.structures[o][e];i.proteins.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.chains[t]).serial)&&d.push(t)}for(let e=0,t=i.structures[a].length;e<t;++e){let t=i.structures[a][e];i.proteins.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.chains[t]).serial)&&c.push(t)}let h={},p=0;for(let e=0,t=d.length;e<t;++e){let t=d[e];for(let i=0,n=c.length;i<n;++i){let n=c[i];if(e==i){let d=this.setAlignment(o,a,t,n,s);l.push(d),r.push(t+","+n),h[p]=[e,i],++p}}}for(let e=0,t=d.length;e<t;++e){let t=d[e];for(let i=0,n=c.length;i<n;++i){let n=c[i];if(e!=i){let d=this.setAlignment(o,a,t,n,s);l.push(d),r.push(t+","+n),h[p]=[e,i],++p}}}let m=Promise.allSettled(l);try{let e=await m;n.clusterAlignment(e,r,h,t),i.ParserUtilsCls.hideLoading(),await i.pdbParserCls.loadPdbDataRender(!0)}catch(e){alert("There are some problems in aligning the chains...")}}setAlignment(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=r.htmlCls.baseUrl+"tmalign/tmalign.cgi",a=n?r.hashUtilsCls.intHash(l.hAtoms,l.chains[s]):l.chains[s],d=n?r.hashUtilsCls.intHash(l.hAtoms,l.chains[i]):l.chains[i],c=l.saveFileCls.getAtomPDB(a,void 0,void 0,void 0,void 0,e),h={pdb_query:l.saveFileCls.getAtomPDB(d,void 0,void 0,void 0,void 0,t),pdb_target:c};return r.getAjaxPostPromise(o,h)}async realignOnVastplus(){let e=this.icn3d,t=e.icn3dui,s=[];for(let i in e.structures){let n=e.structures[i];for(let i=0,l=n.length;i<l;++i){let l=n[i],r=t.hashUtilsCls.intHash(e.hAtoms,e.chains[l]),o=e.firstAtomObjCls.getFirstAtomObj(r);o&&(s[o.structure]=1)}}t.cfg.aligntool="tmalign",await e.vastplusCls.vastplusAlign(Object.keys(s),2,!0)}getResisFromSegs(e){this.icn3d.icn3dui;let t=[],s=[];for(let i=0,n=e.length;i<n;++i){let n=e[i];t.push(n.t_start+"-"+n.t_end),s.push(n.q_start+"-"+n.q_end)}return{resiArray_t:t,resiArray_q:s}}clusterAlignment(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=[];for(let s=0,i=t.length;s<i;++s){let t=e[s].value;r.push(t)}let o=[],a=0,d=!1;for(let e=0,s=t.length;e<s;++e){let s=[];r[e].length>0&&(d=!0);for(let n=0,l=t.length;n<l;++n){let t=this.RotMatrixTransDist(r[e][0],r[n][0],1,i),l=e==n?0:0==r[e].length||0==r[n].length?1:t;l>a&&(a=l),s.push(l)}o.push(s)}if(!d)return void(n.bRender&&alert("These structures can not be aligned..."));a<1e-6&&(a=1);for(let e=0,s=t.length;e<s;++e)for(let s=0,i=t.length;s<i;++s)o[e][s]=o[e][s]/a;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,i=t.join(","),n=s[parseInt(t[0])],l=o[n[0]][n[1]];p[i]?l<p[i]&&(p[i]=l):p[i]=l}let m=Object.keys(p).sort(((e,t)=>p[e]<p[t]||parseInt(1e4*p[e])==parseInt(1e4*p[t])&&e<t?-1:1)),u=parseInt($("#"+l.pre+"maxrmsd").val());u||(u=30),d=!1;for(let e=0,s=m.length;e<s;++e){let s=m[e].split(",");n.opts.color="grey",n.setColorCls.setColorByOptions(n.opts,n.atoms);let i,o,a=[],c=[],h={};$("#"+n.pre+"dl_sequence2").html("");for(let e=0,d=s.length;e<d;++e){let d=parseInt(s[e]),p=r[d][0].segs,m=t[d].split(",");i=m[0],o=m[1];let u=this.getResisFromSegs(p),g=u.resiArray_t,f=u.resiArray_q,C=n.realignParserCls.getSeqCoorResid(g,i);a=a.concat(C.coor);let b=n.realignParserCls.getSeqCoorResid(f,o);c=c.concat(b.coor),n.qt_start_end=[],n.qt_start_end.push(p);let y=!0,v=!0,_=n.chainalignParserCls.setMsa(m,y,v);h=l.hashUtilsCls.unionHash(h,_)}n.hAtoms=l.hashUtilsCls.cloneHash(h);let p=c.length<a.length?c.length:a.length;if(!(p<4)&&(p>=4&&(n.rmsd_suprTmp=l.rmsdSuprCls.getRmsdSuprCls(c,a,p),void 0!==n.rmsd_suprTmp.rot))){let e=n.rmsd_suprTmp.rot;if(null===e[0])continue;let i=n.rmsd_suprTmp.trans1,r=n.rmsd_suprTmp.trans2,a=n.rmsd_suprTmp.rmsd;if(a<u){d=!0,l.htmlCls.clickMenuCls.setLogCmd("realignment RMSD: "+a.toPrecision(4),!1),$("#"+n.pre+"dl_rmsd_html").html("<br><b>Realignment RMSD</b>: "+a.toPrecision(4)+" &#8491;<br><br>"),l.cfg.bSidebyside||l.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(i),n.t_trans_add.push({x:-r.x,y:-r.y,z:-r.z}),l.cfg.aligntool="vast";//!= 'tmalign';
7
+ let c=0,h="query",p=o.substr(0,o.indexOf("_")),m=!0;n.chainalignParserCls.transformStructure(p,c,h,m);let u="";for(let e=0,i=s.length;e<i;++e)u+=t[parseInt(s[e])]+"; ";l.bNode||console.log("Selected the alignment: "+u);break}{let e="";for(let i=0,n=s.length;i<n;++i)e+=t[parseInt(s[i])]+"; ";l.bNode||console.log("skipped the alignment: "+e)}}}d||n.bRender&&alert("These structures can not be aligned...")}RotMatrixTransDist(e,t,s,i){this.icn3d.icn3dui;if(!e||!t)return s;let n=this.GetRotMatrix(e,1,i),l=this.GetRotMatrix(t,1,i),r=[],o=[],a=[],d=[];r[0]=n[9],r[1]=n[10],r[2]=n[11],o[0]=n[12],o[1]=n[13],o[2]=n[14],a[0]=l[9],a[1]=l[10],a[2]=l[11],d[0]=l[12],d[1]=l[13],d[2]=l[14];let c=[],h=[];c[0]=o[0]-d[0],c[1]=o[1]-d[1],c[2]=o[2]-d[2],h[0]=r[0]-a[0],h[1]=r[1]-a[1],h[2]=r[2]-a[2];let p,m,u=0;if(u+=Math.pow(c[0],2),u+=Math.pow(c[1],2),u+=Math.pow(c[2],2),p=Math.sqrt(u),u=0,u+=Math.pow(h[0],2),u+=Math.pow(h[1],2),u+=Math.pow(h[2],2),m=Math.sqrt(u),2!=i){if(p<1e-10||m<1e-10)return s}else if(m<1e-10)return s;if(Math.abs(p-m)>8)return s;let g=[];g[0]=n[0]*r[0]+n[1]*r[1]+n[2]*r[2],g[1]=n[3]*r[0]+n[4]*r[1]+n[5]*r[2],g[2]=n[6]*r[0]+n[7]*r[1]+n[8]*r[2],g[0]-=n[0]*a[0]+n[1]*a[1]+n[2]*a[2],g[1]-=n[3]*a[0]+n[4]*a[1]+n[5]*a[2],g[2]-=n[6]*a[0]+n[7]*a[1]+n[8]*a[2];let f=0;return f=c[0]*g[0],f+=c[1]*g[1],f+=c[2]*g[2],f/=p*m,f<.866?s:(g[0]=l[0]*r[0]+l[1]*r[1]+l[2]*r[2],g[1]=l[3]*r[0]+l[4]*r[1]+l[5]*r[2],g[2]=l[6]*r[0]+l[7]*r[1]+l[8]*r[2],g[0]-=l[0]*a[0]+l[1]*a[1]+l[2]*a[2],g[1]-=l[3]*a[0]+l[4]*a[1]+l[5]*a[2],g[2]-=l[6]*a[0]+l[7]*a[1]+l[8]*a[2],f=c[0]*g[0],f+=c[1]*g[1],f+=c[2]*g[2],f/=p*m,f<.866?s:(u=0,u+=Math.pow(e.q_rotation.x1-t.q_rotation.x1,2),u+=Math.pow(e.q_rotation.y1-t.q_rotation.y1,2),u+=Math.pow(e.q_rotation.z1-t.q_rotation.z1,2),u+=Math.pow(e.q_rotation.x2-t.q_rotation.x2,2),u+=Math.pow(e.q_rotation.y2-t.q_rotation.y2,2),u+=Math.pow(e.q_rotation.z2-t.q_rotation.z2,2),u+=Math.pow(e.q_rotation.x3-t.q_rotation.x3,2),u+=Math.pow(e.q_rotation.y3-t.q_rotation.y3,2),u+=Math.pow(e.q_rotation.z3-t.q_rotation.z3,2),Math.sqrt(u)))}GetRotMatrix(e,t,s){this.icn3d.icn3dui;let i=[];return i&&(i[0]=e.q_rotation.x1/t,i[1]=e.q_rotation.y1/t,i[2]=e.q_rotation.z1/t,i[3]=e.q_rotation.x2/t,i[4]=e.q_rotation.y2/t,i[5]=e.q_rotation.z2/t,i[6]=e.q_rotation.x3/t,i[7]=e.q_rotation.y3/t,i[8]=e.q_rotation.z3/t,2!=s?(i[9]=e.t_trans_add.x/t,i[10]=e.t_trans_add.y/t,i[11]=e.t_trans_add.z/t,i[12]=-e.q_trans_sub.x/t,i[13]=-e.q_trans_sub.y/t,i[14]=-e.q_trans_sub.z/t):(i[9]=-e.q_trans_add.x/t,i[10]=-e.q_trans_add.y/t,i[11]=-e.q_trans_add.z/t,i[12]=0,i[13]=0,i[14]=0)),i}cbu_dist(e,t,s){return e<t?s[e][t]:s[t][e]}compareFloat(e,t,s){let i=e[t].dist,n=e[s].dist;return parseInt(1e4*i)==parseInt(1e4*n)?0:parseInt(1e4*i)<parseInt(1e4*n)?-1:1}clusterLinkage(e,t,s){let i,n,l,r,o,a,d,c,h=this.icn3d,p=h.icn3dui,m=[],u=t.length;for(i=0;i<2*u-1;++i)m[i]={},m[i].leaves=[];let g=[];for(i=0;i<2*u-1;++i)for(g[i]=[],n=0;n<2*u-1;++n)g[i][n]=2;for(i=0;i<u;++i)for(n=i;n<u;++n)g[i][n]=t[i][n];let f={},C={},b={};for(r=u,o=u,i=0;i<u;++i){for(d=2,n=0;n<u;++n){let e=s?parseInt(1e4*this.cbu_dist(i,n,g))<=parseInt(1e4*d):parseInt(1e4*this.cbu_dist(i,n,g))<parseInt(1e4*d);n!=i&&e&&(d=this.cbu_dist(i,n,g),r=i,o=n)}f[r]=o,b[r]=d}let y=[];for(a=0;a<u;++a)m[a].child1=-2,m[a].child2=-2,m[a].parent=a,m[a].dist=0,m[a].leaves.push([a]),y[a]=0;let v=Object.keys(h.structures),_=h.structures[v[0]].length,w=h.structures[v[1]].length,S=_<w?_:w;for(a=u;a<2*u-1;++a){for(l in d=2,f)c=b[l],c<d&&(d=c,r=l,o=f[l]);let e=d;for(m[a].child1=r<u?r:-r,m[a].child2=o<u?o:-o,m[a].parent=-1*a,m[r].dist=e-y[r],m[o].dist=e-y[o],y[a]=e,n=0;n<2*u-1;++n){let e=this.cbu_dist(r,n,g),t=this.cbu_dist(o,n,g);a<n?g[a][n]=e<t?e:t:g[n][a]=e<t?e:t}for(n=0;n<2*u-1;++n)r<n?g[r][n]=2:g[n][r]=2,o<n?g[o][n]=2:g[n][o]=2;let t=4;if(m[r].leaves.length<t*S&&m[o].leaves.length<t*S){m[a].leaves=[];for(let e=0,t=m[r].leaves.length;e<t;++e)for(let t=0,s=m[o].leaves.length;t<s;++t)m[a].leaves.push(m[r].leaves[e].concat(m[o].leaves[t])),m[a].leaves.push(m[o].leaves[t].concat(m[r].leaves[e]));m[r].leaves=[],m[o].leaves=[]}for(l in delete f[r],delete f[o],delete b[r],delete b[o],C=p.hashUtilsCls.cloneHash(f),C)C[l]!=r&&C[l]!=o||(delete f[l],f[l]=a);let s=2*u;for(d=2,n=0;n<2*u-1;++n)n!=a&&this.cbu_dist(a,n,g)<d&&(d=this.cbu_dist(a,n,g),s=n);f[a]=s,b[a]=d}return a==2*u-1&&(m[a-1].parent=-1,m[a-1].dist=0),m}GetChainMappings(e,t){this.icn3d.icn3dui;let s,i,n=[];t.length;let l=this.getClusters(e,!0).clusters,r=l.length;for(let e=0;e<r;++e){let r=l[e];for(let e=0,l=r.length;e<l;++e){let l={nodeArray:[]},o={},a={};for(let n=0,d=r[e].length;n<d;++n){let d=r[e][n],c=t[d].split(",");s=c[0],i=c[1],o.hasOwnProperty(s)||a.hasOwnProperty(i)||(l.nodeArray.push(d.toString().padStart(5,"0")),o[s]=1,a[i]=1)}n.push(l)}}return n}getClusters(e,t){this.icn3d.icn3dui;let s=[],i=[],n=0,l=e.length,r=t?0:1;for(;n<l;++n)e[n].leaves.length>r&&(s.push(e[n].leaves),i.push(e[n].dist));return{clusters:s,scores:i}}}class ps{constructor(e){this.icn3d=e}async applyCommand(e){let t=this.icn3d,s=t.icn3dui;t.bAddCommands=!1;let i=e.split("|||")[0].split("%7C%7C%7C")[0].replace(/\s+/g," ").trim(),n=i.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 s=""!==e;await t.shareLinkCls.shareLink(!0,s)}),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)s.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)s.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("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(" "),s=n.substr(e+1);"all"==s?t.annotationCls.hideAnnoTabAll():"custom"==s?t.annotationCls.hideAnnoTabCustom():"clinvar"==s?t.annotationCls.hideAnnoTabClinvar():"snp"==s?t.annotationCls.hideAnnoTabSnp():"cdd"==s?t.annotationCls.hideAnnoTabCdd():"3ddomain"==s?t.annotationCls.hideAnnoTab3ddomain():"site"==s?t.annotationCls.hideAnnoTabSite():"ptm"==s?t.annotationCls.hideAnnoTabPTM():"interaction"==s?t.annotationCls.hideAnnoTabInteraction():"ssbond"==s?t.annotationCls.hideAnnoTabSsbond():"crosslink"==s?t.annotationCls.hideAnnoTabCrosslink():"transmembrane"==s&&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 THREE.Vector3(1,0,0),s=.5*Math.PI;t.transformCls.setRotation(e,s)}else if("rotate y"==n){let e=new THREE.Vector3(0,1,0),s=.5*Math.PI;t.transformCls.setRotation(e,s)}else if("rotate z"==n){let e=new THREE.Vector3(0,0,1),s=.5*Math.PI;t.transformCls.setRotation(e,s)}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===s.cfg.mmdbid&&void 0===s.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=i.substr(e.length),l=n.indexOf(" "),r=n.substr(0,l).split(",");s.cfg.resdef=n.substr(l+1).replace(/:/gi,";"),await t.realignParserCls.realignChainOnSeqAlign(void 0,r,!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==i.indexOf("define helix sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"helix")}else if(0==i.indexOf("define sheet sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"sheet")}else if(0==i.indexOf("define coil sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineSecondary(e,"coil")}else if(0==i.indexOf("define iganchor sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"iganchor")}else if(0==i.indexOf("define igstrand sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igstrand")}else if(0==i.indexOf("define igloop sets")){let e=i.split(" | ")[1].split(" ")[1];t.addTrackCls.defineIgstrand(e,"igloop")}else if(0==i.indexOf("select interaction")){let e=i.substr(i.lastIndexOf(" ")+1).split(",");if(null!==e){let s=e[0].split("_")[0];t.b2DShown||t.ParserUtilsCls.download2Ddgm(s.toUpperCase()),t.diagram2dCls.selectInteraction(e[0],e[1])}}else if(0==i.indexOf("select saved atoms")||0==i.indexOf("select sets")){i=i.replace(/aligned_protein/g,"protein_aligned"),t.bDefinedSets||(t.definedSetsCls.setPredefinedInMenu(),t.bDefinedSets=!0);let e=i.split(" | "),s=e[0].replace(/,/g," or "),n=19;0==i.indexOf("select sets")&&(n=12);let l=s.substr(n),r=l;2==e.length&&(r=e[1].substr(5)),t.definedSetsCls.selectCombinedSets(l,r)}else if(-1!==i.indexOf("select chain")){let e=i.substr(i.lastIndexOf(" ")+1).split(",");for(let s=0,i=e.length;s<i;++s)t.selectionCls.selectAChain(e[s],e[s],!1)}else if(-1!==i.indexOf("select alignChain")){let e=i.substr(i.lastIndexOf(" ")+1).split(",");for(let s=0,i=e.length;s<i;++s)t.selectionCls.selectAChain(e[s],"align_"+e[s],!0)}else if(0==i.indexOf("select zone cutoff")){let e=this.getThresholdNameArrays(i);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",s.htmlCls.GREYD),$("#"+t.pre+"titlelink").css("color",s.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==i.indexOf("set thickness")){let e=n.split(" | ");t.bSetThickness=!0;for(let s=1,i=e.length;s<i;++s){let i=e[s].split(" "),n=i[0],l=parseFloat(i[1]);"linerad"!=n||isNaN(l)||(t.lineRadius=l),"coilrad"!=n||isNaN(l)||(t.coilWidth=l),"stickrad"!=n||isNaN(l)||(t.cylinderRadius=l),"crosslinkrad"!=n||isNaN(l)||(t.crosslinkRadius=l),"tracerad"!=n||isNaN(l)||(t.traceRadius=l),"ballscale"!=n||isNaN(l)||(t.dotSphereScale=l),"ribbonthick"!=n||isNaN(l)||(t.ribbonthickness=l),"proteinwidth"!=n||isNaN(l)||(t.helixSheetWidth=l),"nucleotidewidth"!=n||isNaN(l)||(t.nucleicAcidWidth=l)}t.drawCls.draw()}else if(0==i.indexOf("set light")){let e=n.split(" | ");for(let s=1,i=e.length;s<i;++s){let i=e[s].split(" "),n=i[0],l=parseFloat(i[1]);"light1"==n&&(t.light1=l),"light2"==n&&(t.light2=l),"light3"==n&&(t.light3=l)}t.drawCls.draw()}else if(0==i.indexOf("set shininess")){let e=n.lastIndexOf(" ");t.shininess=parseFloat(n.substr(e+1)),t.drawCls.draw()}else if(0==i.indexOf("set glycan")){let e=n.lastIndexOf(" ");t.bGlycansCartoon=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==i.indexOf("set membrane")){let e=n.lastIndexOf(" ");t.bMembrane=parseInt(n.substr(e+1)),t.drawCls.draw()}else if(0==i.indexOf("set cmdwindow")){let e=n.lastIndexOf(" "),t=parseInt(n.substr(e+1));s.htmlCls.setMenuCls.setLogWindow(!0,t)}else if(0==n.indexOf("set highlight color")){let e=n.substr(20);"yellow"===e?(t.hColor=s.parasCls.thr(16776960),t.matShader=t.setColorCls.setOutlineColor("yellow")):"green"===e?(t.hColor=s.parasCls.thr(65280),t.matShader=t.setColorCls.setOutlineColor("green")):"red"===e&&(t.hColor=s.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(" | "),s=e[1].split(" "),i=e[2].split(" "),l=e[3].substr(e[3].lastIndexOf(" ")+1),r="true"===e[4].substr(e[4].lastIndexOf(" ")+1),o=e[5].substr(e[5].lastIndexOf(" ")+1),a=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(s[1]),parseFloat(s[3]),parseFloat(s[5]),parseFloat(i[1]),parseFloat(i[3]),parseFloat(i[5]),l,r,o,parseFloat(a),parseFloat(d)),t.drawCls.draw()}else if(0==n.indexOf("add sphere"))this.addShape(i,"sphere"),t.shapeCmdHash[i]=1;else if(0==n.indexOf("add cube"))this.addShape(i,"cube"),t.shapeCmdHash[i]=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==i.indexOf("add label")){let e,n,l,r,o,a,d,c=i.split(" | "),h=c[0].substr("add label".length+1),p=!1;for(let t=1,s=c.length;t<s;++t){let s=c[t].split(" ");"x"==s[0]?(p=!0,e=parseFloat(s[1]),n=parseFloat(s[3]),l=parseFloat(s[5])):"size"==s[0]?r=c[t].substr(c[t].lastIndexOf(" ")+1):"color"==s[0]?o=c[t].substr(c[t].lastIndexOf(" ")+1):"background"==s[0]?a=c[t].substr(c[t].lastIndexOf(" ")+1):"type"==s[0]&&(d=c[t].substr(c[t].lastIndexOf(" ")+1))}if(!p){let i=t.applyCenterCls.centerAtoms(s.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms));e=parseFloat(i.center.x),n=parseFloat(i.center.y),l=parseFloat(i.center.z)}t.analysisCls.addLabel(h,e,n,l,r,o,a,d),t.drawCls.draw()}else if(0==i.indexOf("msa")){let e=i.split(" | ")[1].split(" ");t.targetGapHash={};for(let s=0,i=e.length;s<i;++s){let i=e[s].split("_");t.targetGapHash[parseInt(i[0])]={from:parseInt(i[1]),to:parseInt(i[2])}}await t.annotationCls.resetAnnoAll()}else if(0==i.indexOf("add track")){let e,s,n,l=i.split(" | "),r=l[1].substr(8),o=l[2].substr(6),a=l[3].substr(5);l.length>=5&&(e=l[4].substr(5)),l.length>=6&&(s=l[5].substr(6)),l.length>=7&&(n=l[6].substr(4)),$("#"+t.pre+"anno_custom")[0]&&($("#"+t.pre+"anno_custom")[0].checked=!0),$("[id^="+t.pre+"custom]").show(),"0"==s&&(s=void 0),t.addTrackCls.checkGiSeq(r,o,a,e,s,n,0)}else if(0==n.indexOf("remove one stabilizer")){let e=n.split(" | ")[1].split(" "),s=[];s.push(parseInt(e[0])),s.push(parseInt(e[1])),t.threeDPrintCls.removeOneStabilizer(s),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 s=parseFloat(e[3]),i=parseFloat(e[4]);t.selectionCls.selectBtwPlanes(s,i)}}else if(0==n.indexOf("adjust membrane z-axis")){let e=n.split(" ");if(5==e.length){let s=parseFloat(e[3]),i=parseFloat(e[4]);t.selectionCls.adjustMembrane(s,i)}}else if(0==n.indexOf("toggle membrane"))t.selectionCls.toggleMembrane();else if(0==i.indexOf("calc buried surface")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),i=s[1].split(",");t.analysisCls.calcBuriedSurface(e,i)}}}else if(0==i.indexOf("dist ")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(" ");if(2==s.length){let e=s[0].split(","),i=s[1].split(",");t.analysisCls.measureDistTwoSets(e,i)}}}else if(0==i.indexOf("disttable")){let e=i.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),n=i[1].split(",");t.analysisCls.measureDistManySets(e,n),s.htmlCls.dialogCls.openDlg("dl_disttable","Distances among the sets")}}}else if(0==i.indexOf("angletable")){let e=i.split(" | ");if(2==e.length){let i=e[1].split(" ");if(2==i.length){let e=i[0].split(","),n=i[1].split(",");t.analysisCls.measureAngleManySets(e,n),s.htmlCls.dialogCls.openDlg("dl_angletable","Angles among the sets")}}}else if(0==i.indexOf("display interaction 3d")||0==i.indexOf("view interaction pairs")||0==i.indexOf("save1 interaction pairs")||0==i.indexOf("save2 interaction pairs")||0==i.indexOf("line graph interaction pairs")||0==i.indexOf("scatterplot interaction pairs")||0==i.indexOf("ligplot interaction pairs")){let e=i.split(" | ");if(e.length>=3){let s=e[1].split(" ");if(2==s.length){let n,l,r=s[0].split(","),o=s[1].split(","),a=-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"),m=-1!==e[2].indexOf("pi-stacking");if(e.length>=4&&(n="true"==e[3]),e.length>=5){let s=e[4].split(" ");s.length>=4&&($("#"+t.pre+"hbondthreshold").val(s[1]),$("#"+t.pre+"saltbridgethreshold").val(s[2]),$("#"+t.pre+"contactthreshold").val(s[3]),7==s.length&&($("#"+t.pre+"halogenthreshold").val(s[4]),$("#"+t.pre+"picationthreshold").val(s[5]),$("#"+t.pre+"pistackingthreshold").val(s[6])))}0==i.indexOf("display interaction 3d")?l="3d":0==i.indexOf("view interaction pairs")?l="view":0==i.indexOf("save1 interaction pairs")?l="save1":0==i.indexOf("save2 interaction pairs")?l="save2":0==i.indexOf("line graph interaction pairs")?l="linegraph":0==i.indexOf("scatterplot interaction pairs")?l="scatterplot":0==i.indexOf("ligplot interaction pairs")&&(l="ligplot"),await t.viewInterPairsCls.viewInteractionPairs(r,o,n,l,a,d,c,h,p,m)}}}else if(0==i.indexOf("export pairs")){let e=i.split(" | ");if(3==e.length){let i=e[1].split(" ");if(2==i.length){let n=i[0].split(","),l=i[1].split(","),r=e[2].split(" ")[1];t.showInterCls.pickCustomSphere(r,n,l,t.bSphereCalc),t.bSphereCalc=!0;let o=t.viewInterPairsCls.exportSpherePairs(),a=Object.keys(s.utilsCls.getHlStructures()).join(",");t.saveFileCls.saveFile(a+"_sphere_pairs.html","html",o)}}}else if(0==n.indexOf("graph label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+s.svgid+"_label").val(t),$("#"+s.svgid+" text").removeClass(),$("#"+s.svgid+" text").addClass(t)}else if(0==n.indexOf("cartoon label")){let e=n.lastIndexOf(" "),t=n.substr(e+1);$("#"+s.svgid_ct+"_label").val(t),$("#"+s.svgid_ct+" text").removeClass(),$("#"+s.svgid_ct+" text").addClass(t)}else if(0==n.indexOf("line graph scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.linegraphid+"_scale").val(i),$("#"+s.linegraphid).attr("width",(t.linegraphWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("scatterplot scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.scatterplotid+"_scale").val(i),$("#"+s.scatterplotid).attr("width",(t.scatterplotWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("ligplot scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.ligplotid+"_scale").val(i),t.ligplotScale=parseFloat(i),$("#"+s.ligplotid).attr("width",(t.ligplotWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("contactmap scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.contactmapid+"_scale").val(i),$("#"+s.contactmapid).attr("width",(t.contactmapWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("alignerrormap scale")){let e=n.lastIndexOf(" "),i=n.substr(e+1);$("#"+s.alignerrormapid+"_scale").val(i),$("#"+s.alignerrormapid).attr("width",(t.alignerrormapWidth*parseFloat(i)).toString()+"px")}else if(0==n.indexOf("graph force")){let e=n.lastIndexOf(" ");s.htmlCls.force=parseInt(n.substr(e+1)),$("#"+s.svgid+"_force").val(s.htmlCls.force),t.getGraphCls.handleForce()}else if(0==n.indexOf("hide edges")){let e=n.lastIndexOf(" ");s.htmlCls.hideedges=parseInt(n.substr(e+1)),$("#"+s.svgid+"_hideedges").val(s.htmlCls.hideedges),s.htmlCls.hideedges?(s.htmlCls.contactInsideColor="FFF",s.htmlCls.hbondInsideColor="FFF",s.htmlCls.ionicInsideColor="FFF"):(s.htmlCls.contactInsideColor="DDD",s.htmlCls.hbondInsideColor="AFA",s.htmlCls.ionicInsideColor="8FF"),void 0!==t.graphStr&&t.bRender&&s.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==i.indexOf("your note")){let e=i.split(" | ");t.yournote=e[1],$("#"+t.pre+"yournote").val(t.yournote),s.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 s=parseFloat(e[1].split(" ")[1]),i=e[2].split(" ")[1];await t.contactMapCls.contactMap(s,i)}}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==i.indexOf("set color spectrum")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!0;t.setColorCls.setColorAcrossSets(s,i)}}else if(0==i.indexOf("set residues color spectrum")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!0;t.setColorCls.setColorBySets(s,i)}}else if(0==i.indexOf("set color rainbow")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!1;t.setColorCls.setColorAcrossSets(s,i)}}else if(0==i.indexOf("set residues color rainbow")){let e=i.split(" | ");if(2==e.length){let s=e[1].split(","),i=!1;t.setColorCls.setColorBySets(s,i)}}else if(0==i.indexOf("color")){let e=i.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()]=s.parasCls.thr("#"+t.customResidueColors[e])}else if("align custom"==n&&3==e.length){let s=e[1],i=e[2].split(", ");t.queryresi2score={},t.queryresi2score[s]={};for(let e=0,n=i.length;e<n;++e){let n=i[e].split(" ");t.queryresi2score[s][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==i.indexOf("remove legend"))$("#"+s.pre+"legend").hide();else if(0==i.indexOf("custom tube")){let e=i.split(" | ");this.setQueryresi2score(e),t.setOptionCls.setStyle("proteins","custom tube")}else if(0==n.indexOf("style")){let e=n.substr(n.indexOf(" ")+1),s=e.substr(0,e.indexOf(" ")),i=e.substr(e.indexOf(" ")+1);t.setOptionCls.setStyle(s,i)}else if(0==n.indexOf("window")){let e=n.substr(n.indexOf(" ")+1);setTimeout((function(){"aligned sequences"==e?s.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences"):"interaction table"==e?s.htmlCls.dialogCls.openDlg("dl_allinteraction","Show interactions"):"interaction graph"==e?s.htmlCls.dialogCls.openDlg("dl_linegraph","Show interactions between two lines of residue nodes"):"interaction scatterplot"==e?s.htmlCls.dialogCls.openDlg("dl_scatterplot","Show interactions as scatterplot"):"force-directed graph"==e&&s.htmlCls.dialogCls.openDlg("dl_graph","Force-directed graph")}),1e3)}else if(0==n.indexOf("set theme")){let e=n.substr(n.lastIndexOf(" ")+1);s.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,s.htmlCls.clickMenuCls.setClashedResidues(),t.annoDomainCls.showHideClashedResidues())}else if(0==n.indexOf("save html")){let e=n.substr(n.lastIndexOf(" ")+1);s.htmlCls.eventsCls.saveHtml(e)}else if(0==n.indexOf("resdef"))s.cfg.resdef=n.substr(n.indexOf(" ")+1);else if(0==n.indexOf("vast_search_chainid")){t.chainidArray=i.substr(i.indexOf(" ")+1).split(",");let e=!0,s=!0;await t.realignParserCls.realignChainOnSeqAlign(void 0,t.chainidArray,e,s)}else if(0==n.indexOf("ig refnum off"))await t.refnumCls.hideIgRefNum();else if(0==n.indexOf("custom refnum")){let e=i.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(","),s=[];for(let t=0,i=e.length;t<i;++t)s.push(parseFloat(e[t]));t.transformCls.rotateCoord(t.hAtoms,s),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=s.hashUtilsCls.cloneHash(t.viewSelectionAtoms),t.hlUpdateCls.updateHlAll();else if(-1!==n.indexOf("select prop")){let e,s,n=i.split(" | "),l=n[0].substr("select prop".length+1);if(2==n.length){let t=n[1].split("_");e=t[0],s=t[1]}t.resid2specCls.selectProperty(l,e,s)}else if(-1!==n.indexOf("select each residue"))t.selectionCls.saveEachResiInSel();else if(0==n.indexOf("select")&&-1!==n.indexOf("name")){let e=i.split(" | "),s="",n="",l="";for(let t=0,i=e.length;t<i;++t){let i=e[t];-1!==i.indexOf("select")?s=i.substr(i.indexOf(" ")+1):-1!==i.indexOf("name")&&(n=i.substr(i.indexOf(" ")+1))}l=n,await t.selByCommCls.selectByCommand(s,n,l)}else if(-1!==n.indexOf("select $")||-1!==n.indexOf("select .")||-1!==n.indexOf("select :")||-1!==n.indexOf("select %")||-1!==n.indexOf("select @")){let e=i.split(" | "),s=e[0].substr(e[0].indexOf(" ")+1),n="",l="";e.length>1&&(n=e[1].substr(e[1].indexOf(" ")+1)),e.length>2&&(l=e[2].substr(e[2].indexOf(" ")+1)),-1!==s.indexOf(" or ")?await t.selByCommCls.selectByCommand(s,n,l):await t.selByCommCls.selectBySpec(s,n,l)}s.htmlCls.clickMenuCls.setLogCmd(i,!1),t.bAddCommands=!0}setStrengthPara(e){let t=this.icn3d;if(t.icn3dui,e.length>=5){let s=e[4].split(" ");s.length>=4&&($("#"+t.pre+"hbondthreshold").val(s[1]),$("#"+t.pre+"saltbridgethreshold").val(s[2]),$("#"+t.pre+"contactthreshold").val(s[3]),s.length>=7&&($("#"+t.pre+"halogenthreshold").val(s[4]),$("#"+t.pre+"picationthreshold").val(s[5]),$("#"+t.pre+"pistackingthreshold").val(s[6])))}if(6==e.length){let s=e[5].split(" ");s.length>=6&&($("#"+t.pre+"dist_ss").val(s[0]),$("#"+t.pre+"dist_coil").val(s[1]),$("#"+t.pre+"dist_hbond").val(s[2]),$("#"+t.pre+"dist_inter").val(s[3]),$("#"+t.pre+"dist_ssbond").val(s[4]),$("#"+t.pre+"dist_ionic").val(s[5]),9==s.length&&($("#"+t.pre+"dist_halogen").val(s[6]),$("#"+t.pre+"dist_pication").val(s[7]),$("#"+t.pre+"dist_pistacking").val(s[8])))}}getThresholdNameArrays(e){this.icn3d.icn3dui.htmlCls.clickMenuCls.SetChainsAdvancedMenu();let t,s=e.split(" | "),i=parseFloat(s[0].substr(s[0].lastIndexOf(" ")+1)),n=[],l=[];if(s.length>=2&&s[1].length>4){let e=s[1].split(" ");e.length>1&&(l=e[1].split(",")),e.length>2&&(n=e[2].split(","))}else l=["selected"],n=["non-selected"];return 3==s.length&&(t="true"==s[2]),{threshold:i,nameArray2:l,nameArray:n,bHbondCalc:t}}setQueryresi2score(e){let t=this.icn3d,s=t.icn3dui,i=e[1],n=e[2].split(" ")[1].split("_"),l=e[3];void 0===t.queryresi2score&&(t.queryresi2score={}),t.queryresi2score[i]={};for(let e=parseInt(n[0]),s=0;e<=parseInt(n[1]);++e,++s)"_"!=l[s]&&(t.queryresi2score[i][e]=11.11111111111111*parseInt(l[s]));if(e.length>4){let i=e[4].split(" ");t.startColor=i[1],t.midColor=i[2],t.endColor=i[3];let n=s.htmlCls.clickMenuCls.setLegendHtml();$("#"+s.pre+"dl_legend_html").html(n),s.htmlCls.dialogCls.openDlg("dl_legend","Color Range")}}addShape(e,t){let s=this.icn3d,i=s.icn3dui,n=e.split(" | "),l=n[1].split(" "),r=n[2].substr(n[2].lastIndexOf(" ")+1),o=n[3].substr(n[3].lastIndexOf(" ")+1),a=n[4].substr(n[4].lastIndexOf(" ")+1);r="#"+r.replace(/\#/g,"");let d,c=i.parasCls.thr(r);if("x1"==l[0])d=new THREE.Vector3(parseFloat(l[1]),parseFloat(l[3]),parseFloat(l[5]));else{let e=n[1].split(","),t=s.definedSetsCls.getAtomsFromNameArray(e),i=s.contactCls.getExtent(t);d=new THREE.Vector3(i[2][0],i[2][1],i[2][2])}"sphere"==t?s.sphereCls.createSphereBase(d,c,parseFloat(a),void 0,void 0,void 0,parseFloat(o)):s.boxCls.createBox_base(d,parseFloat(a),c,void 0,void 0,void 0,parseFloat(o))}getMenuFromCmd(e){this.icn3d.icn3dui;let t="Windows > View Sequences & Annotations",s="Analysis > Interactions",i=s+" > 2D Graph(Force-Directed)",n="View > Rotate > Auto Rotation > Rotate ",l="View > Rotate > Rotate 90 deg > ",r="Select > Select on 3D > ",o="Analysis > Label > ",a="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")?s+" > 2D Graph(Force-Directed)":0==e.indexOf("export canvas")?"File > Save File > iCn3D PNG Image":"export stl file"==e?a+"STL":"export vrml file"==e?a+"VRML(Color)":"export stl stabilizer file"==e?a+"STL W/ Stabilizers":"export vrml stabilizer file"==e?a+"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?r+"Atom":"set pk residue"==e?r+"Residue":"set pk strand"==e?r+"Strand/Helix":"set pk domain"==e?r+"3D Domain":"set pk chain"==e?r+"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?s+" > 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?l+"X-axis":"rotate y"==e?l+"Y-axis":"rotate z"==e?l+"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?s+': "Set 1" button: "Show Count Only" button':"table inter details"==e?s+': "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")?s+': "Buried Surface Area" button':0==e.indexOf("display interaction 3d")?s+': "3D Display Interactions" button':0==e.indexOf("view interaction pairs")?s+': "Highlight Interactions in Table" button':0==e.indexOf("save1 interaction pairs")?s+': "Set 1" button':0==e.indexOf("save2 interaction pairs")?s+': "Set 2" button':0==e.indexOf("line graph interaction pairs")?s+': "2D Interaction Network" button':0==e.indexOf("scatterplot interaction pairs")?s+': "2D Interaction Map" button':0==e.indexOf("ligplot interaction pairs")?s+': "2D Interaction for One Ligand/Residue" button':0==e.indexOf("graph label")?i+': "Label Size" menu':0==e.indexOf("graph force")?i+': "Force on Nodes" menu':0==e.indexOf("hide edges")?i+': "Internal Edges" menu':0==e.indexOf("reset interaction pairs")?s+" > 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 ms{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={},s={};for(let i in e.chemicals){let n=e.atoms[i],l=n.structure+"_"+n.chain+"_"+n.resi;"DUM"===n.resn?s[l]=1:t[l]=1}Object.keys(t).length>0&&(e.defNames2Residues.chemicals=Object.keys(t),e.defNames2Descr.chemicals="chemicals",e.defNames2Command.chemicals="select :chemicals"),Object.keys(s).length>0&&(e.defNames2Residues.membrane=Object.keys(s),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.setChainsInMenu(),this.setProtNuclLigInMenu(),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 s={};for(let i in e.alnChains)s=t.hashUtilsCls.unionHash(s,e.alnChains[i]);let i=e.firstAtomObjCls.getResiduesFromAtoms(s),n="protein_aligned",l="aligned protein and nucleotides",r="select "+e.resid2specCls.residueids2spec(Object.keys(i));e.selectionCls.addCustomSelection(Object.keys(i),n,l,r,!0)}}setAtomMenu(e){let t=this.icn3d;t.icn3dui;let s="",i=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues):[],n=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms):[],l=i.concat(n).sort(),r=[];l.forEach((e=>{-1===$.inArray(e,r)&&r.push(e)}));for(let i=0,n=r.length;i<n;++i){let n,l,o=r[i];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&&(l=t.residues[e[0]],l&&(n=t.atoms[Object.keys(l)[0]]))}let a=void 0===n||void 0===n.color||"FFFFFF"===n.color.getHexString().toUpperCase()?"DDDDDD":n.color.getHexString(),d=void 0!==n&&void 0!==n.color?a:"000000";-1!=e.indexOf(o)?s+="<option value='"+o+"' style='color:#"+d+"' selected='selected'>"+o+"</option>":s+="<option value='"+o+"' style='color:#"+d+"'>"+o+"</option>"}return s}setChainsInMenu(){let e=this.icn3d;e.icn3dui;for(let t in e.chains)if(e.chainsSeq[t]&&e.chainsSeq[t].length>1){e.defNames2Residues[t]=Object.keys(e.firstAtomObjCls.getResiduesFromAtoms(e.chains[t])),e.defNames2Descr[t]=t;let s=t.indexOf("_"),i=t.substr(0,s),n=t.substr(s+1);e.defNames2Command[t]="select $"+i+"."+n}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),s={};for(let e=0,i=t.length;e<i;++e){let i=t[e],n=i.indexOf("_"),l=i.substr(0,n);void 0===s[l]&&(s[l]=[]),s[l].push(i)}for(let t in s)e.defNames2Residues[t]=s[t],e.defNames2Descr[t]=t,e.defNames2Command[t]="select $"+t}}setTransmemInMenu(e,t,s){let i=this.icn3d;if(i.icn3dui,i.bOpm){let n={},l={},r={};for(let s in i.atoms){let o=i.atoms[s];if("DUM"===o.resn)continue;let a=o.structure+"_"+o.chain+"_"+o.resi;o.coord.z>e?l[a]=1:o.coord.z<t?r[a]=1:n[a]=1}let o=s?"2":"";Object.keys(n).length>0&&(i.defNames2Residues["transmembrane"+o]=Object.keys(n),i.defNames2Descr["transmembrane"+o]="transmembrane"+o,i.defNames2Command["transmembrane"+o]="select :transmembrane"+o),Object.keys(l).length>0&&(i.defNames2Residues["extracellular"+o]=Object.keys(l),i.defNames2Descr["extracellular"+o]="extracellular"+o,i.defNames2Command["extracellular"+o]="select :extracellular"+o),Object.keys(r).length>0&&(i.defNames2Residues["intracellular"+o]=Object.keys(r),i.defNames2Descr["intracellular"+o]="intracellular"+o,i.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 s=t.hashUtilsCls.cloneHash(e.hAtoms),i=t.hashUtilsCls.cloneHash(e.dAtoms);void 0!==e.bSetChainsAdvancedMenu&&e.bSetChainsAdvancedMenu&&!e.bResetSets||(this.setPredefinedInMenu(),e.bSetChainsAdvancedMenu=!0),e.hAtoms=t.hashUtilsCls.cloneHash(s),e.dAtoms=t.hashUtilsCls.cloneHash(i),e.hlUpdateCls.updateHlMenus()}clickCustomAtoms(){let e=this.icn3d,t=e.icn3dui,s=this;$("#"+e.pre+"atomsCustom").change((function(e){let i=s.icn3d,n=$(this).val();if(i.nameArray=n,null!==n){let e=!1;s.changeCustomAtoms(n,e),t.htmlCls.clickMenuCls.setLogCmd("select sets "+n.join(" "+i.setOperation+" "),!0),i.bSelectResidue=!1}})),t.myEventCls.onIds("#"+e.pre+"atomsCustom","focus",(function(e){let i=s.icn3d;t.utilsCls.isMobile()&&$("#"+i.pre+"atomsCustom").val("")}))}deleteSelectedSets(){let e=this.icn3d;e.icn3dui;let t=$("#"+e.pre+"atomsCustom").val();for(let s=0;s<t.length;++s){let i=t[s];(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(i)||void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(i))&&(void 0!==e.defNames2Atoms&&e.defNames2Atoms.hasOwnProperty(i)&&delete e.defNames2Atoms[i],void 0!==e.defNames2Residues&&e.defNames2Residues.hasOwnProperty(i)&&delete e.defNames2Residues[i])}e.hlUpdateCls.updateHlMenus()}changeCustomAtoms(e,t){let s=this.icn3d,i=s.icn3dui;s.hAtoms={};for(let t=0;t<e.length;++t){let n=e[t];if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(n)||void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(n)){if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(n)){let e=s.defNames2Atoms[n];for(let t=0,i=e.length;t<i;++t)s.hAtoms[e[t]]=1}if(void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(n)){let e=s.defNames2Residues[n],t={};for(let n=0,l=e.length;n<l;++n)t=i.hashUtilsCls.unionHash(t,s.residues[e[n]]);s.hAtoms=i.hashUtilsCls.unionHash(s.hAtoms,t)}}}s.hlUpdateCls.updateHlAll(e,t),s.annotationCls.showAnnoSelectedChains(),$("#"+s.pre+"command").val(""),$("#"+s.pre+"command_name").val("");for(let t=0,i=e.length;t<i;++t)if(s.defNames2Atoms[e[t]],s.defNames2Residues[e[t]],s.defNames2Descr[e[t]],0===t)$("#"+s.pre+"command").val("saved atoms "+e[t]),$("#"+s.pre+"command_name").val(e[t]);else{let i=$("#"+s.pre+"command").val();$("#"+s.pre+"command").val(i+" "+s.setOperation+" "+e[t]),i=$("#"+s.pre+"command_name").val(),$("#"+s.pre+"command_name").val(i+" "+s.setOperation+" "+e[t])}}setHAtomsFromSets(e,t){let s=this.icn3d,i=s.icn3dui;for(let n=0;n<e.length;++n){let l=e[n];if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(l)||void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(l)){if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(l)){let e=s.defNames2Atoms[l];if("or"===t)for(let t=0,i=e.length;t<i;++t)s.hAtoms[e[t]]=1;else if("and"===t){let t={};for(let s=0,i=e.length;s<i;++s)t[e[s]]=1;s.hAtoms=i.hashUtilsCls.intHash(s.hAtoms,t)}else if("not"===t){let t={};for(let s=0,i=e.length;s<i;++s)t[e[s]]=1;s.hAtoms=i.hashUtilsCls.exclHash(s.hAtoms,t)}}if(void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(l)){let e=s.defNames2Residues[l],n={};for(let t=0,l=e.length;t<l;++t)n=i.hashUtilsCls.unionHash(n,s.residues[e[t]]);"or"===t?s.hAtoms=i.hashUtilsCls.unionHash(s.hAtoms,n):"and"===t?s.hAtoms=i.hashUtilsCls.intHash(s.hAtoms,n):"not"===t&&(s.hAtoms=i.hashUtilsCls.exclHash(s.hAtoms,n))}}}}updateAdvancedCommands(e,t){let s=this.icn3d;s.icn3dui;let i=" "+t+" ";for(let n=0,l=e.length;n<l;++n)if(0===n&&"or"==t)$("#"+s.pre+"command").val("saved atoms "+e[n]),$("#"+s.pre+"command_name").val(e[n]);else{let t=$("#"+s.pre+"command").val();$("#"+s.pre+"command").val(t+i+e[n]),t=$("#"+s.pre+"command_name").val(),$("#"+s.pre+"command_name").val(t+i+e[n])}}combineSets(e,t,s,i){let n=this.icn3d,l=n.icn3dui;if(n.hAtoms={},this.setHAtomsFromSets(e,"or"),0==Object.keys(n.hAtoms).length&&(n.hAtoms=l.hashUtilsCls.cloneHash(n.dAtoms)),this.setHAtomsFromSets(t,"and"),this.setHAtomsFromSets(s,"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(s,"not"),void 0!==i){let e="select "+$("#"+n.pre+"command").val();$("#"+n.pre+"command_name").val(i),n.selectionCls.addCustomSelection(Object.keys(n.hAtoms),i,i,e,!1)}}async commandSelect(e){let t=this.icn3d,s=t.icn3dui,i=$("#"+t.pre+"command"+e).val(),n=$("#"+t.pre+"command_name"+e).val().replace(/;/g,"_").replace(/\s+/g,"_");i&&(await t.selByCommCls.selectByCommand(i,n,n),s.htmlCls.clickMenuCls.setLogCmd("select "+i+" | name "+n,!0))}clickCommand_apply(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+e.pre+"command_apply","click",(async function(e){s.icn3d,e.preventDefault(),await s.commandSelect("")})),t.myEventCls.onIds("#"+e.pre+"command_apply2","click",(async function(e){s.icn3d,e.preventDefault(),await s.commandSelect("2")}))}selectCombinedSets(e,t){this.icn3d.icn3dui;let s=e.split(" "),i=[],n=[],l=[],r="or";for(let e=0,t=s.length;e<t;++e){let t=s[e].split("_");if(3!=t.length||isNaN(t[2])||(s[e]=t[0]+"_"+t[1]+t[2]),"or"!==s[e]&&"and"!==s[e]&&"not"!==s[e]){let t=["hbonds_","saltbridge_","halogen_","pi-cation_","pi-stacking_"];for(let i=0,n=t.length;i<n;++i){const n=new RegExp("^"+t[i]+"\\d+$");s[e].match(n)&&(s[e]=t[i]+"auto")}"or"===r?i.push(s[e]):"and"===r?n.push(s[e]):"not"===r&&l.push(s[e])}else r=s[e]}null!==s&&this.combineSets(i,n,l,t)}clickModeswitch(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+e.pre+"modeswitch","click",(function(t){void 0!==$("#"+e.pre+"modeswitch")[0]&&$("#"+e.pre+"modeswitch")[0].checked?s.setModeAndDisplay("selection"):s.setModeAndDisplay("all")}))}setModeAndDisplay(e){let t=this.icn3d,s=t.icn3dui;"all"===e?(this.setMode("all"),t.prevHighlightAtoms=s.hashUtilsCls.cloneHash(t.hAtoms),s.htmlCls.clickMenuCls.setLogCmd("set mode all",!0),t.selectionCls.selectAll(),t.drawCls.draw()):(this.setMode("selection"),void 0!==t.prevHighlightAtoms?t.hAtoms=s.hashUtilsCls.cloneHash(t.prevHighlightAtoms):t.selectionCls.selectAll(),s.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,s=t.icn3dui,i={};if(void 0===t.defNames2Residues.proteins&&this.showSets(),-1!==Object.keys(t.chains).indexOf(e))i=s.hashUtilsCls.unionHash(i,t.chains[e]);else{if(void 0!==t.defNames2Residues[e]&&t.defNames2Residues[e].length>0)for(let n=0,l=t.defNames2Residues[e].length;n<l;++n){let l=t.defNames2Residues[e][n];i=s.hashUtilsCls.unionHash(i,t.residues[l])}if(void 0!==t.defNames2Atoms[e]&&t.defNames2Atoms[e].length>0)for(let s=0,n=t.defNames2Atoms[e].length;s<n;++s){i[t.defNames2Atoms[e][s]]=1}}return i}getAtomsFromNameArray(e){let t=this.icn3d,s=t.icn3dui,i={};for(let n=0,l=e.length;n<l;++n)if("non-selected"===e[n]){let e={};for(let s in t.atoms)!t.hAtoms.hasOwnProperty(s)&&t.dAtoms.hasOwnProperty(s)&&(e[s]=t.atoms[s]);i=s.hashUtilsCls.unionHash(i,e)}else i="selected"===e[n]?s.hashUtilsCls.unionHash(i,s.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)):s.hashUtilsCls.unionHash(i,s.hashUtilsCls.hash2Atoms(this.getAtomsFromOneSet(e[n]),t.atoms));return 0==e.length&&(i=t.atoms),i}}class us{constructor(e){this.icn3d=e}setAtomMenu(e,t){let s=this.icn3d;s.icn3dui;let i="",n=[e[0]];for(let l=0,r=e.length;l<r;++l){let r,o=e[l],a=t[l];if(void 0!==s.defNames2Atoms&&s.defNames2Atoms.hasOwnProperty(o)){let e=s.defNames2Atoms[o];e.length>0&&s.atoms[e[0]]}else if(void 0!==s.defNames2Residues&&s.defNames2Residues.hasOwnProperty(o)){let e=s.defNames2Residues[o];e.length>0&&(r=s.residues[e[0]],r&&s.atoms[Object.keys(r)[0]])}-1!=n.indexOf(o)?i+="<option value='"+o+"' selected='selected'>"+a+"</option>":i+="<option value='"+o+"'>"+a+"</option>"}return 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 s={};for(let i in t)i in e||(s[i]=t[i]);return s}clickStructure(){let e=this.icn3d,t=e.icn3dui,s=this;null==e.allData&&(e.allData={},e.allData.all={atoms:{},proteins:{},nucleotides:{},chemicals:{},ions:{},water:{},structures:{},ssbondpnts:{},residues:{},chains:{},chainsSeq:{},defNames2Atoms:{},defNames2Residues:{}},e.allData.prev={}),$("#"+e.pre+"collections_menu").change((async function(e){let i=s.icn3d,n=$(this).val(),l=$(this).find("option:selected").text();if(i.nameArray=n,null!==n){let e=!0;s.reset();for(const t of n)t in i.allData||(i.allData.prev=JSON.parse(JSON.stringify(i.allData.all)),i.atoms=i.allData.all.atoms,i.proteins=i.allData.all.proteins,i.nucleotides=i.allData.all.nucleotides,i.chemicals=i.allData.all.chemicals,i.ions=i.allData.all.ions,i.water=i.allData.all.water,i.structures=i.allData.all.structures,i.ssbondpnts=i.allData.all.ssbondpnts,i.residues=i.allData.all.residues,i.chains=i.allData.all.chains,i.chainsSeq=i.allData.all.chainsSeq,i.defalls2Atoms=i.allData.all.defalls2Atoms,i.defalls2Residues=i.allData.all.defalls2Residues,await i.chainalignParserCls.downloadMmdbAf(t,void 0,void 0,e).then((()=>{i.allData.all={atoms:i.atoms,proteins:i.proteins,nucleotides:i.nucleotides,chemicals:i.chemicals,ions:i.ions,water:i.water,structures:i.structures,ssbondpnts:i.ssbondpnts,residues:i.residues,chains:i.chains,chainsSeq:i.chainsSeq,defNames2Atoms:i.defNames2Atoms,defNames2Residues:i.defNames2Residues},i.allData[t]={atoms:s.dictionaryDifference(i.allData.prev.atoms,i.atoms),proteins:s.dictionaryDifference(i.allData.prev.proteins,i.proteins),nucleotides:s.dictionaryDifference(i.allData.prev.nucleotides,i.nucleotides),chemicals:s.dictionaryDifference(i.allData.prev.chemicals,i.chemicals),ions:s.dictionaryDifference(i.allData.prev.ions,i.ions),water:s.dictionaryDifference(i.allData.prev.water,i.water),structures:s.dictionaryDifference(i.allData.prev.structures,i.structures),ssbondpnts:s.dictionaryDifference(i.allData.prev.ssbondpnts,i.ssbondpnts),residues:s.dictionaryDifference(i.allData.prev.residues,i.residues),chains:s.dictionaryDifference(i.allData.prev.chains,i.chains),chainsSeq:s.dictionaryDifference(i.allData.prev.chainsSeq,i.chainsSeq),defNames2Atoms:s.dictionaryDifference(i.allData.prev.defNames2Atoms,i.defNames2Atoms),defNames2Residues:s.dictionaryDifference(i.allData.prev.defNames2Residues,i.defNames2Residues)},s.reset()})));for(const e of n)i.atoms=Object.assign(i.atoms,i.allData[e].atoms),i.proteins=Object.assign(i.proteins,i.allData[e].proteins),i.nucleotides=Object.assign(i.nucleotides,i.allData[e].nucleotides),i.chemicals=Object.assign(i.chemicals,i.allData[e].chemicals),i.ions=Object.assign(i.ions,i.allData[e].ions),i.water=Object.assign(i.water,i.allData[e].water),i.structures=Object.assign(i.structures,i.allData[e].structures),i.ssbondpnts=Object.assign(i.ssbondpnts,i.allData[e].ssbondpnts),i.residues=Object.assign(i.residues,i.allData[e].residues),i.chains=Object.assign(i.chains,i.allData[e].chains),i.chainsSeq=Object.assign(i.chainsSeq,i.allData[e].chainsSeq),i.defNames2Atoms=Object.assign(i.defNames2Atoms,i.allData[e].defNames2Atoms),i.defNames2Residues=Object.assign(i.defNames2Residues,i.allData[e].defNames2Residues),i.dAtoms=t.hashUtilsCls.cloneHash(i.atoms),i.hAtoms=t.hashUtilsCls.cloneHash(i.atoms);i.opts.color=1==Object.keys(i.structures).length?"chain":"structure",i.setColorCls.setColorByOptions(i.opts,i.atoms),i.transformCls.zoominSelection(),i.definedSetsCls.showSets(),i.bResetAnno=!0,i.bAnnoShown&&(await i.showAnnoCls.showAnnotations(),i.hlUpdateCls.updateHlAll(n),i.annotationCls.showAnnoSelectedChains()),await i.drawCls.draw(),i.saveFileCls.showTitle(),t.htmlCls.clickMenuCls.setLogCmd("select structure ["+l+"]",!0)}})),t.myEventCls.onIds("#"+e.pre+"collections_menu","focus",(function(e){let i=s.icn3d;t.utilsCls.isMobile()&&$("#"+i.pre+"collections_menu").val("")}))}}class gs{constructor(e){this.icn3d=e}async loadScript(e,t,s){let i=this.icn3d;if(i.icn3dui,!e)return;i.bCommandLoad=!0,i.bRender=!1,i.bStopRotate=!0,e=t?e.replace(/\+/g," "):e.replace(/\+/g," ").replace(/;/g,"\n");let n=[];!s&&i.commands.length>0&&(n[0]=i.commands[0]);let l=e.trim().split("\n");i.commands=l;let r=l[0].indexOf("command=");if(t&&-1!=r){let e=l[0].substr(0,r-1);i.commands.splice(0,1,e)}i.STATENUMBER=i.commands.length,i.commands=n.concat(i.commands),i.STATENUMBER=i.commands.length,i.CURRENTNUMBER=0,i.bReplay?await this.replayFirstStep(i.CURRENTNUMBER):await this.execCommands(i.CURRENTNUMBER,i.STATENUMBER-1,i.STATENUMBER,s)}async execCommands(e,t,s,i){let n=this.icn3d;n.icn3dui,n.bRender=!1,i||n.reinitAfterLoad(),await this.execCommandsBase(e,t,s)}getNameArray(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | "),i=[];return 2==s.length&&(i=s[1].split(","),t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(i)),i}updateTransformation(e){let t=this.icn3d;t.icn3dui;let s=t.commands[e-1]?t.commands[e-1].split("|||"):[];if(2==s.length){let e=JSON.parse(s[1]);t._zoomFactor=e.factor,t.mouseChange.x=e.mouseChange.x,t.mouseChange.y=e.mouseChange.y,t.quaternion._x=e.quaternion._x,t.quaternion._y=e.quaternion._y,t.quaternion._z=e.quaternion._z,t.quaternion._w=e.quaternion._w}t.drawCls.draw()}async execCommandsBase(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=this;for(n=e;n<=t;++n){let i=n===s-1;if(!l.commands[n]||!l.commands[n].trim())continue;if(0==(l.atoms?Object.keys(l.atoms).length:0)&&-1==l.commands[n].indexOf("load"))continue;let a=l.commands[n].split("|||"),d=a[0].trim();if(-1!==d.indexOf("load")){if(0===t&&e===t)return void(l.bNotLoadStructure?(l.hAtoms=r.hashUtilsCls.cloneHash(l.atoms),1===l.commands.length&&(l.bAddCommands=!0),i&&this.renderFinalStep(s)):(await o.applyCommandLoad(l.commands[n]),1===l.commands.length&&(l.bAddCommands=!0),i&&o.renderFinalStep(s)));l.bNotLoadStructure?(l.hAtoms=r.hashUtilsCls.cloneHash(l.atoms),l.backForward&&this.renderFinalStep(1)):(await o.applyCommandLoad(l.commands[n]),l.backForward&&o.renderFinalStep(1))}else if(0==d.indexOf("set map")&&-1==d.indexOf("set map wireframe"))await o.applyCommandMap(a[0].trim());else if(0==d.indexOf("set emmap")&&-1==d.indexOf("set emmap wireframe")){let e=a[0].trim().substr(10).split(" ");2==e.length&&"percentage"==e[0]&&(e[1],await o.applyCommandEmmap(a[0].trim()))}else if(0==d.indexOf("set phi"))await l.delphiCls.applyCommandPhi(a[0].trim());else if(0==d.indexOf("set delphi"))await l.delphiCls.applyCommandDelphi(a[0].trim());else if(0==d.indexOf("view annotations"))Object.keys(l.proteins).length>0&&await o.applyCommandAnnotationsAndCddSite(a[0].trim());else if(0==d.indexOf("set annotation clinvar"))Object.keys(l.proteins).length>0&&await o.applyCommandClinvar(a[0].trim());else if(0==d.indexOf("set annotation snp"))Object.keys(l.proteins).length>0&&await o.applyCommandSnp(a[0].trim());else if(0==d.indexOf("set annotation ptm"))Object.keys(l.proteins).length>0&&await o.applyCommandPTM(a[0].trim());else if(0==d.indexOf("ig template")){let e=d.substr(d.lastIndexOf(" ")+1);await r.htmlCls.clickMenuCls.setIgTemplate(e)}else if(0==d.indexOf("set annotation 3ddomain"))Object.keys(l.proteins).length>0&&o.applyCommand3ddomain(a[0].trim());else if(0==d.indexOf("set annotation all"))Object.keys(l.proteins).length>0&&(await o.applyCommandClinvar(a[0].trim()),await o.applyCommandSnp(a[0].trim()),o.applyCommand3ddomain(a[0].trim())),await l.annotationCls.setAnnoTabAll();else if(0==d.indexOf("view interactions")&&void 0!==r.cfg.align)await o.applyCommandViewinteraction(a[0].trim());else if(0==d.indexOf("symmetry")){l.bAxisOnly=!1;let e=d.substr(d.indexOf(" ")+1);l.symmetrytitle="none"===e?void 0:e,"none"!==e&&await l.symdCls.retrieveSymmetry(Object.keys(l.structures)[0]),l.drawCls.draw()}else if(0==d.indexOf("symd symmetry"))l.bAxisOnly=!1,await l.symdCls.applyCommandSymd(d),l.drawCls.draw();else if(0==d.indexOf("scap"))await l.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);r.cfg.aligntool="vast",await l.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on structure align"))this.getNameArray(d),r.cfg.aligntool="vast",await l.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on tmalign msa")){let e=this.getNameArray(d);r.cfg.aligntool="tmalign",await l.realignParserCls.realignOnStructAlignMsa(e)}else if(0==d.indexOf("realign on tmalign"))this.getNameArray(d),r.cfg.aligntool="tmalign",await l.realignParserCls.realignOnStructAlign();else if(0==d.indexOf("realign on vastplus"))o.getHAtoms(l.commands[n]),await l.vastplusCls.realignOnVastplus();else if(0==d.indexOf("graph interaction pairs"))await o.applyCommandGraphinteraction(d);else if(0==d.indexOf("cartoon 2d domain"))l.bRender=!0,o.updateTransformation(s),await o.applyCommandCartoon2d(d),l.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 r.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);l.bRender=!0,o.updateTransformation(s),await l.cartoon2dCls.draw2Dcartoon(t),l.bRender=!1}else if(0==d.indexOf("add msa track")){let e=d.split(" | "),t=e[1].substr(8),s=e[2].substr(9),i=e[3].substr(5),n=e[4].substr(10);$("#"+l.pre+"anno_custom")[0]&&($("#"+l.pre+"anno_custom")[0].checked=!0),$("[id^="+l.pre+"custom]").show(),await l.addTrackCls.addMsaTracks(t,s,i,n)}else if(0==d.indexOf("add exon track")){let e=d.split(" | "),t=e[1].substr(8),s=e[2].substr(7),i=parseInt(e[3].substr(9)),n=e[4].substr(5);$("#"+l.pre+"anno_custom")[0]&&($("#"+l.pre+"anno_custom")[0].checked=!0),$("[id^="+l.pre+"custom]").show(),await l.addTrackCls.addExonTracks(t,s,i,n)}else await l.applyCommandCls.applyCommand(l.commands[n])}(n===s||i)&&this.renderFinalStep(n)}pressCommandtext(){let e=this.icn3d,t=e.icn3dui,s=this;$("#"+e.pre+"logtext").keypress((async function(e){let i=s.icn3d;if(i.bAddLogs=!1,13==(e.keyCode?e.keyCode:e.which)){e.preventDefault();let n=$(this).val();i.bRender=!0;let l=n.split("\n"),r=i.logs.length;for(let e=r,n=l.length;e<n;++e){let n=e==r?l[e].substr(2).trim():l[e].trim();if(""===n)continue;i.logs.push(n);let o={};if(o.factor=i._zoomFactor,o.mouseChange=i.mouseChange,o.quaternion=i.quaternion,i.commands.push(n+"|||"+i.transformCls.getTransformationStr(o)),i.optsHistory.push(t.hashUtilsCls.cloneHash(i.opts)),i.optsHistory[i.optsHistory.length-1].hlatomcount=Object.keys(i.hAtoms).length,t.utilsCls.isSessionStorageSupported()&&i.setStyleCls.saveCommandsToSession(),i.STATENUMBER=i.commands.length,-1!==n.indexOf("load"))await s.applyCommandLoad(n);else if(-1!==n.indexOf("set map")&&-1===n.indexOf("set map wireframe"))await s.applyCommandMap(n);else if(-1!==n.indexOf("set emmap")&&-1===n.indexOf("set emmap wireframe"))await s.applyCommandEmmap(n);else if(-1!==n.indexOf("set phi"))await i.delphiCls.applyCommandPhi(n);else if(-1!==n.indexOf("set delphi"))await i.delphiCls.applyCommandDelphi(n);else if(0==n.indexOf("view annotations"))await s.applyCommandAnnotationsAndCddSite(n);else if(0==n.indexOf("set annotation clinvar"))await s.applyCommandClinvar(n);else if(0==n.indexOf("set annotation snp"))await s.applyCommandSnp(n);else if(0==n.indexOf("set annotation ptm"))await s.applyCommandPTM(n);else if(0==n.indexOf("ig refnum on"))i.bRunRefnumAgain=!0,i.bAnnoShown||await i.showAnnoCls.showAnnotations(),await i.annotationCls.setAnnoTabIg(!0),i.bRunRefnumAgain=!1;else if(0==n.indexOf("set annotation 3ddomain"))s.applyCommand3ddomain(n);else if(0==n.indexOf("set annotation all"))await s.applyCommandClinvar(n),await s.applyCommandSnp(n),s.applyCommand3ddomain(n),await i.annotationCls.setAnnoTabAll();else if(0==n.indexOf("view interactions")&&void 0!==t.cfg.align)await s.applyCommandViewinteraction(n);else if(0==n.indexOf("symmetry")){let e=n.substr(n.indexOf(" ")+1);i.symmetrytitle="none"===e?void 0:e,"none"!==e&&void 0===i.symmetryHash&&await i.symdCls.retrieveSymmetry(Object.keys(i.structures)[0])}else if(0==n.indexOf("symd symmetry"))await i.symdCls.applyCommandSymd(n);else if(0==n.indexOf("scap "))await i.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(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}await s.applyCommandRealign(n)}else if(0==n.indexOf("realign on structure align")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="vast",await s.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on tmalign")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}t.cfg.aligntool="tmalign",await s.applyCommandRealignByStruct(n)}else if(0==n.indexOf("realign on vastplus")){let e=n.split(" | ");if(2==e.length){let t=e[1].split(",");i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(t)}await i.vastplusCls.realignOnVastplus()}else 0==n.indexOf("graph interaction pairs")?await s.applyCommandGraphinteraction(n):await i.applyCommandCls.applyCommand(n+"|||"+i.transformCls.getTransformationStr(o))}i.selectionCls.saveSelectionIfSelected(),i.drawCls.draw(),$("#"+i.pre+"logtext").val("> "+i.logs.join("\n> ")+"\n> ").scrollTop($("#"+i.pre+"logtext")[0].scrollHeight)}i.bAddLogs=!0}))}async applyCommandLoad(e){let t=this.icn3d,s=t.icn3dui;t.bAddCommands=!1;let i=e.split("|||")[0].replace(/\s\s/g," ").trim();if(-1!==i.indexOf("load")){let e=i.split(" | "),n=e[0];if(e.length>1&&!s.cfg.inpara){let t=e[e.length-1].indexOf(" ");s.cfg.inpara=e[e.length-1].substr(t+1),"undefined"===s.cfg.inpara&&(s.cfg.inpara="")}let l=n.substr(n.lastIndexOf(" ")+1);4==l.length&&(l=l.toUpperCase());let r=l.split(","),o="";for(let e=0,s=r.length;e<s;++e)t.structures&&(t.structures.hasOwnProperty(r[e])||t.structures.hasOwnProperty(r[e].toLowerCase())||t.structures.hasOwnProperty(r[e].toUpperCase()))||(o&&(o+=","),o+=r[e]);if(l=o,t.bInputPNGWithData||!l)return;if(t.inputid=l,-1!==i.indexOf("load mmtf"))s.cfg.mmtfid=l,await t.bcifParserCls.downloadBcif(l);else if(-1!==i.indexOf("load bcif"))s.cfg.bcifid=l,await t.bcifParserCls.downloadBcif(l);else if(-1!==i.indexOf("load pdb"))s.cfg.pdbid=l,await t.pdbParserCls.downloadPdb(l);else if(-1!==i.indexOf("load af"))s.cfg.afid=l,await t.pdbParserCls.downloadPdb(l,!0);else if(-1!==i.indexOf("load opm"))s.cfg.opmid=l,await t.opmParserCls.downloadOpm(l);else if(-1!==i.indexOf("load mmcif"))s.cfg.mmcifid=l,await t.mmcifParserCls.downloadMmcif(l);else if(-1!==i.indexOf("load mmdb ")||-1!==i.indexOf("load mmdb1 "))s.cfg.mmdbid=l,s.cfg.bu=1,await t.mmdbParserCls.downloadMmdb(l);else if(-1!==i.indexOf("load mmdb0"))s.cfg.mmdbid=l,s.cfg.bu=0,await t.mmdbParserCls.downloadMmdb(l);else if(-1!==i.indexOf("load mmdbaf1"))s.cfg.mmdbafid=l,s.cfg.bu=1,await t.chainalignParserCls.downloadMmdbAf(l);else if(-1!==i.indexOf("load mmdbaf0"))s.cfg.mmdbafid=l,s.cfg.bu=0,await t.chainalignParserCls.downloadMmdbAf(l);else if(-1!==i.indexOf("load gi"))s.cfg.gi=l,await t.mmdbParserCls.downloadGi(l);else if(-1!==i.indexOf("load refseq"))s.cfg.refseqid=l,await t.mmdbParserCls.downloadRefseq(l);else if(-1!==i.indexOf("load protein"))s.cfg.protein=l,await t.mmdbParserCls.downloadProteinname(l);else if(-1!==i.indexOf("load seq_struct_ids "))t.bSmithwm=!1,t.bLocalSmithwm=!1,await t.mmdbParserCls.downloadBlast_rep_id(l);else if(-1!==i.indexOf("load seq_struct_ids_smithwm "))t.bSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(l);else if(-1!==i.indexOf("load seq_struct_ids_local_smithwm "))t.bLocalSmithwm=!0,await t.mmdbParserCls.downloadBlast_rep_id(l);else if(-1!==i.indexOf("load cid"))s.cfg.cid=l,await t.sdfParserCls.downloadCid(l);else if(-1!==i.indexOf("load smiles"))s.cfg.smiles=l,await t.sdfParserCls.downloadSmiles(l);else if(-1!==i.indexOf("load alignment"))if(s.cfg.align=l,s.cfg.inpara||-1==s.cfg.inpara.indexOf("atype=2"))await t.alignParserCls.downloadAlignment(s.cfg.align);else{let e=2;await t.chainalignParserCls.downloadMmdbAf(s.cfg.align,void 0,e)}else if(-1!==i.indexOf("load chainalignment")){let e=i.split(" | ");e.length>1&&-1!=e[1].indexOf("resnum")&&(s.cfg.resnum=e[1].substr(e[1].indexOf("resnum")+7)),e.length>2&&-1!=e[2].indexOf("resdef")&&(s.cfg.resdef=e[2].substr(e[2].indexOf("resdef")+7)),e.length>3&&-1!=e[3].indexOf("aligntool")&&(s.cfg.aligntool=e[3].substr(e[3].indexOf("aligntool")+10)),e.length>5&&-1!=e[5].indexOf("resrange")&&(s.cfg.resrange=e[5].substr(e[5].indexOf("resrange")+9)),s.cfg.chainalign=l,await t.chainalignParserCls.downloadChainalignment(l)}else if(-1!==i.indexOf("load url")){let i=e[1],n=void 0!==i?i.indexOf("type "):-1,r="pdb";-1!==n&&(r=i.substr(n+5)),s.cfg.url=l,await t.pdbParserCls.downloadUrl(l,r)}}t.bAddCommands=!0}async applyCommandMap(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | "),i=s[0].substr(8).split(" ");if("sigma"==i[1]){let e=i[2],n=i[0],l="dsn6";if(5==i.length&&(l=i[4]),2==s.length){let i=!0;"dsn6"==l?await t.densityCifParserCls.densityCifParserBase(s[1],n,e,"url",i):"ccp4"==l?await t.ccp4ParserCls.ccp4ParserBase(s[1],n,e,"url",i):"mtz"==l?await t.mtzParserCls.mtzParserBase(s[1],n,e,"url",i):"rcsbmtz"==l&&await t.mtzParserCls.mtzParserBase(s[1],n,e,"url",i,!0)}else await t.densityCifParserCls.densityCifParser(t.inputid,n,e)}}async applyCommandEmmap(e){let t=this.icn3d;t.icn3dui;let s=e.substr(10).split(" ");if(2==s.length&&"percentage"==s[0]){let e=s[1],i="em";await t.densityCifParserCls.densityCifParser(t.inputid,i,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 s=this.icn3d;s.icn3dui;let i=e.substr(e.lastIndexOf(" ")+1);await s.contactMapCls.afErrorMap(i,t)}async applyCommandGraphinteraction(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | ");if(s.length>=3){let e,i=s[1].split(" "),n=i[0].split(","),l=i[1].split(","),r=-1!==s[2].indexOf("hbonds"),o=-1!==s[2].indexOf("salt bridge"),a=-1!==s[2].indexOf("interactions"),d=-1!==s[2].indexOf("halogen"),c=-1!==s[2].indexOf("pi-cation"),h=-1!==s[2].indexOf("pi-stacking");s.length>=4&&(e="true"==s[3]),t.applyCommandCls.setStrengthPara(s),await t.viewInterPairsCls.viewInteractionPairs(n,l,e,"graph",r,o,a,d,c,h)}}async applyCommandCartoon2d(e){let t=this.icn3d;t.icn3dui;let s=e.substr(e.lastIndexOf(" ")+1);await t.cartoon2dCls.draw2Dcartoon(s)}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 s=e.lastIndexOf(" ");e.substr(s+1),await t.annotationCls.setAnnoTabClinvar()}async applyCommandSnp(e){let t=this.icn3d;t.icn3dui;let s=e.lastIndexOf(" ");e.substr(s+1),await t.annotationCls.setAnnoTabSnp()}async applyCommandPTM(e){let t=this.icn3d;t.icn3dui;let s=e.lastIndexOf(" ");e.substr(s+1),await t.annotationCls.setAnnoTabPTM()}applyCommand3ddomain(e){let t=this.icn3d;t.icn3dui;let s=e.lastIndexOf(" "),i=e.substr(s+1);"3ddomain"!=i&&"all"!=i||t.annotationCls.setAnnoTab3ddomain()}async applyCommandViewinteraction(e){let t=this.icn3d,s=t.icn3dui;if(void 0!==s.cfg.align||void 0!==s.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,s=t.icn3dui;t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),e+1===t.commands.length&&(t.bAddCommands=!0),t.bRender=!0;let i=t.commands[e-1]?t.commands[e-1].split("|||"):[];if(2==i.length){let e=JSON.parse(i[1]);t._zoomFactor=e.factor,t.mouseChange.x=e.mouseChange.x,t.mouseChange.y=e.mouseChange.y,t.quaternion._x=e.quaternion._x,t.quaternion._y=e.quaternion._y,t.quaternion._z=e.quaternion._z,t.quaternion._w=e.quaternion._w}if(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 s=t.optsHistory[e-1].pk;"no"===s?t.pk=0:"atom"===s?t.pk=1:"residue"===s?t.pk=2:"strand"===s&&(t.pk=3),t.hlUpdateCls.updateHlAll(),t.drawCls.draw()}else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();else t.hlUpdateCls.updateHlAll(),t.drawCls.draw();(s.cfg.closepopup||s.cfg.imageonly)&&(setTimeout((function(){t.resizeCanvasCls.closeDialogs()}),100),t.resizeCanvasCls.resizeCanvas(s.htmlCls.WIDTH,s.htmlCls.HEIGHT,!0)),t.bTransparentSurface&&t.bRender&&t.drawCls.render(),s.cfg.imageonly&&t.saveFileCls.saveFile(void 0,"png",void 0,!0)}async replayFirstStep(e){let t=this.icn3d,s=t.icn3dui;t.reinitAfterLoad(),await this.execCommandsBase(e,e,t.STATENUMBER);let i=t.commands[e],n=t.commands[e].indexOf("|");-1!=n&&(i=t.commands[e].substr(0,n));let l=i.length>20?i.substr(0,20)+"...":i,r=t.applyCommandCls.getMenuFromCmd(i);$("#"+t.pre+"replay_cmd").html("Cmd: "+l),$("#"+t.pre+"replay_menu").html("Menu: "+r),s.htmlCls.clickMenuCls.setLogCmd(i,!0),t.bCommandLoad=!1,t.ParserUtilsCls.hideLoading(),t.bRender=!0,t.drawCls.draw()}getHAtoms(e){let t=this.icn3d;t.icn3dui;let s=e.split("|||")[0].trim().split(" | ");if(2==s.length){let e=s[1].split(",");t.hAtoms=t.definedSetsCls.getAtomsFromNameArray(e)}}}class fs{constructor(e){this.icn3d=e}async selectByCommand(e,t,s){let i=this.icn3d,n=i.icn3dui;if(0===e.indexOf("saved atoms")){let s=12,n=e.substr(s);i.definedSetsCls.selectCombinedSets(n,t)}else{let l=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 "),r=("select"===l.trim().substr(0,6)?l.trim().substr(7):l.trim()).split(" or "),o={};for(let e=0,t=r.length;e<t;++e){let t=r[e].trim().replace(/\s+/g," "),s=t.indexOf(" ");i.hAtoms={},"and"===t.substr(0,s).toLowerCase()?(await i.applyCommandCls.applyCommand("select "+t.substr(s+1)),o=n.hashUtilsCls.intHash(o,i.hAtoms)):"not"===t.substr(0,s).toLowerCase()?(await i.applyCommandCls.applyCommand("select "+t.substr(s+1)),o=n.hashUtilsCls.exclHash(o,i.hAtoms)):(await i.applyCommandCls.applyCommand("select "+t),o=n.hashUtilsCls.unionHash(o,i.hAtoms))}i.hAtoms=n.hashUtilsCls.cloneHash(o);let a=Object.keys(i.hAtoms);if(""!==t){i.selectionCls.addCustomSelection(a,t,s,e,!1);let n=[t];i.definedSetsCls.changeCustomAtoms(n)}}}selectBySpec(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui;e="select"===e.trim().substr(0,6)?e.trim().substr(7):e.trim(),l.hAtoms={};let o,a=e.replace(/\s+/g," ").replace(/ AND /g," and ").split(" and "),d={},c={},h=!0;for(let e=0,t=a.length;e<t;++e){let t,s,i,n,o,p=a[e].indexOf("$"),m=a[e].indexOf("."),u=a[e].indexOf(":"),g=a[e].indexOf(":ref_"),f=a[e].indexOf("@"),C=a[e];if(-1===f?o=["*"]:(o=C.substr(f+1).split(","),C=C.substr(0,f)),-1===u&&-1===g)i="*";else if(-1!=g){if(n=C.substr(g+5),C=C.substr(0,g),!n)continue}else if(-1!=u&&(i=C.substr(u+1),C=C.substr(0,u),!i))continue;-1===m?s="*":(s=C.substr(m+1),s=s.replace(/_/g,""),C=C.substr(0,m)),-1===p?t="*":(t=C.substr(p+1),C=C.substr(0,p)),(o.length>1||1==o.length&&"*"!==o[0])&&(h=!1);let b,y,v,_,w=[],S=[];if(w="*"===t?Object.keys(l.structures):t.split(","),"*"===s){let e=Object.keys(l.chains);for(let t=0,s=e.length;t<s;++t){y=e[t],b=y.substr(0,y.indexOf("_")),-1!==w.map((function(e){return e.toLowerCase()})).indexOf(b.toLowerCase())&&S.push(y)}}else for(let e=0,t=w.length;e<t;++e){b=w[e];let t=s.split(",");for(let e in t)S.push(b+"_"+t[e])}let A=!!n,x=A?n.split(","):i.split(",");for(let t=0,s=x.length;t<s;++t){let s,i,n=!1,a=x[t].lastIndexOf("-"),h=!1,p=!1,m=!1;if(-1!==a)v=x[t].substr(0,a),_=x[t].substr(a+1),n=!0;else if(!A&&x[t].length>1&&"3"===x[t][0]&&isNaN(x[t][1])&&"-"!==x[t][0]){i=x[t].toUpperCase().substr(1),m=!0}else if(""===x[t]||isNaN(parseInt(x[t]))){if("*"===x[t])h=!0;else if("proteins"!==x[t]&&"nucleotides"!==x[t]&&"chemicals"!==x[t]&&"ions"!==x[t]&&"water"!==x[t]&&"anchors"!==x[t]&&"strands"!==x[t]&&"loops"!==x[t]){s=x[t].toUpperCase(),p=!0}}else v=x[t],_=v,n=!0;for(let a=0,u=S.length;a<u;++a)if(y=S[a],n){v=isNaN(v)?v:parseInt(v),_=isNaN(_)?_:parseInt(_);for(let t=v;t<=_;++t){let s=[];if(A){let e=l.refnum2residArray[t.toString()]?l.refnum2residArray[t.toString()]:[];for(let t=0,i=e.length;t<i;++t){let i=e[t];i.substr(0,i.lastIndexOf("_"))==y&&s.push(i)}}else{s=[y+"_"+t]}for(let t=0,i=s.length;t<i;++t){let i=s[t];0===e?d[i]=1:d.hasOwnProperty(i)||delete d[i];for(let t in l.residues[i])for(let s=0,i=o.length;s<i;++s){let i=o[s];c=this.processAtomStr(i,c,e,t)}}}}else if(y in l.chains){let n=l.chains[y];for(let s in n){l.atoms[s].resn.substr(0,3).toUpperCase();let i,n,r,a=y+"_"+l.atoms[s].resi;if(A&&(i=l.resid2refnum[a],i&&(n=l.refnumCls.rmStrandFromRefnumlabel(i),r=parseInt(n))),h||"proteins"===x[t]&&s in l.proteins||"nucleotides"===x[t]&&s in l.nucleotides||"chemicals"===x[t]&&s in l.chemicals||"ions"===x[t]&&s in l.ions||"water"===x[t]&&s in l.water||A&&i&&"anchors"===x[t]&&r%100==50||A&&i&&"strands"===x[t]&&!l.residIgLoop.hasOwnProperty(a)||A&&i&&"loops"===x[t]&&l.residIgLoop.hasOwnProperty(a)){0===e?d[a]=1:d.hasOwnProperty(a)||delete d[a];for(let t=0,i=o.length;t<i;++t){let i=o[t];c=this.processAtomStr(i,c,e,s)}}}if(p||m){let t=p?1:3,n=p?s:i,a="",h=[];for(let e=0,t=l.chainsSeq[y].length;e<t;++e){if(p)a+=1==l.chainsSeq[y][e].name.length?l.chainsSeq[y][e].name:" ";else if(m){let t=r.utilsCls.residueAbbr2Name(l.chainsSeq[y][e].name);a+=3==t.length?t:t.padEnd(3,"_")}h.push(l.chainsSeq[y][e].resi)}a=a.toUpperCase();let u=n.replace(/x/gi,"."),g=[],f=new RegExp(u,"i"),C=a,b=C.search(f),v=b/t;for(;-1!==b;)g.push(v),C=C.substr(b+t),b=C.search(f),v+=b/t+1;for(let s=0,i=g.length;s<i;++s){let i=g[s];for(let s=0,r=n.length/t;s<r;s+=t){let n=y+"_"+h[s/t+i];0===e?d[n]=1:d.hasOwnProperty(n)||delete d[n];for(let t in l.residues[n])for(let s=0,i=o.length;s<i;++s){let i=o[s];c=this.processAtomStr(i,c,e,t)}}}}}}}if(l.hAtoms=r.hashUtilsCls.cloneHash(c),0==Object.keys(l.hAtoms).length&&console.log("No residues were selected. Please try another search."),(void 0===i||i)&&l.hlUpdateCls.updateHlAll(),o=h?Object.keys(d):Object.keys(c),""!=t){l.selectionCls.addCustomSelection(o,t,s,e,h);let i=[t];n||l.definedSetsCls.changeCustomAtoms(i)}}processAtomStr(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=e.length;return"*"==e.substr(l-1,1)&&l>1?e.substr(0,l-1)===n.atoms[i].name.substr(0,l-1)&&(0===s?t[i]=1:t.hasOwnProperty(i)||delete t[i]):"*"!==e&&e!==n.atoms[i].name||(0===s?t[i]=1:t.hasOwnProperty(i)||delete t[i]),t}}class Cs{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 s in e.structures){let i=e.structures[s];for(let s=0,n=i.length;s<n;++s)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i[s]])}e.dAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.viewSelectionAtoms=t.hashUtilsCls.cloneHash(e.hAtoms),e.ALTERNATE_STRUCTURE=-1}selectAChain(e,t,s,i){let n=this.icn3d,l=n.icn3dui;t=t.replace(/\s/g,"");let r=void 0!==s||s?"select alignChain "+e:"select chain "+e;void 0!==i&&i?(n.hAtoms=l.hashUtilsCls.unionHash(n.hAtoms,n.chains[e]),void 0===n.nameArray&&(n.nameArray=[])):(n.hAtoms={},n.nameArray=[]),n.nameArray.push(e);let o,a=s?n.alnChainsSeq[e]:n.chainsSeq[e];o=void 0===a?0:a.length;let d={};for(let t=0,s=o;t<s;++t){let s=a[t],i=e+"_"+s.resi,l=s.name;if(""!==l&&"-"!==l){d[i]=1;for(let e in n.residues[i])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,r,!0);s?n.hlUpdateCls.updateHlAll(void 0,void 0,i,true):n.hlUpdateCls.updateHlAll(n.nameArray,void 0,i,true)}selectResidueList(e,t,s,i,n,l){let r=this.icn3d;if(r.icn3dui,void 0!==e&&Object.keys(e).length>0){if(void 0!==i&&i?void 0===r.nameArray&&(r.nameArray=[]):(r.hAtoms={},r.nameArray=[]),l)for(let t in e)r.hAtoms[t]=1;else for(let t in e)for(let e in r.residues[t])r.hAtoms[e]=1;let o,a;t=t.replace(/\s/g,""),r.nameArray.push(t),l?(o="select "+r.resid2specCls.atoms2spec(r.hAtoms),a=!1):(o="select "+r.resid2specCls.residueids2spec(Object.keys(e)),a=!0);let d=Object.keys(e);this.addCustomSelection(d,t,s,o,a),(void 0===n||n)&&r.hlUpdateCls.updateHlAll(r.nameArray,void 0,i)}}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,s=t.hashUtilsCls.cloneHash(e.hAtoms);e.hAtoms={};for(let i in s)(e.proteins.hasOwnProperty(i)&&"N"!==e.atoms[i].name&&"H"!==e.atoms[i].name&&"C"!==e.atoms[i].name&&"O"!==e.atoms[i].name&&("CA"!==e.atoms[i].name||"C"!==e.atoms[i].elem)&&"HA"!==e.atoms[i].name||e.nucleotides.hasOwnProperty(i)&&-1===t.parasCls.nuclMainArray.indexOf(e.atoms[i].name))&&(e.hAtoms[i]=1);e.hlUpdateCls.showHighlight()}selectMainSideChains(){let e=this.icn3d,t=e.icn3dui,s=e.firstAtomObjCls.getResiduesFromAtoms(e.hAtoms);e.hAtoms={};for(let i in s)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[i]),e.dAtoms=t.hashUtilsCls.unionHash(e.dAtoms,e.residues[i]);e.drawCls.draw(),e.hlUpdateCls.showHighlight()}clickShow_selected(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds(["#"+e.pre+"show_selected","#"+e.pre+"mn2_show_selected"],"click",(function(e){s.icn3d,s.showSelection(),t.htmlCls.clickMenuCls.setLogCmd("show selection",!0)}))}clickHide_selected(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+e.pre+"mn2_hide_selected","click",(function(e){s.icn3d,s.hideSelection(),t.htmlCls.clickMenuCls.setLogCmd("hide selection",!0)}))}getGraphDataForDisplayed(){let e=this.icn3d;e.icn3dui;let t=JSON.parse(e.graphStr),s=e.firstAtomObjCls.getResiduesFromAtoms(e.dAtoms),i=[],n=[],l={};for(let e=0,n=t.nodes.length;e<n;++e){let n=t.nodes[e],r=n.r.substr(4);s.hasOwnProperty(r)&&(i.push(n),l[n.id]=1)}for(let e=0,s=t.links.length;e<s;++e){let s=t.links[e];l.hasOwnProperty(s.source)&&l.hasOwnProperty(s.target)&&n.push(s)}return t.nodes=i,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,s,i,n){let l=this.icn3d;l.icn3dui,n?l.defNames2Residues[t]=e:l.defNames2Atoms[t]=e,l.defNames2Command[t]=i,l.defNames2Descr[t]=s,l.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 s=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=s.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 s=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(e.dAtoms,e.atoms));e.maxD=s.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,s){let i=this.icn3d,n=i.icn3dui;if(s||(i.selectedResidues={},i.selectedResidues=i.firstAtomObjCls.getResiduesFromCalphaAtoms(i.hAtoms)),!e){t=e="seq_"+(Object.keys(i.defNames2Atoms).length+Object.keys(i.defNames2Residues).length+1)}if(Object.keys(i.selectedResidues).length>0)if(1==i.pk){let l=!0;this.selectResidueList(i.hAtoms,e,t,void 0,void 0,l),this.updateSelectionNameDesc(),s?n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.atoms2spec(i.hAtoms),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.atoms2spec(i.hAtoms)+" | name "+e,!0)}else this.selectResidueList(i.selectedResidues,e,t,void 0,void 0,void 0),this.updateSelectionNameDesc(),s?n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.residueids2spec(Object.keys(i.selectedResidues)),!0):n.htmlCls.clickMenuCls.setLogCmd("select "+i.resid2specCls.residueids2spec(Object.keys(i.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 s={};s[t]=1;let i=t+"_"+e.selectedResidues[t];this.selectResidueList(s,i,i)}}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,s=t.icn3dui,i=e.trim().split("\n");for(let e=0,n=i.length;e<n;++e){let n=i[e].replace(/\t/g," "),l=n.indexOf(" "),r=n.substr(0,l),o=n.substr(l+1),a=o.indexOf(" ");await t.selByCommCls.selectByCommand(o.substr(a+1),r,r),s.htmlCls.clickMenuCls.setLogCmd("select "+o.substr(a+1)+" | name "+r,!0)}}oneStructurePerWindow(){let e=this.icn3d,t=e.icn3dui,s=e.structures?Object.keys(e.structures):[];if(t.cfg.bSidebyside&&2==s.length){let i=s[Object.keys(window.icn3duiHash).indexOf(e.divid)],n=e.structures[i],l={};if(n){for(let s=0,i=n.length;s<i;++s)l=t.hashUtilsCls.unionHash(l,e.chains[n[s]]);e.dAtoms=t.hashUtilsCls.intHash(l,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 s=this.icn3d;if(s.icn3dui,s.bSelectResidue||s.bSelectAlignResidue){let e=$("#"+s.pre+"seq_command_name2").val().replace(/\s+/g,"_");""===e&&(e=$("#"+s.pre+"alignseq_command_name").val().replace(/\s+/g,"_")),""!==e&&this.saveSelection(e,e),s.bSelectResidue=!1,s.bSelectAlignResidue=!1}}saveSelectionPrep(e){var t=this.icn3d,s=t.icn3dui;s.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")||(s.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+t.pre+"atomsCustom").resizable()),e||(t.bSelectResidue=!1,t.bSelectAlignResidue=!1)}selectOneResid(e,t){var s=this.icn3d;s.icn3dui;let i=e.indexOf("$"),n=e.indexOf("."),l=e.indexOf(":"),r=e.indexOf("@");-1==r&&(r=e.length);let o=e.substr(i+1,n-i-1),a=e.substr(n+1,l-n-1),d=e.substr(l+1,r-l-1),c=o+"_"+a+"_"+d;for(let e in s.residues[c])t?delete s.hAtoms[e]:s.hAtoms[e]=1;return t?delete s.selectedResidues[c]:s.selectedResidues[c]=1,"$"+o+"."+a+":"+d}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,s=t.icn3dui;let i=t.structures?Object.keys(t.structures):[];for(let n=0,l=i.length;n<l;++n){let l=i[n],r=t.residues[l+"_MEM_1"],o=t.firstAtomObjCls.getFirstAtomObj(r);if(void 0===o)continue;let a=o.style;t.dAtoms.hasOwnProperty(o.serial)||(t.dAtoms=s.hashUtilsCls.unionHash(t.dAtoms,r),a="nothing");for(let s in r){let i=t.atoms[s];i.style="nothing"!==a?"nothing":"stick",void 0!==e&&(i.style=e?"stick":"nothing")}}void 0===e&&t.drawCls.draw()}adjustMembrane(e,t){var s=this.icn3d;s.icn3dui;for(let i in s.chains[s.inputid.toUpperCase()+"_MEM"]){let n=s.atoms[i];"O"==n.name?n.coord.z=e:"N"==n.name&&(n.coord.z=t)}s.definedSetsCls.setTransmemInMenu(e,t,!0),s.hlUpdateCls.updateHlMenus(),s.drawCls.draw()}selectBtwPlanes(e,t){var s=this.icn3d;if(s.icn3dui,e<t){let s=t;t=e,e=s}let i={};for(let n in s.atoms){let l=s.atoms[n];if("DUM"!=l.resn&&(l.coord.z>=t&&l.coord.z<=e)){i[l.structure+"_"+l.chain+"_"+l.resi]=1}}let n="z_planes_"+e+"_"+t,l=n;this.selectResidueList(i,n,l,!1)}}class bs{constructor(e){this.icn3d=e}residueids2spec(e){var t=this.icn3d;t.icn3dui;let s="";if(void 0!==e){let i,n,l,r,o,a,d,c=e.sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let s=e.lastIndexOf("_"),i=t.lastIndexOf("_");if(e.substr(0,s)<t.substr(0,i))return-1;if(e.substr(0,s)>t.substr(0,i))return 1;if(e.substr(0,s)==t.substr(0,i)){if(parseInt(e.substr(s+1))<parseInt(t.substr(i+1)))return-1;if(parseInt(e.substr(s+1))>parseInt(t.substr(i+1)))return 1;if(parseInt(e.substr(s+1))==parseInt(t.substr(i+1)))return 0}}})),h="",p=0,m=1!=Object.keys(t.structures).length;for(let e=0,u=c.length;e<u;++e){let u=c[e];if(l=u.lastIndexOf("_"),i=u.substr(0,l),n=u.substr(l+1),r=h.indexOf("_"),o=h.substr(0,r),a=h.substr(r+1),isNaN(n))s+=m?"$"+o+"."+a+":"+n+" or ":"."+a+":"+n+" or ";else{if(h!==i)e>0&&(s+=p===d?m?"$"+o+"."+a+":"+d+" or ":"."+a+":"+d+" or ":m?"$"+o+"."+a+":"+d+"-"+p+" or ":"."+a+":"+d+"-"+p+" or "),d=n;else if(h===i){let e=t.ParserUtilsCls.getResiNCBI(h,p);t.ParserUtilsCls.getResiNCBI(i,n)!=e+1&&(s+=p===d?m?"$"+o+"."+a+":"+d+" or ":"."+a+":"+d+" or ":m?"$"+o+"."+a+":"+d+"-"+p+" or ":"."+a+":"+d+"-"+p+" or ",d=n)}h=i,p=n}}r=h.indexOf("_"),o=h.substr(0,r),a=h.substr(r+1),s+=p===d?m?"$"+o+"."+a+":"+d:"."+a+":"+d:m?"$"+o+"."+a+":"+d+"-"+p:"."+a+":"+d+"-"+p}return s}resi2range(e){this.icn3d.icn3dui;let t,s,i=[],n=e.sort((function(e,t){return parseInt(e)-parseInt(t)})),l=n[0];for(let e=0,r=n.length;e<r;++e)s=n[e],0!=e&&s!=t+1&&(i.push(l),i.push(t),l=s),t=s;return i.push(l),i.push(t),i}atoms2spec(e){var t=this.icn3d;t.icn3dui;let s,i="",n=0,l={},r={},o={};for(let a in e)s=t.atoms[a],n>0&&(i+=" or "),i+="$"+s.structure+"."+s.chain+":"+s.resi+"@"+s.name,l[s.structure]=1,r[s.structure+"_"+s.chain]=1,o[s.structure+"_"+s.chain+"_"+s.resi]=1,++n;if(1==Object.keys(o).length){let e="\\$"+s.structure+"\\."+s.chain+":"+s.resi;i=i.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(r).length){let e="\\$"+s.structure+"\\."+s.chain;i=i.replace(new RegExp(e,"g"),"")}else if(1==Object.keys(l).length){let e="\\$"+s.structure;i=i.replace(new RegExp(e,"g"),"")}return i}atoms2residues(e){var t=this.icn3d;t.icn3dui;let s={};for(let t=0,i=e.length;t<i;++t)s[e[t]]=1;let i=t.firstAtomObjCls.getResiduesFromAtoms(s);return Object.keys(i)}atoms2structureArray(e){var t=this.icn3d;t.icn3dui;let s={};for(let i in e){s[t.atoms[i].structure]=1}return Object.keys(s)}selectProperty(e,t,s){var i=this.icn3d,n=i.icn3dui;let l=n.hashUtilsCls.cloneHash(i.hAtoms);if("positive"==e){let e=":r,k,h";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e)}else if("negative"==e){let e=":d,e";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e),i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,i.nucleotides)}else if("hydrophobic"==e){let e=":w,f,y,l,i,c,m";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e),i.hAtoms=n.hashUtilsCls.intHash(i.hAtoms,i.proteins)}else if("polar"==e){let e=":g,v,s,t,a,n,p,q";i.hAtoms={},i.selByCommCls.selectBySpec(e,e,e),i.hAtoms=n.hashUtilsCls.intHash(i.hAtoms,i.proteins)}else if("b factor"==e){let e=n.hashUtilsCls.cloneHash(i.calphas);e=n.hashUtilsCls.unionHash(e,i.nucleotidesO3),e=n.hashUtilsCls.unionHash(e,i.chemicals),e=n.hashUtilsCls.unionHash(e,i.ions),e=n.hashUtilsCls.unionHash(e,i.water),i.hAtoms={};for(let l in e){let e=i.atoms[l];e.b>=parseInt(t)&&e.b<=parseInt(s)&&(i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,i.residues[e.structure+"_"+e.chain+"_"+e.resi]))}}else if("percent out"==e){i.bCalcArea=!0,i.opts.surface="solvent accessible surface",i.applyMapCls.applySurfaceOptions(),i.bCalcArea=!1,i.hAtoms={};for(let e in i.resid2area){let l=e.lastIndexOf("_"),r=e.substr(l+1);if(n.parasCls.residueArea.hasOwnProperty(r)){let o=parseInt(i.resid2area[e]/n.parasCls.residueArea[r]*100);if(o>=t&&o<=s){let t=e.substr(0,l);i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,i.residues[t])}}}}i.hAtoms=n.hashUtilsCls.intHash(i.hAtoms,l),i.drawCls.draw(),i.hlUpdateCls.updateHlAll()}selectComplement(){let e=this.icn3d,t=e.icn3dui,s={};for(let t in e.atoms)e.hAtoms.hasOwnProperty(t)||(s[t]=1);e.hAtoms=t.hashUtilsCls.cloneHash(s),e.hlUpdateCls.updateHlAll()}switchHighlightLevel(){var e=this.icn3d.icn3dui;if(e.bNode)return;let t=this;document.addEventListener("keydown",(function(s){let i=t.icn3d;38===s.keyCode?(s.preventDefault(),0!=Object.keys(i.pickedAtomList).length&&i.hAtoms.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.pickedAtomList).serial)||(i.pickedAtomList=e.hashUtilsCls.cloneHash(i.hAtoms)),t.switchHighlightLevelUp(),e.htmlCls.clickMenuCls.setLogCmd("highlight level up",!0)):40===s.keyCode&&(s.preventDefault(),0!=Object.keys(i.pickedAtomList).length&&i.hAtoms.hasOwnProperty(i.firstAtomObjCls.getFirstAtomObj(i.pickedAtomList).serial)||(i.pickedAtomList=e.hashUtilsCls.cloneHash(i.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 s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[s.structure+"_"+s.chain+"_"+s.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[s.structure+"_"+s.chain+"_"+s.resi])}else if(2===e.highlightlevel){e.highlightlevel=3;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(s)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(s))}else if(3===e.highlightlevel){let s;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);s=e.pickingCls.select3ddomainFromAtom(i),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,s):e.hAtoms=t.hashUtilsCls.cloneHash(s)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(s).length){e.highlightlevel=5;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s.structure+"_"+s.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[s.structure+"_"+s.chain])}}else if(4===e.highlightlevel){e.highlightlevel=5;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s.structure+"_"+s.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[s.structure+"_"+s.chain])}else if(5===e.highlightlevel||6===e.highlightlevel){e.highlightlevel=6;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl||(e.hAtoms={});let i=e.structures[s.structure];for(let s=0,n=i.length;s<n;++s)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[i[s]])}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 s={};for(let t in e.pickedAtomList)residueid=e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi,s[residueid]=1;if(1===Object.keys(s).length){e.highlightlevel=2;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.residues[s.structure+"_"+s.chain+"_"+s.resi]):e.hAtoms=t.hashUtilsCls.cloneHash(e.residues[s.structure+"_"+s.chain+"_"+s.resi])}}else if(4===e.highlightlevel){e.highlightlevel=3;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(s)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(s))}else if(5===e.highlightlevel){let s;if(void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi){e.highlightlevel=4;let i=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);s=e.pickingCls.select3ddomainFromAtom(i),e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,s):e.hAtoms=t.hashUtilsCls.cloneHash(s)}if(void 0===t.cfg.mmdbid&&void 0===t.cfg.gi||0==Object.keys(s).length){e.highlightlevel=3;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.pickingCls.selectStrandHelixFromAtom(s)):e.hAtoms=t.hashUtilsCls.cloneHash(e.pickingCls.selectStrandHelixFromAtom(s))}}else if(6===e.highlightlevel){e.highlightlevel=5;let s=e.firstAtomObjCls.getFirstAtomObj(e.pickedAtomList);e.bShift||e.bCtrl?e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[s.structure+"_"+s.chain]):e.hAtoms=t.hashUtilsCls.cloneHash(e.chains[s.structure+"_"+s.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 ys{constructor(e){this.icn3d=e}getFirstAtomObj(e){let t=this.icn3d;if(t.icn3dui,void 0===e||0===Object.keys(e).length)return;let s=Object.keys(e)[0];return t.atoms[s]}getMiddleAtomObj(e,t){let s=this.icn3d;if(s.icn3dui,void 0===e||0===Object.keys(e).length)return;let i=Object.keys(e),n=t&&t<i.length?i[t]:i[parseInt(i.length/2)];return s.atoms[n]}getFirstCalphaAtomObj(e){let t,s=this.icn3d;if(s.icn3dui,void 0!==e&&0!==Object.keys(e).length){for(let i in e)if("CA"==s.atoms[i].name){t=i;break}if(!t)for(let i in e)if("O3'"==s.atoms[i].name||"O3*"==s.atoms[i].name){t=i;break}return void 0!==t?s.atoms[t]:this.getFirstAtomObj(e)}}getFirstAtomObjByName(e,t){let s,i=this.icn3d;if(i.icn3dui,void 0===e||0===Object.keys(e).length)return i.atoms[0];for(let n in e)if(i.atoms[n].name==t){s=n;break}return void 0!==s?i.atoms[s]:void 0}getLastAtomObj(e){let t=this.icn3d;if(t.icn3dui,void 0===e||0===Object.keys(e).length)return t.atoms[0];let s=Object.keys(e),i=s[s.length-1];return t.atoms[i]}getResiduesFromAtoms(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in e){s[t.atoms[i].structure+"_"+t.atoms[i].chain+"_"+t.atoms[i].resi]=1}return s}getResiduesFromCalphaAtoms(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in e)if("CA"==t.atoms[i].name&&t.proteins.hasOwnProperty(i)||!t.proteins.hasOwnProperty(i)){s[t.atoms[i].structure+"_"+t.atoms[i].chain+"_"+t.atoms[i].resi]=t.atoms[i].resn}return s}getChainsFromAtoms(e){let t=this.icn3d;t.icn3dui;let s={};for(let i in e){let e=t.atoms[i];s[e.structure+"_"+e.chain]=1}return s}getAtomFromResi(e,t){let s=this.icn3d;if(s.icn3dui,s.residues.hasOwnProperty(e))for(let i in s.residues[e])if(s.atoms[i].name===t&&!s.atoms[i].het)return s.atoms[i]}getAtomCoordFromResi(e,t){this.icn3d.icn3dui;let s=this.getAtomFromResi(e,t);if(void 0!==s){return void 0!==s.coord2?s.coord2:s.coord}}}class vs{constructor(e){this.icn3d=e}async CalcPhiUrl(e,t,s,i,n){let l=this.icn3d.icn3dui,r=await l.getXMLHttpRqstPromise(n,"GET","text","PQR");await this.CalcPhi(e,t,s,i,r)}getPdbStr(e){let t=this.icn3d,s=t.icn3dui,i={},n={},l=s.hashUtilsCls.intHash(t.dAtoms,t.hAtoms);for(let e in l)t.atoms[e],t.ions.hasOwnProperty(e)?i[e]=1:n[e]=1;let r=Object.keys(n).length;if(s.utilsCls.isCalphaPhosOnly(s.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(r>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="";return o+=s.cfg.cid?t.saveFileCls.getAtomPDB(n,!0,void 0,void 0,void 0,void 0,true):t.saveFileCls.getAtomPDB(n,void 0,void 0,void 0,void 0,void 0,true),o+=t.saveFileCls.getAtomPDB(i,!0,void 0,!0),o}async CalcPhi(e,t,s,i,n){let l=this.icn3d;l.icn3dui;let r=await this.CalcPhiPrms(e,t,s,i,n);this.loadPhiData(r,s,i),l.bAjaxPhi=!0,i?l.setOptionCls.setOption("phisurface","phi"):l.setOptionCls.setOption("phimap","phi")}CalcPhiPrms(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui;l.loadPhiFrom="delphi";let o=r.htmlCls.baseUrl+"delphi/delphi.cgi",a=r.cfg.cid?r.cfg.cid:Object.keys(l.structures).toString(),d={};if(n)d={pqr2phi:n,gsize:e,salt:t,pdbid:a};else{let s=this.getPdbStr();d={pdb2phi:s,gsize:e,salt:t,pdbid:a}}return new Promise((function(e,t){$.ajax({url:o,type:"POST",data:d,dataType:"binary",responseType:"arraybuffer",cache:!0,beforeSend:function(){l.ParserUtilsCls.showLoading()},complete:function(){l.ParserUtilsCls.hideLoading()},success:function(t){e(t)},error:function(e,t,s){}})}))}async PhiParser(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=this;n="phiurl"==t||"phiurl2"==t?"arraybuffer":"text";let a=await r.getXMLHttpRqstPromise(e,"GET",n,"potential");"phiurl"==t||"phiurl2"==t?o.loadPhiData(a,s,i):o.loadCubeData(a,s,i),l.bAjaxPhi=!0,i?l.setOptionCls.setOption("phisurface","phi"):l.setOptionCls.setOption("phimap","phi")}loadPhiData(e,t,s){let i=this.icn3d;i.icn3dui;let n={filetype:"phi"},l=e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e,r=new Float32Array(l.slice(l.byteLength-24,l.byteLength-8));n.scale=r[0];let o=r[1],a=r[2],d=r[3];n.n=new Int32Array(l.slice(l.byteLength-8,l.byteLength-4)),n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new THREE.Vector3(o-c,a-c,d-c);let h=new Float32Array(l.slice(110,l.byteLength-56));n.bSurface=s,i.mapData.headerPhi=n,i.mapData.dataPhi=h,i.mapData.contourPhi=t;let p=new THREE.Matrix4;p.identity(),p.multiply((new THREE.Matrix4).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),i.mapData.matrixPhi=p}loadCubeData(e,t,s){let i=this.icn3d;i.icn3dui;let n={filetype:"cube"},l=e.split("\n"),r=[];r.push(parseFloat(l[0].substr(0,10))),r.push(parseFloat(l[0].substr(10,6))),r.push(parseFloat(l[0].substr(16,10))),r.push(parseFloat(l[0].substr(26,10))),r.push(parseFloat(l[0].substr(36,10))),n.scale=r[0];let o=r[2],a=r[3],d=r[4];n.n=r[1],n.xExtent=n.yExtent=n.zExtent=n.n;let c=1/n.scale*((n.n-1)/2);n.ori=new THREE.Vector3(o-c,a-c,d-c);let h=[];for(let e=7,t=l.length;e<t;++e){let t=l[e].split(/\s+/);for(let e=0,s=t.length;e<s;++e){let s=parseFloat(t[e]);isNaN(s)||h.push(s)}}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=s,i.mapData.headerPhi=n,i.mapData.dataPhi=h,i.mapData.contourPhi=t;let p=new THREE.Matrix4;p.identity(),p.multiply((new THREE.Matrix4).makeTranslation(n.ori.x,n.ori.y,n.ori.z)),i.mapData.matrixPhi=p}async applyCommandPhi(e){let t=this.icn3d;t.icn3dui;let s=this,i=e.split(" | "),n=i[0].split(" "),l=i[1].split(" "),r=i[2].split(" "),o=i[3].split(" "),a=i[4].split(" "),d=n[2],c=parseFloat(l[1]),h=r[1],p=o[1],m=a[1];if(8==i.length){let e=i[5].split(" "),s=i[6].split(" "),n=i[7].split(" ");t.phisurftype=e[1],t.phisurfop=parseFloat(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 u="pqrurl2"==d||"phiurl2"==d||"cubeurl2"==d;"pqrurl"==d||"pqrurl2"==d?await s.CalcPhiUrl(p,m,c,u,h):await s.PhiParser(h,d,c,u)}async applyCommandDelphi(e){let t=this.icn3d;t.icn3dui;let s=e.split(" | "),i=s[0].split(" "),n=s[1].split(" "),l=s[2].split(" "),r=s[3].split(" "),o=i[2],a=n[1],d=l[1],c=r[1];if($("#"+t.pre+"delphi1gsize").val(d),$("#"+t.pre+"delphi1salt").val(c),$("#"+t.pre+"delphi2gsize").val(d),$("#"+t.pre+"delphi2salt").val(c),7==s.length){let e=s[4].split(" "),i=s[5].split(" "),n=s[6].split(" ");t.phisurftype=e[1],t.phisurfop=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 h="surface"==o;await this.CalcPhi(d,c,a,h)}async loadDelphiFile(e){let t=this.icn3d,s=t.icn3dui,i="delphi2"==e?$("#"+t.pre+"delphi2gsize").val():$("#"+t.pre+"delphi1gsize").val(),n="delphi2"==e?$("#"+t.pre+"delphi2salt").val():$("#"+t.pre+"delphi1gsize").val(),l="delphi2"==e?$("#"+t.pre+"delphicontour2").val():$("#"+t.pre+"delphicontour").val(),r="delphi2"==e;await this.CalcPhi(i,n,l,r);let o="delphi2"==e?"surface":"map";r?s.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+l+" | gsize "+i+" | salt "+n+" | surface "+t.phisurftype+" | opacity "+t.phisurfop+" | wireframe "+t.phisurfwf,!0):s.htmlCls.clickMenuCls.setLogCmd("set delphi "+o+" | contour "+l+" | gsize "+i+" | salt "+n,!0)}loadPhiFile(e){let t,s=this.icn3d,i=s.icn3dui,n=this;"pqr"==e||"phi"==e||"cube"==e?t=$("#"+s.pre+e+"file")[0].files[0]:"pqr2"==e?t=$("#"+s.pre+"pqrfile2")[0].files[0]:"phi2"==e?t=$("#"+s.pre+"phifile2")[0].files[0]:"cube2"==e&&(t=$("#"+s.pre+"cubefile2")[0].files[0]);let l="pqr"==e||"phi"==e||"cube"==e?$("#"+s.pre+"phicontour").val():$("#"+s.pre+"phicontour2").val();if(t){i.utilsCls.checkFileAPI();let s=new FileReader;s.onload=async function(t){let s=n.icn3d,r=t.target.result,o=0,a=0;if("pqr"==e||"pqr2"==e){let t="pqr2"==e;o=$("#"+s.pre+e+"gsize").val(),a=$("#"+s.pre+e+"salt").val(),await n.CalcPhi(o,a,l,t,r)}else if("phi"==e||"phi2"==e){let t="phi2"==e;n.loadPhiData(r,l,t)}else if("cube"==e||"cube2"==e){let t="cube2"==e;n.loadCubeData(r,l,t)}s.bAjaxPhi=!0,bSurface?s.setOptionCls.setOption("phisurface","phi"):s.setOptionCls.setOption("phimap","phi"),bSurface?i.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+l+" | file "+$("#"+s.pre+e+"file").val()+" | gsize "+o+" | salt "+a+" | surface "+s.phisurftype+" | opacity "+s.phisurfop+" | wireframe "+s.phisurfwf,!1):i.htmlCls.clickMenuCls.setLogCmd("load phi "+e+" | contour "+l+" | file "+$("#"+s.pre+e+"file").val()+" | gsize "+o+" | salt "+a,!1)},"phi"==e||"phi2"==e?s.readAsArrayBuffer(t):s.readAsText(t)}else alert("Please select a file before clicking 'Load'")}async loadPhiFileUrl(e){let t,s=this.icn3d,i=s.icn3dui;"pqrurl"==e||"phiurl"==e||"cubeurl"==e?t=$("#"+s.pre+e+"file").val():"pqrurl2"==e?t=$("#"+s.pre+"pqrurlfile2").val():"phiurl2"==e?t=$("#"+s.pre+"phiurlfile2").val():"cubeurl2"==e&&(t=$("#"+s.pre+"cubeurlfile2").val());let n="pqrurl"==e||"phiurl"==e||"cubeurl"==e?$("#"+s.pre+"phiurlcontour").val():$("#"+s.pre+"phiurlcontour2").val();if(t){let l="pqrurl2"==e||"phiurl2"==e||"cubeurl2"==e,r=0,o=0;"pqrurl"==e||"pqrurl2"==e?(r=$("#"+s.pre+e+"gsize").val(),o=$("#"+s.pre+e+"salt").val(),await this.CalcPhiUrl(r,o,n,l,t)):await this.PhiParser(t,e,n,l),l?i.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+r+" | salt "+o+" | surface "+s.phisurftype+" | opacity "+s.phisurfop+" | wireframe "+s.phisurfwf,!0):i.htmlCls.clickMenuCls.setLogCmd("set phi "+e+" | contour "+n+" | url "+encodeURIComponent(t)+" | gsize "+r+" | salt "+o,!0)}else alert("Please input the file URL before clicking 'Load'")}}class _s{constructor(e){this.icn3d=e}async applyDssp(e,t){let s=this.icn3d,i=s.icn3dui,n=this,l=e?"1":"0",r=Object.keys(s.structures),o=[],a=window&&window.location&&-1!=window.location.hostname.indexOf("ncbi.nlm.nih.gov")?"/Structure/mmcifparser/mmcifparser.cgi":i.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi";for(let e=0,t=r.length;e<t;++e){let t="",n={},d=s.structures[r[e]];for(let e=0,t=d.length;e<t;++e)n=i.hashUtilsCls.unionHash(n,s.chains[d[e]]);t+=s.saveFileCls.getAtomPDB(n,void 0,!0);let c={dssp:"t",calphaonly:l,pdbfile:t},h=i.getAjaxPostPromise(a,c);o.push(h)}let d=Promise.allSettled(o);try{let e=await d;await n.parseDsspData(e,r,t),i.bNode||await s.ParserUtilsCls.checkMemProteinAndRotate()}catch(e){console.log("DSSP calculation had a problem with this structure "+r[0]+"..."),await s.pdbParserCls.loadPdbDataRender(t)}}async parseDsspData(e,t,s){let i=this.icn3d;i.icn3dui;for(let s=0,n=e.length;s<n;++s){let n=e[s].value;if(void 0!==n&&-1===JSON.stringify(n).indexOf("Oops there was a problem"))for(let e in i.chainsSeq){let l=e.indexOf("_");if(e.substr(0,l)!=t[s])continue;let r,o=e.substr(l+1),a=i.chainsSeq[e],d="coil";for(let t=0,s=a.length;t<s;++t){let s,l=a[t].resi,c=o+"_"+l,h="c";n.hasOwnProperty(c)?h=n[c]:n.hasOwnProperty(" _"+l)?h=n[" _"+l]:n.hasOwnProperty("_"+l)&&(h=n["_"+l]),s="H"===h?"helix":"E"===h?"sheet":"coil";let p=e+"_"+l;i.secondaries[p]=h;let m,u,g=0;if(s!==d?"coil"===d?(m=!0,u=!1):"coil"===s?(g=2,m=!1,u=!1):("sheet"===d&&"helix"===s||"helix"===d&&"sheet"===s)&&(g=2,m=!0,u=!1):(m=!1,u=!1),1==g){let t=e+"_"+r;for(let e in i.residues[t])i.atoms[e].ssbegin=!0,i.atoms[e].ssend=!1}else if(2==g){let t=e+"_"+r;for(let e in i.residues[t])i.atoms[e].ssbegin=!1,i.atoms[e].ssend=!0}for(let e in i.residues[p])i.atoms[e].ss=s,i.atoms[e].ssbegin=m,i.atoms[e].ssend=u;d=s,r=l}}else console.log("DSSP calculation had a problem with this structure "+t[s]+"...")}await i.pdbParserCls.loadPdbDataRender(s)}}class ws{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="IgE",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="IgE",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["RBPJ_6py8C_human_Unk-n2"]="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="IgE",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,s=[];for(let i=0,n=e.refpdbArray.length;i<n;++i){let n=t.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+e.refpdbArray[i],l=t.getAjaxPromise(n,"text");s.push(l)}return s}async showIgRefNum(e){let t=this.icn3d;t.icn3dui;let s=this;this.setRefPdbs();let i=this.getPdbAjaxArray();if(e)await s.parseRefPdbData(void 0,e);else{t.pdbDataArray=await this.promiseWithFixedJobs(i);let n=await s.parseRefPdbData(t.pdbDataArray,e),l=0;for(;!n&&l<15;){let i=!0;n=await s.parseRefPdbData(t.pdbDataArray,e,i),++l}}}async parseRefPdbData(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this,r=Object.keys(i.structures),o=[],a=[],d=n.htmlCls.tmalignUrl;i.resid2domainid||(i.resid2domainid={}),i.domainid2pdb={};let c=!0,h=!1;for(let l=0,p=r.length;l<p;++l){let p=r[l],m=i.structures[p];for(let l=0,r=m.length;l<r;++l){let r=m[l],u=this.getDomainAtomsArray(r,s);if(i.domainid2refpdbname||(i.domainid2refpdbname={}),i.domainid2score||(i.domainid2score={}),0!=u.length){h=!0;for(let s=0,l=u.length;s<l;++s){c=!1;let l=i.saveFileCls.getAtomPDB(u[s],void 0,void 0,void 0,void 0,p),h=i.firstAtomObjCls.getFirstAtomObj(u[s]),m=i.firstAtomObjCls.getLastAtomObj(u[s]),g=r+","+s+"_"+(h.resi+":"+m.resi+":"+Object.keys(u[s]).length);if(delete i.domainid2score[g],i.domainid2pdb[g]=l,t)i.domainid2refpdbname[g]=[t],a.push(g+"|1"+t);else for(let t=0,s=e.length;t<s;++t){let s=i.defaultPdbId+t,r=e[t].value;r="HEADER "+s+"\n"+r;let c={pdb_query:r,pdb_target:l,queryid:i.refpdbArray[t]},h=n.getAjaxPostPromise(d,c);o.push(h),a.push(g+"|"+i.refpdbArray[t])}}}}}if(!h)return c;if(t){n.bNode||console.log("Start alignment with the reference culsters "+JSON.stringify(i.domainid2refpdbname));let e=[],s=[],r=n.htmlCls.tmalignUrl,o=n.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+t,a=n.getAjaxPromise(o,"text"),d=[];d.push(a);let h=await this.promiseWithFixedJobs(d);for(let l in i.domainid2refpdbname){let o=i.domainid2pdb[l];for(let a=0,d=h.length;a<d;++a){let d=i.defaultPdbId+a,c=h[a].value;c="HEADER "+d+"\n"+c;let p={pdb_query:c,pdb_target:o,queryid:t},m=n.getAjaxPostPromise(r,p);e.push(m),s.push(l+"|"+t)}}let p=[];p=await this.promiseWithFixedJobs(e),c=await l.parseAlignData(p,s)}else{let e=[];e=await this.promiseWithFixedJobs(o);let t=!0;c=await l.parseAlignData(e,a,t)}return c}getDomainAtomsArray(e,t){let s=this.icn3d,i=s.icn3dui,n=[];if(s.chainid2atomsLeft||(s.chainid2atomsLeft={}),!s.proteins.hasOwnProperty(s.firstAtomObjCls.getFirstAtomObj(s.chains[e]).serial)&&!s.proteins.hasOwnProperty(s.firstAtomObjCls.getMiddleAtomObj(s.chains[e]).serial))return n;if(s.chainsSeq[e].length<20)return n;let l=i.hashUtilsCls.intHash(s.chains[e],s.hAtoms);if(0==Object.keys(l).length)return n;if(t){let t={};for(let e in s.resid2domainid)s.resid2domainid[e]&&(t=i.hashUtilsCls.unionHash(t,s.residues[e]));if(l=i.hashUtilsCls.exclHash(l,t),s.chainid2atomsLeft[e]==Object.keys(l).length)return n;if(s.chainid2atomsLeft[e]=Object.keys(l).length,Object.keys(l).length<200)return n}let r=s.domain3dCls.c2b_NewSplitChain(l,void 0).subdomains;if(r.length>=1)for(let t=0,l=r.length;t<l;++t){let l={},o=r[t],a=0;for(let t=0,n=o.length;t<n;t+=2){let n=parseInt(o[t]),r=parseInt(o[t+1]);for(let t=n;t<=r;++t){let n=s.ncbi2resid[e+"_"+t];++a,l=i.hashUtilsCls.unionHash(l,s.residues[n]),delete s.residIgLoop[n],delete s.resid2domainid[n]}}a<20||n.push(l)}return n}getTemplateList(e){let t=this.icn3d;t.icn3dui;let s="",i="",n="",l="";if(s=t.domainid2refpdbname[e][0],t.domainid2score[e]){let s=t.domainid2score[e].split("_");i=s[0],n=s[1],l=s[2]}return{refpdbname:s,score:i,seqid:n,nresAlign:l}}parseAlignData_part1(e,t,s){let i=this.icn3d,n=i.icn3dui,l={},r={};i.chainid2refpdbname||(i.chainid2refpdbname={}),i.domainid2refpdbname||(i.domainid2refpdbname={}),i.domainid2score||(i.domainid2score={}),i.domainid2ig2kabat||(i.domainid2ig2kabat={}),i.domainid2ig2imgt||(i.domainid2ig2imgt={});for(let o=0,a=t.length;o<a;++o){let a=e[o]?e[o].value:void 0;if(!a||0==a.length){n.bNode||console.log("The alignment data for "+t[o]+" is unavailable...");continue}if(void 0===a[0].score)continue;let d=parseFloat(a[0].score),c=t[o].substr(0,t[o].indexOf("|")),h=t[o].substr(t[o].indexOf("|")+1);if(s){if(a[0].score<this.TMThresholdTemplate||a[0].num_res<10)continue}else if(a[0].score<this.TMThresholdTemplate||a[0].num_res<20){n.bNode||console.log("bRound1: "+s+": domainid "+c+" and refpdbname "+h+" were skipped due to a TM-score less than "+this.TMThresholdTemplate);continue}if(s?(n.bNode||console.log("domainid: "+c+" refpdbname "+h+" TM-score: "+a[0].score),r[c]||(r[c]={}),r[c][h]=d):n.bNode||console.log("refpdbname "+h+" TM-score: "+a[0].score),!s&&a[0].segs){let e=!1,t=!1,s=!1,l=!1,r=!0,o=!0,d=!0,p=!0,m=c.split(",")[0];for(let n=0,c=a[0].segs.length;n<c;++n){let c=a[0].segs[n],h=m+"_"+c.t_start,u=parseInt(c.q_start);if(u>2540&&u<2560?e=!0:u>3540&&u<3560?t=!0:u>7540&&u<7560?s=!0:u>8540&&u<8560&&(l=!0),2550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(r=!1)}else if(3550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(o=!1)}else if(7550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(d=!1)}else if(8550==u){"helix"==i.firstAtomObjCls.getFirstAtomObj(i.residues[h]).ss&&(p=!1)}if(e&&t&&s&&l)break}if(!(e&&t&&s&&l&&r&&o&&d&&p)){n.bNode||e&&t&&s&&l||console.log("Some of the Ig strands B, C, E, F are missing in the domain "+c+"..."),n.bNode||r&&o&&d&&p||console.log("Some of the Ig strands B, C, E, F are not beta sheets..."),i.domainid2refpdbname[c][0]==h&&(delete i.domainid2refpdbname[c],delete i.domainid2score[c]);continue}}s||n.bNode||console.log("domainid: "+c),(!l.hasOwnProperty(c)||d>=parseFloat(i.domainid2score[c].split("_")[0]))&&(i.domainid2score[c]=a[0].score+"_"+a[0].frac_identical+"_"+a[0].num_res,i.domainid2refpdbname[c]=s?d>=this.TMThresholdIgType?[h]:["all_templates"]:[h],l[c]=a[0].segs,i.domainid2ig2kabat[c]=a[0].ig2kabat,i.domainid2ig2imgt[c]=a[0].ig2imgt)}if(s)for(let e in r)if(!n.bNode&&"all_templates"==i.domainid2refpdbname[e][0]){let t=r[e],s=Object.keys(t);s.sort((function(e,s){return t[s]-t[e]})),i.domainid2refpdbname[e]=s.slice(0,this.topClusters)}return l}async parseAlignData(e,t,s){let i=this.icn3d,n=i.icn3dui,l=!1,r=this.parseAlignData_part1(e,t,s);if(0==Object.keys(r).length)return l=!0,l;if(s){n.bNode||console.log("Start round 2 alignment with the reference culsters "+JSON.stringify(i.domainid2refpdbname));let e=[],t=[],s=n.htmlCls.tmalignUrl;for(let l in i.domainid2refpdbname){let r=[],o=i.domainid2refpdbname[l],a=l.substr(0,l.indexOf(","));i.refpdbHash.hasOwnProperty(a)&&(o=[a],n.bNode||console.log("Adjusted refpdbname for domainid "+l+": "+a));let d=[];for(let e=0,t=o.length;e<t;++e){let t=o[e];i.refpdbHash[t]&&(d=d.concat(i.refpdbHash[t]))}if(0==d.length)continue;for(let e=0,t=d.length;e<t;++e){let t=n.htmlCls.baseUrl+"mmcifparser/mmcifparser.cgi?refpdbid="+d[e],s=n.getAjaxPromise(t,"text");r.push(s)}let c=await this.promiseWithFixedJobs(r),h=i.domainid2pdb[l];for(let r=0,o=c.length;r<o;++r){let o=i.defaultPdbId+r,a=c[r].value;a="HEADER "+o+"\n"+a;let p={pdb_query:a,pdb_target:h,queryid:d[r]},m=n.getAjaxPostPromise(s,p);e.push(m),t.push(l+"|"+d[r])}}let r=[];return r=await this.promiseWithFixedJobs(e),l=await this.parseAlignData(r,t,!1),l}return this.parseAlignData_part3(r),l}parseAlignData_part3(e){let t=this.icn3d,s=t.icn3dui,i={};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 s=e.split(",")[0];i.hasOwnProperty(s)||(t.chainid2refpdbname[s]=[]),i[s]=1,t.chainid2refpdbname.hasOwnProperty(s)||(t.chainid2refpdbname[s]=[]),t.chainid2refpdbname[s].push(t.domainid2refpdbname[e][0]+"|"+e)}t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={}),t.domainid2info||(t.domainid2info={});for(let i in e){let n=e[i],l=i.split(",")[0],r=this.getTemplateList(i),o=r.refpdbname,a=r.score,d=r.seqid,c=r.nresAlign;if(o){let e="The reference PDB for domain "+i+" is "+o+". The TM-score is "+a+". The sequence identity is "+d+". The number of aligned residues is "+c+".";s.bNode||(console.log(e),s.htmlCls.clickMenuCls.setLogCmd(e,!1,!0)),t.domainid2info[i]={refpdbname:o,score:a,seqid:d,nresAlign:c}}let h,p,m,u,g,f,C=!1,b=!1,y=!1,v=!1,_=!1,w=[],S=[],A=[],x=[];for(let e=0,i=n.length;e<i;++e){let i=n[e];if(!i)continue;let r=l+"_"+i.t_start;if(-1!=i.q_start.indexOf("3550")?(C=!0,h=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]),g=0):-1!=i.q_start.indexOf("4550")?(b=!0,p=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]),++g):-1!=i.q_start.indexOf("6550")?(v=!0,m=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]),++g):-1!=i.q_start.indexOf("7550")&&(_=!0,u=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r])),i.q_start>=3545&&i.q_start<=3555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]);e&&w.push(e)}else if(i.q_start>=7545&&i.q_start<=7555){let e=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[r]);e&&S.push(e)}if(-1!=i.q_start.indexOf("8550")&&1==g&&h&&u&&(p||m)){let e=999,t=999;for(let t=0,s=w.length;t<s;++t){let s=b?p.coord.distanceTo(w[t].coord):m.coord.distanceTo(w[t].coord);s<e&&(e=s)}for(let e=0,s=S.length;e<s;++e){let s=b?p.coord.distanceTo(S[e].coord):m.coord.distanceTo(S[e].coord);s<t&&(t=s)}e=parseInt(e),t=parseInt(t);let i=b?parseInt(p.resi)-parseInt(h.resi):parseInt(m.resi)-parseInt(h.resi),n=b?parseInt(u.resi)-parseInt(p.resi):parseInt(u.resi)-parseInt(m.resi),l=1;b?(e>t+l||e==t+l&&i>n+l)&&(A.push(p.resi),s.bNode||console.log("Rename strand C' to D: distToC "+e+" distToE "+t+" resiDistToC "+i+" resiDistToE "+n)):v&&(e+l<t||e+l==t&&i+l<n)&&(x.push(m.resi),s.bNode||console.log("Rename strand D to C': distToC "+e+" distToE "+t+" resiDistToC "+i+" resiDistToE "+n))}if(C&&b&&y&&v&&_)break}for(let e=0,s=n.length;e<s;++e){let s=n[e];if(!s)continue;s.q_start;let r=parseInt(s.q_start),o="";isNaN(s.q_start)&&(o=s.q_start.substr(s.q_start.length-1,1));let a=l+"_"+s.t_start,d=r,c=this.getLabelFromRefnum(d,o);f=c?c.replace(new RegExp(d,"g"),""):void 0;let h=f;if("C'"==f&&A.length>0){for(let e=0,t=A.length;e<t;++e)if(parseInt(s.t_start)<parseInt(A[e])+10&&parseInt(s.t_start)>parseInt(A[e])-10){h="D";break}}else if("D"==f&&x.length>0)for(let e=0,t=x.length;e<t;++e)if(parseInt(s.t_start)<parseInt(x[e])+10&&parseInt(s.t_start)>parseInt(x[e])-10){h="C'";break}f!=h&&(c=this.getLabelFromRefnum(d,o,h)),"helix"!=t.firstAtomObjCls.getFirstAtomObj(t.residues[a]).ss&&(t.resid2refnum[a]=c,t.resid2domainid[a]=i)}}Object.keys(t.resid2refnum).length>0?t.bShowRefnum=!0:s.bNode||t.bNoIg||(console.log("No Ig reference numbers are assigned based on the reference structures in iCn3D..."),t.bNoIg=!0),t.chainid2igtrack||(t.chainid2igtrack={});for(let e in t.chains){let s=t.firstAtomObjCls.getFirstAtomObj(t.chains[e]);if(t.proteins.hasOwnProperty(s.serial)){let s=t.showSeqCls.getSeq(e);t.chainid2igtrack[e]=this.ajdustRefnum(s,e)}}}getStrandFromRefnum(e,t){this.icn3d.icn3dui;let s,i=parseInt(e);return s=i<1e3?void 0:i>=1200&&i<1320?"A---":i>=1320&&i<1420?"A--":i>=1420&&i<1520?"A-":i>=1520&&i<1620?"A":i>=1620&&i<1720?"A+":i>=1720&&i<1820?"A++":i>=1820&&i<2e3?"A'":i>=2e3&&i<3e3?"B":i>=3e3&&i<3420?"C--":i>=3420&&i<3520?"C-":i>=3520&&i<4e3?"C":i>=4e3&&i<5e3?"C'":i>=5e3&&i<6e3?"C''":i>=6e3&&i<7e3?"D":i>=7e3&&i<7620?"E":i>=7620&&i<8e3?"E+":i>=8e3&&i<9e3?"F":i>=9e3&&i<9620?"G":i>=9620&&i<9720?"G+":i>=9720&&i<9820?"G++":i>=9820&&i<9900?"G+++":i>9900?void 0:" ",t&&(s=t),s}getLabelFromRefnum(e,t,s){this.icn3d.icn3dui;let i=this.getStrandFromRefnum(e,s),n=e.toString();return"C'"==s&&"6"==n.substr(0,1)?n="4"+n.substr(1):"D"==s&&"4"==n.substr(0,1)&&(n="6"+n.substr(1)),i?i+n+t:void 0}async parseCustomRefFile(e){let t=this.icn3d;t.icn3dui,t.bShowCustomRefnum=!0;let s=e.split("\n");t.resid2refnum||(t.resid2refnum={}),t.refnum2residArray||(t.refnum2residArray={}),t.chainsMapping||(t.chainsMapping={});let i=[];for(let e=0,t=s.length;e<t;++e){let t=s[e].split(",");i.push(t)}for(let e=1,s=i[0].length;e<s;++e){if(!i[0][e])continue;let s=i[0][e].trim();if(s)for(let n=1,l=i.length;n<l;++n){if(!i[n][e])continue;let l=i[n][0].trim()+"_"+i[n][e].trim();t.refnum2residArray[s]?t.refnum2residArray[s].push(l):t.refnum2residArray[s]=[l]}}for(let e=1,s=i.length;e<s;++e){let s=i[e][0].trim();for(let n=1,l=i[e].length;n<l;++n){if(!i[e][n]||!i[0][n])continue;let l=i[e][n].trim(),r=i[0][n].trim();t.chainsMapping.hasOwnProperty(s)||(t.chainsMapping[s]={});let o=s+"_"+l;l&&r?(t.resid2refnum[o]=r,t.chainsMapping[s][o]=r):t.chainsMapping[s][o]=l}}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 s=this.icn3d,i=s.icn3dui,n="";if("igstrand"==e||"IgStrand"==e){if(s.bShowRefnum)for(let e in s.chains){let t=s.firstAtomObjCls.getFirstAtomObj(s.chains[e]);if(s.proteins.hasOwnProperty(t.serial)){let t=[];for(let i=0;i<s.chainsSeq[e].length;++i)t.push(s.chainsSeq[e][i].name);s.annoIgCls.showRefNum(t,e)}}let e={};for(let t in s.resid2refnum){let n=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(!n)continue;let l=i.utilsCls.residueName2Abbr(n.resn.substr(0,3)),r=s.resid2domainid[t],o=s.resid2refnum[t];if(o){let e=s.refnumCls.rmStrandFromRefnumlabel(o);s.domainid2ig2kabat[r]&&s.domainid2ig2kabat[r][e]}s.resid2refnum[t]&&(s.residIgLoop.hasOwnProperty(t)?e[t+"_"+l]=s.resid2refnum[t]+"_loop":e[t+"_"+l]=s.resid2refnum[t])}for(let t in s.structures){let i=0,l="";for(let n=0,r=s.structures[t].length;s.bShowRefnum&&n<r;++n){let r=s.structures[t][n],o=s.chain2igArray[r];if(o&&o.length>0){l+='{"'+r+'": {\n';for(let t=0,n=o.length;t<n;++t){let n=o[t].startPosArray,a=o[t].endPosArray,d=o[t].domainid,c=s.domainid2info[d];if(c){l+='"'+d+'": {\n',l+='"refpdbname":"'+c.refpdbname+'", "score":'+c.score+', "seqid":'+c.seqid+', "nresAlign":'+c.nresAlign+', "data": [';for(let t=0,i=n.length;t<i;++t){let i=n[t],o=a[t];for(let t=i;t<=o;++t){const i=r+"_"+s.chainsSeq[r][t].resi+"_"+s.chainsSeq[r][t].name;l+='{"'+i+'": "'+e[i]+'"},\n'}}l+="],\n",l+="},\n",i=1}}l+="}},\n"}}n+='{"'+t+'": {"Ig domain" : '+i+', "igs": [\n',i&&(n+=l),n+="]}},\n"}}else if("kabat"==e||"Kabat"==e){let e={};for(let t in s.resid2refnum){let n,l=s.resid2domainid[t],r=s.resid2refnum[t],o=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(!o)continue;let a=i.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(r){let e=s.refnumCls.rmStrandFromRefnumlabel(r);n=s.domainid2ig2kabat[l]?s.domainid2ig2kabat[l][e]:void 0}e[t+"_"+a]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}else if("imgt"==e||"IMGT"==e){let e={};for(let t in s.resid2refnum){let n,l=s.resid2domainid[t],r=s.resid2refnum[t],o=s.firstAtomObjCls.getFirstAtomObj(s.residues[t]);if(!o)continue;let a=i.utilsCls.residueName2Abbr(o.resn.substr(0,3));if(r){let e=s.refnumCls.rmStrandFromRefnumlabel(r);n=s.domainid2ig2imgt[l]?s.domainid2ig2imgt[l][e]:void 0}e[t+"_"+a]=n}n+='{"Kabat": ',n+=JSON.stringify(e),n+=",\n"}if(t||(n="["+n+"]"),i.bNode)return n;{let t=Object.keys(i.utilsCls.getHlStructures()).join(",");s.saveFileCls.saveFile(t+"_refnum_"+e+".txt","text",[n])}}async promiseWithFixedJobs(e){let t=this.icn3d,s=t.icn3dui;s.bNode||s.icn3d.ParserUtilsCls.showLoading();let i=[],n=s.cfg.maxajax?s.cfg.maxajax:6*t.refpdbArray.length;for(let t=0,s=parseInt((e.length-1)/n+1);t<s;++t){let l=[];l=t==s-1?e.slice(t*n,e.length):e.slice(t*n,(t+1)*n);let r=Promise.allSettled(l),o=await r;i=i.concat(o)}return s.bNode||s.icn3d.ParserUtilsCls.hideLoading(),i}ajdustRefnum(e,t){let s=this.icn3d,i=s.icn3dui;if(!s.chainid2refpdbname[t])return!1;let n,l,r,o,a,d,c,h,p="",m="",u="",g=!1,f=!1,C=1,b=!1;if(!i.bNode){let e=i.hashUtilsCls.intHash(s.chains[t],s.hAtoms);s.firstAtomObjCls.getResiduesFromAtoms(e)}let y=[],v={},_=0,w=0,S=0,A=0,x=!1;for(let i=0,k=e.length;i<k;++i,++w,++S,++A){let e,k=s.ParserUtilsCls.getResi(t,i),O=t+"_"+k;n=s.resid2refnum[O];let R=n?n.substr(0,1):"";if(b||!n||"A"!=R&&"B"!=R||(b=!0,w=1,x=!1),"G"!=m.substr(0,1)||n||(b=!1),n){e=s.resid2domainid[O],l=s.refnumCls.rmStrandFromRefnumlabel(n),p=n.replace(new RegExp(l,"g"),""),l.substr(0,1),r=l,d=parseInt(r),c=(d-1e3*parseInt(d/1e3)).toString(),h=(d-100*parseInt(d/100)).toString(),f="9"==c.substr(0,1)||"9"==h.substr(0,1)||"0"==h.substr(0,1)||"1"==h.substr(0,1),f&&(s.residIgLoop[O]=1),a=r.replace(d.toString(),""),o=a+"_"+C;let t=parseInt(d.toString().substr(0,2));if(g="5"!=c.substr(0,1)&&"18"!=t,p&&" "!=p){if(!f||g&&!f){let t=parseInt(d.toString().substr(d.toString().length-2,2));if(p!=m&&p!=u){if(x=!1,v[p+o]&&(++C,o=r.replace(d.toString(),"")+"_"+C),v[p+o]=1,y[_]={},y[_].startResi=k,y[_].startRefnum=d,S=0,y[_].domainid=e,y[_].endResi=k,y[_].endRefnum=d,50==t&&(y[_].anchorRefnum=d,y[_].resCntBfAnchor=S,A=0,x=!0),!x&&t>=46&&t<=54){let e=t-50;y[_].anchorRefnum=d-e,y[_].resCntBfAnchor=S-e,A=e,x=!0}g&&(y[_].anchorRefnum=0),y[_].strandPostfix=a,y[_].strand=p,y[_].postfix=o,y[_].loopResCnt=w-1,++_,w=0}else if(v[p+o]){if(50==t&&(y[_-1].anchorRefnum=d,y[_-1].resCntBfAnchor=S,y[_-1].startRefnum=y[_-1].anchorRefnum-y[_-1].resCntBfAnchor,A=0,x=!0),!x&&(51==t||52==t||53==t||54==t)){let e=t-50;y[_-1].anchorRefnum=d-e,y[_-1].resCntBfAnchor=S-e,y[_-1].startRefnum=y[_-1].anchorRefnum-y[_-1].resCntBfAnchor,A=e,x=!0}g&&(y[_-1].anchorRefnum=0),y[_-1].domainid=e,y[_-1].endResi=k,y[_-1].endRefnum=d,y[_-1].resCntAtAnchor=A,y[_-1].anchorRefnum&&(y[_-1].endRefnum=y[_-1].anchorRefnum+y[_-1].resCntAtAnchor),w=0}}u=p}}m=p}for(let e=0,i=y.length;e<i;++e){let n=s.firstAtomObjCls.getFirstAtomObj(s.residues[t+"_"+y[e].startResi]),l=s.firstAtomObjCls.getFirstAtomObj(s.residues[t+"_"+y[e].endResi]),r=s.setSeqAlignCls.getPosFromResi(t,y[e].startResi),o=s.setSeqAlignCls.getPosFromResi(t,y[e].endResi);if("sheet"==n.ss&&!n.ssbegin)for(let i=1;i<=8;++i){let n=r-i,l=s.ParserUtilsCls.getResi(t,n);if(e>0&&parseInt(l)<=parseInt(y[e-1].endResi))break;let o=t+"_"+l,a=s.firstAtomObjCls.getFirstAtomObj(s.residues[o]),d=s.resid2domainid[o];if(a.ssbegin){let o=y[e].startRefnum;y[e].startResi=l,y[e].startRefnum-=i,y[e].loopResCnt-=i,y[e].loopResCnt<0&&(y[e].loopResCnt=0),y[e].resCntBfAnchor+=i;for(let a=1;a<=i;++a){n=r-a,l=s.ParserUtilsCls.getResi(t,n);let i=t+"_"+l;delete s.residIgLoop[i],s.resid2refnum[i]=y[e].strand+(o-a).toString(),s.resid2domainid[i]=d}break}}if("sheet"==l.ss&&!l.ssend)for(let n=1;n<=8;++n){let l=o+n,r=s.ParserUtilsCls.getResi(t,l);if(e<i-1&&parseInt(r)>=parseInt(y[e+1].startResi))break;let a=t+"_"+r,d=s.firstAtomObjCls.getFirstAtomObj(s.residues[a]),c=s.resid2domainid[a];if(d.ssend){let a=y[e].endRefnum;y[e].endResi=r,y[e].endRefnum+=n,e<i-1&&(y[e+1].loopResCnt-=n,y[e+1].loopResCnt<0&&(y[e+1].loopResCnt=0)),y[e].resCntAtAnchor+=n;for(let i=1;i<=n;++i){l=o+i,r=s.ParserUtilsCls.getResi(t,l);let n=t+"_"+r;delete s.residIgLoop[n],s.resid2refnum[n]=y[e].strand+(a+i).toString(),s.resid2domainid[n]=c}break}}}let k={};for(let e=y.length-1;e>=0;--e){"G"!=y[e].strand&&y[e].endRefnum-y[e].startRefnum+1<3&&(y[e+1]&&(y[e+1].loopResCnt+=y[e].loopResCnt+parseInt(y[e].endResi)-parseInt(y[e].startResi)+1),y[e].startResi,y.splice(e,1))}_=0;let O,R,I=0,E=!0,T=!0,P=0;b=!1;let D=0;if(y.length>0)for(let i=0,l=e.length;i<l;++i,++I,++D){let e,l=s.ParserUtilsCls.getResi(t,i),o=t+"_"+l;if(n=s.resid2refnum[o],p=y[_].strand,n){e=s.resid2domainid[o],r=s.refnumCls.rmStrandFromRefnumlabel(n),R=parseInt(r),O=p+R,p=n.replace(new RegExp(r,"g"),"");let t=n.substr(0,1);b||"A"!=t&&"B"!=t||(b=!0,E=!0,I=0)}let a=s.firstAtomObjCls.getFirstAtomObj(s.residues[o]);if(a&&s.proteins.hasOwnProperty(a.serial)){let t=!1,i=!1,r=!1;if(t=parseInt(l)==parseInt(y[_].startResi)&&l!=y[_].startResi?l<y[_].startResi:parseInt(l)<parseInt(y[_].startResi),r=parseInt(l)==parseInt(y[_].endResi)&&l!=y[_].endResi?l>y[_].endResi:parseInt(l)>parseInt(y[_].endResi),i=!t&&!r,t)if(s.residIgLoop[o]=1,E)b?(R=y[_].startRefnum-y[_].loopResCnt+I,O=y[_].strand+R,n=O+y[_].strandPostfix,e=y[_].domainid):(O=void 0,n=void 0);else if(P>=0&&("G"==y[P].strand.substr(0,1)||"F"==y[P].strand.substr(0,1)&&"G"!=y[_].strand.substr(0,1)))T?b&&s.resid2refnum[o]?(T=!0,R=y[P].endRefnum+I,O=y[P].strand+R,n=O+y[P].strandPostfix,e=y[P].domainid):(b=!1,E=!0,T=!1,O=void 0,n=void 0):(O=void 0,n=void 0);else{T=!0;let t=y[_].loopResCnt;I<=parseInt(t/2+.5)?y[P]&&(R=y[P].endRefnum+I,O=y[P].strand+R,n=O+y[P].strandPostfix,e=y[P].domainid):(R=y[_].startRefnum-t+I-1,O=y[_].strand+R,n=O+y[_].strandPostfix,e=y[_].domainid)}else i?(E=!1,y[_].anchorRefnum&&(l==y[_].startResi?(D=y[_].anchorRefnum-y[_].resCntBfAnchor,y[_].startRefnum=D):l==y[_].endResi&&(y[_].endRefnum=D),O=y[_].strand+D,n=O+y[_].strandPostfix,e=y[_].domainid),l==y[_].endResi&&(++_,I=0,y[_]||--_)):r&&(s.residIgLoop[o]=1,T?s.resid2refnum[o]?(T=!0,R=y[_].endRefnum+I,O=y[_].strand+R,n=O+y[_].strandPostfix,e=y[_].domainid):(T=!1,O=void 0,n=void 0):(O=void 0,n=void 0))}else n=void 0;m=p,P=_-1,k.hasOwnProperty(e)?(delete s.resid2refnum[o],delete s.residIgLoop[o],delete s.resid2domainid[o]):(s.resid2refnum[o]=n,s.resid2domainid[o]=e,r=s.refnumCls.rmStrandFromRefnumlabel(n),s.refnum2residArray.hasOwnProperty(r)?s.refnum2residArray[r].push(o):s.refnum2residArray[r]=[o],s.chainsMapping.hasOwnProperty(t)||(s.chainsMapping[t]={}),s.chainsMapping[t][o]=O||l)}return!0}}class Ss{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,s,i,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"),s=.5*$("#"+n.pre+"dl_selectannotations").dialog("option","height"),i=s,$("#"+n.pre+"dl_selectannotations").dialog("option","height",s),$("#"+e).dialog("option","width",t),$("#"+e).dialog("option","height",s);let l={my:"left top",at:"right top+"+i,of:"#"+n.pre+"viewer",collision:"none"};$("#"+e).dialog("option","position",l)}}async retrieveScap(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this;i.bScap=!0;let r="",o=e.split(","),a={},d=[],c={};for(let e=0,t=o.length;e<t;++e){let s=o[e].split("_"),l=s[0]+"_"+s[1]+"_"+s[2];a=n.hashUtilsCls.unionHash(a,i.residues[l]),d.push(l),c[s[1]+"_"+s[2]]="",r+=s[1]+"_"+s[2]+"_"+s[3],e!=t-1&&(r+=",")}let h=i.resid2specCls.residueids2spec(d),p="select "+h,m=i.showInterCls.pickCustomSphere_base(10,a,i.atoms,!1,!1,void 0,p,!1),u=Object.keys(m.residues);i.hAtoms={};for(let e=0,t=u.length;e<t;++e){let t=u[e];for(let e in i.residues[t])i.hAtoms[e]=1}i.hAtoms=n.hashUtilsCls.unionHash(i.hAtoms,a),i.hAtoms=n.hashUtilsCls.exclHash(i.hAtoms,i.chemicals);let g,f=i.saveFileCls.getAtomPDB(i.hAtoms),C=n.htmlCls.baseUrl+"scap/scap.cgi",b=Object.keys(i.structures)[0],y={pdb:f,snp:r,pdbid:b,v:"2"};g=await n.getAjaxPostPromise(C,y,!0,void 0,void 0,void 0,"text");let v=g.indexOf("\n"),_=g.substr(0,v),w=g.substr(v+1);console.log("free energy: "+_+" kcal/mol");let S=n.hashUtilsCls.cloneHash(i.hAtoms);for(let e in S){let t=i.atoms[e],s=t.structure+"_"+t.chain,l=s+"_"+t.resi;i.chainsMapping.hasOwnProperty(s)||(i.chainsMapping[s]={}),i.chainsMapping[s][l]=n.utilsCls.residueName2Abbr(t.resn)+t.resi}let A=w.split("\n"),x={};for(let e in A){let t=A[e],s=t.substr(0,6);if("ATOM "===s||"HETATM"===s){let e=t.substr(20,2).trim();""===e&&(e="A");let s=e+"_"+t.substr(22,5).trim();c.hasOwnProperty(s)&&(c[s]+=t+"\n"),x[s]=1}}let k=i.saveFileCls.getAtomPDB(i.atoms,!1,!1,!1,c);i.hAtoms={};i.loadPDBCls.loadPDB(k,b,!1,!1,!0,!0);for(let e in i.residues){if(e.substr(0,e.indexOf("_"))==b+"2"){let t=b+e.substr(e.indexOf("_")),s=i.firstAtomObjCls.getFirstAtomObj(i.residues[t]);if(s)for(let t in i.residues[e])i.atoms[t].ss=s.ss,i.atoms[t].ssbegin=s.ssbegin,i.atoms[t].ssend=s.ssend}}for(let e in i.secondaries){if(e.substr(0,e.indexOf("_"))==b+"2"){let t=b+e.substr(e.indexOf("_"));i.secondaries[e]=i.secondaries[t]}}i.setStyleCls.setAtomStyleByOptions(i.opts),i.setColorCls.setColorByOptions(i.opts,i.hAtoms);let O={};for(let e in i.hAtoms){let t=i.atoms[e],s=t.chain+"_"+t.resi;x.hasOwnProperty(s)&&(O[e]=1)}i.hAtoms=n.hashUtilsCls.unionHash(S,O),i.dAtoms=n.hashUtilsCls.cloneHash(i.hAtoms),i.transformCls.zoominSelection(),i.setOptionCls.setStyle("proteins","stick");for(let e in O){let t=i.atoms[e];if(!t.het){let s=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi,n=i.firstAtomObjCls.getFirstAtomObj(i.residues[s]);n&&(i.atoms[e].color=n.color,i.atomPrevColors[e]=n.color)}let s=t.structure+"_"+t.chain,l=s+"_"+t.resi,r=t.structure.substr(0,t.structure.length-1)+"_"+t.chain+"_"+t.resi;if(i.chainsMapping.hasOwnProperty(s)||(i.chainsMapping[s]={}),i.chainsMapping[s][l]=n.utilsCls.residueName2Abbr(t.resn)+t.resi,-1!=d.indexOf(r)){let e=i.firstAtomObjCls.getFirstAtomObj(i.residues[r]);i.chainsMapping[s][l]=n.utilsCls.residueName2Abbr(e.resn)+e.resi}}if(s)await l.exportPdbProfix(!1,k,r),i.drawCls.draw();else{let e=h,s="snp_"+r;if(await i.selByCommCls.selectByCommand(e,s,s),i.opts.color="atom",i.setColorCls.setColorByOptions(i.opts,i.hAtoms),i.viewInterPairsCls.clearInteractions(),t){let e="linegraph";await i.viewInterPairsCls.viewInteractionPairs(["selected"],["non-selected"],!1,e,!0,!0,!0,!0,!0,!0),l.adjust2DWidth("dl_linegraph")}i.hAtoms=i.dAtoms,i.drawCls.draw(),n.alertAlt||(n.alertAlt=!0,alert('Please press the letter "a" to alternate between wild type and mutant.'))}$("#"+i.pre+"mn2_alternateWrap").show();let R=i.pre+"selection";$("#"+R).show()}async exportPdbProfix(e,t,s){let i,n=this.icn3d,l=n.icn3dui;if(t)i=t;else{let e=l.hashUtilsCls.intHash(n.dAtoms,n.hAtoms),t=!0;i=n.saveFileCls.getAtomPDB(e,void 0,void 0,void 0,void 0,void 0,t)}let r,o=l.htmlCls.baseUrl+"scap/scap.cgi",a={pdb:i,profix:"1",hydrogen:e?"1":"0"};try{r=await l.getAjaxPostPromise(o,a,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(l.bNode)return r;{let t=Object.keys(l.utilsCls.getHlStructures()).join(","),i=e?"add_hydrogen":"add_missing_atoms";s&&(i=s),n.saveFileCls.saveFile(t+"_icn3d_"+i+".pdb","text",[r])}}}class As{constructor(e){this.icn3d=e}async applyCommandSymd(e){this.icn3d.icn3dui,await this.retrieveSymd()}async retrieveSymd(){let e=this.icn3d,t=e.icn3dui,s=this,i=t.htmlCls.baseUrl+"symd/symd.cgi",n=t.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);n=t.hashUtilsCls.intHash(n,e.proteins);let l=Object.keys(n).length,r={};for(let t in n){let s=e.atoms[t];r[s.structure+"_"+s.chain+"_"+s.resi]=1}if(l>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 a,d={pdb:o,pdbid:Object.keys(e.structures).toString()};try{a=await t.getAjaxPostPromise(i,d,!0);let n,l,o,c=a.rcsb_struct_symmetry,h="none";if(void 0!==c){let i;void 0!==e.rmsd_supr&&void 0!==e.rmsd_supr.rot&&(n=e.rmsd_supr.rot,l=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,l=[];for(let e=0,r=n.length;e<r;++e){let r=[],o=new THREE.Vector3(n[e].start[0],n[e].start[1],n[e].start[2]),a=new THREE.Vector3(n[e].end[0],n[e].end[1],n[e].end[2]);i=n[e].order,r.push(o),r.push(a);let d=s.getAxisColor(c[t].symbol,n[e].order),h=s.getPolygonColor(c[t].symbol);r.push(d),r.push(h),r.push(n[e].order),r.push("selection"),l.push(r)}let r={};r[h]=l,e.symdArray.push(r)}if(0==e.symdArray.length)$("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+a.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=a.seqalign.replace(/ /g,"").split(","),l=a.nres,o=a.shift,d=a.rmsd,h=Object.keys(r),p={},m={},u=[],g=[],f=0,C=0,b={};for(let e=0,s=n[0].length;e<s;++e){let s=n[0][e],i=n[1][e];if("-"!=s){if(s==s.toUpperCase()){p[h[f]]=1;let e=t.utilsCls.getIdArray(h[f]);u.push(s+" $"+e[0]+"."+e[1]+":"+e[2]);let i=e[0]+"_"+e[1];b.hasOwnProperty(i)||(b[i]=[]),b[i].push(u.length-1)}++f}if("-"!=i){if(i==i.toUpperCase()){let e=(C+o+l)%l;m[h[e]]=1;let s=t.utilsCls.getIdArray(h[e]);g.push(i+" $"+s[0]+"."+s[1]+":"+s[2])}++C}}let y={},v={},_=[],w=[],S=!1;if(1==Object.keys(b).length){S=!0;let e=parseInt(u.length/i+.5),t=Object.keys(p),s=Object.keys(m);for(let i=0;i<e;++i)y.hasOwnProperty(s[i])||(_.push(u[i]),w.push(g[i]),y[t[i]]=1,v[s[i]]=1)}else{let e,t=0;for(let s in b)b[s].length>t&&(t=b[s].length,e=s);let s=Object.keys(p),i=Object.keys(m);for(let t=0,n=b[e].length;t<n;++t){let n=b[e][t];y.hasOwnProperty(i[n])||(_.push(u[n]),w.push(g[n]),y[s[n]]=1,v[i[n]]=1)}}let A="<br>";A+="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 "+a.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(A),s.setSeqAlignForSymmetry(_,w,S);let x=!1,k=t.htmlCls.alignSeqCls.getAlignSequencesAnnotations(Object.keys(e.alnChains),void 0,void 0,x,S);A=$("#"+e.pre+"dl_sequence2").html()+k.sequencesHtml,$("#"+e.pre+"dl_sequence2").html(A),$("#"+e.pre+"dl_sequence2").width(t.htmlCls.RESIDUE_WIDTH*k.maxSeqCnt+200),t.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences from SymD");let O=Object.keys(e.defNames2Residues).length+Object.keys(e.defNames2Atoms).length,R="symOri"+O;e.selectionCls.selectResidueList(y,R,R),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(y))+" | name "+R,!1),R="symPerm"+O,e.selectionCls.selectResidueList(v,R,R),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(v))+" | name "+R,!1),R="symBoth"+O,y=t.hashUtilsCls.unionHash(y,v),e.selectionCls.selectResidueList(y,R,R),e.selectionCls.updateSelectionNameDesc(),t.htmlCls.clickMenuCls.setLogCmd("select "+e.resid2specCls.residueids2spec(Object.keys(y))+" | name "+R,!1)}}else $("#"+e.pre+"dl_symd").html("<br>The selected residues have no detected symmetry with a Z score of "+a.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(s){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(" ")),s=e.indexOf("$"),i=e.indexOf("."),n=e.indexOf(":"),l=e.substr(s+1,i-s-1),r=e.substr(i+1,n-i-1),o=e.substr(n+1);return{resn:t,resid:l+"_"+r+"_"+o,resi:o,aligned:!0}}setSeqAlignForSymmetry(e,t,s){let i=this.icn3d,n=i.icn3dui;i.conservedName1="symOri_cons",i.conservedName2="symPerm_cons",i.consHash1={},i.consHash2={},i.alnChainsAnTtl={},i.alnChainsAnno={},i.alnChainsSeq={},i.alnChains={},i.alnChainsSeq={};let l={};for(let r=0,o=e.length;r<o;++r){let o,a=this.getResObj(e[r]),d=this.getResObj(t[r]),c=a.resid.substr(0,a.resid.lastIndexOf("_")),h=d.resid.substr(0,d.resid.lastIndexOf("_")),p=h;if(s){p=h.substr(0,h.indexOf("_"))+"2"+h.substr(h.indexOf("_"))}l[a.resid]=1,l[d.resid]=1,o=a.resn==d.resn?"#FF0000":"#0000FF";let m="#"+i.showAnnoCls.getColorhexFromBlosum62(a.resn,d.resn);a.color=o,d.color=o,a.color2=m,d.color2=m;for(let e in i.residues[a.resid])i.atoms[e].color=n.parasCls.thr(o),i.atomPrevColors[e]=n.parasCls.thr(o);for(let e in i.residues[d.resid])i.atoms[e].color=n.parasCls.thr(o),i.atomPrevColors[e]=n.parasCls.thr(o);void 0===i.alnChainsAnTtl[c]&&(i.alnChainsAnTtl[c]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnTtl[c][e]&&(i.alnChainsAnTtl[c][e]=[]);for(let e=0;e<3;++e)i.alnChainsAnTtl[c][e].push("");void 0===i.alnChainsSeq[c]&&(i.alnChainsSeq[c]=[]),void 0===i.alnChainsSeq[p]&&(i.alnChainsSeq[p]=[]),i.alnChainsSeq[c].push(a),i.alnChainsSeq[p].push(d),void 0===i.alnChains[c]&&(i.alnChains[c]={}),void 0===i.alnChains[p]&&(i.alnChains[p]={}),$.extend(i.alnChains[c],i.residues[c+"_"+a.resi]),$.extend(i.alnChains[p],i.residues[p+"_"+d.resi]),i.consHash1[c+"_"+a.resi]=1,i.consHash2[p+"_"+d.resi]=1,void 0===i.alnChainsAnno[c]&&(i.alnChainsAnno[c]=[]);for(let e=0;e<3;++e)void 0===i.alnChainsAnno[c][e]&&(i.alnChainsAnno[c][e]=[]);let u=".";r%5==0&&(u="*"),r%10==0&&(u="|"),i.alnChainsAnno[c][0].push(u);let g="";r%10==0&&(g=r.toString()),i.alnChainsAnno[c][1].push(g)}}async retrieveSymmetry(e){let t,s=this.icn3d,i=s.icn3dui,n=this,l="https://data.rcsb.org/rest/v1/core/assembly/"+e+"/1";try{t=await i.getAjaxPromise(l,"json",!1)}catch(e){return $("#"+s.pre+"dl_symmetry").html("<br>This structure has no symmetry."),void i.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}let r,o,a,d=t.rcsb_struct_symmetry;if(void 0!==d){void 0!==s.rmsd_supr&&void 0!==s.rmsd_supr.rot&&(r=s.rmsd_supr.rot,o=s.rmsd_supr.trans1,a=s.rmsd_supr.trans2),s.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 i=d[e].rotation_axes,l=[];for(let t=0,c=i.length;t<c;++t){let c=[],h=new THREE.Vector3(i[t].start[0],i[t].start[1],i[t].start[2]),p=new THREE.Vector3(i[t].end[0],i[t].end[1],i[t].end[2]);void 0!==s.rmsd_supr&&void 0!==s.rmsd_supr.rot&&(h=s.surfaceCls.transformMemPro(h,r,o,a),p=s.surfaceCls.transformMemPro(p,r,o,a)),c.push(h),c.push(p);let m=n.getAxisColor(d[e].symbol,i[t].order),u=n.getPolygonColor(d[e].symbol);c.push(m),c.push(u),c.push(i[t].order),c.push(d[e].clusters[0].members[0].asym_id),l.push(c)}s.symmetryHash[t]=l}if(0==Object.keys(s.symmetryHash).length)$("#"+s.pre+"dl_symmetry").html("<br>This structure has no symmetry.");else{let e="<option value='none'>None</option>",t=0;for(let i in s.symmetryHash){e+="<option value='"+i+"' "+(0==t?"selected":"")+">"+i+"</option>",++t}$("#"+s.pre+"selectSymmetry").html(e)}}else $("#"+s.pre+"dl_symmetry").html("<br>This structure has no symmetry.");i.htmlCls.dialogCls.openDlg("dl_symmetry","Symmetry")}getPolygonColor(e){let t=this.icn3d.icn3dui,s=e.substr(0,1);return"C"==s?t.parasCls.thr(16747520):"D"==s?t.parasCls.thr(65535):"T"==s?t.parasCls.thr(15631086):"O"==s?t.parasCls.thr(16753920):"I"==s?t.parasCls.thr(65280):t.parasCls.thr(11119017)}getAxisColor(e,t){let s=this.icn3d.icn3dui,i=e.substr(0,1);return"C"==i?s.parasCls.thr(16711680):"D"==i?2==t?s.parasCls.thr(65535):s.parasCls.thr(16711680):"T"==i?2==t?s.parasCls.thr(65535):s.parasCls.thr(65280):"O"==i||"I"==i?2==t?s.parasCls.thr(65535):3==t?s.parasCls.thr(65280):s.parasCls.thr(16711680):s.parasCls.thr(16711680)}}class xs{constructor(e){this.icn3d=e}alignSW(e,t,s,i,n,l,r){this.icn3d.icn3dui;let o=this.bsa_align(r,e,t,[s,i],[n,l]),a="score: "+o[0]+"\n";a+="start: "+o[1]+"\n",a+="cigar: "+this.bsa_cigar2str(o[2])+"\n\n",a+="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 s=[];s.length=e.length;for(let i=0;i<e.length;++i)s[i]=t[e.charCodeAt(i)];return s}bsa_gen_score_matrix(e,t,s){this.icn3d.icn3dui;let i,n,l=[];for(s>0&&(s=-s),i=0;i<e-1;++i){for(l[i]=[],n=0;n<e-1;++n)l[i][n]=i==n?t:s;l[i][n]=0}l[e-1]=[];for(let t=0;t<e;++t)l[e-1][t]=0;return l}bsa_gen_query_profile(e,t,s){this.icn3d.icn3dui;let i,n="string"==typeof e?this.bsg_enc_seq(e,s):e,l=[];if(t.length>=2&&"number"==typeof t[0]&&"number"==typeof t[1]){if(null==s)return null;let e="number"==typeof s?s:s[s.length-1]+1;i=this.bsa_gen_score_matrix(e,t[0],t[1])}else i=t;for(let e=0;e<i.length;++e){let t,s=i[e];t=l[e]=[];for(let e=0;e<n.length;++e)t[e]=s[n[e]]}return l}bsa_align(e,t,s,i,n,l,r){this.icn3d.icn3dui;null==r&&(r=[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,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,r),a=this.bsa_gen_query_profile(s,i,r),d=a[0].length,c=d>o.length?d:o.length;l=null==l||l<0?c:l;let h,p,m=o.target>d?o.target-d:d-o.target;l=l>m?l:m,"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 u,g=h+p,f=-1073741824,C=[],b=[],y=[],v=0,_=-1,w=-1;if(e)for(let e=0;e<=d;++e)C[e]=b[e]=0;else{C[0]=0,b[0]=-g-g;for(let e=1;e<=d;++e)e>=l?C[e]=b[e]=f:(C[e]=-(g+p*(e-1)),b[e]=-(g+g+p*e))}for(let t=0;t<o.length;++t){let s,i=0,n=0,r=0,c=-1,h=a[o[t]];s=y[t]=[];let m=t>l?t-l:0,u=t+l+1<d?t+l+1:d;e||(i=m>0?f:-(g+p*t),n=m>0?f:-(g+g+p*t));for(let t=m;t<u;++t){let l,o=b[t],a=C[t];C[t]=i,a+=h[t],l=a>=o?0:1,a=a>=o?a:o,l=a>=n?l:2,a=a>=n?a:n,l=!e||a>0?l:64,i=a,c=r>a?c:t,r=r>a?r:a,a-=g,a=!e||a>0?a:0,o-=p,l|=o>a?4:0,o=o>a?o:a,b[t]=o,n-=p,l|=n>a?32:0,n=n>a?n:a,s[t]=l}C[u]=i,b[u]=e?0:f,r>v&&(v=r,_=t,w=c)}if(e&&0==v)return null;u=e?v:C[d];let S,A,x,k=[],O=0,R=0;for(e?(A=_,x=w,w!=d-1&&this.push_cigar(k,4,d-1-w)):(A=o.length-1,x=(A+l+1<d?A+l+1:d)-1);A>=0&&x>=0&&(S=y[A][x-(A>l?A-l:0)],O=S>>(O<<1)&3,!(0==O&&S>>6));)0==O&&(O=3&S),0==O?(this.push_cigar(k,0,1),--A,--x):1==O?(this.push_cigar(k,2,1),--A):(this.push_cigar(k,1,1),--x);e?(x>=0&&this.push_cigar(k,4,x+1),R=A+1):(A>=0&&this.push_cigar(k,2,A+1),x>=0&&this.push_cigar(k,1,x+1));for(let e=0;e<k.length>>1;++e)S=k[e],k[e]=k[k.length-1-e],k[k.length-1-e]=S;return[u,R,k]}push_cigar(e,t,s){this.icn3d.icn3dui,0==e.length||t!=(15&e[e.length-1])?e.push(s<<4|t):e[e.length-1]+=s<<4}bsa_cigar2gaps(e,t,s,i){this.icn3d.icn3dui;let n="",l="",r="",o=0,a=s;for(let s=0;s<i.length;++s){let r=15&i[s],d=i[s]>>4;0==r?(n+=t.substr(o,d),l+=e.substr(a,d),o+=d,a+=d):1==r?(n+=t.substr(o,d),l+=Array(d+1).join("-"),o+=d):2==r?(n+=Array(d+1).join("-"),l+=e.substr(a,d),a+=d):4==r&&(o+=d)}let d=l.toUpperCase(),c=n.toUpperCase();for(let e=0;e<d.length;++e)r+=d.charAt(e)==c.charAt(e)?"|":" ";return[l,n,r]}bsa_cigar2str(e){this.icn3d.icn3dui;let t=[];for(let s=0;s<e.length;++s)t.push((e[s]>>4).toString()+"MIDNSHP=XB".charAt(15&e[s]));return t.join("")}}class ks{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 s=this.icn3d,i=s.icn3dui;if(0==e.length)alert("Please select the first set");else{let n=i.hashUtilsCls.cloneHash(s.hAtoms),l=s.definedSetsCls.getAtomsFromNameArray(e),r=s.definedSetsCls.getAtomsFromNameArray(t);s.bCalcArea=!0,s.opts.surface="solvent accessible surface",s.hAtoms=i.hashUtilsCls.cloneHash(l),s.applyMapCls.applySurfaceOptions();let o=s.areavalue,a=i.hashUtilsCls.cloneHash(s.resid2area);s.hAtoms=i.hashUtilsCls.cloneHash(r),s.applyMapCls.applySurfaceOptions();let d=s.areavalue,c=i.hashUtilsCls.cloneHash(s.resid2area);s.hAtoms=i.hashUtilsCls.unionHash(s.hAtoms,l),s.applyMapCls.applySurfaceOptions();let h=s.areavalue,p=i.hashUtilsCls.cloneHash(s.resid2area),m=0,u=0,g=0,f=0;for(let e in a)p.hasOwnProperty(e)&&(f+=parseFloat(p[e]));u=(o-f).toFixed(2);for(let e in c)p.hasOwnProperty(e)&&(g+=parseFloat(p[e]));m=(d-g).toFixed(2),s.bCalcArea=!1,s.hAtoms=i.hashUtilsCls.cloneHash(n);let C=(parseFloat(d)+parseFloat(o)-parseFloat(h)).toFixed(2),b="<br>Calculate solvent accessible surface area in the interface:<br><br>";b+="Set 1: "+e+", Surface: "+o+" &#8491;<sup>2</sup><br>",b+="Set 2: "+t+", Surface: "+d+" &#8491;<sup>2</sup><br>",b+="Total Surface: "+h+" &#8491;<sup>2</sup><br>",b+="<b>Buried Surface for Set 1</b>: "+u+" &#8491;<sup>2</sup><br>",b+="<b>Buried Surface for Set 2</b>: "+m+" &#8491;<sup>2</sup><br><br>",$("#"+s.pre+"dl_buriedarea_html").html(b),i.htmlCls.dialogCls.openDlg("dl_buriedarea","Buried solvent accessible surface area in the interface"),i.htmlCls.clickMenuCls.setLogCmd("buried surface "+C,!1)}}measureDistTwoSets(e,t){var s=this.icn3d,i=s.icn3dui;if(0==e.length||0==t.length)alert("Please select two sets");else{let n=i.hashUtilsCls.cloneHash(s.hAtoms),l=s.definedSetsCls.getAtomsFromNameArray(e),r=s.definedSetsCls.getAtomsFromNameArray(t),o=s.contactCls.getExtent(l),a=s.contactCls.getExtent(r),d=new THREE.Vector3(o[2][0],o[2][1],o[2][2]),c=new THREE.Vector3(a[2][0],a[2][1],a[2][2]);s.hAtoms=i.hashUtilsCls.cloneHash(n),void 0===s.distPnts&&(s.distPnts=[]),s.distPnts.push(d),s.distPnts.push(c);let h=$("#"+s.pre+"distancecolor2").val();this.addLine(d.x,d.y,d.z,c.x,c.y,c.z,h,!0,"distance");let p=0,m=0,u=d.clone().add(c).multiplyScalar(.5),g=(parseInt(10*d.distanceTo(c))/10).toString()+" A";this.addLabel(g,u.x,u.y,u.z,p,h,m,"distance"),s.drawCls.draw()}}measureDistManySets(e,t){var s=this.icn3d,i=s.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for distance calculation...");else{let n=i.hashUtilsCls.cloneHash(s.hAtoms),l={};for(let i=0,n=e.length;i<n;++i){let n=e[i],r=[n];l[n]={};for(let e=0,i=t.length;e<i;++e){let i=t[e],o=[i];if(n==i)continue;let a=s.definedSetsCls.getAtomsFromNameArray(r),d=s.definedSetsCls.getAtomsFromNameArray(o),c=s.contactCls.getExtent(a),h=s.contactCls.getExtent(d),p=new THREE.Vector3(c[2][0],c[2][1],c[2][2]),m=new THREE.Vector3(h[2][0],h[2][1],h[2][2]),u=p.distanceTo(m);l[n][i]=u.toFixed(2)}}s.hAtoms=i.hashUtilsCls.cloneHash(n);let r="Note: Click on the distance to show a dashed line in 3D view.<br><br>";r+="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,s=t.length;e<s;++e){r+="<th><b>"+t[e]+"</b> (&#8491;)</th>"}r+="</tr>";for(let s=0,i=e.length;s<i;++s){let i=e[s];r+="<tr><th><b>"+i+"</b> (&#8491;)</th>";for(let e=0,s=t.length;e<s;++e){let s=t[e];l[i]&&l[i][s]?r+='<td><span class="icn3d-distance" sets="'+i+"|"+s+'">'+l[i][s]+"</span></td>":r+="<td>0</td>"}r+="</tr>"}r+="</table><br><br>",$("#"+i.pre+"dl_disttable_html").html(r)}}measureAngleManySets(e,t){var s=this.icn3d,i=s.icn3dui;if(0==e.length||0==t.length)alert("Please select sets for angleance calculation...");else{let n={};for(let i=0,l=e.length;i<l;++i){let l=e[i],r=[l];n[l]={},s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(r);let o=s.axesCls.setPc1Axes(!0);for(let e=0,i=t.length;e<i;++e){let i=t[e],r=[i];if(l==i)continue;s.hAtoms=s.definedSetsCls.getAtomsFromNameArray(r);let a=s.axesCls.setPc1Axes(!0),d=new THREE.Vector3(parseFloat(o.x),parseFloat(o.y),parseFloat(o.z)).angleTo(new THREE.Vector3(parseFloat(a.x),parseFloat(a.y),parseFloat(a.z)))/3.1416*180;d=Math.abs(d).toFixed(0),d>180&&(d-=180),d>90&&(d=180-d),n[l][i]=d}}let l="<table align=center border=1 cellpadding=10 cellspacing=0><tr><th></th>";for(let e=0,s=t.length;e<s;++e){l+="<th><b>"+t[e]+"</b> (&deg;)</th>"}l+="</tr>";for(let s=0,i=e.length;s<i;++s){let i=e[s];l+="<tr><th><b>"+i+"</b> (&deg;)</th>";for(let e=0,s=t.length;e<s;++e){let s=t[e];n[i]&&n[i][s]?l+="<td><span>"+n[i][s]+"</span></td>":l+="<td>0</td>"}l+="</tr>"}l+="</table><br><br>",$("#"+i.pre+"dl_angletable_html").html(l)}}addLine(e,t,s,i,n,l,r,o,a,d,c){var h=this.icn3d;h.icn3dui;let p={};p.position1=new THREE.Vector3(e,t,s),p.position2=new THREE.Vector3(i,n,l),p.color=r,p.dashed=o,p.radius=d,p.opacity=c,void 0===h.lines[a]&&(h.lines[a]=[]),void 0!==a?h.lines[a].push(p):(void 0===h.lines.custom&&(h.lines.custom=[]),h.lines.custom.push(p)),h.hlObjectsCls.removeHlObjects()}addLineFromPicking(e){var t=this.icn3d,s=t.icn3dui;let i=$("#"+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;s.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 "+i+" | 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,i,n,e),t.pickpair=!1}addLabel(e,t,s,i,n,l,r,o){var a=this.icn3d;a.icn3dui;let d={};"0"!==n&&""!==n&&"undefined"!==n||(n=void 0),"0"!==l&&""!==l&&"undefined"!==l||(l=void 0),"0"!==r&&""!==r&&"undefined"!==r||(r=void 0);let c=new THREE.Vector3;c.x=t,c.y=s,c.z=i,d.position=c,d.text=e,d.size=n,d.color=l,d.background=r,void 0===a.labels[o]&&(a.labels[o]=[]),void 0!==o?a.labels[o].push(d):(void 0===a.labels.custom&&(a.labels.custom=[]),a.labels.custom.push(d)),a.hlObjectsCls.removeHlObjects()}addChainLabels(e){var t=this.icn3d;let s=t.icn3dui.hashUtilsCls.intHash(t.hAtoms,e);void 0===t.labels.chain&&(t.labels.chain=[]);let i=t.firstAtomObjCls.getChainsFromAtoms(s);for(let e in i){let s={};s.position=t.applyCenterCls.centerAtoms(t.chains[e]).center;let i=e.indexOf("_"),n=e.substr(i+1),l=t.showSeqCls.getProteinName(e);l.length>20&&(l=l.substr(0,20)+"..."),s.text="Chain "+n+": "+l,s.size=18,t.firstAtomObjCls.getFirstCalphaAtomObj(t.chains[e]).color.getHexString().toUpperCase(),s.color="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd,s.background="#FFFFFF",t.labels.chain.push(s)}t.hlObjectsCls.removeHlObjects()}addTerminiLabels(e){var t=this.icn3d,s=t.icn3dui;let i,n="#FFFFFF";i=s.hashUtilsCls.unionHash(i,t.proteins),i=s.hashUtilsCls.unionHash(i,t.nucleotides);let l=s.hashUtilsCls.intHash(t.dAtoms,i),r=s.hashUtilsCls.intHash(l,e);void 0===t.labels.chain&&(t.labels.chain=[]);let o=t.firstAtomObjCls.getChainsFromAtoms(r);for(let e in o){let i=s.hashUtilsCls.intHash(l,t.chains[e]),r=Object.keys(i),o=t.atoms[r[0]],a=t.atoms[r[r.length-1]],d={},c={};d.position=o.coord,c.position=a.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(),a.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 Os{constructor(e){this.icn3d=e}draw2Ddgm(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=.667,o={},a={},d={},c={},h={};if(void 0===e)return"";for(let s in e.moleculeInfor){let i="#"+("000000"+e.moleculeInfor[s].color.toString(16)).slice(-6),l=e.moleculeInfor[s].chain.trim();void 0===h[l]?h[l]=1:++h[l];let r=t+"_"+(1===h[l]?l:l+h[l].toString());void 0!==n.mmdbid_q&&(n.mmdbid_q,n.mmdbid_t),o[s]=r,a[s]=i,d[s]=e.moleculeInfor[s].name,c[r]=s}if(void 0===i||!i)for(let s=0,i=e.intracResidues.length;s<i;++s){let i,l,r=e.intracResidues[s],a=0;for(let e in r){let t;t=o[e],0===a?i=t:l=t,++a}if(void 0!==i&&void 0!==l){a=0;for(let e in r){let s,o,d=r[e];0===a?(s=i,o=l):(s=l,o=i),void 0===n.chainids2resids[s]&&(n.chainids2resids[s]={}),void 0===n.chainids2resids[s][o]&&(n.chainids2resids[s][o]=[]);for(let i=0,l=d.length;i<l;++i){let l=d[i],r=n.mmdbMolidResid2mmdbChainResi[t.toUpperCase()+"_"+e+"_"+l];n.chainids2resids[s][o].push(r)}if(void 0===n.chainname2residues&&(n.chainname2residues={}),l=o,!n.chains.hasOwnProperty(l))continue;let c,h=n.firstAtomObjCls.getFirstCalphaAtomObj(n.chains[l]);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=l.substr(l.indexOf("_")+1)+"("+c+")";void 0===n.chainname2residues[s]&&(n.chainname2residues[s]={}),n.chainname2residues[s][p]=n.chainids2resids[s][o],++a}}}let p="<div id='#"+n.pre+t+"'>";p+="<b>"+t.toUpperCase()+"</b><br/>",p+="<svg viewBox='0,0,"+l.htmlCls.width2d+","+l.htmlCls.width2d+"'>";let m={},u=[],g="",f="",C={};if(i)for(let e in n.dAtoms){let t=n.atoms[e];C[c[t.structure+"_"+t.chain]]=1}let b=Object.keys(e.moleculeInfor),y=Object.keys(e.intrac),v=[];for(let e=0,t=b.length;e<t;++e)-1===y.indexOf(b[e])&&v.push(b[e]);let _={};if(v.length>0)for(let t in e.intrac){let s=e.intrac[t];for(let e=0,i=s.intrac.length;e<i;++e){let i=s.intrac[e].toString();-1!==v.indexOf(i)&&(void 0===_[i]&&(_[i]=[]),_[i].push(t),u.push([i,t]))}if("rect"===s.shape){let e=s.coords[0]*r,i=s.coords[1]*r,n=s.coords[2]*r-e,l=s.coords[3]*r-i;m[t]=[e+n/2,i+l/2]}else if("circle"===s.shape){let e=s.coords[0]*r,i=s.coords[1]*r;s.coords[2],m[t]=[e,i]}else if("poly"===s.shape){let e=s.coords[0]*r;s.coords[1],s.coords[2];let i=s.coords[3]*r;s.coords[4],s.coords[5],s.coords[6],s.coords[7],m[t]=[e,i]}}let w=0;for(let t=0,l=b.length;t<l;++t){let l=b[t],c=o[l];if(i&&!C.hasOwnProperty(l))continue;let h=e.intrac[l],p="#FFFFFF",y=a[l];if(void 0!==c&&void 0!==n.chains[c]){let e=Object.keys(n.chains[c]);e.length>0&&(y="#"+n.atoms[e[0]].color.getHexString().toUpperCase())}let S="";n.bInitial&&void 0!==s&&(void 0!==n.alignmolid2color&&n.alignmolid2color[s].hasOwnProperty(l)?(S=n.alignmolid2color[s][l],y="#FF0000"):y="#FFFFFF");let A=d[l],x=" ",k=" ";if(void 0!==c){let e=c.indexOf("_");k=c.substr(e+1),x=k.length>1?k.substr(0,1)+"..":k}else c="Misc";void 0===y&&(y="#FFFFFF");let O=1;if(n.bInitial&&void 0!==n.alnChains[c]){let e=0;for(let t in n.alnChains[c]){let s=n.atoms[t].color.getHexString().toUpperCase();"FF0000"!==s&&"00FF00"!==s||++e}O=1*e/Object.keys(n.chains[c]).length}if(O<.2&&(O=.2),-1===v.indexOf(l)){for(let e=0,t=h.intrac.length;e<t;++e)parseInt(l)<parseInt(h.intrac[e])&&u.push([l,h.intrac[e]]);if("rect"===h.shape){let e=h.coords[0]*r,t=h.coords[1]*r,s=h.coords[2]*r-e,i=h.coords[3]*r-t;g+=this.draw2DNucleotide(e+.5*s,t+.5*i,c,k,x,A,S,p,y,r,O),m[l]=[e+s/2,t+i/2]}else if("circle"===h.shape){let e=h.coords[0]*r,t=h.coords[1]*r;g+=this.draw2DProtein(e,t,c,k,x,A,S,p,y,r,O),m[l]=[e,t]}else if("poly"===h.shape){let e=h.coords[0]*r;h.coords[1],h.coords[2];let t=h.coords[3]*r;h.coords[4],h.coords[5],h.coords[6],h.coords[7];let s=e,i=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]),f+=this.draw2DChemical(s,i,c,k,x,A,S,p,y,r,O),m[l]=[e,t]}}else{let e,t,s=300,i=50;if(void 0!==_[l]&&_[l].length>1){let s=0,i=0;for(let e=0,t=_[l].length;e<t;++e){let t=_[l][e];if(m.hasOwnProperty(t)){let e=m[t];s+=e[0],i+=e[1]}}e=s/_[l].length,t=i/_[l].length}else{let n=s/i;w<n-1?(e=(w+1)*i*r,t=.1*s*r):w-(n-1)<n-1?(e=.1*s*r,t=(w-(n-1)+1)*i*r):(e=.25*s*r,t=e),++w}let o=e,a=t;n.firstAtomObjCls.getFirstAtomObj(n.chains[c]);let d=!0;f+=this.draw2DChemical(o,a,c,k,x,A,S,p,y,r,O,d),m[l]=[o,a]}}for(let e=0,t=u.length;e<t;++e){let t=u[e];if(i&&(!C.hasOwnProperty(t[0])||!C.hasOwnProperty(t[1])))continue;let s,n,l=m[parseInt(t[0])],r=m[parseInt(t[1])];if(void 0===l||void 0===r)continue;s=o[t[0]],n=o[t[1]];let a=s.indexOf("_"),d=n.indexOf("_"),c=s.substr(a+1),h=n.substr(d+1),g=l[0],f=l[1],b=r[0],y=r[1],v=.5*(g+b),_=.5*(f+y);p+="<g class='icn3d-interaction' chainid1='"+s+"' chainid2='"+n+"' >",p+="<title>Interaction of chain "+c+" with chain "+h+"</title>",p+="<line x1='"+g+"' y1='"+f+"' x2='"+v+"' y2='"+_+"' stroke='"+"#000000' stroke-width='2' /></g>",p+="<g class='icn3d-interaction' chainid1='"+n+"' chainid2='"+s+"' >",p+="<title>Interaction of chain "+h+" with chain "+c+"</title>",p+="<line x1='"+v+"' y1='"+_+"' x2='"+b+"' y2='"+y+"' stroke='"+"#000000' stroke-width='2' /></g>"}return p+=f+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;'>&#9711;</span>Protein<br>",t+="<span style='margin-right:18px;'>&#9634;</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>&#9826;</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>&#9634;</span>Biopolymer<br>"):(t+="<span style='margin-right:18px;'>O</span>Protein<br>",t+="<span style='margin-right:18px;'>&#9634;</span>Nucleotide<br>",t+="<span style='margin-right:18px;'>&#9671;</span>Chemical<br>",t+="<span style='margin-right:18px;display: inline-block;transform: skew(-25deg);'>&#9634;</span>Biopolymer<br>"),t+="<br><b>Lines</b>:<br> Interactions at 4 &#197;<br>",e&&(t+="<b>Numbers in red</b>:<br> Aligned chains"),t+="</div><br/>",t}highlightNode(e,t,s,i){let n=this.icn3d.icn3dui;i<.2&&(i=.2);if("rect"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(s).attr("x")),l=Number($(s).attr("y")),r=Number($(s).attr("width")),o=Number($(s).attr("height"));$(t).attr("x",e+r/2*(1-i)),$(t).attr("y",l+o/2*(1-i)),$(t).attr("width",r*i),$(t).attr("height",o*i)}else if("circle"===e)$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3),$(t).attr("r",Number($(s).attr("r"))*i);else if("polygon"===e){$(t).attr("stroke",n.htmlCls.ORANGE),$(t).attr("stroke-width",3);let e=Number($(s).attr("x")),l=Number($(s).attr("y")),r=Number($(s).attr("x0d")),o=Number($(s).attr("y0d")),a=Number($(s).attr("x1d")),d=Number($(s).attr("y1d")),c=Number($(s).attr("x2d")),h=Number($(s).attr("y2d")),p=Number($(s).attr("x3d")),m=Number($(s).attr("y3d"));$(t).attr("points",(e+r*i).toString()+", "+(l+o*i).toString()+", "+(e+a*i).toString()+", "+(l+d*i).toString()+", "+(e+c*i).toString()+", "+(l+h*i).toString()+", "+(e+p*i).toString()+", "+(l+m*i).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,s=this;$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-node",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n=$(this).attr("chainid");i.bCtrl||i.bShift||(i.selectionCls.removeSelection(),i.lineArray2d=[]);let l=1;void 0!==i.alnChains[n]&&(l=1*Object.keys(i.alnChains[n]).length/Object.keys(i.chains[n]).length);let r=$(this).find("rect[class='icn3d-hlnode']"),o=$(this).find("rect[class='icn3d-basenode']");s.highlightNode("rect",r,o,l),r=$(this).find("circle[class='icn3d-hlnode']"),o=$(this).find("circle[class='icn3d-basenode']"),s.highlightNode("circle",r,o,l),r=$(this).find("polygon[class='icn3d-hlnode']"),o=$(this).find("polygon[class='icn3d-basenode']"),s.highlightNode("polygon",r,o,l),i.bCtrl||i.bShift?i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.chains[n]):i.hAtoms=t.hashUtilsCls.cloneHash(i.chains[n]),i.bCtrl||i.bShift?(void 0===i.chainArray2d&&(i.chainArray2d=[]),i.chainArray2d.push(n)):i.chainArray2d=[n],i.hlUpdateCls.updateHlAll(i.chainArray2d),i.annotationCls.showAnnoSelectedChains();let a="select chain "+n;t.htmlCls.clickMenuCls.setLogCmd(a,!0),i.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_2ddgm .icn3d-interaction",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection"),i.bClickInteraction=!0;let n=$(this).attr("chainid1"),l=$(this).attr("chainid2");$(this).find("line").attr("stroke",t.htmlCls.ORANGE),s.selectInteraction(n,l),i.annotationCls.showAnnoSelectedChains();let r="select interaction "+n+","+l;t.htmlCls.clickMenuCls.setLogCmd(r,!0),i.bClickInteraction=!1})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-node",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n=$(this).attr("resid");i.bCtrl||i.bShift||(i.hAtoms={},s.removeLineGraphSelection());$(this).find("circle").attr("stroke",t.htmlCls.ORANGE),$(this).find("circle").attr("stroke-width",2),i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.residues[n]);let l="select "+i.resid2specCls.residueids2spec([n]);i.hlUpdateCls.updateHlAll(),t.htmlCls.clickMenuCls.setLogCmd(l,!0),i.bSelectResidue=!1})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_linegraph .icn3d-interaction",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n=$(this).attr("resid1"),l=$(this).attr("resid2");i.bCtrl||i.bShift||(i.hAtoms={},s.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="+l+"]").find("circle").attr("stroke",t.htmlCls.ORANGE),$("[resid="+l+"]").find("circle").attr("stroke-width",2),i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.residues[n]),i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,i.residues[l]);let r="select "+i.resid2specCls.residueids2spec([n,l]);i.hlUpdateCls.updateHlAll(),i.transformCls.zoominSelection(),t.htmlCls.clickMenuCls.setLogCmd(r,!0)})),$(document).on("click","#"+e.pre+"dl_scatterplot .icn3d-interaction",(function(e){let t=s.icn3d;e.stopImmediatePropagation(),s.clickInteraction(this),t.transformCls.zoominSelection()})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-interaction",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_contactmap .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-interaction",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_ligplot .icn3d-interaction",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickInteraction(this)})),$(document).on("click","#"+e.pre+"dl_alignerrormap .icn3d-node",(function(e){s.icn3d,e.stopImmediatePropagation(),s.clickNode(this)}))}clickNode(e){let t=this.icn3d,s=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let i=$(e).attr("resid");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("circle").attr("stroke",s.htmlCls.ORANGE),$(e).find("circle").attr("stroke-width",2),$(e).find("rect").attr("stroke",s.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[i]);let n="select "+t.resid2specCls.residueids2spec([i]);t.hlUpdateCls.updateHlAll(),s.htmlCls.clickMenuCls.setLogCmd(n,!0),t.bSelectResidue=!1}clickInteraction(e){let t=this.icn3d,s=t.icn3dui;Object.keys(t.hAtoms).length<Object.keys(t.atoms).length&&t.definedSetsCls.setMode("selection");let i=$(e).attr("resid1"),n=$(e).attr("resid2");t.bCtrl||t.bShift||(t.hAtoms={},this.removeScatterplotSelection());$(e).find("rect").attr("stroke",s.htmlCls.ORANGE),$(e).find("rect").attr("stroke-width",2),t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[i]),t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[n]);let l="select "+t.resid2specCls.residueids2spec([i,n]);t.hlUpdateCls.updateHlAll(),s.htmlCls.clickMenuCls.setLogCmd(l,!0)}selectInteraction(e,t){let s=this.icn3d;s.icn3dui,s.hlUpdateCls.removeHl2D(),s.hlObjectsCls.removeHlObjects(),s.bCtrl||s.bShift?(void 0===s.lineArray2d&&(s.lineArray2d=[]),s.lineArray2d.push(e),s.lineArray2d.push(t)):s.lineArray2d=[e,t],this.selectInteractionAtoms(e,t),s.hlObjectsCls.addHlObjects(),s.hlUpdateCls.updateHlAll()}selectInteractionAtoms(e,t){let s,i,n=this.icn3d,l=n.icn3dui,r=n.chainids2resids[e][t];n.bCtrl||n.bShift||(n.hAtoms={});for(let e=0,t=r.length;e<t;++e)n.hAtoms=l.hashUtilsCls.unionHash(n.hAtoms,n.residues[r[e]]);if(Object.keys(n.structures).length>1)s="inter_"+e+"_"+t;else{let i=e.indexOf("_"),n=t.indexOf("_");s="inter_"+e.substr(i+1)+"_"+t.substr(n+1)}i="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(r,s,i,o,!0)}draw2DProtein(e,t,s,i,n,l,r,o,a,d,c){this.icn3d.icn3dui;let h=20*d,p="<g class='icn3d-node' chainid='"+s+"' >";return p+="<title>Chain "+i+": "+l+"</title>",p+="<circle class='icn3d-basenode' cx='"+e+"' cy='"+t+"' r='"+h+"' fill='"+o+"' stroke-width='1' stroke='"+"#000000' class='icn3d-node' chainid='"+s+"' />",p+="<circle class='icn3d-hlnode' cx='"+e+"' cy='"+t+"' r='"+(h*c).toString()+"' fill='"+a+"' stroke-width='1' stroke='"+"#000000' />",p+="<text x='"+(e-0).toString()+"' y='"+(t+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==r&&(p+="<text x='"+(e-0).toString()+"' y='"+(t+h+4+6).toString()+"' style='fill:"+a+"; font-size:8; font-weight:bold; text-anchor:middle' >"+r+"</text>"),p+="</g>",p}draw2DNucleotide(e,t,s,i,n,l,r,o,a,d,c){this.icn3d.icn3dui;let h=30*d,p=30*d,m="<g class='icn3d-node' chainid='"+s+"' >";return m+="<title>Chain "+i+": "+l+"</title>",m+="<rect class='icn3d-basenode' x='"+(e-=.5*h)+"' y='"+(t-=.5*p)+"' width='"+h+"' height='"+p+"' fill='"+o+"' stroke-width='1' stroke='"+"#000000' />",m+="<rect class='icn3d-hlnode' x='"+(e+h/2*(1-c)).toString()+"' y='"+(t+p/2*(1-c)).toString()+"' width='"+(h*c).toString()+"' height='"+(p*c).toString()+"' fill='"+a+"' stroke-width='1' stroke='"+"#000000' />",m+="<text x='"+(e+h/2-0).toString()+"' y='"+(t+p/2+4).toString()+"' style='fill:#000000; font-size:10; text-anchor:middle' >"+n+"</text>",""!==r&&(m+="<text x='"+(e+h/2-0).toString()+"' y='"+(t+p+4+6).toString()+"' style='fill:"+a+"; font-size:8; font-weight:bold; text-anchor:middle' >"+r+"</text>"),m+="</g>",m}draw2DChemical(e,t,s,i,n,l,r,o,a,d,c,h){this.icn3d.icn3dui;let p,m,u,g,f,C,b,y,v=30*d;if(h){let s=.5*v/Math.sqrt(3),i=.5*v;p=e-s,m=t-i,u=e+3*s,g=t-i,f=e+s,C=t+i,b=e-3*s,y=t+i}else{let s=.5*v,i=.5*v;p=e-s,m=t,u=e,g=t+i,f=e+s,C=t,b=e,y=t-i}let _=p-e,w=m-t,S=u-e,A=g-t,x=f-e,k=C-t,O=b-e,R=y-t,I="<g class='icn3d-node' chainid='"+s+"' >";return I+="<title>Chain "+i+": "+l+"</title>",I+="<polygon class='icn3d-basenode' points='"+p+", "+m+","+u+", "+g+","+f+", "+C+","+b+", "+y+"' x='"+e+"' y='"+t+"' x0d='"+_+"' y0d='"+w+"' x1d='"+S+"' y1d='"+A+"' x2d='"+x+"' y2d='"+k+"' x3d='"+O+"' y3d='"+R+"' fill='"+o+"' stroke-width='1' stroke='"+"#000000' />",I+="<polygon class='icn3d-hlnode' points='"+(e+_*c).toString()+", "+(t+w*c).toString()+","+(e+S*c).toString()+", "+(t+A*c).toString()+","+(e+x*c).toString()+", "+(t+k*c).toString()+","+(e+O*c).toString()+", "+(t+R*c).toString()+"' fill='"+a+"' stroke-width='1' stroke='"+"#000000' />",I+="<text x='"+(e+1).toString()+"' y='"+(t+2).toString()+"' style='fill:#000000; font-size:8; text-anchor:middle' >"+n+"</text>",""!==r&&(I+="<text x='"+(e+1).toString()+"' y='"+(t+2+6).toString()+"' style='fill:"+a+"; font-size:8; font-weight:bold; text-anchor:middle' >"+r+"</text>"),I+="</g>",I}}class Rs{constructor(e){this.icn3d=e}async draw2Dcartoon(e,t){let s=this.icn3d,i=s.icn3dui,n=this;if(i.htmlCls.clickMenuCls.setLogCmd("cartoon 2d "+e,!0),s.cartoon2dType=e,t){let t=n.getCartoonSvg(e,s.graphStr);$("#"+i.svgid_ct).html(t)}else{await this.getNodesLinksForSetCartoon(e),s.graphStr=n.getCartoonData(e,s.node_link);let t=n.getCartoonSvg(e,s.graphStr);$("#"+i.svgid_ct).html(t),n.setEventsForCartoon2d(),i.htmlCls.dialogCls.openDlg("dl_2dctn","2D Cartoon")}}getCartoonSvg(e,t){let s=this.icn3d,i=s.icn3dui,n="",l="",r=JSON.parse(t);s.ctnNodeHash={};for(let t=0,i=r.nodes.length;t<i;++t){let i=r.nodes[t];s.ctnNodeHash[i.id]=i,l+="secondary"==e?this.drawHelix(e,i.id,i.ss,i.x,i.y,i.x1,i.y1,i.x2,i.y2,i.len,i.ang,i.c):this.drawOval(e,i.id,i.x,i.y,i.rx,i.ry,i.ang,i.c,i.from,i.to)}s.nodeid2lineid={};for(let t=0,l=r.links.length;t<l;++t){let l=r.links[t].source,o=r.links[t].target,a=s.ctnNodeHash[l].x,d=i.htmlCls.width2d-s.ctnNodeHash[l].y,c=s.ctnNodeHash[o].x,h=i.htmlCls.width2d-s.ctnNodeHash[o].y;"chain"==e?n+="<g class='icn3d-ctinteraction' chainid1='"+s.ctnNodeHash[l].id+"' chainid2='"+s.ctnNodeHash[o].id+"' >":"domain"==e?n+="<g class='icn3d-ctinteraction' from1='"+s.ctnNodeHash[l].from+"' to1='"+s.ctnNodeHash[l].to+"' from2='"+s.ctnNodeHash[o].from+"' to2='"+s.ctnNodeHash[o].to+"' >":"secondary"==e&&(a=s.ctnNodeHash[l].x2,d=i.htmlCls.width2d-s.ctnNodeHash[l].y2,c=s.ctnNodeHash[o].x1,h=i.htmlCls.width2d-s.ctnNodeHash[o].y1,n+="<g class='icn3d-ctinteraction' range1='"+s.ctnNodeHash[l].range+"' range2='"+s.ctnNodeHash[o].range+"' >");let p=l+"--"+o;n+="<title>Interaction of "+e+" "+this.getLabelFromId(l,e)+" with "+e+" "+this.getLabelFromId(o,e)+"</title>",n+="<line class='icn3d-edge' id='"+p+"' x1='"+a+"' y1='"+d+"' x2='"+c+"' y2='"+h+"' stroke='#bbbbbb' stroke-width='1' /></g>",s.nodeid2lineid.hasOwnProperty(l)||(s.nodeid2lineid[l]=[]),s.nodeid2lineid.hasOwnProperty(o)||(s.nodeid2lineid[o]=[]),s.nodeid2lineid[l].push(p),s.nodeid2lineid[o].push(p)}return n+=l,n}setEventsForCartoon2d(){let e=this.icn3d,t=e.icn3dui;$("#"+t.svgid_ct+" .icn3d-ctnode").draggable({start:function(e,t){let s=parseFloat(e.target.getAttribute("cx")),i=parseFloat(e.target.getAttribute("cy"));e.target.setAttribute("cx",s),e.target.setAttribute("cy",i);let n=e.target.getAttribute("ang");if(n)e.target.setAttribute("transform","rotate("+n+","+s+","+i+")");else{let t=parseFloat(e.target.getAttribute("x1")),s=parseFloat(e.target.getAttribute("y1")),i=parseFloat(e.target.getAttribute("x2")),n=parseFloat(e.target.getAttribute("y2"));e.target.setAttribute("x1",t),e.target.setAttribute("y1",s),e.target.setAttribute("x2",i),e.target.setAttribute("y2",n)}},drag:function(s,i){let n=$("#"+t.svgid_ct).offset().left,l=$("#"+t.svgid_ct).offset().top,r=s.target.getAttribute("id"),o=s.target.getAttribute("ang"),a=s.clientX-n,d=s.clientY-l,c=parseFloat(s.target.getAttribute("cx")),h=parseFloat(s.target.getAttribute("cy")),p=(a-c)/e.resizeRatioX,m=(d-h)/e.resizeRatioY,u=parseFloat($("#"+r+"_text").attr("x")),g=parseFloat($("#"+r+"_text").attr("y"));if($("#"+r+"_text").attr("x",u+p),$("#"+r+"_text").attr("y",g+m),s.target.setAttribute("cx",a),s.target.setAttribute("cy",d),o)s.target.setAttribute("transform","rotate("+o+","+a+","+d+")");else{let e=parseFloat(s.target.getAttribute("x1")),t=parseFloat(s.target.getAttribute("y1")),i=parseFloat(s.target.getAttribute("x2")),n=parseFloat(s.target.getAttribute("y2"));if(s.target.setAttribute("x1",e+p),s.target.setAttribute("y1",t+m),s.target.setAttribute("x2",i+p),s.target.setAttribute("y2",n+m),"S"==r.substr(0,1)){let e=parseFloat($("#"+r+"_box").attr("x1")),t=parseFloat($("#"+r+"_box").attr("y1")),s=parseFloat($("#"+r+"_box").attr("x2")),i=parseFloat($("#"+r+"_box").attr("y2"));$("#"+r+"_box").attr("x1",e+p),$("#"+r+"_box").attr("y1",t+m),$("#"+r+"_box").attr("x2",s+p),$("#"+r+"_box").attr("y2",i+m)}}if(e.nodeid2lineid[r])for(let t=0,s=e.nodeid2lineid[r].length;t<s;++t){f(e.nodeid2lineid[r][t],r,o)}function f(e,t,s){if(e&&-1!=e.indexOf(t)){let t=e.split("--");if(2==t.length){let i,n;i=t[1],n=t[0];let l=s?"cx":"x1",r=s?"cy":"y1",o=$("#"+i).attr(l),a=$("#"+i).attr(r);$("#"+e).attr("x1",o),$("#"+e).attr("y1",a);let d=s?"cx":"x2",c=s?"cy":"y2",h=$("#"+n).attr(d),p=$("#"+n).attr(c);$("#"+e).attr("x2",h),$("#"+e).attr("y2",p)}}}}})}getLabelFromId(e,t){let s=e,i=s.indexOf("__");return-1!==i&&(s=s.substr(0,i)),s="secondary"==t?s.substr(0,s.indexOf("-")):s,s}drawHelix(e,t,s,i,n,l,r,o,a,d,c,h){let p=this.icn3d.icn3dui,m=this.getLabelFromId(t,e);n=p.htmlCls.width2d-n,r=p.htmlCls.width2d-r,a=p.htmlCls.width2d-a;let u="<g range='"+m.substr(1)+"' >";return u+="<title>"+e+" "+m+"</title>","H"==t.substr(0,1)?u+="<line id='"+t+"' class='icn3d-ctnode' x1='"+l+"' y1='"+r+"' x2='"+o+"' y2='"+a+"' cx='"+.5*(l+o).toFixed(1)+"' cy='"+.5*(r+a).toFixed(1)+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='round' />":(u+="<line id='"+t+"_box' x1='"+l+"' y1='"+r+"' x2='"+o+"' y2='"+a+"' stroke='#"+h+"' stroke-width='3' stroke-linecap='square' />",u+="<line id='"+t+"' class='icn3d-ctnode' x1='"+l+"' y1='"+r+"' x2='"+o+"' y2='"+a+"' cx='"+.5*(l+o).toFixed(1)+"' cy='"+.5*(r+a).toFixed(1)+"' stroke='#FFF' stroke-width='1' stroke-linecap='square' />"),u+="<text id='"+t+"_text' x='"+(i-0).toString()+"' y='"+(n+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text8' >"+m+"</text>",u+="</g>",u}drawOval(e,t,s,i,n,l,r,o,a,d){let c=this.icn3d.icn3dui,h=this.getLabelFromId(t,e);i=c.htmlCls.width2d-i,r=180-r;let p="chain"==e?"<g chainid='"+t+"' >":"<g from='"+a+"' 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='"+s.toFixed(0)+"' cy='"+i.toFixed(0)+"' rx='"+n.toFixed(0)+"' ry='"+l.toFixed(0)+"' fill='url(#"+t+"_g_obj)' stroke-width='1' stroke='none' ",p+=" ang='"+r+"' transform='rotate("+r+","+s.toFixed(0)+","+i.toFixed(0)+")'",p+="chain"==e?" chainid='"+t+"' />":" from='"+a+"' to='"+d+"' />",p+="<text id='"+t+"_text' x='"+(s-0).toString()+"' y='"+(i+4).toString()+"' style='fill:#000000; text-anchor:middle' class='icn3d-node-text12' >"+h+"</text>",p+="</g>",p}getCartoonData(e,t){let s=this.icn3d;s.icn3dui;let i,n,l=[],r=[];l=t.node;let o=[],a={},d=0;for(let e=0,t=l.length;e<t;++e){let t=l[e],s=JSON.parse(t);a.hasOwnProperty(s.id)||(o.push(s),a[s.id]=d,++d)}let c=[];for(let e=0,t=o.length;e<t;++e){let t=o[e];c.push(JSON.stringify(t))}i=c.join(", "),r=t.link,n=r.join(", "),s.hAtoms;let h='{"nodes": ['+i+'], "links": [';return h+=n+"",h+='], "level": "'+(t.level?t.level:"")+'"}',h}projectTo2d(e){let t=this.icn3d,s=t.icn3dui,i=e.project(t.cam);var n=new THREE.Vector3;return n.x=Math.round((i.x+1)*s.htmlCls.width2d*.5),n.y=Math.round(-i.y*s.htmlCls.width2d*.5),n.z=0,n.y>0?n.y=s.htmlCls.width2d-n.y:n.y=-n.y,n}async getNodesLinksForSetCartoon(e){let t,s,i,n,l,r=this.icn3d,o=r.icn3dui,a=this,d=[],c=[],h=0,p=o.htmlCls.defaultValue,m="",u="",g="",f=!1,C=!0;if("chain"==e){let e={};for(let t in r.hAtoms){let s=r.atoms[t];if("DUM"==s.chain)continue;let i=s.structure+"_"+s.chain;(r.proteins.hasOwnProperty(t)||r.nucleotides.hasOwnProperty(t))&&(e.hasOwnProperty(i)||(e[i]={}),e[i][s.serial]=s)}let t=r.contactCls.getExtent(r.atoms),s=9999,i=9999,n=-9999,a=-9999,h=-9999,p=[];for(let d in e){r.hAtom={},r.hAtoms=o.hashUtilsCls.cloneHash(r.chains[d]);let e=r.axesCls.setPc1Axes(),c=e[0],m=e[1].distanceTo(e[0]),u=e[2].distanceTo(e[0]),g=180*new THREE.Vector2(e[1].x-e[0].x,e[1].y-e[0].y).angle()/Math.PI;g>180&&(g-=180);let f=Object.keys(r.hAtoms)[0],C=r.atoms[f];l=d,c=this.projectTo2d(c);let b=c.x,y=c.y;b<s&&(s=b),b>n&&(n=b),y<i&&(i=y),y>a&&(a=y);let v=.5;m=v*o.htmlCls.width2d*m/(t[1][0]-t[0][0]),u=v*o.htmlCls.width2d*u/(t[1][1]-t[0][1]),m>h&&(h=m),u>h&&(h=u),p.push({id:d,r:l,x:b,y:y,rx:m,ry:u,ang:g,c:C.color.getHexString()})}let m=h+2,u=n-s,g=a-i;for(let e=0,t=p.length;e<t;++e){let t=p[e],n=u<1?.5*o.htmlCls.width2d:(t.x-s)/u*(o.htmlCls.width2d-2*m)+m,l=g<1?.5*o.htmlCls.width2d:(t.y-i)/g*(o.htmlCls.width2d-2*m)+m;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+n.toFixed(0)+', "y": '+l.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}r.hAtoms=o.hashUtilsCls.cloneHash(r.dAtoms),r.node_link={node:d,link:c,level:"chain"}}else if("domain"==e)r.chainid2pssmid||await r.loadScriptCls.applyCommandAnnotationsAndCddSite("view annotations"),a.getNodesLinksForDomains(r.chainid2pssmid);else if("secondary"==e){r.resi2resirange={};let e,a=[];r.contactCls.getExtent(r.atoms);let b="",y=9999,v=9999,_=-9999,w=-9999,S=2,A=[];for(let d in r.hAtoms){let S=r.atoms[d];if("DUM"!=S.chain&&((S.ssbegin||S.ssend)&&"CA"==S.name&&"C"==S.elem)){let d=S.structure+"_"+S.chain+"_"+S.resi;if(C&&S.ssbegin&&(f=!0,C=!1,t=S,b="helix"==S.ss?"H":"S",n=b+S.resi,l="1_1_"+d,g=S.chain),f&&(e=o.utilsCls.residueName2Abbr(S.resn)+S.resi,e+="__"+S.chain,Object.keys(r.structures).length>1&&(e+="__"+S.structure),a.push(e)),g==S.chain&&f&&S.ssend){let o=this.projectTo2d(t.coord.clone()),d=o.x,g=o.y,x=this.projectTo2d(S.coord.clone()),k=x.x,O=x.y;s=.5*(d+k),i=.5*(g+O),d=.5*(s+d),g=.5*(i+g),k=.5*(s+k),O=.5*(i+O),d<y&&(y=d),d>_&&(_=d),g<v&&(v=g),g>w&&(w=g),k<y&&(y=k),k>_&&(_=k),O<v&&(v=O),O>w&&(w=O),f=!1,C=!0,n+="-"+S.resi,l+="-"+S.resi,n+="__"+S.chain,Object.keys(r.structures).length>1&&(n+="__"+S.structure);for(let t=0,s=a.length;t<s;++t)e=a[t],r.resi2resirange[e]=n;a=[],h>0&&m==S.chain&&c.push('{"source": "'+u+'", "target": "'+n+'", "v": '+p+', "c": "'+t.color.getHexString().toUpperCase()+'"}'),A.push({id:n,r:l,ss:b,x:s,y:i,x1:d,y1:g,x2:k,y2:O,c:S.color.getHexString()}),m=S.chain,u=n,++h}}}let x=S+2,k=_-y,O=w-v;for(let e=0,t=A.length;e<t;++e){let t=A[e],s=k<1?.5*o.htmlCls.width2d:(t.x-y)/k*(o.htmlCls.width2d-2*x)+x,i=O<1?.5*o.htmlCls.width2d:(t.y-v)/O*(o.htmlCls.width2d-2*x)+x,n=k<1?.5*o.htmlCls.width2d:(t.x1-y)/k*(o.htmlCls.width2d-2*x)+x,l=O<1?.5*o.htmlCls.width2d:(t.y1-v)/O*(o.htmlCls.width2d-2*x)+x,r=k<1?.5*o.htmlCls.width2d:(t.x2-y)/k*(o.htmlCls.width2d-2*x)+x,a=O<1?.5*o.htmlCls.width2d:(t.y2-v)/O*(o.htmlCls.width2d-2*x)+x;d.push('{"id": "'+t.id+'", "r": "'+t.r+'", "x": '+s.toFixed(0)+', "y": '+i.toFixed(0)+', "x1": '+n.toFixed(0)+', "y1": '+l.toFixed(0)+', "x2": '+r.toFixed(0)+', "y2": '+a.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}r.node_link={node:d,link:c,level:"secondary"}}}getNodesLinksForDomains(e){let t=this.icn3d,s=t.icn3dui,i=[],n=[],l=s.htmlCls.defaultValue;t.resi2resirange={};let r={};for(let e in t.hAtoms){let s=t.atoms[e];"DUM"!=s.chain&&(r[s.structure+"_"+s.chain]=1)}let o=t.contactCls.getExtent(t.atoms),a=9999,d=9999,c=-9999,h=-9999,p=-9999,m=[];for(let i in r){if(!e.hasOwnProperty(i))continue;let r=e[i].pssmid2name,g=e[i].pssmid2fromArray,f=e[i].pssmid2toArray,C={};for(let e in r){let t=g[e];C[e]=t[0]}var u=Object.keys(C);let b,y;u.sort((function(e,t){return C[e]-C[t]}));for(let e=0,C=u.length;e<C;++e){let C=u[e],v=r[C];v+="__"+i.substr(i.indexOf("_")+1),Object.keys(t.structures).length>1&&(v+="__"+i.substr(0,i.indexOf("_")));let _=g[C],w=f[C];t.hAtoms={};for(let e=0,n=_.length;e<n;++e){let n=parseInt(_[e])+1,l=parseInt(w[e])+1;for(let e=n;e<=l;++e)t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.residues[i+"_"+e])}if(0==Object.keys(t.hAtoms).length)continue;let S=t.axesCls.setPc1Axes(),A=S[0],x=S[1].distanceTo(S[0]),k=S[2].distanceTo(S[0]),O=180*new THREE.Vector2(S[1].x-S[0].x,S[1].y-S[0].y).angle()/Math.PI;O>180&&(O-=180);let R=Object.keys(t.hAtoms)[0],I=t.atoms[R];A=this.projectTo2d(A);let E=A.x,T=A.y;E<a&&(a=E),E>c&&(c=E),T<d&&(d=T),T>h&&(h=T);let P=.5;x=P*s.htmlCls.width2d*x/(o[1][0]-o[0][0]),k=P*s.htmlCls.width2d*k/(o[1][1]-o[0][1]),x>p&&(p=x),k>p&&(p=k),void 0!==b&&n.push('{"source": "'+b+'", "target": "'+v+'", "v": '+l+', "c": "'+y.color.getHexString().toUpperCase()+'"}'),m.push({id:v,from:_+"",to:w+"",x:E,y:T,rx:x,ry:k,ang:O,c:I.color.getHexString()}),b=v,y=I}}let g=p+2,f=c-a,C=h-d;for(let e=0,t=m.length;e<t;++e){let t=m[e],n=f<1?.5*s.htmlCls.width2d:(t.x-a)/f*(s.htmlCls.width2d-2*g)+g,l=C<1?.5*s.htmlCls.width2d:(t.y-d)/C*(s.htmlCls.width2d-2*g)+g;i.push('{"id": "'+t.id+'", "from": "'+t.from+'", "to": "'+t.to+'", "x": '+n.toFixed(0)+', "y": '+l.toFixed(0)+', "rx": '+t.rx.toFixed(0)+', "ry": '+t.ry.toFixed(0)+', "ang": '+t.ang.toFixed(0)+', "c": "'+t.c.toUpperCase()+'"}')}t.hAtoms=s.hashUtilsCls.cloneHash(t.dAtoms),t.node_link={node:i,link:n,level:"domain"}}getSelection(e,t,s){let i=this.icn3d,n=i.icn3dui,l={},r=[],o=t.toString().split(","),a=s.toString().split(","),d=3==e.length?e[2]:Object.keys(i.structures)[0],c=e.length>=2?d+"_"+e[1]:Object.keys(i.chains)[0];for(let e=0,t=o.length;e<t;++e){let t=parseInt(o[e])+1,s=parseInt(a[e])+1;for(let e=t;e<=s;++e){let t=c+"_"+e;l=n.hashUtilsCls.unionHash(l,i.residues[t]),r.push(t)}}return{atomSet:l,residArray:r}}click2Dcartoon(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+t.pre+"2dctn_chain","click",(async function(e){let i=t.icn3d;e.preventDefault(),s.initCartoonSvg(),await i.cartoon2dCls.draw2Dcartoon("chain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_domain","click",(async function(e){let i=t.icn3d;e.preventDefault(),s.initCartoonSvg(),await i.cartoon2dCls.draw2Dcartoon("domain")})),t.myEventCls.onIds("#"+t.pre+"2dctn_secondary","click",(async function(e){let i=t.icn3d;e.preventDefault(),s.initCartoonSvg(),await i.cartoon2dCls.draw2Dcartoon("secondary")})),$(document).on("click","#"+e.pre+"dl_2dctn .icn3d-ctnode",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&i.definedSetsCls.setMode("selection");let n,l={},r=[],o=$(this).attr("id"),a=$(this).attr("chainid"),d=$(this).attr("from"),c=$(this).attr("to"),h=$(this).attr("x1");if(void 0!==a)n="chain",l=i.chains[a];else if(void 0!==d){n="domain";let e=o.split("__"),t=s.getSelection(e,d,c);l=t.atomSet,r=t.residArray}else if(void 0!==h){n="secondary";let e=o.split("__"),t=e[0].substr(1).split("-"),i=parseInt(t[0])-1,a=parseInt(t[1])-1,d=s.getSelection(e,i,a);l=d.atomSet,r=d.residArray}i.bCtrl||i.bShift||(i.selectionCls.removeSelection(),i.lineArray2d=[]),void 0!==i.alnChains[a]&&(Object.keys(i.alnChains[a]).length,Object.keys(i.chains[a]).length),i.bCtrl||i.bShift?i.hAtoms=t.hashUtilsCls.unionHash(i.hAtoms,l):i.hAtoms=t.hashUtilsCls.cloneHash(l),"chain"==n?(i.bCtrl||i.bShift?(void 0===i.chainArray2d&&(i.chainArray2d=[]),i.chainArray2d.push(a)):i.chainArray2d=[a],i.hlUpdateCls.updateHlAll(i.chainArray2d)):i.hlUpdateCls.updateHlAll(),i.annotationCls.showAnnoSelectedChains();let p="chain"==n?"select chain "+a:"select "+i.resid2specCls.residueids2spec(r);t.htmlCls.clickMenuCls.setLogCmd(p,!0),i.bSelectResidue=!1}))}initCartoonSvg(){let e=this.icn3d,t=e.icn3dui;e.resizeRatioX=1,e.resizeRatioY=1,$("#"+t.svgid_ct).empty()}}class Is{constructor(e){this.icn3d=e}async drawLigplot(e){let t=this.icn3d,s=t.icn3dui;s.htmlCls.dialogCls.openDlg("dl_ligplot","Show ligand interactions with atom details");let i,n,l=100,r=100;t.len4ang=80;let o=t.saveFileCls.getAtomPDB(e);o=o.trim(),o=o.replace(/\n\n/g,"\n");let a={pdb2svg:o},d=s.htmlCls.baseUrl+"openbabel/openbabel.cgi",c=(await s.getAjaxPostPromise(d,a,void 0,void 0,void 0,void 0,"text")).split("\n"),h="",p="",m={},u=0,g=0,f=0;t.svgGridSize=t.len4ang,t.gridXY2used={};for(let e=0,s=c.length;e<s;++e){let s=c[e];if(0==s.indexOf("<svg width")){let e=s.indexOf('viewBox="')+9,o=s.substr(e),a=o.substr(0,o.indexOf('"')).split(" ");i=parseFloat(a[2]),n=parseFloat(a[3]),l=i+2*t.len4ang,r=n+2*t.len4ang}else if(0==s.indexOf("<line"))h+=s+"\n";else if(0==s.indexOf("<text"))if(-1!=s.indexOf('font-size="12"')){let e=s.indexOf(">")+1,i=s.substr(e),n=parseInt(i.substr(0,i.indexOf("<")));e=s.indexOf('x="')+3;let l=s.substr(e),r=parseFloat(l.substr(0,l.indexOf('"')));e=s.indexOf('y="')+3;let o=s.substr(e),a=parseFloat(o.substr(0,o.indexOf('"')));m[n]={x:r,y:a};let d=parseInt(r/t.svgGridSize),c=parseInt(a/t.svgGridSize);t.gridXY2used[d+"_"+c]=1,u+=r,g+=a,++f}else p+=s+"\n";else if(0==s.indexOf("</svg>"))break}let C=u/f,b=g/f,y=s.ligplotid;t.ligplotWidth=l;let v=t.ligplotWidth,_=r+30,w=-t.len4ang,S="<svg id='"+y+"' viewBox='"+w+","+w+","+l+","+_+"' width='"+v+"px' font-family='sans-serif' stroke='rgb(0,0,0)' stroke-width='2' stroke-linecap='round'>",A=parseInt(i/t.svgGridSize),x=parseInt(n/t.svgGridSize),k=t.viewInterPairsCls.getAllInteractionTable("save1",m,A,x,C,b);t.bLigplot=!0,S+=h+k.svgHtmlLine,S+=p+k.svgHtmlNode,S+="</svg>",$("#"+t.pre+"ligplotDiv").html(S),this.setEventsForLigplot()}getSvgPerPair(e,t,s,i,n,l,r,o,a,d,c,h,p){let m=this.icn3d,u=m.icn3dui,g="hbond"==i||"contact"==i||"halogen"==i?m.len4ang:1.5*m.len4ang,f=m.len4ang/2,C="contact"==i?1:2,b=m.getGraphCls.convertLabel2Resid(t),y=m.firstAtomObjCls.getFirstAtomObj(m.residues[b]),v=m.getGraphCls.convertLabel2Resid(s),_=m.firstAtomObjCls.getFirstAtomObj(m.residues[v]),w=0,S=0,A=0,x=y.serial;for(let t=0,s=e.length;t<s;++t){let s=e[t]-x+1;w+=n[s].x,S+=n[s].y,++A}let k,O,R,I=w/A-1,E=S/A- -1;if(m.resid2cnt.hasOwnProperty(t)?++m.resid2cnt[t]:m.resid2cnt[t]=0,!c&&!m.resid2ToXy.hasOwnProperty(v)){let e=parseInt(I/m.svgGridSize),s=parseInt(E/m.svgGridSize),i=[];for(let t=1;t>=-1;--t)for(let n=1;n>=-1;--n)0==t&&0==n||e+t>=0&&e+t<=l&&s+n>=0&&s+n<=r&&i.push(e+t+"_"+(s+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<=l&&s+n>=0&&s+n<=r&&i.push(e+t+"_"+(s+n));let n,d=!1;for(let e=0,t=i.length;e<t;++e)if(!m.gridXY2used[i[e]]){n=i[e].split("_"),k=(parseInt(n[0])+.5)*m.svgGridSize,O=(parseInt(n[1])+.5)*m.svgGridSize;let t=Math.sqrt((I-k)*(I-k)+(E-O)*(E-O));k=g/t*(k-I)+I,O=g/t*(O-E)+E,m.gridXY2used[i[e]]=1,d=!0;break}if(!d){let e=I-o,s=E-a,i=0;i=Math.abs(e)>Math.abs(s)?e>0?0:180:s>0?90:270,R=i-10+30*m.resid2cnt[t],k=I+g*Math.cos(R*Math.PI/180),O=E+g*Math.sin(R*Math.PI/180)}}let T,P=u.utilsCls.residueName2Abbr(_.resn.substr(0,3))+_.resi,D=_.color?_.color.getHexString():"000",M=m.lineGraphCls.getStrokecolor(void 0,i),F="",H="",L=v+"--"+e.join("-")+i;"hbond"==i?T="H-Bonds":"ionic"==i?T="Salt Bridge/Ionic":"halogen"==i?T="Halogen Bonds":"pi-cation"==i?T="&pi;-Cation":"pi-stacking"==i?T="&pi;-Stacking":"contact"==i&&(T="Contacts");let N=v;if(c||m.resid2ToXy.hasOwnProperty(N)){k=m.resid2ToXy.hasOwnProperty(N)?m.resid2ToXy[N].x2:h,O=m.resid2ToXy.hasOwnProperty(N)?m.resid2ToXy[N].y2:p;let e=I,t=E,s=0;if("contact"==i){let i=Math.sqrt((I-k)*(I-k)+(E-O)*(E-O));f<i&&(e=f/i*(I-k)+k,t=f/i*(E-O)+O,s=1)}H+="<g><title>Interaction type: "+T+"; Distance: "+parseFloat(d).toFixed(1)+" &#197;</title>",H+='<line class="icn3d-interaction" id="'+L+'" resid1="'+b+'" resid2="'+v+'" x1="'+e.toFixed(2)+'" y1="'+t.toFixed(2)+'" x2="'+k.toFixed(2)+'" y2="'+O.toFixed(2)+'" x0="'+I.toFixed(2)+'" y0="'+E.toFixed(2)+'" short="'+s+'" opacity="1.0" stroke="'+M+'" stroke-width="'+C+'" stroke-dasharray="5,5"/>\n',H+="</g>\n"}else{F+="<g><title>"+P+"</title>";let e=28,t=14;F+='<rect id="'+N+'_node" x="'+(k-.5*e).toFixed(2)+'" y="'+(O-.5*t).toFixed(2)+'" width="'+e+'" height="'+t+'" rx="2" ry="2" fill="#'+D+'" stroke-width="1" stroke="'+D+'" resid="'+v+'"/>',F+='<text class="icn3d-ctnode" resid="'+N+'" id="'+N+'" x="'+k.toFixed(2)+'" y="'+O.toFixed(2)+'" fill="#000" stroke="none" text-anchor="middle" alignment-baseline="central" style="font-size:10px">'+P+"</text>",F+="</g>\n",H+="<g><title>Interaction type: "+T+"; Distance: "+parseFloat(d).toFixed(1)+" &#197;</title>",H+='<line class="icn3d-interaction" id="'+L+'" resid1="'+b+'" resid2="'+v+'" x1="'+I.toFixed(2)+'" y1="'+E.toFixed(2)+'" x2="'+k.toFixed(2)+'" y2="'+O.toFixed(2)+'" opacity="1.0" stroke="'+M+'" stroke-width="'+C+'" stroke-dasharray="5,5"/>',H+="</g>\n","contact"!=i&&(m.resid2ToXy.hasOwnProperty(v)||(m.resid2ToXy[v]={x2:k,y2:O}))}return m.nodeid2lineid.hasOwnProperty(N)||(m.nodeid2lineid[N]=[]),m.nodeid2lineid[N].push(L),{node:F,line:H,x2:k,y2:O}}setEventsForLigplot(){let e=this.icn3d,t=e.icn3dui;$("#"+t.ligplotid+" .icn3d-ctnode").draggable({start:function(e,t){let s=parseFloat(e.target.getAttribute("x")),i=parseFloat(e.target.getAttribute("y"));e.target.setAttribute("x",s),e.target.setAttribute("y",i)},drag:function(s,i){let n=e.ligplotScale?e.ligplotScale:1,l=$("#"+t.ligplotid).offset().left+e.len4ang*n,r=$("#"+t.ligplotid).offset().top+e.len4ang*n,o=s.target.getAttribute("resid"),a=(s.clientX-l)/n,d=(s.clientY-r)/n,c=parseFloat(s.target.getAttribute("x")),h=parseFloat(s.target.getAttribute("y")),p=a-c,m=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+m),s.target.setAttribute("x",a),s.target.setAttribute("y",d),e.nodeid2lineid[o])for(let t=0,s=e.nodeid2lineid[o].length;t<s;++t){u(e.nodeid2lineid[o][t],o)}function u(t,s){if(t&&-1!=t.indexOf(s)){let s=t.split("--");if(2==s.length){let i;i=s[0];let n=parseFloat($("#"+i).attr("x")),l=parseFloat($("#"+i).attr("y"));$("#"+t).attr("x2",n),$("#"+t).attr("y2",l);let r=$("#"+t).attr("x1"),o=$("#"+t).attr("y1"),a=r,d=o;if(parseInt($("#"+t).attr("short"))){r=$("#"+t).attr("x0"),o=$("#"+t).attr("y0");let s=Math.sqrt((r-n)*(r-n)+(o-l)*(o-l)),i=e.len4ang/2;i<s&&(a=i/s*(r-n)+n,d=i/s*(o-l)+l)}$("#"+t).attr("x1",a),$("#"+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 s=t.icn3d;e.stopImmediatePropagation(),s.diagram2dCls.clickNode(this)}))}}class Es{constructor(e){this.icn3d=e}resizeCanvas(e,t,s,i){var n=this.icn3d,l=n.icn3dui;if(s||l.cfg.resize){let s=t;$("#"+n.pre+"canvas").width(e).height(s),$("#"+n.pre+"viewer").width(e).height(t),$("#"+n.divid+" div:has(#"+n.pre+"canvas)").width(e).height(s),n.applyCenterCls.setWidthHeight(e,s),n.structures&&Object.keys(n.structures).length>0&&(void 0===i||i)&&n.drawCls.draw()}}windowResize(){let e=this.icn3d.icn3dui,t=this;e.cfg.resize&&!e.utilsCls.isMobile()&&$(window).resize((function(){let s=t.icn3d;e.utilsCls.setViewerWidthHeight(s.icn3dui);let i=e.htmlCls.WIDTH,n=e.htmlCls.HEIGHT;void 0===s||s.bFullscreen||t.resizeCanvas(i,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 s=this.icn3d;s.icn3dui;let i=this;if(s.bStopRotate)return!1;if(s.transformCls.rotateCount>s.transformCls.rotateCountMax)return s.transformCls.resetOrientation(),!1;if(++s.transformCls.rotateCount,t)if("left"===e)s.ROT_DIR="left";else if("right"===e)s.ROT_DIR="right";else if("up"===e)s.ROT_DIR="up";else{if("down"!==e)return!1;s.ROT_DIR="down"}if("left"===e&&"left"===s.ROT_DIR)s.transformCls.rotateLeft(1);else if("right"===e&&"right"===s.ROT_DIR)s.transformCls.rotateRight(1);else if("up"===e&&"up"===s.ROT_DIR)s.transformCls.rotateUp(1);else{if("down"!==e||"down"!==s.ROT_DIR)return!1;s.transformCls.rotateDown(1)}setTimeout((function(){i.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 s=["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_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 i in s){let n=s[i];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 Ts{constructor(e){this.icn3d=e}resetOrientation(){let e=this.icn3d;e.icn3dui;let t=!1;if(e.commands.length>0){let s=e.commands[0].split("|||");if(2==s.length){let i=JSON.parse(s[1]);e._zoomFactor=i.factor,e.mouseChange.x=i.mouseChange.x,e.mouseChange.y=i.mouseChange.y,e.quaternion._x=i.quaternion._x,e.quaternion._y=i.quaternion._y,e.quaternion._z=i.quaternion._z,e.quaternion._w=i.quaternion._w,t=!0}}t||(e._zoomFactor=1,e.mouseChange=new THREE.Vector2(0,0),e.quaternion=new THREE.Quaternion(0,0,0,1)),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,s=t.icn3dui,i=new THREE.Vector3(0,1,0),n=-e/180*Math.PI;t.bControlGl&&!s.bNode?i.applyQuaternion(window.cam.quaternion).normalize():i.applyQuaternion(t.cam.quaternion).normalize();let l=new THREE.Quaternion;l.setFromAxisAngle(i,-n);let r={};r.quaternion=l,r.update=!0,t.bControlGl&&!s.bNode?window.controls.update(r):t.controls.update(r),t.bRender&&t.drawCls.render()}rotateRight(e){let t=this.icn3d,s=t.icn3dui,i=new THREE.Vector3(0,1,0),n=e/180*Math.PI;t.bControlGl&&!s.bNode?i.applyQuaternion(window.cam.quaternion).normalize():i.applyQuaternion(t.cam.quaternion).normalize();let l=new THREE.Quaternion;l.setFromAxisAngle(i,-n);let r={};r.quaternion=l,r.update=!0,t.bControlGl&&!s.bNode?window.controls.update(r):t.controls.update(r),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,s=t.icn3dui,i=new THREE.Vector3(1,0,0),n=e/180*Math.PI;t.bControlGl&&!s.bNode?i.applyQuaternion(window.cam.quaternion).normalize():i.applyQuaternion(t.cam.quaternion).normalize();let l=new THREE.Quaternion;l.setFromAxisAngle(i,-n);let r={};r.quaternion=l,r.update=!0,t.bControlGl&&!s.bNode?window.controls.update(r):t.controls.update(r),t.bRender&&t.drawCls.render()}setRotation(e,t){let s=this.icn3d,i=s.icn3dui;if(!e)return;s.bControlGl&&!i.bNode&&window.cam?e.applyQuaternion(window.cam.quaternion).normalize():s.cam&&e.applyQuaternion(s.cam.quaternion).normalize();let n=new THREE.Quaternion;n.setFromAxisAngle(e,-t);let l={};l.quaternion=n,l.update=!0,s.bControlGl&&!i.bNode&&window.controls?window.controls.update(l):s.controls&&s.controls.update(l),s.bRender&&s.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 s=this.icn3d,i=s.icn3dui,n=new THREE.Vector2(0,0);n.x+=e/100,n.y+=t/100;let l={};l.mouseChange=n,l.update=!0,s.bControlGl&&!i.bNode?window.controls.update(l):s.controls.update(l),s.bRender&&s.drawCls.render()}translateCoord(e,t,s,i){let n=this.icn3d;n.icn3dui;for(let l in e){let e=n.atoms[l];e.coord.x+=t,e.coord.y+=s,e.coord.z+=i}}rotateCoord(e,t){let s=this.icn3d;s.icn3dui;const i=new THREE.Matrix4;i.elements=t;for(let t in e){let e=s.atoms[t];e.coord=e.coord.applyMatrix4(i)}}zoominSelection(e){let t=this.icn3d,s=t.icn3dui,i={};if(i._zoomFactor=1/t._zoomFactor,i.update=!0,t.bControlGl&&!s.bNode?window.controls&&window.controls.update(i):t.controls&&t.controls.update(i),void 0===e&&(e=s.hashUtilsCls.hash2Atoms(t.hAtoms,t.atoms)),Object.keys(e).length>1){let s=t.applyCenterCls.centerAtoms(e);t.maxD=s.maxD,t.maxD<5&&(t.maxD=5),t.center=s.center,t.applyCenterCls.setCenter(t.center),t.cameraCls.setCamera()}}getTransformationStr(e){this.icn3d.icn3dui;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)}}class Ps{constructor(e){this.icn3d=e}saveFile(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=this;if("command"===t){let e=l.loadCmd?l.loadCmd+"\n":"";for(let t=0,s=l.commands.length;t<s;++t){let i=l.commands[t].trim();if(t==s-1){let e=i.split("|||"),t={};t.factor=l._zoomFactor,t.mouseChange=l.mouseChange,t.quaternion=l.quaternion,i=e[0]+"|||"+l.transformCls.getTransformationStr(t)}e+=i+"\n"}let t=decodeURIComponent(e);n=new Blob([t],{type:"text;charset=utf-8;"})}else if("png"===t){let t=$("#"+l.pre+"canvas").width(),s=$("#"+l.pre+"canvas").height();l.applyCenterCls.setWidthHeight(t,s),l.bRender&&l.drawCls.render();let a=!0;if(window.File&&window.FileReader&&window.FileList&&window.Blob||(a=!1),r.utilsCls.isIE()){if(n=l.renderer.domElement.msToBlob(),!a)return o.saveBlob(n,e,i,t,s),n;{let a=new FileReader;a.onload=function(a){let d=a.target.result,c=l.shareLinkCls.getPngText();return n=r.convertTypeCls.getBlobFromBufferAndText(d,c),o.saveBlob(n,e,i,t,s),n},a.readAsArrayBuffer(n)}}else l.renderer.domElement.toBlob((function(d){if(!a)return n=d,o.saveBlob(n,e,i,t,s),n;{let a=new FileReader;a.onload=function(a){let d=a.target.result,c=l.shareLinkCls.getPngText();return n=r.convertTypeCls.getBlobFromBufferAndText(d,c),o.saveBlob(n,e,i,t,s),n},a.readAsArrayBuffer(d)}}));l.scaleFactor=1,l.applyCenterCls.setWidthHeight(t,s),l.bRender&&l.drawCls.render()}else if("html"===t){let e=decodeURIComponent(s);n=new Blob([e],{type:"text/html;charset=utf-8;"})}else if("text"===t){n=new Blob(s,{type:"text;charset=utf-8;"})}else if("binary"===t){n=new Blob(s,{type:"application/octet-stream"})}return"png"!==t&&saveAs(n,e),n}saveBlob(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui,s){let t=(window.URL||window.webkitURL).createObjectURL(e),s=l.shareLinkCls.shareLinkUrl();s=s.replace(/imageonly=1/g,""),s.length>4e3||0!==s.indexOf("http")||l.bInputfile&&!l.bInputUrlfile?$("#"+l.pre+"viewer").html("<img src='"+t+"'/>"):$("#"+l.pre+"viewer").html("<a href='"+s+"' target='_blank'><img src='"+t+"'/></a>"),$("#"+l.pre+"viewer").width(i),$("#"+l.pre+"viewer").height(n),$("#"+l.pre+"cmdlog").hide(),$("#"+l.pre+"title").hide(),$("#"+l.pre+"mnlist").hide(),$("#"+l.pre+"fullscreen").length>0&&$("#"+l.pre+"fullscreen").hide(),l={}}else saveAs(e,t)}saveSvg(e,t,s,i){let n=this.icn3d;if(n.icn3dui.bNode)return"";let l=$("#"+e).width(),r=$("#"+e).height();s&&(r=l),i&&(l+=n.len4ang,r+=n.len4ang);let o=this.getSvgXml(e,l,r,s,i),a=new Blob([o],{type:"image/svg+xml"});saveAs(a,t)}getSvgXml(e,t,s,i,n){if(this.icn3d.icn3dui.bNode)return"";return(t&&s?'<svg viewBox="'+(n?-30:0)+" "+(n?-30:0)+" "+t+" "+s+'"':"<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,s,i){let n=this.icn3d,l=n.icn3dui;if(l.bNode)return"";let r=$("#"+e).width(),o=$("#"+e).height();s&&(o=r);let a=document.getElementById(e),d=a.getBBox(),c=a.cloneNode(!0);i||n.lineGraphCls.copyStylesInline(c,a);let h=document.createElement("CANVAS");h.width=r,h.height=o;let p=h.getContext("2d");p.clearRect(0,0,d.width,d.height);let m=this.getSvgXml(e,r,o,s),u=window.URL||window.webkitURL||window,g=new Blob([m],{type:"image/svg+xml;charset=utf-8"}),f=new Image;f.src=u.createObjectURL(g),f.onload=function(){if(p.drawImage(f,0,0),u.revokeObjectURL(this.src),l.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 s="",i=void 0!==t.defNames2Residues?Object.keys(t.defNames2Residues).sort():[];for(let n=0,l=i.length;n<l;++n){let l=i[n],r=t.defNames2Residues[l];t.defNames2Descr[l];let o=t.defNames2Command[l];o=o.replace(/,/g,", "),s+=this.exportResidues(l,r,e)}i=void 0!==t.defNames2Atoms?Object.keys(t.defNames2Atoms).sort():[];for(let n=0,l=i.length;n<l;++n){let l=i[n],r=t.defNames2Atoms[l];t.defNames2Descr[l];let o=t.defNames2Command[l];o=o.replace(/,/g,", ");let a=t.resid2specCls.atoms2residues(r);s+=this.exportResidues(l,a,e)}return s}exportResidues(e,t,s){var i=this.icn3d,n=i.icn3dui;let l="";if(t.length>0)if(s){let s={};for(let e=0,l=t.length;e<l;++e){let l=t[e],r=i.firstAtomObjCls.getFirstAtomObj(i.residues[l]),o=r.structure+"_"+r.chain,a=n.utilsCls.residueName2Abbr(r.resn)+r.resi;s.hasOwnProperty(o)||(s[o]=[]),s[o].push(a)}l+=e+":\n";for(let e in s){let t=1==s[e].length?"residue":"residues";l+=e+" ("+s[e].length+" "+t+"): ",l+=s[e].join(", "),l+="\n"}l+="\n"}else l+=e+"\tselect ",l+=i.resid2specCls.residueids2spec(t),l+="\n";return l}printPrevSecondary(e,t,s,i){this.icn3d.icn3dui;let n="";if(s)if(e){let e=1;n+=s.resn.padStart(5," ")+s.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+s.resi.toString().padStart(5," ")+" "+e+i.toString().padStart(36," ")+"\n"}else if(t){let e=0;n+=s.resn.padStart(5," ")+s.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+s.resi.toString().padStart(4," ")+" "+e+"\n"}return n}getAtomPDB(e,t,s,i,n,l,r,o){let a=this.icn3d,d=a.icn3dui,c="",h={},p={};for(let e in a.chemicals){let t=a.atoms[e];if("P"==t.elem){h[e]=1;for(let e=0,s=t.bonds.length;e<s;++e){let s=t.bonds[e];s&&"O"==a.atoms[s].elem&&(p[s]=1)}}}let m,u,g=d.hashUtilsCls.intHash(e,a.calphas),f={};for(let e in a.structures)f[e]="";let C=[];for(let e in g){let t=a.atoms[e];u=t.structure,t.structure,t.chain;let s={};if(s.chain=t.chain,s.resn=t.resn,s.resi=t.resi,parseInt(t.resi)>parseInt(m)+1&&(s.ss=" ",C.push(s)),"helix"==t.ss?(s.ss="H",C.push(s)):"sheet"==t.ss&&(s.ss="S",C.push(s)),t.ssend){let e=d.hashUtilsCls.cloneHash(s);e.ss=" ",C.push(e)}m=t.resi}let b,y,v=0,_=!1,w=!1;for(let e=0,t=C.length;e<t;++e){let t=C[e];(t.ss!=b||t.ssbegin)&&(f[u]+=this.printPrevSecondary(_,w,y,v),v=0,_=!1,w=!1,y=void 0," "!=t.ss&&("H"==t.ss?(_=!0,y=t,f[u]+="HELIX".padEnd(15," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(5," ")):"S"==t.ss&&(w=!0,y=t,f[u]+="SHEET".padEnd(17," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(4," "))))," "!=t.ss&&(++v,y=t),b=t.ss}if(f[u]+=this.printPrevSecondary(_,w,y,v),f[u]+="\n",a.biomtMatrices&&Object.keys(e).length==Object.keys(a.atoms).length){let e=Object.keys(a.structures)[0];for(let t=0,s=a.biomtMatrices.length;t<s;++t){let s=t+1;for(let i=0;i<3;++i){let n=i+1;f[e]+="REMARK 350 BIOMT"+n.toString()+" "+s.toString().padStart(2," ")+" "+a.biomtMatrices[t].elements[i+0].toFixed(6).toString().padStart(9," ")+" "+a.biomtMatrices[t].elements[i+4].toFixed(6).toString().padStart(9," ")+" "+a.biomtMatrices[t].elements[i+8].toFixed(6).toString().padStart(9," ")+" "+a.biomtMatrices[t].elements[i+12].toFixed(6).toString().padStart(14," ")+"\n"}}}for(let e in a.chainMissingResidueArray){let t=e.indexOf("_"),s=e.substr(t+1,2),i=e.substr(0,t);for(let t=0,n=a.chainMissingResidueArray[e].length;t<n;++t){let n=a.chainMissingResidueArray[e][t].resi,l=d.utilsCls.residueAbbr2Name(a.chainMissingResidueArray[e][t].name);f[i]+="REMARK 465 "+l.padStart(3," ")+s.padStart(2," ")+" "+n.toString().padStart(5," ")+"\n"}}let S="",A=Object.keys(a.structures).length>1,x=1,k="",O="",R=0,I="",E={};for(let l in e){let e=a.atoms[l];if(s&&e.het)continue;if(e.structure!=k){r&&A||(c+=S,S="",x>1&&(c+="\nENDMDL\n"),A&&(c+="MODEL "+x+"\n"));let t=n?"Mutated chain_residue "+Object.keys(n)+"; ":"";i||r&&A||(c+=this.getPDBHeader(x-1,f,t,e.structure)),++x}e.chain!=O&&e.structure==k&&O&&(c+="TER\n");let m=e.chain+"_"+e.resi;if(n&&n.hasOwnProperty(m)){E.hasOwnProperty(m)||(c+=n[m],E[m]=1);continue}let u="";u+=e.het?"HETATM":"ATOM ",u+=l.toString().padStart(5," "),u+=" ";let g=e.name.trim();isNaN(g.substr(0,1))||(g=g.substr(1)+g.substr(0,1)),4==g.length?u+=g:(u+=" ",g=g.replace(/\*/g,"'"),"O1P"==g?g="OP1":"O2P"==g?g="OP2":"C5M"==g&&(g="C7 "),u+=g.padEnd(3," ")),u+=" ";let C=e.resn;if(u+=C.length<=3?C.padStart(3," "):C.substr(0,3),r&&x>2&&(a.proteins.hasOwnProperty(e.serial)||a.nucleotides.hasOwnProperty(e.serial)))e.structure==k&&e.chain==O||(I=R<36?"abcdefghijklmnopqrstuvwxyz0123456789"[R]:"?",++R),u+=" "+I;else if(e.chain.length>=2){let t=e.chain.replace(/_/gi,"").substr(0,2);o&&(t=" "+t.substr(0,1)),u+=t}else 1==e.chain.length?u+=" "+e.chain.substr(0,1):0==e.chain.length&&(u+=" A");let b=e.resi;!isNaN(b)&&e.chain.length>3&&!isNaN(e.chain.substr(3))&&(b=b-1+parseInt(e.chain.substr(3)));let y=parseInt(b);u+=y.toString().length<=4?y.toString().padStart(4," "):y.toString().substr(0,4);let v=e.resi.toString().substr(e.resi.toString().length-1,1);if(isNaN(v)?u+=v:u+=" ",u+=" ".padStart(3," "),u+=e.coord.x.toFixed(3).toString().padStart(8," "),u+=e.coord.y.toFixed(3).toString().padStart(8," "),u+=e.coord.z.toFixed(3).toString().padStart(8," "),t&&e.het){let t=1.5,s=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?s=e.crg:h.hasOwnProperty(l)?s=1.38:p.hasOwnProperty(l)?s=-.595:d.parasCls.ionCharges.hasOwnProperty(e.elem)&&(s=d.parasCls.ionCharges[e.elem]),u+=s.toFixed(4).toString().padStart(8," "),u+=t.toFixed(4).toString().padStart(7," ")}else{u+="1.00".padStart(6," ");let t=o?"1.0":" ";u+=e.b?parseFloat(e.b).toFixed(2).toString().padStart(6," "):t.padStart(6," "),u+=" ".padStart(10," "),u+=e.elem.padStart(2," "),u+=" ".padStart(2," ")}if(e.het&&e.bonds.length>0){S+="CONECT"+l.toString().padStart(5," ");let t={};for(let s=0,i=e.bonds.length;s<i;++s)e.bonds[s]&&!t.hasOwnProperty(e.bonds[s])&&(S+=e.bonds[s].toString().padStart(5," "),t[e.bonds[s]]=1);S+="\n"}c+=u+"\n",k=e.structure,O=e.chain}return r&&A||(c+=S,A&&(c+="\nENDMDL\n")),c}getSecondary(e){let t=this.icn3d,s=t.icn3dui,i='{"data": [\n',n="",l="",r={};for(let i in e){let e=t.atoms[i],o=e.structure+"_"+e.chain,a=e.resi,d=s.utilsCls.residueName2Abbr(e.resn),c=this.secondary2Abbr(e.ss);o!=n&&(r[o]={resi:[],resn:[],secondary:[]}),o==n&&a==l||(r[o].resi.push(a),r[o].resn.push(d),r[o].secondary.push(c)),n=o,l=a}let o=Object.keys(r),a=o.length;for(let e=0;e<a;++e){let t=o[e];i+='{"chain": "'+t+'",\n',i+='"resi": "'+r[t].resi.join(",")+'",\n',i+='"resn": "'+r[t].resn.join("")+'",\n',i+='"secondary": "'+r[t].secondary.join("")+'"',i+=e<a-1?"},\n":"}\n"}return i+="]}\n",i}secondary2Abbr(e){return this.icn3d.icn3dui,"helix"==e?"H":"sheet"==e?"E":"c"}getSelectedResiduePDB(){let e=this.icn3d,t="",s=e.icn3dui.hashUtilsCls.intHash(e.dAtoms,e.hAtoms);return t+=this.getAtomPDB(s),t}getPDBHeader(e,t,s,i){let n=this.icn3d;n.icn3dui,void 0===e&&(e=0);let l="",r=i||Object.keys(n.structures)[e],o=s?r+"2":r;if(l+="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=""),s&&(e=s+e),l+="TITLE "+e+"\n"}return t&&t[r]&&(l+=t[r]),l}showTitle(){var e=this.icn3d,t=e.icn3dui;let s=e.molTitle?e.molTitle:"",i="black"==e.opts.background?t.htmlCls.GREYD:"black";if(void 0===e.inputid)s.length>40&&(s=s.substr(0,40)+"..."),$("#"+e.pre+"title").html(s);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:"+i+"' target='_blank'>"+e.inputid.toUpperCase()+"</a>: "+s)}else if(void 0!==t.cfg.align)s="VAST+ alignment of "+Object.keys(e.structures),$("#"+e.pre+"title").html(s);else if(void 0!==t.cfg.chainalign){s="Dynamic Structure Alignment of Chains: "+t.cfg.chainalign.split(","),$("#"+e.pre+"title").html(s)}else{let n=Object.keys(t.utilsCls.getStructures(e.dAtoms));if(n.length>1){s="Multiple structures: ";for(let e=0,t=n.length;e<t;++e){s+='<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:'+i+'" target="_blank">'+n[e]+"</a>",e<t-1&&(s+=", ")}$("#"+e.pre+"title").html(s)}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,s,i)}}}setStructureTitle(e,t,s){var i=this.icn3d,n=i.icn3dui;t.length>40&&(t=t.substr(0,40)+"...");let l,r,o=i.inputid;if(-1!=o.indexOf("http"))r="Data from",e=o,l=o;else{let e=n.utilsCls.getHlStructures(),s=!1,a=!1;for(let t in e)t.length>5?a=!0:s=!0;let d=Object.keys(e);if(o=d.join(","),l=n.cfg.refseqid||n.cfg.protein?i.inputid:o.toUpperCase(),s&&a?r="AlphaFold/PDB ID":s?r="PDB ID":a&&(r="AlphaFold ID"),d.length>1&&(r+="s"),i.molTitleHash){t="";for(let e=0,s=d.length;e<s;++e)t+=i.molTitleHash[d[e]],e<s-1&&(t+="; ")}}if(n.cfg.refseqid?r="NCBI Protein Acc.":n.cfg.protein&&(r="Protein/Gene Name"),o&&o.substr(0,4)!=i.defaultPdbId)if(n.cfg.blast_rep_id){let e=n.cfg.oriQuery_id?n.cfg.oriQuery_id:n.cfg.query_id,s=n.cfg.oriBlast_rep_id?n.cfg.oriBlast_rep_id:n.cfg.blast_rep_id;e.length>20&&(e=e.substr(0,17)+"..."),l="Query: "+e+"; target: "+s,$("#"+i.pre+"title").html(l+", "+t)}else $("#"+i.pre+"title").html(r+" <a id='"+i.pre+"titlelink' href='"+e+"' style='color:"+s+"' target='_blank'>"+l+"</a>: "+t);else $("#"+i.pre+"title").html(t)}getLinkToStructureSummary(e){var t=this.icn3d,s=t.icn3dui;let i="https://www.ncbi.nlm.nih.gov/structure/?term=";if(i=void 0!==s.cfg.cid?"https://www.ncbi.nlm.nih.gov/pccompound/?term=":void 0!==s.cfg.refseqid?"https://www.ncbi.nlm.nih.gov/protein/":void 0!==s.cfg.afid?"https://alphafold.ebi.ac.uk/search/text/":Object.keys(t.structures).length>1?"https://www.ncbi.nlm.nih.gov/structure/?term=":s.htmlCls.baseUrl+"pdb/",void 0===t.inputid)i="https://www.ncbi.nlm.nih.gov/pccompound/?term="+t.molTitle;else{let n=t.inputid.split("_");1===n.length?(i+=t.inputid,e&&s.htmlCls.clickMenuCls.setLogCmd("link to "+t.inputid+": "+i,!1)):2===n.length&&(s.cfg.afid?i+=n[0]+" "+n[1]:i+=n[0]+" OR "+n[1],e&&s.htmlCls.clickMenuCls.setLogCmd("link to structures "+n[0]+" and "+n[1]+": "+i,!1))}return i}setEntrezLinks(e){var t=this.icn3d,s=t.icn3dui;let i,n=Object.keys(t.structures);if(1===n.length){i="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0],s.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+": "+i,!1);let l=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(i,l)}else if(2===n.length){i="https://www.ncbi.nlm.nih.gov/"+e+"/?term="+n[0]+" OR "+n[1],s.htmlCls.clickMenuCls.setLogCmd("Entrez "+e+" about PDB "+n[0]+" OR "+n[1]+": "+i,!1);let l=t.structures&&Object.keys(t.structures).length>0?"_blank":"_self";window.open(i,l)}}}class Ds{constructor(e){this.icn3d=e}async shareLink(e,t){let s=this.icn3d,i=s.icn3dui,n=this.shareLinkUrl(),l=n.length>4e3||0!==n.indexOf("http"),r=Object.keys(s.structures).join("_");if(r==s.defaultPdbId&&(s.filename?r=s.filename:s.inputid&&(r=s.inputid)),e){if(t||s.bInputfile||l)return void s.saveFileCls.saveFile(r+"_icn3d_loadable.png","png")}else{if(s.bInputfile&&!s.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(l)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.");i.htmlCls.clickMenuCls.setLogCmd("share link: "+n,!1)}let o="Problem in getting shortened URL";if(!i.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];s.saveFileCls.saveFile(r+"-"+t+".png","png");let i='<div style="float:left; border: solid 1px #0000ff; padding: 5px; margin: 10px; text-align:center;">';i+='<a href="https://structure.ncbi.nlm.nih.gov/icn3d/share.html?'+t+'" target="_blank">',i+='<img style="height:300px" src ="'+r+"-"+t+'.png"><br>\n',i+="\x3c!--Start of your comments==================--\x3e\n";let n=s.yournote?": "+s.yournote.replace(/\n/g,"<br>").replace(/; /g,", "):"";i+="PDB "+r.toUpperCase()+n+"\n",i+="\x3c!--End of your comments====================--\x3e\n",i+="</a>",i+="</div>\n\n",s.saveFileCls.saveFile(r+"-"+t+".html","html",i)}e&&void 0===t.shortLink&&s.saveFileCls.saveFile(r+"_icn3d_loadable.png","png");let i=o.split("page.link/");2==i.length&&(o="https://structure.ncbi.nlm.nih.gov/icn3d/share.html?"+i[1]),$("#"+s.pre+"short_url").val(o),$("#"+s.pre+"short_url_title").val(o+"&t="+s.yournote)}let a=this.shareLinkUrl(void 0,!0),d="view = icn3dpy.view(q='"+(i.cfg.url?"url="+i.cfg.url:i.cfg.idname+"="+i.cfg.idvalue)+"',command='"+a+"')\nview";(i.cfg.url||i.cfg.idname)&&$("#"+s.pre+"jn_commands").val(d),$("#"+s.pre+"ori_url").val(n),e||i.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL or Jupyter Notebook Commands")}getShareLinkPrms(e,t){let s=this.icn3d,i=s.icn3dui;return new Promise((function(n,l){$.ajax({url:"https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=AIzaSyBxl9CgM0dY5lagHL4UOhEpLWE1fuwdnvc",type:"POST",data:{longDynamicLink:"https://icn3d.page.link/?link="+encodeURIComponent(e)},dataType:"json",success:function(e){n(e)},error:function(n,l,r){let o="Problem in getting shortened URL";$("#"+s.pre+"ori_url").val(e),$("#"+s.pre+"short_url").val(o),$("#"+s.pre+"short_url_title").val(o+"&t="+s.yournote),t||i.htmlCls.dialogCls.openDlg("dl_copyurl","Copy a Share Link URL")}})}))}shareLinkUrl(e,t,s){let i=this.icn3d,n=i.icn3dui,l=n.htmlCls.baseUrl+"icn3d/full_"+n.REVISION+".html?",r="";if(n.cfg.bSidebyside&&(l=n.htmlCls.baseUrl+"icn3d/full2.html?"),i.bInputUrlfile){l=window.location.href.split("?")[0]+"?"+i.inputurl+"&"}let o,a={};for(let e in i.cfg){let t=i.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||"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&&(a[e]=JSON.stringify(t)):!0===t?a[e]=1:!1===t?a[e]=0:""!==t&&(a[e]=t)))}i.bAfMem?a.afmem="on":(n.cfg.afid||1==Object.keys(i.structures).length&&Object.keys(i.structures)[0].length>5)&&(a.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(!i.bInputUrlfile){let e=o&&o.substr(1)?o.substr(1).split("&"):[];for(let t=0,s=e.length;t<s;++t){let s=e[t].split("=");2==s.length&&(a[s[0]]=s[1])}n.cfg.idname&&!a[n.cfg.idname]&&(l+=n.cfg.idname+"="+n.cfg.idvalue+"&");for(let e in a)"v"!==e&&("date"===e&&(c=!0),l+=e+"="+a[e]+"&")}let h,p=n.utilsCls.getDateDigitStr();c||(l+="date="+p+"&"),l+="v="+n.REVISION+"&",l+="command=",h=t&&void 0!==o?1:0,(e||i.bInputUrlfile)&&(h=0);let m={};m.factor=i._zoomFactor,m.mouseChange=i.mouseChange,m.quaternion=i.quaternion;let u="",g="",f="toggle highlight",C=0;if(i.commands.length>h){g=i.commands[h].split("|||")[0].split("&command=")[0].trim(),-1!==g.indexOf(f)&&++C}let b,y=h+1,v="";for(let e=i.commands.length;y<e;++y){let e=i.commands[y].split("|||")[0].split("&command=")[0].trim();0==g.indexOf("select sets")&&0===e.indexOf("select sets")&&-1===g.indexOf(" name ")||-1!==g.indexOf("pickatom")&&-1!==e.indexOf("pickatom")||"show selection"==g&&-1!=i.commands.slice(y).toString().indexOf("show selection")||g==e||(-1!==g.indexOf(f)?++C:v+=y===h+1?g:v?"; "+g:g),-1==g.indexOf("load ")&&(u+=g+"\n"),g=e}return g&&(v&&(v+="; "),C>0&&C%2==0&&g!==f&&(v+=f+"; "),v+=g+"|||"+i.transformCls.getTransformationStr(m),u+=g+"|||"+i.transformCls.getTransformationStr(m)+"\n"),l+=v,r=v,u=u.replace(/!/g,Object.keys(i.structures)[0]+"_"),(i.bEsmfold||i.bInputfile&&!i.bInputUrlfile||i.bInputUrlfile&&i.bAppend||l.length>4e3)&&(l=u),void 0!==i.structures&&1==Object.keys(i.structures).length&&void 0!==i.inputid&&(b=Object.keys(i.structures)[0],l=l.replace(new RegExp(b+"_","g"),"!"),r=r.replace(new RegExp(b+"_","g"),"!")),void 0!==n.cfg.blast_rep_id&&(l=l.replace(new RegExp("blast_rep_id=!","g"),"blast_rep_id="+b+"_")),s?u:t?r:l}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 Ms{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,s=e.lines.hbond.length;t<s;++t){e.lines.hbond[t].dashed=!1,e.bDashedLines=!0}if(void 0!==e.lines.distance)for(let t=0,s=e.lines.distance.length;t<s;++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,s=e.lines.hbond.length;t<s;++t){e.lines.hbond[t].dashed=!0}if(void 0!==e.lines.distance)for(let t=0,s=e.lines.distance.length;t<s;++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,s=this.icn3d;s.icn3dui;for(let i=0,n=s.pairArray.length;i<n;i+=2){let n=this.getResidueRepAtom(s.pairArray[i]),l=this.getResidueRepAtom(s.pairArray[i+1]);if(null!=e)for(let s=0,r=e.length;s<r;s+=2){let r=this.getResidueRepAtom(e[s]),o=this.getResidueRepAtom(e[s+1]);if(n.serial==r.serial&&l.serial==o.serial||n.serial==o.serial&&l.serial==r.serial){t=i;break}}if(void 0!==t)break}void 0!==t&&s.pairArray.splice(t,2)}outputSelection(){let e=this.icn3d,t=e.icn3dui,s={};for(let t in e.hAtoms){s[e.atoms[t].structure+"_"+e.atoms[t].chain+"_"+e.atoms[t].resi]=1}let i=Object.keys(s).sort((function(e,t){if(""!==e&&!isNaN(e))return parseInt(e)-parseInt(t);{let s=e.lastIndexOf("_"),i=t.lastIndexOf("_");if(e.substr(0,s)<t.substr(0,s))return-1;if(e.substr(0,s)>t.substr(0,s))return 1;if(e.substr(0,s)==t.substr(0,s)){if(parseInt(e.substr(s+1))<parseInt(t.substr(i+1)))return-1;if(parseInt(e.substr(s+1))>parseInt(t.substr(i+1)))return 1;if(parseInt(e.substr(s+1))==parseInt(t.substr(i+1)))return 0}}})),n="<table><tr><th>Structure</th><th>Chain</th><th>Residue Number</th></tr>";for(let e=0,t=i.length;e<t;++e){let t=i[e].indexOf("_"),s=i[e].lastIndexOf("_");n+="<tr><td>"+i[e].substr(0,t)+"</td><td>"+i[e].substr(t+1,s-t-1)+"</td><td>"+i[e].substr(s+1)+"</td></tr>"}let l=Object.keys(t.utilsCls.getHlStructures()).join(",");e.saveFileCls.saveFile(l+"_residues.txt","html",n)}addStabilizer(){let e=this.icn3d,t=e.icn3dui,s=3.5;if(Object.keys(e.dAtoms).length>0){let i,n={},l=12.25,r=3.2*3.2;for(let t in e.dAtoms){let s=e.atoms[t];!e.nucleotides.hasOwnProperty(s.serial)||"N1"!==s.name&&"N2"!==s.name&&"N3"!==s.name&&"N4"!==s.name&&"N6"!==s.name&&"O2"!==s.name&&"O6"!==s.name||(i=s.structure+"_"+s.chain+"_"+s.resi+"_"+s.name,n[i]=s)}let o=Object.keys(n),a=o.length;void 0===e.pairArray&&(e.pairArray=[]);for(let t=0;t<a;++t)for(let i=t+1;i<a;++i){let a=o[t],d=o[i],c=Math.abs(n[a].coord.x-n[d].coord.x);if(c>s)continue;let h=Math.abs(n[a].coord.y-n[d].coord.y);if(h>s)continue;let p=Math.abs(n[a].coord.z-n[d].coord.z);if(p>s)continue;let m=c*c+h*h+p*p;m>l||m<r||(e.pairArray.push(n[a].serial),e.pairArray.push(n[d].serial))}let d=6,c={};for(let t in e.dAtoms){let s=e.atoms[t];c[s.structure+"_"+s.chain+"_"+s.resi]=1}let h={};for(let t in e.chemicals){let s=e.atoms[t],i=s.structure+"_"+s.chain+"_"+s.resi;c.hasOwnProperty(i)&&(h[i]=1)}for(let t in e.ions){let s=e.atoms[t],i=s.structure+"_"+s.chain+"_"+s.resi;c.hasOwnProperty(i)&&(h[i]=1)}let p=Object.keys(e.chains);for(let t=0,s=p.length;t<s;++t){let s,i=p[t],n=0,l=0;for(let t=0,r=e.chainsSeq[i].length;t<r;++t)s=i+"_"+e.chainsSeq[i][t].resi,"c"!=e.secondaries[s]&&"E"!=e.secondaries[s]&&"H"!=e.secondaries[s]||(n%3!=0&&e.resid2ncbi[e.chainsSeq[i][t].resi]==e.resid2ncbi[l]+1||c.hasOwnProperty(s)&&(h[s]=1),++n,l=e.chainsSeq[i][t].resi);"c"!=e.secondaries[s]&&"E"!=e.secondaries[s]&&"H"!=e.secondaries[s]||c.hasOwnProperty(s)&&(h[s]=1)}let m=Object.keys(h);void 0===e.pairArray&&(e.pairArray=[]);let u=t.hashUtilsCls.exclHash(e.dAtoms,e.water);for(let s=0,i=m.length;s<i;++s){let i=m[s],n=e.secondaries[i],l=e.contactCls.getNeighboringAtoms(u,t.hashUtilsCls.hash2Atoms(e.residues[i],e.atoms),d),r=Object.keys(l).sort(),o=Object.keys(e.residues[i]).sort(),a=!1;if(e.proteins.hasOwnProperty(o[0])){o=[o[0]],a=!0;let t=i.substr(0,i.lastIndexOf("_")),s=e.ParserUtilsCls.getResiNCBI(t,i.substr(i.lastIndexOf("_")+1)),d={};for(let i in l){if(e.chemicals.hasOwnProperty(i)||e.ions.hasOwnProperty(i))continue;let l=e.atoms[i];if(isNaN(l.resi))continue;let r=e.ParserUtilsCls.getResiNCBI(t,l.resi);("c"==n&&(r>s+1||r<s-1)||"E"==n&&(r>s+2||r<s-2)||"H"==n&&(r>s+4||r<s-4))&&(d[i]=1)}r=Object.keys(d).sort()}if(r.length>0&&o.length>0)if(a){let t=parseInt((r.length+.5)/2);e.pairArray.push(o[0]),e.pairArray.push(r[t])}else{let t=10,s=parseInt(r.length/(t+1));for(let i=0,n=o.length;i<n;++i)if(i%t==0){let n=parseInt(i/t)*s,l=n<r.length?n:r.length-1;e.pairArray.push(o[i]),e.pairArray.push(r[l]),o.length<t+1&&(e.pairArray.push(o[i]),e.pairArray.push(r[r.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 s,i=t.atoms[e],n=i.structure+"_"+i.chain+"_"+i.resi;if(t.proteins.hasOwnProperty(e)||t.nucleotides.hasOwnProperty(e))for(let e in t.residues[n]){let i=t.atoms[e];if("CA"===i.name||"N3"===i.name){s=t.atoms[e];break}}else s=i;return void 0===s&&(s=i),s}}class Fs{constructor(e){this.icn3d=e}exportStlFile(e){let t=this.icn3d,s=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 i=this.saveStlFile(),n=Object.keys(s.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".stl","binary",i),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 s=new THREE.Matrix4;s.identity();let l=1;for(let r=0;r<t.biomtMatrices.length;r++){let o=t.biomtMatrices[r];if(void 0===o)continue;if(o.equals(s))continue;let a=100*(r+1);setTimeout(function(s,l){i=this.saveStlFile(s),t.saveFileCls.saveFile(n+e+l+".stl","binary",i),i=""}.bind(this,o,l),a),++l}t.threshbox=180}}exportVrmlFile(e){let t=this.icn3d,s=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 i=this.saveVrmlFile(),n=Object.keys(s.utilsCls.getHlStructures()).join(",");if(t.saveFileCls.saveFile(n+e+".wrl","text",i),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 s=new THREE.Matrix4;s.identity();let n=1;for(let l=0;l<t.biomtMatrices.length;l++){let r=t.biomtMatrices[l];if(void 0===r)continue;if(r.equals(s))continue;let o=100*(l+1);setTimeout(function(s,n){i=this.saveVrmlFile(s),t.saveFileCls.saveFile(t.inputid+e+n+".wrl","text",i),i=""}.bind(this,r,n),o),++n}t.threshbox=180}}getFaceCnt(e){this.icn3d.icn3dui;let t=0;for(let s=0,i=e.children.length;s<i;++s){let i=e.children[s];"Sprite"!==i.type&&(t+=i.geometry.getIndex().array.length/3)}return t}saveStlFile(e){let t=this.icn3d,s=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 i=0;i+=this.getFaceCnt(t.mdl),i+=this.getFaceCnt(t.mdl_ghost);let n=[],l=new Uint8Array(84),r="STL file for the structure(s) ",o=Object.keys(t.structures);for(let e=0,t=o.length;e<t;++e)r+=o[e],e<t-1&&(r+=", ");r.length>80&&(r=r.substr(0,80));for(let e=0;e<80;++e)e<r.length?l[e]=s.convertTypeCls.passInt8([r.charCodeAt(e)])[0]:l[e]=s.convertTypeCls.passInt8([" ".charCodeAt(0)])[0];if(l=void 0!==t.biomtMatrices&&t.biomtMatrices.length>1&&t.bAssembly&&Object.keys(t.dAtoms).length*t.biomtMatrices.length<=t.maxAtoms3DMultiFile?this.updateArray(l,s.convertTypeCls.passInt32([i*t.biomtMatrices.length]),80):this.updateArray(l,s.convertTypeCls.passInt32([i]),80),n.push(new Blob([l],{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 THREE.Matrix4;e.identity();for(let s=0;s<t.biomtMatrices.length;s++){let i=t.biomtMatrices[s];void 0!==i&&(i.equals(e)||(n=this.processStlMeshGroup(t.mdl,n,i),n=this.processStlMeshGroup(t.mdl_ghost,n,i)))}}return t.threeDPrintCls.resetAfter3Dprint(),n}updateArray(e,t,s){this.icn3d.icn3dui;for(let i=0,n=t.length;i<n;++i)e[s+i]=t[i];return e}processStlMeshGroup(e,t,s){let i=this.icn3d.icn3dui;for(let n=0,l=e.children.length;n<l;++n){let l=e.children[n];if("Sprite"===l.type)continue;let r=l.geometry,o=r.getAttribute("position").array,a=r.getIndex().array,d=l.position,c=l.scale,h=l.matrix,p=new Uint8Array(a.length/3*50),m=0;for(let e=0,t=a.length;e<t;e+=3){let t,n,l,u=a[e],g=a[e+1],f=a[e+2],C=new THREE.Vector3(o[3*u],o[3*u+1],o[3*u+2]),b=new THREE.Vector3(o[3*g],o[3*g+1],o[3*g+2]),y=new THREE.Vector3(o[3*f],o[3*f+1],o[3*f+2]);"SphereGeometry"==r.type||"BoxGeometry"==r.type?(t=C.clone().multiply(c).add(d),n=b.clone().multiply(c).add(d),l=y.clone().multiply(c).add(d)):"CylinderGeometry"==r.type?(t=C.clone().applyMatrix4(h),n=b.clone().applyMatrix4(h),l=y.clone().applyMatrix4(h)):(t=C.clone(),n=b.clone(),l=y.clone()),p=this.updateArray(p,i.convertTypeCls.passFloat32([0,0,0]),m),m+=12,void 0!==s&&(t.applyMatrix4(s),n.applyMatrix4(s),l.applyMatrix4(s)),p=this.updateArray(p,i.convertTypeCls.passFloat32([t.x,t.y,t.z]),m),m+=12,p=this.updateArray(p,i.convertTypeCls.passFloat32([n.x,n.y,n.z]),m),m+=12,p=this.updateArray(p,i.convertTypeCls.passFloat32([l.x,l.y,l.z]),m),m+=12,t=n=l=void 0,p=this.updateArray(p,i.convertTypeCls.passInt16([0]),m),m+=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 s=[];s.push("#VRML V2.0 utf8\n");let i=0,n=this.processVrmlMeshGroup(t.mdl,s,i,e);if(s=n.vrmlStrArray,i=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,s,i,e),s=n.vrmlStrArray,i=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 THREE.Matrix4;e.identity();for(let l=0;l<t.biomtMatrices.length;l++){let r=t.biomtMatrices[l];void 0!==r&&(r.equals(e)||(n=this.processVrmlMeshGroup(t.mdl,s,i,r),s=n.vrmlStrArray,i=n.vertexCnt,n=this.processVrmlMeshGroup(t.mdl_ghost,s,i,r),s=n.vrmlStrArray,i=n.vertexCnt))}}return s}processVrmlMeshGroup(e,t,s,i){let n=this.icn3d.icn3dui;for(let s=0,l=e.children.length;s<l;++s){let l=e.children[s];if("Sprite"===l.type)continue;let r=l.geometry;l.material.type,r.type;let o=r.getAttribute("position").array,a=r.getAttribute("color")?r.getAttribute("color").array:[],d=r.getIndex().array,c=l.position,h=l.scale,p=l.matrix,m=n.parasCls.thr(1,1,1);"SphereGeometry"!=r.type&&"BoxGeometry"!=r.type&&"CylinderGeometry"!=r.type||void 0!==l.material&&(m=l.material.color),t.push("Shape {\n"),t.push("geometry IndexedFaceSet {\n"),t.push("coord Coordinate { point [ ");let u=[];for(let e=0,s=o.length;e<s;e+=3){let l,a=new THREE.Vector3(o[e],o[e+1],o[e+2]);l="SphereGeometry"==r.type||"BoxGeometry"==r.type?a.clone().multiply(h).add(c):"CylinderGeometry"==r.type?a.clone().applyMatrix4(p):a.clone(),void 0!==i&&l.applyMatrix4(i),t.push(l.x.toPrecision(5)+" "+l.y.toPrecision(5)+" "+l.z.toPrecision(5)),l=void 0,e<s-3&&t.push(", "),u.push(n.parasCls.thr(1,1,1))}t.push(" ] }\n");let g="",f="";for(let e=0,t=d.length;e<t;e+=3){let s,i=d[e],n=d[e+1],l=d[e+2];s="SphereGeometry"==r.type||"BoxGeometry"==r.type||"CylinderGeometry"==r.type?m:new THREE.Color(a[3*i],a[3*i+1],a[3*i+2]),g+=i+" "+n+" "+l,e<t-3&&(g+=", -1, "),u[i]=s,u[n]=s,u[l]=s}for(let e=0,t=u.length;e<t;++e){let s=u[e];f+=s.r.toPrecision(3)+" "+s.g.toPrecision(3)+" "+s.b.toPrecision(3),e<t-1&&(f+=", ")}t.push("coordIndex [ "+g+" ]\n"),t.push("color Color { color [ "+f+" ] } colorPerVertex TRUE\n"),t.push(" }\n"),t.push("}\n")}return{vrmlStrArray:t,vertexCnt:s}}}class Hs{constructor(e){this.icn3d=e}rayCaster(e,t){this.rayCasterBase(e,t)}rayCasterBase(e,t){let s=this.icn3d;s.icn3dui;let i=e.pageX,n=e.pageY;e.originalEvent.targetTouches&&e.originalEvent.targetTouches[0]&&(i=e.originalEvent.targetTouches[0].pageX,n=e.originalEvent.targetTouches[0].pageY);let l=s.oriContainer.offset().left,r=s.oriContainer.offset().top,o=s.oriContainer.width(),a=s.oriContainer.height(),d=i-l,c=n-r;s.mouse.x=d/o*2-1,s.mouse.y=-c/a*2+1;let h=new THREE.Vector3;h.x=s.mouse.x,h.y=s.mouse.y,s.cam_z>0?h.z=-1:h.z=1,s.cam===s.perspectiveCamera?(s.cam_z>0?h.z=-1:h.z=1,h.unproject(s.cam),s.raycaster.set(s.cam.position,h.sub(s.cam.position).normalize())):s.cam===s.orthographicCamera&&(s.cam_z>0?h.z=1:h.z=-1,h.unproject(s.cam),s.raycaster.set(h,new THREE.Vector3(0,0,-1).transformDirection(s.cam.matrixWorld)));let p=this.isIntersect(s.objects,s.mdl,t,d,c);p||(p=this.isIntersect(s.objects_ghost,s.mdl_ghost,t,d,c))}isIntersect(e,t,s,i,n){let l=this.icn3d;l.icn3dui;let r=l.raycaster.intersectObjects(e),o=!1,a=t.position;if(r.length>0){r[0].point.sub(a);let e=l.rayThreshold,t=this.getAtomsFromPosition(r[0].point,e);for(;!t&&e<10;)e+=.5,t=this.getAtomsFromPosition(r[0].point,e);t?(o=!0,l.pickpair?s&&(l.pAtomNum%2==0?l.pAtom=t:l.pAtom2=t,++l.pAtomNum):l.pAtom=t,s?l.pickingCls.showPicking(t):l.pickingCls.showPicking(t,i,n)):console.log("No atoms were found in 10 andstrom range")}return o}getAtomsFromPosition(e,t,s){let i,n=this.icn3d,l=n.icn3dui;null==t&&(t=1);let r=s||n.dAtoms;for(i in r){let s=n.atoms[i];if(n.ions.hasOwnProperty(i)&&"sphere"===n.opts.ions){let i=l.parasCls.vdwRadii[s.elem.toUpperCase()];if(Math.abs(s.coord.x-e.x)-i>t)continue;if(Math.abs(s.coord.y-e.y)-i>t)continue;if(Math.abs(s.coord.z-e.z)-i>t)continue}else{if(s.coord.x<e.x-t||s.coord.x>e.x+t)continue;if(s.coord.y<e.y-t||s.coord.y>e.y+t)continue;if(s.coord.z<e.z-t||s.coord.z>e.z+t)continue}return s}return null}}class Ls{constructor(e){this.icn3d=e}setControl(){let e=this.icn3d,t=e.icn3dui;if(t.bNode)return;let s=this;e.WIDTH=e.container.width(),e.HEIGHT=e.container.height(),e.applyCenterCls.setWidthHeight(e.WIDTH,e.HEIGHT),e._zoomFactor=1,e.mouseChange=new THREE.Vector2(0,0),e.quaternion=new THREE.Quaternion(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(s){if((s.shiftKey||16===s.keyCode)&&(e.bShift=!0),(s.ctrlKey||17===s.keyCode||224===s.keyCode||91===s.keyCode)&&(e.bCtrl=!0),!e.bControlGl&&!e.controls||e.bControlGl&&!window.controls)return;e.bStopRotate=!0;let i=e.bShift?90:5;if(!e.typetext)if(90===s.keyCode){let s={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?s._zoomFactor=.9:window.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),s._zoomFactor=.8*e._zoomFactor,s._zoomFactor<.1&&(s._zoomFactor=.1)):e.cam===e.perspectiveCamera?s._zoomFactor=.9:e.cam===e.orthographicCamera&&(e._zoomFactor<.1?e._zoomFactor=.1:e._zoomFactor>1&&(e._zoomFactor=1),s._zoomFactor=.8*e._zoomFactor,s._zoomFactor<.1&&(s._zoomFactor=.1)),s.update=!0,e.bControlGl&&!t.bNode?window.controls.update(s):e.controls.update(s),e.bRender&&e.drawCls.render()}else if(88===s.keyCode){let s={};e.bControlGl&&!t.bNode?window.cam===e.perspectiveCamera?s._zoomFactor=1.03:window.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),s._zoomFactor=1.01*e._zoomFactor,s._zoomFactor>10&&(s._zoomFactor=10)):e.cam===e.perspectiveCamera?s._zoomFactor=1.03:e.cam===e.orthographicCamera&&(e._zoomFactor>10?e._zoomFactor=10:e._zoomFactor<1&&(e._zoomFactor=1),s._zoomFactor=1.01*e._zoomFactor,s._zoomFactor>10&&(s._zoomFactor=10)),s.update=!0,e.bControlGl&&!t.bNode?window.controls.update(s):e.controls.update(s),e.bRender&&e.drawCls.render()}else if(76===s.keyCode){let t=new THREE.Vector3(0,1,0),s=-i/180*Math.PI;e.transformCls.setRotation(t,s)}else if(74===s.keyCode){let t=new THREE.Vector3(0,1,0),s=i/180*Math.PI;e.transformCls.setRotation(t,s)}else if(73===s.keyCode){let t=new THREE.Vector3(1,0,0),s=-i/180*Math.PI;e.transformCls.setRotation(t,s)}else if(77===s.keyCode){let t=new THREE.Vector3(1,0,0),s=i/180*Math.PI;e.transformCls.setRotation(t,s)}else 65===s.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(s){if(e.isDragging=!0,e.scene){if(e.bStopRotate=!0,e.pk&&(s.altKey||s.ctrlKey||s.shiftKey||18===s.keyCode||16===s.keyCode||17===s.keyCode||224===s.keyCode||91===s.keyCode)){e.highlightlevel=e.pk;let t=!0;e.rayCls.rayCaster(s,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(s){if(s.preventDefault(),e.isDragging=!0,!e.scene)return;e.bStopRotate=!0,$("#"+e.pre+"popup").hide();e.rayCls.rayCaster(s,!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){s.mouseMove(e)})),e.container.bind("mousewheel",(function(s){s.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(s){s.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,s=t.icn3dui;if(s.bNode)return;if(e.preventDefault(),!t.scene)return;$("#"+t.pre+"popup").hide();if(t.rayCls.rayCaster(e,!1),t.bControlGl&&!s.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 Ns{constructor(e){this.icn3d=e}showPicking(e,t,s){let i=this.icn3d,n=i.icn3dui;if(void 0!==n.cfg.cid&&0!=i.pk&&(i.pk=1),i.highlightlevel=i.pk,this.showPickingBase(e,t,s),0!=i.pk)if(void 0!==t&&void 0!==s){null!=n.cfg.showmenu&&1==n.cfg.showmenu&&(s+=n.htmlCls.MENU_HEIGHT);let l,r=1==i.pk?e.resn+e.resi+"@"+e.name:e.resn+e.resi,o=e.structure+"_"+e.chain;if(void 0!==i.structures&&Object.keys(i.structures).length>1?(r=o+" "+r,l=i.chainid2refpdbname&&i.chainid2refpdbname[o]?240:160,$("#"+i.pre+"popup").css("width",l+"px")):(l=i.chainid2refpdbname&&i.chainid2refpdbname[o]?160:80,$("#"+i.pre+"popup").css("width",l+"px")),i.chainid2refpdbname&&i.chainid2refpdbname[o]){let t=i.resid2refnum[o+"_"+e.resi];t&&(r+=", Ig: "+t)}$("#"+i.pre+"popup").html(r),$("#"+i.pre+"popup").css("top",s).css("left",t+20).show()}else{i.hlUpdateCls.updateHlAll();let t={};t.factor=i._zoomFactor,t.mouseChange=i.mouseChange,t.quaternion={},t.quaternion._x=parseFloat(i.quaternion._x).toPrecision(5),t.quaternion._y=parseFloat(i.quaternion._y).toPrecision(5),t.quaternion._z=parseFloat(i.quaternion._z).toPrecision(5),t.quaternion._w=parseFloat(i.quaternion._w).toPrecision(5),n.htmlCls.clickMenuCls.setLogCmd("pickatom "+e.serial,!0),i.selectionCls.saveSelInCommand(),i.bSphereCalc=!1,i.bHbondCalc=!1}}showPickingBase(e,t,s){this.icn3d.icn3dui,void 0===t&&void 0===s&&this.showPickingHilight(e)}getPickedAtomList(e,t){let s=this.icn3d;s.icn3dui;let i={};if(1===e)i[t.serial]=1;else if(2===e){let e=t.structure+"_"+t.chain+"_"+t.resi;i=s.residues[e]}else if(3===e)i=this.selectStrandHelixFromAtom(t);else if(4===e)i=this.select3ddomainFromAtom(t);else if(5===e){let e=t.structure+"_"+t.chain;i=s.chains[e]}return i}showPickingHilight(e){let t=this.icn3d,s=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 i=Object.keys(t.hAtoms).length==Object.keys(t.atoms).length?{}:s.hashUtilsCls.intHash(t.hAtoms,t.pickedAtomList),n=Object.keys(i).length;if(t.bShift||t.bCtrl)if(t.bShift){if(void 0===t.prevPickedAtomList)t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e=t.firstAtomObjCls.getFirstAtomObj(t.prevPickedAtomList),i=t.firstAtomObjCls.getFirstAtomObj(t.pickedAtomList);if(e.structure+"_"+e.chain!=i.structure+"_"+i.chain)t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList);else{let e;e=s.hashUtilsCls.unionHash(e,t.prevPickedAtomList),e=s.hashUtilsCls.unionHash(e,t.pickedAtomList);let i=t.firstAtomObjCls.getFirstAtomObj(e),n=t.firstAtomObjCls.getLastAtomObj(e);for(let e=i.serial;e<=n.serial;++e)t.hAtoms[e]=1}}t.prevPickedAtomList=s.hashUtilsCls.cloneHash(t.pickedAtomList)}else t.bCtrl&&(t.hAtoms=n>0?s.hashUtilsCls.exclHash(t.hAtoms,t.pickedAtomList):s.hashUtilsCls.unionHash(t.hAtoms,t.pickedAtomList));else t.hAtoms=s.hashUtilsCls.cloneHash(t.pickedAtomList);t.hlObjectsCls.removeHlObjects(),t.hlObjectsCls.addHlObjects()}select3ddomainFromAtom(e){let t,s=this.icn3d,i=s.icn3dui,n=e.structure+"_"+e.chain,l=n+"_"+e.resi;for(let e in s.tddomains){let i=e.indexOf("_3d_domain");if(e.substr(0,i)==n&&-1!==Object.keys(s.tddomains[e]).indexOf(l)){t=e;break}}let r={};for(let e in s.tddomains[t])r=i.hashUtilsCls.unionHash(r,s.residues[e]);return r}selectStrandHelixFromAtom(e){let t=this.icn3d,s=t.icn3dui,i=e,n=e,l={},r=i.resi;if(!i.ssbegin&&!isNaN(i.resi)){for(let e=i.resi-1;e>0;--e){let s=i.structure+"_"+i.chain+"_"+e;if(!t.residues.hasOwnProperty(s))break;let n=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[s]);if(r=n.resi,"coil"!==i.ss&&n.ss===i.ss&&n.ssbegin||"coil"===i.ss&&n.ss!==i.ss){"coil"===i.ss&&n.ss!==i.ss&&(r=parseInt(n.resi)+1);break}}for(let e=r;e<=i.resi;++e){let n=i.structure+"_"+i.chain+"_"+e;l=s.hashUtilsCls.unionHash(l,s.hashUtilsCls.hash2Atoms(t.residues[n],t.atoms))}}let o=n.resi,a=t.firstAtomObjCls.getLastAtomObj(t.chains[n.structure+"_"+n.chain]).resi;for(let e=parseInt(n.resi)+1;e<=parseInt(a);++e){let s=n.structure+"_"+n.chain+"_"+e;if(!t.residues.hasOwnProperty(s))break;let i=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[s]);if(o=i.resi,"coil"!==n.ss&&i.ss===n.ss&&i.ssend||"coil"===n.ss&&i.ss!==n.ss){"coil"!==n.ss||i.ss===n.ss||isNaN(i.resi)||(o=i.resi-1);break}}for(let e=parseInt(n.resi)+1;e<=parseInt(o);++e){let i=n.structure+"_"+n.chain+"_"+e;l=s.hashUtilsCls.unionHash(l,s.hashUtilsCls.hash2Atoms(t.residues[i],t.atoms))}return l}}class qs{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t){let s=this.icn3d,i=s.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 l(){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 r=this;if("xr"in navigator)return n.id=i.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 i(s){s.addEventListener("end",l),await e.xr.setSession(s),n.textContent="EXIT VR",t=s}function l(){s.transformCls.resetOrientation(),s.bVr=!1,s.drawCls.draw(),t.removeEventListener("end",l),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(s.bImpo=!1,s.bVr=!0,s.drawCls.draw(s.bVr),null===t){const e={optionalFeatures:["local-floor","bounded-floor","hand-tracking","layers"]};navigator.xr.requestSession("immersive-vr",e).then(i)}else t.end()}}():(l(),n.style.display="none"),t&&r.xrSessionIsGranted&&n.click()})).catch((function(e){l(),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 Us{constructor(e){this.icn3d=e,this.xrSessionIsGranted=!1}createButton(e,t={}){let s=this.icn3d,i=s.icn3dui;const n=document.createElement("button");function l(){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 r(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(i.utilsCls.isAndroid()&&i.utilsCls.isChrome()){if("xr"in navigator)return n.id=i.pre+"ARButton",n.style.display="none",r(n),navigator.xr.isSessionSupported("immersive-ar").then((function(i){i?function(){if(void 0===t.domOverlay){const e=document.createElement("div");e.style.display="none",document.body.appendChild(e);const s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("width",38),s.setAttribute("height",38),s.style.position="absolute",s.style.right="20px",s.style.top="20px",s.addEventListener("click",(function(){i.end()})),e.appendChild(s);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),s.appendChild(n),void 0===t.optionalFeatures&&(t.optionalFeatures=[]),t.optionalFeatures.push("dom-overlay"),t.domOverlay={root:e}}let i=null;async function l(s){s.addEventListener("end",r),e.xr.setReferenceSpaceType("local"),await e.xr.setSession(s),n.textContent="STOP AR",t.domOverlay.root.style.display="",i=s}function r(){s.transformCls.resetOrientation(),s.bAr=!1,s.drawCls.draw(),i.removeEventListener("end",r),n.textContent="START AR",t.domOverlay.root.style.display="none",i=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(){s.bImpo=!1,s.opts.background="transparent",s.bAr=!0,s.drawCls.draw(s.bAr),null===i?navigator.xr.requestSession("immersive-ar",t).then(l):i.end()}}():(l(),n.style.display="none")})).catch((function(e){l(),console.warn("Exception when trying to call xr.isSessionSupported",e),n.style.display="none"})),n;return document.createElement("span")}return n.id=i.pre+"ARButton",n.style.display="none",r(n),l(),n.style.display="none",n}}class $s{constructor(e){let t,s,i,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.icn3dui.bNode){let e=document.createElement("canvas");t=!(!window.WebGLRenderingContext||!e.getContext("webgl")&&!e.getContext("experimental-webgl")),e.remove(),e=document.createElement("canvas"),s=!(!window.WebGLRenderingContext||!e.getContext("webgl2")),e.remove(),i="xr"in navigator,t?(s&&i?(this.renderer=new THREE.WebGLRenderer({canvas:this.oriContainer.get(0),antialias:!0,preserveDrawingBuffer:!0,sortObjects:!1,alpha:!0}),this.renderer.xr.enabled=!0):this.renderer=new THREE.WebGL1Renderer({canvas:this.oriContainer.get(0),antialias:!0,preserveDrawingBuffer:!0,sortObjects:!1,alpha:!0}),this.overdraw=0):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 THREE.Color(.1,.1,.1),this.shininess=40,this.emissive=1118481,this.light1=.8,this.light2=.4,this.light3=.2,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||(s&&i?(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.effects={none:this.renderer},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 THREE.Color(16777011),this.sphereGeometry=new THREE.SphereGeometry(1,32,32),this.boxGeometry=new THREE.BoxGeometry(1,1,1),this.cylinderGeometry=new THREE.CylinderGeometry(1,1,1,32,1),this.cylinderGeometryOutline=new THREE.CylinderGeometry(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.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 Ie(this),this.cameraCls=new Ee(this),this.fogCls=new Te(this),this.boxCls=new Pe(this),this.brickCls=new De(this),this.curveStripArrowCls=new Me(this),this.curveCls=new Fe(this),this.cylinderCls=new He(this),this.lineCls=new Le(this),this.reprSubCls=new Ne(this),this.sphereCls=new qe(this),this.stickCls=new Ue(this),this.strandCls=new $e(this),this.stripCls=new Be(this),this.tubeCls=new je(this),this.cartoonNuclCls=new ze(this),this.surfaceCls=new Ze(this),this.labelCls=new Ve(this),this.axesCls=new We(this),this.glycanCls=new Ye(this),this.applyCenterCls=new Qe(this),this.applyClbondsCls=new et(this),this.applyMissingResCls=new tt(this),this.applyDisplayCls=new st(this),this.applyMapCls=new rt(this),this.applyOtherCls=new it(this),this.applySsbondsCls=new nt(this),this.applySymdCls=new lt(this),this.hlObjectsCls=new Ht(this),this.residueLabelsCls=new ot(this),this.alternateCls=new ct(this),this.drawCls=new ht(this),this.firstAtomObjCls=new ys(this),this.impostorCls=new at(this),this.instancingCls=new dt(this),this.contactCls=new pt(this),this.hBondCls=new mt(this),this.piHalogenCls=new ut(this),this.saltbridgeCls=new gt(this),this.loadPDBCls=new ds(this),this.loadCIFCls=new cs(this),this.vastplusCls=new hs(this),this.transformCls=new Ts(this),this.setStyleCls=new ft(this),this.setColorCls=new Ct(this),this.threeDPrintCls=new Ms(this),this.export3DCls=new Fs(this),this.annoCddSiteCls=new vt(this),this.annoContactCls=new _t(this),this.annoPTMCls=new wt(this),this.annoIgCls=new St(this),this.annoCrossLinkCls=new At(this),this.annoDomainCls=new xt(this),this.annoSnpClinVarCls=new kt(this),this.annoSsbondCls=new Ot(this),this.annoTransMemCls=new Rt(this),this.domain3dCls=new It(this),this.addTrackCls=new Et(this),this.annotationCls=new Tt(this),this.showAnnoCls=new Pt(this),this.showSeqCls=new Dt(this),this.hlSeqCls=new Mt(this),this.hlUpdateCls=new Ft(this),this.lineGraphCls=new Lt(this),this.getGraphCls=new Nt(this),this.showInterCls=new qt(this),this.viewInterPairsCls=new Ut(this),this.drawGraphCls=new $t(this),this.contactMapCls=new Bt(this),this.alignParserCls=new jt(this),this.chainalignParserCls=new zt(this),this.dsn6ParserCls=new Gt(this),this.ccp4ParserCls=new Vt(this),this.mtzParserCls=new Xt(this),this.mmcifParserCls=new Kt(this),this.mmdbParserCls=new Jt(this),this.bcifParserCls=new Zt(this),this.mol2ParserCls=new Qt(this),this.opmParserCls=new es(this),this.pdbParserCls=new ts(this),this.sdfParserCls=new ss(this),this.xyzParserCls=new is(this),this.realignParserCls=new ns(this),this.densityCifParserCls=new ls(this),this.ParserUtilsCls=new rs(this),this.loadAtomDataCls=new os(this),this.setSeqAlignCls=new as(this),this.applyCommandCls=new ps(this),this.definedSetsCls=new ms(this),this.selectCollectionsCls=new us(this),this.legendTableCls=new yt(this),this.loadScriptCls=new gs(this),this.selByCommCls=new fs(this),this.selectionCls=new Cs(this),this.resid2specCls=new bs(this),this.delphiCls=new vs(this),this.dsspCls=new _s(this),this.refnumCls=new ws(this),this.scapCls=new Ss(this),this.symdCls=new As(this),this.alignSWCls=new xs(this),this.analysisCls=new ks(this),this.resizeCanvasCls=new Es(this),this.saveFileCls=new Ps(this),this.setOptionCls=new bt(this),this.shareLinkCls=new Ds(this),this.diagram2dCls=new Os(this),this.cartoon2dCls=new Rs(this),this.ligplotCls=new Is(this),this.rayCls=new Hs(this),this.controlCls=new Ls(this),this.pickingCls=new Ns(this),this.VRButtonCls=new qs(this),this.ARButtonCls=new Us(this),this.matShader=this.setColorCls.setOutlineColor("yellow")}}$s.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=[]},$s.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},$s.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},$s.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 s=t.cfg.mmdbafid.split(",");if(s.length>1)e.opts.color="structure";else if(1==s.length){let t=s[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 Bs{constructor(e){this.cfg=e,this.pre=this.cfg.divid+"_",this.REVISION="3.38.1",this.bNode=Object.keys(window).length<2,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.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 t(this),this.utilsCls=new s(this),this.parasCls=new i(this),this.myEventCls=new n(this),this.rmsdSuprCls=new l(this),this.subdivideCls=new r(this),this.convertTypeCls=new o(this),this.htmlCls=new g(this)}allCustomEvents(){}}Bs.prototype.show3DStructure=async function(e){let t=this;t.cfg.menuicon?(t.htmlCls.wifiStr='<i class="icn3d-wifi" title="requires internet">&nbsp;</i>',t.htmlCls.licenseStr='<i class="icn3d-license" title="requires license">&nbsp;</i>'):(t.htmlCls.wifiStr="",t.htmlCls.licenseStr=""),t.setIcn3d();let s=t.icn3d;t.utilsCls.isSessionStorageSupported()&&s.setStyleCls.getCommandsBeforeCrash();let i=t.htmlCls.WIDTH,n=t.htmlCls.HEIGHT;t.oriWidth=i,t.oriHeight=n,t.htmlCls.eventsCls.allEventFunctions(),this.allCustomEvents();let l=0;if((null==t.cfg.showmenu||t.cfg.showmenu)&&(l+=t.htmlCls.MENU_HEIGHT),(null==t.cfg.showcommand||t.cfg.showcommand)&&(l+=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?$("#"+s.pre+"title").hide():$("#"+s.pre+"title").show(),$("#"+s.pre+"viewer").width(i).height(parseInt(n)+l),$("#"+s.pre+"canvas").width(i).height(parseInt(n)),$("#"+s.pre+"canvas").resizable({resize:function(e,i){t.htmlCls.WIDTH=i.size.width,t.htmlCls.HEIGHT=i.size.height,void 0===s||t.icn3d.bFullscreen||s.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?(s.bReplay=1,$("#"+s.pre+"replay").show()):(s.bReplay=0,$("#"+s.pre+"replay").hide()),t.utilsCls.isMobile()&&(s.threshbox=60),t.cfg.controlGl&&(s.bControlGl=!0,s.container=s.bControlGl&&!t.bNode?$(document):$("#"+s.id)),s.setStyleCls.handleContextLost(),s.applyCenterCls.setWidthHeight(i,n),s.ori_chemicalbinding=s.opts.chemicalbinding,s.opts=t.hashUtilsCls.cloneHash(s.opts),s.STATENUMBER=s.commands.length,t.utilsCls.isSessionStorageSupported()&&s.bCrashed){s.bCrashed=!1;let e=s.commandsBeforeCrash.split("|||")[0],i=e.substr(e.lastIndexOf(" ")+1);if(i===t.cfg.bcifid||i===t.cfg.mmtfid||i===t.cfg.pdbid||i===t.cfg.opmid||i===t.cfg.mmdbid||i===t.cfg.gi||i===t.cfg.blast_rep_id||i===t.cfg.cid||i===t.cfg.mmcifid||i===t.cfg.align||i===t.cfg.chainalign||i===t.cfg.mmdbafid)return void await s.loadScriptCls.loadScript(s.commandsBeforeCrash,!0)}if(s.molTitle="",s.loadCmd,t.htmlCls.clickMenuCls.getHiddenMenusFromCache(),t.htmlCls.clickMenuCls.applyShownMenus(),e){if(s.init(),s.bInputfile=!0,s.InputfileType="pdb",s.InputfileData=s.InputfileData?s.InputfileData+"\nENDMDL\n"+e:e,await s.pdbParserCls.loadPdbData(e),void 0!==t.cfg.resdef&&void 0!==t.cfg.chains){let e=Object.keys(s.structures),i=t.cfg.chains.split(" | "),n=[];if(e.length==i.length){for(let t=0,s=e.length;t<s;++t)n.push(e[t]+"_"+i[t]);n=s.chainalignParserCls.addPostfixForChainids(n);let t=!0,l=!0;await s.realignParserCls.realignChainOnSeqAlign(void 0,n,t,l)}}else if(void 0!==t.cfg.matchedchains){let e=Object.keys(s.structures)[0]+"_"+t.cfg.masterchain,i=t.cfg.matchedchains.split(","),n=[];for(let e=0,t=i.length;e<t;++e){let t=i[e].lastIndexOf("_"),s=i[e].substr(t+1);isNaN(s)?n.push(i[e]):n.push(i[e].substr(0,t))}let l="";for(let e=0,t=n.length;e<t;++e)e>0&&(l+=","),l+=n[e].substr(0,n[e].indexOf("_"));s.chainidArray=[e].concat(n),s.chainidArray=s.chainalignParserCls.addPostfixForChainids(s.chainidArray),s.loadCmd="vast_search_chainid "+s.chainidArray,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),s.bMmdbafid=!0;let r=!0;await s.chainalignParserCls.downloadMmdbAf(l,r)}}else if(void 0!==t.cfg.url){s.bInputUrlfile=!0;let e=t.cfg.url.split("|"),i=e[0],n=e[1];s.molTitle="",s.inputid=n,s.inputurl="type="+i+"&url="+encodeURIComponent(n),s.loadCmd="load url "+n+" | type "+i,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.pdbParserCls.downloadUrl(n,i,t.cfg.command)}else if(void 0!==t.cfg.mmtfid)s.inputid=t.cfg.mmtfid,s.loadCmd="load mmtf "+t.cfg.mmtfid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.bcifParserCls.downloadBcif(t.cfg.mmtfid);else if(void 0!==t.cfg.bcifid)s.inputid=t.cfg.bcifid,s.loadCmd="load bcif "+t.cfg.bcifid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.bcifParserCls.downloadBcif(t.cfg.bcifid);else if(void 0!==t.cfg.pdbid)s.inputid=t.cfg.pdbid,s.loadCmd="load pdb "+t.cfg.pdbid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.pdbParserCls.downloadPdb(t.cfg.pdbid);else if(void 0!==t.cfg.afid){s.inputid=t.cfg.afid,s.loadCmd="load af "+t.cfg.afid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0);let e=!0;await s.pdbParserCls.downloadPdb(t.cfg.afid,e)}else if(void 0!==t.cfg.opmid)s.inputid=t.cfg.opmid,s.loadCmd="load opm "+t.cfg.opmid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.opmParserCls.downloadOpm(t.cfg.opmid);else if(void 0!==t.cfg.mmdbid)s.inputid=t.cfg.mmdbid,s.loadCmd="load mmdb "+t.cfg.mmdbid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadMmdb(t.cfg.mmdbid);else if(void 0!==t.cfg.gi)s.loadCmd="load gi "+t.cfg.gi,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadGi(t.cfg.gi);else if(void 0!==t.cfg.refseqid)s.inputid=t.cfg.refseqid,s.loadCmd="load refseq "+t.cfg.refseqid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadRefseq(t.cfg.refseqid);else if(void 0!==t.cfg.protein)s.inputid=t.cfg.protein,s.loadCmd="load protein "+t.cfg.protein,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmdbParserCls.downloadProteinname(t.cfg.protein);else if(void 0!==t.cfg.blast_rep_id)if(s.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?(s.loadCmd="load seq_struct_ids_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,s.bSmithwm=!0):"local_smithwm"==t.cfg.alg?(s.loadCmd="load seq_struct_ids_local_smithwm "+t.cfg.query_id+","+t.cfg.blast_rep_id,s.bLocalSmithwm=!0):(s.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,s.bSmithwm=!1,s.bLocalSmithwm=!1),t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.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,i=await t.getAjaxPromise(e,"json",!1,"The RID "+t.cfg.rid+" may have expired...");for(let e=0,n=i.BlastOutput2.length;e<n;++e){let n,l;if(i.BlastOutput2[e].report.results.iterations){let s=i.BlastOutput2[e].report.results.iterations.length;if(i.BlastOutput2[e].report.results.iterations[s-1].search.query_id!=t.cfg.query_id)continue;n=i.BlastOutput2[e].report.results.iterations[s-1].search.hits}else{if(i.BlastOutput2[e].report.results.search.query_id!=t.cfg.query_id)continue;n=i.BlastOutput2[e].report.results.search.hits}for(let e=0,s=n.length;e<s;++e){let s=n[e],i=!1;for(let e=0,n=s.description.length;e<n;++e){if(s.description[e].accession==t.cfg.blast_rep_id){i=!0;break}}if(i){l=s.hsps[0].qseq,l=l.replace(/-/g,"");break}}void 0!==l&&(t.cfg.query_id=l),s.inputid=t.cfg.query_id+"_"+t.cfg.blast_rep_id,s.loadCmd="load seq_struct_ids "+t.cfg.query_id+","+t.cfg.blast_rep_id,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.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,s=await t.getAjaxPromise(e,"jsonp");if(!s.cid||!s.cid[0])return void alert("Please input an valid PubChem CID...");t.cfg.cid=s.cid[0]}s.inputid=t.cfg.cid;let e="https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+s.inputid+"/description/jsonp",i=await t.getAjaxPromise(e,"jsonp",!1);void 0!==i.InformationList&&void 0!==i.InformationList.Information&&(s.molTitle=i.InformationList.Information[0].Title),s.loadCmd="load cid "+t.cfg.cid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.sdfParserCls.downloadCid(t.cfg.cid)}else if(void 0!==t.cfg.smiles)s.inputid=t.cfg.smiles,s.loadCmd="load smiles "+t.cfg.smiles,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.sdfParserCls.downloadSmiles(t.cfg.smiles);else if(void 0!==t.cfg.mmcifid)s.inputid=t.cfg.mmcifid,s.loadCmd="load mmcif "+t.cfg.mmcifid,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.mmcifParserCls.downloadMmcif(t.cfg.mmcifid);else if(void 0!==t.cfg.align){let e=t.cfg.align.split(",");if(6===e.length?s.inputid=e[0]+"_"+e[3]:2===e.length&&(s.inputid=e[0]+"_"+e[1]),s.loadCmd="load alignment "+t.cfg.align+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),t.cfg.inpara&&-1==t.cfg.inpara.indexOf("atype=2"))await s.alignParserCls.downloadAlignment(t.cfg.align);else{let e=2;await s.chainalignParserCls.downloadMmdbAf(t.cfg.align,void 0,e)}}else if(void 0!==t.cfg.chainalign){s.bChainAlign=!0,s.inputid=t.cfg.chainalign;let e=t.cfg.resrange?" | resrange "+t.cfg.resrange:"",i=t.cfg.resdef?t.cfg.resdef:"";s.loadCmd="load chainalignment "+t.cfg.chainalign+" | resnum "+t.cfg.resnum+" | resdef "+i+" | aligntool "+t.cfg.aligntool+" | parameters "+t.cfg.inpara+e,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.chainalignParserCls.downloadChainalignment(t.cfg.chainalign)}else if(void 0!==t.cfg.mmdbafid)t.cfg.mmdbafid=t.cfg.mmdbafid.replace(/\s+/g,"").toUpperCase(),s.bMmdbafid=!0,s.inputid=t.cfg.mmdbafid,1==t.cfg.bu?s.loadCmd="load mmdbaf1 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara:s.loadCmd="load mmdbaf0 "+t.cfg.mmdbafid+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.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=")&&(s.bInputUrlfile=!0)}await s.loadScriptCls.loadScript(t.cfg.command,void 0,!0)},Bs.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&#13;Right(\"Selection\"): Style and color menu options will be applied only to selected atoms'></div></label>",s="<span id='"+e.pre+"modeall' title='Style and color menu options will be applied to all atoms in the structure'>All atoms&nbsp;&nbsp;</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&nbsp;&nbsp;</span></div></div></td>";e.utilsCls.setViewerWidthHeight(e),e.utilsCls.isMobile()||e.cfg.mobilemenu?e.htmlCls.setMenuCls.setTopMenusHtmlMobile(e.cfg.divid,t,s):e.htmlCls.setMenuCls.setTopMenusHtml(e.cfg.divid,t,s),e.icn3d=new $s(e),e.icn3d.controlCls.setControl(),e.setDialogAjax()},Bs.prototype.getMmtfPromise=function(e){return new Promise((function(t,s){MMTF.fetch(e,(async function(e){t(e)}),(function(e){s("error")}))}))},Bs.prototype.getMmtfReducedPromise=function(e){return new Promise((function(t,s){MMTF.fetchReduced(e,(async function(e){t(e)}),(function(e){s("error")}))}))},Bs.prototype.getXMLHttpRqstPromise=function(e,t,s,i){let n=this;return new Promise((function(l,r){let o=new XMLHttpRequest;o.open(t,e,!0),o.responseType=s,o.onreadystatechange=function(){if(4==this.readyState)if(200==this.status){let e=o.response;l(e)}else"2fofc"==i||"fofc"==i?alert("Density server at EBI has no corresponding electron density map for this structure."):"em"==i?alert("Density server at EBI has no corresponding EM density map for this structure."):"rcsbEdmaps"==i?alert("RCSB server has no corresponding electron density map for this structure."):alert("The "+i+" file is unavailable..."),r("error");else n.icn3d.ParserUtilsCls.showLoading()},o.send()}))},Bs.prototype.getAjaxPromise=function(e,t,s,i,n,l,r){let o=this;return new Promise((function(r,a){$.ajax({url:e,dataType:t,cache:!0,beforeSend:function(){s&&o.icn3d.ParserUtilsCls.showLoading()},complete:function(){l&&o.icn3d.ParserUtilsCls.hideLoading()},success:function(e){r(e)},error:function(){i&&alert(i),n&&console.log(n),a("error")}})}))},Bs.prototype.getAjaxPostPromise=async function(e,t,s,i,n,l,r,o){let a=this;return r=r||"json",new Promise((function(o,d){$.ajax({url:e,type:"POST",data:t,dataType:r,cache:!0,beforeSend:function(){s&&a.icn3d.ParserUtilsCls.showLoading()},complete:function(){l&&a.icn3d.ParserUtilsCls.hideLoading()},success:function(e){o(e)},error:function(){!a.bNode&&i&&console.log(i),!a.bNode&&n&&console.log(n),o("error")}})}))},Bs.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,s){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,s){let i=new XMLHttpRequest,n=e.url,l=e.type,r=e.async||!0,o=e.responseType||"blob",a=e.data||null;i.addEventListener("load",(function(){let t={};t[e.dataType]=i.response,s(i.status,i.statusText,t,i.getAllResponseHeaders())})),i.open(l,n,r);for(let e in t)i.setRequestHeader(e,t[e]);i.responseType=o,i.send(a)},abort:function(){s.abort()}}}))};return e.ARButton=Us,e.AddTrack=Et,e.AlignParser=jt,e.AlignSW=xs,e.AlignSeq=m,e.Alternate=ct,e.Analysis=ks,e.AnnoCddSite=vt,e.AnnoContact=_t,e.AnnoCrossLink=At,e.AnnoDomain=xt,e.AnnoSnpClinVar=kt,e.AnnoSsbond=Ot,e.AnnoTransMem=Rt,e.Annotation=Tt,e.ApplyCenter=Qe,e.ApplyClbonds=et,e.ApplyCommand=ps,e.ApplyDisplay=st,e.ApplyMap=rt,e.ApplyOther=it,e.ApplySsbonds=nt,e.ApplySymd=lt,e.Axes=We,e.Box=Pe,e.Brick=De,e.Camera=Ee,e.CartoonNucl=ze,e.ChainalignParser=zt,e.ClickMenu=a,e.Contact=pt,e.Control=Ls,e.ConvertTypeCls=o,e.Curve=Fe,e.CurveStripArrow=Me,e.Cylinder=He,e.DefinedSets=ms,e.Delphi=vs,e.DensityCifParser=ls,e.Diagram2d=Os,e.Dialog=c,e.Domain3d=It,e.Draw=ht,e.DrawGraph=$t,e.Dsn6Parser=Gt,e.Dssp=_s,e.ElectronMap=Je,e.Events=p,e.Export3D=Fs,e.FirstAtomObj=ys,e.Fog=Te,e.GetGraph=Nt,e.Glycan=Ye,e.HBond=mt,e.HashUtilsCls=t,e.HlObjects=Ht,e.HlSeq=Mt,e.HlUpdate=Ft,e.Html=g,e.Impostor=at,e.Instancing=dt,e.Label=Ve,e.Line=Le,e.LineGraph=Lt,e.LoadAtomData=os,e.LoadCIF=cs,e.LoadPDB=ds,e.LoadScript=gs,e.MarchingCube=Xe,e.MmcifParser=Kt,e.MmdbParser=Jt,e.Mol2Parser=Qt,e.MyEventCls=n,e.OpmParser=es,e.ParasCls=i,e.ParserUtils=rs,e.PdbParser=ts,e.PiHalogen=ut,e.Picking=Ns,e.ProteinSurface=Ke,e.Ray=Hs,e.RealignParser=ns,e.Refnum=ws,e.ReprSub=Ne,e.Resid2spec=bs,e.ResidueLabels=ot,e.ResizeCanvas=Es,e.RmsdSuprCls=l,e.Saltbridge=gt,e.SaveFile=Ps,e.Scap=Ss,e.Scene=Ie,e.SdfParser=ss,e.SelectByCommand=fs,e.Selection=Cs,e.SetColor=Ct,e.SetDialog=h,e.SetHtml=u,e.SetMenu=d,e.SetOption=bt,e.SetSeqAlign=as,e.SetStyle=ft,e.ShareLink=Ds,e.ShowAnno=Pt,e.ShowInter=qt,e.ShowSeq=Dt,e.Sphere=qe,e.Stick=Ue,e.Strand=$e,e.Strip=Be,e.SubdivideCls=r,e.Surface=Ze,e.Symd=As,e.ThreeDPrint=Ms,e.Transform=Ts,e.Tube=je,e.UtilsCls=s,e.VRButton=qs,e.Vastplus=hs,e.ViewInterPairs=Ut,e.XyzParser=is,e.iCn3D=$s,e.iCn3DUI=Bs,e.printMsg=class{constructor(){console.log("This is a message from the icn3d package")}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});