icn3d 3.31.11 → 3.31.12

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
@@ -10,4 +10,4 @@ t+=this.getLink("mn6_customref","Custom Ref. Number",void 0,2),t+="</ul>",t+="</
10
10
  t+="<td></td>",t+="</tr></table></div></div>",t}}class p{constructor(e){this.icn3dui=e}setLogCmd(e,t,s){var i=this.icn3dui;i.icn3d,i.htmlCls.clickMenuCls.setLogCmd(e,t,s)}fullScreenChange(){let e=this.icn3dui,t=e.icn3d,s=this;e.bNode||document.fullscreenElement||document.webkitFullscreenElement||document.mozFullscreenElement||document.msFullscreenElement||(s.setLogCmd("exit full screen",!1),t.bFullscreen=!1,e.utilsCls.setViewerWidthHeight(e,!0),t.applyCenterCls.setWidthHeight(e.htmlCls.WIDTH,e.htmlCls.HEIGHT),t.drawCls.draw())}convertUniProtInChains(e){this.icn3dui.icn3d;let t=e.split(","),s="";for(let e=0,i=t.length;e<i;++e)s+=-1!=t[e].indexOf("_")?t[e]:t[e]+"_A",e<i-1&&(s+=",");return s}async searchSeq(){let e=this.icn3dui,t=e.icn3d,s=$("#"+e.pre+"search_seq").val();isNaN(s)&&-1==s.indexOf("$")&&-1==s.indexOf(".")&&-1==s.indexOf(":")&&-1==s.indexOf("@")&&(s=":"+s);let i=s.replace(/\s+/g,"_"),n=i;await t.selByCommCls.selectByCommand(s,i,n),this.setLogCmd("select "+s+" | name "+i,!0)}async setRealign(e,t){let s=this.icn3dui,i=s.icn3d,n=this,l=$("#"+s.pre+"atomsCustomRealignByStruct").val();l.length>0&&(i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(l)),s.cfg.aligntool=e;let r="vast"==e?"structure align":"tmalign";if(r+=t?" msa":"",l.length>0?n.setLogCmd("realign on "+r+" | "+l,!0):n.setLogCmd("realign on "+r,!0),t){if(0==l.length){l=[];let e={};for(let t in i.chains){let s=i.firstAtomObjCls.getFirstAtomObj(i.chains[t]);e.hasOwnProperty(s.structure)||!i.proteins.hasOwnProperty(s.serial)&&!i.nucleotides.hasOwnProperty(s.serial)||(l.push(t),e[s.structure]=1)}}await i.realignParserCls.realignOnStructAlignMsa(l)}else await i.realignParserCls.realignOnStructAlign()}async readFile(e,t,s,i){let n=this.icn3dui.icn3d,l=this,r=t[s],o=e?"append":"load",a=new FileReader;a.onload=async function(a){let d=a.target.result;l.setLogCmd(o+" pdb file "+r.name,!1),e?(n.resetConfig(),n.bResetAnno=!0,n.bResetSets=!0):n.init(),n.bInputfile=!0,n.InputfileType="pdb",n.InputfileData=n.InputfileData?n.InputfileData+"\nENDMDL\n"+d:d,i=s>0?i+"\nENDMDL\n"+d:d,Object.keys(t).length==s+1?(e&&(n.hAtoms={},n.dAtoms={}),await n.pdbParserCls.loadPdbData(i,void 0,void 0,e)):await l.readFile(e,t,s+1,i),e&&(n.bSetChainsAdvancedMenu&&n.definedSetsCls.showSets(),n.bResetAnno=!0,n.bAnnoShown&&(await n.showAnnoCls.showAnnotations(),n.annotationCls.resetAnnoTabAll()))},"object"==typeof r&&a.readAsText(r)}async loadPdbFile(e){let t=this.icn3dui,s=t.icn3d,i=e?"pdbfile_app":"pdbfile";s.bInitial=!0,t.cfg.notebook||dialog.dialog("close"),t.cfg.notebook?s.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let n=$("#"+t.pre+i)[0].files;n[0]?(t.htmlCls.setHtmlCls.fileSupport(),s.molTitle="",s.dataStrAll="",await this.readFile(e,n,0,"")):alert("Please select a file before clicking 'Load'")}saveHtml(e){let t=this.icn3dui.icn3d,s="";s+='<link rel="stylesheet" href="https:///structure.ncbi.nlm.nih.gov/icn3d/lib/jquery-ui-1.13.2.min.css">\n',s+='<link rel="stylesheet" href="https:///structure.ncbi.nlm.nih.gov/icn3d/icn3d_full_ui.css">\n',s+=$("#"+e).html();let i=e.split("_"),n=i.length>2?i[2]:e,l=Object.keys(t.structures)[0];Object.keys(t.structures).length>1&&(l+="-"+Object.keys(t.structures)[1]),t.saveFileCls.saveFile(l+"-"+n+".html","html",encodeURIComponent(s))}setPredefinedMenu(e){let t=this.icn3dui,s=t.icn3d;if(Object.keys(s.chains).length<2)return void alert("At least two chains are required for alignment...");t.htmlCls.clickMenuCls.SetChainsAdvancedMenu();let i=s.definedSetsCls.setAtomMenu(["protein"]);$("#"+t.pre+e).length&&$("#"+t.pre+e).html(i),$("#"+t.pre+e).resizable()}async launchMmdb(e,t,s,i){let n=this.icn3dui,l=n.icn3d,r=this;n.cfg.notebook||dialog.dialog("close");let o=t?1:0;if(!(e=e.replace(/,/g," ").replace(/\s+/g,",").trim()))return void alert("Please enter a list of PDB IDs or AlphaFold UniProt IDs...");let a=e.split(",");if(i)if(l.structures||1!=a.length||4!=a[0].length&&isNaN(a[0])){n.cfg.mmdbafid=e,n.cfg.bu=o,l.bMmdbafid=!0,l.inputid=l.inputid?l.inputid+n.cfg.mmdbafid:n.cfg.mmdbafid,1==n.cfg.bu?l.loadCmd="load mmdbaf1 "+n.cfg.mmdbafid:l.loadCmd="load mmdbaf0 "+n.cfg.mmdbafid,n.htmlCls.clickMenuCls.setLogCmd(l.loadCmd,!0);let t=!!(l.structures&&Object.keys(l.structures).length>0);await l.chainalignParserCls.downloadMmdbAf(n.cfg.mmdbafid),t&&(l.bSetChainsAdvancedMenu&&l.definedSetsCls.showSets(),l.bAnnoShown&&(await l.showAnnoCls.showAnnotations(),l.annotationCls.resetAnnoTabAll()))}else{r.setLogCmd("load mmdb"+o+" "+e,!1);let t=l.structures&&Object.keys(l.structures).length>0?"_blank":"_self";window.open(s+"?mmdbid="+e+"&bu="+o,t)}else if(1!=a.length||4!=a[0].length&&isNaN(a[0])){r.setLogCmd("load mmdbaf"+o+" "+e,!1);let t=l.structures&&Object.keys(l.structures).length>0?"_blank":"_self";window.open(s+"?mmdbafid="+e+"&bu="+o,t)}else{r.setLogCmd("load mmdb"+o+" "+e,!1);let t=l.structures&&Object.keys(l.structures).length>0?"_blank":"_self";window.open(s+"?mmdbid="+e+"&bu="+o,t)}}allEventFunctions(){let e=this.icn3dui,t=e.icn3d,s=this;if(e.bNode)return;let i=document.URL,n=i.indexOf("?");i=-1==n?i:i.substr(0,n),"https://www.ncbi.nlm.nih.gov/Structure/vast/icn3d/"==i&&(i="https://www.ncbi.nlm.nih.gov/Structure/icn3d/"),t.definedSetsCls.clickCustomAtoms(),t.definedSetsCls.clickCommand_apply(),t.definedSetsCls.clickModeswitch(),t.selectionCls.clickShow_selected(),t.selectionCls.clickHide_selected(),t.diagram2dCls.click2Ddgm(),t.cartoon2dCls.click2Dcartoon(),t.addTrackCls.clickAddTrackButton(),t.resizeCanvasCls.windowResize(),t.annotationCls.setTabs(),t.resid2specCls.switchHighlightLevel(),e.utilsCls.isMobile()?(t.hlSeqCls.selectSequenceMobile(),t.hlSeqCls.selectChainMobile()):t.hlSeqCls.selectSequenceNonMobile(),e.htmlCls.clickMenuCls.clickMenu1(),e.htmlCls.clickMenuCls.clickMenu2(),e.htmlCls.clickMenuCls.clickMenu3(),e.htmlCls.clickMenuCls.clickMenu4(),e.htmlCls.clickMenuCls.clickMenu5(),e.htmlCls.clickMenuCls.clickMenu6(),e.myEventCls.onIds(["#"+e.pre+"back","#"+e.pre+"mn6_back"],"click",(async function(t){let i=e.icn3d;t.preventDefault(),s.setLogCmd("back",!1),await i.resizeCanvasCls.back()})),e.myEventCls.onIds(["#"+e.pre+"forward","#"+e.pre+"mn6_forward"],"click",(async function(t){let i=e.icn3d;t.preventDefault(),s.setLogCmd("forward",!1),await i.resizeCanvasCls.forward()})),e.myEventCls.onIds(["#"+e.pre+"fullscreen","#"+e.pre+"mn6_fullscreen"],"click",(function(t){let i=e.icn3d;t.preventDefault(),s.setLogCmd("enter full screen",!1),i.bFullscreen=!0,e.htmlCls.WIDTH=$(window).width(),e.htmlCls.HEIGHT=$(window).height(),i.applyCenterCls.setWidthHeight(e.htmlCls.WIDTH,e.htmlCls.HEIGHT),i.drawCls.draw(),i.resizeCanvasCls.openFullscreen($("#"+e.pre+"canvas")[0])})),document.addEventListener("fullscreenchange",this.fullScreenChange.bind(this)),document.addEventListener("webkitfullscreenchange",this.fullScreenChange.bind(this)),document.addEventListener("mozfullscreenchange",this.fullScreenChange.bind(this)),document.addEventListener("msfullscreenchange",this.fullScreenChange.bind(this)),e.myEventCls.onIds(["#"+e.pre+"toggle","#"+e.pre+"mn2_toggle"],"click",(function(t){e.icn3d.selectionCls.toggleSelection(),s.setLogCmd("toggle selection",!0)})),e.myEventCls.onIds("#"+e.pre+"mn2_hl_clrYellow","click",(function(t){let i=e.icn3d;s.setLogCmd("set highlight color yellow",!0),i.hColor=e.parasCls.thr(16776960),i.matShader=i.setColorCls.setOutlineColor("yellow"),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"mn2_hl_clrGreen","click",(function(t){let i=e.icn3d;s.setLogCmd("set highlight color green",!0),i.hColor=e.parasCls.thr(65280),i.matShader=i.setColorCls.setOutlineColor("green"),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"mn2_hl_clrRed","click",(function(t){let i=e.icn3d;s.setLogCmd("set highlight color red",!0),i.hColor=e.parasCls.thr(16711680),i.matShader=i.setColorCls.setOutlineColor("red"),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"mn2_hl_styleOutline","click",(function(t){let i=e.icn3d;s.setLogCmd("set highlight style outline",!0),i.bHighlight=1,i.hlUpdateCls.showHighlight()})),e.myEventCls.onIds("#"+e.pre+"mn2_hl_styleObject","click",(function(t){let i=e.icn3d;s.setLogCmd("set highlight style 3d",!0),i.bHighlight=2,i.hlUpdateCls.showHighlight()})),e.myEventCls.onIds("#"+e.pre+"mn2_hl_styleNone","click",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),i.hlUpdateCls.clearHighlight(),s.setLogCmd("clear selection",!0)})),e.myEventCls.onIds(["#"+e.pre+"alternate","#"+e.pre+"mn2_alternate","#"+e.pre+"alternate2"],"click",(async function(t){let i=e.icn3d;i.bAlternate=!0,await i.alternateCls.alternateStructures(),i.bAlternate=!1,s.setLogCmd("alternate structures",!1)})),e.myEventCls.onIds("#"+e.pre+"mn2_realignresbyres","click",(function(t){e.icn3d,e.htmlCls.dialogCls.openDlg("dl_realignresbyres","Align multiple chains residue by residue")})),e.myEventCls.onIds("#"+e.pre+"realignSelection","click",(function(t){let i=e.icn3d;Object.keys(i.chains).length<2?alert("At least two chains are required for alignment..."):(i.realignParserCls.realign(),s.setLogCmd("realign",!0))})),e.myEventCls.onIds("#"+e.pre+"mn2_realignonseqalign","click",(function(t){e.icn3d.bRender&&e.htmlCls.dialogCls.openDlg("dl_realign","Please select chains to realign"),s.setPredefinedMenu("atomsCustomRealign")})),e.myEventCls.onIds("#"+e.pre+"mn2_realignonstruct","click",(function(t){e.icn3d.bRender&&e.htmlCls.dialogCls.openDlg("dl_realignbystruct","Please select chains to realign"),s.setPredefinedMenu("atomsCustomRealignByStruct")})),e.myEventCls.onIds("#"+e.pre+"mn2_realigntwostru","click",(function(t){e.icn3d.bRender&&e.htmlCls.dialogCls.openDlg("dl_realigntwostru","Please select structures to realign"),s.setPredefinedMenu("atomsCustomRealignByStruct2")})),e.myEventCls.onIds("#"+e.pre+"applyRealign","click",(async function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"atomsCustomRealign").val();n.length>0&&(i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(n)),await i.realignParserCls.realignOnSeqAlign(),n.length>0?s.setLogCmd("realign on seq align | "+n,!0):s.setLogCmd("realign on seq align",!0)})),e.myEventCls.onIds("#"+e.pre+"applyRealignByStruct","click",(async function(t){e.icn3d,t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.setRealign("vast",!1)})),e.myEventCls.onIds("#"+e.pre+"applyRealignByStruct_tmalign","click",(async function(t){e.icn3d,t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.setRealign("tmalign",!1)})),e.myEventCls.onIds("#"+e.pre+"applyRealignByStructMsa","click",(async function(t){e.icn3d,t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.setRealign("vast",!0)})),e.myEventCls.onIds("#"+e.pre+"applyRealignByStructMsa_tmalign","click",(async function(t){e.icn3d,t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.setRealign("tmalign",!0)})),e.myEventCls.onIds("#"+e.pre+"applyRealignByStruct_vastplus","click",(async function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"atomsCustomRealignByStruct2").val();n.length>0&&(i.hAtoms=i.definedSetsCls.getAtomsFromNameArray(n)),await i.vastplusCls.realignOnVastplus(),n.length>0?s.setLogCmd("realign on vastplus | "+n,!0):s.setLogCmd("realign on vastplus",!0)})),e.myEventCls.onIds("#"+e.pre+"applyColorSpectrumAcrossSets","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"atomsCustomColorSpectrumAcross").val();if(0==n.length)return void alert("Please select some sets");i.setColorCls.setColorAcrossSets(n,!0),s.setLogCmd("set color spectrum | "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"applyColorSpectrumBySets","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"atomsCustomColorSpectrum").val();if(0==n.length)return void alert("Please select some sets");i.setColorCls.setColorBySets(n,!0),s.setLogCmd("set residues color spectrum | "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"applyColorRainbowAcrossSets","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"atomsCustomColorRainbowAcross").val();if(0==n.length)return void alert("Please select some sets");i.setColorCls.setColorAcrossSets(n,!1),s.setLogCmd("set color rainbow | "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"applyColorRainbowBySets","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"atomsCustomColorRainbow").val();if(0==n.length)return void alert("Please select some sets");i.setColorCls.setColorBySets(n,!1),s.setLogCmd("set residues color rainbow | "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"anno_summary","click",(function(t){let i=e.icn3d;t.preventDefault(),i.annotationCls.setAnnoViewAndDisplay("overview"),s.setLogCmd("set view overview",!0)})),e.myEventCls.onIds("#"+e.pre+"anno_details","click",(function(t){let i=e.icn3d;t.preventDefault(),i.annotationCls.setAnnoViewAndDisplay("detailed view"),s.setLogCmd("set view detailed view",!0)})),e.myEventCls.onIds("#"+e.pre+"show_annotations","click",(async function(t){let i=e.icn3d;await i.showAnnoCls.showAnnotations(),s.setLogCmd("view annotations",!0)})),e.myEventCls.onIds("#"+e.pre+"showallchains","click",(function(t){e.icn3d.annotationCls.showAnnoAllChains(),s.setLogCmd("show annotations all chains",!0)})),e.myEventCls.onIds("#"+e.pre+"show_alignsequences","click",(function(t){e.icn3d,e.htmlCls.dialogCls.openDlg("dl_alignment","Select residues in aligned sequences")})),e.myEventCls.onIds(["#"+e.pre+"show_2ddgm","#"+e.pre+"mn2_2ddgm"],"click",(async function(t){let i=e.icn3d;e.htmlCls.dialogCls.openDlg("dl_2ddgm","2D Diagram"),await i.viewInterPairsCls.retrieveInteractionData(),s.setLogCmd("view interactions",!0)})),e.myEventCls.onIds("#"+e.pre+"search_seq_button","click",(async function(t){e.icn3d,t.stopImmediatePropagation(),await s.searchSeq()})),e.myEventCls.onIds("#"+e.pre+"search_seq","keyup",(async function(t){e.icn3d,13===t.keyCode&&(t.preventDefault(),await s.searchSeq())})),e.myEventCls.onIds("#"+e.pre+"reload_vastplus","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("vast+ search "+$("#"+e.pre+"vastpluspdbid").val(),!1);let n=i.structures&&Object.keys(i.structures).length>0?"_blank":"_self";window.open("https://www.ncbi.nlm.nih.gov/Structure/vastplus/vastplus.cgi?uid="+$("#"+e.pre+"vastpluspdbid").val(),n)})),e.myEventCls.onIds("#"+e.pre+"reload_vast","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("vast search "+$("#"+e.pre+"vastpdbid").val()+"_"+$("#"+e.pre+"vastchainid").val(),!1);let n=i.structures&&Object.keys(i.structures).length>0?"_blank":"_self";window.open("https://www.ncbi.nlm.nih.gov/Structure/vast/vastsrv.cgi?pdbid="+$("#"+e.pre+"vastpdbid").val()+"&chain="+$("#"+e.pre+"vastchainid").val(),n)})),e.myEventCls.onIds("#"+e.pre+"reload_foldseek","click",(function(t){e.icn3d,t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"foldseekchainids").val(),l=s.convertUniProtInChains(n);s.setLogCmd("load chainalignment "+l,!0),window.open(i+"?chainalign="+l+"&aligntool=tmalign&showalignseq=1&bu=0","_self")})),e.myEventCls.onIds("#"+e.pre+"reload_mmtf","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load bcif "+$("#"+e.pre+"mmtfid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?bcifid="+$("#"+e.pre+"mmtfid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"mmtfid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load mmtf "+$("#"+e.pre+"mmtfid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?mmtfid="+$("#"+e.pre+"mmtfid").val(),l)}})),e.myEventCls.onIds("#"+e.pre+"reload_pdb","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load pdb "+$("#"+e.pre+"pdbid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?pdbid="+$("#"+e.pre+"pdbid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"translate_pdb","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"translateX").val(),l=$("#"+e.pre+"translateY").val(),r=$("#"+e.pre+"translateZ").val();i.transformCls.translateCoord(i.hAtoms,parseFloat(n),parseFloat(l),parseFloat(r)),i.drawCls.draw(),s.setLogCmd("translate pdb "+n+" "+l+" "+r,!0)})),e.myEventCls.onIds("#"+e.pre+"matrix_pdb","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=[];for(let t=0;t<16;++t)n.push(parseFloat($("#"+e.pre+"matrix"+t).val()));i.transformCls.rotateCoord(i.hAtoms,n),i.drawCls.draw(),s.setLogCmd("rotate pdb "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"pdbid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load pdb "+$("#"+e.pre+"pdbid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?pdbid="+$("#"+e.pre+"pdbid").val(),l)}})),e.myEventCls.onIds("#"+e.pre+"reload_af","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load af "+$("#"+e.pre+"afid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?afid="+$("#"+e.pre+"afid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"reload_afmap","click",(async function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=e.cfg.afid?e.cfg.afid:$("#"+e.pre+"afid").val();s.setLogCmd("set half pae map "+n,!0),await i.contactMapCls.afErrorMap(n)})),e.myEventCls.onIds("#"+e.pre+"reload_afmapfull","click",(async function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=e.cfg.afid?e.cfg.afid:$("#"+e.pre+"afid").val();s.setLogCmd("set full pae map "+n,!0),await i.contactMapCls.afErrorMap(n,!0)})),e.myEventCls.onIds("#"+e.pre+"afid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load af "+$("#"+e.pre+"afid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?afid="+$("#"+e.pre+"afid").val(),l)}})),e.myEventCls.onIds("#"+e.pre+"reload_opm","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load opm "+$("#"+e.pre+"opmid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?opmid="+$("#"+e.pre+"opmid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"opmid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load opm "+$("#"+e.pre+"opmid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?opmid="+$("#"+e.pre+"opmid").val(),l)}})),e.myEventCls.onIds("#"+e.pre+"reload_align_refined","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"alignid1").val()+","+$("#"+e.pre+"alignid2").val();s.setLogCmd("load alignment "+l+" | parameters &atype=1&bu=1",!1);let r=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?align="+l+"&showalignseq=1&atype=1&bu=1",r)})),e.myEventCls.onIds("#"+e.pre+"reload_align_ori","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"alignid1").val()+","+$("#"+e.pre+"alignid2").val();s.setLogCmd("load alignment "+l+" | parameters &atype=0&bu=1",!1);let r=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?align="+l+"&showalignseq=1&atype=0&bu=1",r)})),e.myEventCls.onIds("#"+e.pre+"reload_align_tmalign","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"alignid1").val()+","+$("#"+e.pre+"alignid2").val();s.setLogCmd("load alignment "+l+" | parameters &atype=2&bu=1",!1);let r=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?align="+l+"&showalignseq=1&atype=2&bu=1",r)})),e.myEventCls.onIds("#"+e.pre+"reload_alignaf","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"alignafid1").val()+"_A,"+$("#"+e.pre+"alignafid2").val()+"_A";s.setLogCmd("load chains "+l+" | residues | resdef ",!1);let r=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?chainalign="+l+"&resnum=&resdef=&showalignseq=1",r)})),e.myEventCls.onIds("#"+e.pre+"reload_alignaf_tmalign","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"alignafid1").val()+"_A,"+$("#"+e.pre+"alignafid2").val()+"_A";s.setLogCmd("load chains "+l+" | residues | resdef | align tmalign",!1);let r=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?chainalign="+l+"&aligntool=tmalign&resnum=&resdef=&showalignseq=1",r)})),e.myEventCls.onIds("#"+e.pre+"reload_chainalign_asym","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"chainalignids").val(),r=s.convertUniProtInChains(l);s.setLogCmd("load chains "+r+" on asymmetric unit | residues | resdef ",!1);let o=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?chainalign="+r+"&resnum=&resdef=&showalignseq=1&bu=0",o)})),e.myEventCls.onIds("#"+e.pre+"reload_chainalign_asym2","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"chainalignids2").val(),r=s.convertUniProtInChains(l),o=$("#"+e.pre+"resalignids").val();s.setLogCmd("load chains "+r+" on asymmetric unit | residues "+o+" | resdef ",!1);let a=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?chainalign="+r+"&resnum="+o+"&resdef=&showalignseq=1&bu=0",a)})),e.myEventCls.onIds("#"+e.pre+"reload_chainalign_asym3","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"chainalignids3").val(),r=s.convertUniProtInChains(l),o=$("#"+e.pre+"predefinedres").val().trim().replace(/\n/g,": ");if(o&&r.split(",").length-1!=o.split(": ").length)return void alert("Please make sure the number of chains and the lines of predefined residues are the same...");s.setLogCmd("load chains "+r+" on asymmetric unit | residues | resdef "+o,!1);let a=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?chainalign="+r+"&resnum=&resdef="+o+"&showalignseq=1&bu=0",a)})),e.myEventCls.onIds("#"+e.pre+"reload_chainalign_asym4","click",(async function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"chainalignids4").val(),l=s.convertUniProtInChains(n),r=$("#"+e.pre+"predefinedres2").val().trim().replace(/\n/g,": ");if(r&&l.split(",").length-1!=r.split(": ").length)return void alert("Please make sure the number of chains and the lines of predefined residues are the same...");e.cfg.resdef=r.replace(/:/gi,";");let o=l.split(",");await i.realignParserCls.realignChainOnSeqAlign(void 0,o,!0,!0),s.setLogCmd("realign predefined "+l+" "+r,!0)})),e.myEventCls.onIds("#"+e.pre+"reload_chainalign_tmalign","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"chainalignids").val(),r=s.convertUniProtInChains(l);s.setLogCmd("load chains "+r+" on asymmetric unit | residues | resdef | align tmalign",!1);let o=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?chainalign="+r+"&aligntool=tmalign&resnum=&resdef=&showalignseq=1&bu=0",o)})),e.myEventCls.onIds("#"+e.pre+"reload_mutation_3d","click",(async function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l,r,o=$("#"+e.pre+"mutationids").val();if(l=$("#"+e.pre+"type_mmdbid").is(":checked")?"mmdbid":"afid",r=$("#"+e.pre+"showin_currentpage").is(":checked")?"currentpage":"newpage","currentpage"==r){let e=o;await n.scapCls.retrieveScap(e),s.setLogCmd("scap 3d "+e,!0),s.setLogCmd("select displayed set",!0)}else{let e=o.substr(0,o.indexOf("_"));s.setLogCmd("3d of mutation "+o,!1);let t=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?"+l+"="+e+"&command=scap 3d "+o+"; select displayed set",t)}})),e.myEventCls.onIds("#"+e.pre+"reload_mutation_pdb","click",(async function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l,r,o=$("#"+e.pre+"mutationids").val();if(l=$("#"+e.pre+"type_mmdbid").is(":checked")?"mmdbid":"afid",r=$("#"+e.pre+"showin_currentpage").is(":checked")?"currentpage":"newpage","currentpage"==r){let e=o,t=!0;await n.scapCls.retrieveScap(e,void 0,t),s.setLogCmd("scap pdb "+e,!0)}else{let e=o.substr(0,o.indexOf("_"));s.setLogCmd("pdb of mutation "+o,!1);let t=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?"+l+"="+e+"&command=scap pdb "+o+"; select displayed set",t)}})),e.myEventCls.onIds("#"+e.pre+"reload_mutation_inter","click",(async function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l,r,o=$("#"+e.pre+"mutationids").val();if(l=$("#"+e.pre+"type_mmdbid").is(":checked")?"mmdbid":"afid",r=$("#"+e.pre+"showin_currentpage").is(":checked")?"currentpage":"newpage","currentpage"==r){let e=o,t=!0;await n.scapCls.retrieveScap(e,t),s.setLogCmd("scap interaction "+e,!0);let i=e.split("_"),l="."+i[1]+":"+i[2],r="snp_"+i[1]+"_"+i[2];s.setLogCmd("select "+l+" | name "+r,!0),s.setLogCmd("line graph interaction pairs | selected non-selected | hbonds,salt bridge,interactions,halogen,pi-cation,pi-stacking | false | threshold 3.8 6 4 3.8 6 5.5",!0),s.setLogCmd("adjust dialog dl_linegraph",!0),s.setLogCmd("select displayed set",!0)}else{let e=o.split(","),t=[];for(let s=0,i=e.length;s<i;++s){let i=e[s].lastIndexOf("_"),n=e[s].substr(0,i);t.push(n)}let r=o.substr(0,o.indexOf("_"));n.structures||(n.structures={},n.structures[r]=1),n.resid2specCls.residueids2spec(t),s.setLogCmd("interaction change of mutation "+o,!1);let a=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?"+l+"="+r+"&command=scap interaction "+o,a)}})),e.myEventCls.onIds("#"+e.pre+"reload_mmcif","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load mmcif "+$("#"+e.pre+"mmcifid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?mmcifid="+$("#"+e.pre+"mmcifid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"mmcifid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load mmcif "+$("#"+e.pre+"mmcifid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?mmcifid="+$("#"+e.pre+"mmcifid").val(),l)}})),e.myEventCls.onIds("#"+e.pre+"reload_mmdb","click",(function(t){let n=e.icn3d;t.preventDefault(),s.setLogCmd("load mmdb1 "+$("#"+e.pre+"mmdbid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?mmdbid="+$("#"+e.pre+"mmdbid").val()+"&bu=1",l)})),e.myEventCls.onIds("#"+e.pre+"reload_mmdb_asym","click",(function(t){let n=e.icn3d;t.preventDefault(),s.setLogCmd("load mmdb0 "+$("#"+e.pre+"mmdbid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?mmdbid="+$("#"+e.pre+"mmdbid").val()+"&bu=0",l)})),e.myEventCls.onIds("#"+e.pre+"reload_mmdbaf","click",(function(t){e.icn3d,t.preventDefault();let n=$("#"+e.pre+"mmdbafid").val();s.launchMmdb(n,1,i)})),e.myEventCls.onIds("#"+e.pre+"reload_mmdbaf_asym","click",(function(t){e.icn3d,t.preventDefault();let n=$("#"+e.pre+"mmdbafid").val();s.launchMmdb(n,0,i)})),e.myEventCls.onIds("#"+e.pre+"reload_mmdbaf_append","click",(function(t){e.icn3d,t.preventDefault();let n=$("#"+e.pre+"mmdbafid").val();s.launchMmdb(n,1,i,!0)})),e.myEventCls.onIds("#"+e.pre+"reload_mmdbaf_asym_append","click",(function(t){e.icn3d,t.preventDefault();let n=$("#"+e.pre+"mmdbafid").val();s.launchMmdb(n,0,i,!0)})),e.myEventCls.onIds("#"+e.pre+"mmdbid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),s.setLogCmd("load mmdb1 "+$("#"+e.pre+"mmdbid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?mmdbid="+$("#"+e.pre+"mmdbid").val()+"&bu=1",l)}})),e.myEventCls.onIds("#"+e.pre+"mmdbafid","keyup",(function(t){if(e.icn3d,13===t.keyCode){t.preventDefault();let n=$("#"+e.pre+"mmdbafid").val();s.launchMmdb(n,1,i)}})),e.myEventCls.onIds("#"+e.pre+"reload_blast_rep_id","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"query_id").val(),r=encodeURIComponent($("#"+e.pre+"query_fasta").val()),o=$("#"+e.pre+"blast_rep_id").val();s.setLogCmd("load seq_struct_ids "+l+","+o,!1),l=""!==l&&void 0!==l?l:r;let a=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?from=icn3d&alg=blast&blast_rep_id="+o+"&query_id="+l+"&command=view annotations; set annotation cdd; set annotation site; set view detailed view; select chain "+o+"; show selection",a)})),e.myEventCls.onIds("#"+e.pre+"run_esmfold","click",(async function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),$("#"+e.pre+"dl_mmdbafid").hasClass("ui-dialog-content")&&$("#"+e.pre+"dl_mmdbafid").dialog("close");let n=$("#"+e.pre+"esmfold_fasta").val(),l="stru--";if(-1!=n.indexOf(">")){let e=n.indexOf("\n");if(i.esmTitle=n.substr(1,e-1).trim(),-1!=i.esmTitle.indexOf("|")){let e=i.esmTitle.split("|");l=e.length>2?e[1]:i.esmTitle}else l=-1!=i.esmTitle.indexOf(" ")?i.esmTitle.substr(0,i.esmTitle.indexOf(" ")):i.esmTitle;l.length<6&&(l=l.padEnd(6,"-")),n=n.substr(e+1)}if(n=n.replace(/\s/g,""),n.length>400)return void alert("Your sequence is larger than 400 characters. Please consider to split it as described at https://github.com/facebookresearch/esm/issues/21.");s.setLogCmd("Run ESMFold with the sequence "+n,!1);let r=await e.getAjaxPostPromise("https://api.esmatlas.com/foldSequence/v1/pdb/",n,!0,"Problem in returning PDB from ESMFold server...",void 0,!0,"text");i.bResetAnno=!0,i.bInputfile=!0,i.InputfileType="pdb",i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+r:r,i.bEsmfold=!0;await i.pdbParserCls.loadPdbData(r,l,void 0,!0,void 0,void 0,void 0,i.bEsmfold)})),e.myEventCls.onIds("#"+e.pre+"reload_alignsw","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"query_id").val(),r=encodeURIComponent($("#"+e.pre+"query_fasta").val()),o=$("#"+e.pre+"blast_rep_id").val();s.setLogCmd("load seq_struct_ids_smithwm "+l+","+o,!1),l=""!==l&&void 0!==l?l:r;let a=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?from=icn3d&alg=smithwm&blast_rep_id="+o+"&query_id="+l+"&command=view annotations; set annotation cdd; set annotation site; set view detailed view; select chain "+o+"; show selection",a)})),e.myEventCls.onIds("#"+e.pre+"reload_alignswlocal","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let l=$("#"+e.pre+"query_id").val(),r=encodeURIComponent($("#"+e.pre+"query_fasta").val()),o=$("#"+e.pre+"blast_rep_id").val();s.setLogCmd("load seq_struct_ids_local_smithwm "+l+","+o,!1),l=""!==l&&void 0!==l?l:r;let a=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?from=icn3d&alg=local_smithwm&blast_rep_id="+o+"&query_id="+l+"&command=view annotations; set annotation cdd; set annotation site; set view detailed view; select chain "+o+"; show selection",a)})),e.myEventCls.onIds("#"+e.pre+"reload_proteinname","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load protein "+$("#"+e.pre+"proteinname").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?protein="+$("#"+e.pre+"proteinname").val(),l)})),e.myEventCls.onIds("#"+e.pre+"reload_refseq","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load refseq "+$("#"+e.pre+"refseqid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?refseqid="+$("#"+e.pre+"refseqid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"gi","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load gi "+$("#"+e.pre+"gi").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?gi="+$("#"+e.pre+"gi").val(),l)}})),e.myEventCls.onIds("#"+e.pre+"reload_uniprotid","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load uniprotid "+$("#"+e.pre+"uniprotid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?uniprotid="+$("#"+e.pre+"uniprotid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"uniprotid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load uniprotid "+$("#"+e.pre+"uniprotid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?uniprotid="+$("#"+e.pre+"uniprotid").val(),l)}})),e.myEventCls.onIds("#"+e.pre+"reload_cid","click",(function(t){let n=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load cid "+$("#"+e.pre+"cid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?cid="+$("#"+e.pre+"cid").val(),l)})),e.myEventCls.onIds("#"+e.pre+"cid","keyup",(function(t){let n=e.icn3d;if(13===t.keyCode){t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.setLogCmd("load cid "+$("#"+e.pre+"cid").val(),!1);let l=n.structures&&Object.keys(n.structures).length>0?"_blank":"_self";window.open(i+"?cid="+$("#"+e.pre+"cid").val(),l)}})),e.htmlCls.setHtmlCls.clickReload_pngimage(),e.myEventCls.onIds("#"+e.pre+"reload_state","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close"),i.bInputfile||i.init();let n=$("#"+e.pre+"state")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=async function(t){i.bStatefile=!0;let n=t.target.result;s.setLogCmd("load state file "+$("#"+e.pre+"state").val(),!1),i.commands=[],i.optsHistory=[],await i.loadScriptCls.loadScript(n,!0)},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_selectionfile","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"selectionfile")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=async function(t){let n=t.target.result;await i.selectionCls.loadSelection(n),s.setLogCmd("load selection file "+$("#"+e.pre+"selectionfile").val(),!1)},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_collectionfile","click",(function(t){let s=e.icn3d;t.preventDefault();let i=$("#"+e.pre+"collectionfile")[0].files[0];if(i){e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?s.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close"),e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=async function(t){let i=JSON.parse(t.target.result),n=[i.structures.map((({id:e})=>e)),i.structures.map((({title:e})=>e))],l=s.selectCollectionsCls.setAtomMenu(n[0],n[1]);$("#"+s.pre+"collections_menu").html(l),s.selectCollectionsCls.clickStructure(),$("#"+s.pre+"collections_menu").trigger("change"),e.htmlCls.clickMenuCls.setLogCmd("load collection file "+$("#"+e.pre+"collectionfile").val(),!1)},t.readAsText(i),Object.keys(e.utilsCls.getStructures(s.dAtoms))?($("#"+e.pre+"dl_collection_file").hide(),$("#"+e.pre+"dl_collection_structures").show(),$("#"+e.pre+"dl_collection_file_expand").show(),$("#"+e.pre+"dl_collection_file_shrink").hide(),$("#"+e.pre+"dl_collection_structures_expand").hide(),$("#"+e.pre+"dl_collection_structures_shrink").show()):($("#"+e.pre+"dl_collection_file").show(),$("#"+e.pre+"dl_collection_structures").hide(),$("#"+e.pre+"dl_collection_file_expand").hide(),$("#"+e.pre+"dl_collection_file_shrink").hide(),$("#"+e.pre+"dl_collection_structures_expand").show(),$("#"+e.pre+"dl_collection_structures_shrink").hide()),e.htmlCls.dialogCls.openDlg("dl_selectCollections","Select Collections")}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_dsn6file2fofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.dsn6ParserCls.loadDsn6File("2fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_dsn6filefofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.dsn6ParserCls.loadDsn6File("fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_ccp4file2fofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.ccp4ParserCls.loadCcp4File("2fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_ccp4filefofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.ccp4ParserCls.loadCcp4File("fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_mtzfile2fofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.mtzParserCls.loadMtzFile("2fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_mtzfilefofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.mtzParserCls.loadMtzFile("fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_rcsbmtzfile2fofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.mtzParserCls.loadMtzFile("2fofc",!0)})),e.myEventCls.onIds("#"+e.pre+"reload_rcsbmtzfilefofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.mtzParserCls.loadMtzFile("fofc",!0)})),e.myEventCls.onIds("#"+e.pre+"reload_delphifile","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadDelphiFile("delphi")})),e.myEventCls.onIds("#"+e.pre+"reload_pqrfile","click",(function(t){let s=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.delphiCls.loadPhiFile("pqr")})),e.myEventCls.onIds("#"+e.pre+"reload_phifile","click",(function(t){let s=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.delphiCls.loadPhiFile("phi")})),e.myEventCls.onIds("#"+e.pre+"reload_cubefile","click",(function(t){let s=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),s.delphiCls.loadPhiFile("cube")})),e.myEventCls.onIds("#"+e.pre+"reload_pqrurlfile","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadPhiFileUrl("pqrurl")})),e.myEventCls.onIds("#"+e.pre+"reload_phiurlfile","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadPhiFileUrl("phiurl")})),e.myEventCls.onIds("#"+e.pre+"reload_cubeurlfile","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadPhiFileUrl("cubeurl")})),e.myEventCls.onIds("#"+e.pre+"reload_delphifile2","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.htmlCls.setHtmlCls.updateSurfPara("delphi"),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadDelphiFile("delphi2")})),e.myEventCls.onIds("#"+e.pre+"reload_pqrfile2","click",(function(t){let s=e.icn3d;t.preventDefault(),e.htmlCls.setHtmlCls.updateSurfPara("phi"),e.cfg.notebook||dialog.dialog("close"),s.delphiCls.loadPhiFile("pqr2")})),e.myEventCls.onIds("#"+e.pre+"reload_phifile2","click",(function(t){let s=e.icn3d;t.preventDefault(),e.htmlCls.setHtmlCls.updateSurfPara("phi"),e.cfg.notebook||dialog.dialog("close"),s.delphiCls.loadPhiFile("phi2")})),e.myEventCls.onIds("#"+e.pre+"reload_cubefile2","click",(function(t){let s=e.icn3d;t.preventDefault(),e.htmlCls.setHtmlCls.updateSurfPara("phi"),e.cfg.notebook||dialog.dialog("close"),s.delphiCls.loadPhiFile("cube2")})),e.myEventCls.onIds("#"+e.pre+"reload_pqrurlfile2","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.htmlCls.setHtmlCls.updateSurfPara("phiurl"),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadPhiFileUrl("pqrurl2")})),e.myEventCls.onIds("#"+e.pre+"reload_phiurlfile2","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.htmlCls.setHtmlCls.updateSurfPara("phiurl"),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadPhiFileUrl("phiurl2")})),e.myEventCls.onIds("#"+e.pre+"reload_cubeurlfile2","click",(async function(t){let s=e.icn3d;t.preventDefault(),e.htmlCls.setHtmlCls.updateSurfPara("phiurl"),e.cfg.notebook||dialog.dialog("close"),await s.delphiCls.loadPhiFileUrl("cubeurl2")})),e.myEventCls.onIds("#"+e.pre+"reload_dsn6fileurl2fofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.dsn6ParserCls.loadDsn6FileUrl("2fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_dsn6fileurlfofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.dsn6ParserCls.loadDsn6FileUrl("fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_ccp4fileurl2fofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.ccp4ParserCls.loadCcp4FileUrl("2fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_ccp4fileurlfofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.ccp4ParserCls.loadCcp4FileUrl("fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_mtzfileurl2fofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.mtzParserCls.loadMtzFileUrl("2fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_mtzfileurlfofc","click",(function(t){let s=e.icn3d;t.preventDefault(),s.mtzParserCls.loadMtzFileUrl("fofc")})),e.myEventCls.onIds("#"+e.pre+"reload_rcsbmtzfileurl2fofc","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.mtzParserCls.loadMtzFileUrl("2fofc",!0)})),e.myEventCls.onIds("#"+e.pre+"reload_rcsbmtzfileurlfofc","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.mtzParserCls.loadMtzFileUrl("fofc",!0)})),e.myEventCls.onIds("#"+e.pre+"reload_pdbfile","click",(async function(t){e.icn3d,t.preventDefault();await s.loadPdbFile(!1)})),e.myEventCls.onIds("#"+e.pre+"reload_pdbfile_app","click",(async function(t){let i=e.icn3d;t.preventDefault(),i.bAppend=!0,await s.loadPdbFile(i.bAppend)})),e.myEventCls.onIds("#"+e.pre+"reload_mol2file","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bInitial=!0,e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let n=$("#"+e.pre+"mol2file")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=async function(t){let n=t.target.result;s.setLogCmd("load mol2 file "+$("#"+e.pre+"mol2file").val(),!1),i.molTitle="",i.inputid=void 0,i.init(),i.bInputfile=!0,i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+n:n,i.InputfileType="mol2",await i.mol2ParserCls.loadMol2Data(n)},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_sdffile","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bInitial=!0,e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let n=$("#"+e.pre+"sdffile")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=async function(t){let n=t.target.result;s.setLogCmd("load sdf file "+$("#"+e.pre+"sdffile").val(),!1),i.molTitle="",i.inputid=void 0,i.init(),i.bInputfile=!0,i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+n:n,i.InputfileType="sdf",await i.sdfParserCls.loadSdfData(n)},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_xyzfile","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bInitial=!0,e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let n=$("#"+e.pre+"xyzfile")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=async function(t){let n=t.target.result;s.setLogCmd("load xyz file "+$("#"+e.pre+"xyzfile").val(),!1),i.molTitle="",i.inputid=void 0,i.init(),i.bInputfile=!0,i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+n:n,i.InputfileType="xyz",await i.xyzParserCls.loadXyzData(n)},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_afmapfile","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bInitial=!0,e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let n=$("#"+e.pre+"afmapfile")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=function(t){let n=t.target.result;s.setLogCmd("load AlphaFold PAE file "+$("#"+e.pre+"afmapfile").val(),!1),e.htmlCls.dialogCls.openDlg("dl_alignerrormap","Show Predicted Aligned Error (PAE) map"),i.contactMapCls.processAfErrorMap(JSON.parse(n))},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_afmapfilefull","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bInitial=!0,e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let n=$("#"+e.pre+"afmapfile")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=function(t){let n=t.target.result;s.setLogCmd("load AlphaFold PAE file "+$("#"+e.pre+"afmapfile").val(),!1),e.htmlCls.dialogCls.openDlg("dl_alignerrormap","Show Predicted Aligned Error (PAE) map"),i.contactMapCls.processAfErrorMap(JSON.parse(n),!0)},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"reload_urlfile","click",(async function(t){let s=e.icn3d;t.preventDefault(),s.bInitial=!0,e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?s.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let i=$("#"+e.pre+"filetype").val(),n=$("#"+e.pre+"urlfile").val();s.inputurl="type="+i+"&url="+encodeURIComponent(n),s.init(),s.bInputfile=!0,s.bInputUrlfile=!0,await s.pdbParserCls.downloadUrl(n,i)})),e.myEventCls.onIds("#"+e.pre+"reload_mmciffile","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bInitial=!0,e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close");let n=$("#"+e.pre+"mmciffile")[0].files[0];if(n){e.htmlCls.setHtmlCls.fileSupport();let t=new FileReader;t.onload=async function(t){let n=t.target.result;s.setLogCmd("load mmcif file "+$("#"+e.pre+"mmciffile").val(),!1),i.molTitle="";i.init(),i.bInputfile=!0,i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+data:data,i.InputfileType="mmcif",await i.opmParserCls.loadOpmData(n,void 0,void 0,"mmcif",void 0,!0)},t.readAsText(n)}else alert("Please select a file before clicking 'Load'")})),e.myEventCls.onIds("#"+e.pre+"applycustomcolor","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),i.setOptionCls.setOption("color",$("#"+e.pre+"colorcustom").val()),s.setLogCmd("color "+$("#"+e.pre+"colorcustom").val(),!0)})),e.myEventCls.onIds(["#"+e.pre+"atomsCustomSphere2","#"+e.pre+"atomsCustomSphere","#"+e.pre+"radius_aroundsphere"],"change",(function(t){e.icn3d.bSphereCalc=!1})),e.myEventCls.onIds("#"+e.pre+"applypick_aroundsphere","click",(function(t){let i=e.icn3d,n=parseFloat($("#"+e.pre+"radius_aroundsphere").val()),l=$("#"+e.pre+"atomsCustomSphere").val(),r=$("#"+e.pre+"atomsCustomSphere2").val();if(0==r.length)alert("Please select the first set at step #1");else{let e="select zone cutoff "+n+" | sets "+r+" "+l+" | "+i.bSphereCalc;i.bSphereCalc||i.showInterCls.pickCustomSphere(n,r,l,i.bSphereCalc),i.bSphereCalc=!0,i.hlUpdateCls.updateHlAll(),s.setLogCmd(e,!0)}})),e.myEventCls.onIds("#"+e.pre+"sphereExport","click",(function(t){let i=e.icn3d;t.preventDefault();let n=parseFloat($("#"+e.pre+"radius_aroundsphere").val()),l=$("#"+e.pre+"atomsCustomSphere").val(),r=$("#"+e.pre+"atomsCustomSphere2").val();if(0==r.length)alert("Please select the first set at step #1");else{i.showInterCls.pickCustomSphere(n,r,l,i.bSphereCalc),i.bSphereCalc=!0;let t=i.viewInterPairsCls.exportSpherePairs(),o=Object.keys(e.utilsCls.getHlStructures()).join(",");i.saveFileCls.saveFile(o+"_sphere_pairs.html","html",t),s.setLogCmd("export pairs | "+r+" "+l+" | dist "+n,!0)}})),e.myEventCls.onIds("#"+e.pre+"apply_adjustmem","click",(function(t){let i=e.icn3d;e.cfg.notebook||dialog.dialog("close");let n=parseFloat($("#"+e.pre+"extra_mem_z").val()),l=parseFloat($("#"+e.pre+"intra_mem_z").val());i.selectionCls.adjustMembrane(n,l);let r="adjust membrane z-axis "+n+" "+l;s.setLogCmd(r,!0)})),e.myEventCls.onIds("#"+e.pre+"apply_selectplane","click",(function(t){let i=e.icn3d;e.cfg.notebook||dialog.dialog("close");let n=parseFloat($("#"+e.pre+"selectplane_z1").val()),l=parseFloat($("#"+e.pre+"selectplane_z2").val());i.selectionCls.selectBtwPlanes(n,l);let r="select planes z-axis "+n+" "+l;s.setLogCmd(r,!0)})),e.myEventCls.onIds(["#"+e.pre+"atomsCustomHbond2","#"+e.pre+"atomsCustomHbond","#"+e.pre+"analysis_hbond","#"+e.pre+"analysis_saltbridge","#"+e.pre+"analysis_contact","#"+e.pre+"hbondthreshold","#"+e.pre+"saltbridgethreshold","#"+e.pre+"contactthreshold"],"change",(function(t){e.icn3d.bHbondCalc=!1})),e.myEventCls.onIds("#"+e.pre+"crossstrucinter","change",(function(t){let i=e.icn3d;t.preventDefault(),i.crossstrucinter=parseInt($("#"+e.pre+"crossstrucinter").val()),s.setLogCmd("cross structure interaction "+i.crossstrucinter,!0)})),e.myEventCls.onIds("#"+e.pre+"applyhbonds","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.showInterCls.showInteractions("3d")})),e.myEventCls.onIds("#"+e.pre+"applycontactmap","click",(async function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=parseFloat($("#"+i.pre+"contactdist").val()),l=$("#"+i.pre+"contacttype").val();await i.contactMapCls.contactMap(n,l),s.setLogCmd("contact map | dist "+n+" | type "+l,!0)})),e.myEventCls.onIds("#"+e.pre+"hbondWindow","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.showInterCls.showInteractions("view")})),e.myEventCls.onIds("#"+e.pre+"areaWindow","click",(function(t){let i=e.icn3d;t.preventDefault();let n=$("#"+e.pre+"atomsCustomHbond").val(),l=$("#"+e.pre+"atomsCustomHbond2").val();i.analysisCls.calcBuriedSurface(l,n),s.setLogCmd("calc buried surface | "+l+" "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"sortSet1","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.showInterCls.showInteractions("save1")})),$(document).on("click","."+e.pre+"showintercntonly",(function(t){e.icn3d,t.stopImmediatePropagation(),$(".icn3d-border").hide(),s.setLogCmd("table inter count only",!0)})),$(document).on("click","."+e.pre+"showinterdetails",(function(t){e.icn3d,t.stopImmediatePropagation(),$(".icn3d-border").show(),s.setLogCmd("table inter details",!0)})),e.myEventCls.onIds("#"+e.pre+"sortSet2","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.showInterCls.showInteractions("save2")})),e.myEventCls.onIds("#"+e.pre+"hbondGraph","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.showInterCls.showInteractions("graph")})),e.myEventCls.onIds("#"+e.pre+"hbondLineGraph","click",(async function(t){let i=e.icn3d;t.preventDefault(),i.bShownRefnum=!1,s.setLogCmd("hide ref number",!0),await i.showInterCls.showInteractions("linegraph")})),e.myEventCls.onIds("#"+e.pre+"hbondLineGraph2","click",(async function(t){let i=e.icn3d;t.preventDefault(),i.bShownRefnum=!0,s.setLogCmd("show ref number",!0),await i.showInterCls.showInteractions("linegraph")})),e.myEventCls.onIds("#"+e.pre+"hbondScatterplot","click",(async function(t){let i=e.icn3d;t.preventDefault(),i.bShownRefnum=!1,s.setLogCmd("hide ref number",!0),await i.showInterCls.showInteractions("scatterplot")})),e.myEventCls.onIds("#"+e.pre+"hbondScatterplot2","click",(async function(t){let i=e.icn3d;t.preventDefault(),i.bShownRefnum=!0,s.setLogCmd("show ref number",!0),await i.showInterCls.showInteractions("scatterplot")})),$(document).on("click","#"+e.svgid+" circle.selected",(function(t){let s=e.icn3d;t.stopImmediatePropagation();let i=$(this).attr("res");!1!==s.bSelectResidue||s.bShift||s.bCtrl||s.selectionCls.removeSelection(),void 0!==i&&(s.hlSeqCls.selectResidues(i,this),s.hlObjectsCls.addHlObjects())})),e.myEventCls.onIds("#"+e.svgid+"_svg","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.saveSvg(e.svgid,s.inputid+"_force_directed_graph.svg")})),e.myEventCls.onIds("#"+e.svgid+"_png","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.savePng(e.svgid,s.inputid+"_force_directed_graph.png")})),e.myEventCls.onIds("#"+e.svgid+"_json","click",(function(t){let s=e.icn3d;t.preventDefault();let i=s.graphStr.substr(0,s.graphStr.lastIndexOf("}"));i+=e.htmlCls.setHtmlCls.getLinkColor(),s.saveFileCls.saveFile(s.inputid+"_force_directed_graph.json","text",[i])})),$(document).on("click","#"+e.svgid_ct+"_svg",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.saveSvg(e.svgid_ct,s.inputid+"_cartoon.svg")})),$(document).on("click","#"+e.svgid_ct+"_png",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.savePng(e.svgid_ct,s.inputid+"_cartoon.png")})),$(document).on("click","#"+e.svgid_ct+"_json",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.saveFile(s.inputid+"_cartoon.json","text",[s.graphStr])})),$(document).on("change","#"+e.svgid_ct+"_label",(function(t){e.icn3d,t.preventDefault();let i=$("#"+e.svgid_ct+"_label").val();$("#"+e.svgid_ct+" text").removeClass(),$("#"+e.svgid_ct+" text").addClass(i),s.setLogCmd("cartoon label "+i,!0)})),e.myEventCls.onIds("#"+e.linegraphid+"_svg","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.saveSvg(e.linegraphid,s.inputid+"_line_graph.svg")})),e.myEventCls.onIds("#"+e.linegraphid+"_png","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.savePng(e.linegraphid,s.inputid+"_line_graph.png")})),e.myEventCls.onIds("#"+e.linegraphid+"_json","click",(function(t){let s=e.icn3d;t.preventDefault();let i=s.lineGraphStr.substr(0,s.lineGraphStr.lastIndexOf("}"));i+=e.htmlCls.setHtmlCls.getLinkColor(),s.saveFileCls.saveFile(s.inputid+"_line_graph.json","text",[i])})),e.myEventCls.onIds("#"+e.linegraphid+"_scale","change",(function(t){let i=e.icn3d;t.preventDefault();let n=$("#"+e.linegraphid+"_scale").val();$("#"+e.linegraphid).attr("width",(i.linegraphWidth*parseFloat(n)).toString()+"px"),s.setLogCmd("line graph scale "+n,!0)})),e.myEventCls.onIds("#"+e.scatterplotid+"_svg","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.saveSvg(e.scatterplotid,s.inputid+"_scatterplot.svg")})),e.myEventCls.onIds("#"+e.scatterplotid+"_png","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.savePng(e.scatterplotid,s.inputid+"_scatterplot.png")})),e.myEventCls.onIds("#"+e.scatterplotid+"_json","click",(function(t){let s=e.icn3d;t.preventDefault();let i=s.scatterplotStr.substr(0,s.scatterplotStr.lastIndexOf("}"));i+=e.htmlCls.setHtmlCls.getLinkColor(),s.saveFileCls.saveFile(s.inputid+"_scatterplot.json","text",[i])})),e.myEventCls.onIds("#"+e.scatterplotid+"_scale","change",(function(t){let i=e.icn3d;t.preventDefault();let n=$("#"+e.scatterplotid+"_scale").val();$("#"+e.scatterplotid).attr("width",(i.scatterplotWidth*parseFloat(n)).toString()+"px"),s.setLogCmd("scatterplot scale "+n,!0)})),e.myEventCls.onIds("#"+e.contactmapid+"_svg","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.saveSvg(e.contactmapid,s.inputid+"_contactmap.svg",!0)})),e.myEventCls.onIds("#"+e.contactmapid+"_png","click",(function(t){let s=e.icn3d;t.preventDefault(),s.saveFileCls.savePng(e.contactmapid,s.inputid+"_contactmap.png",!0)})),e.myEventCls.onIds("#"+e.contactmapid+"_json","click",(function(t){let s=e.icn3d;t.preventDefault();let i=s.contactmapStr.substr(0,s.contactmapStr.lastIndexOf("}"));i+=e.htmlCls.setHtmlCls.getLinkColor(),s.saveFileCls.saveFile(s.inputid+"_contactmap.json","text",[i])})),e.myEventCls.onIds("#"+e.contactmapid+"_scale","change",(function(t){let i=e.icn3d;t.preventDefault();let n=$("#"+e.contactmapid+"_scale").val();$("#"+e.contactmapid).attr("width",(i.contactmapWidth*parseFloat(n)).toString()+"px"),s.setLogCmd("contactmap scale "+n,!0)})),e.myEventCls.onIds("#"+e.alignerrormapid+"_svg","click",(function(t){let s=e.icn3d;t.preventDefault();$("#"+e.alignerrormapid+"_scale").val(1),$("#"+e.alignerrormapid).attr("width",(s.alignerrormapWidth*parseFloat(1)).toString()+"px"),s.saveFileCls.saveSvg(e.alignerrormapid,s.inputid+"_alignerrormap.svg",!0)})),e.myEventCls.onIds("#"+e.alignerrormapid+"_png","click",(function(t){let s=e.icn3d;t.preventDefault();$("#"+e.alignerrormapid+"_scale").val(1),$("#"+e.alignerrormapid).attr("width",(s.alignerrormapWidth*parseFloat(1)).toString()+"px"),s.saveFileCls.savePng(e.alignerrormapid,s.inputid+"_alignerrormap.png",!0)})),e.myEventCls.onIds("#"+e.alignerrormapid+"_full","click",(async function(t){let s=e.icn3d;t.preventDefault(),await s.contactMapCls.afErrorMap(afid,!0)})),e.myEventCls.onIds("#"+e.alignerrormapid+"_json","click",(function(t){let s=e.icn3d;t.preventDefault();let i=s.alignerrormapStr.substr(0,s.alignerrormapStr.lastIndexOf("}"));i+=e.htmlCls.setHtmlCls.getLinkColor(),s.saveFileCls.saveFile(s.inputid+"_alignerrormap.json","text",[i])})),e.myEventCls.onIds("#"+e.alignerrormapid+"_scale","change",(function(t){let i=e.icn3d;t.preventDefault();let n=$("#"+e.alignerrormapid+"_scale").val();$("#"+e.alignerrormapid).attr("width",(i.alignerrormapWidth*parseFloat(n)).toString()+"px"),s.setLogCmd("alignerrormap scale "+n,!0)})),e.myEventCls.onIds("#"+e.svgid+"_label","change",(function(t){e.icn3d,t.preventDefault();let i=$("#"+e.svgid+"_label").val();$("#"+e.svgid+" text").removeClass(),$("#"+e.svgid+" text").addClass(i),s.setLogCmd("graph label "+i,!0)})),e.myEventCls.onIds("#"+e.svgid+"_hideedges","change",(function(t){let i=e.icn3d;t.preventDefault(),e.htmlCls.hideedges=parseInt($("#"+e.svgid+"_hideedges").val()),e.htmlCls.hideedges?(e.htmlCls.contactInsideColor="FFF",e.htmlCls.hbondInsideColor="FFF",e.htmlCls.ionicInsideColor="FFF"):(e.htmlCls.contactInsideColor="DDD",e.htmlCls.hbondInsideColor="AFA",e.htmlCls.ionicInsideColor="8FF"),void 0!==i.graphStr&&(i.bRender&&e.htmlCls.force&&e.drawGraph(i.graphStr,e.pre+"dl_graph"),s.setLogCmd("hide edges "+e.htmlCls.hideedges,!0))})),e.myEventCls.onIds("#"+e.svgid+"_force","change",(function(t){let i=e.icn3d;t.preventDefault(),e.htmlCls.force=parseInt($("#"+e.svgid+"_force").val()),void 0!==i.graphStr&&(s.setLogCmd("graph force "+e.htmlCls.force,!0),i.getGraphCls.handleForce())})),e.myEventCls.onIds("#"+e.pre+"hbondReset","click",(function(t){let i=e.icn3d;t.preventDefault(),i.viewInterPairsCls.resetInteractionPairs(),s.setLogCmd("reset interaction pairs",!0)})),e.myEventCls.onIds("#"+e.pre+"applypick_labels","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"labeltext").val(),l=$("#"+e.pre+"labelsize").val(),r=$("#"+e.pre+"labelcolor").val(),o=$("#"+e.pre+"labelbkgd").val();if("0"!==l&&""!==l&&"undefined"!==l||(l=0),"0"!==r&&""!==r&&"undefined"!==r||(r=0),"0"!==o&&""!==o&&"undefined"!==o||(o=0),void 0===i.pAtom||void 0===i.pAtom2)alert("Please pick another atom");else{let e=(i.pAtom.coord.x+i.pAtom2.coord.x)/2,t=(i.pAtom.coord.y+i.pAtom2.coord.y)/2,a=(i.pAtom.coord.z+i.pAtom2.coord.z)/2;i.analysisCls.addLabel(n,e,t,a,l,r,o,"custom"),i.pickpair=!1;let d="",c="",h="";0!=l&&(d=" | size "+l),0!=r&&(c=" | color "+r),0!=o&&(h=" | background "+o),s.setLogCmd("add label "+n+" | x "+e.toPrecision(4)+" y "+t.toPrecision(4)+" z "+a.toPrecision(4)+d+c+h+" | type custom",!0),i.drawCls.draw()}})),e.myEventCls.onIds("#"+e.pre+"applyselection_labels","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close");let n=$("#"+e.pre+"labeltext2").val(),l=$("#"+e.pre+"labelsize2").val(),r=$("#"+e.pre+"labelcolor2").val(),o=$("#"+e.pre+"labelbkgd2").val();"0"!==l&&""!==l&&"undefined"!==l||(l=0),"0"!==r&&""!==r&&"undefined"!==r||(r=0),"0"!==o&&""!==o&&"undefined"!==o||(o=0);let a=i.applyCenterCls.centerAtoms(e.hashUtilsCls.hash2Atoms(i.hAtoms,i.atoms)),d=a.center.x,c=a.center.y,h=a.center.z;i.analysisCls.addLabel(n,d,c,h,l,r,o,"custom");let p="",m="",u="";0!=l&&(p=" | size "+l),0!=r&&(m=" | color "+r),0!=o&&(u=" | background "+o),s.setLogCmd("add label "+n+" | x "+d.toPrecision(4)+" y "+c.toPrecision(4)+" z "+h.toPrecision(4)+p+m+u+" | type custom",!0),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"applylabelcolor","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),i.labelcolor=$("#"+e.pre+"labelcolorall").val(),s.setLogCmd("set label color "+i.labelcolor,!0),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"applypick_stabilizer","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),void 0===i.pAtom||void 0===i.pAtom2?alert("Please pick another atom"):(i.pickpair=!1,s.setLogCmd("add one stabilizer | "+i.pAtom.serial+" "+i.pAtom2.serial,!0),void 0===i.pairArray&&(i.pairArray=[]),i.pairArray.push(i.pAtom.serial),i.pairArray.push(i.pAtom2.serial),i.threeDPrintCls.setThichknessFor3Dprint(),i.drawCls.draw())}));let l=new CP(document.querySelector("#"+e.pre+"colorcustom"));l.on("change",(function(e){this.target.value=e})),e.myEventCls.onIds("#"+e.pre+"colorcustom","input",(function(){let t=$("#"+e.pre+"colorcustom").val();l.set("#"+t).enter()})),e.myEventCls.onIds("#"+e.pre+"colorcustom","keyup",(function(){let t=$("#"+e.pre+"colorcustom").val();l.set("#"+t).enter()})),e.myEventCls.onIds("#"+e.pre+"colorcustom","paste",(function(){let t=$("#"+e.pre+"colorcustom").val();l.set("#"+t).enter()})),e.myEventCls.onIds("#"+e.pre+"colorcustom","cut",(function(){let t=$("#"+e.pre+"colorcustom").val();l.set("#"+t).enter()}));let r=new CP(document.querySelector("#"+e.pre+"labelcolorall"));r.on("change",(function(e){this.target.value=e})),e.myEventCls.onIds("#"+e.pre+"labelcolorall","input",(function(){let t=$("#"+e.pre+"labelcolorall").val();r.set("#"+t).enter()})),e.myEventCls.onIds("#"+e.pre+"labelcolorall","keyup",(function(){let t=$("#"+e.pre+"labelcolorall").val();r.set("#"+t).enter()})),e.myEventCls.onIds("#"+e.pre+"labelcolorall","paste",(function(){let t=$("#"+e.pre+"labelcolorall").val();r.set("#"+t).enter()})),e.myEventCls.onIds("#"+e.pre+"labelcolorall","cut",(function(){let t=$("#"+e.pre+"labelcolorall").val();r.set("#"+t).enter()})),e.myEventCls.onIds("#"+e.pre+"applypick_stabilizer_rm","click",(function(t){let i=e.icn3d;if(t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),void 0===i.pAtom||void 0===i.pAtom2)alert("Please pick another atom");else{i.pickpair=!1,s.setLogCmd("remove one stabilizer | "+i.pAtom.serial+" "+i.pAtom2.serial,!0);let e=[];e.push(i.pAtom.serial),e.push(i.pAtom2.serial),i.threeDPrintCls.removeOneStabilizer(e),i.drawCls.draw()}})),e.myEventCls.onIds("#"+e.pre+"applypick_measuredistance","click",(function(t){let i=e.icn3d;if(t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),i.bMeasureDistance=!1,void 0===i.pAtom||void 0===i.pAtom2)alert("Please pick another atom");else{let t=0,n=0,l=$("#"+e.pre+"linecolor").val(),r=(i.pAtom.coord.x+i.pAtom2.coord.x)/2,o=(i.pAtom.coord.y+i.pAtom2.coord.y)/2,a=(i.pAtom.coord.z+i.pAtom2.coord.z)/2;i.analysisCls.addLineFromPicking("distance");let d=(parseInt(10*i.pAtom.coord.distanceTo(i.pAtom2.coord))/10).toString()+" A";i.analysisCls.addLabel(d,r,o,a,t,l,n,"distance");let c="",h="",p="";0!=l&&(h=" | color "+l),s.setLogCmd("add label "+d+" | x "+r.toPrecision(4)+" y "+o.toPrecision(4)+" z "+a.toPrecision(4)+c+h+p+" | type distance",!0),i.drawCls.draw(),i.pk=2}})),e.myEventCls.onIds("#"+e.pre+"applydist2","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),i.bMeasureDistance=!1;let n=$("#"+e.pre+"atomsCustomDist").val(),l=$("#"+e.pre+"atomsCustomDist2").val();i.analysisCls.measureDistTwoSets(n,l),s.setLogCmd("dist | "+l+" "+n,!0)})),$(document).on("click",".icn3d-distance",(function(t){let i=e.icn3d;t.preventDefault(),i.bMeasureDistance=!1,i.distPnts=[],i.labels.distance=[],i.lines.distance=[];let n=$(this).attr("sets").split("|"),l=[n[0]],r=[n[1]];i.analysisCls.measureDistTwoSets(l,r),s.setLogCmd("dist | "+r+" "+l,!0)})),e.myEventCls.onIds("#"+e.pre+"applydisttable","click",(function(t){let i=e.icn3d;t.preventDefault(),e.cfg.notebook||dialog.dialog("close"),i.bMeasureDistance=!1;let n=$("#"+e.pre+"atomsCustomDistTable").val(),l=$("#"+e.pre+"atomsCustomDistTable2").val();i.analysisCls.measureDistManySets(n,l),e.htmlCls.dialogCls.openDlg("dl_disttable","Distance among the sets"),s.setLogCmd("disttable | "+l+" "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"applylinebtwsets","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bLinebtwsets=!1;let n=$("#"+e.pre+"linebtwsets").val(),l=$("#"+e.pre+"linebtwsets2").val(),r=i.definedSetsCls.getAtomsFromNameArray(n),o=i.definedSetsCls.getAtomsFromNameArray(l),a=i.contactCls.getExtent(r),d=i.contactCls.getExtent(o),c=new THREE.Vector3(a[2][0],a[2][1],a[2][2]),h=new THREE.Vector3(d[2][0],d[2][1],d[2][2]),p=$("#"+e.pre+"linebtwsets_radius").val(),m=$("#"+e.pre+"linebtwsets_customcolor").val(),u=$("#"+e.pre+"linebtwsets_opacity").val(),g="Solid"!=$("#"+e.pre+"linebtwsets_style").val(),f="cylinder",C="add line | x1 "+c.x.toPrecision(4)+" y1 "+c.y.toPrecision(4)+" z1 "+c.z.toPrecision(4)+" | x2 "+h.x.toPrecision(4)+" y2 "+h.y.toPrecision(4)+" z2 "+h.z.toPrecision(4)+" | color "+m+" | dashed "+g+" | type "+f+" | radius "+p+" | opacity "+u;s.setLogCmd(C,!0),i.analysisCls.addLine(c.x,c.y,c.z,h.x,h.y,h.z,m,g,f,p,u),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"applycartoonshape","click",(function(t){let i=e.icn3d;t.preventDefault(),i.bCartoonshape=!1;let n=$("#"+e.pre+"cartoonshape").val(),l=i.definedSetsCls.getAtomsFromNameArray(n),r=i.contactCls.getExtent(l),o=new THREE.Vector3(r[2][0],r[2][1],r[2][2]),a=$("#"+e.pre+"cartoonshape_shape").val(),d=$("#"+e.pre+"cartoonshape_radius").val(),c=$("#"+e.pre+"cartoonshape_customcolor").val(),h=$("#"+e.pre+"cartoonshape_opacity").val();c="#"+c.replace(/\#/g,"");let p,m=e.parasCls.thr(c);"Sphere"==a?(i.sphereCls.createSphereBase(o,m,d,void 0,void 0,void 0,h),p="add sphere | x1 "+o.x.toPrecision(4)+" y1 "+o.y.toPrecision(4)+" z1 "+o.z.toPrecision(4)+" | color "+c+" | opacity "+h+" | radius "+d):(i.boxCls.createBox_base(o,d,m,void 0,void 0,void 0,h),p="add cube | x1 "+o.x.toPrecision(4)+" y1 "+o.y.toPrecision(4)+" z1 "+o.z.toPrecision(4)+" | color "+c+" | opacity "+h+" | radius "+d),s.setLogCmd(p,!0),i.shapeCmdHash[p]=1,i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"clearlinebtwsets","click",(function(t){let i=e.icn3d;t.preventDefault(),i.lines.cylinder=[],s.setLogCmd("clear line between sets",!0),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"clearcartoonshape","click",(function(t){let i=e.icn3d;t.preventDefault(),i.shapeCmdHash={},s.setLogCmd("clear shape",!0),i.drawCls.draw()})),e.myEventCls.onIds("#"+e.pre+"apply_thickness_3dprint","click",(function(t){e.icn3d,t.preventDefault(),e.htmlCls.setHtmlCls.setLineThickness("3dprint")})),e.myEventCls.onIds("#"+e.pre+"apply_thickness_style","click",(function(t){e.icn3d,t.preventDefault(),e.htmlCls.setHtmlCls.setLineThickness("style"),e.htmlCls.setMenuCls.setLogWindow(!0)})),e.myEventCls.onIds("#"+e.pre+"reset_thickness_3dprint","click",(function(t){e.icn3d,t.preventDefault(),e.htmlCls.setHtmlCls.setLineThickness("3dprint",!0)})),e.myEventCls.onIds("#"+e.pre+"reset_thickness_style","click",(function(t){e.icn3d,t.preventDefault(),e.htmlCls.setHtmlCls.setLineThickness("style",!0),e.htmlCls.setMenuCls.setLogWindow(!0)})),e.myEventCls.onIds("#"+e.pre+"reset","click",(function(t){let s=e.icn3d;s.selectionCls.resetAll(),s.bRender&&s.drawCls.draw()})),e.myEventCls.onIds(["#"+e.pre+"toggleHighlight","#"+e.pre+"toggleHighlight2"],"click",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),i.hlUpdateCls.toggleHighlight(),s.setLogCmd("toggle highlight",!0)})),e.myEventCls.onIds("#"+e.pre+"seq_clearselection","click",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),e.cfg.notebook||dialog.dialog("close"),i.hlUpdateCls.clearHighlight(),s.setLogCmd("clear selection",!0)})),e.myEventCls.onIds("#"+e.pre+"seq_clearselection2","click",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),t.preventDefault(),i.hlUpdateCls.clearHighlight(),s.setLogCmd("clear selection",!0)})),e.myEventCls.onIds("#"+e.pre+"alignseq_clearselection","click",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),i.hlUpdateCls.clearHighlight(),s.setLogCmd("clear selection",!0)})),e.myEventCls.onIds("#"+e.pre+"replay","click",(async function(t){let i=e.icn3d;t.stopImmediatePropagation(),i.CURRENTNUMBER++;let n=e.cfg.replay?i.STATENUMBER:i.STATENUMBER-1;if(i.CURRENTNUMBER==n)i.bReplay=0,$("#"+e.pre+"replay").hide();else if(i.commands.length>0&&i.commands[i.CURRENTNUMBER]){await i.loadScriptCls.execCommandsBase(i.CURRENTNUMBER,i.CURRENTNUMBER,i.STATENUMBER);let t=i.commands[i.CURRENTNUMBER].indexOf("|||"),n=-1!=t?i.commands[i.CURRENTNUMBER].substr(0,t):i.commands[i.CURRENTNUMBER],l=30,r=n.length>l?n.substr(0,l)+"...":n,o=i.applyCommandCls.getMenuFromCmd(r);$("#"+e.pre+"replay_cmd").html("Cmd: "+r),$("#"+e.pre+"replay_menu").html("Menu: "+o),s.setLogCmd(n,!0),i.drawCls.draw()}})),t.loadScriptCls.pressCommandtext(),e.myEventCls.onIds("#"+e.pre+"seq_saveselection","click",(function(t){let s=e.icn3d;t.stopImmediatePropagation(),e.cfg.notebook||dialog.dialog("close"),s.selectionCls.saveSelectionPrep();let i=$("#"+e.pre+"seq_command_name").val().replace(/\s+/g,"_");s.selectionCls.saveSelection(i,i)})),e.myEventCls.onIds("#"+e.pre+"seq_saveselection2","click",(function(t){let s=e.icn3d;t.stopImmediatePropagation(),s.selectionCls.saveSelectionPrep();let i=$("#"+e.pre+"seq_command_name2").val().replace(/\s+/g,"_");s.selectionCls.saveSelection(i,i)})),e.myEventCls.onIds("#"+e.pre+"mn2_saveresidue","click",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),e.cfg.notebook||dialog.dialog("close"),i.selectionCls.saveEachResiInSel(),s.setLogCmd("select each residue",!0)})),e.myEventCls.onIds("#"+e.pre+"alignseq_saveselection","click",(function(t){let s=e.icn3d;t.stopImmediatePropagation(),s.selectionCls.saveSelectionPrep();let i=$("#"+e.pre+"alignseq_command_name").val().replace(/\s+/g,"_");s.selectionCls.saveSelection(i,i)})),$(document).on("click","."+e.pre+"outputselection",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),i.bSelectResidue=!1,i.bSelectAlignResidue=!1,s.setLogCmd("output selection",!0),i.threeDPrintCls.outputSelection()})),$(document).on("click",".icn3d-saveicon",(function(t){e.icn3d,t.stopImmediatePropagation();let i=$(this).attr("pid");s.saveHtml(i),s.setLogCmd("save html "+i,!0)})),$(document).on("click",".icn3d-hideicon",(function(t){let s=e.icn3d;t.stopImmediatePropagation();let i=$(this).attr("pid");if(!e.cfg.notebook)if(void 0===s.dialogHashHideDone&&(s.dialogHashHideDone={}),void 0===s.dialogHashPosToRight&&(s.dialogHashPosToRight={}),s.dialogHashHideDone.hasOwnProperty(i)){let e=s.dialogHashHideDone[i].width,t=s.dialogHashHideDone[i].height,n=s.dialogHashHideDone[i].position;$("#"+i).dialog("option","width",e),$("#"+i).dialog("option","height",t),$("#"+i).dialog("option","position",n),delete s.dialogHashHideDone[i]}else{s.dialogHashHideDone[i]={width:$("#"+i).dialog("option","width"),height:$("#"+i).dialog("option","height"),position:$("#"+i).dialog("option","position")};let e,t=160,n=80;$("#"+i).dialog("option","width",t),$("#"+i).dialog("option","height",n),s.dialogHashPosToRight.hasOwnProperty(i)?e=s.dialogHashPosToRight[i]:(e=Object.keys(s.dialogHashPosToRight).length*(t+10),s.dialogHashPosToRight[i]=e);let l={my:"right bottom",at:"right-"+e+" bottom+60",of:"#"+s.divid,collision:"none"};$("#"+i).dialog("option","position",l)}})),$(document).on("click","."+e.pre+"selres",(function(t){let i=e.icn3d;t.stopImmediatePropagation(),i.bSelOneRes=!1;let n=$("."+e.pre+"seloneres");for(let e=0,t=n.length;e<t;++e)n[e].checked=!1;let l=$(this).attr("resid").split("|");i.hAtoms={},i.selectedResidues={};let r="select ";for(let e=0,t=l.length;e<t;++e){let t=l[e];e>0&&(r+=" or "),r+=i.selectionCls.selectOneResid(t)}i.hlUpdateCls.updateHlAll(),s.setLogCmd(r,!0)})),$(document).on("click","."+e.pre+"seloneres",(function(t){let s=e.icn3d;t.stopImmediatePropagation(),s.bSelOneRes||(s.hAtoms={},s.selectedResidues={},s.bSelOneRes=!0);let i=$(this).attr("resid"),n=$(this).attr("id");$("#"+n).length&&$("#"+n)[0].checked?s.selectionCls.selectOneResid(i):$("#"+n).length&&!$("#"+n)[0].checked&&s.selectionCls.selectOneResid(i,!0),s.hlUpdateCls.updateHlAll()})),$(document).on("click","."+e.pre+"selset",(async function(t){let i=e.icn3d;t.stopImmediatePropagation(),i.bSelOneRes=!1;let n=$("."+e.pre+"seloneres");for(let e=0,t=n.length;e<t;++e)n[e].checked=!1;let l=$(this).attr("cmd");await i.selByCommCls.selectByCommand(l,"",""),i.hlObjectsCls.removeHlObjects(),i.hlObjectsCls.addHlObjects(),s.setLogCmd(l,!0)})),$(document).on("click",".icn3d-addtrack",(function(t){let s=e.icn3d;t.stopImmediatePropagation(),$("#"+e.pre+"anno_custom")[0].checked=!0,$("[id^="+e.pre+"custom]").show();let i=$(this).attr("chainid"),n=s.chainsGene[i].geneId;$("#"+e.pre+"track_chainid").val(i),$("#"+e.pre+"track_geneid").val(n),e.htmlCls.dialogCls.openDlg("dl_addtrack","Add track for Chain: "+i),$("#"+e.pre+"track_gi").focus()})),$(document).on("click",".icn3d-customcolor",(function(t){e.icn3d,t.stopImmediatePropagation();let s=$(this).attr("chainid");$("#"+e.pre+"customcolor_chainid").val(s),e.htmlCls.dialogCls.openDlg("dl_customcolor","Apply custom color or tube for Chain: "+s)})),$(document).on("click",".icn3d-helixsets",(function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("chainid");i.addTrackCls.defineSecondary(n,"helix"),s.setLogCmd("define helix sets | chain "+n,!0)})),$(document).on("click",".icn3d-sheetsets",(function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("chainid");i.addTrackCls.defineSecondary(n,"sheet"),s.setLogCmd("define sheet sets | chain "+n,!0)})),$(document).on("click",".icn3d-coilsets",(function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("chainid");i.addTrackCls.defineSecondary(n,"coil"),s.setLogCmd("define coil sets | chain "+n,!0)})),$(document).on("click",".icn3d-iganchorsets",(function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("chainid");i.addTrackCls.defineIgstrand(n,"iganchor"),s.setLogCmd("define iganchor sets | chain "+n,!0)})),$(document).on("click",".icn3d-igstrandsets",(function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("chainid");i.addTrackCls.defineIgstrand(n,"igstrand"),s.setLogCmd("define igstrand sets | chain "+n,!0)})),$(document).on("click",".icn3d-igloopsets",(function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("chainid");i.addTrackCls.defineIgstrand(n,"igloop"),s.setLogCmd("define igloop sets | chain "+n,!0)})),$(document).on("click",".icn3d-igdomainsets",(function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("chainid");i.addTrackCls.defineIgstrand(n,"igdomain"),s.setLogCmd("define igdomain sets | chain "+n,!0)})),e.myEventCls.onIds("#"+e.pre+"deletesets","click",(function(t){e.icn3d.definedSetsCls.deleteSelectedSets(),s.setLogCmd("delete selected sets",!0)})),$(document).on("mouseup touchend","accordion",(function(t){let s=e.icn3d;s.bControlGl&&!e.bNode?window.controls&&(window.controls.noRotate=!1,window.controls.noZoom=!1,window.controls.noPan=!1):s.controls&&(s.controls.noRotate=!1,s.controls.noZoom=!1,s.controls.noPan=!1)})),$(document).on("mousedown touchstart","accordion",(function(t){let s=e.icn3d;s.bControlGl&&!e.bNode?window.controls&&(window.controls.noRotate=!0,window.controls.noZoom=!0,window.controls.noPan=!0):s.controls&&(s.controls.noRotate=!0,s.controls.noZoom=!0,s.controls.noPan=!0)})),$(document).on("click",".icn3d-expand",(function(t){e.icn3d,t.stopImmediatePropagation();let s=$(this).attr("id"),i=s.lastIndexOf("_"),n=s.substr(0,i);$("#"+n).show(),$("#"+n+"_expand").hide(),$("#"+n+"_shrink").show()})),$(document).on("click",".icn3d-shrink",(function(t){e.icn3d,t.stopImmediatePropagation();let s=$(this).attr("id"),i=s.lastIndexOf("_"),n=s.substr(0,i);$("#"+n).hide(),$("#"+n+"_expand").show(),$("#"+n+"_shrink").hide()})),window.onscroll=function(t){let s=e.icn3d;"detailed view"==s.view&&0==$(window).scrollTop()&&0==$(window).scrollTop()&&0==$("#"+e.pre+"dl_selectannotations").scrollTop()?s.annotationCls.showFixedTitle():s.annotationCls.hideFixedTitle()},e.myEventCls.onIds("#"+e.pre+"dl_selectannotations","scroll",(function(){"detailed view"==t.view&&0==$(window).scrollTop()&&0==$(window).scrollTop()&&0==$("#"+e.pre+"dl_selectannotations").scrollTop()?t.annotationCls.showFixedTitle():t.annotationCls.hideFixedTitle()})),e.myEventCls.onIds("#"+e.pre+"mn6_themeBlue","click",(function(t){e.icn3d,e.htmlCls.setMenuCls.setTheme("blue"),s.setLogCmd("set theme blue",!0)})),e.myEventCls.onIds("#"+e.pre+"mn6_themeOrange","click",(function(t){e.icn3d,e.htmlCls.setMenuCls.setTheme("orange"),s.setLogCmd("set theme orange",!0)})),e.myEventCls.onIds("#"+e.pre+"mn6_themeBlack","click",(function(t){e.icn3d,e.htmlCls.setMenuCls.setTheme("black"),s.setLogCmd("set theme black",!0)})),$(document).on("click","."+e.pre+"snpin3d",(async function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("snp");await i.scapCls.retrieveScap(n),s.setLogCmd("scap 3d "+n,!0),s.setLogCmd("select displayed set",!0)})),$(document).on("click","."+e.pre+"snpinter",(async function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("snp");await i.scapCls.retrieveScap(n,!0),s.setLogCmd("scap interaction "+n,!0);let l=n.split("_"),r="."+l[1]+":"+l[2],o="snp_"+l[1]+"_"+l[2];s.setLogCmd("select "+r+" | name "+o,!0),s.setLogCmd("line graph interaction pairs | selected non-selected | hbonds,salt bridge,interactions,halogen,pi-cation,pi-stacking | false | threshold 3.8 6 4 3.8 6 5.5",!0),s.setLogCmd("adjust dialog dl_linegraph",!0),s.setLogCmd("select displayed set",!0)})),$(document).on("click","."+e.pre+"snppdb",(async function(t){let i=e.icn3d;t.stopImmediatePropagation();let n=$(this).attr("snp");await i.scapCls.retrieveScap(n,void 0,!0),s.setLogCmd("scap pdb "+n,!0)}))}}class m{constructor(e){this.icn3dui=e}getAlignSequencesAnnotations(e,t,s,i,n,l){let r=this.icn3dui,o=r.icn3d,a="";e=Object.keys(o.alnChains),l&&(e=e.reverse());let d=0,c={};if(void 0!==e)for(let t=0,s=e.length;t<s;++t){let s=e[t];if(!(o.alnChainsSeq[s]&&o.alnChainsSeq[s].length>0))return{sequencesHtml:a,maxSeqCnt:d};c[s]=1}let h,p=void 0===t||t;p&&(o.hAtoms={});let m,u,g=0,f=0;for(let t=0,l=e.length;t<l;++t){let l=e[t];0==g&&(m=l),u=n&&g>0?m:l,p&&(o.hAtoms=r.hashUtilsCls.unionHash(o.hAtoms,o.alnChains[l]));let C=[],b="",y=void 0!==o.alnChainsSeq[l]?o.alnChainsSeq[l].length:0;y>d&&(d=y);let v,_,w=u.indexOf("_"),S=u.substr(0,w),A=u.substr(w+1);for(let e=0,t=y;e<t;++e)if("-"!=o.alnChainsSeq[l][e].resn){v=o.alnChainsSeq[l][e].resi;break}for(let e=y-1;e>=0;--e)if("-"!=o.alnChainsSeq[l][e].resn){_=o.alnChainsSeq[l][e].resi;break}b+="<span class='icn3d-residueNum' title='starting residue number'>"+v+"</span>",h=!(void 0===e||!c.hasOwnProperty(u));for(let e=0,t=y;e<t;++e){let t="N/A",a="";""!==o.alnChainsSeq[l][e].resi&&(t=o.alnChainsSeq[l][e].resi,a=S+"_"+A+"_"+t,o.alnChainsSeq[l][e].color);let d,c="class='icn3d-residue";if((void 0===i||i)&&(h||void 0!==s&&""!==a&&-1!==s.indexOf(a))&&(c="class='icn3d-residue icn3d-highlightSeq"),c+=""===a?"'":" "+o.alnChainsSeq[l][e].class+"'",o.residues.hasOwnProperty(a)){let e=o.firstAtomObjCls.getFirstCalphaAtomObj(o.residues[a]);d=void 0!==e.color?"#"+e.color.getHexString()+";":"#000000;"}else d="#000000;";if("#FFFFFF;"===d.toUpperCase()&&(d=r.htmlCls.GREYD),n&&0==e){b+="<span style='width:"+f*10+"px'></span>"}""!==a?-1!=o.alnChainsSeq[l][e].resi?b+="<span id='align_"+r.pre+a+"' "+c+" style='color:"+d+"' title='"+o.alnChainsSeq[l][e].resn+o.alnChainsSeq[l][e].resi+"'>"+o.alnChainsSeq[l][e].resn+"</span>":b+="<span>"+o.alnChainsSeq[l][e].resn+"</span>":b+="<span title='"+o.alnChainsSeq[l][e].resn+o.alnChainsSeq[l][e].resi+"'>"+o.alnChainsSeq[l][e].resn+"</span>"}b+="<span class='icn3d-residueNum' title='ending residue number'>"+_+"</span>";let x=e.length,k=void 0!==o.alnChainsAnno[l]?o.alnChainsAnno[l].length:0;for(let t=0,s=k;t<s;++t){C[t]="";let s=t<x?e[x-1-t]:u;C[t]+="<span class='icn3d-residueNum'></span>";for(let e=0,i=o.alnChainsAnno[l][t].length;e<i;++e){let i=o.alnChainsAnno[l][t][e];if("H"==i||"E"==i||"c"==i||"o"==i)if("H"==i)C[t]+=e%2==0?'<span class="icn3d-helix">&nbsp;</span>':'<span class="icn3d-helix2">&nbsp;</span>';else if("E"==i)if(void 0!==o.alnChainsSeq[s][e]){let i=s+"_"+o.alnChainsSeq[s][e].resi;if(o.residues.hasOwnProperty(i)){o.firstAtomObjCls.getFirstCalphaAtomObj(o.residues[i]).ssend?C[t]+='<span class="icn3d-sheet2">&nbsp;</span>':C[t]+='<span class="icn3d-sheet">&nbsp;</span>'}else C[t]+='<span class="icn3d-sheet">&nbsp;</span>'}else C[t]+='<span class="icn3d-sheet">&nbsp;</span>';else C[t]+="c"==i?'<span class="icn3d-coil">&nbsp;</span>':"o"==i?'<span class="icn3d-other">&nbsp;</span>':"<span></span>";else C[t]+="<span>"+i+"</span>"}C[t]+="<span class='icn3d-residueNum'></span>"}let O=l,R=void 0!==o.pdbid_chain2title?o.pdbid_chain2title[u]:"";for(let e=k-1;e>=0;--e){let t=o.alnChainsAnTtl[l][e][0];"SS"==t&&(t=""),a+="<div class='icn3d-residueLine' style='white-space:nowrap;'><div class='icn3d-seqTitle' anno='"+e+"'>"+t+"</div>"+C[e]+"<br/></div>"}a+='<div class="icn3d-seqTitle icn3d-link icn3d-blue" chain="'+l+'" anno="sequence" title="'+R+'">'+O+' </div><span class="icn3d-seqLine">'+b+"</span><br/>",g>0&&(f+=y),++g}return{sequencesHtml:a,maxSeqCnt:d}}}class u{constructor(e){this.icn3dui=e}getLink(e,t,s,i){let n=this.icn3dui;return n.icn3d,n.htmlCls.allMenus[e]=t,i&&(n.htmlCls.allMenusSel[e]=i),s&&(n.htmlCls.simpleMenus[e]=1),"<li><span data-pinger id='"+n.pre+e+"' class='icn3d-link'>"+t+"</span></li>"}getMenuText(e,t,s,i,n){let l=this.icn3dui;l.icn3d,l.htmlCls.allMenus[e]=t,n&&(l.htmlCls.allMenusSel[e]=n),i&&(l.htmlCls.simpleMenus[e]=1);let r="icn3d-menupd"==s?" style='padding-left:1.5em!important;'":"";return"<li><span data-pinger id='"+l.pre+e+"'"+r+">"+t+"</span>"}getMenuUrl(e,t,s,i,n){let l=this.icn3dui;return l.icn3d,l.htmlCls.allMenus[e]=s,n&&(l.htmlCls.allMenusSel[e]=n),i&&(l.htmlCls.simpleMenus[e]=1),"<li><a id='"+l.pre+e+"' href='"+t+"' target='_blank'>"+s+"</a></li>"}getMenuSep(){return this.icn3dui.icn3d,"<li class='icn3d-menusep'>-</li>"}getLinkWrapper(e,t,s,i,n,l){let r=this.icn3dui;r.icn3d,r.htmlCls.allMenus[e]=t,n&&(r.htmlCls.allMenusSel[e]=n),i&&(r.htmlCls.simpleMenus[e]=1);let o=l?' style="display:none"':"";return"<li id='"+r.pre+s+"'"+o+"><span data-pinger id='"+r.pre+e+"' class='icn3d-link'>"+t+"</span></li>"}getLinkWrapper2(e,t,s,i,n){let l=this.icn3dui;return l.icn3d,l.htmlCls.allMenus[e]=t,n&&(l.htmlCls.allMenusSel[e]=n),i&&(l.htmlCls.simpleMenus[e]=1),"<li id='"+l.pre+s+"'><span data-pinger id='"+l.pre+e+"' class='icn3d-link'>"+t+"</span>"}getRadio(e,t,s,i,n,l){let r=this.icn3dui;r.icn3d,r.htmlCls.allMenus[t]=s,l&&(r.htmlCls.allMenusSel[t]=l),n&&(r.htmlCls.simpleMenus[t]=1);let o=i?" checked":"";return"<li><label data-pinger id='"+r.pre+t+"' class='icn3d-rad'>"+r.htmlCls.inputRadioStr+"name='"+r.pre+e+"' class='"+r.pre+e+"' v='"+s+"'"+o+"><span class='ui-icon ui-icon-blank'></span> <span class='icn3d-rad-text'>"+s+"</span></label></li>"}getRadioColor(e,t,s,i,n,l,r){let o=this.icn3dui;o.icn3d,o.htmlCls.allMenus[t]=s,r&&(o.htmlCls.allMenusSel[t]=r),l&&(o.htmlCls.simpleMenus[t]=1);let a=n?" checked":"";return"<li><label data-pinger id='"+o.pre+t+"' class='icn3d-rad'>"+o.htmlCls.inputRadioStr+"name='"+o.pre+e+"'"+a+"><span class='ui-icon ui-icon-blank'></span> <span class='icn3d-color-rad-text' color='"+i+"'><span style='background-color:#"+i+"'>"+o.htmlCls.space3+"</span> "+s+"</span></label></li>"}setAdvanced(e){let t=this.icn3dui;t.icn3d;let s=void 0===e?"":e,i=t.cfg.notebook?"icn3d-hidden":"",n=t.htmlCls.divStr+"dl_advanced"+s+"' class='"+i+"'>";return n+="<table width='500'><tr><td valign='top'><table cellspacing='0'>",n+="<tr><td><b>Select:</b></td><td>"+t.htmlCls.inputTextStr+"id='"+t.pre+"command"+s+"' placeholder='$[structures].[chains]:[residues]@[atoms]' size='60'></td></tr>",n+="<tr><td><b>Name:</b></td><td>"+t.htmlCls.inputTextStr+"id='"+t.pre+"command_name"+s+"' placeholder='my_selection' size='60'></td></tr>",n+="<tr><td colspan='2' align='left'>"+t.htmlCls.space3+t.htmlCls.buttonStr+"command_apply"+s+"'><b>Save Selection to Defined Sets</b></button></td></tr>",n+="</table></td>",n+="</tr>",n+="<tr><td>",n+='Specification Tips: <div style="width:20px; margin-top:6px; display:inline-block;"><span id="'+t.pre+"specguide"+s+'_expand" class="ui-icon ui-icon-plus icn3d-expand icn3d-link" style="width:15px;" title="Expand"></span><span id="'+t.pre+"specguide"+s+'_shrink" class="ui-icon ui-icon-minus icn3d-shrink icn3d-link" style="display:none; width:15px;" title="Shrink"></span></div><br>',n+=t.htmlCls.divStr+"specguide"+s+"' style='display:none; width:500px' class='icn3d-box'>",n+='<b>Specification:</b> In the selection "$1HHO,4N7N.A,B,C:5-10,LV,3AlaVal,chemicals@CA,C,C*":',n+='<ul><li>"$1HHO,4N7N" uses "$" to indicate structure selection.<br/>',n+='<li>".A,B,C" uses "." to indicate chain selection.<br/>',n+='<li>":5-10,LV,3LeuVal,chemicals" uses the colon ":" to indicate residue selection. Residue selection could be residue number(5-10), one-letter IUPAC residue name abbreviations(LV), three-letter residue names(AlaVal, "3" indicates each residue name has three letters), or predefined names: "proteins", "nucleotides", "chemicals", "ions", and "water". IUPAC abbreviations can be written either as a contiguous string(e.g., ":LV"), in order to find all instances of that sequence in the structure, or they can be separated by commas(e.g., ":L,V") to select all residues of a given type in the structure(in the latter case, select all Leucine and Valine in the structure).<br/>',n+='<li>"@CA,C,C*" uses "@" to indicate atom name selection. "C*" selects any atom names starting with "C". <br/>',n+='<li>Partial definition is allowed, e.g., ":1-10" selects all residue IDs 1-10 in all chains.<br/>',n+='<li>Different selections can be unioned(with "<b>or</b>", default), intersected(with "<b>and</b>"), or negated(with "<b>not</b>"). For example, ":1-10 or :K" selects all residues 1-10 and all Lys residues. ":1-10 and :K" selects all Lys residues in the range of residue number 1-10. ":1-10 or not :K" selects all residues 1-10, which are not Lys residues.<br/>',n+='<li>The wild card character "X" or "x" can be used to represent any character.',n+="</ul>",n+="<b>Set Operation:</b>",n+='<ul><li>Users can select multiple sets in the menu "Select > Defined Sets".<br/>',n+='<li>Different sets can be unioned(with "<b>or</b>", default), intersected(with "<b>and</b>"), or negated(with "<b>not</b>"). For example, if the "Defined Sets" menu has four sets ":1-10", ":11-20", ":5-15", and ":7-8", the command "saved atoms :1-10 or :11-20 and :5-15 not :7-8" unions all residues 1-10 and 11-20 to get the residues 1-20, then intersects with the residues 5-15 to get the residues 5-15, then exclude the residues 7-8 to get the final residues 5-6 and 9-15.</ul>',n+="<b>Full commands in url or command window:</b>",n+="<ul><li>Select without saving the set: select $1HHO,4N7N.A,B,C:5-10,LV,chemicals@CA,C,C*<br/>",n+="<li>Select and save: select $1HHO,4N7N.A,B,C:5-10,LV,chemicals@CA,C,C* | name my_name</ul>",n+="</div>",n+="</td></tr></table>",n+="</div>",n}getOptionHtml(e,t){let s=this.icn3dui;s.icn3d;let i="";for(let n=0,l=e.length;n<l;++n){let l=e[n];i+=n==t?s.htmlCls.optionStr+"'"+l+"' selected>"+l+"</option>":s.htmlCls.optionStr+"'"+l+"'>"+l+"</option>"}return i}setColorHints(){let e=this.icn3dui;e.icn3d;let t="";return t+=e.htmlCls.divNowrapStr+'<span style="margin-left:33px; color:#00FF00; font-weight:bold">Green</span>: H-Bonds; ',t+='<span style="color:#00FFFF; font-weight:bold">Cyan</span>: Salt Bridge/Ionic; ',t+='<span style="font-weight:bold">Grey</span>: contacts</div>',t+=e.htmlCls.divNowrapStr+'<span style="margin-left:33px; color:#FF00FF; font-weight:bold">Magenta</span>: Halogen Bonds; ',t+='<span style="color:#FF0000; font-weight:bold">Red</span>: &pi;-Cation; ',t+='<span style="color:#0000FF; font-weight:bold">Blue</span>: &pi;-Stacking</div>',t}setThicknessHtml(e){let t=this.icn3dui,s=t.icn3d,i="",n="3dprint"==e?"1":"0.1",l="3dprint"==e?"1.2":"0.3",r="3dprint"==e?"0.8":"0.4",o="3dprint"==e?"0.8":"0.4",a="3dprint"==e?"1":"0.4",d="3dprint"==e?"0.6":"0.3",c="3dprint"==e?"1":"0.2",h="3dprint"==e?"2":"1.3",p="3dprint"==e?"1.4":"0.8",m=40,u=.8,g=.4,f=.2,C=0,b=1,y=0;if("style"==e){if(""!=this.getCookie("shininess")&&(m=parseFloat(this.getCookie("shininess"))),""!=this.getCookie("light1")&&(u=parseFloat(this.getCookie("light1")),g=parseFloat(this.getCookie("light2")),f=parseFloat(this.getCookie("light3"))),""!=this.getCookie("lineRadius")){n=parseFloat(this.getCookie("lineRadius")),l=parseFloat(this.getCookie("coilWidth")),r=parseFloat(this.getCookie("cylinderRadius"));let e=this.getCookie("crosslinkRadius");o=isNaN(e)?s.crosslinkRadius:parseFloat(e),a=parseFloat(this.getCookie("traceRadius")),d=parseFloat(this.getCookie("dotSphereScale")),c=parseFloat(this.getCookie("ribbonthickness")),h=parseFloat(this.getCookie("helixSheetWidth")),p=parseFloat(this.getCookie("nucleicAcidWidth"))}""!=this.getCookie("glycan")&&(C=parseFloat(this.getCookie("glycan"))),""!=this.getCookie("membrane")&&(b=parseFloat(this.getCookie("membrane"))),""!=this.getCookie("cmdwindow")&&(y=parseFloat(this.getCookie("cmdwindow"))),i+="<b>Note</b>: The following parameters will be saved in cache. You just need to set them once. <br><br>",i+="<b>1. Shininess</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"shininess' value='"+m+"' size=4>"+t.htmlCls.space3+"(for the shininess of the 3D objects, default 40)<br/><br/>",i+="<b>2. Three directional lights</b>: <br>",i+="<b>Key Light</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"light1' value='"+u+"' size=4>"+t.htmlCls.space3+"(for the light strength of the key light, default 0.8)<br/>",i+="<b>Fill Light</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"light2' value='"+g+"' size=4>"+t.htmlCls.space3+"(for the light strength of the fill light, default 0.4)<br/>",i+="<b>Back Light</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"light3' value='"+f+"' size=4>"+t.htmlCls.space3+"(for the light strength of the back light, default 0.2)<br/><br/>",i+="<b>3. Thickness</b>: <br>"}return i+="<b>Line Radius</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"linerad_"+e+"' value='"+n+"' size=4>"+t.htmlCls.space3+"(for stabilizers, hydrogen bonds, distance lines, default 0.1)<br/>",i+="<b>Coil Radius</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"coilrad_"+e+"' value='"+l+"' size=4>"+t.htmlCls.space3+"(for coils, default 0.3)<br/>",i+="<b>Stick Radius</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"stickrad_"+e+"' value='"+r+"' size=4>"+t.htmlCls.space3+"(for sticks, default 0.4)<br/>",i+="<b>Cross-Linkage Radius</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"crosslinkrad_"+e+"' value='"+o+"' size=4>"+t.htmlCls.space3+"(for cross-linkages, default 0.4)<br/>",i+="<b>Trace Radius</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"tracerad_"+e+"' value='"+a+"' size=4>"+t.htmlCls.space3+"(for C alpha trace, O3' trace, default 0.4)<br/>",i+="<b>Ribbon Thickness</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"ribbonthick_"+e+"' value='"+c+"' size=4>"+t.htmlCls.space3+"(for helix and sheet ribbons, nucleotide ribbons, default 0.2)<br/>",i+="<b>Protein Ribbon Width</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"prtribbonwidth_"+e+"' value='"+h+"' size=4>"+t.htmlCls.space3+"(for helix and sheet ribbons, default 1.3)<br/>",i+="<b>Nucleotide Ribbon Width</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"nucleotideribbonwidth_"+e+"' value='"+p+"' size=4>"+t.htmlCls.space3+"(for nucleotide ribbons, default 0.8)<br/>",i+="<b>Ball Scale</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"ballscale_"+e+"' value='"+d+"' size=4>"+t.htmlCls.space3+"(for styles 'Ball and Stick' and 'Dot', default 0.3)<br/>","style"==e&&(i+="<br><b>4. Show Glycan Cartoon</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"glycan' value='"+C+"' size=4>"+t.htmlCls.space3+"(0: hide, 1: show, default 0)<br/>",i+="<br><b>5. Show Membrane</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"membrane' value='"+b+"' size=4>"+t.htmlCls.space3+"(0: hide, 1: show, default 1)<br/>",i+="<br><b>6. Enlarge Command Window</b>: "+t.htmlCls.inputTextStr+"id='"+t.pre+"cmdwindow' value='"+y+"' size=4>"+t.htmlCls.space3+"(0: Regular, 1: Large, default 0)<br/><br/>"),i+=t.htmlCls.spanNowrapStr+""+t.htmlCls.buttonStr+"apply_thickness_"+e+"'>Apply</button></span>&nbsp;&nbsp;&nbsp;",i+=t.htmlCls.spanNowrapStr+""+t.htmlCls.buttonStr+"reset_thickness_"+e+"'>Reset</button></span>",i}getCookie(e){let t=e+"=",s=decodeURIComponent(document.cookie).split(";");for(let e=0;e<s.length;e++){let i=s[e];for(;" "==i.charAt(0);)i=i.substring(1);if(0==i.indexOf(t))return i.substring(t.length,i.length)}return""}setSequenceGuide(e,t){let s=this.icn3dui,i=s.icn3d,n="",l=i&&i.defNames2Atoms?Object.keys(i.defNames2Atoms).length:1;t?n+=s.htmlCls.divStr+"seqguide"+e+"'>":(n+='<div style="width:20px; margin-left:3px; display:inline-block;"><span id="'+s.pre+"seqguide"+e+'_expand" class="ui-icon ui-icon-plus icn3d-expand icn3d-link" style="width:15px;" title="Expand"></span><span id="'+s.pre+"seqguide"+e+'_shrink" class="ui-icon ui-icon-minus icn3d-shrink icn3d-link" style="display:none; width:15px;" title="Shrink"></span></div> ',n+="<div style='min-width:200px; display:inline-block;'><b>Selection:</b> Name: "+s.htmlCls.inputTextStr+"id='"+s.pre+"seq_command_name"+e+"' value='seq_"+l+"' size='5'> "+s.htmlCls.space2+"<button style='white-space:nowrap;' id='"+s.pre+"seq_saveselection"+e+"'>Save</button> <button style='white-space:nowrap; margin-left:20px;' id='"+s.pre+"seq_clearselection"+e+"'>Clear</button></div><br/>",n+=s.htmlCls.divStr+"seqguide"+e+"' style='display:none; white-space:normal;' class='icn3d-box'>"),n+=this.getSelectionHints();return n+="<b>Residue labeling:</b> standard residue with coordinates: UPPER case letter; nonstandard residue with coordinates: the first UPPER case letter plus a period except that water residue uses the letter 'O'; residue missing coordinates: lower case letter."+(s.utilsCls.isMac()&&!s.utilsCls.isMobile()?"<br/><br/><b>Turn on scroll bar:</b> System preferences -> General -> show scroll bars -> check Always":"")+"<br/></div>",n}setAlignSequenceGuide(e,t){let s=this.icn3dui,i=s.icn3d,n="";let l=i&&i.defNames2Atoms?Object.keys(i.defNames2Atoms).length:1;n+='<div style="width:20px; margin-left:3px; display:inline-block;"><span id="'+s.pre+'alignseqguide_expand" class="ui-icon ui-icon-plus icn3d-expand icn3d-link" style="width:15px;" title="Expand"></span><span id="'+s.pre+'alignseqguide_shrink" class="ui-icon ui-icon-minus icn3d-shrink icn3d-link" style="display:none; width:15px;" title="Shrink"></span></div> ',n+="<div style='min-width:200px; display:inline-block;''><b>Selection:</b> Name: "+s.htmlCls.inputTextStr+"id='"+s.pre+"alignseq_command_name' value='alseq_"+l+"' size='10'> "+s.htmlCls.space2+"<button style='white-space:nowrap;' id='"+s.pre+"alignseq_saveselection'>Save</button> <button style='white-space:nowrap; margin-left:20px;' id='"+s.pre+"alignseq_clearselection'>Clear</button></div><br/>",n+=s.htmlCls.divStr+"alignseqguide' style='display:none; white-space:normal;' class='icn3d-box'>",n+=this.getSelectionHints();return n+="<b>Residue labeling:</b> aligned residue with coordinates: UPPER case letter; non-aligned residue with coordinates: lower case letter which can be highlighted; residue missing coordinates: lower case letter which can NOT be highlighted."+(s.utilsCls.isMac()&&!s.utilsCls.isMobile()?"<br/><br/><b>Turn on scroll bar:</b> System preferences -> General -> show scroll bars -> check Always":"")+"<br/></div>",n}getSelectionHints(){let e=this.icn3dui;e.icn3d;let t="";if(e.utilsCls.isMobile())t+='<b>Select Aligned Sequences:</b> touch to select, touch again to deselect, multiple selection is allowed without Ctrl key, click "Save Selection" to save the current selection.<br/>';else{t+='<b>Select on 1D sequences:</b> drag to select, drag again to deselect, multiple selection is allowed without Ctrl key, click "Save Selection" to save the current selection.<br/><br/>',t+="<b>Select on 2D interaction diagram:</b> click on the nodes or lines. The nodes are chains and can be united with the Ctrl key. The lines are interactions and can NOT be united. Each click on the lines selects half of the lines, i.e., select the interacting residues in one of the two chains.<br/><br/>",t+="<b>Select on 3D structures:</b> "+(e.utilsCls.isMobile()?"use finger to pick":'hold "Alt" and use mouse to pick')+', click the second time to deselect, hold "Ctrl" to union selection, hold "Shift" to select a range, press the up/down arrow to switch among atom/residue/strand/chain/structure, click "Save Selection" to save the current selection.<br/><br/>',t+='<b>Save the current selection</b>(either on 3D structure, 2D interactions, or 1D sequence): open the menu "Select -> Save Selection", specify the name and description for the selection, and click "Save".<br/><br/>'}return t}addGsizeSalt(e){let t=this.icn3dui;t.icn3d;let s="";s+="<span style='white-space:nowrap;font-weight:bold;'>Grid Size: <select id='"+t.pre+e+"gsize'>";s+=this.getOptionHtml(["65","97","129"],0),s+="</select></span>",s+="<span style='white-space:nowrap;font-weight:bold;margin-left:30px;'>Salt Concentration: <select id='"+t.pre+e+"salt'>";return s+=this.getOptionHtml(["0","0.15"],1),s+="</select> M</span><br/>",s}getFootHtml(e,t){let s=this.icn3dui;s.icn3d;let i="<div style='width:500px;'>";return"delphi"==e?s.cfg.cid?i+="<b>Note</b>: Partial charges(MMFF94) are from PubChem Compound SDF files.<br/><br/>":(i+="<b>Note</b>: Only the selected residues are used for <a href='http://honig.c2b2.columbia.edu/delphi'>DelPhi</a> potential calculation by solving linear Poisson-Boltzmann equation.",i+='<div style="width:20px; margin-top:6px; display:inline-block;"><span id="'+s.pre+t+'_expand" class="ui-icon ui-icon-plus icn3d-expand icn3d-link" style="width:15px;" title="Expand"></span><span id="'+s.pre+t+'_shrink" class="ui-icon ui-icon-minus icn3d-shrink icn3d-link" style="display:none; width:15px;" title="Shrink"></span></div><br>',i+=s.htmlCls.divStr+t+"' style='display:none;'>",i+="<br>The hydrogens and partial charges of proteins and nucleotides are added using <a href='http://compbio.clemson.edu/pka_webserver'>DelPhiPKa</a> with the Amber charge and size files. The hydrogens of ligands are added using <a href='http://openbabel.org/wiki/Main_Page'>Open Babel</a>. The partial charges of ligands are calculated using <a href='http://ambermd.org/antechamber/ac.html'>Antechamber</a> with the Gasteiger charge method. All partial charges are calculated at pH 7.<br/><br/>",i+='Lipids are treated as ligands. Please use "HETATM" instead of "ATOM " for each lipid atom in your PDB file. Each phosphate in lipids is assigned with a charge of -1. You can download PQR and modify it, or prepare your PQR file using other tools. Then load the PQR file at the menu "Analysis > Load PQR/Potential".<br/><br/>',i+="</div>"):(i+="<b>Note</b>: Always load a PDB file before loading a PQR or DelPhi potential file.",i+='<div style="width:20px; margin-top:6px; display:inline-block;"><span id="'+s.pre+t+'_expand" class="ui-icon ui-icon-plus icn3d-expand icn3d-link" style="width:15px;" title="Expand"></span><span id="'+s.pre+t+'_shrink" class="ui-icon ui-icon-minus icn3d-shrink icn3d-link" style="display:none; width:15px;" title="Shrink"></span></div><br>',i+=s.htmlCls.divStr+t+"' style='display:none;'>",i+='The PDB file can be loaded in the URL with "pdbid=" or at "File > Open File". The PQR file can be prepared at the menu "Analysis > Download PQR" with your modification or using other tools. The DelPhi potential file can be calculated at <a href=\'http://compbio.clemson.edu/sapp/delphi_webserver/\'>DelPhi Web Server</a> and be exported as a Cube file. ',"url"==e&&(i+="The PQR or potential file can be accessed in a URL if it is located in the same host as iCn3D."),i+="<br/><br/>",i+="</div>"),i+="</div>",i}getPotentialHtml(e,t){let s=this.icn3dui;s.icn3d;let i,n,l,r,o,a="";r="Equipotential Map",o="Surface with Potential","delphi"==e?n="delphi":"local"==e?(i="pqr",n="phi",l="cube"):"url"==e&&(i="pqrurl",n="phiurl",l="cubeurl"),a+=s.htmlCls.divStr+"dl_"+n+"' class='"+t+"'>",a+=s.htmlCls.setDialogCls.addNotebookTitle("dl_"+n,"DelPhi Potential"),a+=s.htmlCls.divStr+"dl_"+n+"_tabs' style='border:0px;'>",a+="<ul>",a+="<li><a href='#"+s.pre+n+"tab1'>Equipotential Map</a></li>",a+="<li><a href='#"+s.pre+n+"tab2'>Surface with Potential</a></li>",a+="</ul>",a+=s.htmlCls.divStr+n+"tab1'>","delphi"==e&&(a+=this.addGsizeSalt(n+"1")+"<br>"),a+="<span style='white-space:nowrap;font-weight:bold;'>Potential contour at: <select id='"+s.pre+n+"contour'>";let d;a+=this.getOptionHtml(["0.5","1","2","3","4","5","6","7","8","9","10"],2),a+="</select> kT/e(25.6mV at 298K)</span><br/><br/>","delphi"==e?(a+=s.htmlCls.buttonStr+"reload_"+n+"file' style='margin-top: 6px;'>Equipotential Map</button>",a+=s.htmlCls.buttonStr+n+"mapNo' style='margin-left:30px;'>Remove Map</button><br>"):"local"==e?(a+=s.htmlCls.divStr+n+"tab1_tabs' style='border:0px;'>",a+="<ul>",a+="<li><a href='#"+s.pre+n+"tab1_"+i+"'>PQR</a></li>",a+="<li><a href='#"+s.pre+n+"tab1_"+n+"'>Phi</a></li>",a+="<li><a href='#"+s.pre+n+"tab1_"+l+"'>Cube</a></li>",a+="</ul>",d="<span style='margin-left:30px'>"+s.htmlCls.buttonStr+n+"mapNo'>Remove Map</button></span></div>",a+=s.htmlCls.divStr+n+"tab1_"+i+"'>",a+=this.addGsizeSalt(i)+"<br>",a+="<b>PQR File</b>: "+s.htmlCls.inputFileStr+"id='"+s.pre+i+"file'> <br><br>"+s.htmlCls.buttonStr+"reload_"+i+"file' style='margin-top: 6px;'>Equipotential Map</button>"+d,a+=s.htmlCls.divStr+n+"tab1_"+n+"'>",a+="<b>Phi File</b>: "+s.htmlCls.inputFileStr+"id='"+s.pre+n+"file'> <br><br>"+s.htmlCls.buttonStr+"reload_"+n+"file' style='margin-top: 6px;'>Equipotential Map</button>"+d,a+=s.htmlCls.divStr+n+"tab1_"+l+"'>",a+="<b>Cube File</b>: "+s.htmlCls.inputFileStr+"id='"+s.pre+l+"file'> <br><br>"+s.htmlCls.buttonStr+"reload_"+l+"file' style='margin-top: 6px;'>Equipotential Map</button>"+d,a+="</div>"):"url"==e&&(a+=s.htmlCls.divStr+n+"tab1_tabs' style='border:0px;'>",a+="<ul>",a+="<li><a href='#"+s.pre+n+"tab1_"+i+"2'>PQR</a></li>",a+="<li><a href='#"+s.pre+n+"tab1_"+n+"2'>Phi</a></li>",a+="<li><a href='#"+s.pre+n+"tab1_"+l+"2'>Cube</a></li>",a+="</ul>",d="<span style='margin-left:30px'>"+s.htmlCls.buttonStr+n+"mapNo'>Remove Map</button></span></div>",a+=s.htmlCls.divStr+n+"tab1_"+i+"2'>",a+=this.addGsizeSalt(i)+"<br>",a+="<b>PQR URL</b> in the same host: "+s.htmlCls.inputTextStr+"id='"+s.pre+i+"file'> <br><br>"+s.htmlCls.buttonStr+"reload_"+i+"file' style='margin-top: 6px;'>Equipotential Map</button>"+d,a+=s.htmlCls.divStr+n+"tab1_"+n+"2'>",a+="<b>Phi URL</b> in the same host: "+s.htmlCls.inputTextStr+"id='"+s.pre+n+"file'> <br><br>"+s.htmlCls.buttonStr+"reload_"+n+"file' style='margin-top: 6px;'>Equipotential Map</button>"+d,a+=s.htmlCls.divStr+n+"tab1_"+l+"2'>",a+="<b>Cube URL</b> in the same host: "+s.htmlCls.inputTextStr+"id='"+s.pre+l+"file'> <br><br>"+s.htmlCls.buttonStr+"reload_"+l+"file' style='margin-top: 6px;'>Equipotential Map</button>"+d,a+="</div>"),a+="<br>"+this.getFootHtml(e,n+"tab1_foot"),a+="</div>",a+=s.htmlCls.divStr+n+"tab2'>","delphi"==e&&(a+=this.addGsizeSalt(n+"2")+"<br>"),a+="<span style='white-space:nowrap;font-weight:bold;'>Surface with max potential at: <select id='"+s.pre+n+"contour2'>";a+=this.getOptionHtml(["0.5","1","2","3","4","5","6","7","8","9","10"],2),a+="</select> kT/e(25.6mV at 298K)</span><br/><br/>",a+="<b>Surface</b>: <select id='"+s.pre+n+"surftype'>",a+="<option value='21'>Van der Waals</option>",a+="<option value='22' selected>Molecular Surface</option>",a+="<option value='23'>Solvent Accessible</option>",a+="</select>",a+="<span style='margin-left:20px'><b>Opacity</b>: <select id='"+s.pre+n+"surfop'>";return a+=this.getOptionHtml(["1.0","0.9","0.8","0.7","0.6","0.5","0.4","0.3","0.2","0.1"],0),a+="</select></span>",a+="<span style='margin-left:20px'><b>Wireframe</b>: <select id='"+s.pre+n+"surfwf'>",a+="<option value='yes'>Yes</option>",a+="<option value='no' selected>No</option>",a+="</select></span><br/>",a+="<br/>","delphi"==e?(a+=s.htmlCls.buttonStr+"reload_"+n+"file2' style='margin-top: 6px;'>Surface with Potential</button>",a+=s.htmlCls.buttonStr+n+"mapNo2' style='margin-left:30px;'>Remove Surface</button><br>"):"local"==e?(a+=s.htmlCls.divStr+n+"tab2_tabs' style='border:0px;'>",a+="<ul>",a+="<li><a href='#"+s.pre+n+"tab2_"+i+"'>PQR</a></li>",a+="<li><a href='#"+s.pre+n+"tab2_"+n+"'>Phi</a></li>",a+="<li><a href='#"+s.pre+n+"tab2_"+l+"'>Cube</a></li>",a+="</ul>",d="<span style='margin-left:30px'>"+s.htmlCls.buttonStr+n+"mapNo2'>Remove Surface</button></span></div>",a+=s.htmlCls.divStr+n+"tab2_"+i+"'>",a+=this.addGsizeSalt(i+"2")+"<br>",a+="<b>PQR File</b>: "+s.htmlCls.inputFileStr+"id='"+s.pre+i+"file2'> <br><br>"+s.htmlCls.buttonStr+"reload_"+i+"file2' style='margin-top: 6px;'>Surface with Potential</button>"+d,a+=s.htmlCls.divStr+n+"tab2_"+n+"'>",a+="<b>Phi File</b>: "+s.htmlCls.inputFileStr+"id='"+s.pre+n+"file2'> <br><br>"+s.htmlCls.buttonStr+"reload_"+n+"file2' style='margin-top: 6px;'>Surface with Potential</button>"+d,a+=s.htmlCls.divStr+n+"tab2_"+l+"'>",a+="<b>Cube File</b>: "+s.htmlCls.inputFileStr+"id='"+s.pre+l+"file2'> <br><br>"+s.htmlCls.buttonStr+"reload_"+l+"file2' style='margin-top: 6px;'>Surface with Potential</button>"+d,a+="</div>"):"url"==e&&(a+=s.htmlCls.divStr+n+"tab2_tabs' style='border:0px;'>",a+="<ul>",a+="<li><a href='#"+s.pre+n+"tab2_"+i+"2'>PQR</a></li>",a+="<li><a href='#"+s.pre+n+"tab2_"+n+"2'>Phi</a></li>",a+="<li><a href='#"+s.pre+n+"tab2_"+l+"2'>Cube</a></li>",a+="</ul>",d="<span style='margin-left:30px'>"+s.htmlCls.buttonStr+n+"mapNo2'>Remove Surface</button></span></div>",a+=s.htmlCls.divStr+n+"tab2_"+i+"2'>",a+=this.addGsizeSalt(i+"2")+"<br>",a+="<b>PQR URL</b> in the same host: "+s.htmlCls.inputTextStr+"id='"+s.pre+i+"file2'> <br><br>"+s.htmlCls.buttonStr+"reload_"+i+"file2' style='margin-top: 6px;'>Surface with Potential</button>"+d,a+=s.htmlCls.divStr+n+"tab2_"+n+"2'>",a+="<b>Phi URL</b> in the same host: "+s.htmlCls.inputTextStr+"id='"+s.pre+n+"file2'> <br><br>"+s.htmlCls.buttonStr+"reload_"+n+"file2' style='margin-top: 6px;'>Surface with Potential</button>"+d,a+=s.htmlCls.divStr+n+"tab2_"+l+"2'>",a+="<b>Cube URL</b> in the same host: "+s.htmlCls.inputTextStr+"id='"+s.pre+l+"file2'> <br><br>"+s.htmlCls.buttonStr+"reload_"+l+"file2' style='margin-top: 6px;'>Surface with Potential</button>"+d,a+="</div>"),a+="<br>"+this.getFootHtml(e,n+"tab2_foot"),a+="</div>",a+="</div>",a+="</div>",a}async exportPqr(e){let t=this.icn3dui,s=t.icn3d,i={},n={},l=t.hashUtilsCls.intHash(s.dAtoms,s.hAtoms);for(let e in l)s.atoms[e],s.ions.hasOwnProperty(e)?i[e]=1:n[e]=1;let r=e?"pdb":"pqr";if(t.cfg.cid){let l="",o=!e;l+=s.saveFileCls.getAtomPDB(n,o)+s.saveFileCls.getAtomPDB(i,o);let a=Object.keys(t.utilsCls.getHlStructures()).join(",");s.saveFileCls.saveFile(a+"_icn3d."+r,"text",[l])}else{if(t.utilsCls.isCalphaPhosOnly(t.hashUtilsCls.hash2Atoms(n,s.atoms)))return void alert("The potential will not be shown because the side chains are missing in the structure...");let l="",o=!0;l+=s.saveFileCls.getAtomPDB(n,void 0,void 0,void 0,void 0,void 0,o),l+=s.saveFileCls.getAtomPDB(i,!0,void 0,!0);let a=t.htmlCls.baseUrl+"delphi/delphi.cgi",d={pdb2pqr:l,pdbid:t.cfg.cid?t.cfg.cid:Object.keys(s.structures).toString()},c=await t.getAjaxPostPromise(a,d,!0,void 0,void 0,!0,"text");if(e){let e=c.split("\n"),s="";for(let i=0,n=e.length;i<n;++i){let n=e[i];if("ATOM "==n.substr(0,6)||"HETATM"==n.substr(0,6)){let e,i=n.substr(12,4).trim();if("ATOM "==n.substr(0,6))e=i.substr(0,1);else{let s=i.substr(0,2);e=t.parasCls.vdwRadii.hasOwnProperty(s)?s:i.substr(0,1)}s+=n.substr(0,54)+" "+e.padStart(2," ")+"\n"}else s+=n+"\n"}c=s}let h=Object.keys(t.utilsCls.getHlStructures()).join(",");s.saveFileCls.saveFile(h+"_icn3d_residues."+r,"text",[c])}}clickReload_pngimage(){let e=this.icn3dui;if(e.icn3d,e.bNode)return;let t=this;e.myEventCls.onIds("#"+e.pre+"reload_pngimage","click",(function(s){let i=e.icn3d;s.preventDefault(),e.cfg.notebook||dialog.dialog("close"),e.cfg.notebook?i.resizeCanvasCls.closeDialogs():$(".ui-dialog-content").dialog("close"),i.init();let n=$("#"+e.pre+"pngimage")[0].files[0];if(n){t.fileSupport();let e=new FileReader;e.onload=async function(e){let s=e.target.result;await t.loadPng(s)},e.readAsText(n)}else alert("Please select a file before clicking 'Load'")}))}async loadPng(e,t){let s=this.icn3dui,i=s.icn3d,n="Share Link: ",l=e.indexOf(n),r="Start of state file======\n",o=e.indexOf(r);if(-1==l&&-1==o)alert('Please load a PNG image saved by clicking the menu "File > Save File > iCn3D PNG Image"...');else if(-1!=l){let t=e.substr(l+n.length);s.htmlCls.clickMenuCls.setLogCmd("load iCn3D PNG image "+$("#"+s.pre+"pngimage").val(),!1),window.open(t,"_self")}else if(-1!=o){let n="Start of data file======\n",l=e.indexOf(n);i.bInputfile=-1!=l,i.bInputPNGWithData=i.bInputfile;let a,d=t?t.replace(/;/g,"\n"):"";if(i.bInputfile){let t=e.indexOf("End of data file======\n"),s=e.substr(l+n.length,t-l-n.length);i.InputfileData=i.InputfileData?i.InputfileData+"\nENDMDL\n"+s:s;let c="Start of type file======\n",h=e.indexOf(c),p=e.indexOf("End of type file======\n"),m=e.substr(h+c.length,p-h-c.length-1);i.InputfileType=m;let u=e.indexOf("End of state file======\n");a=e.substr(o+r.length,u-o-r.length),a=decodeURIComponent(a+"\n"+d),"pdb"===m?(await i.pdbParserCls.loadPdbData(s),i.commands=[],i.optsHistory=[]):("mol2"===m?await i.mol2ParserCls.loadMol2Data(s):"sdf"===m?await i.sdfParserCls.loadSdfData(s):"xyz"===m?await i.xyzParserCls.loadXyzData(s):"mmcif"===m&&await i.mmcifParserCls.loadMmcifData(s),i.commands=[],i.optsHistory=[])}else{let t=e.indexOf("End of state file======\n");a=e.substr(o+r.length,t-o-r.length),a=decodeURIComponent(a+"\n"+d),i.commands=[],i.optsHistory=[]}await i.loadScriptCls.loadScript(a,!0),s.htmlCls.clickMenuCls.setLogCmd("load iCn3D PNG image "+$("#"+s.pre+"pngimage").val(),!1)}}fileSupport(){window.File&&window.FileReader&&window.FileList&&window.Blob||alert("The File APIs are not fully supported in this browser.")}getLinkColor(){let e="";return e+=", linkmap: {\n",e+='3: {"type": "peptidebond", "c":""},\n',e+='4: {"type": "ssbond", "c":"FFA500"},\n',e+='5: {"type": "ionic", "c":"0FF"},\n',e+='6: {"type": "ionicInside", "c":"FFF"},\n',e+='11: {"type": "contact", "c":"888"},\n',e+='12: {"type": "contactInside", "c":"FFF"},\n',e+='13: {"type": "hbond", "c":"0F0"},\n',e+='14: {"type": "hbondInside", "c":"FFF"},\n',e+='15: {"type": "clbond", "c":"006400"},\n',e+='17: {"type": "halogen", "c":"F0F"},\n',e+='18: {"type": "halogenInside", "c":"FFF"},\n',e+='19: {"type": "pication", "c":"F00"},\n',e+='20: {"type": "picationInside", "c":"FFF"},\n',e+='21: {"type": "pistacking", "c":"00F"},\n',e+='22: {"type": "pistackingInside", "c":"FFF"}\n',e+="}}\n",', linkmap: {\n3: {"type": "peptidebond", "c":""},\n4: {"type": "ssbond", "c":"FFA500"},\n5: {"type": "ionic", "c":"0FF"},\n6: {"type": "ionicInside", "c":"FFF"},\n11: {"type": "contact", "c":"888"},\n12: {"type": "contactInside", "c":"FFF"},\n13: {"type": "hbond", "c":"0F0"},\n14: {"type": "hbondInside", "c":"FFF"},\n15: {"type": "clbond", "c":"006400"},\n17: {"type": "halogen", "c":"F0F"},\n18: {"type": "halogenInside", "c":"FFF"},\n19: {"type": "pication", "c":"F00"},\n20: {"type": "picationInside", "c":"FFF"},\n21: {"type": "pistacking", "c":"00F"},\n22: {"type": "pistackingInside", "c":"FFF"}\n}}\n'}setCookieForThickness(){let e=this.icn3dui,t=e.icn3d;if(!e.bNode){let e=3650;this.setCookie("lineRadius",t.lineRadius,e),this.setCookie("coilWidth",t.coilWidth,e),this.setCookie("cylinderRadius",t.cylinderRadius,e),this.setCookie("crosslinkRadius",t.crosslinkRadius,e),this.setCookie("traceRadius",t.traceRadius,e),this.setCookie("dotSphereScale",t.dotSphereScale,e),this.setCookie("ribbonthickness",t.ribbonthickness,e),this.setCookie("helixSheetWidth",t.helixSheetWidth,e),this.setCookie("nucleicAcidWidth",t.nucleicAcidWidth,e)}}setLineThickness(e,t){let s=this.icn3dui,i=s.icn3d;if(i.bSetThickness=!0,"style"==e&&(t&&($("#"+s.pre+"shininess").val("40"),$("#"+s.pre+"light1").val("0.8"),$("#"+s.pre+"light2").val("0.4"),$("#"+s.pre+"light3").val("0.2"),$("#"+s.pre+"glycan").val("0"),$("#"+s.pre+"membrane").val("1"),$("#"+s.pre+"cmdwindow").val("0")),i.shininess=parseFloat($("#"+s.pre+"shininess").val()),i.light1=parseFloat($("#"+s.pre+"light1").val()),i.light2=parseFloat($("#"+s.pre+"light2").val()),i.light3=parseFloat($("#"+s.pre+"light3").val()),i.bGlycansCartoon=parseInt($("#"+s.pre+"glycan").val()),i.bMembrane=parseInt($("#"+s.pre+"membrane").val()),i.bCmdWindow=parseInt($("#"+s.pre+"cmdwindow").val())),t&&($("#"+s.pre+"linerad_"+e).val(.1),$("#"+s.pre+"coilrad_"+e).val(.3),$("#"+s.pre+"stickrad_"+e).val(.4),$("#"+s.pre+"crosslinkrad_"+e).val(.4),$("#"+s.pre+"tracerad_"+e).val(.4),$("#"+s.pre+"ballscale_"+e).val(.3),$("#"+s.pre+"ribbonthick_"+e).val(.2),$("#"+s.pre+"prtribbonwidth_"+e).val(1.3),$("#"+s.pre+"nucleotideribbonwidth_"+e).val(.8)),i.lineRadius=parseFloat($("#"+s.pre+"linerad_"+e).val()),i.coilWidth=parseFloat($("#"+s.pre+"coilrad_"+e).val()),i.cylinderRadius=parseFloat($("#"+s.pre+"stickrad_"+e).val()),i.crosslinkRadius=parseFloat($("#"+s.pre+"crosslinkrad_"+e).val()),i.traceRadius=parseFloat($("#"+s.pre+"tracerad_"+e).val()),i.dotSphereScale=parseFloat($("#"+s.pre+"ballscale_"+e).val()),i.ribbonthickness=parseFloat($("#"+s.pre+"ribbonthick_"+e).val()),i.helixSheetWidth=parseFloat($("#"+s.pre+"prtribbonwidth_"+e).val()),i.nucleicAcidWidth=parseFloat($("#"+s.pre+"nucleotideribbonwidth_"+e).val()),!s.bNode){let e=3650;this.setCookie("shininess",i.shininess,e),this.setCookie("light1",i.light1,e),this.setCookie("light2",i.light2,e),this.setCookie("light3",i.light3,e),this.setCookie("glycan",i.bGlycansCartoon,e),this.setCookie("membrane",i.bMembrane,e),this.setCookie("cmdwindow",i.bCmdWindow,e)}if(this.setCookieForThickness(),e=t){let e="reset thickness";s.htmlCls.clickMenuCls.setLogCmd(e,!0),i.bSetThickness=!1,i.threeDPrintCls.resetAfter3Dprint()}else s.htmlCls.clickMenuCls.setLogCmd("set thickness | linerad "+i.lineRadius+" | coilrad "+i.coilWidth+" | stickrad "+i.cylinderRadius+" | crosslinkrad "+i.crosslinkRadius+" | tracerad "+i.traceRadius+" | ribbonthick "+i.ribbonthickness+" | proteinwidth "+i.helixSheetWidth+" | nucleotidewidth "+i.nucleicAcidWidth+" | ballscale "+i.dotSphereScale,!0),s.htmlCls.clickMenuCls.setLogCmd("set glycan "+i.bGlycansCartoon,!0),s.htmlCls.clickMenuCls.setLogCmd("set membrane "+i.bMembrane,!0),s.htmlCls.clickMenuCls.setLogCmd("set cmdwindow "+i.bCmdWindow,!0);i.drawCls.draw()}setCookie(e,t,s){let i=new Date;i.setTime(i.getTime()+24*s*60*60*1e3);let n="expires="+i.toUTCString();document.cookie=e+"="+t+";"+n+";path=/"}updateSurfPara(e){let t=this.icn3dui,s=t.icn3d;s.phisurftype=$("#"+t.pre+e+"surftype").val(),s.phisurfop=$("#"+t.pre+e+"surfop").val(),s.phisurfwf=$("#"+t.pre+e+"surfwf").val()}exportPdb(){let e=this.icn3dui,t=e.icn3d,s="",i=e.hashUtilsCls.intHash(t.dAtoms,t.hAtoms);if(s+=t.saveFileCls.getAtomPDB(i),!e.bNode){let i=Object.keys(e.utilsCls.getHlStructures()).join(",");t.saveFileCls.saveFile(i+"_icn3d.pdb","text",[s])}return s}exportSecondary(){let e=this.icn3dui,t=e.icn3d,s="",i=e.hashUtilsCls.intHash(t.dAtoms,t.hAtoms);if(s+=t.saveFileCls.getSecondary(i),!e.bNode){let i=Object.keys(e.utilsCls.getHlStructures()).join(",");t.saveFileCls.saveFile(i+"_icn3d_ss.txt","text",[s])}return s}}class g{constructor(e){let t=e;this.icn3dui=e,this.cfg=this.icn3dui.cfg,this.opts={},this.opts.background="black",this.allMenus={},this.allMenusSel={},this.simpleMenus={},this.shownMenus={},this.WIDTH=400,this.HEIGHT=400,this.RESIDUE_WIDTH=10,t.utilsCls.isMobile()||this.cfg.mobilemenu?this.MENU_HEIGHT=0:this.MENU_HEIGHT=40,this.LOG_HEIGHT=65,this.MENU_WIDTH=750,this.LESSWIDTH=20,this.LESSWIDTH_RESIZE=20,this.LESSHEIGHT=20,this.width2d=200,this.CMD_HEIGHT=.8*this.LOG_HEIGHT,this.EXTRAHEIGHT=this.MENU_HEIGHT+this.CMD_HEIGHT,null!=this.cfg.showmenu&&0==this.cfg.showmenu&&(this.EXTRAHEIGHT-=this.MENU_HEIGHT),null!=this.cfg.showcommand&&0==this.cfg.showcommand&&(this.EXTRAHEIGHT-=this.CMD_HEIGHT),this.GREY8="#AAAAAA",this.GREYB="#CCCCCC",this.GREYC="#DDDDDD",this.GREYD="#EEEEEE",this.ORANGE="#FFA500",this.themecolor="blue",this.defaultValue=1,this.ssValue=3,this.coilValue=3,this.contactValue=11,this.contactInsideValue=12,this.hbondValue=13,this.hbondInsideValue=14,this.ssbondValue=4,this.ionicValue=5,this.ionicInsideValue=6,this.clbondValue=15,this.halogenValue=17,this.halogenInsideValue=18,this.picationValue=19,this.picationInsideValue=20,this.pistackingValue=21,this.pistackingInsideValue=22,this.contactColor="888",this.contactInsideColor="FFF",this.hbondColor="0F0",this.hbondInsideColor="FFF",this.ssbondColor="FFA500",this.ionicColor="0FF",this.ionicInsideColor="FFF",this.clbondColor="006400",this.halogenColor="F0F",this.halogenInsideColor="FFF",this.picationColor="F00",this.picationInsideColor="FFF",this.pistackingColor="00F",this.pistackingInsideColor="FFF",this.hideedges=1,this.force=4,this.simulation=void 0,this.baseUrl=window&&window.location&&"structure.ncbi.nlm.nih.gov"==window.location.hostname?"https://structure.ncbi.nlm.nih.gov/Structure/":"https://www.ncbi.nlm.nih.gov/Structure/",this.tmalignUrl=this.baseUrl+"tmalign/tmalign.cgi",this.divStr="<div id='"+this.icn3dui.pre,this.divNowrapStr="<div style='white-space:nowrap'>",this.spanNowrapStr="<span style='white-space:nowrap'>",this.inputTextStr="<input type='text' ",this.inputFileStr="<input type='file' ",this.inputRadioStr="<input type='radio' ",this.inputCheckStr="<input type='checkbox' ",this.optionStr="<option value=",this.buttonStr="<button id='"+this.icn3dui.pre,this.postfix="2",this.space2="&nbsp;&nbsp;",this.space3=this.space2+"&nbsp;",this.space4=this.space2+this.space2,this.wifiStr="",this.licenseStr="",this.closeAc={collapsible:!0,active:!1},this.clickMenuCls=new a(this.icn3dui),this.setMenuCls=new d(this.icn3dui),this.dialogCls=new c(this.icn3dui),this.setDialogCls=new h(this.icn3dui),this.eventsCls=new p(this.icn3dui),this.alignSeqCls=new m(this.icn3dui),this.setHtmlCls=new u(this.icn3dui)}}class f extends THREE.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new _(e)})),this.register((function(e){return new O(e)})),this.register((function(e){return new R(e)})),this.register((function(e){return new w(e)})),this.register((function(e){return new S(e)})),this.register((function(e){return new A(e)})),this.register((function(e){return new x(e)})),this.register((function(e){return new k(e)})),this.register((function(e){return new y(e)})),this.register((function(e){return new I(e)}))}load(e,t,s,i){const n=this;let l;l=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:THREE.LoaderUtils.extractUrlBase(e),this.manager.itemStart(e);const r=function(t){i?i(t):console.error(t),n.manager.itemError(e),n.manager.itemEnd(e)},o=new THREE.FileLoader(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,(function(s){try{n.parse(s,l,(function(s){t(s),n.manager.itemEnd(e)}),r)}catch(e){r(e)}}),s,r)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,i){let n;const l={},r={};if("string"==typeof e)n=e;else{if(THREE.LoaderUtils.decodeText(new Uint8Array(e,0,4))===E){try{l[b.KHR_BINARY_GLTF]=new D(e)}catch(e){return void(i&&i(e))}n=l[b.KHR_BINARY_GLTF].content}else n=THREE.LoaderUtils.decodeText(new Uint8Array(e))}const o=JSON.parse(n);if(void 0===o.asset||o.asset.version[0]<2)return void(i&&i(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const a=new pe(o,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});a.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](a);r[t.name]=t,l[t.name]=!0}if(o.extensionsUsed)for(let e=0;e<o.extensionsUsed.length;++e){const t=o.extensionsUsed[e],s=o.extensionsRequired||[];switch(t){case b.KHR_MATERIALS_UNLIT:l[t]=new v;break;case b.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new L;break;case b.KHR_DRACO_MESH_COMPRESSION:l[t]=new M(o,this.dracoLoader);break;case b.KHR_TEXTURE_TRANSFORM:l[t]=new F;break;case b.KHR_MESH_QUANTIZATION:l[t]=new N;break;default:s.indexOf(t)>=0&&void 0===r[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}a.setExtensions(l),a.setPlugins(r),a.parse(s,i)}parseAsync(e,t){const s=this;return new Promise((function(i,n){s.parse(e,t,i,n)}))}}function C(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const b={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class y{constructor(e){this.parser=e,this.name=b.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,i=t.length;s<i;s++){const i=t[s];i.extensions&&i.extensions[this.name]&&void 0!==i.extensions[this.name].light&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let i=t.cache.get(s);if(i)return i;const n=t.json,l=((n.extensions&&n.extensions[this.name]||{}).lights||[])[e];let r;const o=new Color(16777215);void 0!==l.color&&o.fromArray(l.color);const a=void 0!==l.range?l.range:0;switch(l.type){case"directional":r=new DirectionalLight(o),r.target.position.set(0,0,-1),r.add(r.target);break;case"point":r=new PointLight(o),r.distance=a;break;case"spot":r=new SpotLight(o),r.distance=a,l.spot=l.spot||{},l.spot.innerConeAngle=void 0!==l.spot.innerConeAngle?l.spot.innerConeAngle:0,l.spot.outerConeAngle=void 0!==l.spot.outerConeAngle?l.spot.outerConeAngle:Math.PI/4,r.angle=l.spot.outerConeAngle,r.penumbra=1-l.spot.innerConeAngle/l.spot.outerConeAngle,r.target.position.set(0,0,-1),r.add(r.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+l.type)}return r.position.set(0,0,0),r.decay=2,void 0!==l.intensity&&(r.intensity=l.intensity),r.name=t.createUniqueName(l.name||"light_"+e),i=Promise.resolve(r),t.cache.add(s,i),i}createNodeAttachment(e){const t=this,s=this.parser,i=s.json.nodes[e],n=(i.extensions&&i.extensions[this.name]||{}).light;return void 0===n?null:this._loadLight(n).then((function(e){return s._getNodeRef(t.cache,n,e)}))}}class v{constructor(){this.name=b.KHR_MATERIALS_UNLIT}getMaterialType(){return MeshBasicMaterial}extendParams(e,t,s){const i=[];e.color=new Color(1,1,1),e.opacity=1;const n=t.pbrMetallicRoughness;if(n){if(Array.isArray(n.baseColorFactor)){const t=n.baseColorFactor;e.color.fromArray(t),e.opacity=t[3]}void 0!==n.baseColorTexture&&i.push(s.assignTexture(e,"map",n.baseColorTexture,sRGBEncoding))}return Promise.all(i)}}class _{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const n=[],l=i.extensions[this.name];if(void 0!==l.clearcoatFactor&&(t.clearcoat=l.clearcoatFactor),void 0!==l.clearcoatTexture&&n.push(s.assignTexture(t,"clearcoatMap",l.clearcoatTexture)),void 0!==l.clearcoatRoughnessFactor&&(t.clearcoatRoughness=l.clearcoatRoughnessFactor),void 0!==l.clearcoatRoughnessTexture&&n.push(s.assignTexture(t,"clearcoatRoughnessMap",l.clearcoatRoughnessTexture)),void 0!==l.clearcoatNormalTexture&&(n.push(s.assignTexture(t,"clearcoatNormalMap",l.clearcoatNormalTexture)),void 0!==l.clearcoatNormalTexture.scale)){const e=l.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new Vector2(e,e)}return Promise.all(n)}}class w{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_SHEEN}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const n=[];t.sheenColor=new Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const l=i.extensions[this.name];return void 0!==l.sheenColorFactor&&t.sheenColor.fromArray(l.sheenColorFactor),void 0!==l.sheenRoughnessFactor&&(t.sheenRoughness=l.sheenRoughnessFactor),void 0!==l.sheenColorTexture&&n.push(s.assignTexture(t,"sheenColorMap",l.sheenColorTexture,sRGBEncoding)),void 0!==l.sheenRoughnessTexture&&n.push(s.assignTexture(t,"sheenRoughnessMap",l.sheenRoughnessTexture)),Promise.all(n)}}class S{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const n=[],l=i.extensions[this.name];return void 0!==l.transmissionFactor&&(t.transmission=l.transmissionFactor),void 0!==l.transmissionTexture&&n.push(s.assignTexture(t,"transmissionMap",l.transmissionTexture)),Promise.all(n)}}class A{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_VOLUME}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const n=[],l=i.extensions[this.name];t.thickness=void 0!==l.thicknessFactor?l.thicknessFactor:0,void 0!==l.thicknessTexture&&n.push(s.assignTexture(t,"thicknessMap",l.thicknessTexture)),t.attenuationDistance=l.attenuationDistance||0;const r=l.attenuationColor||[1,1,1];return t.attenuationColor=new Color(r[0],r[1],r[2]),Promise.all(n)}}class x{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_IOR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const i=s.extensions[this.name];return t.ior=void 0!==i.ior?i.ior:1.5,Promise.resolve()}}class k{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_SPECULAR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,i=s.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const n=[],l=i.extensions[this.name];t.specularIntensity=void 0!==l.specularFactor?l.specularFactor:1,void 0!==l.specularTexture&&n.push(s.assignTexture(t,"specularIntensityMap",l.specularTexture));const r=l.specularColorFactor||[1,1,1];return t.specularColor=new Color(r[0],r[1],r[2]),void 0!==l.specularColorTexture&&n.push(s.assignTexture(t,"specularColorMap",l.specularColorTexture,sRGBEncoding)),Promise.all(n)}}class O{constructor(e){this.parser=e,this.name=b.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,i=s.textures[e];if(!i.extensions||!i.extensions[this.name])return null;const n=i.extensions[this.name],l=t.options.ktx2Loader;if(!l){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,n.source,l)}}class R{constructor(e){this.parser=e,this.name=b.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,i=s.json,n=i.textures[e];if(!n.extensions||!n.extensions[t])return null;const l=n.extensions[t],r=i.images[l.source];let o=s.textureLoader;if(r.uri){const e=s.options.manager.getHandler(r.uri);null!==e&&(o=e)}return this.detectSupport().then((function(n){if(n)return s.loadTextureImage(e,l.source,o);if(i.extensionsRequired&&i.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return s.loadTexture(e)}))}detectSupport(){return this.isSupported||(this.isSupported=new Promise((function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}}))),this.isSupported}}class I{constructor(e){this.name=b.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const e=s.extensions[this.name],i=this.parser.getDependency("buffer",e.buffer),n=this.parser.options.meshoptDecoder;if(!n||!n.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return Promise.all([i,n.ready]).then((function(t){const s=e.byteOffset||0,i=e.byteLength||0,l=e.count,r=e.byteStride,o=new ArrayBuffer(l*r),a=new Uint8Array(t[0],s,i);return n.decodeGltfBuffer(new Uint8Array(o),l,r,a,e.mode,e.filter),o}))}return null}}const E="glTF",T=1313821514,P=5130562;class D{constructor(e){this.name=b.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,12);if(this.header={magic:THREE.LoaderUtils.decodeText(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==E)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const s=this.header.length-12,i=new DataView(e,12);let n=0;for(;n<s;){const t=i.getUint32(n,!0);n+=4;const s=i.getUint32(n,!0);if(n+=4,s===T){const s=new Uint8Array(e,12+n,t);this.content=THREE.LoaderUtils.decodeText(s)}else if(s===P){const s=12+n;this.body=e.slice(s,s+t)}n+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class M{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=b.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,i=this.dracoLoader,n=e.extensions[this.name].bufferView,l=e.extensions[this.name].attributes,r={},o={},a={};for(const e in l){const t=ee[e]||e.toLowerCase();r[t]=l[e]}for(const t in e.attributes){const i=ee[t]||t.toLowerCase();if(void 0!==l[t]){const n=s.accessors[e.attributes[t]],l=K[n.componentType];a[i]=l,o[i]=!0===n.normalized}}return t.getDependency("bufferView",n).then((function(e){return new Promise((function(t){i.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],i=o[t];void 0!==i&&(s.normalized=i)}t(e)}),r,a)}))}))}}class F{constructor(){this.name=b.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class H extends THREE.MeshStandardMaterial{constructor(e){super(),this.isGLTFSpecularGlossinessMaterial=!0;const t=["#ifdef USE_SPECULARMAP"," uniform sampler2D specularMap;","#endif"].join("\n"),s=["#ifdef USE_GLOSSINESSMAP"," uniform sampler2D glossinessMap;","#endif"].join("\n"),i=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP"," vec4 texelSpecular = texture2D( specularMap, vUv );"," // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture"," specularFactor *= texelSpecular.rgb;","#endif"].join("\n"),n=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP"," vec4 texelGlossiness = texture2D( glossinessMap, vUv );"," // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture"," glossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),l=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),r={specular:{value:(new Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=r,this.onBeforeCompile=function(e){for(const t in r)e.uniforms[t]=r[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",t).replace("#include <metalnessmap_pars_fragment>",s).replace("#include <roughnessmap_fragment>",i).replace("#include <metalnessmap_fragment>",n).replace("#include <lights_physical_fragment>",l)},Object.defineProperties(this,{specular:{get:function(){return r.specular.value},set:function(e){r.specular.value=e}},specularMap:{get:function(){return r.specularMap.value},set:function(e){r.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return r.glossiness.value},set:function(e){r.glossiness.value=e}},glossinessMap:{get:function(){return r.glossinessMap.value},set:function(e){r.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(e)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class L{constructor(){this.name=b.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity"]}getMaterialType(){return H}extendParams(e,t,s){const i=t.extensions[this.name];e.color=new Color(1,1,1),e.opacity=1;const n=[];if(Array.isArray(i.diffuseFactor)){const t=i.diffuseFactor;e.color.fromArray(t),e.opacity=t[3]}if(void 0!==i.diffuseTexture&&n.push(s.assignTexture(e,"map",i.diffuseTexture,sRGBEncoding)),e.emissive=new Color(0,0,0),e.glossiness=void 0!==i.glossinessFactor?i.glossinessFactor:1,e.specular=new Color(1,1,1),Array.isArray(i.specularFactor)&&e.specular.fromArray(i.specularFactor),void 0!==i.specularGlossinessTexture){const t=i.specularGlossinessTexture;n.push(s.assignTexture(e,"glossinessMap",t)),n.push(s.assignTexture(e,"specularMap",t,sRGBEncoding))}return Promise.all(n)}createMaterial(e){const t=new H(e);return t.fog=!0,t.color=e.color,t.map=void 0===e.map?null:e.map,t.lightMap=null,t.lightMapIntensity=1,t.aoMap=void 0===e.aoMap?null:e.aoMap,t.aoMapIntensity=1,t.emissive=e.emissive,t.emissiveIntensity=1,t.emissiveMap=void 0===e.emissiveMap?null:e.emissiveMap,t.bumpMap=void 0===e.bumpMap?null:e.bumpMap,t.bumpScale=1,t.normalMap=void 0===e.normalMap?null:e.normalMap,t.normalMapType=TangentSpaceNormalMap,e.normalScale&&(t.normalScale=e.normalScale),t.displacementMap=null,t.displacementScale=1,t.displacementBias=0,t.specularMap=void 0===e.specularMap?null:e.specularMap,t.specular=e.specular,t.glossinessMap=void 0===e.glossinessMap?null:e.glossinessMap,t.glossiness=e.glossiness,t.alphaMap=null,t.envMap=void 0===e.envMap?null:e.envMap,t.envMapIntensity=1,t}}class N{constructor(){this.name=b.KHR_MESH_QUANTIZATION}}class q extends THREE.Interpolant{constructor(e,t,s,i){super(e,t,s,i)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,i=this.valueSize,n=e*i*3+i;for(let e=0;e!==i;e++)t[e]=s[n+e];return t}}q.prototype.beforeStart_=q.prototype.copySampleValue_,q.prototype.afterEnd_=q.prototype.copySampleValue_,q.prototype.interpolate_=function(e,t,s,i){const n=this.resultBuffer,l=this.sampleValues,r=this.valueSize,o=2*r,a=3*r,d=i-t,c=(s-t)/d,h=c*c,p=h*c,m=e*a,u=m-a,g=-2*p+3*h,f=p-h,C=1-g,b=f-h+c;for(let e=0;e!==r;e++){const t=l[u+e+r],s=l[u+e+o]*d,i=l[m+e+r],a=l[m+e]*d;n[e]=C*t+b*s+g*i+f*a}return n};const U=new THREE.Quaternion;class B extends q{interpolate_(e,t,s,i){const n=super.interpolate_(e,t,s,i);return U.fromArray(n).normalize().toArray(n),n}}const j=0,z=1,G=2,V=3,W=4,Y=5,X=6,K={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},J={9728:THREE.NearestFilter,9729:THREE.LinearFilter,9984:THREE.NearestMipmapNearestFilter,9985:THREE.LinearMipmapNearestFilter,9986:THREE.NearestMipmapLinearFilter,9987:THREE.LinearMipmapLinearFilter},Z={33071:THREE.ClampToEdgeWrapping,33648:THREE.MirroredRepeatWrapping,10497:THREE.RepeatWrapping},Q={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},ee={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},te={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},se={CUBICSPLINE:void 0,LINEAR:THREE.InterpolateLinear,STEP:THREE.InterpolateDiscrete},ie="OPAQUE",ne="MASK",le="BLEND";function re(e,t,s){for(const i in s.extensions)void 0===e[i]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[i]=s.extensions[i])}function oe(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function ae(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,i=t.weights.length;s<i;s++)e.morphTargetInfluences[s]=t.weights[s];if(t.extras&&Array.isArray(t.extras.targetNames)){const s=t.extras.targetNames;if(e.morphTargetInfluences.length===s.length){e.morphTargetDictionary={};for(let t=0,i=s.length;t<i;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function de(e){const t=e.extensions&&e.extensions[b.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+ce(t.attributes):e.indices+":"+ce(e.attributes)+":"+e.mode,s}function ce(e){let t="";const s=Object.keys(e).sort();for(let i=0,n=s.length;i<n;i++)t+=s[i]+":"+e[s[i]]+";";return t}function he(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}class pe{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new C,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={},"undefined"!=typeof createImageBitmap&&!1===/^((?!chrome|android).)*safari/i.test(navigator.userAgent)?this.textureLoader=new ImageBitmapLoader(this.options.manager):this.textureLoader=new TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new THREE.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,i=this.json,n=this.extensions;this.cache.removeAll(),this._invokeAll((function(e){return e._markDefs&&e._markDefs()})),Promise.all(this._invokeAll((function(e){return e.beforeRoot&&e.beforeRoot()}))).then((function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])})).then((function(t){const l={scene:t[0][i.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:i.asset,parser:s,userData:{}};re(n,l,i),oe(l,i),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(l)}))).then((function(){e(l)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,i=t.length;s<i;s++){const i=t[s].joints;for(let t=0,s=i.length;t<s;t++)e[i[t]].isBone=!0}for(let t=0,i=e.length;t<i;t++){const i=e[t];void 0!==i.mesh&&(this._addNodeRef(this.meshCache,i.mesh),void 0!==i.skin&&(s[i.mesh].isSkinnedMesh=!0)),void 0!==i.camera&&this._addNodeRef(this.cameraCache,i.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const i=s.clone(),n=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,i]of e.children.entries())n(i,t.children[s])};return n(s,i),i.name+="_instance_"+e.uses[t]++,i}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const i=e(t[s]);if(i)return i}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let i=0;i<t.length;i++){const n=e(t[i]);n&&s.push(n)}return s}getDependency(e,t){const s=e+":"+t;let i=this.cache.get(s);if(!i){switch(e){case"scene":i=this.loadScene(t);break;case"node":i=this.loadNode(t);break;case"mesh":i=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":i=this.loadAccessor(t);break;case"bufferView":i=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":i=this.loadBuffer(t);break;case"material":i=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":i=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":i=this.loadSkin(t);break;case"animation":i=this.loadAnimation(t);break;case"camera":i=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,i)}return i}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,i=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(i.map((function(t,i){return s.getDependency(e,i)}))),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&"arraybuffer"!==t.type)throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(void 0===t.uri&&0===e)return Promise.resolve(this.extensions[b.KHR_BINARY_GLTF].body);const i=this.options;return new Promise((function(e,n){s.load(THREE.LoaderUtils.resolveURL(t.uri,i.path),e,void 0,(function(){n(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))}))}))}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then((function(e){const s=t.byteLength||0,i=t.byteOffset||0;return e.slice(i,i+s)}))}loadAccessor(e){const t=this,s=this.json,i=this.json.accessors[e];if(void 0===i.bufferView&&void 0===i.sparse)return Promise.resolve(null);const n=[];return void 0!==i.bufferView?n.push(this.getDependency("bufferView",i.bufferView)):n.push(null),void 0!==i.sparse&&(n.push(this.getDependency("bufferView",i.sparse.indices.bufferView)),n.push(this.getDependency("bufferView",i.sparse.values.bufferView))),Promise.all(n).then((function(e){const n=e[0],l=Q[i.type],r=K[i.componentType],o=r.BYTES_PER_ELEMENT,a=o*l,d=i.byteOffset||0,c=void 0!==i.bufferView?s.bufferViews[i.bufferView].byteStride:void 0,h=!0===i.normalized;let p,m;if(c&&c!==a){const e=Math.floor(d/c),s="InterleavedBuffer:"+i.bufferView+":"+i.componentType+":"+e+":"+i.count;let a=t.cache.get(s);a||(p=new r(n,e*c,i.count*c/o),a=new InterleavedBuffer(p,c/o),t.cache.add(s,a)),m=new InterleavedBufferAttribute(a,l,d%c/o,h)}else p=null===n?new r(i.count*l):new r(n,d,i.count*l),m=new BufferAttribute(p,l,h);if(void 0!==i.sparse){const t=Q.SCALAR,s=K[i.sparse.indices.componentType],o=i.sparse.indices.byteOffset||0,a=i.sparse.values.byteOffset||0,d=new s(e[1],o,i.sparse.count*t),c=new r(e[2],a,i.sparse.count*l);null!==n&&(m=new BufferAttribute(m.array.slice(),m.itemSize,m.normalized));for(let e=0,t=d.length;e<t;e++){const t=d[e];if(m.setX(t,c[e*l]),l>=2&&m.setY(t,c[e*l+1]),l>=3&&m.setZ(t,c[e*l+2]),l>=4&&m.setW(t,c[e*l+3]),l>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,n=t.images[i];let l=this.textureLoader;if(n.uri){const e=s.manager.getHandler(n.uri);null!==e&&(l=e)}return this.loadTextureImage(e,i,l)}loadTextureImage(e,t,s){const i=this,n=this.json,l=n.textures[e],r=n.images[t],o=(r.uri||r.bufferView)+":"+l.sampler;if(this.textureCache[o])return this.textureCache[o];const a=this.loadImageSource(t,s).then((function(t){t.flipY=!1,l.name&&(t.name=l.name);const s=(n.samplers||{})[l.sampler]||{};return t.magFilter=J[s.magFilter]||LinearFilter,t.minFilter=J[s.minFilter]||LinearMipmapLinearFilter,t.wrapS=Z[s.wrapS]||RepeatWrapping,t.wrapT=Z[s.wrapT]||RepeatWrapping,i.associations.set(t,{textures:e}),t})).catch((function(){return null}));return this.textureCache[o]=a,a}loadImageSource(e,t){const s=this,i=this.json,n=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then((e=>e.clone()));const l=i.images[e],r=self.URL||self.webkitURL;let o=l.uri||"",a=!1;if(void 0!==l.bufferView)o=s.getDependency("bufferView",l.bufferView).then((function(e){a=!0;const t=new Blob([e],{type:l.mimeType});return o=r.createObjectURL(t),o}));else if(void 0===l.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const d=Promise.resolve(o).then((function(e){return new Promise((function(s,i){let l=s;!0===t.isImageBitmapLoader&&(l=function(e){const t=new Texture(e);t.needsUpdate=!0,s(t)}),t.load(THREE.LoaderUtils.resolveURL(e,n.path),l,void 0,i)}))})).then((function(e){var t;return!0===a&&r.revokeObjectURL(o),e.userData.mimeType=l.mimeType||((t=l.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e})).catch((function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),e}));return this.sourceCache[e]=d,d}assignTexture(e,t,s,i){const n=this;return this.getDependency("texture",s.index).then((function(l){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),n.extensions[b.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[b.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=n.associations.get(l);l=n.extensions[b.KHR_TEXTURE_TRANSFORM].extendTexture(l,e),n.associations.set(l,t)}}return void 0!==i&&(l.encoding=i),e[t]=l,l}))}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const i=void 0===t.attributes.tangent,n=void 0!==t.attributes.color,l=void 0===t.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+s.uuid;let t=this.cache.get(e);t||(t=new PointsMaterial,Material.prototype.copy.call(t,s),t.color.copy(s.color),t.map=s.map,t.sizeAttenuation=!1,this.cache.add(e,t)),s=t}else if(e.isLine){const e="LineBasicMaterial:"+s.uuid;let t=this.cache.get(e);t||(t=new LineBasicMaterial,Material.prototype.copy.call(t,s),t.color.copy(s.color),this.cache.add(e,t)),s=t}if(i||n||l){let e="ClonedMaterial:"+s.uuid+":";s.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),i&&(e+="derivative-tangents:"),n&&(e+="vertex-colors:"),l&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=s.clone(),n&&(t.vertexColors=!0),l&&(t.flatShading=!0),i&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(s))),s=t}s.aoMap&&void 0===t.attributes.uv2&&void 0!==t.attributes.uv&&t.setAttribute("uv2",t.attributes.uv),e.material=s}getMaterialType(){return MeshStandardMaterial}loadMaterial(e){const t=this,s=this.json,i=this.extensions,n=s.materials[e];let l;const r={},o=n.extensions||{},a=[];if(o[b.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=i[b.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];l=e.getMaterialType(),a.push(e.extendParams(r,n,t))}else if(o[b.KHR_MATERIALS_UNLIT]){const e=i[b.KHR_MATERIALS_UNLIT];l=e.getMaterialType(),a.push(e.extendParams(r,n,t))}else{const s=n.pbrMetallicRoughness||{};if(r.color=new Color(1,1,1),r.opacity=1,Array.isArray(s.baseColorFactor)){const e=s.baseColorFactor;r.color.fromArray(e),r.opacity=e[3]}void 0!==s.baseColorTexture&&a.push(t.assignTexture(r,"map",s.baseColorTexture,sRGBEncoding)),r.metalness=void 0!==s.metallicFactor?s.metallicFactor:1,r.roughness=void 0!==s.roughnessFactor?s.roughnessFactor:1,void 0!==s.metallicRoughnessTexture&&(a.push(t.assignTexture(r,"metalnessMap",s.metallicRoughnessTexture)),a.push(t.assignTexture(r,"roughnessMap",s.metallicRoughnessTexture))),l=this._invokeOne((function(t){return t.getMaterialType&&t.getMaterialType(e)})),a.push(Promise.all(this._invokeAll((function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,r)}))))}!0===n.doubleSided&&(r.side=DoubleSide);const d=n.alphaMode||ie;if(d===le?(r.transparent=!0,r.depthWrite=!1):(r.transparent=!1,d===ne&&(r.alphaTest=void 0!==n.alphaCutoff?n.alphaCutoff:.5)),void 0!==n.normalTexture&&l!==MeshBasicMaterial&&(a.push(t.assignTexture(r,"normalMap",n.normalTexture)),r.normalScale=new Vector2(1,1),void 0!==n.normalTexture.scale)){const e=n.normalTexture.scale;r.normalScale.set(e,e)}return void 0!==n.occlusionTexture&&l!==MeshBasicMaterial&&(a.push(t.assignTexture(r,"aoMap",n.occlusionTexture)),void 0!==n.occlusionTexture.strength&&(r.aoMapIntensity=n.occlusionTexture.strength)),void 0!==n.emissiveFactor&&l!==MeshBasicMaterial&&(r.emissive=(new Color).fromArray(n.emissiveFactor)),void 0!==n.emissiveTexture&&l!==MeshBasicMaterial&&a.push(t.assignTexture(r,"emissiveMap",n.emissiveTexture,sRGBEncoding)),Promise.all(a).then((function(){let s;return s=l===H?i[b.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(r):new l(r),n.name&&(s.name=n.name),oe(s,n),t.associations.set(s,{materials:e}),n.extensions&&re(i,s,n),s}))}createUniqueName(e){const t=PropertyBinding.sanitizeNodeName(e||"");let s=t;for(let e=1;this.nodeNamesUsed[s];++e)s=t+"_"+e;return this.nodeNamesUsed[s]=!0,s}loadGeometries(e){const t=this,s=this.extensions,i=this.primitiveCache;function n(e){return s[b.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then((function(s){return ue(s,e,t)}))}const l=[];for(let s=0,r=e.length;s<r;s++){const r=e[s],o=de(r),a=i[o];if(a)l.push(a.promise);else{let e;e=r.extensions&&r.extensions[b.KHR_DRACO_MESH_COMPRESSION]?n(r):ue(new BufferGeometry,r,t),i[o]={primitive:r,promise:e},l.push(e)}}return Promise.all(l)}loadMesh(e){const t=this,s=this.json,i=this.extensions,n=s.meshes[e],l=n.primitives,r=[];for(let e=0,t=l.length;e<t;e++){const t=void 0===l[e].material?(void 0===(o=this.cache).DefaultMaterial&&(o.DefaultMaterial=new MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:FrontSide})),o.DefaultMaterial):this.getDependency("material",l[e].material);r.push(t)}var o;return r.push(t.loadGeometries(l)),Promise.all(r).then((function(s){const r=s.slice(0,s.length-1),o=s[s.length-1],a=[];for(let s=0,d=o.length;s<d;s++){const d=o[s],c=l[s];let h;const p=r[s];if(c.mode===W||c.mode===Y||c.mode===X||void 0===c.mode)h=!0===n.isSkinnedMesh?new SkinnedMesh(d,p):new Mesh(d,p),!0!==h.isSkinnedMesh||h.geometry.attributes.skinWeight.normalized||h.normalizeSkinWeights(),c.mode===Y?h.geometry=ge(h.geometry,TriangleStripDrawMode):c.mode===X&&(h.geometry=ge(h.geometry,TriangleFanDrawMode));else if(c.mode===z)h=new LineSegments(d,p);else if(c.mode===V)h=new Line(d,p);else if(c.mode===G)h=new LineLoop(d,p);else{if(c.mode!==j)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+c.mode);h=new Points(d,p)}Object.keys(h.geometry.morphAttributes).length>0&&ae(h,n),h.name=t.createUniqueName(n.name||"mesh_"+e),oe(h,n),c.extensions&&re(i,h,c),t.assignFinalMaterial(h),a.push(h)}for(let s=0,i=a.length;s<i;s++)t.associations.set(a[s],{meshes:e,primitives:s});if(1===a.length)return a[0];const d=new Group;t.associations.set(d,{meshes:e});for(let e=0,t=a.length;e<t;e++)d.add(a[e]);return d}))}loadCamera(e){let t;const s=this.json.cameras[e],i=s[s.type];if(i)return"perspective"===s.type?t=new PerspectiveCamera(MathUtils.radToDeg(i.yfov),i.aspectRatio||1,i.znear||1,i.zfar||2e6):"orthographic"===s.type&&(t=new OrthographicCamera(-i.xmag,i.xmag,i.ymag,-i.ymag,i.znear,i.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),oe(t,s),Promise.resolve(t);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(e){const t=this.json.animations[e],s=[],i=[],n=[],l=[],r=[];for(let e=0,o=t.channels.length;e<o;e++){const o=t.channels[e],a=t.samplers[o.sampler],d=o.target,c=void 0!==d.node?d.node:d.id,h=void 0!==t.parameters?t.parameters[a.input]:a.input,p=void 0!==t.parameters?t.parameters[a.output]:a.output;s.push(this.getDependency("node",c)),i.push(this.getDependency("accessor",h)),n.push(this.getDependency("accessor",p)),l.push(a),r.push(d)}return Promise.all([Promise.all(s),Promise.all(i),Promise.all(n),Promise.all(l),Promise.all(r)]).then((function(s){const i=s[0],n=s[1],l=s[2],r=s[3],o=s[4],a=[];for(let e=0,t=i.length;e<t;e++){const t=i[e],s=n[e],d=l[e],c=r[e],h=o[e];if(void 0===t)continue;let p;switch(t.updateMatrix(),t.matrixAutoUpdate=!0,te[h.path]){case te.weights:p=NumberKeyframeTrack;break;case te.rotation:p=QuaternionKeyframeTrack;break;default:p=VectorKeyframeTrack}const m=t.name?t.name:t.uuid,u=void 0!==c.interpolation?se[c.interpolation]:InterpolateLinear,g=[];te[h.path]===te.weights?t.traverse((function(e){e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let f=d.array;if(d.normalized){const e=he(f.constructor),t=new Float32Array(f.length);for(let s=0,i=f.length;s<i;s++)t[s]=f[s]*e;f=t}for(let e=0,t=g.length;e<t;e++){const t=new p(g[e]+"."+te[h.path],s.array,f,u);"CUBICSPLINE"===c.interpolation&&(t.createInterpolant=function(e){return new(this instanceof QuaternionKeyframeTrack?B:q)(this.times,this.values,this.getValueSize()/3,e)},t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),a.push(t)}}const d=t.name?t.name:"animation_"+e;return new AnimationClip(d,void 0,a)}))}createNodeMesh(e){const t=this.json,s=this,i=t.nodes[e];return void 0===i.mesh?null:s.getDependency("mesh",i.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,i.mesh,e);return void 0!==i.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=i.weights.length;t<s;t++)e.morphTargetInfluences[t]=i.weights[t]})),t}))}loadNode(e){const t=this.json,s=this.extensions,i=this,n=t.nodes[e],l=n.name?i.createUniqueName(n.name):"";return function(){const t=[],s=i._invokeOne((function(t){return t.createNodeMesh&&t.createNodeMesh(e)}));return s&&t.push(s),void 0!==n.camera&&t.push(i.getDependency("camera",n.camera).then((function(e){return i._getNodeRef(i.cameraCache,n.camera,e)}))),i._invokeAll((function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)})).forEach((function(e){t.push(e)})),Promise.all(t)}().then((function(t){let r;if(r=!0===n.isBone?new Bone:t.length>1?new Group:1===t.length?t[0]:new Object3D,r!==t[0])for(let e=0,s=t.length;e<s;e++)r.add(t[e]);if(n.name&&(r.userData.name=n.name,r.name=l),oe(r,n),n.extensions&&re(s,r,n),void 0!==n.matrix){const e=new Matrix4;e.fromArray(n.matrix),r.applyMatrix4(e)}else void 0!==n.translation&&r.position.fromArray(n.translation),void 0!==n.rotation&&r.quaternion.fromArray(n.rotation),void 0!==n.scale&&r.scale.fromArray(n.scale);return i.associations.has(r)||i.associations.set(r,{}),i.associations.get(r).nodes=e,r}))}loadScene(e){const t=this.json,s=this.extensions,i=this.json.scenes[e],n=this,l=new Group;i.name&&(l.name=n.createUniqueName(i.name)),oe(l,i),i.extensions&&re(s,l,i);const r=i.nodes||[],o=[];for(let e=0,s=r.length;e<s;e++)o.push(me(r[e],l,t,n));return Promise.all(o).then((function(){return n.associations=(e=>{const t=new Map;for(const[e,s]of n.associations)(e instanceof Material||e instanceof Texture)&&t.set(e,s);return e.traverse((e=>{const s=n.associations.get(e);null!=s&&t.set(e,s)})),t})(l),l}))}}function me(e,t,s,i){const n=s.nodes[e];return i.getDependency("node",e).then((function(e){if(void 0===n.skin)return e;let t;return i.getDependency("skin",n.skin).then((function(e){t=e;const s=[];for(let e=0,n=t.joints.length;e<n;e++)s.push(i.getDependency("node",t.joints[e]));return Promise.all(s)})).then((function(s){return e.traverse((function(e){if(!e.isMesh)return;const i=[],n=[];for(let e=0,l=s.length;e<l;e++){const l=s[e];if(l){i.push(l);const s=new Matrix4;void 0!==t.inverseBindMatrices&&s.fromArray(t.inverseBindMatrices.array,16*e),n.push(s)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[e])}e.bind(new Skeleton(i,n),e.matrixWorld)})),e}))})).then((function(e){t.add(e);const l=[];if(n.children){const t=n.children;for(let n=0,r=t.length;n<r;n++){const r=t[n];l.push(me(r,e,s,i))}}return Promise.all(l)}))}function ue(e,t,s){const i=t.attributes,n=[];function l(t,i){return s.getDependency("accessor",t).then((function(t){e.setAttribute(i,t)}))}for(const t in i){const s=ee[t]||t.toLowerCase();s in e.attributes||n.push(l(i[t],s))}if(void 0!==t.indices&&!e.index){const i=s.getDependency("accessor",t.indices).then((function(t){e.setIndex(t)}));n.push(i)}return oe(e,t),function(e,t,s){const i=t.attributes,n=new Box3;if(void 0===i.POSITION)return;{const e=s.json.accessors[i.POSITION],t=e.min,l=e.max;if(void 0===t||void 0===l)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(n.set(new Vector3(t[0],t[1],t[2]),new Vector3(l[0],l[1],l[2])),e.normalized){const t=he(K[e.componentType]);n.min.multiplyScalar(t),n.max.multiplyScalar(t)}}const l=t.targets;if(void 0!==l){const e=new Vector3,t=new Vector3;for(let i=0,n=l.length;i<n;i++){const n=l[i];if(void 0!==n.POSITION){const i=s.json.accessors[n.POSITION],l=i.min,r=i.max;if(void 0!==l&&void 0!==r){if(t.setX(Math.max(Math.abs(l[0]),Math.abs(r[0]))),t.setY(Math.max(Math.abs(l[1]),Math.abs(r[1]))),t.setZ(Math.max(Math.abs(l[2]),Math.abs(r[2]))),i.normalized){const e=he(K[i.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(e)}e.boundingBox=n;const r=new Sphere;n.getCenter(r.center),r.radius=n.min.distanceTo(n.max)/2,e.boundingSphere=r}(e,t,s),Promise.all(n).then((function(){return void 0!==t.targets?function(e,t,s){let i=!1,n=!1,l=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(i=!0),void 0!==s.NORMAL&&(n=!0),void 0!==s.COLOR_0&&(l=!0),i&&n&&l)break}if(!i&&!n&&!l)return Promise.resolve(e);const r=[],o=[],a=[];for(let d=0,c=t.length;d<c;d++){const c=t[d];if(i){const t=void 0!==c.POSITION?s.getDependency("accessor",c.POSITION):e.attributes.position;r.push(t)}if(n){const t=void 0!==c.NORMAL?s.getDependency("accessor",c.NORMAL):e.attributes.normal;o.push(t)}if(l){const t=void 0!==c.COLOR_0?s.getDependency("accessor",c.COLOR_0):e.attributes.color;a.push(t)}}return Promise.all([Promise.all(r),Promise.all(o),Promise.all(a)]).then((function(t){const s=t[0],r=t[1],o=t[2];return i&&(e.morphAttributes.position=s),n&&(e.morphAttributes.normal=r),l&&(e.morphAttributes.color=o),e.morphTargetsRelative=!0,e}))}(e,t.targets,s):e}))}function ge(e,t){let s=e.getIndex();if(null===s){const t=[],i=e.getAttribute("position");if(void 0===i)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<i.count;e++)t.push(e);e.setIndex(t),s=e.getIndex()}const i=s.count-2,n=[];if(t===TriangleFanDrawMode)for(let e=1;e<=i;e++)n.push(s.getX(0)),n.push(s.getX(e)),n.push(s.getX(e+1));else for(let e=0;e<i;e++)e%2==0?(n.push(s.getX(e)),n.push(s.getX(e+1)),n.push(s.getX(e+2))):(n.push(s.getX(e+2)),n.push(s.getX(e+1)),n.push(s.getX(e)));n.length/3!==i&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const l=e.clone();return l.setIndex(n),l}const fe={Handedness:Object.freeze({NONE:"none",LEFT:"left",RIGHT:"right"}),ComponentState:Object.freeze({DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"}),ComponentProperty:Object.freeze({BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"}),ComponentType:Object.freeze({TRIGGER:"trigger",SQUEEZE:"squeeze",TOUCHPAD:"touchpad",THUMBSTICK:"thumbstick",BUTTON:"button"}),ButtonTouchThreshold:.05,AxisTouchThreshold:.1,VisualResponseProperty:Object.freeze({TRANSFORM:"transform",VISIBILITY:"visibility"})};async function Ce(e){const t=await fetch(e);if(t.ok)return t.json();throw new Error(t.statusText)}async function be(e,t,s=null,i=!0){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No basePath supplied");const n=await async function(e){if(!e)throw new Error("No basePath supplied");return await Ce(`${e}/profilesList.json`)}(t);let l;if(e.profiles.some((e=>{const s=n[e];return s&&(l={profileId:e,profilePath:`${t}/${s.path}`,deprecated:!!s.deprecated}),!!l})),!l){if(!s)throw new Error("No matching profile name found");const e=n[s];if(!e)throw new Error(`No matching profile name found and default profile "${s}" missing.`);l={profileId:s,profilePath:`${t}/${e.path}`,deprecated:!!e.deprecated}}const r=await Ce(l.profilePath);let o;if(i){let t;if(t="any"===e.handedness?r.layouts[Object.keys(r.layouts)[0]]:r.layouts[e.handedness],!t)throw new Error(`No matching handedness, ${e.handedness}, in profile ${l.profileId}`);t.assetPath&&(o=l.profilePath.replace("profile.json",t.assetPath))}return{profile:r,assetPath:o}}const ye={xAxis:0,yAxis:0,button:0,state:fe.ComponentState.DEFAULT};class ve{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===fe.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(ye)}updateFromComponent({xAxis:e,yAxis:t,button:s,state:i}){const{normalizedXAxis:n,normalizedYAxis:l}=function(e=0,t=0){let s=e,i=t;if(Math.sqrt(e*e+t*t)>1){const n=Math.atan2(t,e);s=Math.cos(n),i=Math.sin(n)}return{normalizedXAxis:.5*s+.5,normalizedYAxis:.5*i+.5}}(e,t);switch(this.componentProperty){case fe.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?n:.5;break;case fe.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?l:.5;break;case fe.ComponentProperty.BUTTON:this.value=this.states.includes(i)?s:0;break;case fe.ComponentProperty.STATE:this.valueNodeProperty===fe.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(i):this.value=this.states.includes(i)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class _e{constructor(e,t){if(!(e&&t&&t.visualResponses&&t.gamepadIndices&&0!==Object.keys(t.gamepadIndices).length))throw new Error("Invalid arguments supplied");this.id=e,this.type=t.type,this.rootNodeName=t.rootNodeName,this.touchPointNodeName=t.touchPointNodeName,this.visualResponses={},Object.keys(t.visualResponses).forEach((e=>{const s=new ve(t.visualResponses[e]);this.visualResponses[e]=s})),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:fe.ComponentState.DEFAULT,button:void 0!==this.gamepadIndices.button?0:void 0,xAxis:void 0!==this.gamepadIndices.xAxis?0:void 0,yAxis:void 0!==this.gamepadIndices.yAxis?0:void 0}}get data(){return{id:this.id,...this.values}}updateFromGamepad(e){if(this.values.state=fe.ComponentState.DEFAULT,void 0!==this.gamepadIndices.button&&e.buttons.length>this.gamepadIndices.button){const t=e.buttons[this.gamepadIndices.button];this.values.button=t.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,t.pressed||1===this.values.button?this.values.state=fe.ComponentState.PRESSED:(t.touched||this.values.button>fe.ButtonTouchThreshold)&&(this.values.state=fe.ComponentState.TOUCHED)}void 0!==this.gamepadIndices.xAxis&&e.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=e.axes[this.gamepadIndices.xAxis],this.values.xAxis=this.values.xAxis<-1?-1:this.values.xAxis,this.values.xAxis=this.values.xAxis>1?1:this.values.xAxis,this.values.state===fe.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>fe.AxisTouchThreshold&&(this.values.state=fe.ComponentState.TOUCHED)),void 0!==this.gamepadIndices.yAxis&&e.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=e.axes[this.gamepadIndices.yAxis],this.values.yAxis=this.values.yAxis<-1?-1:this.values.yAxis,this.values.yAxis=this.values.yAxis>1?1:this.values.yAxis,this.values.state===fe.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>fe.AxisTouchThreshold&&(this.values.state=fe.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach((e=>{e.updateFromComponent(this.values)}))}}class we{constructor(e,t,s){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=s,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach((e=>{const t=this.layoutDescription.components[e];this.components[e]=new _e(e,t)})),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const e=[];return Object.values(this.components).forEach((t=>{e.push(t.data)})),e}updateFromGamepad(){Object.values(this.components).forEach((e=>{e.updateFromGamepad(this.xrInputSource.gamepad)}))}}class Se extends THREE.Object3D{constructor(){super(),this.motionController=null,this.envMap=null}setEnvironmentMap(e){return this.envMap==e||(this.envMap=e,this.traverse((e=>{e.isMesh&&(e.material.envMap=this.envMap,e.material.needsUpdate=!0)}))),this}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&(this.motionController.updateFromGamepad(),Object.values(this.motionController.components).forEach((e=>{Object.values(e.visualResponses).forEach((e=>{const{valueNode:t,minNode:s,maxNode:i,value:n,valueNodeProperty:l}=e;t&&(l===fe.VisualResponseProperty.VISIBILITY?t.visible=n:l===fe.VisualResponseProperty.TRANSFORM&&(t.quaternion.slerpQuaternions(s.quaternion,i.quaternion,n),t.position.lerpVectors(s.position,i.position,n)))}))})))}}function Ae(e,t){!function(e,t){Object.values(e.components).forEach((e=>{const{type:s,touchPointNodeName:i,visualResponses:n}=e;if(s===fe.ComponentType.TOUCHPAD)if(e.touchPointNode=t.getObjectByName(i),e.touchPointNode){const t=new SphereGeometry(.001),s=new MeshBasicMaterial({color:255}),i=new Mesh(t,s);e.touchPointNode.add(i)}else console.warn(`Could not find touch dot, ${e.touchPointNodeName}, in touchpad component ${e.id}`);Object.values(n).forEach((e=>{const{valueNodeName:s,minNodeName:i,maxNodeName:n,valueNodeProperty:l}=e;if(l===fe.VisualResponseProperty.TRANSFORM){if(e.minNode=t.getObjectByName(i),e.maxNode=t.getObjectByName(n),!e.minNode)return void console.warn(`Could not find ${i} in the model`);if(!e.maxNode)return void console.warn(`Could not find ${n} in the model`)}e.valueNode=t.getObjectByName(s),e.valueNode||console.warn(`Could not find ${s} in the model`)}))}))}(e.motionController,t),e.envMap&&t.traverse((t=>{t.isMesh&&(t.material.envMap=e.envMap,t.material.needsUpdate=!0)})),e.add(t)}class xe{constructor(e=null){this.gltfLoader=e,this.path="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",this._assetCache={},this.gltfLoader||(this.gltfLoader=new f)}createControllerModel(e){const t=new Se;let s=null;return e.addEventListener("connected",(e=>{const i=e.data;"tracked-pointer"===i.targetRayMode&&i.gamepad&&be(i,this.path,"generic-trigger").then((({profile:e,assetPath:n})=>{t.motionController=new we(i,e,n);const l=this._assetCache[t.motionController.assetUrl];if(l)s=l.scene.clone(),Ae(t,s);else{if(!this.gltfLoader)throw new Error("GLTFLoader not set.");this.gltfLoader.setPath(""),this.gltfLoader.load(t.motionController.assetUrl,(e=>{this._assetCache[t.motionController.assetUrl]=e,s=e.scene.clone(),Ae(t,s)}),null,(()=>{throw new Error(`Asset ${t.motionController.assetUrl} missing or malformed.`)}))}})).catch((e=>{console.warn(e)}))})),e.addEventListener("disconnected",(()=>{t.motionController=null,t.remove(s),s=null})),t}}class ke extends THREE.EventDispatcher{constructor(e){if(super(),void 0===e)return void console.error("ControllerGestures must be passed a renderer");const t=new THREE.Clock;this.controller1=e.xr.getController(0),this.controller1.userData.gestures={index:0},this.controller1.userData.selectPressed=!1,this.controller1.addEventListener("selectstart",i),this.controller1.addEventListener("selectend",n),this.controller2=e.xr.getController(1),this.controller2.userData.gestures={index:1},this.controller2.userData.selectPressed=!1,this.controller2.addEventListener("selectstart",i),this.controller2.addEventListener("selectend",n),this.doubleClickLimit=.2,this.pressMinimum=.4,this.right=new THREE.Vector3(1,0,0),this.up=new THREE.Vector3(0,1,0),this.type="unknown",this.prevTap="none",this.clock=t;const s=this;function i(){const e=this.userData.gestures;e.startPosition=void 0,e.startTime=t.getElapsedTime(),-1==s.type.indexOf("tap")&&(e.taps=0),s.type="unknown",this.userData.selectPressed=!0}function n(){const e=this.userData.gestures;e.endTime=t.getElapsedTime();e.endTime-e.startTime<s.doubleClickLimit&&e.taps++,s.type="tap",this.userData.selectPressed=!1,e.startPosition=void 0}}get multiTouch(){let e;return e=void 0!==this.controller1&&void 0!==this.controller2&&(this.controller1.userData.selectPressed&&this.controller2.userData.selectPressed),e}get touch(){let e;return e=void 0!==this.controller1&&void 0!==this.controller2&&(this.controller1.userData.selectPressed||this.controller2.userData.selectPressed),e}get debugMsg(){return this.type}update(){const e=this.controller1.userData.gestures,t=this.controller2.userData.gestures,s=this.clock.getElapsedTime();let i;if(this.controller1.userData.selectPressed&&void 0===e.startPosition&&(i=s-e.startTime,i>.05&&(e.startPosition=this.controller1.position.clone())),this.controller2.userData.selectPressed&&void 0===t.startPosition&&(i=s-t.startTime,i>.05&&(t.startPosition=this.controller2.position.clone())),!this.controller1.userData.selectPressed&&"tap"===this.type&&(i=this.clock.getElapsedTime()-e.endTime,i>this.doubleClickLimit)){switch(e.taps){case 1:self.prevTap="tap";break;case 2:this.dispatchEvent({type:"doubletap",position:this.controller1.position,matrixWorld:this.controller1.matrixWorld}),self.prevTap="doubletap"}this.type="unknown",e.taps=0}if("unknown"===this.type&&this.touch)"doubletap"==self.prevTap?(this.type="pinch",this.startDistance=this.controller1.position.distanceTo(this.controller2.position),this.dispatchEvent({type:"pinch",delta:new THREE.Vector3(0,0,0),scale:1,initialise:!0})):(this.type="pan",this.startPosition=this.controller1.position.clone(),this.dispatchEvent({type:"pan",delta:new THREE.Vector3(0,0,0),initialise:!0}));else if(("pinch"===this.type||"pan"===this.type)&&"doubletap"==self.prevTap&&this.controller2.position){const e=this.controller1.position.distanceTo(this.controller2.position)/this.startDistance,t=this.controller1.position.clone().sub(this.startPosition);this.dispatchEvent({type:"pinch",delta:t,scale:e})}}}class Oe{constructor(e,t){this.config=void 0===t?{panelSize:{width:1,height:1},width:512,height:512,opacity:.7,body:{fontFamily:"Arial",fontSize:30,padding:2,backgroundColor:"#000",fontColor:"#fff",borderRadius:6}}:t,void 0===this.config.width&&(this.config.width=512),void 0===this.config.height&&(this.config.height=512),void 0===this.config.body&&(this.config.body={fontFamily:"Arial",size:30,padding:2,backgroundColor:"#000",fontColor:"#fff",borderRadius:6});const s=this.config.body;void 0===s.borderRadius&&(s.borderRadius=6),void 0===s.fontFamily&&(s.fontFamily="Arial"),void 0===s.padding&&(s.padding=2),void 0===s.fontSize&&(s.fontSize=30),void 0===s.backgroundColor&&(s.backgroundColor="#000"),void 0===s.fontColor&&(s.fontColor="#fff"),Object.entries(this.config).forEach((([e,t])=>{if(!("object"!=typeof t||"panelSize"===e||t instanceof THREE.WebGLRenderer||t instanceof THREE.Scene)){const e=void 0!==t.position?t.position:{x:0,y:0};void 0!==e.left&&void 0===e.x&&(e.x=e.left),void 0!==e.top&&void 0===e.y&&(e.y=e.top);const s=void 0!==t.width?t.width:this.config.width,i=void 0!==t.height?t.height:this.config.height;void 0!==e.right&&void 0===e.x&&(e.x=this.config.width-e.right-s),void 0!==e.bottom&&void 0===e.y&&(e.y=this.config.height-e.bottom-i),void 0===e.x&&(e.x=0),void 0===e.y&&(e.y=0),t.position=e,void 0===t.type&&(t.type="text")}}));const i=this.createOffscreenCanvas(this.config.width,this.config.height);this.context=i.getContext("2d"),this.context.save();const n=void 0!==this.config.opacity?this.config.opacity:.7,l=new THREE.MeshBasicMaterial({transparent:!0,opacity:n});this.panelSize=void 0!==this.config.panelSize?this.config.panelSize:{width:1,height:1};const r=new THREE.PlaneGeometry(this.panelSize.width,this.panelSize.height);this.mesh=new THREE.Mesh(r,l),this.texture=new THREE.CanvasTexture(i),this.mesh.material.map=this.texture,this.scene=this.config.scene;if(Object.values(this.config).filter((e=>"input-text"===e.type)).length>0){this.keyboard=new Re(this.panelSize.width,this.config.renderer);this.keyboard.mesh.position.set(0,-.3,.2),this.mesh.add(this.keyboard.mesh)}if(void 0===e)this.content={body:""},this.config.body.type="text";else{this.content=e;Object.values(t).filter((e=>"button"===e.type||"scroll"===e.overflow||"input-text"===e.type)).length>0&&(void 0===t||void 0===t.renderer?console.warn("CanvasUI: button, scroll or input-text in the config but no renderer"):(this.renderer=t.renderer,this.initControllers()))}this.selectedElements=[void 0,void 0],this.selectPressed=[!1,!1],this.scrollData=[void 0,void 0],this.intersects=[void 0,void 0],this.needsUpdate=!0,this.update()}getIntersectY(e){const t=this.config.height||512,s=this.intersects[e];return void 0===s||void 0===s.uv?0:(1-s.uv.y)*t}initControllers(){this.vec3=new THREE.Vector3,this.mat4=new THREE.Matrix4,this.raycaster=new THREE.Raycaster;const e=this;function t(t){const s=t.target===e.controller?0:1,i=e.selectedElements[s];if(void 0!==i)if("button"==i.type)e.select(s);else if("input-text"==i.type&&e.keyboard)if(e.keyboard.visible)e.keyboard.linkedUI=void 0,e.keyboard.linkedText=void 0,e.keyboard.linkedElement=void 0,e.keyboard.visible=!1;else{let t;e.keyboard.linkedUI=e,Object.entries(e.config).forEach((([e,s])=>{s==i&&(t=e)}));const s=(.5-(i.position.y+i.height+e.config.body.padding)/e.config.height)*e.panelSize.height,n=Math.max(e.panelSize.width,e.panelSize.height)/2;e.keyboard.position.set(0,-n/1.5-s,.1),e.keyboard.linkedText=e.content[t],e.keyboard.linkedName=t,e.keyboard.linkedElement=i,e.keyboard.visible=!0}}function s(t){const s=t.target===e.controller?0:1;if(e.selectPressed[s]=!0,void 0!==e.selectedElements[s]&&"scroll"==e.selectedElements[s].overflow){const t=e.selectedElements[s];e.scrollData[s]={scrollY:t.scrollY,rayY:e.getIntersectY(s)}}}function i(t){const s=t.target===e.controller?0:1;e.selectPressed[s]=!1,void 0!==e.selectedElements[s]&&"scroll"==e.selectedElements[s].overflow&&(e.scrollData[s]=void 0)}if(this.controller=this.renderer.xr.getController(0),this.controller.addEventListener("select",t),this.controller.addEventListener("selectstart",s),this.controller.addEventListener("selectend",i),this.controller1=this.renderer.xr.getController(1),this.controller1.addEventListener("select",t),this.controller1.addEventListener("selectstart",s),this.controller1.addEventListener("selectend",i),this.scene){const e=.015,t=new THREE.IcosahedronBufferGeometry(e),s=new THREE.MeshBasicMaterial({color:170}),i=new THREE.Mesh(t,s);i.visible=!1,this.scene.add(i);const n=new THREE.Mesh(t,s);n.visible=!1,this.scene.add(n),this.intersectMesh=[i,n]}}setClip(e){const t=this.context;if(t.restore(),t.save(),void 0!==e.clipPath){const s=new Path2D(e.clipPath);t.clip(s)}else{const s=void 0!==e.position?e.position:{x:0,y:0},i=e.borderRadius||0,n=e.width||this.config.width,l=e.height||this.config.height;if(t.beginPath(),0!==i){const e=Math.PI/2;t.moveTo(s.x+i,s.y),t.arc(s.x+i,s.y+i,i,e,2*e,!0),t.lineTo(s.x,s.y+l-i),t.arc(s.x+i,s.y+l-i,i,0,e,!0),t.lineTo(s.x+n-i,s.y+l),t.arc(s.x+n-i,s.y+l-i,i,3*e,4*e,!0),t.lineTo(s.x+n,s.y+i),t.arc(s.x+n-i,s.y+i,i,2*e,3*e,!0),t.closePath(),t.clip()}else t.rect(s.x,s.y,n,l),t.clip()}}setPosition(e,t,s){void 0!==this.mesh&&this.mesh.position.set(e,t,s)}setRotation(e,t,s){void 0!==this.mesh&&this.mesh.rotation.set(e,t,s)}updateElement(e,t){let s=this.content[e];void 0!==s?("object"==typeof s?s.content=t:s=t,this.content[e]=s,this.needsUpdate=!0):console.warn(`CanvasGUI.updateElement: No ${e} found`)}get panel(){return this.mesh}getElementAtLocation(e,t){const s=this,i=Object.entries(this.config).filter((([i,n])=>{if(!("object"!=typeof n||"panelSize"===i||"body"===i||n instanceof THREE.WebGLRenderer||n instanceof THREE.Scene)){const i=n.position,l=void 0!==n.width?n.width:s.config.width,r=void 0!==n.height?n.height:s.config.height;return e>=i.x&&e<i.x+l&&t>=i.y&&t<i.y+r}}));return 0==i.length?null:this.config[i[0][0]]}updateConfig(e,t,s){let i=this.config[e];void 0!==i?(i[t]=s,this.needsUpdate=!0):console.warn(`CanvasUI.updateconfig: No ${e} found`)}hover(e=0,t){if(void 0===t)void 0!==this.selectedElements[e]&&(this.selectedElements[e]=void 0,this.needsUpdate=!0);else{const s=t.x*(this.config.width||512),i=(1-t.y)*(this.config.height||512),n=this.getElementAtLocation(s,i);null===n?void 0!==this.selectedElements[e]&&(this.selectedElements[e]=void 0,this.needsUpdate=!0):this.selectedElements[e]!==n&&(this.selectedElements[e]=n,this.needsUpdate=!0)}}select(e=0){if(void 0!==this.selectedElements[e]){const t=this.selectedElements[e];t.onSelect&&t.onSelect(),"input-text"===t.type?this.keyboard.mesh.visible=!0:this.selectedElements[e]=void 0}}scroll(e){if(void 0===this.selectedElements[e])return void(this.intersectMesh&&(this.intersectMesh[e].visible=!1));if("scroll"!==this.selectedElements[e].overflow)return;const t=this.selectedElements[e];if(this.selectPressed[e]){const s=this.scrollData[e];if(void 0!==s){this.intersectMesh&&(this.intersectMesh[e].visible=!0,this.intersectMesh[e].position.copy(this.intersects[e].point));const i=this.getIntersectY(e)-s.rayY;t.scrollY=Math.min(Math.max(t.minScrollY,s.scrollY+i),0),this.needsUpdate=!0}}else this.intersectMesh&&(this.intersectMesh[e].visible=!1)}handleController(e,t){this.mat4.identity().extractRotation(e.matrixWorld),this.raycaster.ray.origin.setFromMatrixPosition(e.matrixWorld),this.raycaster.ray.direction.set(0,0,-1).applyMatrix4(this.mat4);const s=this.raycaster.intersectObject(this.mesh);s.length>0?(this.hover(t,s[0].uv),this.intersects[t]=s[0],this.scroll(t)):(this.hover(t),this.intersects[t]=void 0,this.scroll(t))}update(){if(void 0===this.mesh)return;if(this.controller&&this.handleController(this.controller,0),this.controller1&&this.handleController(this.controller1,1),this.keyboard&&this.keyboard.visible&&this.keyboard.update(),!this.needsUpdate)return;let e=this.context;e.clearRect(0,0,this.config.width,this.config.height);const t=this.config.body.backgroundColor?this.config.body.backgroundColor:"#000";!this.config.body.fontFamily||this.config.body.fontFamily;const s=this.config.body.fontColor?this.config.body.fontColor:"#fff";!this.config.body.fontSize||this.config.body.fontSize,this.setClip(this.config.body),e.fillStyle=t,e.fillRect(0,0,this.config.width,this.config.height);const i=this;Object.entries(this.content).forEach((([t,n])=>{const l=void 0!==i.config[t]?i.config[t]:i.config.body;if("none"!==(void 0!==l.display?l.display:"block")){const r=void 0!==l.position?l.position:{x:0,y:0},o=void 0!==l.width?l.width:i.config.width,a=void 0!==l.height?l.height:i.config.height;"button"!=l.type||n.toLowerCase().startsWith("<path>")||(void 0===l.borderRadius&&(l.borderRadius=6),void 0===l.textAlign&&(l.textAlign="center")),i.setClip(l);const d=n.toLowerCase().startsWith("<path>"),c=void 0!==i.selectedElements[0]&&this.selectedElements[0]===l||void 0!==i.selectedElements[1]&&this.selectedElements[1]===l;if(void 0!==l.backgroundColor&&(c&&"button"==l.type&&void 0!==l.hover?e.fillStyle=l.hover:e.fillStyle=l.backgroundColor,e.fillRect(r.x,r.y,o,a)),"text"==l.type||"button"==l.type||"input-text"==l.type){let h=!1;if(c?(d||"button"!=l.type?e.fillStyle=void 0!==l.hover?l.hover:void 0!==l.fontColor?l.fontColor:s:e.fillStyle=void 0!==l.fontColor?l.fontColor:s,h=void 0===l.hover):e.fillStyle=void 0!==l.fontColor?l.fontColor:s,d){const t=n.toUpperCase().substring(6,n.length-7);e.save(),e.translate(r.x,r.y);const s=new Path2D(t);e.fill(s),e.restore()}else i.wrapText(t,n);h&&(e.beginPath(),e.strokeStyle="#fff",e.lineWidth=2,e.rect(r.x,r.y,o,a),e.stroke())}else if("img"==l.type)if(void 0===l.img)this.loadImage(n).then((e=>{console.log(`w: ${e.width} | h: ${e.height}`),l.img=e,i.needsUpdate=!0,i.update()})).catch((e=>console.error(e)));else{const t=o/(l.img.width/l.img.height);e.drawImage(l.img,r.x,r.y,o,t)}}})),this.needsUpdate=!1,this.texture.needsUpdate=!0}loadImage(e){return new Promise(((t,s)=>{const i=new THREE.Image;i.addEventListener("load",(()=>t(i))),i.addEventListener("error",(e=>s(e))),i.src=e}))}createOffscreenCanvas(e,t){const s=document.createElement("canvas");return s.width=e,s.height=t,s}fillRoundedRect(e,t,s,i,n){const l=this.context;l.beginPath(),l.moveTo(e+n,t),l.lineTo(e+s-n,t),l.quadraticCurveTo(e+s,t,e+s,t+n),l.lineTo(e+s,t+i-n),l.quadraticCurveTo(e+s,t+i,e+s-n,t+i),l.lineTo(e+n,t+i),l.quadraticCurveTo(e,t+i,e,t+i-n),l.lineTo(e,t+n),l.quadraticCurveTo(e,t,e+n,t),l.closePath(),l.fill()}lookAt(e){void 0!==this.mesh&&(e instanceof Vector3?this.mesh.lookAt(e):console.error("CanvasUI lookAt called parameter not a THREE.Vector3"))}get visible(){return void 0!==this.mesh&&this.mesh.visible}set visible(e){this.mesh&&(this.mesh.visible=e)}get position(){if(void 0!==this.mesh)return this.mesh.position}set position(e){void 0!==this.mesh&&(e instanceof Vector3?this.mesh.position.copy(e):console.error("CanvasUI trying to set the mesh position using a parameter that is not a THREE.Vector3"))}get quaternion(){if(void 0!==this.mesh)return this.mesh.quaternion}set quaternion(e){void 0!==this.mesh&&(e instanceof QUaternion?this.mesh.quaternion.copy(e):console.error("CanvasUI trying to set the mesh quaternion using a parameter that is not a THREE.Quaternion"))}wrapText(e,t){const s=t.split(" ");let i="";const n=[],l=void 0!==this.config[e]?this.config[e]:this.config.body,r=void 0!==l.width?l.width:this.config.width,o=void 0!==l.height?l.height:this.config.height,a=void 0!==l.position?l.position:{x:0,y:0},d=void 0!==l.padding?l.padding:void 0!==this.config.body.padding?this.config.body.padding:10,c=void 0!==l.paddingTop?l.paddingTop:d,h=void 0!==l.paddingLeft?l.paddingLeft:d,p=void 0!==l.paddingBottom?l.paddingBottom:d,m=void 0!==l.paddingRight?l.paddingRight:d,u={x:a.x+h,y:a.y+c,width:r-h-m,height:o-c-p},g=void 0!==l.textAlign?l.textAlign:void 0!==this.config.body.textAlign?this.config.body.textAlign:"left",f=void 0!==l.fontSize?l.fontSize:void 0!==this.config.body.fontSize?this.config.body.fontSize:30,C=void 0!==l.fontFamily?l.fontFamily:void 0!==this.config.body.fontFamily?this.config.body.fontFamily:"Arial",b=f+(void 0!==l.leading?l.leading:void 0!==this.config.body.leading?this.config.body.leading:8),y=this.context;y.textAlign=g,y.font=`${f}px '${C}'`,s.forEach((function(e){let t=s.length>1?`${i}${e} `:e,l=y.measureText(t);if(l.width>u.width&&e.length>1)if(0==i.length&&l.width>u.width){for(;l.width>u.width;){let s=0;do{s++,t=e.substr(0,s),l=y.measureText(t)}while(l.width<u.width&&s<e.length-1);if(s--,t=e.substr(0,s),n.push(t),e=e.substr(s),s<=1)break;l=y.measureText(e)}""!=e&&n.push(e)}else n.push(i),i=`${e} `;else i=t})),""!=i&&n.push(i);const v=n.length*b;let _=0;if(v>u.height&&"scroll"===l.overflow){void 0===l.scrollY&&(l.scrollY=0);const e=void 0!==l.fontColor?l.fontColor:this.config.body.fontColor;y.fillStyle="#aaa",this.fillRoundedRect(a.x+r-12,a.y,12,o,6),y.fillStyle="#666";const t=u.height/v,s=t*o,i=-l.scrollY*t;this.fillRoundedRect(a.x+r-12,a.y+i,12,s,6),y.fillStyle=e,_=l.scrollY,l.minScrollY=u.height-v}let w,S=_+u.y+f/2;switch(g){case"center":w=u.x+u.width/2;break;case"right":w=u.x+u.width;break;default:w=u.x}n.forEach((e=>{S+b>0&&y.fillText(e,w,S),S+=b}))}}class Re{constructor(e,t,s="EN"){const i=this.getConfig(s);i.panelSize={width:e,height:.5*e},i.height=256,i.body={backgroundColor:"#555"},i.renderer=t;const n=this.getContent(s);this.keyboard=new Oe(n,i),this.keyboard.mesh.visible=!1,this.shift=!1}get mesh(){return this.keyboard.mesh}getConfig(e){const t={};let s=10;const i=39.2,n=49,l="#333",r="#000";let o=s,a=s;for(let e=0;e<10;e++){const d={type:"button",position:{x:a,y:o},width:i,height:n,padding:s,paddingTop:20,backgroundColor:r,borderRadius:6,hover:l,onSelect:this.onSelect.bind(this,e)};t[`btn${e}`]=d,a+=49.2}o+=59,a=s;for(let e=0;e<10;e++){const d={type:"button",position:{x:a,y:o},width:i,height:n,padding:s,paddingTop:20,backgroundColor:r,borderRadius:6,hover:l,onSelect:this.onSelect.bind(this,e+10)};t[`btn${e+10}`]=d,a+=49.2}o+=59,a=s;for(let e=0;e<9;e++){const d=0==e||8==e?1.5*i+5:i,c={type:"button",position:{x:a,y:o},width:d,height:n,padding:s,paddingTop:20,backgroundColor:r,borderRadius:6,hover:l,onSelect:this.onSelect.bind(this,e+20)};t[`btn${e+20}`]=c,a+=d+s}o+=59,a=s;for(let e=0;e<5;e++){const d=0==e||4==e?88.4:2==e?186.8:i,c={type:"button",position:{x:a,y:o},width:d,height:n,padding:s,paddingTop:20,backgroundColor:r,borderRadius:6,hover:l,onSelect:this.onSelect.bind(this,e+30)};0==e&&(c.fontSize=20),t[`btn${e+30}`]=c,a+=d+s}return t}getContent(e,t=0){let s,i={};switch(this.language=e,this.keyboardIndex=t,t){case 0:s=["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","@","⇧","z","x","c","v","b","n","m","⇦","","?123",","," ",".","↲"];for(let e=0;e<s.length;e++){const t=s[e];""!==t&&(i[`btn${e}`]=t)}break;case 1:s=["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","@","⇧","Z","X","C","V","B","N","M","⇦","","?123",","," ",".","↲"];for(let e=0;e<s.length;e++){const t=s[e];""!==t&&(i[`btn${e}`]=t)}break;case 2:s=["1","2","3","4","5","6","7","8","9","0","@","#","%","&","*","/","-","+","(",")","⇧","?","!",'"',"'","\\",":",";","⇦","","abc",","," ",".","↲"];for(let e=0;e<s.length;e++){const t=s[e];""!==t&&(i[`btn${e}`]=t)}break;case 3:s=["1","2","3","4","5","6","7","8","9","0","€","£","$","^","=","|","{","}","[","}","⇧","<",">","_","`","~",":",";","⇦","","abc",","," ",".","↲"];for(let e=0;e<s.length;e++){const t=s[e];""!==t&&(i[`btn${e}`]=t)}}return i}get position(){return this.keyboard.mesh.position}get visible(){return this.keyboard.mesh.visible}set visible(e){this.keyboard.mesh.visible=e}setKeyboard(e){this.keyboard.content=this.getContent(this.language,e),this.keyboard.needsUpdate=!0}onSelect(e){if(!this.visible)return;let t=!1;switch(e){case 34:this.visible=!1,this.linkedElement.onEnter&&this.linkedElement.onEnter(this.linkedText);break;case 32:this.linkedText+=" ",t=!0;break;case 30:this.shift=!1,this.keyboardIndex<2?this.setKeyboard(2):this.setKeyboard(0),this.keyboard.needsUpdate=!0;break;case 28:this.linkedText=this.linkedText.substring(0,this.linkedText.length-1),t=!0;break;case 20:this.shift=!this.shift,0==this.keyboardIndex?this.setKeyboard(1):1==this.keyboardIndex?this.setKeyboard(0):2==this.keyboardIndex?this.setKeyboard(3):3==this.keyboardIndex&&this.setKeyboard(2);break;default:const s=this.keyboard.content[`btn${e}`];this.linkedText+=s,t=!0,1==this.keyboardIndex&&this.setKeyboard(0)}t&&(this.linkedUI.updateElement(this.linkedName,this.linkedText),this.linkedElement.onChanged&&this.linkedElement.onChanged(this.linkedText))}update(){this.keyboard&&this.keyboard.update()}}class Ie{constructor(e){this.icn3d=e}rebuildScene(e){let t=this.icn3d,s=t.icn3dui;void 0===e&&(e=t.opts),this.rebuildSceneBase(e),t.fogCls.setFog(),t.cameraCls.setCamera(),s.cfg.imageonly||this.setVrArButtons(),this.setVrAr(),void 0!==t.bSkipChemicalbinding&&t.bSkipChemicalbinding||t.applyOtherCls.applyChemicalbindingOptions(),t.bSkipChemicalbinding=!0,"show"===e.chemicalbinding&&(t.opts.hbonds="yes"),t.applySsbondsCls.applySsbondsOptions(),t.applyClbondsCls.applyClbondsOptions(),t.applyMissingResCls.applyMissingResOptions(),t.applyDisplayCls.applyDisplayOptions(t.opts,t.dAtoms),t.applyOtherCls.applyOtherOptions(),t.scene_ghost.updateMatrixWorld(!0)}rebuildSceneBase(e){let t=this.icn3d,s=t.icn3dui;if($.extend(t.opts,e),t.cam_z=2*t.maxD,void 0!==t.scene)for(let e=t.scene.children.length-1;e>=0;e--){let s=t.scene.children[e];t.scene.remove(s)}else t.scene=new THREE.Scene;if(void 0!==t.scene_ghost)for(let e=t.scene_ghost.children.length-1;e>=0;e--){let s=t.scene_ghost.children[e];t.scene_ghost.remove(s)}else t.scene_ghost=new THREE.Scene;if(""!=s.htmlCls.setHtmlCls.getCookie("shininess")){let e=parseFloat(s.htmlCls.setHtmlCls.getCookie("shininess"));t.shininess!=e&&s.htmlCls.clickMenuCls.setLogCmd("set shininess "+e,!0),t.shininess=e}if(!s.bNode&&""!=s.htmlCls.setHtmlCls.getCookie("light1")){let e=parseFloat(s.htmlCls.setHtmlCls.getCookie("light1")),i=parseFloat(s.htmlCls.setHtmlCls.getCookie("light2")),n=parseFloat(s.htmlCls.setHtmlCls.getCookie("light3"));t.light1==e&&t.light2==i&&t.light3==n||s.htmlCls.clickMenuCls.setLogCmd("set light | light1 "+e+" | light2 "+i+" | light3 "+n,!0),t.light1=e,t.light2=i,t.light3=n}t.directionalLight=new THREE.DirectionalLight(16777215,t.light1),t.directionalLight2=new THREE.DirectionalLight(16777215,t.light2),t.directionalLight3=new THREE.DirectionalLight(16777215,t.light3),t.cam_z>0?(t.directionalLight.position.set(-1,1,1),t.directionalLight2.position.set(1,1,1),t.directionalLight3.position.set(1,1,-1),t.lightPos=new THREE.Vector3(-1,1,1),t.lightPos2=new THREE.Vector3(1,1,1),t.lightPos3=new THREE.Vector3(1,1,-1)):(t.directionalLight.position.set(-1,1,-1),t.directionalLight2.position.set(1,1,-1),t.directionalLight3.position.set(1,1,1),t.lightPos=new THREE.Vector3(-1,1,-1),t.lightPos2=new THREE.Vector3(1,1,-1),t.lightPos3=new THREE.Vector3(1,1,1));let i=new THREE.AmbientLight(4210752);if(t.scene.add(t.directionalLight),t.scene.add(i),void 0!==t.mdl)for(let e=t.mdl.children.length-1;e>=0;e--){let s=t.mdl.children[e];s.geometry&&s.geometry.dispose(),s.material&&s.material.dispose(),t.mdl.remove(s)}if(void 0!==t.mdlImpostor){for(let e=t.mdlImpostor.children.length-1;e>=0;e--){let s=t.mdlImpostor.children[e];s.geometry&&s.geometry.dispose(),s.material&&s.material.dispose(),t.mdlImpostor.remove(s)}t.mdlImpostor.children.length=0}s.bNode||t.renderer.renderLists.dispose(),t.mdl=new THREE.Object3D,t.mdlImpostor=new THREE.Object3D,t.scene.add(t.mdl),t.scene.add(t.mdlImpostor),t.mdl_ghost=new THREE.Object3D,t.scene_ghost.add(t.mdl_ghost),t.objects=[],t.objects_ghost=[],t.raycaster=new THREE.Raycaster,t.projector=new THREE.Projector,t.mouse=new THREE.Vector2;let n=s.parasCls.backgroundColors[t.opts.background.toLowerCase()];s.bNode||("transparent"===t.opts.background.toLowerCase()?t.renderer.setClearColor(n,0):t.renderer.setClearColor(n,1)),t.perspectiveCamera=new THREE.PerspectiveCamera(20,t.container.whratio,.1,1e4),t.perspectiveCamera.position.set(0,0,t.cam_z),t.perspectiveCamera.lookAt(new THREE.Vector3(0,0,0)),t.orthographicCamera=new THREE.OrthographicCamera,t.orthographicCamera.position.set(0,0,t.cam_z),t.orthographicCamera.lookAt(new THREE.Vector3(0,0,0)),t.cams={perspective:t.perspectiveCamera,orthographic:t.orthographicCamera}}setVrAr(){let e=this.icn3d;e.icn3dui;let t=this;e.bSetVrAr=!0,e.bVr?(e.canvasUI=this.createUI(),e.raycasterVR=new THREE.Raycaster,e.workingMatrix=new THREE.Matrix4,e.workingVector=new THREE.Vector3,e.origin=new THREE.Vector3,e.dolly=new THREE.Object3D,e.dolly.position.z=5,e.dolly.add(e.cam),e.scene.add(e.dolly),e.dollyId=e.dolly.id,e.dummyCam=new THREE.Object3D,e.cam.add(e.dummyCam),e.clock=new THREE.Clock,e.controllers=this.getControllers(),e.controllers.forEach((s=>{s.addEventListener("connected",(function(e){try{const s={},i="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",n="generic-trigger";be(e.data,i,n).then((({profile:i,assetPath:n})=>{s.name=i.profileId,s.targetRayMode=e.data.targetRayMode,Object.entries(i.layouts).forEach((([e,t])=>{const i={};Object.values(t.components).forEach((e=>{i[e.rootNodeName]=e.gamepadIndices})),s[e]=i})),t.updateControllers(s)}))}catch(e){}})),s.addEventListener("disconnected",(function(){this.remove(this.children[0]),e.controllers.forEach((e=>{}))}))}))):e.bAr&&(e.gestures=new ke(e.renderer),e.scene.add(e.gestures.controller1),e.scene.add(e.gestures.controller2),e.gestures.addEventListener("doubletap",(e=>{t.positionCenter()})),e.gestures.addEventListener("pinch",(s=>{if(void 0!==s.initialise)t.startPosition=e.mdl.position.clone(),t.startScale=e.mdl.scale.clone();else{let i=1;const n=t.startScale.clone().multiplyScalar(s.scale*i);e.mdl.scale.copy(n)}})))}positionCenter(){let e=this.icn3d;e.icn3dui;const t=e.gestures.controller1;e.mdl.position.set(-.06,0,-.6).applyMatrix4(t.matrixWorld),e.mdl.scale.copy(new THREE.Vector3(.005,.005,.005))}setVrArButtons(){let e=this.icn3d,t=e.icn3dui;e.bSetVrArButtons=!0,t.bNode||($("#"+t.pre+"VRButton").remove(),$("#"+t.pre+"viewer").get(0).appendChild(e.VRButtonCls.createButton(e.renderer)),$("#"+t.pre+"ARButton").remove(),$("#"+t.pre+"viewer").get(0).appendChild(e.ARButtonCls.createButton(e.renderer)))}updateControllers(e){this.icn3d.icn3dui,this.addEventForController(e,"right"),this.addEventForController(e,"left")}addEventForController(e,t){let s=this.icn3d;s.icn3dui;const i="right"==t?s.renderer.xr.getController(0):s.renderer.xr.getController(1),n="right"==t?e.right:e.left;if(i&&void 0!==n){let e=!1,t=!1;Object.keys(n).forEach((i=>{-1!=i.indexOf("trigger")&&(e=!0),-1!=i.indexOf("squeeze")&&(t=!0),-1==i.indexOf("thumbstick")&&-1==i.indexOf("touchpad")||(s.xAxisIndex=n[i].xAxis,s.yAxisIndex=n[i].yAxis)})),e&&(i.addEventListener("selectstart",(function(){this.userData.selectPressed=!0})),i.addEventListener("selectend",(function(){this.userData.selectPressed=!1,this.userData.selected=void 0}))),t&&(i.addEventListener("squeezestart",(function(){this.userData.squeezePressed=!0,s.cam.add(s.canvasUI.mesh)})),i.addEventListener("squeezeend",(function(){this.userData.squeezePressed=!1,s.cam.remove(s.canvasUI.mesh)})))}}createUI(){let e=this.icn3d,t=e.icn3dui,s=94,i=50,n=94,l=34,r=12,o="#1c94c4",a="#ccc",d="#fbcb09",c=20;const h={panelSize:{width:2,height:1.6},height:400,select:{type:"button",paddingTop:c,position:{top:6,left:6},width:s,height:i,fontColor:"#000",fontSize:14,backgroundColor:a},residue:{type:"button",paddingTop:c,position:{top:62,left:6},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.pk=2,e.pAtomNum||(e.pAtomNum=0),e.cam.remove(e.canvasUI.mesh)}},secondarySelect:{type:"button",paddingTop:12,position:{top:118,left:6},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.pk=3,e.pAtomNum||(e.pAtomNum=0),e.cam.remove(e.canvasUI.mesh)}},chainSelect:{type:"button",paddingTop:c,position:{top:174,left:6},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.pk=5,e.pAtomNum||(e.pAtomNum=0),e.cam.remove(e.canvasUI.mesh)}},atom:{type:"button",paddingTop:c,position:{top:230,left:6},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.pk=1,e.pAtomNum||(e.pAtomNum=0),e.cam.remove(e.canvasUI.mesh)}},reset:{type:"button",paddingTop:c,position:{top:286,left:6},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.viewInterPairsCls.resetInteractionPairs(),e.selectionCls.resetAll(),e.cam.remove(e.canvasUI.mesh)}},togglehl:{type:"button",paddingTop:12,position:{top:342,left:6},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.hlUpdateCls.toggleHighlight(),e.cam.remove(e.canvasUI.mesh)}},style:{type:"button",paddingTop:c,position:{top:6,left:106},width:s,height:i,fontColor:"#000",fontSize:14,backgroundColor:a},ribbon:{type:"button",paddingTop:c,position:{top:62,left:106},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setStyle("proteins","ribbon"),e.setOptionCls.setStyle("nucleotides","nucleotide cartoon"),e.cam.remove(e.canvasUI.mesh)}},schematic:{type:"button",paddingTop:c,position:{top:118,left:106},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setStyle("proteins","schematic"),e.setOptionCls.setStyle("nucleotides","schematic"),e.cam.remove(e.canvasUI.mesh)}},stick:{type:"button",paddingTop:c,position:{top:174,left:106},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setStyle("proteins","stick"),e.setOptionCls.setStyle("nucleotides","stick"),e.cam.remove(e.canvasUI.mesh)}},sphere:{type:"button",paddingTop:c,position:{top:230,left:106},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setStyle("proteins","sphere"),e.setOptionCls.setStyle("nucleotides","sphere"),e.cam.remove(e.canvasUI.mesh)}},surface:{type:"button",paddingTop:c,position:{top:286,left:106},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.opts.surface="molecular surface",e.applyMapCls.applySurfaceOptions(),e.cam.remove(e.canvasUI.mesh)}},surfaceTrn:{type:"button",paddingTop:12,position:{top:342,left:106},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.opts.surface="molecular surface",e.opts.opacity="0.2",e.applyMapCls.applySurfaceOptions(),e.cam.remove(e.canvasUI.mesh)}},color:{type:"button",paddingTop:c,position:{top:6,left:206},width:s,height:i,fontColor:"#000",fontSize:14,backgroundColor:a},rainbow:{type:"button",paddingTop:c,position:{top:62,left:206},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setOption("color","rainbow for chains"),e.cam.remove(e.canvasUI.mesh)}},atomColor:{type:"button",paddingTop:c,position:{top:118,left:206},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setOption("color","atom"),e.cam.remove(e.canvasUI.mesh)}},chainColor:{type:"button",paddingTop:c,position:{top:174,left:206},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setOption("color","chain"),e.cam.remove(e.canvasUI.mesh)}},secondaryColor:{type:"button",paddingTop:12,position:{top:230,left:206},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setOption("color","secondary structure green"),e.cam.remove(e.canvasUI.mesh)}},charge:{type:"button",paddingTop:c,position:{top:342,left:206},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setOption("color","charge"),e.cam.remove(e.canvasUI.mesh)}},AlphaFold:{type:"button",paddingTop:c,position:{top:286,left:206},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){e.setOptionCls.setOption("color","confidence"),e.cam.remove(e.canvasUI.mesh)}},unicolor:{type:"button",paddingTop:c,position:{top:6,left:306},width:s,height:i,fontColor:"#000",fontSize:14,backgroundColor:a},red:{type:"button",position:{top:i,left:300},width:n,height:l,fontColor:"red",hover:d,onSelect:function(){e.setOptionCls.setOption("color","red"),e.cam.remove(e.canvasUI.mesh)}},green:{type:"button",position:{top:78,left:300},width:n,height:l,fontColor:"green",hover:d,onSelect:function(){e.setOptionCls.setOption("color","green"),e.cam.remove(e.canvasUI.mesh)}},blue:{type:"button",position:{top:106,left:300},width:n,height:l,fontColor:"blue",hover:d,onSelect:function(){e.setOptionCls.setOption("color","blue"),e.cam.remove(e.canvasUI.mesh)}},blueviolet:{type:"button",position:{top:134,left:300},width:n,height:l,fontColor:"#8A2BE2",hover:d,onSelect:function(){e.setOptionCls.setOption("color","8A2BE2"),e.cam.remove(e.canvasUI.mesh)}},magenta:{type:"button",position:{top:162,left:300},width:n,height:l,fontColor:"magenta",hover:d,onSelect:function(){e.setOptionCls.setOption("color","magenta"),e.cam.remove(e.canvasUI.mesh)}},yellow:{type:"button",position:{top:190,left:300},width:n,height:l,fontColor:"yellow",hover:d,onSelect:function(){e.setOptionCls.setOption("color","yellow"),e.cam.remove(e.canvasUI.mesh)}},orange:{type:"button",position:{top:218,left:300},width:n,height:l,fontColor:"orange",hover:d,onSelect:function(){e.setOptionCls.setOption("color","FFA500"),e.cam.remove(e.canvasUI.mesh)}},cyan:{type:"button",position:{top:246,left:300},width:n,height:l,fontColor:"cyan",hover:d,onSelect:function(){e.setOptionCls.setOption("color","cyan"),e.cam.remove(e.canvasUI.mesh)}},gray:{type:"button",position:{top:274,left:300},width:n,height:l,fontColor:"gray",hover:d,onSelect:function(){e.setOptionCls.setOption("color","888888"),e.cam.remove(e.canvasUI.mesh)}},white:{type:"button",position:{top:302,left:300},width:n,height:l,fontColor:"white",hover:d,onSelect:function(){e.setOptionCls.setOption("color","white"),e.cam.remove(e.canvasUI.mesh)}},analysis:{type:"button",paddingTop:c,position:{top:6,left:406},width:s,height:i,fontColor:"#000",fontSize:14,backgroundColor:a},distance:{type:"button",paddingTop:c,position:{top:62,left:406},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){try{e.bMeasureDistance=!0;let s=e.pickingCls.getPickedAtomList(e.pk,e.pAtom),i=e.pickingCls.getPickedAtomList(e.pk,e.pAtom2),n=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(s,e.atoms)).center,l=e.applyCenterCls.centerAtoms(t.hashUtilsCls.hash2Atoms(i,e.atoms)).center,r=0,o=0,a="#FFFF00",d=(n.x+l.x)/2,c=(n.y+l.y)/2,h=(n.z+l.z)/2,p=!0;e.analysisCls.addLine(n.x,n.y,n.z,l.x,l.y,l.z,a,p,"distance");let m=(parseInt(10*n.distanceTo(l))/10).toString()+" A";e.analysisCls.addLabel(m,d,c,h,r,a,o,"distance"),e.drawCls.draw(),e.cam.remove(e.canvasUI.mesh)}catch(e){}}},interaction:{type:"button",paddingTop:c,position:{top:118,left:406},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){try{e.viewInterPairsCls.viewInteractionPairs(["selected"],["non-selected"],!1,"3d",1,1,1,1,1,1),e.cam.remove(e.canvasUI.mesh)}catch(e){}}},delphi:{type:"button",paddingTop:c,position:{top:174,left:406},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:async function(){e.phisurftype=22,e.phisurfop=1,e.phisurfwf="no",await e.delphiCls.CalcPhi(65,.15,2,!0),e.cam.remove(e.canvasUI.mesh)}},removeLabel:{type:"button",paddingTop:c,position:{top:230,left:406},width:s,height:i,fontColor:o,fontSize:r,backgroundColor:a,hover:d,onSelect:function(){for(let t in e.labels)e.labels[t]=[];e.drawCls.draw(),e.cam.remove(e.canvasUI.mesh)}},renderer:e.renderer},p=new Oe({select:"Select",residue:"Residue",secondarySelect:"Secondary Structure",chainSelect:"Chain",atom:"Atom",reset:"Reset",togglehl:"Toggle Highlight",style:"Style",ribbon:"Ribbon",schematic:"Schematic",stick:"Stick",sphere:"Sphere",surface:"Surface",surfaceTrn:"Transparent Surface",color:"Color",rainbow:"Rainbow",atomColor:"Atom",chainColor:"Chain",secondaryColor:"Secondary Structure",AlphaFold:"AlphaFold",charge:"Charge",unicolor:"UniColor",red:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",green:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",blue:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",blueviolet:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",magenta:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",yellow:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",orange:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",cyan:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",gray:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",white:"<path>M 100 15 L 15 15 L 15 100 L 100 100 Z<path>",analysis:"Analysis",distance:"Distance",interaction:"Interaction",delphi:"DelPhi Potential",removeLabel:"Remove Label"},h);return p.mesh.position.set(0,0,-3),p}createUILog(){let e=this.icn3d;e.icn3dui;const t={panelSize:{width:2,height:2},height:512,info:{type:"text",overflow:"scroll",position:{top:6,left:6},width:506,height:506,backgroundColor:"#aaa",fontColor:"#000"},renderer:e.renderer},s=new Oe({info:"Debug info"},t);return s.mesh.position.set(0,-1,-2),s}getControllers(){let e=this.icn3d;e.icn3dui;const t=new xe,s=(new THREE.BufferGeometry).setFromPoints([new THREE.Vector3(0,0,0),new THREE.Vector3(0,0,-1)]),i=new THREE.Line(s);i.name="line",i.scale.z=50;const n=[];for(let s=0;s<=1;s++){const l=e.renderer.xr.getController(s);if(!l)continue;e.dolly.add(l),l.add(i.clone()),l.userData.selectPressed=!1,e.cam.add(l),n.push(l);const r=e.renderer.xr.getControllerGrip(s);r.add(t.createControllerModel(r)),e.scene.add(r)}return n}}class Ee{constructor(e){this.icn3d=e}setCamera(){let e=this.icn3d,t=e.icn3dui;if(e.bControlGl&&!t.bNode){window.cam=e.cams[e.opts.camera.toLowerCase()];let s=e.maxD;if(window.cam===e.perspectiveCamera){let i=void 0!==e.biomtMatrices&&e.biomtMatrices.length*e.cnt>e.maxatomcnt;i?window.camMaxDFactor=1:void 0!==window.camMaxDFactorFog?window.camMaxDFactor=window.camMaxDFactorFog:window.camMaxDFactor=3,window.cam_z>0?window.cam.position.z=s*window.camMaxDFactor:window.cam.position.z=-s*window.camMaxDFactor,"yes"===e.opts.slab?i?window.cam.near=.1:void 0!==window.camMaxDFactorFog?window.cam.near=s*window.camMaxDFactorFog-10:window.cam.near=s*window.camMaxDFactor:window.cam.near=.1,window.cam.far=1e4,e.bControlGl&&!t.bNode?window.controls=new THREE.TrackballControls(window.cam,void 0,e):t.bNode?e.controls=new THREE.TrackballControls(e.cam,document,e):e.controls=new THREE.TrackballControls(e.cam,document.getElementById(e.id),e)}else window.cam===e.orthographicCamera&&(void 0!==e.biomtMatrices&&e.biomtMatrices.length*e.cnt>10*e.maxatomcnt?window.cam.right=e.maxD/2*1.5:window.cam.right=e.maxD/2*2.5,window.cam.left=-window.cam.right,window.cam.top=window.cam.right/e.container.whratio,window.cam.bottom=-window.cam.right/e.container.whratio,"yes"===e.opts.slab?window.cam.near=2*e.maxD:window.cam.near=0,window.cam.far=1e4,e.bControlGl&&!t.bNode?window.controls=new THREE.OrthographicTrackballControls(window.cam,void 0,e):t.bNode?e.controls=new THREE.OrthographicTrackballControls(e.cam,document,e):e.controls=new THREE.OrthographicTrackballControls(e.cam,document.getElementById(e.id),e));window.cam.updateProjectionMatrix()}e.cam=e.cams[e.opts.camera.toLowerCase()];let s=e.maxD;if(e.cam===e.perspectiveCamera){let i=void 0!==e.biomtMatrices&&e.biomtMatrices.length*e.cnt>e.maxatomcnt;i?e.camMaxDFactor=1:void 0!==e.camMaxDFactorFog?e.camMaxDFactor=e.camMaxDFactorFog:e.camMaxDFactor=3,e.cam_z>0?e.cam.position.z=s*e.camMaxDFactor:e.cam.position.z=-s*e.camMaxDFactor,"yes"===e.opts.slab?i?e.cam.near=.1:void 0!==e.camMaxDFactorFog?e.cam.near=s*e.camMaxDFactorFog-10:e.cam.near=s*e.camMaxDFactor:e.cam.near=.1,e.cam.far=1e4,e.bControlGl&&!t.bNode?window.controls=new THREE.TrackballControls(e.cam,void 0,e):t.bNode?e.controls=new THREE.TrackballControls(e.cam,document,e):e.controls=new THREE.TrackballControls(e.cam,document.getElementById(e.id),e)}else e.cam===e.orthographicCamera&&(void 0!==e.biomtMatrices&&e.biomtMatrices.length*e.cnt>10*e.maxatomcnt?e.cam.right=e.maxD/2*1.5:e.cam.right=e.maxD/2*2.5,e.cam.left=-e.cam.right,e.cam.top=e.cam.right/e.container.whratio,e.cam.bottom=-e.cam.right/e.container.whratio,"yes"===e.opts.slab?e.cam.near=2*e.maxD:e.cam.near=0,e.cam.far=1e4,e.bControlGl&&!t.bNode?window.controls=new THREE.OrthographicTrackballControls(e.cam,void 0,e):t.bNode?e.controls=new THREE.OrthographicTrackballControls(e.cam,document,e):e.controls=new THREE.OrthographicTrackballControls(e.cam,document.getElementById(e.id),e));e.cam.updateProjectionMatrix()}}class Te{constructor(e){this.icn3d=e}setFog(e){let t=this.icn3d,s=t.icn3dui.parasCls.backgroundColors[t.opts.background.toLowerCase()];if(e){let e=t.applyCenterCls.centerAtoms(t.hAtoms);t.maxD=e.maxD,t.maxD<25&&(t.maxD=25)}let i=void 0!==t.biomtMatrices&&t.biomtMatrices.length*t.cnt>t.maxatomcnt;if("yes"===t.opts.fog)if("perspective"===t.opts.camera)if(i)t.scene.fog=void 0,t.bSetFog=!1;else{let e=t._zoomFactor>1?1*t._zoomFactor:t._zoomFactor;t.scene.fog=new THREE.Fog(s,2.5*t.maxD*e,4*t.maxD*e),t.bSetFog=!0,t.camMaxDFactorFog=3}else"orthographic"===t.opts.camera&&(t.scene.fog=void 0,t.bSetFog=!1);else t.scene.fog=void 0,t.bSetFog=!1}}class Pe{constructor(e){this.icn3d=e}createBox(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui;if(o.bNode)return;void 0===t&&(t=.8),void 0===s&&(s=!1),void 0===i&&(i=.8),l?void 0===n&&(n=r.hColor):void 0===n&&(n=e.color);let a=s?t:(o.parasCls.vdwRadii[e.elem.toUpperCase()]||t)*(i||1);this.createBox_base(e.coord,a,n,l)}createBox_base(e,t,s,i,n,l,r){let o,a=this.icn3d;a.icn3dui.bNode||(void 0===r&&(r=l?.5:1),new THREE.BoxGeometry(1,1,1),o=new THREE.Mesh(a.boxGeometry,new THREE.MeshPhongMaterial({transparent:!0,opacity:r,specular:a.frac,shininess:a.shininess,emissive:a.emissive,color:s})),o.scale.x=o.scale.y=o.scale.z=t,o.position.copy(e),a.mdl.add(o),i?a.prevHighlightObjects.push(o):n?a.prevOtherMesh.push(o):a.objects.push(o))}createBoxRepresentation_P_CA(e,t,s){let i=this.icn3d;if(i.icn3dui.bNode)return;let n=this;i.reprSubCls.createRepresentationSub(e,(function(e){"CA"!==e.name&&"O3'"!==e.name&&"O3*"!==e.name||n.createBox(e,void 0,void 0,t,void 0,s)}))}}class De{constructor(e){this.icn3d=e}createBrick(e,t,s,i){let n=this.icn3d;if(n.icn3dui.bNode)return;let l=new THREE.CylinderGeometry(1,1,1,4,1),r=new THREE.Mesh(l,new THREE.MeshPhongMaterial({specular:n.frac,shininess:n.shininess,emissive:n.emissive,color:i}));r.position.copy(e).add(t).multiplyScalar(.5),r.matrixAutoUpdate=!1,r.lookAt(t.clone().sub(e)),r.updateMatrix(),r.matrix.multiply((new THREE.Matrix4).makeScale(s,s,e.distanceTo(t))).multiply((new THREE.Matrix4).makeRotationX(.5*Math.PI)),n.mdl.add(r)}}class Me{constructor(e){this.icn3d=e}createCurveSubArrow(e,t,s,i,n,l,r,o,a,d,c,h,p,m,u){if(this.icn3d.icn3dui.bNode)return;let g=[],f=[];g.push(e),f.push(o),this.prepareStrand(g,f,t,s,i,void 0,n,l,r,a,d,!1,c,h,p,m,u),g=[],f=[]}createStripArrow(e,t,s,i,n,l,r,o,a,d,c,h,p,m,u,g){if(this.icn3d.icn3dui.bNode)return;let f=[],C=[];f.push(e),f.push(t),C.push(o),C.push(a),this.prepareStrand(f,C,void 0,s,i,n,l,void 0,r,d,c,!0,h,p,m,u,g),f=[],C=[]}prepareStrand(e,t,s,i,n,l,r,o,a,d,c,h,p,m,u,g,f){let C=this.icn3d,b=C.icn3dui;if(1===d.length)return;let y=i,v=!u,_=[];_.push(i[i.length-2]),_.push(i[i.length-1]),n=n||C.axisDIV;let w,S,A,x,k=2/(a-1),O={};for(let e=0,s=t.length;e<s;++e)O[e]=[];let R=b.subdivideCls.subdivide(d,i,n,void 0,void 0,g,f)[0];if(1===R.length)return;let I,E=[],T=void 0===u||u?d.length-2:d.length;for(I=0;I<T;++I){for(let s=0,i=t.length;s<i;++s)O[s].push(e[s][I]);E.push(i[I])}if(E.push(i[I]),void 0===u||u)for(let e=0,s=t.length;e<s;++e)w=k*t[e]-1,S=R.length-1-n,A=d.length-2,x=new THREE.Vector3(R[S].x+c[A].x*w,R[S].y+c[A].y*w,R[S].z+c[A].z*w),O[e].push(x);let P,D=[];for(let e=0,s=t.length;e<s;++e)P=b.subdivideCls.subdivide(O[e],E,n,p,r),O[e]=P[0],i=P[2],0===e&&(D=P[1]);if(h?v?C.bDoublecolor?C.stripCls.createStrip(O[0],O[1],y,n,l,r,!0,void 0,m,D,g,f,d,c):C.stripCls.createStrip(O[0],O[1],i,n,l,r,!0,void 0,m,D,g,f,d,c):C.stripCls.createStrip(O[0],O[1],i,n,l,r,!0,void 0,m,D,g,f):C.curveCls.createCurveSub(O[0],s,i,n,r,o,!0,void 0,m,D,g,f),void 0===u||u){E=[],D=[];for(let e=0,s=t.length;e<s;++e){O[e]=[];for(let s=n*(d.length-2),i=n*(d.length-1);p[parseInt(s/n)]&&s<i;s+=n){let i=parseInt(s/n);for(let l=0;l<n;++l){let r=k*t[e]-1;r=r*1.8*(n-l)/n;let o=parseInt(s/n),a=new THREE.Vector3(R[s+l].x+c[o].x*r,R[s+l].y+c[o].y*r,R[s+l].z+c[o].z*r);a.smoothen=!0,O[e].push(a),E.push(_[0]),0===e&&D.push(i)}}let s=0,i=R.length-1,l=d.length-1,r=new THREE.Vector3(R[i].x+c[l].x*s,R[i].y+c[l].y*s,R[i].z+c[l].z*s);r.smoothen=!0,O[e].push(r),E.push(_[1]),0===e&&D.push(i)}R=[],h?C.stripCls.createStrip(O[0],O[1],E,n,l,r,!0,void 0,void 0,D,g,f):C.curveCls.createCurveSub(O[0],s,E,n,r,o,!0,void 0,void 0,D,g,f)}for(let e in O){for(let t=0,s=O[e].length;t<s;++t)O[e][t]=null;O[e]=[]}O={}}}class Fe{constructor(e){this.icn3d=e}createCurveSub(e,t,s,i,n,l,r,o,a,d,c,h){let p,m=this.icn3d,u=m.icn3dui;if(!u.bNode&&0!==e.length){if(i=i||5,r)p=e;else{let t=!0,l=u.subdivideCls.subdivide(e,s,i,o,n,c,h,t);p=l[0],s=l[2]}if(0!==p.length){if(m.stripCls.setCalphaDrawnCoord(p,i,a),1===n){let e=m.coilWidth/2,t=4,s=!1;if(p.length>1)if(void 0!==d){let i,n,l=[];for(let r=0,o=p.length;r<o;++r){if(i=d[r],i!==n&&parseInt(i)!==parseInt(n)+1&&void 0!==n||r===o-1){let i=new THREE.TubeGeometry(new THREE.CatmullRomCurve3(l),l.length,e,t,s),n=new THREE.Mesh(i,m.matShader);n.renderOrder=m.renderOrderPicking,m.mdl.add(n),m.prevHighlightObjects.push(n),i=null,l=[]}l.push(p[r]),n=i}l=[]}else{let i=new THREE.TubeGeometry(new THREE.CatmullRomCurve3(p),p.length,e,t,s),n=new THREE.Mesh(i,m.matShader);n.renderOrder=m.renderOrderPicking,m.mdl.add(n),m.prevHighlightObjects.push(n),i=null}}else{let e,i=new THREE.BufferGeometry,r=[],o=[],a=0;if(2===n&&l)for(let t=0;t<p.length;++t,a+=3)p[t].addScalar(.6),r[a]=p[t].x,r[a+1]=p[t].y,r[a+2]=p[t].z,e=u.parasCls.thr(s[t]),o[a]=e.r,o[a+1]=e.g,o[a+2]=e.b;else for(let t=0;t<p.length;++t,a+=3)r[a]=p[t].x,r[a+1]=p[t].y,r[a+2]=p[t].z,e=u.parasCls.thr(s[t]),o[a]=e.r,o[a+1]=e.g,o[a+2]=e.b;let d=3;i.setAttribute("position",new THREE.BufferAttribute(new Float32Array(r),d)),i.setAttribute("color",new THREE.BufferAttribute(new Float32Array(o),d));let c=new THREE.Line(i,new THREE.LineBasicMaterial({linewidth:t,vertexColors:!0}));m.mdl.add(c),2===n?m.prevHighlightObjects.push(c):m.objects.push(c)}p=null}}}}class He{constructor(e){this.icn3d=e}createCylinder(e,t,s,i,n,l,r,o,a){let d=this.icn3d,c=d.icn3dui;if(c.bNode)return;let h,p=a;void 0===a&&(a=o?.5:1),1===n?(h=new THREE.Mesh(d.cylinderGeometryOutline,d.matShader),h.position.copy(e).add(t).multiplyScalar(.5),h.matrixAutoUpdate=!1,h.lookAt(t.clone().sub(e)),h.updateMatrix(),h.matrix.multiply((new THREE.Matrix4).makeScale(s,s,e.distanceTo(t))).multiply((new THREE.Matrix4).makeRotationX(.5*Math.PI)),h.renderOrder=d.renderOrderPicking,d.mdl.add(h),d.prevHighlightObjects.push(h)):(2===n?(h=new THREE.Mesh(d.cylinderGeometry,new THREE.MeshPhongMaterial({transparent:!0,opacity:a,specular:d.frac,shininess:d.shininess,emissive:d.emissive,color:i})),s*=1.5):h=new THREE.Mesh(d.cylinderGeometry,new THREE.MeshPhongMaterial({transparent:!0,opacity:a,specular:d.frac,shininess:d.shininess,emissive:d.emissive,color:i})),h.position.copy(e).add(t).multiplyScalar(.5),h.matrixAutoUpdate=!1,h.lookAt(t.clone().sub(e)),h.updateMatrix(),h.matrix.multiply((new THREE.Matrix4).makeScale(s,s,e.distanceTo(t))).multiply((new THREE.Matrix4).makeRotationX(.5*Math.PI)),!d.bImpo||p||o?d.mdl.add(h):(d.posArray.push(e.x),d.posArray.push(e.y),d.posArray.push(e.z),i||(i=c.parasCls.thr(16777215)),d.colorArray.push(i.r),d.colorArray.push(i.g),d.colorArray.push(i.b),d.pos2Array.push(t.x),d.pos2Array.push(t.y),d.pos2Array.push(t.z),void 0!==l?(d.color2Array.push(l.r),d.color2Array.push(l.g),d.color2Array.push(l.b)):(d.color2Array.push(i.r),d.color2Array.push(i.g),d.color2Array.push(i.b)),d.radiusArray.push(s),d.cnt<=d.maxatomcnt&&d.mdl_ghost.add(h)),2===n?d.bImpo&&!p?d.cnt<=d.maxatomcnt&&d.prevHighlightObjects_ghost.push(h):d.prevHighlightObjects.push(h):d.bImpo&&!p?d.cnt<=d.maxatomcnt&&d.objects_ghost.push(h):(void 0===r||r)&&d.objects.push(h))}createCylinder_base(e,t,s,i,n,l,r){let o=this.icn3d;if(o.icn3dui.bNode)return;let a=new THREE.Mesh(o.cylinderGeometry,new THREE.MeshPhongMaterial({specular:o.frac,shininess:o.shininess,emissive:o.emissive,color:i}));return a.position.copy(e).add(t).multiplyScalar(.5),a.matrixAutoUpdate=!1,a.lookAt(t.clone().sub(e)),a.updateMatrix(),a.matrix.multiply((new THREE.Matrix4).makeScale(s,s,e.distanceTo(t))).multiply((new THREE.Matrix4).makeRotationX(.5*Math.PI)),a}createCylinderHelix(e,t,s){let i=this.icn3d;if(i.icn3dui.bNode)return;let n,l,r,o=null,a={},d={};for(r in e){let c=e[r];c.het||(("helix"!==c.ss&&"sheet"!==c.ss||c.ssend||c.ssbegin)&&(a[c.serial]=c),"sheet"===c.ss&&(d[c.serial]=c),"CA"===c.name&&("helix"===c.ss&&c.ssend&&(null!==o&&n===c.chain&&parseInt(l)<parseInt(c.resi)&&(1===s||2===s?this.createCylinder(o.coord,c.coord,t,i.hColor,s):this.createCylinder(o.coord,c.coord,t,c.color)),o=null),null===o&&"helix"===c.ss&&c.ssbegin&&(o=c,n=c.chain,l=c.resi)))}1===s||2===s?(Object.keys(a).length>0&&i.tubeCls.createTube(a,"CA",i.coilWidth,s),Object.keys(d).length>0&&i.strandCls.createStrand(d,void 0,void 0,!0,0,i.helixSheetWidth,!1,2*i.ribbonthickness,s)):(Object.keys(a).length>0&&i.tubeCls.createTube(a,"CA",i.coilWidth),Object.keys(d).length>0&&i.strandCls.createStrand(d,void 0,void 0,!0,0,i.helixSheetWidth,!1,2*i.ribbonthickness))}createCylinderCurve(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui.bNode)return;let r,o,a,d,c,h,p=null;for(a in e)if(d=e[a],!d.het&&(c=d.structure+"_"+d.chain,h=d.structure+"_"+r,-1!=t.indexOf(d.name))){if(null!==p&&r===d.chain&&l.ParserUtilsCls.getResiNCBI(h,o)+1===l.ParserUtilsCls.getResiNCBI(c,d.resi)&&Math.abs(p.coord.x-d.coord.x)<8&&Math.abs(p.coord.y-d.coord.y)<8&&Math.abs(p.coord.z-d.coord.z)<8){let e=p.coord.clone().add(d.coord).multiplyScalar(.5);if(n)1===n&&(this.createCylinder(p.coord,e,s,p.color,n),this.createCylinder(e,d.coord,s,d.color,n),l.sphereCls.createSphere(d,s,!0,1,n));else if(i){let t=l.lineCls.createSingleLine(p.coord,e,p.color,!1);l.mdl.add(t),l.objects.push(t),t=l.lineCls.createSingleLine(e,d.coord,d.color,!1),l.mdl.add(t),l.objects.push(t)}else this.createCylinder(p.coord,e,s,p.color),this.createCylinder(e,d.coord,s,d.color),l.sphereCls.createSphere(d,s,!0,1,n)}p=d,r=d.chain,o=d.resi,l.sphereCls.createSphere(d,s,!0,1,n),2===n&&l.boxCls.createBox(d,void 0,void 0,void 0,void 0,n)}if(null!==p&&r===d.chain&&l.ParserUtilsCls.getResiNCBI(h,o)+1===l.ParserUtilsCls.getResiNCBI(c,d.resi)&&Math.abs(p.coord.x-d.coord.x)<8&&Math.abs(p.coord.y-d.coord.y)<8&&Math.abs(p.coord.z-d.coord.z)<8){let e=p.coord.add(d.coord).multiplyScalar(.5);if(n)1===n&&(this.createCylinder(p.coord,e,s,p.color,n),this.createCylinder(e,d.coord,s,d.color,n),l.sphereCls.createSphere(d,s,!0,1,n));else if(i){let t=l.lineCls.createSingleLine(p.coord,e,p.color,!1);l.mdl.add(t),l.objects.push(t),t=l.lineCls.createSingleLine(e,d.coord,d.color,!1),l.mdl.add(t),l.objects.push(t)}else this.createCylinder(p.coord,e,s,p.color),this.createCylinder(e,d.coord,s,d.color)}}}class Le{constructor(e){this.icn3d=e}createLineRepresentation(e,t){let s=this.icn3d;if(s.icn3dui.bNode)return;let i=new THREE.BufferGeometry,n=[],l=[],r=0,o=0;s.reprSubCls.createRepresentationSub(e,void 0,(function(e,t){if(e.color===t.color)n[r++]=e.coord.x,n[r++]=e.coord.y,n[r++]=e.coord.z,n[r++]=t.coord.x,n[r++]=t.coord.y,n[r++]=t.coord.z,l[o++]=e.color.r,l[o++]=e.color.g,l[o++]=e.color.b,l[o++]=t.color.r,l[o++]=t.color.g,l[o++]=t.color.b;else{let s=e.coord.clone().add(t.coord).multiplyScalar(.5);n[r++]=e.coord.x,n[r++]=e.coord.y,n[r++]=e.coord.z,n[r++]=s.x,n[r++]=s.y,n[r++]=s.z,n[r++]=t.coord.x,n[r++]=t.coord.y,n[r++]=t.coord.z,n[r++]=s.x,n[r++]=s.y,n[r++]=s.z,l[o++]=e.color.r,l[o++]=e.color.g,l[o++]=e.color.b,l[o++]=e.color.r,l[o++]=e.color.g,l[o++]=e.color.b,l[o++]=t.color.r,l[o++]=t.color.g,l[o++]=t.color.b,l[o++]=t.color.r,l[o++]=t.color.g,l[o++]=t.color.b}}));if(i.setAttribute("position",new THREE.BufferAttribute(new Float32Array(n),3)),i.setAttribute("color",new THREE.BufferAttribute(new Float32Array(l),3)),2!==t){let e;1===t||(e=new THREE.LineSegments(i,new THREE.LineBasicMaterial({linewidth:s.linewidth,vertexColors:!0})),s.mdl.add(e)),1===t?s.prevHighlightObjects.push(e):s.objects.push(e)}else 2===t&&s.boxCls.createBoxRepresentation_P_CA(e,.8,t)}createConnCalphSidechain(e,t){let s=this.icn3d;if(s.icn3dui.bNode)return;let i={};for(let s in e){let n=e[s];if(!n.het&&n.style2===t){i[n.structure+"_"+n.chain+"_"+n.resi]=1}}let n=[],l=[];for(let e in i){let t=s.firstAtomObjCls.getFirstAtomObjByName(s.residues[e],"CA");if(void 0!==t)for(let e=0,i=t.bonds.length;e<i;++e){let i=s.atoms[t.bonds[e]];"C"!==i.name&&"N"!==i.name&&"H"!==i.elem&&i.resi==t.resi&&(n.push(t.coord),n.push(i.coord),l.push(t.color),l.push(i.color))}}for(let e=0,i=n.length;e<i;e+=2)if("ball and stick"===t||"stick"===t||"ball and stick2"===t||"stick2"===t){let i="stick"===t||"stick2"===t?s.cylinderRadius:.5*s.cylinderRadius;s.cylinderCls.createCylinder(n[e],n[e+1],i,l[e+1])}else if("lines"===t||"lines2"===t){let t=this.createSingleLine(n[e],n[e+1],l[e+1],!1,.5);s.mdl.add(t)}}createSingleLine(e,t,s,i,n){if(this.icn3d.icn3dui.bNode)return;let l,r=new THREE.BufferGeometry,o=[];l=i?new THREE.LineDashedMaterial({linewidth:1,color:s,dashSize:n,gapSize:.5*n}):new THREE.LineBasicMaterial({linewidth:1,color:s}),o[0]=e.x,o[1]=e.y,o[2]=e.z,o[3]=t.x,o[4]=t.y,o[5]=t.z;r.setAttribute("position",new THREE.BufferAttribute(new Float32Array(o),3));let a=new THREE.LineSegments(r,l);return i&&a.computeLineDistances(),a}createLines(e){let t=this.icn3d,s=t.icn3dui;if(!s.bNode&&void 0!==e)for(let i in e){let n=e[i];for(let e=0,l=n.length;e<l;++e){let l=n[e],r=l.position1,o=l.position2,a=!!l.dashed&&l.dashed,d="missingres"==i?.8:.3,c=l.radius?l.radius:t.lineRadius,h=l.opacity?l.opacity:1,p="#"+l.color.replace(/\#/g,""),m=s.parasCls.thr(p);if(a){let e,s,n=r.distanceTo(o),l=parseInt(n/d),a=o.clone().sub(r).multiplyScalar(d/n);for(let n=0;n<l;++n)n%2==1&&(e=r.clone().add(a.clone().multiplyScalar(n)),s=r.clone().add(a.clone().multiplyScalar(n+1)),"stabilizer"==i?t.brickCls.createBrick(e,s,c,m):t.cylinderCls.createCylinder(e,s,c,m,void 0,void 0,void 0,void 0,h))}else"stabilizer"==i?t.brickCls.createBrick(r,o,c,m):t.cylinderCls.createCylinder(r,o,c,m,void 0,void 0,void 0,void 0,h)}}}}class Ne{constructor(e){this.icn3d=e}createRepresentationSub(e,t,s){if(!this.icn3d.icn3dui.bNode)for(let i in e){let n=e[i];t&&t(n);for(let e in n.bonds){let t=this.icn3d.atoms[n.bonds[e]];void 0===t||t.serial<n.serial||t.chain===n.chain&&(t.resi===n.resi||"C"===n.name&&"N"===t.name||"O3'"===n.name&&"P"===t.name||"O3*"===n.name&&"P"===t.name||"SG"===n.name&&"SG"===t.name)&&s&&s(n,t)}}}}class qe{constructor(e){this.icn3d=e}createSphere(e,t,s,i,n){let l=this.icn3d.icn3dui;if(l.bNode)return;void 0===t&&(t=.8),void 0===s&&(s=!1);let r=l.parasCls.vdwRadii[e.elem.toUpperCase()]||t;s&&(r=t,i=1),this.createSphereBase(e.coord,e.color,r,i,n)}createSphereBase(e,t,s,i,n,l,r){let o,a=this.icn3d,d=a.icn3dui;if(d.bNode)return;void 0===i&&(i=1);let c=r;if(void 0===r&&(r=l?.5:1),2===n)i*=1.5,t=a.hColor,o=new THREE.Mesh(a.sphereGeometry,new THREE.MeshPhongMaterial({transparent:!0,opacity:r,specular:a.frac,shininess:a.shininess,emissive:a.emissive,color:t})),o.scale.x=o.scale.y=o.scale.z=s*(i||1),o.position.copy(e),a.mdl.add(o);else if(1===n)o=new THREE.Mesh(a.sphereGeometry,a.matShader),o.scale.x=o.scale.y=o.scale.z=s*(i||1),o.position.copy(e),o.renderOrder=a.renderOrderPicking,a.mdl.add(o);else if(void 0===t&&(t=d.parasCls.defaultAtomColor),o=new THREE.Mesh(a.sphereGeometry,new THREE.MeshPhongMaterial({transparent:!0,opacity:r,specular:a.frac,shininess:a.shininess,emissive:a.emissive,color:t})),o.scale.x=o.scale.y=o.scale.z=s*(i||1),o.position.copy(e),!a.bImpo||c||l)a.mdl.add(o);else{a.posArraySphere.push(e.x),a.posArraySphere.push(e.y),a.posArraySphere.push(e.z),a.colorArraySphere.push(t.r),a.colorArraySphere.push(t.g),a.colorArraySphere.push(t.b);let n=s*(i||1);a.radiusArraySphere.push(n),a.cnt<=a.maxatomcnt&&a.mdl_ghost.add(o)}1===n||2===n?a.bImpo?a.cnt<=a.maxatomcnt&&a.prevHighlightObjects_ghost.push(o):a.prevHighlightObjects.push(o):a.bImpo&&!c?a.cnt<=a.maxatomcnt&&a.objects_ghost.push(o):a.objects.push(o)}createSphereRepresentation(e,t,s,i,n){let l=this.icn3d;if(l.icn3dui.bNode)return;let r=this;l.reprSubCls.createRepresentationSub(e,(function(e){r.createSphere(e,t,s,i,n)}))}}class Ue{constructor(e){this.icn3d=e}createStickRepresentation(e,t,s,i,n,l){let r=this.icn3d;if(r.icn3dui.bNode)return;let o=void 0!==l&&l?t/r.cylinderRadius:1,a=r.cylinderRadius*o*.4,d=r.cylinderRadius*o*.3;r.reprSubCls.createRepresentationSub(e,(function(e){r.sphereCls.createSphere(e,t,!i,i,n)}),(function(e,t){let i=e.coord.clone().add(t.coord).multiplyScalar(.5),l=e.serial+"_"+t.serial;if(r.doublebonds.hasOwnProperty(l)){let s,l,d,c,h=new THREE.Vector3(Math.random(),Math.random(),Math.random());if(1==e.bonds.length&&1==t.bonds.length){c=t.coord.clone(),c.sub(e.coord);let s=h.clone();c.cross(s).normalize().multiplyScalar(.2*o)}else{if(e.bonds.length>=t.bonds.length&&e.bonds.length>1)s=e.serial,l=e.bonds[0],d=e.bonds[1];else{if(!(t.bonds.length>=e.bonds.length&&t.bonds.length>1))return void console.log("Double bond was not drawn due to the undefined cross plane");s=t.serial,l=t.bonds[0],d=t.bonds[1]}let i=r.atoms[s].coord.clone();i.sub(r.atoms[l].coord);let n=r.atoms[s].coord.clone();n.sub(r.atoms[d].coord),i.cross(n),0==parseInt(1e4*i.length())&&(i=new THREE.Vector3(.2,.3,.5)),c=t.coord.clone(),c.sub(e.coord),c.cross(i).normalize().multiplyScalar(.2*o),0==parseInt(1e4*c.length())&&(i=new THREE.Vector3(.5,.3,.2),c.cross(i).normalize().multiplyScalar(.2*o))}e.color===t.color?r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord.clone().add(c),t.coord.clone().add(c),a,e.color,n),r.cylinderCls.createCylinder(e.coord.clone().sub(c),t.coord.clone().sub(c),a,e.color,n)):r.bImpo?r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord.clone().add(c),t.coord.clone().add(c),a,e.color,n,t.color),r.cylinderCls.createCylinder(e.coord.clone().sub(c),t.coord.clone().sub(c),a,e.color,n,t.color)):r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord.clone().add(c),i.clone().add(c),a,e.color,n),r.cylinderCls.createCylinder(t.coord.clone().add(c),i.clone().add(c),a,t.color,n),r.cylinderCls.createCylinder(e.coord.clone().sub(c),i.clone().sub(c),a,e.color,n),r.cylinderCls.createCylinder(t.coord.clone().sub(c),i.clone().sub(c),a,t.color,n))}else if(r.aromaticbonds.hasOwnProperty(l)){let s,l,d;if(e.bonds.length>t.bonds.length&&e.bonds.length>1)s=e.serial,l=e.bonds[0],d=e.bonds[1];else{if(!(t.bonds.length>1))return;s=t.serial,l=t.bonds[0],d=t.bonds[1]}let c=r.atoms[s].coord.clone();c.sub(r.atoms[l].coord);let h=r.atoms[s].coord.clone();h.sub(r.atoms[d].coord),c.cross(h);let p=t.coord.clone();p.sub(e.coord),p.cross(c).normalize().multiplyScalar(.2*o);let m=0;for(let s=0,i=e.bondOrder.length;s<i;++s)"1.5"===e.bondOrder[s]&&e.bonds[s]!==t.serial&&(m=e.bonds[s]);let u="add";if(0===m)u="add";else{let s=e.coord.clone().add(p),i=e.coord.clone().sub(p),n=t.coord.clone().sub(s).normalize(),l=r.atoms[m].coord.clone().sub(s).normalize(),o=t.coord.clone().sub(i).normalize(),a=r.atoms[m].coord.clone().sub(i).normalize();u=Math.acos(n.dot(l))<Math.acos(o.dot(a))?"sub":"add"}if(e.color===t.color){let s,i;"add"===u?(r.cylinderCls.createCylinder(e.coord.clone().sub(p),t.coord.clone().sub(p),a,e.color,n),s=e.coord.clone().add(p),i=t.coord.clone().add(p).sub(s).multiplyScalar(1/11)):(r.cylinderCls.createCylinder(e.coord.clone().add(p),t.coord.clone().add(p),a,e.color,n),s=e.coord.clone().sub(p),i=t.coord.clone().sub(p).sub(s).multiplyScalar(1/11));for(let t=0;t<=10;++t)if(t%2==0){let l=s.clone().add(i.clone().multiplyScalar(t)),o=s.clone().add(i.clone().multiplyScalar(t+1));r.cylinderCls.createCylinder(l,o,a,e.color,n)}}else{let s,l;"add"===u?(r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord.clone().sub(p),i.clone().sub(p),a,e.color,n),r.cylinderCls.createCylinder(t.coord.clone().sub(p),i.clone().sub(p),a,t.color,n)),s=e.coord.clone().add(p),l=t.coord.clone().add(p).sub(s).multiplyScalar(1/11)):(r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord.clone().add(p),i.clone().add(p),a,e.color,n),r.cylinderCls.createCylinder(t.coord.clone().add(p),i.clone().add(p),a,t.color,n)),s=e.coord.clone().sub(p),l=t.coord.clone().sub(p).sub(s).multiplyScalar(1/11));for(let i=0;i<=10;++i)if(i%2==0&&r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)){let o=s.clone().add(l.clone().multiplyScalar(i)),d=s.clone().add(l.clone().multiplyScalar(i+1));i<5?r.cylinderCls.createCylinder(o,d,a,e.color,n):r.cylinderCls.createCylinder(o,d,a,t.color,n)}}}else if(r.triplebonds.hasOwnProperty(l)){let s=new THREE.Vector3(Math.random(),Math.random(),Math.random()),l=t.coord.clone();l.sub(e.coord);let a=s.clone();a.cross(l).normalize().multiplyScalar(.3*o),e.color===t.color?r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord,t.coord,d,e.color,n),r.cylinderCls.createCylinder(e.coord.clone().add(a),t.coord.clone().add(a),d,e.color,n),r.cylinderCls.createCylinder(e.coord.clone().sub(a),t.coord.clone().sub(a),r.triBondRadius,e.color,n)):r.bImpo?r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord,t.coord,d,e.color,n,t.color),r.cylinderCls.createCylinder(e.coord.clone().add(a),t.coord.clone().add(a),d,e.color,n,t.color),r.cylinderCls.createCylinder(e.coord.clone().sub(a),t.coord.clone().sub(a),d,e.color,n,t.color)):r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord,i,d,e.color,n),r.cylinderCls.createCylinder(t.coord,i,d,t.color,n),r.cylinderCls.createCylinder(e.coord.clone().add(a),i.clone().add(a),d,e.color,n),r.cylinderCls.createCylinder(t.coord.clone().add(a),i.clone().add(a),d,t.color,n),r.cylinderCls.createCylinder(e.coord.clone().sub(a),i.clone().sub(a),d,e.color,n),r.cylinderCls.createCylinder(t.coord.clone().sub(a),i.clone().sub(a),d,t.color,n))}else e.color===t.color?r.cylinderCls.createCylinder(e.coord,t.coord,s,e.color,n):r.bImpo?r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&r.cylinderCls.createCylinder(e.coord,t.coord,s,e.color,n,t.color):r.dAtoms.hasOwnProperty(e.serial)&&r.dAtoms.hasOwnProperty(t.serial)&&(r.cylinderCls.createCylinder(e.coord,i,s,e.color,n),r.cylinderCls.createCylinder(t.coord,i,s,t.color,n))}))}}class Be{constructor(e){this.icn3d=e}createStrand(e,t,s,i,n,l,r,o,a){let d=this.icn3d,c=d.icn3dui;if(c.bNode)return;let h=!!i,p={};p=Object.keys(e).length<Object.keys(d.atoms).length?this.getSSExpandedAtoms(e):e,2===a&&(i?(i=!1,t=null,s=null,n=null,l=null,o=void 0):(i=!0,t=2,s=void 0,n=void 0,l=void 0,o=d.ribbonthickness)),t=t||d.strandDIV,s=s||d.axisDIV,n=n||d.coilWidth,r=r||!1,l=l||d.helixSheetWidth;let m={};for(let e=0;e<t;++e)m[e]=[];let u,g,f,C,b=[],y=[],v=[],_=[],w=[],S=null,A=null,x=null,k=null,O=null,R=null,I=null,E=null,T=!1,P=null,D=null,M=null,F=null,H=null,L=null,N=!1,q=!1,U={};d.bCalphaOnly=c.utilsCls.isCalphaPhosOnly(p);let B={};for(let e in p){let t=p[e];B[t.structure+"_"+t.chain+"_"+t.resi]=1}let $=Object.keys(B).length,j=0,z=Object.keys(d.hAtoms).length==Object.keys(d.atoms).length,G=[];for(let c in p){C=p[c];let B=C.structure+"_"+C.chain;if(("O"===C.name||"CA"===C.name)&&!C.het&&("CA"===C.name&&(e.hasOwnProperty(c)&&("helix"!==C.ss&&"sheet"!==C.ss||C.ssend||C.ssbegin)&&(U[c]=C),S=C.coord,x=C.color,H=C.serial,G.push(C.serial)),"O"===C.name||d.bCalphaOnly&&"CA"===C.name)){if(null==S&&(S=C.coord,x=C.color,H=C.serial),"O"===C.name&&(A=C.coord),C.ssend&&"sheet"===C.ss?N=!0:C.ssend&&"helix"===C.ss&&(q=!0),O){1===a||2===a?w.push(d.hColor):w.push(R),f="coil"!==E&&"coil"===C.ss||T&&C.ssbegin||"coil"===E?n:l;let s,i,o=4;"O"===C.name?(s=O.clone(),null!=k?s.sub(k):(k=O.clone(),G.length>o+1?(s=k.clone(),i=d.atoms[G[G.length-1-o-1]].coord.clone(),i.sub(s)):s=new THREE.Vector3(Math.random(),Math.random(),Math.random()))):d.bCalphaOnly&&"CA"===C.name&&(G.length>o+1?(s=k.clone(),i=d.atoms[G[G.length-1-o-1]].coord.clone(),i.sub(s)):s=new THREE.Vector3(Math.random(),Math.random(),Math.random())),s.normalize(),s.multiplyScalar(f),null!==I&&s.dot(I)<0&&s.negate(),I=s;for(let e=0,s=2/(t-1);e<t;++e){let t=s*e-1,i=new THREE.Vector3(k.x+I.x*t,k.y+I.y*t,k.z+I.z*t);r||"sheet"!==E||(i.smoothen=!0),m[e].push(i)}b.push(k),y.push(I),e.hasOwnProperty(D)?(v.push(F),_.push(L)):(v.push(0),_.push(0)),++j}let c=M?M.coord:void 0,p=d.ParserUtilsCls.getResiNCBI(C.structure+"_"+u,g)+1!==d.ParserUtilsCls.getResiNCBI(B,C.resi)||c&&Math.abs(S.x-c.x)>6||c&&Math.abs(S.y-c.y)>6||c&&Math.abs(S.z-c.z)>6;if((u!==C.chain||C.ssbegin||C.ssend||j===$-1||p)&&m[0].length>0){let c="CA",u=[],g=[];if(isNaN(d.atoms[D].resi))u=[];else{let e=d.atoms[D].structure+"_"+d.atoms[D].chain+"_"+(parseInt(d.atoms[D].resi)-1).toString(),t=d.firstAtomObjCls.getAtomCoordFromResi(e,c);u=void 0!==t?[t]:[]}if(!isNaN(d.atoms[D].resi)){let e=d.atoms[D].structure+"_"+d.atoms[D].chain+"_"+(parseInt(d.atoms[D].resi)+1).toString(),t=d.firstAtomObjCls.getAtomCoordFromResi(e,c);void 0!==t&&g.push(t);let s=d.atoms[D].structure+"_"+d.atoms[D].chain+"_"+(parseInt(d.atoms[D].resi)+2).toString(),i=d.firstAtomObjCls.getAtomCoordFromResi(s,c);void 0!==i&&g.push(i)}if(!p){1===a||2===a?w.push(d.hColor):w.push(R),f=C.ssend&&"sheet"===C.ss?0:"coil"===E&&C.ssbegin||T&&C.ssbegin||"coil"===C.ss?n:l;let s,i,o=4;"O"===C.name?(s=A.clone(),s.sub(S)):d.bCalphaOnly&&"CA"===C.name&&(G.length>o?(s=S.clone(),i=d.atoms[G[G.length-1-o]].coord.clone(),i.sub(s)):s=new THREE.Vector3(Math.random(),Math.random(),Math.random())),s.normalize(),s.multiplyScalar(f),null!==I&&s.dot(I)<0&&s.negate(),I=s;for(let e=0,s=2/(t-1);e<t;++e){let t=s*e-1,i=new THREE.Vector3(S.x+I.x*t,S.y+I.y*t,S.z+I.z*t);r||"sheet"!==E||(i.smoothen=!0),m[e].push(i)}P=C.serial,b.push(S),y.push(I),e.hasOwnProperty(P)?(v.push(C.resi),_.push(H)):(v.push(0),_.push(0))}for(let e=0;!i&&e<t;++e)N?d.curveStripArrowCls.createCurveSubArrow(m[e],1,w,s,a,h,t,e,b,y,v,_,!0,u,g):q&&(z?d.curveCls.createCurveSub(m[e],1,w,s,a,h,!1,v,_,void 0,u,g):d.curveStripArrowCls.createCurveSubArrow(m[e],1,w,s,a,h,t,e,b,y,v,_,!1,u,g));if(i)if(N){let e=0,i=t-1;d.curveStripArrowCls.createStripArrow(m[0],m[t-1],w,s,o,a,t,e,i,b,y,v,_,!0,u,g)}else if(q)if(z)d.stripCls.createStrip(m[0],m[t-1],w,s,o,a,!1,v,_,void 0,u,g,b,y);else{let e=0,i=t-1;d.curveStripArrowCls.createStripArrow(m[0],m[t-1],w,s,o,a,t,e,i,b,y,v,_,!1,u,g)}else 2===a&&d.stripCls.createStrip(m[0],m[t-1],w,s,o,a,!1,v,_,void 0,u,g,b,y);for(let e=0;e<t;++e)m[e]=[];w=[],b=[],y=[],v=[],_=[],N=!1,q=!1}if((u!==C.chain||d.ParserUtilsCls.getResiNCBI(C.structure+"_"+u,g)+1!==d.ParserUtilsCls.getResiNCBI(B,C.resi))&&m[0].length>0){let e="CA",n=[],l=[];if(isNaN(d.atoms[D].resi))n=[];else{let t=d.atoms[D].structure+"_"+d.atoms[D].chain+"_"+(parseInt(d.atoms[D].resi)-1).toString();d.firstAtomObjCls.getAtomCoordFromResi(t,e)}for(let e=0;!i&&e<t;++e)N?d.curveStripArrowCls.createCurveSubArrow(m[e],1,w,s,a,h,t,e,b,y,v,_,!0,n,l):q&&(z?d.curveCls.createCurveSub(m[e],1,w,s,a,h,!1,v,_,void 0,n,l):d.curveStripArrowCls.createCurveSubArrow(m[e],1,w,s,a,h,t,e,b,y,v,_,!1,n,l));if(i)if(N){let e=0,i=t-1;d.curveStripArrowCls.createStripArrow(m[0],m[t-1],w,s,o,a,t,e,i,b,y,v,_,!0,n,l)}else if(q)if(z)d.stripCls.createStrip(m[0],m[t-1],w,s,o,a,!1,v,_,void 0,n,l,b,y);else{let e=0,i=t-1;d.curveStripArrowCls.createStripArrow(m[0],m[t-1],w,s,o,a,t,e,i,b,y,v,_,!1,n,l)}for(let e=0;e<t;++e)m[e]=[];w=[],b=[],y=[],v=[],_=[],N=!1,q=!1}u=C.chain,g=C.resi,E=C.ss,T=C.ssend,D=C.serial,e.hasOwnProperty(C.serial)&&(M=C),F=C.resi,L=H,k=S,O=C.coord,R=x}}G=[],d.tubeCls.createTube(U,"CA",n,a),U={},m={}}getSSExpandedAtoms(e,t){let s,i,n,l,r,o,a,d,c=this.icn3d,h=c.icn3dui,p=0,m=Object.keys(e).length,u=h.hashUtilsCls.cloneHash(e);for(let g in e){if(s=e[g].structure+"_"+e[g].chain,i=e[g].resi,n=e[g],void 0===l&&(a=e[g]),s!==l&&void 0!==l||i!==r&&c.resid2ncbi[i]!==c.resid2ncbi[r]+1&&void 0!==r||p===m-1){s!==l&&void 0!==l||i!==r&&i!==c.resid2ncbi[r]+1&&void 0!==r?d=o:p===m-1&&(d=n);let g=a.resi;if(!isNaN(a.resi)&&"coil"!==a.ss&&!a.ssbegin){for(let e=parseInt(a.resi)-1;e>0;--e){let t=a.structure+"_"+a.chain+"_"+e;if(!c.residues.hasOwnProperty(t))break;let s=c.firstAtomObjCls.getFirstCalphaAtomObj(c.residues[t]);if(s.ss===a.ss&&s.ssbegin){g=s.resi;break}}for(let e=g;e<a.resi;++e){let t=a.structure+"_"+a.chain+"_"+e;u=h.hashUtilsCls.unionHash(u,h.hashUtilsCls.hash2Atoms(c.residues[t],c.atoms))}}if(!isNaN(a.resi)&&3===c.pk&&1===t&&"coil"===a.ss){let t=a.structure+"_"+a.chain+"_"+(parseInt(a.resi)-1).toString();c.residues.hasOwnProperty(t)&&(u=h.hashUtilsCls.unionHash(u,h.hashUtilsCls.hash2Atoms(c.residues[t],c.atoms)),e=h.hashUtilsCls.unionHash(e,h.hashUtilsCls.hash2Atoms(c.residues[t],c.atoms)))}let f=d.resi;if(void 0!==d.ss&&"coil"!==d.ss&&!d.ssend&&!d.notshow){let e=c.firstAtomObjCls.getLastAtomObj(c.chains[d.structure+"_"+d.chain]).resi;for(let t=parseInt(d.resi)+1;t<=parseInt(e);++t){let e=d.structure+"_"+d.chain+"_"+t;if(!c.residues.hasOwnProperty(e))break;let s=c.firstAtomObjCls.getFirstCalphaAtomObj(c.residues[e]);if(s.ss===d.ss&&s.ssend){f=s.resi;break}}for(let e=parseInt(d.resi)+1;e<=parseInt(f);++e){let t=d.structure+"_"+d.chain+"_"+e;u=h.hashUtilsCls.unionHash(u,h.hashUtilsCls.hash2Atoms(c.residues[t],c.atoms))}}if(3===c.pk&&1===t&&"coil"===d.ss){let t=d.structure+"_"+d.chain+"_"+(parseInt(d.resi)+1).toString();c.residues.hasOwnProperty(t)&&(u=h.hashUtilsCls.unionHash(u,h.hashUtilsCls.hash2Atoms(c.residues[t],c.atoms)),e=h.hashUtilsCls.unionHash(e,h.hashUtilsCls.hash2Atoms(c.residues[t],c.atoms)))}d.notshow&&(d.notshow=void 0),a=n}l=s,r=i,o=n,++p}return u}}class $e{constructor(e){this.icn3d=e}createStrip(e,t,s,i,n,l,r,o,a,d,c,h,p,m){let u=this.icn3d,g=u.icn3dui;if(!(g.bNode||e.length<2)){if(i=i||u.axisDIV,p&&u.bDoublecolor&&!u.bCalphaOnly){let e=!1,t=g.subdivideCls.subdivide(p,s,i,o,l,c,h,e);p=t[0],this.setCalphaDrawnCoord(p,i,a);for(let e=0,t=m.length;e<t;++e)m[e].normalize();m=g.subdivideCls.subdivide(m,s,i,o,l,c,h,e)[0],s=t[2]}else{if(!r){let n=!1,r=g.subdivideCls.subdivide(e,s,i,o,l,c,h,n),a=g.subdivideCls.subdivide(t,s,i,o,l,c,h,n);e=r[0],t=a[0],s=r[2]}if(e.length<2)return;this.setCalphaDrawnCoord(e,i,a)}if(1===l){let s=u.coilWidth/2,i=4,n=!1;if(void 0!==d){let l,r,o=[],a=[];for(let c=0,h=e.length;c<h;++c){if(l=d[c],l!==r&&parseInt(l)!==parseInt(r)+1&&void 0!==r||c===h-1){let e=new THREE.TubeGeometry(new THREE.CatmullRomCurve3(o),o.length,s,i,n),t=new THREE.Mesh(e,u.matShader);t.renderOrder=u.renderOrderPicking,u.mdl.add(t),u.prevHighlightObjects.push(t),e=null;let l=new THREE.TubeGeometry(new THREE.CatmullRomCurve3(a),a.length,s,i,n);t=new THREE.Mesh(l,u.matShader),t.renderOrder=u.renderOrderPicking,u.mdl.add(t),u.prevHighlightObjects.push(t),l=null,o=[],a=[]}o.push(e[c]),a.push(t[c]),r=l}o=[],a=[]}else{let l=new THREE.TubeGeometry(new THREE.CatmullRomCurve3(e),e.length,s,i,n),r=new THREE.Mesh(l,u.matShader);r.renderOrder=u.renderOrderPicking,u.mdl.add(r),u.prevHighlightObjects.push(r),l=null;let o=new THREE.TubeGeometry(new THREE.CatmullRomCurve3(t),t.length,s,i,n);r=new THREE.Mesh(o,u.matShader),r.renderOrder=u.renderOrderPicking,u.mdl.add(r),u.prevHighlightObjects.push(r),o=null}}else{let i,r,o,a,d,c=new THREE.BufferGeometry,h=[],p=[],m=[],g=0,f=0,C=0;for(let l=0,c=e.length;l<c;++l)if(r=e[l],o=t[l],r&&o){for(let e=0;e<2;++e)h[g++]=r.x,h[g++]=r.y,h[g++]=r.z;for(let e=0;e<2;++e)h[g++]=o.x,h[g++]=o.y,h[g++]=o.z;l<c-1&&(i=t[l].clone().sub(e[l]).cross(e[l+1].clone().sub(e[l])).normalize().multiplyScalar(n)),a=e[l].clone().add(i),d=t[l].clone().add(i);for(let e=0;e<2;++e)h[g++]=a.x,h[g++]=a.y,h[g++]=a.z;for(let e=0;e<2;++e)h[g++]=d.x,h[g++]=d.y,h[g++]=d.z;for(let e=0;e<8;++e){let e=s[l]?s[l]:s[l-1]?s[l-1]:{r:0,g:0,b:0};p[f++]=e.r,p[f++]=e.g,p[f++]=e.b}}let b=[[0,2,-6,-8],[-4,-2,6,4],[7,3,-5,-1],[-3,-7,1,5]];for(let t=1,s=e.length;t<s;++t){let e=8*t;for(let t=0;t<4;++t)m[C++]=e+b[t][0],m[C++]=e+b[t][1],m[C++]=e+b[t][2],m[C++]=e+b[t][3],m[C++]=e+b[t][0],m[C++]=e+b[t][2]}let y,v=3,_=h.length/v-8;for(let t=0;t<4;++t){for(let e=0;e<v;++e)h[g++]=h[2*t*v+e];for(let e=0;e<v;++e)h[g++]=h[(_+2*t)*v+e];if(s[0]){p[f++]=s[0].r,p[f++]=s[0].g,p[f++]=s[0].b;let t=s[e.length-1]?s[e.length-1]:s[e.length-2]?s[e.length-2]:{r:0,g:0,b:0};p[f++]=t.r,p[f++]=t.g,p[f++]=t.b}}_+=8,m[C++]=_,m[C++]=_+2,m[C++]=_+6,m[C++]=_+4,m[C++]=_,m[C++]=_+6,m[C++]=_+1,m[C++]=_+5,m[C++]=_+7,m[C++]=_+3,m[C++]=_+1,m[C++]=_+7,c.setAttribute("position",new THREE.BufferAttribute(new Float32Array(h),v)),c.setAttribute("color",new THREE.BufferAttribute(new Float32Array(p),v)),c.setIndex(new THREE.BufferAttribute(new Uint32Array(m),1)),c.computeVertexNormals(),2===l?(y=new THREE.Mesh(c,new THREE.MeshPhongMaterial({transparent:!0,opacity:.5,specular:u.frac,shininess:u.shininess,emissive:u.emissive,vertexColors:!0,side:THREE.DoubleSide})),u.mdl.add(y),u.prevHighlightObjects.push(y)):(y=new THREE.Mesh(c,new THREE.MeshPhongMaterial({specular:u.frac,shininess:u.shininess,emissive:u.emissive,vertexColors:!0,side:THREE.DoubleSide})),u.mdl.add(y),u.objects.push(y))}e=null,t=null}}setCalphaDrawnCoord(e,t,s){let i=this.icn3d;i.icn3dui;let n=0;if(void 0!==s)for(let l=0,r=e.length;l<r;l+=t){let t=s[n];i.atoms.hasOwnProperty(t)&&(i.atoms[t].coord2=e[l].clone()),++n}}}class je{constructor(e){this.icn3d=e}createTube(e,t,s,i,n,l){let r=this.icn3d;if(r.icn3dui.bNode)return;let o,a,d,c,h,p=[],m=[],u=[],g=[],f=[],C=0,b=[];for(let l in e)if(c=e[l],c.name===t&&!c.het){if(0==C&&(d=c),c.structure,c.chain,(parseInt(c.resi)-1).toString(),C>0&&(o!==c.chain||Math.abs(c.coord.x-h.coord.x)>6||Math.abs(c.coord.y-h.coord.y)>6||Math.abs(c.coord.z-h.coord.z)>6||r.ParserUtilsCls.getResiNCBI(c.structure+"_"+o,a)+1<r.ParserUtilsCls.getResiNCBI(c.structure+"_"+c.chain,c.resi)&&(Math.abs(c.coord.x-h.coord.x)>3||Math.abs(c.coord.y-h.coord.y)>3||Math.abs(c.coord.z-h.coord.z)>3))){if(2!==i){if(!isNaN(d.resi)&&!isNaN(h.resi)){let e=d.structure+"_"+d.chain+"_"+(parseInt(d.resi)-1).toString(),i=r.firstAtomObjCls.getAtomCoordFromResi(e,t);g=void 0!==i?[i]:[];let l=h.structure+"_"+h.chain+"_"+(parseInt(h.resi)+1).toString(),o=h.structure+"_"+h.chain+"_"+(parseInt(h.resi)+2).toString(),a=h.structure+"_"+h.chain+"_"+(parseInt(h.resi)+3).toString();if(r.residues.hasOwnProperty(l)){let e=r.firstAtomObjCls.getAtomFromResi(l,t);void 0!==e&&e.ssbegin&&(l=h.structure+"_"+h.chain+"_"+(parseInt(h.resi)+2).toString(),o=h.structure+"_"+h.chain+"_"+(parseInt(h.resi)+3).toString(),p.push(e.coord),n?u.push(this.getCustomtubesize(l)):u.push(this.getRadius(s,e)),m.push(e.color))}if(1==p.length&&r.residues.hasOwnProperty(l)){let e=r.firstAtomObjCls.getAtomFromResi(l,t);if(e){p.push(e.coord),m.push(e.color);let t=this.getRadius(s,c);u.push(t),l=o,o=a}}let C=r.firstAtomObjCls.getAtomCoordFromResi(l,t);void 0!==C&&f.push(C);let b=r.firstAtomObjCls.getAtomCoordFromResi(o,t);void 0!==b&&f.push(b)}b.push({pnts:p,colors:m,radii:u,prevone:g,nexttwo:f})}p=[],m=[],u=[],g=[],f=[],d=c,C=0}if(0==p.length&&!isNaN(c.resi)){let e=c.structure+"_"+c.chain+"_"+(parseInt(c.resi)-1).toString();r.residues.hasOwnProperty(e)&&(h=r.firstAtomObjCls.getAtomFromResi(e,t),void 0!==h&&h.ssend&&(p.push(h.coord),n?u.push(this.getCustomtubesize(e)):u.push(this.getRadius(s,h)),m.push(h.color)))}let e;p.push(c.coord),e=n?this.getCustomtubesize(c.structure+"_"+c.chain+"_"+c.resi):this.getRadius(s,c),u.push(e),m.push(c.color),1===C&&(m[m.length-2]=c.color),o=c.chain,a=c.resi;let l=1.2;2!==i||c.ssbegin||r.boxCls.createBox(c,void 0,void 0,l,void 0,i),++C,h=c}if(2!==i){if(g=[],void 0!==d&&!isNaN(d.resi)){let e=d.structure+"_"+d.chain+"_"+(parseInt(d.resi)-1).toString(),s=r.firstAtomObjCls.getAtomCoordFromResi(e,t);g=void 0!==s?[s]:[]}if(f=[],void 0!==c&&!isNaN(c.resi)){let e=c.structure+"_"+c.chain+"_"+(parseInt(c.resi)+1).toString(),i=c.structure+"_"+c.chain+"_"+(parseInt(c.resi)+2).toString(),n=c.structure+"_"+c.chain+"_"+(parseInt(c.resi)+3).toString();if(1==p.length&&r.residues.hasOwnProperty(e)){let l=r.firstAtomObjCls.getAtomFromResi(e,t);if(l){p.push(l.coord),m.push(l.color);let t=this.getRadius(s,c);u.push(t),e=i,i=n}}let l=r.firstAtomObjCls.getAtomCoordFromResi(e,t);void 0!==l&&f.push(l);let o=r.firstAtomObjCls.getAtomCoordFromResi(i,t);void 0!==o&&f.push(o)}b.push({pnts:p,colors:m,radii:u,prevone:g,nexttwo:f})}for(let e=0,t=b.length;e<t;++e){let t=b[e].pnts,s=b[e].colors,n=b[e].radii,r=b[e].prevone,o=b[e].nexttwo;this.createTubeSub(t,s,n,i,r,o,l)}b=[]}getCustomtubesize(e){let t=this.icn3d;t.icn3dui;let s=e.lastIndexOf("_"),i=e.substr(s+1),n=e.substr(0,s);return t.queryresi2score[n]&&t.queryresi2score[n].hasOwnProperty(i)?.01*t.queryresi2score[n][i]:t.coilWidth}createTubeSub(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui;if(a.bNode)return;if(e.length<2)return;let d,c=o.tubeDIV,h=o.axisDIV,p=1/c,m=1/h,u=new THREE.BufferGeometry,g=[],f=[],C=[],b=0,y=0,v=0,_=a.subdivideCls.subdivide(e,t,h,void 0,void 0,n,l),w=_[0];t=_[2];let S,A=new THREE.Vector3;for(let e=0,i=w.length;e<i;++e){let n,l,r,o,h=(e-1)*m;if(0===e)n=s[0];else if(h%1==0)n=s[h];else{let e=Math.floor(h),t=h-e;n=s[e]*t+s[e+1]*(1-t)}e<i-1?(l=w[e].clone().sub(w[e+1]),r=new THREE.Vector3(0,-l.z,l.y).normalize().multiplyScalar(n),o=l.clone().cross(r).normalize().multiplyScalar(n),A.dot(r)<0&&(r.negate(),o.negate()),A=r,S=o):(r=A,o=S);for(let s=0;s<c;++s){let i=2*Math.PI*p*s,n=w[e].clone().add(r.clone().multiplyScalar(Math.cos(i))).add(o.clone().multiplyScalar(Math.sin(i)));g[b++]=n.x,g[b++]=n.y,g[b++]=n.z,d=e==t.length-1&&t.length>1?a.parasCls.thr(t[t.length-2]):a.parasCls.thr(t[e]),f[y++]=d.r,f[y++]=d.g,f[y++]=d.b}}let x,k=0;for(let e=0,t=w.length-1;e<t;++e){let e=0,t=3*k,s=new THREE.Vector3(g[t],g[t+1],g[t+2]);t=3*(k+c);let i=new THREE.Vector3(g[t],g[t+1],g[t+2]);t=3*(k+c+1);let n=new THREE.Vector3(g[t],g[t+1],g[t+2]),l=s.clone().sub(i).lengthSq(),r=s.clone().sub(n).lengthSq();l>r&&(l=r,e=1);for(let t=0;t<c;++t)C[v++]=k+t,C[v++]=k+(t+e)%c+c,C[v++]=k+(t+1)%c,C[v++]=k+(t+1)%c,C[v++]=k+(t+e)%c+c,C[v++]=k+(t+e+1)%c+c;k+=c}u.setAttribute("position",new THREE.BufferAttribute(new Float32Array(g),3)),u.setAttribute("color",new THREE.BufferAttribute(new Float32Array(f),3)),u.setIndex(new THREE.BufferAttribute(new Uint32Array(C),1)),u.computeVertexNormals(),2===i?(x=new THREE.Mesh(u,new THREE.MeshPhongMaterial({transparent:!0,opacity:.5,specular:o.frac,shininess:o.shininess,emissive:o.emissive,vertexColors:!0,side:THREE.DoubleSide})),o.mdl&&o.mdl.add(x)):1===i?(x=new THREE.Mesh(u,o.matShader),x.renderOrder=o.renderOrderPicking,o.mdl&&o.mdl.add(x)):(x=new THREE.Mesh(u,new THREE.MeshPhongMaterial({specular:o.frac,shininess:o.shininess,emissive:o.emissive,vertexColors:!0,side:THREE.DoubleSide})),o.mdl&&o.mdl.add(x)),1===i||2===i?o.prevHighlightObjects.push(x):o.objects.push(x)}getRadius(e,t){let s=this.icn3d;s.icn3dui;let i=e;return i=e||(t.b>0&&t.b<=100?.01*t.b:t.b>100?1:s.coilWidth),i}}class ze{constructor(e){this.icn3d=e}drawCartoonNucleicAcid(e,t,s,i){this.drawStrandNucleicAcid(e,2,t,!0,void 0,s,i)}drawStrandNucleicAcid(e,t,s,i,n,l,r){let o,a,d,c=this.icn3d;if(c.icn3dui.bNode)return;2===r&&(t=void 0,l=void 0),n=n||c.nucleicAcidWidth,s=s||c.axisDIV,t=t||c.nucleicAcidStrandDIV;let h=[];for(d=0;d<t;d++)h[d]=[];let p,m,u,g=[],f=null;for(o in e){let C=e[o];if(void 0===C)continue;let b=C.structure+"_"+C.chain,y=C.structure+"_"+p;if(("O3'"===C.name||"OP2"===C.name||"O3*"===C.name||"O2P"===C.name)&&!C.het)if("O3'"===C.name||"O3*"===C.name){if(p!==C.chain||c.ParserUtilsCls.getResiNCBI(y,m)+1!==c.ParserUtilsCls.getResiNCBI(b,C.resi)){if(u&&f)for(a=0;a<t;a++){let e=2/(t-1)*a-1;h[a].push(new THREE.Vector3(u.x+f.x*e,u.y+f.y*e,u.z+f.z*e))}for(i&&c.stripCls.createStrip(h[0],h[1],g,s,l,r),a=0;!l&&a<t;a++)c.curveCls.createCurveSub(h[a],1,g,s,r);for(h=[],d=0;d<t;d++)h[d]=[];g=[],f=null}u=new THREE.Vector3(C.coord.x,C.coord.y,C.coord.z),p=C.chain,m=C.resi,1===r||2===r?g.push(c.hColor):g.push(C.color)}else if("OP2"===C.name||"O2P"===C.name){if(!u){f=null;continue}let e=new THREE.Vector3(C.coord.x,C.coord.y,C.coord.z);for(e.sub(u),e.normalize().multiplyScalar(n),null!==f&&e.dot(f)<0&&e.negate(),f=e,a=0;a<t;a++){let e=2/(t-1)*a-1;h[a].push(new THREE.Vector3(u.x+f.x*e,u.y+f.y*e,u.z+f.z*e))}u=null}}if(u&&f)for(a=0;a<t;a++){let e=2/(t-1)*a-1;h[a].push(new THREE.Vector3(u.x+f.x*e,u.y+f.y*e,u.z+f.z*e))}for(i&&c.stripCls.createStrip(h[0],h[1],g,s,l,r),a=0;!l&&a<t;a++)c.curveCls.createCurveSub(h[a],1,g,s,r)}drawNucleicAcidStick(e,t){let s=this.icn3d;if(s.icn3dui.bNode)return;let i,n,l,r=null,o=null;for(l in e){let a=e[l];void 0===a||a.het||(a.resi===n&&a.chain===i||(null!==r&&null!==o&&s.cylinderCls.createCylinder(new THREE.Vector3(r.coord.x,r.coord.y,r.coord.z),new THREE.Vector3(o.coord.x,o.coord.y,o.coord.z),s.cylinderRadius,r.color,t),r=null,o=null),"O3'"!==a.name&&"O3*"!==a.name||(r=a),"A"===a.resn.trim()||"G"===a.resn.trim()||"DA"===a.resn.trim()||"DG"===a.resn.trim()?"N9"===a.name&&(o=a):"N1"===a.name&&(o=a),n=a.resi,i=a.chain)}null!==r&&null!==o&&s.cylinderCls.createCylinder(new THREE.Vector3(r.coord.x,r.coord.y,r.coord.z),new THREE.Vector3(o.coord.x,o.coord.y,o.coord.z),s.cylinderRadius,r.color,t)}}class Ge{constructor(e){this.icn3d=e}makeTextSprite(e,t){let s=this.icn3d,i=s.icn3dui;if(i.bNode)return;void 0===t&&(t={});let n,l,r,o=t.hasOwnProperty("fontface")?t.fontface:"Arial",a=t.hasOwnProperty("fontsize")?t.fontsize:18,d=t.hasOwnProperty("factor")?t.factor:1,c=t.hasOwnProperty("alpha")?t.alpha:1,h=!1,p=!1;t.hasOwnProperty("bSchematic")&&t.bSchematic&&(p=!0,h=!0,a=40),t.hasOwnProperty("backgroundColor")&&void 0!==t.backgroundColor?(n=i.utilsCls.hexToRgb(t.backgroundColor,c),l=t.hasOwnProperty("borderColor")?i.utilsCls.hexToRgb(t.borderColor,c):{r:0,g:0,b:0,a:1},r=t.hasOwnProperty("borderThickness")?t.borderThickness:4):(h=!1,n=void 0,l=void 0,r=0);let m="black"!=s.opts.background?{r:0,g:0,b:0,a:1}:{r:255,g:255,b:0,a:1},u=t.hasOwnProperty("textColor")&&void 0!==t.textColor?i.utilsCls.hexToRgb(t.textColor,1):m;u||(u=m);let g=document.createElement("canvas"),f=g.getContext("2d");f.font="Bold "+a+"px "+o;let C=f.measureText(e).width,b=C+2*r,y=a+2*r;p&&(b>y?y=b:b=y);let v=.8*C/y;if(g.width=b,g.height=y,f.clearRect(0,0,b,y),h)if(f.fillStyle="rgba("+n.r+","+n.g+","+n.b+","+n.a+")",f.strokeStyle="rgba("+l.r+","+l.g+","+l.b+","+l.a+")",f.lineWidth=r,p){let e=.4*b;this.circle(f,0,0,b,y,e)}else{let e=0;this.roundRect(f,0,0,b,y,e)}f.font="Bold "+a+"px "+o,f.textAlign="center",f.textBaseline="middle",f.fillStyle="rgba("+u.r+", "+u.g+", "+u.b+", 1.0)",f.strokeStyle="rgba("+u.r+", "+u.g+", "+u.b+", 1.0)",f.fillText(e,.5*b,.5*y);let _=new THREE.Texture(g);_.needsUpdate=!0;let w=new THREE.SpriteMaterial({map:_,depthTest:!1,depthWrite:!1});w.map.minFilter=THREE.LinearFilter;let S=new THREE.Sprite(w);return p?S.scale.set(.3*d,.3*d,1):S.scale.set(v*d,d,1),S.renderOrder=1,S}roundRect(e,t,s,i,n,l){e.beginPath(),e.moveTo(t+l,s),e.lineTo(t+i-l,s),e.quadraticCurveTo(t+i,s,t+i,s+l),e.lineTo(t+i,s+n-l),e.quadraticCurveTo(t+i,s+n,t+i-l,s+n),e.lineTo(t+l,s+n),e.quadraticCurveTo(t,s+n,t,s+n-l),e.lineTo(t,s+l),e.quadraticCurveTo(t,s,t+l,s),e.closePath(),e.fill(),e.stroke()}circle(e,t,s,i,n,l){e.beginPath(),e.arc(t+i/2,.9*(s+n/2),l,0,2*Math.PI,!0),e.closePath(),e.fill(),e.stroke()}}class Ve{constructor(e){this.icn3d=e,this.textSpriteCls=new Ge(e)}createLabelRepresentation(e){let t=this.icn3d;t.icn3dui;let s=t.oriMaxD/100;s<.4&&(s=.4);let i=3*s*t.labelScale;for(let s in e){let n=void 0!==e[s]?e[s]:[],l="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd;for(let e=0,r=n.length;e<r;++e){let r=n[e];0==r.size&&(r.size=void 0),0==r.color&&(r.color=void 0),0==r.background&&(r.background=void 0);let o=void 0!==r.size?r.size:t.LABELSIZE,a=void 0!==r.color?r.color:l;t.labelcolor&&(a=t.labelcolor);let d,c=void 0!==r.background?r.background:"#cccccc",h=void 0!==r.alpha?r.alpha:1;if(c=r.background,void 0!==a&&void 0!==c&&a.toLowerCase()===c.toString().toLowerCase()&&(a="#888888"),void 0!==r.bSchematic&&r.bSchematic)d=this.textSpriteCls.makeTextSprite(r.text,{fontsize:parseInt(o),textColor:a,borderColor:c,backgroundColor:c,alpha:h,bSchematic:1,factor:i});else if(1===r.text.length)d=this.textSpriteCls.makeTextSprite(r.text,{fontsize:parseInt(o),textColor:a,borderColor:c,backgroundColor:c,alpha:h,bSchematic:1,factor:i});else{let e=r.factor?i*r.factor:i;d=this.textSpriteCls.makeTextSprite(r.text,{fontsize:parseInt(o),textColor:a,borderColor:c,backgroundColor:c,alpha:h,bSchematic:0,factor:e})}let p="schematic"==s||"residue"==s?0:t.coilWidth;d.position.set(parseFloat(r.position.x)+p,parseFloat(r.position.y)+p,parseFloat(r.position.z)+p),t.mdl.add(d)}}}hideLabels(){let e=this.icn3d;if(e.icn3dui,void 0!==e.mdl)for(let t=0,s=e.mdl.children.length;t<s;++t){let s=e.mdl.children[t];void 0!==s&&"Sprite"===s.type&&e.mdl.remove(s)}}}class We{constructor(e){this.icn3d=e}buildAxes(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui;if(o.bNode)return;new THREE.Object3D;let a=0,d=0,c=0;l?(a=t.x,d=t.y,c=t.z):(a-=.3*e,d-=.3*e);let h,p,m,u,g,f,C,b,y,v=new THREE.Vector3(a,d,c),_=e/10,w=e/100;u=g=f=_,l&&(h=s.clone().sub(t),p=i.clone().sub(t),m=n.clone().sub(t),u=h.length(),g=p.length(),f=m.length(),w=u/100,w<.4&&(w=.4)),l?(C=r.cylinderCls.createCylinder_base(t,s,w,o.parasCls.thr(16711680)),b=r.cylinderCls.createCylinder_base(t,i,w,o.parasCls.thr(65280)),y=r.cylinderCls.createCylinder_base(t,n,w,o.parasCls.thr(255))):(C=r.cylinderCls.createCylinder_base(new THREE.Vector3(a,d,c),new THREE.Vector3(a+u,d,c),w,o.parasCls.thr(16711680)),b=r.cylinderCls.createCylinder_base(new THREE.Vector3(a,d,c),new THREE.Vector3(a,d+g,c),w,o.parasCls.thr(65280)),y=r.cylinderCls.createCylinder_base(new THREE.Vector3(a,d,c),new THREE.Vector3(a,d,c+f),w,o.parasCls.thr(255))),r.mdl.add(C),r.mdl.add(b),r.mdl.add(y);let S=l?h.normalize():new THREE.Vector3(1,0,0),A=l?s:new THREE.Vector3(v.x+_,v.y,v.z),x=this.createArrow(S,A,u,16711680,4*w,4*w);r.mdl.add(x);let k=l?p.normalize():new THREE.Vector3(0,1,0),O=l?i:new THREE.Vector3(v.x,v.y+_,v.z),R=this.createArrow(k,O,g,65280,4*w,4*w);r.mdl.add(R);let I=l?m.normalize():new THREE.Vector3(0,0,1),E=l?n:new THREE.Vector3(v.x,v.y,v.z+_),T=this.createArrow(I,E,f,255,4*w,4*w);r.mdl.add(T)}buildAllAxes(e,t){let s=this.icn3d;if(!s.icn3dui.bNode&&s.pc1)for(let i=0,n=s.axes.length;i<n;++i){let n=s.axes[i][0],l=s.axes[i][1],r=s.axes[i][2],o=s.axes[i][3];this.buildAxes(e,n,l,r,o,t)}}createArrow(e,t,s,i,n,l,r){let o=this.icn3d;if(o.icn3dui.bNode)return;let a,d=new THREE.CylinderGeometry(0,.5,1,32,1);d.translate(0,.5,0),a=r?new THREE.MeshPhongMaterial({transparent:!0,opacity:.5,specular:o.frac,shininess:o.shininess,emissive:o.emissive,color:i}):new THREE.MeshPhongMaterial({specular:o.frac,shininess:o.shininess,emissive:o.emissive,side:THREE.DoubleSide,color:i});let c=new THREE.Mesh(d,a),h=new THREE.Quaternion;if(e.y>.99999)h.set(0,0,0,1);else if(e.y<-.99999)h.set(1,0,0,0);else{let t=new THREE.Vector3;t.set(e.z,0,-e.x).normalize();let s=Math.acos(e.y);h.setFromAxisAngle(t,s)}return c.applyQuaternion(h),c.scale.set(l,n,l),c.position.copy(t),c}setPc1Axes(){let e=this.icn3d,t=e.icn3dui;if(t.bNode)return;let s=t.hashUtilsCls.intHash(e.hAtoms,e.dAtoms),i=[],n=Object.keys(s).length<100;for(let t in s){let s=e.atoms[t],l=s.structure+"_"+s.chain+"_"+s.resi;(n||""!=l)&&i.push(s.coord.clone())}let l=t.rmsdSuprCls.getEigenForSelection(i,i.length),r=new THREE.Vector3(l.h1[0],l.h1[1],l.h1[2]);if(0==l.k&&e.bRender)return void alert("Can't determine the first principal component. Please select a subset and try it again.");let o=e.applyCenterCls.centerAtoms(s),a=o.maxD,d=o.center,c=d.clone().add(r.normalize().multiplyScalar(.4*a)),h=new THREE.Vector3(l.h2[0],l.h2[1],l.h2[2]),p=d.clone().add(h.normalize().multiplyScalar(.3*a)),m=new THREE.Vector3(l.h3[0],l.h3[1],l.h3[2]),u=d.clone().add(m.normalize().multiplyScalar(.3*a));this.buildAxes(void 0,d,c,p,u,!0);let g=[d,c,p,u];return e.axes.push(g),e.drawCls.draw(),g}}class Ye{constructor(e){this.icn3d=e}showGlycans(){let e=this.icn3d,t=e.icn3dui;if(t.bNode)return;let s={},i=e.dAtoms;for(let n in i){let i=e.atoms[n];i.het&&-1!=t.parasCls.glycanHash.hasOwnProperty(i.resn)&&(void 0===s[i.resn]&&(s[i.resn]={}),"Misc"!=i.chain&&(s[i.resn][i.structure+"_"+i.chain+"_"+i.resi]=1))}let n=Object.keys(s);for(let i=0,l=n.length;i<l;++i){let l=n[i];if(!t.parasCls.glycanHash.hasOwnProperty(l))continue;let r=t.parasCls.glycanHash[l].s,o=new THREE.Color("#"+t.parasCls.glycanHash[l].c),a=Object.keys(s[l]);for(let t=0,s=a.length;t<s;++t){let s=e.applyCenterCls.centerAtoms(e.residues[a[t]]),i=s.center,n=.5*s.maxD*.6;if("cube"==r)e.boxCls.createBox_base(i,n,o,!1,!1,!0);else if("sphere"==r)e.sphereCls.createSphereBase(i,o,n,1,!1,!0);else if("cone"==r){let t=new THREE.Vector3(0,0,1),s=e.axesCls.createArrow(t,new THREE.Vector3(0,0,-1*n).add(i),0,o,2*n,2*n,!0);e.mdl.add(s),e.objects.push(s)}else if("cylinder"==r){let t=new THREE.Vector3(0,0,n).add(i),s=new THREE.Vector3(0,0,-1*n).add(i);e.cylinderCls.createCylinder(t,s,n,o,!1,o,!1,!0)}}}}}class Xe{constructor(e){this.icn3d=e,this.ISDONE=2;this.edgeTable=new Uint32Array([0,0,0,0,0,0,0,2816,0,0,0,1792,0,3328,3584,3840,0,0,0,138,0,21,0,134,0,0,0,652,0,2067,3865,3600,0,0,0,42,0,0,0,294,0,0,21,28,0,3875,1049,3360,0,168,162,170,0,645,2475,2210,0,687,293,172,4010,3747,3497,3232,0,0,0,0,0,69,0,900,0,0,0,1792,138,131,1608,1920,0,81,0,2074,84,85,84,86,0,81,0,3676,330,1105,1881,1616,0,0,0,42,0,69,0,502,0,0,21,3580,138,2035,1273,1520,2816,104,2337,106,840,581,367,102,2816,3695,3429,3180,1898,1635,1385,1120,0,0,0,0,0,0,0,3910,0,0,69,588,42,2083,41,2880,0,0,0,1722,0,2293,4095,3830,0,255,757,764,2538,2291,3065,2800,0,0,81,338,0,3925,1119,3414,84,855,85,340,2130,2899,89,2384,1792,712,194,1162,4036,3781,3535,3270,708,719,197,204,3018,2755,2505,2240,0,0,0,0,168,420,168,1958,162,162,676,2988,170,163,680,928,3328,3096,3328,3642,52,53,1855,1590,2340,2111,2869,2620,298,51,825,560,3584,3584,3090,3482,1668,1941,1183,1430,146,2975,2069,2460,154,915,153,400,3840,3592,3329,3082,1796,1541,1295,1030,2818,2575,2309,2060,778,515,265,0]),this.triTable=[[],[],[],[],[],[],[],[11,9,8],[],[],[],[8,10,9],[],[10,8,11],[9,11,10],[8,10,9,8,11,10],[],[],[],[1,7,3],[],[4,2,0],[],[2,1,7],[],[],[],[2,7,3,2,9,7],[],[1,4,11,1,0,4],[3,8,0,11,9,4,11,10,9],[4,11,9,11,10,9],[],[],[],[5,3,1],[],[],[],[2,5,8,2,1,5],[],[],[2,4,0],[3,2,4],[],[0,9,1,8,10,5,8,11,10],[3,4,0,3,10,4],[5,8,10,8,11,10],[],[3,5,7],[7,1,5],[1,7,3,1,5,7],[],[9,2,0,9,7,2],[0,3,8,1,7,11,1,5,7],[11,1,7,1,5,7],[],[9,1,0,5,3,2,5,7,3],[8,2,5,8,0,2],[2,5,3,5,7,3],[3,9,1,3,8,9,7,11,10,7,10,5],[9,1,0,10,7,11,10,5,7],[3,8,0,7,10,5,7,11,10],[11,5,7,11,10,5],[],[],[],[],[],[0,6,2],[],[7,2,9,7,9,8],[],[],[],[8,10,9],[7,1,3],[7,1,0],[6,9,3,6,10,9],[7,10,8,10,9,8],[],[6,0,4],[],[11,1,4,11,3,1],[2,4,6],[2,0,4,2,4,6],[2,4,6],[1,4,2,4,6,2],[],[6,0,4],[],[2,11,3,6,9,4,6,10,9],[8,6,1,8,1,3],[10,0,6,0,4,6],[8,0,3,9,6,10,9,4,6],[10,4,6,10,9,4],[],[],[],[5,3,1],[],[0,6,2],[],[7,4,8,5,2,1,5,6,2],[],[],[2,4,0],[7,4,8,2,11,3,10,5,6],[7,1,3],[5,6,10,0,9,1,8,7,4],[5,6,10,7,0,3,7,4,0],[10,5,6,4,8,7],[9,11,8],[3,5,6],[0,5,11,0,11,8],[6,3,5,3,1,5],[3,9,6,3,8,9],[9,6,0,6,2,0],[0,3,8,2,5,6,2,1,5],[1,6,2,1,5,6],[9,11,8],[1,0,9,6,10,5,11,3,2],[6,10,5,2,8,0,2,11,8],[3,2,11,10,5,6],[10,5,6,9,3,8,9,1,3],[0,9,1,5,6,10],[8,0,3,10,5,6],[10,5,6],[],[],[],[],[],[],[],[1,10,2,9,11,6,9,8,11],[],[],[6,0,2],[3,6,9,3,2,6],[3,5,1],[0,5,1,0,11,5],[0,3,5],[6,9,11,9,8,11],[],[],[],[4,5,9,7,1,10,7,3,1],[],[11,6,7,2,4,5,2,0,4],[11,6,7,8,0,3,1,10,2,9,4,5],[6,7,11,1,10,2,9,4,5],[],[4,1,0,4,5,1,6,7,3,6,3,2],[9,4,5,0,6,7,0,2,6],[4,5,9,6,3,2,6,7,3],[6,7,11,5,3,8,5,1,3],[6,7,11,4,1,0,4,5,1],[4,5,9,3,8,0,11,6,7],[9,4,5,7,11,6],[],[],[0,6,4],[8,6,4,8,1,6],[],[0,10,2,0,9,10,4,8,11,4,11,6],[10,2,1,6,0,3,6,4,0],[10,2,1,11,4,8,11,6,4],[4,2,6],[1,0,9,2,4,8,2,6,4],[2,4,0,2,6,4],[8,2,4,2,6,4],[11,4,1,11,6,4],[0,9,1,4,11,6,4,8,11],[3,6,0,6,4,0],[8,6,4,8,11,6],[10,8,9],[6,3,9,6,7,3],[6,7,1],[10,7,1,7,3,1],[7,11,6,8,10,2,8,9,10],[11,6,7,10,0,9,10,2,0],[2,1,10,7,11,6,8,0,3],[1,10,2,6,7,11],[7,2,6,7,9,2],[1,0,9,3,6,7,3,2,6],[7,0,6,0,2,6],[2,7,3,2,6,7],[7,11,6,3,9,1,3,8,9],[9,1,0,11,6,7],[0,3,8,11,6,7],[11,6,7],[],[],[],[],[5,3,7],[8,5,2,8,7,5],[5,3,7],[1,10,2,5,8,7,5,9,8],[1,7,5],[1,7,5],[9,2,7,9,7,5],[11,3,2,8,5,9,8,7,5],[1,3,7,1,7,5],[0,7,1,7,5,1],[9,3,5,3,7,5],[9,7,5,9,8,7],[8,10,11],[3,4,10,3,10,11],[8,10,11],[5,9,4,1,11,3,1,10,11],[2,4,5],[5,2,4,2,0,4],[0,3,8,5,9,4,10,2,1],[2,1,10,9,4,5],[2,8,5,2,11,8],[3,2,11,1,4,5,1,0,4],[9,4,5,8,2,11,8,0,2],[11,3,2,9,4,5],[8,5,3,5,1,3],[5,0,4,5,1,0],[3,8,0,4,5,9],[9,4,5],[11,9,10],[11,9,10],[1,11,4,1,10,11],[8,7,4,11,1,10,11,3,1],[2,7,9,2,9,10],[4,8,7,0,10,2,0,9,10],[2,1,10,0,7,4,0,3,7],[10,2,1,8,7,4],[1,7,4],[3,2,11,4,8,7,9,1,0],[11,4,2,4,0,2],[2,11,3,7,4,8],[4,1,7,1,3,7],[1,0,9,8,7,4],[3,4,0,3,7,4],[8,7,4],[8,9,10,8,10,11],[3,9,11,9,10,11],[0,10,8,10,11,8],[10,3,1,10,11,3],[2,8,10,8,9,10],[9,2,0,9,10,2],[8,0,3,1,10,2],[10,2,1],[1,11,9,11,8,9],[11,3,2,0,9,1],[11,0,2,11,8,0],[11,3,2],[8,1,3,8,9,1],[9,1,0],[8,0,3],[]],this.edgeTable2=[0,265,515,778,2060,2309,2575,2822,1030,1295,1541,1804,3082,3331,3593,3840,400,153,915,666,2460,2197,2975,2710,1430,1183,1941,1692,3482,3219,3993,3728,560,825,51,314,2620,2869,2111,2358,1590,1855,1077,1340,3642,3891,3129,3376,928,681,419,170,2988,2725,2479,2214,1958,1711,1445,1196,4010,3747,3497,3232,2240,2505,2755,3018,204,453,719,966,3270,3535,3781,4044,1226,1475,1737,1984,2384,2137,2899,2650,348,85,863,598,3414,3167,3925,3676,1370,1107,1881,1616,2800,3065,2291,2554,764,1013,255,502,3830,4095,3317,3580,1786,2035,1273,1520,2912,2665,2403,2154,876,613,367,102,3942,3695,3429,3180,1898,1635,1385,1120,1120,1385,1635,1898,3180,3429,3695,3942,102,367,613,876,2154,2403,2665,2912,1520,1273,2035,1786,3580,3317,4095,3830,502,255,1013,764,2554,2291,3065,2800,1616,1881,1107,1370,3676,3925,3167,3414,598,863,85,348,2650,2899,2137,2384,1984,1737,1475,1226,4044,3781,3535,3270,966,719,453,204,3018,2755,2505,2240,3232,3497,3747,4010,1196,1445,1711,1958,2214,2479,2725,2988,170,419,681,928,3376,3129,3891,3642,1340,1077,1855,1590,2358,2111,2869,2620,314,51,825,560,3728,3993,3219,3482,1692,1941,1183,1430,2710,2975,2197,2460,666,915,153,400,3840,3593,3331,3082,1804,1541,1295,1030,2822,2575,2309,2060,778,515,265,0],this.triTable2=[[],[8,3,0],[9,0,1],[8,3,1,8,1,9],[11,2,3],[11,2,0,11,0,8],[11,2,3,0,1,9],[2,1,11,1,9,11,11,9,8],[10,1,2],[8,3,0,1,2,10],[9,0,2,9,2,10],[3,2,8,2,10,8,8,10,9],[10,1,3,10,3,11],[1,0,10,0,8,10,10,8,11],[0,3,9,3,11,9,9,11,10],[8,10,9,8,11,10],[8,4,7],[3,0,4,3,4,7],[1,9,0,8,4,7],[9,4,1,4,7,1,1,7,3],[2,3,11,7,8,4],[7,11,4,11,2,4,4,2,0],[3,11,2,4,7,8,9,0,1],[2,7,11,2,1,7,1,4,7,1,9,4],[10,1,2,8,4,7],[2,10,1,0,4,7,0,7,3],[4,7,8,0,2,10,0,10,9],[2,7,3,2,9,7,7,9,4,2,10,9],[8,4,7,11,10,1,11,1,3],[11,4,7,1,4,11,1,11,10,1,0,4],[3,8,0,7,11,4,11,9,4,11,10,9],[7,11,4,4,11,9,11,10,9],[9,5,4],[3,0,8,4,9,5],[5,4,0,5,0,1],[4,8,5,8,3,5,5,3,1],[11,2,3,9,5,4],[9,5,4,8,11,2,8,2,0],[3,11,2,1,5,4,1,4,0],[8,5,4,2,5,8,2,8,11,2,1,5],[2,10,1,9,5,4],[0,8,3,5,4,9,10,1,2],[10,5,2,5,4,2,2,4,0],[3,4,8,3,2,4,2,5,4,2,10,5],[5,4,9,1,3,11,1,11,10],[0,9,1,4,8,5,8,10,5,8,11,10],[3,4,0,3,10,4,4,10,5,3,11,10],[4,8,5,5,8,10,8,11,10],[9,5,7,9,7,8],[0,9,3,9,5,3,3,5,7],[8,0,7,0,1,7,7,1,5],[1,7,3,1,5,7],[11,2,3,8,9,5,8,5,7],[9,2,0,9,7,2,2,7,11,9,5,7],[0,3,8,2,1,11,1,7,11,1,5,7],[2,1,11,11,1,7,1,5,7],[1,2,10,5,7,8,5,8,9],[9,1,0,10,5,2,5,3,2,5,7,3],[5,2,10,8,2,5,8,5,7,8,0,2],[10,5,2,2,5,3,5,7,3],[3,9,1,3,8,9,7,11,10,7,10,5],[9,1,0,10,7,11,10,5,7],[3,8,0,7,10,5,7,11,10],[11,5,7,11,10,5],[11,7,6],[0,8,3,11,7,6],[9,0,1,11,7,6],[7,6,11,3,1,9,3,9,8],[2,3,7,2,7,6],[8,7,0,7,6,0,0,6,2],[1,9,0,3,7,6,3,6,2],[7,6,2,7,2,9,2,1,9,7,9,8],[1,2,10,6,11,7],[2,10,1,7,6,11,8,3,0],[11,7,6,10,9,0,10,0,2],[7,6,11,3,2,8,8,2,10,8,10,9],[6,10,7,10,1,7,7,1,3],[6,10,1,6,1,7,7,1,0,7,0,8],[9,0,3,6,9,3,6,10,9,6,3,7],[6,10,7,7,10,8,10,9,8],[8,4,6,8,6,11],[11,3,6,3,0,6,6,0,4],[0,1,9,4,6,11,4,11,8],[1,9,4,11,1,4,11,3,1,11,4,6],[3,8,2,8,4,2,2,4,6],[2,0,4,2,4,6],[1,9,0,3,8,2,2,8,4,2,4,6],[9,4,1,1,4,2,4,6,2],[10,1,2,11,8,4,11,4,6],[10,1,2,11,3,6,6,3,0,6,0,4],[0,2,10,0,10,9,4,11,8,4,6,11],[2,11,3,6,9,4,6,10,9],[8,4,6,8,6,1,6,10,1,8,1,3],[1,0,10,10,0,6,0,4,6],[8,0,3,9,6,10,9,4,6],[10,4,6,10,9,4],[9,5,4,7,6,11],[4,9,5,3,0,8,11,7,6],[6,11,7,4,0,1,4,1,5],[6,11,7,4,8,5,5,8,3,5,3,1],[4,9,5,6,2,3,6,3,7],[9,5,4,8,7,0,0,7,6,0,6,2],[4,0,1,4,1,5,6,3,7,6,2,3],[7,4,8,5,2,1,5,6,2],[6,11,7,1,2,10,9,5,4],[11,7,6,8,3,0,1,2,10,9,5,4],[11,7,6,10,5,2,2,5,4,2,4,0],[7,4,8,2,11,3,10,5,6],[4,9,5,6,10,7,7,10,1,7,1,3],[5,6,10,0,9,1,8,7,4],[5,6,10,7,0,3,7,4,0],[10,5,6,4,8,7],[5,6,9,6,11,9,9,11,8],[0,9,5,0,5,3,3,5,6,3,6,11],[0,1,5,0,5,11,5,6,11,0,11,8],[11,3,6,6,3,5,3,1,5],[9,5,6,3,9,6,3,8,9,3,6,2],[5,6,9,9,6,0,6,2,0],[0,3,8,2,5,6,2,1,5],[1,6,2,1,5,6],[1,2,10,5,6,9,9,6,11,9,11,8],[1,0,9,6,10,5,11,3,2],[6,10,5,2,8,0,2,11,8],[3,2,11,10,5,6],[10,5,6,9,3,8,9,1,3],[0,9,1,5,6,10],[8,0,3,10,5,6],[10,5,6],[10,6,5],[8,3,0,10,6,5],[0,1,9,5,10,6],[10,6,5,9,8,3,9,3,1],[3,11,2,10,6,5],[6,5,10,2,0,8,2,8,11],[1,9,0,6,5,10,11,2,3],[1,10,2,5,9,6,9,11,6,9,8,11],[1,2,6,1,6,5],[0,8,3,2,6,5,2,5,1],[5,9,6,9,0,6,6,0,2],[9,6,5,3,6,9,3,9,8,3,2,6],[11,6,3,6,5,3,3,5,1],[0,5,1,0,11,5,5,11,6,0,8,11],[0,5,9,0,3,5,3,6,5,3,11,6],[5,9,6,6,9,11,9,8,11],[10,6,5,4,7,8],[5,10,6,7,3,0,7,0,4],[5,10,6,0,1,9,8,4,7],[4,5,9,6,7,10,7,1,10,7,3,1],[7,8,4,2,3,11,10,6,5],[11,6,7,10,2,5,2,4,5,2,0,4],[11,6,7,8,0,3,1,10,2,9,4,5],[6,7,11,1,10,2,9,4,5],[7,8,4,5,1,2,5,2,6],[4,1,0,4,5,1,6,7,3,6,3,2],[9,4,5,8,0,7,0,6,7,0,2,6],[4,5,9,6,3,2,6,7,3],[6,7,11,4,5,8,5,3,8,5,1,3],[6,7,11,4,1,0,4,5,1],[4,5,9,3,8,0,11,6,7],[9,4,5,7,11,6],[10,6,4,10,4,9],[8,3,0,9,10,6,9,6,4],[1,10,0,10,6,0,0,6,4],[8,6,4,8,1,6,6,1,10,8,3,1],[2,3,11,6,4,9,6,9,10],[0,10,2,0,9,10,4,8,11,4,11,6],[10,2,1,11,6,3,6,0,3,6,4,0],[10,2,1,11,4,8,11,6,4],[9,1,4,1,2,4,4,2,6],[1,0,9,3,2,8,2,4,8,2,6,4],[2,4,0,2,6,4],[3,2,8,8,2,4,2,6,4],[1,4,9,11,4,1,11,1,3,11,6,4],[0,9,1,4,11,6,4,8,11],[11,6,3,3,6,0,6,4,0],[8,6,4,8,11,6],[6,7,10,7,8,10,10,8,9],[9,3,0,6,3,9,6,9,10,6,7,3],[6,1,10,6,7,1,7,0,1,7,8,0],[6,7,10,10,7,1,7,3,1],[7,11,6,3,8,2,8,10,2,8,9,10],[11,6,7,10,0,9,10,2,0],[2,1,10,7,11,6,8,0,3],[1,10,2,6,7,11],[7,2,6,7,9,2,2,9,1,7,8,9],[1,0,9,3,6,7,3,2,6],[8,0,7,7,0,6,0,2,6],[2,7,3,2,6,7],[7,11,6,3,9,1,3,8,9],[9,1,0,11,6,7],[0,3,8,11,6,7],[11,6,7],[11,7,5,11,5,10],[3,0,8,7,5,10,7,10,11],[9,0,1,10,11,7,10,7,5],[3,1,9,3,9,8,7,10,11,7,5,10],[10,2,5,2,3,5,5,3,7],[5,10,2,8,5,2,8,7,5,8,2,0],[9,0,1,10,2,5,5,2,3,5,3,7],[1,10,2,5,8,7,5,9,8],[2,11,1,11,7,1,1,7,5],[0,8,3,2,11,1,1,11,7,1,7,5],[9,0,2,9,2,7,2,11,7,9,7,5],[11,3,2,8,5,9,8,7,5],[1,3,7,1,7,5],[8,7,0,0,7,1,7,5,1],[0,3,9,9,3,5,3,7,5],[9,7,5,9,8,7],[4,5,8,5,10,8,8,10,11],[3,0,4,3,4,10,4,5,10,3,10,11],[0,1,9,4,5,8,8,5,10,8,10,11],[5,9,4,1,11,3,1,10,11],[3,8,4,3,4,2,2,4,5,2,5,10],[10,2,5,5,2,4,2,0,4],[0,3,8,5,9,4,10,2,1],[2,1,10,9,4,5],[8,4,5,2,8,5,2,11,8,2,5,1],[3,2,11,1,4,5,1,0,4],[9,4,5,8,2,11,8,0,2],[11,3,2,9,4,5],[4,5,8,8,5,3,5,1,3],[5,0,4,5,1,0],[3,8,0,4,5,9],[9,4,5],[7,4,11,4,9,11,11,9,10],[3,0,8,7,4,11,11,4,9,11,9,10],[11,7,4,1,11,4,1,10,11,1,4,0],[8,7,4,11,1,10,11,3,1],[2,3,7,2,7,9,7,4,9,2,9,10],[4,8,7,0,10,2,0,9,10],[2,1,10,0,7,4,0,3,7],[10,2,1,8,7,4],[2,11,7,2,7,1,1,7,4,1,4,9],[3,2,11,4,8,7,9,1,0],[7,4,11,11,4,2,4,0,2],[2,11,3,7,4,8],[9,1,4,4,1,7,1,3,7],[1,0,9,8,7,4],[3,4,0,3,7,4],[8,7,4],[8,9,10,8,10,11],[0,9,3,3,9,11,9,10,11],[1,10,0,0,10,8,10,11,8],[10,3,1,10,11,3],[3,8,2,2,8,10,8,9,10],[9,2,0,9,10,2],[8,0,3,1,10,2],[10,2,1],[2,11,1,1,11,9,11,8,9],[11,3,2,0,9,1],[11,0,2,11,8,0],[11,3,2],[8,1,3,8,9,1],[9,1,0],[8,0,3],[]]}}Xe.prototype.march=function(e,t,s,i){let n=!!i.fulltable,l=i.hasOwnProperty("origin")&&i.origin.hasOwnProperty("x")?i.origin:{x:0,y:0,z:0},r=!!i.voxel,o=i.matrix,a=i.nX||0,d=i.nY||0,c=i.nZ||0,h=i.scale||1,p=null;p=i.unitCube?i.unitCube:{x:h,y:h,z:h};let m,u,g=new Int32Array(a*d*c);for(m=0,u=g.length;m<u;++m)g[m]=-1;let f=function(e,s,i,n,a,h){let m={x:0,y:0,z:0},u=a;!!!(n&1<<a)&&!!(n&1<<h)&&(u=h),1&u&&i++,2&u&&s++,4&u&&e++,o?(m=new THREE.Vector3(e,s,i),m=m.applyMatrix4(o),m={x:m.x,y:m.y,z:m.z}):(m.x=l.x+p.x*e,m.y=l.y+p.y*s,m.z=l.z+p.z*i);let f=(d*e+s)*c+i;return r?(t.push(m),t.length-1):(g[f]<0&&(g[f]=t.length,t.push(m)),g[f])},C=new Int32Array(12),b=n?this.edgeTable2:this.edgeTable,y=n?this.triTable2:this.triTable;for(m=0;m<a-1;++m)for(let i=0;i<d-1;++i)for(let n=0;n<c-1;++n){let l=0;for(let t=0;t<8;++t){l|=!!(e[(d*(m+((4&t)>>2))+i+((2&t)>>1))*c+n+(1&t)]&this.ISDONE)<<t}if(0===l||255===l)continue;let o=b[l];if(0===o)continue;let a=y[l];1&o&&(C[0]=f(m,i,n,l,0,1)),2&o&&(C[1]=f(m,i,n,l,1,3)),4&o&&(C[2]=f(m,i,n,l,3,2)),8&o&&(C[3]=f(m,i,n,l,2,0)),16&o&&(C[4]=f(m,i,n,l,4,5)),32&o&&(C[5]=f(m,i,n,l,5,7)),64&o&&(C[6]=f(m,i,n,l,7,6)),128&o&&(C[7]=f(m,i,n,l,6,4)),256&o&&(C[8]=f(m,i,n,l,0,4)),512&o&&(C[9]=f(m,i,n,l,1,5)),1024&o&&(C[10]=f(m,i,n,l,3,7)),2048&o&&(C[11]=f(m,i,n,l,2,6));for(let e=0;e<a.length;e+=3){let i=C[a[e]],n=C[a[e+1]],l=C[a[e+2]];r&&e>=3&&(t.push(t[i]),i=t.length-1,t.push(t[n]),n=t.length-1,t.push(t[l]),l=t.length-1),s.push(i),s.push(n),s.push(l)}}},Xe.prototype.laplacianSmooth=function(e,t,s){let i,n,l,r,o,a=new Array(t.length);for(i=0,n=t.length;i<n;i++)a[i]={x:0,y:0,z:0};let d,c=new Array(20);for(i=0;i<20;i++)c[i]=new Array(t.length);for(i=0,n=t.length;i<n;i++)c[0][i]=0;for(i=0,n=s.length/3;i<n;i++){let e=3*i,t=3*i+1,n=3*i+2;for(d=!0,l=0,r=c[0][s[e]];l<r;l++)if(s[t]==c[l+1][s[e]]){d=!1;break}for(d&&(c[0][s[e]]++,c[c[0][s[e]]][s[e]]=s[t]),d=!0,l=0,r=c[0][s[e]];l<r;l++)if(s[n]==c[l+1][s[e]]){d=!1;break}for(d&&(c[0][s[e]]++,c[c[0][s[e]]][s[e]]=s[n]),d=!0,l=0,r=c[0][s[t]];l<r;l++)if(s[e]==c[l+1][s[t]]){d=!1;break}for(d&&(c[0][s[t]]++,c[c[0][s[t]]][s[t]]=s[e]),d=!0,l=0,r=c[0][s[t]];l<r;l++)if(s[n]==c[l+1][s[t]]){d=!1;break}for(d&&(c[0][s[t]]++,c[c[0][s[t]]][s[t]]=s[n]),d=!0,l=0;l<c[0][s[n]];l++)if(s[e]==c[l+1][s[n]]){d=!1;break}for(d&&(c[0][s[n]]++,c[c[0][s[n]]][s[n]]=s[e]),d=!0,l=0,r=c[0][s[n]];l<r;l++)if(s[t]==c[l+1][s[n]]){d=!1;break}d&&(c[0][s[n]]++,c[c[0][s[n]]][s[n]]=s[t])}let h=.5;for(o=0;o<e;o++){for(i=0,n=t.length;i<n;i++)if(c[0][i]<3)a[i].x=t[i].x,a[i].y=t[i].y,a[i].z=t[i].z;else if(3==c[0][i]||4==c[0][i]){for(a[i].x=0,a[i].y=0,a[i].z=0,l=0,r=c[0][i];l<r;l++)a[i].x+=t[c[l+1][i]].x,a[i].y+=t[c[l+1][i]].y,a[i].z+=t[c[l+1][i]].z;a[i].x+=h*t[i].x,a[i].y+=h*t[i].y,a[i].z+=h*t[i].z,a[i].x/=h+c[0][i],a[i].y/=h+c[0][i],a[i].z/=h+c[0][i]}else{for(a[i].x=0,a[i].y=0,a[i].z=0,l=0,r=c[0][i];l<r;l++)a[i].x+=t[c[l+1][i]].x,a[i].y+=t[c[l+1][i]].y,a[i].z+=t[c[l+1][i]].z;a[i].x+=1*t[i].x,a[i].y+=1*t[i].y,a[i].z+=1*t[i].z,a[i].x/=1+c[0][i],a[i].y/=1+c[0][i],a[i].z/=1+c[0][i]}for(i=0,n=t.length;i<n;i++)t[i].x=a[i].x,t[i].y=a[i].y,t[i].z=a[i].z}};class Ke{constructor(e,t){this.icn3d=e,this.threshbox=t,this.dataArray={},this.header,this.data=void 0,this.matrix=void 0,this.isovalue=void 0,this.loadPhiFrom=void 0,this.vpColor=null,this.vpPot=null,this.INOUT=1,this.ISDONE=2,this.ISBOUND=4,this.ptranx=0,this.ptrany=0,this.ptranz=0,this.probeRadius=1.4,this.defaultScaleFactor=2,this.scaleFactor=this.defaultScaleFactor,this.finalScaleFactor={},this.pHeight=0,this.pWidth=0,this.pLength=0,this.cutRadius=0,this.vpBits=null,this.vpDistance=null,this.vpAtomID=null,this.vertnumber=0,this.facenumber=0,this.pminx=0,this.pminy=0,this.pminz=0,this.pmaxx=0,this.pmaxy=0,this.pmaxz=0,this.bCalcArea=!1,this.atomsToShow={},this.vdwRadii={H:1.2,LI:1.82,Na:2.27,K:2.75,C:1.7,N:1.55,O:1.52,F:1.47,P:1.8,S:1.8,CL:1.75,BR:1.85,SE:1.9,ZN:1.39,CU:1.4,NI:1.63,X:2},this.depty={},this.widxz={},this.faces=void 0,this.verts=void 0,this.nb=[new Int32Array([1,0,0]),new Int32Array([-1,0,0]),new Int32Array([0,1,0]),new Int32Array([0,-1,0]),new Int32Array([0,0,1]),new Int32Array([0,0,-1]),new Int32Array([1,1,0]),new Int32Array([1,-1,0]),new Int32Array([-1,1,0]),new Int32Array([-1,-1,0]),new Int32Array([1,0,1]),new Int32Array([1,0,-1]),new Int32Array([-1,0,1]),new Int32Array([-1,0,-1]),new Int32Array([0,1,1]),new Int32Array([0,1,-1]),new Int32Array([0,-1,1]),new Int32Array([0,-1,-1]),new Int32Array([1,1,1]),new Int32Array([1,1,-1]),new Int32Array([1,-1,1]),new Int32Array([-1,1,1]),new Int32Array([1,-1,-1]),new Int32Array([-1,-1,1]),new Int32Array([-1,1,-1]),new Int32Array([-1,-1,-1])],this.origextent=void 0,this.marchingCube=new Xe}}Ke.prototype.getVDWIndex=function(e){return e.elem&&void 0!==this.vdwRadii[e.elem.toUpperCase()]?e.elem:"X"},Ke.prototype.inOrigExtent=function(e,t,s){return!(e<this.origextent[0][0]||e>this.origextent[1][0])&&(!(t<this.origextent[0][1]||t>this.origextent[1][1])&&!(s<this.origextent[0][2]||s>this.origextent[1][2]))},Ke.prototype.getFacesAndVertices=function(){let e,t,s=this.verts;for(e=0,t=s.length;e<t;e++)s[e].x=s[e].x/this.scaleFactor-this.ptranx,s[e].y=s[e].y/this.scaleFactor-this.ptrany,s[e].z=s[e].z/this.scaleFactor-this.ptranz;let i=[];for(e=0,t=this.faces.length;e<t;e+=3){let t=this.faces[e],n=this.faces[e+1],l=this.faces[e+2],r=s[t].atomid,o=s[n].atomid,a=s[l].atomid;this.atomsToShow[r]&&this.atomsToShow[o]&&this.atomsToShow[a]&&(t!==n&&n!==l&&t!==l&&i.push({a:t,b:n,c:l}))}return this.vpBits=null,this.vpDistance=null,this.vpAtomID=null,this.vpColor=null,this.vpPot=null,{vertices:s,faces:i}},Ke.prototype.initparm=function(e,t,s,i,n,l,r,o,a){this.header=n,this.dataArray=l,this.matrix=r,this.isovalue=o,this.loadPhiFrom=a,this.bCalcArea=s;for(let e=0,t=i.length;e<t;e++)this.atomsToShow[i[e]]=1;let d=1/this.scaleFactor*5.5;this.origextent=e,this.pminx=e[0][0],this.pmaxx=e[1][0],this.pminy=e[0][1],this.pmaxy=e[1][1],this.pminz=e[0][2],this.pmaxz=e[1][2],t?(this.pminx-=this.probeRadius+d,this.pminy-=this.probeRadius+d,this.pminz-=this.probeRadius+d,this.pmaxx+=this.probeRadius+d,this.pmaxy+=this.probeRadius+d,this.pmaxz+=this.probeRadius+d):(this.pminx-=d,this.pminy-=d,this.pminz-=d,this.pmaxx+=d,this.pmaxy+=d,this.pmaxz+=d),this.pminx=Math.floor(this.pminx*this.scaleFactor)/this.scaleFactor,this.pminy=Math.floor(this.pminy*this.scaleFactor)/this.scaleFactor,this.pminz=Math.floor(this.pminz*this.scaleFactor)/this.scaleFactor,this.pmaxx=Math.ceil(this.pmaxx*this.scaleFactor)/this.scaleFactor,this.pmaxy=Math.ceil(this.pmaxy*this.scaleFactor)/this.scaleFactor,this.pmaxz=Math.ceil(this.pmaxz*this.scaleFactor)/this.scaleFactor,this.ptranx=-this.pminx,this.ptrany=-this.pminy,this.ptranz=-this.pminz;let c=129,h=this.pmaxx-this.pminx;this.pmaxy-this.pminy>h&&(h=this.pmaxy-this.pminy),this.pmaxz-this.pminz>h&&(h=this.pmaxz-this.pminz),this.scaleFactor=(c-1)/h,this.scaleFactor=this.defaultScaleFactor,this.defaultScaleFactor*h>this.threshbox&&(c=Math.floor(this.threshbox),this.scaleFactor=(this.threshbox-1)/h),this.bCalcArea&&(this.scaleFactor=this.defaultScaleFactor),this.pLength=Math.ceil(this.scaleFactor*(this.pmaxx-this.pminx))+1,this.pWidth=Math.ceil(this.scaleFactor*(this.pmaxy-this.pminy))+1,this.pHeight=Math.ceil(this.scaleFactor*(this.pmaxz-this.pminz))+1,this.boundingatom(t),this.cutRadius=this.probeRadius*this.scaleFactor,this.vpBits=new Uint8Array(this.pLength*this.pWidth*this.pHeight),this.vpDistance=new Float64Array(this.pLength*this.pWidth*this.pHeight),this.vpAtomID=new Int32Array(this.pLength*this.pWidth*this.pHeight),this.vpColor=[],this.vpPot=[]},Ke.prototype.boundingatom=function(e){let t,s,i,n,l=[];for(let r in this.vdwRadii){if(!this.vdwRadii.hasOwnProperty(r))continue;let o=this.vdwRadii[r];l[r]=e?(o+this.probeRadius)*this.scaleFactor+.5:o*this.scaleFactor+.5,i=l[r]*l[r],this.widxz[r]=Math.floor(l[r])+1,this.depty[r]=new Int32Array(this.widxz[r]*this.widxz[r]),n=0;for(let e=0;e<this.widxz[r];e++)for(let l=0;l<this.widxz[r];l++)t=e*e+l*l,t>i?this.depty[r][n]=-1:(s=Math.sqrt(i-t),this.depty[r][n]=Math.floor(s)),n++}},Ke.prototype.fillvoxels=function(e,t){let s,i,n,l;for(s=0,l=this.vpBits.length;s<l;s++)this.vpBits[s]=0,this.vpDistance[s]=-1,this.vpAtomID[s]=-1,this.vpColor[s]=new THREE.Color,this.vpPot[s]=0;for(s in t){let i=e[t[s]];void 0!==i&&"DUM"!==i.resn&&this.fillAtom(i,e)}if(this.dataArray){let e=0,t=this.header.xExtent-1,l=0,r=this.header.yExtent-1,o=0,a=this.header.zExtent-1,d=1,c=Math.floor(.5+d*(t-e))+1,h=Math.floor(.5+d*(r-l))+1,p=Math.floor(.5+d*(a-o))+1,m=h*p,u=p,g=new Float32Array(c*h*p);for(s=0;s<c;++s)for(i=0;i<h;++i)for(n=0;n<p;++n){let e,t=s*m+i*u+n;"phi"==this.header.filetype?e=n*m+i*u+s:"cube"==this.header.filetype&&(e=s*m+i*u+n),e<this.dataArray.length&&(g[t]=this.dataArray[e])}let f=this.pWidth*this.pHeight,C=this.pHeight;for(s=0;s<this.pLength;++s)for(i=0;i<this.pWidth;++i)for(n=0;n<this.pHeight;++n){let e=s/this.scaleFactor-this.ptranx,t=i/this.scaleFactor-this.ptrany,l=n/this.scaleFactor-this.ptranz,r=new THREE.Vector3(e,t,l);r.sub(this.header.ori).multiplyScalar(this.header.scale);let o=Math.floor(r.x),a=Math.ceil(r.x),d=Math.floor(r.y),b=Math.ceil(r.y),y=Math.floor(r.z),v=Math.ceil(r.z);a==o&&(a=o+1),b==d&&(b=d+1),v==y&&(v=y+1),a>c&&(a=c),b>h&&(b=h),v>p&&(v=p);let _,w=g[o*m+d*u+y],S=g[a*m+d*u+y],A=g[o*m+b*u+y],x=g[o*m+d*u+v],k=g[a*m+b*u+y],O=g[o*m+b*u+v],R=g[a*m+d*u+v],I=g[a*m+b*u+v],E=r.x-o,T=r.y-d,P=r.z-y,D=((w*(1-E)+S*E)*(1-T)+(A*(1-E)+k*E)*T)*(1-P)+((x*(1-E)+R*E)*(1-T)+(O*(1-E)+I*E)*T)*P,M=s*f+i*C+n;this.vpPot[M]=D,D>this.isovalue&&(D=this.isovalue),D<-this.isovalue&&(D=-this.isovalue),D>0?(D/=1*this.isovalue,_=new THREE.Color(1-D,1-D,1)):(D/=-1*this.isovalue,_=new THREE.Color(1,1-D,1-D)),this.vpColor[M]=_}}for(s=0,l=this.vpBits.length;s<l;s++)this.vpBits[s]&this.INOUT&&(this.vpBits[s]|=this.ISDONE)},Ke.prototype.fillAtom=function(e,t){let s,i,n,l,r,o,a,d,c,h,p,m,u,g,f,C,b,y,v;s=Math.floor(.5+this.scaleFactor*(e.coord.x+this.ptranx)),i=Math.floor(.5+this.scaleFactor*(e.coord.y+this.ptrany)),n=Math.floor(.5+this.scaleFactor*(e.coord.z+this.ptranz));let _=this.getVDWIndex(e),w=0,S=this.pWidth*this.pHeight;for(h=0,v=this.widxz[_];h<v;h++)for(p=0;p<v;p++){if(-1!=this.depty[_][w])for(C=-1;C<2;C++)for(b=-1;b<2;b++)for(y=-1;y<2;y++)if(0!==C&&0!==b&&0!==y)for(a=C*h,c=y*p,m=0;m<=this.depty[_][w];m++){if(d=m*b,u=s+a,g=i+d,f=n+c,u<0||g<0||f<0||u>=this.pLength||g>=this.pWidth||f>=this.pHeight)continue;let h=u*S+g*this.pHeight+f;if(this.vpBits[h]&this.INOUT){let p=t[this.vpAtomID[h]];p.serial!=e.serial&&(l=s+a-Math.floor(.5+this.scaleFactor*(p.x+this.ptranx)),r=i+d-Math.floor(.5+this.scaleFactor*(p.y+this.ptrany)),o=n+c-Math.floor(.5+this.scaleFactor*(p.z+this.ptranz)),a*a+d*d+c*c<l*l+r*r+o*o&&(this.vpAtomID[h]=e.serial))}else this.vpBits[h]|=this.INOUT,this.vpAtomID[h]=e.serial}w++}},Ke.prototype.fillvoxelswaals=function(e,t){let s,i;for(s=0,i=this.vpBits.length;s<i;s++)this.vpBits[s]&=~this.ISDONE;for(s in t){let i=e[t[s]];void 0!==i&&this.fillAtomWaals(i,e)}},Ke.prototype.fillAtomWaals=function(e,t){let s,i,n,l,r,o,a,d,c,h,p,m,u,g,f,C,b,y,v,_=0;s=Math.floor(.5+this.scaleFactor*(e.coord.x+this.ptranx)),i=Math.floor(.5+this.scaleFactor*(e.coord.y+this.ptrany)),n=Math.floor(.5+this.scaleFactor*(e.coord.z+this.ptranz));let w=this.getVDWIndex(e),S=this.pWidth*this.pHeight;for(u=0,v=this.widxz[w];u<v;u++)for(g=0;g<v;g++){if(-1!=this.depty[w][_])for(C=-1;C<2;C++)for(b=-1;b<2;b++)for(y=-1;y<2;y++)if(0!==C&&0!==b&&0!==y)for(a=C*u,c=y*g,f=0;f<=this.depty[w][_];f++){if(d=f*b,h=s+a,p=i+d,m=n+c,h<0||p<0||m<0||h>=this.pLength||p>=this.pWidth||m>=this.pHeight)continue;let u=h*S+p*this.pHeight+m;if(this.vpBits[u]&this.ISDONE){let h=t[this.vpAtomID[u]];h.serial!=e.serial&&(l=s+a-Math.floor(.5+this.scaleFactor*(h.x+this.ptranx)),r=i+d-Math.floor(.5+this.scaleFactor*(h.y+this.ptrany)),o=n+c-Math.floor(.5+this.scaleFactor*(h.z+this.ptranz)),a*a+d*d+c*c<l*l+r*r+o*o&&(this.vpAtomID[u]=e.serial))}else this.vpBits[u]|=this.ISDONE,this.vpAtomID[u]=e.serial}_++}},Ke.prototype.buildboundary=function(){let e=this.pWidth*this.pHeight;for(let t=0;t<this.pLength;t++)for(let s=0;s<this.pHeight;s++)for(let i=0;i<this.pWidth;i++){let n=t*e+i*this.pHeight+s;if(this.vpBits[n]&this.INOUT){let l=0;for(;l<26;){let r=t+this.nb[l][0],o=s+this.nb[l][2],a=i+this.nb[l][1];if(r>-1&&r<this.pLength&&a>-1&&a<this.pWidth&&o>-1&&o<this.pHeight&&!(this.vpBits[r*e+a*this.pHeight+o]&this.INOUT)){this.vpBits[n]|=this.ISBOUND;break}l++}}}},Ke.prototype.fastdistancemap=function(){let e,t,s,i,n,l=new function(e,t,s){let i=new Int32Array(e*t*s*3);this.set=function(e,n,l,r){let o=3*((e*t+n)*s+l);i[o]=r.ix,i[o+1]=r.iy,i[o+2]=r.iz},this.get=function(e,n,l){let r=3*((e*t+n)*s+l);return{ix:i[r],iy:i[r+1],iz:i[r+2]}}}(this.pLength,this.pWidth,this.pHeight),r=this.pWidth*this.pHeight,o=this.cutRadius*this.cutRadius,a=[],d=[];for(e=0;e<this.pLength;e++)for(t=0;t<this.pWidth;t++)for(s=0;s<this.pHeight;s++)if(n=e*r+t*this.pHeight+s,this.vpBits[n]&=~this.ISDONE,this.vpBits[n]&this.INOUT&&this.vpBits[n]&this.ISBOUND){let i={ix:e,iy:t,iz:s};l.set(e,t,s,i),a.push(i),this.vpDistance[n]=0,this.vpBits[n]|=this.ISDONE,this.vpBits[n]&=~this.ISBOUND}do{for(d=this.fastoneshell(a,l),a=[],e=0,i=d.length;e<i;e++)n=r*d[e].ix+this.pHeight*d[e].iy+d[e].iz,this.vpBits[n]&=~this.ISBOUND,this.vpDistance[n]<=1.0404*o&&a.push({ix:d[e].ix,iy:d[e].iy,iz:d[e].iz})}while(0!==a.length);a=[],d=[],l=null;let c=this.scaleFactor-.5;c<0&&(c=0);let h=o-.5/(.1+c);for(e=0;e<this.pLength;e++)for(t=0;t<this.pWidth;t++)for(s=0;s<this.pHeight;s++)n=e*r+t*this.pHeight+s,this.vpBits[n]&=~this.ISBOUND,this.vpBits[n]&this.INOUT&&(this.vpBits[n]&this.ISDONE&&!(this.vpBits[n]&this.ISDONE&&this.vpDistance[n]>=h)||(this.vpBits[n]|=this.ISBOUND))},Ke.prototype.fastoneshell=function(e,t){let s,i,n,l,r,o,a,d,c,h,p,m,u=[];if(0===e.length)return u;let g={ix:-1,iy:-1,iz:-1},f=this.pWidth*this.pHeight;for(a=0,c=e.length;a<c;a++)for(s=e[a].ix,i=e[a].iy,n=e[a].iz,p=t.get(s,i,n),d=0;d<6;d++)g.ix=s+this.nb[d][0],g.iy=i+this.nb[d][1],g.iz=n+this.nb[d][2],g.ix<this.pLength&&g.ix>-1&&g.iy<this.pWidth&&g.iy>-1&&g.iz<this.pHeight&&g.iz>-1&&(m=g.ix*f+this.pHeight*g.iy+g.iz,this.vpBits[m]&this.INOUT&&!(this.vpBits[m]&this.ISDONE)?(t.set(g.ix,g.iy,n+this.nb[d][2],p),l=g.ix-p.ix,r=g.iy-p.iy,o=g.iz-p.iz,h=l*l+r*r+o*o,this.vpDistance[m]=h,this.vpBits[m]|=this.ISDONE,this.vpBits[m]|=this.ISBOUND,u.push({ix:g.ix,iy:g.iy,iz:g.iz})):this.vpBits[m]&this.INOUT&&this.vpBits[m]&this.ISDONE&&(l=g.ix-p.ix,r=g.iy-p.iy,o=g.iz-p.iz,h=l*l+r*r+o*o,h<this.vpDistance[m]&&(t.set(g.ix,g.iy,g.iz,p),this.vpDistance[m]=h,this.vpBits[m]&this.ISBOUND||(this.vpBits[m]|=this.ISBOUND,u.push({ix:g.ix,iy:g.iy,iz:g.iz})))));for(a=0,c=e.length;a<c;a++)for(s=e[a].ix,i=e[a].iy,n=e[a].iz,p=t.get(s,i,n),d=6;d<18;d++)g.ix=s+this.nb[d][0],g.iy=i+this.nb[d][1],g.iz=n+this.nb[d][2],g.ix<this.pLength&&g.ix>-1&&g.iy<this.pWidth&&g.iy>-1&&g.iz<this.pHeight&&g.iz>-1&&(m=g.ix*f+this.pHeight*g.iy+g.iz,this.vpBits[m]&this.INOUT&&!(this.vpBits[m]&this.ISDONE)?(t.set(g.ix,g.iy,n+this.nb[d][2],p),l=g.ix-p.ix,r=g.iy-p.iy,o=g.iz-p.iz,h=l*l+r*r+o*o,this.vpDistance[m]=h,this.vpBits[m]|=this.ISDONE,this.vpBits[m]|=this.ISBOUND,u.push({ix:g.ix,iy:g.iy,iz:g.iz})):this.vpBits[m]&this.INOUT&&this.vpBits[m]&this.ISDONE&&(l=g.ix-p.ix,r=g.iy-p.iy,o=g.iz-p.iz,h=l*l+r*r+o*o,h<this.vpDistance[m]&&(t.set(g.ix,g.iy,g.iz,p),this.vpDistance[m]=h,this.vpBits[m]&this.ISBOUND||(this.vpBits[m]|=this.ISBOUND,u.push({ix:g.ix,iy:g.iy,iz:g.iz})))));for(a=0,c=e.length;a<c;a++)for(s=e[a].ix,i=e[a].iy,n=e[a].iz,p=t.get(s,i,n),d=18;d<26;d++)g.ix=s+this.nb[d][0],g.iy=i+this.nb[d][1],g.iz=n+this.nb[d][2],g.ix<this.pLength&&g.ix>-1&&g.iy<this.pWidth&&g.iy>-1&&g.iz<this.pHeight&&g.iz>-1&&(m=g.ix*f+this.pHeight*g.iy+g.iz,this.vpBits[m]&this.INOUT&&!(this.vpBits[m]&this.ISDONE)?(t.set(g.ix,g.iy,n+this.nb[d][2],p),l=g.ix-p.ix,r=g.iy-p.iy,o=g.iz-p.iz,h=l*l+r*r+o*o,this.vpDistance[m]=h,this.vpBits[m]|=this.ISDONE,this.vpBits[m]|=this.ISBOUND,u.push({ix:g.ix,iy:g.iy,iz:g.iz})):this.vpBits[m]&this.INOUT&&this.vpBits[m]&this.ISDONE&&(l=g.ix-p.ix,r=g.iy-p.iy,o=g.iz-p.iz,h=l*l+r*r+o*o,h<this.vpDistance[m]&&(t.set(g.ix,g.iy,g.iz,p),this.vpDistance[m]=h,this.vpBits[m]&this.ISBOUND||(this.vpBits[m]|=this.ISBOUND,u.push({ix:g.ix,iy:g.iy,iz:g.iz})))));return u},Ke.prototype.marchingcubeinit=function(e){for(let t=0,s=this.vpBits.length;t<s;t++)1==e?this.vpBits[t]&=~this.ISBOUND:4==e?(this.vpBits[t]&=~this.ISDONE,this.vpBits[t]&this.ISBOUND&&(this.vpBits[t]|=this.ISDONE),this.vpBits[t]&=~this.ISBOUND):2==e?this.vpBits[t]&this.ISBOUND&&this.vpBits[t]&this.ISDONE?this.vpBits[t]&=~this.ISBOUND:this.vpBits[t]&this.ISBOUND&&!(this.vpBits[t]&this.ISDONE)&&(this.vpBits[t]|=this.ISDONE):3==e&&(this.vpBits[t]&=~this.ISBOUND)},Ke.prototype.counter=function(){let e=Array(256);for(let t=0;t<256;t++)e[t]=[];this.incrementUsed=function(t,s){void 0===e[t][s]&&(e[t][s]={used:0,unused:0}),e[t][s].used++},this.incrementUnused=function(t,s){void 0===e[t][s]&&(e[t][s]={used:0,unused:0}),e[t][s].unused++};this.print=function(){let t=this.marchingCube.triTable,s=[];for(let i=0;i<t.length;i++){let n=[];for(let s=0;s<t[i].length;s+=3){let l=s/3;void 0!==e[i][l]&&e[i][l].unused||(n.push(t[i][s]),n.push(t[i][s+1]),n.push(t[i][s+2])),void 0===e[i][l]&&console.log("undef "+i+","+l)}s.push(n)}!function(e){let t="[";for(let s=0;s<e.length;s++){let i=0,n=e[s];for(let e=0;e<n.length;e++)i|=1<<n[e];t+="0x"+i.toString(16)+", "}t+="]"}(s)}},Ke.prototype.marchingcube=function(e){this.marchingcubeinit(e),this.verts=[],this.faces=[],this.marchingCube.march(this.vpBits,this.verts,this.faces,{smooth:1,nX:this.pLength,nY:this.pWidth,nZ:this.pHeight});let t=this.pWidth*this.pHeight;for(let e=0,s=this.verts.length;e<s;e++)this.verts[e].atomid=this.vpAtomID[this.verts[e].x*t+this.pHeight*this.verts[e].y+this.verts[e].z],this.dataArray&&(this.verts[e].color=this.vpColor[this.verts[e].x*t+this.pHeight*this.verts[e].y+this.verts[e].z]),this.dataArray&&(this.verts[e].pot=this.vpPot[this.verts[e].x*t+this.pHeight*this.verts[e].y+this.verts[e].z]);let s,i=0;if(this.bCalcArea){let e={};s={};for(let t=0,n=this.faces.length;t<n;t+=3){let n=this.faces[t],l=this.faces[t+1],r=this.faces[t+2];if(n==l||l==r||n==r)continue;let o=Math.min(n,l,r),a=Math.max(n,l,r),d=o+"_"+(n+l+r-o-a)+"_"+a;if(e.hasOwnProperty(d))continue;e[d]=1;let c=this.verts[n].atomid,h=this.verts[l].atomid,p=this.verts[r].atomid;if(!this.atomsToShow[c]||!this.atomsToShow[h]||!this.atomsToShow[p])continue;let m=this.verts[n],u=this.verts[l],g=this.verts[r],f=(m.x-u.x)*(m.x-u.x)+(m.y-u.y)*(m.y-u.y)+(m.z-u.z)*(m.z-u.z),C=(m.x-g.x)*(m.x-g.x)+(m.y-g.y)*(m.y-g.y)+(m.z-g.z)*(m.z-g.z),b=(g.x-u.x)*(g.x-u.x)+(g.y-u.y)*(g.y-u.y)+(g.z-u.z)*(g.z-u.z),y=Math.min(f,C,b),v=Math.max(f,C,b),_=f+C+b-y-v,w=0;w=0==parseInt(100*(v-y))?.433*y:0==parseInt(100*(_-y))?.5*y:.707*y;let S=w/3;void 0===s[c]?s[c]=S:s[c]+=S,void 0===s[h]?s[h]=S:s[h]+=S,void 0===s[p]?s[p]=S:s[p]+=S,i+=w}i=i/this.scaleFactor/this.scaleFactor}return this.bCalcArea||this.marchingCube.laplacianSmooth(1,this.verts,this.faces),{area:i,serial2area:s,scaleFactor:this.scaleFactor}};class Je{constructor(e){this.icn3d=e,this.INOUT=1,this.ISDONE=2,this.ISBOUND=4,this.isovalue=1.5,this.dataArray={},this.matrix=void 0,this.center=void 0,this.maxdist=void 0,this.pmin=void 0,this.pmax=void 0,this.water=void 0,this.header=void 0,this.type=void 0,this.rmsd_supr=void 0,this.loadPhiFrom=void 0,this.ptranx=0,this.ptrany=0,this.ptranz=0,this.probeRadius=1.4,this.defaultScaleFactor=2,this.scaleFactor=this.defaultScaleFactor,this.pHeight=0,this.pWidth=0,this.pLength=0,this.cutRadius=0,this.vpBits=null,this.vpGridTrans=null,this.vpAtomID=null,this.vertnumber=0,this.facenumber=0,this.pminx=0,this.pminy=0,this.pminz=0,this.pmaxx=0,this.pmaxy=0,this.pmaxz=0,this.depty={},this.widxz={},this.faces=void 0,this.verts=void 0,this.nb=[new Int32Array([1,0,0]),new Int32Array([-1,0,0]),new Int32Array([0,1,0]),new Int32Array([0,-1,0]),new Int32Array([0,0,1]),new Int32Array([0,0,-1]),new Int32Array([1,1,0]),new Int32Array([1,-1,0]),new Int32Array([-1,1,0]),new Int32Array([-1,-1,0]),new Int32Array([1,0,1]),new Int32Array([1,0,-1]),new Int32Array([-1,0,1]),new Int32Array([-1,0,-1]),new Int32Array([0,1,1]),new Int32Array([0,1,-1]),new Int32Array([0,-1,1]),new Int32Array([0,-1,-1]),new Int32Array([1,1,1]),new Int32Array([1,1,-1]),new Int32Array([1,-1,1]),new Int32Array([-1,1,1]),new Int32Array([1,-1,-1]),new Int32Array([-1,-1,1]),new Int32Array([-1,1,-1]),new Int32Array([-1,-1,-1])],this.marchingCube=new Xe}}Je.prototype.getFacesAndVertices=function(e,t){let s,i,n={};for(s=0,i=t.length;s<i;s++)n[t[s]]=1;let l=this.verts,r={};for(s=0,i=l.length;s<i;s++){let e;if("phi"==this.type)e=new THREE.Vector3(l[s].x,l[s].y,l[s].z).multiplyScalar(1/this.header.scale).applyMatrix4(this.matrix);else{if(this.ccp4){let e,t=l[s].index;this.vpGridTrans[t]&&(e=t,l[s].x+=this.vpGridTrans[e][0]*this.header.xExtent*this.scaleFactor,l[s].y+=this.vpGridTrans[e][1]*this.header.xExtent*this.scaleFactor,l[s].z+=this.vpGridTrans[e][2]*this.header.xExtent*this.scaleFactor,r[e]=1)}e=new THREE.Vector3(l[s].x,l[s].y,l[s].z).applyMatrix4(this.matrix)}l[s].x=e.x,l[s].y=e.y,l[s].z=e.z}let o=[];for(s=0,i=this.faces.length;s<i;s+=3){let e=this.faces[s],t=this.faces[s+1],i=this.faces[s+2];e!==t&&t!==i&&e!==i&&(this.ccp4?r.hasOwnProperty(l[e].index)&&r.hasOwnProperty(l[t].index)&&r.hasOwnProperty(l[i].index)&&o.push({a:e,b:t,c:i}):o.push({a:e,b:t,c:i}))}return this.vpBits=null,this.vpGridTrans=null,this.vpAtomID=null,{vertices:l,faces:o}},Je.prototype.initparm=function(e,t,s,i,n,l,r,o,a,d,c,h,p){this.header=e,this.loadPhiFrom=h,this.header&&void 0!==this.header.max?this.isovalue=this.header.min+(this.header.max-this.header.min)*i/100:this.header&&void 0!==this.header.mean?this.isovalue=this.header.mean+this.header.sigma*i:this.isovalue=i,this.dataArray=t,this.matrix=s,this.center=n,this.maxdist=l,this.pmin=r,this.pmax=o,this.water=a,this.type=d,this.rmsd_supr=c,this.pminx=0,this.pmaxx=this.header.xExtent-1,this.pminy=0,this.pmaxy=this.header.yExtent-1,this.pminz=0,this.pmaxz=this.header.zExtent-1,this.ptranx=-this.pminx,this.ptrany=-this.pminy,this.ptranz=-this.pminz;let m=this.pmaxx-this.pminx;this.pmaxy-this.pminy>m&&(m=this.pmaxy-this.pminy),this.pmaxz-this.pminz>m&&(m=this.pmaxz-this.pminz),this.scaleFactor=1,this.pLength=Math.floor(.5+this.scaleFactor*(this.pmaxx-this.pminx))+1,this.pWidth=Math.floor(.5+this.scaleFactor*(this.pmaxy-this.pminy))+1,this.pHeight=Math.floor(.5+this.scaleFactor*(this.pmaxz-this.pminz))+1,this.cutRadius=this.probeRadius*this.scaleFactor,this.vpBits=new Uint8Array(this.pLength*this.pWidth*this.pHeight),this.ccp4&&(this.vpGridTrans=new Array(this.pLength*this.pWidth*this.pHeight)),this.vpAtomID=new Uint8Array(this.pLength*this.pWidth*this.pHeight)},Je.prototype.transformMemPro=function(e,t,s,i){let n=e.clone();n.sub(s);let l=n.x*t[0]+n.y*t[1]+n.z*t[2]+i.x,r=n.x*t[3]+n.y*t[4]+n.z*t[5]+i.y,o=n.x*t[6]+n.y*t[7]+n.z*t[8]+i.z;return n.x=l,n.y=r,n.z=o,n},Je.prototype.fillvoxels=function(e,t){let s,i,n,l,r,o;for(s=0,l=this.vpBits.length;s<l;s++)this.vpBits[s]=0,this.vpAtomID[s]=0;let a=this.pWidth*this.pHeight,d=this.pHeight;if("phi"!=this.type||this.header.bSurface){let c=(new THREE.Matrix4).copy(this.matrix).invert(),h=[];this.maxdist=parseInt(this.maxdist);let p,m,u,g=new Array(9);if(void 0!==this.rmsd_supr&&void 0!==this.rmsd_supr.rot){p=this.rmsd_supr.rot,m=this.rmsd_supr.trans1,u=this.rmsd_supr.trans2;let e=new THREE.Matrix3,t=new THREE.Matrix3;e.set(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]),t.copy(e).invert(),g[0]=t.elements[0],g[1]=t.elements[3],g[2]=t.elements[6],g[3]=t.elements[1],g[4]=t.elements[4],g[5]=t.elements[7],g[6]=t.elements[2],g[7]=t.elements[5],g[8]=t.elements[8]}if("phi"==this.type&&this.header.bSurface){let l=new Float32Array(this.pLength*this.pWidth*this.pHeight);for(s=0;s<this.pLength;++s)for(i=0;i<this.pWidth;++i)for(n=0;n<this.pHeight;++n){let e,t=s*a+i*d+n;"phi"==this.header.filetype?e=n*a+i*d+s:"cube"==this.header.filetype&&(e=s*a+i*d+n),e<this.dataArray.length&&(l[t]=this.dataArray[e])}for(let s in t){let i=e[t[s]];if("DUM"===i.resn)continue;let n=i.coord.clone();if("delphi"!=this.loadPhiFrom)if(void 0!==this.rmsd_supr&&void 0!==this.rmsd_supr.rot){n=this.transformMemPro(i.coord,g,u,m).applyMatrix4(c)}else n=i.coord.clone().applyMatrix4(c);n.sub(this.header.ori).multiplyScalar(this.header.scale);let r=Math.floor(n.x),o=Math.ceil(n.x),h=Math.floor(n.y),p=Math.ceil(n.y),f=Math.floor(n.z),C=Math.ceil(n.z);o==r&&(o=r+1),p==h&&(p=h+1),C==f&&(C=f+1),o>this.pLength&&(o=this.pLength),p>this.pWidth&&(p=this.pWidth),C>this.pHeight&&(C=this.pHeight);let b,y=l[r*a+h*d+f],v=l[o*a+h*d+f],_=l[r*a+p*d+f],w=l[r*a+h*d+C],S=l[o*a+p*d+f],A=l[r*a+p*d+C],x=l[o*a+h*d+C],k=l[o*a+p*d+C],O=n.x-r,R=n.y-h,I=n.z-f,E=((y*(1-O)+v*O)*(1-R)+(_*(1-O)+S*O)*R)*(1-I)+((w*(1-O)+x*O)*(1-R)+(A*(1-O)+k*O)*R)*I;E>this.isovalue&&(E=this.isovalue),E<-this.isovalue&&(E=-this.isovalue),E>0?(E/=1*this.isovalue,b=new THREE.Color(1-E,1-E,1)):(E/=-1*this.isovalue,b=new THREE.Color(1,1-E,1-E)),this.icn3d.atoms[t[s]].color=b,this.icn3d.atomPrevColors[t[s]]=b}}else{for(let p in t){let f,C=e[t[p]];if("DUM"!==C.resn){if(void 0!==this.rmsd_supr&&void 0!==this.rmsd_supr.rot){f=this.transformMemPro(C.coord,g,u,m).applyMatrix4(c)}else f=C.coord.clone().applyMatrix4(c);for(s=Math.floor(f.x)-this.maxdist,l=Math.ceil(f.x)+this.maxdist;s<=l;++s)if(!(s<0||s>this.header.xExtent*this.scaleFactor-1))for(i=Math.floor(f.y)-this.maxdist,r=Math.ceil(f.y)+this.maxdist;i<=r;++i)if(!(i<0||i>this.header.yExtent*this.scaleFactor-1))for(n=Math.floor(f.z)-this.maxdist,o=Math.ceil(f.z)+this.maxdist;n<=o;++n){if(n<0||n>this.header.zExtent*this.scaleFactor-1)continue;let e=s*a+i*d+n;h.push(e)}}}for(s=0,l=h.length;s<l;++s){let e=h[s];"2fofc"==this.type?this.vpBits[e]=this.dataArray[e]>=this.isovalue?1:0:"fofc"==this.type?(this.vpBits[e]=this.dataArray[e]>=this.isovalue||this.dataArray[e]<=-this.isovalue?1:0,this.vpAtomID[e]=this.dataArray[e]>=0?1:0):"em"==this.type&&(this.vpBits[e]=this.dataArray[e]>=this.isovalue?1:0)}}}else for(s=0;s<this.pLength;++s)for(i=0;i<this.pWidth;++i)for(n=0;n<this.pHeight;++n){let e,t=s*a+i*d+n;"phi"==this.header.filetype?e=n*a+i*d+s:"cube"==this.header.filetype&&(e=s*a+i*d+n),e<this.dataArray.length&&(this.vpBits[t]=this.dataArray[e]>=this.isovalue||this.dataArray[e]<=-this.isovalue?1:0,this.vpAtomID[t]=this.dataArray[e]>=0?1:0)}for(s=0,l=this.vpBits.length;s<l;s++)this.vpBits[s]&this.INOUT&&(this.vpBits[s]|=this.ISDONE)},Je.prototype.buildboundary=function(){let e,t,s,i=this.pWidth*this.pHeight;for(e=0;e<this.pLength;e++)for(t=0;t<this.pHeight;t++)for(s=0;s<this.pWidth;s++){let n=e*i+s*this.pHeight+t;if(this.vpBits[n]&this.INOUT){let l=0;for(;l<26;){let r=e+this.nb[l][0],o=t+this.nb[l][2],a=s+this.nb[l][1];if(r>-1&&r<this.pLength&&a>-1&&a<this.pWidth&&o>-1&&o<this.pHeight&&!(this.vpBits[r*i+a*this.pHeight+o]&this.INOUT)){this.vpBits[n]|=this.ISBOUND;break}l++}}}},Je.prototype.marchingcubeinit=function(e){for(let t=0,s=this.vpBits.length;t<s;t++)1==e?this.vpBits[t]&=~this.ISBOUND:4==e?(this.vpBits[t]&=~this.ISDONE,this.vpBits[t]&this.ISBOUND&&(this.vpBits[t]|=this.ISDONE),this.vpBits[t]&=~this.ISBOUND):2==e?this.vpBits[t]&this.ISBOUND&&this.vpBits[t]&this.ISDONE?this.vpBits[t]&=~this.ISBOUND:this.vpBits[t]&this.ISBOUND&&!(this.vpBits[t]&this.ISDONE)&&(this.vpBits[t]|=this.ISDONE):this.vpBits[t]&=~this.ISBOUND},Je.prototype.counter=function(){let e=Array(256);for(let t=0;t<256;t++)e[t]=[];this.incrementUsed=function(t,s){void 0===e[t][s]&&(e[t][s]={used:0,unused:0}),e[t][s].used++},this.incrementUnused=function(t,s){void 0===e[t][s]&&(e[t][s]={used:0,unused:0}),e[t][s].unused++};this.print=function(){let t=this.marchingCube.triTable,s=[];for(let i=0;i<t.length;i++){let n=[];for(let s=0;s<t[i].length;s+=3){let l=s/3;void 0!==e[i][l]&&e[i][l].unused||(n.push(t[i][s]),n.push(t[i][s+1]),n.push(t[i][s+2])),void 0===e[i][l]&&console.log("undef "+i+","+l)}s.push(n)}!function(e){let t="[";for(let s=0;s<e.length;s++){let i=0,n=e[s];for(let e=0;e<n.length;e++)i|=1<<n[e];t+="0x"+i.toString(16)+", "}t+="]"}(s)}},Je.prototype.marchingcube=function(e){this.marchingcubeinit(e),this.verts=[],this.faces=[],this.marchingCube.march(this.vpBits,this.verts,this.faces,{smooth:1,nX:this.pLength,nY:this.pWidth,nZ:this.pHeight});let t=this.pWidth*this.pHeight;for(let e=0,s=this.verts.length;e<s;e++)this.verts[e].atomid=this.vpAtomID[this.verts[e].x*t+this.pHeight*this.verts[e].y+this.verts[e].z];this.marchingCube.laplacianSmooth(1,this.verts,this.faces)};class Ze{constructor(e){this.icn3d=e}createSurfaceRepresentation(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=this;if(0==Object.keys(e).length)return;null==i&&(i=1),l.opacity=i;let a=l.contactCls.getExtent(e),d=[];if(l.bConsiderNeighbors){let t;t=r.hashUtilsCls.unionHash(t,e),t=r.hashUtilsCls.unionHash(t,l.contactCls.getAtomsWithinAtom(l.atoms,e,5)),d=Object.keys(t)}else d=Object.keys(e);let c;10==parseInt(10*i)||s||l.bInstanced&&(Object.keys(l.atoms).length,l.biomtMatrices.length,l.maxatomcnt);let h={allatoms:l.atoms,atomsToShow:Object.keys(e),extendedAtoms:d,water:l.water,center:l.center,maxdist:1,pmin:l.pmin,pmax:l.pmax,rmsd_supr:l.rmsd_supr};if(11==t){if(h.header=l.mapData.header2,h.data=l.mapData.data2,h.matrix=l.mapData.matrix2,h.isovalue=l.mapData.sigma2,h.type="2fofc",h.ccp4=l.mapData.ccp4,h.grid=l.mapData.grid2,h.unit_cell=l.mapData.unit_cell2,!h.header&&!h.ccp4)return;if(c=this.SetupMap(h),h.ccp4)return void(l.mapData={})}else if(12==t){if(h.header=l.mapData.header,h.data=l.mapData.data,h.matrix=l.mapData.matrix,h.isovalue=l.mapData.sigma,h.type="fofc",h.ccp4=l.mapData.ccp4,h.grid=l.mapData.grid,h.unit_cell=l.mapData.unit_cell,!h.header&&!h.ccp4)return;if(c=this.SetupMap(h),h.ccp4)return void(l.mapData={})}else if(13==t)h.maxdist=3,h.header=l.mapData.headerEm,h.data=l.mapData.dataEm,h.matrix=l.mapData.matrixEm,h.isovalue=l.mapData.sigmaEm,h.type="em",c=this.SetupMap(h);else if(14==t)h.header=l.mapData.headerPhi,h.data=l.mapData.dataPhi,h.matrix=l.mapData.matrixPhi,h.isovalue=l.mapData.contourPhi,h.type="phi",h.loadPhiFrom=l.loadPhiFrom,c=this.SetupMap(h);else{let s=r.hashUtilsCls.exclHash(e,l.water);d=r.hashUtilsCls.exclHash(d,l.water);let i=t;21==i?i=1:22==i?i=2:23==i&&(i=3),h={extent:a,allatoms:l.atoms,atomsToShow:Object.keys(s),extendedAtoms:d,type:i,threshbox:l.transparentRenderOrder?60:l.threshbox,bCalcArea:l.bCalcArea},h.header=l.mapData.headerPhi,h.data=l.mapData.dataPhi,h.matrix=l.mapData.matrixPhi,h.isovalue=l.mapData.contourPhi,h.loadPhiFrom=l.loadPhiFrom,c=this.SetupSurface(h)}if(l.bCalcArea){l.areavalue=c.area.toFixed(2);let e=c.serial2area,t=c.scaleFactor*c.scaleFactor;l.resid2area={};let s={},i={};for(let t in e){let n=l.atoms[t],r=n.structure+"_"+n.chain+"_"+n.resi+"_"+n.resn;s[n.structure]=1,i[n.structure+"_"+n.chain]=1,void 0===l.resid2area[r]?l.resid2area[r]=e[t]:l.resid2area[r]+=e[t]}let n='<table border="1" cellpadding="10" cellspacing="0">',o=Object.keys(s).length>1?"<th>Structure</th>":"",a=Object.keys(i).length>1?"<th>Chain</th>":"";n+="<tr>"+o+a+"<th>Residue</th><th>Number</th><th>SASA (&#8491;<sup>2</sup>)</th><th>Percent Out</th><th>In/Out</th></tr>";for(let e in l.resid2area){let d=e.lastIndexOf("_"),c=e.substr(d+1),h=r.utilsCls.getIdArray(e.substr(0,d));o=Object.keys(s).length>1?"<td>"+h[0]+"</td>":"",a=Object.keys(i).length>1?"<td>"+h[1]+"</td>":"";let p="",m="";l.resid2area[e]=(l.resid2area[e]/t).toFixed(2),r.parasCls.residueArea.hasOwnProperty(c)&&(m=parseInt(l.resid2area[e]/r.parasCls.residueArea[c]*100),m>100&&(m=100),m>=50&&(p="out"),m<20&&(p="in")),n+='<tr align="center">'+o+a+"<td>"+c+'</td><td align="right">'+h[2]+'</td><td align="right">'+l.resid2area[e]+'</td><td align="right">'+m+"%</td><td>"+p+"</td></tr>"}return n+="</table>",void(l.areahtml=n)}let p,m,u,g=c.vertices,f=c.faces,C=r.parasCls.thr("#00FFFF"),b=r.parasCls.thr("#00FF00"),y=r.parasCls.thr("#ff0000"),v=r.parasCls.thr("#00FFFF"),_=r.parasCls.thr("#0000FF"),w=r.parasCls.thr("#FF0000");11!=t&&12!=t&&13!=t&&14!=t||void 0===l.rmsd_supr||void 0===l.rmsd_supr.rot||(p=l.rmsd_supr.rot,m=l.rmsd_supr.trans1,u=l.rmsd_supr.trans2);let S=(11==t||12==t||13==t||14==t&&"delphi"!=l.loadPhiFrom)&&void 0!==l.rmsd_supr&&void 0!==l.rmsd_supr.rot;n=new THREE.BufferGeometry;let A,x=[],k=[],O=[],R=0;for(let e=0,s=g.length;e<s;++e,R+=3){let s=g[e],i=new THREE.Vector3(s.x,s.y,s.z);if(S&&(i=o.transformMemPro(i,p,m,u)),x[R]=i.x,x[R+1]=i.y,x[R+2]=i.z,11==t)A=C;else if(12==t)A=s.atomid?b:y;else if(13==t)A=v;else if(14==t)A=s.atomid?_:w;else if(21==t||22==t||23==t){A=s.color;let e=s.atomid;l.atoms[e].pot=s.pot}else{let e=s.atomid;A=l.atoms[e].color}k[R]=A.r,k[R+1]=A.g,k[R+2]=A.b}if(r.bNode)return;R=0;for(let e=0,t=f.length;e<t;++e,R+=3){let t=f[e];O[R]=t.a,O[R+1]=t.b,O[R+2]=t.c}if(n.setAttribute("position",new THREE.BufferAttribute(new Float32Array(x),3)),n.setAttribute("color",new THREE.BufferAttribute(new Float32Array(k),3)),n.setIndex(new THREE.BufferAttribute(new Uint32Array(O),1)),n.computeVertexNormals(),n.type="Surface",l.transparentRenderOrder){let e={};for(let t=0,s=f.length;t<s;++t){let s=f[t].a,i=f[t].b,n=f[t].c;void 0===e[s]&&(e[s]=[]),e[s].push(i),e[s].push(n)}for(let n in e){this.geometry=new THREE.BufferGeometry;let o=[],a=[],d=[],c=0,h=0,p=0,m=e[n],u=new THREE.Vector3(0,0,0),f=3,C=0;for(let e=0,s=m.length;e<s;e+=2){let s=m[e],i=m[e+1];o[c++]=g[n].x,o[c++]=g[n].y,o[c++]=g[n].z,o[c++]=g[s].x,o[c++]=g[s].y,o[c++]=g[s].z,o[c++]=g[i].x,o[c++]=g[i].y,o[c++]=g[i].z,21==t||22==t||23==t?(a[h++]=g[n].color.r,a[h++]=g[n].color.g,a[h++]=g[n].color.b,a[h++]=g[s].color.r,a[h++]=g[s].color.g,a[h++]=g[s].color.b,a[h++]=g[i].color.r,a[h++]=g[i].color.g,a[h++]=g[i].color.b):(a[h++]=l.atoms[g[n].atomid].color.r,a[h++]=l.atoms[g[n].atomid].color.g,a[h++]=l.atoms[g[n].atomid].color.b,a[h++]=l.atoms[g[s].atomid].color.r,a[h++]=l.atoms[g[s].atomid].color.g,a[h++]=l.atoms[g[s].atomid].color.b,a[h++]=l.atoms[g[i].atomid].color.r,a[h++]=l.atoms[g[i].atomid].color.g,a[h++]=l.atoms[g[i].atomid].color.b);let r=e/2*3;d[p++]=r,d[p++]=r+1,d[p++]=r+2,u=u.add(new THREE.Vector3(g[r].x,g[r].y,g[r].z)),u=u.add(new THREE.Vector3(g[r+1].x,g[r+1].y,g[r+1].z)),u=u.add(new THREE.Vector3(g[r+2].x,g[r+2].y,g[r+2].z)),C+=3}this.geometry.setAttribute("position",new THREE.BufferAttribute(new Float32Array(o),f)),this.geometry.setAttribute("color",new THREE.BufferAttribute(new Float32Array(a),f)),this.geometry.setIndex(new THREE.BufferAttribute(new Uint32Array(d),1)),this.geometry.computeVertexNormals(),this.geometry.type="Surface";let b,y=new THREE.Mesh(this.geometry,new THREE.MeshBasicMaterial({specular:l.frac,shininess:0,emissive:l.emissive,vertexColors:!0,wireframe:s,opacity:i,transparent:!0,side:THREE.DoubleSide}));b=l.bControlGl&&!r.bNode?u.multiplyScalar(1/C).sub(l.oriCenter).applyMatrix4(window.cam.matrixWorldInverse):u.multiplyScalar(1/C).sub(l.oriCenter).applyMatrix4(l.cam.matrixWorldInverse),y.renderOrder=l.cam_z>0?-parseInt(b.z):parseInt(b.z),y.onBeforeRender=function(e,t,s,i,n,o){let a,d=new THREE.Vector3(0,0,0),c=i.getAttribute("position").array;for(let e=0,t=c.length;e<t;e+=3)d=d.add(new THREE.Vector3(c[e],c[e+1],c[e+2]));a=l.bControlGl&&!r.bNode?d.multiplyScalar(3/c.length).sub(l.oriCenter).applyMatrix4(window.cam.matrixWorldInverse):d.multiplyScalar(3/c.length).sub(l.oriCenter).applyMatrix4(l.cam.matrixWorldInverse),this.renderOrder=l.cam_z>0?-parseInt(a.z):parseInt(a.z)},l.mdl.add(y),11==t||12==t?l.prevMaps.push(y):13==t?l.prevEmmaps.push(y):14==t?l.prevPhimaps.push(y):l.prevSurfaces.push(y)}}else{let e=new THREE.Mesh(n,new THREE.MeshPhongMaterial({specular:l.frac,shininess:20,emissive:l.emissive,vertexColors:!0,wireframe:s,opacity:i,transparent:!0,depthWrite:10==parseInt(10*i),side:THREE.DoubleSide}));e.renderOrder=-2,l.mdl.add(e),11==t||12==t?l.prevMaps.push(e):13==t?l.prevEmmaps.push(e):14==t?l.prevPhimaps.push(e):l.prevSurfaces.push(e)}c=null,g=null,f=null,n=null}transformMemPro(e,t,s,i,n){this.icn3d.icn3dui;let l=e.clone();l.sub(s),n&&console.log("sub coord: "+JSON.stringify(l));let r=l.x*t[0]+l.y*t[1]+l.z*t[2]+i.x,o=l.x*t[3]+l.y*t[4]+l.z*t[5]+i.y,a=l.x*t[6]+l.y*t[7]+l.z*t[8]+i.z;return l.x=r,l.y=o,l.z=a,n&&console.log("out coord: "+JSON.stringify(l)),l}SetupSurface(e){let t=this.icn3d;t.icn3dui;let s=e.threshbox,i=new Ke(t,s);i.initparm(e.extent,1!==e.type,e.bCalcArea,e.atomsToShow,e.header,e.data,e.matrix,e.isovalue,e.loadPhiFrom),i.fillvoxels(e.allatoms,e.extendedAtoms),i.buildboundary(),2===e.type&&(i.fastdistancemap(),i.boundingatom(!1),i.fillvoxelswaals(e.allatoms,e.extendedAtoms));let n=i.marchingcube();i.vpBits=null,i.vpDistance=null,i.vpAtomID=null;let l=i.getFacesAndVertices(e.atomsToShow);return l.area=n.area,l.serial2area=n.serial2area,l.scaleFactor=n.scaleFactor,i.faces=null,i.verts=null,l}SetupMap(e){let t=this.icn3d;if(t.icn3dui,!e.ccp4){let s,i=new Je(t);return i.initparm(e.header,e.data,e.matrix,e.isovalue,e.center,e.maxdist,e.pmin,e.pmax,e.water,e.type,e.rmsd_supr,e.loadPhiFrom,e.icn3d),i.fillvoxels(e.allatoms,e.extendedAtoms),e.header.bSurface||i.buildboundary(),e.header.bSurface||i.marchingcube(),i.vpBits=null,i.vpAtomID=null,e.header.bSurface||(s=i.getFacesAndVertices(e.allatoms,e.atomsToShow)),i.faces=null,i.verts=null,s}{let s,i=10,n=t.center?[t.center.x,t.center.y,t.center.z]:[0,0,0];if("2fofc"==e.type){s="2fofc";let l=t.ccp4ParserCls.extract_block(e.grid,e.unit_cell,i,n,s),r=t.ccp4ParserCls.marchingCubes(l.size,l.values,l.points,e.isovalue,"marching cubes");t.ccp4ParserCls.makeChickenWire(r,s),l=null,r=null}else if("fofc"==e.type){s="fofc_neg";let l=t.ccp4ParserCls.extract_block(e.grid,e.unit_cell,i,n,s),r=t.ccp4ParserCls.marchingCubes(l.size,l.values,l.points,e.isovalue,"marching cubes");t.ccp4ParserCls.makeChickenWire(r,s),s="fofc_pos",l=t.ccp4ParserCls.extract_block(e.grid,e.unit_cell,i,n,s),r=t.ccp4ParserCls.marchingCubes(l.size,l.values,l.points,e.isovalue,"marching cubes"),t.ccp4ParserCls.makeChickenWire(r,s),l=null,r=null}}}}class Qe{constructor(e){this.icn3d=e}applyCenterOptions(e){let t,s=this.icn3d;switch(s.icn3dui,void 0===e&&(e=s.opts),e.rotationcenter.toLowerCase()){case"molecule center":void 0!==s.center&&this.setRotationCenter(s.center);break;case"pick center":void 0!==s.pAtom&&this.setRotationCenter(s.pAtom.coord);break;case"display center":t=this.centerAtoms(s.dAtoms).center,this.setRotationCenter(t);break;case"highlight center":t=this.centerAtoms(s.hAtoms).center,this.setRotationCenter(t)}}setRotationCenter(e){this.icn3d.icn3dui,this.setCenter(e)}setCenter(e){let t=this.icn3d;t.icn3dui,t.mdl.position.set(0,0,0),t.mdlImpostor.position.set(0,0,0),t.mdl_ghost.position.set(0,0,0),t.mdl.position.sub(e),t.mdlImpostor.position.sub(e),t.mdl_ghost.position.sub(e)}centerSelection(e,t){let s=this.icn3d,i=s.icn3dui;if(s.opts.rotationcenter="highlight center",void 0===e&&(e=i.hashUtilsCls.hash2Atoms(s.hAtoms,s.atoms)),t||(s._zoomFactor=1,s.mouseChange=new THREE.Vector2(0,0),s.quaternion=new THREE.Quaternion(0,0,0,1)),Object.keys(e).length>1){let t=this.centerAtoms(e);s.center=t.center,this.setCenter(s.center),s.cameraCls.setCamera()}}centerAtoms(e){let t=this.icn3d;t.icn3dui;let s=new THREE.Vector3(9999,9999,9999),i=new THREE.Vector3(-9999,-9999,-9999),n=new THREE.Vector3;for(let l in e){let e=t.atoms[l].coord;n.add(e),s.min(e),i.max(e)}let l=t.ParserUtilsCls.getGeoCenter(s,i);return{center:l,maxD:t.ParserUtilsCls.getStructureSize(e,s,i,l),pmin:s,pmax:i}}setWidthHeight(e,t){let s=this.icn3d;s.icn3dui,void 0===s.scaleFactor&&(s.scaleFactor=1),s.renderer.setSize(e*s.scaleFactor,t*s.scaleFactor),s.renderer.domElement.style.width=e*s.scaleFactor+"px",s.renderer.domElement.style.height=t*s.scaleFactor+"px",s.renderer.domElement.width=e*s.scaleFactor,s.renderer.domElement.height=t*s.scaleFactor,s.container.whratio=e/t}}class et{constructor(e){this.icn3d=e}applyClbondsOptions(e){let t=this.icn3d,s=t.icn3dui;if(void 0===e&&(e=t.opts),t.bCalcCrossLink||(t.clbondpnts={},t.clbondResid2serial={},this.applyClbondsOptions_base("chemical"),this.applyClbondsOptions_base("all"),t.bCalcCrossLink=!0),"yes"===e.clbonds.toLowerCase()&&"nothing"!==e.chemicals){let e="#006400";if(s.parasCls.thr(25600),t.lines.clbond=[],t.residuesHashClbonds={},t.structures){let i=Object.keys(t.structures);for(let n=0,l=i.length;n<l;++n){let l=i[n];if(t.clbondpnts[l])for(let i=0,n=t.clbondpnts[l].length;i<n;i+=2){let n=t.clbondpnts[l][i],r=t.clbondpnts[l][i+1],o={};if(o.color=e,o.dashed=!1,o.radius=t.crosslinkRadius,o.serial1=t.clbondResid2serial[n+","+r],o.serial2=t.clbondResid2serial[r+","+n],!t.dAtoms.hasOwnProperty(o.serial1)||!t.dAtoms.hasOwnProperty(o.serial2))continue;o.position1=t.atoms[o.serial1].coord,o.position2=t.atoms[o.serial2].coord,t.lines.clbond.push(o);let a={};a=s.hashUtilsCls.unionHash(a,t.residues[n]),a=s.hashUtilsCls.unionHash(a,t.residues[r]);let d=s.hashUtilsCls.intHash(a,t.sidec);for(let e in d)t.atoms[e].style2="stick";t.residuesHashClbonds[n]=1,t.residuesHashClbonds[r]=1}}}}return t.residuesHashClbonds}applyClbondsOptions_base(e){let t=this.icn3d;t.icn3dui;for(let s in t.chemicals){let i=t.atoms[s],n=i.structure+"_"+i.chain+"_"+i.resi;for(let s in i.bonds){let l=t.atoms[i.bonds[s]];if(void 0!==l&&(l.chain!==i.chain||l.resi!==i.resi)){let s=l.structure+"_"+l.chain+"_"+l.resi;if("chemical"!=e||l.het){if("chemical"==e)continue;void 0===t.clbondpnts[i.structure]&&(t.clbondpnts[i.structure]=[]),t.clbondpnts[i.structure].push(n),t.clbondpnts[l.structure].push(s),t.clbondResid2serial[n+","+s]=i.serial,t.clbondResid2serial[s+","+n]=l.serial}}}}}}class tt{constructor(e){this.icn3d=e}applyMissingResOptions(e){let t=this.icn3d;if(t.icn3dui,t.bCalcMissingRes||(t.missingResPnts={},t.missingResResid2serial={},this.applyMissingResOptions_base(),t.bCalcMissingRes=!0),t.lines.missingres=[],t.structures){let e=Object.keys(t.structures);for(let s=0,i=e.length;s<i;++s){let i=e[s];if(t.missingResPnts[i])for(let e=0,s=t.missingResPnts[i].length;e<s;e+=2){let s=t.missingResPnts[i][e],n=t.missingResPnts[i][e+1],l={dashed:!0};l.serial1=t.missingResResid2serial[s+","+n],l.serial2=t.missingResResid2serial[n+","+s],l.color="#"+t.atoms[l.serial1].color.getHexString(),l.radius=t.coilWidth,t.dAtoms.hasOwnProperty(l.serial1)&&t.dAtoms.hasOwnProperty(l.serial2)&&(l.position1=t.atoms[l.serial1].coord,l.position2=t.atoms[l.serial2].coord,t.lines.missingres.push(l))}}}}applyMissingResOptions_base(e){let t=this.icn3d;t.icn3dui;let s=[];for(let e in t.chainsSeq){let i,n,l,r,o=!1,a=!1;for(let d=0,c=t.chainsSeq[e].length;d<c;++d)n=e+"_"+t.chainsSeq[e][d].resi,t.residues.hasOwnProperty(n)?(o=!0,r=!0):r=!1,!r&&a?i=l:o&&i&&r&&!a&&(s.push(i),s.push(n),i=void 0),a=r,l=n}for(let e=0,i=s.length;e<i;e+=2){let i=s[e],n=s[e+1],l=i.substr(0,i.indexOf("_"));i.substr(0,n.indexOf("_"));let r=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[i]),o=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[n]);r&&o&&(void 0===t.missingResPnts[l]&&(t.missingResPnts[l]=[]),t.missingResPnts[l].push(i),t.missingResPnts[l].push(n),t.missingResResid2serial[i+","+n]=r.serial,t.missingResResid2serial[n+","+i]=o.serial)}}}class st{constructor(e){this.icn3d=e}applyDisplayOptions(e,t,s){let i=this.icn3d,n=i.icn3dui;if(!n.bNode&&""!=n.htmlCls.setHtmlCls.getCookie("lineRadius")){let e=parseFloat(n.htmlCls.setHtmlCls.getCookie("lineRadius")),t=parseFloat(n.htmlCls.setHtmlCls.getCookie("coilWidth")),s=parseFloat(n.htmlCls.setHtmlCls.getCookie("cylinderRadius")),l=n.htmlCls.setHtmlCls.getCookie("crosslinkRadius"),r=l&&!isNaN(l)?parseFloat(l):i.crosslinkRadius,o=parseFloat(n.htmlCls.setHtmlCls.getCookie("traceRadius")),a=parseFloat(n.htmlCls.setHtmlCls.getCookie("dotSphereScale")),d=parseFloat(n.htmlCls.setHtmlCls.getCookie("ribbonthickness")),c=parseFloat(n.htmlCls.setHtmlCls.getCookie("helixSheetWidth")),h=parseFloat(n.htmlCls.setHtmlCls.getCookie("nucleicAcidWidth"));i.bSetThicknessOnce||i.lineRadius==e&&i.coilWidth==t&&i.cylinderRadius==s&&i.crosslinkRadius==r&&i.traceRadius==o&&i.dotSphereScale==a&&i.ribbonthickness==d&&i.helixSheetWidth==c&&i.nucleicAcidWidth==h||(i.bSetThicknessOnce=!0,n.htmlCls.clickMenuCls.setLogCmd("set thickness | linerad "+e+" | coilrad "+t+" | stickrad "+s+" | crosslinkrad "+r+" | tracerad "+o+" | ribbonthick "+d+" | proteinwidth "+c+" | nucleotidewidth "+h+" | ballscale "+a,!0)),i.lineRadius=e,i.coilWidth=t,i.cylinderRadius=s,i.crosslinkRadius=r,i.traceRadius=o,i.dotSphereScale=a,i.ribbonthickness=d,i.helixSheetWidth=c,i.nucleicAcidWidth=h}let l,r={},o={},a={};if(1===s&&Object.keys(t).length<Object.keys(i.atoms).length){a=n.hashUtilsCls.hash2Atoms(t,i.atoms),r=i.firstAtomObjCls.getResiduesFromAtoms(t,i.atoms);for(let e in r){l=e;let t=e.lastIndexOf("_"),s=e.substr(0,t+1),i=e.substr(t+1);if(isNaN(i))continue;let n=parseInt(i),a=s+(n-1).toString();(n+1).toString(),r.hasOwnProperty(a)||r.hasOwnProperty(a)||(o[e]=1)}if(1===Object.keys(a).length&&Object.keys(i.residues[l]).length>1&&"sphere"!==a[Object.keys(a)[0]].style&&"dot"!==a[Object.keys(a)[0]].style){if(void 0===i.bCid||!i.bCid)for(let e in a){let t=a[e],n=1;i.boxCls.createBox(t,void 0,void 0,n,void 0,s)}}else for(let e in o){let l=i.firstAtomObjCls.getFirstCalphaAtomObj(i.residues[e]),r=l,o=r.structure+"_"+r.chain+"_"+(parseInt(r.resi)-1).toString(),a=r.structure+"_"+r.chain+"_"+(parseInt(r.resi)+1).toString();if("cylinder and plate"===r.style&&"helix"===r.ss)for(let t in i.residues[e]){let e=i.atoms[t],n=1;i.boxCls.createBox(e,void 0,void 0,n,void 0,s)}else if("ribbon"===r.style&&"coil"===r.ss||"strand"===r.style&&"coil"===r.ss||"o3 trace"===r.style||"schematic"===r.style||"c alpha trace"===r.style||"b factor tube"===r.style||"cylinder and plate"===r.style&&"helix"!==r.ss){if(void 0!==l&&void 0!==l.style2&&"nothing"!==l.style2)continue;let e=!1;if(!isNaN(r.resi)&&!e&&i.residues.hasOwnProperty(a)){let s=Object.keys(i.residues[a])[0],l=n.hashUtilsCls.hash2Atoms(i.residues[a],i.atoms)[s];if(r.style===l.style&&!l.ssbegin||l.ssbegin){let s=i.residues[a];if(t=n.hashUtilsCls.unionHash(t,s),e=!0,l.ssbegin)for(let e in s)i.atoms[e].notshow=!0}}if(!isNaN(r.resi)&&!e&&i.residues.hasOwnProperty(o)){let s=Object.keys(i.residues[o])[0],l=n.hashUtilsCls.hash2Atoms(i.residues[o],i.atoms)[s];r.style===l.style&&(t=n.hashUtilsCls.unionHash(t,i.residues[o]),e=!0)}}else if("ribbon"===r.style&&"coil"!==r.ss&&r.ssend||"strand"===r.style&&"coil"!==r.ss&&r.ssend){if(void 0!==l&&void 0!==l.style2&&"nothing"!==l.style2)continue;let e=!1;if(!isNaN(r.resi)&&!e&&i.residues.hasOwnProperty(a)){let s=Object.keys(i.residues[a])[0];n.hashUtilsCls.hash2Atoms(i.residues[a],i.atoms)[s],t=n.hashUtilsCls.unionHash(t,i.residues[a]),e=!0}}}a={}}if(i.bInitial){if(""!=n.htmlCls.setHtmlCls.getCookie("membrane")){let e=parseInt(n.htmlCls.setHtmlCls.getCookie("membrane"));i.bMembrane!=e&&n.htmlCls.clickMenuCls.setLogCmd("set membrane "+e,!0),i.bMembrane=isNaN(e)?0:parseInt(e)}i.bMembrane?i.selectionCls.toggleMembrane(!0):i.selectionCls.toggleMembrane(!1)}i.setStyleCls.setStyle2Atoms(t);let d=.5*i.cylinderRadius;void 0!==i.labels&&delete i.labels.schematic;for(let e in i.style2atoms){let t=i.style2atoms[e],l=n.hashUtilsCls.intHash(t,i.nucleotides),r=n.utilsCls.isCalphaPhosOnly(n.hashUtilsCls.hash2Atoms(l,i.atoms));if("ribbon"===e)i.strandCls.createStrand(n.hashUtilsCls.hash2Atoms(t,i.atoms),2,void 0,!0,void 0,void 0,!1,i.ribbonthickness,s);else if("strand"===e)i.strandCls.createStrand(n.hashUtilsCls.hash2Atoms(t,i.atoms),null,null,null,null,null,!1,void 0,s);else if("cylinder and plate"===e)i.cylinderCls.createCylinderHelix(n.hashUtilsCls.hash2Atoms(t,i.atoms),i.cylinderHelixRadius,s);else if("nucleotide cartoon"===e)r?i.cylinderCls.createCylinderCurve(n.hashUtilsCls.hash2Atoms(t,i.atoms),["P"],i.traceRadius,!1,s):(i.cartoonNuclCls.drawCartoonNucleicAcid(n.hashUtilsCls.hash2Atoms(t,i.atoms),null,i.ribbonthickness,s),2!==s&&i.cartoonNuclCls.drawNucleicAcidStick(n.hashUtilsCls.hash2Atoms(t,i.atoms),s));else if("o3 trace"===e)r?i.cylinderCls.createCylinderCurve(n.hashUtilsCls.hash2Atoms(t,i.atoms),["P"],i.traceRadius,!1,s):i.cylinderCls.createCylinderCurve(n.hashUtilsCls.hash2Atoms(t,i.atoms),["O3'","O3*"],i.traceRadius,!1,s);else if("schematic"===e){let e=i.firstAtomObjCls.getFirstAtomObj(t);if(i.chemicals.hasOwnProperty(e.serial)){i.residueLabelsCls.addNonCarbonAtomLabels(n.hashUtilsCls.hash2Atoms(t,i.atoms));let e=!0;i.stickCls.createStickRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),d,d,void 0,s,e)}else i.residueLabelsCls.addResidueLabels(n.hashUtilsCls.hash2Atoms(t,i.atoms),!0),r?i.cylinderCls.createCylinderCurve(n.hashUtilsCls.hash2Atoms(t,i.atoms),["P"],i.traceRadius,!1,s):i.cylinderCls.createCylinderCurve(n.hashUtilsCls.hash2Atoms(t,i.atoms),["O3'","O3*"],i.traceRadius,!1,s),i.cylinderCls.createCylinderCurve(n.hashUtilsCls.hash2Atoms(t,i.atoms),["CA"],i.traceRadius,!1,s)}else"c alpha trace"===e?i.cylinderCls.createCylinderCurve(n.hashUtilsCls.hash2Atoms(t,i.atoms),["CA"],i.traceRadius,!1,s):"b factor tube"===e?i.tubeCls.createTube(n.hashUtilsCls.hash2Atoms(t,i.atoms),"CA",null,s,!1,!0):"custom tube"===e?i.tubeCls.createTube(n.hashUtilsCls.hash2Atoms(t,i.atoms),"CA",null,s,!0,!0):"lines"===e||"lines2"===e?(1===s?i.stickCls.createStickRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),i.hlLineRadius,i.hlLineRadius,void 0,s):i.lineCls.createLineRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),s),i.lineCls.createConnCalphSidechain(n.hashUtilsCls.hash2Atoms(t,i.atoms),e)):"stick"===e||"stick2"===e?(i.stickCls.createStickRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),i.cylinderRadius,i.cylinderRadius,void 0,s,void 0),i.lineCls.createConnCalphSidechain(n.hashUtilsCls.hash2Atoms(t,i.atoms),e)):"backbone"===e?(t=this.selectMainChainSubset(t),i.stickCls.createStickRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),i.cylinderRadius,i.cylinderRadius,void 0,s,void 0)):"ball and stick"===e||"ball and stick2"===e?(i.stickCls.createStickRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),i.cylinderRadius,.5*i.cylinderRadius,i.dotSphereScale,s,void 0),i.lineCls.createConnCalphSidechain(n.hashUtilsCls.hash2Atoms(t,i.atoms),e)):"sphere"===e||"sphere2"===e?i.sphereCls.createSphereRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),i.sphereRadius,void 0,void 0,s):"dot"===e&&i.sphereCls.createSphereRepresentation(n.hashUtilsCls.hash2Atoms(t,i.atoms),i.sphereRadius,!1,i.dotSphereScale,s)}if(i.cnt>i.maxmaxatomcnt&&i.init_base(),void 0!==i.labels&&Object.keys(i.labels).length>0){i.labelCls.hideLabels();for(let e in i.labels)"schematic"!=e&&this.changeLabelColor(i.labels[e]);i.labelCls.createLabelRepresentation(i.labels)}}changeLabelColor(e){let t=this.icn3d;if(t.icn3dui,e)for(let s=0,i=e.length;s<i;++s){let i=e[s];"black"!=t.opts.background&&i.color==t.colorBlackbkgd?i.color=t.colorWhitebkgd:"black"==t.opts.background&&i.color==t.colorWhitebkgd&&(i.color=t.colorBlackbkgd)}}selectMainChainSubset(e){let t=this.icn3d;t.icn3dui;let s=["C1'","C1*","C2'","C2*","C3'","C3*","C4'","C4*","C5'","C5*","O3'","O3*","O4'","O4*","O5'","O5*","P","OP1","O1P","OP2","O2P"],i={};for(let n in e)(t.proteins.hasOwnProperty(n)&&("N"===t.atoms[n].name||"C"===t.atoms[n].name||"O"===t.atoms[n].name||"CA"===t.atoms[n].name&&"C"===t.atoms[n].elem)||t.nucleotides.hasOwnProperty(n)&&-1!==s.indexOf(t.atoms[n].name))&&(i[n]=1);return i}}class it{constructor(e){this.icn3d=e}applyOtherOptions(e){let t=this.icn3d,s=t.icn3dui;if(void 0===e&&(e=t.opts),t.hBondCls.setHbondsContacts(e,"contact"),t.hBondCls.setHbondsContacts(e,"halogen"),t.hBondCls.setHbondsContacts(e,"pi-cation"),t.hBondCls.setHbondsContacts(e,"pi-stacking"),t.hBondCls.setHbondsContacts(e,"hbond"),t.hBondCls.setHbondsContacts(e,"saltbridge"),void 0!==t.pairArray&&t.pairArray.length>0){this.updateStabilizer();let e="#FFFFFF",s=t.stabilizerpnts;t.lines.stabilizer=[];for(let i=0,n=Math.floor(s.length/2);i<n;i++){let n={};n.position1=s[2*i],n.position2=s[2*i+1],n.color=e,n.dashed=!1,t.lines.stabilizer.push(n)}}if(t.lineCls.createLines(t.lines),t.distPnts&&t.distPnts.length>0)for(let e=0,s=t.distPnts.length;e<s;++e)t.boxCls.createBox_base(t.distPnts[e],t.originSize,t.hColor,!1);if(void 0!==t.prevMaps)for(let e=0,s=t.prevMaps.length;e<s;++e)t.mdl.add(t.prevMaps[e]);if(void 0!==t.prevEmmaps)for(let e=0,s=t.prevEmmaps.length;e<s;++e)t.mdl.add(t.prevEmmaps[e]);if(void 0!==t.prevPhimaps)for(let e=0,s=t.prevPhimaps.length;e<s;++e)t.mdl.add(t.prevPhimaps[e]);if(void 0!==t.prevSurfaces)for(let e=0,s=t.prevSurfaces.length;e<s;++e)t.mdl.add(t.prevSurfaces[e]);if(void 0!==t.symmetryHash&&void 0!==t.symmetrytitle&&t.applySymdCls.applySymmetry(t.symmetrytitle),void 0!==t.symdArray&&t.symdArray.length>0&&t.applySymdCls.applySymd(),void 0!==t.prevOtherMesh)for(let e=0,s=t.prevOtherMesh.length;e<s;++e)t.mdl.add(t.prevOtherMesh[e]);if(t.bInitial&&""!=s.htmlCls.setHtmlCls.getCookie("glycan")){let e=parseInt(s.htmlCls.setHtmlCls.getCookie("glycan"));t.bGlycansCartoon!=e&&s.htmlCls.clickMenuCls.setLogCmd("set glycan "+e,!0),t.bGlycansCartoon=e}t.bGlycansCartoon&&!t.bAlternate&&t.glycanCls.showGlycans();for(let e in t.shapeCmdHash)"add cube"==e.substr(0,8)?t.applyCommandCls.addShape(e,"cube"):t.applyCommandCls.addShape(e,"sphere");switch(t.applyCenterCls.applyCenterOptions(e),t.axesCls.buildAllAxes(void 0,!0),e.axis.toLowerCase()){case"yes":t.axis=!0,t.axesCls.buildAxes(t.maxD/2);break;case"no":t.axis=!1}switch(e.pk.toLowerCase()){case"atom":t.pk=1;break;case"no":t.pk=0;break;case"residue":t.pk=2;break;case"strand":t.pk=3}}applyChemicalbindingOptions(e){let t=this.icn3d,s=t.icn3dui;if(void 0===e&&(e=t.opts),"show"===e.chemicalbinding){let e;void 0!==t.chemicals&&Object.keys(t.chemicals).length>0&&(e=s.hashUtilsCls.hash2Atoms(t.chemicals,t.atoms));let i=4;if(void 0!==e){let n=t.contactCls.getAtomsWithinAtom(t.atoms,e,i),l=3.5;t.opts.hbonds="yes",Object.keys(n).length>0&&t.hBondCls.calculateChemicalHbonds(e,n,parseFloat(l)),t.bSetFog||t.transformCls.zoominSelection(s.hashUtilsCls.unionHash(e,n))}}else"hide"===e.chemicalbinding&&(t.hBondCls.hideHbonds(),t.showInterCls.hideExtraBonds(),t.bSetFog||t.transformCls.zoominSelection(t.atoms))}updateStabilizer(){let e=this.icn3d;if(e.icn3dui,e.stabilizerpnts=[],void 0!==e.pairArray)for(let t=0,s=e.pairArray.length;t<s;t+=2){let s=this.getResidueRepPos(e.pairArray[t]),i=this.getResidueRepPos(e.pairArray[t+1]);e.stabilizerpnts.push(s),e.stabilizerpnts.push(i)}}getResidueRepPos(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("N3"===i.name){s=t.atoms[e].coord;break}if("CA"===i.name&&"coil"==i.ss){s=t.atoms[e].coord;break}if("CA"===i.name&&("helix"==i.ss||"sheet"==i.ss)){s=void 0!==t.atoms[e].coord2?t.atoms[e].coord2:t.atoms[e].coord;break}}else s=i.coord;return void 0===s&&(s=i.coord),s}}class nt{constructor(e){this.icn3d=e}applySsbondsOptions(e){let t=this.icn3d,s=t.icn3dui;if(void 0===e&&(e=t.opts),"yes"===e.ssbonds.toLowerCase()&&void 0!==t.ssbondpnts){let e,i,n="#FFFF00",l=s.parasCls.thr(16776960),r=Object.keys(t.structures);if(t.bAlternate){let s=r.length;e=t.ALTERNATE_STRUCTURE%s,i=t.ALTERNATE_STRUCTURE%s+1}else e=0,i=r.length;t.lines.ssbond=[];for(let o=e,a=i;o<a;++o){let e=r[o];if(t.ssbondpnts[e])for(let i=Math.floor(t.ssbondpnts[e].length/2)-1;i>=0;i--){let r=t.ssbondpnts[e][2*i],o=t.ssbondpnts[e][2*i+1],a={};a.color=n,a.dashed=!1;let d=[],c=[],h=[],p=[],m=!1,u=!1;for(let e in t.residues[r])"SG"===t.atoms[e].name&&(h.push(t.atoms[e].coord),d.push(t.atoms[e].serial),m=!0);if(!m)for(let e in t.residues[r])if("CA"===t.atoms[e].name){h.push(t.atoms[e].coord),d.push(t.atoms[e].serial),m=!0,u=!0;break}m=!1;for(let e in t.residues[o])"SG"===t.atoms[e].name&&(p.push(t.atoms[e].coord),c.push(t.atoms[e].serial),m=!0);if(!m)for(let e in t.residues[o])if("CA"===t.atoms[e].name){p.push(t.atoms[e].coord),c.push(t.atoms[e].serial),m=!0,u=!0;break}let g=u?7:3,f=!1;for(let e=0,t=h.length;e<t;++e)for(let t=0,s=p.length;t<s;++t)if(h[e].distanceTo(p[t])<g){f=!0,a.serial1=d[e],a.position1=h[e],a.serial2=c[t],a.position2=p[t];break}if(void 0!==a.serial1&&void 0!==a.serial2&&!t.dAtoms.hasOwnProperty(a.serial1)&&!t.dAtoms.hasOwnProperty(a.serial2))continue;if(!f){t.ssbondpnts[e].splice(2*i,2);continue}let C,b,y,v=t.atoms[a.serial1].bonds.indexOf(a.serial2);-1!=v&&(C=t.atoms[a.serial1].bonds.slice(0,v),b=t.atoms[a.serial1].bonds.slice(v+1),t.atoms[a.serial1].bonds=C.concat(b)),v=t.atoms[a.serial2].bonds.indexOf(a.serial1),-1!=v&&(C=t.atoms[a.serial2].bonds.slice(0,v),b=t.atoms[a.serial2].bonds.slice(v+1),t.atoms[a.serial2].bonds=C.concat(b)),t.lines.ssbond.push(a),y=s.hashUtilsCls.unionHash(y,t.residues[r]),y=s.hashUtilsCls.unionHash(y,t.residues[o]);let _=t.firstAtomObjCls.getFirstAtomObj(y),w="lines"==_.style?"lines":"stick";"lines"!=_.style&&t.cylinderCls.createCylinder(a.position1,a.position2,t.cylinderRadius,l);let S=s.hashUtilsCls.intHash(y,t.sidec);for(let e in S)t.atoms[e].style2=w}}}}}class lt{constructor(e){this.icn3d=e}applySymd(){let e=this.icn3d;e.icn3dui;for(let t=0,s=e.symdArray.length;t<s;++t){let s=e.symdArray[t],i=Object.keys(s)[0];this.applySymmetry(i,!0,s[i])}}applySymmetry(e,t,s){let i=this.icn3d,n=i.icn3dui,l=t?s:i.symmetryHash[e];l||(l=[]);let r=e.substr(0,1),o=parseInt(e.substring(1,e.indexOf(" "))),a=1.5*i.cylinderRadius,d=1*i.cylinderRadius,c=[];for(let e=0,s=l.length;e<s;++e){let s=l[e][0],h=l[e][1],p=l[e][2],m=l[e][3],u=l[e][4],g=l[e][5];if(i.cylinderCls.createCylinder(s,h,a,p,0),!i.bAxisOnly)if("C"==r||"D"==r&&u==o){let e={};Object.keys(i.chains).length;let l=!1,r={};if(t&&Object.keys(i.hAtoms).length<Object.keys(i.atoms).length){for(let e in i.hAtoms){let t=i.atoms[e];r[t.structure+"_"+t.chain]=1}Object.keys(r).length>1&&(l=!0)}if(t)if(l){let t=Object.keys(r)[0];e=i.chains[t]}else{0==Object.keys(i.hAtoms).length&&(i.hAtoms=n.hashUtilsCls.cloneHash(i.dAtoms));let t,s=parseInt(Object.keys(i.hAtoms).length/u),l=0;for(let n in i.hAtoms)if(e[n]=1,t=n,++l,l>s)break;let r=i.atoms[t].structure+"_"+i.atoms[t].chain+"_"+i.atoms[t].resi;e=n.hashUtilsCls.unionHash(e,i.residues[r])}else{let t=Object.keys(i.structures)[0]+"_"+g;if(i.chains.hasOwnProperty(t)||(t=Object.keys(i.structures)[0]+"_"+g.toLowerCase()),!i.chains.hasOwnProperty(t)){t=Object.keys(i.chains)[0];for(let e in i.chains){let s=Object.keys(i.chains[e])[0];if(i.proteins.hasOwnProperty(s)){t=e;break}}}e=i.chains[t]}let a=s.clone().add(h).multiplyScalar(.5),c=new THREE.Vector3,p=0,f=h.clone().sub(s).normalize(),C=new THREE.Vector3(0,0,1),b=new THREE.Quaternion;b.setFromUnitVectors(f,C);let y=-9999;for(let t in e){let e=i.atoms[t].coord.clone();c.add(e),e.sub(a).applyQuaternion(b);let s=e.x*e.x+e.y*e.y;s>y&&(y=s),++p}let v=i.ParserUtilsCls.getMassCenter(c,p),_=new THREE.Line3(s,h),w=new THREE.Vector3;_.closestPointToPoint(v,!0,w);let S,A,x,k,O=Math.sqrt(y),R=v.clone().sub(w).normalize().multiplyScalar(O),I=a.clone().add(s.clone().sub(a).multiplyScalar(.83)).add(R),E=a.clone().add(h.clone().sub(a).multiplyScalar(.83)).add(R),T=2*Math.PI/o;for(let e=0;e<o;++e){let t=(.5+e)*T,n=I.clone().sub(s);n.applyAxisAngle(f,t).add(s);let l=E.clone().sub(s);l.applyAxisAngle(f,t).add(s),i.cylinderCls.createCylinder(n,l,d,m,0),i.sphereCls.createSphereBase(n,m,d,1,0),i.sphereCls.createSphereBase(l,m,d,1,0),0==e?(S=n,A=l):(i.cylinderCls.createCylinder(n,x,d,m,0),i.cylinderCls.createCylinder(l,k,d,m,0)),x=n,k=l}S&&x&&i.cylinderCls.createCylinder(S,x,d,m,0),A&&k&&i.cylinderCls.createCylinder(A,k,d,m,0)}else("T"==r&&3==u||"O"==r&&4==u||"I"==r&&5==u)&&(c.push(s),c.push(h))}if("T"==r){let e=c[0];i.sphereCls.createSphereBase(e,colorPolygon,d,1,0);let t,s,n,l=e.distanceTo(c[2]),r=e.distanceTo(c[3]);l<r?(t=l,s=c[3]):(t=r,s=c[2]),i.sphereCls.createSphereBase(s,colorPolygon,d,1,0),i.cylinderCls.createCylinder(e,s,d,colorPolygon,0);for(let l=4,r=c.length;l<r;++l){let r=c[l];e.distanceTo(r)>t&&(i.sphereCls.createSphereBase(r,colorPolygon,d,1,0),i.cylinderCls.createCylinder(e,r,d,colorPolygon,0),i.cylinderCls.createCylinder(s,r,d,colorPolygon,0),void 0!==n&&i.cylinderCls.createCylinder(c[n],r,d,colorPolygon,0),n=l)}}else if("O"==r)for(let e=0,t=c.length;e<t;e+=2){let t=c[e],s=c[e+1];i.sphereCls.createSphereBase(t,colorPolygon,d,1,0),i.sphereCls.createSphereBase(s,colorPolygon,d,1,0);for(let n=e+2,l=c.length;n<l;++n){let e=c[n];i.sphereCls.createSphereBase(e,colorPolygon,d,1,0),i.cylinderCls.createCylinder(t,e,d,colorPolygon,0),i.cylinderCls.createCylinder(s,e,d,colorPolygon,0)}}else if("I"==r)for(let e=0,t=c.length;e<t;e+=2){let t=c[e],s=c[e+1];i.sphereCls.createSphereBase(t,colorPolygon,d,1,0),i.sphereCls.createSphereBase(s,colorPolygon,d,1,0);for(let n=e+2,l=c.length;n<l;n+=2){let e,l,r=c[n],o=c[n+1];t.distanceTo(r)<t.distanceTo(o)?(e=r,l=o):(e=o,l=r),i.sphereCls.createSphereBase(e,colorPolygon,d,1,0),i.sphereCls.createSphereBase(l,colorPolygon,d,1,0),i.cylinderCls.createCylinder(t,e,d,colorPolygon,0),i.cylinderCls.createCylinder(s,l,d,colorPolygon,0)}}}}class rt{constructor(e){this.icn3d=e}applySurfaceOptions(e){let t,s,i=this.icn3d,n=i.icn3dui;switch(void 0===e&&(e=i.opts),e.wireframe){case"yes":e.wireframe=!0;break;case"no":e.wireframe=!1}switch(e.opacity=parseFloat(e.opacity),t=n.hashUtilsCls.intHash(i.dAtoms,i.hAtoms),"nothing"===e.water&&(t=n.hashUtilsCls.exclHash(t,i.water)),s=n.hashUtilsCls.hash2Atoms(t,i.atoms),e.surface.toLowerCase()){case"van der waals surface":case"van der waals surface with context":i.surfaceCls.createSurfaceRepresentation(s,1,e.wireframe,e.opacity);break;case"solvent accessible surface":case"solvent accessible surface with context":i.surfaceCls.createSurfaceRepresentation(s,3,e.wireframe,e.opacity);break;case"molecular surface":case"molecular surface with context":i.surfaceCls.createSurfaceRepresentation(s,2,e.wireframe,e.opacity);break;case"nothing":this.removeSurfaces()}}applyMapOptions(e){let t,s,i=this.icn3d,n=i.icn3dui;switch(void 0===e&&(e=i.opts),e.mapwireframe){case"yes":e.mapwireframe=!0;break;case"no":e.mapwireframe=!1}switch(t=n.hashUtilsCls.intHash(i.dAtoms,i.hAtoms),s=n.hashUtilsCls.hash2Atoms(t,i.atoms),e.map.toLowerCase()){case"2fofc":i.surfaceCls.createSurfaceRepresentation(s,11,e.mapwireframe);break;case"fofc":i.surfaceCls.createSurfaceRepresentation(s,12,e.mapwireframe);break;case"nothing":this.removeMaps()}}applyEmmapOptions(e){let t,s,i=this.icn3d,n=i.icn3dui;switch(void 0===e&&(e=i.opts),e.emmapwireframe){case"yes":e.emmapwireframe=!0;break;case"no":e.emmapwireframe=!1}switch(t=n.hashUtilsCls.intHash(i.dAtoms,i.hAtoms),s=n.hashUtilsCls.hash2Atoms(t,i.atoms),e.emmap.toLowerCase()){case"em":i.surfaceCls.createSurfaceRepresentation(s,13,e.emmapwireframe);break;case"nothing":this.removeEmmaps()}}applyPhimapOptions(e){let t,s,i=this.icn3d,n=i.icn3dui;switch(void 0===e&&(e=i.opts),e.phimapwireframe){case"yes":e.phimapwireframe=!0;break;case"no":e.phimapwireframe=!1}switch(t=n.hashUtilsCls.intHash(i.dAtoms,i.hAtoms),s=n.hashUtilsCls.hash2Atoms(t,i.atoms),e.phimap.toLowerCase()){case"phi":i.surfaceCls.createSurfaceRepresentation(s,14,e.phimapwireframe);break;case"nothing":this.removePhimaps()}}applyphisurfaceOptions(e){let t,s,i=this.icn3d,n=i.icn3dui;switch(void 0===e&&(e=i.opts),i.phisurfwf){case"yes":e.phisurfwf=!0;break;case"no":e.phisurfwf=!1}switch(e.phisurfop=parseFloat(i.phisurfop),t=n.hashUtilsCls.intHash(i.dAtoms,i.hAtoms),"nothing"===e.water&&(t=n.hashUtilsCls.exclHash(t,i.water)),s=n.hashUtilsCls.hash2Atoms(t,i.atoms),e.phisurface.toLowerCase()){case"phi":i.surfaceCls.createSurfaceRepresentation(s,parseInt(i.phisurftype),e.phisurfwf,e.phisurfop);break;case"nothing":this.removeSurfaces()}}removeSurfaces(){let e=this.icn3d;e.icn3dui;for(let t=0,s=e.prevSurfaces.length;t<s;++t)e.mdl.remove(e.prevSurfaces[t]);e.prevSurfaces=[]}removeLastSurface(){let e=this.icn3d;e.icn3dui,e.prevSurfaces.length>0&&(e.mdl.remove(e.prevSurfaces[e.prevSurfaces.length-1]),e.prevSurfaces.slice(e.prevSurfaces.length-1,1))}removeMaps(){let e=this.icn3d;e.icn3dui;for(let t=0,s=e.prevMaps.length;t<s;++t)e.mdl.remove(e.prevMaps[t]);e.prevMaps=[]}removeEmmaps(){let e=this.icn3d;e.icn3dui;for(let t=0,s=e.prevEmmaps.length;t<s;++t)e.mdl.remove(e.prevEmmaps[t]);e.prevEmmaps=[]}removePhimaps(){let e=this.icn3d;e.icn3dui;for(let t=0,s=e.prevPhimaps.length;t<s;++t)e.mdl.remove(e.prevPhimaps[t]);e.prevPhimaps=[]}removeLastMap(){let e=this.icn3d;e.icn3dui,e.prevMaps.length>0&&(e.mdl.remove(e.prevMaps[e.prevMaps.length-1]),e.prevMaps.slice(e.prevMaps.length-1,1))}removeLastEmmap(){let e=this.icn3d;e.icn3dui,e.prevEmmaps.length>0&&(e.mdl.remove(e.prevEmmaps[e.prevEmmaps.length-1]),e.prevEmmaps.slice(e.prevEmmaps.length-1,1))}removeLastPhimap(){let e=this.icn3d;e.icn3dui,e.prevPhimaps.length>0&&(e.mdl.remove(e.prevPhimaps[e.prevPhimaps.length-1]),e.prevPhimaps.slice(e.prevPhimaps.length-1,1))}}class ot{constructor(e){this.icn3d=e}addResidueLabels(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui;if(r.bNode)return;let o=r.hashUtilsCls.intHash(l.hAtoms,e);t?void 0===l.labels.schematic&&(l.labels.schematic=[]):void 0===l.labels.residue&&(l.labels.residue=[]);let a="";for(let e in o){let s=l.atoms[e],o={},d=s.structure+"_"+s.chain+"_"+s.resi;if(!s.het&&("CA"===s.name||"O3'"===s.name||"O3*"===s.name)||l.water.hasOwnProperty(s.serial)||l.ions.hasOwnProperty(s.serial)||l.chemicals.hasOwnProperty(s.serial)&&d!==a){if(o.position=s.coord,o.bSchematic=0,t&&(o.bSchematic=1),o.text=r.utilsCls.residueName2Abbr(s.resn),i)o.text+=s.resi;else if(n){let e=s.structure+"_"+s.chain+"_"+s.resi,t="";l.resid2refnum[e]&&(t=" "==l.resid2refnum[e].substr(0,1)?"":l.resid2refnum[e]),o.text=t}o.size=18,o.factor=.3;let e=s.color.getHexString().toUpperCase();o.color=i?"black"!=l.opts.background?l.colorWhitebkgd:l.colorBlackbkgd:n?"#00FFFF":"CCCCCC"===e||"C8C8C8"===e?"#888888":"#"+e,o.background="#FFFFFF",t?l.labels.schematic.push(o):l.labels.residue.push(o)}a=d}l.hlObjectsCls.removeHlObjects()}addNonCarbonAtomLabels(e){let t=this.icn3d,s=t.icn3dui;if(s.bNode)return;let i=s.hashUtilsCls.intHash(t.hAtoms,e);void 0===t.labels.schematic&&(t.labels.schematic=[]);for(let e in i){let s=t.atoms[e];if(!t.residues.hasOwnProperty(s.structure+"_"+s.chain+"_"+s.resi))continue;if("C"===s.elem)continue;let i={};i.position=s.coord,i.bSchematic=1,i.text=s.elem,i.size=18,i.color="black"!=t.opts.background?t.colorWhitebkgd:s.color.getHexString(),i.background="#FFFFFF",t.labels.schematic.push(i)}t.hlObjectsCls.removeHlObjects()}addAtomLabels(e,t){let s=this.icn3d,i=s.icn3dui;if(i.bNode)return;let n=i.hashUtilsCls.intHash(s.hAtoms,e);n=i.hashUtilsCls.intHash(s.dAtoms,n),void 0===s.labels.residue&&(s.labels.residue=[]);for(let e in n){let i=s.atoms[e],n={};n.position=i.coord,n.bSchematic=0,n.text=t?i.elem:i.name.padEnd(2," "),n.size=18,t&&(n.bSchematic=!0);let l=i.color.getHexString().toUpperCase();n.color="black"!=s.opts.background?s.colorWhitebkgd:s.colorBlackbkgd,t&&(n.color="CCCCCC"===l||"C8C8C8"===l?"#888888":"#"+l),n.background="#FFFFFF",s.labels.residue.push(n)}s.hlObjectsCls.removeHlObjects()}}class at{constructor(e){this.icn3d=e}onBeforeRender(e,t,s,i,n,l){let r=n.uniforms,o=[];if(r.objectId&&(r.objectId.value=SupportsReadPixelsFloat?this.id:this.id/255,o.push("objectId")),(r.modelViewMatrixInverse||r.modelViewMatrixInverseTranspose||r.modelViewProjectionMatrix||r.modelViewProjectionMatrixInverse)&&this.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,this.matrixWorld),r.modelViewMatrixInverse&&(r.modelViewMatrixInverse.value.copy(this.modelViewMatrix).invert(),o.push("modelViewMatrixInverse")),r.modelViewMatrixInverseTranspose&&(r.modelViewMatrixInverse?r.modelViewMatrixInverseTranspose.value.copy(r.modelViewMatrixInverse.value).transpose():r.modelViewMatrixInverseTranspose.value.copy(this.modelViewMatrix).invert().transpose(),o.push("modelViewMatrixInverseTranspose")),r.modelViewProjectionMatrix&&(s.updateProjectionMatrix(),r.modelViewProjectionMatrix.value.multiplyMatrices(s.projectionMatrix,this.modelViewMatrix),o.push("modelViewProjectionMatrix")),r.modelViewProjectionMatrixInverse){let e=new THREE.Matrix4;r.modelViewProjectionMatrix?(e.copy(r.modelViewProjectionMatrix.value),r.modelViewProjectionMatrixInverse.value.copy(e).invert()):(s.updateProjectionMatrix(),e.multiplyMatrices(s.projectionMatrix,this.modelViewMatrix),r.modelViewProjectionMatrixInverse.value.copy(e).invert()),o.push("modelViewProjectionMatrixInverse")}if(r.projectionMatrix&&(s.updateProjectionMatrix(),r.projectionMatrix.value.copy(s.projectionMatrix),o.push("projectionMatrix")),r.projectionMatrixInverse&&(s.updateProjectionMatrix(),r.projectionMatrixInverse.value.copy(s.projectionMatrix).invert(),o.push("projectionMatrixInverse")),o.length){let t=e.properties.get(n);if(t.program){let s=e.getContext(),i=t.program;s.useProgram(i.program);let n=i.getUniforms();o.forEach((function(e){n.setValue(s,e,r[e].value)}))}}}setParametersForShader(e){let t,s=this.icn3d,i=s.icn3dui.parasCls.backgroundColors[s.opts.background.toLowerCase()],n=2.5*s.maxD,l=4*s.maxD,r=void 0!==s.biomtMatrices&&s.biomtMatrices.length*s.cnt>s.maxatomcnt;"yes"===s.opts.slab?r?t=.1:void 0!==s.camMaxDFactorFog?(t=s.maxD*s.camMaxDFactorFog-10,n=2.5*s.maxD-t<0?0:2.5*s.maxD-t,l=4*s.maxD-t):t=s.maxD*s.camMaxDFactor:t=.1;let o=void 0!==e?e:1,a=s.shininess/100*.5;s.uniforms=THREE.UniformsUtils.merge([THREE.UniformsLib.common,{modelViewMatrix:{value:new THREE.Matrix4},modelViewMatrixInverse:{value:new THREE.Matrix4},modelViewMatrixInverseTranspose:{value:new THREE.Matrix4},modelViewProjectionMatrix:{value:new THREE.Matrix4},modelViewProjectionMatrixInverse:{value:new THREE.Matrix4},projectionMatrix:{value:new THREE.Matrix4},projectionMatrixInverse:{value:new THREE.Matrix4},diffuse:{type:"v3",value:[1,1,1]},emissive:{type:"v3",value:[.06,.06,.06]},roughness:{type:"f",value:.5},metalness:{type:"f",value:a},opacity:{type:"f",value:o},nearClip:{type:"f",value:t},ortho:{type:"f",value:0},shrink:{type:"f",value:.13},fogColor:{type:"v3",value:[i.r,i.g,i.b]},fogNear:{type:"f",value:n},fogFar:{type:"f",value:l},fogDensity:{type:"f",value:2}},THREE.UniformsLib.ambient,THREE.UniformsLib.lights]),s.defines={USE_COLOR:1,NEAR_CLIP:1,CAP:1},"yes"!==s.opts.fog||r||(s.defines.USE_FOG=1,"orthographic"===s.opts.camera&&(s.defines.FOG_EXP2=1)),s.bExtFragDepth&&(s.defines.USE_LOGDEPTHBUF_EXT=1)}drawImpostorShader(){this.icn3d.icn3dui.bNode||(this.setParametersForShader(),this.createImpostorShaderSphere("SphereImpostor"),this.createImpostorShaderCylinder("CylinderImpostor"))}getShader(e){this.icn3d.icn3dui;let t=$NGL_shaderTextHash[e];return t=t.replace(/#include\s+(\S+)/gim,(function(e,t){let s;return THREE.ShaderChunk.hasOwnProperty(t)&&(s=THREE.ShaderChunk[t]),s||""})),t}createImpostorShaderBase(e,t,s,i,n,l,r,o,a){let d=this.icn3d;d.icn3dui;let c=new THREE.ShaderMaterial({defines:d.defines,uniforms:d.uniforms,vertexShader:this.getShader(e+".vert"),fragmentShader:this.getShader(e+".frag"),depthTest:!0,depthWrite:!0,lights:!0});c.extensions.fragDepth=!0,"CylinderImpostor"==e?d.CylinderImpostorMaterial=c:"SphereImpostor"==e&&(d.SphereImpostorMaterial=c);let h,p,m=l*r,u=l*o,g=new(m>65535?Uint32Array:Uint16Array)(u);for(let e=0;e<l;e++){h=e*o,p=e*r,g.set(s,h);for(let e=0;e<o;++e)g[h+e]+=p}let f=new THREE.BufferGeometry;g&&(f.setIndex(new THREE.BufferAttribute(g,1)),f.getIndex().setUsage(THREE.DynamicDrawUsage));let C={f:1,v2:2,v3:3,c:3};for(let e in n){let t,s=n[e];t=new Float32Array(m*C[s.type]),f.setAttribute(e,new THREE.BufferAttribute(t,C[s.type]).setUsage(THREE.DynamicDrawUsage))}let b,y,v,_,w,S,A=f.attributes;for(let e in i){y=i[e],b=A[e],v=b.itemSize,_=b.array;for(let e=0;e<l;++e){u=e*v,w=u*r;for(let e=0;e<r;++e){S=w+v*e;for(let e=0;e<v;++e)_[S+e]=y[u+e]}}b.needsUpdate=!0}let x=f.attributes.mapping.array;for(let e=0;e<l;e++)x.set(t,e*a*r);let k=new THREE.Mesh(f,c);k.frustumCulled=!1,k.scale.x=k.scale.y=k.scale.z=1,"CylinderImpostor"==e?k.type="Cylinder":"SphereImpostor"==e&&(k.type="Sphere"),k.onBeforeRender=this.onBeforeRender,d.mdlImpostor.add(k)}createImpostorShaderCylinder(e){let t=this.icn3d;t.icn3dui;let s=new Float32Array(t.posArray),i=new Float32Array(t.colorArray),n=new Float32Array(t.pos2Array),l=new Float32Array(t.color2Array),r=new Float32Array(t.radiusArray),o=new Float32Array([-1,1,-1,-1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,-1,1]),a=new Uint16Array([0,1,2,1,4,2,2,4,3,4,5,3]),d=s.length/3,c={position1:s,color:i,position2:n,color2:l,radius:r},h={position1:{type:"v3",value:null},color:{type:"v3",value:null},position2:{type:"v3",value:null},color2:{type:"v3",value:null},radius:{type:"f",value:null},mapping:{type:"v3",value:null}};this.createImpostorShaderBase(e,o,a,c,h,d,6,12,3),c=null,s=null,i=null,n=null,l=null,r=null,t.posArray=[],t.colorArray=[],t.pos2Array=[],t.color2Array=[],t.radiusArray=[]}createImpostorShaderSphere(e){let t=this.icn3d;t.icn3dui;let s=new Float32Array(t.posArraySphere),i=new Float32Array(t.colorArraySphere),n=new Float32Array(t.radiusArraySphere),l=new Float32Array([-1,1,-1,-1,1,1,1,-1]),r=new Uint16Array([0,1,2,1,3,2]),o=s.length/3,a={position:s,color:i,radius:n},d={position:{type:"v3",value:null},color:{type:"v3",value:null},radius:{type:"f",value:null},mapping:{type:"v2",value:null}};this.createImpostorShaderBase(e,l,r,a,d,o,4,6,2),a=null,s=null,i=null,n=null,t.posArraySphere=[],t.colorArraySphere=[],t.radiusArraySphere=[]}clearImpostors(){let e=this.icn3d;e.icn3dui,e.posArray=[],e.colorArray=[],e.pos2Array=[],e.color2Array=[],e.radiusArray=[],e.posArraySphere=[],e.colorArraySphere=[],e.radiusArraySphere=[]}}class dt{constructor(e){this.icn3d=e}positionFromGeometry(e){this.icn3d.icn3dui;let t,s,i=e.geometry,n=i.vertices,l=e.position,r=e.scale,o=e.matrix,a=n.length,d=[];for(let e=0;e<a;e++)t=3*e,s="SphereGeometry"==i.type||"BoxGeometry"==i.type?n[e].clone().multiply(r).add(l):"CylinderGeometry"==i.type?n[e].clone().applyMatrix4(o):n[e],d[t+0]=s.x,d[t+1]=s.y,d[t+2]=s.z;return d}colorFromGeometry(e){let t=this.icn3d.icn3dui,s=e.geometry,i=t.parasCls.thr(1,1,1);"SphereGeometry"!=s.type&&"BoxGeometry"!=s.type&&"CylinderGeometry"!=s.type||void 0!==e.material&&(i=e.material.color);let n,l,r,o,a,d=s.faces;s.vertices.length,s.type;let c=d.length,h=[];for(let e=0;e<c;e++)l=d[e],"Surface"==s.type?(r=l.vertexColors[0],o=l.vertexColors[1],a=l.vertexColors[2]):"SphereGeometry"==s.type||"BoxGeometry"==s.type||"CylinderGeometry"==s.type?(r=i,o=i,a=i):(r=l.color,o=l.color,a=l.color),n=3*l.a,h[n+0]=r.r,h[n+1]=r.g,h[n+2]=r.b,n=3*l.b,h[n+0]=o.r,h[n+1]=o.g,h[n+2]=o.b,n=3*l.c,h[n+0]=a.r,h[n+1]=a.g,h[n+2]=a.b;return h}indexFromGeometry(e){this.icn3d.icn3dui;let t,s,i=e.geometry.faces,n=i.length,l=[];for(let e=0;e<n;e++)t=3*e,s=i[e],l[t+0]=s.a,l[t+1]=s.b,l[t+2]=s.c;return l}normalFromGeometry(e){this.icn3d.icn3dui;let t,s,i,n,l,r,o=e.geometry,a=o.faces;o.vertices.length;let d=a.length,c=[];for(let e=0;e<d;e++)s=a[e],i=s.vertexNormals,n=i[0],l=i[1],r=i[2],t=3*s.a,c[t+0]=n.x,c[t+1]=n.y,c[t+2]=n.z,t=3*s.b,c[t+0]=l.x,c[t+1]=l.y,c[t+2]=l.z,t=3*s.c,c[t+0]=r.x,c[t+1]=r.y,c[t+2]=r.z;return c}drawSymmetryMates(){let e=this.icn3d;e.icn3dui.bNode||(e.bInstanced?this.drawSymmetryMatesInstancing():this.drawSymmetryMatesNoInstancing())}applyMat(e,t,s){let i=this.icn3d;if(i.icn3dui,void 0===i.rmsd_supr)e.applyMatrix4(t);else{let s=i.rmsd_supr.rot,n=i.rmsd_supr.trans1,l=i.rmsd_supr.trans2,r=new THREE.Matrix4;r.set(s[0],s[1],s[2],0,s[3],s[4],s[5],0,s[6],s[7],s[8],0,0,0,0,1);let o=new THREE.Matrix4;o.copy(r).invert();let a=new THREE.Matrix4;a.makeTranslation(-l.x,-l.y,-l.z),e.applyMatrix4(a),e.applyMatrix4(o),a.makeTranslation(n.x,n.y,n.z),e.applyMatrix4(a),e.applyMatrix4(t),a.makeTranslation(-n.x,-n.y,-n.z),e.applyMatrix4(a),e.applyMatrix4(r),a.makeTranslation(l.x,l.y,l.z),e.applyMatrix4(a)}}drawSymmetryMatesNoInstancing(){let e=this.icn3d;if(e.icn3dui,void 0===e.biomtMatrices||0==e.biomtMatrices.length)return;let t=1,s=e.center.clone(),i=new THREE.Matrix4;i.identity();let n=new THREE.Object3D,l=new THREE.Object3D,r=new THREE.Object3D;for(let o=0;o<e.biomtMatrices.length&&1==Object.keys(e.structures).length;o++){let a,d=e.biomtMatrices[o];if(void 0===d)continue;if(d.equals(i))continue;if(void 0!==e.mdl&&(a=e.mdl.clone(),this.applyMat(a,d),n.add(a)),void 0!==e.mdlImpostor){a=e.mdlImpostor.clone(),this.applyMat(a,d);for(let t=a.children.length-1;t>=0;t--){let s=a.children[t];s.onBeforeRender=e.impostorCls.onBeforeRender,s.frustumCulled=!1}l.add(a)}void 0!==e.mdl_ghost&&(a=e.mdl_ghost.clone(),this.applyMat(a,d),r.add(a));let c=e.center.clone();this.applyMat(c,d,!0),s.add(c),++t}e.mdl.add(n),e.mdlImpostor.add(l),e.mdl_ghost.add(r),void 0!==e.bSetInstancing&&e.bSetInstancing?(e.maxD=e.maxDAssembly,e.center=e.centerAssembly.clone(),e.applyCenterCls.setCenter(e.center),e.cameraCls.setCamera()):(e.maxD*=Math.sqrt(t),e.center=e.ParserUtilsCls.getMassCenter(s,t),e.maxDAssembly=e.maxD,e.centerAssembly=e.center.clone(),e.applyCenterCls.setCenter(e.center),e.cameraCls.setCamera()),e.bSetInstancing=!0}createInstancedGeometry(e){let t=this.icn3d,s=t.icn3dui,i=e.geometry,n=new THREE.InstancedBufferGeometry,l=[],r=[],o=[],a=[],d=[],c=[],h=[],p=[];if(t.bImpo&&"Cylinder"==e.type){t.instancedMaterial=this.getInstancedMaterial("CylinderInstancing");let e=s.hashUtilsCls.hashvalue2array(i.attributes.position1.array),r=s.hashUtilsCls.hashvalue2array(i.attributes.color.array),m=s.hashUtilsCls.hashvalue2array(i.attributes.position2.array),u=s.hashUtilsCls.hashvalue2array(i.attributes.color2.array),g=s.hashUtilsCls.hashvalue2array(i.index.array),f=s.hashUtilsCls.hashvalue2array(i.attributes.radius.array),C=s.hashUtilsCls.hashvalue2array(i.attributes.mapping.array);l=l.concat(e),o=o.concat(r),h=h.concat(m),p=p.concat(u),a=a.concat(g),d=d.concat(f),c=c.concat(C),n.setAttribute("position1",new THREE.BufferAttribute(new Float32Array(l),3)),n.setAttribute("color",new THREE.BufferAttribute(new Float32Array(o),3)),n.setAttribute("position2",new THREE.BufferAttribute(new Float32Array(h),3)),n.setAttribute("color2",new THREE.BufferAttribute(new Float32Array(p),3)),n.setAttribute("radius",new THREE.BufferAttribute(new Float32Array(d),1)),n.setAttribute("mapping",new THREE.BufferAttribute(new Float32Array(c),3)),n.setIndex(new THREE.BufferAttribute(new Uint32Array(a),1)),e=null,r=null,m=null,u=null,g=null,f=null,C=null}else if(t.bImpo&&"Sphere"==e.type){t.instancedMaterial=this.getInstancedMaterial("SphereInstancing");let e=s.hashUtilsCls.hashvalue2array(i.attributes.position.array),r=s.hashUtilsCls.hashvalue2array(i.attributes.color.array),h=s.hashUtilsCls.hashvalue2array(i.index.array),p=s.hashUtilsCls.hashvalue2array(i.attributes.radius.array),m=s.hashUtilsCls.hashvalue2array(i.attributes.mapping.array);l=l.concat(e),o=o.concat(r),a=a.concat(h),d=d.concat(p),c=c.concat(m),n.setAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),n.setAttribute("color",new THREE.BufferAttribute(new Float32Array(o),3)),n.setAttribute("radius",new THREE.BufferAttribute(new Float32Array(d),1)),n.setAttribute("mapping",new THREE.BufferAttribute(new Float32Array(c),2)),n.setIndex(new THREE.BufferAttribute(new Uint32Array(a),1)),e=null,r=null,h=null,p=null,m=null}else{t.instancedMaterial=this.getInstancedMaterial("Instancing");let e=i.attributes.position?s.hashUtilsCls.hashvalue2array(i.attributes.position.array):[],d=i.attributes.normal?s.hashUtilsCls.hashvalue2array(i.attributes.normal.array):[],c=i.attributes.color?s.hashUtilsCls.hashvalue2array(i.attributes.color.array):[],h=i.index?s.hashUtilsCls.hashvalue2array(i.index.array):[];l=l.concat(e),r=r.concat(d),o=o.concat(c),a=a.concat(h);let p=[],m="CylinderGeometry"==i.type?1:0;for(let e=0,t=l.length/3;e<t;++e)p.push(m);n.setAttribute("position",new THREE.BufferAttribute(new Float32Array(l),3)),n.setAttribute("normal",new THREE.BufferAttribute(new Float32Array(r),3)),n.setAttribute("color",new THREE.BufferAttribute(new Float32Array(o),3)),n.setAttribute("cylinder",new THREE.BufferAttribute(new Float32Array(p),1)),n.setIndex(new THREE.BufferAttribute(new Uint32Array(a),1)),e=null,d=null,c=null,h=null}l=null,r=null,o=null,a=null,d=null,c=null,h=null,p=null;let m=new THREE.InstancedBufferAttribute(new Float32Array(t.matricesElements1),4),u=new THREE.InstancedBufferAttribute(new Float32Array(t.matricesElements2),4),g=new THREE.InstancedBufferAttribute(new Float32Array(t.matricesElements3),4),f=new THREE.InstancedBufferAttribute(new Float32Array(t.matricesElements4),4);return n.setAttribute("matrix1",m),n.setAttribute("matrix2",u),n.setAttribute("matrix3",g),n.setAttribute("matrix4",f),n}getInstancedMaterial(e){let t=this.icn3d;t.icn3dui;let s=new THREE.ShaderMaterial({defines:t.defines,uniforms:t.uniforms,vertexShader:t.impostorCls.getShader(e+".vert"),fragmentShader:t.impostorCls.getShader(e+".frag"),depthTest:!0,depthWrite:!0,lights:!0});return s.extensions.fragDepth=!0,s.extensions.derivatives="#extension GL_OES_standard_derivatives : enable",s}createInstancedMesh(e){let t=this.icn3d;t.icn3dui;for(let s=0,i=e.children.length;s<i;++s){let i=e.children[s];if("Sprite"===i.type)continue;let n=this.createInstancedGeometry(i),l=new THREE.Mesh(n,t.instancedMaterial);l.onBeforeRender=t.impostorCls.onBeforeRender,l.frustumCulled=!1,l.scale.x=l.scale.y=l.scale.z=1,l.type=i.type,n=null,e.add(l)}}drawSymmetryMatesInstancing(){let e=this.icn3d;if(e.icn3dui,void 0===e.biomtMatrices||0==e.biomtMatrices.length)return;let t=1,s=e.center.clone();if(e.impostorCls.setParametersForShader(),void 0===e.bSetInstancing||!e.bSetInstancing){e.matricesElements1=[],e.matricesElements2=[],e.matricesElements3=[],e.matricesElements4=[];let i=new THREE.Matrix4;i.identity();for(let n=0;n<e.biomtMatrices.length&&1==Object.keys(e.structures).length;n++){let l=e.biomtMatrices[n];if(void 0===l)continue;let r=l.toArray();if(l.equals(i))continue;e.matricesElements1.push(r[0],r[1],r[2],r[3]),e.matricesElements2.push(r[4],r[5],r[6],r[7]),e.matricesElements3.push(r[8],r[9],r[10],r[11]),e.matricesElements4.push(r[12],r[13],r[14],r[15]);let o=e.center.clone();o.applyMatrix4(l),s.add(o),++t}}this.createInstancedMesh(e.mdl),this.createInstancedMesh(e.mdlImpostor),void 0!==e.bSetInstancing&&e.bSetInstancing?(e.maxD=e.maxDAssembly,e.center=e.centerAssembly.clone(),e.applyCenterCls.setCenter(e.center),e.cameraCls.setCamera()):(e.maxD*=Math.sqrt(t),e.center=e.ParserUtilsCls.getMassCenter(s,t),e.maxDAssembly=e.maxD,e.centerAssembly=e.center.clone(),e.applyCenterCls.setCenter(e.center),e.cameraCls.setCamera()),e.bSetInstancing=!0}}class ct{constructor(e){this.icn3d=e}async alternateStructures(){let e=this.icn3d,t=e.icn3dui;e.bAlternate=!0,-1==e.ALTERNATE_STRUCTURE&&(e.viewSelectionAtoms=t.hashUtilsCls.cloneHash(e.dAtoms));let s=Object.keys(e.viewSelectionAtoms).length,i=Object.keys(e.atoms).length,n={};for(let t in e.viewSelectionAtoms){n[e.atoms[t].structure]=1}let l=Object.keys(n);e.dAtoms={};let r=e.bScap;for(let s=0,i=l.length;s<i;++s){let n,o=l[s];if(e.bShift?(e.ALTERNATE_STRUCTURE<0&&(e.ALTERNATE_STRUCTURE=1),n=s==e.ALTERNATE_STRUCTURE%i-1||e.ALTERNATE_STRUCTURE%i==0&&s===i-1):n=s==e.ALTERNATE_STRUCTURE%i+1||e.ALTERNATE_STRUCTURE%i==i-1&&0===s,n){for(let s in e.structures[o]){let i=e.structures[o][s];e.dAtoms=t.hashUtilsCls.unionHash(e.dAtoms,e.chains[i])}e.bShift?--e.ALTERNATE_STRUCTURE:++e.ALTERNATE_STRUCTURE,e.ALTERNATE_STRUCTURE<0&&(e.ALTERNATE_STRUCTURE+=i);let n="";r&&(0==s?n="Wild Type ":1==s&&(n="Mutant ")),$("#"+e.pre+"title").html(n+o);break}}if(s<i){let s=t.hashUtilsCls.intHash(e.dAtoms,e.viewSelectionAtoms);Object.keys(s).length>0&&(e.dAtoms=t.hashUtilsCls.cloneHash(s)),e.bShowHighlight=!1}e.applyMapCls.removeSurfaces(),e.applyMapCls.applySurfaceOptions(),e.applyMapCls.removeMaps(),e.applyMapCls.applyMapOptions(),e.applyMapCls.removeEmmaps(),e.applyMapCls.applyEmmapOptions(),e.applyMapCls.removePhimaps(),e.applyMapCls.applyPhimapOptions(),e.applyMapCls.removeSurfaces(),e.applyMapCls.applyphisurfaceOptions(),e.axes=[],e.pc1&&e.axesCls.setPc1Axes(),e.opts.rotationcenter="highlight center",e.drawCls.draw(),e.bShowHighlight=!0}async alternateWrapper(){let e=this.icn3d;e.icn3dui,e.bAlternate=!0,await this.alternateStructures(),e.bAlternate=!1}}class ht{constructor(e){this.icn3d=e}draw(e){let t=this.icn3d,s=t.icn3dui;if(t.impostorCls.clearImpostors(),!t.bRender||t.hAtoms&&0!=Object.keys(t.hAtoms)||(t.hAtoms=s.hashUtilsCls.cloneHash(t.atoms)),t.sceneCls.rebuildScene(),t.bImpo&&t.impostorCls.drawImpostorShader(),t.setColorCls.applyPrevColor(),void 0!==t.biomtMatrices&&t.biomtMatrices.length>1)if(t.bAssembly&&1==Object.keys(t.structures).length&&(void 0===s.cfg.mmdbid&&1==s.cfg.bu||void 0!==s.cfg.mmdbid&&1==s.cfg.bu&&Object.keys(t.atoms).length*t.biomtMatrices.length>t.maxatomcnt))t.instancingCls.drawSymmetryMates();else{let e=!0;t.applyCenterCls.centerSelection(void 0,e)}let i=void 0!==t.hAtoms?Object.keys(t.hAtoms).length:0;if(i>0&&i<Object.keys(t.dAtoms).length&&(t.hlObjectsCls.removeHlObjects(),(void 0===t.bShowHighlight||t.bShowHighlight)&&t.hlObjectsCls.addHlObjects()),!0===t.bRender&&((t.bInitial||$("#"+t.pre+"wait").is(":visible"))&&($("#"+t.pre+"wait")&&$("#"+t.pre+"wait").hide(),$("#"+t.pre+"canvas")&&$("#"+t.pre+"canvas").show(),$("#"+t.pre+"cmdlog")&&$("#"+t.pre+"cmdlog").show()),this.applyTransformation(t._zoomFactor,t.mouseChange,t.quaternion),this.render(e)),t.bOpm&&!s.cfg.chainalign){let e=s.utilsCls.getMemDesc();$("#"+t.pre+"dl_rmsd_html").html(e),s.cfg.bSidebyside||s.htmlCls.dialogCls.openDlg("dl_rmsd","Membranes")}}applyTransformation(e,t,s){let i=this.icn3d,n=i.icn3dui;if(n.bNode)return;let l={update:!1};l._zoomFactor=e,l.mouseChange=new THREE.Vector2,l.mouseChange.copy(t),l.quaternion=new THREE.Quaternion,l.quaternion.copy(s),i.bControlGl&&!n.bNode?window.controls.update(l):i.controls.update(l)}render(e){let t=this.icn3d;t.icn3dui;let s=this;e?t.renderer.setAnimationLoop((function(){s.render_base()})):s.render_base()}handleController(e,t,s,i,n,l){let r=this.icn3d;r.icn3dui;try{let n=0;if(l&&(0!=l[0]&&0!=l[1]||0!=l[0]?n=l[0]:0!=l[1]&&(n=l[1])),void 0===n&&(n=0),s&&!i){let s=n/1e3*t;const i=5;if(0!=n){r.uistr+="dolly";const e=r.dolly.quaternion.clone();r.dummyCam.getWorldQuaternion(r.dolly.quaternion),r.dolly.translateZ(s*i),r.dolly.quaternion.copy(e)}else{e.children[0].scale.z=10,r.workingMatrix.identity().extractRotation(e.matrixWorld),r.raycasterVR.ray.origin.setFromMatrixPosition(e.matrixWorld),r.raycasterVR.ray.direction.set(0,0,-1).applyMatrix4(r.workingMatrix);const t=r.raycasterVR.intersectObjects(r.objects);if(t.length>0){e.children[0].scale.z=t[0].distance,t[0].point.sub(r.mdl.position);let s=r.rayThreshold,i=r.rayCls.getAtomsFromPosition(t[0].point,s);for(;!i&&s<10;)s+=.5,i=r.rayCls.getAtomsFromPosition(t[0].point,s);i&&(r.pAtomNum%2==0?r.pAtom=i:r.pAtom2=i,++r.pAtomNum,this.showPickingVr(r.pk,i))}}}}catch(e){}}showPickingVr(e,t){let s=this.icn3d;s.icn3dui,e||(e=2),s.hAtoms=s.pickingCls.getPickedAtomList(e,t),2===e?s.residueLabelsCls.addResidueLabels(s.hAtoms,void 0,void 0,!0):1===e&&s.residueLabelsCls.addAtomLabels(s.hAtoms),s.setOptionCls.setStyle("proteins",t.style)}render_base(){let e=this.icn3d,t=e.icn3dui,s=this;if(t.bNode)return;let i=e.bControlGl&&!t.bNode?window.cam:e.cam;if(e.directionalLight){let t=new THREE.Quaternion;t.setFromUnitVectors(new THREE.Vector3(0,0,e.cam_z).normalize(),i.position.clone().normalize()),e.directionalLight.position.copy(e.lightPos.clone().applyQuaternion(t).normalize()),e.directionalLight2.position.copy(e.lightPos2.clone().applyQuaternion(t).normalize()),e.directionalLight3.position.copy(e.lightPos3.clone().applyQuaternion(t).normalize())}if(e.bVr||e.renderer.setPixelRatio(window.devicePixelRatio),e.bVr){let t=.04;if(e.controllers){let i=this.updateGamepadState();for(let n=0,l=e.controllers.length;n<l;++n){let l=e.controllers[n];l&&(t=n%2==0?t:-t,s.handleController(l,t,l.userData.selectPressed,l.userData.squeezePressed,i.xArray,i.yArray))}}e.renderer.xr.isPresenting&&(e.canvasUI&&e.canvasUI.update(),e.canvasUILog&&e.canvasUILog.update())}else e.bAr&&e.renderer.xr.isPresenting&&(e.gestures.update(),e.canvasUILog&&e.canvasUILog.update());e.scene&&(e.renderer.outputEncoding=THREE.sRGBEncoding,e.renderer.render(e.scene,i))}updateGamepadState(){let e=this.icn3d;e.icn3dui;let t=e.xAxisIndex?e.xAxisIndex:2,s=e.yAxisIndex?e.yAxisIndex:3;if(e.renderer.xr.isPresenting){const i=e.renderer.xr.getSession().inputSources;let n=[],l=[];return i.forEach((e=>{const i=e.gamepad.axes;let r=parseInt(1e3*i[t]),o=parseInt(-1e3*i[s]);n.push(r),l.push(o)})),{xArray:n,yArray:l}}return{xArray:[0,0],yArray:[0,0]}}}class pt{constructor(e){this.icn3d=e}getAtomsWithinAtom(e,t,s,i,n,l,r){let o=this.icn3d;o.icn3dui;let a=this.getNeighboringAtoms(e,t,s,r);i&&(o.resid2Residhash={});let d={};for(let e in t){let c,h,p=o.atoms[e],m=p.structure+"_"+p.chain+"_"+p.resi;for(let e in o.residues[m])if(o.atoms[e]&&("CA"===o.atoms[e].name&&"C"===o.atoms[e].elem||"O3'"===o.atoms[e].name||"O3*"===o.atoms[e].name)){c=o.atoms[e];break}void 0===c&&(c=p),i&&(h=p.resn+" $"+p.structure+"."+p.chain+":"+p.resi,void 0===o.resid2Residhash[h]&&(o.resid2Residhash[h]={}));let u=p.structure+"_"+p.chain+"_"+p.resi;for(let e in a){let m=a[e];if(!o.crossstrucinter&&p.structure!=m.structure)continue;if(!r&&m.serial in t)continue;if(o.bOpm&&"DUM"===m.resn)continue;let g=m.coord.distanceTo(p.coord);if(g<s){let e,t;d[m.serial]=m,n&&(d[p.serial]=p);let s=m.structure+"_"+m.chain+"_"+m.resi;for(let t in o.residues[s])if("CA"===o.atoms[t].name&&"C"===o.atoms[t].elem||"O3'"===o.atoms[t].name||"O3*"===o.atoms[t].name){e=o.atoms[t];break}if(void 0===e&&(e=m),n&&(o.contactpnts.push({serial:e.serial,coord:e.coord}),o.contactpnts.push({serial:c.serial,coord:c.coord})),i){let s=m.structure+"_"+m.chain+"_"+m.resi;t=m.resn+" $"+m.structure+"."+m.chain+":"+m.resi;let i=g.toFixed(1),n=e.coord.distanceTo(c.coord).toFixed(1),r=u+"_"+p.resn+","+s+"_"+m.resn,a=h+","+t;if((void 0===o.resids2interAll[r]||void 0===o.resids2interAll[r].contact||!o.resids2interAll[r].contact.hasOwnProperty(a)||void 0!==o.resids2interAll[r].hbond&&!o.resids2interAll[r].hbond.hasOwnProperty(a)||void 0!==o.resids2interAll[r].ionic&&!o.resids2interAll[r].ionic.hasOwnProperty(a)||void 0!==o.resids2interAll[r].halogen&&!o.resids2interAll[r].halogen.hasOwnProperty(a)||void 0!==o.resids2interAll[r]["pi-cation"]&&!o.resids2interAll[r]["pi-cation"].hasOwnProperty(a)||void 0!==o.resids2interAll[r]["pi-stacking"]&&!o.resids2interAll[r]["pi-stacking"].hasOwnProperty(a))&&(void 0===o.resid2Residhash[h][t]||i<o.resid2Residhash[h][t].split("_")[0])){let e=void 0===o.resid2Residhash[h][t]?1:parseInt(o.resid2Residhash[h][t].split("_")[4])+1;o.resid2Residhash[h][t]=i+"_"+n+"_"+p.name+"_"+m.name+"_"+e,l||(void 0===o.resids2inter[r]&&(o.resids2inter[r]={}),void 0===o.resids2inter[r].contact&&(o.resids2inter[r].contact={}),o.resids2inter[r].contact[h+","+t]=i+"_"+n+"_"+p.name+"_"+m.name+"_"+e),void 0===o.resids2interAll[r]&&(o.resids2interAll[r]={}),void 0===o.resids2interAll[r].contact&&(o.resids2interAll[r].contact={}),o.resids2interAll[r].contact[h+","+t]=i+"_"+n+"_"+p.name+"_"+m.name+"_"+e}}}}}return d}getNeighboringAtoms(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=this.getExtent(t),r=(l[2][0]-l[0][0])*(l[2][0]-l[0][0])+(l[2][1]-l[0][1])*(l[2][1]-l[0][1])+(l[2][2]-l[0][2])*(l[2][2]-l[0][2]),o=(l[2][0]-l[1][0])*(l[2][0]-l[1][0])+(l[2][1]-l[1][1])*(l[2][1]-l[1][1])+(l[2][2]-l[1][2])*(l[2][2]-l[1][2]),a=r>o?r:o,d=Math.sqrt(a),c=(d+s)*(d+s),h={};for(let r in e){let e=n.atoms[r];!i&&t.hasOwnProperty(e.serial)||(this.bOpm&&"DUM"===e.resn||e.coord.x<l[0][0]-s||e.coord.x>l[1][0]+s||e.coord.y<l[0][1]-s||e.coord.y>l[1][1]+s||e.coord.z<l[0][2]-s||e.coord.z>l[1][2]+s||(e.coord.x-l[2][0])*(e.coord.x-l[2][0])+(e.coord.y-l[2][1])*(e.coord.y-l[2][1])+(e.coord.z-l[2][2])*(e.coord.z-l[2][2])<c&&(h[e.serial]=e))}return h}getExtent(e){let t,s,i,n,l,r,o,a,d,c,h,p=this.icn3d;for(h in p.icn3dui,t=s=i=9999,n=l=r=-9999,o=a=d=c=0,e){let e=p.atoms[h];c++,o+=e.coord.x,a+=e.coord.y,d+=e.coord.z,t=t<e.coord.x?t:e.coord.x,s=s<e.coord.y?s:e.coord.y,i=i<e.coord.z?i:e.coord.z,n=n>e.coord.x?n:e.coord.x,l=l>e.coord.y?l:e.coord.y,r=r>e.coord.z?r:e.coord.z}return[[t,s,i],[n,l,r],[o/c,a/c,d/c]]}hideContact(){let e=this.icn3d;e.icn3dui,e.opts.contact="no",void 0===e.lines&&(e.lines={}),e.lines.contact=[],e.contactpnts=[]}}class mt{constructor(e){this.icn3d=e}isHbondDonorAcceptor(e){let t=this.icn3d;if(t.icn3dui,"N"==e.name&&!e.het||"N"==e.elem&&"Arg"==e.resn||"N"==e.elem&&"Asn"==e.resn||"N"==e.elem&&"Gln"==e.resn||"N"==e.elem&&"Lys"==e.resn||"N"==e.elem&&"Trp"==e.resn)return"donor";if("O"==e.name&&!e.het||"S"==e.elem&&"Met"==e.resn||"O"==e.elem&&"Asn"==e.resn||"O"==e.elem&&"Asp"==e.resn||"O"==e.elem&&"Gln"==e.resn||"O"==e.elem&&"Glu"==e.resn)return"acceptor";if("S"==e.elem&&"Cys"==e.resn||"N"==e.elem&&"His"==e.resn||"O"==e.elem&&"Ser"==e.resn||"O"==e.elem&&"Thr"==e.resn||"O"==e.elem&&"Tyr"==e.resn)return"both";if("Pro"==e.resn)return"none";if("N"==e.elem){if("Asn"==e.resn||"Gln"==e.resn)return"both";let s=0,i=0;for(let i=0,n=e.bonds.length;i<n;++i)"H"==t.atoms[e.bonds[i]].elem&&++s;if(2==s)return"donor";s=0;for(let n=0,l=e.bonds.length;n<l;++n){let l=t.atoms[e.bonds[n]];if("H"!=l.elem){++s;for(let e=0,s=l.bonds.length;e<s;++e)"N"==t.atoms[l.bonds[e]].elem&&++i}}return 1==s?"donor":2==s?i>1?"ring":"donor":"none"}if("O"==e.elem&&1==e.bonds.length){if("Asn"==e.resn||"Gln"==e.resn)return"both";for(let s=0,i=e.bonds.length;s<i;++s)if("H"==t.atoms[e.bonds[s]].elem)return"donor";let s=t.atoms[e.bonds[0]],i=0;for(let e=0,n=s.bonds.length;e<n;++e)"O"!=t.atoms[s.bonds[e]].elem&&"N"!=t.atoms[s.bonds[e]].elem&&"S"!=t.atoms[s.bonds[e]].elem||++i;return i>=2?"acceptor":"both"}if("O"==e.elem&&2==e.bonds.length){for(let s=0,i=e.bonds.length;s<i;++s)if("H"==t.atoms[e.bonds[s]].elem)return"donor";return"acceptor"}return"both"}calcAngles(e,t){let s=this.icn3d;s.icn3dui;let i=[],n=new THREE.Vector3,l=new THREE.Vector3;n.subVectors(t.coord,e.coord);for(let t=0,r=e.bonds.length;t<r;++t)"H"!=s.atoms[e.bonds[t]].elem&&(l.subVectors(s.atoms[e.bonds[t]].coord,e.coord),i.push(n.angleTo(l)));return i}calcPlaneAngle(e,t){let s=this.icn3d;s.icn3dui;let i=e,n=new THREE.Vector3;n.subVectors(t.coord,e.coord);let l=[new THREE.Vector3,new THREE.Vector3],r=0;for(let t=0,n=e.bonds.length;t<n&&!(r>1);++t)"H"!=s.atoms[e.bonds[t]].elem&&(i=s.atoms[e.bonds[t]],l[r++].subVectors(s.atoms[e.bonds[t]].coord,e.coord));if(1===r)for(let t=0,n=i.bonds.length;t<n&&!(r>1);++t)"H"!=s.atoms[i.bonds[t]].elem&&s.atoms[i.bonds[t]].serial!=e.serial&&l[r++].subVectors(s.atoms[i.bonds[t]].coord,e.coord);if(2!==r)return;let o=l[0].cross(l[1]);return Math.abs(Math.PI/2-o.angleTo(n))}isValidHbond(e,t,s){let i=this.icn3d;i.icn3dui;let n,l,r=this.isHbondDonorAcceptor(e),o=this.isHbondDonorAcceptor(t),a=50*Math.PI/180,d=50*Math.PI/180,c=90*Math.PI/180,h=30*Math.PI/180;if("donor"==r&&("acceptor"==o||"both"==o||"ring"==o)||"acceptor"==o&&("donor"==r||"both"==r||"ring"==r))n=e,l=t;else if("acceptor"==r&&("donor"==o||"both"==o||"ring"==o)||"donor"==o&&("acceptor"==r||"both"==r||"ring"==r))l=e,n=t;else{if("both"!=r&&"ring"!=r||"both"!=o&&"ring"!=o)return!1;n=e,l=t,i.nucleotides.hasOwnProperty(e.serial)&&i.nucleotides.hasOwnProperty(t.serial)&&("ring"==r||"ring"==o)||(e.het||t.het)&&"ring"==r&&"ring"==o||(h=90*Math.PI/180)}let p=this.calcAngles(n,l),m=90*Math.PI/180;for(let e=0,t=p.length;e<t;++e)if(Math.abs(m-p[e])>d)return!1;let u=this.calcPlaneAngle(n,l);if(void 0!==u&&u>h)return!1;let g=this.calcAngles(l,n),f=90*Math.PI/180;for(let e=0,t=g.length;e<t;++e)if(Math.abs(f-g[e])>a)return!1;let C=this.calcPlaneAngle(l,n);return!(void 0!==C&&C>c)}calculateChemicalHbonds(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui;if(0===Object.keys(e).length||0===Object.keys(t).length)return;r.resid2Residhash={};let a,d,c={},h=s*s;for(let t in e){let s=e[t],n=i?"LYS"===s.resn&&"N"===s.elem&&"N"!==s.name||"ARG"===s.resn&&("NH1"===s.name||"NH2"===s.name)||("GLU"===s.resn||"ASP"===s.resn)&&"O"===s.elem&&"O"!==s.name||s.het&&("N"===s.elem||"O"===s.elem||"S"===s.elem):"N"===s.elem||"O"===s.elem||"S"===s.elem&&(s.het||"Cys"===s.resn||"Met"===s.resn);n=r.bOpm?n&&"DUM"!==s.resn:n,n&&(a=s.structure+"_"+s.chain+"_"+s.resi,d=a+"_"+s.name,c[d]=s)}let p={},m={},u=.5,g=-27.888,f={};for(let e in t){let C=t[e],b=i?"LYS"===C.resn&&"N"===C.elem&&"N"!==C.name||"ARG"===C.resn&&("NH1"===C.name||"NH2"===C.name)||("GLU"===C.resn||"ASP"===C.resn)&&"O"===C.elem&&"O"!==C.name||C.het&&("N"===C.elem||"O"===C.elem||"S"===C.elem):"N"===C.elem||"O"===C.elem||"S"===C.elem&&(C.het||"Cys"===C.resn||"Met"===C.resn);if(b=r.bOpm?b&&"DUM"!==C.resn:b,b){a=C.structure+"_"+C.chain+"_"+C.resi,d=a+"_"+C.name;let e=C.resn+" $"+C.structure+"."+C.chain+":"+C.resi+"@"+C.name;void 0===r.resid2Residhash[e]&&(r.resid2Residhash[e]={});for(let t in c){if(i&&!(("LYS"!==C.resn&&"ARG"!==C.resn||"LYS"!==c[t].resn&&"ARG"!==c[t].resn)&&("GLU"!==C.resn&&"ASP"!==C.resn||"GLU"!==c[t].resn&&"ASP"!==c[t].resn)))continue;if(!r.crossstrucinter&&C.structure!=c[t].structure)continue;if(a==t.substr(0,t.lastIndexOf("_")))continue;let d=Math.abs(C.coord.x-c[t].coord.x);if(d>s)continue;let b=Math.abs(C.coord.y-c[t].coord.y);if(b>s)continue;let y=Math.abs(C.coord.z-c[t].coord.z);if(y>s)continue;let v=d*d+b*b+y*y;if(v>h)continue;if(!r.proteins.hasOwnProperty(C.serial)||!r.proteins.hasOwnProperty(c[t].serial)||"N"!==C.name&&"O"!==C.name||"O"!==c[t].name&&"N"!==c[t].name){if(!this.isValidHbond(C,c[t],s))continue}else{if(C.name===c[t].name)continue;if(C.structure==c[t].structure&&C.chain==c[t].chain&&Math.abs(C.resi-c[t].resi)<=1)continue;let e,i="N"===C.name?C:c[t],n="O"===C.name?C:c[t];if("Pro"===i.resn)continue;if(void 0===i.hcoord){if(!this.isValidHbond(C,c[t],s))continue}else{let s,l=i.hcoord,o=i.coord,a=n.structure+"_"+n.chain+"_"+n.resi;for(let e in r.residues[a])if("C"===r.atoms[e].name){s=r.atoms[e];break}if(!s)continue;let d=s.coord,h=n.coord,p=l.distanceTo(h),m=l.distanceTo(d),f=o.distanceTo(d),b=o.distanceTo(h);e=p<u||m<u||f<u||b<u?-9.9:g/p-g/m+g/f-g/b,"helix"==C.ss&&c[t].ss}}if(f[C.serial]>2||f[c[t].serial]>2)continue;void 0===f[C.serial]?f[C.serial]=1:++f[C.serial],void 0===f[c[t].serial]?f[c[t].serial]=1:++f[c[t].serial],"graph"!==n&&(i?(r.saltbridgepnts.push({serial:C.serial,coord:C.coord}),r.saltbridgepnts.push({serial:c[t].serial,coord:c[t].coord})):(r.hbondpnts.push({serial:C.serial,coord:C.coord}),r.hbondpnts.push({serial:c[t].serial,coord:c[t].coord})));let _=c[t].structure+"_"+c[t].chain+"_"+c[t].resi;p=o.hashUtilsCls.unionHash(p,r.residues[a]),p=o.hashUtilsCls.unionHash(p,r.residues[_]),m[a]=1,m[_]=1;let w=c[t].resn+" $"+c[t].structure+"."+c[t].chain+":"+c[t].resi+"@"+c[t].name,S=a+"_"+C.resn+","+_+"_"+c[t].resn;void 0!==r.resids2interAll[S]&&void 0!==r.resids2interAll[S].ionic&&r.resids2interAll[S].ionic.hasOwnProperty(e+","+w)||(r.resid2Residhash[e][w]=v.toFixed(1),l||(void 0===r.resids2inter[S]&&(r.resids2inter[S]={}),void 0===r.resids2inter[S].hbond&&(r.resids2inter[S].hbond={}),r.resids2inter[S].hbond[e+","+w]=v.toFixed(1)),void 0===r.resids2interAll[S]&&(r.resids2interAll[S]={}),void 0===r.resids2interAll[S].hbond&&(r.resids2interAll[S].hbond={}),r.resids2interAll[S].hbond[e+","+w]=v.toFixed(1))}}}let C=Object.keys(m);if("graph"!==n)for(let e=0,t=C.length;e<t;++e)for(let t in r.residues[C[e]])r.atoms[t].style2="stick";return p}setHbondsContacts(e,t){let s=this.icn3d;s.icn3dui;let i=t,n="hbond"==t?"hbonds":t;if(s.lines[i]=[],"yes"===e[n].toLowerCase()){let e,n;"hbond"==t?(n=s.hbondpnts,e="#0F0"):"saltbridge"==t?(n=s.saltbridgepnts,e="#0FF"):"contact"==t?(n=s.contactpnts,e="#888"):"halogen"==t?(n=s.halogenpnts,e="#F0F"):"pi-cation"==t?(n=s.picationpnts,e="#F00"):"pi-stacking"==t&&(n=s.pistackingpnts,e="#00F");for(let t=0,l=Math.floor(n.length/2);t<l;t++){let l={};l.position1=n[2*t].coord,l.serial1=n[2*t].serial,l.position2=n[2*t+1].coord,l.serial2=n[2*t+1].serial,l.color=e,l.dashed=!0,(void 0===l.serial1||void 0===l.serial2||s.dAtoms.hasOwnProperty(l.serial1)||s.dAtoms.hasOwnProperty(l.serial2))&&s.lines[i].push(l)}}}hideHbonds(){let e=this.icn3d;e.icn3dui,e.opts.hbonds="no",void 0===e.lines&&(e.lines={}),e.lines.hbond=[],e.hbondpnts=[]}}class ut{constructor(e){this.icn3d=e}calculateHalogenPiInteractions(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui;if(0===Object.keys(e).length||0===Object.keys(t).length)return;let a={},d={},c={},h={};if("halogen"==n){for(let t in e){let s=e[t];a=o.hashUtilsCls.unionHash(a,this.getHalogenDonar(s)),c=o.hashUtilsCls.unionHash(c,this.getHalogenAcceptor(s))}for(let e in t){let s=t[e];h=o.hashUtilsCls.unionHash(h,this.getHalogenDonar(s)),d=o.hashUtilsCls.unionHash(d,this.getHalogenAcceptor(s))}}else if("pi-cation"==n){r.processedRes={};for(let t in e){let s=e[t];a=o.hashUtilsCls.unionHash(a,this.getPi(s,!1)),c=o.hashUtilsCls.unionHash(c,this.getCation(s))}r.processedRes={};for(let e in t){let s=t[e];h=o.hashUtilsCls.unionHash(h,this.getPi(s,!1)),d=o.hashUtilsCls.unionHash(d,this.getCation(s))}}else if("pi-stacking"==n){r.processedRes={};for(let t in e){let s=e[t];a=o.hashUtilsCls.unionHash(a,this.getPi(s,!0))}r.processedRes={};for(let e in t){let s=t[e];d=o.hashUtilsCls.unionHash(d,this.getPi(s,!0))}}let p={},m={};r.resid2Residhash={};let u=s*s;for(let e in a){let t=a[e],c=t.resn+" $"+t.structure+"."+t.chain+":"+t.resi+"@"+t.name;void 0===r.resid2Residhash[c]&&(r.resid2Residhash[c]={});for(let a in d){let h=d[a];if((r.crossstrucinter||t.structure==h.structure)&&e.substr(0,e.lastIndexOf("_"))!=a.substr(0,a.lastIndexOf("_"))){if("pi-cation"==n&&"ARG"===h.resn&&"NH1"===h.name){let e=h.structure+"_"+h.chain+"_"+h.resi,t=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[e],"NH2"),s=h.coord.clone().add(t.coord).multiplyScalar(.5);h=o.hashUtilsCls.cloneHash(h),h.coord=s}"pi-stacking"==n&&void 0!==t.normal&&void 0!==h.normal&&Math.abs(t.normal.dot(h.normal)),this.getHalogenPiInteractions(t,h,i,n,s,u,c,l)&&(p=o.hashUtilsCls.unionHash(p,r.residues[t.structure+"_"+t.chain+"_"+t.resi]),p=o.hashUtilsCls.unionHash(p,r.residues[h.structure+"_"+h.chain+"_"+h.resi]),m[t.structure+"_"+t.chain+"_"+t.resi]=1,m[h.structure+"_"+h.chain+"_"+h.resi]=1)}}}for(let e in c){let t=c[e],a=t.resn+" $"+t.structure+"."+t.chain+":"+t.resi+"@"+t.name;if(void 0===r.resid2Residhash[a]&&(r.resid2Residhash[a]={}),"pi-cation"==n&&"ARG"===t.resn&&"NH1"===t.name){let e=t.structure+"_"+t.chain+"_"+t.resi,s=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[e],"NH2"),i=t.coord.clone().add(s.coord).multiplyScalar(.5);t=o.hashUtilsCls.cloneHash(t),t.coord=i}for(let d in h){let c=h[d];(r.crossstrucinter||t.structure==c.structure)&&(e.substr(0,e.lastIndexOf("_"))!=d.substr(0,d.lastIndexOf("_"))&&this.getHalogenPiInteractions(t,c,i,n,s,u,a,l)&&(p=o.hashUtilsCls.unionHash(p,r.residues[t.structure+"_"+t.chain+"_"+t.resi]),p=o.hashUtilsCls.unionHash(p,r.residues[c.structure+"_"+c.chain+"_"+c.resi]),m[t.structure+"_"+t.chain+"_"+t.resi]=1,m[c.structure+"_"+c.chain+"_"+c.resi]=1))}}let g=Object.keys(m);if("graph"!==i)for(let e=0,t=g.length;e<t;++e)for(let t in r.residues[g[e]])r.atoms[t].style2="stick",r.ions.hasOwnProperty(t)&&(r.atoms[t].style2="sphere");return p}getHalogenDonar(e){this.icn3d.icn3dui;let t={};if("CL"===e.elem||"BR"===e.elem||"I"===e.elem){t[e.structure+"_"+e.chain+"_"+e.resi+"_"+e.name]=e}return t}getHalogenAcceptor(e){let t=this.icn3d;t.icn3dui;let s={},i="N"===e.elem||"O"===e.elem||"S"===e.elem;if(i=t.bOpm?i&&"DUM"!==e.resn:i,i){s[e.structure+"_"+e.chain+"_"+e.resi+"_"+e.name]=e}return s}getPi(e,t){let s=this.icn3d,i=s.icn3dui,n={},l=e.structure+"_"+e.chain+"_"+e.resi,r=e.het||s.nucleotides.hasOwnProperty(e.serial)||"PHE"===e.resn||"TYR"===e.resn||"TRP"===e.resn;if(t&&(r=r||"HIS"===e.resn),r&&!s.processedRes.hasOwnProperty(l)){if(e.het){let e=this.getAromaticPisLigand(l);n=i.hashUtilsCls.unionHash(n,e)}else{let t,i,r;r=s.nucleotides.hasOwnProperty(e.serial)?this.getAromaticRings(e.resn,l,"nucleotide"):this.getAromaticRings(e.resn,l,"protein"),void 0!==r&&(t=r.piPosArray,i=r.normalArray);for(let s=0,r=t.length;s<r;++s)n[l+"_pi"+s]={resn:e.resn,name:"pi"+s,coord:t[s],serial:e.serial,structure:e.structure,chain:e.chain,resi:e.resi,normal:i[s]}}s.processedRes[l]=1}return n}getCation(e){let t=this.icn3d,s=t.icn3dui,i={};if("ARG"===e.resn&&"NH2"===e.name)return;let n="LYS"===e.resn&&"N"===e.elem&&"N"!==e.name||"ARG"===e.resn&&("NH1"===e.name||"NH2"===e.name)||e.het&&-1!==s.parasCls.cationsTrimArray.indexOf(e.elem)||e.het&&"N"===e.elem&&(1==e.bonds.length||4==e.bonds.length);if(n=t.bOpm?n&&"DUM"!==e.resn:n,n){i[e.structure+"_"+e.chain+"_"+e.resi+"_"+e.name]=e}return i}getHalogenPiInteractions(e,t,s,i,n,l,r,o){let a=this.icn3d;a.icn3dui;let d=Math.abs(e.coord.x-t.coord.x);if(d>n)return!1;let c=Math.abs(e.coord.y-t.coord.y);if(c>n)return!1;let h=Math.abs(e.coord.z-t.coord.z);if(h>n)return!1;let p=d*d+c*c+h*h;if(p>l)return!1;"graph"!==s&&("halogen"==i?(a.halogenpnts.push({serial:e.serial,coord:e.coord}),a.halogenpnts.push({serial:t.serial,coord:t.coord})):"pi-cation"==i?(a.picationpnts.push({serial:e.serial,coord:e.coord}),a.picationpnts.push({serial:t.serial,coord:t.coord})):"pi-stacking"==i&&(a.pistackingpnts.push({serial:e.serial,coord:e.coord}),a.pistackingpnts.push({serial:t.serial,coord:t.coord})));let m=t.resn+" $"+t.structure+"."+t.chain+":"+t.resi+"@"+t.name;a.resid2Residhash[r][m]=p.toFixed(1);let u=e.structure+"_"+e.chain+"_"+e.resi+"_"+e.resn+","+t.structure+"_"+t.chain+"_"+t.resi+"_"+t.resn;return o||(void 0===a.resids2inter[u]&&(a.resids2inter[u]={}),void 0===a.resids2inter[u][i]&&(a.resids2inter[u][i]={}),a.resids2inter[u][i][r+","+m]=p.toFixed(1)),void 0===a.resids2interAll[u]&&(a.resids2interAll[u]={}),void 0===a.resids2interAll[u][i]&&(a.resids2interAll[u][i]={}),a.resids2interAll[u][i][r+","+m]=p.toFixed(1),!0}getRingNormal(e){if(this.icn3d.icn3dui,e.length<3)return;let t=e[0].clone().sub(e[1]),s=e[1].clone().sub(e[2]);return t.cross(s).normalize()}getAromaticRings(e,t,s){let i=this.icn3d;i.icn3dui;let n=[],l=[],r=[],o=[];if("nucleotide"==s){let s=new THREE.Vector3,a=new THREE.Vector3;if("A"==e.trim().toUpperCase()||"DA"==e.trim().toUpperCase()||"G"==e.trim().toUpperCase()||"DG"==e.trim().toUpperCase()){for(let e in i.residues[t]){let t=i.atoms[e];"N1"==t.name||"C2"==t.name||"N3"==t.name||"C6"==t.name?(s.add(t.coord),r.push(t.coord)):"C4"==t.name||"C5"==t.name?(s.add(t.coord),a.add(t.coord),r.push(t.coord),o.push(t.coord)):"N7"!=t.name&&"C8"!=t.name&&"N9"!=t.name||(a.add(t.coord),o.push(t.coord))}6==r.length&&(s.multiplyScalar(1/6),n.push(s),l.push(this.getRingNormal(r))),5==o.length&&(a.multiplyScalar(.2),n.push(a),l.push(this.getRingNormal(o)))}else if("C"==e.trim().toUpperCase()||"DC"==e.trim().toUpperCase()||"T"==e.trim().toUpperCase()||"DT"==e.trim().toUpperCase()||"U"==e.trim().toUpperCase()||"DU"==e.trim().toUpperCase()){for(let e in i.residues[t]){let t=i.atoms[e];"N1"==t.name||"C2"==t.name||"N3"==t.name||"C6"==t.name?(s.add(t.coord),r.push(t.coord)):"C4"!=t.name&&"C5"!=t.name||(s.add(t.coord),r.push(t.coord))}6==r.length&&(s.multiplyScalar(1/6),n.push(s),l.push(this.getRingNormal(r)))}}else if("protein"==s){let s=new THREE.Vector3,a=new THREE.Vector3;if("PHE"==e.toUpperCase()||"TYR"==e.toUpperCase()){for(let e in i.residues[t]){let t=i.atoms[e];"CG"!=t.name&&"CD1"!=t.name&&"CE1"!=t.name&&"CZ"!=t.name&&"CE2"!=t.name&&"CD2"!=t.name||(s.add(t.coord),r.push(t.coord))}6==r.length&&(s.multiplyScalar(1/6),n.push(s),l.push(this.getRingNormal(r)))}else if("HIS"==e.toUpperCase()){for(let e in i.residues[t]){let t=i.atoms[e];"CG"!=t.name&&"ND1"!=t.name&&"CE1"!=t.name&&"NE2"!=t.name&&"CD2"!=t.name||(s.add(t.coord),r.push(t.coord))}5==r.length&&(s.multiplyScalar(.2),n.push(s),l.push(this.getRingNormal(r)))}else if("TRP"==e.toUpperCase()){for(let e in i.residues[t]){let t=i.atoms[e];"CZ2"==t.name||"CH2"==t.name||"CZ3"==t.name||"CE3"==t.name?(s.add(t.coord),r.push(t.coord)):"CD2"==t.name||"CE2"==t.name?(s.add(t.coord),a.add(t.coord),r.push(t.coord),o.push(t.coord)):"CG"!=t.name&&"CD1"!=t.name&&"NE1"!=t.name||(a.add(t.coord),o.push(t.coord))}6==r.length&&(s.multiplyScalar(1/6),n.push(s),l.push(this.getRingNormal(r))),5==o.length&&(a.multiplyScalar(.2),n.push(a),l.push(this.getRingNormal(o)))}}return{piPosArray:n,normalArray:l}}dfs_cycle(e,t,s){let i=this.icn3d;if(i.icn3dui,2==i.ring_color[e])return s;if(1==i.ring_color[e]){s++;let n=t;for(i.ring_mark[n]=s;n!=e;)n=i.ring_par[n],i.ring_mark[n]=s;return s}if(i.ring_par[e]=t,i.ring_color[e]=1,void 0!==i.atoms[e])for(let t=0,n=i.atoms[e].bonds.length;t<n;++t){let n=i.atoms[e].bonds[t];n!=i.ring_par[e]&&(s=this.dfs_cycle(n,e,s))}return i.ring_color[e]=2,s}getAromaticPisLigand(e){let t=this.icn3d;t.icn3dui;let s={},i=Object.keys(t.residues[e]),n=i.length;t.ring_color={},t.ring_par={},t.ring_mark={};let l=0;l=this.dfs_cycle(i[1],i[0],l);let r={};for(let e=0;e<n;e++){let s=i[e];t.ring_mark[s]&&(void 0===r[t.ring_mark[s]]&&(r[t.ring_mark[s]]=[]),r[t.ring_mark[s]].push(s))}for(let i=1;i<=l;i++){let n,l=new THREE.Vector3,o=0,a=[];if(r.hasOwnProperty(i))for(let e=0,s=r[i].length;e<s;++e)n=r[i][e],l.add(t.atoms[n].coord),a.push(t.atoms[n].coord),++o;if(o>=3&&o<=6&&a[0]&&a[1]&&a[2]&&a[3]){let i=a[0].clone().sub(a[1]).normalize(),r=a[1].clone().sub(a[2]).normalize(),d=a[2].clone().sub(a[3]).normalize(),c=i.cross(r).normalize(),h=c.dot(d);if(Math.abs(h)<.052){l.multiplyScalar(1/o);let i=t.atoms[n];s[e+"_pi"+n]={resn:i.resn,name:"pi"+n,coord:l,serial:i.serial,structure:i.structure,chain:i.chain,resi:i.resi,normal:c}}}}return s}hideHalogenPi(){let e=this.icn3d;e.icn3dui,e.opts.halogen="no",e.opts["pi-cation"]="no",e.opts["pi-stacking"]="no",void 0===e.lines&&(e.lines={}),e.lines.halogen=[],e.lines["pi-cation"]=[],e.lines["pi-stacking"]=[],e.halogenpnts=[],e.picationpnts=[],e.pistackingpnts=[]}}class gt{constructor(e){this.icn3d=e}calculateIonicInteractions(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui;if(0===Object.keys(e).length||0===Object.keys(t).length)return;r.resid2Residhash={};let a,d,c={},h={},p=s*s;for(let t in e){let s=e[t];if("ARG"===s.resn&&"NH2"===s.name||"GLU"===s.resn&&"OE2"===s.name||"ASP"===s.resn&&"OD2"===s.name)continue;let i=("LYS"===s.resn||"HIS"===s.resn)&&"N"===s.elem&&"N"!==s.name||"ARG"===s.resn&&("NH1"===s.name||"NH2"===s.name)||s.het&&-1!==o.parasCls.cationsTrimArray.indexOf(s.elem)||s.het&&"N"===s.elem&&1==s.bonds.length,n=this.isAnion(s);i=r.bOpm?i&&"DUM"!==s.resn:i,n=r.bOpm?n&&"DUM"!==s.resn:n,(i||n)&&(a=s.structure+"_"+s.chain+"_"+s.resi,d=a+"_"+s.name,i&&(c[d]=s),n&&(h[d]=s))}let m={},u={};for(let e in t){let i=t[e];if("ARG"===i.resn&&"NH2"===i.name||"GLU"===i.resn&&"OE2"===i.name||"ASP"===i.resn&&"OD2"===i.name)continue;let g=("LYS"===i.resn||"HIS"===i.resn)&&"N"===i.elem&&"N"!==i.name||"ARG"===i.resn&&("NH1"===i.name||"NH2"===i.name)||i.het&&-1!==o.parasCls.cationsTrimArray.indexOf(i.elem),f=this.isAnion(i);if(g=r.bOpm?g&&"DUM"!==i.resn:g,f=r.bOpm?f&&"DUM"!==i.resn:f,g||f){a=i.structure+"_"+i.chain+"_"+i.resi,d=a+"_"+i.name;let e=i.resn+" $"+i.structure+"."+i.chain+":"+i.resi+"@"+i.name;void 0===r.resid2Residhash[e]&&(r.resid2Residhash[e]={});let t={};g?t=h:f&&(t=c);let C,b=i.structure+"_"+i.chain+"_"+i.resi;g&&"ARG"===i.resn&&"NH1"===i.name?C=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[b],"NH2"):f&&"GLU"===i.resn&&"OE1"===i.name?C=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[b],"OE2"):f&&"ASP"===i.resn&&"OD1"===i.name&&(C=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[b],"OD2"));let y=void 0===C?i.coord:i.coord.clone().add(C.coord).multiplyScalar(.5);for(let d in t){if(a==d.substr(0,d.lastIndexOf("_")))continue;if(!r.crossstrucinter&&i.structure!=t[d].structure)continue;let c,h=t[d].structure+"_"+t[d].chain+"_"+t[d].resi;f&&"ARG"===t[d].resn&&"NH1"===t[d].name?c=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[h],"NH2"):g&&"GLU"===t[d].resn&&"OE1"===t[d].name?c=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[h],"OE2"):g&&"ASP"===t[d].resn&&"OD1"===t[d].name&&(c=r.firstAtomObjCls.getFirstAtomObjByName(r.residues[h],"OD2"));let C=void 0===c?t[d].coord:t[d].coord.clone().add(c.coord).multiplyScalar(.5),b=Math.abs(y.x-C.x);if(b>s)continue;let v=Math.abs(y.y-C.y);if(v>s)continue;let _=Math.abs(y.z-C.z);if(_>s)continue;let w=b*b+v*v+_*_;if(w>p)continue;"graph"!==n&&(r.saltbridgepnts.push({serial:i.serial,coord:y}),r.saltbridgepnts.push({serial:t[d].serial,coord:C}));let S=t[d].structure+"_"+t[d].chain+"_"+t[d].resi;m=o.hashUtilsCls.unionHash(m,r.residues[a]),m=o.hashUtilsCls.unionHash(m,r.residues[S]),u[a]=1,u[S]=1;let A=t[d].resn+" $"+t[d].structure+"."+t[d].chain+":"+t[d].resi+"@"+t[d].name;r.resid2Residhash[e][A]=w.toFixed(1);let x=a+"_"+i.resn+","+S+"_"+t[d].resn;l||(void 0===r.resids2inter[x]&&(r.resids2inter[x]={}),void 0===r.resids2inter[x].ionic&&(r.resids2inter[x].ionic={}),r.resids2inter[x].ionic[e+","+A]=w.toFixed(1)),void 0===r.resids2interAll[x]&&(r.resids2interAll[x]={}),void 0===r.resids2interAll[x].ionic&&(r.resids2interAll[x].ionic={}),r.resids2interAll[x].ionic[e+","+A]=w.toFixed(1)}}}let g=Object.keys(u);if("graph"!==n)for(let e=0,t=g.length;e<t;++e)for(let t in r.residues[g[e]])r.atoms[t].style2="stick",r.ions.hasOwnProperty(t)&&(r.atoms[t].style2="sphere");return m}isAnion(e){let t,s=this.icn3d,i=s.icn3dui;if(e.het&&"O"===e.elem&&1==e.bonds.length){let i=s.atoms[e.bonds[0]];for(let n=0;n<i.bonds.length;++n){let l=i.bonds[n];if("O"==s.atoms[l].elem&&l!=e.serial){t=!0;break}}}if("O"===e.elem&&1==e.bonds.length){let i=s.atoms[e.bonds[0]];"P"!=i.elem&&"S"!=i.elem||(t=!0)}return"GLU"===e.resn&&("OE1"===e.name||"OE2"===e.name)||"ASP"===e.resn&&("OD1"===e.name||"OD2"===e.name)||s.nucleotides.hasOwnProperty(e.serial)&&("OP1"===e.name||"OP2"===e.name||"O1P"===e.name||"O2P"===e.name)||e.het&&-1!==i.parasCls.anionsTrimArray.indexOf(e.elem)||t}hideSaltbridge(){let e=this.icn3d;e.icn3dui,e.opts.saltbridge="no",void 0===e.lines&&(e.lines={}),e.lines.saltbridge=[],e.saltbridgepnts=[]}}class ft{constructor(e){this.icn3d=e}setStyle2Atoms(e){let t=this.icn3d;t.icn3dui,t.style2atoms={};for(let s in e)void 0===t.style2atoms[t.atoms[s].style]&&(t.style2atoms[t.atoms[s].style]={}),t.style2atoms[t.atoms[s].style][s]=1,void 0!==t.atoms[s].style2&&"nothing"!==t.atoms[s].style2&&(void 0===t.style2atoms[t.atoms[s].style2]&&(t.style2atoms[t.atoms[s].style2]={}),t.style2atoms[t.atoms[s].style2][s]=1)}setAtomStyleByOptions(e){let t,s=this.icn3d,i=s.icn3dui;if(void 0===e&&(e=s.opts),void 0!==e.proteins){t=i.hashUtilsCls.intHash(s.hAtoms,s.proteins);for(let i in t)s.atoms[i].style=e.proteins.toLowerCase()}if(void 0!==e.sidec&&"nothing"!==e.sidec){t=i.hashUtilsCls.intHash(s.hAtoms,s.sidec);for(let i in t)s.atoms[i].style2=e.sidec.toLowerCase()}if(void 0!==e.ntbase&&"nothing"!==e.ntbase){t=i.hashUtilsCls.intHash(s.hAtoms,s.ntbase);for(let i in t)s.atoms[i].style2=e.ntbase.toLowerCase()}if(void 0!==e.chemicals){t=i.hashUtilsCls.intHash(s.hAtoms,s.chemicals);for(let i in t)s.atoms[i].style=e.chemicals.toLowerCase()}if(void 0!==e.ions){t=i.hashUtilsCls.intHash(s.hAtoms,s.ions);for(let i in t)s.atoms[i].style=e.ions.toLowerCase()}if(void 0!==e.water){t=i.hashUtilsCls.intHash(s.hAtoms,s.water);for(let i in t)s.atoms[i].style=e.water.toLowerCase()}if(void 0!==e.nucleotides){t=i.hashUtilsCls.intHash(s.hAtoms,s.nucleotides);for(let i in t)s.atoms[i].style=e.nucleotides.toLowerCase()}}setBackground(e){var t=this.icn3d,s=t.icn3dui;t.setOptionCls.setOption("background",e),s.htmlCls.clickMenuCls.setLogCmd("set background "+e,!0);let i="black"==e?s.htmlCls.GREYD:"black";$("#"+t.pre+"title").css("color",i),$("#"+t.pre+"titlelink").css("color",i)}saveCommandsToSession(){var e=this.icn3d;e.icn3dui;let t=e.commands.join("\n"),s=decodeURIComponent(t);sessionStorage.setItem("commands",s)}getCommandsBeforeCrash(){var e=this.icn3d,t=e.icn3dui;window.addEventListener("load",(function(){sessionStorage.setItem("good_exit","pending")})),window.addEventListener("beforeunload",(function(){sessionStorage.setItem("good_exit","true")})),sessionStorage.getItem("good_exit")&&"pending"===sessionStorage.getItem("good_exit")&&(t.utilsCls.isMac()||(e.bCrashed=!0),e.commandsBeforeCrash=sessionStorage.getItem("commands"),e.commandsBeforeCrash||(e.commandsBeforeCrash=""))}handleContextLost(){var e=this.icn3d;e.icn3dui;let t=$("#"+e.pre+"canvas")[0];t.addEventListener("webglcontextlost",(function(e){e.preventDefault()}),!1),t.addEventListener("webglcontextrestored",(function(t){console.log("WebGL context was lost. Reset WebGLRenderer and launch iCn3D again."),e.renderer=new THREE.WebGLRenderer({canvas:e.oriContainer.get(0),antialias:!0,preserveDrawingBuffer:!0,sortObjects:!1,alpha:!0}),e.renderer.xr.enabled=!0,e.drawCls.draw()}),!1)}adjustIcon(){var e=this.icn3d;e.icn3dui,1===e.STATENUMBER?$("#"+e.pre+"back").hasClass("icn3d-middleIcon")&&($("#"+e.pre+"back").toggleClass("icn3d-middleIcon"),$("#"+e.pre+"back").toggleClass("icn3d-endIcon")):$("#"+e.pre+"back").hasClass("icn3d-endIcon")&&($("#"+e.pre+"back").toggleClass("icn3d-middleIcon"),$("#"+e.pre+"back").toggleClass("icn3d-endIcon")),e.STATENUMBER===e.commands.length?$("#"+e.pre+"forward").hasClass("icn3d-middleIcon")&&($("#"+e.pre+"forward").toggleClass("icn3d-middleIcon"),$("#"+e.pre+"forward").toggleClass("icn3d-endIcon")):$("#"+e.pre+"forward").hasClass("icn3d-endIcon")&&($("#"+e.pre+"forward").toggleClass("icn3d-middleIcon"),$("#"+e.pre+"forward").toggleClass("icn3d-endIcon"))}}class Ct{constructor(e){this.icn3d=e}colorSpectrum(e){let t=this.icn3d,s=t.icn3dui,i=0,n=0;e=s.hashUtilsCls.intHash(e,t.hAtoms);for(let s in e){t.atoms[s].het||++n}let l=n>1?1/(n-1):1;for(let n in e){let e=t.atoms[n];e.color=e.het?s.parasCls.atomColors[e.elem]||s.parasCls.defaultAtomColor:s.parasCls.thr().setHSL(3/4*(1-i++*l),1,.45),t.atomPrevColors[n]=e.color}}colorRainbow(e){let t=this.icn3d,s=t.icn3dui,i=0,n=0;e=s.hashUtilsCls.intHash(e,t.hAtoms);for(let s in e){t.atoms[s].het||++n}let l=n>1?1/(n-1):1;for(let n in e){let e=t.atoms[n];e.color=e.het?s.parasCls.atomColors[e.elem]||s.parasCls.defaultAtomColor:s.parasCls.thr().setHSL(3/4*i++*l,1,.45),t.atomPrevColors[n]=e.color}}setColorAcrossSets(e,t){let s=this.icn3d,i=s.icn3dui,n=0,l=e.length,r=l>1?1/(l-1):1;for(let l=0,o=e.length;l<o;++l){let o=s.definedSetsCls.getAtomsFromNameArray([e[l]]);for(let e in o){let l=s.atoms[e];l.color=t?i.parasCls.thr().setHSL(3/4*(1-n*r),1,.45):i.parasCls.thr().setHSL(3/4*n*r,1,.45),s.atomPrevColors[e]=l.color}++n}s.drawCls.draw()}setColorBySets(e,t){let s=this.icn3d;s.icn3dui;for(let i=0,n=e.length;i<n;++i){let n=s.definedSetsCls.getAtomsFromNameArray([e[i]]);t?this.colorSpectrum(n):this.colorRainbow(n)}s.drawCls.draw()}setColorByOptions(e,t,s){let i=this.icn3d,n=i.icn3dui;if(void 0!==e)if(s)for(let e in t){let t=i.atoms[e];i.atomPrevColors[e]=t.color}else if(0===e.color.indexOf("#"))for(let s in t){let t=i.atoms[s];t.color=n.parasCls.thr().setStyle(e.color.toLowerCase()),i.atomPrevColors[s]=t.color}else{let s,l,r,o,a;switch("confidence"==e.color.toLowerCase()?$("#"+n.pre+"legend").show():$("#"+n.pre+"legend").hide(),e.color.toLowerCase()){case"rainbow":this.colorRainbow(t);break;case"rainbow for chains":for(let e in i.chains)this.colorRainbow(i.chains[e]);break;case"spectrum":this.colorSpectrum(t);break;case"spectrum for chains":for(let e in i.chains)this.colorSpectrum(i.chains[e]);break;case"structure":let d=i.bAfMem?[n.parasCls.thr(16711935),n.parasCls.thr(65280)]:n.parasCls.stdChainColors,c=-1,h="",p=d.length;for(let e in t){let t=i.atoms[e];t.structure!=h&&(++c,c%=p),t.het?(t.color=n.parasCls.atomColors[t.elem],i.atomPrevColors[e]=t.color):(t.color=d[c],i.atomPrevColors[e]=t.color),h=t.structure}break;case"chain":if(void 0!==i.chainsColor&&Object.keys(i.chainsColor).length>0)this.setMmdbChainColor();else{let e=-1,s="",l=n.parasCls.stdChainColors.length;for(let r in t){let t=i.atoms[r];t.chain!=s&&(++e,e%=l),t.het?(t.color=n.parasCls.atomColors[t.elem],i.atomPrevColors[r]=t.color):(t.color=n.parasCls.stdChainColors[e],Object.keys(i.chainsColor).length>0&&this.updateChainsColor(t),i.atomPrevColors[r]=t.color),s=t.chain}}break;case"domain":s=0,l=0;let m=Object.keys(i.tddomains);l=m.length,r=l>1?1/(l-1):1;for(let e=0,t=m.length;e<t;++e){let t=n.parasCls.thr().setHSL(3/4*(1-s++*r),1,.45);for(let s in i.tddomains[m[e]])for(let e in i.residues[s]){let s=i.atoms[e];s.color=t,i.atomPrevColors[e]=s.color}}break;case"defined sets":if(s=0,i.nameArray&&0!=i.nameArray.length){l=i.nameArray.length,r=l>1?1/(l-1):1;for(let e=0;e<l;++e){let t=i.nameArray[e],l=i.definedSetsCls.getAtomsFromNameArray([t]),o=n.parasCls.thr().setHSL(3/4*s++*r,1,.45);for(let e in l){let t=i.atoms[e];t.color=o,i.atomPrevColors[e]=t.color}}}else alert('Please first select sets in "Analysis > Defined Sets", and try it again.');break;case"secondary structure green":case"secondary structure":i.sheetcolor="green";for(let e in t){let t=i.atoms[e];t.color=t.het?n.parasCls.atomColors[t.elem]||n.parasCls.defaultAtomColor:n.parasCls.ssColors[t.ss]||n.parasCls.thr(16711935),i.atomPrevColors[e]=t.color}break;case"secondary structure yellow":i.sheetcolor="yellow";for(let e in t){let t=i.atoms[e];t.color=t.het?n.parasCls.atomColors[t.elem]||n.parasCls.defaultAtomColor:n.parasCls.ssColors2[t.ss]||n.parasCls.thr(16711935),i.atomPrevColors[e]=t.color}break;case"secondary structure spectrum":s=0,l=0;let u,g,f=[],C=-9999;for(let e in t){if(!i.proteins.hasOwnProperty(e))continue;let t=i.atoms[e];-9999==C&&(u=parseInt(e)),-9999!=C&&(t.ss!=g.ss||Math.abs(t.resi-g.resi)>1||t.ssbegin&&g.ssend)&&("coil"==g.ss||f.push([u,C]),u=e),C=parseInt(e),g=t}"coil"==g.ss||f.push([u,C]),l=f.length,r=l>1?1/(l-1):1;for(let e=0,t=f.length;e<t;++e){let t=n.parasCls.thr().setHSL(3/4*(1-s++*r),1,.45);for(let s=f[e][0];s<=f[e][1];++s){let e=i.atoms[s];e.color=t,i.atomPrevColors[s]=e.color}}break;case"residue":for(let e in t){let t=i.atoms[e];t.color=t.het?n.parasCls.atomColors[t.elem]||n.parasCls.defaultAtomColor:n.parasCls.residueColors[t.resn]||n.parasCls.defaultResidueColor,i.atomPrevColors[e]=t.color}break;case"ig strand":if(i.bShowRefnum){let e,s=i.firstAtomObjCls.getResiduesFromAtoms(t);for(let t in s){if(i.resid2refnum[t]){let s=i.resid2refnum[t],l=i.refnumCls.rmStrandFromRefnumlabel(s),r=s.replace(new RegExp(l,"g"),"");e=i.annoIgCls.getRefnumColor(r),i.residIgLoop.hasOwnProperty(t)&&(e=n.parasCls.thr(n.htmlCls.GREYB))}else e=n.parasCls.thr("#00FFFF");for(let s in i.residues[t]){let t=i.atoms[s];t.color=n.parasCls.thr(e),i.atomPrevColors[s]=t.color}}}break;case"ig protodomain":if(i.bShowRefnum){let e,s=i.firstAtomObjCls.getResiduesFromAtoms(t);for(let t in s){if(i.resid2refnum[t]){let s=i.resid2refnum[t];if(s){let l=i.refnumCls.rmStrandFromRefnumlabel(s),r=s.replace(new RegExp(l,"g"),"");e=i.annoIgCls.getProtodomainColor(r),i.residIgLoop.hasOwnProperty(t)&&(e=n.parasCls.thr(n.htmlCls.GREYB))}else e=n.parasCls.thr(n.htmlCls.GREYB)}else e=n.parasCls.thr("#00FFFF");for(let s in i.residues[t]){let t=i.atoms[s];t.color=n.parasCls.thr(e),i.atomPrevColors[s]=t.color}}}break;case"residue custom":for(let e in t){let t=i.atoms[e];t.color=t.het?n.parasCls.atomColors[t.elem]||n.parasCls.defaultAtomColor:i.customResidueColors[t.resn]||n.parasCls.defaultResidueColor,i.atomPrevColors[e]=t.color}break;case"align custom":i.middB=50,i.spanBinv1=.02,i.spanBinv2=.02;for(let e in t){let t,s=i.atoms[e].structure+"_"+i.atoms[e].chain;if(void 0===i.queryresi2score||!i.queryresi2score.hasOwnProperty(s))continue;let l=i.atoms[e].resi;if(i.queryresi2score[s].hasOwnProperty(l)){let e=i.queryresi2score[s][l];e>100&&(e=100);let r=(i.middB-e)*i.spanBinv1,o=(e-i.middB)*i.spanBinv2;e<i.middB?"blue"==i.startColor?t="white"==i.midColor?n.parasCls.thr().setRGB(1-r,1-r,1):n.parasCls.thr().setRGB(0,0,r):"red"==i.startColor?t="white"==i.midColor?n.parasCls.thr().setRGB(1,1-r,1-r):n.parasCls.thr().setRGB(r,0,0):"green"==i.startColor&&(t="white"==i.midColor?n.parasCls.thr().setRGB(1-r,1,1-r):n.parasCls.thr().setRGB(0,r,0)):"red"==i.endColor?t="white"==i.midColor?n.parasCls.thr().setRGB(1,1-o,1-o):n.parasCls.thr().setRGB(o,0,0):"green"==i.endColor?t="white"==i.midColor?n.parasCls.thr().setRGB(1-o,1,1-o):n.parasCls.thr().setRGB(0,o,0):"blue"==i.endColor&&(t="white"==i.midColor?n.parasCls.thr().setRGB(1-o,1-o,1):n.parasCls.thr().setRGB(0,0,o))}else t=n.parasCls.defaultAtomColor;i.atoms[e].color=t,i.atomPrevColors[e]=t}break;case"charge":for(let e in t){let t=i.atoms[e];t.color=t.het?n.parasCls.defaultAtomColor:n.parasCls.chargeColors[t.resn]||n.parasCls.defaultResidueColor,i.atomPrevColors[e]=t.color}break;case"hydrophobic":for(let e in t){let t=i.atoms[e];t.color=t.het?n.parasCls.defaultAtomColor:n.parasCls.hydrophobicColors[t.resn]||n.parasCls.defaultResidueColor,i.atomPrevColors[e]=t.color}break;case"normalized hydrophobic":for(let e in t){let t=i.atoms[e];t.color=t.het?n.parasCls.defaultAtomColor:n.parasCls.normalizedHPColors[t.resn]||n.parasCls.defaultResidueColor,i.atomPrevColors[e]=t.color}break;case"atom":for(let e in t){let t=i.atoms[e];t.color=n.parasCls.atomColors[t.elem]||n.parasCls.defaultAtomColor,i.atomPrevColors[e]=t.color}break;case"confidence":for(let e in t){let t=i.atoms[e];if(void 0===t.b||isNaN(t.b)||0==parseInt(1e3*t.b))t.color=n.parasCls.thr().setRGB(0,1,0);else{let e=t.b;e=t.structure.substr(0,4)!=i.defaultPdbId&&t.structure.length<6?100-e:e,e>=90?t.color=n.parasCls.thr().setRGB(0,.325,.839):e>=70&&e<90?t.color=n.parasCls.thr().setRGB(.396,.572,.953):e>=50&&e<70?t.color=n.parasCls.thr().setRGB(1,.859,.075):e<50&&(t.color=n.parasCls.thr().setRGB(1,.49,.271))}i.atomPrevColors[e]=t.color}break;case"b factor":i.middB=50,i.spanBinv1=.02,i.spanBinv2=.02;for(let e in t){let t=i.atoms[e];if(void 0===t.b||isNaN(t.b)||0==parseInt(1e3*t.b))t.color=n.parasCls.thr().setRGB(0,1,0);else{let e=t.b;e>100&&(e=100),e=t.structure.substr(0,4)!=i.defaultPdbId&&t.structure.length>5?100-e:e;let s=(i.middB-e)*i.spanBinv1,l=(e-i.middB)*i.spanBinv2;t.color=e<i.middB?n.parasCls.thr().setRGB(1-s,1-s,1):n.parasCls.thr().setRGB(1,1-l,1-l)}i.bOpm&&"DUM"==t.resn&&(t.color=n.parasCls.atomColors[t.elem]),i.atomPrevColors[e]=t.color}break;case"b factor percentile":if(o=1e3,a=-1e3,!i.bfactorArray){i.bfactorArray=[];for(let e in i.atoms){let t=i.atoms[e];o>t.b&&(o=t.b),a<t.b&&(a=t.b),i.bfactorArray.push(t.b)}i.bfactorArray.sort((function(e,t){return e-t}))}let b=i.bfactorArray.length;for(let e in t){let t=i.atoms[e];if(void 0===t.b||isNaN(t.b)||0==parseInt(1e3*t.b)||0==i.bfactorArray.length)t.color=n.parasCls.thr().setRGB(0,1,0);else{let e=t.structure>5?100-t.b:t.b,s=i.bfactorArray.indexOf(e)/b;t.color=s<.5?n.parasCls.thr().setRGB(2*s,2*s,1):n.parasCls.thr().setRGB(1,2*(1-s),2*(1-s))}i.atomPrevColors[e]=t.color}break;case"area":if(void 0===i.resid2area){let e=n.hashUtilsCls.cloneHash(i.hAtoms);i.hAtoms=n.hashUtilsCls.cloneHash(i.atoms),i.bCalcArea=!0,i.opts.surface="solvent accessible surface",i.applyMapCls.applySurfaceOptions(),i.bCalcArea=!1,i.hAtoms=n.hashUtilsCls.cloneHash(e)}let y=void 0!==i.midpercent?i.midpercent:35;i.spanBinv1=.02,i.spanBinv2=.02;for(let e in t){let t=i.atoms[e],s=t.structure+"_"+t.chain+"_"+t.resi+"_"+t.resn,l=n.parasCls.residueArea.hasOwnProperty(t.resn)?i.resid2area[s]/n.parasCls.residueArea[t.resn]*100:y;l>100&&(l=100);let r=(y-l)*i.spanBinv1,o=(l-y)*i.spanBinv2;t.color=l<y?n.parasCls.thr().setRGB(1-r,1-r,1):n.parasCls.thr().setRGB(1,1-o,1-o),i.bOpm&&"DUM"==t.resn&&(t.color=n.parasCls.atomColors[t.elem]),i.atomPrevColors[e]=t.color}break;case"identity":case"conserved":this.setConservationColor(t,!0);break;case"conservation":this.setConservationColor(t,!1);break;case"white":this.setAtmClr(t,16777215);break;case"grey":this.setAtmClr(t,8947848);break;case"red":this.setAtmClr(t,16711680);break;case"green":this.setAtmClr(t,65280);break;case"blue":this.setAtmClr(t,255);break;case"magenta":this.setAtmClr(t,16711935);break;case"yellow":this.setAtmClr(t,16776960);break;case"cyan":this.setAtmClr(t,65535);break;case"custom":break;default:for(let s in t){let t=i.atoms[s];t.color=n.parasCls.thr().setStyle("#"+e.color.toLowerCase()),i.atomPrevColors[s]=t.color}}i.legendTableCls.showColorLegend(e.color.toLowerCase())}}setAtmClr(e,t){let s=this.icn3d,i=s.icn3dui;for(let n in e){let e=s.atoms[n];e.color=i.parasCls.thr().setHex(t),s.atomPrevColors[n]=e.color}}updateChainsColor(e){let t=this.icn3d;t.icn3dui;let s=e.structure+"_"+e.chain;void 0!==t.chainsColor[s]&&(t.chainsColor[s]=e.color)}setMmdbChainColor(e){let t,s=this.icn3d,i=s.icn3dui,n=void 0===e?s.hAtoms:e;this.applyOriginalColor(i.hashUtilsCls.hash2Atoms(n,s.atoms)),t=i.hashUtilsCls.unionHash(t,s.chemicals),t=i.hashUtilsCls.unionHash(t,s.ions);for(let e in t){let t=s.atoms[e];t.color=i.parasCls.atomColors[t.elem]||i.parasCls.defaultAtomColor,s.atomPrevColors[e]=t.color}}setConservationColor(e,t){let s=this.icn3d,i=s.icn3dui;this.setMmdbChainColor(e);for(let n in s.alnChainsSeq){let l=s.alnChainsSeq[n];for(let r=0,o=l.length;r<o;++r){let o=n+"_"+l[r].resi;for(let n in s.residues[o])if(e.hasOwnProperty(n)){let e=t?i.parasCls.thr(l[r].color):i.parasCls.thr(l[r].color2);s.atoms[n].color=e,s.atomPrevColors[n]=e}}}}applyOriginalColor(e){let t=this.icn3d,s=t.icn3dui;void 0===e&&(e=t.atoms);for(let i in e){let n=e[i],l=n.structure+"_"+n.chain;t.chainsColor.hasOwnProperty(l)?n.color=t.chainsColor[l]:n.color=s.parasCls.atomColors[n.elem],t.atomPrevColors[i]=n.color}}applyPrevColor(){let e=this.icn3d;e.icn3dui;for(let t in e.atoms){e.atoms[t].color=e.atomPrevColors[t]}}setOutlineColor(e){this.icn3d.icn3dui;let t={outline:{vertex_shader:["uniform float offset;","void main() {","vec4 pos = modelViewMatrix * vec4( position + normal * offset, 1.0 );","gl_Position = projectionMatrix * pos;","}"].join("\n"),fragment_shader:["void main(){","gl_FragColor = vec4( 1.0, 1.0, 0.0, 1.0 );","}"].join("\n")}};"yellow"===e?t.outline.fragment_shader=["void main(){","gl_FragColor = vec4( 1.0, 1.0, 0.0, 1.0 );","}"].join("\n"):"green"===e?t.outline.fragment_shader=["void main(){","gl_FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );","}"].join("\n"):"red"===e&&(t.outline.fragment_shader=["void main(){","gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );","}"].join("\n"));let s=t.outline;return new THREE.ShaderMaterial({uniforms:{offset:{type:"f",value:.5}},vertexShader:s.vertex_shader,fragmentShader:s.fragment_shader,depthTest:!1,depthWrite:!1})}}class bt{constructor(e){this.icn3d=e}setOption(e,t){var s=this.icn3d;s.icn3dui,s.opts[e]=t,s.selectionCls.saveSelectionIfSelected(),"color"===e?(s.setColorCls.setColorByOptions(s.opts,s.hAtoms),s.drawCls.draw(),s.hlUpdateCls.updateHlAll(),s.getGraphCls.updateGraphColor()):"surface"===e||"opacity"===e||"wireframe"===e?("opacity"!==e&&"wireframe"!==e||s.applyMapCls.removeLastSurface(),s.applyMapCls.applySurfaceOptions(),s.drawCls.draw()):"map"===e||"mapwireframe"===e?("mapwireframe"===e&&s.applyMapCls.removeLastMap(),s.applyMapCls.applyMapOptions(),s.drawCls.draw()):"emmap"===e||"emmapwireframe"===e?("emmapwireframe"===e&&s.applyMapCls.removeLastEmmap(),s.applyMapCls.applyEmmapOptions(),s.drawCls.draw()):"phimap"===e||"phimapwireframe"===e?("phimapwireframe"===e&&s.applyMapCls.removeLastPhimap(),s.applyMapCls.applyPhimapOptions(),s.drawCls.draw()):"phisurface"===e?(s.applyMapCls.applyphisurfaceOptions(),s.drawCls.draw()):"chemicalbinding"===e?(s.bSkipChemicalbinding=!1,s.drawCls.draw()):s.drawCls.draw()}setStyle(e,t){var s=this.icn3d,i=s.icn3dui;let n={};switch(e){case"proteins":if(n=i.hashUtilsCls.intHash(s.hAtoms,s.proteins),Object.keys(s.hAtoms).length,Object.keys(s.proteins).length,"nothing"==t){s.opts.ssbonds="no",s.lines.ssbond=[];for(let e in n)s.atoms[e].style2="nothing"}else s.opts.ssbonds="yes";break;case"sidec":n=i.hashUtilsCls.intHash(s.hAtoms,s.sidec);break;case"nucleotides":n=i.hashUtilsCls.intHash(s.hAtoms,s.nucleotides),Object.keys(s.hAtoms).length,Object.keys(s.nucleotides).length;break;case"ntbase":n=i.hashUtilsCls.intHash(s.hAtoms,s.ntbase);break;case"chemicals":n=i.hashUtilsCls.intHash(s.hAtoms,s.chemicals);break;case"ions":n=i.hashUtilsCls.intHash(s.hAtoms,s.ions);break;case"water":n=i.hashUtilsCls.intHash(s.hAtoms,s.water)}if("sidec"===e||"ntbase"===e)for(let e in n)s.atoms[e].style2=t;else for(let e in n)s.atoms[e].style=t;s.opts[e]=t,s.selectionCls.saveSelectionIfSelected(),s.drawCls.draw()}saveStyle(){var e=this.icn3d;e.icn3dui;for(let t in e.atoms){let s=e.atoms[t];s.styleSave=s.style,void 0!==s.style2&&(s.style2Save=s.style2)}}applySavedStyle(){var e=this.icn3d;e.icn3dui;for(let t in e.atoms){let s=e.atoms[t];void 0!==s.styleSave&&(s.style=s.styleSave),void 0!==s.style2Save&&(s.style2=s.style2Save)}e.drawCls.draw()}saveColor(){var e=this.icn3d;e.icn3dui;for(let t in e.atoms){let s=e.atoms[t];s.colorSave=s.color.clone()}}applySavedColor(){var e=this.icn3d;e.icn3dui;for(let t in e.atoms){let s=e.atoms[t];void 0!==s.colorSave&&(s.color=s.colorSave.clone(),e.atomPrevColors[t]=s.color)}e.hlUpdateCls.changeSeqColor(Object.keys(e.residues)),e.drawCls.draw()}}class yt{constructor(e){this.icn3d=e}showColorLegend(e){let t=this.icn3d,s=t.icn3dui,i=e.substr(0,1).toUpperCase()+e.substr(1);"confidence"==e?i="pLDDT":"normalized hydrophobic"==e?i="Normalized Hydrophobicity":"hydrophobic"==e?i="Hydrophobicity":"ig strand"==e?i="Ig Strand":"ig protodomain"==e?i="Ig Protodomain":"exon"==e&&(i="Exon");let n="Color by <b>"+i+"</b><br><br>";if("atom"==e){let e=["proteins","nucleotides","chemicals","ions","water"];for(let i=0,l=e.length;i<l;++i){let l=e[i],r=s.hashUtilsCls.intHash(t[l],t.hAtoms);n+=this.getColorLegendForElem(l,r)}}else if("residue"==e)n+=this.getColorLegendForResidue(t.hAtoms);else if("charge"==e)n+=this.getColorLegendForCharge(t.hAtoms);else if("ig strand"==e)n+=this.getColorLegendForIgstrand(t.hAtoms);else if("ig protodomain"==e)n+=this.getColorLegendForIgproto(t.hAtoms);else if("normalized hydrophobic"==e||"hydrophobic"==e){let i=!0,o=this.getRes2color(t.hAtoms,i);var l=Object.keys(o).map((e=>[e,s.parasCls.hydrophobicValues[e]]));l.sort(((e,t)=>parseFloat(e[1])-parseFloat(t[1])));var r=l.map((e=>[e[0],Object.keys(o[e[0]])[0]]));n+="<div>","normalized hydrophobic"==e?(n+="Dark green (W, F, L, I, Y, M, V, C): Hydrophobic<br>",n+="Light green (P, T, S, A, Q, N, G): Polar<br>",n+="Grey: Charged, not hydrophobic<br><br>"):(n+="Green (W, F, L, I, Y, M, V, C): Hydrophobic<br>",n+="Yellow (P, T, S, A, Q, N, G): Polar<br>",n+="Red: Negatively Charged<br>",n+="Blue: Positively Charged<br><br>");let a=0;for(let e of r)s.parasCls.residueAbbrev[e[0]]&&(n+="<div style='display:inline-block; width:100px'>",n+="<div style='width: 10px; height: 10px; background-color:#"+e[1]+"; border: 0px;display:inline-block;' ></div> ",n+=s.parasCls.residueAbbrev[e[0]]+"</div>",a%4==3&&(n+="<br>"),++a);n+="</div>"}else"b factor"==e?(n+="<div style='width:450px'>B factor quantitates the uncertainty for each atom. A high B factor reflects that the position is less certain.</div><br>",n+=s.htmlCls.clickMenuCls.setLegendHtml()):"confidence"==e?n+=s.htmlCls.clickMenuCls.setLegendHtml(!0):"exon"==e?(t.startColor="red",t.midColor="white",t.endColor="blue",t.startValue="Start",t.midValue="Middle",t.endValue="End",n+=s.htmlCls.clickMenuCls.setLegendHtml()):n="";n?($("#"+s.pre+"dl_legend_html").html(n),s.htmlCls.dialogCls.openDlg("dl_legend","Color Legend")):$("#"+s.pre+"dl_legend").hasClass("ui-dialog-content")&&$("#"+s.pre+"dl_legend").dialog("isOpen")&&$("#"+s.pre+"dl_legend").dialog("close")}getColorLegendForElem(e,t){let s=this.icn3d,i=s.icn3dui,n="",l={};for(let e in t){let t=s.atoms[e],i=void 0===t||void 0===t.color||"FFFFFF"===t.color.getHexString().toUpperCase()?"DDDDDD":t.color.getHexString();void 0===l[t.elem]&&(l[t.elem]={}),l[t.elem][i]=1}if(Object.keys(l).length>0){n+="<b>"+e+"</b><br>";let t=Object.keys(l).sort();for(let e=0,s=t.length;e<s;++e){let s=t[e];n+="<span>";for(let e in l[s])n+="<div style='width: 10px; height: 10px; background-color:#"+e+"; border: 0px;display:inline-block;' ></div> ";n+=i.parasCls.atomnames[s.toUpperCase()]+"</span><br>"}n+="<br>"}return n}getRes2color(e,t){let s=this.icn3d,i=s.icn3dui,n={},l=s.firstAtomObjCls.getResiduesFromAtoms(e);for(let e in l){let l=s.residues[e],r=s.firstAtomObjCls.getFirstAtomObj(l),o=t?r.resn:i.parasCls.residueAbbrev[r.resn],a=void 0===r||void 0===r.color||"FFFFFF"===r.color.getHexString().toUpperCase()?"DDDDDD":r.color.getHexString();null!=o&&(void 0===n[o]&&(n[o]={}),n[o][a]=1)}return n}getColorLegendForResidue(e){this.icn3d.icn3dui;let t="",s=this.getRes2color(e);if(Object.keys(s).length>0){t+="<div>";let e=Object.keys(s).sort(),i="",n=0;for(let l=0,r=e.length;l<r;++l){let r="",o=e[l];r+="<div style='display:inline-block; width:100px'>";for(let e in s[o])r+="<div style='width: 10px; height: 10px; background-color:#"+e+"; border: 0px;display:inline-block;' ></div> ";r+=o+"</div>",n%4==3&&(r+="<br>"),-1!=o.indexOf("(")?(t+=r,++n):i+=r}i&&(t+="<br>"+i),t+="</div>"}return t}getColorLegendForCharge(e){let t=this.icn3d;t.icn3dui;let s="",i=t.firstAtomObjCls.getResiduesFromAtoms(e),n={};for(let e in i){let s=t.residues[e],i=t.firstAtomObjCls.getFirstAtomObj(s);"ARG"==i.resn||"LYS"==i.resn?n.Positive=1:"HIS"==i.resn?n["Partial-Positive"]=1:"ASP"==i.resn||"GLU"==i.resn||t.nucleotides[i.serial]?n.Negative=1:n.Neutral=1}const l={Positive:"0000ff","Partial-Positive":"8080ff",Negative:"ff0000",Neutral:"888888"};let r=["Positive","Partial-Positive","Negative","Neutral"];s+="<div>";for(let e=0,t=r.length;e<t;++e){let t=r[e];n[t]&&(s+="<span>",s+="<div style='width: 10px; height: 10px; background-color:#"+l[t]+"; border: 0px;display:inline-block;' ></div> ",s+=t,s+="</span><br>")}return s+="<br>(Charges are at pH 7)",s+="</div>",s}getColorLegendForIgstrand(e){this.icn3d.icn3dui;let t="";const s={"A Strand":"9400D3","B Strand":"ba55d3","C Strand":"0000FF","C' Strand":"6495ED","C'' Strand":"006400","D Strand":"00FF00","E Strand":"FFD700","F Strand":"FF8C00","G Strand":"FF0000",Loop:"CCCCCC"};t+="<div>";for(let e in s){t+="<span>",t+="<div style='width: 10px; height: 10px; background-color:#"+s[e]+"; border: 0px;display:inline-block;' ></div> ",t+=e,t+="</span><br>"}return t+="</div>",t}getColorLegendForIgproto(e){this.icn3d.icn3dui;let t="";const s={"<b>Protodomain 1</b>":"","A Strand":"0000FF","B Strand":"006400","C Strand":"FFD700","C' Strand":"FF8C00","<br><b>Linker</b>":"","C'' Strand":"FF0000","<br><b>Protodomain 2</b>":"","D Strand":"0000FF","E Strand":"006400","F Strand":"FFD700","G Strand":"FF8C00","":"",Loop:"CCCCCC"};t+="<div>A protodomain is a supersecondary structure <br>that by its duplication, symmetry operations <br>can generate a structural domain.<br><br>";for(let e in s){let i=s[e];t+="<span>",i&&(t+="<div style='width: 10px; height: 10px; background-color:#"+i+"; border: 0px;display:inline-block;' ></div> "),t+=e,t+="</span><br>"}return t+="</div>",t}}class vt{constructor(e){this.icn3d=e}async showCddSiteAll(){let e=this.icn3d,t=e.icn3dui,s=this;e.chainid2pssmid={};let i=$.map(e.protein_chainid,(function(e){return e})),n=Object.keys(e.protein_chainid),l="https://www.ncbi.nlm.nih.gov/Structure/cdannots/cdannots.fcgi?fmt&frclive&live=lcl&queries="+i;if(1==Object.keys(e.structures).length&&!t.cfg.afid&&(t.cfg.mmtfid||t.cfg.pdbid||t.cfg.opmid||t.cfg.mmdbid||t.cfg.gi||t.cfg.uniprotid||t.cfg.blast_rep_id||t.cfg.cid||t.cfg.mmcifid)||2==Object.keys(e.structures).length&&t.cfg.align){let e={};try{t.bNode?e=await t.getAjaxPromise(l,"jsonp"):e.value=await t.getAjaxPromise(l,"jsonp"),s.parseCddData([e],n)}catch(e){return void s.getNoCdd(i)}}else{let i=[];for(let s=0,r=n.length;s<r;++s){let r=Array.isArray(e.giSeq[n[s]])?e.giSeq[n[s]].join("").toUpperCase():e.giSeq[n[s]].toUpperCase();r=r.replace(/O/g,""),l="https://www.ncbi.nlm.nih.gov/Structure/cdannots/cdannots.fcgi?fmt&frclive&live=lcl&queries="+r;let o=t.getAjaxPromise(l,"jsonp");i.push(o)}let r=Promise.allSettled(i);try{let e=await r;s.parseCddData(e,n,!0)}catch(e){}}}parseCddData(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this,r={};n.bNode&&(i.resid2cdd||(i.resid2cdd={}),i.resid2site||(i.resid2site={}));for(let o=0,a=e.length;o<a;++o){let a=n.bNode?e[o]:e[o].value;if(a)for(let e=0,d=a.data.length;e<d;++e){let d=a.data[e];d._id;let c=s?t[o]:t[e];r[c]=1;let h='<div id="'+i.pre+c+'_cddseq_sequence" class="icn3d-cdd icn3d-dl_sequence">',p=h,m=h,u=d.doms;n.bNode&&!i.resid2cdd[c]&&(i.resid2cdd[c]=[]);let g=l.setDomainFeature(u,c,"domain",h,p,m);i.chainid2pssmid[c]={pssmid2name:g.pssmid2name,pssmid2fromArray:g.pssmid2fromArray,pssmid2toArray:g.pssmid2toArray};let f=g.acc2domain;h=g.html+"</div>",p=g.html2+"</div>",m=g.html3+"</div>",$("#"+i.pre+"dt_cdd_"+c).html(h),$("#"+i.pre+"ov_cdd_"+c).html(p),$("#"+i.pre+"tt_cdd_"+c).html(m),h='<div id="'+i.pre+c+'_siteseq_sequence" class="icn3d-dl_sequence">',p=h,m=h;let C=d.motifs;n.bNode&&!i.resid2site[c]&&(i.resid2site[c]=[]),g=l.setDomainFeature(C,c,"feat",h,p,m,f),h=g.html,p=g.html2,m=g.html3;let b=a.data[e].sites,y=void 0!==b?b.length:0;for(let e=0;e<y;++e){b[e].srcdom,b[e].type;let t=b[e].sz,s="site: "+b[e].title;s.length>17&&(s=s.substr(0,17)+"...");let l,r=b[e].title,o=[];for(let t=0,s=b[e].locs.length;t<s;++t){l=b[e].locs[t].coords;for(let e=0,t=l.length;e<t;++e)o.push(i.ParserUtilsCls.getResi(c,Math.round(l[e])))}let a=!1;for(let e=0,t=o.length;e<t;++e){let t=c+"_"+o[e];if(i.residues.hasOwnProperty(t)){a=!0;break}}let d='<div class="icn3d-seqTitle '+(a?"icn3d-link icn3d-blue":"")+'" site="site" posarray="'+l.toString()+'" shorttitle="'+s+'" setname="'+c+"_site_"+e+'" anno="sequence" chain="'+c+'" title="'+r+'">'+s+" </div>",u='<span class="icn3d-residueNum" title="residue count">'+t.toString()+" Res</span>",g='<span class="icn3d-seqLine">';m+=d+u+"<br>",h+=d+u+g,p+=d+u+g;let f="site"+e.toString(),C=0,y=0,v=1;i.seqStartLen&&i.seqStartLen[c]&&(p+=i.showSeqCls.insertMulGapOverview(c,i.seqStartLen[c])),i.seqStartLen&&i.seqStartLen[c]&&(h+=i.showSeqCls.insertMulGap(i.seqStartLen[c],"-"));for(let t=0,s=i.giSeq[c].length;t<s;++t)if(h+=i.showSeqCls.insertGap(c,t,"-"),-1!=l.indexOf(t)){let s=i.giSeq[c][t],l=s;s.length>1&&(l=s[0]+"..");let r=i.ParserUtilsCls.getResi(c,t);if(h+='<span id="'+f+"_"+i.pre+c+"_"+r+'" title="'+l+r+'" class="icn3d-residue">'+s+"</span>",n.bNode){let t={};t[c+"_"+r]="site: "+b[e].title,i.resid2site[c].push(t)}p+=i.showSeqCls.insertGapOverview(c,t);let o=n.cfg.blast_rep_id==c?Math.round(i.seqAnnWidth*t/(i.maxAnnoLength+i.nTotalGap)-C-y):Math.round(i.seqAnnWidth*t/i.maxAnnoLength-C-y);o>=0&&(p+='<div style="display:inline-block; width:'+o+'px;">&nbsp;</div>',p+='<div style="display:inline-block; background-color:#000; width:'+v+'px;" title="'+l+r+'">&nbsp;</div>',C+=o,y+=v)}else h+="<span>-</span>";i.seqStartLen&&i.seqStartLen[c]&&(h+=i.showSeqCls.insertMulGap(i.seqEndLen[c],"-")),g='<span class="icn3d-residueNum" title="residue count">&nbsp;'+t.toString()+" Residues</span>",g+="</span>",g+="<br>",h+=g,p+=g}h+="</div>",p+="</div>",m+="</div>",$("#"+i.pre+"dt_site_"+c).html(h),$("#"+i.pre+"ov_site_"+c).html(p),$("#"+i.pre+"tt_site_"+c).html(m)}}for(let e in i.protein_chainid)r.hasOwnProperty(e)||($("#"+i.pre+"dt_cdd_"+e).html(""),$("#"+i.pre+"ov_cdd_"+e).html(""),$("#"+i.pre+"tt_cdd_"+e).html(""),$("#"+i.pre+"dt_site_"+e).html(""),$("#"+i.pre+"ov_site_"+e).html(""),$("#"+i.pre+"tt_site_"+e).html(""));i.showAnnoCls.enableHlSeq(),i.bAjaxCddSite=!0}getNoCdd(e){let t=this.icn3d;t.icn3dui,console.log("No CDD data were found for the protein "+e+"...");for(let e in t.protein_chainid)$("#"+t.pre+"dt_cdd_"+e).html(""),$("#"+t.pre+"ov_cdd_"+e).html(""),$("#"+t.pre+"tt_cdd_"+e).html(""),$("#"+t.pre+"dt_site_"+e).html(""),$("#"+t.pre+"ov_site_"+e).html(""),$("#"+t.pre+"tt_site_"+e).html("");t.showAnnoCls.enableHlSeq(),t.bAjaxCddSite=!0}setDomainFeature(e,t,s,i,n,l,r,o,a){let d,c,h,p=this.icn3d,m=p.icn3dui,u="domain"!=s&&"feat"!=s;"domain"==s&&(r={},d={},c={},h={});let g=void 0!==e?e.length:0,f="domain"==s?14:19,C="domain"==s?100:120;for(let b=0;b<g;++b){let g="domain"==s?e[b].pssmid:0,y="domain"==s?e[b].acc:"feat"==s?e[b].srcdom:"",v="domain"==s?e[b].title.split(":")[0]:"feat"==s?e[b].title:o[b];v=v.replace(/\"/g,"``"),v=v.replace(/'/g,"`"),"domain"==s&&(r[y]=v);let _="domain"==s?e[b].defline:"",w=u?o[b]:s+": "+v;w.length>f&&(w=w.substr(0,f)+"...");let S=u?a[b]:s+": "+v;"domain"==s&&(d[g]=v);let A=e[b].locs;if(A)for(let e=0,r=A.length;e<r;++e){let r=[],a=[],d={},u=0,f="domain"==s||"ig"==s?A[e].segs:[A[e]];for(let e=0,t=f.length;e<t;++e){let t=Math.round(f[e].from),s=Math.round(f[e].to);r.push(t),a.push(s);for(let e=t;e<=s;++e)d[e]=1;u+=s-t+1}let x=t+"_"+v;"domain"!=s&&(x=t+"_"+b+"_"+e+"_"+v),"domain"==s&&(c[g]=r),"domain"==s&&(h[g]=a);let k=!1;for(let e=0,s=r.length;e<s;++e){let s=parseInt(r[e]),i=parseInt(a[e]);for(let e=s;e<=i;++e){let s=t+"_"+p.ParserUtilsCls.getResi(t,e);if(p.residues.hasOwnProperty(s)){k=!0;break}}if(k)break}let O=k?"icn3d-link icn3d-blue":"",R='<div class="icn3d-seqTitle '+O+'" '+s+'="'+y+'" from="'+r+'" to="'+a+'" shorttitle="'+w+'" setname="'+x+'" anno="sequence" chain="'+t+'" title="'+S+'">'+w+" </div>",I='<span class="icn3d-residueNum" title="residue count">'+u.toString()+" Res</span>";l+=R+I+"<br>";let E='<span class="icn3d-seqLine">';i+=R+I+E,"domain"==s&&(n+='<div style="width:20px; display:inline-block;"><span id="'+p.pre+t+"_"+y+"_"+e+'_cddseq_expand" class="ui-icon ui-icon-plus icn3d-expand icn3d-link" style="width:15px;" title="Expand"></span><span id="'+p.pre+t+"_"+y+"_"+e+'_cddseq_shrink" class="ui-icon ui-icon-minus icn3d-shrink icn3d-link" style="display:none; width:15px;" title="Shrink"></span></div>'),n+='<div style="width:'+C+'px!important;" class="icn3d-seqTitle '+O+'" '+s+'="'+y+'" from="'+r+'" to="'+a+'" shorttitle="'+w+'" index="'+b+'" setname="'+x+'" anno="sequence" chain="'+t+'" title="'+S+'">'+w+" </div>",n+=I+E;let T=s+b.toString();p.seqStartLen&&p.seqStartLen[t]&&(i+=p.showSeqCls.insertMulGap(p.seqStartLen[t],"-"));for(let e=0,n=p.giSeq[t].length;e<n;++e)if(i+=p.showSeqCls.insertGap(t,e,"-"),d.hasOwnProperty(e)){let n=p.giSeq[t][e],l=n;n.length>1&&(l=n[0]+"..");let r=p.ParserUtilsCls.getResi(t,e);if(i+='<span id="'+T+"_"+p.pre+t+"_"+r+'" title="'+l+r+'" class="icn3d-residue">'+n+"</span>",m.bNode){let e={};e[t+"_"+r]=S,"domain"==s?p.resid2cdd[t].push(e):p.resid2site[t].push(e)}}else i+="<span>-</span>";if(p.seqStartLen&&p.seqStartLen[t]&&(i+=p.showSeqCls.insertMulGap(p.seqEndLen[t],"-")),p.seqStartLen&&p.seqStartLen[t]&&(n+=p.showSeqCls.insertMulGapOverview(t,p.seqStartLen[t])),m.cfg.blast_rep_id!=t){let i;for(let l=0,d=r.length;l<d;++l){let d;0==l&&(i=this.getColorFromPos(t,r[l],o)),d=0==l?Math.round(p.seqAnnWidth*r[l]/p.maxAnnoLength):Math.round(p.seqAnnWidth*(r[l]-a[l-1]-1)/p.maxAnnoLength),n+='<div style="display:inline-block; width:'+d+'px;">&nbsp;</div>',n+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+i+"; width:"+Math.round(p.seqAnnWidth*(a[l]-r[l]+1)/p.maxAnnoLength)+'px;" class="icn3d-seqTitle '+O+'" '+s+'="'+(b+1).toString()+'" from="'+r+'" to="'+a+'" shorttitle="'+w+'" index="'+b+'" setname="'+x+'" id="'+t+"_domain_"+b+"_"+e+'" anno="sequence" chain="'+t+'" title="'+S+'">'+v+" </div>"}}else{let i=[],l=[];for(let e=0,t=r.length;e<t;++e){i.push(r[e]);for(let t=parseInt(r[e]);t<=parseInt(a[e]);++t)void 0!==p.targetGapHash&&p.targetGapHash.hasOwnProperty(t)&&(l.push(t-1),i.push(t));l.push(a[e])}for(let r=0,a=i.length;r<a;++r){let a=this.getColorFromPos(t,i[r],o);n+=p.showSeqCls.insertGapOverview(t,i[r]),n+='<div style="display:inline-block; width:'+(0==r?Math.round(p.seqAnnWidth*(i[r]-p.baseResi[t]-1)/(p.maxAnnoLength+p.nTotalGap)):Math.round(p.seqAnnWidth*(i[r]-l[r-1]-1)/(p.maxAnnoLength+p.nTotalGap)))+'px;">&nbsp;</div>',n+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+a+"; width:"+Math.round(p.seqAnnWidth*(l[r]-i[r]+1)/(p.maxAnnoLength+p.nTotalGap))+'px;" class="icn3d-seqTitle '+O+'" '+s+'="'+(b+1).toString()+'" from="'+i+'" to="'+l+'" shorttitle="'+w+'" index="'+b+'" setname="'+x+'" id="'+t+"_domain_"+b+"_"+e+'" anno="sequence" chain="'+t+'" title="'+S+'">'+v+" </div>"}}E='<span class="icn3d-residueNum" title="residue count">&nbsp;'+u.toString()+" Residues</span>",E+="</span>",E+="<br>",i+=E,n+=E,"domain"==s&&(n+='<div id="'+p.pre+t+"_"+y+"_"+e+'_cddseq" style="display:none; white-space:normal;" class="icn3d-box">'+_+'(<a href="'+m.htmlCls.baseUrl+"cdd/cddsrv.cgi?uid="+y+'" target="_blank" class="icn3d-blue">open details view...</a>)</div>')}}return{html:i,html2:n,html3:l,acc2domain:r,pssmid2name:d,pssmid2fromArray:c,pssmid2toArray:h}}getColorFromPos(e,t,s){let i,n=this.icn3d;n.icn3dui;let l=e+"_"+n.ParserUtilsCls.getResi(e,t),r=n.firstAtomObjCls.getFirstAtomObj(n.residues[l]),o=r&&void 0!==r.color&&"FFFFFF"!==r.color.getHexString()?r.color.getHexString():"DDDDDD";return i=r&&void 0!==r.color?o:"CCCCCC",i}showAnnoType(e,t,s,i,n,l){let r=this.icn3d,o=r.icn3dui,a='<div id="'+r.pre+e+"_"+s+'seq_sequence" class="icn3d-dl_sequence">',d=a,c=a;if(0==n.length)return $("#"+r.pre+"dt_"+s+"_"+e).html(""),$("#"+r.pre+"ov_"+s+"_"+e).html(""),void $("#"+r.pre+"tt_"+s+"_"+e).html("");let h=i;i.length>17&&(i=i.substr(0,17)+"...");let p=[];for(let e=0,t=n.length;e<t;++e){let t=n[e].substr(n[e].lastIndexOf("_")+1);p.push(t)}let m=p.length,u=s,g='<div class="icn3d-seqTitle icn3d-link icn3d-blue" '+s+'="" posarray="'+p.toString()+'" shorttitle="'+i+'" setname="'+e+"_"+u+'" anno="sequence" chain="'+e+'" title="'+h+'">'+i+" </div>",f='<span class="icn3d-residueNum" title="residue count">'+m.toString()+" Res</span>";c+=g+f+"<br>";let C='<span class="icn3d-seqLine">';a+=g+f+C,d+=g+f+C;let b=s,y=0,v=0;r.seqStartLen&&r.seqStartLen[e]&&(d+=r.showSeqCls.insertMulGapOverview(e,r.seqStartLen[e])),r.seqStartLen&&r.seqStartLen[e]&&(a+=r.showSeqCls.insertMulGap(r.seqStartLen[e],"-"));for(let t=0,i=r.giSeq[e].length;t<i;++t){a+=r.showSeqCls.insertGap(e,t,"-");let i=r.ParserUtilsCls.getResi(e,t);if(-1!=p.indexOf(i)){let n=r.giSeq[e][t],c=n;n.length>1&&(c=n[0]+"..");let h=i,p=e+"_"+i,m=n+i;if("ssbond"==s){m="Residue "+p+" has disulfide bond with";let t="";if(void 0!==l[p])for(let e=0,s=l[p].length;e<s;++e)t+=" residue "+l[p][e];if(m+=t,o.bNode){let s={};s[p]="disulfide bond with"+t,r.resid2ssbond[e].push(s)}}else if("crosslink"==s){m="Residue "+p+" has cross-linkage with";let t="";if(void 0!==l[p])for(let e=0,s=l[p].length;e<s;++e)t+=" residue "+l[p][e];if(m+=t,o.bNode){let s={};s[p]="cross-linkage with"+t,r.resid2crosslink[e].push(s)}}else{m="Residue "+p+" has connection with";let e="";if(l&&void 0!==l[p])for(let t=0,s=l[p].length;t<s;++t)e+=" residue "+l[p][t];m+=e}a+='<span id="'+b+"_"+r.pre+e+"_"+h+'" title="'+m+'" class="icn3d-residue">'+c+"</span>",d+=r.showSeqCls.insertGapOverview(e,t);let u=o.cfg.blast_rep_id==e?Math.round(r.seqAnnWidth*t/(r.maxAnnoLength+r.nTotalGap)-y-v):Math.round(r.seqAnnWidth*t/r.maxAnnoLength-y-v);u>=0&&(d+='<div style="display:inline-block; width:'+u+'px;">&nbsp;</div>',d+='<div style="display:inline-block; background-color:#000; width:1px;" title="'+m+'">&nbsp;</div>',y+=u,v+=1)}else a+="<span>-</span>"}r.seqStartLen&&r.seqStartLen[e]&&(a+=r.showSeqCls.insertMulGap(r.seqEndLen[e],"-")),C='<span class="icn3d-residueNum" title="residue count">&nbsp;'+m.toString()+" Residues</span>",C+="</span>",C+="<br>",a+=C,d+=C,a+="</div>",d+="</div>",c+="</div>",$("#"+r.pre+"dt_"+s+"_"+e).html(a),$("#"+r.pre+"ov_"+s+"_"+e).html(d),$("#"+r.pre+"tt_"+s+"_"+e).html(c)}setToolTip(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"snp]").add("[id^="+e.pre+"clinvar]").add("[id^="+e.pre+"ssbond]").add("[id^="+e.pre+"crosslink]").tooltip({content:function(){return $(this).prop("title")},show:null,close:function(e,t){t.tooltip.hover((function(){$(this).stop(!0).fadeTo(400,1)}),(function(){$(this).fadeOut("400",(function(){$(this).remove()}))}))}})}}class _t{constructor(e){this.icn3d=e}showInteraction(e,t){this.icn3d.icn3dui,this.showInteraction_base(e,t)}showInteraction_base(e,t){let s=this.icn3d,i=s.icn3dui;i.bNode&&(s.resid2contact||(s.resid2contact={}),s.resid2contact[e]||(s.resid2contact[e]=[])),void 0===s.chainname2residues&&(s.chainname2residues={});let n=Object.keys(s.chains),l=e,r=Math.round(l.indexOf("_"));if(s.firstAtomObjCls.getFirstCalphaAtomObj(s.chains[l]),void 0===s.chainname2residues[l]){s.chainname2residues[l]={};let t=n.length;if(t>100&&void 0===i.cfg.mmdbid&&void 0===i.cfg.gi&&void 0===i.cfg.blast_rep_id&&void 0===i.cfg.align&&void 0===i.cfg.chainalign)return $("#"+s.pre+"dt_interaction_"+e).html(""),void $("#"+s.pre+"ov_interaction_"+e).html("");for(let e=0;e<t;++e){let t=n[e];if(t===l)continue;if(t.substr(0,t.indexOf("_"))!==l.substr(0,l.indexOf("_")))continue;if(r=Math.round(l.indexOf("_")),r>4)continue;let o,a=s.firstAtomObjCls.getFirstCalphaAtomObj(s.chains[t]);s.chemicals.hasOwnProperty(a.serial)?o="chemical":s.nucleotides.hasOwnProperty(a.serial)?o="nucleotide":s.ions.hasOwnProperty(a.serial)?o="ion":s.proteins.hasOwnProperty(a.serial)?o="protein":s.water.hasOwnProperty(a.serial)&&(o="water");let d=s.contactCls.getAtomsWithinAtom(i.hashUtilsCls.hash2Atoms(s.chains[l],s.atoms),i.hashUtilsCls.hash2Atoms(s.chains[t],s.atoms),4);if(0==Object.keys(d).length)continue;let c={};for(let e in d){let t=s.atoms[e];c[t.structure+"_"+t.chain+"_"+t.resi]=1}let h=t.substr(t.indexOf("_")+1)+"("+o+")";s.chainname2residues[l][h]=Object.keys(c)}}let o='<div id="'+s.pre+e+'_interseq_sequence" class="icn3d-dl_sequence">',a=o,d=o,c=0;for(let t in s.chainname2residues[e]){let n=s.chainname2residues[e][t];if(!n)continue;let l="Interact ."+t;l.length>17&&(l=l.substr(0,17)+"...");let r="Interact ."+t,h=[];for(let e=0,t=n.length;e<t;++e){let t=n[e],i=t.substr(n[e].lastIndexOf("_")+1);if(s.residues[t]){let e=Object.keys(s.residues[t])[0];(s.proteins.hasOwnProperty(e)||s.nucleotides.hasOwnProperty(e))&&h.push(i)}}let p=h.length;if(0==p)continue;let m=t.replace(/\s/g,""),u='<div class="icn3d-seqTitle icn3d-link icn3d-blue" interaction="'+(c+1).toString()+'" posarray="'+h.toString()+'" shorttitle="'+l+'" setname="'+e+"_"+m+'" anno="sequence" chain="'+e+'" title="'+r+'">'+l+" </div>",g='<span class="icn3d-residueNum" title="residue count">'+p.toString()+" Res</span>";d+=u+g+"<br>";let f='<span class="icn3d-seqLine">';o+=u+g+f,a+=u+g+f;let C="inter"+c.toString(),b=0,y=0,v=1;s.seqStartLen&&s.seqStartLen[e]&&(a+=s.showSeqCls.insertMulGapOverview(e,s.seqStartLen[e])),s.seqStartLen&&s.seqStartLen[e]&&(o+=s.showSeqCls.insertMulGap(s.seqStartLen[e],"-"));for(let t=0,n=s.giSeq[e].length;t<n;++t){o+=s.showSeqCls.insertGap(e,t,"-");let n=s.ParserUtilsCls.getResi(e,t);if(-1!=h.indexOf(n)){let l=s.giSeq[e][t],d=l;l.length>1&&(d=l[0]+"..");let c=n;if(o+='<span id="'+C+"_"+s.pre+e+"_"+c+'" title="'+l+c+'" class="icn3d-residue">'+d+"</span>",i.bNode){let t={};t[e+"_"+c]=r,s.resid2contact[e].push(t)}a+=s.showSeqCls.insertGapOverview(e,t);let h=i.cfg.blast_rep_id==e?Math.round(s.seqAnnWidth*t/(s.maxAnnoLength+s.nTotalGap)-b-y):Math.round(s.seqAnnWidth*t/s.maxAnnoLength-b-y);h>=0&&(a+='<div style="display:inline-block; width:'+h+'px;">&nbsp;</div>',a+='<div style="display:inline-block; background-color:#000; width:'+v+'px;" title="'+d+c+'">&nbsp;</div>',b+=h,y+=v)}else o+="<span>-</span>"}s.seqStartLen&&s.seqStartLen[e]&&(o+=s.showSeqCls.insertMulGap(s.seqEndLen[e],"-")),f='<span class="icn3d-residueNum" title="residue count">&nbsp;'+p.toString()+" Residues</span>",f+="</span>",f+="<br>",o+=f,a+=f,++c}o+="</div>",a+="</div>",d+="</div>",$("#"+s.pre+"dt_interaction_"+e).html(o),$("#"+s.pre+"ov_interaction_"+e).html(a),$("#"+s.pre+"tt_interaction_"+e).html(d),i.utilsCls.isMobile()?(s.hlSeqCls.selectSequenceMobile(),s.hlSeqCls.selectChainMobile()):s.hlSeqCls.selectSequenceNonMobile()}}class wt{constructor(e){this.icn3d=e}async showPTM(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=this,a=e.substr(0,e.indexOf("_")),d=e.substr(e.indexOf("_")+1);if("afmem"==s){let t={Transmembrane:[{begin:i,end:n}]};this.setAnnoPtmTransmem("transmem",t,e)}else if(a.length>5){let t,i="https://www.ebi.ac.uk/proteins/api/features/"+a;try{t=await r.getAjaxPromise(i,"json"),o.parsePTM(t,e,s)}catch{return void o.getNoPTM(e,s)}}else{let t,i=a.substr(0,4).toLowerCase(),n="https://www.ebi.ac.uk/pdbe/api/mappings/uniprot/"+i;try{t=await r.getAjaxPromise(n,"json");let a="";l.UPResi2ResiPosPerChain||(l.UPResi2ResiPosPerChain={}),l.UPResi2ResiPosPerChain[e]={};let c=t[i].UniProt,h=!1;for(let t in c){let s=c[t].mappings;for(let i=0,n=s.length;i<n;++i){let n=s[i];if(n.chain_id==d){let s=n.unp_start,i=n.unp_end,r=n.start.residue_number;n.end.residue_number-r!=i-s&&console.log("There might be some issues in the PDB to UniProt residue mapping.");for(let t=0;t<=i-s;++t)l.UPResi2ResiPosPerChain[e][t+s]=t+r-1;""!=a&&6==a.length||(a=t),h=!0}}}if(l.annoPtmData||(l.annoPtmData={}),""==a)o.getNoPTM(e,s);else if(l.annoPtmData.hasOwnProperty(a))o.parsePTM(l.annoPtmData[a],e,s);else{let t,i="https://www.ebi.ac.uk/proteins/api/features/"+a;try{t=await r.getAjaxPromise(i,"json"),l.annoPtmData[a]=t,o.parsePTM(t,e,s)}catch(t){return void o.getNoPTM(e,s)}}}catch(t){return void o.getNoPTM(e,s)}}}parsePTM(e,t,s){let i=this.icn3d;i.icn3dui.bNode&&("ptm"==s?(i.resid2ptm={},i.resid2ptm[t]=[]):(i.resid2transmem={},i.resid2transmem[t]=[]));let n={},l={};for(let t=0,i=e.features.length;t<i;++t){let i=e.features[t];if("ptm"==s&&"PTM"==i.category&&"DISULFID"!=i.type&&"CROSSLNK"!=i.type){let e="";e="CARBOHYD"==i.type?"Glycosylation":"LIPID"==i.type?"Lipidation, "+i.description:0==i.description.indexOf("Phospho")?"Phosphorylation":i.description?i.description:i.type,n[e]||(n[e]=[]),n[e].push(i)}else if("transmem"==s&&"TOPOLOGY"==i.category&&"TRANSMEM"==i.type){let e="Transmembrane";l[e]||(l[e]=[]),l[e].push(i)}}"ptm"==s?this.setAnnoPtmTransmem("ptm",n,t):this.setAnnoPtmTransmem("transmem",l,t),i.showAnnoCls.enableHlSeq(),i.bAjaxPTM=!0}setAnnoPtmTransmem(e,t,s){let i=this.icn3d,n=i.icn3dui,l=0,r="",o="",a="";r+='<div id="'+i.pre+s+"_"+e+'seq_sequence" class="icn3d-cdd icn3d-dl_sequence">',o+=r,a+=r,s.substr(0,s.indexOf("_"));for(let d in t){let c=t[d],h=[],p=!1;for(let e=0,t=c.length;e<t;++e){let t=parseInt(c[e].begin),n=parseInt(c[e].end);for(let e=t;e<=n;++e)stucture.length>5?h.push(e-1):i.UPResi2ResiPosPerChain&&i.UPResi2ResiPosPerChain[s][e]&&h.push(i.UPResi2ResiPosPerChain[s][e]),!p&&i.residues.hasOwnProperty(s+"_"+e)&&(p=!0)}if(0==h.length)continue;let m=h.length,u="ptm"==e?"PTM: "+d:"Transmembrane";u.length>17&&(u=u.substr(0,17)+"...");let g=d,f='<div class="icn3d-seqTitle '+(p?"icn3d-link icn3d-blue":"")+'" '+e+'="'+e+'" posarray="'+h.toString()+'" shorttitle="'+u+'" setname="'+s+"_"+e+"_"+l+'" anno="sequence" chain="'+s+'" title="'+g+'">'+u+" </div>",C='<span class="icn3d-residueNum" title="residue count">'+m.toString()+" Res</span>",b='<span class="icn3d-seqLine">';a+=f+C+"<br>",r+=f+C+b,o+=f+C+b;let y=e+l.toString(),v=0,_=0,w=1;i.seqStartLen&&i.seqStartLen[s]&&(o+=i.showSeqCls.insertMulGapOverview(s,i.seqStartLen[s])),i.seqStartLen&&i.seqStartLen[s]&&(r+=i.showSeqCls.insertMulGap(i.seqStartLen[s],"-"));for(let e=0,t=i.giSeq[s].length;e<t;++e)if(r+=i.showSeqCls.insertGap(s,e,"-"),-1!=h.indexOf(e)){let t=i.giSeq[s][e],l=t;t.length>1&&(l=t[0]+"..");let a=i.ParserUtilsCls.getResi(s,e);if(r+='<span id="'+y+"_"+i.pre+s+"_"+a+'" title="'+l+a+'" class="icn3d-residue">'+t+"</span>",n.bNode){let e={};e[s+"_"+a]=u,i.resid2ptm[s].push(e)}o+=i.showSeqCls.insertGapOverview(s,e);let d=n.cfg.blast_rep_id==s?Math.round(i.seqAnnWidth*e/(i.maxAnnoLength+i.nTotalGap)-v-_):Math.round(i.seqAnnWidth*e/i.maxAnnoLength-v-_);d>=0&&(o+='<div style="display:inline-block; width:'+d+'px;">&nbsp;</div>',o+='<div style="display:inline-block; background-color:#000; width:'+w+'px;" title="'+l+a+'">&nbsp;</div>',v+=d,_+=w)}else r+="<span>-</span>";i.seqStartLen&&i.seqStartLen[s]&&(r+=i.showSeqCls.insertMulGap(i.seqEndLen[s],"-")),b='<span class="icn3d-residueNum" title="residue count">&nbsp;'+m.toString()+" Residues</span>",b+="</span>",b+="<br>",r+=b,o+=b,++l}r+="</div>",o+="</div>",a+="</div>",$("#"+i.pre+"dt_"+e+"_"+s).html(r),$("#"+i.pre+"ov_"+e+"_"+s).html(o),$("#"+i.pre+"tt_"+e+"_"+s).html(a)}getNoPTM(e,t){let s=this.icn3d;s.icn3dui,console.log("No PTM data were found for the chain "+e+"...");let i="ptm"==t?"ptm":"transmem";$("#"+s.pre+"dt_"+i+"_"+e).html(""),$("#"+s.pre+"ov_"+i+"_"+e).html(""),$("#"+s.pre+"tt_"+i+"_"+e).html(""),s.showAnnoCls.enableHlSeq(),s.bAjaxPTM=!0}}class St{constructor(e){this.icn3d=e}async showIg(e,t){let s=this.icn3d;s.icn3dui,s.bRunRefnumAgain&&await s.refnumCls.showIgRefNum(t);let i="",n="",l="";if(s.bShowRefnum&&s.chainid2refpdbname.hasOwnProperty(e)&&s.chainid2refpdbname[e].length>0){let t=s.showSeqCls.getSeq(e),r=s.annoIgCls.showAllRefNum(t,e);i+=r.html,n+=r.html2,l+=r.html3}$("#"+s.pre+"dt_"+"ig_"+e).html(i),$("#"+s.pre+"ov_"+"ig_"+e).html(n),$("#"+s.pre+"tt_"+"ig_"+e).html(l)}showAllRefNum(e,t){let s=this.icn3d;s.icn3dui;let i="",n="",l="",r=!1;for(let i=0,n=e.length;i<n;++i){let e=t+"_"+s.ParserUtilsCls.getResi(t,i),n=s.resid2domainid[e];if(s.domainid2ig2kabat[n]&&Object.keys(s.domainid2ig2kabat[n]).length>0){r=!0;break}}let o=!1;for(let i=0,n=e.length;i<n;++i){let e=t+"_"+s.ParserUtilsCls.getResi(t,i),n=s.resid2domainid[e];if(s.domainid2ig2imgt[n]&&Object.keys(s.domainid2ig2imgt[n]).length>0){o=!0;break}}let a=this.showRefNum(e,t);i+=a.html,n+=a.html2,l+=a.html3;let d=1;return r&&(a=this.showRefNum(e,t,d),i+=a.html,n+=a.html2,l+=a.html3),d=2,o&&(a=this.showRefNum(e,t,d),i+=a.html,n+=a.html2,l+=a.html3),{html:i,html2:n,html3:l}}showRefNum(e,t,s,i){let n=this.icn3d;if(n.icn3dui,n.chainid2igtrack){if(!n.chainid2igtrack[t])return{html:"",html2:"",html3:""}}let l=this.getIgAnnoHtml(t,e,i,s);return n.bShowRefnum&&(n.opts.color="ig strand",n.setColorCls.setColorByOptions(n.opts,n.chains[t])),l}setChain2igArray(e,t,s){let i,n=this.icn3d;n.icn3dui;let l={};for(let r=0,o=t.length;r<o;++r){let t=e+"_"+n.ParserUtilsCls.getResi(e,r),o=s?0:n.resid2domainid[t];i=n.resid2refnum[t],i&&(l[o]||(l[o]=[]),l[o].push(r))}for(let t in l){let s,i,r=l[t],o=[],a=[];for(let e=0,t=r.length;e<t;++e)s=r[e],0==e&&o.push(s),e>0&&s!=i+1&&(a.push(i),o.push(s)),i=s;a.push(s);let d={};d.domainid=t,d.startPosArray=o,d.endPosArray=a,n.chain2igArray[e].push(d)}}getIgAnnoHtml(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r="",o="",a="";n.chain2igArray||(n.chain2igArray={});let d,c,h,p=!1,m="";n.chain2igArray[e]=[],this.setChain2igArray(e,t,s);let u=n.chain2igArray[e];for(let t=0,s=u.length;t<s;++t){let s=u[t].domainid;if(!n.domainid2info)continue;if(!n.domainid2info[s])continue;let i=!1,l=!1,r=!1,o=!1,a={};for(let s=0,d=u[t].startPosArray.length;s<d;++s){let d=u[t].startPosArray[s],c=u[t].endPosArray[s];for(let t=d;t<=c;++t){const s=e+"_"+n.chainsSeq[e][t].resi;a[s]=1;let d=n.resid2refnum[s];d&&(-1!=d.indexOf("B2550")&&(i=!0),-1!=d.indexOf("C3550")&&(l=!0),-1!=d.indexOf("E7550")&&(r=!0),-1!=d.indexOf("F8550")&&(o=!0))}}if(!(i&&l&&r&&o)){for(let e in a)delete n.resid2refnum[e],delete n.residIgLoop[e],delete n.resid2domainid[e];let t=Object.keys(a),s=n.setSeqAlignCls.getPosFromResi(e,t[t.length-1].split("_")[2]);for(let t=s+1,i=n.chainsSeq[e].length;t<i;++t){let s=e+"_"+n.chainsSeq[e][t].resi;if(!n.residIgLoop.hasOwnProperty(s))break;delete n.resid2refnum[s],delete n.residIgLoop[s],delete n.resid2domainid[s]}n.setSeqAlignCls.getPosFromResi(e,t[0].split("_")[2]);for(let t=s-1;t>=0;--t){let s=e+"_"+n.chainsSeq[e][t].resi;if(!n.residIgLoop.hasOwnProperty(s))break;delete n.resid2refnum[s],delete n.residIgLoop[s],delete n.resid2domainid[s]}}}n.chain2igArray[e]=[],this.setChain2igArray(e,t,s);let g="";for(let l=0,r=t.length;l<r;++l){g+=n.showSeqCls.insertGap(e,l,"-");let t=e+"_"+n.ParserUtilsCls.getResi(e,l),r=s?0:n.resid2domainid[t];d=s?n.chainsMapping[e][t]:n.resid2refnum[t];let o=!1;if(d)if(c=n.refnumCls.rmStrandFromRefnumlabel(d),m=d.replace(new RegExp(c,"g"),""),c.substr(0,1),h=s?d:1==i?n.domainid2ig2kabat[r]?n.domainid2ig2kabat[r][c]:void 0:2==i?n.domainid2ig2imgt[r]?n.domainid2ig2imgt[r][c]:void 0:c,s)if(h){g+=parseInt(h)%2==0?'<span title="'+h+'">'+h+"</span>":'<span title="'+h+'">&nbsp;</span>'}else g+="<span></span>";else if(1==i||2==i)if(h){let e=parseInt(h).toString(),t='style="color:'+this.getRefnumColor(m,!0)+'"';g+=parseInt(e.substr(e.length-2,2))%2==0?"<span "+t+' title="'+h+'">'+h+"</span>":"<span "+t+' title="'+h+'">&nbsp;</span>'}else g+="<span></span>";else" "!=m?(p=n.residIgLoop[t],g+=this.getRefnumHtml(t,h,c,d,m,p,o)):g+="<span></span>";else g+="<span></span>"}if(l.bNode)return{html:r,html2:o,html3:a};let f="icn3d-link icn3d-blue",C="IgStRAnD Ref. No.",b=n.chain2igArray[e].length,y=[],v=[],_={};for(let t=0;t<b;++t){let s=n.chain2igArray[e][t];y=y.concat(s.startPosArray),v=v.concat(s.endPosArray);for(let e=0,i=s.startPosArray.length;e<i;++e){_[s.startPosArray[e]]=t}}let w='<div style="display:inline-block" class="icn3d-residueNum" title="Ig domain count">'+b.toString()+" Ig(s)</div>",S='<div id="'+n.pre+e+'_igseq_sequence" class="icn3d-ig icn3d-dl_sequence">';s&&(S='<div class="icn3d-dl_sequence">');let A='<div style="width:120px!important;" class="icn3d-seqTitle '+f+'" ig="0" from="'+y+'" to="'+v+'" shorttitle="'+C+'" index="0" setname="'+e+'_Igs" anno="sequence" chain="'+e+'" title="IgStRAnD Reference Numbers">'+C+" </div>";if(S+='<div class="icn3d-residueLine" style="white-space:nowrap;">',s?(S+='<div class="icn3d-annoTitle" anno="0" title="Custom Reference Numbers">Custom Ref. No.</div>',S+='<span class="icn3d-residueNum"></span>'):1==i?(S+='<div class="icn3d-annoTitle" anno="0" title="Kabat Reference Numbers">Kabat Ref. No.</div>',S+='<span class="icn3d-residueNum"></span>'):2==i?(S+='<div class="icn3d-annoTitle" anno="0" title="IMGT Reference Numbers">IMGT Ref. No.</div>',S+='<span class="icn3d-residueNum"></span>'):(S+=A,S+=w),a+=S+"<br>",r+=S+'<span class="icn3d-seqLine">',n.seqStartLen&&n.seqStartLen[e]&&(r+=n.showSeqCls.insertMulGap(n.seqStartLen[e],"-")),r+=g,n.seqStartLen&&n.seqStartLen[e]&&(r+=n.showSeqCls.insertMulGap(n.seqEndLen[e],"-")),s||(r+=w),r+="</span>",r+="<br>",r+="</div>",r+="</div>",u=n.chain2igArray[e],0==u.length)return{html:r,html2:o,html3:a};let x=[],k=[],O=[],R=[];for(let e=0,t=u.length;e<t;++e){let t=u[e].domainid;if(!n.domainid2info)continue;let s=n.domainid2info[t];if(!s)continue;let i=s.score,l=parseFloat(i)<n.refnumCls.TMThresholdIgType?"Ig":n.ref2igtype[s.refpdbname];k.push(l+" (TM:"+parseFloat(i).toFixed(2)+")"),O.push(l+" (TM:"+parseFloat(i).toFixed(2)+"), template: "+s.refpdbname+", type: "+n.ref2igtype[s.refpdbname]+", Seq. identity: "+parseFloat(s.seqid).toFixed(2)+", aligned residues: "+s.nresAlign),R.push(l);let r=[];for(let t=0,s=u[e].startPosArray.length;t<s;++t)r.push({from:u[e].startPosArray[t],to:u[e].endPosArray[t]});let o={};o.locs=[{segs:r}],x.push(o)}if(0==x.length)return{html:r,html2:o,html3:a};if(!i&&!s){let t,s;o+=A,o+=w+'<span class="icn3d-seqLine">',n.seqStartLen&&n.seqStartLen[e]&&(o+=n.showSeqCls.insertMulGapOverview(e,n.seqStartLen[e]));for(let i=0,l=y.length;i<l;++i){let l=e+"_"+n.ParserUtilsCls.getResi(e,y[i]),r=_[y[i]];if(r!=t){let e=n.firstAtomObjCls.getFirstAtomObj(n.residues[l]),t=e&&void 0!==e.color&&"FFFFFF"!==e.color.getHexString()?e.color.getHexString():"DDDDDD";s=e&&void 0!==e.color?t:"CCCCCC"}o+='<div style="display:inline-block; width:'+(0==i?Math.round(n.seqAnnWidth*y[i]/n.maxAnnoLength):Math.round(n.seqAnnWidth*(y[i]-v[i-1]-1)/n.maxAnnoLength))+'px;">&nbsp;</div>',o+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+s+"; width:"+Math.round(n.seqAnnWidth*(v[i]-y[i]+1)/n.maxAnnoLength)+'px;" class="icn3d-seqTitle '+f+'" ig="0" from="'+y+'" to="'+v+'" shorttitle="'+R[r]+'" index="0" setname="'+e+'_igs" id="'+e+'_igs" anno="sequence" chain="'+e+'" title="'+R[r]+'">'+R[r]+" </div>",t=r}o+=w,o+="</div></div>",a+="</div></div>",S='<div id="'+n.pre+e+'_igseq_sequence" class="icn3d-ig icn3d-dl_sequence">';let i=S,l=S,d=n.annoCddSiteCls.setDomainFeature(x,e,"ig",S,i,l,void 0,k,O);r+=d.html+"</div>",o+=d.html2+"</div>",a+=d.html3+"</div>"}return{html:r,html2:o,html3:a}}getRefnumHtml(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui,d=parseInt(t).toString(),c=(d-1e3*parseInt(d/1e3)).toString(),h=parseInt(d.toString().substr(0,2)),p="5"!=c.substr(0,1)&&"18"!=h,m=this.getRefnumColor(n,!0),u=l?'style="color:'+m+'"':'style="color:'+m+'; text-decoration: underline overline;"',g=d.substr(d.length-2,2),f=parseInt(g);parseInt(d.substr(d.length-3,3));let C="";return!i||50!=f||p||l?i&&f%2==0&&52!=f&&!r?(g=isNaN(t)?g+t.substr(t.length-1,1):g,C+="<span "+u+' title="'+i+'">'+g+"</span>"):C+="<span "+u+' title="'+i+'">&nbsp;</span>':(o.hAtomsRefnum=a.hashUtilsCls.unionHash(o.hAtomsRefnum,o.residues[e]),C+="<span "+u+' title="'+i+'"><b>'+i.substr(0,1)+"</b>"+i.substr(1)+"</span>"),C}getRefnumColor(e,t){let s=this.icn3d.icn3dui,i=e?e.substr(0,1):"";return"C"==e?"#0000FF":"C'"==e?"#6495ED":"C''"==e?"#006400":"A"==i?"#9400D3":"B"==i?"#ba55d3":"D"==i?"#00FF00":"E"==i?"#FFD700":"F"==i?"#FF8C00":"G"==i?"#FF0000":s.htmlCls.GREYB}getProtodomainColor(e){let t=this.icn3d.icn3dui,s=e?e.substr(0,1):"";return"A"==s||"D"==s?"#0000FF":"B"==s||"E"==s?"#006400":"C"==e||"F"==s?"#FFD700":"C'"==e||"G"==s?"#FF8C00":"C''"==e?"#FF0000":t.htmlCls.GREYB}}class At{constructor(e){this.icn3d=e}showCrosslink(e,t){let s=this.icn3d;s.icn3dui;let i=this;void 0===s.clbondpnts?setTimeout((function(){i.showCrosslink_base(e,t)}),1e3):this.showCrosslink_base(e,t)}showCrosslink_base(e,t){let s=this.icn3d;s.icn3dui.bNode&&(s.resid2crosslink||(s.resid2crosslink={}),s.resid2crosslink[e]||(s.resid2crosslink[e]=[]));let i=t,n={},l=i.substr(0,i.indexOf("_")),r=s.clbondpnts[l];if(void 0===r)return $("#"+s.pre+"dt_crosslink_"+e).html(""),$("#"+s.pre+"ov_crosslink_"+e).html(""),void $("#"+s.pre+"tt_crosslink_"+e).html("");for(let e=0,t=r.length;e<t;e+=2){let t=r[e],s=r[e+1];t.substr(0,t.lastIndexOf("_")),i===s.substr(0,s.lastIndexOf("_"))&&(void 0===n[s]&&(n[s]=[]),n[s].push(t))}let o=Object.keys(n);s.annoCddSiteCls.showAnnoType(e,t,"crosslink","Cross-Linkages",o,n)}}class xt{constructor(e){this.icn3d=e}showDomainPerStructure(e){let t=this.icn3d;t.icn3dui;let s=this,i=Object.keys(t.structures)[e],n={domains:{}};for(let e in t.chains){if(i==e.substr(0,e.indexOf("_"))&&t.protein_chainid.hasOwnProperty(e)){n.domains[e]={},n.domains[e].domains=[];let s=t.chains[e],i=t.domain3dCls.c2b_NewSplitChain(s),l=i.subdomains,r=i.pos2resi;for(let t=0,s=l.length;t<s;++t){let s={intervals:[]};for(let e=0,i=l[t].length;e<i;e+=2)s.intervals.push([l[t][e],l[t][e+1]]);n.domains[e].domains.push(s)}n.domains[e].pos2resi=r}}t.mmdb_dataArray[e]=n;for(let n in t.protein_chainid)-1!==n.indexOf(i)&&s.showDomainWithData(n,t.mmdb_dataArray[e],true);t.bAjax3ddomain=!0,t.bAjaxDoneArray[e]=!0}showDomainAll(){let e=this.icn3d;e.icn3dui;let t=Object.keys(e.structures);e.mmdb_dataArray=[],e.bAjaxDoneArray=[];for(let s=0,i=t.length;s<i;++s)e.bAjaxDoneArray[s]=!1;for(let e=0,s=t.length;e<s;++e)this.showDomainPerStructure(e)}showDomainWithData(e,t,s){let i,n,l,r=this.icn3d,o=r.icn3dui,a='<div id="'+r.pre+e+'_domainseq_sequence" class="icn3d-dl_sequence">',d=a,c=a,h=e.indexOf("_"),p=e.substr(h+1);p.length>1&&"1"==p.substr(p.length-1)&&(p=p.substr(0,p.length-1)),l=e,i=t.domains[e]?t.domains[e].domains:[],n=t.domains[e].pos2resi;for(let t=0,s=i.length;t<s;++t){let s="3D domain "+(t+1).toString()+" of "+l,h=s.length>17?s.substr(0,17)+"...":s,p=i[t].intervals,m={},u={},g=[],f=[],C=[],b=[],y={},v=0;for(let e=0,t=p.length;e<t;++e){let t=Math.round(p[e][0])-1,s=Math.round(p[e][1])-1;if(!m.hasOwnProperty(t)&&!u.hasOwnProperty(s)){m[t]=1,u[s]=1,g.push(n[t]),f.push(n[s]),C.push(t),b.push(s),v+=s-t+1;for(let e=t;e<=s;++e){y[n[e]]=1}}}if(o.bNode){let s="3D domain "+(t+1).toString();r.resid2domain||(r.resid2domain={}),r.resid2domain[e]||(r.resid2domain[e]=[]);for(let t=0,i=C.length;t<i;++t){let i=parseInt(C[t]),l=parseInt(b[t]);for(let t=i;t<=l;++t){let i={};i[e+"_"+n[t]]=s,r.resid2domain[e].push(i)}}}let _='<div class="icn3d-seqTitle icn3d-link icn3d-blue" 3ddomain="'+(t+1).toString()+'" from="'+C+'" to="'+b+'" shorttitle="'+h+'" index="'+t+'" setname="'+e+"_3d_domain_"+(t+1).toString()+'" anno="sequence" chain="'+e+'" title="'+s+'">'+h+" </div>",w='<span class="icn3d-residueNum" title="residue count">'+v.toString()+" Res</span>";c+=_+w+"<br>";let S='<span class="icn3d-seqLine">';a+=_+w+S,d+=_+w+S;let A="domain3d"+t.toString();r.seqStartLen&&r.seqStartLen[e]&&(a+=r.showSeqCls.insertMulGap(r.seqStartLen[e],"-"));for(let t=0,s=r.giSeq[e].length;t<s;++t){a+=r.showSeqCls.insertGap(e,t,"-");let s=r.ParserUtilsCls.getResi(e,t);if(y.hasOwnProperty(s)){let i=r.giSeq[e][t],n=i;i.length>1&&(n=i[0]+"..");let l=s;a+='<span id="'+A+"_"+r.pre+e+"_"+l+'" title="'+n+l+'" class="icn3d-residue">'+i+"</span>"}else a+="<span>-</span>"}r.seqStartLen&&r.seqStartLen[e]&&(a+=r.showSeqCls.insertMulGap(r.seqEndLen[e],"-"));let x=r.firstAtomObjCls.getFirstCalphaAtomObj(r.chains[e]),k=void 0===x.color||"FFFFFF"===x.color.getHexString()?"DDDDDD":x.color.getHexString(),O=void 0!==x.color?k:"CCCCCC";if(r.seqStartLen&&r.seqStartLen[e]&&(d+=r.showSeqCls.insertMulGapOverview(e,r.seqStartLen[e])),o.cfg.blast_rep_id!=e)for(let i=0,n=C.length;i<n;++i){d+='<div style="display:inline-block; width:'+(0==i?Math.round(r.seqAnnWidth*C[i]/r.maxAnnoLength):Math.round(r.seqAnnWidth*(C[i]-b[i-1]-1)/r.maxAnnoLength))+'px;">&nbsp;</div>',d+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+O+"; width:"+Math.round(r.seqAnnWidth*(b[i]-C[i]+1)/r.maxAnnoLength)+'px;" class="icn3d-seqTitle icn3d-link icn3d-blue" 3ddomain="'+(t+1).toString()+'" from="'+C+'" to="'+b+'" shorttitle="'+h+'" index="'+t+'" setname="'+e+"_3d_domain_"+(t+1).toString()+'" id="'+e+"_3d_domain_"+t+'" anno="sequence" chain="'+e+'" title="'+s+'">3D domain '+(t+1).toString()+"</div>"}else{let i=[],n=[];for(let e=0,t=g.length;e<t;++e){i.push(g[e]);for(let t=parseInt(g[e]);t<=parseInt(f[e]);++t)void 0!==r.targetGapHash&&r.targetGapHash.hasOwnProperty(t)&&(n.push(t-1),i.push(t));n.push(f[e])}for(let l=0,o=i.length;l<o;++l){d+=r.showSeqCls.insertGapOverview(e,i[l]),d+='<div style="display:inline-block; width:'+(0==l?Math.round(r.seqAnnWidth*(i[l]-r.baseResi[e]-1)/(r.maxAnnoLength+r.nTotalGap)):Math.round(r.seqAnnWidth*(i[l]-n[l-1]-1)/(r.maxAnnoLength+r.nTotalGap)))+'px;">&nbsp;</div>',d+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+O+"; width:"+Math.round(r.seqAnnWidth*(n[l]-i[l]+1)/(r.maxAnnoLength+r.nTotalGap))+'px;" class="icn3d-seqTitle icn3d-link icn3d-blue" 3ddomain="'+(t+1).toString()+'" from="'+i+'" to="'+n+'" shorttitle="'+h+'" index="'+t+'" setname="'+e+"_3d_domain_"+(t+1).toString()+'" id="'+e+"_3d_domain_"+t+'" anno="sequence" chain="'+e+'" title="'+s+'">3D domain '+(t+1).toString()+"</div>"}}S='<span class="icn3d-residueNum" title="residue count">&nbsp;'+v.toString()+" Residues</span>",S+="</span>",S+="<br>",a+=S,d+=S}a+="</div>",d+="</div>",c+="</div>",$("#"+r.pre+"dt_domain_"+e).html(a),$("#"+r.pre+"ov_domain_"+e).html(d),$("#"+r.pre+"tt_domain_"+e).html(c)}}class kt{constructor(e){this.icn3d=e}async showSnp(e,t){this.icn3d.icn3dui,await this.showSnpClinvar(e,t,!0)}async showClinvar(e,t){this.icn3d.icn3dui,await this.showSnpClinvar(e,t,!1)}async showSnpClinvar(e,t,s){let i=this.icn3d.icn3dui,n=this,l=i.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?chainid="+t;try{let r=await i.getAjaxPromise(l,"jsonp"),o=r.snpgi,a=r.gi;if(s)await n.showSnpPart2(e,t,o);else{let s=o;[6137708,1942289,224510717,2624886,253723219,2554905,75765331,3660278,312207882,319443632,342350956,1827805,109157826,1065265,40889086,6730307,163931185,494469,163931091,60594093,55669745,18655489,17942684,6980537,166235465,6435586,4139398,4389047,364506122,78101667,262118402,20664221,2624640,158430173,494395,28948777,34810587,13399647,3660342,261278854,342350965,384482350,378792570,15988303,213424334,4558333,2098365,10835631,3318817,374074330,332639529,122919696,4389286,319443573,2781341,67464020,194709238,210061039,364506106,28949044,40889076,161172338,17943181,4557976,62738484,365813173,6137343,350610552,17942703,576308,223674070,15826518,1310997,93279697,4139395,255311799,157837067,361132363,357380836,146387678,383280379,1127268,299856826,13786789,1311054,46015217,3402130,381353319,30750059,218766885,340707375,27065817,355333104,2624634,62738384,241913553,304446010].includes(a)&&(s=a),await n.showClinvarPart2(e,t,s)}}catch(t){return void(s?n.processNoSnp(e):n.processNoClinvar(e))}}navClinVar(e){let t=this.icn3d;t.icn3dui;let s=this;t.currClin[e]=-1,$(document).on("click","#"+t.pre+e+"_prevclin",(function(t){let i=s.icn3d;t.stopImmediatePropagation();let n=void 0!==i.resi2disease_nonempty[e]?Object.keys(i.resi2disease_nonempty[e]).length:0;--i.currClin[e],i.currClin[e]<0&&(i.currClin[e]=n-1),s.showClinVarLabelOn3D(e)})),$(document).on("click","#"+t.pre+e+"_nextclin",(function(t){let i=s.icn3d;t.stopImmediatePropagation();let n=void 0!==i.resi2disease_nonempty[e]?Object.keys(i.resi2disease_nonempty[e]).length:0;++i.currClin[e],i.currClin[e]>n-1&&(i.currClin[e]=0),s.showClinVarLabelOn3D(e)}))}showClinVarLabelOn3D(e){let t,s,i=this.icn3d,n=i.icn3dui,l=Object.keys(i.resi2disease_nonempty[e]);t=e,s=t+"_"+(parseInt(l[i.currClin[e]])+i.baseResi[e]).toString();let r="",o=i.resi2disease_nonempty[e][l[i.currClin[e]]];for(let e=0,t=o.length;e<t;++e)if(""!=o[e]&&"not specified"!=o[e]&&"not provided"!=o[e]){r=o[e];break}""==r&&(r=o.length>0?o[0]:"N/A");let a=i.applyCenterCls.centerAtoms(n.hashUtilsCls.hash2Atoms(i.residues[s],i.atoms));r.length>30&&(r=r.substr(0,30)+"..."),i.selectionCls.removeSelection(),null==i.labels&&(i.labels={}),i.labels.clinvar=[];let d=i.LABELSIZE,c="black"!=i.opts.background?i.colorWhitebkgd:i.colorBlackbkgd;i.analysisCls.addLabel(r,a.center.x+1,a.center.y+1,a.center.z+1,d,c,void 0,"clinvar"),i.hAtoms={};for(let e in i.residues[s])i.hAtoms[e]=1;$("#clinvar_"+i.pre+s).addClass("icn3d-highlightSeq"),void 0===$("#"+i.pre+"modeswitch")[0]||$("#"+i.pre+"modeswitch")[0].checked||i.definedSetsCls.setMode("selection"),i.drawCls.draw()}getSnpLine(e,t,s,i,n,l,r,o,a,d,c,h,p,m,u,g){let f=this.icn3d,C=f.icn3dui,b="",y=m?"clinvar":"snp",v=!1;for(let e in i){for(let t=0,s=i[e].length;t<s;++t)if(0==i[e][t]){v=!0;break}if(v)break}if(c){let e="ClinVar",t="SNP",s="",i="";v||void 0===f.organism||"human"===f.organism||"homo sapiens"===f.organism||(s=" <span style='color:#FFA500'>(from human)</span>",i=" <span style='color:#FFA500'>(based on human sequences and mapped to this structure by sequence similarity)</span>"),b+=m?'<div class="icn3d-seqTitle icn3d-link icn3d-blue icn3d-clinvar-path" clinvar="clinvar" posarray="'+d+'" shorttitle="'+e+'" setname="'+h+"_"+e+'" anno="sequence" chain="'+h+'" title="'+e+i+'">'+e+s+"</div>":'<div class="icn3d-seqTitle icn3d-link icn3d-blue" clinvar="clinvar" posarray="'+a+'" shorttitle="'+t+'" setname="'+h+"_"+t+'" anno="sequence" chain="'+h+'" title="'+t+i+'">'+t+s+"</div>"}else if(2==e&&m){let e=C.utilsCls.isMobile()?"none":"button";b+='<div id="'+f.pre+h+'_prevclin" style="display:inline-block; font-size:11px; font-weight:bold; width:60px!important;"><button class="link" style="-webkit-appearance:'+e+'; height:18px; width:55px;"><span style="white-space:nowrap; margin-left:-40px;" title="Show the previous ClinVar on structure">&lt; ClinVar</span></button></div>',b+='<div id="'+f.pre+h+'_nextclin" style="display:inline-block; font-size:11px; font-weight:bold; width:60px!important;"><button class="link" style="-webkit-appearance:'+e+'; height:18px; width:55px;"><span style="white-space:nowrap; margin-left:-40px;" title="Show the next ClinVar on structure">ClinVar &gt;</span></button></div>'}else b+='<div class="icn3d-seqTitle"></div>';let _=y,w=0,S=0,A={},x={};for(let t=1,i=f.giSeq[h].length;t<=i;++t)if(void 0!==r[t]){++w;let i="";for(let n=0,r=s[t].length;n<r&&!g;++n){let s=l[t][n].split("; "),r=o[t][n].split("; "),a="";for(let e=0,t=s.length;e<t;++e)a+=s[e]+"("+r[e]+"); ";""!=a&&(A[t]="icn3d-clinvar",n==e-2&&(x[t]="icn3d-clinvar",-1!=a.indexOf("Pathogenic")&&(x[t]="icn3d-clinvar-path"))),i+=a+" | "}-1!=i.indexOf("Pathogenic")&&(A[t]="icn3d-clinvar-path"),"icn3d-clinvar"!=A[t]&&"icn3d-clinvar-path"!=A[t]||++S}if(0==w&&!m)return $("#"+f.pre+"dt_clinvar_"+h).html(""),$("#"+f.pre+"ov_clinvar_"+h).html(""),$("#"+f.pre+"tt_clinvar_"+h).html(""),$("#"+f.pre+"dt_snp_"+h).html(""),$("#"+f.pre+"ov_snp_"+h).html(""),$("#"+f.pre+"tt_snp_"+h).html(""),"";if(0==S&&m)return $("#"+f.pre+"dt_clinvar_"+h).html(""),$("#"+f.pre+"ov_clinvar_"+h).html(""),$("#"+f.pre+"tt_clinvar_"+h).html(""),"";let k=m?S:w;if(b+=1==e?'<span class="icn3d-residueNum" title="residue count">'+k+" Res</span>":'<span class="icn3d-residueNum"></span>',u)return b+"<br>";b+='<span class="icn3d-seqLine">';let O="",R=0,I=0;p?f.seqStartLen&&f.seqStartLen[h]&&(b+=f.showSeqCls.insertMulGapOverview(h,f.seqStartLen[h])):f.seqStartLen&&f.seqStartLen[h]&&(b+=f.showSeqCls.insertMulGap(f.seqStartLen[h],"-"));for(let t=1,a=f.giSeq[h].length;t<=a;++t)if(p){if(void 0!==r[t]){let e=f.giSeq[h][t-1],i=e;e.length>1&&(i=e[0]+"..");let n=f.ParserUtilsCls.getResi(h,t-1)+i+">";for(let e=0,i=s[t].length;e<i;++e)if(n+=s[t][e],!g){let s=l[t][e].split("; "),i=o[t][e].split("; "),n="";for(let e=0,t=s.length;e<t;++e)n+=s[e]+"("+i[e]+"); "}b+=f.showSeqCls.insertGapOverview(h,t-1);let r=Math.round(f.seqAnnWidth*(t-1)/(f.maxAnnoLength+f.nTotalGap)-R-I);m?"icn3d-clinvar"!=A[t]&&"icn3d-clinvar-path"!=A[t]||r>=0&&(b+='<div style="display:inline-block; width:'+r+'px;">&nbsp;</div>',b+='<div style="display:inline-block; background-color:#000; width:1px;" title="'+n+'">&nbsp;</div>',R+=r,I+=1):r>0&&(b+='<div style="display:inline-block; width:'+r+'px;">&nbsp;</div>',b+='<div style="display:inline-block; background-color:#000; width:1px;" title="'+n+'">&nbsp;</div>',R+=r,I+=1)}}else if(b+=f.showSeqCls.insertGap(h,t-1,"-"),void 0!==r[t])if(m||1!=e){let r=f.giSeq[h][t-1],a=r;r.length>1&&(a=r[0]+"..");let d,c=f.ParserUtilsCls.getResi(h,t-1),p="",u="<div class='snptip'>",y=s[t].length,v=0,w=0;if(2==e&&(v=0,w=y),m){d=1;let r=0;for(let e=v;e<y&&e<w;++e){let m=h+"_"+c+"_"+s[t][e],g=C.utilsCls.isMobile()?"none":"button",b=!0;f.residues.hasOwnProperty(h+"_"+c)||(b=!1);let v=l[t][e].split("; "),_=o[t][e].split("; "),w="",S=0;for(let t=0,s=v.length;t<s;++t)S>0?w+="; ":0!==e&&1!==e||(O='disease="'+v[t]+'"'),w+=v[t]+"("+_[t]+")",++S;""!=w&&(r<d&&(p+=s[t][e]),u+=c+a+">"+s[t][e],u+=": "+w,b&&!C.cfg.hidelicense&&(u+="<br>"+f.showAnnoCls.addSnpButton(m,"snpin3d","3D with scap","SNP in 3D with scap",70,g)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(m,"snpinter","Interactions","SNP Interactions in 3D",70,g)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(m,"snppdb","PDB","Download SNP PDB",35,g)),u+="<br>Links: <a href='https://www.ncbi.nlm.nih.gov/clinvar/?term="+n[t][e]+"[AlleleID]' target='_blank'>ClinVar</a>, <a href='https://www.ncbi.nlm.nih.gov/snp/?term="+i[t][e]+"' target='_blank'>dbSNP(rs"+i[t][e]+")</a>",e<y-1&&(u+="<br><br>"),++r)}r>d&&2==e&&(p+="..")}else{d=1;for(let e=v;e<y&&e<w;++e){let r=h+"_"+c+"_"+s[t][e],m=C.utilsCls.isMobile()?"none":"button",b=!0;if(f.residues.hasOwnProperty(h+"_"+c)||(b=!1),e<d&&(p+=s[t][e]),u+=c+a+">"+s[t][e],g)b&&!C.cfg.hidelicense&&(u+="<br>"+f.showAnnoCls.addSnpButton(r,"snpin3d","3D with scap","SNP in 3D with scap",70,m)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(r,"snpinter","Interactions","SNP Interactions in 3D",70,m)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(r,"snppdb","PDB","Download SNP PDB",35,m)),0!=i[t][e]&&(u+="<br>Link: <a href='https://www.ncbi.nlm.nih.gov/snp/?term="+i[t][e]+"' target='_blank'>dbSNP(rs"+i[t][e]+")</a>"),e<y-1&&(u+="<br><br>");else{let s=l[t][e].split("; "),a=o[t][e].split("; "),d="",c=0;for(let t=0,i=s.length;t<i;++t)c>0?d+="; ":0!==e&&1!==e||(O='disease="'+s[t]+'"'),d+=s[t]+"("+a[t]+")",++c;""!=d?(u+=": "+d,b&&!C.cfg.hidelicense&&(u+="<br>"+f.showAnnoCls.addSnpButton(r,"snpin3d","3D with scap","SNP in 3D with scap",70,m)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(r,"snpinter","Interactions","SNP Interactions in 3D",70,m)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(r,"snppdb","PDB","Download SNP PDB",35,m)),u+="<br>Links: <a href='https://www.ncbi.nlm.nih.gov/clinvar/?term="+n[t][e]+"[AlleleID]' target='_blank'>ClinVar</a>, <a href='https://www.ncbi.nlm.nih.gov/snp/?term="+i[t][e]+"' target='_blank'>dbSNP(rs"+i[t][e]+")</a>"):(b&&!C.cfg.hidelicense&&(u+="<br>"+f.showAnnoCls.addSnpButton(r,"snpin3d","3D with scap","SNP in 3D with scap",70,m)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(r,"snpinter","Interactions","SNP Interactions in 3D",70,m)+"&nbsp;&nbsp;",u+=f.showAnnoCls.addSnpButton(r,"snppdb","PDB","Download SNP PDB",35,m)),u+="<br>Link: <a href='https://www.ncbi.nlm.nih.gov/snp/?term="+i[t][e]+"' target='_blank'>dbSNP(rs"+i[t][e]+")</a>"),e<y-1&&(u+="<br><br>")}}y>d&&2==e&&(p+="..")}u+="</div>",m?"icn3d-clinvar"==A[t]||"icn3d-clinvar-path"==A[t]?b+=1==e?"<span>&dArr;</span>":""==p||" "==p?"<span>-</span>":'<span id="'+_+"_"+f.pre+h+"_"+c+'" label title="'+u+'" '+O+' class="icn3d-tooltip icn3d-residue '+x[t]+'">'+p+"</span>":b+="<span>-</span>":b+=""==p||" "==p?"<span>-</span>":g?'<span id="'+_+"_"+f.pre+h+"_"+c+'" label title="'+u+'" class="icn3d-tooltip icn3d-residue '+x[t]+'">'+p+"</span>":'<span id="'+_+"_"+f.pre+h+"_"+c+'" label title="'+u+'" '+O+' class="icn3d-tooltip icn3d-residue '+x[t]+'">'+p+"</span>"}else b+="<span>&dArr;</span>";else b+="<span>-</span>";return p||f.seqStartLen&&f.seqStartLen[h]&&(b+=f.showSeqCls.insertMulGap(f.seqEndLen[h],"-")),b+=1==e?'<span class="icn3d-residueNum" title="residue count">&nbsp;'+k+" Residues</span>":'<span class="icn3d-residueNum"></span>',b+="</span>",b+="<br>",b}processSnpClinvar(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o='<div id="'+l.pre+t+'_snpseq_sequence" class="icn3d-dl_sequence">',a=o,d=o,c='<div id="'+l.pre+t+'_clinvarseq_sequence" class="icn3d-dl_sequence">',h=c,p=c,m=!i||n?e.data:e.split("\n"),u={},g={},f={};void 0===l.resi2disease_nonempty[t]&&(l.resi2disease_nonempty[t]={});let C={},b={},y={},v={},_={},w="";r.bNode&&(i?(l.resid2snp||(l.resid2snp={}),l.resid2snp[t]||(l.resid2snp[t]=[])):(l.resid2clinvar||(l.resid2clinvar={}),l.resid2clinvar[t]||(l.resid2clinvar[t]=[])));for(let e=0,s=m.length;e<s;++e)if(""!=m[e]){let s=!i||n?m[e]:m[e].split("\t"),o=s[3];if(o==w)continue;w=o;let a=o.substr(0,o.length-3),d=Math.round(a);if(r.bNode){let e={};e[t+"_"+d]=o,i?l.resid2snp[t].push(e):l.resid2clinvar[t].push(e)}o.substr(o.length-3,1);let c=o.substr(o.indexOf(">")+1),h=s[4],p=i?"":s[5],S=i?"":s[6],A=i?"":s[7],x=l.ParserUtilsCls.getResi(t,d-1);v[x]=1,""!=S&&(_[x]=1),g[d]=e+1,void 0===u[d]&&(u[d]=[]),u[d].push(c),void 0===b[d]&&(b[d]=[]),b[d].push(h),void 0===y[d]&&(y[d]=[]),y[d].push(p),void 0===f[d]&&(f[d]=[]),f[d].push(S),""!=S&&(void 0===l.resi2disease_nonempty[t][d]&&(l.resi2disease_nonempty[t][d]=[]),l.resi2disease_nonempty[t][d].push(S)),void 0===C[d]&&(C[d]=[]),C[d].push(A)}let S=Object.keys(v),A=Object.keys(_);if(i){let e=!1;o+=this.getSnpLine(1,2,u,b,y,f,g,C,S,A,1,t,!1,e,void 0,i),o+=this.getSnpLine(2,2,u,b,y,f,g,C,S,A,0,t,!1,e,void 0,i),d+=this.getSnpLine(1,2,u,b,y,f,g,C,S,A,1,t,!1,e,!0,i),d+=this.getSnpLine(2,2,u,b,y,f,g,C,S,A,0,t,!1,e,!0,i),a+=this.getSnpLine(1,2,u,b,y,f,g,C,S,A,1,t,!0,e,void 0,i),o+="</div>",a+="</div>",d+="</div>",$("#"+l.pre+"dt_snp_"+t).html(o),$("#"+l.pre+"ov_snp_"+t).html(a),$("#"+l.pre+"tt_snp_"+t).html(d)}else{let e=!0;c+=this.getSnpLine(1,2,u,b,y,f,g,C,S,A,1,t,!1,e,void 0,i),c+=this.getSnpLine(2,2,u,b,y,f,g,C,S,A,0,t,!1,e,void 0,i),p+=this.getSnpLine(1,2,u,b,y,f,g,C,S,A,1,t,!1,e,!0,i),p+=this.getSnpLine(2,2,u,b,y,f,g,C,S,A,0,t,!1,e,!0,i),h+=this.getSnpLine(1,2,u,b,y,f,g,C,S,A,1,t,!0,e,void 0,i),c+="</div>",h+="</div>",p+="</div>",$("#"+l.pre+"dt_clinvar_"+t).html(c),$("#"+l.pre+"ov_clinvar_"+t).html(h),$("#"+l.pre+"tt_clinvar_"+t).html(p),this.navClinVar(t,s)}l.showAnnoCls.enableHlSeq(),i?l.bAjaxSnp=!0:l.bAjaxClinvar=!0}async showClinvarPart2(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this,r=n.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?chainid_clinvar="+t;i.chainsGene[e]&&i.chainsGene[e].geneSymbol&&(r+="&gene="+i.chainsGene[e].geneSymbol);try{let s=await n.getAjaxPromise(r,"jsonp");if(s&&s.data&&s.data.length>0){let i=!1,n=s;l.processSnpClinvar(n,e,t,i)}else l.processNoClinvar(e)}catch(t){return void l.processNoClinvar(e)}}async showSnpPart2(e,t,s){let i=this.icn3d,n=i.icn3dui,l=this;if(void 0!==s){let s=n.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?chainid_snp="+t;i.chainsGene[e]&&i.chainsGene[e].geneSymbol&&(s+="&gene="+i.chainsGene[e].geneSymbol);try{let i=await n.getAjaxPromise(s,"jsonp");if(i&&i.data&&i.data.length>0){let s=!0,n=!0;l.processSnpClinvar(i,e,t,s,n)}else l.processNoSnp(e)}catch(t){return void l.processNoSnp(e)}}else this.processNoSnp(e),console.log("No gi was found for the chain "+t+"...")}processNoClinvar(e){let t=this.icn3d;t.icn3dui,console.log("No ClinVar data were found for the protein "+e+"..."),$("#"+t.pre+"dt_clinvar_"+e).html(""),$("#"+t.pre+"ov_clinvar_"+e).html(""),t.showAnnoCls.enableHlSeq(),t.bAjaxClinvar=!0}processNoSnp(e){let t=this.icn3d;t.icn3dui,console.log("No SNP data were found for the protein "+e+"..."),$("#"+t.pre+"dt_snp_"+e).html(""),$("#"+t.pre+"ov_snp_"+e).html(""),t.showAnnoCls.enableHlSeq(),t.bAjaxSnp=!0}}class Ot{constructor(e){this.icn3d=e}showSsbond(e,t){let s=this.icn3d;s.icn3dui;let i=this;void 0===s.ssbondpnts?setTimeout((function(){i.showSsbond_base(e,t)}),1e3):this.showSsbond_base(e,t)}showSsbond_base(e,t){let s=this.icn3d;s.icn3dui.bNode&&(s.resid2ssbond||(s.resid2ssbond={}),s.resid2ssbond[e]||(s.resid2ssbond[e]=[]));let i=t,n={},l=i.substr(0,i.indexOf("_")),r=s.ssbondpnts[l];if(void 0===r)return $("#"+s.pre+"dt_ssbond_"+e).html(""),$("#"+s.pre+"ov_ssbond_"+e).html(""),void $("#"+s.pre+"tt_ssbond_"+e).html("");for(let e=0,t=r.length;e<t;e+=2){let t=r[e],s=r[e+1],l=t.substr(0,t.lastIndexOf("_")),o=s.substr(0,s.lastIndexOf("_"));i===l&&(void 0===n[t]&&(n[t]=[]),n[t].push(s)),i===o&&(void 0===n[s]&&(n[s]=[]),n[s].push(t))}let o=Object.keys(n);s.annoCddSiteCls.showAnnoType(e,t,"ssbond","Disulfide Bonds",o,n)}}class Rt{constructor(e){this.icn3d=e}showTransmem(e,t){let s=this.icn3d;s.icn3dui;let i=this;void 0===s.ssbondpnts?setTimeout((function(){i.showTransmem_base(e,t)}),1e3):this.showTransmem_base(e,t)}showTransmem_base(e,t){let s=this.icn3d;s.icn3dui;let i={};for(let e in s.chains[t]){let t=s.atoms[e];if(t.coord.z<s.halfBilayerSize&&t.coord.z>-s.halfBilayerSize){i[t.structure+"_"+t.chain+"_"+t.resi]=1}}let n=Object.keys(i);s.annoCddSiteCls.showAnnoType(e,t,"transmem","Transmembrane",n)}}class It{constructor(e){this.icn3d=e,this.init3ddomain()}init3ddomain(){this.icn3d.icn3dui,this.dcut=8,this.min_contacts=2,this.MAX_SSE=512,this.ctc_cnt=[];for(let e=0;e<this.MAX_SSE;++e)this.ctc_cnt[e]=[];this.elt_size=[],this.elt_size.length=this.MAX_SSE,this.group_num=[],this.group_num.length=this.MAX_SSE,this.split_ratio=.25,this.min_size=25,this.min_sse=3,this.max_csz=4,this.mean_cts=0,this.c_delta=3,this.nc_fact=0,this.elements=[],this.elements.length=2*this.MAX_SSE,this.stack=[],this.stack.length=this.MAX_SSE,this.top=0,this.curr_prt0=[],this.curr_prt0.length=this.MAX_SSE,this.curr_prt1=[],this.curr_prt1.length=this.MAX_SSE,this.curr_ne0=0,this.curr_ne1=0,this.curr_ratio=0,this.curr_msize=0,this.parts=[],this.parts.length=2*this.MAX_SSE,this.np=0,this.n_doms=0,this.save_ratios=[],this.save_ratios.length=this.MAX_SSE,this.saved=0}update_partition(e,t,s){this.icn3d.icn3dui;let i,n,l,r,o,a,d,c,h,p,m,u,g,f,C=[],b=[],y=[],v=[];for(y.length=this.MAX_SSE,v.length=this.MAX_SSE,i=this.stack[this.top-1],n=this.elements.length;i<n;++i)C.push(this.elements[i]);let _=!0;for(b=y,i=c=h=p=0,r=-1;i<t;i++){for(l=r+1;l<=e[i];l++)b[c++]=C[l];r=e[i],_?(h=c,b=v,c=p,_=!1):(p=c,b=y,c=h,_=!0)}for(l=r+1;l<s;l++)b[c++]=C[l];if(_?h=c:p=c,h<this.min_sse&&p<this.min_sse)return e;for(i=0;i<h;i++)for(r=this.group_num[y[i]],l=0;l<p;l++)if(r==this.group_num[v[l]])return e;for(i=m=0;i<h;i++)m+=this.elt_size[y[i]];for(i=u=0;i<p;i++)u+=this.elt_size[v[i]];for(i=o=0;i<h;i++)for(l=i;l<h;l++)o+=this.ctc_cnt[y[i]][y[l]];for(i=a=0;i<p;i++)for(l=i;l<p;l++)a+=this.ctc_cnt[v[i]][v[l]];if(1*o/m<this.mean_cts||1*a/u<this.mean_cts)return e;for(o=Math.max(o,this.nc_fact*m),a=Math.max(a,this.nc_fact*u),i=d=0;i<h;i++)for(r=y[i],l=0;l<p;l++)d+=this.ctc_cnt[r][v[l]];if(g=Math.min(o,a),f=1*d/(g+1),f>=this.curr_ratio+.01||f>this.split_ratio)return e;if(f>this.curr_ratio-.01&&Math.min(m,u)<this.curr_msize)return e;for(i=0;i<h;i++)this.curr_prt0[i]=y[i];for(i=0;i<p;i++)this.curr_prt1[i]=v[i];return this.curr_ne0=h,this.curr_ne1=p,this.curr_ratio=f,this.curr_msize=Math.min(m,u),e}cut_size(e,t){this.icn3d.icn3dui;let s,i,n,l=[];for(l.length=this.MAX_SSE,s=0;s<e;s++)l[s]=s;for(;;){for(s=n=1;s<e;s++)if(l[s]-l[s-1]<=this.c_delta){n=0;break}for(n&&l[e-1]<t-1&&(l=this.update_partition(l,e,t)),i=e-1;i>=0&&l[i]==t-e+i;i--);if(i<0)break;for(l[i]++,s=i+1;s<e;s++)l[s]=l[s-1]+1}}process_set(){this.icn3d.icn3dui;let e,t,s,i,n,l,r=[];for(e=this.stack[this.top-1],t=this.elements.length;e<t;++e)r.push(this.elements[e]);for(i=0;i<r.length&&r[i]>-1;i++);for(l=Math.min(i-1,this.max_csz),this.curr_ne0=this.curr_ne1=0,this.curr_ratio=100,s=1;s<=l;s++)this.cut_size(s,i);if(this.top--,0==this.curr_ne0){for(n=this.stack[this.top],e=n;e<this.elements.length&&this.elements[e]>-1;e++)this.parts[this.np++]=this.elements[e];this.parts[this.np++]=-1,this.n_doms++}else{if(this.save_ratios[this.saved++]=this.curr_ratio,this.curr_ne0>this.min_sse){for(n=this.stack[this.top],e=0;e<this.curr_ne0;e++)this.elements[n++]=this.curr_prt0[e];this.elements[n++]=-1,this.stack[++this.top]=n}else{for(e=0;e<this.curr_ne0;e++)this.parts[this.np++]=this.curr_prt0[e];this.parts[this.np++]=-1,this.n_doms++}if(this.curr_ne1>this.min_sse){for(n=this.stack[this.top],e=0;e<this.curr_ne1;e++)this.elements[n++]=this.curr_prt1[e];this.elements[n++]=-1,this.stack[++this.top]=n}else{for(e=0;e<this.curr_ne1;e++)this.parts[this.np++]=this.curr_prt1[e];this.parts[this.np++]=-1,this.n_doms++}}}process_all(e){let t;for(this.icn3d.icn3dui,this.top=1,this.stack[0]=this.np=this.n_doms=0,this.saved=0,t=0;t<e;t++)this.elements[t]=t;for(this.elements[e]=-1;this.top>0;)this.process_set()}output(e){let t,s;this.icn3d.icn3dui;let i=[];for(t=0;t<2*e;t++)i.push(0);for(t=s=0;s<this.n_doms;t++)i[t]=this.parts[t]+1,this.parts[t]<0&&s++;return i}new_split_chain(e,t,s,i,n,l,r,o,a,d,c){let h;for(this.icn3d.icn3dui,this.split_ratio=t,this.min_size=s,this.min_sse=i,this.max_csz=n,this.mean_cts=l,this.c_delta=r,this.nc_fact=o,this.process_all(e),this.parts=this.output(e),d=this.saved,h=0;h<this.saved;h++)c[h]=this.save_ratios[h];return d}c2b_AlphaContacts(e,t,s,i,n,l){this.icn3d.icn3dui,n||(n=this.dcut);let r=[],o=[];for(let n=0;n<e;n++){if(!t[n]||!s[n]||!i[n])continue;let e={};e.rnum=l[n],e.x=t[n],e.y=s[n],e.z=i[n],o.push(e)}o.sort((function(e,t){return e.x-t.x}));let a,d,c=o.length;for(a=0;a<c;++a){let e=o[a],t=e.x,s=e.y,i=e.z;for(d=a+1;d<c;++d){let l=o[d];if(parseInt(e.rnum)-parseInt(l.rnum)<=3&&parseInt(l.rnum)-parseInt(e.rnum)<=3)continue;let a=l.x,c=l.y,h=l.z;if(a>t+n)break;let p=(t-a)*(t-a);p+=(s-c)*(s-c),p+=(i-h)*(i-h);let m=Math.sqrt(p);if(m>n)continue;let u={},g={};parseInt(e.rnum)<parseInt(l.rnum)?(g.first=e.rnum,g.second=l.rnum):(g.first=l.rnum,g.second=e.rnum),u.first=g,u.second=m,r.push(u)}}return r}c2b_ContactTable(e,t){this.icn3d.icn3dui;let s={},i=e.length;if(i!=t.length)return s;for(let n=0;n<i;n++){let i=e[n]+"_"+t[n];s[i]?s[i]++:s[i]=1}return s}countUtil(e,t,s){this.visited[e]=!0,this.groupnum2sheet[s]||(this.groupnum2sheet[s]=[]),this.groupnum2sheet[s].push(parseInt(e));for(let i in t[e])this.visited[i]||this.countUtil(i,t,s)}c2b_NewSplitChain(e,t){let s=this.icn3d;s.icn3dui,this.init3ddomain();let i=[],n=[],l=[],r=[],o=[],a=[],d=[],c=s.firstAtomObjCls.getResiduesFromAtoms(e),h=Object.keys(c),p=h[0].substr(0,h[0].lastIndexOf("_"));s.posid2resid||(s.posid2resid={});let m={},u={};for(let e=0;e<h.length;++e){let t=h[e],a=t.substr(t.lastIndexOf("_")+1),d=s.firstAtomObjCls.getFirstCalphaAtomObj(s.residues[t]);d&&(i.push(d.coord.x),n.push(d.coord.y),l.push(d.coord.z),r.push(e+1),u[e]=a,s.posid2resid[d.structure+"_"+d.chain+"_"+(e+1).toString()]=t,d.ssend&&(m.To=e+1,m.x2=d.coord.x,m.y2=d.coord.y,m.z2=d.coord.z,m.Sheet="sheet"==d.ss,o.push(m),m={}),d.ssbegin&&(m.From=e+1,m.x1=d.coord.x,m.y1=d.coord.y,m.z1=d.coord.z))}let g=o.length;if(g<=3)return{subdomains:a,substruct:o,pos2resi:u};if(g>this.MAX_SSE)return{subdomains:a,substruct:o,pos2resi:u};let f=h.length,C=f,b=this.c2b_AlphaContacts(f,i,n,l,t,r),y=[];for(let e=0;e<f;e++)y.push(0);let v=!1;for(let e=0;e<o.length;e++){let t=o[e],s=t.From,i=t.To;this.elt_size[e]=i-s+1;for(let t=s;t<=i;t++)y[t-1]=e+1;t.Sheet&&(v=!0)}let _=[],w=[],S=[],A=[];for(let e=0,t=b.length;e<t;++e){let t=b[e].first,s=y[t.first-1],i=y[t.second-1];s<=0||i<=0||!s||!i||(_.push(s),w.push(i),s!=i&&(S.push(s),A.push(i)))}for(let e=0;e<S.length;e++)_.push(A[e]),w.push(S[e]);for(let e=0;e<g;e++)_.push(e+1),w.push(e+1);let x=this.c2b_ContactTable(_,w),k={};for(let e in x){let t=e.split("_"),s=parseInt(t[0]),i=parseInt(t[1]);x[e]<this.min_contacts&&(x[e]=0),o[s-1].Sheet&&o[i-1].Sheet&&x[e]>=this.min_contacts&&(k[s]||(k[s]={}),k[i]||(k[i]={}),k[s][i]=1,k[i][s]=1)}let O=0,R={};this.groupnum2sheet={},this.visited={};for(let e in k)this.visited[e]=!1;for(let e in k)0==this.visited[e]&&(O++,this.countUtil(e,k,O));for(let e in this.groupnum2sheet){let t=this.groupnum2sheet[e].sort((function(e,t){return e-t}));for(let e=0,s=t.length;e<s;++e)R[t[e]]=t[0]}let I={};for(let e=0;e<g;e++)if(o[e].Sheet){let t={};R[e+1]?(t.sheet_num=R[e+1],t.adj_strand2=1,t.sse=e+1):(t.sheet_num=0,t.adj_strand2=0,t.sse=e+1,I[t.sse]=1),d.push(t)}for(let e=0;e<g;e++)for(let t=0;t<g;t++){let s=(e+1).toString()+"_"+(t+1).toString();if(x[s]){let i=x[s];e==t&&i--,this.ctc_cnt[e][t]=i,this.ctc_cnt[t][e]=i}else this.ctc_cnt[e][t]=0}if(v){let e=0;for(let t=0;t<d.length;t++){let s=d[t];s.sheet_num>0&&this.elt_size[s.sse-1]>=6&&0!=s.adj_strand2&&e++}for(let e=0;e<g;e++)this.group_num[e]=e+1;if(e>0)for(let e=0;e<d.length;e++){let t=d[e];0!=t.sheet_num&&(this.group_num[t.sse-1]=t.sheet_num)}}else for(let e=0;e<g;e++)this.group_num[e]=e+1;this.parts=[],this.parts.length=2*this.MAX_SSE;let E=[];E.length=this.MAX_SSE;let T=0;for(let e=0;e<g;e++)this.parts[2*e]=this.parts[2*e+1]=0,E[e]=0;T=this.new_split_chain(g,.25,25,3,4,0,3,0,this.parts,T,E);let P=[];if(T>0){let e=0;for(let t=0;t<=T;t++){let t=[];for(;e<2*g;){let s=this.parts[e++];if(0==s){P.push(t);break}t.push(s)}}}P.sort((function(e,t){return e[0]-t[0]}));let D=[];for(let e=0,t=P.length;e<t;++e){let t=[];for(let s=0,i=P[e].length;s<i;++s){let i=P[e][s];I.hasOwnProperty(i)||t.push(i)}t.length>=this.min_sse&&D.push(P[e])}if(P=D,0==P.length){let e={},t={},s=0;for(let i=0,n=this.group_num.length;i<n;++i){let n=this.group_num[i],l=i+1;n&&n!=i+1&&(t[n]||(t[n]=[]),t[n].push(l),e[n]?(++e[n],e[n]>=3&&(s=n)):e[n]=1)}if(0!=s){let e=[s].concat(t[s]);P.push(e)}}for(let e=0,t=P.length;e<t;++e){let t=P[e],s={};if(t.length<=2)continue;for(let e=0;e<f;e++)s[e+1]=0;for(let e=0;e<t.length;e++){let i=t[e]-1;if(i<0||i>=o.length)return{subdomains:a,substruct:o,pos2resi:u};let n=o[i],l=n.From,r=n.To;for(let e=l;e<=r;e++)s[e]=1;if(0==i&&l>1)for(let e=1;e<l;e++)l-e<=10&&(s[e]=1);if(i==o.length-1&&r<parseInt(C))for(let e=r+1;e<=parseInt(C);e++)e-r<=10&&(s[e]=1);if(i>0){let e=o[i-1].To,t=parseInt(.5*(l-e-1));if(t>0)for(let e=l-t;e<=l-1;e++)s[e]=1}if(i<o.length-1){let e=o[i+1].From,t=parseInt(.5*(e-r-1)+.5);if(t>0)for(let e=r+1;e<=r+t;e++)s[e]=1}}let i,n=!1,l=[];for(let e=0;e<f;e++){let t=s[e+1];n||1!=t?n&&0==t&&(l.push(i),l.push(e),n=!1):(i=e+1,n=!0)}n&&(l.push(i),l.push(C)),a.push(l)}s.tddomains||(s.tddomains={});for(let e=0,t=a.length;e<t;++e){let t="domain3d-"+Object.keys(s.tddomains).length;s.tddomains[t]={};for(let i=0,n=a[e].length;i<n;i+=2)for(let n=a[e][i];n<=a[e][i+1];++n){let e=p+"_"+n;s.tddomains[t][e]=1}}return{subdomains:a,substruct:o,pos2resi:u}}getDomainJsonForAlign(e,t){let s=this.icn3d,i=s.icn3dui,n=this.c2b_NewSplitChain(e),l=n.subdomains,r=n.substruct,o=n.pos2resi,a=s.firstAtomObjCls.getResiduesFromAtoms(e),d=Object.keys(a),c=d[0].substr(0,d[0].lastIndexOf("_"));t&&(l=[]),l.push([1,d.length]);let h='{"data": [';for(let e=0,t=l.length;e<t;++e){e>0&&(h+=", "),h+='{"ss": [';let t=0;for(let i=0,n=l[e].length;i<n;i+=2){let n=l[e][i],a=l[e][i+1];for(let e=0,i=r.length;e<i;++e){let i=r[e].Sheet?2:1,l=o[r[e].From-1],d=o[r[e].To-1],p=r[e].From,m=r[e].To,u=c+"_"+l,g=s.firstAtomObjCls.getFirstCalphaAtomObj(s.residues[u]);if(!g||!s.hAtoms.hasOwnProperty(g.serial))continue;let f=c+"_"+d,C=s.firstAtomObjCls.getFirstCalphaAtomObj(s.residues[f]);C&&s.hAtoms.hasOwnProperty(C.serial)&&(p>=n&&m<=a&&(t>0&&(h+=", "),h+="["+i+","+p+","+m+","+r[e].x1.toFixed(2)+","+r[e].y1.toFixed(2)+","+r[e].z1.toFixed(2)+","+r[e].x2.toFixed(2)+","+r[e].y2.toFixed(2)+","+r[e].z2.toFixed(2)+"]",++t))}}h+="]",h+=', "domain": [';let n=0;for(let t=0,r=l[e].length;t<r;t+=2){let r=l[e][t],o=l[e][t+1];for(let e=0,t=d.length;e<t;++e){let t=d[e],l=e+1,a=s.firstAtomObjCls.getFirstCalphaAtomObj(s.residues[t]);if(!a)continue;if(!s.hAtoms.hasOwnProperty(a.serial))continue;let c=i.parasCls.resn2restype[a.resn];void 0!==c&&l>=r&&l<=o&&(n>0&&(h+=", "),h+="["+l+","+c+","+a.coord.x.toFixed(2)+","+a.coord.y.toFixed(2)+","+a.coord.z.toFixed(2)+"]",++n)}}h+="]}"}return h+="]}",h}}class Et{constructor(e){this.icn3d=e}clickAddTrackButton(){let e=this.icn3d,t=e.icn3dui,s=this;t.myEventCls.onIds("#"+e.pre+"addtrack_button1","click",(async function(e){let i=s.icn3d;e.stopImmediatePropagation(),dialog.dialog("close");let n=$("#"+i.pre+"track_chainid").val(),l=$("#"+i.pre+"track_gi").val(),r=isNaN(l)?"Acc "+l:"gi "+l,o=t.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=track",a={targets:n,queries:l},d=await t.getAjaxPostPromise(o,a);s.alignSequenceToStructure(n,d,r)})),t.myEventCls.onIds("#"+e.pre+"addtrack_button2","click",(async function(e){let i=s.icn3d;e.stopImmediatePropagation(),dialog.dialog("close");let n=$("#"+i.pre+"track_chainid").val(),l=$("#"+i.pre+"track_fasta").val(),r=$("#"+i.pre+"fasta_title").val(),o=n.substr(0,n.indexOf("_")),a=n;if(5==o.length)a=a.substr(0,4);else if(o.length>5){a="";for(let e=0,t=i.chainsSeq[n].length;e<t;++e)a+=i.chainsSeq[n][e].name}let d=t.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=track",c={targets:a,queries:l},h=await t.getAjaxPostPromise(d,c);s.alignSequenceToStructure(n,h,r)})),t.myEventCls.onIds("#"+e.pre+"addtrack_button2b","click",(async function(e){let t=s.icn3d;e.stopImmediatePropagation(),dialog.dialog("close");let i=$("#"+t.pre+"track_chainid").val(),n=$("#"+t.pre+"fasta_startpos").val();n||(n=1);let l="identity"==$("#"+t.pre+"colorseqby").val()?"identity":"custom",r=$("#"+t.pre+"track_fastaalign").val();r&&await s.addMsaTracks(i,n,l,r)})),t.myEventCls.onIds("#"+e.pre+"exons_table","click",(async function(e){let t=s.icn3d;e.stopImmediatePropagation();let i=$("#"+t.pre+"track_geneid").val().trim();window.open("https://www.ncbi.nlm.nih.gov/gene/"+i+"?report=gene_table","_blank")})),t.myEventCls.onIds("#"+e.pre+"addtrack_button2c","click",(async function(e){let t=s.icn3d;e.stopImmediatePropagation(),dialog.dialog("close");let i=$("#"+t.pre+"track_chainid").val(),n=$("#"+t.pre+"track_geneid").val();if(!n)return void alert("Please fill in the Gene ID...");let l=$("#"+t.pre+"fasta_startpos2").val();l||(l=1);await s.addExonTracks(i,n,l,"identity")})),t.myEventCls.onIds("#"+e.pre+"addtrack_button3","click",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),dialog.dialog("close");let n=$("#"+i.pre+"track_chainid").val(),l=$("#"+i.pre+"track_bed")[0].files[0];if(l){window.File&&window.FileReader&&window.FileList&&window.Blob||alert("The File APIs are not fully supported in this browser.");let e=new FileReader;e.onload=function(e){let l,r=e.target.result.split("\n"),o=!1,a=!1;for(let e=0,d=r.length;e<d;++e)if("browser"!=r[e].substr(0,7))if("track"==r[e].substr(0,5)){if(-1!=r[e].toLowerCase().indexOf("itemrgb")&&(o=!0),-1!=r[e].toLowerCase().indexOf("colorbystrand=")){a=!0;let t=r[e].toLowerCase().indexOf("colorbystrand="),s=r[e].substr(t),i=s.indexOf('"');if(-1!=i){let e=s.substr(i+1),t=e.indexOf('"');if(-1!=i){l=e.substr(0,t).split(" ")}}}}else{if(""==r[e])continue;let d=r[e].replace(/\s+/g," ").split(" ");(d.length>8||d.length<6)&&(a=!1),d.length<9&&(o=!1),d[0];let c,h,p=d[1],m=d[2],u=d[3];d.length,d.length>5&&(c=d[5]),d.length,d.length,d.length>8&&(h=d[8]),d.length,d.length,d.length;let g=u,f="51,51,51";o?f=h:a&&("+"==c&&l.length>0?f=l[0]:"-"==c&&l.length>1?f=l[1]:"."==c&&l.length>2&&(f=l[2]));let C="",b=[];for(let e=0,t=m;e<t;++e)e<p?(C+="-",b.push("")):(C+=i.giSeq[n][e],b.push("rgb("+f+")"));s.showNewTrack(n,g,C,b,void 0,void 0,f),t.htmlCls.clickMenuCls.setLogCmd("add track | chainid "+n+" | title "+g+" | text "+s.simplifyText(C)+" | type bed | color "+f,!0)}},e.readAsText(l)}else alert("Please select a file...")})),t.myEventCls.onIds("#"+e.pre+"addtrack_button4","click",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),dialog.dialog("close");let n=$("#"+i.pre+"track_chainid").val(),l=$("#"+i.pre+"track_title").val(),r=$("#"+i.pre+"track_text").val(),o=s.getFullText(r);s.showNewTrack(n,l,o.text,void 0,void 0,"custom",void 0,void 0,o.fromArray,o.toArray),t.htmlCls.clickMenuCls.setLogCmd("add track | chainid "+n+" | title "+l+" | text "+s.simplifyText(r)+" | type custom",!0)})),t.myEventCls.onIds("#"+e.pre+"addtrack_button5","click",(function(e){let i=s.icn3d;e.stopImmediatePropagation(),dialog.dialog("close");let n=$("#"+i.pre+"track_chainid").val(),l=$("#"+i.pre+"track_selection").val(),r="",o=t.hashUtilsCls.intHash(i.hAtoms,i.chains[n]),a=i.firstAtomObjCls.getResiduesFromCalphaAtoms(o),d=[];for(let e=0,t=i.giSeq[n].length;e<t;++e){let t=i.giSeq[n][e],s=t;t.length>1&&(s=t[0]);let l=i.ParserUtilsCls.getResi(n,e);if(a.hasOwnProperty(n+"_"+l)){let e=i.firstAtomObjCls.getFirstCalphaAtomObj(i.residues[n+"_"+l]),t=void 0===e.color||"FFFFFF"===e.color.getHexString().toUpperCase()?"DDDDDD":e.color.getHexString(),o=void 0!==e.color?t:"CCCCCC";r+=s,d.push("#"+o)}else r+="-",d.push("")}s.showNewTrack(n,l,r,d,void 0,"selection",void 0),t.htmlCls.clickMenuCls.setLogCmd("add track | chainid "+n+" | title "+l+" | text "+s.simplifyText(r)+" | type selection",!0)}))}showNewTrack(e,t,s,i,n,l,r,o,a,d,c,h){let p=this.icn3d,m=p.icn3dui,u=!1;"cannot be aligned"==s&&(u=!0);let g=s.replace(/-/g,"").length;if(!o)if(s.length>p.giSeq[e].length)s=s.substr(0,p.giSeq[e].length);else if(s.length<p.giSeq[e].length&&!u){let t="";for(let i=0,n=p.giSeq[e].length-s.length;i<n;++i)t+="-";s+=t}let f=t.replace(/\s/g,"_").replace(/\./g,"dot").replace(/\W/g,"");f.length>20&&(f=f.substr(0,20));let C=m.htmlCls.RESIDUE_WIDTH*s.length+200;$("#"+p.pre+"dt_custom_"+e).append("<div id='"+p.pre+"dt_custom_"+e+"_"+f+"'></div>"),$("#"+p.pre+"dt_custom_"+e+"_"+f).width(C),$("#"+p.pre+"ov_custom_"+e).append("<div id='"+p.pre+"ov_custom_"+e+"_"+f+"'></div>"),$("#"+p.pre+"ov_custom_"+e+"_"+f).width(C),$("#"+p.pre+"tt_custom_"+e).append("<div id='"+p.pre+"tt_custom_"+e+"_"+f+"'></div>"),$("#"+p.pre+"tt_custom_"+e+"_"+f).width(C);let b='<div id="'+p.pre+'giseq_sequence" class="icn3d-dl_sequence">',y=b,v=b,_=b,w=b,S=parseInt(10*Math.random()),A='<div class="icn3d-seqTitle icn3d-link icn3d-blue" custom="'+(S+1).toString()+'" from="'+a+'" to="'+d+'" shorttitle="'+f+'" index="'+S+'" setname="'+e+"_custom_"+(S+1).toString()+'" anno="sequence" chain="'+e+'" title="'+t+'">'+f+" </div>",x='<div class="icn3d-seqTitle" chain="'+e+'" title="Exons of '+t+'">Exons </div>',k='<span class="icn3d-residueNum" title="residue count">'+g.toString()+" Pos</span>";_+=A+k+"<br>",w+=x+k+"<br>";let O='<span class="icn3d-seqLine">';b+=A+k+O,y+=x+k+O,v+=A+k+O;let R=e.indexOf("_"),I="cst"+e.substr(R+1),E=0,T=0,P=(void 0===l||"seq"===l||"custom"===l)&&-1==s.indexOf("cannot-be-aligned")&&-1==s.indexOf("cannot be aligned"),D="identity"===l&&-1==s.indexOf("cannot-be-aligned")&&-1==s.indexOf("cannot be aligned"),M={},F=0;A="";let H={},L={},N={},q=0;if(h)for(let e=0,t=h.length;e<t;++e){let t=h[e].resStart,s=h[e].resEnd,i=parseInt(h[e].genomeRange.split("-")[0]);for(let n=0,l=s-t+1;n<l;++n){let l=this.getExonColor(t,s,q);H[q]=l,L[q]=i+p.exonOrder*n*3+"-"+(i+p.exonOrder*n*3+2*p.exonOrder),N[q]=e,++q}}q=0;for(let t=0,a=s.length;t<a;++t){let a=t-F-(p.seqStartLen&&p.seqStartLen[e]?p.seqStartLen[e]:0);o?p.targetGapHash.hasOwnProperty(a)&&!M.hasOwnProperty(a)&&(F+=p.targetGapHash[a].to-p.targetGapHash[a].from+1,M[a]=1):b+=p.showSeqCls.insertGap(e,t,"-");let d=s.charAt(t);if(" "!=d&&"-"!=d){let s,o=p.chainsSeq[e][a]?p.chainsSeq[e][a].name:" ",c=p.showAnnoCls.getColorhexFromBlosum62(d,o),u=d==o?"FF0000":"0000FF",g=p.baseResi[e]+(t+1)-(p.seqStartLen&&p.seqStartLen[e]?p.seqStartLen[e]:0);if(void 0!==n&&(g=p.baseResi[e]+n[t]+1),void 0!==i&&""!=i[t])s='style="color:'+i[t]+'"';else if(r)s='style="color:rgb('+r+')"';else if(P||"seq"==l){if(s='style="color:#'+c+'"',"seq"==l)for(let t in p.residues[e+"_"+g]){let e=m.parasCls.thr("#"+c);p.atoms[t].color=e,p.atomPrevColors[t]=e}}else s=D?'style="color:#'+u+'"':"";if(b+='<span id="'+I+"_"+p.pre+e+"_"+g+'" title="'+d+g+'" class="icn3d-residue" '+s+">"+d+"</span>",h){let t='style="background-color:'+H[q]+'"';y+='<span id="'+I+"_"+p.pre+e+"_"+g+'" title="'+d+g+", Exon "+(N[q]+1)+": "+L[q]+'" class="icn3d-residue" '+t+">&nbsp;</span>";for(let t in p.residues[e+"_"+g]){let e=p.atoms[t];e.color=m.parasCls.thr(H[q]),p.atomPrevColors[t]=e.color}}A+=p.showSeqCls.insertGapOverview(e,t);let f=Math.round(p.seqAnnWidth*t/(p.maxAnnoLength+p.nTotalGap)-E-T);f<0&&(f=0),A+='<div style="display:inline-block; width:'+f+'px;">&nbsp;</div>',s=void 0!==i&&""!=i[t]?i[t]:r?"rgb("+r+")":P?"#"+c:"#333",A+='<div style="display:inline-block; background-color:'+s+'; width:1px;" title="'+d+(t+1).toString()+'">&nbsp;</div>',E+=f,T+=1,++q}else u?b+="<span>"+d+"</span>":(b+="<span>-</span>",y+="<span></span>")}if(void 0!==a){A="";let s=[],i=[];for(let e=0,t=a.length;e<t;++e){s.push(a[e]);for(let t=parseInt(a[e]);t<=parseInt(d[e]);++t)void 0!==p.targetGapHash&&p.targetGapHash.hasOwnProperty(t)&&(i.push(t-1),s.push(t));i.push(d[e])}p.nTotalGap=0;for(let e in p.targetGapHash)p.nTotalGap+=p.targetGapHash[e].to-p.targetGapHash[e].from+1;let n,l=p.firstAtomObjCls.getFirstCalphaAtomObj(p.chains[e]),r=void 0===l.color||"FFFFFF"===l.color.getHexString()?"DDDDDD":l.color.getHexString(),o=void 0!==l.color?r:"CCCCCC",m=0;for(let l=0,r=s.length;l<r;++l){A+=p.showSeqCls.insertGapOverview(e,s[l]);let r=c?s[l]:s[l]-p.baseResi[e]-1,u=0==l?Math.round(p.seqAnnWidth*r/(p.maxAnnoLength+p.nTotalGap)):Math.round(p.seqAnnWidth*(s[l]-i[l-1]-1)/(p.maxAnnoLength+p.nTotalGap));if(u<0&&(u=0),A+='<div style="display:inline-block; width:'+u+'px;">&nbsp;</div>',h){let t,s;n=d[l]-a[l]+1;let i,r,o,c=m,p=m+n-1;m+=n;for(let e=0,i=h.length;e<i;++e){let i=h[e].resStart,n=h[e].resEnd;c>=i&&c<=n&&(t={exonIndex:e,rangeStart:i,rangeEnd:n,from:c,genomeRange:h[e].genomeRange}),p>=i&&p<=n&&(s={exonIndex:e,rangeStart:i,rangeEnd:n,to:p,genomeRange:h[e].genomeRange})}if(t&&s&&t.exonIndex==s.exonIndex)i=this.getExonColor(t.rangeStart,t.rangeEnd,c),r=this.getExonColor(t.rangeStart,t.rangeEnd,p),o=i+" 0%, #FFF 50%, "+r+" 100%",A+=this.getExonHtml(t.exonIndex,o,t.from,s.to,t.genomeRange,e,f);else if(t&&(i=this.getExonColor(t.rangeStart,t.rangeEnd,c),o=i+" 0%, #FFF 50%, #00F 100%",A+=this.getExonHtml(t.exonIndex,o,t.from,t.rangeEnd,t.genomeRange,e,f)),t&&s){for(let i=t.exonIndex+1;i<s.exonIndex;++i)o="#F00 0%, #FFF 50%, #00F 100%",A+=this.getExonHtml(i,o,h[i].resStart,h[i].resEnd,h[i].genomeRange,e,f);r=this.getExonColor(s.rangeStart,s.rangeEnd,p),o="#F00 0%, #FFF 50%, "+r+" 100%",A+=this.getExonHtml(s.exonIndex,o,s.rangeStart,s.to,s.genomeRange,e,f)}}else A+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+o+"; width:"+Math.round(p.seqAnnWidth*(i[l]-s[l]+1)/(p.maxAnnoLength+p.nTotalGap))+'px;" class="icn3d-seqTitle icn3d-link icn3d-blue" custom="'+(S+1).toString()+'" from="'+s+'" to="'+i+'" shorttitle="'+f+'" index="'+S+'" setname="'+e+"_custom_"+(S+1).toString()+'" id="'+e+"_custom_"+S+'" anno="sequence" chain="'+e+'" title="'+t+'">'+t+"</div>"}}O='<span class="icn3d-residueNum" title="residue count">'+g.toString()+" Pos</span>",O+="</span>",O+="<br>",O+="</div>",b+=O,v+=A+O,y+=O,_+="</div>",w+="</div>",h?($("#"+p.pre+"dt_custom_"+e+"_"+f).html(y+b),$("#"+p.pre+"ov_custom_"+e+"_"+f).html(v),$("#"+p.pre+"tt_custom_"+e+"_"+f).html(w+_)):($("#"+p.pre+"dt_custom_"+e+"_"+f).html(b),$("#"+p.pre+"ov_custom_"+e+"_"+f).html(v),$("#"+p.pre+"tt_custom_"+e+"_"+f).html(_))}getExonHtml(e,t,s,i,n,l,r){let o=this.icn3d;return o.icn3dui,'<div style="display:inline-block; color:white!important; width:'+Math.round(o.seqAnnWidth*(i-s+1)/(o.maxAnnoLength+o.nTotalGap))+'px;" class="icn3d-seqTitle icn3d-link icn3d-blue" domain="'+(e+1)+'" from="'+s+'" to="'+i+'" setname="'+r+", "+(e+1)+'" title="Exon: '+n+' genomic interval" anno="sequence" chain="'+l+'"><div style="height: 12px; border: 1px solid #000; background: linear-gradient(to right, '+t+');"></div></div>'}getExonColor(e,t,s){this.icn3d.icn3dui;let i=.5*(e+t);if(s<i){let t=parseInt((s-e)/(i-e)*255);return"rgb(255, "+t+", "+t+")"}{let e=parseInt((t-s)/(t-i)*255);return"rgb("+e+", "+e+", 255)"}}alignSequenceToStructure(e,t,s){let i,n,l,r=this.icn3d,o=r.icn3dui;void 0!==t.data&&(i=t.data[0].query,l=Object.keys(t.data[0].targets)[0],n=t.data[0].targets[l],n=n.hsps[0]);let a="",d=[],c={};if(void 0!==i&&void 0!==n){let h=n.scores.e_value.toPrecision(2);h>1e-200&&(h=parseFloat(h).toExponential()),n.scores.bit_score;let p=t.targets[l].seqdata,m=i.seqdata,u=n.segs;for(let e=0,t=u.length;e<t;++e){let t=u[e];for(let e=0;e<=t.orito-t.orifrom;++e)c[e+t.orifrom]=e+t.from}for(let t=0,s=p.length;t<s;++t)if(c.hasOwnProperty(t)){a+=m[c[t]];let s=r.showAnnoCls.getColorhexFromBlosum62(p[t],m[c[t]]);d.push("#"+s);let i=r.ParserUtilsCls.getResi(e,t);for(let t in r.residues[e+"_"+i]){let e=o.parasCls.thr("#"+s);r.atoms[t].color=e,r.atomPrevColors[t]=e}}else a+="-",d.push("");s+=", E: "+h}else a+="cannot be aligned";this.showNewTrack(e,s,a,d,c,"seq"),r.hlUpdateCls.updateHlAll(),r.drawCls.draw(),o.htmlCls.clickMenuCls.setLogCmd("add track | chainid "+e+" | title "+s+" | text "+this.simplifyText(a)+" | type seq",!0)}defineSecondary(e,t){let s=this.icn3d,i=s.icn3dui;$("#"+s.pre+"dl_definedsets").hasClass("ui-dialog-content")&&$("#"+s.pre+"dl_definedsets").dialog("isOpen")||(i.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+s.pre+"atomsCustom").resizable());let n,l,r={},o=!1,a=!0,d=0,c=0,h=e+"_C(Nterm";s.hAtoms={};for(let i=0,p=s.chainsSeq[e].length;i<p;++i){let p=e+"_"+s.chainsSeq[e][i].resi;if(s.residues.hasOwnProperty(p)){let i=s.firstAtomObjCls.getFirstCalphaAtomObj(s.residues[p]),m=s.secondaries[p];"H"==m?(i.ssbegin&&(++d,Object.keys(r).length>0&&(l=n+"H"+d.toString().padStart(2,"0")+")","coil"==t&&(s.selectionCls.selectResidueList(r,l,l,o,a),o||(o=!0)),r={})),n=e+"_H"+d.toString().padStart(2,"0"),r[p]=1,i.ssend&&(h=e+"_C(H"+d.toString().padStart(2,"0"),"helix"==t&&(s.selectionCls.selectResidueList(r,n,n,o,a),o||(o=!0)),r={})):"E"==m?(i.ssbegin&&(++c,Object.keys(r).length>0&&(l=n+"S"+c.toString().padStart(2,"0")+")","coil"==t&&(s.selectionCls.selectResidueList(r,l,l,o,a),o||(o=!0)),r={})),n=e+"_S"+c.toString().padStart(2,"0"),r[p]=1,i.ssend&&(h=e+"_C(S"+c.toString().padStart(2,"0"),"sheet"==t&&(s.selectionCls.selectResidueList(r,n,n,o,a),o||(o=!0)),r={})):(n=h+"-",r[p]=1)}}Object.keys(r).length>0&&(l=n+"Cterm)","coil"==t&&s.selectionCls.selectResidueList(r,l,l,o,a))}defineIgstrand(e,t){let s=this.icn3d,i=s.icn3dui;$("#"+s.pre+"dl_definedsets").hasClass("ui-dialog-content")&&$("#"+s.pre+"dl_definedsets").dialog("isOpen")||(i.htmlCls.dialogCls.openDlg("dl_definedsets","Select sets"),$("#"+s.pre+"atomsCustom").resizable());let n={},l=!1,r=!0;if(s.hAtoms={},"igdomain"==t){let t=s.chain2igArray[e];if(t&&t.length>0)for(let i=0,o=t.length;i<o;++i){let o=t[i].startPos,a=t[i].endPos,d=t[i].domainid;n={};for(let t=parseInt(o);t<=parseInt(a);++t){n[e+"_"+s.chainsSeq[e][t].resi]=1}let c=d;s.selectionCls.selectResidueList(n,c,c,l,r)}}else{let i,o,a,d,c,h=0,p=0,m="NT",u=!1;for(let g=0,f=s.chainsSeq[e].length;g<f;++g){let f,C,b,y=e+"_"+s.chainsSeq[e][g].resi;s.residues.hasOwnProperty(y)&&(f=s.resid2refnum[y],f&&(C=s.refnumCls.rmStrandFromRefnumlabel(f),o=f.replace(C,""),b=parseInt(C),"iganchor"==t?b>1e3&&"50"==C.substr(C.length-2,2)&&(n[y]=1):(d=s.residIgLoop.hasOwnProperty(y)?"igloop":"igstrand",u&&d!=c&&Object.keys(n).length>0&&("igstrand"==c?(++h,i="Strand-"+a+"-"+e+"-"+h.toString().padStart(3,"0"),i=i.replace(/'/g,"`"),"igstrand"==t&&(s.selectionCls.selectResidueList(n,i,i,l,r),l||(l=!0)),m=a):"igloop"==c&&(++p,i="Loop-"+m+"_"+o+"-"+e+"-"+p.toString().padStart(3,"0"),i=i.replace(/'/g,"`"),"igloop"==t&&(s.selectionCls.selectResidueList(n,i,i,l,r),l||(l=!0))),n={}),n[y]=1,a=o,c=d,u=!0)))}"iganchor"==t?(i="Anchor-"+e,s.selectionCls.selectResidueList(n,i,i,l,r)):"igstrand"==c?(++h,i="Strand-"+a+"-"+e+"-"+h.toString().padStart(3,"0"),i=i.replace(/'/g,"`"),"igstrand"==t&&s.selectionCls.selectResidueList(n,i,i,l,r)):"igloop"==c&&(++p,o="CT",i="Loop-"+m+"_"+o+"-"+e+"-"+p.toString().padStart(3,"0"),i=i.replace(/'/g,"`"),"igloop"==t&&s.selectionCls.selectResidueList(n,i,i,l,r))}}simplifyText(e){this.icn3d.icn3dui;let t,s,i="",n=!1,l=-1;for(t=0,s=(e=e.replace(/undefined/g," ")).length;t<s;++t)"-"==e[t]||" "==e[t]?(n&&t!==l&&(i+=l+1==t-1?(l+1+1).toString()+" "+e.substr(l+1,t-1-l)+", ":(l+1+1).toString()+"-"+(t-1+1).toString()+" "+e.substr(l+1,t-1-l)+", ",n=!1),l=t):n=!0;return n&&t==s&&(i+=l+1==t-1?(l+1+1).toString()+" "+e.substr(l+1,t-1-l)+", ":(l+1+1).toString()+"-"+(t-1+1).toString()+" "+e.substr(l+1,t-1-l)+", "),i}checkGiSeq(e,t,s,i,n,l,r){let o=this.icn3d;o.icn3dui;let a=this;if(r>20)return!1;if(void 0!==o.giSeq&&void 0!==o.giSeq[e]){let r=this.getFullText(s);return s=r.text,this.showNewTrack(e,t,s,void 0,void 0,i,n,l),!1}setTimeout((function(){a.checkGiSeq(e,t,s,i,n,l,r+1)}),100)}getFullText(e){this.icn3d.icn3dui;let t="",s=[],i=[],n=e.split(","),l=-1;for(let e=0,r=n.length;e<r;++e){let r=n[e].trim();if(0==r.length)continue;let o=r.split(" ");if(2!==o.length)continue;let a,d,c=o[1],h=o[0].split("-");if(2==h.length)a=h[0]-1,d=h[1]-1;else{if(1!=h.length)continue;a=h[0]-1,d=a}s.push(a),i.push(d);for(let e=0;e<a-l-1;++e)t+="-";let p=d-a+1;c.length>p?t+=c.substr(0,p):t+=c;for(let e=0;e<p-c.length;++e)t+="-";l=d}return{text:t,fromArray:s,toArray:i}}setCustomFile(e,t,s,i){var n=this.icn3d,l=n.icn3dui;let r=this,o=$("#"+n.pre+"customcolor_chainid").val(),a=$("#"+n.pre+"cstcolorfile")[0].files[0];if(a){l.utilsCls.checkFileAPI();let n=new FileReader;n.onload=function(n){let a=r.icn3d,d=n.target.result.split("\n");void 0===a.queryresi2score&&(a.queryresi2score={}),a.queryresi2score[o]={};for(let e=0,t=d.length;e<t;++e)if(""!==d[e].trim()){let t=d[e].split(/\s+/);a.queryresi2score[o][t[0]]=t[1]}let c=Object.keys(a.queryresi2score[o]),h=Math.min.apply(null,c),p=Math.max.apply(null,c),m="";for(let e=h;e<=p;++e)a.queryresi2score[o].hasOwnProperty(e)?m+=Math.round(a.queryresi2score[o][e]/11):m+="_";if("color"==e){a.opts.color="align custom",a.setColorCls.setColorByOptions(a.opts,a.hAtoms),a.hlUpdateCls.updateHlAll(),l.htmlCls.clickMenuCls.setLogCmd("color align custom | "+o+" | range "+h+"_"+p+" | "+m+" | colorrange "+t+" "+s+" "+i,!0);let e=l.htmlCls.clickMenuCls.setLegendHtml();$("#"+l.pre+"dl_legend_html").html(e),l.htmlCls.dialogCls.openDlg("dl_legend","Color range")}else"tube"==e&&(a.setOptionCls.setStyle("proteins","custom tube"),l.htmlCls.clickMenuCls.setLogCmd("color tube | "+o+" | range "+h+"_"+p+" | "+m,!0));a.drawCls.draw()},n.readAsText(a)}else alert("Please select a file before clicking 'Load'")}async getMsa(e,t,s){let i=this.icn3d,n=i.icn3dui,l=[t],r=[],o=n.htmlCls.baseUrl+"/vastdyn/vastdyn.cgi?chainlist="+e,a=await n.getAjaxPromise(o,"jsonp"),d=0,c=0,h=0;for(let e in a){let t=a[e],s=e.indexOf(".");-1!=s&&(e=e.substr(0,s)),l.push(e),t.length>d&&(d=t.length,c=h),++h}o=n.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=msa";let p=e.split(","),m={};m[t]=0;for(let e=0,t=p.length;e<t;++e)m[p[e]]=e+1;let u=p[c];p.splice(c,1);let g=s||t;p.length>0&&(g+=","+p.join(","));let f={targets:u,queries:g},C=await n.getAjaxPostPromise(o,f);if(!C.data)return void console.log("The protein accessions "+u+","+g+" can not be aligned...");let b=[];i.qt_start_end={};let y=[],v=[],_=Object.keys(C.targets)[0],w=C.targets[_].seqdata;p.splice(0,0,t);for(let e=0,s=p.length;e<s;++e){let s,n,l;if(!C.data[e])continue;s=C.data[e].query,l=s.acc.length<=5?s.acc.substr(0,4)+"_"+s.acc.substr(4,1):s.acc,0==e&&(l=t),y.push(l),_=Object.keys(C.data[e].targets)[0],n=C.data[e].targets[_],n=n.hsps[0],v.push(s.seqdata);let r=100*n.scores.num_ident+s.sz;i.qt_start_end[e]=[];let o=n.segs;for(let t=0,s=o.length;t<s;++t){let s=o[t],n={t_start:s.orifrom,t_end:s.orito,q_start:s.from,q_end:s.to};i.qt_start_end[e].push(n)}b.push({index:e,alignLen:r})}p=y,b.sort((function(e,t){return t.alignLen-e.alignLen}));let S=9999,A=-1;for(let e=0,t=p.length;e<t;++e)if(i.qt_start_end[e])for(let t=0,s=i.qt_start_end[e].length;t<s;++t){let s,n;s=i.qt_start_end[e][t].t_start,n=i.qt_start_end[e][t].t_end;for(let e=s;e<=n;++e)e<S&&(S=e),e>A&&(A=e)}let x=S,k=w.length-(A+1),O=[],R=[];for(let e=0,t=p.length;e<t;++e){if(!i.qt_start_end[e])continue;let t=i.qt_start_end[e][0].q_start;O.push(t),x<t&&(x=t);let s=i.qt_start_end[e].length-1;t=i.qt_start_end[e][s].q_end,R.push(t);let n=v[e].length-(t+1);k<n&&(k=n)}i.msaSeq={},i.msaSeq[u]="";for(let e=S;e<=A;++e)i.msaSeq[u]+=w[e];let I=[0];for(let e=0,t=b.length;e<t;++e){let t=b[e].index;I.push(t),i.msaSeq[p[t]]="",v[t]&&i.setSeqAlignCls.mergeTwoSeqForAllSimple(u,p,t,I,S,A,v)}let E,T="";for(let e=0;e<x-S;++e)T+="-";for(let e=0;e<S;++e)T+=w[e];i.msaSeq[u]=T+i.msaSeq[u];for(let e=0,t=p.length;e<t;++e){T="";for(let t=0;t<x-O[e];++t)T+="-";for(let t=0;t<O[e];++t)T+=v[e][t];i.msaSeq[p[e]]=T+i.msaSeq[p[e]]}for(let e=A+1;e<w.length;++e)i.msaSeq[u]+=w[e];E=w.length-(A+1);for(let e=0;e<k-E;++e)i.msaSeq[u]+="-";for(let e=0,t=p.length;e<t;++e){for(let t=R[e]+1;t<v[e].length;++t)i.msaSeq[p[e]]+=v[e][t];E=v[e].length-(R[e]+1);for(let t=0;t<k-E;++t)i.msaSeq[p[e]]+="-"}for(let e in i.msaSeq){let t=m[e];r[t]=i.msaSeq[e],l[t]=e}let P=[],D=[];for(let e=0,t=r.length;e<t;++e)r[e]&&(D.push(r[e]),P.push(l[e]));let M=D[0];return D.splice(0,1),P.splice(0,1),{trackTitleArray:P,trackSeqArray:D,seqFirst:M}}async getIsoformMsa(e,t){let s=this.icn3d,i=s.icn3dui,n=[],l=[],r=i.htmlCls.baseUrl+"/vastdyn/vastdyn.cgi?chainlist="+e,o=await i.getAjaxPromise(r,"jsonp"),a=0,d=0,c=0,h=[],p=[];for(let e in o){let t=o[e];p.push(t);let s=e.indexOf(".");-1!=s&&(e=e.substr(0,s)),h.push(e),t.length>a&&(a=t.length,d=c),++c}s.qt_start_end={};let m="genomeRes",u={};for(let e=0,i=h.length;e<i;++e){let i=h[e];u[i]=e,s.qt_start_end[e]=[];let n=t[i];for(let t=0,i=n.length;t<i;++t){let i=n[t],l={t_start:s.exonOrder*i.genResStart,t_end:s.exonOrder*i.genResEnd,q_start:i.resStart,q_end:i.resEnd};s.qt_start_end[e].push(l)}}let g=999999999,f=-999999999;for(let e=0,t=h.length;e<t;++e)if(s.qt_start_end[e])for(let t=0,i=s.qt_start_end[e].length;t<i;++t){let i,n;i=s.qt_start_end[e][t].t_start,n=s.qt_start_end[e][t].t_end;for(let e=i;e<=n;++e)e<g&&(g=e),e>f&&(f=e)}for(let e=0,t=h.length;e<t;++e){let t=s.qt_start_end[e];for(let e=0,s=t.length;e<s;++e){let s=t[e];s.t_start-=g,s.t_end-=g}}s.msaSeq={},s.msaSeq.genomeRes="";let C=f-g;for(let e=0;e<=C;++e)s.msaSeq.genomeRes+="X";let b=[0];for(let e=0,t=h.length;e<t;++e)b.push(e),s.msaSeq[h[e]]="",p[e]&&s.setSeqAlignCls.mergeTwoSeqForAllSimple(m,h,e,b,0,C,p);for(let e in s.msaSeq){let t=u[e];void 0!==t&&(l[t]=s.msaSeq[e],n[t]=e)}let y=[];for(let e=0,t=l.length;e<t;++e)y[e]="";for(let e=0,t=l[d].length;e<t;++e){let t="-"!=l[d][e];if(!t)for(let s=0,i=l.length;s<i;++s)if("-"!=l[s][e]){t=!0;break}if(t)for(let t=0,s=l.length;t<s;++t)y[t]+=l[t][e]}return{trackTitleArray:n,trackSeqArray:y,maxIndex:d}}async showMsaTracks(e,t,s,i,n,l,r){let o=this.icn3d;o.icn3dui;for(let t=0,s=o.chainsSeq[e].length;t<s;++t){o.ParserUtilsCls.getResi(e,t)==n&&(o.startposGiSeq=t)}if(void 0===o.startposGiSeq)return void alert('Please double check the start position before clicking "Add Track"');o.targetGapHash={};let a,d,c="-",h=0,p=0,m=0,u=!1,g=0,f=0,C=t.length;o.seqStartLen||(o.seqStartLen={}),o.seqEndLen||(o.seqEndLen={});for(let s=0,i=t.length;s<i;++s)"-"==t[s]&&t[s]!=c&&(a=p,m=0),"-"==c&&t[s]!=c&&p>0&&(d=h,o.targetGapHash[a+o.startposGiSeq]={from:a+o.startposGiSeq,to:d+m-1+o.startposGiSeq}),c=t[s],h=p,"-"!=t[s]?(++p,f=s,o.seqEndLen[e]=C-1-f,u||(g=s,o.seqStartLen[e]=g,u=!0)):++m;o.maxAnnoLength<o.maxAnnoLengthOri+o.seqStartLen[e]+o.seqEndLen[e]&&(o.maxAnnoLength=o.maxAnnoLengthOri+o.seqStartLen[e]+o.seqEndLen[e]),await o.annotationCls.resetAnnoAll();let b="",y=0;for(let e in o.targetGapHash)y>0&&(b+=" "),b+=e+"_"+o.targetGapHash[e].from+"_"+o.targetGapHash[e].to,++y;let v={};for(let a=0,d=i.length;a<d;++a){let d=n,c="";for(let e=0;e<o.startposGiSeq;++e){if(o.targetGapHash.hasOwnProperty(e))for(let t=0;t<o.targetGapHash[e].to-o.targetGapHash[e].from+1;++t)c+="-";c+="-"}let h,p="-",m=[],u=[],g=!1,f=0;for(let e=0;e<C;++e)0==a&&(v[d]=0),h=i[a][e],"-"==p&&"-"!=h&&m.push(e),"-"!=p&&"-"==h&&u.push(e-1),"-"!=h&&(g||(f=e,g=!0)),c+=h,"-"!=t[e]&&(t[e]==i[a][e]&&++v[d],++d),p=h;"-"!=p&&u.push(C-1);let b=s[a].length<20?s[a]:s[a].substr(0,20)+"...",y=!0,_=r?r[s[a]]:void 0;this.showNewTrack(e,b,c,void 0,void 0,l,void 0,y,m,u,f,_)}o.opts.color="exon",o.legendTableCls.showColorLegend(o.opts.color),o.hlUpdateCls.updateHlAll(),o.drawCls.draw()}processAccList(e){this.icn3d.icn3dui;let t=e.split(","),s={},i="";for(let e=0,n=t.length;e<n;++e){let n=t[e];if(s.hasOwnProperty(n))continue;s[n]=1;let l=n.indexOf(".");i+=-1!=l?n.substr(0,l):n,e<t.length-1&&(i+=",")}return i}async addExonTracks(e,t,s,i){let n,l=this.icn3d,r=l.icn3dui,o=[],a=[],d=r.htmlCls.baseUrl+"/vastdyn/vastdyn.cgi?geneid2isoforms="+t,c=await r.getAjaxPromise(d,"jsonp"),h=c.acclist,p=c.exons,m={},u="";l.exonOrder=1;for(let e=0,t=h.length;e<t;++e){let s=h[e],i=s.indexOf("."),n=-1!=i?s.substr(0,i):s,r=0,o=0,a=[];for(let e=0,t=p[s].length;e<t;++e){let i=p[s][e].split("-");i[0]=parseInt(i[0]),i[1]=parseInt(i[1]),i[2]=parseInt(i[2]),l.exonOrder=i[0]<i[1]?1:-1;let n=i[0]+"-"+i[1];r+=e==t-1?i[2]-3:i[2];let d=parseInt(o/3+.5),c=parseInt(r/3+.5)-1,h=parseInt(i[0]/3+.5),m=h+l.exonOrder*(c-d);a.push({genomeRange:n,genResStart:h,genResEnd:m,resStart:d,resEnd:c}),o=r}m[n]=a,u+=n,e<t-1&&(u+=",")}let g=await this.getIsoformMsa(u,m);o=g.trackTitleArray,a=g.trackSeqArray;let f,C=g.maxIndex,b=o[C],y=e.substr(0,e.indexOf("_"));if(y.length>5?(l.uniprot2acc&&l.uniprot2acc[y]&&(y=l.uniprot2acc[y]),f=y):f=e,y.length>5){let e="";for(let t=0,s=l.chainsSeq.length;t<s;++t)e+=l.chainsSeq[t].resn;g=await this.getMsa(b,f,e)}else g=await this.getMsa(b,f);g.trackTitleArray;let v=g.trackSeqArray;n=g.seqFirst;let _=a[C],w=v[0],S=0,A=0,x=a.length;for(;S<_.length&&A<w.length;){if(_[S]!=w[A])if("-"==_[S])w=w.substr(0,A)+"-"+w.substr(A),n=n.substr(0,A)+"-"+n.substr(A);else for(let e=0;e<x;++e)a[e]=a[e].substr(0,S)+"-"+a[e].substr(S);++S,++A}await this.showMsaTracks(e,n,o,a,s,i,m),r.htmlCls.clickMenuCls.setLogCmd("add exon track | chainid "+e+" | geneid "+t+" | startpos "+s+" | type "+i,!0)}async addMsaTracks(e,t,s,i){let n,l=this.icn3d.icn3dui,r=[],o=[],a=i.split(">"),d=a[1].indexOf("\n");n=a[1].substr(d+1).replace(/\n/g,"");for(let e=2,t=a.length;e<t;++e){let t=a[e].indexOf("\n"),s=a[e].substr(0,t);-1!=s.indexOf("|")&&(s=s.split("|")[1]),r.push(s);let i=a[e].substr(t+1).replace(/\n/g,"");o.push(i)}await this.showMsaTracks(e,n,r,o,t,s),l.htmlCls.clickMenuCls.setLogCmd("add msa track | chainid "+e+" | startpos "+t+" | type "+s+" | fastaList "+i,!0)}}class Tt{constructor(e){this.icn3d=e}hideAllAnno(){let e=this.icn3d;e.icn3dui,this.setAnnoSeqBase(!1),$("[id^="+e.pre+"custom]").hide()}setAnnoSeqBase(e){let t=this.icn3d;t.icn3dui;let s=["cdd","clinvar","snp","site","ptm","ssbond","crosslink","transmem","domain","interaction","ig"];for(let i in s){let n=s[i];e?$("[id^="+t.pre+n+"]").show():$("[id^="+t.pre+n+"]").hide()}}setAnnoTabBase(e){let t=this.icn3d;t.icn3dui;let s=["all","cdd","clinvar","snp","binding","ptm","ssbond","crosslink","transmem","3dd","custom","interact","ig"];for(let i in s){let n=s[i];$("#"+t.pre+"anno_"+n).length&&($("#"+t.pre+"anno_"+n)[0].checked=e)}}async setAnnoTabAll(){let e=this.icn3d;e.icn3dui,this.setAnnoTabBase(!0),this.setAnnoSeqBase(!0),await this.updateClinvar(),await this.updateSnp(),this.updateDomain(),await this.updatePTM(),this.updateSsbond(),this.updateCrosslink(),await this.updateTransmem(),e.bRunRefnumAgain=!0,await this.updateIg(),e.bRunRefnumAgain=!1,this.updateInteraction()}hideAnnoTabAll(){this.icn3d.icn3dui,this.setAnnoTabBase(!1),this.hideAllAnno()}async resetAnnoAll(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"dt_]").html(""),$("[id^="+e.pre+"tt_]").html(""),$("[id^="+e.pre+"ov_]").html(""),await e.showAnnoCls.processSeqData(e.chainid_seq),this.setAnnoViewAndDisplay("detailed view"),await this.resetAnnoTabAll()}async resetAnnoTabAll(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"anno_binding").length&&$("#"+e.pre+"anno_binding")[0].checked&&$("[id^="+e.pre+"site]").show(),$("#"+e.pre+"anno_snp").length&&$("#"+e.pre+"anno_snp")[0].checked&&(e.bSnpShown=!1,await this.updateSnp(),$("[id^="+e.pre+"snp]").show()),$("#"+e.pre+"anno_clinvar").length&&$("#"+e.pre+"anno_clinvar")[0].checked&&(e.bClinvarShown=!1,await this.updateClinvar(),$("[id^="+e.pre+"clinvar]").show()),$("#"+e.pre+"anno_cdd").length&&$("#"+e.pre+"anno_cdd")[0].checked&&$("[id^="+e.pre+"cdd]").show(),$("#"+e.pre+"anno_3dd").length&&$("#"+e.pre+"anno_3dd")[0].checked&&($("[id^="+e.pre+"domain]").show(),e.bDomainShown=!1,this.updateDomain()),$("#"+e.pre+"anno_interact").length&&$("#"+e.pre+"anno_interact")[0].checked&&($("[id^="+e.pre+"interaction]").show(),e.bInteractionShown=!1,this.updateInteraction()),$("#"+e.pre+"anno_ptm").length&&$("#"+e.pre+"anno_ptm")[0].checked&&(e.bPTMShown=!1,await this.updatePTM(),$("[id^="+e.pre+"ptm]").show()),$("#"+e.pre+"anno_custom").length&&$("#"+e.pre+"anno_custom")[0].checked&&$("[id^="+e.pre+"custom]").show(),$("#"+e.pre+"anno_ssbond").length&&$("#"+e.pre+"anno_ssbond")[0].checked&&($("[id^="+e.pre+"ssbond]").show(),e.bSSbondShown=!1,this.updateSsbond()),$("#"+e.pre+"anno_crosslink").length&&$("#"+e.pre+"anno_crosslink")[0].checked&&($("[id^="+e.pre+"crosslink]").show(),e.bCrosslinkShown=!1,this.updateCrosslink()),$("#"+e.pre+"anno_transmem").length&&$("#"+e.pre+"anno_transmem")[0].checked&&(e.bTranememShown=!1,await this.updateTransmem(),$("[id^="+e.pre+"transmem]").show()),($("#"+e.pre+"anno_ig").length&&$("#"+e.pre+"anno_ig")[0].checked||e.bShowRefnum)&&(e.bRunRefnumAgain=!1,await this.updateIg(),$("[id^="+e.pre+"ig]").show())}setAnnoTabCustom(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"custom]").show(),$("#"+e.pre+"anno_custom").length&&($("#"+e.pre+"anno_custom")[0].checked=!0)}hideAnnoTabCustom(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"custom]").hide(),$("#"+e.pre+"anno_custom").length&&($("#"+e.pre+"anno_custom")[0].checked=!1)}async setAnnoTabClinvar(){let e=this.icn3d;e.icn3dui,await this.updateClinvar(),$("[id^="+e.pre+"clinvar]").show(),$("#"+e.pre+"anno_clinvar").length&&($("#"+e.pre+"anno_clinvar")[0].checked=!0)}hideAnnoTabClinvar(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"clinvar]").hide(),$("#"+e.pre+"anno_clinvar").length&&($("#"+e.pre+"anno_clinvar")[0].checked=!1)}async setAnnoTabSnp(){let e=this.icn3d;e.icn3dui,await this.updateSnp(),$("[id^="+e.pre+"snp]").show(),$("#"+e.pre+"anno_snp").length&&($("#"+e.pre+"anno_snp")[0].checked=!0)}hideAnnoTabSnp(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"snp]").hide(),$("#"+e.pre+"anno_snp").length&&($("#"+e.pre+"anno_snp")[0].checked=!1)}setAnnoTabCdd(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"cdd]").show(),$("#"+e.pre+"anno_cdd").length&&($("#"+e.pre+"anno_cdd")[0].checked=!0)}hideAnnoTabCdd(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"cdd]").hide(),$("#"+e.pre+"anno_cdd").length&&($("#"+e.pre+"anno_cdd")[0].checked=!1)}setAnnoTab3ddomain(){let e=this.icn3d;e.icn3dui,this.updateDomain(),$("[id^="+e.pre+"domain]").show(),$("#"+e.pre+"anno_3dd").length&&($("#"+e.pre+"anno_3dd")[0].checked=!0)}hideAnnoTab3ddomain(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"domain]").hide(),$("#"+e.pre+"anno_3dd").length&&($("#"+e.pre+"anno_3dd")[0].checked=!1)}setAnnoTabSite(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"site]").show(),$("[id^="+e.pre+"feat]").show(),$("#"+e.pre+"anno_binding").length&&($("#"+e.pre+"anno_binding")[0].checked=!0)}hideAnnoTabSite(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"site]").hide(),$("[id^="+e.pre+"feat]").hide(),$("#"+e.pre+"anno_binding").length&&($("#"+e.pre+"anno_binding")[0].checked=!1)}setAnnoTabInteraction(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"interaction]").show(),$("#"+e.pre+"anno_interact").length&&($("#"+e.pre+"anno_interact")[0].checked=!0),this.updateInteraction()}hideAnnoTabInteraction(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"interaction]").hide(),$("#"+e.pre+"anno_interact").length&&($("#"+e.pre+"anno_interact")[0].checked=!1)}async setAnnoTabPTM(){let e=this.icn3d;e.icn3dui,await this.updatePTM(),$("[id^="+e.pre+"ptm]").show(),$("#"+e.pre+"anno_ptm").length&&($("#"+e.pre+"anno_ptm")[0].checked=!0)}hideAnnoTabPTM(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"ptm]").hide(),$("#"+e.pre+"anno_ptm").length&&($("#"+e.pre+"anno_ptm")[0].checked=!1)}setAnnoTabSsbond(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"ssbond]").show(),$("#"+e.pre+"anno_ssbond").length&&($("#"+e.pre+"anno_ssbond")[0].checked=!0),this.updateSsbond()}hideAnnoTabSsbond(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"ssbond]").hide(),$("#"+e.pre+"anno_ssbond").length&&($("#"+e.pre+"anno_ssbond")[0].checked=!1)}setAnnoTabCrosslink(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"crosslink]").show(),$("#"+e.pre+"anno_crosslink").length&&($("#"+e.pre+"anno_crosslink")[0].checked=!0),this.updateCrosslink()}hideAnnoTabCrosslink(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"crosslink]").hide(),$("#"+e.pre+"anno_crosslink").length&&($("#"+e.pre+"anno_crosslink")[0].checked=!1)}async setAnnoTabTransmem(){let e=this.icn3d;e.icn3dui,await this.updateTransmem(),$("[id^="+e.pre+"transmem]").show(),$("#"+e.pre+"anno_transmem").length&&($("#"+e.pre+"anno_transmem")[0].checked=!0)}hideAnnoTabTransmem(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"transmem]").hide(),$("#"+e.pre+"anno_transmem").length&&($("#"+e.pre+"anno_transmem")[0].checked=!1)}async setAnnoTabIg(e,t){let s=this.icn3d;s.icn3dui,await this.updateIg(e,t),$("[id^="+s.pre+"ig]").show(),$("#"+s.pre+"anno_ig").length&&($("#"+s.pre+"anno_ig")[0].checked=!0)}hideAnnoTabIg(){let e=this.icn3d;e.icn3dui,$("[id^="+e.pre+"ig]").hide(),$("#"+e.pre+"anno_ig").length&&($("#"+e.pre+"anno_ig")[0].checked=!1)}setTabs(){let e=this.icn3d,t=e.icn3dui,s=this;$("#"+e.pre+"dl_addtrack_tabs").tabs(),$("#"+e.pre+"dl_anno_view_tabs").tabs(),t.myEventCls.onIds("#"+e.pre+"anno_all","click",(async function(i){$("#"+e.pre+"anno_all")[0].checked?(await s.setAnnoTabAll(),t.htmlCls.clickMenuCls.setLogCmd("set annotation all",!0)):(s.hideAnnoTabAll(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation all",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_binding","click",(function(i){$("#"+e.pre+"anno_binding")[0].checked?(s.setAnnoTabSite(),t.htmlCls.clickMenuCls.setLogCmd("set annotation site",!0)):(s.hideAnnoTabSite(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation site",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_snp","click",(async function(i){$("#"+e.pre+"anno_snp")[0].checked?(await s.setAnnoTabSnp(),t.htmlCls.clickMenuCls.setLogCmd("set annotation snp",!0)):(s.hideAnnoTabSnp(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation snp",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_clinvar","click",(async function(i){$("#"+e.pre+"anno_clinvar")[0].checked?(await s.setAnnoTabClinvar(),t.htmlCls.clickMenuCls.setLogCmd("set annotation clinvar",!0)):(s.hideAnnoTabClinvar(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation clinvar",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_cdd","click",(function(e){s.clickCdd()})),t.myEventCls.onIds("#"+e.pre+"anno_3dd","click",(function(i){$("#"+e.pre+"anno_3dd")[0].checked?(s.setAnnoTab3ddomain(),t.htmlCls.clickMenuCls.setLogCmd("set annotation 3ddomain",!0)):(s.hideAnnoTab3ddomain(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation 3ddomain",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_interact","click",(function(i){$("#"+e.pre+"anno_interact")[0].checked?(s.setAnnoTabInteraction(),t.htmlCls.clickMenuCls.setLogCmd("set annotation interaction",!0)):(s.hideAnnoTabInteraction(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation interaction",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_ptm","click",(async function(i){$("#"+e.pre+"anno_ptm")[0].checked?(await s.setAnnoTabPTM(),t.htmlCls.clickMenuCls.setLogCmd("set annotation ptm",!0)):(s.hideAnnoTabPTM(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation ptm",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_custom","click",(function(i){$("#"+e.pre+"anno_custom")[0].checked?(s.setAnnoTabCustom(),t.htmlCls.clickMenuCls.setLogCmd("set annotation custom",!0)):(s.hideAnnoTabCustom(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation custom",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_ssbond","click",(function(i){$("#"+e.pre+"anno_ssbond")[0].checked?(s.setAnnoTabSsbond(),t.htmlCls.clickMenuCls.setLogCmd("set annotation ssbond",!0)):(s.hideAnnoTabSsbond(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation ssbond",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_crosslink","click",(function(i){$("#"+e.pre+"anno_crosslink")[0].checked?(s.setAnnoTabCrosslink(),t.htmlCls.clickMenuCls.setLogCmd("set annotation crosslink",!0)):(s.hideAnnoTabCrosslink(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation crosslink",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_transmem","click",(async function(i){$("#"+e.pre+"anno_transmem").length&&$("#"+e.pre+"anno_transmem")[0].checked?(await s.setAnnoTabTransmem(),t.htmlCls.clickMenuCls.setLogCmd("set annotation transmembrane",!0)):(s.hideAnnoTabTransmem(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation transmembrane",!0))})),t.myEventCls.onIds("#"+e.pre+"anno_ig","click",(async function(i){$("#"+e.pre+"anno_ig").length&&$("#"+e.pre+"anno_ig")[0].checked?(e.bRunRefnumAgain=!0,await s.setAnnoTabIg(),t.htmlCls.clickMenuCls.setLogCmd("set annotation ig",!0),e.bRunRefnumAgain=!1):(s.hideAnnoTabIg(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation ig",!0))}))}clickCdd(){let e=this.icn3d,t=e.icn3dui;$("[id^="+e.pre+"cdd]").length>0&&($("#"+e.pre+"anno_cdd")[0].checked?(this.setAnnoTabCdd(),t.htmlCls.clickMenuCls.setLogCmd("set annotation cdd",!0)):(this.hideAnnoTabCdd(),t.htmlCls.clickMenuCls.setLogCmd("hide annotation cdd",!0)))}showAnnoSelectedChains(){let e=this.icn3d,t=e.icn3dui,s={};for(let t in e.hAtoms){let i=e.atoms[t];s[i.structure+"_"+i.chain]=1}$("#"+e.pre+"dl_annotations > .icn3d-annotation").hide();for(let i in s){$("#"+e.pre+"anno_"+i).length&&$("#"+e.pre+"anno_"+i).show();let s=e.firstAtomObjCls.getFirstCalphaAtomObj(e.chains[i]);if(void 0!==s.resn){let i=t.utilsCls.residueName2Abbr(s.resn.substr(0,3));$("#"+e.pre+"anno_"+i).show()}}}showAnnoAllChains(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"dl_annotations > .icn3d-annotation").show()}setAnnoView(e){let t=this.icn3d;t.icn3dui.bNode||("detailed view"===e?(t.view="detailed view",$("#"+t.pre+"dl_anno_view_tabs").tabs("option","active",1)):(t.view="overview",$("#"+t.pre+"dl_anno_view_tabs").tabs("option","active",0)))}setAnnoDisplay(e,t){let s=this.icn3d;s.icn3dui;let i=["giseq","custom","site","ptm","snp","clinvar","cdd","domain","interaction","ssbond","crosslink","transmem","ig"];for(let n in i){let l=i[n];$("[id^="+s.pre+t+"_"+l+"]").attr("style",e)}}showFixedTitle(){this.icn3d.icn3dui;this.setAnnoDisplay("display:block;","tt")}hideFixedTitle(){this.icn3d.icn3dui;this.setAnnoDisplay("display:none!important;","tt")}setAnnoViewAndDisplay(e){let t=this.icn3d;if(t.icn3dui,"detailed view"===e){this.setAnnoView("detailed view");let e="display:block;";this.setAnnoDisplay(e,"dt"),$("#"+t.pre+"seqguide_wrapper").attr("style",e),e="display:none;",this.setAnnoDisplay(e,"ov")}else{this.setAnnoView("overview"),this.hideFixedTitle();let e="display:none;";this.setAnnoDisplay(e,"dt"),$("#"+t.pre+"seqguide_wrapper").attr("style",e),e="display:block;",this.setAnnoDisplay(e,"ov")}}async updateClinvar(){let e=this.icn3d;if(e.icn3dui,void 0===e.bClinvarShown||!e.bClinvarShown)for(let t in e.protein_chainid){let s=e.protein_chainid[t];await e.annoSnpClinVarCls.showClinvar(t,s)}e.bClinvarShown=!0}async updateSnp(){let e=this.icn3d;if(e.icn3dui,void 0===e.bSnpShown||!e.bSnpShown)for(let t in e.protein_chainid){let s=e.protein_chainid[t];await e.annoSnpClinVarCls.showSnp(t,s)}e.bSnpShown=!0}updateDomain(){let e=this.icn3d;e.icn3dui,void 0!==e.bDomainShown&&e.bDomainShown||e.annoDomainCls.showDomainAll(),e.bDomainShown=!0}updateInteraction(){let e=this.icn3d;if(e.icn3dui,void 0===e.bInteractionShown||!e.bInteractionShown)for(let t in e.interactChainbase){let s=e.interactChainbase[t];e.annoContactCls.showInteraction(t,s)}e.bInteractionShown=!0}async updatePTM(){let e=this.icn3d;if(e.icn3dui,void 0===e.bPTMShown||!e.bPTMShown)for(let t in e.PTMChainbase){let s=e.PTMChainbase[t];await e.annoPTMCls.showPTM(t,s,"ptm")}e.bPTMShown=!0}updateSsbond(){let e=this.icn3d;if(e.icn3dui,void 0===e.bSSbondShown||!e.bSSbondShown)for(let t in e.ssbondChainbase){let s=e.ssbondChainbase[t];e.annoSsbondCls.showSsbond(t,s)}e.bSSbondShown=!0}updateCrosslink(){let e=this.icn3d;if(e.icn3dui,void 0===e.bCrosslinkShown||!e.bCrosslinkShown)for(let t in e.crosslinkChainbase){let s=e.crosslinkChainbase[t];e.annoCrossLinkCls.showCrosslink(t,s)}e.bCrosslinkShown=!0}async updateTransmem(){let e=this.icn3d,t=e.icn3dui;if(void 0===e.bTranememShown||!e.bTranememShown)for(let s in e.protein_chainid){let i=e.protein_chainid[s];if(void 0!==t.cfg.opmid)e.annoTransMemCls.showTransmem(s,i);else if(e.bAfMem&&e.afmem_start_end){let t=e.afmem_start_end[0],n=e.afmem_start_end[1];await e.annoPTMCls.showPTM(s,i,"afmem",t,n)}else await e.annoPTMCls.showPTM(s,i,"transmem")}e.bTranememShown=!0}async updateIg(e,t){let s=this.icn3d,i=s.icn3dui;if(s.opts.color="ig strand",!e){s.hAtoms={};for(let e in s.protein_chainid)s.hAtoms=i.hashUtilsCls.unionHash(s.hAtoms,s.chains[e])}let n=s.firstAtomObjCls.getResiduesFromAtoms(s.hAtoms);for(let e in n)s.resid2refnum&&delete s.resid2refnum[e],s.residIgLoop&&delete s.residIgLoop[e],s.resid2domainid&&delete s.resid2domainid[e];s.bRunRefnumAgain=!0;for(let e in s.protein_chainid)await s.annoIgCls.showIg(e,t),s.bRunRefnumAgain=!1;s.bShowRefnum&&(s.hlUpdateCls.updateHlAll(),s.drawCls.draw())}}class Pt{constructor(e){this.icn3d=e}showAnnotations_part1(e){let t=this.icn3d,s=t.icn3dui;if(s.htmlCls.dialogCls.openDlg("dl_selectannotations","Sequences and Annotations"),(void 0===t.bAssemblyNote||!t.bAssemblyNote)&&void 0!==t.asuCnt){let e=" <br><div id='"+t.pre+"assembly_note' style='margin-left:5px;'><span class='icn3d-annoLargeTitle'>Assembly Tips:</span> Only the asymmetric unit is shown in the sequence window.<br>Click \"Assembly\" in the menu \"View\" to switch between asymmetric unit and biological assembly(<b>"+t.asuCnt+"</b> asymmetric unit).</div>";$("#"+t.pre+"dl_annotations_tabs").append(e),t.bAssemblyNote=!0}t.bResetAnno&&(t.giSeq={},t.currClin={},t.resi2disease_nonempty={},t.baseResi={},t.matchedPos={},$("#"+s.pre+"dl_annotations").empty(),t.annotationCls.setAnnoView("overview"));let i={},n={},l={};if(void 0===t.bAnnoShown||!t.bAnnoShown||t.bResetAnno){t.protein_chainid={};let r,o=Object.keys(t.chains);if(e){let s=t.resid2specCls.atoms2structureArray(e);o=[];for(let e=0,i=s.length;e<i;++e)o=o.concat(t.structures[s[e]])}void 0===t.giSeq&&(t.giSeq={}),void 0===t.currClin&&(t.currClin={}),void 0===t.resi2disease_nonempty&&(t.resi2disease_nonempty={}),void 0===t.baseResi&&(t.baseResi={}),void 0===t.matchedPos&&(t.matchedPos={}),r=s.bNode?500:s.cfg.notebook?s.htmlCls.WIDTH/2:$("#"+t.pre+"dl_selectannotations").dialog("option","width"),t.seqAnnWidth=r-120-60-50;for(let e=0,r=o.length;e<r;++e){Math.round(o[e].indexOf("_"));let r=t.firstAtomObjCls.getMiddleAtomObj(t.chains[o[e]],100);if(void 0===r&&(r=t.firstAtomObjCls.getFirstAtomObj(t.chains[o[e]])),void 0===r)continue;let a,d=o[e].substr(o[e].indexOf("_")+1);if(-1!==d.indexOf("_")?(d=d.substr(0,d.indexOf("_")),a=o[e].substr(0,o[e].indexOf("_"))+"_"+d):d.length>1&&"1"==d.substr(d.length-1)?(d=d.substr(0,d.length-1),a=o[e].substr(0,o[e].indexOf("_"))+"_"+d):a=o[e],t.proteins.hasOwnProperty(r.serial)&&t.chainsSeq[o[e]].length>1)t.protein_chainid[o[e]]=a;else if(t.nucleotides.hasOwnProperty(r.serial)&&t.chainsSeq[o[e]].length>1)i[o[e]]=a;else if(t.chainsSeq[o[e]].length>1)n[o[e]]=a;else{let s=t.chainsSeq[o[e]][0].name,i=o[e]+"_"+t.chainsSeq[o[e]][0].resi;void 0===l[s]&&(l[s]=[]),l[s].push(i)}if((void 0!==s.cfg.pdbid||void 0!==s.cfg.opmid||void 0!==s.cfg.mmcifid||void 0!==s.cfg.mmtfid)&&(t.proteins.hasOwnProperty(r.serial)||t.nucleotides.hasOwnProperty(r.serial)))for(let s=0,i=t.chainsSeq[o[e]].length;s<i;++s){let i=t.chainsSeq[o[e]][s];if(""!==i.name&&"-"!==i.name&&i.name==i.name.toUpperCase()){let s=o[e]+"_"+i.resi,n=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[s]);if(void 0===n&&(n=t.firstAtomObjCls.getFirstAtomObj(t.chains[o[e]])),t.proteins.hasOwnProperty(n.serial)||t.nucleotides.hasOwnProperty(n.serial))continue;{let e=i.name.trim();void 0===l[e]&&(l[e]=[]),l[e].push(s)}}}}t.maxAnnoLengthOri=1;for(let e in t.chainsSeq)t.chainsSeq[e].length>t.maxAnnoLengthOri&&(t.protein_chainid.hasOwnProperty(e)||i.hasOwnProperty(e))&&(t.maxAnnoLengthOri=t.chainsSeq[e].length);t.maxAnnoLength=t.maxAnnoLengthOri}return{nucleotide_chainid:i,chemical_chainid:n,chemical_set:l}}async showAnnotations(e){let t=this.icn3d,s=t.icn3dui,i=this,n=this.showAnnotations_part1(e),l=n.nucleotide_chainid,r=n.chemical_chainid,o=n.chemical_set;if(!t.bAnnoShown||t.bResetAnno)if(t.bAnnoShown=!0,void 0===s.cfg.blast_rep_id){if(t.bFullUi){if(void 0!==s.cfg.mmtfid){let e=Object.keys(t.structures)[0];await t.mmcifParserCls.downloadMmcifSymmetry(e,"mmtfid")}await this.showAnnoSeqData(l,r,o)}}else if(void 0===s.cfg.blast_rep_id||t.bSmithwm||t.bLocalSmithwm){if(void 0!==s.cfg.blast_rep_id&&(t.bSmithwm||t.bLocalSmithwm)){let e,n,a=[s.cfg.blast_rep_id];if(-1!=s.cfg.query_id.indexOf(">")?n=s.cfg.query_id.substr(s.cfg.query_id.indexOf("\n")+1):!/\d/.test(s.cfg.query_id)||s.cfg.query_id.length>50?n=s.cfg.query_id:a.push(s.cfg.query_id),t.blastAcxn){let i=s.cfg.afid+"_A",n="";for(let e=0,s=t.chainsSeq[i].length;e<s;++e)n+=t.chainsSeq[i][e].name;e=n}else{let t=s.htmlCls.baseUrl+"/vastdyn/vastdyn.cgi?chainlist="+a,i=await s.getAjaxPromise(t,"jsonp",!1,"Can not retrieve the sequence of the accession(s) "+a.join(", "));for(let t in i)e=i[t]}let d=1,c=-1,h=-1,p=-1,m=!!t.bLocalSmithwm;t.seqStructAlignDataLocalSmithwm=t.alignSWCls.alignSW(e,n,d,c,h,p,m),await i.showAnnoSeqData(l,r,o)}}else{let e=s.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=querytarget",n={targets:s.cfg.blast_rep_id,queries:s.cfg.query_id};if(void 0!==s.cfg.query_from_to){let e=s.cfg.query_from_to.split(":");for(let t=0,s=e.length;t<s;++t)e[t]=parseInt(e[t])-1;n.queries=s.cfg.query_id+":"+e.join(":")}if(void 0!==s.cfg.target_from_to){let e=s.cfg.target_from_to.split(":");for(let t=0,s=e.length;t<s;++t)e[t]=parseInt(e[t])-1;n.targets=s.cfg.blast_rep_id+":"+e.join(":")}if(t.blastAcxn){let e=s.cfg.afid+"_A",i="";for(let s=0,n=t.chainsSeq[e].length;s<n;++s)i+=t.chainsSeq[e][s].name;n.targets=i}let a=await s.getAjaxPostPromise(e,n);t.seqStructAlignData=a,await i.showAnnoSeqData(l,r,o)}}async showAnnoSeqData(e,t,s){let i=this.icn3d,n=i.icn3dui;n.bNode||await this.getAnnotationData();let l=0;for(let t in e)this.getSequenceData(t,e[t],"nucleotide",l),++l;i.interactChainbase=n.hashUtilsCls.unionHash(i.interactChainbase,i.protein_chainid),i.interactChainbase=n.hashUtilsCls.unionHash(i.interactChainbase,e),l=0;for(let e in t)this.getSequenceData(e,t[e],"chemical",l),++l;i.interactChainbase=n.hashUtilsCls.unionHash(i.interactChainbase,t),i.PTMChainbase=n.hashUtilsCls.unionHash(i.PTMChainbase,i.protein_chainid),i.ssbondChainbase=n.hashUtilsCls.unionHash(i.ssbondChainbase,i.protein_chainid),i.ssbondChainbase=n.hashUtilsCls.unionHash(i.ssbondChainbase,t),i.crosslinkChainbase=n.hashUtilsCls.unionHash(i.crosslinkChainbase,i.protein_chainid),i.crosslinkChainbase=n.hashUtilsCls.unionHash(i.crosslinkChainbase,e),i.crosslinkChainbase=n.hashUtilsCls.unionHash(i.crosslinkChainbase,t);for(let e in s)this.getCombinedSequenceData(e,s[e],l),++l;n.bNode||(this.enableHlSeq(),i.annotationCls.hideAllAnno(),i.annotationCls.clickCdd())}async getAnnotationData(){let e=this.icn3d,t=e.icn3dui,s=this,i=$.map(e.protein_chainid,(function(e){return e})),n=0;e.chainsGene||(e.chainsGene={});for(let s in e.protein_chainid){let i=s.substr(0,s.indexOf("_"));if(i.length>5){let n;e.uniprot2acc&&e.uniprot2acc[i]?e.uniprot2acc[i]:e.uniprot2acc={},n="https://rest.uniprot.org/uniprotkb/search?format=json&fields=xref_geneid,gene_names&query="+i;let l=await t.getAjaxPromise(n,"json"),r=l.results[0]&&l.results[0].uniProtKBCrossReferences&&l.results[0].uniProtKBCrossReferences[0]?l.results[0].uniProtKBCrossReferences[0].id:void 0,o=l.results[0]&&l.results[0].genes&&l.results[0].genes[0]&&l.results[0].genes[0].geneName?l.results[0].genes[0].geneName.value:"ID "+r;e.chainsGene[s]={geneId:r,geneSymbol:o}}}for(let s in e.protein_chainid){let i=t.utilsCls.isMobile()?"none":"button",l=e.showSeqCls.getProteinName(s),r=l,o=0==n?"<span class='icn3d-annoLargeTitle'><b>Proteins</b>: </span><br><br>":"",a=e.chainsGene[s]&&e.chainsGene[s].geneId&&e.chainsGene[s].geneDesc?"(Gene: <a href='https://www.ncbi.nlm.nih.gov/gene/"+e.chainsGene[s].geneId+"?report=gene_table' target='_blank' title='"+e.chainsGene[s].geneDesc+"'>"+e.chainsGene[s].geneSymbol+"</a>)":"",d=s.substr(0,s.indexOf("_")),c=d.length>5?'<a href="https://alphafold.ebi.ac.uk/entry/'+d+'" target="_blank">'+s+"</a>":s,h="<div id='"+e.pre+"anno_"+s+"' class='icn3d-annotation'>"+o+"<span style='font-weight:bold;'>Annotations of "+c+"</span>: <a class='icn3d-blue' href='https://www.ncbi.nlm.nih.gov/protein?term="+s+"' target='_blank' title='"+l+"'>"+r+"</a>"+a+"&nbsp;&nbsp;&nbsp;"+this.addButton(s,"icn3d-addtrack","Add Track","Add a custom track",60,i)+"&nbsp;&nbsp;&nbsp;";h+=this.addButton(s,"icn3d-customcolor","Custom Color/Tube","Use a custom file to define the colors or tubes in 3D structure",110,i)+"&nbsp;&nbsp;&nbsp;",h+=this.addButton(s,"icn3d-helixsets","Helix Sets",'Define sets for each helix in this chain and add them to the menu of "Defined Sets"',60,i)+"&nbsp;"+this.addButton(s,"icn3d-sheetsets","Sheet Sets",'Define sets for each sheet in this chain and add them to the menu of "Defined Sets"',60,i)+"&nbsp;"+this.addButton(s,"icn3d-coilsets","Coil Sets",'Define sets for each coil in this chain and add them to the menu of "Defined Sets"',60,i),h+="&nbsp;&nbsp;&nbsp;"+this.addButton(s,"icn3d-iganchorsets","Ig Anchor Set",'Define the set for all Ig anchors in this chain and add them to the menu of "Defined Sets"',80,i)+"&nbsp;"+this.addButton(s,"icn3d-igstrandsets","Ig Strand Sets",'Define sets for each Ig strand in this chain and add them to the menu of "Defined Sets"',80,i)+"&nbsp;"+this.addButton(s,"icn3d-igloopsets","Ig Loop Sets",'Define sets for each Ig loop in this chain and add them to the menu of "Defined Sets"',80,i)+"&nbsp;"+this.addButton(s,"icn3d-igdomainsets","Ig Domain Sets",'Define sets for each Ig domain in this chain and add them to the menu of "Defined Sets"',80,i),$("#"+e.pre+"dl_annotations").append(h);let p=["giseq","cdd","clinvar","snp","site","ptm","ssbond","crosslink","transmem","domain","custom","interaction","ig"];for(let t in p){let i=p[t];$("#"+e.pre+"anno_"+s).append(this.getAnDiv(s,i))}$("#"+e.pre+"anno_"+s).append("<br><hr><br>"),++n}if(t.bNode||e.annoCddSiteCls.setToolTip(),void 0!==e.chainid_seq)await this.processSeqData(e.chainid_seq);else try{let n=[],l=[];for(let e=0,t=i.length;e<t;++e){i[e].substr(0,i.indexOf("_")).length>=6?l.push(i[e]):n.push(i[e])}if(n.length>0){let s=t.htmlCls.baseUrl+"/vastdyn/vastdyn.cgi?chainlist="+n;e.chainid_seq=await t.getAjaxPromise(s,"jsonp")}else e.chainid_seq={};for(let t=0,s=l.length;t<s;++t){let s=l[t],i="";for(let t=0,n=e.chainsSeq[s].length;t<n;++t)i+=e.chainsSeq[s][t].name;e.chainid_seq[s]=i}await s.processSeqData(e.chainid_seq)}catch(n){s.enableHlSeq(),t.bNode||console.log("No sequence data were found for the protein "+i+"...");for(let t in e.protein_chainid){let s=e.protein_chainid[t];e.showSeqCls.setAlternativeSeq(t,s),e.showSeqCls.showSeq(t,s)}return void await e.annoCddSiteCls.showCddSiteAll()}}getSequenceData(e,t,s,i){let n=this.icn3d;n.icn3dui;let l=n.showSeqCls.getProteinName(e),r=l;r.length>40&&(r=r.substr(0,40)+"...");let o="";0==i&&("protein"==s?o="<span class='icn3d-annoLargeTitle'><b>Proteins</b>: </span><br><br>":"nucleotide"==s?o="<span class='icn3d-annoLargeTitle'><b>Nucleotides</b>: </span><br><br>":"chemical"==s&&(o="<span class='icn3d-annoLargeTitle'><b>Chemicals/Ions/Water</b>: </span><br><br>")),$("#"+n.pre+"dl_annotations").append("<div id='"+n.pre+"anno_"+e+"' class='icn3d-annotation'>"+o+"<b>"+e+"</b>: <span title='"+l+"'>"+r+"</span> </div>"),$("#"+n.pre+"anno_"+e).append(this.getAnDiv(e,"giseq")),$("#"+n.pre+"anno_"+e).append(this.getAnDiv(e,"interaction")),$("#"+n.pre+"anno_"+e).append("<br><hr><br>"),n.giSeq[e]=[];for(let t=0;t<n.chainsSeq[e].length;++t){let s=n.chainsSeq[e][t].name;n.giSeq[e][t]=s}n.matchedPos[e]=0,n.baseResi[e]=n.chainsSeq[e][0].resi-n.matchedPos[e]-1,n.showSeqCls.showSeq(e,t,s)}getCombinedSequenceData(e,t,s){let i,n=this.icn3d,l=n.icn3dui,r=0==s?"<span class='icn3d-annoLargeTitle'><b>Chemicals/Ions/Water</b>: </span><br><br>":"",o=t[0].lastIndexOf("_"),a=t[0].substr(0,o),d=void 0!==l.cfg.mmdbid&&void 0!==n.chainid2sid?n.chainid2sid[a]:void 0;i=void 0!==d?"<b>"+e+" <a class='icn3d-blue' href='https://pubchem.ncbi.nlm.nih.gov/substance/"+d+"#section=2D-Structure' target='_blank'><img src='https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?sid="+d+"'></a></b>":"<b>"+e+"</b>",$("#"+n.pre+"dl_annotations").append("<div id='"+n.pre+"anno_"+e+"' class='icn3d-annotation'>"+r+i+"</div>"),$("#"+n.pre+"anno_"+e).append("<div id='"+n.pre+"giseq_"+e+"'><div id='"+n.pre+"dt_giseq_"+e+"' style='display:none'></div><div id='"+n.pre+"ov_giseq_"+e+"'></div></div>"),$("#"+n.pre+"anno_"+e).append("<br><hr><br>");let c='<div id="'+n.pre+'giseq_sequence" class="icn3d-dl_sequence">';c+='<div class="icn3d-seqTitle icn3d-link icn3d-blue" anno="sequence" gi="'+e+'" resn="'+e+'"><span style="white-space:nowrap;" title="Chemical '+e+'">Chem. '+e+"</span></div>",c+='<span class="icn3d-residueNum" style="width:60px!important;" title="starting protein sequence number">Count: '+t.length+"</span>",c+='<span class="icn3d-seqLine">';let h=c,p=c;for(let s=0,i=t.length;s<i;++s){let i=e,l=i;i.length>3&&(l=i.substr(0,3)),s<t.length-1&&(l+=",");let r=t[s],o=r.substr(r.lastIndexOf("_")+1);h+='<span id="giseq_'+n.pre+r+'" title="'+i+o+'" class="icn3d-residue icn3d-chemical">'+l+"</span>"}let m=l.htmlCls.GREY8,u=Math.round(n.seqAnnWidth*t.length/n.maxAnnoLength);u<1&&(u=1),p+='<div class="icn3d-seqTitle" style="display:inline-block; color:white; font-weight:bold; background-color:'+m+"; width:"+u+'px;">&nbsp;</div>',c="</span>",c+="<br>",c+="</div>",h+=c,p+=c,$("#"+n.pre+"dt_giseq_"+e).html(h),$("#"+n.pre+"ov_giseq_"+e).html(p)}async processSeqData(e){let t=this.icn3d,s=t.icn3dui;for(let i in t.protein_chainid){let n=t.protein_chainid[i];if(e.hasOwnProperty(n)){let s=e[n];t.giSeq[i]=s;let l="";for(let e=0;e<10&&e<t.chainsSeq[i].length;++e)l+=t.chainsSeq[i][e].name.substr(0,1);let r=s.toLowerCase().indexOf(l.toLowerCase());-1==r?(console.log("The gi sequence didn't match the protein sequence. The start of 3D protein sequence: "+l+". The gi sequence: "+s.substr(0,10)+"."),t.showSeqCls.setAlternativeSeq(i,n)):(t.matchedPos[i]=r,t.baseResi[i]=t.chainsSeq[i][0].resi-t.matchedPos[i]-1)}else s.bNode||console.log("No sequence data were found for the chain "+i+"..."),t.showSeqCls.setAlternativeSeq(i,n);if(s.cfg.blast_rep_id!=i)t.showSeqCls.showSeq(i,n);else if(s.cfg.blast_rep_id==i&&void 0===t.seqStructAlignData&&void 0===t.seqStructAlignDataSmithwm){let e,l,r,o=s.cfg.oriQuery_id?s.cfg.oriQuery_id:s.cfg.query_id;e=o.length>14?"Query: "+o.substr(0,6)+"...":isNaN(s.cfg.query_id)?"Query: "+o:"Query: gi "+o;let a="cannot be aligned";t.queryStart="",t.queryEnd="",t.bRender&&alert("The sequence can NOT be aligned to the structure"),t.showSeqCls.showSeq(i,n,void 0,e,l,a,r)}else if(s.cfg.blast_rep_id==i&&(void 0!==t.seqStructAlignData||void 0!==t.seqStructAlignDataSmithwm)){let e,l,r,o,a,d=s.cfg.oriQuery_id?s.cfg.oriQuery_id:s.cfg.query_id;if(e=d.length>14?"Query: "+d.substr(0,6)+"...":isNaN(s.cfg.query_id)?"Query: "+d:"Query: gi "+d,void 0!==t.seqStructAlignData){let e,s,i=t.seqStructAlignData;if(void 0!==i.data){e=i.data[0].query;let t=Object.keys(i.data[0].targets);s=i.data[0].targets[t[0]],s=void 0!==s&&s.hsps.length>0?s.hsps[0]:void 0}if(void 0!==e&&void 0!==s){l=s.scores.e_value.toPrecision(2),l>1e-200&&(l=parseFloat(l).toExponential()),s.scores.bit_score;let t=Object.keys(i.targets);r=i.targets[t[0]].seqdata,o=e.seqdata,a=s.segs}}else{let e=t.seqStructAlignDataSmithwm;l=e.score,r=e.target.replace(/-/g,""),o=e.query.replace(/-/g,""),a=[];let s=-1,i=-1,n=!1,d={};for(let t=0,l=e.target.length;t<l;++t)"-"!=e.target[t]&&++s,"-"!=e.query[t]&&++i,n||"-"==e.target[t]||"-"==e.query[t]?!n||"-"!=e.target[t]&&"-"!=e.query[t]||(n=!1,d.orito="-"==e.target[t]?s:s-1,d.to="-"==e.query[t]?i:i-1,a.push(d),d={}):(n=!0,d.orifrom=s,d.from=i);"-"!=e.target[e.target.length-1]&&"-"!=e.query[e.target.length-1]&&(d.orito=s,d.to=i,a.push(d))}let c="",h="";if(t.queryStart="",t.queryEnd="",void 0!==a){let e={};void 0===t.targetGapHash&&(t.targetGapHash={}),t.fullpos2ConsTargetpos={},t.consrvResPosArray=[];let n=0,l=0;t.nTotalGap=0,t.queryStart=a[0].from+1,t.queryEnd=a[a.length-1].to+1;for(let s=0,i=a.length;s<i;++s){let i=a[s];if(s>0)if(i.orifrom-n<i.from-l)t.targetGapHash[i.orifrom]={from:l+1,to:i.from-1},t.nTotalGap+=t.targetGapHash[i.orifrom].to-t.targetGapHash[i.orifrom].from+1;else if(i.orifrom-n>i.from-l)for(let t=n+1;t<i.orifrom;++t)e[t]=-1;for(let t=0;t<=i.orito-i.orifrom;++t)e[t+i.orifrom]=t+i.from;n=i.orito,l=i.to}let d=0;t.alnChainsSeq[i]=[];for(let n=0,l=r.length;n<l;++n){if(t.targetGapHash.hasOwnProperty(n))for(let e=t.targetGapHash[n].from;e<=t.targetGapHash[n].to;++e)c+=o[e];h+=t.showSeqCls.insertGap(i,n,"-",!0),t.targetGapHash.hasOwnProperty(n)&&(d+=t.targetGapHash[n].to-t.targetGapHash[n].from+1);let l=t.bUsePdbNum?t.ParserUtilsCls.getResi(i,n):n+1;if(e.hasOwnProperty(n)&&-1!==e[n]){c+=o[e[n]];let a=this.getColorhexFromBlosum62(r[n],o[e[n]]);r[n]==o[e[n]]?(h+=r[n],t.fullpos2ConsTargetpos[n+d]={same:1,pos:l,res:r[n],color:a},t.consrvResPosArray.push(l),t.alnChainsSeq[i].push({resi:l,color:"#FF0000",color2:"#"+a})):this.conservativeReplacement(r[n],o[e[n]])?(h+="+",t.fullpos2ConsTargetpos[n+d]={same:0,pos:l,res:r[n],color:a},t.consrvResPosArray.push(l),t.alnChainsSeq[i].push({resi:l,color:"#0000FF",color2:"#"+a})):(h+=" ",t.fullpos2ConsTargetpos[n+d]={same:-1,pos:l,res:r[n],color:a},t.alnChainsSeq[i].push({resi:l,color:s.htmlCls.GREYC,color2:"#"+a}))}else c+="-",h+=" "}}else c+="cannot be aligned",t.bRender&&alert("The sequence can NOT be aligned to the structure");let p=void 0!==t.seqStructAlignData?"BLAST, E: "+l:"Score: "+l;t.showSeqCls.showSeq(i,n,void 0,e,p,c,h);let m,u={};if(void 0!==t.consrvResPosArray)for(let e=0,s=t.consrvResPosArray.length;e<s;++e)m=n+"_"+t.consrvResPosArray[e],u[m]=1;let g=s.hashUtilsCls.cloneHash(t.hAtoms);t.selectionCls.selectResidueList(u,"protein_aligned",p,!1),t.hAtoms=s.hashUtilsCls.cloneHash(g)}}s.bNode||(this.enableHlSeq(),await t.annoCddSiteCls.showCddSiteAll())}enableHlSeq(){let e=this.icn3d;e.icn3dui.utilsCls.isMobile()?(e.hlSeqCls.selectSequenceMobile(),e.hlSeqCls.selectChainMobile()):e.hlSeqCls.selectSequenceNonMobile(),Object.keys(e.hAtoms).length<Object.keys(e.dAtoms).length&&e.hlUpdateCls.updateHlSeq()}getAnDiv(e,t){let s=this.icn3d;s.icn3dui;let i="Loading "+t+"...";return"custom"==t?i="":"domain"==t&&(i="Loading 3D "+t+"..."),"<div id='"+s.pre+t+"_"+e+"'><div id='"+s.pre+"tt_"+t+"_"+e+"' class='icn3d-fixed-pos' style='display:none!important'></div><div id='"+s.pre+"dt_"+t+"_"+e+"' style='display:none'>"+i+"</div><div id='"+s.pre+"ov_"+t+"_"+e+"'>"+i+"</div></div>"}addButton(e,t,s,i,n,l){return this.icn3d.icn3dui,"<div class='"+t+"' chainid='"+e+"' style='display:inline-block; font-size:11px; font-weight:bold; width:"+n+"px!important;'><button style='-webkit-appearance:"+l+"; height:18px; width:"+n+"px;'><span style='white-space:nowrap; margin-left:-3px;' title='"+i+"'>"+s+"</span></button></div>"}addSnpButton(e,t,s,i,n,l){let r=this.icn3d;return r.icn3dui,"<div class='"+r.pre+t+"' snp='"+e+"' style='margin:3px 0 3px 0; display:inline-block; font-size:11px; font-weight:bold; width:"+n+"px!important;'><button style='-webkit-appearance:"+l+"; height:18px; width:"+n+"px;'><span style='white-space:nowrap; margin-left:-3px;' title='"+i+"'>"+s+"</span></button></div>"}conservativeReplacement(e,t){let s=this.icn3d.icn3dui,i=-1!==s.parasCls.b62ResArray.indexOf(e)?s.parasCls.b62ResArray.indexOf(e):s.parasCls.b62ResArray.length-1,n=-1!==s.parasCls.b62ResArray.indexOf(t)?s.parasCls.b62ResArray.indexOf(t):s.parasCls.b62ResArray.length-1;return s.parasCls.b62Matrix[i][n]>0}getColorhexFromBlosum62(e,t){let s=this.icn3d.icn3dui,i="333333";if(!e||!t)return i;e=e.toUpperCase(),t=t.toUpperCase();let n=-1!==s.parasCls.b62ResArray.indexOf(e)?s.parasCls.b62ResArray.indexOf(e):s.parasCls.b62ResArray.length-1,l=-1!==s.parasCls.b62ResArray.indexOf(t)?s.parasCls.b62ResArray.indexOf(t):s.parasCls.b62ResArray.length-1,r=s.parasCls.b62Matrix[n][l];if(void 0===r)return"333333";if(r>0){let e=221-parseInt(r/11*221),t=e<10?"0"+e.toString(16):e.toString(16);i="DD"+t+t}else{let e=221-parseInt(-1*r/4*221),t=e<10?"0"+e.toString(16):e.toString(16);i=t+t+"DD"}return i}}class Dt{constructor(e){this.icn3d=e}getSeq(e){let t,s=this.icn3d,i=s.icn3dui;if(void 0===i.cfg.mmdbid&&void 0===i.cfg.gi&&void 0===i.cfg.blast_rep_id&&void 0===i.cfg.align&&void 0===i.cfg.chainalign&&void 0===i.cfg.mmdbafid){t=[];for(let i=0;i<s.chainsSeq[e].length;++i)t.push(s.chainsSeq[e][i])}else t=s.giSeq[e];if(!t)return[];let n=[];for(let e=0,s=t.length;e<s;++e)t[e]&&n.push(t[e]);return t=n,t}showSeq(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui,d=this.getSeq(e),c=!1;void 0===a.cfg.mmdbid&&void 0===a.cfg.gi&&void 0===a.cfg.blast_rep_id&&void 0===a.cfg.align&&void 0===a.cfg.chainalign&&void 0===a.cfg.mmdbafid&&(c=!0);let h=a.htmlCls.RESIDUE_WIDTH*(d.length+o.nTotalGap)+200,p=["giseq","cddsite","clinvar","snp","ptm","ssbond","crosslink","transmem","domain","custom","interaction","ig"];for(let t in p){let s=p[t];$("#"+o.pre+s+"_"+e).length&&$("#"+o.pre+s+"_"+e).width(h)}let m,u="",g="",f="";if(u+='<div class="icn3d-dl_sequence">',f+='<div class="icn3d-dl_sequence">',d.length>10){m='<div class="icn3d-residueLine" style="white-space:nowrap;">';let t=o.firstAtomObjCls.getFirstCalphaAtomObj(o.chains[e]);void 0===a.cfg.mmdbid&&void 0===a.cfg.gi&&void 0===a.cfg.blast_rep_id&&void 0===a.cfg.align&&void 0===a.cfg.chainalign&&void 0===a.cfg.mmdbafid||void 0===t.resi_ori||t.resi_ori==t.resi||-1!=e.indexOf("Misc")?m+='<div class="icn3d-annoTitle" anno="0"></div>':m+='<div class="icn3d-annoTitle" anno="0" title="NCBI Residue Numbers">NCBI Residue Numbers</div>',m+='<span class="icn3d-residueNum"></span>',f+=m+"<br>",u+=m+'<span class="icn3d-seqLine">';let s=0,i=0,n="";o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqStartLen[e]," "));for(let t=0,l=d.length;t<l;++t){let l;u+=this.insertGap(e,t,"-"),l=o.ParserUtilsCls.getResi(e,t),u+="<span>",l%10==0&&(u+=l);let r=e+"_"+l,a=l%10!=0&&l%10!=1&&l%10!=9;if(o.residues.hasOwnProperty(r)){let e=o.firstAtomObjCls.getFirstCalphaAtomObj(o.residues[r]);"H"==o.secondaries[r]&&e.ssbegin?(++s,n='<span class="icn3d-helix-color">H'+s+"</span>",a&&(u+=n,n="")):"E"==o.secondaries[r]&&e.ssbegin?(++i,"green"==o.sheetcolor?n='<span class="icn3d-sheet-color">S'+i+"</span>":"yellow"==o.sheetcolor&&(n='<span class="icn3d-sheet-colory">S'+i+"</span>"),a&&(u+=n,n="")):e.ssend&&(n=""),""!=n&&a&&(u+=n,n="")}u+="</span>"}o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqEndLen[e]," ")),u+='<span class="icn3d-residueNum"></span>',u+="</span>",u+="<br>",u+="</div>",f+="</div>"}m='<div class="icn3d-residueLine" style="white-space:nowrap;">',m+='<div class="icn3d-annoTitle" anno="0"></div>',m+='<span class="icn3d-residueNum"></span>',f+=m+"<br>",u+=m+'<span class="icn3d-seqLine">',o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqStartLen[e],"-"));for(let t=0,s=d.length;t<s;++t){u+=this.insertGap(e,t,"-");let s=e+"_"+o.ParserUtilsCls.getResi(e,t);if(o.residues.hasOwnProperty(s))if("H"==o.secondaries[s])u+=t%2==0?'<span class="icn3d-helix">':'<span class="icn3d-helix2">',u+="&nbsp;</span>";else if("E"==o.secondaries[s]){o.firstAtomObjCls.getFirstCalphaAtomObj(o.residues[s]).ssend?"green"==o.sheetcolor?u+='<span class="icn3d-sheet2">':"yellow"==o.sheetcolor&&(u+='<span class="icn3d-sheet2y">'):"green"==o.sheetcolor?u+='<span class="icn3d-sheet">':"yellow"==o.sheetcolor&&(u+='<span class="icn3d-sheety">'),u+="&nbsp;</span>"}else"c"==o.secondaries[s]?u+='<span class="icn3d-coil">&nbsp;</span>':"o"==o.secondaries[s]&&(u+='<span class="icn3d-other">&nbsp;</span>');else u+="<span>-</span>"}o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqEndLen[e],"-")),u+='<span class="icn3d-residueNum"></span>',u+="</span>",u+="<br>",u+="</div>",u+="</div>",f+="</div></div>",m=a.cfg.blast_rep_id===e?'<div id="'+o.pre+'giseq_sequence" class="icn3d-dl_sequence" style="border: solid 1px #000">':'<div id="'+o.pre+'giseq_sequence" class="icn3d-dl_sequence">';let C="Protein",b="Protein";void 0!==s&&("nucleotide"==s?(C="Nucl.",b="Nucleotide"):"chemical"==s&&(C="Chem.",b="Chemical")),m+='<div class="icn3d-seqTitle icn3d-link icn3d-blue" gi="'+e+'" anno="sequence" chain="'+e+'"><span style="white-space:nowrap;" title="'+b+" "+e+'">'+C+" "+e+"</span></div>",m+='<span class="icn3d-residueNum" title="starting protein sequence number">'+(o.baseResi[e]+1).toString()+"</span>",f+=m+"<br>";let y='<span class="icn3d-seqLine">';u+=m+y,g+=m+y;let v,_=0;o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqStartLen[e],"-"));for(let t=0,s=d.length;t<s;++t){u+=this.insertGap(e,t,"-"),void 0!==o.targetGapHash&&o.targetGapHash.hasOwnProperty(t)&&(_+=o.targetGapHash[t].to-o.targetGapHash[t].from+1);let s=c?d[t].name:d[t],i=s;if(s.length>1&&(i=s[0]+".."),v=o.ParserUtilsCls.getResi(e,t),o.residues.hasOwnProperty(e+"_"+v)){let n="333333";if(a.cfg.blast_rep_id==e&&void 0!==o.fullpos2ConsTargetpos&&void 0!==o.fullpos2ConsTargetpos[t+_])n=o.fullpos2ConsTargetpos[t+_].color;else{let t=o.firstAtomObjCls.getFirstCalphaAtomObj(o.residues[e+"_"+v]),s=void 0===t.color||"FFFFFF"===t.color.getHexString().toUpperCase()||"FFF"===t.color.getHexString().toUpperCase()?"DDDDDD":t.color.getHexString();n=void 0!==t.color?s:"CCCCCC"}u+='<span id="giseq_'+o.pre+e+"_"+v+'" title="'+s+v+'" class="icn3d-residue" style="color:#'+n+'">'+i+"</span>"}else i=i.toLowerCase(),u+='<span title="'+s+v+'" class="icn3d-residue">'+i+"</span>"}o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqEndLen[e],"-")),a.cfg.blast_rep_id==e&&(o.opts.color=o.blastAcxn?"confidence":"conservation",o.setColorCls.setColorByOptions(o.opts,o.atoms));let w=o.firstAtomObjCls.getFirstCalphaAtomObj(o.chains[e]),S=w.color?w.color.getHexString():"CCCCCC",A=Math.round(o.seqAnnWidth*d.length/(o.maxAnnoLength+o.nTotalGap));if(A<1&&(A=1),o.seqStartLen&&o.seqStartLen[e]&&(g+=this.insertMulGapOverview(e,o.seqStartLen[e])),a.cfg.blast_rep_id!=e)g+='<div id="giseq_summary_'+o.pre+e+'" class="icn3d-seqTitle icn3d-link" gi chain="'+e+'" style="display:inline-block; color:white; font-weight:bold; background-color:#'+S+"; width:"+A+'px;">'+e+"</div>";else{let t=[],s=[];t.push(0);for(let e=0,i=d.length;e<i;++e)void 0!==o.targetGapHash&&o.targetGapHash.hasOwnProperty(e)&&(s.push(e-1),t.push(e));s.push(d.length-1),g+='<div id="giseq_summary_'+o.pre+e+'" class="icn3d-seqTitle icn3d-link" gi chain="'+e+'" style="width:'+A+'px;">';for(let i=0,n=t.length;i<n;++i)g+=this.insertGapOverview(e,t[i]),g+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+S+"; width:"+Math.round(o.seqAnnWidth*(s[i]-t[i]+1)/(o.maxAnnoLength+o.nTotalGap))+'px;" class="icn3d-seqTitle icn3d-link icn3d-blue" anno="sequence" gi chain="'+e+'" title="'+e+'">'+e+"</div>";g+="</div>"}if(m='<span class="icn3d-residueNum" title="ending protein sequence number">'+v+"</span>",m+="</span>",m+="<br>",u+=m,g+=m,a.cfg.blast_rep_id==e){if(void 0!==r&&""!==r){m='<div class="icn3d-seqTitle icn3d-link icn3d-blue" blast="" posarray="'+o.consrvResPosArray.toString()+'" title="'+n+'" setname="'+e+'_blast" anno="sequence" chain="'+e+'"><span style="white-space:nowrap;" title="'+n+'">'+n+"</span></div>",m+='<span class="icn3d-residueNum"></span>',f+=m+"<br>";let t='<span class="icn3d-seqLine">';u+=m+t,g+=m+t;let s=0,i=0,l=1;o.queryStart;for(let t=0,n=r.length;t<n;++t){let n=r[t];if("-"==n)u+="<span>-</span>";else if(" "==n)u+="<span> </span>";else{let r=o.fullpos2ConsTargetpos[t].pos;if(o.residues.hasOwnProperty(e+"_"+r)){let s=o.fullpos2ConsTargetpos[t].color;u+='<span id="giseq_'+o.pre+e+"_"+r+'" title="'+o.fullpos2ConsTargetpos[t].res+r+'" class="icn3d-residue" style="color:#'+s+'">'+n+"</span>"}else n=n.toLowerCase(),u+='<span class="icn3d-residue">'+n+"</span>";g+=this.insertGapOverview(e,t);let a=Math.round(o.seqAnnWidth*t/(o.maxAnnoLength+o.nTotalGap)-s-i);a>=0&&(g+='<div style="display:inline-block; width:'+a+'px;">&nbsp;</div>',g+='<div style="display:inline-block; background-color:#F00; width:'+l+'px;" title="'+n+r+'">&nbsp;</div>',s+=a,i+=l)}}m='<span class="icn3d-residueNum"></span>',m+="</span>",m+="<br>",u+=m,g+=m}m='<div class="icn3d-annoTitle" anno="sequence" chain="'+e+'"><span style="white-space:nowrap;" title="'+i+'">'+i+"</span></div>",m+='<span class="icn3d-residueNum" title="starting protein sequence number">'+o.queryStart+"</span>",f+=m+"<br>";let t='<span class="icn3d-seqLine" style="font-weight: bold;">';u+=m+t,g+=m+t;let s=o.queryStart;for(let t=0,i=l.length;t<i;++t){let i=l[t];" "==i||"-"==i?u+="<span>-</span>":(void 0===o.fullpos2ConsTargetpos||void 0===o.fullpos2ConsTargetpos[t]||o.residues.hasOwnProperty(e+"_"+o.fullpos2ConsTargetpos[t].pos)||(i=i.toLowerCase()),u+='<span title="'+i+s+'" class="icn3d-residue">'+i+"</span>",++s)}let a=o.firstAtomObjCls.getFirstCalphaAtomObj(o.chains[e]),d=void 0===a.color||"FFFFFF"===a.color.getHexString()?"DDDDDD":a.color.getHexString(),c=void 0!==a.color?d:"CCCCCC",h=[],p=[],C="-";for(let e=0,t=l.length;e<t;++e){let t=l[e];"-"!=t&&"-"==C?h.push(e):"-"==t&&"-"!=C&&p.push(e-1),C=t}"-"!=C&&p.push(l.length-1);for(let t=0,s=h.length;t<s;++t){g+='<div style="display:inline-block; width:'+(0==t?Math.round(o.seqAnnWidth*(h[t]-o.baseResi[e]-1)/(o.maxAnnoLength+o.nTotalGap)):Math.round(o.seqAnnWidth*(h[t]-p[t-1]-1)/(o.maxAnnoLength+o.nTotalGap)))+'px;">&nbsp;</div>',g+='<div style="display:inline-block; color:white!important; font-weight:bold; background-color:#'+c+"; width:"+Math.round(o.seqAnnWidth*(p[t]-h[t]+1)/(o.maxAnnoLength+o.nTotalGap))+'px;" anno="sequence" chain="'+e+'" title="'+i+'">'+i+"</div>"}m='<span class="icn3d-residueNum" title="ending protein sequence number">'+o.queryEnd+"</span>",m+="</span>",m+="<br>",u+=m,g+=m}if(u+="</div>",g+="</div>",f+="</div>",d.length>10){let t=o.firstAtomObjCls.getFirstCalphaAtomObj(o.chains[e]);if((void 0!==a.cfg.mmdbid||void 0!==a.cfg.gi||void 0!==a.cfg.blast_rep_id||void 0!==a.cfg.align||void 0!==a.cfg.chainalign||void 0!==a.cfg.mmdbafid)&&void 0!==t.resi_ori&&t.resi_ori!=t.resi&&-1==e.indexOf("Misc")){m='<div class="icn3d-dl_sequence">',m+='<div class="icn3d-residueLine" style="white-space:nowrap;">',m+='<div class="icn3d-annoTitle" anno="0" title="PDB Residue Numbers">PDB Residue Numbers</div>',m+='<span class="icn3d-residueNum"></span>',f+=m+"<br>",u+=m+'<span class="icn3d-seqLine">',o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqStartLen[e],"-"));for(let t=0,s=d.length;t<s;++t){u+=this.insertGap(e,t,"-");let s=e+"_"+o.ParserUtilsCls.getResi(e,t);if(o.residues.hasOwnProperty(s)){let e=o.firstAtomObjCls.getFirstCalphaAtomObj(o.residues[s]).resi_ori;u+="<span>",e%10==0&&(u+=e+" "),u+="</span>"}else u+="<span></span>"}o.seqStartLen&&o.seqStartLen[e]&&(u+=this.insertMulGap(o.seqEndLen[e],"-")),u+='<span class="icn3d-residueNum"></span>',u+="</span>",u+="<br>",u+="</div>",u+="</div>",f+="</div></div>"}if(o.bShowCustomRefnum&&o.chainsMapping.hasOwnProperty(e)){let t=!0,s=o.annoIgCls.showRefNum(d,e,void 0,t);u+=s.html,f+=s.html3}}o.bShowRefnum&&o.hlUpdateCls.updateHlAll(),$("#"+o.pre+"dt_giseq_"+e).html(u),$("#"+o.pre+"ov_giseq_"+e).html(g),$("#"+o.pre+"tt_giseq_"+e).html(f)}insertGap(e,t,s,i){let n=this.icn3d;n.icn3dui;let l="";return void 0!==n.targetGapHash&&n.targetGapHash.hasOwnProperty(t)&&(l+=this.insertMulGap(n.targetGapHash[t].to-n.targetGapHash[t].from+1,s,i)),l}insertMulGap(e,t,s){this.icn3d.icn3dui;let i="";for(let n=0;n<e;++n)i+=s?t:"<span>"+t+"</span>";return i}insertGapOverview(e,t){let s=this.icn3d;s.icn3dui;let i="";return void 0!==s.targetGapHash&&s.targetGapHash.hasOwnProperty(t)&&(i+=this.insertMulGapOverview(e,s.targetGapHash[t].to-s.targetGapHash[t].from+1)),i}insertMulGapOverview(e,t){let s=this.icn3d;s.icn3dui;let i="",n=s.seqAnnWidth*t/(s.maxAnnoLength+s.nTotalGap);return n=parseInt(n),i+='<div style="display:inline-block; width:'+n+'px;">&nbsp;</div>',i}setAlternativeSeq(e,t){let s=this.icn3d;s.icn3dui;let i=s.chainsSeq[e];s.giSeq[e]=[];for(let t=0,n=i.length;t<n;++t){let n=i[t].name;s.giSeq[e][t]=n}s.matchedPos[e]=0,s.baseResi[e]=s.chainsSeq[e][0].resi-s.matchedPos[e]-1}getProteinName(e){let t=this.icn3d,s=t.icn3dui,i="";if(void 0===s.cfg.mmdbid&&void 0===s.cfg.gi&&void 0===s.cfg.blast_rep_id||void 0===t.mmdb_data)(void 0!==s.cfg.align||void 0!==s.cfg.chainalign||void 0!==s.cfg.mmdbafid||t.bRealign||t.bSymd)&&void 0!==t.chainid2title&&void 0!==t.chainid2title[e]&&(i=t.chainid2title[e]);else{let s=t.mmdb_data.moleculeInfor,n=e.substr(e.indexOf("_")+1);for(let e in s)if(s[e].chain==n){i=s[e].name.replace(/\'/g,"&prime;");break}}return i}}class Mt{constructor(e){this.icn3d=e}selectSequenceNonMobile(){let e=this.icn3d;if(e.icn3dui.bNode)return;let t=this;$("#"+e.pre+"dl_sequence2").add("[id^="+e.pre+"dt_giseq]").add("[id^="+e.pre+"dt_custom]").add("[id^="+e.pre+"dt_site]").add("[id^="+e.pre+"dt_ptm]").add("[id^="+e.pre+"dt_snp]").add("[id^="+e.pre+"dt_clinvar]").add("[id^="+e.pre+"dt_cdd]").add("[id^="+e.pre+"dt_domain]").add("[id^="+e.pre+"dt_interaction]").add("[id^="+e.pre+"dt_ssbond]").add("[id^="+e.pre+"dt_crosslink]").add("[id^="+e.pre+"dt_transmem]").add("[id^="+e.pre+"dt_ig]").add("[id^="+e.pre+"tt_giseq]").add("[id^="+e.pre+"tt_custom]").add("[id^="+e.pre+"tt_site]").add("[id^="+e.pre+"tt_ptm]").add("[id^="+e.pre+"tt_snp]").add("[id^="+e.pre+"tt_clinvar]").add("[id^="+e.pre+"tt_cdd]").add("[id^="+e.pre+"tt_domain]").add("[id^="+e.pre+"tt_interaction]").add("[id^="+e.pre+"tt_ssbond]").add("[id^="+e.pre+"tt_crosslink]").add("[id^="+e.pre+"tt_transmem]").add("[id^="+e.pre+"tt_ig]").selectable({distance:1,stop:function(){let e=t.icn3d;$(this).attr("id")===e.pre+"dl_sequence2"?(e.bAlignSeq=!0,e.bAnnotations=!1):(e.bAlignSeq=!1,e.bAnnotations=!0),!1!==e.bSelectResidue||e.bShift||e.bCtrl||e.selectionCls.removeSelection(),$("span.ui-selected",this).each((function(){let e=$(this).attr("id");void 0!==e&&t.selectResidues(e,this)})),e.selectionCls.saveSelectionPrep(!0),e.selectionCls.saveSelection(void 0,void 0,!0),e.hlObjectsCls.addHlObjects();let s={};for(let t in e.selectedResidues){let e=t.lastIndexOf("_");s[t.substr(0,e)]=1}let i=Object.keys(s);e.hlUpdateCls.updateHl2D(i),$("div.ui-selected",this).each((function(){void 0!==$(this).attr("chain")&&t.selectTitle(this)}))}}),$("[id^="+e.pre+"ov_giseq]").add("[id^="+e.pre+"ov_custom]").add("[id^="+e.pre+"ov_site]").add("[id^="+e.pre+"ov_ptm]").add("[id^="+e.pre+"ov_snp]").add("[id^="+e.pre+"ov_clinvar]").add("[id^="+e.pre+"ov_cdd]").add("[id^="+e.pre+"ov_domain]").add("[id^="+e.pre+"ov_interaction]").add("[id^="+e.pre+"ov_ssbond]").add("[id^="+e.pre+"ov_crosslink]").add("[id^="+e.pre+"ov_transmem]").add("[id^="+e.pre+"ov_ig]").add("[id^="+e.pre+"tt_giseq]").add("[id^="+e.pre+"tt_custom]").add("[id^="+e.pre+"tt_site]").add("[id^="+e.pre+"tt_ptm]").add("[id^="+e.pre+"tt_snp]").add("[id^="+e.pre+"tt_clinvar]").add("[id^="+e.pre+"tt_cdd]").add("[id^="+e.pre+"tt_domain]").add("[id^="+e.pre+"tt_interaction]").add("[id^="+e.pre+"tt_ssbond]").add("[id^="+e.pre+"tt_crosslink]").add("[id^="+e.pre+"tt_transmem]").add("[id^="+e.pre+"tt_ig]").add("#"+e.pre+"dl_sequence2").add("[id^="+e.pre+"dt_giseq]").add("[id^="+e.pre+"dt_custom]").add("[id^="+e.pre+"dt_site]").add("[id^="+e.pre+"dt_ptm]").add("[id^="+e.pre+"dt_snp]").add("[id^="+e.pre+"dt_clinvar]").add("[id^="+e.pre+"dt_cdd]").add("[id^="+e.pre+"dt_domain]").add("[id^="+e.pre+"dt_interaction]").add("[id^="+e.pre+"dt_ssbond]").add("[id^="+e.pre+"dt_crosslink]").add("[id^="+e.pre+"dt_transmem]").add("[id^="+e.pre+"dt_ig]").add("[id^="+e.pre+"tt_giseq]").add("[id^="+e.pre+"tt_custom]").add("[id^="+e.pre+"tt_site]").add("[id^="+e.pre+"tt_ptm]").add("[id^="+e.pre+"tt_snp]").add("[id^="+e.pre+"tt_clinvar]").add("[id^="+e.pre+"tt_cdd]").add("[id^="+e.pre+"tt_domain]").add("[id^="+e.pre+"tt_interaction]").add("[id^="+e.pre+"tt_ssbond]").add("[id^="+e.pre+"tt_crosslink]").add("[id^="+e.pre+"tt_transmem]").add("[id^="+e.pre+"tt_ig]").on("click",".icn3d-seqTitle",(function(e){let s=t.icn3d;e.stopImmediatePropagation(),$(this).parents("div").attr("id")===s.pre+"dl_sequence2"?(s.bAlignSeq=!0,s.bAnnotations=!1):(s.bAlignSeq=!1,s.bAnnotations=!0),t.selectTitle(this),s.hlUpdateCls.hlSummaryDomain3ddomain(this)}))}selectSequenceMobile(){let e=this.icn3d;if(e.icn3dui.bNode)return;let t=this;$("#"+e.pre+"dl_sequence2").add("[id^="+e.pre+"giseq]").add("[id^="+e.pre+"custom]").add("[id^="+e.pre+"site]").add("[id^="+e.pre+"ptm]").add("[id^="+e.pre+"clinvar]").add("[id^="+e.pre+"snp]").add("[id^="+e.pre+"cdd]").add("[id^="+e.pre+"domain]").add("[id^="+e.pre+"interaction]").add("[id^="+e.pre+"ssbond]").add("[id^="+e.pre+"crosslink]").add("[id^="+e.pre+"transmem]").add("[id^="+e.pre+"ig]").on("click",".icn3d-residue",(function(e){let s=t.icn3d;e.stopImmediatePropagation();let i=$(this).attr("id");void 0!==i&&(t.selectResidues(i,this),s.selectionCls.saveSelectionPrep(!0),s.selectionCls.saveSelection(void 0,void 0,!0)),s.hlObjectsCls.addHlObjects();let n={};for(let e in s.selectedResidues){let t=e.lastIndexOf("_");n[e.substr(0,t)]=1}s.hlUpdateCls.removeHl2D();let l=Object.keys(n);s.hlUpdateCls.updateHl2D(l)}))}selectChainMobile(){let e=this.icn3d;if(e.icn3dui.bNode)return;let t=this;$("#"+e.pre+"dl_sequence2").add("[id^="+e.pre+"giseq]").add("[id^="+e.pre+"custom]").add("[id^="+e.pre+"site]").add("[id^="+e.pre+"ptm]").add("[id^="+e.pre+"feat]").add("[id^="+e.pre+"clinvar]").add("[id^="+e.pre+"snp]").add("[id^="+e.pre+"cdd]").add("[id^="+e.pre+"domain]").add("[id^="+e.pre+"interaction]").add("[id^="+e.pre+"ssbond]").add("[id^="+e.pre+"crosslink]").add("[id^="+e.pre+"transmem]").add("[id^="+e.pre+"ig]").on("click",".icn3d-seqTitle",(function(e){let s=t.icn3d;e.stopImmediatePropagation(),$(this).parents("div").attr("id")===s.pre+"dl_sequence2"?(s.bAlignSeq=!0,s.bAnnotations=!1):(s.bAlignSeq=!1,s.bAnnotations=!0),t.selectTitle(this),s.hlUpdateCls.hlSummaryDomain3ddomain(this)}))}selectTitle(e){let t=this.icn3d,s=t.icn3dui;if(!s.bNode&&$(e).hasClass("icn3d-seqTitle")){let i,n,l,r=$(e).attr("chain"),o=$(e).attr("resn");if(t.bAlignSeq?t.bSelectAlignResidue=!1:t.bSelectResidue=!1,t.bAnnotations||t.hlUpdateCls.removeSeqChainBkgd(r),t.bCtrl||t.bShift||(t.hlUpdateCls.removeSeqResidueBkgd(),t.hlUpdateCls.removeSeqChainBkgd(),t.currSelectedSets=[]),$(e).toggleClass("icn3d-highlightSeq"),o?i=o:t.bAnnotations?(i=$(e).attr("setname"),n=$(e).attr("title")):i=t.bAlignSeq?"align_"+r:r,$(e).hasClass("icn3d-highlightSeq"))if(t.bAnnotations){if($(e).hasClass("icn3d-highlightSeq"))if(t.hlUpdateCls.removeHl2D(),void 0!==$(e).attr("gi")){if(t.bCtrl||t.bShift)if(t.currSelectedSets.push(r),o){let e=s.hashUtilsCls.cloneHash(t.hAtoms),n=!0;t.selByCommCls.selectBySpec("select :3"+o,i,i,!1,n),t.hAtoms=s.hashUtilsCls.unionHash(t.hAtoms,e),t.hlUpdateCls.updateHlAll(o,void 0,!0,!0)}else t.selectionCls.selectAChain(r,r,!1,!0);else if(t.currSelectedSets=[r],o){let e=!0;t.selByCommCls.selectBySpec("select :3"+o,i,i,!1,e),t.hlUpdateCls.updateHlAll(o,void 0,!0,!0)}else t.selectionCls.selectAChain(r,r,!1);o?s.htmlCls.clickMenuCls.setLogCmd("select :3"+o,!0):s.htmlCls.clickMenuCls.setLogCmd("select chain "+r,!0);let e=t.currSelectedSets.join(" or ");t.currSelectedSets.length>1&&s.htmlCls.clickMenuCls.setLogCmd("select sets "+e,!0)}else{let o={};if(void 0!==$(e).attr("domain")||void 0!==$(e).attr("feat")||void 0!==$(e).attr("3ddomain")||void 0!==$(e).attr("custom")||void 0!==$(e).attr("ig")){t.hlUpdateCls.hlSummaryDomain3ddomain(e);let a,d,c,h=$(e).attr("from").split(","),p=$(e).attr("to").split(",");r.substr(0,r.indexOf("_"));for(let s=0,i=h.length;s<i;++s){d=parseInt(h[s]),c=parseInt(p[s]);for(let s=d;s<=c;++s){if(void 0!==$(e).attr("domain")||void 0!==$(e).attr("feat")||void 0!==$(e).attr("ig")){let e=r+"_"+(s+1).toString();a=t.ncbi2resid[e]}else a=void 0!==$(e).attr("3ddomain")?t.posid2resid[r+"_"+(s+1).toString()]:r+"_"+(s+1).toString();o[a]=1}}t.bCtrl||t.bShift?t.selectionCls.selectResidueList(o,i,n,!0):t.selectionCls.selectResidueList(o,i,n,!1),a=r+"_"+parseInt((d+c)/2).toString(),l=t.applyCenterCls.centerAtoms(s.hashUtilsCls.hash2Atoms(t.residues[a],t.atoms))}else if(void 0!==$(e).attr("posarray")){let a,d=$(e).attr("posarray").split(",");r.substr(0,r.indexOf("_"));for(let s=0,i=d.length;s<i;++s){if(void 0!==$(e).attr("site")||void 0!==$(e).attr("ptm")){let e=r+"_"+(parseInt(d[s])+1).toString();a=t.ncbi2resid[e]}else a=r+"_"+d[s];o[a]=1}t.bCtrl||t.bShift?t.selectionCls.selectResidueList(o,i,n,!0):t.selectionCls.selectResidueList(o,i,n,!1),a=r+"_"+d[parseInt((0+d.length)/2)].toString(),l=t.applyCenterCls.centerAtoms(s.hashUtilsCls.hash2Atoms(t.residues[a],t.atoms))}for(let e in t.labels)"schematic"!==e&&"distance"!==e&&(t.labels[e]=[]);let a=t.LABELSIZE,d="black"!=t.opts.background?t.colorWhitebkgd:t.colorBlackbkgd;void 0!==l&&t.analysisCls.addLabel(n,l.center.x,l.center.y,l.center.z,a,d,void 0,"custom"),t.drawCls.draw(),s.htmlCls.clickMenuCls.setLogCmd("select "+t.resid2specCls.residueids2spec(Object.keys(o))+" | name "+i,!0),t.bCtrl||t.bShift?t.currSelectedSets.push(i):t.currSelectedSets=[i];let c=t.currSelectedSets.join(" or ");t.currSelectedSets.length>1&&s.htmlCls.clickMenuCls.setLogCmd("select sets "+c,!0)}}else{t.bCtrl||t.bShift?(t.currSelectedSets.push(i),t.selectionCls.selectAChain(r,i,!0,!0)):(t.currSelectedSets=[i],t.selectionCls.selectAChain(r,i,t.bAlignSeq)),t.bAlignSeq?s.htmlCls.clickMenuCls.setLogCmd("select alignChain "+r,!0):s.htmlCls.clickMenuCls.setLogCmd("select chain "+r,!0);let e=t.currSelectedSets.join(" or ");t.currSelectedSets.length>1&&s.htmlCls.clickMenuCls.setLogCmd("select sets "+e,!0)}else t.hlObjectsCls.removeHlObjects(),t.hlUpdateCls.removeHl2D(),$("#"+t.pre+"atomsCustom").val("")}}selectResidues(e,t){let s=this.icn3d,i=s.icn3dui;if(!i.bNode&&(!1!==s.bSelectResidue||s.bShift||s.bCtrl||s.selectionCls.removeSelection(),void 0!==e&&""!==e)){e=e.substr(e.indexOf("_")+1),s.bSelectResidue=!0,$(t).toggleClass("icn3d-highlightSeq");let n=e.substr(e.indexOf("_")+1);if(s.residues.hasOwnProperty(n))if($(t).hasClass("icn3d-highlightSeq")){for(let e in s.residues[n])s.hAtoms[e]=1;if(s.selectedResidues[n]=1,s.bAnnotations&&void 0!==$(t).attr("disease")){let e=$(t).attr("disease"),l=s.applyCenterCls.centerAtoms(i.hashUtilsCls.hash2Atoms(s.residues[n],s.atoms)),r=15;e.length>r&&(e=e.substr(0,r)+"...");let o=s.LABELSIZE,a=i.htmlCls.GREYD;s.analysisCls.addLabel(e,l.center.x,l.center.y,l.center.z,o,a,void 0,"custom")}}else{for(let e in s.residues[n])delete s.hAtoms[e];delete s.selectedResidues[n],s.hlObjectsCls.removeHlObjects()}}}}class Ft{constructor(e){this.icn3d=e}update2DdgmContent(){let e=this.icn3d,t=e.icn3dui,s="";void 0!==t.cfg.mmdbid||void 0!==t.cfg.gi?(s+=e.diagram2dCls.draw2Ddgm(e.interactionData,e.inputid,void 0,!0),s+=e.diagram2dCls.set2DdgmNote(),$("#"+e.pre+"dl_2ddgm_html").html(s)):e.mmdbidArray&&(void 0!==t.cfg.align||void 0!==t.cfg.chainalign||e.bRealign)&&(s+=e.diagram2dCls.draw2Ddgm(e.interactionData1,e.mmdbidArray[0].toUpperCase(),0,!0),void 0!==e.mmdbid_q&&e.mmdbid_q===e.mmdbid_t?s+=e.diagram2dCls.draw2Ddgm(e.interactionData2,e.mmdbidArray[0].toUpperCase(),1,!0):s+=e.diagram2dCls.draw2Ddgm(e.interactionData2,e.mmdbidArray[1].toUpperCase(),1,!0),s+=e.diagram2dCls.set2DdgmNote(!0),$("#"+e.pre+"dl_2ddgm_html").html(s))}changeSeqColor(e){let t=this.icn3d,s=t.icn3dui;for(let i=0,n=e.length;i<n;++i){let n=e[i],l=t.firstAtomObjCls.getFirstCalphaAtomObj(t.residues[n]);if(!l)continue;let r=void 0===l.color||"FFFFFF"===l.color.getHexString().toUpperCase()?"DDDDDD":l.color.getHexString(),o=void 0!==l.color?r:"CCCCCC";$("[id=giseq_"+t.pre+n+"]").attr("style","color:#"+o),$("[id=align_"+t.pre+n+"]").attr("style","color:#"+o),(void 0!==s.cfg.align||void 0!==s.cfg.chainalign||t.bRealign||t.bSymd)&&$("[id=align_"+t.pre+n+"]").attr("style","color:#"+o)}}removeHlAll(){this.icn3d.icn3dui,this.removeHlObjects(),this.removeHlSeq(),this.removeHl2D(),this.removeHlMenus()}removeHlObjects(){let e=this.icn3d;e.icn3dui,e.hlObjectsCls.removeHlObjects()}removeHlSeq(){this.icn3d.icn3dui,this.removeSeqResidueBkgd()}removeHl2D(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"dl_2ddgm rect").attr("stroke","#000000"),$("#"+e.pre+"dl_2ddgm circle").attr("stroke","#000000"),$("#"+e.pre+"dl_2ddgm polygon").attr("stroke","#000000"),$("#"+e.pre+"dl_2ddgm rect").attr("stroke-width",1),$("#"+e.pre+"dl_2ddgm circle").attr("stroke-width",1),$("#"+e.pre+"dl_2ddgm polygon").attr("stroke-width",1),$("#"+e.pre+"dl_2ddgm circle").length>0&&($("#"+e.pre+"dl_2ddgm svg line").attr("stroke","#000000"),$("#"+e.pre+"dl_2ddgm line").attr("stroke-width",1))}removeHlMenus(){let e=this.icn3d;e.icn3dui,$("#"+e.pre+"atomsCustom").val(""),$("#"+e.pre+"atomsCustom")[0].blur()}updateHlAll(e,t,s,i){let n=this.icn3d,l=n.icn3dui;n.prevHighlightAtoms=l.hashUtilsCls.cloneHash(n.hAtoms),this.updateHlObjects(i),void 0!==e?this.updateHlSeqInChain(e,s):this.updateHlSeq(void 0,void 0,s),this.updateHl2D(),(void 0===t||t)&&this.updateHlMenus(e)}updateHlObjects(e){let t=this.icn3d;t.icn3dui,t.hlObjectsCls.removeHlObjects(),(t.hAtoms&&t.atoms&&Object.keys(t.hAtoms).length<Object.keys(t.dAtoms).length||e)&&((void 0===t.bShowHighlight||t.bShowHighlight)&&t.hlObjectsCls.addHlObjects(),t.definedSetsCls.setMode("selection"))}updateHlSeq(e,t,s){let i=this.icn3d;i.icn3dui,void 0!==s&&s||this.removeHlSeq(),void 0===t&&(t=i.firstAtomObjCls.getResiduesFromCalphaAtoms(i.hAtoms)),i.hAtoms&&i.atoms&&Object.keys(i.hAtoms).length<Object.keys(i.atoms).length&&this.hlSequence(Object.keys(t)),this.changeSeqColor(Object.keys(t))}updateHlSeqInChain(e,t){let s=this.icn3d;if(s.icn3dui,void 0!==t&&t||this.removeHlSeq(),!s.hAtoms||!s.atoms||Object.keys(s.hAtoms).length!=Object.keys(s.atoms).length)for(let t=0,i=e.length;t<i;++t){let i=e[t];if(-1!==Object.keys(s.chains).indexOf(i))this.hlSeqInChain(i);else{let e=[];void 0!==s.defNames2Residues[i]&&s.defNames2Residues[i].length>0&&(e=s.defNames2Residues[i]);let t={};if(void 0!==s.defNames2Atoms[i]&&s.defNames2Atoms[i].length>0){for(let e=0,n=s.defNames2Atoms[i].length;e<n;++e){let n=s.defNames2Atoms[i][e],l=s.atoms[n];t[l.structure+"_"+l.chain+"_"+l.resi]=1}e=e.concat(Object.keys(t))}this.hlSequence(e)}}}updateHl2D(e){let t=this.icn3d,s=t.icn3dui;if(this.removeHl2D(),!t.hAtoms||!t.atoms||Object.keys(t.hAtoms).length!=Object.keys(t.atoms).length){if(void 0===e){let s=t.firstAtomObjCls.getChainsFromAtoms(t.hAtoms);e=Object.keys(s)}if(void 0!==e)for(let i=0,n=e.length;i<n;++i){let n=s.hashUtilsCls.intHash(t.chains[e[i]],t.hAtoms),l=1*Object.keys(n).length/Object.keys(t.chains[e[i]]).length,r=t.firstAtomObjCls.getFirstCalphaAtomObj(n);if(void 0!==t.alnChains[e[i]]){let l=s.hashUtilsCls.intHash(t.alnChains[e[i]],n);Object.keys(l).length>0&&(r=t.firstAtomObjCls.getFirstCalphaAtomObj(l))}let o=void 0!==r&&void 0!==r.color?"#"+r.color.getHexString():"#FFFFFF",a=$("#"+t.pre+"dl_2ddgm g[chainid="+e[i]+"] rect[class='icn3d-hlnode']"),d=$("#"+t.pre+"dl_2ddgm g[chainid="+e[i]+"] rect[class='icn3d-basenode']");void 0!==a&&(t.diagram2dCls.highlightNode("rect",a,d,l),$(a).attr("fill",o)),a=$("#"+t.pre+"dl_2ddgm g[chainid="+e[i]+"] circle[class='icn3d-hlnode']"),d=$("#"+t.pre+"dl_2ddgm g[chainid="+e[i]+"] circle[class='icn3d-basenode']"),void 0!==a&&(t.diagram2dCls.highlightNode("circle",a,d,l),$(a).attr("fill",o)),a=$("#"+t.pre+"dl_2ddgm g[chainid="+e[i]+"] ellipse[class='icn3d-hlnode']"),void 0!==a&&t.diagram2dCls.highlightNode("ellipse",a,void 0,l),a=$("#"+t.pre+"dl_2ddgm g[chainid="+e[i]+"] polygon[class='icn3d-hlnode']"),d=$("#"+t.pre+"dl_2ddgm g[chainid="+e[i]+"] polygon[class='icn3d-basenode']"),void 0!==a&&(t.diagram2dCls.highlightNode("polygon",a,d,l),$(a).attr("fill",o))}if(void 0!==t.lineArray2d)for(let e=0,i=t.lineArray2d.length;e<i;e+=2)$("#"+t.pre+"dl_2ddgm g[chainid1="+t.lineArray2d[e]+"][chainid2="+t.lineArray2d[e+1]+"] line").attr("stroke",s.htmlCls.ORANGE);t.prevHighlightAtoms=s.hashUtilsCls.cloneHash(t.hAtoms),t.definedSetsCls.setMode("selection")}}updateHlMenus(e){let t=this.icn3d;t.icn3dui,void 0===e&&(e=[]);let s=t.definedSetsCls.setAtomMenu(e);$("#"+t.pre+"atomsCustom").length&&($("#"+t.pre+"atomsCustom").html(s),$("#"+t.pre+"atomsCustom")[0].blur())}hlSequence(e){let t=this.icn3d;t.icn3dui;let s={};for(let i=0,n=e.length;i<n;++i){let n=e[i].trim(),l=$("[id=giseq_"+t.pre+n+"]");0!==l.length&&l.addClass("icn3d-highlightSeq"),l=$("[id=align_"+t.pre+n+"]"),0!==l.length&&l.addClass("icn3d-highlightSeq");let r=n.lastIndexOf("_");s[n.substr(0,r)]=1}for(let e in s)0!==$("#giseq_summary_"+t.pre+e).length&&$("#giseq_summary_"+t.pre+e).addClass("icn3d-highlightSeqBox")}hlSeqInChain(e){let t=this.icn3d;t.icn3dui;for(let s=0,i=t.chainsSeq[e].length;s<i;++s){let i=e+"_"+t.chainsSeq[e][s].resi;0!==$("#giseq_"+t.pre+i).length&&$("#giseq_"+t.pre+i).addClass("icn3d-highlightSeq"),0!==$("#align_"+t.pre+i).length&&$("#align_"+t.pre+i).addClass("icn3d-highlightSeq")}0!==$("#giseq_summary_"+t.pre+e).length&&$("#giseq_summary_"+t.pre+e).addClass("icn3d-highlightSeqBox")}toggleHighlight(){let e=this.icn3d;e.icn3dui,e.bShowHighlight?(this.clearHighlight(),e.bShowHighlight=!1):(this.showHighlight(),e.bShowHighlight=!0)}clearHighlight(){let e=this.icn3d;e.icn3dui,e.labels.picking=[],e.drawCls.draw(),e.hlObjectsCls.removeHlObjects(),this.removeHl2D(),e.bRender&&e.drawCls.render(),this.removeSeqChainBkgd(),this.removeSeqResidueBkgd(),e.bSelectResidue=!1}showHighlight(){let e=this.icn3d;e.icn3dui,e.hlObjectsCls.addHlObjects(),this.updateHlAll()}highlightChains(e){let t=this.icn3d;t.icn3dui,t.hlObjectsCls.removeHlObjects(),this.removeHl2D(),t.hlObjectsCls.addHlObjects(),this.updateHl2D(e);let s={};for(let i=0,n=e.length;i<n;++i){let n=e[i];for(let e in t.chainsSeq[n]){let i=t.chainsSeq[n][e],l=n+"_"+i.resi;""!==i.name&&"-"!==i.name&&(s[l]=1)}}this.hlSequence(Object.keys(s))}hlSummaryDomain3ddomain(e){if(this.icn3d.icn3dui,void 0!==$(e).attr("domain")){let t=$(e).attr("index"),s=$(e).attr("chain");0!==$("[id^="+s+"_domain_"+t+"]").length&&$("[id^="+s+"_domain_"+t+"]").addClass("icn3d-highlightSeqBox")}if(void 0!==$(e).attr("3ddomain")){let t=$(e).attr("index"),s=$(e).attr("chain");0!==$("[id^="+s+"_3d_domain_"+t+"]").length&&$("[id^="+s+"_3d_domain_"+t+"]").addClass("icn3d-highlightSeqBox")}}removeSeqChainBkgd(e){void 0===e?$(".icn3d-seqTitle").each((function(e){$(this).removeClass("icn3d-highlightSeq"),$(this).removeClass("icn3d-highlightSeqBox")})):$(".icn3d-seqTitle").each((function(t){$(this).attr("chain")!==e&&($(this).removeClass("icn3d-highlightSeq"),$(this).removeClass("icn3d-highlightSeqBox"))}))}removeSeqResidueBkgd(){$(".icn3d-residue").each((function(e){$(this).removeClass("icn3d-highlightSeq")}))}}class Ht{constructor(e){this.icn3d=e}addHlObjects(e,t,s){let i=this.icn3d,n=i.icn3dui,l=s?n.hashUtilsCls.intHash(s,i.dAtoms):n.hashUtilsCls.intHash(i.hAtoms,i.dAtoms);i.applyDisplayCls.applyDisplayOptions(i.opts,l,i.bHighlight),(t||i.bRender)&&i.drawCls.render()}removeHlObjects(){let e=this.icn3d;e.icn3dui;for(let t in e.prevHighlightObjects)e.mdl&&e.mdl.remove(e.prevHighlightObjects[t]);e.prevHighlightObjects=[];for(let t in e.prevHighlightObjects_ghost)e.mdl&&e.mdl.remove(e.prevHighlightObjects_ghost[t]);e.prevHighlightObjects_ghost=[]}}class Lt{constructor(e){this.icn3d=e}drawLineGraph(e,t){let s,i=this.icn3d,n=i.icn3dui,l=JSON.parse(e),r=[],o=[],a=[],d={};for(let e=0,t=l.nodes.length;e<t;++e){let t=l.nodes[e];d[t.id]=t}let c={};for(let e=0,t=l.links.length;e<t;++e){let t=l.links[e];t.v!=n.htmlCls.hbondValue&&t.v!=n.htmlCls.ionicValue&&t.v!=n.htmlCls.halogenValue&&t.v!=n.htmlCls.picationValue&&t.v!=n.htmlCls.pistackingValue&&t.v!=n.htmlCls.contactValue||(r.push(t),c[t.source]=1,c[t.target]=1)}let h=i.getGraphCls.getNodeTopBottom(c,d);o=h.nodeArray1,a=h.nodeArray2,i.lineGraphStr="{\n";let p=Object.keys(i.structures);if(p.length>1){let e={},l=[],o=[],a=[],c=[],h=[],m=[],u=[],g=[],f=[],C=[],b=[],y=[],v={},_={};for(let t=0,s=p.length;t<s;++t)l[t]=[],o[t]=[],a[t]=[],c[t]={},h[t]=[],m[t]=[],u[t]=[],g[t]={},f[t]=[],C[t]=[],b[t]=[],y[t]={},e[p[t]]=t;for(let t=0,s=r.length;t<s;++t){let s=r[t],n=d[s.source],l=d[s.target];if(!(n&&l&&n.r&&l.r))continue;let o=this.getIdArrayFromNode(n),h=this.getIdArrayFromNode(l),m=e[o[2]];if(o[2]==p[m]&&h[2]==p[m]){a[m].push(s),c[m][s.source]=1,c[m][s.target]=1;let e,t,l=o[2]+"_"+o[3],r=h[2]+"_"+h[3],d=l+"_"+o[4],p=r+"_"+h[4];if(i.chainsMapping[l]&&i.chainsMapping[l][d]&&i.chainsMapping[r]&&i.chainsMapping[r][p]){e="a"==n.s?i.chainsMapping[l][d]:i.chainsMapping[r][p],t="a"==n.s?i.chainsMapping[r][p]:i.chainsMapping[l][d];let o=e+"_"+t+"_"+s.c;v.hasOwnProperty(o)?(++v[o],_[o]-=s.n):(v[o]=1,_[o]=s.n)}}}let w="=>",S="==>",A="-",x="--";for(let t=0,s=r.length;t<s;++t){let s=r[t],l=d[s.source],o=d[s.target];if(!(l&&o&&l.r&&o.r))continue;let h=this.getIdArrayFromNode(l),m=this.getIdArrayFromNode(o),f=e[h[2]];if(h[2]==p[f]&&m[2]==p[f]){a[f].push(s),c[f][s.source]=1,c[f][s.target]=1;let e,t,r=h[2]+"_"+h[3],o=m[2]+"_"+m[3],d=r+"_"+h[4],C=o+"_"+m[4];if(i.chainsMapping[r]&&i.chainsMapping[r][d]&&i.chainsMapping[o]&&i.chainsMapping[o][C]){e="a"==l.s?i.chainsMapping[r][d]:i.chainsMapping[o][C],t="a"==l.s?i.chainsMapping[o][C]:i.chainsMapping[r][d];let a=e+"_"+t+"_"+s.c,c=n.hashUtilsCls.cloneHash(s);c.source+=w+i.chainsMapping[r][d],c.target+=w+i.chainsMapping[o][C];let h=n.hashUtilsCls.cloneHash(s);h.source+=S+i.chainsMapping[r][d],h.target+=S+i.chainsMapping[o][C],v[a]==p.length&&0==_[a]?u[f].push(c):b[f].push(h),g[f][s.source]=i.chainsMapping[r][d],g[f][s.target]=i.chainsMapping[o][C],y[f][s.source]=i.chainsMapping[r][d],y[f][s.target]=i.chainsMapping[o][C]}else{let e=n.hashUtilsCls.cloneHash(s);e.source+=i.chainsMapping[r]&&i.chainsMapping[r][d]?S+i.chainsMapping[r][d]:S+x,e.target+=i.chainsMapping[o]&&i.chainsMapping[o][C]?S+i.chainsMapping[o][C]:S+x,b[f].push(e),g[f][s.source]=i.chainsMapping[r]&&i.chainsMapping[r][d]?i.chainsMapping[r][d]:A,g[f][s.target]=i.chainsMapping[o]&&i.chainsMapping[o][C]?i.chainsMapping[o][C]:A,y[f][s.source]=i.chainsMapping[r]&&i.chainsMapping[r][d]?i.chainsMapping[r][d]:x,y[f][s.target]=i.chainsMapping[o]&&i.chainsMapping[o][C]?i.chainsMapping[o][C]:x}}}let k=[],O=[],R=0,I=[],E=1;for(let e=0,t=p.length;e<t;++e){let t=i.getGraphCls.getNodeTopBottom(c[e],d);l[e]=t.nodeArray1,o[e]=t.nodeArray2,Object.keys(i.chainsMapping).length>0&&(E=1,t=i.getGraphCls.getNodeTopBottom(c[e],d,void 0,E,g[e]),h[e]=t.nodeArray1,m[e]=t.nodeArray2,d=n.hashUtilsCls.unionHash(d,t.name2node),E=2,t=i.getGraphCls.getNodeTopBottom(c[e],d,void 0,E,y[e]),f[e]=t.nodeArray1,C[e]=t.nodeArray2,d=n.hashUtilsCls.unionHash(d,t.name2node)),k[e]=l[e].length,O[e]=o[e].length,R=Math.max(R,O[e]),I.push(p[e])}let T,P,D,M,F,H=1,L=3*H,N=7*H,q=10,U=10,B=30,$=20;t?(D=(n.utilsCls.sumArray(k)+2*I.length)*(L+N)+4*U+2*B+$*I.length,P=(R+2)*(L+N)+2*q+B):(T=110+$,D=T*I.length,P=(R+2)*(L+N)+2*q,P+=20),Object.keys(i.chainsMapping).length>0&&(D*=3),t?(i.scatterplotWidth=2*P,F=i.scatterplotWidth,M=n.scatterplotid):(i.linegraphWidth=2*P,F=i.linegraphWidth,M=n.linegraphid),s=0==I.length?"No interactions found for each structure<br><br>":"2D integration graph for "+I.length+" structure(s) <b>"+I+'</b>. There are three sections: "Interactions", "Common interactions", and "Different interactions". Each section has '+I.length+" graphs.<br><br>",s+="<svg id='"+M+"' viewBox='0,0,"+P+","+D+"' width='"+F+"px'>";let j,z=0;E=0,j=this.drawGraphPerType(E,p,t,l,o,a,d,z,T,$,k,L,N,U),z=j.heightFinal,s+=j.html,Object.keys(i.chainsMapping).length>0&&(E=1,j=this.drawGraphPerType(E,p,t,h,m,u,d,z,T,$,k,L,N,U),z=j.heightFinal,s+=j.html,E=2,j=this.drawGraphPerType(E,p,t,f,C,b,d,z,T,$,k,L,N,U),z=j.heightFinal,s+=j.html),s+="</svg>"}else if(t){let e,t,l,c,h=p[0],m=o.length,u=a.length,g=1,f=3*g,C=7*g,b=30;t=(m+2)*(f+C)+2*10+b,e=(u+2)*(f+C)+2*10+b,i.scatterplotWidth=2*e,c=i.scatterplotWidth,l=n.scatterplotid,s=r.length>0?"":"No interactions found for these two sets<br><br>",s+="<svg id='"+l+"' viewBox='0,0,"+e+","+t+"' width='"+c+"px'>",s+=this.drawScatterplot_base(o,a,r,d,0),i.lineGraphStr+=i.getGraphCls.updateGraphJson(h,1,o,a,r),s+="</svg>"}else{let e=p[0],t=o.length,l=a.length,c=1,h=3*c,m=7*c,u=110,g=10,f=t>l?t*(h+m)+2*g:l*(h+m)+2*g;i.linegraphWidth=2*f,s=r.length>0?"":"No interactions found for these two sets<br><br>",s+="<svg id='"+n.linegraphid+"' viewBox='0,0,"+f+","+u+"' width='"+i.linegraphWidth+"px'>",s+=this.drawLineGraph_base(o,a,r,d,0),i.lineGraphStr+=i.getGraphCls.updateGraphJson(e,1,o,a,r),s+="</svg>"}return i.lineGraphStr+="}\n",i.scatterplotStr=i.lineGraphStr,t?$("#"+i.pre+"scatterplotDiv").html(s):$("#"+i.pre+"linegraphDiv").html(s),s}drawGraphPerType(e,t,s,i,n,l,r,o,a,d,c,h,p,m){let u=this.icn3d;u.icn3dui;let g,f,C="",b=2==t.length&&"2"==t[1].replace(t[0],"");0==e?(g="Interactions in ",f=""):1==e?(g="Common interactions in ",f="_common"):2==e&&(g="Different interactions in ",f="_diff");for(let y=0,v=t.length;y<v;++y){let v=g;b&&(0==y?v+="Wild Type ":1==y&&(v+="Mutant ")),s?(C+=this.drawScatterplot_base(i[y],n[y],l[y],r,o,void 0,v+t[y],d),a=(c[y]+1)*(h+p)+2*m+d):C+=this.drawLineGraph_base(i[y],n[y],l[y],r,o,v+t[y],d),o+=a,e?y>0&&(u.lineGraphStr+=", \n"):u.lineGraphStr+=", \n",u.lineGraphStr+=u.getGraphCls.updateGraphJson(t[y],y+f,i[y],n[y],l[y])}return{heightFinal:o,html:C}}getIdArrayFromNode(e){let t=this.icn3d.icn3dui,s=[];s.push(""),s.push("");let i=e.r.substr(4);return s=s.concat(t.utilsCls.getIdArray(i)),s}drawLineGraph_base(e,t,s,i,n,l,r){let o,a,d=this.icn3d,c=d.icn3dui,h="",p=e.length,m=t.length;p>m?(o=10,a=10*Math.abs(p-m)*.5+10):(a=10,o=10*Math.abs(p-m)*.5+10),l&&(h+="<text x='10' y='"+(n+=r)+"' style='font-size:8px; font-weight:bold'>"+l+"</text>");let u=30+n,g=80+n,f="",C={},b={};for(let t=0;t<p;++t)f+=d.getGraphCls.drawResNode(e[t],t,3,7,o,u,"a"),C[e[t].id]={x:o+10*t,y:u};for(let e=0;e<m;++e)f+=d.getGraphCls.drawResNode(t[e],e,3,7,a,g,"b"),b[t[e].id]={x:a+10*e,y:g};for(let e=0,t=s.length;e<t;++e){let t=s[e],n=i[t.source],l=i[t.target];if(void 0===n||void 0===l)continue;let r,o,a=n.r.substr(4),d=l.r.substr(4),p=C[n.id],m=b[l.id];if(void 0===p||void 0===m)continue;r=t.v==c.htmlCls.contactValue?1==t.n?1:3:1==t.n?2:4,t.v==c.htmlCls.hbondValue?o="#"+c.htmlCls.hbondColor:t.v==c.htmlCls.ionicValue?o="#"+c.htmlCls.ionicColor:t.v==c.htmlCls.halogenValue?o="#"+c.htmlCls.halogenColor:t.v==c.htmlCls.picationValue?o="#"+c.htmlCls.picationColor:t.v==c.htmlCls.pistackingValue?o="#"+c.htmlCls.pistackingColor:t.v==c.htmlCls.contactValue&&(o="#"+c.htmlCls.contactColor),h+="<g class='icn3d-interaction' resid1='"+a+"' resid2='"+d+"' >";let u=1==t.n?"Interaction":t.n+" interactions";t.n>1&&(h+="<title>"+u+" of residue "+n.id+" with residue "+l.id+"</title>"),h+="<line x1='"+p.x+"' y1='"+p.y+"' x2='"+m.x+"' y2='"+m.y+"' stroke='"+o+"' stroke-width='"+r+"'/></g>"}return h+=f,h}drawScatterplot_base(e,t,s,i,n,l,r,o,a){let d=this.icn3d;d.icn3dui;let c="",h=e.length,p=t.length,m=l?3:7,u=(h+1)*(3+m)+30+40;r&&(c+="<text x='10' y='"+((n+=o)+15).toString()+"' style='font-size:8px; font-weight:bold'>"+r+"</text>");let g=n+u-(50+(3+m)),f=40+(3+m),C="",b={},y={};for(let t=0;t<h;++t)C+=d.getGraphCls.drawResNode(e[t],t,3,m,g,40,"a",!0,void 0,a),b[e[t].id]={x:40,y:g-t*(3+m)};let v=n+u-50;for(let e=0;e<p;++e)C+=d.getGraphCls.drawResNode(t[e],e,3,m,f,v,"b",!1,l,a),y[t[e].id]={x:f+e*(3+m),y:v};for(let e=0,t=s.length;e<t;++e){let t=s[e],n=i[t.source],r=i[t.target];n&&r&&(c+=this.drawOnePairNode(t,n,r,b,y,l,a),l&&!a&&(c+=this.drawOnePairNode(t,r,n,b,y,l,a)))}return c+=C,c}drawOnePairNode(e,t,s,i,n,l,r){let o,a,d=this.icn3d,c=d.icn3dui,h="",p=l?6:4.5,m=.5*p,u=t.r.substr(4),g=s.r.substr(4),f=i[t.id],C=n[s.id];if(void 0===f||void 0===C)return h;if(e.v==c.htmlCls.hbondValue?o="#"+c.htmlCls.hbondColor:e.v==c.htmlCls.ionicValue?o="#"+c.htmlCls.ionicColor:e.v==c.htmlCls.halogenValue?o="#"+c.htmlCls.halogenColor:e.v==c.htmlCls.picationValue?o="#"+c.htmlCls.picationColor:e.v==c.htmlCls.pistackingValue?o="#"+c.htmlCls.pistackingColor:e.v==c.htmlCls.contactValue&&(o="#"+c.htmlCls.contactColor),l&&(o="#"+e.c),a=e.v==c.htmlCls.contactValue?1==e.n?1:3:1==e.n?2:4,r&&d.hex2skip[e.c]);else if(r&&d.hex2id[e.c])d.hex2id[e.c],h+="<rect class='icn3d-interaction' resid1='"+u+"' resid2='"+g+"' x='"+(C.x-m).toString()+"' y='"+(f.y-m).toString()+"' width='"+p+"' height='"+p+"' fill='"+o+"' stroke-width='"+a+"' stroke='"+o+"' />";else{h+="<g class='icn3d-interaction' resid1='"+u+"' resid2='"+g+"' >";let i=1==e.n?"Interaction":e.n+" interactions";e.n>1&&(h+="<title>"+i+" of residue "+t.id+" with residue "+s.id+"</title>"),h+=l?"<rect x='"+(C.x-m).toString()+"' y='"+(f.y-m).toString()+"' width='"+p+"' height='"+p+"' fill='"+o+"' stroke-width='"+a+"' stroke='"+o+"' />":"<rect x='"+(C.x-m).toString()+"' y='"+(f.y-m).toString()+"' width='"+p+"' height='"+p+"' fill='"+o+"' fill-opacity='0.6' stroke-width='"+a+"' stroke='"+o+"' />",h+="</g>"}return h}copyStylesInline(e,t){this.icn3d.icn3dui;let s=["svg","g"];for(let i=0;i<e.childNodes.length;i++){let n=e.childNodes[i];if(-1!=s.indexOf(n.tagName)){this.copyStylesInline(n,t.childNodes[i]);continue}let l=t.childNodes[i].currentStyle||window.getComputedStyle(t.childNodes[i]);if("undefined"!=l&&null!=l)for(let e=0;e<l.length;e++)n.style.setProperty(l[e],l.getPropertyValue(l[e]))}}}class Nt{constructor(e){this.icn3d=e}getGraphData(e,t,s,i,n,l,r){let o=this.icn3d,a=o.icn3dui,d="",c="",h=[],p=[],m=this.getNodesLinksForSet(e,l,"a",r),u=this.getNodesLinksForSet(t,l,"b",r);h=m.node.concat(u.node);let g=[],f={},C=0;for(let e=0,t=h.length;e<t;++e){let t=h[e],s=JSON.parse(t);if(f.hasOwnProperty(s.id)){g[f[s.id]].s="ab"}else g.push(s),f[s.id]=C,++C}let b=[];for(let e=0,t=g.length;e<t;++e){let t=g[e];b.push(JSON.stringify(t))}d=b.join(", "),p=m.link.concat(u.link),c=p.join(", ");let y=a.hashUtilsCls.unionHash(a.hashUtilsCls.cloneHash(t),e),v="",_="",w="",S="",A="",x="";1==s.length&&1==i.length&&s[0]==i[0]||(v+=this.getHbondLinksForSet(e,l),v+=this.getHbondLinksForSet(t,l)),1==s.length&&1==i.length&&s[0]==i[0]||(_+=this.getIonicLinksForSet(e,l),_+=this.getIonicLinksForSet(t,l)),1==s.length&&1==i.length&&s[0]==i[0]||(w+=this.getHalogenPiLinksForSet(e,l),w+=this.getHalogenPiLinksForSet(t,l)),1==s.length&&1==i.length&&s[0]==i[0]||(S+=this.getContactLinksForSet(e,l),S+=this.getContactLinksForSet(t,l));for(let e in o.ssbondpnts)for(let t=0,s=o.ssbondpnts[e].length;t<s;t+=2){let s=o.ssbondpnts[e][t],i=o.ssbondpnts[e][t+1],n=o.firstAtomObjCls.getFirstAtomObj(o.residues[s]),r=o.firstAtomObjCls.getFirstAtomObj(o.residues[i]);if(y.hasOwnProperty(n.serial)&&y.hasOwnProperty(r.serial)){let e=a.utilsCls.residueName2Abbr(n.resn)+n.resi;"chain"!=l&&"structure"!=l||(e+="."+n.chain),"structure"==l&&(e+="."+n.structure);let t=a.utilsCls.residueName2Abbr(r.resn)+r.resi;"chain"!=l&&"structure"!=l||(t+="."+r.chain),"structure"==l&&(t+="."+r.structure),A+=', {"source": "'+e+'", "target": "'+t+'", "v": '+a.htmlCls.ssbondValue+', "c": "'+a.htmlCls.ssbondColor+'"}'}}for(let e in o.clbondpnts)for(let t=0,s=o.clbondpnts[e].length;t<s;t+=2){let s=o.clbondpnts[e][t],i=o.clbondpnts[e][t+1],n=o.firstAtomObjCls.getFirstAtomObj(o.residues[s]),r=o.firstAtomObjCls.getFirstAtomObj(o.residues[i]);if(y.hasOwnProperty(n.serial)&&y.hasOwnProperty(r.serial)){let e=a.utilsCls.residueName2Abbr(n.resn)+n.resi;"chain"!=l&&"structure"!=l||(e+="."+n.chain),"structure"==l&&(e+="."+n.structure);let t=a.utilsCls.residueName2Abbr(r.resn)+r.resi;"chain"!=l&&"structure"!=l||(t+="."+r.chain),"structure"==l&&(t+="."+r.structure),x+=', {"source": "'+e+'", "target": "'+t+'", "v": '+a.htmlCls.clbondValue+', "c": "'+a.htmlCls.clbondColor+'"}'}}let k='{"nodes": ['+d+'], "links": [';return k+=""==c?c+n.substr(1)+A+x+S+v+_+w:c+n+A+x+S+v+_+w,k+="]}",k}drawResNode(e,t,s,i,n,l,r,o,a,d){let c=this.icn3d;c.icn3dui;let h,p=e.r.substr(4);h=o?n-t*(s+i):n+t*(s+i),c.firstAtomObjCls.getFirstAtomObj(c.residues[p]);let m="#"+e.c.toUpperCase();c.hColor.getHexString().toUpperCase();let u=e.id.indexOf("."),g=-1==u?e.id:e.id.substr(0,u),f="a"==r?-7:10;if(t%2==1&&(f="a"==r?f-7:f+7),a&&(g=g.substr(1),o||(f+=4*s)),c.bShownRefnum&&c.resid2refnum[p]){let e=c.resid2refnum[p],t=c.refnumCls.rmStrandFromRefnumlabel(e);g=c.residueId2Name[p]+t}let C="<g class='icn3d-node' resid='"+p+"' >",b=e.id;return c.resid2refnum[p]&&(b+="=>"+c.resid2refnum[p]),C+="<title>"+b+"</title>",o?(C+="<circle cx='"+l+"' cy='"+h+"' r='"+s+"' fill='"+m+"' stroke-width='1' stroke='"+"#000' resid='"+p+"' />",C+="<text x='"+(l-20).toString()+"' y='"+(h+2).toString()+"' fill='"+"#000' stroke='none' style='font-size:6px; text-anchor:middle' >"+g+"</text>"):(C+="<circle cx='"+h+"' cy='"+l+"' r='"+s+"' fill='"+m+"' stroke-width='1' stroke='"+"#000' resid='"+p+"' />",C+="<text x='"+(h+0).toString()+"' y='"+(l+f).toString()+"' fill='"+"#000' stroke='none' style='font-size:6px; text-anchor:middle' >"+g+"</text>"),C+="</g>",C}getNodeTopBottom(e,t,s,i,n){let l=this.icn3d.icn3dui,r=this,o=[],a=[],d={};for(let s in e){let e=t[s];if(e){if(1==i||2==i){if(e=l.hashUtilsCls.cloneHash(e),1==i){let t=n[s]?n[s]:"-";e.id+="=>"+t}else{let t=n[s]?n[s]:"--";e.id+="==>"+t}d[e.id]=e}"a"==e.s?o.push(e):"b"==e.s?a.push(e):"ab"==e.s&&(o.push(e),a.push(e))}}return o.sort((function(e,t){return r.compNode(e,t)})),a.sort((function(e,t){return r.compNode(e,t,s)})),{nodeArray1:o,nodeArray2:a,name2node:d}}updateGraphJson(e,t,s,i,n){let l=this.icn3d.icn3dui,r="";return r+='"structure'+t+'": {"id": "'+e+'", "nodes1":[',r+=l.utilsCls.getJSONFromArray(s),r+='], \n"nodes2":[',r+=l.utilsCls.getJSONFromArray(i),r+='], \n"links":[',r+=l.utilsCls.getJSONFromArray(n),r+="]}",r}updateGraphColor(){let e=this.icn3d,t=e.icn3dui;if(void 0!==e.graphStr){let s=JSON.parse(e.graphStr),i={};for(let t in e.residues){let s=e.firstAtomObjCls.getFirstAtomObj(e.residues[t]);i[t]=s.color.getHexString().toUpperCase()}let n={};for(let e=0,l=s.nodes.length;e<l;++e){let l=s.nodes[e],r=[];r.push(""),r.push("");let o=l.r.substr(4);r=r.concat(t.utilsCls.getIdArray(o));let a=r[2]+"_"+r[3]+"_"+r[4];l.c=i[a],n[l.id]=a}for(let e=0,l=s.links.length;e<l;++e){let l=s.links[e];if(l.v==t.htmlCls.ssValue||l.v==t.htmlCls.coilValue){let e=n[l.target];l.c=i[e]}}e.graphStr=JSON.stringify(s)}e.bGraph&&e.drawGraphCls.drawGraph(e.graphStr,e.pre+"dl_graph"),e.bLinegraph&&e.lineGraphCls.drawLineGraph(e.graphStr),e.bScatterplot&&e.lineGraphCls.drawLineGraph(e.graphStr,!0)}handleForce(){let e=this.icn3d;0==e.icn3dui.htmlCls.force&&void 0!==e.simulation?(e.simulation.stop(),e.simulation.force("charge",null),e.simulation.force("x",null),e.simulation.force("y",null),e.simulation.force("r",null),e.simulation.force("link",null)):e.drawGraphCls.drawGraph(e.graphStr,e.pre+"dl_graph")}getNodesLinksForSet(e,t,s,i){let n=this.icn3d,l=n.icn3dui,r=[],o=[],a=0,d=l.htmlCls.coilValue,c="",h="",p=0,m={};for(let u in e){let e=n.atoms[u];if("DUM"!=e.chain&&(i||e.het||"CA"==e.name&&"C"==e.elem||"O3'"==e.name||"O3*"==e.name||"P"==e.name)){let i=e.structure+"_"+e.chain+"_"+e.resi;if(m.hasOwnProperty(i))continue;m[i]=1;let u=l.utilsCls.residueName2Abbr(e.resn)+e.resi;"chain"!=t&&"structure"!=t||(u+="."+e.chain),"structure"==t&&(u+="."+e.structure);let g="1_1_"+i,f=e.color?e.color.getHexString().toUpperCase():"000";r.push('{"id": "'+u+'", "r": "'+g+'", "s": "'+s+'", "x": '+e.coord.x.toFixed(0)+', "y": '+e.coord.y.toFixed(0)+', "c": "'+f+'"}'),a>0&&c==e.chain&&(n.resid2ncbi[e.resi]==n.resid2ncbi[p]+1||n.resid2ncbi[e.resi]==n.resid2ncbi[p])&&(o.push('{"source": "'+h+'", "target": "'+u+'", "v": '+d+', "c": "'+f+'"}'),e.ssbegin&&(d=l.htmlCls.ssValue),e.ssend&&(d=l.htmlCls.coilValue)),c=e.chain,h=u,p=e.resi,++a}}return{node:r,link:o}}getHbondLinksForSet(e,t){let s=this.icn3d,i=s.icn3dui,n={},l=parseFloat($("#"+s.pre+"hbondthreshold").val()),r=e,o=r;if(Object.keys(o).length>0&&Object.keys(r).length>0){let e=!1;s.hBondCls.calculateChemicalHbonds(i.hashUtilsCls.hash2Atoms(o,s.atoms),i.hashUtilsCls.hash2Atoms(r,s.atoms),parseFloat(l),e,"graph",!0),n=i.hashUtilsCls.cloneHash(s.resid2Residhash)}return this.getGraphLinks(n,n,i.htmlCls.hbondInsideColor,t,i.htmlCls.hbondInsideValue)}getIonicLinksForSet(e,t){let s=this.icn3d,i=s.icn3dui,n={},l=parseFloat($("#"+s.pre+"saltbridgethreshold").val()),r=e,o=r;if(Object.keys(o).length>0&&Object.keys(r).length>0){let e=!1;s.saltbridgeCls.calculateIonicInteractions(i.hashUtilsCls.hash2Atoms(o,s.atoms),i.hashUtilsCls.hash2Atoms(r,s.atoms),parseFloat(l),e,"graph",!0),n=i.hashUtilsCls.cloneHash(s.resid2Residhash)}return this.getGraphLinks(n,n,i.htmlCls.ionicInsideColor,t,i.htmlCls.ionicInsideValue)}getHalogenPiLinksForSet(e,t){let s,i=this.icn3d,n=i.icn3dui,l={},r=e,o=r,a="";return s=parseFloat($("#"+i.pre+"halogenthreshold").val()),Object.keys(o).length>0&&Object.keys(r).length>0&&(i.piHalogenCls.calculateHalogenPiInteractions(n.hashUtilsCls.hash2Atoms(r,i.atoms),n.hashUtilsCls.hash2Atoms(o,i.atoms),parseFloat(s),"graph","halogen",!0),l=n.hashUtilsCls.cloneHash(i.resid2Residhash)),a+=this.getGraphLinks(l,l,n.htmlCls.halogenInsideColor,t,n.htmlCls.halogenInsideValue),s=parseFloat($("#"+i.pre+"picationthreshold").val()),Object.keys(o).length>0&&Object.keys(r).length>0&&(i.piHalogenCls.calculateHalogenPiInteractions(n.hashUtilsCls.hash2Atoms(r,i.atoms),n.hashUtilsCls.hash2Atoms(o,i.atoms),parseFloat(s),"graph","pi-cation",!0),l=n.hashUtilsCls.cloneHash(i.resid2Residhash)),a+=this.getGraphLinks(l,l,n.htmlCls.picationInsideColor,t,n.htmlCls.picationInsideValue),s=parseFloat($("#"+i.pre+"pistackingthreshold").val()),Object.keys(o).length>0&&Object.keys(r).length>0&&(i.piHalogenCls.calculateHalogenPiInteractions(n.hashUtilsCls.hash2Atoms(r,i.atoms),n.hashUtilsCls.hash2Atoms(o,i.atoms),parseFloat(s),"graph","pi-stacking",!0),l=n.hashUtilsCls.cloneHash(i.resid2Residhash)),a+=this.getGraphLinks(l,l,n.htmlCls.pistackingInsideColor,t,n.htmlCls.pistackingInsideValue),a}getContactLinksForSet(e,t,s){let i=this.icn3d;i.icn3dui;let n=[],l="",r="",o={};for(let t in e){let e=i.atoms[t];e.ss==l&&e.chain==r||(Object.keys(o).length>0&&n.push(o),o={}),o[e.serial]=1,l=e.ss,r=e.chain}Object.keys(o).length>0&&n.push(o);let a=n.length,d="";for(let e=0;e<a;++e)for(let i=e+1;i<a;++i)d+=this.getContactLinks(n[e],n[i],t,!0,s);return d}getContactLinks(e,t,s,i,n){let l=this.icn3d,r=l.icn3dui,o=parseFloat($("#"+l.pre+"contactthreshold").val());l.contactCls.getAtomsWithinAtom(t,e,parseFloat(o),!0,!1,i);let a=r.hashUtilsCls.cloneHash(l.resid2Residhash);return this.getGraphLinks(a,a,r.htmlCls.contactInsideColor,s,r.htmlCls.contactInsideValue,n)}compNode(e,t,s){let i=this.icn3d.icn3dui,n=e.r.substr(4),l=t.r.substr(4),r=i.utilsCls.getIdArray(n),o=i.utilsCls.getIdArray(l),a=r[0]+"_"+r[1],d=o[0]+"_"+o[1],c=parseInt(r[2]),h=parseInt(o[2]);return a>d?s?-1:1:a<d?s?1:-1:a==d?c>h?1:c<h?-1:0:void 0}getGraphLinks(e,t,s,i,n,l){var r=this.icn3d,o=r.icn3dui;let a="";n=void 0===n?1:n;let d={};for(let a in e){a=a.trim();let e=a.indexOf(" "),c=a.indexOf(":"),h=a.indexOf("@"),p=-1!==h?h:a.length,m=a.indexOf("."),u=a.indexOf("$"),g=o.utilsCls.residueName2Abbr(a.substr(0,e))+a.substr(c+1,p-c-1);"chain"!=i&&"structure"!=i||(g+="."+a.substr(m+1,c-m-1)),"structure"==i&&(g+="."+a.substr(u+1,m-u-1));for(let e in t[a]){e=e.trim();let t=e.indexOf(" "),a=e.indexOf(":"),c=e.indexOf("@"),h=-1!==c?c:e.length,p=e.indexOf("."),m=e.indexOf("$"),u=o.utilsCls.residueName2Abbr(e.substr(0,t))+e.substr(a+1,h-a-1);if(e.substr(p+1,a-p-1),"chain"!=i&&"structure"!=i||(u+="."+e.substr(p+1,a-p-1)),"structure"==i&&(u+="."+e.substr(m+1,p-m-1)),l&&(g=r.resi2resirange[g],u=r.resi2resirange[u]),void 0!==g&&void 0!==u){let e='"source": "'+g+'", "target": "'+u+'", "v": '+n+', "c": "'+s+'"';d.hasOwnProperty(e)?++d[e]:d[e]=1}}}for(let e in d)a+=", {"+e+', "n": '+d[e]+"}";return a}convertLabel2Resid(e){this.icn3d.icn3dui,e.indexOf(" ");let t=e.indexOf("@"),s=-1!==t?t:e.length,i=e.indexOf("$"),n=e.indexOf("."),l=e.indexOf(":");return e.substr(i+1,n-i-1)+"_"+e.substr(n+1,l-n-1)+"_"+e.substr(l+1,s-l-1)}}class qt{constructor(e){this.icn3d=e}async showInteractions(e){let t,s,i=this.icn3d,n=i.icn3dui,l=$("#"+i.pre+"atomsCustomHbond").val(),r=$("#"+i.pre+"atomsCustomHbond2").val();if(t=i.definedSetsCls.getAtomsFromNameArray(l),s=i.definedSetsCls.getAtomsFromNameArray(r),i.dAtoms=n.hashUtilsCls.unionHash(i.dAtoms,t),i.dAtoms=n.hashUtilsCls.unionHash(i.dAtoms,s),0==r.length)alert("Please select the first set");else{i.definedSetsCls.setMode("selection");let t=$("#"+i.pre+"analysis_hbond")[0].checked,s=$("#"+i.pre+"analysis_saltbridge")[0].checked,o=$("#"+i.pre+"analysis_contact")[0].checked,a=$("#"+i.pre+"analysis_halogen")[0].checked,d=$("#"+i.pre+"analysis_pication")[0].checked,c=$("#"+i.pre+"analysis_pistacking")[0].checked,h="threshold "+$("#"+i.pre+"hbondthreshold").val()+" "+$("#"+i.pre+"saltbridgethreshold").val()+" "+$("#"+i.pre+"contactthreshold").val()+" "+$("#"+i.pre+"halogenthreshold").val()+" "+$("#"+i.pre+"picationthreshold").val()+" "+$("#"+i.pre+"pistackingthreshold").val(),p=(await i.viewInterPairsCls.viewInteractionPairs(r,l,i.bHbondCalc,e,t,s,o,a,d,c)).interactionTypes,m=i.bHbondCalc?"true":"false",u=r+" "+l+" | "+p+" | "+m+" | "+h;if("3d"==e)n.htmlCls.clickMenuCls.setLogCmd("display interaction 3d | "+u,!0);else if("view"==e)n.htmlCls.clickMenuCls.setLogCmd("view interaction pairs | "+u,!0);else if("save1"==e)n.htmlCls.clickMenuCls.setLogCmd("save1 interaction pairs | "+u,!0);else if("save2"==e)n.htmlCls.clickMenuCls.setLogCmd("save2 interaction pairs | "+u,!0);else if("linegraph"==e)n.htmlCls.clickMenuCls.setLogCmd("line graph interaction pairs | "+u,!0);else if("scatterplot"==e)n.htmlCls.clickMenuCls.setLogCmd("scatterplot interaction pairs | "+u,!0);else if("graph"==e){let e=parseInt($("#"+i.pre+"dist_ss").val()),t=parseInt($("#"+i.pre+"dist_coil").val()),s=parseInt($("#"+i.pre+"dist_hbond").val()),o=parseInt($("#"+i.pre+"dist_inter").val()),a=parseInt($("#"+i.pre+"dist_ssbond").val()),d=parseInt($("#"+i.pre+"dist_ionic").val()),c=parseInt($("#"+i.pre+"dist_halogen").val()),u=parseInt($("#"+i.pre+"dist_pication").val()),g=parseInt($("#"+i.pre+"dist_pistacking").val());n.htmlCls.clickMenuCls.setLogCmd("graph interaction pairs | "+r+" "+l+" | "+p+" | "+m+" | "+h+" | "+e+" "+t+" "+s+" "+o+" "+a+" "+d+" "+c+" "+u+" "+g,!0)}i.bHbondCalc=!0}}showHbonds(e,t,s,i,n,l){let r,o,a,d,c=this.icn3d,h=c.icn3dui;if(!i&&(n?(r="saltbridge",o="salt bridge "+e+" | sets "+t+" "+s+" | "+i):(r="hbonds",o="hbonds "+e+" | sets "+t+" "+s+" | "+i),c.opts[r]="yes",c.opts.water="dot",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.hBondCls.calculateChemicalHbonds(h.hashUtilsCls.hash2Atoms(d,c.atoms),h.hashUtilsCls.hash2Atoms(a,c.atoms),parseFloat(e),n);n?(c.resid2ResidhashSaltbridge=h.hashUtilsCls.cloneHash(c.resid2Residhash),t="all atoms that have salt bridges with the selected atoms"):(c.resid2ResidhashHbond=h.hashUtilsCls.cloneHash(c.resid2Residhash),t="all atoms that are hydrogen-bonded 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";let l=r+"_auto";c.selectionCls.addCustomSelection(Object.keys(i),l,t,o,!0),c.selectionCls.saveSelectionIfSelected(),c.drawCls.draw()}}showHydrogens(){let e=this.icn3d;if(void 0!==e.icn3dui.cfg.cid)for(let t in e.hAtoms){let s=e.atoms[t];if("H"!==s.elem.substr(0,1)){e.atoms[s.serial].bonds=e.atoms[s.serial].bonds2.concat(),e.atoms[s.serial].bondOrder=e.atoms[s.serial].bondOrder2.concat();for(let t=0,i=e.atoms[s.serial].bonds.length;t<i;++t){let i=e.atoms[s.serial].bonds[t];"H"===e.atoms[i].elem.substr(0,1)&&(e.dAtoms[i]=1,e.hAtoms[i]=1)}}}else for(let t in e.atoms){let s=e.atoms[t];if("H"===s.elem.substr(0,1)){if(e.atoms[t].bonds.length>0){let i=e.atoms[t].bonds[0];e.atoms[i].bonds.push(s.serial),e.atoms[i].bondOrder&&e.atoms[i].bondOrder.push(1)}e.dAtoms[t]=1}}
11
11
  //!!!ic.bShowHighlight = false;
12
12
  }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(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){let t=this.icn3d,s=t.icn3dui,i=[],n=Object.keys(t.resids2inter);("save1"==e||"save2"==e)&&n.sort((function(t,i){return s.utilsCls.compResid(t,i,e)}));let l,r,o="",a="",d="",c="",h="",p="",m="",u="",g="",f=0,C=0,b=0,y=0,v=0,_=0,w="";for(let s=0,S=n.length;s<S;++s){let S=n[s],A=S.split(",");l="save1"==e?A[0]:A[1],r="save1"==e?A[1]:A[0];let x,k,O=l.split("_");s>0&&l!=a&&(i.push({res1:a,res2:w,cntHbond:f,cntIonic:C,cntContact:b,cntHalegen:y,cntPication:v,cntPistacking:_}),o+=this.getInteractionPerResidue(d,c,h,p,m,u,g,f,C,b,y,v,_),c="",h="",p="",m="",u="",g="",f=0,C=0,b=0,y=0,v=0,_=0,w=""),x=t.resids2inter[S].hbond,k=this.getInteractionPairDetails(x,e,"hbond"),c+=k.html,f+=k.cnt,k.cnt>0&&(w+=r+":hbond_"+k.cnt+" "),x=t.resids2inter[S].ionic,k=this.getInteractionPairDetails(x,e,"ionic"),h+=k.html,C+=k.cnt,k.cnt>0&&(w+=r+":ionic_"+k.cnt+" "),x=t.resids2inter[S].contact,k=this.getContactPairDetails(x,e,"contact"),p+=k.html,b+=k.cnt,k.cnt>0&&(w+=r+":contact_"+k.cnt+" "),x=t.resids2inter[S].halogen,k=this.getInteractionPairDetails(x,e,"halogen"),m+=k.html,y+=k.cnt,k.cnt>0&&(w+=r+":halogen_"+k.cnt+" "),x=t.resids2inter[S]["pi-cation"],k=this.getInteractionPairDetails(x,e,"pi-cation"),u+=k.html,v+=k.cnt,k.cnt>0&&(w+=r+":pi-cation_"+k.cnt+" "),x=t.resids2inter[S]["pi-stacking"],k=this.getInteractionPairDetails(x,e,"pi-stacking"),g+=k.html,_+=k.cnt,k.cnt>0&&(w+=r+":pi-stacking_"+k.cnt+" "),a=l,d=O}i.push({res1:a,res2:w,cntHbond:f,cntIonic:C,cntContact:b,cntHalegen:y,cntPication:v,cntPistacking:_}),o+=this.getInteractionPerResidue(d,c,h,p,m,u,g,f,C,b,y,v,_);let S="";if(n.length>0){S+='<br><table class="icn3d-sticky" align=center border=1 cellpadding=10 cellspacing=0><thead>',S+="<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>",S+="<th rowspan=2># Halogen<br>Bond</th><th rowspan=2># &pi;-Cation</th><th rowspan=2># &pi;-Stacking</th>",S+="<th>Hydrogen Bond (backbone atoms: @CA, @N, @C, @O)</th><th>Salt Bridge/Ionic Interaction</th><th>Contact</th>",S+="<th>Halogen Bond</th><th>&pi;-Cation</th><th>&pi;-Stacking</th></tr>",S+="<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>';S+=e,S+=e,S+='<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>',S+=e,S+=e,S+=e,S+="</tr>",S+="</thead><tbody>",S+=o,S+="</tbody></table><br/>"}return{html:S,bondCnt:i}}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){let i=this.icn3d;i.icn3dui;let n="",l=0,r=' <span style="background-color:#',o='">&nbsp;&nbsp;&nbsp;</span>';if(void 0!==e)for(let a in e){let d=a.split(","),c="save1"==t?d[0]:d[1],h="save1"==t?d[1]:d[0],p=i.getGraphCls.convertLabel2Resid(c),m=i.firstAtomObjCls.getFirstAtomObj(i.residues[p]),u=m.color?m.color.getHexString():"",g=i.getGraphCls.convertLabel2Resid(h),f=i.firstAtomObjCls.getFirstAtomObj(i.residues[g]),C=f.color?f.color.getHexString():"",b=Math.sqrt(e[a]).toFixed(1);n+='<tr><td><span style="white-space:nowrap"><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+s+"2_"+l+'a" resid="'+c+'"/> '+c+r+u+o+'</span></td><td><span style="white-space:nowrap"><input type="checkbox" class="'+i.pre+'seloneres" id="'+i.pre+s+"2_"+l+'b" resid="'+h+'"/> '+h+r+C+o+'</span></td><td align="center">'+b+"</td>",n+='<td align="center"><button class="'+i.pre+'selres" resid="'+c+"|"+h+'">Highlight</button></td>',n+="</tr>",++l}return{html:n,cnt:l}}getContactPairDetails(e,t){let s=this.icn3d;s.icn3dui;let i="",n=0,l=' <span style="background-color:#',r='">&nbsp;&nbsp;&nbsp;</span>';if(void 0!==e)for(let o in e){let a=o.split(","),d="save1"==t?a[0]:a[1],c="save1"==t?a[1]:a[0],h=s.getGraphCls.convertLabel2Resid(d),p=s.firstAtomObjCls.getFirstAtomObj(s.residues[h]),m=p.color?p.color.getHexString():"",u=s.getGraphCls.convertLabel2Resid(c),g=s.firstAtomObjCls.getFirstAtomObj(s.residues[u]),f=g.color?g.color.getHexString():"",C=e[o].split("_"),b=C[0],y=C[1],v=C[2],_=C[3],w=C[4];i+='<tr><td><span style="white-space:nowrap"><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"inter2_"+n+'a" resid="'+d+'"/> '+d+"@"+v+l+m+r+'</span></td><td><span style="white-space:nowrap"><input type="checkbox" class="'+s.pre+'seloneres" id="'+s.pre+"inter2_"+n+'b" resid="'+c+'"/> '+c+"@"+_+l+f+r+'</span></td><td align="center">'+w+'</td><td align="center">'+b+'</td><td align="center">'+y+"</td>",i+='<td align="center"><button class="'+s.pre+'selres" resid="'+d+"|"+c+'">Highlight</button></td>',i+="</tr>",n+=parseInt(w)}return{html:i,cnt:n}}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 Bt{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 $t{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=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);for(let e in r.pdbChainIndexHash){let t=r.pdbChainIndexHash[e].split("_");l=t[0],t[1],n=t[2],t[3],a.transformStructure(l,e-1,"query")}let e=[],t=[],c=[],h=o.htmlCls.baseUrl+"vastdyn/vastdyn.cgi",p=o.htmlCls.baseUrl+"tmalign/tmalign.cgi";for(let s in r.afChainIndexHash){let i=r.afChainIndexHash[s].split("_");l=i[0];let a=i[1];n=i[2];let d,m=i[3];if("tmalign"!=o.cfg.aligntool){let e={domains1:r.domain3dCls.getDomainJsonForAlign(r.chains[l+"_"+a]),domains2:r.domain3dCls.getDomainJsonForAlign(r.chains[n+"_"+m])};d=o.getAjaxPostPromise(h,e)}else{let e={pdb_query:r.saveFileCls.getAtomPDB(r.chains[l+"_"+a]),pdb_target:r.saveFileCls.getAtomPDB(r.chains[n+"_"+m])};d=o.getAjaxPostPromise(p,e)}e.push(d),t.push(s-1),c.push(l)}let m=Promise.allSettled(e),u=await m;await a.downloadChainalignmentPart2b(s,i,d,u,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}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?void(i.bRender&&alert("These structures can NOT be aligned...")):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];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)||(m[s]=1,u[e]=r[e],d="target",this.transformStructure(t,l,d),d="query",this.transformStructure(s,l,d),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,t,s){let i=this.icn3d,n=i.icn3dui;i.opts.proteins="c alpha trace";let l=e.split(","),r=n.cfg.domainids?n.cfg.domainids.split(","):[];r.length<l.length&&(r=[]),i.chainidArray=this.addPostfixForChainids(l);let o=l[0].indexOf("_");i.mmdbid_t=l[0].substr(0,o).toUpperCase(),i.chain_t=l[0].substr(o+1);let a,d,c=[];i.mmdbid_t.length>5?(d="https://alphafold.ebi.ac.uk/files/AF-"+i.mmdbid_t+"-F1-model_"+i.AFUniprotVersion+".pdb",a=n.getAjaxPromise(d,"text")):(d=n.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+n.cfg.bu+"&uid="+i.mmdbid_t,void 0!==n.cfg.inpara&&(d+=n.cfg.inpara),a=n.getAjaxPromise(d,"jsonp")),c.push(a),i.ParserUtilsCls.setYourNote(e.toUpperCase()+" in iCn3D"),i.pdbid_chain2title={},void 0===i.chainids2resids&&(i.chainids2resids={}),i.afChainIndexHash={},i.pdbChainIndexHash={};for(let e=1,t=l.length;e<t;++e){let t,s,r=l[e].indexOf("_"),o=l[e].substr(0,r).toUpperCase();i.mmdbid_q=5==o.length?o.substr(0,4):o,i.chain_q=l[e].substr(r+1),i.mmdbid_q.length>5?(t="https://alphafold.ebi.ac.uk/files/AF-"+i.mmdbid_q+"-F1-model_"+i.AFUniprotVersion+".pdb",s=n.getAjaxPromise(t,"text")):(t=n.htmlCls.baseUrl+"mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu="+n.cfg.bu+"&uid="+i.mmdbid_q,void 0!==n.cfg.inpara&&(t+=n.cfg.inpara),s=n.getAjaxPromise(t,"jsonp")),c.push(s)}for(let e=1,t=l.length;e<t;++e){let t=l[e].indexOf("_"),s=l[e].substr(0,t).toUpperCase();if(i.mmdbid_q=5==s.length?s.substr(0,4):s,i.chain_q=l[e].substr(t+1),!n.cfg.resnum&&!n.cfg.resdef){let t=i.mmdbid_q+"_"+i.chain_q+","+i.mmdbid_t+"_"+i.chain_t,l=r.length>0?r[e]+","+r[0]:void 0;if("tmalign"!=n.cfg.aligntool&&4==i.mmdbid_t.length&&4==i.mmdbid_q.length){let o;o=r.length>0?n.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?domainpairs="+l:n.htmlCls.baseUrl+"vastdyn/vastdyn.cgi?chainpairs="+t;let a=n.getAjaxPromise(o,"jsonp");c.push(a),i.pdbChainIndexHash[e]=s+"_"+i.chain_q+"_"+i.mmdbid_t+"_"+i.chain_t}else i.afChainIndexHash[e]=i.mmdbid_q+"_"+i.chain_q+"_"+i.mmdbid_t+"_"+i.chain_t}}let h=Promise.allSettled(c),p=await h;await this.parseChainAlignData(p,l,i.mmdbid_t,i.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((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(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="alignment RMSD: "+s.toPrecision(4);"tmalign"==o.cfg.aligntool&&(i+="; TM-score: "+e[0].score.toPrecision(4)),o.htmlCls.clickMenuCls.setLogCmd(i,!1);let n="<br><b>Alignment RMSD</b>: "+s.toPrecision(4)+" &#8491;<br>";"tmalign"==o.cfg.aligntool&&(n+="<b>TM-score</b>: "+e[0].score.toPrecision(4)+"<br><br>",r.tmscore=e[0].score.toPrecision(4)),$("#"+r.pre+"dl_rmsd_html").html(n),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)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={},a={},d=!1,c={};c.color=t.length>1?"structure":t[0].length>5?"confidence":"chain";for(let e=0,i=t.length;e<i;++e){let i,c;if(e==t.length-1&&(d=!0),0!=e||s||n.structArray.length!=t.length?(i="query",c=!0):(i="target",c=!1),isNaN(t[e])&&t[e].length>5){let s=!1;a=await n.pdbParserCls.loadPdbData(r[e],t[e],!1,c,i,d,s)}else{let s=!0,l=t[e];a=await n.mmdbParserCls.parseMmdbData(r[e],i,void 0,void 0,d,s,l)}o=l.hashUtilsCls.unionHash(o,a)}if(n.setColorCls.setColorByOptions(c,o),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){let e=!0,t=!0;await n.realignParserCls.realignChainOnSeqAlign(void 0,n.chainidArray,e,t),$("#"+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),void 0!==s.emd?($("#"+s.pre+"mapWrapper1").hide(),$("#"+s.pre+"mapWrapper2").hide(),$("#"+s.pre+"mapWrapper3").hide()):($("#"+s.pre+"emmapWrapper1").hide(),$("#"+s.pre+"emmapWrapper2").hide(),$("#"+s.pre+"emmapWrapper3").hide()),await s.opmParserCls.loadOpmData(e,t,void 0,"mmcif")}}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;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));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();(parseInt(i.cfg.date)>=20231001||!i.cfg.date&&parseInt(i.utilsCls.getDateDigitStr())>=20231001)&&(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(0),s=e.getColumn("database_code").getString(0);if("EMDB"==t){c=s;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.getCategory("_atom_site"),M={},F={id:""},H="",L={},N={},q="",U=D.rowCount,B=1,$=!(10*U>n.maxatomcnt),j=[];if(!i){_=D.getColumn("group_PDB"),w=D.getColumn("label_comp_id"),S=D.getColumn("type_symbol"),A=D.getColumn("label_atom_id"),x=D.getColumn("auth_asym_id"),k=D.getColumn("label_seq_id"),O=D.getColumn("auth_seq_id"),R=D.getColumn("label_alt_id"),I=D.getColumn("B_iso_or_equiv"),E=D.getColumn("Cartn_x"),T=D.getColumn("Cartn_y"),P=D.getColumn("Cartn_z"),j=D.getColumn("label_asym_id");let e={},t="";for(let s=0;s<U;++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=j.getString(s);if(c=h,"ATOM"==n?i=3==r.length?"p":"n":"WAT"==r||"HOH"==r?(i="s",d="Misc"):(i="l",d=r),!$&&("p"==i&&("C"!=o||"CA"!=a)||"n"==i&&"P"!=a))continue;if("B"==p)continue;if(N[d]=1,"?"!=c&&"."!=c&&"0"!=c||(c=h),"s"==i||"l"==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==q&&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=B.toString();M[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!=H||t!=m)L={},L[v]={},L[v][y.id]=y;else{for(let e in L[v])this.hasCovalentBond(y,L[v][e],I)&&(C.hasOwnProperty(y.id)||(C[y.id]={}),C.hasOwnProperty(L[v][e].id)||(C[L[v][e].id]={}),C[y.id][L[v][e].id]=1,C[L[v][e].id][y.id]=1);L[v][y.id]=y}"N"==a&&""!=F.id&&this.hasCovalentBond(y,F,I)&&(C.hasOwnProperty(y.id)||(C[y.id]={}),C.hasOwnProperty(F.id)||(C[F.id]={}),C[y.id][F.id]=1,C[F.id][y.id]=1),"C"==a&&(F=y),H=v,q=d+"_"+r,t=m,++B}for(let e=0;e<b.length;e+=2){let t=M[b[e]],s=M[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',q="",B=1;let e=D.getColumn("pdbx_PDB_model_num").getString(0);e="1"==e?t:t+e;for(let t=0;t<U;++t){let s,i=_.getString(t),n=w.getString(t),l=S.getString(t),o=A.getString(t),a=x.getString(t),d=k.getString(t),c=O.getString(t),h=R.getString(t),p=j.getString(t);if(d=c,"ATOM"==i?s=3==n.length?"p":"n":"WAT"==n||"HOH"==n?(s="s",a="Misc"):(s="l",a=n),!$&&("p"==s&&("C"!=l||"CA"!=o)||"n"==s&&"P"!=o))continue;if("B"==h)continue;"?"!=d&&"."!=d&&"0"!=d||(d=c);let m=I.getString(t),b=E.getFloat(t),y=T.getFloat(t),v=P.getFloat(t),D=B.toString(),M=a+"_"+d;r+="{",r+='"het":'+("HETATM"==i?"1":"0")+", ",r+='"serial":'+B+", ",r+='"name":"'+o+'", ',r+='"resn":"'+n+'", ',r+='"structure":"'+e+'", ',r+='"chain":"'+a+'", ',r+='"resi":'+d+", ",r+='"coord":{"x":'+b+', "y":'+y+', "z":'+v+"}, ",r+='"b":"'+m+'", ',r+='"elem":"'+l+'", ',r+='"bonds":[';let F={};C.hasOwnProperty(D)&&(F=C[D]);let H=Object.keys(F);for(let e=0,t=H.length;e<t;++e)"undefined"!==H[e]&&(r+=H[e],r+=", ");if(H.length>0&&(r=r.substr(0,r.length-2)),r+="], ",f.hasOwnProperty(M)){r+='"ss":"'+f[M]+'", '}else r+='"ss":"coil", ';u.hasOwnProperty(M)?r+='"ssbegin":1, ':r+='"ssbegin":0, ',g.hasOwnProperty(M)?r+='"ssend":1, ':r+='"ssend":0, ',r+='"mt":"'+s+'"',r+="}",r+=",\n",q=a+"_"+n,prevAutochain=p,++B}B>1&&(r=r.substr(0,r.length-2)),r+="]"}_=w=S=A=x=k=O=R=I=E=T=P=j=[];let z={};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+="]",z[r]=o),o="["),o+="["+a+', "'+d+'"]',e<l-1&&(o+=", "),r=c}o+="]",z[r]=o,t=s=i=n=[]}r+=', "sequences":{';let G=!1;for(let e in N){let t;t=ligSeqHash.hasOwnProperty(e)?"["+ligSeqHash[e]+"]":z[e],""!==t&&void 0!==t&&(r+='"'+e+'": '+t+", ",G=!0)}if(G&&(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}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),void 0!==r.emd?($("#"+r.pre+"mapWrapper1").hide(),$("#"+r.pre+"mapWrapper2").hide(),$("#"+r.pre+"mapWrapper3").hide()):($("#"+r.pre+"emmapWrapper1").hide(),$("#"+r.pre+"emmapWrapper2").hide(),$("#"+r.pre+"emmapWrapper3").hide()),1==Object.keys(r.structures).length&&$("#"+r.pre+"alternateWrapper").hide(),void 0!==r.biomtMatrices&&r.biomtMatrices.length>1&&($("#"+r.pre+"assemblyWrapper").show(),r.asuCnt=r.biomtMatrices.length),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);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=a.loadPDBCls.loadPDB(e,t,s,void 0,void 0,i,n,o);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()));let h=!1;return a.bSecondaryStructure&&1==Object.keys(a.structures).length?h=!1:d.cfg.mmtfid||d.cfg.pdbid||d.cfg.opmid||d.cfg.mmdbid||d.cfg.gi||d.cfg.uniprotid||d.cfg.blast_rep_id||d.cfg.cid||d.cfg.mmcifid||d.cfg.align||d.cfg.chainalign||(h=!0),(!a.bSecondaryStructure||h)&&Object.keys(a.proteins).length>0&&!r?await this.applyCommandDssp(i):(await this.loadPdbDataRender(i),d.bNode||await a.ParserUtilsCls.checkMemProteinAndRotate()),c}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;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")}}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 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=e+1,p=d.length;h<p;++h){let e=d[h],p=Object.keys(n[e]);if(0!=p.length)for(let d=0,h=c.length;d<h;++d){let h=c[d],m=t.domain3dCls.getDomainJsonForAlign(n[i][h]);for(let d=0,c=p.length;d<c;++d){let c,u=p[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][h],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(h+","+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,l,r,o,a,d,c=this.icn3d,h=c.icn3dui,p=this,m={},u={},g={},f=[],C=h.htmlCls.baseUrl+"pwaln/pwaln.fcgi?from=chainalign";if(i&&(r=h.cfg.resdef.trim().replace(/\+/gi," ").split(": "),r.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&&(n=v);let _=v+t[e].substr(y);if(0==e&&(l=_),c.chainsSeq&&c.chainsSeq[_])if(m.hasOwnProperty(_)||i||(m[_]="",u[_]=[],g[_]=[]),i)if(0==e);else{let t={};o=r[e-1].split(" | ");let s=l+","+_;m[s]||(m[s]={}),u[s]||(u[s]={}),g[s]||(g[s]={}),d=o[0].split(","),a=p.getSeqCoorResid(d,l),t=h.hashUtilsCls.unionHash(t,a.hAtoms),m[s][n]||(m[s][n]=""),u[s][n]||(u[s][n]=[]),g[s][n]||(g[s][n]=[]),m[s][n]+=a.seq,u[s][n]=u[s][n].concat(a.coor),g[s][n]=g[s][n].concat(a.resid),d=o[1].split(","),a=p.getSeqCoorResid(d,_),t=h.hashUtilsCls.unionHash(t,a.hAtoms),m[s][v]||(m[s][v]=""),u[s][v]||(u[s][v]=[]),g[s][v]||(g[s][v]=[]),m[s][v]+=a.seq,u[s][v]=u[s][v].concat(a.coor),g[s][v]=g[s][v].concat(a.resid)}else if(0==e){if(d=[],s){let e=c.firstAtomObjCls.getResiduesFromAtoms(c.hAtoms);for(var b in e){let e=b.substr(b.lastIndexOf("_")+1);b.substr(0,b.lastIndexOf("_"))==_&&d.push(e)}}else h.cfg.resnum&&(d=h.cfg.resnum.split(","));a=p.getSeqCoorResid(d,_),m[_]+=a.seq,u[_]=u[_].concat(a.coor),g[_]=g[_].concat(a.resid)}else{let e=!1;if(s){let t=c.firstAtomObjCls.getResiduesFromAtoms(c.hAtoms);for(var b in t){if(b.substr(0,b.lastIndexOf("_"))==_){e=!0;let t=c.firstAtomObjCls.getFirstAtomObj(c.residues[b]).resn;m[_]+=h.utilsCls.residueName2Abbr(t),u[_]=u[_].concat(this.getResCoorArray(b)),g[_].push(b)}}}if(!e)for(let e=0,t=c.chainsSeq[_].length;e<t;++e){m[_]+=c.chainsSeq[_][e].name;let t=_+"_"+c.chainsSeq[_][e].resi;u[_]=u[_].concat(this.getResCoorArray(t)),g[_].push(t)}let t={targets:m[l],queries:m[_]},i=h.getAjaxPostPromise(C,t);f.push(i)}}if(i)await p.parseChainRealignPredefined(t,m,u,g);else{let i=Promise.allSettled(f);try{let n=await i;await p.parseChainRealignData(n,e,t,m,u,g,s)}catch(e){return void alert("The realignment did not work...")}}}}getSeqCoorResid(e,t){let s=this.icn3d,i=s.icn3dui,n="",l=[],r=[],o={};for(let o=0,a=e.length;o<a;++o)if(-1!=e[o].indexOf("-")){let a=e[o].split("-");for(let e=parseInt(a[0]);e<=parseInt(a[1]);++e){let o=s.setSeqAlignCls.getPosFromResi(t,e);s.chainsSeq[t]&&s.chainsSeq[t][o]&&-1!=i.parasCls.b62ResArray.indexOf(s.chainsSeq[t][o].name.toUpperCase())&&(n+=s.chainsSeq[t][o].name.toUpperCase(),l=l.concat(this.getResCoorArray(t+"_"+e)),r.push(t+"_"+e))}}else{let i=e[o],a=s.setSeqAlignCls.getPosFromResi(t,i);if(!s.chainsSeq[t][a])continue;let d=this.getResCoorArray(t+"_"+i);n+=s.chainsSeq[t][a].name.toUpperCase(),l=l.concat(d),r.push(t+"_"+i)}for(let e=0,t=r.length;e<t;++e)o=i.hashUtilsCls.unionHash(o,s.residues[r[e]]);return{seq:n,coor:l,resid:r,hAtoms:o}}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?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))}}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,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();(parseInt(c.cfg.date)>=20231001||!c.cfg.date&&parseInt(c.utilsCls.getDateDigitStr())>=20231001)&&(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,h=e.moleculeInfor[t].sid;if(g[r]=o,f[r]=a,"protein"==o&&(d.organism=e.moleculeInfor[t].taxonomyName.toLowerCase()),void 0!==h&&(d.chainid2sid[r]=h),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(),(parseInt(c.cfg.date)>=20231001||!c.cfg.date&&parseInt(c.utilsCls.getDateDigitStr())>=20231001)&&(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=void 0===c.cfg.mmcifid&&void 0===c.cfg.mmtfid&&void 0===c.cfg.bcifid&&"mmcif"!=d.InputfileType,a=o?"protein"===g[O]:"p"===n.mt,u=o?"nucleotide"===g[O]:"n"===n.mt,N=o?"solvent"===g[O]:"s"===n.mt,q=o?"ligand"===g[O]||void 0!==g[O]&&-1!==g[O].indexOf("other")||void 0===g[O]:"l"===n.mt;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"),a||u?(a?(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)):u&&(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):N?(d.water[p]=1,n.het=!0):q&&("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 U=n.structure+"_"+n.chain;void 0===d.chains[U]&&(d.chains[U]={}),d.chains[U][p]=1;let B=U+"_"+n.resi;void 0===d.residues[B]&&(d.residues[B]={}),d.residues[B][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[B]=r;let $="-";if("helix"===n.ss?$="H":"sheet"===n.ss?$="E":n.het||u?$="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[U]&&(d.chainsSeq[U]=[],P=!1),!isNaN(n.resi)&&null!==n.resi))if(P&&!D&&void 0!==d.chainsSeq[U][n.resi-1])d.chainsSeq[U][n.resi-1].name=r;else if(!P||!d.chainsSeq[U].hasOwnProperty(n.resi-1)){let e={};e.resi=n.resi,e.name=r,n.resi%10==0&&n.resi.toString(),d.chainsSeq[U].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)"mmdbid"===s&&"target"===n&&(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;if(t&&"tmalign"==l.cfg.aligntool)i=s;else if(n.posid2resid){let t=n.posid2resid[e+"_"+s];i=t.substr(t.lastIndexOf("_")+1)}else i=n.chainsSeq[e][s].resi;return 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){let i=this.icn3d;i.icn3dui;let n=e;return(e==i.defaultPdbId||s||i.structures.hasOwnProperty(e))&&(n=1===t?e:e+t.toString()),n}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),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="",q=!1,U=!0;for(let e in u){let r=u[e],B=r.substr(0,6);if("HEADER"!==B||q||t)if("TITLE "===B){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[L]=c.molTitle}else if("HELIX "===B){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=L+"_"+e+"_"+i;I.push(n),i===t&&E.push(n),i===s&&T.push(n)}}else if("SHEET "===B){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=L+"_"+e+"_"+s;k.push(n),s===t&&O.push(n),s===i&&R.push(n)}}else if("HBOND "===B)void 0!==s&&s||(c.bSecondaryStructure=!0);else if("SSBOND"===B){c.bSsbondProvided=!0;let e=L+"_"+(" "==r.substr(15,1)?"A":r.substr(15,1))+"_"+r.substr(17,4).trim(),t=L+"_"+(" "==r.substr(29,1)?"A":r.substr(29,1))+"_"+r.substr(31,4).trim();void 0===c.ssbondpnts[L]&&(c.ssbondpnts[L]=[]),c.ssbondpnts[L].push(e),c.ssbondpnts[L].push(t)}else if("REMARK"===B){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);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(),""!=N&&t==N&&t!=N||(c.chainMissingResidueArray[i].push(n),N=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"===B&&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"===B)++d,H=c.defaultPdbId,L=this.getStructureId(H,d,n),m||(k=[],O=[],R=[],I=[],E=[],T=[]),q=!1;else if("JRNL "===B)"PMID"===r.substr(12,4)&&(c.pmid=r.substr(19).trim());else if("ATOM "===B||"HETATM"===B){A=r.substr(72,4).trim(),U?(L=this.getStructureId(H,d,n),U=!1):A!=x&&(++d,H=c.defaultPdbId,L=this.getStructureId(H,d,n),m||(k=[],O=[],R=[],I=[],E=[],T=[]),q=!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),N=r.substr(20,2).trim();""===N&&(N="A");let $=r.substr(22,5).trim(),j=$;if(s&&"DUM"===u&&(t=l,N="MEM",j=1,$=1),i&&"DUM"===u)break;C=L+"_"+N,y=C+"_"+$,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"===B[0],serial:a,name:l,alt:e,resn:u,structure:L,chain:N,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[L.toString()]&&(c.structures[L.toString()]=[]),c.structures[L.toString()].includes(C)||c.structures[L.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"===B){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 B.substr(0,3);else H=r.substr(62).trim(),""==H&&(H=l?c.defaultPdbId:c.inputid&&-1==c.inputid.indexOf("/")?c.inputid.substr(0,10):c.defaultPdbId),L=this.getStructureId(H,d,n),c.molTitle="",c.molTitleHash={},q=!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),this.adjustSeq(c.chainMissingResidueArray);let B=Object.keys(c.structures);for(let e=0,t=B.length;e<t;++e){let t=B[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 j,z,G=[],V=new THREE.Vector3(9999,9999,9999),W=new THREE.Vector3(-9999,-9999,-9999),Y=new THREE.Vector3,X=0,K={},J=[];for(let e in c.hAtoms){let t=c.atoms[e],s=t.coord;Y.add(s),V.min(s),W.max(s),++X,1==X&&(j=t.chain,z=t.resi,J.push(t)),t.het?t.het&&("HOH"===t.resn||"WAT"===t.resn||"SOL"===t.resn?c.water[t.serial]=1:-1!==$.inArray(t.resn,h.parasCls.ionsArray)||t.elem.trim()===t.resn.trim()?c.ions[t.serial]=1:c.chemicals[t.serial]=1,t.color=h.parasCls.atomColors[t.elem]):-1!==$.inArray(t.resn,h.parasCls.nucleotidesArray)?(c.nucleotides[t.serial]=1,"O3'"!==t.name&&"O3*"!==t.name||(c.nucleotidesO3[t.serial]=1,c.secondaries[t.structure+"_"+t.chain+"_"+t.resi]="o"),-1===h.parasCls.nuclMainArray.indexOf(t.name)&&(c.ntbase[t.serial]=1)):("P"===t.elem&&(K[t.structure+"_"+t.chain+"_"+t.resi]=1),c.proteins[t.serial]=1,"CA"===t.name&&(c.calphas[t.serial]=1),"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&(c.sidec[t.serial]=1)),j===t.chain&&z===t.resi||(this.refreshBonds(G,J[0]),J.splice(0,1),j=t.chain,z=t.resi,G.length=0),G.push(t),"C"!==t.name&&"O3'"!==t.name||J.push(t)}this.refreshBonds(G,J[0]);for(let e in K){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=V,c.pmax=W,c.cnt=X,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=this.icn3d,l=n.icn3dui,r={},o=s?CIFTools.Text.parse(e):CIFTools.Binary.parse(e);if(o.isError)return void alert("The Binary CIF data can NOT be parsed: "+o.toString());let a,d,c=o.result.dataBlocks[0],h=!1,p={},m={};n.atoms||(i=!1),i?(n.oriNStru=n.structures?Object.keys(n.structures).length:0,d=n.oriNStru+1,a=n.atoms?Object.keys(n.atoms).length:0):(n.init(),d=1,a=0);let u,g,f,C=[],b=[],y=[],v=[],_=[],w=[],S="",A="",x="",k=t||n.defaultPdbId,O=k,R=!0;if(c.getCategory("_entry")&&(k=c.getCategory("_entry").getColumn("id").getString(0),""==k&&(k=i?n.defaultPdbId:n.inputid&&-1==n.inputid.indexOf("/")?n.inputid.substr(0,10):n.defaultPdbId),O=n.loadPDBCls.getStructureId(k,d),n.molTitle="",n.molTitleHash={}),c.getCategory("_struct")){let e=c.getCategory("_struct").getColumn("title").getString(0);e=e.replace(/"/,"'");let t=e.replace(/ALPHAFOLD MONOMER V2.0 PREDICTION FOR /gi,"");n.molTitle+=t.trim()+" ",n.molTitleHash||(n.molTitleHash={}),n.molTitleHash[O]=n.molTitle}if(c.getCategory("_entity_src_gen")&&(n.organism=c.getCategory("_entity_src_gen").getColumn("gene_src_common_name").getString(0)),c.getCategory("_database_2")){let e=c.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){n.emd=s;break}}}if(c.getCategory("_struct_conf")){n.bSecondaryStructure=!0;let e=c.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 l=e.getColumn("end_auth_seq_id"),r=e.rowCount;for(let e=0;e<r;++e){let n=t.getString(e),r=s.getString(e),o=parseInt(i.getString(e)),a=parseInt(l.getString(e));if("HELX"==n.substr(0,4))for(let e=parseInt(o);e<=parseInt(a);++e){let t=O+"_"+r+"_"+e;v.push(t),e==o&&_.push(t),e==a&&w.push(t)}else if("STRN"==n.substr(0,4))for(let e=o;e<=a;++e){let t=O+"_"+r+"_"+e;C.push(t),e==o&&b.push(t),e==a&&y.push(t)}}t=s=i=l=[]}if(c.getCategory("_struct_sheet_range")){let e=c.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=O+"_"+n+"_"+e;C.push(t),e==l&&b.push(t),e==r&&y.push(t)}}t=s=i=[]}if(c.getCategory("_struct_conn")){n.bSsbondProvided=!0;let e=c.getCategory("_struct_conn"),t=e.getColumn("conn_type_id"),s=e.getColumn("ptnr1_auth_asym_id"),i=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=t.getString(e),c=s.getString(e);i.getString(e);let h=O+"_"+c+"_"+l.getString(e),p=r.getString(e);o.getString(e);let m=O+"_"+p+"_"+a.getString(e);"disulf"==d&&(void 0===n.ssbondpnts[O]&&(n.ssbondpnts[O]=[]),n.ssbondpnts[O].push(h),n.ssbondpnts[O].push(m))}t=s=i=l=r=o=a=[]}if(c.getCategory("_exptl")){-1!=c.getCategory("_exptl").getColumn("method").getString(0).indexOf("NMR")&&(h=!0)}if(c.getCategory("_pdbx_struct_oper_list")){let e=c.getCategory("_pdbx_struct_oper_list"),t=e.getColumn("id"),s=e.getColumn("matrix[1][1]"),i=e.getColumn("matrix[1][2]"),l=e.getColumn("matrix[1][3]"),r=e.getColumn("vector[1]"),o=e.getColumn("matrix[2][1]"),a=e.getColumn("matrix[2][2]"),d=e.getColumn("matrix[2][3]"),h=e.getColumn("vector[2]"),p=e.getColumn("matrix[3][1]"),m=e.getColumn("matrix[3][2]"),u=e.getColumn("matrix[3][3]"),g=e.getColumn("vector[3]"),f=e.rowCount;for(let e=0;e<f;++e){"X0"!=t.getString(e)&&(null==n.biomtMatrices[e]&&(n.biomtMatrices[e]=(new THREE.Matrix4).identity()),n.biomtMatrices[e].set(s.getString(e),i.getString(e),l.getString(e),r.getString(e),o.getString(e),a.getString(e),d.getString(e),h.getString(e),p.getString(e),m.getString(e),u.getString(e),g.getString(e),0,0,0,1))}t=s=i=l=r=o=a=d=h=p=m=u=g=[]}c.getCategory("_citation")&&(n.pmid=c.getCategory("_citation").getColumn("pdbx_database_id_PubMed").getString(0));let I=c.getCategory("_atom_site"),E=I.rowCount,T=!(E>n.maxatomcnt);T||(n.opts.proteins="c alpha trace",n.opts.nucleotides="o3 trace");let P,D=I.getColumn("group_PDB"),M=I.getColumn("label_comp_id"),F=I.getColumn("type_symbol"),H=I.getColumn("label_atom_id"),L=I.getColumn("auth_asym_id"),N=I.getColumn("label_seq_id"),q=I.getColumn("auth_seq_id"),U=I.getColumn("label_alt_id"),B=I.getColumn("B_iso_or_equiv"),j=I.getColumn("Cartn_x"),z=I.getColumn("Cartn_y"),G=I.getColumn("Cartn_z"),V=I.getColumn("label_asym_id"),W={},Y="",X={};for(let e=0;e<E;++e){let t,s=D.getString(e),i=M.getString(e),o=F.getString(e),c=H.getString(e),I=L.getString(e),E=N.getString(e),$=q.getString(e),K=U.getString(e),J=B.getString(e),Z=V.getString(e);if(E=$,"ATOM"==s?t=3==i.length?"p":"n":"WAT"==i||"HOH"==i?(t="s",I="Misc"):(t="l",I=i),""===I&&(I="A"),!T&&("p"==t&&("C"!=o||"CA"!=c)||"n"==t&&"P"!=c))continue;if("B"==K)continue;if(X[I]=1,R&&(O=n.loadPDBCls.getStructureId(k,d),R=!1),++a,"?"!=E&&"."!=E&&"0"!=E||(E=$),"s"==t||"l"==t){let e={};W.hasOwnProperty(I)||(W[I]=[]),3!=i.length||"HOH"==i||"WAT"==i?3==i.length&&("O"!=o||"HOH"!=i&&"WAT"!=i)||(e.resi=E,e.name=l.utilsCls.residueName2Abbr(i),W[I].push(e)):I+"_"+i==P&&Y==Z||(e.resi=E,e.name=l.utilsCls.residueName2Abbr(i),W[I].push(e))}u=O+"_"+I,f=u+"_"+$,g=u+"_"+E;let Q=j.getFloat(e),ee=z.getFloat(e),te=G.getFloat(e),se={het:"HETATM"==s,serial:a,name:c,alt:K,resn:i,structure:O,chain:I,resi:E,coord:new THREE.Vector3(Q,ee,te),b:J,elem:o,bonds:[],ss:"coil",ssbegin:!1,ssend:!1};!se.het&&se.name,!se.het&&se.name,n.atoms[a]=se,n.dAtoms[a]=1,n.hAtoms[a]=1,r[a]=1,n.loadPDBCls.isSecondary(g,C,h,!T)?(n.atoms[a].ss="sheet",n.loadPDBCls.isSecondary(g,b,h,!T)&&(n.atoms[a].ssbegin=!0),n.loadPDBCls.isSecondary(g,y,h,!T)&&(n.atoms[a].ssend=!0)):n.loadPDBCls.isSecondary(g,v,h,!T)&&(n.atoms[a].ss="helix",n.loadPDBCls.isSecondary(g,_,h,!T)&&(n.atoms[a].ssbegin=!0),n.loadPDBCls.isSecondary(g,w,h,!T)&&(n.atoms[a].ssend=!0));let ie="-";if(ie="helix"===n.atoms[a].ss?"H":"sheet"===n.atoms[a].ss?"E":!n.atoms[a].het&&l.parasCls.residueColors.hasOwnProperty(n.atoms[a].resn.toUpperCase())?"c":"o",n.secondaries[g]=ie,f!==x||I+"_"+i!=P||Y!=Z){let e=l.utilsCls.residueName2Abbr(i);if(n.residueId2Name[g]=e,1!==a&&""!==A&&(n.residues[A]=m),g!==A&&(m={}),u!==S){1!==a&&""!==S&&(void 0===n.chains[S]&&(n.chains[S]={}),n.chains[S]=l.hashUtilsCls.unionHash(n.chains[S],p)),p={},void 0===n.structures[O.toString()]&&(n.structures[O.toString()]=[]),n.structures[O.toString()].includes(u)||n.structures[O.toString()].push(u),void 0===n.chainsSeq[u]&&(n.chainsSeq[u]=[]);let t={};t.resi=E,t.name=e,n.chainsSeq[u].push(t)}else{let t={};t.resi=E,t.name=e,n.chainsSeq[u].push(t)}}p[a]=1,m[a]=1,S=u,A=g,x=f,P=I+"_"+i,Y=Z}n.residues[g]=m,void 0===n.chains[u]&&(n.chains[u]={}),n.chains[u]=l.hashUtilsCls.unionHash2Atoms(n.chains[u],p,n.atoms),D=M=F=H=L=N=q=U=B=j=z=G=V=[];let K={};if(c.getCategory("_pdbx_poly_seq_scheme")){let e=c.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"),r=e.rowCount,o="",a=[];for(let e=0;e<r;++e){t.getString(e);let r=s.getString(e),d=i.getString(e),c=n.getString(e);c!=o&&e>0&&(K[o]=a,a=[]),a.push({resi:r,name:l.utilsCls.residueName2Abbr(d)}),o=c}K[o]=a,t=s=i=n=[]}this.setSeq(O,X,K,W);let J=Object.keys(n.structures);for(let e=0,t=J.length;e<t;++e){let t=J[e];if(t!=k&&(void 0===n.ssbondpnts[t]&&(n.ssbondpnts[t]=[]),void 0!==n.ssbondpnts[k]))for(let e=0,s=n.ssbondpnts[k].length;e<s;++e){let s=n.ssbondpnts[k][e],i=s.indexOf("_"),l=t+s.substr(i);n.ssbondpnts[t].push(l)}}n.bSsbondProvided||n.loadPDBCls.setSsbond();let Z,Q,ee=[],te=new THREE.Vector3(9999,9999,9999),se=new THREE.Vector3(-9999,-9999,-9999),ie=new THREE.Vector3,ne=0,le={},re=[];for(let e in n.hAtoms){let t=n.atoms[e],s=t.coord;ie.add(s),te.min(s),se.max(s),++ne,1==ne&&(Z=t.chain,Q=t.resi,re.push(t)),t.het?t.het&&("HOH"===t.resn||"WAT"===t.resn||"SOL"===t.resn?n.water[t.serial]=1:-1!==$.inArray(t.resn,l.parasCls.ionsArray)||t.elem.trim()===t.resn.trim()?n.ions[t.serial]=1:n.chemicals[t.serial]=1,t.color=l.parasCls.atomColors[t.elem]):-1!==$.inArray(t.resn,l.parasCls.nucleotidesArray)?(n.nucleotides[t.serial]=1,"O3'"!==t.name&&"O3*"!==t.name||(n.nucleotidesO3[t.serial]=1,n.secondaries[t.structure+"_"+t.chain+"_"+t.resi]="o"),-1===l.parasCls.nuclMainArray.indexOf(t.name)&&(n.ntbase[t.serial]=1)):("P"===t.elem&&(le[t.structure+"_"+t.chain+"_"+t.resi]=1),n.proteins[t.serial]=1,"CA"===t.name&&(n.calphas[t.serial]=1),"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&(n.sidec[t.serial]=1)),Z===t.chain&&Q===t.resi||(n.loadPDBCls.refreshBonds(ee,re[0]),re.splice(0,1),Z=t.chain,Q=t.resi,ee.length=0),ee.push(t),"C"!==t.name&&"O3'"!==t.name||re.push(t)}n.loadPDBCls.refreshBonds(ee,re[0]);for(let e in le){let t=n.residues[e];for(a in t){let t=n.atoms[a];t.het=!0,n.chemicals[t.serial]=1,n.secondaries[e]="o",delete n.proteins[t.serial],"CA"===t.name&&delete n.calphas[t.serial],"N"!==t.name&&"H"!==t.name&&"CA"!==t.name&&"HA"!==t.name&&"C"!==t.name&&"O"!==t.name&&delete n.sidec[t.serial]}}return n.pmin=te,n.pmax=se,n.cnt=ne,n.center=n.ParserUtilsCls.getGeoCenter(n.pmin,n.pmax),n.maxD=n.ParserUtilsCls.getStructureSize(n.atoms,n.pmin,n.pmax,n.center),n.maxD<5&&(n.maxD=5),n.oriMaxD=n.maxD,n.oriCenter=n.center.clone(),r}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]);s[e.firstAtomObjCls.getFirstAtomObj(r).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';
13
- 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 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(n,"sphere");else if(0==n.indexOf("add cube"))this.addShape(n,"cube");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","Distance 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")){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"),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("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(),t.getGraphCls.updateGraphColor()}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("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(-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;s.shapeCmdHash[e]=1;let 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=i.parasCls.thr(r),c=new THREE.Vector3(parseFloat(l[1]),parseFloat(l[3]),parseFloat(l[5]));"sphere"==t?s.sphereCls.createSphereBase(c,d,parseFloat(a),void 0,void 0,void 0,parseFloat(o)):s.boxCls.createBox_base(c,parseFloat(a),d,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 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("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,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"),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"),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";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"),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(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{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)if("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=!1,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="structure",i.setStyleCls.setAtomStyleByOptions(),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].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=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){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 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[1].indexOf("resdef")+7)),e.length>3&&-1!=e[3].indexOf("aligntool")&&(s.cfg.aligntool=e[3].substr(e[1].indexOf("aligntool")+10)),s.cfg.chainalign=l,await t.chainalignParserCls.downloadChainalignment(l,s.cfg.resnum,s.cfg.resdef)}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.dsn6ParserCls.dsn6ParserBase(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.dsn6ParserCls.dsn6Parser(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.chains)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[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}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),o=r.subdomains,a=r.pos2resi;if(o.length>=1)for(let t=0,l=o.length;t<l;++t){let l={},r=o[t],d=0;for(let t=0,n=r.length;t<n;t+=2){let n=parseInt(r[t]),o=parseInt(r[t+1]);for(let t=n;t<=o;++t){let n=e+"_"+a[t-1];++d,l=i.hashUtilsCls.unionHash(l,s.residues[n]),delete s.residIgLoop[n],delete s.resid2domainid[n]}}d<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();if(l&&r){let e=s+"_"+l;t.resid2refnum[e]=r,t.chainsMapping.hasOwnProperty(s)||(t.chainsMapping[s]={}),t.chainsMapping[s][e]=r}}}await t.showAnnoCls.showAnnotations(),t.annotationCls.setAnnoViewAndDisplay("detailed view")}rmStrandFromRefnumlabel(e){return this.icn3d.icn3dui,e&&isNaN(e.substr(0,1))&&e?e.replace(/'/g,"").replace(/\*/g,"").replace(/\^/g,"").replace(/\+/g,"").replace(/\-/g,"").substr(1):e}exportRefnum(e,t){let 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="";for(let n=0,l=s.structures[t].length;s.bShowRefnum&&n<l;++n){let l=s.structures[t][n],r=s.chain2igArray[l];if(r&&r.length>0){i+='{"'+l+'": {\n';for(let t=0,n=r.length;t<n;++t){let n=r[t].startPosArray,o=r[t].endPosArray,a=r[t].domainid,d=s.domainid2info[a];if(d){i+='"'+a+'": {\n',i+='"refpdbname":"'+d.refpdbname+'", "score":'+d.score+', "seqid":'+d.seqid+', "nresAlign":'+d.nresAlign+', "data": [';for(let t=0,r=n.length;t<r;++t){let r=n[t],a=o[t];for(let t=r;t<=a;++t){const n=l+"_"+s.chainsSeq[l][t].resi+"_"+s.chainsSeq[l][t].name;i+='{"'+n+'": "'+e[n]+'"},\n'}}i+="],\n",i+="},\n"}}i+="}},\n"}}n+='{"'+t+'": {"Ig domain" : '+(i?1:0)+', "igs": [\n',n+=i,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){let n=y[e].strand;if("G"!=n&&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);let l=t+"_"+y[e].startResi;if(y.splice(e,1),"B"==n||"C"==n||"E"==n||"F"==n){i.bNode||console.log("Ig strand "+n+" is removed since it is too short..."),k[s.resid2domainid[l]]=1;continue}}}_=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)}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)}}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_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_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),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}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 Es{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 Ts{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){if(this.icn3d.icn3dui.bNode)return"";let i=$("#"+e).width(),n=$("#"+e).height();s&&(n=i);let l=this.getSvgXml(e,i,n,s),r=new Blob([l],{type:"image/svg+xml"});saveAs(r,t)}getSvgXml(e,t,s,i){if(this.icn3d.icn3dui.bNode)return"";return(t&&s?'<svg viewBox="0 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){let i=this.icn3d,n=i.icn3dui;if(n.bNode)return"";let l=$("#"+e).width(),r=$("#"+e).height();s&&(r=l);let o=document.getElementById(e),a=o.getBBox(),d=o.cloneNode(!0);i.lineGraphCls.copyStylesInline(d,o);let c=document.createElement("CANVAS");c.width=l,c.height=r;let h=c.getContext("2d");h.clearRect(0,0,a.width,a.height);let p=this.getSvgXml(e,l,r,s),m=window.URL||window.webkitURL||window,u=new Blob([p],{type:"image/svg+xml;charset=utf-8"}),g=new Image;g.src=m.createObjectURL(u),g.onload=function(){if(h.drawImage(g,0,0),m.revokeObjectURL(this.src),n.utilsCls.isIE()){let e=c.msToBlob();e&&(saveAs(e,t),c.remove())}else c.toBlob((function(e){e&&(saveAs(e,t),c.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){let o=this.icn3d,a=o.icn3dui,d="",c={},h={};for(let e in o.chemicals){let t=o.atoms[e];if("P"==t.elem){c[e]=1;for(let e=0,s=t.bonds.length;e<s;++e){let s=t.bonds[e];s&&"O"==o.atoms[s].elem&&(h[s]=1)}}}let p,m,u=a.hashUtilsCls.intHash(e,o.calphas),g={};for(let e in o.structures)g[e]="";let f=[];for(let e in u){let t=o.atoms[e];m=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(p)+1&&(s.ss=" ",f.push(s)),"helix"==t.ss?(s.ss="H",f.push(s)):"sheet"==t.ss&&(s.ss="S",f.push(s)),t.ssend){let e=a.hashUtilsCls.cloneHash(s);e.ss=" ",f.push(e)}p=t.resi}let C,b,y=0,v=!1,_=!1;for(let e=0,t=f.length;e<t;++e){let t=f[e];t.ss!=C&&(g[m]+=this.printPrevSecondary(v,_,b,y),y=0,v=!1,_=!1,b=void 0," "!=t.ss&&("H"==t.ss?(v=!0,b=t,g[m]+="HELIX".padEnd(15," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(5," ")):"S"==t.ss&&(_=!0,b=t,g[m]+="SHEET".padEnd(17," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(4," "))))," "!=t.ss&&(++y,b=t),C=t.ss}if(g[m]+=this.printPrevSecondary(v,_,b,y),g[m]+="\n",o.biomtMatrices&&Object.keys(e).length==Object.keys(o.atoms).length){let e=Object.keys(o.structures)[0];for(let t=0,s=o.biomtMatrices.length;t<s;++t){let s=t+1;for(let i=0;i<3;++i){let n=i+1;g[e]+="REMARK 350 BIOMT"+n.toString()+" "+s.toString().padStart(2," ")+" "+o.biomtMatrices[t].elements[i+0].toFixed(6).toString().padStart(9," ")+" "+o.biomtMatrices[t].elements[i+4].toFixed(6).toString().padStart(9," ")+" "+o.biomtMatrices[t].elements[i+8].toFixed(6).toString().padStart(9," ")+" "+o.biomtMatrices[t].elements[i+12].toFixed(6).toString().padStart(14," ")+"\n"}}}for(let e in o.chainMissingResidueArray){let t=e.indexOf("_"),s=e.substr(t+1,2),i=e.substr(0,t);for(let t=0,n=o.chainMissingResidueArray[e].length;t<n;++t){let n=o.chainMissingResidueArray[e][t].resi,l=a.utilsCls.residueAbbr2Name(o.chainMissingResidueArray[e][t].name);g[i]+="REMARK 465 "+l.padStart(3," ")+s.padStart(2," ")+" "+n.toString().padStart(5," ")+"\n"}}let w="",S=Object.keys(o.structures).length>1,A=1,x="",k="",O=0,R="",I={};for(let l in e){let e=o.atoms[l];if(s&&e.het)continue;if(e.structure!=x){r&&S||(d+=w,w="",A>1&&(d+="\nENDMDL\n"),S&&(d+="MODEL "+A+"\n"));let t=n?"Mutated chain_residue "+Object.keys(n)+"; ":"";i||r&&S||(d+=this.getPDBHeader(A-1,g,t,e.structure)),++A}e.chain!=k&&e.structure==x&&k&&(d+="TER\n");let p=e.chain+"_"+e.resi;if(n&&n.hasOwnProperty(p)){I.hasOwnProperty(p)||(d+=n[p],I[p]=1);continue}let m="";m+=e.het?"HETATM":"ATOM ",m+=l.toString().padStart(5," "),m+=" ";let u=e.name.trim();isNaN(u.substr(0,1))||(u=u.substr(1)+u.substr(0,1)),4==u.length?m+=u:(m+=" ",u=u.replace(/\*/g,"'"),"O1P"==u?u="OP1":"O2P"==u?u="OP2":"C5M"==u&&(u="C7 "),m+=u.padEnd(3," ")),m+=" ";let f=e.resn;if(m+=f.length<=3?f.padStart(3," "):f.substr(0,3),r&&A>2&&(o.proteins.hasOwnProperty(e.serial)||o.nucleotides.hasOwnProperty(e.serial)))e.structure==x&&e.chain==k||(R=O<36?"abcdefghijklmnopqrstuvwxyz0123456789"[O]:"?",++O),m+=" "+R;else if(e.chain.length>=2){m+=e.chain.replace(/_/gi,"").substr(0,2)}else 1==e.chain.length?m+=" "+e.chain.substr(0,1):0==e.chain.length&&(m+=" A");let C=e.resi;!isNaN(C)&&e.chain.length>3&&!isNaN(e.chain.substr(3))&&(C=C-1+parseInt(e.chain.substr(3)));let b=parseInt(C);m+=b.toString().length<=4?b.toString().padStart(4," "):b.toString().substr(0,4);let y=e.resi.toString().substr(e.resi.toString().length-1,1);if(isNaN(y)?m+=y:m+=" ",m+=" ".padStart(3," "),m+=e.coord.x.toFixed(3).toString().padStart(8," "),m+=e.coord.y.toFixed(3).toString().padStart(8," "),m+=e.coord.z.toFixed(3).toString().padStart(8," "),t&&e.het){let t=1.5,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:a.parasCls.vdwRadii.hasOwnProperty(e.elem)&&(t=a.parasCls.vdwRadii[e.elem]),void 0!==a.cfg.cid&&void 0!==e.crg?s=e.crg:c.hasOwnProperty(l)?s=1.38:h.hasOwnProperty(l)?s=-.595:a.parasCls.ionCharges.hasOwnProperty(e.elem)&&(s=a.parasCls.ionCharges[e.elem]),m+=s.toFixed(4).toString().padStart(8," "),m+=t.toFixed(4).toString().padStart(7," ")}else m+="1.00".padStart(6," "),m+=e.b?parseFloat(e.b).toFixed(2).toString().padStart(6," "):" ".padStart(6," "),m+=" ".padStart(10," "),m+=e.elem.padStart(2," "),m+=" ".padStart(2," ");if(e.het&&e.bonds.length>0){w+="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])&&(w+=e.bonds[s].toString().padStart(5," "),t[e.bonds[s]]=1);w+="\n"}d+=m+"\n",x=e.structure,k=e.chain}return r&&S||(d+=w,S&&(d+="\nENDMDL\n")),d}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 Ps{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){let s=this.icn3d,i=s.icn3dui,n=i.htmlCls.baseUrl+"icn3d/?",l="";if(i.cfg.bSidebyside&&(n=i.htmlCls.baseUrl+"icn3d/full2.html?"),s.bInputUrlfile){n=window.location.href.split("?")[0]+"?"+s.inputurl+"&"}let r,o={};for(let e in s.cfg){let t=s.cfg[e];"inpara"!==e&&"command"!==e&&"usepdbnum"!==e&&"date"!==e&&"v"!==e&&void 0!==t&&("width"===e&&"100%"===t||"height"===e&&"100%"===t||"resize"===e&&!0===t||"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&&(o[e]=JSON.stringify(t)):!0===t?o[e]=1:!1===t?o[e]=0:""!==t&&(o[e]=t)))}s.bAfMem?o.afmem="on":(i.cfg.afid||1==Object.keys(s.structures).length&&Object.keys(s.structures)[0].length>5)&&(o.afmem="off");let a=-1;void 0!==i.cfg.inpara&&(a=i.cfg.inpara.indexOf("&command=")),r=-1!==a?i.cfg.inpara.substr(0,a):i.cfg.inpara;let d=!1;if(!s.bInputUrlfile){let e=r&&r.substr(1)?r.substr(1).split("&"):[];for(let t=0,s=e.length;t<s;++t){let s=e[t].split("=");2==s.length&&(o[s[0]]=s[1])}i.cfg.idname&&!o[i.cfg.idname]&&(n+=i.cfg.idname+"="+i.cfg.idvalue+"&");for(let e in o)"v"!==e&&("date"===e&&(d=!0),n+=e+"="+o[e]+"&")}let c,h=i.utilsCls.getDateDigitStr();d||(n+="date="+h+"&"),n+="v="+i.REVISION+"&",n+="command=",c=t&&void 0!==r?1:0,(e||s.bInputUrlfile)&&(c=0);let p={};p.factor=s._zoomFactor,p.mouseChange=s.mouseChange,p.quaternion=s.quaternion;let m="",u="",g="toggle highlight",f=0;if(s.commands.length>c){u=s.commands[c].split("|||")[0].split("&command=")[0].trim(),-1!==u.indexOf(g)&&++f}let C,b=c+1,y="";for(let e=s.commands.length;b<e;++b){let e=s.commands[b].split("|||")[0].split("&command=")[0].trim();0==u.indexOf("select sets")&&0===e.indexOf("select sets")&&-1===u.indexOf(" name ")||-1!==u.indexOf("pickatom")&&-1!==e.indexOf("pickatom")||"show selection"==u&&-1!=s.commands.slice(b).toString().indexOf("show selection")||(-1!==u.indexOf(g)?++f:y+=b===c+1?u:y?"; "+u:u),m+=u+"\n",u=e}return u&&(y&&(y+="; "),f>0&&f%2==0&&u!==g&&(y+=g+"; "),y+=u+"|||"+s.transformCls.getTransformationStr(p),m+=u+"|||"+s.transformCls.getTransformationStr(p)+"\n"),n+=y,l=y,m=m.replace(/!/g,Object.keys(s.structures)[0]+"_"),(s.bEsmfold||s.bInputfile&&!s.bInputUrlfile||s.bInputUrlfile&&s.bAppend||n.length>4e3)&&(n=m),void 0!==s.structures&&1==Object.keys(s.structures).length&&void 0!==s.inputid&&(C=Object.keys(s.structures)[0],n=n.replace(new RegExp(C+"_","g"),"!"),l=l.replace(new RegExp(C+"_","g"),"!")),void 0!==i.cfg.blast_rep_id&&(n=n.replace(new RegExp("blast_rep_id=!","g"),"blast_rep_id="+C+"_")),t?l:n}getPngText(){let e,t=this.icn3d;t.icn3dui;let s="";if(t.bInputfile)e=this.shareLinkUrl(true),"http"==e.substr(0,4)?s+="\nShare Link: "+e:(s+="\nStart of type file======\n",s+=t.InputfileType+"\n",s+="End of type file======\n",s+="Start of data file======\n",s+=t.saveFileCls.getAtomPDB(t.atoms),s+="End of data file======\n",s+="Start of state file======\n",s+=e+"\n",s+="End of state file======\n");else{e=this.shareLinkUrl(),e.length>4e3||0!==e.indexOf("http")?(e=this.shareLinkUrl(true),s+="\nStart of state file======\n",s+=e+"\n",s+="End of state file======\n"):s+="\nShare Link: "+e}return s=s.replace(/!/g,Object.keys(t.structures)[0]+"_"),s}}class Ds{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 Ms{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 Fs{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 Hs{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 Ls{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 Ns{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 qs{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 Us{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 Be(this),this.stripCls=new $e(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 Es(this),this.setStyleCls=new ft(this),this.setColorCls=new Ct(this),this.threeDPrintCls=new Ds(this),this.export3DCls=new Ms(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 Bt(this),this.contactMapCls=new $t(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 Is(this),this.saveFileCls=new Ts(this),this.setOptionCls=new bt(this),this.shareLinkCls=new Ps(this),this.diagram2dCls=new Os(this),this.cartoon2dCls=new Rs(this),this.rayCls=new Fs(this),this.controlCls=new Hs(this),this.pickingCls=new Ls(this),this.VRButtonCls=new Ns(this),this.ARButtonCls=new qs(this),this.matShader=this.setColorCls.setOutlineColor("yellow")}}Us.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=[]},Us.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},Us.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},Us.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&&(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.31.3",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,void 0!==t.cfg.bCalphaOnly&&(s.bCalphaOnly=t.cfg.bCalphaOnly),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.resdef&&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),t.htmlCls.clickMenuCls.setLogCmd("resdef "+t.cfg.resdef,!0),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){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.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,s.loadCmd="load chainalignment "+t.cfg.chainalign+" | resnum "+t.cfg.resnum+" | resdef "+t.cfg.resdef+" | aligntool "+t.cfg.aligntool+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.chainalignParserCls.downloadChainalignment(t.cfg.chainalign,t.cfg.resnum,t.cfg.resdef);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 Us(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=qs,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=Hs,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=Bt,e.Dsn6Parser=Gt,e.Dssp=_s,e.ElectronMap=Je,e.Events=p,e.Export3D=Ms,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=Ls,e.ProteinSurface=Ke,e.Ray=Fs,e.RealignParser=ns,e.Refnum=ws,e.ReprSub=Ne,e.Resid2spec=bs,e.ResidueLabels=ot,e.ResizeCanvas=Is,e.RmsdSuprCls=l,e.Saltbridge=gt,e.SaveFile=Ts,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=Ps,e.ShowAnno=Pt,e.ShowInter=qt,e.ShowSeq=Dt,e.Sphere=qe,e.Stick=Ue,e.Strand=Be,e.Strip=$e,e.SubdivideCls=r,e.Surface=Ze,e.Symd=As,e.ThreeDPrint=Ds,e.Transform=Es,e.Tube=je,e.UtilsCls=s,e.VRButton=Ns,e.Vastplus=hs,e.ViewInterPairs=Ut,e.XyzParser=is,e.iCn3D=Us,e.iCn3DUI=Bs,e.printMsg=class{constructor(){console.log("This is a message from the icn3d package")}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
13
+ 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 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(n,"sphere");else if(0==n.indexOf("add cube"))this.addShape(n,"cube");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","Distance 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")){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"),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("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(),t.getGraphCls.updateGraphColor()}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("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(-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;s.shapeCmdHash[e]=1;let 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=i.parasCls.thr(r),c=new THREE.Vector3(parseFloat(l[1]),parseFloat(l[3]),parseFloat(l[5]));"sphere"==t?s.sphereCls.createSphereBase(c,d,parseFloat(a),void 0,void 0,void 0,parseFloat(o)):s.boxCls.createBox_base(c,parseFloat(a),d,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 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("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,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"),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"),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";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"),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(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{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)if("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=!1,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="structure",i.setStyleCls.setAtomStyleByOptions(),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].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=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){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 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[1].indexOf("resdef")+7)),e.length>3&&-1!=e[3].indexOf("aligntool")&&(s.cfg.aligntool=e[3].substr(e[1].indexOf("aligntool")+10)),s.cfg.chainalign=l,await t.chainalignParserCls.downloadChainalignment(l,s.cfg.resnum,s.cfg.resdef)}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.dsn6ParserCls.dsn6ParserBase(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.dsn6ParserCls.dsn6Parser(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.chains)e.hAtoms=t.hashUtilsCls.unionHash(e.hAtoms,e.chains[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}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),o=r.subdomains,a=r.pos2resi;if(o.length>=1)for(let t=0,l=o.length;t<l;++t){let l={},r=o[t],d=0;for(let t=0,n=r.length;t<n;t+=2){let n=parseInt(r[t]),o=parseInt(r[t+1]);for(let t=n;t<=o;++t){let n=e+"_"+a[t-1];++d,l=i.hashUtilsCls.unionHash(l,s.residues[n]),delete s.residIgLoop[n],delete s.resid2domainid[n]}}d<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();if(l&&r){let e=s+"_"+l;t.resid2refnum[e]=r,t.chainsMapping.hasOwnProperty(s)||(t.chainsMapping[s]={}),t.chainsMapping[s][e]=r}}}await t.showAnnoCls.showAnnotations(),t.annotationCls.setAnnoViewAndDisplay("detailed view")}rmStrandFromRefnumlabel(e){return this.icn3d.icn3dui,e&&isNaN(e.substr(0,1))&&e?e.replace(/'/g,"").replace(/\*/g,"").replace(/\^/g,"").replace(/\+/g,"").replace(/\-/g,"").substr(1):e}exportRefnum(e,t){let 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){let n=y[e].strand;if("G"!=n&&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);let l=t+"_"+y[e].startResi;if(y.splice(e,1),"B"==n||"C"==n||"E"==n||"F"==n){i.bNode||console.log("Ig strand "+n+" is removed since it is too short..."),k[s.resid2domainid[l]]=1;continue}}}_=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)}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)}}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_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_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),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}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 Es{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 Ts{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){if(this.icn3d.icn3dui.bNode)return"";let i=$("#"+e).width(),n=$("#"+e).height();s&&(n=i);let l=this.getSvgXml(e,i,n,s),r=new Blob([l],{type:"image/svg+xml"});saveAs(r,t)}getSvgXml(e,t,s,i){if(this.icn3d.icn3dui.bNode)return"";return(t&&s?'<svg viewBox="0 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){let i=this.icn3d,n=i.icn3dui;if(n.bNode)return"";let l=$("#"+e).width(),r=$("#"+e).height();s&&(r=l);let o=document.getElementById(e),a=o.getBBox(),d=o.cloneNode(!0);i.lineGraphCls.copyStylesInline(d,o);let c=document.createElement("CANVAS");c.width=l,c.height=r;let h=c.getContext("2d");h.clearRect(0,0,a.width,a.height);let p=this.getSvgXml(e,l,r,s),m=window.URL||window.webkitURL||window,u=new Blob([p],{type:"image/svg+xml;charset=utf-8"}),g=new Image;g.src=m.createObjectURL(u),g.onload=function(){if(h.drawImage(g,0,0),m.revokeObjectURL(this.src),n.utilsCls.isIE()){let e=c.msToBlob();e&&(saveAs(e,t),c.remove())}else c.toBlob((function(e){e&&(saveAs(e,t),c.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){let o=this.icn3d,a=o.icn3dui,d="",c={},h={};for(let e in o.chemicals){let t=o.atoms[e];if("P"==t.elem){c[e]=1;for(let e=0,s=t.bonds.length;e<s;++e){let s=t.bonds[e];s&&"O"==o.atoms[s].elem&&(h[s]=1)}}}let p,m,u=a.hashUtilsCls.intHash(e,o.calphas),g={};for(let e in o.structures)g[e]="";let f=[];for(let e in u){let t=o.atoms[e];m=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(p)+1&&(s.ss=" ",f.push(s)),"helix"==t.ss?(s.ss="H",f.push(s)):"sheet"==t.ss&&(s.ss="S",f.push(s)),t.ssend){let e=a.hashUtilsCls.cloneHash(s);e.ss=" ",f.push(e)}p=t.resi}let C,b,y=0,v=!1,_=!1;for(let e=0,t=f.length;e<t;++e){let t=f[e];t.ss!=C&&(g[m]+=this.printPrevSecondary(v,_,b,y),y=0,v=!1,_=!1,b=void 0," "!=t.ss&&("H"==t.ss?(v=!0,b=t,g[m]+="HELIX".padEnd(15," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(5," ")):"S"==t.ss&&(_=!0,b=t,g[m]+="SHEET".padEnd(17," ")+t.resn.padStart(3," ")+t.chain.replace(/_/gi,"").substr(0,2).padStart(2," ")+t.resi.toString().padStart(4," "))))," "!=t.ss&&(++y,b=t),C=t.ss}if(g[m]+=this.printPrevSecondary(v,_,b,y),g[m]+="\n",o.biomtMatrices&&Object.keys(e).length==Object.keys(o.atoms).length){let e=Object.keys(o.structures)[0];for(let t=0,s=o.biomtMatrices.length;t<s;++t){let s=t+1;for(let i=0;i<3;++i){let n=i+1;g[e]+="REMARK 350 BIOMT"+n.toString()+" "+s.toString().padStart(2," ")+" "+o.biomtMatrices[t].elements[i+0].toFixed(6).toString().padStart(9," ")+" "+o.biomtMatrices[t].elements[i+4].toFixed(6).toString().padStart(9," ")+" "+o.biomtMatrices[t].elements[i+8].toFixed(6).toString().padStart(9," ")+" "+o.biomtMatrices[t].elements[i+12].toFixed(6).toString().padStart(14," ")+"\n"}}}for(let e in o.chainMissingResidueArray){let t=e.indexOf("_"),s=e.substr(t+1,2),i=e.substr(0,t);for(let t=0,n=o.chainMissingResidueArray[e].length;t<n;++t){let n=o.chainMissingResidueArray[e][t].resi,l=a.utilsCls.residueAbbr2Name(o.chainMissingResidueArray[e][t].name);g[i]+="REMARK 465 "+l.padStart(3," ")+s.padStart(2," ")+" "+n.toString().padStart(5," ")+"\n"}}let w="",S=Object.keys(o.structures).length>1,A=1,x="",k="",O=0,R="",I={};for(let l in e){let e=o.atoms[l];if(s&&e.het)continue;if(e.structure!=x){r&&S||(d+=w,w="",A>1&&(d+="\nENDMDL\n"),S&&(d+="MODEL "+A+"\n"));let t=n?"Mutated chain_residue "+Object.keys(n)+"; ":"";i||r&&S||(d+=this.getPDBHeader(A-1,g,t,e.structure)),++A}e.chain!=k&&e.structure==x&&k&&(d+="TER\n");let p=e.chain+"_"+e.resi;if(n&&n.hasOwnProperty(p)){I.hasOwnProperty(p)||(d+=n[p],I[p]=1);continue}let m="";m+=e.het?"HETATM":"ATOM ",m+=l.toString().padStart(5," "),m+=" ";let u=e.name.trim();isNaN(u.substr(0,1))||(u=u.substr(1)+u.substr(0,1)),4==u.length?m+=u:(m+=" ",u=u.replace(/\*/g,"'"),"O1P"==u?u="OP1":"O2P"==u?u="OP2":"C5M"==u&&(u="C7 "),m+=u.padEnd(3," ")),m+=" ";let f=e.resn;if(m+=f.length<=3?f.padStart(3," "):f.substr(0,3),r&&A>2&&(o.proteins.hasOwnProperty(e.serial)||o.nucleotides.hasOwnProperty(e.serial)))e.structure==x&&e.chain==k||(R=O<36?"abcdefghijklmnopqrstuvwxyz0123456789"[O]:"?",++O),m+=" "+R;else if(e.chain.length>=2){m+=e.chain.replace(/_/gi,"").substr(0,2)}else 1==e.chain.length?m+=" "+e.chain.substr(0,1):0==e.chain.length&&(m+=" A");let C=e.resi;!isNaN(C)&&e.chain.length>3&&!isNaN(e.chain.substr(3))&&(C=C-1+parseInt(e.chain.substr(3)));let b=parseInt(C);m+=b.toString().length<=4?b.toString().padStart(4," "):b.toString().substr(0,4);let y=e.resi.toString().substr(e.resi.toString().length-1,1);if(isNaN(y)?m+=y:m+=" ",m+=" ".padStart(3," "),m+=e.coord.x.toFixed(3).toString().padStart(8," "),m+=e.coord.y.toFixed(3).toString().padStart(8," "),m+=e.coord.z.toFixed(3).toString().padStart(8," "),t&&e.het){let t=1.5,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:a.parasCls.vdwRadii.hasOwnProperty(e.elem)&&(t=a.parasCls.vdwRadii[e.elem]),void 0!==a.cfg.cid&&void 0!==e.crg?s=e.crg:c.hasOwnProperty(l)?s=1.38:h.hasOwnProperty(l)?s=-.595:a.parasCls.ionCharges.hasOwnProperty(e.elem)&&(s=a.parasCls.ionCharges[e.elem]),m+=s.toFixed(4).toString().padStart(8," "),m+=t.toFixed(4).toString().padStart(7," ")}else m+="1.00".padStart(6," "),m+=e.b?parseFloat(e.b).toFixed(2).toString().padStart(6," "):" ".padStart(6," "),m+=" ".padStart(10," "),m+=e.elem.padStart(2," "),m+=" ".padStart(2," ");if(e.het&&e.bonds.length>0){w+="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])&&(w+=e.bonds[s].toString().padStart(5," "),t[e.bonds[s]]=1);w+="\n"}d+=m+"\n",x=e.structure,k=e.chain}return r&&S||(d+=w,S&&(d+="\nENDMDL\n")),d}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 Ps{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){let s=this.icn3d,i=s.icn3dui,n=i.htmlCls.baseUrl+"icn3d/?",l="";if(i.cfg.bSidebyside&&(n=i.htmlCls.baseUrl+"icn3d/full2.html?"),s.bInputUrlfile){n=window.location.href.split("?")[0]+"?"+s.inputurl+"&"}let r,o={};for(let e in s.cfg){let t=s.cfg[e];"inpara"!==e&&"command"!==e&&"usepdbnum"!==e&&"date"!==e&&"v"!==e&&void 0!==t&&("width"===e&&"100%"===t||"height"===e&&"100%"===t||"resize"===e&&!0===t||"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&&(o[e]=JSON.stringify(t)):!0===t?o[e]=1:!1===t?o[e]=0:""!==t&&(o[e]=t)))}s.bAfMem?o.afmem="on":(i.cfg.afid||1==Object.keys(s.structures).length&&Object.keys(s.structures)[0].length>5)&&(o.afmem="off");let a=-1;void 0!==i.cfg.inpara&&(a=i.cfg.inpara.indexOf("&command=")),r=-1!==a?i.cfg.inpara.substr(0,a):i.cfg.inpara;let d=!1;if(!s.bInputUrlfile){let e=r&&r.substr(1)?r.substr(1).split("&"):[];for(let t=0,s=e.length;t<s;++t){let s=e[t].split("=");2==s.length&&(o[s[0]]=s[1])}i.cfg.idname&&!o[i.cfg.idname]&&(n+=i.cfg.idname+"="+i.cfg.idvalue+"&");for(let e in o)"v"!==e&&("date"===e&&(d=!0),n+=e+"="+o[e]+"&")}let c,h=i.utilsCls.getDateDigitStr();d||(n+="date="+h+"&"),n+="v="+i.REVISION+"&",n+="command=",c=t&&void 0!==r?1:0,(e||s.bInputUrlfile)&&(c=0);let p={};p.factor=s._zoomFactor,p.mouseChange=s.mouseChange,p.quaternion=s.quaternion;let m="",u="",g="toggle highlight",f=0;if(s.commands.length>c){u=s.commands[c].split("|||")[0].split("&command=")[0].trim(),-1!==u.indexOf(g)&&++f}let C,b=c+1,y="";for(let e=s.commands.length;b<e;++b){let e=s.commands[b].split("|||")[0].split("&command=")[0].trim();0==u.indexOf("select sets")&&0===e.indexOf("select sets")&&-1===u.indexOf(" name ")||-1!==u.indexOf("pickatom")&&-1!==e.indexOf("pickatom")||"show selection"==u&&-1!=s.commands.slice(b).toString().indexOf("show selection")||(-1!==u.indexOf(g)?++f:y+=b===c+1?u:y?"; "+u:u),m+=u+"\n",u=e}return u&&(y&&(y+="; "),f>0&&f%2==0&&u!==g&&(y+=g+"; "),y+=u+"|||"+s.transformCls.getTransformationStr(p),m+=u+"|||"+s.transformCls.getTransformationStr(p)+"\n"),n+=y,l=y,m=m.replace(/!/g,Object.keys(s.structures)[0]+"_"),(s.bEsmfold||s.bInputfile&&!s.bInputUrlfile||s.bInputUrlfile&&s.bAppend||n.length>4e3)&&(n=m),void 0!==s.structures&&1==Object.keys(s.structures).length&&void 0!==s.inputid&&(C=Object.keys(s.structures)[0],n=n.replace(new RegExp(C+"_","g"),"!"),l=l.replace(new RegExp(C+"_","g"),"!")),void 0!==i.cfg.blast_rep_id&&(n=n.replace(new RegExp("blast_rep_id=!","g"),"blast_rep_id="+C+"_")),t?l:n}getPngText(){let e,t=this.icn3d;t.icn3dui;let s="";if(t.bInputfile)e=this.shareLinkUrl(true),"http"==e.substr(0,4)?s+="\nShare Link: "+e:(s+="\nStart of type file======\n",s+=t.InputfileType+"\n",s+="End of type file======\n",s+="Start of data file======\n",s+=t.saveFileCls.getAtomPDB(t.atoms),s+="End of data file======\n",s+="Start of state file======\n",s+=e+"\n",s+="End of state file======\n");else{e=this.shareLinkUrl(),e.length>4e3||0!==e.indexOf("http")?(e=this.shareLinkUrl(true),s+="\nStart of state file======\n",s+=e+"\n",s+="End of state file======\n"):s+="\nShare Link: "+e}return s=s.replace(/!/g,Object.keys(t.structures)[0]+"_"),s}}class Ds{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 Ms{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 Fs{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 Hs{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 Ls{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 Ns{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 qs{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 Us{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 Be(this),this.stripCls=new $e(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 Es(this),this.setStyleCls=new ft(this),this.setColorCls=new Ct(this),this.threeDPrintCls=new Ds(this),this.export3DCls=new Ms(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 Bt(this),this.contactMapCls=new $t(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 Is(this),this.saveFileCls=new Ts(this),this.setOptionCls=new bt(this),this.shareLinkCls=new Ps(this),this.diagram2dCls=new Os(this),this.cartoon2dCls=new Rs(this),this.rayCls=new Fs(this),this.controlCls=new Hs(this),this.pickingCls=new Ls(this),this.VRButtonCls=new Ns(this),this.ARButtonCls=new qs(this),this.matShader=this.setColorCls.setOutlineColor("yellow")}}Us.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=[]},Us.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},Us.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},Us.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&&(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.31.3",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,void 0!==t.cfg.bCalphaOnly&&(s.bCalphaOnly=t.cfg.bCalphaOnly),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.resdef&&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),t.htmlCls.clickMenuCls.setLogCmd("resdef "+t.cfg.resdef,!0),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){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.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,s.loadCmd="load chainalignment "+t.cfg.chainalign+" | resnum "+t.cfg.resnum+" | resdef "+t.cfg.resdef+" | aligntool "+t.cfg.aligntool+" | parameters "+t.cfg.inpara,t.htmlCls.clickMenuCls.setLogCmd(s.loadCmd,!0),await s.chainalignParserCls.downloadChainalignment(t.cfg.chainalign,t.cfg.resnum,t.cfg.resdef);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 Us(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=qs,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=Hs,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=Bt,e.Dsn6Parser=Gt,e.Dssp=_s,e.ElectronMap=Je,e.Events=p,e.Export3D=Ms,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=Ls,e.ProteinSurface=Ke,e.Ray=Fs,e.RealignParser=ns,e.Refnum=ws,e.ReprSub=Ne,e.Resid2spec=bs,e.ResidueLabels=ot,e.ResizeCanvas=Is,e.RmsdSuprCls=l,e.Saltbridge=gt,e.SaveFile=Ts,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=Ps,e.ShowAnno=Pt,e.ShowInter=qt,e.ShowSeq=Dt,e.Sphere=qe,e.Stick=Ue,e.Strand=Be,e.Strip=$e,e.SubdivideCls=r,e.Surface=Ze,e.Symd=As,e.ThreeDPrint=Ds,e.Transform=Es,e.Tube=je,e.UtilsCls=s,e.VRButton=Ns,e.Vastplus=hs,e.ViewInterPairs=Ut,e.XyzParser=is,e.iCn3D=Us,e.iCn3DUI=Bs,e.printMsg=class{constructor(){console.log("This is a message from the icn3d package")}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});