MediaWiki:Common.js

From Molmil Wiki
Revision as of 15:47, 13 August 2020 by Molmil Wiki Administrator (talk | contribs) (molmil.jsをloadするのではなくコピーした内容をそのまま書くようにした)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
var molmil_settings = {src: "http://gjbekker.github.io/molmil/"}, canvas;
function initViewer() {
	// wait until Molmil has been properly loaded
    if (! window.molmil.configBox || ! molmil.configBox.initFinished) {return setTimeout(initViewer, 100);}
    canvas = document.getElementById("molmilViewer"); 
    canvas = molmil.createViewer(canvas); // initialize the canvas
    molmil.loadPDB(canvas.getAttribute("data-pdbid"), null, null, canvas.molmilViewer); // load the entry
	}
/*!
 * molmil.js
 *
 * Molmil molecular web viewer: https://github.com/gjbekker/molmil
 * 
 * By Gert-Jan Bekker
 * License: LGPLv3
 *   See https://github.com/gjbekker/molmil/blob/master/LICENCE.md
 */
;var molmil=molmil||{};molmil.canvasList=[];molmil.mouseDown=false;molmil.mouseDownS={};molmil.mouseMoved=false;molmil.Xcoord=0;molmil.Ycoord=0;molmil.Zcoord=0;molmil.activeCanvas=null;molmil.touchList=null;molmil.touchMode=false;molmil.longTouchTID=null;molmil.previousTouchEvent=null;molmil.ignoreBlackList=false;molmil.settings_default={src:"/molmil/",pdb_url:"https://pdbj.org/rest/displayPDBfile?format=mmjson-all&id=__ID__",comp_url:"https://pdbj.org/rest/displayCOMPfile?format=mmjson&id=__ID__",promodeE_check_url:"https://pdbj.org/rest/quick_search?fields=5&query=__ID__",promodeE_base_structure_url:"https://pdbj.org/rest/displayPromodeEfile?format=min&id=__ID__",promodeE_mode_vectors_url:"https://pdbj.org/rest/displayPromodeEfile?format=vec&id=__ID_____MODE__",promodeE_animation_url:"https://pdbj.org/rest/displayPromodeEfile?format=anm&id=__ID_____MODE__",molmil_video_url:"http://127.0.0.1:8080/app/"};molmil.cli_canvas=null;molmil.cli_soup=null;molmil.settings=window.molmil_settings||molmil.settings_default;for(var e in molmil.settings_default){if(!molmil.settings.hasOwnProperty(e)){molmil.settings[e]=molmil.settings_default[e]}}molmil.configBox={initFinished:false,liteMode:false,cullFace:true,vdwR:{DUMMY:1.7,H:1.09,D:1.09,C:1.7,N:1.55,O:1.52,S:1.8,Cl:1.75,B:1.8,P:1.8,Fe:1.8,Ba:1.8,So:1.8,Mg:1.8,Zn:1.8,Cu:1.4,Ni:1.8,Br:1.95,Ca:1.8,Mn:1.8,Al:1.8,Ti:1.8,Cr:1.8,Ag:1.8,F:1.47,Si:1.8,Au:1.8,I:2.15,Li:1.8,He:1.8,Se:1.9},sndStrucInfo:{1:[255,255,255],2:[255,255,0],3:[255,0,255],4:[0,0,255]},zNear:20,zFar:20000,QLV_SETTINGS:[{SPHERE_TESS_LV:0,CB_NOI:4,CB_NOVPR:4,CB_DOME_TESS_LV:0},{SPHERE_TESS_LV:1,CB_NOI:4,CB_NOVPR:8,CB_DOME_TESS_LV:1},{SPHERE_TESS_LV:2,CB_NOI:8,CB_NOVPR:16,CB_DOME_TESS_LV:2},{SPHERE_TESS_LV:3,CB_NOI:12,CB_NOVPR:32,CB_DOME_TESS_LV:3},{SPHERE_TESS_LV:4,CB_NOI:16,CB_NOVPR:32,CB_DOME_TESS_LV:4}],OES_element_index_uint:null,EXT_frag_depth:null,BGCOLOR:[0,0,0,1],backboneAtoms4Display:{N:1,C:1,O:1,H:1,OXT:1,H1:1,H2:1,H3:1,HA:1,HA2:1,HA3:1},backboneAtoms4DisplayXNA:{P:1,"O5'":1,OP1:1,OP2:1,"C3'":1,"C4'":1,"C5'":1,"O4'":1,"C2'":1,"O3'":1,"O2'":1,H:1},xna_simple_base_atoms:{"O5'":1,"C5'":1,"C4'":1,"O4'":1,"C3'":1,"O3'":1,"C2'":1,O6:1,N2:1,N4:1,P:1,OP1:1,OP2:1,O2:1,"O2'":1,N6:1,O4:1,"DO3'":1,D41:1,D42:1,D21:1,D22:1,D61:1,D62:1},projectionMode:1,colorMode:1,smoothFactor:2,glsl_shaders:[["shaders/standard.glsl"],["shaders/lines.glsl"],["shaders/picking.glsl"],["shaders/linesPicking.glsl"],["shaders/atomSelection.glsl"],["shaders/lines.glsl","lines_uniform_color","#define UNIFORM_COLOR 1\n"],["shaders/standard.glsl","standard_alpha","#define ALPHA_MODE 1\n"],["shaders/standard.glsl","standard_uniform_color","#define UNIFORM_COLOR 1\n"],["shaders/standard.glsl","standard_alpha_uniform_color","#define ALPHA_MODE 1\n#define UNIFORM_COLOR 1\n"],["shaders/anaglyph.glsl"]],glsl_fog:0,skipClearGeometryBuffer:true,stereoMode:0,stereoFocalFraction:1.5,stereoEyeSepFraction:30,camera_fovy:45,HQsurface_gridSpacing:1,webGL2:false};molmil.AATypes={ALA:1,CYS:1,ASP:1,GLU:1,PHE:1,GLY:1,HIS:1,ILE:1,LYS:1,LEU:1,MET:1,ASN:1,PRO:1,GLN:1,ARG:1,SER:1,THR:1,VAL:1,TRP:1,TYR:1,ACE:1,NME:1,HIP:1,HIE:1,HID:1,CYX:1,A:1,T:1,G:1,C:1,DA:1,DT:1,DG:1,DC:1,U:1,DU:1,MSE:1,SEQ:1,CSW:1};molmil.AATypesBase={ALA:1,CYS:1,ASP:1,GLU:1,PHE:1,GLY:1,HIS:1,ILE:1,LYS:1,LEU:1,MET:1,ASN:1,PRO:1,GLN:1,ARG:1,SER:1,THR:1,VAL:1,TRP:1,TYR:1,ACE:1,NME:1,HIP:1,HIE:1,HID:1};molmil.initSettings=function(){var d,h=localStorage.getItem("molmil.settings_COLORS")||1;if(h==2){d={DUMMY:[255,20,147],H:[255,255,255],D:[255,255,255],C:[144,144,144],N:[48,80,248],O:[255,13,13],S:[255,255,48],Cl:[31,240,31],B:[255,181,181],P:[255,128,0],Fe:[224,102,51],Ba:[0,201,0],Mg:[138,255,0],Zn:[125,128,176],Cu:[200,128,51],Ni:[80,208,80],Br:[165,42,42],Ca:[61,255,0],Mn:[156,122,199],Al:[191,166,166],Ti:[191,194,199],Cr:[138,153,199],Ag:[192,192,192],F:[144,224,80],Si:[240,200,160],Au:[255,209,35],I:[148,0,148],Li:[204,128,255],He:[217,255,255]}}else{if(h==3){d={DUMMY:[255,127,0],H:[204,204,204],D:[204,204,204],C:[0,255,255],N:[0,0,255],O:[255,0,0],P:[255,255,0],S:[0,255,0]}}else{d={DUMMY:[255,20,147],H:[255,255,255],D:[255,255,255],C:[200,200,200],N:[143,143,255],O:[240,0,0],S:[255,200,50],Cl:[0,255,0],B:[0,255,0],P:[255,165,0],Fe:[255,165,0],Ba:[255,165,0],Mg:[34,139,34],Zn:[165,42,42],Cu:[165,42,42],Ni:[165,42,42],Br:[165,42,42],Ca:[128,128,144],Mn:[128,128,144],Al:[128,128,144],Ti:[128,128,144],Cr:[128,128,144],Ag:[128,128,144],F:[218,165,32],Si:[218,165,32],Au:[218,165,32],I:[160,32,240],Li:[178,34,34],He:[255,192,203]}}}molmil.configBox.elementColors={};for(var g in d){molmil.configBox.elementColors[g]=[d[g][0],d[g][1],d[g][2],255]}molmil.configBox.sndStrucColor={};for(var g in molmil.configBox.sndStrucInfo){molmil.configBox.sndStrucColor[g]=[molmil.configBox.sndStrucInfo[g][0],molmil.configBox.sndStrucInfo[g][1],molmil.configBox.sndStrucInfo[g][2],255]}molmil.configBox.bu_colors=[[0,204,255],[255,51,255],[0,255,102],[153,102,255],[255,255,0],[204,102,102],[153,204,102],[204,153,204],[153,153,102],[0,204,204],[153,153,153],[51,153,204],[0,255,153],[51,153,255],[204,102,153],[0,255,204],[51,204,255],[204,102,204],[0,255,255],[102,153,204],[204,153,0],[51,204,102],[102,153,255],[204,153,51],[51,204,153],[102,204,255],[204,153,102],[51,204,204],[153,102,204],[204,153,153],[51,255,51],[51,255,102],[153,153,204],[204,204,0],[51,255,153],[153,153,255],[204,204,51],[51,255,204],[153,204,255],[204,204,102],[51,255,255],[204,102,255],[204,204,153],[102,153,153],[204,153,255],[204,204,204],[102,204,51],[204,204,255],[255,51,204],[102,204,102],[102,204,153],[255,102,51],[102,204,204],[255,102,102],[102,255,0],[255,102,153],[102,255,51],[255,102,204],[102,255,102],[255,102,255],[102,255,153],[255,153,0],[102,255,204],[255,153,51],[102,255,255],[255,153,102],[153,204,0],[255,153,153],[153,204,51],[255,153,204],[255,153,255],[153,204,153],[255,204,0],[153,204,204],[255,204,51],[153,255,0],[255,204,102],[153,255,51],[255,204,153],[153,255,102],[255,204,204],[153,255,153],[255,204,255],[153,255,204],[153,255,255],[255,255,51],[204,255,0],[255,255,102],[204,255,51],[255,255,153],[204,255,102],[255,255,204],[204,255,153],[255,255,255],[204,255,204],[204,255,255]];molmil.configBox.glsl_fog=localStorage.getItem("molmil.settings_glsl_fog")==1;molmil.configBox.projectionMode=localStorage.getItem("molmil.settings_PROJECTION")||1;molmil.configBox.stereoMode=parseInt(localStorage.getItem("molmil.settings_STEREO"))||0;molmil.configBox.smoothFactor=localStorage.getItem("molmil.settings_BBSF")||2;var f=localStorage.getItem("molmil.settings_BGCOLOR");if(f){try{molmil.configBox.BGCOLOR=JSON.parse(f)}catch(g){}}};molmil.displayMode_None=0;molmil.displayMode_Visible=0.5;molmil.displayMode_Default=1;molmil.displayMode_Spacefill=2;molmil.displayMode_Spacefill_SC=2.5;molmil.displayMode_BallStick=3;molmil.displayMode_BallStick_SC=3.5;molmil.displayMode_Stick=4;molmil.displayMode_Stick_SC=4.5;molmil.displayMode_Wireframe=5;molmil.displayMode_Wireframe_SC=5.5;molmil.displayMode_CaTrace=6;molmil.displayMode_Tube=7;molmil.displayMode_Cartoon=8;molmil.displayMode_CartoonRocket=8.5;molmil.displayMode_ChainSurfaceCG=10;molmil.displayMode_ChainSurfaceSimple=11;molmil.displayMode_XNA=400;molmil.colorEntry_Default=1;molmil.colorEntry_Structure=2;molmil.colorEntry_CPK=3;molmil.colorEntry_Group=4;molmil.colorEntry_Chain=5;molmil.colorEntry_Custom=6;molmil.colorEntry_ChainAlt=7;molmil.colorEntry_ABEGO=8;molmil.atomObject=function(l,g,f,h,d){this.xyz=l;this.element=f.charAt(0).toUpperCase()+f.slice(1).toLowerCase();this.atomName=g;this.displayMode=0;this.display=1;this.rgba=[0,0,0,255];this.molecule=h;this.chain=d;this.radius=0;this.AID=0};molmil.atomObject.prototype.toString=function(){var d=this.molecule.atoms.length>1;return(d?this.atomName:this.element)+" ("+this.AID+") - "+(d?(this.molecule.name||"")+" ":"")+(this.molecule.RSID||"")+(this.molecule.chain.name?" - Chain "+this.molecule.chain.name:"")};molmil.molObject=function(d,g,f){this.atoms=[];this.name=d;this.id=g;this.RSID=g;this.chain=f;this.ligand=true;this.water=false;this.display=1;this.next=null,this.previous=null;this.rgba=[0,0,0,255];this.sndStruc=1;this.xna=false;this.showSC=false};molmil.molObject.prototype.toString=function(){return" Residue"};molmil.chainObject=function(d,f){this.name=d;this.authName=d;this.molecules=[];this.entry=f;this.display=true;this.modelsXYZ=[[]];this.atoms=[];this.bonds=[];this.bondsOK=false;this.displayMode=molmil.displayMode_Default;this.isHet=true;this.rgba=[255,255,255,255];this.display=true};molmil.chainObject.prototype.toString=function(){return" Chain"};molmil.entryObject=function(d){this.chains=[];this.meta=d||{};this.display=true};molmil.polygonObject=function(d){this.programs=[];this.meta=d||{}};molmil.entryObject.prototype.toString=function(){return" Entry"};molmil.animationObj=function(d){this.soup=d;this.renderer=d.renderer;this.frameNo=0;this.motionMode=1;this.init=false;this.delay=66;this.frameAction=function(){};this.detail_or=-1;this.infoBox=null};molmil.animationObj.prototype.initialise=function(d){this.renderer.animationMode=true;this.number_of_frames=this.soup.structures.length?this.soup.structures[0].number_of_frames:0;this.init=true;this.infoBox=d};molmil.animationObj.prototype.updateInfoBox=function(){if(!this.infoBox){return}if(this.infoBox.timeBox){if(this.soup.frameInfo){this.infoBox.timeBox.innerHTML=this.soup.frameInfo[this.frameNo][1]+"ps"}else{this.infoBox.timeBox.innerHTML=this.frameNo}}if(this.infoBox.sliderBox){if(this.soup.frameInfo){this.infoBox.timeBox.value=this.soup.frameInfo[this.frameNo][1]}else{this.infoBox.timeBox.value=this.frameNo}this.infoBox.sliderBox.value=this.frameNo}};molmil.animationObj.prototype.beginning=function(){if(!this.init){this.initialise()}this.frameNo=0;this.renderer.selectFrame(this.frameNo,this.detail_or);this.soup.canvas.update=true;this.frameAction();this.updateInfoBox()};molmil.animationObj.prototype.go2Frame=function(d){if(!this.init){this.initialise()}this.frameNo=d;this.renderer.selectFrame(this.frameNo,this.detail_or);this.soup.canvas.update=true;this.frameAction();this.updateInfoBox()};molmil.animationObj.prototype.previous=function(){if(!this.init){this.initialise()}this.frameNo-=1;if(this.frameNo<0){this.frameNo=0}this.renderer.selectFrame(this.frameNo,this.detail_or);this.soup.canvas.update=true;this.frameAction();this.updateInfoBox()};molmil.animationObj.prototype.pause=function(){if(this.TID){clearTimeout(this.TID);this.TID=null}};molmil.animationObj.prototype.play=function(){if(!this.init){this.initialise()}this.playing=true;if(this.motionMode==2){this.TID=molmil_dep.asyncStart(this.backwardRenderer,[],this,this.delay)}else{this.TID=molmil_dep.asyncStart(this.forwardRenderer,[],this,this.delay)}};molmil.animationObj.prototype.next=function(){if(!this.init){this.initialise()}this.frameNo+=1;if(this.frameNo>=this.number_of_frames){this.frameNo=this.number_of_frames-1}this.renderer.selectFrame(this.frameNo,this.detail_or);this.soup.canvas.update=true;this.frameAction();this.updateInfoBox()};molmil.animationObj.prototype.end=function(){if(!this.init){this.initialise()}this.frameNo=this.number_of_frames-1;this.renderer.selectFrame(this.frameNo,this.detail_or);this.soup.canvas.update=true;this.frameAction();this.updateInfoBox()};molmil.animationObj.prototype.forwardRenderer=function(){this.frameNo+=1;if(this.frameNo>=this.number_of_frames){if(this.motionMode==3){this.frameNo-=1;return this.backwardRenderer()}else{this.playing=false}}else{this.renderer.selectFrame(this.frameNo,this.detail_or);this.soup.canvas.update=true;this.TID=molmil_dep.asyncStart(this.forwardRenderer,[],this,this.delay);this.frameAction();this.updateInfoBox()}};molmil.animationObj.prototype.backwardRenderer=function(){this.frameNo-=1;if(this.frameNo<0){if(this.motionMode==3){this.frameNo+=1;return this.forwardRenderer()}else{this.playing=false}}else{this.renderer.selectFrame(this.frameNo,this.detail_or);this.soup.canvas.update=true;this.TID=molmil_dep.asyncStart(this.backwardRenderer,[],this,this.delay);this.frameAction();this.updateInfoBox()}};molmil.viewer=function(d){this.canvas=d;this.renderer=new molmil.render(this);this.UI=new molmil.UI(this);this.defaultCanvas=[d,this.renderer];this.onAtomPick=function(){};this.animation=new molmil.animationObj(this);this.clear()};molmil.viewer.prototype.toString=function(){return" SOUP"};molmil.viewer.prototype.reloadSettings=function(){this.renderer.reloadSettings()};molmil.viewer.prototype.clear=function(){this.structureFiles=[];this.trajectory=[];this.structures=[];this.chains=[];this.files=[];this.infoBag={};this.bumats=[];this.BUmatrices={};this.BUassemblies={};this.poly_asym_ids=[];this.BUcache={};this.BUmode=false;this.avgX=0;this.avgY=0;this.avgZ=0;this.stdX=0;this.stdY=0;this.stdZ=0;this.avgXYZ=[];this.stdXYZ=[];this.COR=[0,0,0];this.geomRanges=[0,0,0,0,0,0];this.maxRange=0;this.atomRef={};this.AID=1;this.CID=1;this.MID=1;this.BU=false;this.atomSelection=[];this.hideWaters=true;this.hideHydrogens=true;this.sceneBU=null;this.canvases=[];this.SCstuff=false;if(this.canvas){this.canvas.atomCORset=false;this.canvases=[this.canvas]}this.renderer.clear();this.renderer.camera.z_set=false};molmil.viewer.prototype.gotoMol=function(Q){var L=Q.N;var n=Q.CA;var o=Q.C;if(!(Q.N&&Q.CA&&Q.C)){var T=Q.chain.modelsXYZ[this.renderer.modelId],w,q,p,t=[0,0,0];for(var O=0;O<Q.atoms.length;O++){w=T[Q.atoms[O].xyz];q=T[Q.atoms[O].xyz+1];p=T[Q.atoms[O].xyz+2];t[0]+=w;t[1]+=q;t[2]+=p}t[0]/=Q.atoms.length;t[1]/=Q.atoms.length;t[2]/=Q.atoms.length;var f=[1e+99,-1],I;for(var O=0;O<Q.atoms.length;O++){w=T[Q.atoms[O].xyz];q=T[Q.atoms[O].xyz+1];p=T[Q.atoms[O].xyz+2];I=Math.pow(t[0]-w,2)+Math.pow(t[1]-q,2)+Math.pow(t[2]-p,2);if(I<f[0]){f[0]=I;f[1]=O}}n=Q.atoms[f[1]];var R,d,D,P=[-1,-1,-1];for(var O=0;O<Q.atoms.length;O++){w=T[Q.atoms[O].xyz];q=T[Q.atoms[O].xyz+1];p=T[Q.atoms[O].xyz+2];for(var N=O+1;N<Q.atoms.length;N++){R=T[Q.atoms[N].xyz];d=T[Q.atoms[N].xyz+1];D=T[Q.atoms[N].xyz+2];I=Math.pow(w-R,2)+Math.pow(q-d,2)+Math.pow(p-D,2);if(I>P[0]){P[0]=I;P[1]=O;P[2]=N}}}L=Q.atoms[P[1]];o=Q.atoms[P[2]]}this.renderer.camera.reset();if(this.canvas.atomCORset){this.resetCOR()}if(!L||!o||L==n||n==o){var w=T[n.xyz];var q=T[n.xyz+1];var p=T[n.xyz+2];this.renderer.camera.x=-w+this.COR[0];this.renderer.camera.y=-q+this.COR[1];this.renderer.camera.z=-p-molmil.configBox.zNear+this.COR[2]-2;return}var l,h,g,G=[0,0,0];var l=[Q.chain.modelsXYZ[this.renderer.modelId][L.xyz],Q.chain.modelsXYZ[this.renderer.modelId][L.xyz+1],Q.chain.modelsXYZ[this.renderer.modelId][L.xyz+2]];var h=[Q.chain.modelsXYZ[this.renderer.modelId][o.xyz],Q.chain.modelsXYZ[this.renderer.modelId][o.xyz+1],Q.chain.modelsXYZ[this.renderer.modelId][o.xyz+2]];var g=[Q.chain.modelsXYZ[this.renderer.modelId][n.xyz],Q.chain.modelsXYZ[this.renderer.modelId][n.xyz+1],Q.chain.modelsXYZ[this.renderer.modelId][n.xyz+2]];l[0]-=this.avgXYZ[0];l[1]-=this.avgXYZ[1];l[2]-=this.avgXYZ[2];h[0]-=this.avgXYZ[0];h[1]-=this.avgXYZ[1];h[2]-=this.avgXYZ[2];g[0]-=this.avgXYZ[0];g[1]-=this.avgXYZ[1];g[2]-=this.avgXYZ[2];G[0]=g[0]-((l[0]+h[0])*0.5);G[1]=g[1]-((l[1]+h[1])*0.5);G[2]=g[2]-((l[2]+h[2])*0.5);vec3.normalize(G,G);var K=[l[0]-g[0],l[1]-g[1],l[2]-g[2]];vec3.normalize(K,K);var J=[h[0]-g[0],h[1]-g[1],h[2]-g[2]];vec3.normalize(J,J);var H=vec3.cross([0,0,0],K,J);vec3.normalize(H,H);var S=[G[0]*5-g[0],G[1]*5-g[1],G[2]*5-g[2]];var F=vec3.cross([0,0,0],G,H);vec3.normalize(F,F);var E=vec3.cross([0,0,0],F,G);var M=mat4.create();M[0]=F[0];M[4]=F[1];M[8]=F[2];M[1]=E[0];M[5]=E[1];M[9]=E[2];M[2]=-G[0];M[6]=-G[1];M[10]=-G[2];M[12]=-vec3.dot(F,S);M[13]=-vec3.dot(E,S);M[14]=-vec3.dot(G,S);this.renderer.camera.x=-M[12];this.renderer.camera.y=-M[13];this.renderer.camera.z=M[14]-molmil.configBox.zNear;quat.fromMat3(this.renderer.camera.QView,mat3.fromMat4(mat3.create(),M));quat.normalize(this.renderer.camera.QView,this.renderer.camera.QView)};molmil.viewer.prototype.waterToggle=function(g){for(var d=0,h,f;d<this.structures.length;d++){if(!this.structures[d].chains){continue}for(h=0;h<this.structures[d].chains.length;h++){for(f=0;f<this.structures[d].chains[h].atoms.length;f++){if(this.structures[d].chains[h].atoms[f].molecule.water&&(!this.hideHydrogens||this.structures[d].chains[h].atoms[f].element!="H")){this.structures[d].chains[h].atoms[f].display=g}}}}this.hideWaters=!g};molmil.viewer.prototype.hydrogenToggle=function(g){for(var d=0,h,f;d<this.structures.length;d++){if(!this.structures[d].chains){continue}for(h=0;h<this.structures[d].chains.length;h++){for(f=0;f<this.structures[d].chains[h].atoms.length;f++){if(this.structures[d].chains[h].atoms[f].element=="H"||this.structures[d].chains[h].atoms[f].element=="D"){this.structures[d].chains[h].atoms[f].display=g}}}}this.hideHydrogens=!g};molmil.viewer.prototype.restoreDefaultCanvas=function(d){this.canvas=this.defaultCanvas[0];this.renderer=this.defaultCanvas[1]};molmil.getSelectedAtom=function(f,d){f=f||0;d=d||molmil.cli_soup;if(f>=d.atomSelection.length){return}return d.atomSelection[f]};molmil.viewer.prototype.selectObject=function(q,p,d){p=this.canvas.height-p;var h=this.renderer.gl;if(!this.renderer.FBOs.pickingBuffer){this.renderer.FBOs.pickingBuffer=new molmil.FBO(h,this.renderer.width,this.renderer.height);this.renderer.FBOs.pickingBuffer.addTexture("colourBuffer",h.RGBA,h.RGBA);this.renderer.FBOs.pickingBuffer.setup()}else{if(this.renderer.FBOs.pickingBuffer.width!=this.renderer.width||this.renderer.FBOs.pickingBuffer.height!=this.renderer.height){this.renderer.FBOs.pickingBuffer.resize(this.renderer.width,this.renderer.height)}}this.renderer.FBOs.pickingBuffer.bind();this.renderer.renderPicking();var g=new Uint8Array(4);h.readPixels(q,p,1,1,h.RGBA,h.UNSIGNED_BYTE,g);var o=Math.round(vec4.dot([g[0]/255,g[1]/255,g[2]/255,g[3]/255],[1/(255*255*255),1/(255*255),1/255,1])*4228250625);this.renderer.FBOs.pickingBuffer.unbind();if(o!=0){var l=this.atomRef[o];if(l){var n=this.canvas.commandLine?this.canvas.commandLine.environment.console:console;n.log("Clicked on atom: "+l);console.log("Clicked on atom: ",l);if(d&&d.ctrlKey){var s=true;for(var f=0;f<this.atomSelection.length;f++){if(this.atomSelection[f]==l){s=false;break}}if(s){this.atomSelection.push(l)}if(this.atomSelection.length==2){n.log("Distance: ",molmil.calcMMDistance(this.atomSelection[0],this.atomSelection[1],this)," | ",this.atomSelection[0],this.atomSelection[1])}else{if(this.atomSelection.length==3){n.log("Angle: ",molmil.calcMMAngle(this.atomSelection[0],this.atomSelection[1],this.atomSelection[2],this)," | ",this.atomSelection[0],this.atomSelection[1],this.atomSelection[2])}else{if(this.atomSelection.length==4){n.log("Torsion: ",molmil.calcMMTorsion(this.atomSelection[0],this.atomSelection[1],this.atomSelection[2],this.atomSelection[3],this)," | ",this.atomSelection[0],this.atomSelection[1],this.atomSelection[2],this.atomSelection[3])}}}}else{this.atomSelection=[l]}this.onAtomPick(l);this.canvas.renderer.updateSelection()}}else{this.atomSelection=[];this.canvas.renderer.updateSelection()}this.canvas.update=true};molmil.viewer.prototype.loadStructure=function(n,p,s,f){f=f||{};var q=n.substr(-3).toLowerCase()==".gz"&&!f.no_pako_gz;if(q&&!window.hasOwnProperty("pako")){var o=document.getElementsByTagName("head")[0];var l=molmil_dep.dcE("script");l.src=molmil.settings.src+"pako.js";l.soup=this;l.argList=[n,p,s,f];l.onload=function(){molmil_dep.asyncStart(this.soup.loadStructure,this.argList,this.soup,0)};o.appendChild(l);return}var h=new molmil_dep.CallRemote("GET"),d=molmil_dep.getKeyFromObject(f||{},"async",true);h.ASYNC=d;h.target=this;h.gz=q;if(h.gz){h.responseType="arraybuffer"}if(this.onloaderror){h.OnError=this.onloaderror}h.filename=n.substr(n.lastIndexOf("/")+1);if(p==1||(p+"").toLowerCase()=="mmjson"){var g=n;if(h.ASYNC&&!h.gz){h.responseType="json"}h.parse=function(){if(this.gz){var t=JSON.parse(pako.inflate(new Uint8Array(this.request.response),{to:"string"}))}else{var t=h.request.response}if(typeof t!="object"&&t!=null){t=JSON.parse(this.request.responseText)}else{if(t==null){throw""}}return this.target.load_PDBx(t,this.pdbid,this.filename)}}else{if(p==2||(p+"").toLowerCase()=="mmcif"){h.parse=function(){return this.target.load_mmCIF(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseText,this.filename)}}else{if(p==3||(p+"").toLowerCase()=="pdbml"){h.parse=function(){return this.target.load_PDBML(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseXML,this.filename)}}else{if(p==4||(p+"").toLowerCase()=="pdb"){h.parse=function(){return this.target.load_PDB(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseText,this.filename)}}else{if(p==5||(p+"").toLowerCase()=="polygon-xml"){h.parse=function(){return this.target.load_polygonXML(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseXML||this.request.responseText,this.filename,f)}}else{if(p==6||(p+"").toLowerCase()=="polygon-json"){h.ASYNC=true;h.responseType="json";h.parse=function(){var t=this.gz?JSON.parse(pako.inflate(new Uint8Array(this.request.response),{to:"string"})):h.request.response;if(typeof t!="object"&&t!=null){t=JSON.parse(this.request.responseText)}return this.target.load_polygonJSON(t,this.filename)}}else{if(p==7||(p+"").toLowerCase()=="gro"){h.parse=function(){return this.target.load_GRO(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseText,this.filename)}}else{if(p==8||(p+"").toLowerCase()=="mpbf"){h.ASYNC=true;h.responseType="arraybuffer";h.parse=function(){return this.target.load_MPBF(this.request.response,this.filename)}}else{if((p+"").toLowerCase()=="ccp4"){h.ASYNC=true;h.responseType="arraybuffer";h.parse=function(){return this.target.load_ccp4(this.request.response,this.filename,f)}}else{if((p+"").toLowerCase()=="obj"){h.ASYNC=true;h.parse=function(){return this.target.load_obj(this.request.response,this.filename)}}else{if((p+"").toLowerCase()=="mdl"){h.parse=function(){return this.target.load_mdl(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseText,this.filename)}}else{if((p+"").toLowerCase()=="mol2"){h.parse=function(){return this.target.load_mol2(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseText,this.filename)}}else{if((p+"").toLowerCase()=="xyz"){h.parse=function(){return this.target.load_xyz(this.gz?pako.inflate(new Uint8Array(this.request.response),{to:"string"}):this.request.responseText,this.filename,f)}}else{if(p.toLowerCase()=="gromacs-trr"){h.ASYNC=true;h.responseType="arraybuffer";h.parse=function(){return this.target.loadGromacsTRR(this.request.response,this.filename)}}else{if(p.toLowerCase()=="gromacs-xtc"){h.ASYNC=true;h.responseType="arraybuffer";h.parse=function(){return this.target.loadGromacsXTC(this.request.response,this.filename)}}else{if(p.toLowerCase()=="psygene-traj"){h.ASYNC=true;h.responseType="arraybuffer";h.parse=function(){var t=this.request.response;this.target.loadMyPrestoTrj(t,molmil_dep.getKeyFromObject(f||{},"fxcell",null));return this.target.structures}}else{console.log("Unknown format: "+p);return}}}}}}}}}}}}}}}}h.ondone=s;h.OnDone=function(){var t=this.parse();if(!t){return}molmil.safeStartViewer(this.target.canvas);if(s){s(this.target,t)}else{molmil.displayEntry(t,1);molmil.colorEntry(t,1,null,true,this.target)}};h.Send(n)};molmil.toBigEndian32=function(f,o,p,l){var d=new Uint32Array(f,o,p),g,h;for(g=0;g<p;g++){h=d[g];d[g]=(((h&255)<<24)|((h&65280)<<8)|((h>>8)&65280)|((h>>24)&255))}return new l(f,o,p)};molmil.toBigEndian64=function(d,o,p,l){var h=new DataView(d,o,p*8);var f=new Float64Array(p);for(var g=0;g<p;g++){f[g]=h.getFloat64(g*8)}return f};molmil.toBigEndian64_=function(l,h,g,f){var p=new Uint32Array(l,h,g),o,s,q;for(o=0;o<g*2;o+=2){s=p[o];q=p[o+1];p[o+1]=((s&255)<<24)|((s&65280)<<8)|((s>>8)&65280)|((s>>24)&255);p[o]=((q&255)<<24)|((q&65280)<<8)|((q>>8)&65280)|((q>>24)&255)}if(f==Float64Array&&h%8!=0){var d=new DataView(l,h,g);var t=new Float64Array(g);for(o=0;o<g;o++){}}return new f(l,h,g)};molmil.xtc_sizeofint=function(f){var d=1,g=0;while(f>=d&&g<32){g++;d<<=1}return g};molmil.xtc_sizeofints=function(o,p){var l,n,f,h,q=new Uint8Array(32),d,g;f=1;q[0]=1;h=0;for(l=0;l<o;l++){g=0;for(d=0;d<f;d++){g=q[d]*p[l]+g;q[d]=g&255;g>>=8}while(g!=0){q[d++]=g&255;g>>=8}f=d}n=1;f--;while(q[f]>=n){h++;n*=2}return h+f*8};molmil.xtc_decodebits=function(h,g,o){var l,f,d=(1<<o)-1,n=new Uint32Array(h.subarray(1,3));l=h[0];f=0;while(o>=8){n[1]=(n[1]<<8)|g[l++];f|=(n[1]>>n[0])<<(o-8);o-=8}if(o>0){if(n[0]<o){n[0]+=8;n[1]=(n[1]<<8)|g[l++]}n[0]-=o;f|=(n[1]>>n[0])&((1<<o)-1)}f&=d;h[0]=l;h[1]=n[0];h[2]=n[1];return f};molmil.xtc_decodeints=function(f,h,s,n,u,t){var w=new Int32Array(32),o,l,g,d,q;w[1]=w[2]=w[3]=0;g=0;while(n>8){w[g++]=molmil.xtc_decodebits(f,h,8);n-=8}if(n>0){w[g++]=molmil.xtc_decodebits(f,h,n)}for(o=s-1;o>0;o--){q=0;for(l=g-1;l>=0;l--){q=(q<<8)|w[l];d=(q/u[o])|0;w[l]=d;q=q-d*u[o]}t[o]=q}t[0]=w[0]|(w[1]<<8)|(w[2]<<16)|(w[3]<<24)};molmil.viewer.prototype.loadGromacsXTC=function(x){var p=this.structures[0].chains,V=[],U,E=[];for(U=0;U<p.length;U++){V.push([(p[U].atoms[0].AID-1)*3,p[U].atoms.length*3]);p[U].modelsXYZ=[]}this.frameInfo=[];var F=[0,0,0,0,0,0,0,0,0,8,10,12,16,20,25,32,40,50,64,80,101,128,161,203,256,322,406,512,645,812,1024,1290,1625,2048,2580,3250,4096,5060,6501,8192,10321,13003,16384,20642,26007,32768,41285,52015,65536,82570,104031,131072,165140,208063,262144,330280,416127,524287,660561,832255,1048576,1321122,1664510,2097152,2642245,3329021,4194304,5284491,6658042,8388607,10568983,13316085,16777216];var q=9;var T=F.length;var H=0,J,d,A=molmil.toBigEndian32,U,B,S,K,s,w,M,n,R,C,G,h,t,Q,u,I,f,l,y,O,z,o,D,P,N,g,L;var u=new Int32Array(3);while(true){d={};J=molmil.toBigEndian32(x,H,3,Int32Array);H+=12;d.magicnum=J[0];d.natoms=J[1];d.step=J[2];J=A(x,H,10,Float32Array);H+=40;d.time=J[0];d.box=J.subarray(1);if(d.natoms<=9){d.x=A(x,H,d.natoms*3,Float32Array);H+=d.natoms*4}else{u[0]=u[1]=u[2]=0;s=[0,0,0];t=[0,0,0];w=[0,0,0];z=[0,0,0];o=[0,0,0];d.x=new Float32Array(d.natoms*3);g=0;B=molmil.toBigEndian32(x,H,1,Int32Array)[0];H+=4;S=A(x,H,1,Float32Array)[0];H+=4;K=molmil.toBigEndian32(x,H,6,Int32Array);H+=24;s[0]=K[3]-K[0]+1;s[1]=K[4]-K[1]+1;s[2]=K[5]-K[2]+1;if((s[0]|s[1]|s[2])>16777215){w[0]=molmil.xtc_sizeofint(s[0]);w[1]=molmil.xtc_sizeofint(s[1]);w[2]=molmil.xtc_sizeofint(s[2]);M=0}else{M=molmil.xtc_sizeofints(3,s)}n=molmil.toBigEndian32(x,H,1,Int32Array)[0];H+=4;J=n+8;R=(T<J)?T:J;C=R-8;J=n-1;J=(q>J)?q:J;G=(F[J]/2)|0;h=(F[n]/2)|0;t[0]=t[1]=t[2]=F[n];Q=F[R];L=molmil.toBigEndian32(x,H,1,Int32Array)[0];H+=4;L=Math.ceil(L/4)*4;l=1/S;y=0;O=0;I=new Uint8Array(x,H);z[0]=z[1]=z[2]=0;while(O<B){if(M==0){z[0]=molmil.xtc_decodebits(u,I,w[0]);z[1]=molmil.xtc_decodebits(u,I,w[1]);z[2]=molmil.xtc_decodebits(u,I,w[2])}else{molmil.xtc_decodeints(u,I,3,M,s,z)}O++;z[0]+=K[0];z[1]+=K[1];z[2]+=K[2];o[0]=z[0];o[1]=z[1];o[2]=z[2];D=molmil.xtc_decodebits(u,I,1);P=0;if(D==1){y=molmil.xtc_decodebits(u,I,5);P=y%3;y-=P;P--}if(y>0){z[0]=z[1]=z[2]=0;for(N=0;N<y;N+=3){molmil.xtc_decodeints(u,I,3,n,t,z);O++;z[0]+=o[0]-h;z[1]+=o[1]-h;z[2]+=o[2]-h;if(N==0){J=z[0];z[0]=o[0];o[0]=J;J=z[1];z[1]=o[1];o[1]=J;J=z[2];z[2]=o[2];o[2]=J;d.x[g++]=o[0]*l;d.x[g++]=o[1]*l;d.x[g++]=o[2]*l}else{o[0]=z[0];o[1]=z[1];o[2]=z[2]}d.x[g++]=z[0]*l;d.x[g++]=z[1]*l;d.x[g++]=z[2]*l}}else{d.x[g++]=z[0]*l;d.x[g++]=z[1]*l;d.x[g++]=z[2]*l}n+=P;if(P<0){h=G;if(n>q){G=(F[n-1]/2)|0}else{G=0}}else{if(P>0){G=h;h=(F[n]/2)|0}}t[0]=t[1]=t[2]=F[n];if(t[0]==0||t[1]==0||t[2]==0){console.error("(xdrfile error) Undefined error.");return}}H+=L}E.push(d.x);for(U=0;U<V.length;U++){p[U].modelsXYZ.push(d.x.subarray(V[U][0],V[U][0]+V[U][1]))}for(U=0;U<d.natoms*3;U++){d.x[U]*=10}this.frameInfo.push([d.step,d.time]);if(H>=x.byteLength){break}}this.structures[0].number_of_frames=this.structures[0].chains.length?this.structures[0].chains[0].modelsXYZ.length:0;return[this.structures.length?this.structures[0]:{}]};molmil.viewer.prototype.loadGromacsTRR=function(o){var h,n=0,l,p,q,d,w,u,g=[],t;var s=this.structures[0].chains,f=[];for(t=0;t<s.length;t++){f.push([(s[t].atoms[0].AID-1)*3,s[t].atoms.length*3]);s[t].modelsXYZ=[]}this.frameInfo=[];while(true){h={};q=molmil.toBigEndian32(o,n,2,Int32Array);n+=8;h.magicnum=q[0];h.i1=q[1];l=molmil.toBigEndian32(o,n,1,Int32Array)[0];n+=4;h.version=molmil.decodeUtf8(new Uint8Array(o,n,l));n+=l;q=molmil.toBigEndian32(o,n,13,Int32Array);n+=13*4;h.ir_size=q[0];h.e_size=q[1];h.box_size=q[2];h.vir_size=q[3];h.pres_size=q[4];h.top_size=q[5];h.sym_size=q[6];h.x_size=q[7];h.v_size=q[8];h.f_size=q[9];h.natoms=q[10];h.step=q[11];h.nre=q[12];d=h.box_size/9;if(d==8){w=molmil.toBigEndian64;u=Float64Array}else{w=molmil.toBigEndian32;u=Float32Array}q=w(o,n,2,u);n+=2*d;h.time=q[0];h.lam=q[1];if(h.box_size){h.box=w(o,n,9,u);n+=h.box_size}if(h.vir_size){h.vir=w(o,n,9,u);n+=h.vir_size}if(h.pres_size){h.pres=w(o,n,9,u);n+=h.pres_size}if(h.x_size){h.x=w(o,n,h.natoms*3,u);for(t=0;t<h.natoms*3;t++){h.x[t]*=10}n+=h.x_size;g.push(h.x);for(t=0;t<f.length;t++){s[t].modelsXYZ.push(h.x.subarray(f[t][0],f[t][0]+f[t][1]))}}if(h.v_size){n+=h.v_size}if(h.f_size){n+=h.f_size}this.frameInfo.push([h.step,h.time]);if(n>=o.byteLength){break}}this.structures[0].number_of_frames=this.structures[0].chains.length?this.structures[0].chains[0].modelsXYZ.length:0;return[this.structures.length?this.structures[0]:{}]};molmil.viewer.prototype.loadMyPrestoTrj=function(F,C){var t=0,y,G,J,L;this.trajectoryMD=[];var h=[];var I=this.structures[0].chains,u=[];for(L=0;L<I.length;L++){u.push([(I[L].atoms[0].AID-1)*3,I[L].atoms.length*3]);I[L].modelsXYZ=[]}while(true){y=[];Array.prototype.push.apply(y,new Int32Array(F,t,2));t+=8;Array.prototype.push.apply(y,new Float32Array(F,t,7));t+=28;Array.prototype.push.apply(y,new Int32Array(F,t,2));t+=8;Array.prototype.push.apply(y,new Float32Array(F,t,1));t+=4;Array.prototype.push.apply(y,new Int32Array(F,t,2));t+=8;this.trajectoryMD.push(y);G=new Float32Array(F,t,y[13]/4);t+=y[13];t+=4;h.push(G);for(L=0;L<u.length;L++){I[L].modelsXYZ.push(G.subarray(u[L][0],u[L][0]+u[L][1]))}if(t>=F.byteLength){break}}this.structures[0].number_of_frames=this.structures[0].chains.length?this.structures[0].chains[0].modelsXYZ.length:0;if(C&&C.length&&(C[0]!=0||C[1]!=0||C[2]!=0)){var d=this.structures[0];var H,L,E,M,z,s,p,o,x,D,B,A,l,K,w,q=Math.round,N,n,g,f;for(H=0;H<h.length;H++){n=h[H];for(L=0;L<d.chains.length;L++){N=d.chains[L].molecules;for(E=0;E<N.length-1;E++){z=N[E].N||N[E].CA;if(!z){continue}x=N[E+1].N||N[E+1].CA;if(!x){continue}g=(x.AID-1)*3;f=(z.AID-1)*3;K=n[g]-n[f];w=q(K/C[0]);n[f]+=w*C[0];g++;f++;K=n[g]-n[f];w=q(K/C[1]);n[f]+=w*C[1];g++;f++;K=n[g]-n[f];w=q(K/C[2]);n[f]+=w*C[2]}for(E=1;E<N.length;E++){z=N[E].N||N[E].CA;if(!z){continue}x=N[E-1].N||N[E-1].CA;if(!x){continue}g=(x.AID-1)*3;f=(z.AID-1)*3;K=n[g]-n[f];w=q(K/C[0]);n[f]+=w*C[0];g++;f++;K=n[g]-n[f];w=q(K/C[1]);n[f]+=w*C[1];g++;f++;K=n[g]-n[f];w=q(K/C[2]);n[f]+=w*C[2];l=N[E].atoms;for(M=0;M<l.length;M++){g=(z.AID-1)*3;f=(l[M].AID-1)*3;K=n[g]-n[f];w=q(K/C[0]);n[f]+=w*C[0];g++;f++;K=n[g]-n[f];w=q(K/C[1]);n[f]+=w*C[1];g++;f++;K=n[g]-n[f];w=q(K/C[2]);n[f]+=w*C[2]}}}}}return[this.structures.length?this.structures[0]:{}]};molmil.viewer.prototype.loadStructureData=function(h,l,f,d,g){var n;if(l==1||(l+"").toLowerCase()=="mmjson"){n=this.load_PDBx(typeof h=="string"?JSON.parse(h):h,f)}else{if(l==2||(l+"").toLowerCase()=="cif"){n=this.load_mmCIF(h,f)}else{if(l==3||(l+"").toLowerCase()=="pdbml"){n=this.load_PDBML(h,f)}else{if(l==4||(l+"").toLowerCase()=="pdb"){n=this.load_PDB(h,f)}else{if(l==5||(l+"").toLowerCase()=="polygon-xml"){n=this.load_polygonXML(h,f,g)}else{if(l==6||(l+"").toLowerCase()=="polygon-json"){n=this.load_polygonJSON(typeof h=="object"?h:JSON.parse(h),f)}else{if(l==7||(l+"").toLowerCase()=="gro"){n=this.load_GRO(h,f)}else{if(l==8||(l+"").toLowerCase()=="mpbf"){n=this.load_MPBF(h,f)}else{if((l+"").toLowerCase()=="mdl"){n=this.load_mdl(h,f)}else{if((l+"").toLowerCase()=="mol2"){n=this.load_mol2(h,f)}else{if((l+"").toLowerCase()=="xyz"){n=this.load_xyz(h,f,g)}else{if((l+"").toLowerCase()=="ccp4"){n=this.load_ccp4(h,f,g)}else{if((l+"").toLowerCase()=="obj"){n=this.load_obj(h,f,g)}else{if((l+"").toLowerCase()=="psygene-traj"){n=this.loadMyPrestoTrj(h,molmil_dep.getKeyFromObject(g||{},"fxcell",null))}else{if((l+"").toLowerCase()=="gromacs-trr"){n=this.loadGromacsTRR(h)}else{if((l+"").toLowerCase()=="gromacs-xtc"){n=this.loadGromacsXTC(h)}}}}}}}}}}}}}}}}if(!n){return}if(this.canvas){molmil.safeStartViewer(this.canvas)}if(d){d(this,n)}else{if(this.customLoaderFunc){this.customLoaderFunc(this,n)}else{molmil.displayEntry(n,1);molmil.colorEntry(n,1,null,true,this)}}};molmil.viewer.prototype.buildAminoChain=function(d){if(d.isHet){return}if(d.molecules.length==1&&d.molecules[0].xna){d.molecules[0].ligand=d.isHet=true;d.molecules[0].xna=false;delete d.molecules[0].N;delete d.molecules[0].CA;delete d.molecules[0].C;return}var q,p,g,f,h,o,l=d.entry;var n=d.modelsXYZ[0];d.bonds=[];for(q=0;q<d.molecules.length;q++){h=d.molecules[q].xna?64:16;for(p=q+1;p<d.molecules.length;p++){if(d.molecules[q].xna!=d.molecules[p].xna){continue}if(d.molecules[q].C&&d.molecules[p].N){g=d.molecules[q].C.xyz;f=d.molecules[p].N.xyz;dx=n[g]-n[f];dx*=dx;dy=n[g+1]-n[f+1];dy*=dy;dz=n[g+2]-n[f+2];dz*=dz;r=dx+dy+dz;if(r<=3.24){d.molecules[q].next=d.molecules[p];d.molecules[p].previous=d.molecules[q];d.bonds.push([d.molecules[q].C,d.molecules[p].N,1]);break}else{if(d.molecules[p].C&&d.molecules[q].N){g=d.molecules[p].C.xyz;f=d.molecules[q].N.xyz;dx=n[g]-n[f];dx*=dx;dy=n[g+1]-n[f+1];dy*=dy;dz=n[g+2]-n[f+2];dz*=dz;r=dx+dy+dz;if(r<=3.24){d.molecules[q].next=d.molecules[p];d.molecules[p].previous=d.molecules[q];d.bonds.push([d.molecules[q].C,d.molecules[p].N,1]);break}}}}else{if(d.molecules[q].CA&&d.molecules[p].CA){g=d.molecules[q].CA.xyz;f=d.molecules[p].CA.xyz;dx=n[g]-n[f];dx*=dx;dy=n[g+1]-n[f+1];dy*=dy;dz=n[g+2]-n[f+2];dz*=dz;r=dx+dy+dz;if(r<=h){d.molecules[q].next=d.molecules[p];d.molecules[p].previous=d.molecules[q];break}}}}}};molmil.viewer.prototype.buildBondList=function(f,t){var x,w,n,l;var A,y,u,d,h,g,p,o,z=molmil.configBox.vdwR;if(t||f.bonds.length==0){this.buildAminoChain(f)}var s=f.modelsXYZ[0],q=false;f.bondsOK=true;for(x=0;x<f.molecules.length;x++){molmil.buildBondsList4Molecule(f.bonds,f.molecules[x],s);if(f.molecules[x].CA){if(f.molecules[x].name=="CYS"){n=molmil.getAtomFromMolecule(f.molecules[x],"SG");if(!n){continue}for(w=x+1;w<f.molecules.length;w++){if(f.molecules[x].CA){if(f.molecules[w].name!="CYS"){continue}l=molmil.getAtomFromMolecule(f.molecules[w],"SG");if(!l){continue}p=n.xyz;o=l.xyz;A=s[p]-s[o];A*=A;y=s[p+1]-s[o+1];y*=y;u=s[p+2]-s[o+2];u*=u;d=A+y+u;if(d<=5){f.bonds.push([n,l,1]);break}}}}}else{if(f.molecules[x].ligand){for(w=x+1;w<f.molecules.length;w++){if(!f.molecules[w].ligand){continue}for(h=0;h<f.molecules[x].atoms.length;h++){if(f.molecules[x].atoms[h].element=="H"||f.molecules[x].atoms[h].element=="D"){continue}p=f.molecules[x].atoms[h].xyz;for(g=0;g<f.molecules[w].atoms.length;g++){if(f.molecules[w].atoms[g].element=="H"||f.molecules[w].atoms[g].element=="D"){continue}o=f.molecules[w].atoms[g].xyz;A=s[p]-s[o];A*=A;y=s[p+1]-s[o+1];y*=y;u=s[p+2]-s[o+2];u*=u;d=A+y+u;maxDistance=3.24;if(z[f.molecules[x].atoms[h].element]===undefined||z[f.molecules[x].atoms[h].element]>=1.8){if(z[f.molecules[w].atoms[g].element]===undefined||z[f.molecules[w].atoms[g].element]>=1.8){maxDistance=6}else{maxDistance=4.5}}else{if(z[f.molecules[w].atoms[g].element]===undefined||z[f.molecules[w].atoms[g].element]>=1.8){if(z[f.molecules[x].atoms[h].element]===undefined||z[f.molecules[x].atoms[h].element]>=1.8){maxDistance=6}else{maxDistance=4.5}}}if(d<=maxDistance){f.bonds.push([f.molecules[x].atoms[h],f.molecules[w].atoms[g],1])}}}}}}}};molmil.viewer.prototype.getChain=function(f,h){var d=[];for(var g=0;g<f.chains.length;g++){if(f.chains[g].name==h){d.push(f.chains[g])}}return d};molmil.viewer.prototype.getChainAuth=function(f,h){var d=[];for(var g=0;g<f.chains.length;g++){if(f.chains[g].authName==h){d.push(f.chains[g])}}return d};molmil.viewer.prototype.getMolObject4Chain=function(f,h){if(!f instanceof Array){f=[f]}for(var g=0,d;g<f.length;g++){for(d=0;d<f[g].molecules.length;d++){if(f[g].molecules[d].id==h){return f[g].molecules[d]}}}return null};molmil.viewer.prototype.getMolObject4ChainAlt=function(f,g){if(!f instanceof Array){f=[f]}for(var h=0,d;h<f.length;h++){for(d=0;d<f[h].molecules.length;d++){if(f[h].molecules[d].RSID==g){return f[h].molecules[d]}}}return null};molmil.decodeUtf8=function(l){var d="",g=0,o=0,h=0,f=0,n=new Uint8Array(l);if(n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191){g=3}while(g<n.length){o=n[g];if(o<128){d+=String.fromCharCode(o);g++}else{if(o>191&&o<224){if(g+1>=n.length){throw"UTF-8 Decode failed. Two byte character was truncated."}f=n[g+1];d+=String.fromCharCode(((o&31)<<6)|(f&63));g+=2}else{if(g+2>=n.length){throw"UTF-8 Decode failed. Multi byte character was truncated."}f=n[g+1];c3=n[g+2];d+=String.fromCharCode(((o&15)<<12)|((f&63)<<6)|(c3&63));g+=3}}}return d};molmil.viewer.prototype.load_obj=function(D,w,z){if(!z){z={solid:true}}D=D.split("\n");var A,y;var h=[],g=[],q=[],u,x=[0,0,0,0];var d=[1e+99,-1e+99,1e+99,-1e+99,1e+99,-1e+99];for(y=0;y<D.length;y++){if(D[y].substr(0,2)=="vn"){A=D[y].split(/\s+/);g.push(u=[parseFloat(A[1]),parseFloat(A[2]),parseFloat(A[3])]);vec3.normalize(u,u)}else{if(D[y].substr(0,1)=="v"){A=D[y].split(/\s+/);h.push(u=[parseFloat(A[1]),parseFloat(A[2]),parseFloat(A[3])]);if(u[0]<d[0]){d[0]=u[0]}if(u[0]>d[1]){d[1]=u[0]}if(u[1]<d[2]){d[2]=u[1]}if(u[1]>d[3]){d[3]=u[1]}if(u[2]<d[4]){d[4]=u[2]}if(u[2]>d[5]){d[5]=u[2]}x[0]+=u[0];x[1]+=u[1];x[2]+=u[2];x[3]+=1}else{if(D[y].substr(0,1)=="f"){A=D[y].split(/\s+/);q.push([parseInt(A[1].split("//")[0])-1,parseInt(A[2].split("//")[0])-1,parseInt(A[3].split("//")[0])-1])}}}}var l=new Float32Array(h.length*7);var f=new Int32Array(q.length*3);var B=new Uint8Array(l.buffer);var y,s=0,C=0;for(y=0;y<h.length;y++,C+=28){l[s++]=h[y][0];l[s++]=h[y][1];l[s++]=h[y][2];l[s++]=g[y][0];l[s++]=g[y][1];l[s++]=g[y][2];B[C+24]=255;B[C+25]=255;B[C+26]=255;B[C+27]=255;s++}s=0;for(y=0;y<q.length;y++){f[s++]=q[y][0];f[s++]=q[y][1];f[s++]=q[y][2]}var t=new molmil.polygonObject({filename:w,COR:x});canvas.molmilViewer.structures.push(t);t.options=[];t.meta.geomRanges=d;var o=molmil.geometry.build_simple_render_program(l,f,canvas.renderer,z);canvas.renderer.programs.push(o);t.programs.push(o);canvas.molmilViewer.calculateCOG();canvas.renderer.initBuffers();canvas.update=true;molmil.safeStartViewer(canvas)};molmil.viewer.prototype.load_ccp4=function(H,I,P){if(!P){P={sigma:1}}var V=new Int32Array(H,0,10);var T=new Float32Array(H,40,6);var S=new Int32Array(H,64,3);var Q=new Float32Array(H,76,3);var O=new Int32Array(H,88,1);var N=new Int32Array(H,92,233);var M=new Float32Array(H,1024,N[0]/4);var L=new Float32Array(H,0,256);if(!P.hasOwnProperty("solid")){P.solid=true}if(!P.hasOwnProperty("sigma")){P.sigma=1}var C=V[0]*V[1]*V[2];var l=new Float32Array(H,1024+N[0],C);if(!P.skipNormalization){var s=1/new Float32Array(H,54*4,1)[0];for(var K=0;K<C;K++){l[K]=(l[K]-Q[2])*s}}var q=[S[0]-1,S[1]-1,S[2]-1];var B=[T[q[0]]/V[q[0]+7],T[q[1]]/V[q[1]+7],T[q[2]]/V[q[2]+7]];var x=[B[0]*V[q[0]+4],B[1]*V[q[1]+4],B[2]*V[q[2]+4]];var G=function(d,g,f){return arguments[q[0]]+V[0]*(arguments[q[1]]+V[1]*arguments[q[2]])};var A=polygonize([V[q[0]],V[q[1]],V[q[2]]],l,P.sigma,G);var B=[T[0]/V[0+7],T[1]/V[1+7],T[2]/V[2+7]];for(K=0;K<A.vertices.length;K++){A.vertices[K][0]=((A.vertices[K][0])*B[0])+x[0];A.vertices[K][1]=((A.vertices[K][1])*B[1])+x[1];A.vertices[K][2]=((A.vertices[K][2])*B[2])+x[2]}molmil.taubinSmoothing(A.vertices,A.faces,0.5,-0.53,10);var K,o,N,D=[],W;for(K=0;K<A.vertices.length;K++){D.push([0,0,0])}for(K in A.vertexIndex){W=D[A.vertexIndex[K][0]];o=A.vertexIndex[K][1];for(N=0;N<o.length;N++){vec3.add(W,W,A.face_normals[o[N]])}vec3.normalize(W,W)}A.normals=D;molmil.taubinSmoothing(A.normals,A.faces,0.5,-0.53,10);var w=new Float32Array(A.vertices.length*7);var u=new Int32Array(A.faces.length*3);var U=new Uint8Array(w.buffer);var J=[0,0,0,0],R=[0,0,0];var t=[1e+99,-1e+99,1e+99,-1e+99,1e+99,-1e+99];for(var z=0,p,n;z<A.vertices.length;z++){p=z*7;n=z*28;w[p+3]=D[z][0];w[p+4]=D[z][1];w[p+5]=D[z][2];w[p]=A.vertices[z][0];w[p+1]=A.vertices[z][1];w[p+2]=A.vertices[z][2];J[0]+=A.vertices[z][0];J[1]+=A.vertices[z][1];J[2]+=A.vertices[z][2];J[3]+=1;if(w[p]<t[0]){t[0]=w[p]}if(w[p]>t[1]){t[1]=w[p]}if(w[p+1]<t[2]){t[2]=w[p+1]}if(w[p+1]>t[3]){t[3]=w[p+1]}if(w[p+2]<t[4]){t[4]=w[p+2]}if(w[p+2]>t[5]){t[5]=w[p+2]}U[n+24]=255;U[n+25]=255;U[n+26]=255;U[n+27]=255}var E=new molmil.polygonObject({filename:I,COR:J});canvas.molmilViewer.structures.push(E);E.options=[];E.meta.geomRanges=t;for(var K=0,F;K<A.faces.length;K++){F=K*3;u[F]=A.faces[K][0];u[F+1]=A.faces[K][1];u[F+2]=A.faces[K][2]}var y=molmil.geometry.build_simple_render_program(w,u,canvas.renderer,P);canvas.renderer.programs.push(y);E.programs.push(y);canvas.molmilViewer.calculateCOG();canvas.renderer.initBuffers();canvas.update=true;molmil.safeStartViewer(canvas)};molmil.viewer.prototype.load_MPBF=function(p,d){var o=0;while(o<p.byteLength){var w=[0,0,0,0];var z=new Int32Array(p,o,4);o+=16;var f=molmil.decodeUtf8(new Uint8Array(p,o,z[3]));o+=z[3]+(z[3]%4!=0?4-z[3]%4:0);var h=o;var x=new Float32Array(p,o,7*z[1]);o+=7*z[1]*4;var A=new Int32Array(p,o,z[2]*3);o+=z[2]*3*4;var n=[1e+99,-1e+99,1e+99,-1e+99,1e+99,-1e+99];for(var s=0;s<x.length;s+=7){w[0]+=x[s];w[1]+=x[s+1];w[2]+=x[s+2];w[3]++;if(x[s]<n[0]){n[0]=x[s]}if(x[s]>n[1]){n[1]=x[s]}if(x[s+1]<n[2]){n[2]=x[s+1]}if(x[s+1]>n[3]){n[3]=x[s+1]}if(x[s+2]<n[4]){n[4]=x[s+2]}if(x[s+2]>n[5]){n[5]=x[s+2]}}var l=new molmil.polygonObject({filename:d,COR:w});this.structures.push(l);l.options=[];l.meta.geomRanges=n;var y=this.renderer;var u=y.gl;var t=u.createBuffer();u.bindBuffer(u.ARRAY_BUFFER,t);u.bufferData(u.ARRAY_BUFFER,x,u.STATIC_DRAW);var g=u.createBuffer();u.bindBuffer(u.ELEMENT_ARRAY_BUFFER,g);u.bufferData(u.ELEMENT_ARRAY_BUFFER,A,u.STATIC_DRAW);var q={};q.gl=y.gl;q.renderer=y;q.nElements=z[2]*3;q.vertexBuffer=t;q.indexBuffer=g;q.angle=y.angle;q.shader=y.shaders.standard_alpha;q.attributes=y.shaders.standard_alpha.attributes;q.status=true;q.render=function(B,C){if(!this.status){return}var D=mat3.create();mat3.normalFromMat4(D,B);this.gl.useProgram(this.shader.program);this.gl.uniformMatrix4fv(this.shader.uniforms.modelViewMatrix,false,B);this.gl.uniformMatrix3fv(this.shader.uniforms.normalMatrix,false,D);this.gl.uniformMatrix4fv(this.shader.uniforms.projectionMatrix,false,this.renderer.projectionMatrix);this.gl.uniform3f(this.shader.uniforms.COR,C[0],C[1],C[2]);this.gl.uniform1f(this.shader.uniforms.focus,this.renderer.fogStart);this.gl.uniform1f(this.shader.uniforms.fogSpan,this.renderer.fogStart+(this.renderer.clearCut*2));this.gl.uniform4f(this.shader.uniforms.backgroundColor,molmil.configBox.BGCOLOR[0],molmil.configBox.BGCOLOR[1],molmil.configBox.BGCOLOR[2],1);this.render_internal()};q.render_internal=function(){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);molmil.resetAttributes(this.gl);molmil.bindAttribute(this.gl,this.attributes.in_Position,3,this.gl.FLOAT,false,28,0);molmil.bindAttribute(this.gl,this.attributes.in_Normal,3,this.gl.FLOAT,false,28,12);molmil.bindAttribute(this.gl,this.attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,28,24);molmil.clearAttributes(this.gl);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer);if(this.angle){var C=0,B;while(true){B=Math.min(this.nElements-C,3000000);if(B<1){break}this.gl.drawElements(this.gl.TRIANGLES,B,u.INDEXINT,C*4);C+=B}}else{this.gl.drawElements(this.gl.TRIANGLES,this.nElements,u.INDEXINT,0)}};q.renderPicking=function(){};y.programs.push(q);l.programs.push(q);l.options.push([f,q]);if(molmil.configBox.skipClearGeometryBuffer){l.data=l.data||{};l.data.vertexBuffer=x;l.data.indexBuffer=A;l.data.vertexSize=7;l.data.vertices_offset=h}}this.renderer.initBD=true;this.calculateCOG();if(molmil.geometry.onGenerate){molmil_dep.asyncStart(molmil.geometry.onGenerate[0],molmil.geometry.onGenerate[1],molmil.geometry.onGenerate[2],0)}return l};molmil.viewer.prototype.load_xyz=function(l,d,h){h=h||{};var n,f,o,s,q,p,g;l=l.split("\n");for(i=0;i<l.length;i++){l[i]=molmil_dep.Strip(l[i]);if(!l[i].length){continue}l[i]=l[i].split(/[ ,\t]+/);if(l[i].length==1&&l[i]&&!isNaN(parseInt(l[i][0],10))){this.structures.push(n=new molmil.entryObject({id:d}));n.chains.push(f=new molmil.chainObject("",n));f.CID=this.CID++;this.chains.push(f);f.molecules.push(g=new molmil.molObject("???",0,f));if(h.skipBonds){f.bondsOK=true}continue}o=l[i][0];s=parseFloat(l[i][1]);q=parseFloat(l[i][2]);p=parseFloat(l[i][3]);Xpos=f.modelsXYZ[0].length;f.modelsXYZ[0].push(s,q,p);g.atoms.push(atom=new molmil.atomObject(Xpos,o,o,g,f));atom.AID=this.AID++;this.atomRef[atom.AID]=atom;f.atoms.push(atom)}this.calculateCOG();molmil.resetColors(n,this);return n};molmil.viewer.prototype.load_mol2=function(G,C){G=G.split("\n");var D,H="",w=false,d=[],n=false,A=[],E=false,B={},F,f;for(D=0;D<G.length;D++){if(G[D].substr(0,9).toUpperCase()=="@<TRIPOS>"){w=false;n=false;E=false}if(w){d.push(G[D])}if(n){A.push(G[D])}if(E){F=G[D].trim().split(/[ ,]+/);B[parseInt(F[0])]=F[1]}if(G[D].substr(0,17).toUpperCase()=="@<TRIPOS>MOLECULE"){H=G[D+1].trim()}else{if(G[D].substr(0,13).toUpperCase()=="@<TRIPOS>ATOM"){w=true}else{if(G[D].substr(0,13).toUpperCase()=="@<TRIPOS>BOND"){n=true}else{if(G[D].substr(0,21).toUpperCase()=="@<TRIPOS>SUBSTRUCTURE"){E=true}}}}}var u,t,q,g,l,p,h,o,s;this.structures.push(f=new molmil.entryObject({id:C}));f.chains.push(o=new molmil.chainObject("",f));o.CID=this.CID++;for(D=0;D<d.length;D++){F=d[D].trim().split(/[ ,]+/);g=F[1];u=parseFloat(F[2]);t=parseFloat(F[3]);q=parseFloat(F[4]);l=F.length>5?F[5]:"";p=F.length>5?F[6]:"";if(p!=h){o.molecules.push(s=new molmil.molObject(molmil_dep.getKeyFromObject(B,p,p),p,o));s.MID=this.MID++;h=p}Xpos=o.modelsXYZ[0].length;o.modelsXYZ[0].push(u,t,q);s.atoms.push(atom=new molmil.atomObject(Xpos,g,l.split(".")[0],s,o));o.atoms.push(atom);atom.display=true;atom.AID=this.AID++;this.atomRef[atom.AID]=atom}this.calculateCOG();for(D=0;D<A.length;D++){F=A[D].trim().split(/[ ,]+/);if(F[0]==""){continue}a1=parseInt(F[1])-1;a2=parseInt(F[2])-1;if(F[3]=="ar"){F[3]=2}if(F[3]=="am"){F[3]=1}bt=parseInt(F[3]);o.bonds.push([o.atoms[a1],o.atoms[a2],bt])}o.bondsOK=true;this.chains.push(o);molmil.resetColors(f,this);return f};molmil.viewer.prototype.load_mdl=function(F,w){F=F.split("\n");var H=F[0].trim()||w,h=0,d;this.structures.push(d=new molmil.entryObject({id:w}));while(true){if(h+3>=F.length){break}var g=F[h+3].match(/\S+/g);var u=parseInt(g[0]),t=parseInt(g[1]),A,d,l,q,s,p,o,n,f,G,E,D;d.chains.push(l=new molmil.chainObject("",d));l.CID=this.CID++;l.molecules.push(q=new molmil.molObject(H,1,l));q.MID=this.MID++;var C={};for(A=4;A<u+4;A++){s=parseFloat(F[h+A].substring(0,11).trim());p=parseFloat(F[h+A].substring(11,21).trim());o=parseFloat(F[h+A].substring(21,31).trim());f=F[h+A].substring(31,35).trim();if(C[f]===undefined){C[f]=1}else{C[f]++}n=l.modelsXYZ[0].length;l.modelsXYZ[0].push(s,p,o);q.atoms.push(atom=new molmil.atomObject(n,f+C[f],f,q,l));l.atoms.push(atom);atom.display=true;atom.AID=this.AID++;this.atomRef[atom.AID]=atom}for(A=u+4;A<u+4+t;A++){g=F[h+A].trim().split(/[ ,]+/);G=parseInt(g[0])-1;E=parseInt(g[1])-1;D=parseInt(g[2]);l.bonds.push([q.atoms[G],q.atoms[E],D])}l.bondsOK=true;this.chains.push(l);h+=4+u+t;while(true){h++;try{if(F[h].trim()=="M  END"){break}}catch(B){break}}h+=2}this.calculateCOG();molmil.resetColors(d,this);return d};molmil.viewer.prototype.load_GRO=function(V,L){V=V.trim().split("\n");var A=null;var o=null;var E=null;var H=null;var l,M;var s,T,g,U,F,D,C,t,n,N,P,J,q,p,K,S;var G=[];var O=[];var f=[];var d=null,B,I;this.structures.push(d=new molmil.entryObject({id:L}));s="";d.chains.push(A=new molmil.chainObject(s,d));A.CID=this.CID++;o=s;H=null;for(M=2;M<V.length-1;M++){T=V[M].substring(0,5).trim();g=V[M].substring(11,15).trim();U=V[M].substring(5,11).trim();F=parseFloat(V[M].substring(20,28).trim())*10;D=parseFloat(V[M].substring(28,36).trim())*10;C=parseFloat(V[M].substring(36,44).trim())*10;if(T!=H){A.molecules.push(E=new molmil.molObject(U,T,A));E.MID=this.MID++;H=T}for(t=0;t<g.length;t++){if(!molmil_dep.isNumber(g[t])){break}}if(g.length>1&&!molmil_dep.isNumber(g[1])&&g[1]==g[1].toLowerCase()){n=g.substring(t,t+2)}else{n=g.substring(t,t+1)}B=A.modelsXYZ[0].length;A.modelsXYZ[0].push(F,D,C);E.atoms.push(l=new molmil.atomObject(B,g,n,E,A));if(!molmil.AATypes.hasOwnProperty(E.name.substr(0,3))){if(E.name=="HOH"||E.name=="DOD"||E.name=="WAT"||E.name=="SOL"){E.water=true;E.ligand=false;l.display=false}else{if(l.atomName=="P"){E.N=l;E.xna=true;E.ligand=false;if(!E.CA){A.isHet=false;E.CA=l}}else{if(l.atomName=="C1'"){A.isHet=false;E.CA=l;E.xna=true;E.ligand=false}else{if(l.atomName=="O3'"){E.C=l;E.xna=true;E.ligand=false}}}}}else{if(l.atomName=="N"){E.N=l;E.ligand=false}else{if(l.atomName=="CA"){E.CA=l;E.ligand=false}else{if(l.atomName=="C"){A.isHet=false;E.C=l;E.ligand=false}else{if(l.atomName=="O"){E.O=l;E.ligand=false}}}}}if(l.element=="H"||l.element=="D"){l.display=false}A.atoms.push(l);l.AID=this.AID++;this.atomRef[l.AID]=l}this.calculateCOG();for(S=0;S<d.chains.length;S++){this.buildAminoChain(d.chains[S])}var R=[],u,w,h;for(S=0;S<d.chains.length;S++){A=d.chains[S];u=A,w=A.molecules.length;for(h=0;h<w;h++){A.molecules[h].chain_alt=A.molecules[h].chain;A.molecules[h].chain=u;if(((!A.molecules[h].next&&h<w-1)||(!A.molecules[h].previous&&h!=0))&&(!(A.molecules[h].water||A.molecules[h].ligand)||(h&&A.molecules[h-1].name!=A.molecules[h].name))){u=new molmil.chainObject(molmil_dep.Strip(u.name),u.entry);u.isHet=false;R.push(u);if(!A.molecules[h].previous){A.molecules[h].chain=u}}}}if(R.length){Array.prototype.push.apply(d.chains,R);var Q=[];for(S=0;S<d.chains.length;S++){d.chains[S].name=(S+1)+"";Array.prototype.push.apply(Q,d.chains[S].molecules);d.chains[S].molecules=[];d.chains[S].modelsXYZ_old=d.chains[S].modelsXYZ;d.chains[S].modelsXYZ=[];for(h=0;h<d.chains[S].modelsXYZ_old.length;h++){d.chains[S].modelsXYZ.push([])}d.chains[S].atoms=[]}for(h=0;h<Q.length;h++){Q[h].chain.molecules.push(Q[h]);for(M=0;M<Q[h].atoms.length;M++){l=Q[h].atoms[M].xyz;for(S=0;S<Q[h].chain_alt.modelsXYZ_old.length;S++){Q[h].chain.modelsXYZ[S].push(Q[h].chain_alt.modelsXYZ_old[S][l],Q[h].chain_alt.modelsXYZ_old[S][l+1],Q[h].chain_alt.modelsXYZ_old[S][l+2])}Q[h].atoms[M].xyz=Q[h].chain.modelsXYZ[0].length-3;Q[h].atoms[M].chain=Q[h].chain}Array.prototype.push.apply(Q[h].chain.atoms,Q[h].atoms);delete Q[h].chain_alt}for(S=0;S<d.chains.length;S++){delete d.chains[S].modelsXYZ_old}for(S=0;S<d.chains.length;S++){if(d.chains[S].molecules.length==0){d.chains.splice(S,1);S--;continue}if(d.chains[S].molecules[0].water||d.chains[S].molecules[0].ligand){d.chains[S].name=(d.chains[S].name?d.chains[S].name+" - ":"")+d.chains[S].molecules[0].name;d.chains[S].isHet=true}}}for(S=0;S<d.chains.length;S++){this.chains.push(d.chains[S])}for(S=0;S<d.chains.length;S++){this.ssAssign(d.chains[S])}molmil.resetColors(d,this);return d};molmil.viewer.prototype.load_PDB=function(U,C){var t=null;var Q=null;var X=null;var F=null;var d,S;var U=U.split("\n");var O,E,w,h,M,I,G,N,q,u,l,n,f,R,H,V;var D=[];var A=[];var s=[];var K=null,J,B;for(S=0;S<U.length;S++){if((U[S].substring(0,5)=="MODEL"&&t)||!K){if(K){break}this.structures.push(K=new molmil.entryObject({id:C}));B=U[S].substr(5).trim();Q=F=null}if(U[S].substring(0,4)=="ATOM"||U[S].substring(0,6)=="HETATM"){O=U[S].substring(21,22).trim();E=U[S].substring(22,28).trim();w=U[S].substring(11,16).trim();h=U[S].substring(17,21).trim();M=parseFloat(U[S].substring(30,38).trim());I=parseFloat(U[S].substring(38,46).trim());G=parseFloat(U[S].substring(46,54).trim());for(N=0;N<w.length;N++){if(!molmil_dep.isNumber(w[N])){break}}if(w.length>1&&!molmil_dep.isNumber(w[1])&&w[1]==w[1].toLowerCase()){q=w.substring(N,N+2)}else{q=w.substring(N,N+1)}if(O!=Q){this.chains.push(t=new molmil.chainObject(O,K));K.chains.push(t);t.CID=this.CID++;Q=O;F=null}if(E!=F){t.molecules.push(X=new molmil.molObject(h,E,t));X.MID=this.MID++;F=E}J=t.modelsXYZ[0].length;t.modelsXYZ[0].push(M,I,G);X.atoms.push(d=new molmil.atomObject(J,w,q,X,t));if(U[S].substr(0,4)!="ATOM"||!molmil.AATypes.hasOwnProperty(X.name.substr(0,3))){if(X.name=="HOH"||X.name=="DOD"||X.name=="WAT"||X.name=="SOL"){X.water=true;X.ligand=false;d.display=false}else{if(d.atomName=="P"){X.N=d;X.xna=true;X.ligand=false;if(!X.CA){t.isHet=false;X.CA=d}}else{if(d.atomName=="C1'"){t.isHet=false;X.CA=d;X.xna=true;X.ligand=false}else{if(d.atomName=="O3'"){X.C=d;X.xna=true;X.ligand=false}}}}}else{if(d.atomName=="N"){X.N=d;X.ligand=false}else{if(d.atomName=="CA"){X.CA=d;X.ligand=false}else{if(d.atomName=="C"){t.isHet=false;X.C=d;X.ligand=false}else{if(d.atomName=="O"){X.O=d;X.ligand=false}}}}}if(d.element=="H"||d.element=="D"){d.display=false}t.atoms.push(d);d.AID=this.AID++;this.atomRef[d.AID]=d}}var o=0,p;for(;S<U.length;S++){if(U[S].substring(0,5)=="MODEL"){Q=o=-1}if(U[S].substring(0,4)=="ATOM"||U[S].substring(0,6)=="HETATM"){O=U[S].substring(21,22).trim();M=parseFloat(U[S].substring(30,38).trim());I=parseFloat(U[S].substring(38,46).trim());G=parseFloat(U[S].substring(46,54).trim());if(O!=Q){Q=O;o+=1;K.chains[o].modelsXYZ.push(p=[])}p.push(M,I,G)}}K.number_of_frames=K.chains.length?K.chains[0].modelsXYZ.length:0;this.calculateCOG();for(V=0;V<K.chains.length;V++){this.buildAminoChain(K.chains[V])}var L=[],W,g,T;for(V=0;V<K.chains.length;V++){t=K.chains[V];W=t,g=t.molecules.length;for(T=0;T<g;T++){t.molecules[T].chain_alt=t.molecules[T].chain;t.molecules[T].chain=W;if(((!t.molecules[T].next&&T<g-1)||(!t.molecules[T].previous&&T!=0))&&(!(t.molecules[T].water||t.molecules[T].ligand)||(T&&t.molecules[T-1].name!=t.molecules[T].name))){W=new molmil.chainObject(molmil_dep.Strip(W.name),W.entry);W.isHet=false;L.push(W);if(!t.molecules[T].previous){t.molecules[T].chain=W}}}}if(L.length){Array.prototype.push.apply(this.chains,L);Array.prototype.push.apply(K.chains,L);var P=[];for(V=0;V<K.chains.length;V++){Array.prototype.push.apply(P,K.chains[V].molecules);K.chains[V].molecules=[];K.chains[V].modelsXYZ_old=K.chains[V].modelsXYZ;K.chains[V].modelsXYZ=[];for(T=0;T<K.chains[V].modelsXYZ_old.length;T++){K.chains[V].modelsXYZ.push([])}K.chains[V].atoms=[]}for(T=0;T<P.length;T++){P[T].chain.molecules.push(P[T]);for(S=0;S<P[T].atoms.length;S++){d=P[T].atoms[S].xyz;for(V=0;V<P[T].chain_alt.modelsXYZ_old.length;V++){if(V>=P[T].chain.modelsXYZ.length){P[T].chain.modelsXYZ.push([])}P[T].chain.modelsXYZ[V].push(P[T].chain_alt.modelsXYZ_old[V][d],P[T].chain_alt.modelsXYZ_old[V][d+1],P[T].chain_alt.modelsXYZ_old[V][d+2])}P[T].atoms[S].xyz=P[T].chain.modelsXYZ[0].length-3;P[T].atoms[S].chain=P[T].chain}Array.prototype.push.apply(P[T].chain.atoms,P[T].atoms);delete P[T].chain_alt}for(V=0;V<K.chains.length;V++){delete K.chains[V].modelsXYZ_old}for(V=0;V<K.chains.length;V++){if(K.chains[V].molecules.length==0){K.chains.splice(V,1);V--;continue}if(K.chains[V].molecules[0].water||K.chains[V].molecules[0].ligand){K.chains[V].name=(K.chains[V].name?K.chains[V].name+" - ":"")+K.chains[V].molecules[0].name;K.chains[V].isHet=true}}}for(V=0;V<K.chains.length;V++){this.ssAssign(K.chains[V])}molmil.resetColors(K,this);return K};molmil.viewer.prototype.calcZ=function(d){var g=d;d=d||this.geomRanges;var f=Math.max(Math.abs(d[0]),Math.abs(d[1]),Math.abs(d[2]),Math.abs(d[3]),Math.abs(d[4]),Math.abs(d[5]));if(g){this.renderer.maxRange=(Math.max(Math.abs(d[1]-d[0]),Math.abs(d[3]-d[2]),Math.abs(d[5]-d[4]))*0.5)-molmil.configBox.zNear-5}if(molmil.configBox.stereoMode){return -(f*molmil.configBox.zFar/9000)-molmil.configBox.zNear-1}if(molmil.configBox.projectionMode==1){return -(f*molmil.configBox.zFar/3000)-molmil.configBox.zNear-1}else{return -((f/Math.min(this.renderer.width,this.renderer.height))*molmil.configBox.zFar*(0.625))-molmil.configBox.zNear-1}};molmil.viewer.prototype.load_polygonJSON=function(n,f,o){o=o||{};var z=n.vertices||[],w=n.triangles_lists||[],A=n.lines_lists||[],l=[],g=[],u;var x=[0,0,0,0];if(n.hasOwnProperty("vertices2")){for(var t=0;t<n.vertices2.length;t++){n.vertices2[t].splice(3,0,0,0,0)}Array.prototype.push.apply(z,n.vertices2)}for(var t=0,s;t<w.length;t++){u=[];for(s=0;s<w[t].length;s++){u.push(w[t][s][0],w[t][s][1],w[t][s][2])}if(u.length){g.push(u.unique())}}for(var t=0;t<A.length;t++){u=[];for(s=0;s<A[t].length;s++){u.push(A[t][s][0],A[t][s][1])}if(u.length){u.unique();l.push(u)}}for(var t=0;t<z.length;t++){x[0]+=z[t][0];x[1]+=z[t][1];x[2]+=z[t][2];x[3]+=1;z[t][6]*=255;z[t][7]*=255;z[t][8]*=255}var q=0,y=0,t,s,d=0,h=0;for(t=0;t<g.length;t++){d+=g[t].length;h+=w[t].length}for(t=0;t<l.length;t++){q+=l[t].length;y+=A[t].length}if(!q&&!d){return null}var p=new molmil.polygonObject({filename:f,COR:x});this.structures.push(p);this.processPolygon3D(p,z,q,y,l,A,d,h,g,w,o);this.renderer.initBD=true;return p};molmil.viewer.prototype.processPolygon3D=function(B,h,E,x,C,f,z,q,K,y,J){var s,A,w,G=this.renderer.gl;var H,F,u,l,I,d,M={};var g=J.alpha||255;if(E){var t=new Float32Array(E*4),p=new Uint8Array(t.buffer);if(molmil.configBox.OES_element_index_uint){var o=new Uint32Array(x*2)}else{var o=new Uint16Array(x*2)}for(H=0,u=0,d=0,l=0;H<C.length;H++){for(F=0;F<C[H].length;F++,l+=16){M[C[H][F]]=u/4;I=h[C[H][F]];t[u++]=I[0];t[u++]=I[1];t[u++]=I[2];p[l+12]=I[6];p[l+13]=I[7];p[l+14]=I[8];p[l+15]=255;u++}for(F=0;F<f[H].length;F++){o[d++]=M[f[H][F][0]];o[d++]=M[f[H][F][1]]}}s=molmil.geometry.build_simple_render_program(t,o,this.renderer,{lines_render:true});this.renderer.programs.push(s);B.programs.push(s)}if(z){var D=new Float32Array(z*7),L=new Uint8Array(D.buffer);if(molmil.configBox.OES_element_index_uint){var n=new Uint32Array(q*3)}else{var n=new Uint16Array(q*3)}M={};if(molmil.configBox.skipClearGeometryBuffer){B.data=B.data||{};B.data.vertexBuffer=D;B.data.indexBuffer=n;B.data.vertexSize=7}for(H=0,u=0,d=0,l=0;H<K.length;H++){for(F=0;F<K[H].length;F++,l+=28){M[K[H][F]]=u/7;I=h[K[H][F]];D[u++]=I[0];D[u++]=I[1];D[u++]=I[2];D[u++]=I[3];D[u++]=I[4];D[u++]=I[5];L[l+24]=I[6];L[l+25]=I[7];L[l+26]=I[8];L[l+27]=g;u++}for(F=0;F<y[H].length;F++){n[d++]=M[y[H][F][0]];n[d++]=M[y[H][F][1]];n[d++]=M[y[H][F][2]]}}s=molmil.geometry.build_simple_render_program(D,n,this.renderer,{solid:true,alphaMode:g!=255});this.renderer.programs.push(s);B.programs.push(s)}this.renderer.initBD=true;this.calculateCOG();if(molmil.geometry.onGenerate){molmil_dep.asyncStart(molmil.geometry.onGenerate[0],molmil.geometry.onGenerate[1],molmil.geometry.onGenerate[2],0)}};molmil.viewer.prototype.load_polygonXML=function(g,B,E){if(typeof g=="string"){var f=new DOMParser();g=f.parseFromString(g,"text/xml")}E=E||{};var t=[],o={},d=[],n=[];var x=[],G=[],H,F;var h=[0,0,0,0],l=[1e+99,-1e+99,1e+99,-1e+99,1e+99,-1e+99];var u=g.documentElement.childNodes,A,C,I,z;for(var D=0;D<u.length;D++){if(u[D].tagName=="vertices"){A=u[D].childNodes;for(C=0;C<A.length;C++){if(A[C].tagName!="vertex"){continue}I=A[C].getAttribute("image").trim().split(/\s+/);for(z=0;z<9;z++){I[z]=parseFloat(I[z])}o[A[C].getAttribute("id")]=n.length;h[0]+=I[0];h[1]+=I[1];h[2]+=I[2];h[3]++;if(I[0]<l[0]){l[0]=I[0]}if(I[0]>l[1]){l[1]=I[0]}if(I[1]<l[2]){l[2]=I[1]}if(I[1]>l[3]){l[3]=I[1]}if(I[2]<l[4]){l[4]=I[2]}if(I[2]>l[5]){l[5]=I[2]}n.push(I)}}else{if(u[D].tagName=="triangle_array"){A=u[D].childNodes;H=[];F=[];for(C=0;C<A.length;C++){if(A[C].tagName!="triangle"){continue}I=A[C].getAttribute("vertex").trim().split(/\s+/);for(z=0;z<3;z++){I[z]=o[I[z]]}F.push(I);H.push(I[0],I[1],I[2])}if(H.length){G.push(H.unique());t.push(F)}}else{if(u[D].tagName=="quad_array"){A=u[D].childNodes;H=[];F=[];for(C=0;C<A.length;C++){if(A[C].tagName!="quad"){continue}I=A[C].getAttribute("vertex").trim().split(/\s+/);for(z=0;z<4;z++){I[z]=o[I[z]]}F.push([I[0],I[1],I[2]]);H.push(I[0],I[1],I[2]);F.push([I[0],I[2],I[3]]);H.push(I[0],I[2],I[3])}if(H.length){G.push(H.unique());t.push(F)}}else{if(u[D].tagName=="line_array"){A=u[D].childNodes;H=[];F=[];for(C=0;C<A.length;C++){if(A[C].tagName!="line"){continue}I=A[C].getAttribute("vertex").trim().split(/\s+/);for(z=0;z<2;z++){I[z]=o[I[z]]}F.push(I);H.push(I[0],I[1])}if(H.length){x.push(H.unique());d.push(F)}}else{if(u[D].tagName=="polyline_array"){A=u[D].childNodes;H=[];F=[];for(C=0;C<A.length;C++){if(A[C].tagName!="polyline"){continue}I=A[C].getAttribute("vertex").trim().split(/\s+/);for(z=0;z<I.length;z++){I[z]=o[I[z]]}for(z=0;z<I.length-1;z++){F.push([I[z],I[z+1]]);H.push(I[z],I[z+1])}}if(H.length){x.push(H.unique());d.push(F)}}}}}}}var y=0,q=0,D,s=0,p=0;for(D=0;D<G.length;D++){s+=G[D].length;p+=t[D].length}for(D=0;D<x.length;D++){y+=x[D].length;q+=d[D].length}if(!y&&!s){return null}var w=new molmil.polygonObject({filename:B,COR:h,geomRanges:l});this.structures.push(w);this.processPolygon3D(w,n,y,q,x,d,s,p,G,t,E);this.renderer.initBD=true;return w};molmil.viewer.prototype.load_mmCIF=function(f){var d=loadCIF(f);return this.load_PDBx(d)};molmil.viewer.prototype.load_PDBML=function(f){if(typeof f=="string"){var g=new DOMParser();f=g.parseFromString(f,"text/xml")}var d=loadPDBML(f);return this.load_PDBx(d)};molmil.viewer.prototype.load_PDBx=function(au){var ab=Object.keys(au),J=[],aa;for(var ar=0;ar<ab.length;ar++){var o=ab[ar].substr(5).split("-")[0];var B=au[ab[ar]];var g=B.atom_site||B.chem_comp_atom||B.pdbx_chem_comp_model_atom||null;if(!g){continue}var q=B.hasOwnProperty("chem_comp_atom");var T=g.Cartn_x||(g.pdbx_model_Cartn_x_ideal&&g.pdbx_model_Cartn_x_ideal[0]!=null?g.pdbx_model_Cartn_x_ideal:g.model_Cartn_x)||g.model_Cartn_x;var R=g.Cartn_y||(g.pdbx_model_Cartn_y_ideal&&g.pdbx_model_Cartn_x_ideal[0]!=null?g.pdbx_model_Cartn_y_ideal:g.model_Cartn_y)||g.model_Cartn_y;var Q=g.Cartn_z||(g.pdbx_model_Cartn_z_ideal&&g.pdbx_model_Cartn_x_ideal[0]!=null?g.pdbx_model_Cartn_z_ideal:g.model_Cartn_z)||g.model_Cartn_z;var V=g.id;var t=g.auth_seq_id||[];var M=g.auth_comp_id;var E=g.label_seq_id||[];var L=g.label_comp_id||g.comp_id||g.model_id;var n=g.auth_asym_id||[];var l=g.label_asym_id||[];var G=g.label_alt_id||[];var y=g.auth_atom_id||g.atom_id||[];var w=g.label_atom_id||[];var ap=g.type_symbol||[];var ai=g.pdbx_PDB_model_num;var F=null;var ag=null;var ay=null;var X=null;var f;var Z=null,Y,O;var U={};try{for(var am=0;am<B.chem_comp.id.length;am++){if(B.chem_comp.mon_nstd_flag[am]||B.chem_comp.type[am].toLowerCase().indexOf("peptide")!=-1){U[B.chem_comp.id[am]]=true}}U.ACE=U.NME=true}catch(ar){U=molmil.AATypes}for(var ax=0;ax<T.length;ax++){if((ai&&ai[ax]!=O)||!Z){if(Z){break}this.structures.push(Z=new molmil.entryObject({id:o}));O=ai?ai[ax]:0;ag=X=null}if(l[ax]!=ag||!F){this.chains.push(F=new molmil.chainObject(l[ax],Z));Z.chains.push(F);F.authName=n[ax];F.CID=this.CID++;ag=l[ax];X=-1}if((E[ax]||t[ax])!=X||!ay||X==-1){F.molecules.push(ay=new molmil.molObject((L[ax]||M[ax]),(E[ax]||t[ax]),F));ay.RSID=t[ax]||E[ax];ay.MID=this.MID++;X=(E[ax]||t[ax])}Y=F.modelsXYZ[0].length;F.modelsXYZ[0].push(T[ax],R[ax],Q[ax]);ay.atoms.push(f=new molmil.atomObject(Y,y[ax]||w[ax]||"",ap[ax]||"",ay,F));if(!f.element){for(aa=0;aa<f.atomName.length;aa++){if(!molmil_dep.isNumber(f.atomName[aa])){break}}if(f.atomName.length>1&&!molmil_dep.isNumber(f.atomName[1])&&f.atomName[1]==f.atomName[1].toLowerCase()){f.element=f.atomName.substring(aa,aa+2)}else{f.element=f.atomName.substring(aa,aa+1)}}f.label_alt_id=G[ax];if(f.label_alt_id&&f.label_alt_id!="A"){f.display=false}if(q||!U.hasOwnProperty(ay.name)){if(ay.name=="HOH"||ay.name=="DOD"||ay.name=="WAT"){ay.water=true;ay.ligand=false}}else{F.isHet=false;if(f.atomName=="N"){ay.N=f;ay.ligand=false}else{if(f.atomName=="CA"){ay.CA=f;ay.ligand=false}else{if(f.atomName=="C"){ay.C=f;ay.ligand=false}else{if(f.atomName=="O"){ay.O=f;ay.ligand=false;ay.xna=false}else{if(f.atomName=="P"&&!ay.O){ay.N=f;ay.xna=true;ay.ligand=false;if(!ay.CA){ay.CA=f}}else{if(f.atomName=="C1'"&&!ay.O){ay.CA=f;ay.xna=true;ay.ligand=false}else{if(f.atomName=="O3'"&&!ay.O){ay.C=f;ay.xna=true;ay.ligand=false}}}}}}}}F.atoms.push(f);f.AID=this.AID++;this.atomRef[f.AID]=f}J.push(Z);var p=0,s;for(;ax<T.length;ax++){if(ai&&ai[ax]!=O){O=ai?ai[ax]:0;ag=null;p=-1}if(l[ax]!=ag||!F){ag=l[ax];p+=1;if(p>=Z.chains.length){s=[]}else{Z.chains[p].modelsXYZ.push(s=[])}}s.push(T[ax],R[ax],Q[ax])}Z.number_of_frames=Z.chains.length?Z.chains[0].modelsXYZ.length:0;this.calculateCOG();var S=B.chem_comp_bond||B.pdbx_chem_comp_model_bond;if(S){var at={};for(var am=0;am<Z.chains[0].atoms.length;am++){at[Z.chains[0].atoms[am].atomName]=Z.chains[0].atoms[am]}var ae,ad;for(var am=0;am<S.atom_id_1.length;am++){ae=at[S.atom_id_1[am]];ad=at[S.atom_id_2[am]];Z.chains[0].bonds.push([ae,ad,S.value_order[am]=="DOUB"?2:1])}Z.chains[0].bondsOK=true}else{for(var am=0;am<Z.chains.length;am++){this.buildAminoChain(Z.chains[am])}}var ac,W,h,ak,u,K,A;var D=false;var aw=B.struct_conf;if(aw&&T.length){for(var am=0,af;am<aw.id.length;am++){ac=aw.conf_type_id[am];if(ac=="HELX_P"){ac=3}else{if(ac=="TURN_P"){/*ac=4*/continue;}else{continue}}W=aw.beg_label_asym_id[am];h=aw.beg_label_seq_id[am];ak=aw.end_label_asym_id[am];u=aw.end_label_seq_id[am];K=this.getMolObject4Chain(this.getChain(Z,W),h);A=this.getMolObject4Chain(this.getChain(Z,ak),u);while(A){if(K==null){break}K.sndStruc=ac;if(K==A){break}K=K.next}}D=true}var al=B.struct_sheet_range;if(al&&T.length){for(var am=0,af;am<al.beg_label_asym_id.length;am++){W=al.beg_label_asym_id[am];h=al.beg_label_seq_id[am];ak=al.end_label_asym_id[am];u=al.end_label_seq_id[am];K=this.getMolObject4Chain(this.getChain(Z,W),h);A=this.getMolObject4Chain(this.getChain(Z,ak),u);while(A){if(K==null){break}K.sndStruc=2;if(K==A){break}K=K.next}}D=true}if(!D){for(av=0;av<Z.chains.length;av++){this.ssAssign(Z.chains[av])}}var P;if(B.hasOwnProperty("entity_poly")){P=B.entity_poly.entity_id;for(var am=0;am<B.struct_asym.id.length;am++){if(P.indexOf(B.struct_asym.entity_id[am])!=-1){this.poly_asym_ids.push(B.struct_asym.id[am])}}}var H=B.pdbx_struct_oper_list;if(H){var am,C=H.type.length;var z=!H.hasOwnProperty("matrix[1][1]");for(am=0;am<C;am++){mat=mat4.create();mat[0]=H[z?"matrix11":"matrix[1][1]"][am];mat[4]=H[z?"matrix12":"matrix[1][2]"][am];mat[8]=H[z?"matrix13":"matrix[1][3]"][am];mat[12]=H[z?"vector1":"vector[1]"][am];mat[1]=H[z?"matrix21":"matrix[2][1]"][am];mat[5]=H[z?"matrix22":"matrix[2][2]"][am];mat[9]=H[z?"matrix23":"matrix[2][3]"][am];mat[13]=H[z?"vector2":"vector[2]"][am];mat[2]=H[z?"matrix31":"matrix[3][1]"][am];mat[6]=H[z?"matrix32":"matrix[3][2]"][am];mat[10]=H[z?"matrix33":"matrix[3][3]"][am];mat[14]=H[z?"vector3":"vector[3]"][am];if(mat[0]==1&&mat[1]==0&&mat[2]==0&&mat[3]==0&&mat[4]==0&&mat[5]==1&&mat[6]==0&&mat[7]==0&&mat[8]==0&&mat[9]==0&&mat[10]==1&&mat[11]==0&&mat[12]==0&&mat[13]==0&&mat[14]==0&&mat[15]==1){this.BUmatrices[H.id[am]]=["identity operation",mat]}else{this.BUmatrices[H.id[am]]=[H.type[am],mat]}}this.AisB=(!H||!B.pdbx_struct_assembly||(H.id.length==1&&B.pdbx_struct_assembly.id==1));var N=B.pdbx_struct_assembly_gen,aq,ao,an=mat4.create(),aj,ah,I;C=N.assembly_id.length;var x=function(az){ao=[];az=az.split(",");for(aj=0;aj<az.length;aj++){if(az[aj].indexOf("-")!=-1){az[aj]=az[aj].replace("(","").replace(")","").split("-");for(ah=parseInt(az[aj][0]);ah<parseInt(az[aj][1])+1;ah++){ao.push(ah)}}else{ao.push(az[aj].replace("(","").replace(")",""))}}return ao};for(am=0;am<C;am++){if(!this.BUassemblies.hasOwnProperty(N.assembly_id[am])){this.BUassemblies[N.assembly_id[am]]=[]}I=[];if(N.oper_expression[am].indexOf(")(")!=-1){aq=N.oper_expression[am].split(")(");aq[0]=x(aq[0].substr(1));aq[1]=x(aq[1].substr(0,aq[1].length-1));for(aj=0;aj<aq[0].length;aj++){for(ah=0;ah<aq[1].length;ah++){P="combi_"+aq[0][aj]+"_"+aq[1][ah];if(!this.BUmatrices.hasOwnProperty(P)){mat4.multiply(an,this.BUmatrices[aq[0][aj]][1],this.BUmatrices[aq[1][ah]][1]);if(an[0]==1&&an[1]==0&&an[2]==0&&an[3]==0&&an[4]==0&&an[5]==1&&an[6]==0&&an[7]==0&&an[8]==0&&an[9]==0&&an[10]==1&&an[11]==0&&an[12]==0&&an[13]==0&&an[14]==0&&an[15]==1){this.BUmatrices[P]=["identity operation",an]}else{this.BUmatrices[P]=["combined",mat4.clone(an)]}}I.push(P)}}}else{I=x(N.oper_expression[am])}this.BUassemblies[N.assembly_id[am]].push([I,N.asym_id_list[am].split(",")])}}for(var av=0,af,d;av<Z.chains.length;av++){for(af=0;af<Z.chains[av].molecules.length;af++){d=Z.chains[av].molecules[af];if(!d.ligand&&!d.water&&!d.xna&&!molmil.AATypesBase.hasOwnProperty(d.name)){d.weirdAA=true}}}molmil.resetColors(Z,this);this.pdbxData=B;delete B.atom_site;}return J[0]};molmil.viewer.prototype.calculateCOG=function(){if(this.skipCOGupdate){return}this.avgX=0;this.avgY=0;this.avgZ=0;this.stdX=0;this.stdY=0;this.stdZ=0;this.avgXYZ=[0,0,0];this.stdXYZ=[0,0,0];var w=0;var p;var g,o;var z=[];this.geomRanges=[0,0,0,0,0,0],ALTs=[];var t,u,q,C,x,E;for(q=0;q<this.structures.length;q++){t=this.structures[q];if(t instanceof molmil.entryObject){for(C=0;C<t.chains.length;C++){u=t.chains[C];g=u.modelsXYZ[0];for(x=0;x<u.molecules.length;x++){if(!u.molecules[x].display){continue}if(u.molecules[x].ligand||u.molecules[x].water){for(E=0;E<u.molecules[x].atoms.length;E++){o=u.molecules[x].atoms[E].xyz;xyz=[g[o],g[o+1],g[o+2]];this.avgX+=xyz[0];this.avgY+=xyz[1];this.avgZ+=xyz[2];z.push(xyz);w++}}else{p=u.molecules[x].CA;if(p!=null){o=p.xyz;xyz=[g[o],g[o+1],g[o+2]];this.avgX+=xyz[0];this.avgY+=xyz[1];this.avgZ+=xyz[2];z.push(xyz);w+=1}}}}}else{if(t instanceof molmil.polygonObject){this.avgX+=t.meta.COR[0];this.avgY+=t.meta.COR[1];this.avgZ+=t.meta.COR[2];w+=t.meta.COR[3];if(t.meta.hasOwnProperty("geomRanges")){ALTs.push(t.meta.geomRanges,t.meta.COR[3])}}}}if(w==0){return}this.avgX/=w;this.avgY/=w;this.avgZ/=w;var A=1e+99,F=-1e+99,d=1e+99,f=-1e+99,h=1e+99,l=-1e+99;var B,D;for(var y=0;y<z.length;y++){B=z[y][0]-this.avgX;this.stdX+=B*B;if(B<A){A=B}if(B>F){F=B}B=z[y][1]-this.avgY;this.stdY+=B*B;if(B<d){d=B}if(B>f){f=B}B=z[y][2]-this.avgZ;this.stdZ+=B*B;if(B<h){h=B}if(B>l){l=B}}for(var y=0;y<ALTs.length;y+=2){D=ALTs[y][1];B=ALTs[y][0]-this.avgX;this.stdX+=(B*B)*D*0.5;if(B<A){A=B}B=ALTs[y][1]-this.avgX;this.stdX+=(B*B)*D*0.5;if(B>F){F=B}B=ALTs[y][2]-this.avgY;this.stdY+=(B*B)*D*0.5;if(B<d){d=B}B=ALTs[y][3]-this.avgY;this.stdY+=(B*B)*D*0.5;if(B>f){f=B}B=ALTs[y][4]-this.avgZ;this.stdZ+=(B*B)*D*0.5;if(B<h){h=B}B=ALTs[y][5]-this.avgZ;this.stdZ+=(B*B)*D*0.5;if(B>l){l=B}}this.stdX=Math.sqrt(this.stdX/w);this.stdY=Math.sqrt(this.stdY/w);this.stdZ=Math.sqrt(this.stdZ/w);this.avgXYZ=[this.avgX,this.avgY,this.avgZ];this.stdXYZ=[this.stdX,this.stdY,this.stdZ];this.COR=this.avgXYZ;this.geomRanges=[A,F,d,f,h,l]};molmil.viewer.prototype.ssAssign=function(F){var n,l,az=[0,0,0],aw=[0,0,0],at=[0,0,0],aq=[0,0,0],t,q;for(var aj=0;aj<F.molecules.length;aj++){n=F.molecules[aj];t=n.chain;if(n.ligand||n.water||n.name=="PRO"||n.xna){continue}if(n.previous){try{n.NH={xyz:[0,0,0]};az[0]=t.modelsXYZ[0][n.previous.C.xyz];az[1]=t.modelsXYZ[0][n.previous.C.xyz+1];az[2]=t.modelsXYZ[0][n.previous.C.xyz+2];aw[0]=t.modelsXYZ[0][n.previous.O.xyz];aw[1]=t.modelsXYZ[0][n.previous.O.xyz+1];aw[2]=t.modelsXYZ[0][n.previous.O.xyz+2];at[0]=t.modelsXYZ[0][n.N.xyz];at[1]=t.modelsXYZ[0][n.N.xyz+1];at[2]=t.modelsXYZ[0][n.N.xyz+2];vec3.subtract(n.NH.xyz,az,aw);vec3.normalize(n.NH.xyz,n.NH.xyz);vec3.add(n.NH.xyz,n.NH.xyz,at)}catch(ap){n.NH=null}}else{n.NH=true}}var af,ae,ad;var Z=function(x,d){af=d[0]-x[0];ae=d[1]-x[1];ad=d[2]-x[2];return af*af+ae*ae+ad*ad};var p={},f={},u=[],ar;var an,am,G,ai,ac,ag,aa;for(an=0;an<F.molecules.length;an++){n=F.molecules[an];t=n.chain;if(n.ligand||n.water||n.xna){continue}if(!n.previous){u.push(ar=[])}ar.push(n);for(am=an+2;am<F.molecules.length;am++){l=F.molecules[am];q=l.chain;if(l.ligand||l.water||n.xna||!n.N||!l.C||!n.C||!l.N){continue}az[0]=t.modelsXYZ[0][n.N.xyz];az[1]=t.modelsXYZ[0][n.N.xyz+1];az[2]=t.modelsXYZ[0][n.N.xyz+2];aw[0]=q.modelsXYZ[0][l.C.xyz];aw[1]=q.modelsXYZ[0][l.C.xyz+1];aw[2]=q.modelsXYZ[0][l.C.xyz+2];ai=Z(az,aw);if(ai<25&&n.NH&&l.O){ai=Math.sqrt(ai);at[0]=q.modelsXYZ[0][l.O.xyz];at[1]=q.modelsXYZ[0][l.O.xyz+1];at[2]=q.modelsXYZ[0][l.O.xyz+2];ac=Math.sqrt(Z(az,at));if(n.NH==true){ag=ai-1;aa=ac-1}else{ag=Math.sqrt(Z(n.NH.xyz,aw));aa=Math.sqrt(Z(n.NH.xyz,at))}G=0.084*((1/ac)+(1/ag)-(1/aa)-(1/ai))*332;if(G<-0.67){p[n.MID+"-"+l.MID]=G;if(!f.hasOwnProperty(n.MID)){f[n.MID]=[]}f[n.MID].push(l);if(!f.hasOwnProperty(l.MID)){f[l.MID]=[]}f[l.MID].push(n)}}az[0]=t.modelsXYZ[0][n.C.xyz];az[1]=t.modelsXYZ[0][n.C.xyz+1];az[2]=t.modelsXYZ[0][n.C.xyz+2];aw[0]=q.modelsXYZ[0][l.N.xyz];aw[1]=q.modelsXYZ[0][l.N.xyz+1];aw[2]=q.modelsXYZ[0][l.N.xyz+2];ai=Z(aw,az);if(ai<25&&n.O&&l.NH){ai=Math.sqrt(ai);at[0]=t.modelsXYZ[0][n.O.xyz];at[1]=t.modelsXYZ[0][n.O.xyz+1];at[2]=t.modelsXYZ[0][n.O.xyz+2];ac=Math.sqrt(Z(aw,at));if(l.NH==true){ag=ai-1;aa=ac-1}else{ag=Math.sqrt(Z(l.NH.xyz,az));aa=Math.sqrt(Z(l.NH.xyz,at))}G=0.084*((1/ac)+(1/ag)-(1/aa)-(1/ai))*332;if(G<-0.67){p[l.MID+"-"+n.MID]=G;if(!f.hasOwnProperty(n.MID)){f[n.MID]=[]}f[n.MID].push(l);if(!f.hasOwnProperty(l.MID)){f[l.MID]=[]}f[l.MID].push(n)}}}}if(Object.keys(f).length==0){var U=180/Math.PI;var aA=[0,0,0],ax=[0,0,0],au=[0,0,0],aC=[0,0,0],aB=[0,0,0],O=[0,0,0],g;var h=function(x,d,A,z){try{vec3.subtract(aA,d,x);vec3.subtract(ax,A,d);vec3.subtract(au,z,A);vec3.scale(aC,aA,vec3.length(ax));vec3.cross(aB,ax,au);ae=vec3.dot(aC,aB);vec3.cross(O,aA,ax);af=vec3.dot(O,aB);g=Math.atan2(ae,af)*U;if(g<0){g+=360}return g}catch(y){return 0}};var az,aw,at,aq,N,K,J,I,ah,M=[],ay=[];for(var T=0;T<u.length;T++){ar=u[T];M=[],ay=[];for(aj=2;aj<ar.length-1;aj++){az=ar[aj-2].CA;aw=ar[aj-1].CA;at=ar[aj].CA;aq=ar[aj+1].CA;if(!az||!aw||!at||!aq){M.push(0);ay.push(0);continue}az=az.xyz;aw=aw.xyz;at=at.xyz;aq=aq.xyz;N=[F.modelsXYZ[0][az],F.modelsXYZ[0][az+1],F.modelsXYZ[0][az+2]];K=[F.modelsXYZ[0][aw],F.modelsXYZ[0][aw+1],F.modelsXYZ[0][aw+2]];J=[F.modelsXYZ[0][at],F.modelsXYZ[0][at+1],F.modelsXYZ[0][at+2]];I=[F.modelsXYZ[0][aq],F.modelsXYZ[0][aq+1],F.modelsXYZ[0][aq+2]];ah=h(N,K,J,I);if(ah>=10&&ah<=120){M.push(1)}else{if(ah>=120&&ah<=270){M.push(2)}else{M.push(0)}}ay.push(ah)}M.push(0);for(aj=1;aj<ar.length-1;aj++){if(M[aj]==0){if(M[aj-1]==1&&M[aj+1]==1){M[aj]=1}if(M[aj-1]==2&&M[aj+1]==2){M[aj]=2}}}M[0]=M[1]=M[2];M[M.length-1]=M[M.length-2];var s=[-1,0],al;for(aj=0;aj<M.length;aj++){if(M[aj]!=s[1]){if(s[1]!=0&&aj-s[0]<4){for(al=s[0];al<aj;al++){M[al]=0}}s[0]=aj;s[1]=M[aj]}}for(aj=0;aj<ar.length;aj++){if(M[aj]==1){ar[aj].sndStruc=3}else{if(M[aj]==2){ar[aj].sndStruc=2}else{if(M[aj]==3){ar[aj].sndStruc=4}}}}}return}var ab=function(d){return d?d.MID:null};var W,V,o,w;var L=[],av,Y,X,ao,R,Q,H=[],S=false;for(var at=0;at<u.length;at++){L.push(av=[]);for(an=0;an<u[at].length;an++){o=0;W=ab(u[at][an]);Y=X=[at,an];if((p.hasOwnProperty(ab(u[at][an+3])+"-"+W))&&!S&&(H.length<3||p.hasOwnProperty(W+"-"+ab(u[at][an-3])))){o=3;Y=[at,an];X=[at,an+3]}else{if(p.hasOwnProperty(W+"-"+ab(u[at][an-3]))&&H.length>3){o=3;Y=[at,an-3];X=[at,an];S=true}}if(p.hasOwnProperty(ab(u[at][an+5])+"-"+W)&&!S&&(H.length<5||p.hasOwnProperty(W+"-"+ab(u[at][an-5])))){o=5;Y=[at,an];X=[at,an+5]}else{if(p.hasOwnProperty(W+"-"+ab(u[at][an-5]))&&H.length>5){o=5;Y=[at,an-5];X=[at,an];S=true}}if(p.hasOwnProperty(ab(u[at][an+4])+"-"+W)&&!S&&(H.length<4||p.hasOwnProperty(W+"-"+ab(u[at][an-4])))){o=4;Y=[at,an];X=[at,an+4]}else{if(p.hasOwnProperty(W+"-"+ab(u[at][an-4]))&&H.length>3){o=4;Y=[at,an-4];X=[at,an];S=true}}if(H.length&&H[H.length-1]!=o){H=[];S=false}H.push(o);av.push([o,Y,X])}}for(var at=0;at<L.length;at++){av=L[at];w=[];H=[];o=0;for(an=0;an<av.length;an++){if(av[an][0]!=o){if(o==3||o==4||o==5){if((w.length>1&&o!=3)||w.length>2){for(am=w[0][1][1];am<w[w.length-1][2][1];am++){u[at][am].sndStruc=3}}else{if(w.length){H.push([w[0][1][1],w[w.length-1][2][1]])}}}o=0;w=[]}if(av[an][0]){w.push(av[an]);o=av[an][0]}}for(an=0;an<H.length;an++){W=Math.max(0,H[an][0]-1);V=Math.min(u[at].length-1,H[an][1]+1);o=u[at][Math.max(0,H[an][0]-1)].sndStruc==3||u[at][Math.min(u[at].length-1,H[an][1]+1)].sndStruc==3?3:4;for(am=H[an][0];am<H[an][1];am++){u[at][am].sndStruc=o}}}var P;for(var at=0;at<u.length;at++){for(an=0;an<u[at].length;an++){if(u[at][an].sndStruc!=3){ao=null;if(u[at][an].previous&&u[at][an].next){R=f[ab(u[at][an].previous)];Q=f[ab(u[at][an].next)];if(R&&Q){for(var al=0,ak;al<R.length;al++){for(ak=0;ak<Q.length;ak++){if(R[al].previous&&R[al].previous==Q[ak].next){ao=[R[al].previous];break}else{if(Q[ak].previous&&Q[ak].previous==R[al].next){ao=[R[al].next];break}}}if(ao){break}}}}if(!ao){ao=f[ab(u[at][an])]}if(ao){for(P=0;P<ao.length;P++){if(ao[P].sndStruc==2){u[at][an].sndStruc=2;break}R=[u[at][an].previous,u[at][an],u[at][an].next];Q=[ao[P].previous,ao[P],ao[P].next];if(p.hasOwnProperty(ab(R[0])+"-"+ab(Q[1]))&&p.hasOwnProperty(ab(Q[1])+"-"+ab(R[2]))){R[0].sndStruc=R[1].sndStruc=R[2].sndStruc=Q[1].sndStruc=2}else{if(p.hasOwnProperty(ab(R[1])+"-"+ab(Q[0]))&&p.hasOwnProperty(ab(Q[2])+"-"+ab(R[1]))){R[1].sndStruc=Q[0].sndStruc=Q[1].sndStruc=Q[2].sndStruc=2}else{if(p.hasOwnProperty(ab(R[1])+"-"+ab(Q[1]))&&p.hasOwnProperty(ab(Q[1])+"-"+ab(R[1]))){R[1].sndStruc=Q[1].sndStruc=2}else{if(p.hasOwnProperty(ab(R[0])+"-"+ab(Q[2]))&&p.hasOwnProperty(ab(R[2])+"-"+ab(Q[0]))){R[0].sndStruc=R[1].sndStruc=R[2].sndStruc=Q[0].sndStruc=Q[1].sndStruc=Q[2].sndStruc=2}}}}}}}}}};molmil.viewer.prototype.setCOR=function(f){var l=this.renderer.modelId;if(this.lastKnowAS){resetCOR()}this.lastKnownAS=null;if(!this.atomSelection.length&&!f){return}if(!f){f=[this.atomSelection[0].chain.modelsXYZ[l][this.atomSelection[0].xyz],this.atomSelection[0].chain.modelsXYZ[l][this.atomSelection[0].xyz+1],this.atomSelection[0].chain.modelsXYZ[l][this.atomSelection[0].xyz+2]]}this.lastKnownAS=[f[0],f[1],f[2]];var g=mat3.create();mat3.fromMat4(g,this.renderer.modelViewMatrix);var h=vec3.subtract([0,0,0],this.lastKnownAS,this.avgXYZ);vec3.transformMat3(h,h,g);this.renderer.camera.x+=h[0];this.renderer.camera.y+=h[1];this.renderer.camera.z+=h[2];for(var d=0;d<this.canvases.length;d++){this.canvases[d].molmilViewer.COR=this.lastKnownAS}this.canvas.atomCORset=true};molmil.viewer.prototype.resetCOR=function(){var f=mat3.create();mat3.fromMat4(f,this.renderer.modelViewMatrix);var g=vec3.subtract([0,0,0],this.avgXYZ,this.lastKnownAS);vec3.transformMat3(g,g,f);this.renderer.camera.x+=g[0];this.renderer.camera.y+=g[1];this.renderer.camera.z+=g[2];for(var d=0;d<this.canvases.length;d++){this.canvases[d].molmilViewer.COR=this.avgXYZ}this.canvas.atomCORset=false;this.lastKnownAS=null};molmil.exportPLY=function(C){C=C||molmil.cli_soup;molmil.geometry.skipClearBuffer=true;molmil.geometry.reInitChains=true;C.renderer.initBuffers();C.renderer.canvas.update=true;molmil.geometry.generate(C.structures,C.renderer);var h=[];if(molmil.geometry.buffer1){h.push(molmil.geometry.buffer1)}if(molmil.geometry.buffer3){h.push(molmil.geometry.buffer3)}if(molmil.geometry.buffer4){h.push(molmil.geometry.buffer4)}for(var y=0;y<C.structures.length;y++){if(C.structures[y] instanceof molmil.polygonObject&&C.structures[y].data){h.push(C.structures[y].data)}}var u,f=0,q=0,w;for(u=0;u<h.length;u++){w=h[u].vertexSize||8;f+=h[u].vertexBuffer.length/w;q+=h[u].indexBuffer.length/3}var x="ply\nformat binary_little_endian 1.0\nelement vertex "+f+"\nproperty float x\nproperty float y\nproperty float z\nproperty float nx\nproperty float ny\nproperty float nz\nproperty uint8 red\nproperty uint8 green\nproperty uint8 blue\nproperty uint8 alpha\nelement face "+q+"\nproperty list int32 int32 vertex_indices\nend_header\n";var l=new Float32Array(f*7);var n=new Uint8Array(l.buffer);var p=new Int32Array(q*4);var s,D,A=0,B=0,o=0,z,t,g=0;for(u=0;u<h.length;u++){w=h[u].vertexSize||8;z=h[u].vertexBuffer;t=new Uint8Array(z.buffer,h[u].vertices_offset);for(s=0,D=0;s<z.length;s+=w,D+=(w*4),B+=28){l[A++]=z[s];l[A++]=z[s+1];l[A++]=z[s+2];l[A++]=z[s+3];l[A++]=z[s+4];l[A++]=z[s+5];n[B+24]=t[D+24];n[B+25]=t[D+25];n[B+26]=t[D+26];n[B+27]=t[D+27];A++}z=h[u].indexBuffer;for(s=0;s<z.length;s+=3){p[o++]=3;p[o++]=g+z[s];p[o++]=g+z[s+1];p[o++]=g+z[s+2]}g+=h[u].vertexBuffer.length/w}var d=new Blob([x,l,p],{type:"application/octet-binary"});saveAs(d,"molmil.ply");molmil.geometry.skipClearBuffer=false};molmil.exportSTL=function(C){C=C||molmil.cli_soup;molmil.geometry.skipClearBuffer=true;molmil.geometry.reInitChains=true;C.renderer.initBuffers();C.renderer.canvas.update=true;molmil.geometry.generate(C.structures,C.renderer);var o=[];if(molmil.geometry.buffer1){o.push(molmil.geometry.buffer1)}if(molmil.geometry.buffer3){o.push(molmil.geometry.buffer3)}if(molmil.geometry.buffer4){o.push(molmil.geometry.buffer4)}for(var z=0;z<C.structures.length;z++){if(C.structures[z] instanceof molmil.polygonObject&&C.structures[z].data){o.push(C.structures[z].data)}}var u,l=0,q=0,w;for(u=0;u<o.length;u++){w=o[u].vertexSize||8;l+=o[u].vertexBuffer.length/w;q+=o[u].indexBuffer.length/3}var y="generated by molmil";y+=new Array(80-y.length+1).join(" ");var s=new Uint32Array(1);s[0]=q;var t=[y,s];var u,D,n,A,p,z,h=[0,0,0],g=[0,0,0],f=[0,0,0],B=[0,0,0],x=[0,0,0];for(u=0;u<o.length;u++){A=o[u].vertexBuffer;p=o[u].indexBuffer;w=o[u].vertexSize||8;for(v=0;v<p.length;v+=3){D=new Float32Array(12);n=new Uint16Array(1);n[0]=0;z=p[v]*w;h[0]=D[3]=A[z];h[1]=D[4]=A[z+1];h[2]=D[5]=A[z+2];z=p[v+1]*w;g[0]=D[6]=A[z];g[1]=D[7]=A[z+1];g[2]=D[8]=A[z+2];z=p[v+2]*w;f[0]=D[9]=A[z];f[1]=D[10]=A[z+1];f[2]=D[11]=A[z+2];vec3.min(B,g,h);vec3.normalize(B,B);vec3.min(x,f,h);vec3.normalize(x,x);D[0]=B[1]*x[2]-B[2]*x[1];D[1]=B[2]*x[0]-B[0]*x[2];D[2]=B[0]*x[1]-B[1]*x[0];t.push(D);t.push(n)}}var d=new Blob(t,{type:"application/octet-binary"});saveAs(d,"molmil.stl");molmil.geometry.skipClearBuffer=false};molmil.geometry={templates:{sphere:{},cylinder:[],dome:{}},detail_lvs:5,dome:[0,0,-1],radius:0.25,sheetHeight:0.125,skipClearBuffer:false,onGenerate:null};molmil.geometry.generator=function(f,O,Q,s){s=s||{};var g=molmil.configBox.QLV_SETTINGS[O.renderer.QLV].SPHERE_TESS_LV;var M=molmil.configBox.QLV_SETTINGS[O.renderer.QLV].CB_NOI;var H=molmil.configBox.QLV_SETTINGS[O.renderer.QLV].CB_NOVPR;var G,P;var L=molmil.geometry.getCylinder(g);var l=0,x=0;for(var G=0;G<f.length;G++){P=f[G];if(P.type=="sphere"){}if(P.type=="cylinder"){l+=(L.vertices.length/3);x+=L.indices.length}}var h=new Float32Array(l*7);var n=new Uint8Array(h.buffer);var w=new Uint32Array(x);var D=mat4.create();var J=[0,0,0,0],N=[0,0,0,0];var E=4,q,C=0,t=0,A=0,F=0,d=0,C,B,z,y,I,K;for(var G=0;G<f.length;G++){P=f[G];q=P.rgba;if(P.type=="sphere"){}if(P.type=="cylinder"){E=P.radius;B=P.coords[1][0]-P.coords[0][0];z=P.coords[1][1]-P.coords[0][1];y=P.coords[1][2]-P.coords[0][2];I=Math.sqrt((B*B)+(z*z)+(y*y));B/=I;z/=I;y/=I;K=Math.acos(-y);mat4.identity(D);mat4.rotate(D,D,K,[z,-B,0]);for(C=0;C<L.indices.length;C++,d++){w[d]=L.indices[C]+F}for(C=0;C<L.vertices.length;C+=3,t+=28){vec3.transformMat4(J,[L.vertices[C]*E,L.vertices[C+1]*E,L.vertices[C+2]*I*2],D);vec3.transformMat4(N,[L.normals[C],L.normals[C+1],L.normals[C+2]],D);h[A++]=J[0]+P.coords[1][0];h[A++]=J[1]+P.coords[1][1];h[A++]=J[2]+P.coords[1][2];h[A++]=N[0];h[A++]=N[1];h[A++]=N[2];n[t+24]=q[0];n[t+25]=q[1];n[t+26]=q[2];n[t+27]=q[3];A++}F+=L.vertices.length/3}}var u=molmil.geometry.build_simple_render_program(h,w,O.renderer,s);O.renderer.programs.push(u);O.renderer.initBuffers();O.canvas.update=true;return u};molmil.geometry.getSphere=function(d,f){if(d in this.templates.sphere){return this.templates.sphere[d][f]}else{return this.generateSphere(d)[f]}};molmil.geometry.getCylinder=function(d){return this.templates.cylinder[d]};molmil.geometry.generateCylinder=function(){var g,o,f,d,s,q,n,l;for(var h=0;h<this.detail_lvs;h++){g=(h+1)*4;f=0;o=2/g;this.templates.cylinder.push({vertices:[],normals:[],indices:[]});for(d=0;d<g;d++){s=Math.cos(f*Math.PI);q=Math.sin(f*Math.PI);this.templates.cylinder[h].vertices.push(s,q,0);this.templates.cylinder[h].vertices.push(s,q,0.5);l=Math.sqrt(s*s+q*q);this.templates.cylinder[h].normals.push(s/l,q/l,0);this.templates.cylinder[h].normals.push(s/l,q/l,0);f+=o}for(d=0;d<(g-1)*2;d+=2){this.templates.cylinder[h].indices.push(d,d+2,d+3);this.templates.cylinder[h].indices.push(d+3,d+1,d)}this.templates.cylinder[h].indices.push(d,0,1);this.templates.cylinder[h].indices.push(1,d+1,d)}return this.templates.cylinder};molmil.geometry.generateCylinder();molmil.geometry.generateSphere=function(l){this.templates.sphere[l]=[];var h,g,f,d;for(h=0;h<this.detail_lvs;h++){f={vertices:[],normals:[],indices:[]};d=molmil.octaSphereBuilder(h);for(g=0;g<d.vertices.length;g++){f.vertices.push(d.vertices[g][0]*l,d.vertices[g][1]*l,d.vertices[g][2]*l)}for(g=0;g<d.faces.length;g++){f.indices.push(d.faces[g][0],d.faces[g][1],d.faces[g][2])}for(g=0;g<d.vertices.length;g++){f.normals.push(d.vertices[g][0],d.vertices[g][1],d.vertices[g][2])}this.templates.sphere[l].push(f)}return this.templates.sphere[l]};molmil.geometry.generate=function(h,g,l){this.reset();var n=[],d=[];for(var f=0,o;f<h.length;f++){if(!(h[f] instanceof molmil.entryObject)||h[f].display==false){continue}for(var o=0;o<h[f].chains.length;o++){if(!h[f].chains[o]){continue}if(h[f].chains[o].display&&h[f].chains[o].molecules.length>0&&!h[f].chains[o].isHet&&!h[f].chains[o].molecules[0].water){d.push(h[f].chains[o])}n.push(h[f].chains[o])}}this.initChains(n,g,l);this.initCartoon(d);if(molmil.configBox.EXT_frag_depth){this.generateAtomsImposters()}else{this.generateAtoms()}this.generateBonds();this.generateWireframe();this.generateCartoon();this.generateSurfaces(d,g.soup);this.registerPrograms(g);if(!this.skipClearBuffer){this.reset()}if(this.onGenerate){molmil_dep.asyncStart(this.onGenerate[0],this.onGenerate[1],this.onGenerate[2],0)}};molmil.geometry.build_simple_render_program=function(n,g,h,f){var l=h.gl;var d={};d.settings=f;d.gl=h.gl;d.renderer=h;d.setBuffers=function(p,s){var q=this.gl.createBuffer();this.gl.bindBuffer(l.ARRAY_BUFFER,q);this.gl.bufferData(this.gl.ARRAY_BUFFER,p,this.gl.STATIC_DRAW);var o=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,o);this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,s,this.gl.STATIC_DRAW);this.nElements=s.length;this.vertexBuffer=q;this.indexBuffer=o};if(n&&g){d.setBuffers(n,g)}d.angle=h.angle;d.point_shader=h.shaders.points;if(d.point_shader){d.point_attributes=d.point_shader.attributes}if(f.uniform_color){d.standard_shader=h.shaders.standard_uniform_color;d.wireframe_shader=h.shaders.lines_uniform_color;d.point_shader=h.shaders.points_uniform_color}else{if(f.alphaMode){d.standard_shader=h.shaders.standard_alpha}else{d.standard_shader=h.shaders.standard}d.wireframe_shader=h.shaders.lines;d.point_shader=h.shaders.points}d.standard_attributes=d.standard_shader.attributes;d.wireframe_attributes=d.wireframe_shader.attributes;d.status=true;d.point_render=function(p,t,s){if(!this.status){return}this.gl.activeTexture(this.gl.TEXTURE0);this.gl.bindTexture(this.gl.TEXTURE_2D,h.textures.atom_imposter);var u=mat3.create();this.gl.useProgram(this.point_shader.program);this.gl.uniformMatrix4fv(this.point_shader.uniforms.modelViewMatrix,false,p);this.gl.uniformMatrix4fv(this.point_shader.uniforms.projectionMatrix,false,this.renderer.projectionMatrix);this.gl.uniform3f(this.point_shader.uniforms.COR,t[0],t[1],t[2]);this.gl.uniform1f(this.point_shader.uniforms.focus,this.renderer.fogStart);this.gl.uniform1f(this.point_shader.uniforms.fogSpan,this.renderer.fogStart+(this.renderer.clearCut*2));this.gl.uniform1f(this.point_shader.uniforms.zFar,molmil.configBox.zFar);this.gl.uniform1f(this.point_shader.uniforms.zNear,molmil.configBox.zNear);this.gl.uniform1i(this.point_shader.uniforms.textureMap,0);this.gl.uniform1f(this.point_shader.uniforms.zInvDiff,1/((1/molmil.configBox.zFar)-(1/molmil.configBox.zNear)));this.gl.uniform1f(this.point_shader.uniforms.zNearInv,1/molmil.configBox.zNear);this.gl.enable(this.gl.DEPTH_TEST);if(this.settings.uniform_color){this.gl.uniform3f(this.point_shader.uniforms.uniform_color,this.uniform_color[s][0]/255,this.uniform_color[s][1]/255,this.uniform_color[s][2]/255)}if(this.renderer.settings.slab){this.gl.uniform1f(this.point_shader.uniforms.slabNear,-p[14]+this.renderer.settings.slabNear-molmil.configBox.zNear);this.gl.uniform1f(this.point_shader.uniforms.slabFar,-p[14]+this.renderer.settings.slabFar-molmil.configBox.zNear)}this.gl.uniform4f(this.point_shader.uniforms.backgroundColor,molmil.configBox.BGCOLOR[0],molmil.configBox.BGCOLOR[1],molmil.configBox.BGCOLOR[2],1);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);molmil.resetAttributes(this.gl);if(this.settings.has_ID){molmil.bindAttribute(this.gl,this.point_attributes.in_Position,3,this.gl.FLOAT,false,28,0);molmil.bindAttribute(this.gl,this.point_attributes.in_radius,1,this.gl.FLOAT,false,28,12);molmil.bindAttribute(this.gl,this.point_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,28,16);molmil.bindAttribute(this.gl,this.point_attributes.in_ScreenSpaceOffset,2,this.gl.SHORT,false,28,20)}else{molmil.bindAttribute(this.gl,this.point_attributes.in_Position,3,this.gl.FLOAT,false,24,0);molmil.bindAttribute(this.gl,this.point_attributes.in_radius,1,this.gl.FLOAT,false,24,12);molmil.bindAttribute(this.gl,this.point_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,24,16);molmil.bindAttribute(this.gl,this.point_attributes.in_ScreenSpaceOffset,2,this.gl.SHORT,false,24,20)}molmil.clearAttributes(this.gl);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer);if(this.angle){var q=0,o;while((o=Math.min(this.nElements-q,3000000))>0){this.gl.drawElements(this.gl.TRIANGLES,o,l.INDEXINT,q*4);q+=o}}else{this.gl.drawElements(this.gl.TRIANGLES,this.nElements,l.INDEXINT,0)}};d.wireframe_render=function(p,t,s){if(!this.status){return}var u=mat3.create();this.gl.useProgram(this.wireframe_shader.program);this.gl.uniformMatrix4fv(this.wireframe_shader.uniforms.modelViewMatrix,false,p);this.gl.uniformMatrix4fv(this.wireframe_shader.uniforms.projectionMatrix,false,this.renderer.projectionMatrix);this.gl.uniform3f(this.wireframe_shader.uniforms.COR,t[0],t[1],t[2]);this.gl.uniform1f(this.wireframe_shader.uniforms.focus,this.renderer.fogStart);this.gl.uniform1f(this.wireframe_shader.uniforms.fogSpan,this.renderer.fogStart+(this.renderer.clearCut*2));if(this.settings.uniform_color){this.gl.uniform3f(this.wireframe_shader.uniforms.uniform_color,this.uniform_color[s][0]/255,this.uniform_color[s][1]/255,this.uniform_color[s][2]/255)}if(this.renderer.settings.slab){this.gl.uniform1f(this.wireframe_shader.uniforms.slabNear,-p[14]+this.renderer.settings.slabNear-molmil.configBox.zNear);this.gl.uniform1f(this.wireframe_shader.uniforms.slabFar,-p[14]+this.renderer.settings.slabFar-molmil.configBox.zNear)}this.gl.uniform4f(this.wireframe_shader.uniforms.backgroundColor,molmil.configBox.BGCOLOR[0],molmil.configBox.BGCOLOR[1],molmil.configBox.BGCOLOR[2],1);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);molmil.resetAttributes(this.gl);if(this.settings.lines_render){if(this.settings.has_ID){molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Position,3,this.gl.FLOAT,false,20,0);if(!this.settings.uniform_color){molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,20,12)}}else{molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Position,3,this.gl.FLOAT,false,16,0);molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,16,12)}}else{if(this.settings.has_ID){molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Position,3,this.gl.FLOAT,false,32,0);molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,32,24)}else{molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Position,3,this.gl.FLOAT,false,28,0);molmil.bindAttribute(this.gl,this.wireframe_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,28,24)}}molmil.clearAttributes(this.gl);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer);if(this.angle){var q=0,o;while((o=Math.min(this.nElements-q,3000000))>0){this.gl.drawElements(this.gl.LINES,o,l.INDEXINT,q*4);q+=o}}else{this.gl.drawElements(this.gl.LINES,this.nElements,l.INDEXINT,0)}};d.standard_render=function(p,t,s){if(!this.status){return}var u=mat3.create();mat3.normalFromMat4(u,p);this.gl.useProgram(this.standard_shader.program);this.gl.uniformMatrix4fv(this.standard_shader.uniforms.modelViewMatrix,false,p);this.gl.uniformMatrix3fv(this.standard_shader.uniforms.normalMatrix,false,u);this.gl.uniformMatrix4fv(this.standard_shader.uniforms.projectionMatrix,false,this.renderer.projectionMatrix);this.gl.uniform3f(this.standard_shader.uniforms.COR,t[0],t[1],t[2]);this.gl.uniform1f(this.standard_shader.uniforms.focus,this.renderer.fogStart);this.gl.uniform1f(this.standard_shader.uniforms.fogSpan,this.renderer.fogStart+(this.renderer.clearCut*2));if(this.settings.uniform_color){this.gl.uniform3f(this.standard_shader.uniforms.uniform_color,this.uniform_color[s][0]/255,this.uniform_color[s][1]/255,this.uniform_color[s][2]/255)}this.gl.uniform4f(this.standard_shader.uniforms.backgroundColor,molmil.configBox.BGCOLOR[0],molmil.configBox.BGCOLOR[1],molmil.configBox.BGCOLOR[2],1);if(this.renderer.settings.slab){this.gl.uniform1f(this.standard_shader.uniforms.slabNear,-p[14]+this.renderer.settings.slabNear-molmil.configBox.zNear);this.gl.uniform1f(this.standard_shader.uniforms.slabFar,-p[14]+this.renderer.settings.slabFar-molmil.configBox.zNear)}this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);molmil.resetAttributes(this.gl);if(this.settings.has_ID){molmil.bindAttribute(this.gl,this.standard_attributes.in_Position,3,this.gl.FLOAT,false,32,0);molmil.bindAttribute(this.gl,this.standard_attributes.in_Normal,3,this.gl.FLOAT,false,32,12);if(!this.settings.uniform_color){molmil.bindAttribute(this.gl,this.standard_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,32,24)}}else{molmil.bindAttribute(this.gl,this.standard_attributes.in_Position,3,this.gl.FLOAT,false,28,0);molmil.bindAttribute(this.gl,this.standard_attributes.in_Normal,3,this.gl.FLOAT,false,28,12);molmil.bindAttribute(this.gl,this.standard_attributes.in_Colour,4,this.gl.UNSIGNED_BYTE,true,28,24)}molmil.clearAttributes(this.gl);if(this.settings.alphaMode){if(molmil.configBox.cullFace){this.gl.disable(this.gl.CULL_FACE)}this.gl.enable(this.gl.BLEND);this.gl.blendEquation(this.gl.FUNC_ADD);this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA);this.gl.disable(this.gl.DEPTH)}this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer);if(this.angle){var q=0,o;while((o=Math.min(this.nElements-q,3000000))>0){this.gl.drawElements(this.gl.TRIANGLES,o,l.INDEXINT,q*4);q+=o}}else{this.gl.drawElements(this.gl.TRIANGLES,this.nElements,l.INDEXINT,0)}if(this.settings.alphaMode){if(molmil.configBox.cullFace){this.gl.enable(this.gl.CULL_FACE)}this.gl.disable(this.gl.BLEND);this.gl.enable(this.gl.DEPTH)}};if(!f.multiMatrix){if(f.imposterPoints){d.render=d.point_render}else{if(!f.solid){d.render=d.wireframe_render}else{d.render=d.standard_render}}}else{d.render=function(o,s){var q=mat4.create();for(var p=0;p<this.matrices.length;p++){mat4.multiply(q,o,this.matrices[p]);this.render_internal(q,s,p)}};if(!f.solid){d.render_internal=d.wireframe_render;d.shader=d.wireframe_shader}else{d.render_internal=d.standard_render;d.shader=d.standard_shader}}if(f.has_ID){if(f.lines_render){d.pickingShader=h.shaders.linesPicking;d.pickingAttributes=h.shaders.linesPicking.attributes;d.renderPicking=function(p,s){if(!this.status){return}this.gl.useProgram(this.pickingShader.program);this.gl.uniformMatrix4fv(this.pickingShader.uniforms.modelViewMatrix,false,p);this.gl.uniformMatrix4fv(this.pickingShader.uniforms.projectionMatrix,false,this.renderer.projectionMatrix);this.gl.uniform3f(this.pickingShader.uniforms.COR,s[0],s[1],s[2]);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);molmil.resetAttributes(this.gl);molmil.bindAttribute(this.gl,this.pickingAttributes.in_Position,3,this.gl.FLOAT,false,20,0);molmil.bindAttribute(this.gl,this.pickingAttributes.in_ID,1,this.gl.FLOAT,false,20,16);molmil.clearAttributes(this.gl);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer);if(this.angle){var q=0,o;while((o=Math.min(this.nElements-q,3000000))>0){this.gl.drawElements(this.gl.POINTS,o,l.INDEXINT,q*4);q+=o}}else{this.gl.drawElements(this.gl.POINTS,this.nElements,l.INDEXINT,0)}}}else{d.pickingShader=h.shaders.picking;d.pickingAttributes=h.shaders.picking.attributes;d.renderPicking=function(p,s){if(!this.status){return}this.gl.useProgram(this.pickingShader.program);this.gl.uniformMatrix4fv(this.pickingShader.uniforms.modelViewMatrix,false,p);this.gl.uniformMatrix4fv(this.pickingShader.uniforms.projectionMatrix,false,this.renderer.projectionMatrix);this.gl.uniform3f(this.pickingShader.uniforms.COR,s[0],s[1],s[2]);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);molmil.resetAttributes(this.gl);molmil.bindAttribute(this.gl,this.pickingAttributes.in_Position,3,this.gl.FLOAT,false,32,0);molmil.bindAttribute(this.gl,this.pickingAttributes.in_ID,1,this.gl.FLOAT,false,32,28);molmil.clearAttributes(this.gl);this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer);if(this.angle){var q=0,o;while((o=Math.min(this.nElements-q,3000000))>0){this.gl.drawElements(this.gl.TRIANGLES,o,l.INDEXINT,q*4);q+=o}}else{this.gl.drawElements(this.gl.TRIANGLES,this.nElements,l.INDEXINT,0)}}}}else{d.renderPicking=function(){}}return d};molmil.geometry.registerPrograms=function(d){if(!d.program1){d.program1=this.build_simple_render_program(null,null,d,{has_ID:true,solid:true});d.programs.push(d.program1)}if(!d.program2){d.program2=this.build_simple_render_program(null,null,d,{has_ID:true,lines_render:true});d.programs.push(d.program2)}if(!d.program3){d.program3=this.build_simple_render_program(null,null,d,{has_ID:true,solid:true});d.programs.push(d.program3)}if(!d.program4){d.program4=this.build_simple_render_program(null,null,d,{has_ID:false,solid:true});d.programs.push(d.program4)}if(molmil.configBox.EXT_frag_depth){if(!d.program5){d.program5=this.build_simple_render_program(null,null,d,{has_ID:true,imposterPoints:true});d.programs.push(d.program5)}d.program5.setBuffers(this.buffer5.vertexBuffer,this.buffer5.indexBuffer)}d.program1.setBuffers(this.buffer1.vertexBuffer,this.buffer1.indexBuffer);d.program2.setBuffers(this.buffer2.vertexBuffer,this.buffer2.indexBuffer);d.program3.setBuffers(this.buffer3.vertexBuffer,this.buffer3.indexBuffer);d.program4.setBuffers(this.buffer4.vertexBuffer,this.buffer4.indexBuffer);if(molmil.configBox.liteMode){molmil.geometry.reset()}};molmil.geometry.reset=function(){this.atoms2draw=[];this.wfatoms2draw=[];this.trace=[];this.bonds2draw=[];this.lines2draw=[];this.bondRef={};this.buffer1={vP:0,iP:0};this.buffer2={vP:0,iP:0};this.buffer3={vP:0,iP:0};this.buffer4={vP:0,iP:0};this.buffer5={vP:0,iP:0}};molmil.geometry.initChains=function(A,I,g){g=g||0;var w,H,G;var o=this.atoms2draw;var s=this.wfatoms2draw;var E=this.bonds2draw;var t=this.lines2draw;var f=this.bondRef;var h=0,u=0,C;for(var D=0;D<A.length;D++){w=A[D];C=false;if(!w.display){continue}for(var H=0;H<w.atoms.length;H++){if(w.atoms[H].displayMode==0||!w.atoms[H].display){continue}else{if(w.atoms[H].displayMode==4){s.push(w.atoms[H])}else{o.push(w.atoms[H])}}C=true}if(C&&!w.bondsOK){I.soup.buildBondList(w,false)}for(var G=0;G<w.bonds.length;G++){if(w.bonds[G][0].displayMode<2||w.bonds[G][1].displayMode<2||!w.bonds[G][0].display||!w.bonds[G][1].display){continue}if(w.bonds[G][0].displayMode==4||w.bonds[G][1].displayMode==4){t.push(w.bonds[G])}else{E.push(w.bonds[G]);u+=w.bonds[G][2]*2;if(!f.hasOwnProperty(w.bonds[G][0].AID)){f[w.bonds[G][0].AID]=[]}if(!f.hasOwnProperty(w.bonds[G][1].AID)){f[w.bonds[G][1].AID]=[]}f[w.bonds[G][0].AID].push(w.bonds[G][1]);f[w.bonds[G][1].AID].push(w.bonds[G][0])}}if(w.displayMode==1){if(!w.bondsOK){I.soup.buildBondList(w,false)}for(var x=0;x<w.molecules.length;x++){if(w.molecules[x].CA){if(w.molecules[x].next&&w.molecules[x].next.displayMode==1&&w.molecules[x].next.CA){o.push(w.molecules[x].CA);E.push([w.molecules[x].CA,w.molecules[x].next.CA]);u+=2}else{if(w.molecules[x].previous&&w.molecules[x].previous.displayMode==1&&w.molecules[x].previous.CA){o.push(w.molecules[x].CA)}}}}}if(w.displayMode>1&&(w.displayMode!=molmil.displayMode_ChainSurfaceCG||w.displayMode!=molmil.displayMode_ChainSurfaceSimple)){if(!w.twoDcache||this.reInitChains){molmil.prepare2DRepr(w,this.modelId||0)}h+=w.molecules.length}}this.reInitChains=false;var d=molmil.configBox.QLV_SETTINGS[I.QLV].SPHERE_TESS_LV;var F=molmil.configBox.QLV_SETTINGS[I.QLV].CB_NOI;var z=molmil.configBox.QLV_SETTINGS[I.QLV].CB_NOVPR;if(molmil.configBox.EXT_frag_depth){var y=0}else{var y=o.length*(6*Math.pow(4,d+1))}y+=E.length*(d+1)*4*2;y+=h*F*z;if(y>10000000){d-=1}if(y>30000000){d-=1}if(y>100000000){d-=1}if(y<250000&&d<3){d+=1}d=this.detail_lv=Math.max(d+g,0);if(molmil.configBox.liteMode){d=this.detail_lv=1}this.noi=molmil.configBox.QLV_SETTINGS[this.detail_lv].CB_NOI;this.novpr=molmil.configBox.QLV_SETTINGS[this.detail_lv].CB_NOVPR;if(molmil.configBox.liteMode){this.noi=1}var q=this.buffer1,n=this.buffer2;var y=0,p=0;if(molmil.configBox.EXT_frag_depth){this.buffer5.vertexBuffer=new Float32Array(o.length*4*7);if(molmil.configBox.OES_element_index_uint){this.buffer5.indexBuffer=new Uint32Array(o.length*6)}else{this.buffer5.indexBuffer=new Uint16Array(o.length*4)}}else{var l=this.getSphere(1,d);y+=(l.vertices.length/3)*o.length;p+=l.indices.length*o.length}var B=this.getCylinder(d);y+=(B.vertices.length/3)*u;p+=B.indices.length*u;q.vertexBuffer=new Float32Array(y*8);q.vertexBuffer8=new Uint8Array(q.vertexBuffer.buffer);if(molmil.configBox.OES_element_index_uint){q.indexBuffer=new Uint32Array(p)}else{q.indexBuffer=new Uint16Array(p)}n.vertexBuffer=new Float32Array(s.length*5);n.vertexBuffer8=new Uint8Array(n.vertexBuffer.buffer);if(molmil.configBox.OES_element_index_uint){n.indexBuffer=new Uint32Array(t.length*2)}else{n.indexBuffer=new Uint16Array(t.length*2)}};molmil.geometry.initCartoon=function(F){var H,B,I,C=0,o=0,d,f=0,z=this.cartoonChains=[],K,J=this.nowps=[];var t=this.noi;var s=this.novpr;if(this.dome[2]!=this.detail_lv){var l=this.dome=[molmil.buildOctaDome(molmil.configBox.QLV_SETTINGS[this.detail_lv].CB_DOME_TESS_LV,0),molmil.buildOctaDome(molmil.configBox.QLV_SETTINGS[this.detail_lv].CB_DOME_TESS_LV,1),this.detail_lv];var n=mat4.create();mat4.rotateZ(n,n,(45*Math.PI)/180);for(var E=0;E<this.dome[0].vertices.length;E++){vec3.transformMat4(this.dome[0].vertices[E],this.dome[0].vertices[E],n);vec3.transformMat4(this.dome[1].vertices[E],this.dome[1].vertices[E],n)}var D=this.ringTemplate=[];var h=s,q=0,L=2/h,w,u,A,G;for(A=0;A<h;A++){w=Math.cos(q*Math.PI);u=Math.sin(q*Math.PI);D.push([w,u,0]);q+=L}this.squareVertices=[[-1,1,0],[1,1,0],[1,-1,0],[-1,-1,0],[-1,1,0]];this.squareVerticesN=[[-1,0,0],[0,1,0],[1,0,0],[0,-1,0],[-1,0,0]]}else{var l=this.dome}for(H=0;H<F.length;H++){B=F[H];if(B.displayMode<2||B.displayMode==molmil.displayMode_ChainSurfaceCG||B.displayMode==molmil.displayMode_ChainSurfaceSimple){continue}K=0;z.push(B);for(I=0;I<B.twoDcache.length;I++){d=B.twoDcache[I];if(B.displayMode>2&&d.sndStruc==2){if(!d.isFirst){C+=s;o+=s*2}C+=4+(d.molecules.length*8*(t+1))+8+s;o+=2+(d.molecules.length*8*(t+1))+(s*2);if(!d.isLast){C+=s}K+=d.molecules.length*(t+1);if(d.isLast){K-=t}}else{if(d.rocket){if(d.skip){continue}C+=s+1+(d.waypoints.length*s)+s+1;o+=s+(d.waypoints.length*s*2)+s;if(!d.isFirst){C+=s*(Math.round(t*0.5)+1);o+=s*2*(Math.round(t*0.5)+1)}if(!d.isLast){C+=s;C+=s*(Math.round(t*0.5)+2);o+=s*2*(Math.round(t*0.5)+2)}K+=d.molecules.length*(t+1)}else{if(d.isFirst){C+=l[0].vertices.length;o+=l[0].faces.length-(s*2)}if(d.isLast){C+=l[0].vertices.length+s;o+=l[0].faces.length+(s*2)}C+=d.molecules.length*s*(t+1);o+=d.molecules.length*s*2*(t+1);K+=d.molecules.length*(t+1);if(d.isLast){K-=t;C-=s*(t+1);o-=s*2*(t+1)}}}}J.push(K)}var g=this.buffer3;g.vertexBuffer=new Float32Array(C*8);g.vertexBuffer8=new Uint8Array(g.vertexBuffer.buffer);if(molmil.configBox.OES_element_index_uint){g.indexBuffer=new Uint32Array(o*3)}else{g.indexBuffer=new Uint16Array(o*3)}};molmil.geometry.generateAtomsImposters=function(){var l=this.atoms2draw,B=molmil.configBox.vdwR,w,h,G,u,g;vBuffer=this.buffer5.vertexBuffer,vP=this.buffer5.vP,iP=this.buffer5.iP,vP8=vP*4,vP16=vP*2;var f=new Uint8Array(this.buffer5.vertexBuffer.buffer);var D=new Uint16Array(this.buffer5.vertexBuffer.buffer);var o=this.buffer5.indexBuffer;var d=this.modelId||0,F;var t,s,q,C;var E=[[-1,+1],[+1,+1],[+1,-1],[-1,-1]];var A=vP/7;for(G=0;G<l.length;G++){if(l[G].displayMode==1){w=molmil_dep.getKeyFromObject(B,l[G].element,B.DUMMY)}else{if(l[G].displayMode==2){w=0.33}else{w=0.15}}F=d;if(l[G].chain.modelsXYZ.length<=d){d=0}t=l[G].chain.modelsXYZ[d][l[G].xyz];s=l[G].chain.modelsXYZ[d][l[G].xyz+1];q=l[G].chain.modelsXYZ[d][l[G].xyz+2];g=l[G].rgba;for(C=0;C<4;C++){vBuffer[vP++]=t;vBuffer[vP++]=s;vBuffer[vP++]=q;vBuffer[vP++]=w;f[vP8+16]=g[0];f[vP8+17]=g[1];f[vP8+18]=g[2];f[vP8+19]=g[3];vP++;D[vP16+10]=E[C][0];D[vP16+11]=E[C][1];vP++;vBuffer[vP++]=l[G].AID;vP8+=28;vP16+=14}o[iP++]=3+A;o[iP++]=2+A;o[iP++]=1+A;o[iP++]=3+A;o[iP++]=1+A;o[iP++]=0+A;A+=4}this.buffer5.vP=vP;this.buffer5.iP=iP};molmil.geometry.generateAtoms=function(){var f=this.atoms2draw,B=molmil.configBox.vdwR,d,n,w,A,o;vBuffer=this.buffer1.vertexBuffer,iBuffer=this.buffer1.indexBuffer,vP=this.buffer1.vP,iP=this.buffer1.iP,detail_lv=this.detail_lv,vBuffer8=this.buffer1.vertexBuffer8,vP8=vP*4;var g=vP/8;var l=this.modelId||0,q;var u,t,s;n=this.getSphere(1.7,detail_lv);var h=n.vertices.length/3;for(w=0;w<f.length;w++){if(f[w].displayMode==1){d=molmil_dep.getKeyFromObject(B,f[w].element,B.DUMMY)}else{if(f[w].displayMode==2){d=0.33}else{d=0.15}}n=this.getSphere(d,detail_lv);for(A=0;A<n.indices.length;A++,iP++){iBuffer[iP]=n.indices[A]+g}q=l;if(f[w].chain.modelsXYZ.length<=l){l=0}u=f[w].chain.modelsXYZ[l][f[w].xyz];t=f[w].chain.modelsXYZ[l][f[w].xyz+1];s=f[w].chain.modelsXYZ[l][f[w].xyz+2];o=f[w].rgba;for(A=0;A<n.vertices.length;A+=3,vP8+=32){vBuffer[vP++]=n.vertices[A]+u;vBuffer[vP++]=n.vertices[A+1]+t;vBuffer[vP++]=n.vertices[A+2]+s;vBuffer[vP++]=n.normals[A];vBuffer[vP++]=n.normals[A+1];vBuffer[vP++]=n.normals[A+2];vBuffer8[vP8+24]=o[0];vBuffer8[vP8+25]=o[1];vBuffer8[vP8+26]=o[2];vBuffer8[vP8+27]=o[3];vP++;vBuffer[vP++]=f[w].AID}g+=h}this.buffer1.vP=vP;this.buffer1.iP=iP};molmil.geometry.generateBonds=function(){var A=this.getCylinder(this.detail_lv);var B=this.modelId||0,P;var h=this.bonds2draw,q=this.buffer1.vertexBuffer,o=this.buffer1.indexBuffer,D=this.buffer1.vP,T=this.buffer1.iP,X=this.detail_lv,s=this.buffer1.vertexBuffer8,C=D*4;var O=A.vertices.length/3;var N,L,J,H,V=[0,0,0],U=[0,0,0],n=[0,0,0];var Q=D/8,K,I,G,t,W,E,R,S;var F=mat4.create();var w=[0,0,0,0],M=[0,0,0,0],l,g,f,d,u;for(b=0;b<h.length;b++){R=h[b][2]==2?4:2;P=B;if(h[b][0].chain.modelsXYZ.length<=B){B=0}K=h[b][0].chain.modelsXYZ[B][h[b][0].xyz];I=h[b][0].chain.modelsXYZ[B][h[b][0].xyz+1];G=h[b][0].chain.modelsXYZ[B][h[b][0].xyz+2];t=h[b][1].chain.modelsXYZ[B][h[b][1].xyz];W=h[b][1].chain.modelsXYZ[B][h[b][1].xyz+1];E=h[b][1].chain.modelsXYZ[B][h[b][1].xyz+2];l=K-t;g=I-W;f=G-E;d=Math.sqrt((l*l)+(g*g)+(f*f));l/=d;g/=d;f/=d;u=Math.acos(-f);mat4.identity(F);mat4.rotate(F,F,u,[g,-l,0]);N=0.15;L=0;J=0;H=0;if(h[b][2]==2){N=0.075;L=-0.075}S=h[b][0].rgba;for(v=0;v<A.indices.length;v++,T++){o[T]=A.indices[v]+Q}for(v=0;v<A.vertices.length;v+=3,C+=32){vec3.transformMat4(w,[(A.vertices[v]*N)+L,(A.vertices[v+1]*N)+J,(A.vertices[v+2]+H)*d],F);vec3.transformMat4(M,[A.normals[v],A.normals[v+1],A.normals[v+2]],F);q[D++]=w[0]+K;q[D++]=w[1]+I;q[D++]=w[2]+G;q[D++]=M[0];q[D++]=M[1];q[D++]=M[2];s[C+24]=S[0];s[C+25]=S[1];s[C+26]=S[2];s[C+27]=S[3];D++;q[D++]=0}Q+=O;H+=0.5;S=h[b][1].rgba;for(v=0;v<A.indices.length;v++,T++){o[T]=A.indices[v]+Q}for(v=0;v<A.vertices.length;v+=3,C+=32){vec3.transformMat4(w,[(A.vertices[v]*N)+L,(A.vertices[v+1]*N)+J,(A.vertices[v+2]+H)*d],F);vec3.transformMat4(M,[A.normals[v],A.normals[v+1],A.normals[v+2]],F);q[D++]=w[0]+K;q[D++]=w[1]+I;q[D++]=w[2]+G;q[D++]=M[0];q[D++]=M[1];q[D++]=M[2];s[C+24]=S[0];s[C+25]=S[1];s[C+26]=S[2];s[C+27]=S[3];D++;q[D++]=0}Q+=O;if(h[b][2]==2){N=0.075;L=0.075;H=0;S=h[b][0].rgba;for(v=0;v<A.indices.length;v++,T++){o[T]=A.indices[v]+Q}for(v=0;v<A.vertices.length;v+=3,C+=32){vec3.transformMat4(w,[(A.vertices[v]*N)+L,(A.vertices[v+1]*N)+J,(A.vertices[v+2]+H)*d],F);vec3.transformMat4(M,[A.normals[v],A.normals[v+1],A.normals[v+2]],F);q[D++]=w[0]+K;q[D++]=w[1]+I;q[D++]=w[2]+G;q[D++]=M[0];q[D++]=M[1];q[D++]=M[2];s[C+24]=S[0];s[C+25]=S[1];s[C+26]=S[2];s[C+27]=S[3];D++;q[D++]=0}Q+=O;H+=0.5;S=h[b][1].rgba;for(v=0;v<A.indices.length;v++,T++){o[T]=A.indices[v]+Q}for(v=0;v<A.vertices.length;v+=3,C+=32){vec3.transformMat4(w,[(A.vertices[v]*N)+L,(A.vertices[v+1]*N)+J,(A.vertices[v+2]+H)*d],F);vec3.transformMat4(M,[A.normals[v],A.normals[v+1],A.normals[v+2]],F);q[D++]=w[0]+K;q[D++]=w[1]+I;q[D++]=w[2]+G;q[D++]=M[0];q[D++]=M[1];q[D++]=M[2];s[C+24]=S[0];s[C+25]=S[1];s[C+26]=S[2];s[C+27]=S[3];D++;q[D++]=0}Q+=O}}this.buffer1.vP=D;this.buffer1.iP=T};molmil.geometry.generateWireframe=function(){var n=this.wfatoms2draw,t=this.lines2draw,w,o=this.buffer2.vertexBuffer,s=this.buffer2.indexBuffer,q=this.buffer2.vP,y=this.buffer2.iP,x=this.buffer2.vertexBuffer8,l=q*4;var h=0.5;var d=q/5;var g={};var f=this.modelId||0;for(var w=0;w<n.length;w++,d++,l+=20){g[n[w].AID]=d;o[q++]=n[w].chain.modelsXYZ[f][n[w].xyz];o[q++]=n[w].chain.modelsXYZ[f][n[w].xyz+1];o[q++]=n[w].chain.modelsXYZ[f][n[w].xyz+2];x[l+12]=n[w].rgba[0];x[l+13]=n[w].rgba[1];x[l+14]=n[w].rgba[2];x[l+16]=n[w].rgba[3];q++;o[q++]=n[w].AID}for(var u=0;u<t.length;u++){s[y++]=g[t[u][0].AID];s[y++]=g[t[u][1].AID]}this.buffer2.vP=q;this.buffer2.iP=y};molmil.geometry.generateSurfaces=function(w,D){var y,p,o=[],A=[],C=0,d=0,x;for(y=0;y<w.length;y++){if(w[y].displayMode==molmil.displayMode_ChainSurfaceCG){if(w[y].HQsurface){p=molmil.coarseSurface(w[y],molmil.configBox.HQsurface_gridSpacing,1.4)}else{p=molmil.coarseSurface(w[y],7.5,7.5*0.75,{deproj:true})}p.rgba=w[y].rgba;o.push(p);C+=p.vertices.length;d+=p.faces.length*3}else{if(w[y].displayMode==molmil.displayMode_ChainSurfaceSimple){x=w[y].displaySettings||{};x.skipProgram=true;p=molmil.tubeSurface(w[y],x,D);C+=p.vBuffer.length;d+=p.iBuffer.length;p.rgba=w[y].rgba;A.push(p)}}}var n=new Float32Array(C*7);var B=new Uint8Array(n.buffer);var h=new Uint32Array(d);var t=0,z=0,q,g,l=0,u=0;for(q=0;q<o.length;q++){p=o[q];g=p.rgba;for(y=0;y<p.vertices.length;y++,z+=28){n[t++]=p.vertices[y][0];n[t++]=p.vertices[y][1];n[t++]=p.vertices[y][2];n[t++]=p.normals[y][0];n[t++]=p.normals[y][1];n[t++]=p.normals[y][2];B[z+24]=g[0];B[z+25]=g[1];B[z+26]=g[2];B[z+27]=g[3];t++}for(y=0;y<p.faces.length;y++){h[u++]=p.faces[y][0]+l;h[u++]=p.faces[y][1]+l;h[u++]=p.faces[y][2]+l}l+=p.vertices.length}for(q=0;q<A.length;q++){p=A[q];n.set(p.vBuffer,t);t+=p.vBuffer.length;z+=p.vBuffer.length*4;for(y=0;y<p.iBuffer.length;y++){h[u++]=p.iBuffer[y]+l}l+=p.vBuffer.length/7}var f=this.buffer4;f.vertexBuffer=n;f.vertexBuffer8=B;f.indexBuffer=h};molmil.geometry.generateCartoon=function(){var F=this.cartoonChains,J,M,o,D,w,C,g,A,h,l,n,E,d,G,p,y=0,O,B,z=[0,0,0],L=0.0001,u;var s=this.noi;var q=this.novpr;var K,f,I,x;var H=[];for(E=0;E<s+1;E++){H.push(E/(s+1))}for(J=0;J<F.length;J++){K=this.nowps[J];f=0;C=[],g=[],A=[],h=new Array(K),l=new Float32Array(K);chain=F[J];w=[];BNs=[];u=[];if(chain.displayMode==0){continue}for(M=0;M<chain.twoDcache.length;M++){u.push(w.length);currentBlock=chain.twoDcache[M];if(currentBlock.rocket){if(currentBlock.skip){continue}currentBlock.rocketPre=0;currentBlock.rocketPost=0;if(!currentBlock.isFirst){currentBlock.rocketPre=Math.round(s*0.5)+2;molmil.hermiteInterpolate(chain.twoDcache[M-1].xyz[D],currentBlock.waypoints[0],chain.twoDcache[M-1].tangents[D],currentBlock.waypoint_tangents[0],Math.round(s*0.5)+1,w,C);for(E=0;E<Math.round(s*0.5)+2;E++){h[f]=currentBlock.molecules[0].rgba;l[f]=0;f++}}for(D=0;D<currentBlock.waypoints.length;D++){h[f]=currentBlock.molecules[0].rgba;l[f]=0;f++;w.push(currentBlock.waypoints[D]);C.push(currentBlock.waypoint_tangents[D])}if(!currentBlock.isLast){currentBlock.rocketPost=Math.round(s*0.5)+2;for(o=M+1;o<chain.twoDcache.length;o++){if(!chain.twoDcache[o].skip){break}}I=C.length;molmil.hermiteInterpolate(currentBlock.waypoints[D-1],chain.twoDcache[o].xyz[0],currentBlock.waypoint_tangents[D-1],chain.twoDcache[o].tangents[0],Math.round(s*0.5)+1,w,C);z[0]=C[I][0]+C[I+1][0];z[1]=C[I][1]+C[I+1][1];z[2]=C[I][2]+C[I+1][2];vec3.normalize(z,z);C[I][0]=z[0];C[I][1]=z[1];C[I][2]=z[2];for(E=0;E<Math.round(s*0.5)+2;E++){h[f]=currentBlock.molecules[0].rgba;l[f]=0;f++}}}else{for(D=0;D<currentBlock.molecules.length-1;D++){molmil.hermiteInterpolate(currentBlock.xyz[D],currentBlock.xyz[D+1],currentBlock.tangents[D],currentBlock.tangents[D+1],s,w,C);for(E=0;E<s+1;E++){h[f]=currentBlock.molecules[D].rgba;l[f]=currentBlock.molecules[D].CA.AID;f++}}if(!currentBlock.isLast){if(!chain.twoDcache[M+1].rocket){molmil.hermiteInterpolate(currentBlock.xyz[D],chain.twoDcache[M+1].xyz[0],currentBlock.tangents[D],currentBlock.tangents[D+1],s,w,C);for(E=0;E<s+1;E++){h[f]=currentBlock.molecules[D].rgba;l[f]=currentBlock.molecules[D].CA.AID;f++}}}else{w.push([currentBlock.xyz[D][0],currentBlock.xyz[D][1],currentBlock.xyz[D][2]]);if(C.length){C.push(C[f-1])}else{C.push([1,0,0])}h[f]=currentBlock.molecules[D].rgba;l[f]=currentBlock.molecules[D].CA.AID;f++}}}u.push(w.length);for(M=0,y=0;M<chain.twoDcache.length;M++){currentBlock=chain.twoDcache[M];if(chain.displayMode>2&&(currentBlock.sndStruc==2||currentBlock.sndStruc==3)&&!currentBlock.rocket){n=null;if(currentBlock.sndStruc==2){n=currentBlock.normals;I=currentBlock.molecules.length-(currentBlock.isLast?1:0);for(D=0;D<I;D++){for(E=0;E<s+1;E++,y++){d=C[y];p=vec3.lerp([0,0,0],n[D],n[D+1],H[E]);vec3.normalize(p,p);vec3.scaleAndAdd(p,p,d,-vec3.dot(p,d)/vec3.dot(d,d));vec3.normalize(p,p);A.push(p);G=vec3.cross([0,0,0],p,d);vec3.normalize(G,G);vec3.negate(G,G);g.push(G)}}if(I!=currentBlock.molecules.length){d=C[y];p=vec3.lerp([0,0,0],n[D],n[D+1],H[E]);vec3.normalize(p,p);vec3.scaleAndAdd(p,p,d,-vec3.dot(p,d)/vec3.dot(d,d));vec3.normalize(p,p);A.push(p);G=vec3.cross([0,0,0],p,d);vec3.normalize(G,G);vec3.negate(G,G);g.push(G);y++}}else{if(currentBlock.sndStruc==3){n=currentBlock.binormals;if(!currentBlock.isFirst&&!currentBlock.Nresume&&x){vec3.cross(z,C[y-1],C[y]);if(vec3.length(z)>L){vec3.normalize(z,z);theta=Math.acos(Math.max(-1,Math.min(1,vec3.dot(C[y-1],C[y]))));mat4.rotate(x,identityMatrix,theta,z);vec3.transformMat4(O,O,x)}vec3.cross(B,C[y],O);n[0]=[B[0],B[1],B[2]];if(vec3.dot(n[0],n[1])<0){I=currentBlock;E=1;while(true){for(D=E;D<I.molecules.length;D++){vec3.negate(I.binormals[D],I.binormals[D])}I.invertedBinormals=!I.invertedBinormals;I=I.nextBlock;E=0;if(!I){break}}}}I=currentBlock.molecules.length-(currentBlock.isLast?1:0);for(D=0;D<I;D++){for(E=0;E<s+1;E++,y++){d=C[y];G=vec3.lerp([0,0,0],n[D],n[D+1],H[E]);vec3.normalize(G,G);vec3.scaleAndAdd(G,G,d,-vec3.dot(G,d)/vec3.dot(d,d));vec3.normalize(G,G);g.push(G);p=vec3.cross([0,0,0],G,d);vec3.normalize(p,p);A.push(p)}}if(I!=currentBlock.molecules.length){d=C[y];G=[n[D+1][0],n[D+1][1],n[D+1][2]];vec3.normalize(G,G);vec3.scaleAndAdd(G,G,d,-vec3.dot(G,d)/vec3.dot(d,d));vec3.normalize(G,G);g.push(G);p=vec3.cross([0,0,0],G,d);vec3.normalize(p,p);A.push(p);y++}}}}else{y=A.length;x=mat4.create(),identityMatrix=mat4.create();if(y==0){smallest=Number.MAX_VALUE;if(C[0][0]<=smallest){smallest=C[0][0];O=[1,0,0]}if(C[0][1]<=smallest){smallest=C[0][1];O=[0,1,0]}if(C[0][2]<=smallest){smallest=C[0][2];O=[0,0,1]}vec3.cross(z,C[0],O);vec3.normalize(z,z);vec3.cross(O,C[0],z);vec3.cross(B=[0,0,0],C[0],O);A.push([O[0],O[1],O[2]]);g.push([B[0],B[1],B[2]]);y++}else{O=[A[y-1][0],A[y-1][1],A[y-1][2]];B=[g[y-1][0],g[y-1][1],g[y-1][2]]}for(;y<u[M+1];y++){vec3.cross(z,C[y-1],C[y]);if(vec3.length(z)>L){vec3.normalize(z,z);theta=Math.acos(Math.max(-1,Math.min(1,vec3.dot(C[y-1],C[y]))));mat4.rotate(x,identityMatrix,theta,z);vec3.transformMat4(O,O,x)}vec3.cross(B,C[y],O);A.push([O[0],O[1],O[2]]);g.push([B[0],B[1],B[2]])}}}A.push(A[A.length-1]);g.push(g[g.length-1]);y=0;for(M=0;M<chain.twoDcache.length;M++){currentBlock=chain.twoDcache[M];if(chain.displayMode>2){if(currentBlock.sndStruc==2){y=this.buildSheet(u[M],u[M+1],w,C,A,g,h,l,currentBlock.isFirst,currentBlock.isLast);continue}else{if(currentBlock.rocket){if(currentBlock.skip){continue}y=this.buildLoop(u[M],u[M]+currentBlock.rocketPre+(currentBlock.rocketPre?1:0),w,C,A,g,h,l);y=this.buildRocket(u[M]+currentBlock.rocketPre,u[M+1]-currentBlock.rocketPost,w,C,A,g,h,l,currentBlock.isLast);y=this.buildLoop(u[M+1]-currentBlock.rocketPost,u[M+1],w,C,A,g,h,l);continue}else{if(currentBlock.sndStruc==3){if(currentBlock.isFirst){this.buildLoopNcap(u[M],w,C,A,g,h,l);y++;u[M]+=1}y=this.buildHelix(u[M],u[M+1],w,C,A,g,h,l,currentBlock);if(currentBlock.isLast){this.buildLoopCcap(u[M+1]-1,w,C,A,g,h,l)}continue}}}}if(currentBlock.isFirst){this.buildLoopNcap(u[M],w,C,A,g,h,l);y++;u[M]+=1}y=this.buildLoop(u[M],u[M+1],w,C,A,g,h,l);if(currentBlock.isLast){this.buildLoopCcap(u[M+1]-1,w,C,A,g,h,l)}}}};molmil.geometry.buildLoopNcap=function(C,w,o,y,E,s,u){var q=this.dome[0],n=this.radius,K,J=this.ringTemplate;var h=this.buffer3.vertexBuffer,z=this.buffer3.indexBuffer,A=this.buffer3.vP,g=this.buffer3.iP,I,H,G,V,S,R,Q,O,L,f,d,U,M,D,l=this.buffer3.vertexBuffer8,x=A*4;var F=A*0.125;I=w[C][0],H=w[C][1],G=w[C][2],f=o[C][0],d=o[C][1],U=o[C][2],V=y[C][0],S=y[C][1],R=y[C][2],Q=E[C][0],O=E[C][1],L=E[C][2],M=s[C],D=u[C];for(K=0;K<q.vertices.length;K++,x+=32){h[A++]=n*q.vertices[K][0]*V+n*q.vertices[K][1]*Q+n*q.vertices[K][2]*f+I;h[A++]=n*q.vertices[K][0]*S+n*q.vertices[K][1]*O+n*q.vertices[K][2]*d+H;h[A++]=n*q.vertices[K][0]*R+n*q.vertices[K][1]*L+n*q.vertices[K][2]*U+G;h[A++]=q.vertices[K][0]*V+q.vertices[K][1]*Q+q.vertices[K][2]*f;h[A++]=q.vertices[K][0]*S+q.vertices[K][1]*O+q.vertices[K][2]*d;h[A++]=q.vertices[K][0]*R+q.vertices[K][1]*L+q.vertices[K][2]*U;l[x+24]=M[0];l[x+25]=M[1];l[x+26]=M[2];l[x+27]=M[3];A++;h[A++]=u[C]}for(K=0;K<q.faces.length;K++){z[g++]=q.faces[K][0]+F;z[g++]=q.faces[K][1]+F;z[g++]=q.faces[K][2]+F}for(K=0;K<J.length;K++,x+=32){h[A++]=n*J[K][0]*V+n*J[K][1]*Q+I;h[A++]=n*J[K][0]*S+n*J[K][1]*O+H;h[A++]=n*J[K][0]*R+n*J[K][1]*L+G;h[A++]=J[K][0]*V+J[K][1]*Q;h[A++]=J[K][0]*S+J[K][1]*O;h[A++]=J[K][0]*R+J[K][1]*L;l[x+24]=M[0];l[x+25]=M[1];l[x+26]=M[2];l[x+27]=M[3];A++;h[A++]=u[C]}this.buffer3.vP=A;this.buffer3.iP=g};molmil.geometry.buildLoopCcap=function(C,w,o,y,E,s,u){var q=this.dome[1],n=this.radius,K,J=this.ringTemplate;var h=this.buffer3.vertexBuffer,z=this.buffer3.indexBuffer,A=this.buffer3.vP,g=this.buffer3.iP,I,H,G,V,S,R,Q,O,L,f,d,U,M,D,l=this.buffer3.vertexBuffer8,x=A*4;var F=A*0.125;I=w[C][0],H=w[C][1],G=w[C][2],f=o[C][0],d=o[C][1],U=o[C][2],V=y[C][0],S=y[C][1],R=y[C][2],Q=E[C][0],O=E[C][1],L=E[C][2],M=s[C],D=u[C];for(K=0;K<q.vertices.length;K++,x+=32){h[A++]=n*q.vertices[K][0]*V+n*q.vertices[K][1]*Q+n*q.vertices[K][2]*f+I;h[A++]=n*q.vertices[K][0]*S+n*q.vertices[K][1]*O+n*q.vertices[K][2]*d+H;h[A++]=n*q.vertices[K][0]*R+n*q.vertices[K][1]*L+n*q.vertices[K][2]*U+G;h[A++]=q.vertices[K][0]*V+q.vertices[K][1]*Q+q.vertices[K][2]*f;h[A++]=q.vertices[K][0]*S+q.vertices[K][1]*O+q.vertices[K][2]*d;h[A++]=q.vertices[K][0]*R+q.vertices[K][1]*L+q.vertices[K][2]*U;l[x+24]=M[0];l[x+25]=M[1];l[x+26]=M[2];l[x+27]=M[3];A++;h[A++]=D}for(K=0;K<q.faces.length;K++){z[g++]=q.faces[K][0]+F;z[g++]=q.faces[K][1]+F;z[g++]=q.faces[K][2]+F}this.buffer3.vP=A;this.buffer3.iP=g};molmil.geometry.buildLoop=function(E,D,w,o,y,G,s,u){var q=this.dome[0],n=this.radius,M,A=this.novpr;var L=this.ringTemplate,n=this.radius,K,J,I,Y,W,V,U,S,Q,g,d,X,R,F;var h=this.buffer3.vertexBuffer,z=this.buffer3.indexBuffer,C=this.buffer3.vP,f=this.buffer3.iP,l=this.buffer3.vertexBuffer8,x=C*4;var H=C*0.125;var O=H-A;for(E;E<D;E++){K=w[E][0],J=w[E][1],I=w[E][2],g=o[E][0],d=o[E][1],X=o[E][2],Y=y[E][0],W=y[E][1],V=y[E][2],U=G[E][0],S=G[E][1],Q=G[E][2],R=s[E],F=u[E];for(M=0;M<L.length;M++,x+=32){h[C++]=n*L[M][0]*Y+n*L[M][1]*U+K;h[C++]=n*L[M][0]*W+n*L[M][1]*S+J;h[C++]=n*L[M][0]*V+n*L[M][1]*Q+I;h[C++]=L[M][0]*Y+L[M][1]*U;h[C++]=L[M][0]*W+L[M][1]*S;h[C++]=L[M][0]*V+L[M][1]*Q;l[x+24]=R[0];l[x+25]=R[1];l[x+26]=R[2];l[x+27]=R[3];C++;h[C++]=F}for(M=0;M<(A*2)-2;M+=2,H+=1,O+=1){z[f++]=H;z[f++]=O;z[f++]=O+1;z[f++]=O+1;z[f++]=H+1;z[f++]=H}z[f++]=H;z[f++]=O;z[f++]=O-(A-1);z[f++]=O-(A-1);z[f++]=H-(A-1);z[f++]=H;H++;O++}this.buffer3.vP=C;this.buffer3.iP=f;return E};molmil.geometry.buildRocket=function(U,ac,o,n,s,G,X,J,ab){var V=1.15,Y,f=this.novpr,y=false;var K=this.ringTemplate,O,M,L,E,D,C,w,u,q,I,H,F,g,d;var z=this.buffer3.vertexBuffer,x=this.buffer3.indexBuffer,R=this.buffer3.vP,Z=this.buffer3.iP,A=this.buffer3.vertexBuffer8,Q=R*4;var W=R*0.125;var l=W-f;var S=R;O=o[U][0],M=o[U][1],L=o[U][2],I=n[U][0],H=n[U][1],F=n[U][2],E=s[U][0],D=s[U][1],C=s[U][2],w=G[U][0],u=G[U][1],q=G[U][2],g=X[U],d=J[U];z[R++]=O;z[R++]=M;z[R++]=L;z[R++]=-I;z[R++]=-H;z[R++]=-F;A[Q+24]=g[0];A[Q+25]=g[1];A[Q+26]=g[2];A[Q+27]=g[3];R++;z[R++]=d;Q+=32;for(Y=0;Y<K.length;Y++,Q+=32){z[R++]=V*K[Y][0]*E+V*K[Y][1]*w+O;z[R++]=V*K[Y][0]*D+V*K[Y][1]*u+M;z[R++]=V*K[Y][0]*C+V*K[Y][1]*q+L;z[R++]=-I;z[R++]=-H;z[R++]=-F;A[Q+24]=g[0];A[Q+25]=g[1];A[Q+26]=g[2];A[Q+27]=g[3];R++;z[R++]=d}for(Y=0;Y<K.length;Y++){x[Z++]=W+Y+2;x[Z++]=W+Y+1;x[Z++]=W}x[Z-3]=W+1;W+=K.length+1;l=W-f;for(U;U<ac;U++){O=o[U][0],M=o[U][1],L=o[U][2],I=n[U][0],H=n[U][1],F=n[U][2],E=s[U][0],D=s[U][1],C=s[U][2],w=G[U][0],u=G[U][1],q=G[U][2],g=X[U],d=J[U];for(Y=0;Y<K.length;Y++,Q+=32){z[R++]=V*K[Y][0]*E+V*K[Y][1]*w+O;z[R++]=V*K[Y][0]*D+V*K[Y][1]*u+M;z[R++]=V*K[Y][0]*C+V*K[Y][1]*q+L;z[R++]=K[Y][0]*E+K[Y][1]*w;z[R++]=K[Y][0]*D+K[Y][1]*u;z[R++]=K[Y][0]*C+K[Y][1]*q;A[Q+24]=g[0];A[Q+25]=g[1];A[Q+26]=g[2];A[Q+27]=g[3];R++;z[R++]=d}for(Y=0;Y<(f*2)-2;Y+=2,W+=1,l+=1){x[Z++]=W+f;x[Z++]=l+f;x[Z++]=l+1+f;x[Z++]=l+1+f;x[Z++]=W+1+f;x[Z++]=W+f}x[Z++]=W+f;x[Z++]=l+f;x[Z++]=l-(f-1)+f;x[Z++]=l-(f-1)+f;x[Z++]=W-(f-1)+f;x[Z++]=W+f;W++;l++}for(Y=R-(K.length*8);Y<R;Y+=8){z[Y]-=I*2;z[Y+1]-=H*2;z[Y+2]-=F*2}for(Y=0;Y<K.length;Y++,Q+=32){z[R++]=V*K[Y][0]*E+V*K[Y][1]*w+O-I*2;z[R++]=V*K[Y][0]*D+V*K[Y][1]*u+M-H*2;z[R++]=V*K[Y][0]*C+V*K[Y][1]*q+L-F*2;z[R++]=K[Y][0]*E+K[Y][1]*w;z[R++]=K[Y][0]*D+K[Y][1]*u;z[R++]=K[Y][0]*C+K[Y][1]*q;A[Q+24]=g[0];A[Q+25]=g[1];A[Q+26]=g[2];A[Q+27]=g[3];R++;z[R++]=d}z[R++]=O;z[R++]=M;z[R++]=L;z[R++]=I;z[R++]=H;z[R++]=F;A[Q+24]=g[0];A[Q+25]=g[1];A[Q+26]=g[2];A[Q+27]=g[3];R++;Q+=32;z[R++]=d;for(Y=0;Y<K.length;Y++){x[Z++]=W+K.length;x[Z++]=W+Y;x[Z++]=W+Y+1}x[Z-1]=W;W+=K.length+1;l=W-f;V=this.radius;if(!ab){var aa=this.radius;for(Y=0;Y<K.length;Y++,Q+=32){z[R++]=aa*K[Y][0]*E+aa*K[Y][1]*w+O-I*V*2;z[R++]=aa*K[Y][0]*D+aa*K[Y][1]*u+M-H*V*2;z[R++]=aa*K[Y][0]*C+aa*K[Y][1]*q+L-F*V*2;z[R++]=K[Y][0]*E+K[Y][1]*w;z[R++]=K[Y][0]*D+K[Y][1]*u;z[R++]=K[Y][0]*C+K[Y][1]*q;A[Q+24]=g[0];A[Q+25]=g[1];A[Q+26]=g[2];A[Q+27]=g[3];R++;z[R++]=d}}this.buffer3.vP=R;this.buffer3.iP=Z;return U};molmil.geometry.buildHelix=function(Z,ak,q,o,u,G,af,M,X){var O=this.dome[0],aa=this.radius,ah,f=this.novpr;var Q=this.ringTemplate,aa=this.radius,U,S,R,E,D,C,x,w,s,I,H,F,h,d;var z=this.buffer3.vertexBuffer,y=this.buffer3.indexBuffer,W=this.buffer3.vP,ai=this.buffer3.iP,A=this.buffer3.vertexBuffer8,V=W*4;var ad=W*0.125;var l=ad-f;var ag,Y,g;var J=X.invertedBinormals,L=X.Nresume,K=X.Cresume;var ac=[0,0],aj=this.noi,ab=Z,ae=L?aj:0;for(Z;Z<ak;Z++){U=q[Z][0],S=q[Z][1],R=q[Z][2],I=o[Z][0],H=o[Z][1],F=o[Z][2],E=u[Z][0],D=u[Z][1],C=u[Z][2],x=G[Z][0],w=G[Z][1],s=G[Z][2],h=af[Z],d=M[Z];if(!L&&Z<ab+aj){ag=(ae/aj);ae++}else{if(!K&&Z>ak-aj-2){ag=(ae/(aj));ae--}else{ag=1}}Y=(5*ag)+1;g=1/Y;for(ah=0;ah<Q.length;ah++,V+=32){z[W++]=aa*Q[ah][0]*E+Y*aa*Q[ah][1]*x+U;z[W++]=aa*Q[ah][0]*D+Y*aa*Q[ah][1]*w+S;z[W++]=aa*Q[ah][0]*C+Y*aa*Q[ah][1]*s+R;ac[0]=Q[ah][0];ac[1]=g*Q[ah][1];vec2.normalize(ac,ac);z[W++]=ac[0]*E+ac[1]*x;z[W++]=ac[0]*D+ac[1]*w;z[W++]=ac[0]*C+ac[1]*s;if(ag>0.5&&((J&&z[W-3]*E+z[W-2]*D+z[W-1]*C<-0.01)||(!J&&z[W-3]*E+z[W-2]*D+z[W-1]*C>0.01))){A[V+24]=255;A[V+25]=255;A[V+26]=255;A[V+27]=255}else{A[V+24]=h[0];A[V+25]=h[1];A[V+26]=h[2];A[V+27]=h[3]}W++;z[W++]=d}for(ah=0;ah<(f*2)-2;ah+=2,ad+=1,l+=1){y[ai++]=ad;y[ai++]=l;y[ai++]=l+1;y[ai++]=l+1;y[ai++]=ad+1;y[ai++]=ad}y[ai++]=ad;y[ai++]=l;y[ai++]=l-(f-1);y[ai++]=l-(f-1);y[ai++]=ad-(f-1);y[ai++]=ad;ad++;l++}this.buffer3.vP=W;this.buffer3.iP=ai;return Z};molmil.geometry.buildSheet=function(ab,al,u,q,y,J,af,O,R,ak){var Q=this.dome[0],ac=this.radius,ag,f=this.novpr;var S=this.ringTemplate,ac=this.radius,W,V,U,H,G,F,A,z,x,L,K,I,g,d;var D=this.buffer3.vertexBuffer,C=this.buffer3.indexBuffer,Y=this.buffer3.vP,ah=this.buffer3.iP,E=this.buffer3.vertexBuffer8,X=Y*4;var ad=Y*0.125;var o=ad-f;var aa=this.squareVertices,aj=this.noi,M=this.squareVerticesN;var ai=this.sheetHeight,Z=ai*8;if(!R){W=(u[ab][0]*0.75)+(u[ab+1][0]*0.25),V=(u[ab][1]*0.75)+(u[ab][1]*0.25),U=(u[ab][2]*0.75)+(u[ab][2]*0.25),L=q[ab-1][0],K=q[ab-1][1],I=q[ab-1][2],H=y[ab-1][0],G=y[ab-1][1],F=y[ab-1][2],A=J[ab-1][0],z=J[ab-1][1],x=J[ab-1][2],g=af[ab-1],d=O[ab];for(ag=0;ag<S.length;ag++,X+=32){D[Y++]=ai*0.5*S[ag][0]*H+ai*0.5*S[ag][1]*A+W;D[Y++]=ai*0.5*S[ag][0]*G+ai*0.5*S[ag][1]*z+V;D[Y++]=ai*0.5*S[ag][0]*F+ai*0.5*S[ag][1]*x+U;D[Y++]=((S[ag][0]*H+S[ag][1]*A)+L)*0.5;D[Y++]=((S[ag][0]*G+S[ag][1]*z)+K)*0.5;D[Y++]=((S[ag][0]*F+S[ag][1]*x)+I)*0.5;E[X+24]=g[0];E[X+25]=g[1];E[X+26]=g[2];E[X+27]=g[3];Y++;D[Y++]=O[ab-1]}for(ag=0;ag<(f*2)-2;ag+=2,ad+=1,o+=1){C[ah++]=ad;C[ah++]=o;C[ah++]=o+1;C[ah++]=o+1;C[ah++]=ad+1;C[ah++]=ad}C[ah++]=ad;C[ah++]=o;C[ah++]=o-(f-1);C[ah++]=o-(f-1);C[ah++]=ad-(f-1);C[ah++]=ad;ad++;o++}W=u[ab][0],V=u[ab][1],U=u[ab][2],L=q[ab][0],K=q[ab][1],I=q[ab][2],H=y[ab][0],G=y[ab][1],F=y[ab][2],A=J[ab][0],z=J[ab][1],x=J[ab][2],g=af[ab],d=O[ab];for(ag=0;ag<4;ag++,X+=32){D[Y++]=ai*aa[ag][0]*H+Z*aa[ag][1]*A+W;D[Y++]=ai*aa[ag][0]*G+Z*aa[ag][1]*z+V;D[Y++]=ai*aa[ag][0]*F+Z*aa[ag][1]*x+U;D[Y++]=-L;D[Y++]=-K;D[Y++]=-I;E[X+24]=255;E[X+25]=255;E[X+26]=255;E[X+27]=255;Y++;D[Y++]=d}C[ah++]=ad;C[ah++]=ad+1;C[ah++]=ad+2;C[ah++]=ad;C[ah++]=ad+2;C[ah++]=ad+3;ad+=4;var s=Math.ceil(aj/1.5);var l=(ai*12)/s;s=al-s;var ae=0;for(ab;ab<s;ab++,ae++){W=u[ab][0],V=u[ab][1],U=u[ab][2],L=q[ab][0],K=q[ab][1],I=q[ab][2],H=y[ab][0],G=y[ab][1],F=y[ab][2],A=J[ab][0],z=J[ab][1],x=J[ab][2],g=af[ab],d=O[ab];for(ag=0;ag<4;ag++,X+=32){D[Y++]=ai*aa[ag][0]*H+Z*aa[ag][1]*A+W;D[Y++]=ai*aa[ag][0]*G+Z*aa[ag][1]*z+V;D[Y++]=ai*aa[ag][0]*F+Z*aa[ag][1]*x+U;D[Y++]=M[ag][0]*H+M[ag][1]*A;D[Y++]=M[ag][0]*G+M[ag][1]*z;D[Y++]=M[ag][0]*F+M[ag][1]*x;if(ag==1||ag==3){E[X+24]=255;E[X+25]=255;E[X+26]=255;E[X+27]=255}else{E[X+24]=g[0];E[X+25]=g[1];E[X+26]=g[2];E[X+27]=g[3]}Y++;D[Y++]=d;X+=32;D[Y++]=ai*aa[ag][0]*H+Z*aa[ag][1]*A+W;D[Y++]=ai*aa[ag][0]*G+Z*aa[ag][1]*z+V;D[Y++]=ai*aa[ag][0]*F+Z*aa[ag][1]*x+U;D[Y++]=M[ag+1][0]*H+M[ag+1][1]*A;D[Y++]=M[ag+1][0]*G+M[ag+1][1]*z;D[Y++]=M[ag+1][0]*F+M[ag+1][1]*x;if(ag==0||ag==2){E[X+24]=255;E[X+25]=255;E[X+26]=255;E[X+27]=255}else{E[X+24]=g[0];E[X+25]=g[1];E[X+26]=g[2];E[X+27]=g[3]}Y++;D[Y++]=d}if(ae>0){C[ah++]=ad-8;C[ah++]=ad-1;C[ah++]=ad+7;C[ah++]=ad-8;C[ah++]=ad+7;C[ah++]=ad+0;C[ah++]=ad-7;C[ah++]=ad+1;C[ah++]=ad+2;C[ah++]=ad-7;C[ah++]=ad+2;C[ah++]=ad-6;C[ah++]=ad-5;C[ah++]=ad+3;C[ah++]=ad+4;C[ah++]=ad-5;C[ah++]=ad+4;C[ah++]=ad-4;C[ah++]=ad-2;C[ah++]=ad-3;C[ah++]=ad+5;C[ah++]=ad-2;C[ah++]=ad+5;C[ah++]=ad+6}ad+=8}Z=ai*12;ab--;for(;ab<al;ab++,ae++){if(ab>=s){Z-=l}W=u[ab][0],V=u[ab][1],U=u[ab][2],L=q[ab][0],K=q[ab][1],I=q[ab][2],H=y[ab][0],G=y[ab][1],F=y[ab][2],A=J[ab][0],z=J[ab][1],x=J[ab][2],g=af[ab],d=O[ab];for(ag=0;ag<4;ag++,X+=32){D[Y++]=ai*aa[ag][0]*H+Z*aa[ag][1]*A+W;D[Y++]=ai*aa[ag][0]*G+Z*aa[ag][1]*z+V;D[Y++]=ai*aa[ag][0]*F+Z*aa[ag][1]*x+U;D[Y++]=M[ag][0]*H+M[ag][1]*A;D[Y++]=M[ag][0]*G+M[ag][1]*z;D[Y++]=M[ag][0]*F+M[ag][1]*x;if(ag==1||ag==3){E[X+24]=255;E[X+25]=255;E[X+26]=255;E[X+27]=255}else{E[X+24]=g[0];E[X+25]=g[1];E[X+26]=g[2];E[X+27]=g[3]}Y++;X+=32;D[Y++]=d;D[Y++]=ai*aa[ag][0]*H+Z*aa[ag][1]*A+W;D[Y++]=ai*aa[ag][0]*G+Z*aa[ag][1]*z+V;D[Y++]=ai*aa[ag][0]*F+Z*aa[ag][1]*x+U;D[Y++]=M[ag+1][0]*H+M[ag+1][1]*A;D[Y++]=M[ag+1][0]*G+M[ag+1][1]*z;D[Y++]=M[ag+1][0]*F+M[ag+1][1]*x;if(ag==0||ag==2){E[X+24]=255;E[X+25]=255;E[X+26]=255;E[X+27]=255}else{E[X+24]=g[0];E[X+25]=g[1];E[X+26]=g[2];E[X+27]=g[3]}Y++;D[Y++]=d}if(ae>0){C[ah++]=ad-8;C[ah++]=ad-1;C[ah++]=ad+7;C[ah++]=ad-8;C[ah++]=ad+7;C[ah++]=ad+0;C[ah++]=ad-7;C[ah++]=ad+1;C[ah++]=ad+2;C[ah++]=ad-7;C[ah++]=ad+2;C[ah++]=ad-6;C[ah++]=ad-5;C[ah++]=ad+3;C[ah++]=ad+4;C[ah++]=ad-5;C[ah++]=ad+4;C[ah++]=ad-4;C[ah++]=ad-2;C[ah++]=ad-3;C[ah++]=ad+5;C[ah++]=ad-2;C[ah++]=ad+5;C[ah++]=ad+6}ad+=8}if(!ak){L=q[ab][0],K=q[ab][1],I=q[ab][2],H=y[ab][0],G=y[ab][1],F=y[ab][2],A=J[ab][0],z=J[ab][1],x=J[ab][2],g=af[ab],d=O[ab];for(ag=0;ag<S.length;ag++,X+=32){D[Y++]=W;D[Y++]=V;D[Y++]=U;D[Y++]=-L;D[Y++]=-K;D[Y++]=-I;E[X+24]=g[0];E[X+25]=g[1];E[X+26]=g[2];E[X+27]=g[3];Y++;D[Y++]=O[ab]}ad+=S.length;for(ag=0;ag<S.length;ag++,X+=32){D[Y++]=ai*S[ag][0]*H+ai*S[ag][1]*A+W;D[Y++]=ai*S[ag][0]*G+ai*S[ag][1]*z+V;D[Y++]=ai*S[ag][0]*F+ai*S[ag][1]*x+U;D[Y++]=((S[ag][0]*H+S[ag][1]*A)-L)*0.5;D[Y++]=((S[ag][0]*G+S[ag][1]*z)-K)*0.5;D[Y++]=((S[ag][0]*F+S[ag][1]*x)-I)*0.5;E[X+24]=g[0];E[X+25]=g[1];E[X+26]=g[2];E[X+27]=g[3];Y++;D[Y++]=O[ab]}o=ad-f;for(ag=0;ag<(f*2)-2;ag+=2,ad+=1,o+=1){C[ah++]=ad;C[ah++]=o;C[ah++]=o+1;C[ah++]=o+1;C[ah++]=ad+1;C[ah++]=ad}C[ah++]=ad;C[ah++]=o;C[ah++]=o-(f-1);C[ah++]=o-(f-1);C[ah++]=ad-(f-1);C[ah++]=ad;ad++;o++}this.buffer3.vP=Y;this.buffer3.iP=ah;return ab};molmil.priestle_smoothing=function(p,l,n,o,h){var q,f=n-l,d=new Array(f),g=new Array(f);for(m=0;m<f;m++){d[m]=[0,0,0]}for(q=0;q<h;q++){for(m=1;m<f-1;m++){d[m][0]=(p[l+m-1][0]+p[l+m+1][0])*0.5;d[m][1]=(p[l+m-1][1]+p[l+m+1][1])*0.5;d[m][2]=(p[l+m-1][2]+p[l+m+1][2])*0.5;d[m][0]=(d[m][0]+p[l+m][0])*0.5;d[m][1]=(d[m][1]+p[l+m][1])*0.5;d[m][2]=(d[m][2]+p[l+m][2])*0.5}for(m=1;m<f-1;m++){if(!o.hasOwnProperty(m)){p[l+m][0]=d[m][0];p[l+m][1]=d[m][1];p[l+m][2]=d[m][2]}}}};var numeric=(typeof exports==="undefined")?(function numeric(){}):(exports);if(typeof global!=="undefined"){global.numeric=numeric}numeric.version="1.2.6";numeric.dotMMsmall=function(C,B){var t,o,l,g,f,d,w,A,u,s,n,z,D,h;g=C.length;f=B.length;d=B[0].length;w=Array(g);for(t=g-1;t>=0;t--){A=Array(d);u=C[t];for(l=d-1;l>=0;l--){s=u[f-1]*B[f-1][l];for(o=f-2;o>=1;o-=2){n=o-1;s+=u[o]*B[o][l]+u[n]*B[n][l]}if(o===0){s+=u[0]*B[0][l]}A[l]=s}w[t]=A}return w};numeric._getCol=function(f,g,d){var l=f.length,h;for(h=l-1;h>0;--h){d[h]=f[h][g];--h;d[h]=f[h][g]}if(h===0){d[0]=f[0][g]}};numeric.dotMMbig=function(B,w){var C=numeric._getCol,d=w.length,D=Array(d);var h=B.length,g=w[0].length,f=new Array(h),t;var o=numeric.dotVV;var s,q,l,u;--d;--h;for(s=h;s!==-1;--s){f[s]=Array(g)}--g;for(s=g;s!==-1;--s){C(w,s,D);for(q=h;q!==-1;--q){u=0;t=B[q];f[q][s]=o(t,D)}}return f};numeric.dotMV=function(d,o){var l=d.length,h=o.length,g;var f=Array(l),n=numeric.dotVV;for(g=l-1;g>=0;g--){f[g]=n(d[g],o)}return f};numeric.dotVM=function(s,o){var D,C,B,w,u,t,I,G,F,l,A,n,g,E,h,f,d,z,H;w=s.length;u=o[0].length;I=Array(u);for(B=u-1;B>=0;B--){l=s[w-1]*o[w-1][B];for(C=w-2;C>=1;C-=2){A=C-1;l+=s[C]*o[C][B]+s[A]*o[A][B]}if(C===0){l+=s[0]*o[0][B]}I[B]=l}return I};numeric.dotVV=function(d,o){var g,l=d.length,h,f=d[l-1]*o[l-1];for(g=l-2;g>=1;g-=2){h=g-1;f+=d[g]*o[g]+d[h]*o[h]}if(g===0){f+=d[0]*o[0]}return f};numeric.dot=function(f,h){var g=numeric.dim;switch(g(f).length*1000+g(h).length){case 2002:if(h.length<10){return numeric.dotMMsmall(f,h)}else{return numeric.dotMMbig(f,h)}case 2001:return numeric.dotMV(f,h);case 1002:return numeric.dotVM(f,h);case 1001:return numeric.dotVV(f,h);case 1000:return numeric.mulVS(f,h);case 1:return numeric.mulSV(f,h);case 0:return f*h;default:throw new Error("numeric.dot only works on vectors and matrices")}};numeric.dim=function(d){var g,f;if(typeof d==="object"){g=d[0];if(typeof g==="object"){f=g[0];if(typeof f==="object"){return numeric._dim(d)}return[d.length,g.length]}return[d.length]}return[]};numeric.transpose=function(s){var p,l,g=s.length,d=s[0].length,q=Array(d),h,f,o;for(l=0;l<d;l++){q[l]=Array(g)}for(p=g-1;p>=1;p-=2){f=s[p];h=s[p-1];for(l=d-1;l>=1;--l){o=q[l];o[p]=f[l];o[p-1]=h[l];--l;o=q[l];o[p]=f[l];o[p-1]=h[l]}if(l===0){o=q[0];o[p]=f[0];o[p-1]=h[0]}}if(p===0){h=s[0];for(l=d-1;l>=1;--l){q[l][0]=h[l];--l;q[l][0]=h[l]}if(l===0){q[0][0]=h[0]}}return q};numeric.inv=function(u){var C=numeric.dim(u),D=Math.abs,h=C[0],g=C[1];var f=numeric.clone(u),y,t;var w=numeric.identity(h),d,B;var q,p,l,u;for(p=0;p<g;++p){var o=-1;var z=-1;for(q=p;q!==h;++q){l=D(f[q][p]);if(l>z){o=q;z=l}}t=f[o];f[o]=f[p];f[p]=t;B=w[o];w[o]=w[p];w[p]=B;u=t[p];for(l=p;l!==g;++l){t[l]/=u}for(l=g-1;l!==-1;--l){B[l]/=u}for(q=h-1;q!==-1;--q){if(q!==p){y=f[q];d=w[q];u=y[p];for(l=p+1;l!==g;++l){y[l]-=t[l]*u}for(l=g-1;l>0;--l){d[l]-=B[l]*u;--l;d[l]-=B[l]*u}if(l===0){d[0]-=B[0]*u}}}}return w};numeric.sclone=numeric.clone=function(d,f,l){if(typeof f==="undefined"){f=0}if(typeof l==="undefined"){l=numeric.dim(d).length}var h,g=Array(d.length);if(f===l-1){for(h in d){if(d.hasOwnProperty(h)){g[h]=d[h]}}return g}for(h in d){if(d.hasOwnProperty(h)){g[h]=numeric.clone(d[h],f+1,l)}}return g};numeric.identity=function(d){return numeric.diag(numeric.rep([d],1))};numeric.diag=function(p){var l,o,h,q=p.length,f=Array(q),g;for(l=q-1;l>=0;l--){g=Array(q);o=l+2;for(h=q-1;h>=o;h-=2){g[h]=0;g[h-1]=0}if(h>l){g[h]=0}g[l]=p[l];for(h=l-1;h>=1;h-=2){g[h]=0;g[h-1]=0}if(h===0){g[0]=0}f[l]=g}return f};numeric.rep=function(l,f,d){if(typeof d==="undefined"){d=0}var o=l[d],g=Array(o),h;if(d===l.length-1){for(h=o-2;h>=0;h-=2){g[h+1]=f;g[h]=f}if(h===-1){g[0]=f}return g}for(h=o-1;h>=0;h--){g[h]=numeric.rep(l,f,d+1)}return g};molmil.polynomialFit=function(u,t,f){var z=[],w,l,h;var s=numeric.transpose([t]);for(h=0;h<u.length;h++){w=[1];for(l=1;l<=f;l++){w.push(w[l-1]*u[h])}z.push(w)}var p=numeric.transpose(z);var o=numeric.dot(p,z);var d=numeric.inv(o);var n=numeric.dot(p,s);var q=numeric.dot(d,n);var g=[];for(l=0;l<q.length;l++){g.push(q[l][0])}return g};molmil.polynomialCalc=function(d,g){var f,h=g[0];for(f=1;f<g.length;f++){h+=g[f]*Math.pow(d,f)}return h};molmil.prepare2DRepr=function(aa,F){if(aa.modelsXYZ.length<=F){F=0}var g=32*Math.PI/180,f=-11*Math.PI/180,D=Math.cos(g),L=Math.sin(g),C=Math.cos(f),J=Math.sin(f),Z=4.7,h=0.5,w=5.2,ad,ac=[0,0,0],l=[0,0,0],X=[0,0,0],U=[0,0,0],E=molmil.configBox.smoothFactor,u;if(aa.molecules.length<2||aa.isHet){return aa.displayMode=0}var s=aa.twoDcache=[],P,R,H,ab,O=aa.molecules.length,Y,V,T,S,G,o=[],N,p,B;for(P=0;P<O;P++){if(!aa.molecules[P].CA){continue}if(aa.molecules[P].sndStruc!=R||aa.molecules[P].previous==null){R=aa.molecules[P].sndStruc;s.push(H={molecules:[],xyz:[],sndStruc:R})}H.molecules.push(aa.molecules[P]);Y=aa.molecules[P].CA.xyz;V=[aa.modelsXYZ[F][Y],aa.modelsXYZ[F][Y+1],aa.modelsXYZ[F][Y+2]];H.xyz.push(V);o.push(V)}O=o.length;for(ab=0,N=0;ab<s.length;ab++){H=s[ab];if(H.molecules[0].xna){H.sndStruc=molmil.displayMode_XNA}H.isFirst=H.molecules[0].previous==null||H.molecules[0].previous.name=="ACE"||!H.molecules[0].previous.CA;H.isLast=H.molecules[H.molecules.length-1].next==null||H.molecules[H.molecules.length-1].next.name=="NME"||!H.molecules[H.molecules.length-1].next.CA;if(H.sndStruc==3){if(H.molecules.length>2){H.waypoints=[];H.waypoint_tangents=[];var A=[],M=[],K=[],I=[],t=Math.floor(H.molecules.length/8);if(t>5){t=5}else{if(t<1){t=1}}if(!H.isFirst){A.push(-(Math.sqrt(Math.pow(o[N-1][0]-o[N][0],2)+Math.pow(o[N-1][1]-o[N][1],2)+Math.pow(o[N-1][2]-o[N][2],2))));M.push(o[N-1][0]);K.push(o[N-1][1]);I.push(o[N-1][2])}for(Y=0;Y<H.molecules.length;Y++){if(H.molecules[Y].displayMode==31){H.rocket=true}if(Y>0){A.push(A[A.length-1]+Math.sqrt(Math.pow(o[N+Y][0]-o[N+Y-1][0],2)+Math.pow(o[N+Y][1]-o[N+Y-1][1],2)+Math.pow(o[N+Y][2]-o[N+Y-1][2],2)))}else{A.push(0)}M.push(o[N+Y][0]);K.push(o[N+Y][1]);I.push(o[N+Y][2])}if(!H.isLast){A.push(A[Y-1]+Math.sqrt(Math.pow(o[N+Y-1][0]-o[N+Y][0],2)+Math.pow(o[N+Y-1][1]-o[N+Y][1],2)+Math.pow(o[N+Y-1][2]-o[N+Y][2],2)));M.push(o[N+Y][0]);K.push(o[N+Y][1]);I.push(o[N+Y][2])}M=molmil.polynomialFit(A,M,t);K=molmil.polynomialFit(A,K,t);I=molmil.polynomialFit(A,I,t);var Q=Math.round(H.molecules.length/2);if(Q<2){Q=2}if(molmil.configBox.liteMode){Q=2}var q=(A[A.length-1]-6)/(Q-1),d=3;for(Y=0;Y<Q;Y++){H.waypoints.push([molmil.polynomialCalc(d,M),molmil.polynomialCalc(d,K),molmil.polynomialCalc(d,I)]);d+=q}H.waypoint_tangents.push([H.waypoints[1][0]-H.waypoints[0][0],H.waypoints[1][1]-H.waypoints[0][1],H.waypoints[1][2]-H.waypoints[0][2]]);for(Y=1;Y<H.waypoints.length-1;Y++){H.waypoint_tangents.push([H.waypoints[Y+1][0]-H.waypoints[Y-1][0],H.waypoints[Y+1][1]-H.waypoints[Y-1][1],H.waypoints[Y+1][2]-H.waypoints[Y-1][2]])}Y=H.waypoints.length-1;H.waypoint_tangents.push([H.waypoints[Y][0]-H.waypoints[Y-1][0],H.waypoints[Y][1]-H.waypoints[Y-1][1],H.waypoints[Y][2]-H.waypoints[Y-1][2]]);for(Y=0;Y<H.waypoint_tangents.length;Y++){vec3.normalize(H.waypoint_tangents[Y],H.waypoint_tangents[Y])}if(vec3.distance(H.waypoints[0],H.waypoints[H.waypoints.length-1])<2){H.rocket=false;H.sndStruc=1}if(H.rocket){o[N]=H.waypoints[0];o[N+H.molecules.length-1]=H.waypoints[H.waypoints.length-1]}}else{H.sndStruc=1}}N+=H.molecules.length}for(ab=0,N=0;ab<s.length;ab++){H=s[ab];if(H.molecules.length<3){H.sndStruc=1}if(H.sndStruc!=3&&H.sndStruc!=4&&H.sndStruc!=molmil.displayMode_XNA){if(H.sndStruc==2){H.normals=[[]],G=null;for(P=1;P<H.molecules.length-1;P++){G=vec3.add([0,0,0],H.xyz[P-1],H.xyz[P+1]);G[0]/=2;G[1]/=2;G[2]/=2;vec3.subtract(G,H.xyz[P],G);vec3.normalize(G,G);if(P>1&&vec3.dot(H.normals[P-1],G)<0){vec3.negate(G,G)}H.normals.push(G)}if(G==null){if(!H.isFirst&&!H.isLast){Y=s[ab-1].xyz[s[ab-1].xyz.length-1];V=H.xyz[0];T=s[ab+1].xyz[0];G=vec3.add([0,0,0],Y,T);G[0]/=2;G[1]/=2;G[2]/=2;vec3.subtract(G,V,G);vec3.normalize(G,G);X[0]=T[0]-V[0];X[1]=T[1]-V[1];X[2]=T[2]-V[2];vec3.normalize(X,X);vec3.cross(U,X,G);vec3.cross(G,U,X);H.normals.push(G)}else{G=[0,0,0];H.normals.push(G)}}else{H.normals.push(G)}while(H.normals.length<H.molecules.length){H.normals.push(G)}H.normals[0]=H.normals[1];H.normals[H.normals.length-1]=H.normals[H.normals.length-2];p=new Array(H.normals.length);for(Y=0;Y<2;Y++){for(P=1;P<H.molecules.length-1;P++){p[P]=[H.normals[P-1][0]+H.normals[P][0]+H.normals[P+1][0],H.normals[P-1][1]+H.normals[P][1]+H.normals[P+1][1],H.normals[P-1][2]+H.normals[P][2]+H.normals[P+1][2]];vec3.normalize(p[P],p[P])}for(P=1;P<H.molecules.length-1;P++){H.normals[P]=p[P]}H.normals[0]=H.normals[1];H.normals[H.normals.length-1]=H.normals[H.normals.length-2]}for(P=0;P<H.molecules.length-1;P++){X[0]=H.xyz[P+1][0]-H.xyz[P][0];X[1]=H.xyz[P+1][1]-H.xyz[P][1];X[2]=H.xyz[P+1][2]-H.xyz[P][2];vec3.cross(U,X,H.normals[P]);vec3.cross(H.normals[P],U,X);vec3.normalize(H.normals[P],H.normals[P])}H.normals.push(H.normals[H.normals.length-1])}if(E>0){u={};for(P=0;P<H.molecules.length;P++){if(H.molecules[P].showSC){u[P+(H.isFirst?0:1)]=true}}if(!H.isLast&&s[ab+1].molecules[0].showSC){u[H.molecules.length]=true}molmil.priestle_smoothing(o,N-(H.isFirst?0:1),N+H.molecules.length+(H.isLast?0:1),u,E)}}N+=H.molecules.length}for(ab=0,N=0;ab<s.length;ab++){H=s[ab];H.tangents=new Array(H.molecules.length+1);for(P=0;P<H.molecules.length+1;P++){H.tangents[P]=[0,0,0]}if((H.sndStruc==3||H.sndStruc==4)&&H.molecules.length<3){H.sndStruc=1}if(H.molecules[0].xna){ad=w}else{ad=Z}if(H.sndStruc==molmil.displayMode_XNA){P=0;if(P+N<1){V=o[0];S=o[2]}else{if(P+N==O-1){V=o[P+N-1];S=o[P+N]}else{if(P+N<O-1){V=o[P+N-1];S=o[P+N+1]}}}X[0]=S[0]-V[0];X[1]=S[1]-V[1];X[2]=S[2]-V[2];vec3.normalize(X,X);H.tangents[0]=[X[0]*ad,X[1]*ad,X[2]*ad];G=H.molecules.length-(ab==s.length-1);for(P=1;P<G;P++){V=o[P+N-1];T=o[P+N];S=o[P+N+1];H.tangents[P][0]=S[0]-V[0];H.tangents[P][1]=S[1]-V[1];H.tangents[P][2]=S[2]-V[2];vec3.normalize(H.tangents[P],H.tangents[P]);H.tangents[P][0]*=ad;H.tangents[P][1]*=ad;H.tangents[P][2]*=ad}if(P+N<1){V=o[0];S=o[2]}else{if(P+N==O-1){V=o[P+N-1];S=o[P+N]}else{if(P+N<O-1){V=o[P+N-1];S=o[P+N+1]}}}X[0]=S[0]-V[0];X[1]=S[1]-V[1];X[2]=S[2]-V[2];vec3.normalize(X,X);H.tangents[H.tangents.length-1]=[X[0]*ad,X[1]*ad,X[2]*ad];if(G!=H.molecules.length&&H.molecules.length>2){H.tangents[H.tangents.length-2]=H.tangents[H.tangents.length-1]}}else{if(H.sndStruc==3||H.sndStruc==4){H.binormals=new Array(H.molecules.length+1);P=0;if(P+N<1){V=o[0];S=o[2]}else{if(P+N==O-1){V=o[P+N-1];S=o[P+N]}else{if(P+N<O-1){V=o[P+N-1];S=o[P+N+1]}}}X[0]=S[0]-V[0];X[1]=S[1]-V[1];X[2]=S[2]-V[2];vec3.normalize(X,X);H.tangents[0]=[X[0]*ad,X[1]*ad,X[2]*ad];G=H.molecules.length-(ab==s.length-1);for(P=1;P<G;P++){V=o[P+N-1];T=o[P+N];S=o[P+N+1];H.tangents[P][0]=S[0]-V[0];H.tangents[P][1]=S[1]-V[1];H.tangents[P][2]=S[2]-V[2];ac[0]=S[0]-V[0];ac[1]=S[1]-V[1];ac[2]=S[2]-V[2];vec3.normalize(ac,ac);X[0]=T[0]-V[0];X[1]=T[1]-V[1];X[2]=T[2]-V[2];U[0]=S[0]-T[0];U[1]=S[1]-T[1];U[2]=S[2]-T[2];vec3.cross(l,X,U);vec3.normalize(l,l);X[0]=D*l[0];X[1]=D*l[1];X[2]=D*l[2];U[0]=L*ac[0];U[1]=L*ac[1];U[2]=L*ac[2];H.binormals[P]=[X[0]+U[0],X[1]+U[1],X[2]+U[2]];X[0]=C*ac[0];X[1]=C*ac[1];X[2]=C*ac[2];U[0]=J*l[0];U[1]=J*l[1];U[2]=J*l[2];H.tangents[P][0]=(X[0]+U[0])*ad;H.tangents[P][1]=(X[1]+U[1])*ad;H.tangents[P][2]=(X[2]+U[2])*ad;vec3.cross(X,H.binormals[P],H.tangents[P]);vec3.cross(H.binormals[P],H.tangents[P],X);vec3.normalize(H.binormals[P],H.binormals[P])}if(P+N<1){V=o[0];S=o[2]}else{if(P+N==O-1){V=o[P+N-1];S=o[P+N]}else{if(P+N<O-1){V=o[P+N-1];S=o[P+N+1]}}}X[0]=S[0]-V[0];X[1]=S[1]-V[1];X[2]=S[2]-V[2];vec3.normalize(X,X);H.tangents[H.tangents.length-1]=[X[0]*ad,X[1]*ad,X[2]*ad];if(G!=H.molecules.length){H.tangents[H.tangents.length-2]=H.tangents[H.tangents.length-1];X=H.binormals[H.binormals.length-3];H.binormals[H.binormals.length-2]=[-X[0],-X[1],-X[2]]}H.binormals[0]=H.binormals[1];H.binormals[H.binormals.length-1]=H.binormals[H.binormals.length-2]}else{B=H.sndStruc==5?144:60;if(o.length<3){if(o.length==1){H.tangents[0]=H.tangents[1]=[1,0,0]}else{H.tangents[0]=H.tangents[1]=H.tangents[2]=[o[1][0]-o[0][0],o[1][1]-o[0][1],o[1][2]-o[0][2]]}}else{for(P=0;P<H.molecules.length+1;P++){if(P+N<1){V=o[0];S=o[2]}else{if(P+N==O-1){V=o[P+N-1];S=o[P+N]}else{if(P+N<O-1){V=o[P+N-1];S=o[P+N+1]}}}X[0]=S[0]-V[0];X[1]=S[1]-V[1];X[2]=S[2]-V[2];if(X[0]*X[0]+X[1]*X[1]+X[2]*X[2]>B){H.tangents[P]=H.tangents[P>0?P-1:P+1]}else{H.tangents[P][0]=X[0]*h;H.tangents[P][1]=X[1]*h;H.tangents[P][2]=X[2]*h}}if(H.molecules[P-2].next==null&&P+N-3>-1){H.tangents[P-1][0]=o[P+N-2][0]-o[P+N-3][0];H.tangents[P-1][1]=o[P+N-2][1]-o[P+N-3][1];H.tangents[P-1][2]=o[P+N-2][2]-o[P+N-3][2]}}}}N+=H.molecules.length}var W;for(ab=0;ab<s.length;ab++){H=s[ab];if(H.sndStruc==3&&!H.rocket){G=H.molecules.length-(ab==s.length-1?1:0);for(P=1;P<G;P++){if(vec3.dot(H.binormals[P-1],H.binormals[P])<0){W={molecules:[],xyz:[],tangents:[],binormals:[],sndStruc:3};H.nextBlock=W;H.Cresume=true;W.Nresume=true;W.invertedBinormals=!H.invertedBinormals;W.isLast=H.isLast;H.isLast=false;for(N=P;N<H.binormals.length;N++){vec3.negate(H.binormals[N],H.binormals[N])}W.molecules=H.molecules.slice(P);W.tangents=H.tangents.slice(P);W.binormals=H.binormals.slice(P);W.xyz=H.xyz.slice(P);H.molecules=H.molecules.splice(0,P);H.tangents=H.tangents.splice(0,P+1);H.binormals=H.binormals.splice(0,P+1);H.xyz=H.xyz.splice(0,P);if(H.rocket){W.rocket=W.skip=true;W.waypoints=H.waypoints;W.waypoint_tangents=H.waypoint_tangents}if(H.molecules.length==1){H.invertedBinormals=!H.invertedBinormals}s.splice(ab+1,0,W);break}}if(vec3.dot(H.binormals[P-1],H.binormals[P])<0){vec3.negate(H.binormals[P],H.binormals[P])}}}};molmil.render=function(d){this.canvas=null;this.reloadSettings();this.programs=[];this.clearCut=0;this.fogStart=0;this.camera=new molmil.glCamera();this.soup=d;this.modelViewMatrix=mat4.create();this.projectionMatrix=mat4.create();this.pitch=0;this.heading=0;this.TransX=0;this.TransY=0;this.TransZ=0;this.pitchAngle=0;this.headingAngle=0;this.TransB=[0.5,0.5,0];this.animationMode=false;this.framesDefinition=[];this.framesBuffer=[];this.textures={};this.FBOs={};this.shaders={};this.buffers={};this.gl=null;this.modelId=0};molmil.render.prototype.clear=function(){for(var d=0;d<this.programs.length;d++){this.gl.deleteBuffer(this.programs[d].vertexBuffer);this.gl.deleteBuffer(this.programs[d].indexBuffer)}this.programs=[];this.program1=this.program2=this.program3=this.program4=this.program5=undefined};molmil.render.prototype.reloadSettings=function(){this.QLV=localStorage.getItem("molmil.settings_QLV");if(this.QLV==null){this.QLV=2;localStorage.setItem("molmil.settings_QLV",this.QLV)}else{this.QLV=parseInt(this.QLV)}if(molmil.configBox.liteMode){this.QLV=1}if(this.gl){this.gl.clearColor.apply(this.gl,molmil.configBox.BGCOLOR)}this.settings={}};molmil.render.prototype.selectDefaultContext=function(){this.gl=this.defaultContext};molmil.render.prototype.selectDataContext=function(){if(!this.dataContext){this.dataContext=this.canvas.getContext("webgl",{preserveDrawingBuffer:true})||this.canvas.getContext("experimental-webgl",{preserveDrawingBuffer:true})}this.gl=this.dataContext};molmil.generateSphereImposterTexture=function(C,y){var h=[50,50,100+250],p,o,s,n,d,g=[0,0,0],t=[0,0,0],w=[0,0,0],l=[0,0,0],f,B;var A=new Uint8Array(C*C*4);for(var z=0;z<C;z++){p=((z/C)*2)-1;for(var x=0;x<C;x++){o=((x/C)*2)-1;s=Math.sqrt(Math.pow(p,2)+Math.pow(o,2));if(s<1){g[0]=p;g[1]=o;g[2]=Math.sqrt(1-g[0]*g[0]-g[1]*g[1]);t[0]=h[0]-g[0];t[1]=h[1]-g[1];t[2]=h[2]-g[2];vec3.normalize(t,t);f=Math.min(Math.max(vec3.dot(g,t),0),1);B=vec3.dot(g,t);l[0]=t[0]-2*B*g[0];l[1]=t[1]-2*B*g[1];l[2]=t[2]-2*B*g[2];vec3.negate(w,g);vec3.normalize(w,w);B=Math.pow(Math.max(vec3.dot(l,w),0),64)*0.5;A[((x*(C*4))+(z*4))+0]=f*255;A[((x*(C*4))+(z*4))+1]=B*255;A[((x*(C*4))+(z*4))+2]=g[2]*255;A[((x*(C*4))+(z*4))+3]=255}else{A[((x*(C*4))+(z*4))+0]=0;A[((x*(C*4))+(z*4))+1]=0;A[((x*(C*4))+(z*4))+2]=0;A[((x*(C*4))+(z*4))+3]=0}}}var q=y.createTexture();y.bindTexture(y.TEXTURE_2D,q);y.texImage2D(y.TEXTURE_2D,0,y.RGBA,C,C,0,y.RGBA,y.UNSIGNED_BYTE,A);y.pixelStorei(y.UNPACK_FLIP_Y_WEBGL,true);y.texParameteri(y.TEXTURE_2D,y.TEXTURE_MAG_FILTER,y.LINEAR);y.texParameteri(y.TEXTURE_2D,y.TEXTURE_MIN_FILTER,y.LINEAR);y.texParameteri(y.TEXTURE_2D,y.TEXTURE_WRAP_S,y.CLAMP_TO_EDGE);y.texParameteri(y.TEXTURE_2D,y.TEXTURE_WRAP_T,y.CLAMP_TO_EDGE);y.bindTexture(y.TEXTURE_2D,null);q.loaded=true;return q};molmil.render.prototype.initGL=function(f,l,d){if(window.WebGL2RenderingContext&&molmil.configBox.webGL2){this.defaultContext=f.getContext("webgl2")||f.getContext("experimental-webgl2");if(this.defaultContext){molmil.configBox.webGL2=true}}this.defaultContext=this.defaultContext||f.getContext("webgl")||f.getContext("experimental-webgl");f.renderer=this;if(!this.defaultContext){this.altCanvas=molmil.__webglNotSupported__(f);return false}this.gl=this.defaultContext;this.gl.boundAttributes={};molmil.configBox.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint");this.textures.atom_imposter=molmil.generateSphereImposterTexture(128,this.gl);this.gl.INDEXINT=molmil.configBox.OES_element_index_uint?this.gl.UNSIGNED_INT:this.gl.UNSIGNED_SHORT;this.width=l|f.width;this.height=d|f.height;this.gl.viewportWidth=this.width;this.gl.viewportHeight=this.height;f.onmousedown=molmil.handle_molmilViewer_mouseDown;document.onmouseup=molmil.handle_molmilViewer_mouseUp;document.onmousemove=molmil.handle_molmilViewer_mouseMove;f.addEventListener(molmil_dep.dBT.MFF?"DOMMouseScroll":"mousewheel",molmil.handle_molmilViewer_mouseScroll,false);f.addEventListener("touchstart",molmil.handle_molmilViewer_touchStart,false);f.addEventListener("touchmove",molmil.handle_molmilViewer_touchMove,false);f.addEventListener("touchend",molmil.handle_molmilViewer_touchEnd,false);this.gl.clearColor.apply(this.gl,molmil.configBox.BGCOLOR);this.gl.enable(this.gl.DEPTH_TEST);if(molmil.configBox.cullFace){this.gl.enable(this.gl.CULL_FACE);this.gl.cullFace(this.gl.BACK)}this.canvas=f;var g=this.gl.getParameter(this.gl.ALIASED_LINE_WIDTH_RANGE);this.angle=g&&g.length==2&&g[0]==1&&g[1]==1;return true};molmil.render.prototype.initRenderer=function(){this.initShaders(molmil.configBox.glsl_shaders);this.resizeViewPort()};molmil.shaderEngine={code:{}};molmil.shaderEngine.recompile=function(g){var f="";if(molmil.configBox.glsl_fog){f+="#define ENABLE_FOG 1\n"}if(g.settings.slab){f+="#define ENABLE_SLAB 1\n"}for(var d in g.shaders){g.shaders[d].compile(f)}};molmil.render.prototype.initShaders=function(h){var w=this;var d,n,y,u,l,h=molmil.configBox.glsl_shaders,q,g;for(var f=0;f<h.length;f++){l=h[f][0];d=h[f][1]||l.replace(/\\/g,"/").replace(/.*\//,"").split(".")[0];q=h[f].length>3?h[f][3]:[];g=false;for(var t=0;t<q.length;t++){if(!molmil.configBox[q[t]]){molmil.configBox[q[t]]=this.gl.getExtension(q[t])}g=g||!molmil.configBox[q[t]]}if(g){continue}if(!molmil.shaderEngine.code.hasOwnProperty(molmil.settings.src+l)){var o=new molmil_dep.CallRemote("GET");o.ASYNC=false;o.Send(molmil.settings.src+l);molmil.shaderEngine.code[molmil.settings.src+l]=o.request.responseText}}var d,n,y,u,l,x,h=molmil.configBox.glsl_shaders,s;for(var f=0;f<h.length;f++){l=h[f][0];d=h[f][1]||l.replace(/\\/g,"/").replace(/.*\//,"").split(".")[0];u=molmil.shaderEngine.code[molmil.settings.src+l];if(!u){continue}source=u.split("//#");s=JSON.parse(source[0]);s.name=d;s.vertexShader=source[1].substr(7);s.fragmentShader=source[2].substr(9);s.defines=h[f][2]||"";s.compile=function(p){this.program=w.gl.createProgram();molmil.setupShader(w.gl,this.name+"_v",this.program,p+this.defines+this.vertexShader,w.gl.VERTEX_SHADER);molmil.setupShader(w.gl,this.name+"_f",this.program,p+this.defines+this.fragmentShader,w.gl.FRAGMENT_SHADER);w.gl.linkProgram(this.program);if(!w.gl.getProgramParameter(this.program,w.gl.LINK_STATUS)){console.log("Could not initialise shaders for "+this.name)}w.gl.useProgram(this.program);for(u in this.attributes){this.attributes[u]=w.gl.getAttribLocation(this.program,u)}for(u in this.uniforms){this.uniforms[u]=w.gl.getUniformLocation(this.program,u)}};w.shaders[d]=s}molmil.shaderEngine.recompile(w)};molmil.setupShader=function(n,f,d,l,g){var h=n.createShader(g);n.shaderSource(h,l);n.compileShader(h);if(!n.getShaderParameter(h,n.COMPILE_STATUS)){console.log(f+":\n"+n.getShaderInfoLog(h));return null}n.attachShader(d,h);return h};molmil.render.prototype.updateSelection=function(){var l=new Float32Array(this.soup.atomSelection.length*8*6),f=[255,255,0];var h;for(var g=0,n=0,d;g<this.soup.atomSelection.length;g++){if(this.soup.atomSelection[g].displayMode==1){h=molmil_dep.getKeyFromObject(molmil.configBox.vdwR,this.soup.atomSelection[g].element,molmil.configBox.vdwR.DUMMY)*1.1}else{h=0.5}for(d=0;d<6;d++){l[n++]=this.soup.atomSelection[g].chain.modelsXYZ[this.modelId][this.soup.atomSelection[g].xyz];l[n++]=this.soup.atomSelection[g].chain.modelsXYZ[this.modelId][this.soup.atomSelection[g].xyz+1];l[n++]=this.soup.atomSelection[g].chain.modelsXYZ[this.modelId][this.soup.atomSelection[g].xyz+2];l[n++]=f[0];l[n++]=f[1];l[n++]=f[2];if(d==0||d==5){l[n++]=-h;l[n++]=+h}else{if(d==1){l[n++]=+h;l[n++]=+h}else{if(d==2||d==3){l[n++]=+h;l[n++]=-h}else{if(d==4){l[n++]=-h;l[n++]=-h}}}}}}if(!this.buffers.atomSelectionBuffer){this.buffers.atomSelectionBuffer=this.gl.createBuffer()}this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.buffers.atomSelectionBuffer);this.gl.bufferData(this.gl.ARRAY_BUFFER,l,this.gl.STATIC_DRAW);this.buffers.atomSelectionBuffer.items=this.soup.atomSelection.length*6};molmil.render.prototype.selectFrame=function(d,f){this.modelId=molmil.geometry.modelId=d;molmil.geometry.reInitChains=true;molmil.geometry.generate(this.soup.structures,this,f);this.initBD=true};molmil.render.prototype.initBuffers=function(){molmil.geometry.generate(this.soup.structures,this);this.updateSelection();this.initBD=true};molmil.render.prototype.renderPicking=function(){if(!this.initBD){return}this.gl.clearColor(0,0,0,0);this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);var f=[0,0,0];var d=mat3.create();mat3.fromMat4(d,this.modelViewMatrix);vec3.transformMat3(f,this.soup.COR,d);for(var g=0;g<this.programs.length;g++){this.programs[g].renderPicking(this.modelViewMatrix,f)}this.gl.useProgram(null)};molmil.render.prototype.render=function(){if(!this.canvas.update||!this.initBD){return}if(this.canvas.update){for(var A=0;A<this.soup.canvases.length;A++){if(this.soup.canvases[A]!=this.canvas){this.soup.canvases[A].update=-1}}this.canvas.update=false;this.camera.pitchAngle=this.pitchAngle||this.pitch*Math.min(Math.max((Math.pow(Math.abs(this.camera.z),0.1)*0.25),0.5),2);this.camera.headingAngle=this.headingAngle||this.heading*Math.min(Math.max((Math.pow(Math.abs(this.camera.z),0.1)*0.25),0.5),2);if(this.TransX||this.TransY){var o=mat4.invert(mat4.create(),this.projectionMatrix);var x=(-this.camera.z-molmil.configBox.zNear)/(molmil.configBox.zFar-molmil.configBox.zNear);var w=vec3.lerp([0,0,0],molmil.unproject(this.TransB[0],this.TransB[1],0,o),molmil.unproject(this.TransB[0],this.TransB[1],1,o),x);this.TransB[0]+=this.TransX/this.width;this.TransB[1]-=this.TransY/this.height;var g=vec3.lerp([0,0,0],molmil.unproject(this.TransB[0],this.TransB[1],0,o),molmil.unproject(this.TransB[0],this.TransB[1],1,o),x);this.camera.x+=2*(g[0]-w[0]);this.camera.y+=2*(g[1]-w[1])}this.camera.z+=this.TransZ*Math.max(-this.camera.z/(this.width*0.5),0.05);if(this.camera.z>this.maxRange){this.camera.z=this.maxRange}if(this.camera.z<-(this.maxRange+molmil.configBox.zFar)){this.camera.z=-(this.maxRange+molmil.configBox.zFar)}this.pitch=0,this.heading=0,this.TransX=0,this.TransY=0,this.TransZ=0,this.pitchAngle=0,this.headingAngle=0;this.camera.positionCamera();this.modelViewMatrix=this.camera.generateMatrix();if(molmil.configBox.projectionMode==2){var y=-(this.camera.z*2)/molmil.configBox.zFar;mat4.ortho(this.projectionMatrix,-this.width*y,this.width*y,-this.height*y,this.height*y,Math.max(molmil.configBox.zNear,0.1),this.camera.z+(molmil.configBox.zFar*10))}}else{this.canvas.update=false}this.clearCut=((1-Math.abs(this.camera.QView[0]))*this.soup.stdXYZ[0])+((1-Math.abs(this.camera.QView[1]))*this.soup.stdXYZ[1])+((1-Math.abs(this.camera.QView[2]))*this.soup.stdXYZ[2]);this.fogStart=-this.camera.z-(this.clearCut*0.5);if(this.fogStart<molmil.configBox.zNear+1){this.fogStart=molmil.configBox.zNear+1}var f=molmil.configBox.BGCOLOR.slice();if(f[3]==0){f[0]=f[1]=f[2]=0}var h=[0,0,0];var B=mat3.create();mat3.fromMat4(B,this.modelViewMatrix);vec3.transformMat3(h,this.soup.COR,B);if(molmil.configBox.stereoMode){if(!this.FBOs.hasOwnProperty("stereoLeft")){this.FBOs.stereoLeft=new molmil.FBO(this.gl,this.width,this.height);this.FBOs.stereoLeft.addTexture("stereoLeft",this.gl.RGBA,this.gl.RGBA);this.FBOs.stereoLeft.setup();this.FBOs.stereoRight=new molmil.FBO(this.gl,this.width,this.height);this.FBOs.stereoRight.addTexture("stereoRight",this.gl.RGBA,this.gl.RGBA);this.FBOs.stereoRight.setup()}var s=this.modelViewMatrix[12];var C=molmil.configBox.stereoCameraConfig;var l,z,n=C[7],q=C[8];this.modelViewMatrix[12]=s-C[5]*0.5;l=-C[3]*(n/C[6]);z=C[4]*(n/C[6]);mat4.frustum(this.projectionMatrix,l,z,C[0],C[1],n,q);if(molmil.configBox.stereoMode==1){this.FBOs.stereoLeft.bind();this.gl.clearColor.apply(this.gl,f);this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);for(var t=0;t<this.programs.length;t++){if(this.programs[t].nElements){this.programs[t].render(this.modelViewMatrix,h)}}this.FBOs.stereoLeft.unbind()}else{if(molmil.configBox.stereoMode==2){this.gl.viewport(this.width,0,this.width,this.height);this.gl.scissor(this.width,0,this.width,this.height);this.gl.clearColor.apply(this.gl,f);this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);for(var t=0;t<this.programs.length;t++){if(this.programs[t].nElements){this.programs[t].render(this.modelViewMatrix,h)}}}}this.modelViewMatrix[12]=s+C[5]*0.5;l=-C[4]*(n/C[6]);z=C[3]*(n/C[6]);mat4.frustum(this.projectionMatrix,l,z,C[0],C[1],n,q);if(molmil.configBox.stereoMode==1){this.FBOs.stereoRight.bind();this.gl.clearColor.apply(this.gl,f);this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);for(var t=0;t<this.programs.length;t++){if(this.programs[t].nElements){this.programs[t].render(this.modelViewMatrix,h)}}this.FBOs.stereoRight.unbind()}else{if(molmil.configBox.stereoMode==2){this.gl.viewport(0,0,this.width,this.height);this.gl.scissor(0,0,this.width,this.height);for(var t=0;t<this.programs.length;t++){if(this.programs[t].nElements){this.programs[t].render(this.modelViewMatrix,h)}}}}if(molmil.configBox.stereoMode==1){var d=this.shaders.anaglyph;this.gl.clearColor.apply(this.gl,f);this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);this.gl.useProgram(d.program);this.FBOs.stereoLeft.bindTextureToUniform("stereoLeft",d.uniforms.stereoLeft,0);this.FBOs.stereoRight.bindTextureToUniform("stereoRight",d.uniforms.stereoRight,1);var u=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,u);this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),this.gl.STATIC_DRAW);molmil.resetAttributes(this.gl);molmil.bindAttribute(this.gl,d.attributes.in_Position,2,this.gl.FLOAT,false,0,0);molmil.clearAttributes(this.gl);this.gl.drawArrays(this.gl.TRIANGLES,0,6)}this.modelViewMatrix[12]=s}else{this.gl.clearColor.apply(this.gl,f);this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);for(var t=0;t<this.programs.length;t++){if(this.programs[t].nElements){this.programs[t].render(this.modelViewMatrix,h)}}}if(this.buffers.atomSelectionBuffer){this.renderAtomSelection(this.modelViewMatrix,h)}if(this.onRenderFinish){this.onRenderFinish()}this.gl.useProgram(null)};molmil.render.prototype.initFBOs=function(){if("scene" in this.FBOs){this.FBOs.depth.resize(this.width,this.height);this.FBOs.scene.resize(this.width,this.height)}else{this.FBOs.depth=new molmil.FBO(this.gl,this.width,this.height);this.FBOs.depth.addTexture("depthBuffer",this.gl.RGBA,this.gl.RGBA);this.FBOs.depth.setup();this.FBOs.scene=new molmil.FBO(this.gl,this.width,this.height);this.FBOs.scene.addTexture("colourBuffer",this.gl.RGBA,this.gl.RGBA);this.FBOs.scene.setup()}};molmil.render.prototype.resizeViewPort=function(){this.width=this.canvas.width;this.height=this.canvas.height;if(molmil.configBox.stereoMode==2){this.width*=0.5}if(molmil.configBox.projectionMode==1){mat4.perspective(this.projectionMatrix,molmil.configBox.camera_fovy*(Math.PI/360),this.width/this.height,molmil.configBox.zNear,molmil.configBox.zFar)}var g=molmil.configBox.zNear*molmil.configBox.stereoFocalFraction;var f=g/molmil.configBox.stereoEyeSepFraction;var h,d;h=molmil.configBox.zNear*Math.tan(molmil.configBox.camera_fovy/2)*0.25;d=-h;a=(this.width/this.height)*Math.tan(molmil.configBox.camera_fovy/2)*g;b=a-(f/2);c=a+(f/2);delete this.FBOs.stereoLeft;molmil.configBox.stereoCameraConfig=[d,h,a,b,c,f,g,molmil.configBox.zNear*0.25,molmil.configBox.zFar*0.25];this.gl.viewport(0,0,this.width,this.height)};molmil.render.prototype.renderAtomSelection=function(d,f){if(!this.buffers.atomSelectionBuffer.items){return}this.gl.useProgram(this.shaders.atomSelection.program);this.gl.uniform3f(this.shaders.atomSelection.uniforms.COR,f[0],f[1],f[2]);this.gl.uniformMatrix4fv(this.shaders.atomSelection.uniforms.modelViewMatrix,false,d);this.gl.uniformMatrix4fv(this.shaders.atomSelection.uniforms.projectionMatrix,false,this.projectionMatrix);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.buffers.atomSelectionBuffer);molmil.resetAttributes(this.gl);molmil.bindAttribute(this.gl,this.shaders.atomSelection.attributes.in_Position,3,this.gl.FLOAT,false,32,0);molmil.bindAttribute(this.gl,this.shaders.atomSelection.attributes.in_Colour,3,this.gl.FLOAT,false,32,12);molmil.bindAttribute(this.gl,this.shaders.atomSelection.attributes.in_ScreenSpaceOffset,2,this.gl.FLOAT,false,32,24);molmil.clearAttributes(this.gl);this.gl.enable(this.gl.BLEND);if(molmil.configBox.cullFace){this.gl.disable(this.gl.CULL_FACE)}this.gl.blendEquation(this.gl.FUNC_ADD);this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA);this.gl.drawArrays(this.gl.TRIANGLES,0,this.buffers.atomSelectionBuffer.items);if(molmil.configBox.cullFace){this.gl.enable(this.gl.CULL_FACE)}this.gl.disable(this.gl.BLEND)};molmil.FBO=function(g,f,d){this.width=f;this.height=d;this.gl=g;this.textures={};this.colourNumber=0;this.fbo=null;this.depthBuffer=null};molmil.FBO.prototype.addTexture=function(h,d,g){if(h in this.textures){this.gl.bindTexture(this.gl.TEXTURE_2D,this.textures[h][0])}else{var f=this.gl.createTexture();this.textures[h]=[f,this.colourNumber++,d,g];this.gl.bindTexture(this.gl.TEXTURE_2D,f);this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.NEAREST);this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.NEAREST);this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE);this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE)}this.gl.texImage2D(this.gl.TEXTURE_2D,0,d,this.width,this.height,0,g,this.gl.UNSIGNED_BYTE,null);this.gl.bindTexture(this.gl.TEXTURE_2D,null)};molmil.FBO.prototype.setup=function(){if(this.fbo!=null){this.rebindTextures(true)}else{this.fbo=this.gl.createFramebuffer();this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.fbo);this.rebindTextures(false);this.depthBuffer=this.gl.createRenderbuffer();this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthBuffer);this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this.width,this.height);this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.depthBuffer);this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null)}};molmil.FBO.prototype.rebindTextures=function(g){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.fbo);var f=[];for(var d in this.textures){this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0+this.textures[d][1],this.gl.TEXTURE_2D,this.textures[d][0],0);f.push(this.gl.COLOR_ATTACHMENT0+this.textures[d][1])}this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.depthBuffer);if(g){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null)}};molmil.FBO.prototype.bindTextureToUniform=function(f,g,d){this.gl.activeTexture(this.gl.TEXTURE0+d);this.gl.bindTexture(this.gl.TEXTURE_2D,this.textures[f][0]);this.gl.uniform1i(g,d)};molmil.FBO.prototype.resize=function(g,d){if(g==this.width&&d==this.height){return}this.width=g;this.height=d;for(var f in this.textures){this.addTexture(f,this.textures[f][2],this.textures[f][3])}this.rebindTextures(false);this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthBuffer);this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this.width,this.height);this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.depthBuffer);this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null)};molmil.FBO.prototype.bind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.fbo)};molmil.FBO.prototype.unbind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null)};molmil.glCamera=function(){this.reset()};molmil.glCamera.prototype.reset=function(){this.x=this.y=this.z=this.pitchAngle=this.headingAngle=0;this.QPitch=quat.create();this.QHeading=quat.create();this.QView=quat.create();this.pitchAngle=this.headingAngle=0};molmil.glCamera.prototype.generateMatrix=function(){var d=mat4.create();mat4.fromQuat(d,this.QView);d[12]=this.x;d[13]=this.y;d[14]=this.z;return d};molmil.glCamera.prototype.positionCamera=function(){quat.setAxisAngle(this.QPitch,[1,0,0],(this.pitchAngle/180)*Math.PI);quat.setAxisAngle(this.QHeading,[0,1,0],(this.headingAngle/180)*Math.PI);var d=quat.create();quat.multiply(d,this.QPitch,this.QHeading);quat.multiply(this.QView,d,this.QView);this.headingAngle=this.pitchAngle=0};molmil.handle_molmilViewer_mouseDown=function(d){molmil.activeCanvas=this;molmil.mouseDown=1;molmil.mouseDownS[d.which]=1;molmil.Xcoord=d.clientX;molmil.Ycoord=d.clientY;molmil.Zcoord=d.clientY;molmil.mouseMoved=false;document.oncontextmenu=molmil.disableContextMenu};molmil.disableContextMenu=function(d){if(d.stopPropagation){d.stopPropagation()}if(d.preventDefault){d.preventDefault()}d.cancelBubble=true;d.cancel=true;d.returnValue=false;return false};molmil.getOffset=function(f){var g=f.target,d=0,h=0;while(g&&!isNaN(g.offsetLeft)&&!isNaN(g.offsetTop)){d+=g.offsetLeft-g.scrollLeft;h+=g.offsetTop-g.scrollTop;g=g.offsetParent}d=f.clientX-d;h=f.clientY-h;return{x:d,y:h}};molmil.handle_molmilViewer_mouseUp=function(h){var f=molmil.activeCanvas;if(!molmil.mouseMoved&&f){if(h.ctrlKey!=f.atomCORset){if(h.ctrlKey){f.molmilViewer.setCOR()}else{f.molmilViewer.resetCOR()}f.renderer.modelViewMatrix=f.renderer.camera.generateMatrix()}if(f.isFullScreen){var n={x:h.screenX,y:h.screenY}}else{var n=molmil.getOffset(h)}var g=window.devicePixelRatio||1;f.renderer.soup.selectObject(n.x*g,n.y*g,h);if(h.which==3){f.renderer.soup.UI.showContextMenuAtom(h.clientX,h.clientY,h.pageX)}}molmil.mouseDownS[h.which]=0;if(molmil_dep.dBT.mac&&!h.ctrlKey&&molmil.mouseDownS[3]){molmil.mouseDownS[3]=0}var d=true;for(var l in molmil.mouseDownS){if(molmil.mouseDownS[l]){d=false;break}}molmil.mouseDown=d?0:1;if(d){setTimeout(function(){document.oncontextmenu=null},10);f=null}else{h.preventDefault();return false}};molmil.handle_molmilViewer_mouseMove=function(f){var d=molmil.activeCanvas;if(!molmil.mouseDown||!d){return}molmil.mouseMoved=true;if(molmil.mouseDownS[2]||(molmil.mouseDownS[1]&&molmil.mouseDownS[3])||(molmil.mouseDownS[1]&&f.shiftKey)){d.renderer.TransX+=(f.clientX-molmil.Xcoord)*0.5;d.renderer.TransY+=(f.clientY-molmil.Ycoord)*0.5;molmil.Xcoord=f.clientX;molmil.Zcoord=molmil.Ycoord=f.clientY}else{if(molmil.mouseDownS[1]){d.renderer.heading+=f.clientX-molmil.Xcoord;d.renderer.pitch+=f.clientY-molmil.Ycoord;molmil.Xcoord=f.clientX;molmil.Ycoord=f.clientY}else{if(molmil.mouseDownS[3]){d.renderer.TransZ=(f.clientY-molmil.Zcoord);molmil.Zcoord=f.clientY}}}if(f.ctrlKey!=d.atomCORset){if(f.ctrlKey){d.molmilViewer.setCOR()}else{d.molmilViewer.resetCOR()}}d.update=true;f.preventDefault()};molmil.handle_molmilViewer_mouseScroll=function(d){d.target.renderer.TransZ-=(d.wheelDelta||-d.detail*40);d.target.update=true;try{d.preventDefault()}catch(f){}return false};molmil.onDocumentMouseMove=function(d){if(molmil.mouseXstart==null){molmil.mouseXstart=d.clientX;molmil.mouseYstart=d.clientY}mouseX=d.clientX-molmil.mouseXstart;mouseY=d.clientY-molmil.mouseYstart;molmil.mouseXstart=d.clientX;molmil.mouseYstart=d.clientY};molmil.handle_molmilViewer_touchStart=function(g){if(document.body.onmousedown){document.body.onmousedown();document.body.onmousedown=null}molmil.activeCanvas=this;molmil.touchList=[];for(var f=0;f<g.touches.length;f++){molmil.touchList.push([g.touches[f].clientX,g.touches[f].clientY])}if(molmil.touchList.length==1){molmil.touchMode=1;molmil.previousTouchEvent=g;molmil.longTouchTID=setTimeout(molmil.handle_molmilViewer_touchHold,500)}else{if(molmil.touchList.length==2){var h=vec2.distance([0,0],[screen.width,screen.height]);var d=vec2.distance(molmil.touchList[0],molmil.touchList[1]);if(d/h<0.075){molmil.touchMode=3}else{molmil.touchMode=2}}}g.preventDefault()};molmil.handle_molmilViewer_touchHold=function(){if(!molmil.longTouchTID){return}if(molmil.previousTouchEvent){if(Math.sqrt((Math.pow(molmil.previousTouchEvent.touches[0].clientX-molmil.touchList[0][0],2))+(Math.pow(molmil.previousTouchEvent.touches[0].clientY-molmil.touchList[0][1],2)))<1){if(molmil.activeCanvas.isFullScreen){var f={x:molmil.previousTouchEvent.touches[0].screenX,y:molmil.previousTouchEvent.touches[0].screenY}}else{var f=molmil.getOffset(molmil.previousTouchEvent.touches[0])}var d=window.devicePixelRatio||1;molmil.activeCanvas.renderer.soup.selectObject(f.x*d,f.y*d,event)}molmil.activeCanvas.renderer.soup.UI.showContextMenuAtom(molmil.previousTouchEvent.touches[0].clientX,molmil.previousTouchEvent.touches[0].clientY,molmil.previousTouchEvent.touches[0].pageX)}molmil.longTouchTID=null;molmil.previousTouchEvent=null};molmil.handle_molmilViewer_touchMove=function(h){if(!molmil.touchList.length||!molmil.activeCanvas){return}if(molmil.longTouchTID){clearTimeout(molmil.longTouchTID);molmil.longTouchTID=null}var g=[];for(var f=0;f<h.touches.length;f++){g.push([h.touches[f].clientX,h.touches[f].clientY])}if(molmil.touchMode==1){molmil.activeCanvas.renderer.heading+=g[0][0]-molmil.touchList[0][0];molmil.activeCanvas.renderer.pitch+=g[0][1]-molmil.touchList[0][1]}else{if(molmil.touchMode==2){molmil.activeCanvas.renderer.TransZ=(vec2.distance(g[0],g[1])-vec2.distance(molmil.touchList[0],molmil.touchList[1]))*5}else{if(molmil.touchMode==3){var l=vec2.distance([0,0],[screen.width,screen.height]);var d=vec2.distance(molmil.touchList[0],molmil.touchList[1]);if(d/l<0.075){molmil.activeCanvas.renderer.TransX=((g[0][0]+g[1][0])/2)-((molmil.touchList[0][0]+molmil.touchList[1][0])/2);molmil.activeCanvas.renderer.TransY=((g[0][1]+g[1][1])/2)-((molmil.touchList[0][1]+molmil.touchList[1][1])/2)}}}}molmil.touchList=g;molmil.activeCanvas.update=true;h.preventDefault()};molmil.handle_molmilViewer_touchEnd=function(){if(molmil.previousTouchEvent&&molmil.touchMode==1){if(Math.sqrt((Math.pow(molmil.previousTouchEvent.touches[0].clientX-molmil.touchList[0][0],2))+(Math.pow(molmil.previousTouchEvent.touches[0].clientY-molmil.touchList[0][1],2)))<1){if(molmil.activeCanvas.isFullScreen){var f={x:molmil.previousTouchEvent.touches[0].screenX,y:molmil.previousTouchEvent.touches[0].screenY}}else{var f=molmil.getOffset(molmil.previousTouchEvent.touches[0])}var d=window.devicePixelRatio||1;molmil.activeCanvas.renderer.soup.selectObject(f.x*d,f.y*d,event)}}molmil.touchList=[];molmil.touchMode=0;molmil.longTouchTID=null};molmil.setOnContextMenu=function(f,d){f.oncontextmenu=d;f.addEventListener("touchstart",molmil.handle_contextMenu_touchStart,false);f.addEventListener("touchend",molmil.handle_contextMenu_touchEnd,false)};molmil.handle_contextMenu_touchStart=function(d){previousTouchEvent=d;longTouchTID=setTimeout(molmil.handle_contextMenu_touchHold,500);d.preventDefault()};molmil.handle_contextMenu_touchHold=function(){if(!longTouchTID){return}longTouchTID=null;previousTouchEvent.touches[0].target.oncontextmenu(previousTouchEvent.touches[0]);previousTouchEvent=null};molmil.handle_contextMenu_touchEnd=function(d){if(previousTouchEvent){previousTouchEvent.touches[0].target.onclick()}longTouchTID=null;clearTimeout(longTouchTID)};molmil.UI=function(d){this.soup=d;this.canvas=d.canvas;this.LM=null;this.RM=null};molmil.UI.prototype.init=function(){var f,h;f=document.createElement("span");f.className="molmil_UI_LB unselectableText";this.LM=h=document.createElement("span");h.className="molmil_UI_LB_icon";h.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="Layer_1" style="enable-background:new 0 0 32 32;/* background-color: red; */" version="1.1" viewBox="0 0 32 32" xml:space="preserve"><path d="M4,10h24c1.104,0,2-0.896,2-2s-0.896-2-2-2H4C2.896,6,2,6.896,2,8S2.896,10,4,10z M28,14H4c-1.104,0-2,0.896-2,2  s0.896,2,2,2h24c1.104,0,2-0.896,2-2S29.104,14,28,14z M28,22H4c-1.104,0-2,0.896-2,2s0.896,2,2,2h24c1.104,0,2-0.896,2-2  S29.104,22,28,22z" fill="red"/></svg>';h.UI=this;h.onclick=function(){this.UI.showLM(this)};f.appendChild(h);(this.canvas?this.canvas.parentNode:document.body).appendChild(f);f=document.createElement("span");f.className="molmil_UI_RB unselectableText";this.RM=h=document.createElement("div");if(molmil.configBox.BGCOLOR[0]==0&&molmil.configBox.BGCOLOR[1]==0&&molmil.configBox.BGCOLOR[2]==0){h.style.color="white"}h.className="molmil_UI_RB_icon";h.innerHTML="&lt;<br/>&lt;<br/>&lt;";h.title="Structures panel: contains a list of all loaded entries";h.UI=this;h.onclick=function(){this.UI.showRM(this)};f.appendChild(h);f.menu=f.pushNode("div");f.menu.style.display="none";f.menu.className="molmil_UI_RM";(this.canvas?this.canvas.parentNode:document.body).appendChild(f);var d=this.canvas;var g=function(o){var l=document.molmil_FSC;if(l!=d){return}var n=window.devicePixelRatio||1;if(!l.isFullScreen){l.renderer.width=l.width=screen.width*n;l.renderer.height=l.height=screen.height*n;l.style.width=screen.width+"px";l.style.height=screen.height+"px";l.isFullScreen=true}else{l.renderer.width=l.width=l.defaultSize[0]*n;l.renderer.height=l.height=l.defaultSize[1]*n;l.style.width=l.defaultSize[0]+"px";l.style.height=l.defaultSize[1]+"px";l.isFullScreen=false;document.molmil_FSC=null}l.renderer.resizeViewPort();l.update=true;l.renderer.render()};document.addEventListener("webkitfullscreenchange",g,false);document.addEventListener("mozfullscreenchange",g,false);document.addEventListener("MSFullscreenChange",g,false);document.addEventListener("fullscreenchange",g,false)};molmil.UI.prototype.deleteEntry=function(d){};molmil.UI.prototype.displayEntry=function(f,d){if(f.ref){molmil.displayEntry(f.ref,d,true,this.soup)}document.body.onmousedown()};molmil.UI.prototype.colorEntry=function(l,d){if(l.ref){if(d==molmil.colorEntry_Custom){var f=molmil_dep.dcE("div");f.setClass("molmil_menu_popup");f.pushNode("span","Color by: ");var h=f.pushNode("input");h.type="color";h.value="#FFFFFF";var g=f.pushNode("button","Apply");g.style.marginLeft="1em";g.entry=l;g.ci=h;g.popup=f;g.soup=this.soup;g.UI=this;g.onclick=function(){var n=molmil.hex2rgb(this.ci.value);n.push(255);if(this.entry.mtype==3.1){l.ref.rgba=n;this.UI.soup.renderer.initBuffers();this.UI.soup.renderer.canvas.update=true}else{if(this.entry.mtype==3.2){for(a=0;a<l.ref.atoms.length;a++){l.ref.atoms[a].rgba=n}this.UI.soup.renderer.initBuffers();this.UI.soup.renderer.canvas.update=true}else{molmil.colorEntry(this.entry.ref,molmil.colorEntry_Custom,n,true,this.soup)}}this.popup.parentNode.removeChild(this.popup)};this.LM.parentNode.pushNode(f)}else{molmil.colorEntry(l.ref,d,null,true,this.soup)}}document.body.onmousedown()};molmil.UI.prototype.showColorMenu=function(h,g){if(h.subMenu){h.subMenu.style.zIndex=9999;clearTimeout(h.subMenu.TID);h.subMenu.style.display="";return}var o=molmil_dep.findPos(h);var n=h.subMenu=molmil_dep.dcE("div");n.className="contextMenu cM_sub";if(h.inv||g.inv){n.style.left="auto";n.style.right=((h.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}else{n.style.left=((h.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}var f,l=this;var d=function(p,s,q){f=n.pushNode("div",p);f.className="contextMenu_E";f.UI=l;f.entry=g;f.onclick=s;if(q){f.onmouseover=s;f.next=f.pushNode("span",">")}else{f.addEventListener("touchstart",function(){this.onclick()},false)}};if(g.mtype!=3.1&&g.mtype!=3.2){d("Default",function(){this.UI.colorEntry(g,1)})}if(g.mtype!=3.2){d("Structure",function(){if(g.mtype==3.1){var p=g.ref;p.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,p.sndStruc,molmil.configBox.sndStrucColor[1]);this.UI.soup.renderer.initBuffers();this.UI.soup.renderer.canvas.update=true;document.body.onmousedown()}else{this.UI.colorEntry(g,2)}})}if(g.mtype!=3.1){d("Atom (CPK)",function(){if(g.mtype==3.2){var p=g.ref;for(a=0;a<p.atoms.length;a++){p.atoms[a].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,p.atoms[a].element,molmil.configBox.elementColors.DUMMY)}this.UI.soup.renderer.initBuffers();this.UI.soup.renderer.canvas.update=true;document.body.onmousedown()}else{this.UI.colorEntry(g,3)}})}if(g.mtype==1||g.mtype==2||g.mtype==0.5){d("Group",function(){this.UI.colorEntry(g,4)});d("ABEGO",function(){this.UI.colorEntry(g,molmil.colorEntry_ABEGO)})}if(g.mtype==1||g.mtype==0.5){d("Chain",function(){this.UI.colorEntry(g,5)});d("Chain alt.",function(){this.UI.colorEntry(g,molmil.colorEntry_ChainAlt)})}d("Custom",function(){this.UI.colorEntry(g,6)});h.onmouseout=function(){this.subMenu.style.zIndex=9998;this.subMenu.TID=molmil_dep.asyncStart(function(){this.style.display="none"},[],h.subMenu,500)};h.pushNode(n)};molmil.UI.prototype.showDisplayMenuCM=function(h){var p=this.soup.atomSelection;if(!p.length){return}if(h.subMenu){h.subMenu.style.zIndex=9999;clearTimeout(h.subMenu.TID);h.subMenu.style.display="";return}var s=molmil_dep.findPos(h);var g=h.subMenu=molmil_dep.dcE("div");if(h.inv){g.style.left="auto";g.style.right=((h.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}else{g.style.left=((h.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}var n=s[0]+(h.inv?-1:1)*(h.parentNode.clientWidth+(2*molmil_dep.fontSize));var u=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;var o=u<n+(molmil_dep.fontSize*25);g.className="contextMenu cM_sub";var w,l=this;var f=function(x,z,y){w=g.pushNode("div",x);w.className="contextMenu_E";w.UI=l;w.entry=null;w.onclick=z;if(y){w.onmouseover=z;w.next=w.pushNode("span",">")}else{w.addEventListener("touchstart",function(){this.onclick()},false)}};var d=[];var q=[];for(var t=0;t<p.length;t++){d.push(p[t].molecule);q.push(p[t].molecule.chain)}f("Residue",function(){this.UI.showDisplayMenu(this,{mtype:3,ref:d,inv:o})},true);f("Chain",function(){this.UI.showDisplayMenu(this,{mtype:2,ref:q,inv:o})},true);h.onmouseout=function(){this.subMenu.style.zIndex=9998;this.subMenu.TID=molmil_dep.asyncStart(function(){this.style.display="none"},[],h.subMenu,500)};h.pushNode(g)};molmil.UI.prototype.showColorMenuCM=function(h){var p=this.soup.atomSelection;if(!p.length){return}if(h.subMenu){h.subMenu.style.zIndex=9999;clearTimeout(h.subMenu.TID);h.subMenu.style.display="";return}var s=molmil_dep.findPos(h);var g=h.subMenu=molmil_dep.dcE("div");if(h.inv){g.style.left="auto";g.style.right=((h.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}else{g.style.left=((h.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}var n=s[0]+(h.inv?-1:1)*(h.parentNode.clientWidth+(2*molmil_dep.fontSize));var u=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;var o=u<n+(molmil_dep.fontSize*25);g.className="contextMenu cM_sub";var w,l=this;var f=function(x,z,y){w=g.pushNode("div",x);w.className="contextMenu_E";w.UI=l;w.entry=null;w.onclick=z;if(y){w.onmouseover=z;w.next=w.pushNode("span",">")}else{w.addEventListener("touchstart",function(){this.onclick()},false)}};var d=[];var q=[];for(var t=0;t<p.length;t++){d.push(p[t].molecule);q.push(p[t].molecule.chain)}f("Atom",function(){this.UI.showColorMenu(this,{mtype:4,ref:p,inv:o})},true);f("Residue",function(){this.UI.showColorMenu(this,{mtype:3,ref:d,inv:o})},true);f("Residue (cartoon)",function(){this.UI.showColorMenu(this,{mtype:3.1,ref:d,inv:o})},true);f("Residue (atoms)",function(){this.UI.showColorMenu(this,{mtype:3.2,ref:d,inv:o})},true);f("Chain",function(){this.UI.showColorMenu(this,{mtype:2,ref:q,inv:o})},true);h.onmouseout=function(){this.subMenu.style.zIndex=9998;this.subMenu.TID=molmil_dep.asyncStart(function(){this.style.display="none"},[],h.subMenu,500)};h.pushNode(g)};molmil.UI.prototype.showDisplayMenu=function(g,p){if(g.subMenu){g.subMenu.style.zIndex=9999;clearTimeout(g.subMenu.TID);g.subMenu.style.display="";return}var o=molmil_dep.findPos(g);var f=g.subMenu=molmil_dep.dcE("div");f.className="contextMenu cM_sub";var t,h=this;if(g.inv||p.inv){f.style.left="auto";f.style.right=((g.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}else{f.style.left=((g.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}var l=o[0]+(g.inv?-1:1)*(g.parentNode.clientWidth+(2*molmil_dep.fontSize));var s=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;var n=s<l+(molmil_dep.fontSize*25);var d=function(u,x,w){t=f.pushNode("div",u);t.className="contextMenu_E";t.inv=n;t.UI=h;t.entry=p;t.onclick=x;if(w){t.onmouseover=x;t.next=t.pushNode("span",">")}else{t.addEventListener("touchstart",function(){this.onclick()},false)}};if(p.ref[0].display){d("Hidden",function(){this.UI.displayEntry(p,0)})}else{d("Visible",function(){this.UI.displayEntry(p,0.5)})}if(p.mtype!=3){d("Default",function(){this.UI.displayEntry(p,1)})}if(p.mtype!=10){if(p.mtype==3&&(p.ref[0].ligand||p.ref[0].water)){d("Space fill",function(){this.UI.displayEntry(p,2)});d("Ball & stick",function(){this.UI.displayEntry(p,3)});d("Stick",function(){this.UI.displayEntry(p,4)});d("Wireframe",function(){this.UI.displayEntry(p,5)})}else{var q=function(u,z){if(u.subMenu){u.subMenu.style.zIndex=9999;clearTimeout(u.subMenu.TID);u.subMenu.style.display="";return}var A=molmil_dep.findPos(u);var y=u.subMenu=molmil_dep.dcE("div");if(u.inv){y.style.left="auto";y.style.right=((u.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}else{y.style.left=((u.parentNode.clientWidth/molmil_dep.fontSize)+1.8)+"em"}y.className="contextMenu cM_sub";var x;var w=function(B,D,C){x=y.pushNode("div",B);x.className="contextMenu_E";x.UI=h;x.entry=p;x.onclick=D;if(C){x.onmouseover=D;x.next=x.pushNode("span",">")}else{x.addEventListener("touchstart",function(){this.onclick()},false)}};w("Space fill",function(){this.UI.displayEntry(p,z==1?2:2.5)});w("Ball & stick",function(){this.UI.displayEntry(p,z==1?3:3.5)});w("Stick",function(){this.UI.displayEntry(p,z==1?4:4.5)});w("Wireframe",function(){this.UI.displayEntry(p,z==1?5:5.5)});u.onmouseout=function(){this.subMenu.style.zIndex=9998;this.subMenu.TID=molmil_dep.asyncStart(function(){this.style.display="none"},[],u.subMenu,500)};u.pushNode(y)};d("Amino acid",function(){q(this,1)},true);d("Side chain",function(){q(this,2)},true)}if(p.mtype<3&&!(p.ref[0].ligand||p.ref[0].water)){d("Ca trace",function(){this.UI.displayEntry(p,6)});d("Tube",function(){this.UI.displayEntry(p,7)});d("Cartoon",function(){this.UI.displayEntry(p,8)});d("Rocket",function(){this.UI.displayEntry(p,8.5)});d("CG Surface",function(){this.UI.displayEntry(p,molmil.displayMode_ChainSurfaceCG)});d("Simple Surface",function(){this.UI.displayEntry(p,molmil.displayMode_ChainSurfaceSimple)})}}g.onmouseout=function(){this.subMenu.style.zIndex=9998;this.subMenu.TID=molmil_dep.asyncStart(function(){this.style.display="none"},[],g.subMenu,500)};g.pushNode(f)};molmil.UI.prototype.showContextMenuAtom=function(t,s,l){if(document.body.onmousedown){document.body.onmousedown()}var p=this.soup.atomSelection;if(!p.length){return}var u=0;var w=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;if(w<l+(molmil_dep.fontSize*12)){u=(l+(molmil_dep.fontSize*12))-w}var n=w<l+(molmil_dep.fontSize*25);var f=molmil_dep.dcE("div");f.className="contextMenu";f.style.left=t-u+"px";f.style.top=s+(document.body.scrollTop||0)+"px";if(p.length>1){f.pushNode("div",this.soup.atomSelection.length+" atoms selected")}else{var q=p[0];var o=q.molecule.atoms.length>1;var g=f.pushNode("div",(o?q.atomName:q.element)+" - "+(o?(q.molecule.name||"")+" ":"")+(q.molecule.RSID||"")+(q.molecule.chain.name?" - Chain "+q.molecule.chain.name:""))}f.pushNode("HR");var h=this;var d=function(x,z,y){item=f.pushNode("div",x);if(!item.pushNode){return}item.className="contextMenu_E";item.UI=h;item.entry=null;item.inv=n;item.onclick=z;if(y){item.onmouseover=z;item.next=item.pushNode("span",">")}else{item.addEventListener("touchstart",function(){this.onclick()},false)}};d("Display",function(){this.UI.showDisplayMenuCM(this)},true);d("Color",function(){this.UI.showColorMenuCM(this)},true);document.body.pushNode(f);document.body.onmousedown=function(y){if(y&&y.target.className.indexOf("contextMenu_E")!=-1){return}var x=document.getElementsByClassName("contextMenu");for(var z=0;z<x.length;z++){x[z].parentNode.removeChild(x[z])}x=document.getElementsByClassName("contextMenu_E_sel")[0];document.body.onmousedown=null};return false};molmil.UI.prototype.showCM=function(l,g){if(document.body.onmousedown){document.body.onmousedown()}var p=0;var o=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;if(o<l.pageX+(molmil_dep.fontSize*12)){p=(l.pageX+(molmil_dep.fontSize*12))-o}g.inv=o<l.pageX+(molmil_dep.fontSize*25);var n=molmil_dep.dcE("div");n.className="contextMenu";n.style.left=l.pageX-p+"px";n.style.top=l.pageY+"px";var f,h=this;g.setClass("contextMenu_E_sel");var d=function(q,t,s){f=n.pushNode("div",q);f.className="contextMenu_E";f.UI=h;f.entry=g;f.onclick=t;if(s){f.onmouseover=t;f.next=f.pushNode("span",">")}else{f.addEventListener("touchstart",function(){this.onclick()},false)}};if(g.mtype==0.5||g.mtype==1){if(this.soup.hideWaters){d("Show waters",function(){this.UI.toggleWaters(1)})}else{d("Hide waters",function(){this.UI.toggleWaters(0)})}if(this.soup.hideHydrogens){d("Show hydrogens",function(){this.UI.toggleHydrogens(1)})}else{d("Hide hydrogens",function(){this.UI.toggleHydrogens(0)})}}d("Display",function(){this.UI.showDisplayMenu(this,g)},true);if(g.mtype!=10){d("Color",function(){this.UI.showColorMenu(this,g)},true)}document.body.pushNode(n);document.body.onmousedown=function(s){if(s&&s.target.className.indexOf("contextMenu_E")!=-1){return}var q=document.getElementsByClassName("contextMenu");for(var t=0;t<q.length;t++){q[t].parentNode.removeChild(q[t])}q=document.getElementsByClassName("contextMenu_E_sel")[0];if(q){g.removeClass("contextMenu_E_sel")}document.body.onmousedown=null};try{l.preventDefault()}catch(l){}return false};molmil.UI.prototype.showRM=function(h){var o=h.parentNode.menu;molmil_dep.Clear(o);if(o.style.display=="none"){h.innerHTML="&gt;<br/>&gt;<br/>&gt;";o.style.maxHeight=((this.canvas?this.canvas:document.body)-32)+"px";o.style.display=""}else{h.innerHTML="&lt;<br/>&lt;<br/>&lt;";o.style.display="none"}var n=this.canvas?this.canvas.molmilViewer.structures:[];if(o.childNodes.length>0){if(n.length==o.nof){return}}o.nof=n.length;o.pushNode("span","Structures:").className="optCat_k";o.pushNode("hr");var d,l,g;for(var f=0;f<n.length;f++){g=n[f];if(g instanceof molmil.entryObject){l=o.pushNode("div");l.plus=l.pushNode("a","+");l.plus.className="optCat_p";l.name=l.pushNode("a",g.meta.id);l.name.title="Left click to expand\nRight click to show the context menu for display & color options";l.name.className="optCat_n";l.plus.onclick=l.name.onclick=molmil_dep.expandCatTree;l.name.UI=l.UI=this;molmil.setOnContextMenu(l.name,function(p){this.UI.showCM(p,this)});l.name.mtype=1;l.payload=l.name.ref=[g];l.expandFunc=this.showChains}else{l=o.pushNode("div",g.filename);l.className="optCat_n";l.style.marginLeft="1.25em";l.UI=this;molmil.setOnContextMenu(l,function(p){this.UI.showCM(p,this)});l.mtype=10;l.ref=[g.polygon]}}};molmil.UI.prototype.showChains=function(l,h){var f,g;l.pushNode("span","Chains:").className="optCat_k";l.pushNode("hr");h=h instanceof Array?h[0]:h;for(var d=0;d<h.chains.length;d++){f=h.chains[d];g=l.pushNode("div");g.plus=g.pushNode("a","+");g.plus.className="optCat_p";g.name=g.pushNode("a",f.name?f.name:d+1);g.name.title="Left click to expand\nRight click to show the context menu for display & color options";g.name.className="optCat_n";g.plus.onclick=g.name.onclick=molmil_dep.expandCatTree;g.payload=f;g.name.UI=g.UI=this.UI;g.expandFunc=this.UI.showResidues;molmil.setOnContextMenu(g.name,function(n){this.UI.showCM(n,this)});g.name.mtype=2;g.name.ref=[f]}l.pushNode("hr")};molmil.UI.prototype.showResidues=function(l,h){l.pushNode("span","Residues/Ligands:").className="optCat_k";l.pushNode("hr");var g,f;h=h instanceof Array?h[0]:h;for(var d=0;d<h.molecules.length;d++){g=h.molecules[d];f=l.pushNode("div",g.name+(g.id?" ("+g.id+")":""));f.title="Double click to jump to residue\nRight click to show the context menu for display & color options";f.className="optCat_n";f.payload=g;f.UI=this.UI;molmil.setOnContextMenu(f,function(n){this.UI.showCM(n,this)});f.mtype=3;f.ref=[g];f.ondblclick=function(){this.UI.canvas.molmilViewer.gotoMol(this.payload)};f.onclick=function(){this.UI.canvas.molmilViewer.atomSelection=[this.payload.CA||this.payload.atoms[0]];this.UI.canvas.renderer.updateSelection();this.UI.canvas.update=true}}l.pushNode("hr")};molmil.UI.prototype.showLM=function(f){try{if(f.parentNode.childNodes.length>1){f.parentNode.removeChild(f.nextSibling);f.parentNode.removeChild(f.nextSibling);return}}catch(g){}var h=document.createElement("div"),g;h.className="molmil_UI_LM";g=h.appendChild(document.createElement("div"));g.menu=h;g.UI=this;g.className="molmil_UI_ME";g.innerHTML="Open >";g.title="Open files or entries";g.onclick=function(){molmil_dep.Clear(this.menu.sub);var l;this.menu.sub.style.display="";if(!molmil_dep.dBT.ios_version){l=this.menu.sub.pushNode("div","mmCIF file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("mmCIF",2)};l=this.menu.sub.pushNode("div","PDBML file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("PDBML",3)};l=this.menu.sub.pushNode("div","mmJSON file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("mmJSON",1)};l=this.menu.sub.pushNode("div","PDB (flat) file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("PDB",4)};l=this.menu.sub.pushNode("div","GRO file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("GRO",7)};l=this.menu.sub.pushNode("div","CCP4 file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("CCP4","ccp4",null,null,true)};l=this.menu.sub.pushNode("div","MDL mol file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("MDL mol","mdl")};l=this.menu.sub.pushNode("div","Mol2 file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("Mol2","mol2")};l=this.menu.sub.pushNode("div","Polygon XML file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("Polygon XML file",5)};l=this.menu.sub.pushNode("div","Polygon JSON file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.open("Polygon JSON file",6)};this.menu.sub.pushNode("hr")}l=this.menu.sub.pushNode("div","PDB (PDBj)","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.openID(1)};l=this.menu.sub.pushNode("div","PDB chem_comp (PDBj)","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.openID(2)};l=this.menu.sub.pushNode("div","Promode Elastic (PDBj)","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.openPMEID()}};g=h.appendChild(document.createElement("div"));g.menu=h;g.UI=this;g.className="molmil_UI_ME";g.innerHTML="Save >";g.onclick=function(){molmil_dep.Clear(this.menu.sub);var l;this.menu.sub.style.display="";l=this.menu.sub.pushNode("div","PNG image","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){this.UI.savePNG()};l=this.menu.sub.pushNode("div","MP4 video","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){molmil.initVideo(this.UI)};l=this.menu.sub.pushNode("div","PLY polygon file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){molmil.exportPLY(this.UI.soup)};l=this.menu.sub.pushNode("div","STL polygon file","molmil_UI_ME");l.UI=this.UI;l.onclick=function(){molmil.exportSTL(this.UI.soup)}};h.pushNode("hr");g=h.appendChild(document.createElement("div"));g.UI=this;g.LM=f;g.className="molmil_UI_ME";g.innerHTML="Settings";g.title="Opens Molmil's advanced settings panel";g.onclick=function(){this.LM.onclick();this.UI.settings()};g=h.appendChild(document.createElement("div"));g.UI=this;g.LM=f;g.className="molmil_UI_ME";g.innerHTML="View >";g.title="View options";g.onclick=function(){this.UI.view(h.sub)};var d=this.soup.structures.length?this.soup.structures[0].number_of_frames:0;if(d>1){g=h.appendChild(document.createElement("div"));g.menu=h;g.UI=this;g.className="molmil_UI_ME";g.innerHTML="Animation";g.canvas=this.canvas;g.LM=f;g.title="Displays Animation panel, useful for exploring multiple models or playing MD trajectories";g.onclick=function(){this.UI.animationPopUp();this.LM.onclick()};h.pushNode("hr")}if(!molmil_dep.dBT.ios_version){g=h.pushNode("div");g.className="molmil_UI_ME";g.innerHTML="Enable full-screen";g.canvas=this.canvas;g.LM=f;g.title="Enables full screen mode";g.onclick=function(){var l=this.canvas.requestFullScreen||this.canvas.webkitRequestFullScreen||this.canvas.mozRequestFullScreen||this.canvas.msRequestFullscreen||null;if(l){document.molmil_FSC=this.canvas;l.call(this.canvas)}this.LM.onclick()}}g=h.appendChild(document.createElement("div"));g.UI=this;g.className="molmil_UI_ME";g.innerHTML="Toggle CLI";g.title="Toggles between displaying and hiding the Command Line Interface";g.onclick=function(){this.UI.toggleCLI()};g=h.appendChild(document.createElement("div"));g.UI=this;g.className="molmil_UI_ME";g.innerHTML="Clear";g.title="Removes all loaded entries from this canvas";g.onclick=function(){this.UI.clear()};h.pushNode("hr");g=h.appendChild(document.createElement("div"));g.UI=this;g.className="molmil_UI_ME";g.innerHTML="Help";g.LM=f;g.onclick=function(){window.open("https://github.com/gjbekker/molmil/wiki");this.LM.onclick()};f.parentNode.appendChild(h);h.sub=f.parentNode.appendChild(document.createElement("div"));h.sub.className="molmil_UI_LM";h.sub.style.display="none"};molmil.UI.prototype.view=function(d){molmil_dep.Clear(d);var f;d.style.display="";f=d.pushNode("div","Reset zoom","molmil_UI_ME");f.UI=this;f.onclick=function(){if(this.UI.LM&&this.UI.LM.parentNode.childNodes.length>1){this.UI.LM.onclick()}this.UI.soup.renderer.camera.z=this.UI.soup.calcZ();this.UI.soup.canvas.update=true};f=d.pushNode("div","Configure slab","molmil_UI_ME");f.UI=this;f.onclick=function(){this.UI.configureSlab.apply(this.UI)};if(!this.soup.AisB){f=d.pushNode("div","Configure BU","molmil_UI_ME");f.UI=this;f.onclick=function(){this.UI.configureBU.apply(this.UI)}}};molmil.UI.prototype.configureBU=function(s){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var o=this.soup.infoBag.BU_assembly||-1;var t=this.soup.infoBag.BU_rm||[3,2];var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("div","Biological Unit configuration");d.pushNode("hr");var z=d.pushNode("table"),w,g;var x,y;w=z.pushNode("tr");g=w.pushNode("td","Unit selection:");x=w.pushNode("td").pushNode("select");var p=this.soup;var A=0,n,u,l;for(u=0;u<p.chains.length;u++){if(p.poly_asym_ids.indexOf(p.chains[u].name)!=-1){A++}}g=x.pushNode("option","Asymmetric unit (%NOC)".replace("%NOC",A));g.value=-1;var h=-1;if(Object.keys(p.BUmatrices).length>1||Object.keys(p.BUassemblies).length>1){for(var q in p.BUassemblies){A=0;for(n=0;n<p.BUassemblies[q].length;n++){l=0;for(u=0;u<p.BUassemblies[q][n][1].length;u++){if(p.poly_asym_ids.indexOf(p.BUassemblies[q][n][1][u])!=-1){l++}}A+=l*p.BUassemblies[q][n][0].length}g=x.pushNode("option","Biological unit %N (%NOC)".replace("%NOC",A).replace("%N",q));g.value=q}if(o&&(o==-1||p.BUassemblies.hasOwnProperty(o))){h=o}else{o=figureOutAssemblyId(p.pdbxData,p.BUassemblies);if(p.BUassemblies.hasOwnProperty(o)){h=o}}}x.value=h;w=z.pushNode("tr");g=w.pushNode("td","Unit repr.:");y=w.pushNode("td").pushNode("select");g=y.pushNode("option","Only backbone, colored by CPK");g.value=[1,1];g=y.pushNode("option","Only backbone, colored by each asymmetric chain");g.value=[1,2];g=y.pushNode("option","Only backbone, colored by each chain");g.value=[1,3];g=y.pushNode("option","Only alpha carbon and phosphorus, colored by CPK");g.value=[2,1];g=y.pushNode("option","Only alpha carbon and phosphorus, colored by each asymmetric chain");g.value=[2,2];g=y.pushNode("option","Only alpha carbon and phosphorus, colored by each chain");g.value=[2,3];g=y.pushNode("option","Tube, colored by each asymmetric chain");g.value=[3,2];g=y.pushNode("option","Tube, colored by each chain");g.value=[3,3];g=y.pushNode("option","Tube, colored by secondary structure");g.value=[3,4];g=y.pushNode("option","Cartoon, colored by each asymmetric chain");g.value=[4,2];g=y.pushNode("option","Cartoon, colored by each chain");g.value=[4,3];g=y.pushNode("option","Cartoon, colored by secondary structure");g.value=[4,4];g=y.pushNode("option","Coarse surface, colored by each asymmetric chain");g.value=[5,2];g=y.pushNode("option","Coarse surface, colored by each chain");g.value=[5,3];y.value=t;x.soup=y.soup=p;x.oninput=y.oninput=function(){var B=y.value.split(",");this.soup.infoBag.BU_assembly=x.value;this.soup.infoBag.BU_rm=[parseInt(B[0]),parseInt(B[1])];molmil.toggleBU(this.soup.infoBag.BU_assembly,this.soup.infoBag.BU_rm[0],this.soup.infoBag.BU_rm[1],null,this.soup)};var f=d.pushNode("button","Close");f.style.marginLeft="1em";f.onclick=function(){d.parentNode.removeChild(d)};if(s){s.pushNode(d)}else{this.LM.parentNode.pushNode(d)}};molmil.UI.prototype.configureSlab=function(n){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("div","Slab configuration");d.pushNode("hr");var s=d.pushNode("table"),o,g;var h,q;o=s.pushNode("tr");o.pushNode("td","Slab near:");h=o.pushNode("td").pushNode("input");h.type="range";g=o.pushNode("td","0");g.style.minWidth="4em";g.style.textAlign="right";o=s.pushNode("tr");o.pushNode("td","Slab far:");q=o.pushNode("td").pushNode("input");q.type="range";g=o.pushNode("td","0");g.style.minWidth="4em";g.style.textAlign="right";h.oninput=function(){this.parentNode.nextSibling.innerHTML=Math.round(parseFloat(this.value)*10)/10;if(parseFloat(q.value)<=parseFloat(this.value)){q.value=parseFloat(this.value)+1;q.oninput()}else{molmil.setSlab(parseFloat(h.value),parseFloat(q.value),canvas.molmilViewer)}};q.oninput=function(){this.parentNode.nextSibling.innerHTML=Math.round(parseFloat(this.value)*10)/10;if(parseFloat(h.value)>=parseFloat(this.value)){h.value=parseFloat(this.value)-1;h.oninput()}else{molmil.setSlab(parseFloat(h.value),parseFloat(q.value),canvas.molmilViewer)}};var l=Math.min(this.soup.geomRanges[0],this.soup.geomRanges[2],this.soup.geomRanges[4])+molmil.configBox.zNear;var p=Math.max(this.soup.geomRanges[1],this.soup.geomRanges[3],this.soup.geomRanges[5])+molmil.configBox.zNear;h.min=q.min=l;h.max=q.max=p;h.step=q.step=0.1;h.value=this.soup.renderer.settings.slabNear||l;q.value=this.soup.renderer.settings.slabFar||p;h.oninput();q.oninput();var f=d.pushNode("button","Close");f.style.marginLeft="1em";f.onclick=function(){d.parentNode.removeChild(d)};if(n){n.pushNode(d)}else{this.LM.parentNode.pushNode(d)}};molmil.UI.prototype.settings=function(){var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("div","Settings");d.pushNode("hr");var h=molmil_dep.dcE("button"),f;h.qlv=molmil_dep.dcE("input");h.qlv.type="range";h.qlv.min="0";h.qlv.max="4";h.qlv.step="1";h.qlv.value=localStorage.getItem("molmil.settings_QLV");h.qlv.ref=molmil_dep.dcE("span");h.qlv.ref.innerHTML=h.qlv.value;h.qlv.onmousemove=function(){this.ref.innerHTML=this.value};h.bbsf=molmil_dep.dcE("input");h.bbsf.value=molmil.configBox.smoothFactor;h.fog=molmil_dep.dcE("input");h.fog.type="checkbox";h.fog.checked=localStorage.getItem("molmil.settings_glsl_fog")==1;h.projectionMode=molmil_dep.dcE("select");f=h.projectionMode.pushNode("option","Perspective projection");f.value=1;f=h.projectionMode.pushNode("option","Orthographic projection");f.value=2;if(molmil.configBox.projectionMode==2){f.selected=true}h.stereoMode=molmil_dep.dcE("select");f=h.stereoMode.pushNode("option","None");f.value=0;f=h.stereoMode.pushNode("option","Anaglyph");f.value=1;if(molmil.configBox.stereoMode==1){f.selected=true}f=h.stereoMode.pushNode("option","Side-by-side");f.value=2;if(molmil.configBox.stereoMode==2){f.selected=true}h.colorMode=molmil_dep.dcE("select");f=h.colorMode.pushNode("option","Rasmol");f.value=1;f=h.colorMode.pushNode("option","Jmol");f.value=2;if(localStorage.getItem("molmil.settings_COLORS")==2){f.selected=true}f=h.colorMode.pushNode("option","Basic");f.value=3;if(localStorage.getItem("molmil.settings_COLORS")==3){f.selected=true}h.bgcolor=molmil_dep.dcE("span");h.bgcolor.pushNode("span","R: ");h.bgcolor.R=h.bgcolor.pushNode("input");h.bgcolor.pushNode("span"," G: ");h.bgcolor.G=h.bgcolor.pushNode("input");h.bgcolor.pushNode("span"," B: ");h.bgcolor.B=h.bgcolor.pushNode("input");h.bgcolor.pushNode("span"," A: ");h.bgcolor.A=h.bgcolor.pushNode("input");h.bgcolor.R.style.width=h.bgcolor.G.style.width=h.bgcolor.B.style.width=h.bgcolor.A.style.width="2.5em";h.bgcolor.R.value=Math.round(molmil.configBox.BGCOLOR[0]*255);h.bgcolor.G.value=Math.round(molmil.configBox.BGCOLOR[1]*255);h.bgcolor.B.value=Math.round(molmil.configBox.BGCOLOR[2]*255);h.bgcolor.A.value=Math.round(molmil.configBox.BGCOLOR[3]*255);var l=d.pushNode("table"),g,f;g=l.pushNode("tr");g.pushNode("td","Quality:");f=molmil_dep.dcE("div");f.pushNode(h.qlv);f.pushNode(h.qlv.ref);g.pushNode("td").pushNode(f);g=l.pushNode("tr");g.pushNode("td","Sheet/loop backbone smooth factor:");f=molmil_dep.dcE("div");f.pushNode(h.bbsf);g.pushNode("td").pushNode(f);g=l.pushNode("tr");g.pushNode("td","Fog:");f=molmil_dep.dcE("div");f.pushNode(h.fog);g.pushNode("td").pushNode(f);g=l.pushNode("tr");g.pushNode("td","Projection mode:");g.pushNode("td").pushNode(h.projectionMode);g=l.pushNode("tr");g.pushNode("td","Stereoscopy:");g.pushNode("td").pushNode(h.stereoMode);g=l.pushNode("tr");g.pushNode("td","Color scheme*:");g.pushNode("td").pushNode(h.colorMode);g.title="Atom (CPK) colors need to be manually re-applied to become effective";g=l.pushNode("tr");g.pushNode("td","BG color:");g.pushNode("td").pushNode(h.bgcolor);d.pushNode("hr");h.innerHTML="Apply";h.UI=this;h.popup=d;h.onclick=function(){localStorage.setItem("molmil.settings_QLV",this.qlv.value);localStorage.setItem("molmil.settings_glsl_fog",(molmil.configBox.glsl_fog=this.fog.checked)?"1":"0");localStorage.setItem("molmil.settings_PROJECTION",this.projectionMode.value);localStorage.setItem("molmil.settings_STEREO",this.stereoMode.value);localStorage.setItem("molmil.settings_COLORS",this.colorMode.value);localStorage.setItem("molmil.settings_BGCOLOR",JSON.stringify([parseFloat(this.bgcolor.R.value)/255,parseFloat(this.bgcolor.G.value)/255,parseFloat(this.bgcolor.B.value)/255,parseFloat(this.bgcolor.A.value)/255]));localStorage.setItem("molmil.settings_BBSF",this.bbsf.value);molmil.initSettings();this.UI.soup.reloadSettings();molmil.configBox.projectionMode=this.projectionMode.value;molmil.configBox.stereoMode=parseInt(this.stereoMode.value);this.UI.soup.renderer.resizeViewPort();molmil.shaderEngine.recompile(this.UI.soup.renderer);this.UI.soup.renderer.initBuffers();this.UI.soup.canvas.update=true;this.popup.parentNode.removeChild(this.popup)};d.pushNode(h);var n=d.pushNode("button","Cancel");n.style.marginLeft="1em";n.onclick=function(){d.parentNode.removeChild(d)};this.LM.parentNode.pushNode(d)};molmil.UI.prototype.toggleWaters=function(d){this.soup.waterToggle(d);this.soup.renderer.initBuffers();this.soup.canvas.update=true;document.body.onmousedown()};molmil.UI.prototype.toggleHydrogens=function(d){this.soup.hydrogenToggle(d);this.soup.renderer.initBuffers();this.soup.canvas.update=true;document.body.onmousedown()};molmil.UI.prototype.animationPopUp=function(){var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("div","Animation controls");d.pushNode("hr");this.soup.animation.initialise(d);if(this.soup.frameInfo){var g=d.pushNode("input");g.type="range";g.value=g.min=0;g.max=this.soup.frameInfo.length;g.soup=this.soup;g.oninput=function(h){this.soup.animation.go2Frame(h.srcElement.valueAsNumber)};d.sliderBox=g;var f=d.pushNode("span",this.soup.frameInfo[0][1]+"ps");d.timeBox=f}else{var g=d.pushNode("input");g.type="range";g.value=g.min=0;g.max=this.soup.chains[0].modelsXYZ.length;g.soup=this.soup;g.oninput=function(h){this.soup.animation.go2Frame(h.srcElement.valueAsNumber)};d.sliderBox=g;var f=d.pushNode("span","0");d.timeBox=f}d.pushNode("br");d.pushNode("span","Motion:");label=d.pushNode("label");inp=label.pushNode("input");inp.type="radio";inp.name="motion";if(this.soup.animation.motionMode==1){inp.checked=true}label.pushNode("span","Forward");label.AI=this.soup.animation;label.onclick=function(){this.AI.motionMode=1};label=d.pushNode("label");inp=label.pushNode("input");inp.type="radio";inp.name="motion";if(this.soup.animation.motionMode==2){inp.checked=true}label.pushNode("span","Backward");label.AI=this.soup.animation;label.onclick=function(){this.AI.motionMode=2};label=d.pushNode("label");inp=label.pushNode("input");inp.type="radio";inp.name="motion";if(this.soup.animation.motionMode==3){inp.checked=true}label.pushNode("span","Swing");label.AI=this.soup.animation;label.onclick=function(){this.AI.motionMode=3};d.pushNode("br");label=d.pushNode("div");label.setClass("unselectableText");label.style.fontStyle="normal";label.style.textAlign="center";inp=label.pushNode("span","|&#8920;");inp.setClass("smallButton");inp.AI=this.soup.animation;inp.onclick=function(){this.AI.beginning()};inp=label.pushNode("span","<");inp.setClass("smallButton");inp.AI=this.soup.animation;inp.onclick=function(){this.AI.previous()};inp=label.pushNode("span","ll");inp.setClass("smallButton");inp.AI=this.soup.animation;inp.onclick=function(){this.AI.pause()};inp=label.pushNode("span","&#9658;");inp.setClass("smallButton");inp.AI=this.soup.animation;inp.onclick=function(){this.AI.play()};inp=label.pushNode("span",">");inp.setClass("smallButton");inp.AI=this.soup.animation;inp.onclick=function(){this.AI.next()};inp=label.pushNode("span","&#8921;|");inp.setClass("smallButton");inp.AI=this.soup.animation;inp.onclick=function(){this.AI.end()};d.close=d.pushNode("button","Close");d.close.style.display="block";d.close.style.marginLeft=d.close.style.marginRight="auto";d.close.onclick=function(){this.popup.parentNode.removeChild(this.popup)};d.close.popup=d;this.LM.parentNode.pushNode(d)};molmil.UI.prototype.resetRM=function(){try{molmil_dep.Clear(this.RM.parentNode.menu);if(this.RM.parentNode.menu.style.display!="none"){this.showRM(this.RM)}}catch(d){}};molmil.UI.prototype.toggleCLI=function(){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}if(!this.canvas.commandLine){new molmil.commandLine(this.canvas)}this.canvas.commandLine.icon.onclick();this.resetRM()};molmil.UI.prototype.clear=function(){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("div","Do you want to clear all loaded structures?");d.yes=d.pushNode("button","Yes");d.yes.canvas=this.canvas;d.yes.UI=this;d.yes.onclick=function(){if(this.canvas){molmil.clear(this.canvas)}this.UI.resetRM();d.cancel.onclick()};d.cancel=d.pushNode("button","Cancel");d.cancel.onclick=function(){this.popup.parentNode.removeChild(this.popup)};d.cancel.popup=d;this.LM.parentNode.pushNode(d)};molmil.UI.prototype.showDialog=function(f){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");if(f){f.apply(this,[d])}if(this.LM){this.LM.parentNode.pushNode(d)}return d};molmil.UI.prototype.xyz_input_popup=function(f,g,d){this.showDialog(function(h){var o=h.pushNode("table"),q,s,p,n;var l;q=o.pushNode("tr");q.pushNode("td","Filename:");q.pushNode("td",g);q=o.pushNode("tr");q.pushNode("td","Skip bond building:");l=q.pushNode("td").pushNode("input");l.type="checkbox";p=h.pushNode("button","Load");p.onclick=function(){var t={};t.skipBonds=l.checked;this.UI.soup.loadStructureData(f,"xyz",g,d,t);h.parentNode.removeChild(h)};p.UI=this;n=h.pushNode("button","Cancel");n.onclick=function(){h.parentNode.removeChild(h)}})};molmil.UI.prototype.ccp4_input_popup=function(f,g,d){this.showDialog(function(l){var t=l.pushNode("table"),o,h,q,u;var s,n,p;o=t.pushNode("tr");o.pushNode("td","Filename:");o.pushNode("td",g);o=t.pushNode("tr");o.pushNode("td","Sigma:");s=o.pushNode("td").pushNode("input");s.value=1;o=t.pushNode("tr");o.pushNode("td","Solid:");n=o.pushNode("td").pushNode("input");n.type="checkbox";n.checked=true;o=t.pushNode("tr");o.pushNode("td","Skip normalization:");p=o.pushNode("td").pushNode("input");p.type="checkbox";q=l.pushNode("button","Load");q.onclick=function(){var w={};try{w.sigma=parseFloat(s.value)}catch(x){return alert("Incorrect value for sigma")}w.solid=n.checked;w.skipNormalization=p.checked;this.UI.soup.loadStructureData(f,"ccp4",g,d,w);l.parentNode.removeChild(l)};q.UI=this;u=l.pushNode("button","Cancel");u.onclick=function(){l.parentNode.removeChild(l)}})};molmil.UI.prototype.open=function(h,n,f,p,o){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var g=this.soup;var l=this;var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("div","Open "+h+" file: ");d.inp=d.pushNode("input");d.inp.type="file";d.load=d.pushNode("button","Load");d.load.fileFormat=n;d.settings={};d.load.onclick=function(){if(!d.inp.files.length){return}var q=new FileReader();q.fileFormat=this.fileFormat;q.filename=d.inp.files[0].name;q.onload=function(t){d.cancel.onclick();var s=function(u,w){l.resetRM();if(f){f(u,w)}else{molmil.displayEntry(w,u.AID>100000?5:1);molmil.colorEntry(w,1,[],true,u)}};if(this.fileFormat=="ccp4"){l.ccp4_input_popup(t.target.result,this.filename,s)}else{if(this.fileFormat){g.loadStructureData(t.target.result,this.fileFormat,this.filename,s,d.settings)}else{f(this.filename,t.target.result)}}p=null};if(o){q.readAsArrayBuffer(d.inp.files[0])}else{q.readAsText(d.inp.files[0])}};d.cancel=d.pushNode("button","Cancel");d.cancel.onclick=function(){this.popup.parentNode.removeChild(this.popup);if(p){p()}};d.cancel.popup=d;if(this.LM){this.LM.parentNode.pushNode(d)}return d};molmil.UI.prototype.openPMEID=function(){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var g=this;var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("div","Promode Elastic");d.pushNode("hr");d.pushNode("span","Display: ");d.dpm1=d.pushNode("label");d.dpm1.inp=d.dpm1.pushNode("input");d.dpm1.inp.type="radio";d.dpm1.inp.name="displayMode";d.dpm1.pushNode("span","Displacement vectors");d.dpm1.inp.checked=true;d.pushNode("br");d.dpm2=d.pushNode("label");d.dpm2.inp=d.dpm2.pushNode("input");d.dpm2.inp.type="radio";d.dpm2.inp.name="displayMode";d.dpm2.pushNode("span","Animation");d.pushNode("br");d.pushNode("span","Mode:").style.paddingRight="1.125em";d.mode=d.pushNode("select");d.mode.style.width="10em";for(var f=0;f<10;f++){d.mode.pushNode("option",f+1)}d.pushNode("br");d.pushNode("span","PDB ID: ");d.inp=d.pushNode("input");d.inp.type="text";d.inp.style.width="10em";d.inp.onkeyup=function(h){if(h.keyCode==13){this.load.onclick()}else{if(h.keyCode==27){this.cancel.onclick()}}};d.pushNode("br");d.pushNode("span","Variant:").style.paddingRight=".25em";d.sel=d.pushNode("select");d.sel.style.width="10em";d.pushNode("br");d.inp.load=d.load=d.pushNode("button","Load");d.load.canvas=this.canvas;d.load.inpBuf=null;d.load.doLoad=function(l){l=l||d.sel.childNodes[d.sel.selectedIndex].innerHTML;var h=d.mode.childNodes[d.mode.selectedIndex].innerHTML;if(d.dpm1.inp.checked){this.canvas.molmilViewer.loadStructure(molmil.settings.promodeE_base_structure_url.replace("__ID__",l),4);this.canvas.molmilViewer.loadStructure(molmil.settings.promodeE_mode_vectors_url.replace("__ID__",l).replace("__MODE__",h),5)}else{this.canvas.molmilViewer.loadStructure(molmil.settings.promodeE_animation_url.replace("__ID__",l).replace("__MODE__",h),4,function(n,o){molmil.displayEntry(o,n.AID>100000?5:1);molmil.colorEntry(o,1);n.animation.motionMode=3;n.animation.play()})}d.cancel.onclick()};d.load.onclick=function(){if(d.inp.value!=this.inpBuf){this.inpBuf=d.inp.value;var h=new molmil_dep.CallRemote("GET");h.ASYNC=true;h.OnDone=function(){molmil_dep.Clear(d.sel);var l=JSON.parse(this.request.responseText);if(l.length==1){return d.load.doLoad(l[0][2])}for(var n=0;n<l.length;n++){d.sel.pushNode("option",l[n][2])}};h.Send(molmil.settings.promodeE_check_url.replace("__ID__",this.inpBuf))}else{if(d.sel.length){d.load.doLoad()}}};d.inp.cancel=d.cancel=d.pushNode("button","Cancel");d.cancel.onclick=function(){this.popup.parentNode.removeChild(this.popup)};d.cancel.popup=d;this.LM.parentNode.pushNode(d);d.inp.focus()};molmil.UI.prototype.openID=function(d){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var l,g;if(d==1){l="PDB ID";g=molmil.settings.pdb_url}else{if(d==2){l="Comp ID";g=molmil.settings.comp_url}else{return}}var h=this;var f=molmil_dep.dcE("div");f.setClass("molmil_menu_popup");f.pushNode("span",l+": ");f.inp=f.pushNode("input");f.inp.type="text";f.inp.onkeyup=function(n){if(n.keyCode==13){this.load.onclick()}else{if(n.keyCode==27){this.cancel.onclick()}}};f.inp.load=f.load=f.pushNode("button","Load");f.load.canvas=this.canvas;f.load.url=g;f.load.onclick=function(){if(!f.inp.value){return}this.canvas.molmilViewer.loadStructure(this.url.replace("__ID__",f.inp.value),1,function(n,o){molmil.displayEntry(o,n.AID>100000?5:1);molmil.colorEntry(o,1,[],true,n);h.resetRM()});f.cancel.onclick()};f.inp.cancel=f.cancel=f.pushNode("button","Cancel");f.cancel.onclick=function(){this.popup.parentNode.removeChild(this.popup)};f.cancel.popup=f;this.LM.parentNode.pushNode(f);f.inp.focus()};molmil.UI.prototype.savePNG=function(){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.pushNode("span"," ");d.range=d.pushNode("input");d.range.type="range";d.range.min="0.25";d.range.max="4";d.range.step=".25";d.range.value="1.0";d.range.onmousemove=function(){this.nfo.innerHTML=(this.canvas.width*this.value)+"px x "+(this.canvas.height*this.value)+"px"};d.range.nfo=d.pushNode("span");d.range.nfo.style.display="inline-block";d.save=d.pushNode("button","Save");d.range.canvas=d.save.canvas=this.canvas;d.save.onclick=function(){var l=parseInt(d.range.value);if(l!=1){var h=this.canvas.width;var f=this.canvas.height;var g=molmil.configBox.BGCOLOR[3];this.canvas.width*=l;this.canvas.height*=l;molmil.configBox.BGCOLOR[3]=0;this.canvas.renderer.selectDataContext();this.canvas.renderer.resizeViewPort();this.canvas.update=true;this.canvas.renderer.render();this.canvas.toBlob(function(n){saveAs(n,"image.png")});this.canvas.renderer.selectDefaultContext();this.canvas.width=h;this.canvas.height=f;molmil.configBox.BGCOLOR[3]=g;this.canvas.renderer.resizeViewPort();this.canvas.update=true;this.canvas.renderer.render()}else{var g=molmil.configBox.BGCOLOR[3];molmil.configBox.BGCOLOR[3]=0;this.canvas.renderer.selectDataContext();this.canvas.update=true;this.canvas.renderer.render();this.canvas.toBlob(function(n){saveAs(n,"image.png")});this.canvas.renderer.selectDefaultContext();molmil.configBox.BGCOLOR[3]=g;this.canvas.update=true;this.canvas.renderer.render()}d.cancel.onclick()};d.cancel=d.pushNode("button","Cancel");d.cancel.onclick=function(){this.popup.parentNode.removeChild(this.popup)};d.cancel.popup=d;d.range.onmousemove();this.LM.parentNode.pushNode(d)};molmil.UI.prototype.videoRenderer=function(){if(this.LM&&this.LM.parentNode.childNodes.length>1){this.LM.onclick()}var f=null;var g=null;this.canvas.renderer.onRenderFinish=function(){if(!f){return}if(g==null){g=new Uint8Array(this.canvas.width*this.canvas.width*4)}var h=new molmil_dep.CallRemote("POST");h.AddParameter("id",f);h.AddParameter("data",canvas.toDataURL());this.canvas.renderer.gl.readPixels(0,0,this.canvas.width,this.canvas.width,this.canvas.renderer.gl.RGBA,this.canvas.renderer.gl.UNSIGNED_BYTE,g);h.Send(molmil.settings.molmil_video_url+"addFrame")};var d=molmil_dep.dcE("div");d.setClass("molmil_menu_popup");d.preview=d.pushNode("button","Play & Preview");d.pushNode("br");d.record=d.pushNode("button","Play & Record");d.pushNode("br");d.canvas=d.preview.canvas=d.record.canvas=this.canvas;d.preview.popup=d.record.popup=d;d.preview.onclick=function(){f=null;this.canvas.molmilViewer.animation.beginning();this.canvas.molmilViewer.animation.play()};d.endVideo=function(){if(this.canvas.molmilViewer.animation.playing){molmil_dep.asyncStart(this.endVideo,[],this,250)}else{var h=new molmil_dep.CallRemote("GET");h.AddParameter("id",f);h.Send(molmil.settings.molmil_video_url+"deInitVideo");console.log(molmil.settings.molmil_video_url+"getVideo?id="+f);window.open(molmil.settings.molmil_video_url+"getVideo?id="+f);f=null}};d.record.onclick=function(){var l=this.canvas.width,n=this.canvas.height;if(l%2==1){l--}if(n%2==1){n--}if(l!=this.canvas.width||n!=this.canvas.height){this.canvas.renderer.resizeViewPort()}var o=new molmil_dep.CallRemote("GET");o.AddParameter("w",this.canvas.width);o.AddParameter("h",this.canvas.height);o.Send(molmil.settings.molmil_video_url+"initVideo");f=o.request.responseText;this.canvas.molmilViewer.animation.beginning();this.canvas.molmilViewer.animation.play();this.popup.endVideo()};d.cancel=d.pushNode("button","Cancel");d.cancel.canvas=this.canvas;d.cancel.onclick=function(){this.canvas.molmilViewer.animation.end();this.popup.endVideo();this.popup.parentNode.removeChild(this.popup)};d.cancel.popup=d;this.LM.parentNode.pushNode(d)};molmil.toggleEntry=function(o,g,n,h){h=h||molmil.cli_soup;var d,f,l;if(o instanceof molmil.entryObject){for(d=0;d<o.molecules.length;d++){l=o.molecules[d];if(!l.ligand&&!l.water){for(f=0;f<l.atoms.length;f++){l.atoms[f].display=g}}l.display=g}}else{if(o instanceof molmil.chainObject){for(d=0;d<o.molecules.length;d++){l=o.molecules[d];for(f=0;f<l.atoms.length;f++){l.atoms[f].display=g}l.display=g}}else{if(o instanceof molmil.molObject){for(f=0;f<o.atoms.length;f++){o.atoms[f].display=g}o.display=g}else{if(o instanceof molmil.atomObject){o.display=false}else{if(o instanceof polygonObject){o.display=g}else{return}}}}}if(n){h.renderer.initBuffers();h.renderer.canvas.update=true}};molmil.displayEntry=function(o,q,f,s,h){s=s||molmil.cli_soup;if(o instanceof Array){for(var p=0;p<o.length;p++){molmil.displayEntry(o[p],q,null,null,h)}if(f){s.renderer.initBuffers();s.renderer.canvas.update=true}return}if(s&&((s.SCstuff&&q%1==0)||(!s.SCstuff&&q%1!=0))){molmil.geometry.reInitChains=true}var g,w,t,d,n,u=molmil.configBox.backboneAtoms4Display,x=molmil.configBox.backboneAtoms4DisplayXNA,l=molmil.configBox.xna_simple_base_atoms,y;if(o instanceof molmil.entryObject){if(q==molmil.displayMode_None){o.display=false}else{if(q==molmil.displayMode_Visible){o.display=true}else{if(q==molmil.displayMode_None){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=0;for(var w=0;w<d.atoms.length;w++){d.atoms[w].displayMode=0}for(var g=0;g<d.molecules.length;g++){d.molecules[g].displayMode=0;d.molecules[g].showSC=false}}}else{if(q==molmil.displayMode_Default){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=3;for(g=0;g<d.molecules.length;g++){n=d.molecules[g];if(n.ligand||n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=3}}else{if(n.xna){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=l.hasOwnProperty(n.atoms[w].atomName)||n.atoms[w].element=="H"?0:3}}else{if(n.weirdAA){for(w=0;w<n.atoms.length;w++){if(u.hasOwnProperty(n.atoms[w].atomName)){n.atoms[w].displayMode=0}else{n.atoms[w].displayMode=3}}}else{for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}}}n.displayMode=3;n.showSC=n.weirdAA}}molmil.geometry.reInitChains=true}else{if(q==molmil.displayMode_Spacefill){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=1;for(var w=0;w<d.atoms.length;w++){d.atoms[w].displayMode=1}for(var g=0;g<d.molecules.length;g++){d.molecules[g].displayMode=0;d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_Spacefill_SC){for(t=0;t<o.chains.length;t++){d=o.chains[t];for(var w=0;w<d.atoms.length;w++){if(d.atoms[w].molecule.xna){y=x}else{y=u}if(!d.atoms[w].molecule.ligand&&!d.atoms[w].molecule.water&&y.hasOwnProperty(d.atoms[w].atomName)){d.atoms[w].displayMode=0}else{d.atoms[w].displayMode=1}}for(var g=0;g<d.molecules.length;g++){d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_BallStick){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=1;for(var w=0;w<d.atoms.length;w++){d.atoms[w].displayMode=2}for(var g=0;g<d.molecules.length;g++){d.molecules[g].displayMode=0;d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_BallStick_SC){for(t=0;t<o.chains.length;t++){d=o.chains[t];for(var w=0;w<d.atoms.length;w++){if(d.atoms[w].molecule.xna){y=x}else{y=u}if(!d.atoms[w].molecule.ligand&&!d.atoms[w].molecule.water&&y.hasOwnProperty(d.atoms[w].atomName)){d.atoms[w].displayMode=0}else{d.atoms[w].displayMode=2}}for(var g=0;g<d.molecules.length;g++){d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_Stick){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=1;for(var w=0;w<d.atoms.length;w++){d.atoms[w].displayMode=3}for(var g=0;g<d.molecules.length;g++){d.molecules[g].displayMode=0;d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_Stick_SC){for(t=0;t<o.chains.length;t++){d=o.chains[t];for(var w=0;w<d.atoms.length;w++){if(d.atoms[w].molecule.xna){y=x}else{y=u}if(!d.atoms[w].molecule.ligand&&!d.atoms[w].molecule.water&&y.hasOwnProperty(d.atoms[w].atomName)){d.atoms[w].displayMode=0}else{d.atoms[w].displayMode=3}}for(var g=0;g<d.molecules.length;g++){d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_Wireframe){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=1;for(var w=0;w<d.atoms.length;w++){d.atoms[w].displayMode=4}for(var g=0;g<d.molecules.length;g++){d.molecules[g].displayMode=0;d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_Wireframe_SC){for(t=0;t<o.chains.length;t++){d=o.chains[t];for(var w=0;w<d.atoms.length;w++){if(d.atoms[w].molecule.xna){y=x}else{y=u}if(!d.atoms[w].molecule.ligand&&!d.atoms[w].molecule.water&&y.hasOwnProperty(d.atoms[w].atomName)){d.atoms[w].displayMode=0}else{d.atoms[w].displayMode=4}}for(var g=0;g<d.molecules.length;g++){d.molecules[g].showSC=true;d.twoDcache=null}}}else{if(q==molmil.displayMode_CaTrace){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=1;for(g=0;g<d.molecules.length;g++){n=d.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=1;n.showSC=false}}}else{if(q==molmil.displayMode_Tube){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=2;for(g=0;g<d.molecules.length;g++){n=d.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=2;n.showSC=false}}}else{if(q==molmil.displayMode_Cartoon){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=3;for(g=0;g<d.molecules.length;g++){n=d.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=3;n.showSC=false}}}else{if(q==molmil.displayMode_CartoonRocket){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=3;d.twoDcache=null;for(g=0;g<d.molecules.length;g++){n=d.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=31;n.showSC=false}}}else{if(q==molmil.displayMode_ChainSurfaceCG){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=molmil.displayMode_ChainSurfaceCG;d.HQsurface=false}}else{if(q==molmil.displayMode_ChainSurfaceCG+0.5){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=molmil.displayMode_ChainSurfaceCG;d.HQsurface=true}}else{if(q==molmil.displayMode_ChainSurfaceSimple){for(t=0;t<o.chains.length;t++){d=o.chains[t];d.displayMode=molmil.displayMode_ChainSurfaceSimple;d.displaySettings=h}}}}}}}}}}}}}}}}}}}}}else{if(o instanceof molmil.chainObject){if(q==molmil.displayMode_None){o.display=false}else{if(q==molmil.displayMode_Visible){o.display=true}else{if(q==molmil.displayMode_None){o.display=false;o.displayMode=0;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];n.displayMode=0;for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}n.showSC=false}}else{if(q==molmil.displayMode_Default){o.displayMode=3;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];if(n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=3}}else{if(n.xna){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=l.hasOwnProperty(n.atoms[w].atomName)||n.atoms[w].element=="H"?0:3}}else{for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}}n.displayMode=3;n.showSC=false}}else{if(q==molmil.displayMode_Spacefill){o.displayMode=1;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];n.displayMode=0;for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=1}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_Spacefill_SC){for(g=0;g<o.molecules.length;g++){n=o.molecules[g];for(w=0;w<n.atoms.length;w++){if(n.xna){y=x}else{y=u}if(!n.ligand&&!n.water&&y.hasOwnProperty(n.atoms[w].atomName)){n.atoms[w].displayMode=0}else{n.atoms[w].displayMode=1}}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_BallStick){o.displayMode=1;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];n.displayMode=0;for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=2}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_BallStick_SC){for(g=0;g<o.molecules.length;g++){n=o.molecules[g];for(w=0;w<n.atoms.length;w++){if(n.xna){y=x}else{y=u}if(!n.ligand&&!n.water&&y.hasOwnProperty(n.atoms[w].atomName)){n.atoms[w].displayMode=0}else{n.atoms[w].displayMode=2}}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_Stick){o.displayMode=1;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];n.displayMode=0;for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=3}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_Stick_SC){for(g=0;g<o.molecules.length;g++){n=o.molecules[g];for(w=0;w<n.atoms.length;w++){if(n.xna){y=x}else{y=u}if(!n.ligand&&!n.water&&y.hasOwnProperty(n.atoms[w].atomName)){n.atoms[w].displayMode=0}else{n.atoms[w].displayMode=3}}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_Wireframe){o.displayMode=1;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];n.displayMode=0;for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=4}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_Wireframe_SC){o.displayMode=1;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];for(w=0;w<n.atoms.length;w++){if(n.xna){y=x}else{y=u}if(!n.ligand&&!n.water&&y.hasOwnProperty(n.atoms[w].atomName)){n.atoms[w].displayMode=0}else{n.atoms[w].displayMode=4}}n.showSC=true;n.chain.twoDcache=null}}else{if(q==molmil.displayMode_CaTrace){o.displayMode=1;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=1;n.showSC=false}}else{if(q==molmil.displayMode_Tube){o.displayMode=2;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=2;n.showSC=false}}else{if(q==molmil.displayMode_Cartoon){if(o.displayMode==3){o.twoDcache=null}o.displayMode=3;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=3;n.showSC=false}}else{if(q==molmil.displayMode_CartoonRocket){if(o.displayMode==3){o.twoDcache=null}o.displayMode=3;for(g=0;g<o.molecules.length;g++){n=o.molecules[g];if(!n.ligand&&!n.water){for(w=0;w<n.atoms.length;w++){n.atoms[w].displayMode=0}}n.displayMode=31;n.showSC=false}}else{if(q==molmil.displayMode_ChainSurfaceCG){o.displayMode=molmil.displayMode_ChainSurfaceCG}else{if(q==molmil.displayMode_ChainSurfaceCG+0.5){o.displayMode=molmil.displayMode_ChainSurfaceCG;o.HQsurface=true}else{if(q==molmil.displayMode_ChainSurfaceSimple){o.displayMode=molmil.displayMode_ChainSurfaceSimple;o.displaySettings=h}}}}}}}}}}}}}}}}}}}}else{if(o instanceof molmil.molObject){if(q==molmil.displayMode_None){o.display=false;for(w=0;w<o.atoms.length;w++){o.atoms[w].display=false}}else{if(q==molmil.displayMode_Visible){o.display=true;for(w=0;w<o.atoms.length;w++){o.atoms[w].display=true}}else{if(q==molmil.displayMode_None){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=0}}else{if(q==molmil.displayMode_Default){if(o.ligand||o.water){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=3}}else{if(o.xna){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=l.hasOwnProperty(o.atoms[w].atomName)||o.atoms[w].element=="H"?0:3}}else{for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=0}}}o.displayMode=3;o.showSC=false}else{if(q==molmil.displayMode_Spacefill){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=1}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_Spacefill_SC){for(w=0;w<o.atoms.length;w++){if(o.xna){y=x}else{y=u}if(!o.ligand&&!o.water&&y.hasOwnProperty(o.atoms[w].atomName)){o.atoms[w].displayMode=0}else{o.atoms[w].displayMode=1}}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_BallStick){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=2}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_BallStick_SC){for(w=0;w<o.atoms.length;w++){if(o.xna){y=x}else{y=u}if(!o.ligand&&!o.water&&y.hasOwnProperty(o.atoms[w].atomName)){o.atoms[w].displayMode=0}else{o.atoms[w].displayMode=2}}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_Stick){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=3}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_Stick_SC){for(w=0;w<o.atoms.length;w++){if(o.xna){y=x}else{y=u}if(!o.ligand&&!o.water&&y.hasOwnProperty(o.atoms[w].atomName)){o.atoms[w].displayMode=0}else{o.atoms[w].displayMode=3}}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_Wireframe){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=4}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_Wireframe_SC){for(w=0;w<o.atoms.length;w++){if(o.xna){y=x}else{y=u}if(!o.ligand&&!o.water&&y.hasOwnProperty(o.atoms[w].atomName)){o.atoms[w].displayMode=0}else{o.atoms[w].displayMode=4}}o.showSC=true;o.chain.twoDcache=null}else{if(q==molmil.displayMode_CaTrace){if(!o.ligand&&!o.water){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=0}}o.displayMode=1;o.showSC=false}else{if(q==molmil.displayMode_Tube){if(!o.ligand&&!o.water){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=0}}o.displayMode=2;o.showSC=false}else{if(q==molmil.displayMode_Cartoon){if(!o.ligand&&!o.water){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=0}}o.displayMode=3;o.showSC=false}else{if(q==molmil.displayMode_Cartoon){if(!o.ligand&&!o.water){for(w=0;w<o.atoms.length;w++){o.atoms[w].displayMode=0}}o.displayMode=31;o.showSC=false}}}}}}}}}}}}}}}}}else{if(o instanceof molmil.atomObject){if(q==molmil.displayMode_None){o.display=false}else{if(q==molmil.displayMode_Visible){o.display=true}else{if(q==molmil.displayMode_Spacefill){o.displayMode=1}else{if(q==molmil.displayMode_BallStick){o.displayMode=2}else{if(q==molmil.displayMode_Stick){o.displayMode=3}else{if(q==molmil.displayMode_Wireframe){o.displayMode=4}}}}}}}else{if(o instanceof molmil.polygonObject){o.display=q?true:false}}}}}if(f){s.renderer.initBuffers();s.renderer.canvas.update=true}};molmil.colorEntry=function(n,u,w,f,p){p=p||molmil.cli_soup;if(n instanceof Array){for(var o=0;o<n.length;o++){molmil.colorEntry(n[o],u,w,null,p)}if(f){p.renderer.initBuffers();p.renderer.canvas.update=true}return}var g,t,s,d,l,s,d,q;if(n instanceof molmil.entryObject){if(u==molmil.colorEntry_Default){for(s=0;s<n.chains.length;s++){d=n.chains[s];d.rgba=[255,255,255,255];for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,l.sndStruc,molmil.configBox.sndStrucColor[1]);for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,l.atoms[t].element,molmil.configBox.elementColors.DUMMY)}}}}else{if(u==molmil.colorEntry_Structure){for(s=0;s<n.chains.length;s++){d=n.chains[s];for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,l.sndStruc,molmil.configBox.sndStrucColor[1]);for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=l.rgba}}}}else{if(u==molmil.colorEntry_CPK){for(s=0;s<n.chains.length;s++){d=n.chains[s];for(g=0;g<d.molecules.length;g++){l=d.molecules[g];for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,l.atoms[t].element,molmil.configBox.elementColors.DUMMY)}l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,"C",molmil.configBox.elementColors.DUMMY)}}}else{if(u==molmil.colorEntry_Group){q=[];for(s=0;s<n.chains.length;s++){d=n.chains[s];if(d.molecules.length>1){q=molmil.interpolateBR(d.molecules.length)}else{q=[[0,0,255,255]]}for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=q[g];for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=q[g]}}}}else{if(u==molmil.colorEntry_Chain){q=molmil.interpolateBR(n.chains.length);for(s=0;s<n.chains.length;s++){d=n.chains[s];d.rgba=q[s];for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=q[s];for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=q[s]}}}}else{if(u==molmil.colorEntry_Custom){for(s=0;s<n.chains.length;s++){d=n.chains[s];d.rgba=w;for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=w;for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=w}}}}else{if(u==molmil.colorEntry_ChainAlt){q=molmil.configBox.bu_colors;var h=0;for(s=0;s<n.chains.length;s++){d=n.chains[s];d.rgba=[q[h][0],q[h][1],q[h][2],255];h++;for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=n.chains[s].rgba;for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=n.chains[s].rgba}}if(h>=q.length){h=0}}}else{if(u==molmil.colorEntry_ABEGO){for(s=0;s<n.chains.length;s++){d=n.chains[s];d.rgba=[255,255,255,255];if(d.isHet){continue}if(d.molecules[0].phiAngle==undefined){molmil.calculateBBTorsions(d,p)}for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=[255,255,255,255];if(l.omegaAngle<45&&l.omegaAngle>-45){l.rgba=[128,128,128,255]}else{if(l.phiAngle<0){if(l.psiAngle>50||l.psiAngle<-75){l.rgba=[0,0,255,255]}else{l.rgba=[255,0,0,255]}}else{if(l.psiAngle>100||l.psiAngle<-100){l.rgba=[255,255,0,255]}else{l.rgba=[0,255,0,255]}}}for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=l.rgba}}}}}}}}}}}}else{if(n instanceof molmil.chainObject){if(u==molmil.colorEntry_Default){n.rgba=[255,255,255,255];for(g=0;g<n.molecules.length;g++){l=n.molecules[g];l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,l.sndStruc,molmil.configBox.sndStrucColor[1]);for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,l.atoms[t].element,molmil.configBox.elementColors.DUMMY)}}}else{if(u==molmil.colorEntry_Structure){for(g=0;g<n.molecules.length;g++){l=n.molecules[g];l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,l.sndStruc,molmil.configBox.sndStrucColor[1]);for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=l.rgba}}}else{if(u==molmil.colorEntry_CPK){for(g=0;g<n.molecules.length;g++){l=n.molecules[g];for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,l.atoms[t].element,molmil.configBox.elementColors.DUMMY)}l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,"C",molmil.configBox.elementColors.DUMMY)}}else{if(u==molmil.colorEntry_Group){q=[];d=n;if(d.molecules.length>1){q=molmil.interpolateBR(d.molecules.length)}else{q=[[1,1,1]]}for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=q[g];for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=q[g]}}}else{if(u==molmil.colorEntry_Custom){n.rgba=w;for(g=0;g<n.molecules.length;g++){l=n.molecules[g];l.rgba=w;for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=w}}}else{if(u==molmil.colorEntry_ABEGO&&!n.isHet){d=n;d.rgba=[255,255,255,255];if(d.molecules[0].phiAngle==undefined){molmil.calculateBBTorsions(d,p)}for(g=0;g<d.molecules.length;g++){l=d.molecules[g];l.rgba=[255,255,255,255];if(l.omegaAngle<45&&l.omegaAngle>-45){l.rgba=[128,128,128,255]}else{if(l.phiAngle<0){if(l.psiAngle>50||l.psiAngle<-75){l.rgba=[0,0,255,255]}else{l.rgba=[255,0,0,255]}}else{if(l.psiAngle>100||l.psiAngle<-100){l.rgba=[255,255,0,255]}else{l.rgba=[0,255,0,255]}}}for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=l.rgba}}}}}}}}}else{if(n instanceof molmil.molObject){if(u==molmil.colorEntry_Default){l=n;l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,l.sndStruc,molmil.configBox.sndStrucColor[1]);for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,l.atoms[t].element,molmil.configBox.elementColors.DUMMY)}}else{if(u==molmil.colorEntry_Structure){l=n;l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,l.sndStruc,molmil.configBox.sndStrucColor[1]);for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=l.rgba}}else{if(u==molmil.colorEntry_CPK){l=n;for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,l.atoms[t].element,molmil.configBox.elementColors.DUMMY)}l.rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,"C",molmil.configBox.elementColors.DUMMY)}else{if(u==3.2){l=n;for(t=0;t<l.atoms.length;t++){l.atoms[t].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,l.atoms[t].element,molmil.configBox.elementColors.DUMMY)}}else{if(u==molmil.colorEntry_Custom){n.rgba=w;for(t=0;t<n.atoms.length;t++){n.atoms[t].rgba=n.rgba}}}}}}}else{if(n instanceof molmil.atomObject){if(u==molmil.colorEntry_Default||u==molmil.colorEntry_CPK){n.rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,n.element,molmil.configBox.elementColors.DUMMY)}else{if(u==molmil.colorEntry_Structure){l=n.molecule;n.rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,l.sndStruc,molmil.configBox.sndStrucColor[1])}else{if(u==molmil.colorEntry_Custom){n.rgba=w}}}}else{if(n instanceof molmil.polygonObject){}else{return}}}}}if(f){p.renderer.initBuffers();p.renderer.canvas.update=true}};molmil.getAtomFromMolecule=function(d,g){for(var f=0;f<d.atoms.length;f++){if(d.atoms[f].atomName==g){return d.atoms[f]}}return null};molmil.resetColors=function(l,g){if(g){l.soup=g}g=g||molmil.cli_soup;for(var d=0,f,o,n,h;d<g.structures.length;d++){if(l&&g.structures[d]!=l){continue}if(!g.structures[d].chains){continue}for(o=0;o<g.structures[d].chains.length;o++){h=g.structures[d].chains[o];for(f=0;f<h.atoms.length;f++){h.atoms[f].rgba=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,h.atoms[f].element,molmil.configBox.elementColors.DUMMY)}for(n=0;n<h.molecules.length;n++){h.molecules[n].rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,h.molecules[n].sndStruc,molmil.configBox.sndStrucColor[1])}}}};molmil.fetchFrom=function(h,g){var d=[],f;if(h instanceof Array){for(f=0;f<h.length;f++){d=d.concat(molmil.getProteinChains(h[f],g))}}else{if(h instanceof molmil.atomObject){if(g==molmil.molObject){d.push(h.molecule)}else{if(g==molmil.chainObject){d.push(h.chain)}else{if(g==molmil.entryObject){d.push(h.chain.entry)}}}}else{if(h instanceof molmil.molObject){if(g==molmil.atomObject){d=d.concat(h.atoms)}else{if(g==molmil.chainObject){d.push(h.chain)}else{if(g==molmil.entryObject){d.push(h.chain.entry)}}}}else{if(h instanceof molmil.chainObject){if(g==molmil.atomObject){d=d.concat(h.atoms)}else{if(g==molmil.molObject){d=d.concat(h.molecules)}else{if(g==molmil.entryObject){d.push(h.entry)}}}}else{if(h instanceof molmil.entryObject){if(g==molmil.atomObject){for(f=0;f<h.chains.length;f++){d=d.concat(h.atoms[f])}}else{if(g==molmil.molObject){for(f=0;f<h.chains.length;f++){d=d.concat(h.molecules[f])}}else{if(g==molmil.chainObject){d=d.concat(h.chains)}}}}}}}}return d.unique()};molmil.getProteinChains=function(g){var d=[];if(g instanceof Array){for(var f=0;f<g.length;f++){d=d.concat(molmil.getProteinChains(g[f]))}}else{if(g instanceof molmil.entryObject){for(var h=0;h<g.chains.length;h++){if(!g.chains[h].isHet&&g.chains[h].molecules.length&&!g.chains[h].molecules[0].water){d.push(g.chains[h])}}}else{if(g instanceof molmil.chainObj){if(!g.isHet&&g.molecules.length&&!g.molecules[0].water){d.push(g)}}}}return d};molmil.getResiduesForChain=function(g,l,h){var f=[];for(var d=0;d<g.molecules.length;d++){if(g.molecules[d].RSID>=l&&g.molecules[d].RSID<=h){f.push(g.molecules[d])}}return f};molmil.setCanvas=function(f,d){f.canvas=d;if(!d.renderer){f.renderer=d.renderer=new molmil.render(f)}};molmil.initTexture=function(g,f){var d=f.createTexture();d.image=new Image();d.image.texture=d;d.loaded=false;d.image.onload=function(){molmil.handleLoadedTexture(this.texture,f)};d.image.src=g;return d};molmil.handleLoadedTexture=function(d,f){f.bindTexture(f.TEXTURE_2D,d);f.texImage2D(f.TEXTURE_2D,0,f.RGBA,f.RGBA,f.UNSIGNED_BYTE,d.image);f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.LINEAR);f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.LINEAR);f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE);f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE);f.bindTexture(f.TEXTURE_2D,null);d.loaded=true};molmil.resetAttributes=function(f){for(var d in f.boundAttributes){if(f.boundAttributes[d]!=0){f.boundAttributes[d]=-1}}};molmil.bindAttribute=function(o,d,f,g,n,h,l){if(!o.boundAttributes[d]){o.enableVertexAttribArray(d);o.boundAttributes[d]=1}else{if(o.boundAttributes[d]==-1){o.boundAttributes[d]=1}}o.vertexAttribPointer(d,f,g,n,h,l)};molmil.clearAttributes=function(f){for(var d in f.boundAttributes){if(f.boundAttributes[d]==-1){f.disableVertexAttribArray(d);f.boundAttributes[d]=0}}};molmil.safeStartViewer=function(d){if(!d.renderer.camera.z_set){d.renderer.camera.z=d.molmilViewer.calcZ();d.renderer.camera.z_set=true}if(d.initialized){return}for(var f in d.renderer.textures){if(!d.renderer.textures[f].loaded){return molmil_dep.asyncStart(molmil.safeStartViewer,[d],null,100)}}d.renderer.resizeViewPort();molmil.canvasList.push(d);d.initialized=true;if(document.body.classList!==undefined){document.body.classList.add("entryLoaded")}};molmil.animate_molmilViewers=function(){molmil.settings.animationFrameID=requestAnimationFrame(molmil.animate_molmilViewers);for(var d=0;d<molmil.canvasList.length;d++){molmil.canvasList[d].renderer.render()}};molmil.unproject=function(f,d,h,g){f=2*f-1;d=2*d-1;h=2*h-1;var l=[f,d,h,1];vec4.transformMat4(l,l,g);l[3]=1/l[3];return[l[0]*l[3],l[1]*l[3],l[2]*l[3]]};molmil.hermiteInterpolate=function(f,d,q,o,h,C,w,y){var A,B,z,x,u,p,n,l,g;for(A=0;A<(h+(y?2:1));A+=1){B=A/(h+1);z=B*B;x=z*B;u=2*x-3*z+1;p=-2*x+3*z;n=x-2*z+B;l=x-z;C.push([(f[0]*u)+(d[0]*p)+(q[0]*n)+(o[0]*l),(f[1]*u)+(d[1]*p)+(q[1]*n)+(o[1]*l),(f[2]*u)+(d[2]*p)+(q[2]*n)+(o[2]*l)])}for(A=0;A<(h+(y?2:1));A+=1){B=A/(h+1);z=B*B;u=6*(z-B);p=6*(-z+B);n=3*z-4*B+1;l=3*z-2*B;g=[(f[0]*u)+(d[0]*p)+(q[0]*n)+(o[0]*l),(f[1]*u)+(d[1]*p)+(q[1]*n)+(o[1]*l),(f[2]*u)+(d[2]*p)+(q[2]*n)+(o[2]*l)];vec3.normalize(g,g);w.push(g)}};molmil.octaSphereBuilder=function(n){var q=[],h=[],p=0,l,o,z,y,w,u,A,d,g,x,s={};d=function(f,B,t){g=Math.sqrt(f*f+B*B+t*t);q.push([f/g,B/g,t/g]);return p++};x=function(E,C){var f=E<C;smallerIndex=f?E:C;greaterIndex=f?C:E;key=[smallerIndex,greaterIndex];ret=molmil_dep.getKeyFromObject(s,key,null);if(ret!=null){return ret}var D=q[E];var B=q[C];var t=d((D[0]+B[0])*0.5,(D[1]+B[1])*0.5,(D[2]+B[2])*0.5);s[key]=t;return t};d(-1,1,0);d(1,1,0);d(1,-1,0);d(-1,-1,0);d(0,0,-1);d(0,0,1);h.push([0,1,4]);h.push([1,2,4]);h.push([2,3,4]);h.push([3,0,4]);h.push([5,1,0]);h.push([5,2,1]);h.push([5,3,2]);h.push([5,0,3]);for(l=0;l<n;l++){z=[];for(o=0;o<h.length;o++){y=x(h[o][0],h[o][1]);w=x(h[o][1],h[o][2]);u=x(h[o][2],h[o][0]);z.push([h[o][0],y,u]);z.push([h[o][1],w,y]);z.push([h[o][2],u,w]);z.push([y,w,u])}h=z}return{vertices:q,faces:h}};molmil.buildOctaDome=function(q,n){var f=molmil.octaSphereBuilder(q),u,s,p,l,o=[],g;for(var h=0;h<f.vertices.length;h++){u=f.vertices[4][0]-f.vertices[h][0];s=f.vertices[4][1]-f.vertices[h][1];p=f.vertices[4][2]-f.vertices[h][2];l=u*u+s*s+p*p;if((n==0&&l>2.00001)||(n==1&&l<1.99999)){o.push(h)}}for(var h=o.length-1;h>-1;h--){f.vertices.splice(o[h],1)}for(h=0;h<f.faces.length;h++){if(o.indexOf(f.faces[h][0])!=-1||o.indexOf(f.faces[h][1])!=-1||o.indexOf(f.faces[h][2])!=-1){f.faces.splice(h,1);h-=1}else{for(g=0;g<f.faces[h].length;g++){for(k=o.length-1;k>-1;k--){if(f.faces[h][g]>o[k]){f.faces[h][g]-=1}}}}}return f};molmil.buildBondsList4Molecule=function(o,n,p){var u,s,q,d,g,f,l,h,t=molmil.configBox.vdwR;for(g=0;g<n.atoms.length;g++){for(f=g+1;f<n.atoms.length;f++){if(n.atoms[g].label_alt_id!=n.atoms[f].label_alt_id&&n.atoms[g].label_alt_id!=null&&n.atoms[f].label_alt_id!=null){continue}l=n.atoms[g].xyz;h=n.atoms[f].xyz;u=p[l]-p[h];u*=u;s=p[l+1]-p[h+1];s*=s;q=p[l+2]-p[h+2];q*=q;d=u+s+q;maxDistance=3.24;if(t[n.atoms[g].element]===undefined||t[n.atoms[g].element]>=1.8){if(t[n.atoms[f].element]===undefined||t[n.atoms[f].element]>=1.8){maxDistance=6}else{maxDistance=4.5}}else{if(t[n.atoms[f].element]===undefined||t[n.atoms[f].element]>=1.8){if(t[n.atoms[g].element]===undefined||t[n.atoms[g].element]>=1.8){maxDistance=6}else{maxDistance=4.5}}else{if(n.atoms[g].element=="H"||n.atoms[f].element=="H"||n.atoms[g].element=="D"||n.atoms[f].element=="D"){maxDistance=1.6}}}if(d<=maxDistance){o.push([n.atoms[g],n.atoms[f],1])}}}};molmil.isBlackListed=function(){if(molmil.ignoreBlackList){return false}if(navigator.userAgent.indexOf("Mac OS X 10.6")!=-1){return true}else{if(navigator.userAgent.indexOf("Mac OS X 10_6")!=-1){return true}}return false};molmil.addEnableMolmilButton=function(d){d.renderer=d.molmilViewer.renderer;var g=molmil_dep.dcE("DIV");var f=g.pushNode(molmil_dep.createButton("Enable"));d.style.display="none";d.parentNode.pushNode(g);f.onclick=function(){molmil.ignoreBlackList=true;molmil_dep.reloadPage()};return g};molmil.createViewer=function(o,h,d,n,g){var f;var l=window.devicePixelRatio||1;if(o.tagName.toLowerCase()=="canvas"){f=o}else{f=o.pushNode("canvas")}h=h||f.width;d=d||f.height;f.width=h*l;f.height=d*l;f.defaultSize=[h,d];f.style.width=h+"px";f.style.height=d+"px";f.setSize=function(p,q){var s=window.devicePixelRatio||1;this.renderer.width=this.width=p*s;this.renderer.height=this.height=q*s;this.style.width=p+"px";this.style.height=q+"px";this.renderer.resizeViewPort();this.update=true;this.renderer.render()};if(n){f.molmilViewer=n;molmil.setCanvas(n,f);f.molmilViewer.renderer.camera=f.molmilViewer.defaultCanvas[1].camera;f.molmilViewer.renderer.QLV=f.molmilViewer.defaultCanvas[1].QLV}else{f.molmilViewer=new molmil.viewer(f);if(molmil.isBlackListed()){return molmil.addEnableMolmilButton(f)}}if(!f.molmilViewer.renderer.initGL(f)){return f.molmilViewer.renderer.altCanvas}f.style.backgroundColor="rgb("+Math.round(molmil.configBox.BGCOLOR[0]*255)+", "+Math.round(molmil.configBox.BGCOLOR[1]*255)+", "+Math.round(molmil.configBox.BGCOLOR[2]*255)+")";if(!g){f.molmilViewer.UI.init()}f.molmilViewer.renderer.initRenderer();if(n){f.renderer.initBuffers();f.update=true;molmil.safeStartViewer(f)}return f};molmil.selectQLV=function(g,d,f){d=Math.min(Math.max(d,0),molmil.configBox.QLV_SETTINGS.length-1);if(molmil.configBox.liteMode){d=1}g.QLV=d;if(f){g.initBuffers();g.canvas.update=true}};molmil.interpolateBR=function(g){if(g==1){return[[0,0,255,255]]}var h=[],f;for(var d=0;d<g;d++){f=molmil.hslToRgb123((1-(d/(g-1)))*(2/3),1,0.5);h.push([f[0]*255,f[1]*255,f[2]*255,255])}return h};molmil.resetCOG=function(f,d){if(d){f.molmilViewer.calculateCOG()}f.molmilViewer.avgXYZ=[f.molmilViewer.avgX,f.molmilViewer.avgY,f.molmilViewer.avgZ];f.molmilViewer.stdXYZ=[f.molmilViewer.stdX,f.molmilViewer.stdY,f.molmilViewer.stdZ];f.molmilViewer.COR=f.molmilViewer.avgXYZ;f.renderer.camera.z=f.molmilViewer.calcZ()};molmil.loadFile=function(l,h,d,g,f){f=f||molmil.cli_soup;f.loadStructure(l,h,d||function(n,o){molmil.displayEntry(o,1);molmil.colorEntry(o,1,null,true,f)},{async:g?true:false})};molmil.loadPDBlite=function(f,d,n,g){molmil.configBox.liteMode=true;g=g||molmil.cli_soup;var l=new molmil_dep.CallRemote("GET"),n=true;l.ASYNC=n;l.OnDone=function(){this.atom_data=JSON.parse(this.request.responseText)};l.OnError=function(){this.error=true;g=g||molmil.cli_soup;g.loadStructure(molmil.settings.pdb_url.replace("__ID__",f),1,d||function(o,p){delete o.pdbxData;molmil.displayEntry(p,molmil.displayMode_Default);molmil.displayEntry(p,molmil.displayMode_CartoonRocket);molmil.colorEntry(p,1,null,true,g)},{async:n?true:false})};l.Send(molmil.settings.pdb_url.replace("format=mmjson-all","format=mmjson-lite").replace("__ID__",f));var h=new molmil_dep.CallRemote("GET"),n=true;h.ASYNC=n;h.target=this;h.requestA=l;h.OnDone=function(){if(this.requestA.error){return}if(!this.requestA.atom_data){return molmil_dep.asyncStart(this.OnDone,[],this,100)}var o=JSON.parse(this.request.responseText);o["data_"+f.toUpperCase()]["atom_site"]=this.requestA.atom_data["data_"+f.toUpperCase()]["atom_site"];g.loadStructureData(o,"mmjson",f+".json",d||function(p,q){delete p.pdbxData;molmil.displayEntry(q,molmil.displayMode_Default);molmil.displayEntry(q,molmil.displayMode_CartoonRocket);molmil.colorEntry(q,1,null,true,g)})};h.Send(molmil.settings.pdb_url.replace("__ID__",f).replace("format=mmjson-all","format=mmjson-plus-noatom"))};molmil.loadPDB=function(f,d,h,g){g=g||molmil.cli_soup;g.loadStructure(molmil.settings.pdb_url.replace("__ID__",f),1,d||function(l,n){if(g.AID>150000&&(navigator.userAgent.toLowerCase().indexOf("mobile")!=-1||navigator.userAgent.toLowerCase().indexOf("android")!=-1||window.navigator.msMaxTouchPoints)){molmil.displayEntry(n,molmil.displayMode_Wireframe)}else{molmil.displayEntry(n,1)}molmil.colorEntry(n,1,null,true,g)},{async:h?true:false})};molmil.loadCC=function(h,d,g,f){f=f||molmil.cli_soup;f.loadStructure(molmil.settings.comp_url.replace("__ID__",h),1,d||function(l,n){molmil.displayEntry(n,1);molmil.colorEntry(n,1,null,true,f)},{async:g?true:false})};molmil.clear=function(d){d=d||molmil.cli_canvas;d.molmilViewer.clear();d.renderer.initBuffers();d.renderer.camera.reset();d.update=true;if(document.body.classList!==undefined){document.body.classList.remove("entryLoaded")}};molmil.tubeSurface=function(am,aK,aN){if(am instanceof molmil.chainObject){am=[am]}if(!am.length){return}aN=aN||molmil.cli_soup;aK=aK||{};var F;var aL=molmil.configBox.QLV_SETTINGS[aN.renderer.QLV].CB_NOI/32;var ad=[],ac,C=[];for(ac=0;ac<am.length;ac++){chain=am[ac];F=aK.rgba||chain.rgba;var aM=[],aD=chain.modelsXYZ[0];var ax=[0,0,0,0];for(var X=0;X<chain.molecules.length;X++){if(!chain.molecules[X].CA){continue}aM.push([aD[chain.molecules[X].CA.xyz],aD[chain.molecules[X].CA.xyz+1],aD[chain.molecules[X].CA.xyz+2]]);ax[0]+=aD[chain.molecules[X].CA.xyz];ax[1]+=aD[chain.molecules[X].CA.xyz+1];ax[2]+=aD[chain.molecules[X].CA.xyz+2];ax[3]+=1}if(ax[3]<2){continue}ax[0]/=ax[3];ax[1]/=ax[3];ax[2]/=ax[3];var W,aa,Z,u=[[0,0,0],[0,0,0],[0,0,0]],O,N,L;for(W=0;W<aM.length;W++){O=aM[W][0]-ax[0];N=aM[W][1]-ax[1];L=aM[W][2]-ax[2];u[0][0]+=O*O;u[1][1]+=N*N;u[2][2]+=L*L;u[0][1]+=O*N;u[0][2]+=O*L;u[1][2]+=N*L}var B=1/aM.length;u[0][0]*=B;u[1][1]*=B;u[2][2]*=B;u[0][1]=u[1][0]=u[0][1]*B;u[0][2]=u[2][0]=u[0][2]*B;u[1][2]=u[2][1]=u[1][2]*B;var ak=[1,1,1];var ar=new Float64Array(9);ar[0]=u[0][0];ar[1]=u[0][1];ar[2]=u[0][2];ar[3]=u[1][0];ar[4]=u[1][1];ar[5]=u[1][2];ar[6]=u[2][0];ar[7]=u[2][1];ar[8]=u[2][2];var E=10000;var aq=1e-9,aa=0,aI=0,al=0,L=new Float64Array(3);var aE=function(n){aa=0;aI=0;al=Math.sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);n[0]/=al;n[1]/=al;n[2]/=al;while(aa<=E){vec3.transformMat3(L,n,ar);al=Math.sqrt(L[0]*L[0]+L[1]*L[1]+L[2]*L[2]);n[0]=L[0]/al;n[1]=L[1]/al;n[2]=L[2]/al;if(Math.abs((al-aI)/al)<aq){break}aI=al;aa++}};aE(ak);var aF=vec3.squaredLength(L)/al;var aw=new Float64Array(9);aw[0]=ak[0]*ak[0]*aF;aw[1]=ak[0]*ak[1]*aF;aw[2]=ak[0]*ak[2]*aF;aw[3]=ak[1]*ak[0]*aF;aw[4]=ak[1]*ak[1]*aF;aw[5]=ak[1]*ak[2]*aF;aw[6]=ak[2]*ak[0]*aF;aw[7]=ak[2]*ak[1]*aF;aw[8]=ak[2]*ak[2]*aF;ar[0]-=aw[0];ar[1]-=aw[1];ar[2]-=aw[2];ar[3]-=aw[3];ar[4]-=aw[4];ar[5]-=aw[5];ar[6]-=aw[6];ar[7]-=aw[7];ar[8]-=aw[8];var aj=[1,1,1];aE(aj);var aF=vec3.squaredLength(L)/al;var aw=new Float64Array(9);aw[0]=aj[0]*aj[0]*aF;aw[1]=aj[0]*aj[1]*aF;aw[2]=aj[0]*aj[2]*aF;aw[3]=aj[1]*aj[0]*aF;aw[4]=aj[1]*aj[1]*aF;aw[5]=aj[1]*aj[2]*aF;aw[6]=aj[2]*aj[0]*aF;aw[7]=aj[2]*aj[1]*aF;aw[8]=aj[2]*aj[2]*aF;ar[0]-=aw[0];ar[1]-=aw[1];ar[2]-=aw[2];ar[3]-=aw[3];ar[4]-=aw[4];ar[5]-=aw[5];ar[6]-=aw[6];ar[7]-=aw[7];ar[8]-=aw[8];var ai=[1,1,1];aE(ai);var K=[],q=[1e+99,-1],aJ=[-1e+99,-1],J=[],H=[];for(W=0;W<aM.length;W++){O=(aM[W][0]-ax[0])*ak[0]+(aM[W][1]-ax[1])*ak[1]+(aM[W][2]-ax[2])*ak[2];N=(aM[W][0]-ax[0])*aj[0]+(aM[W][1]-ax[1])*aj[1]+(aM[W][2]-ax[2])*aj[2];L=(aM[W][0]-ax[0])*ai[0]+(aM[W][1]-ax[1])*ai[1]+(aM[W][2]-ax[2])*ai[2];K.push(O);J.push(Math.abs(N));H.push(Math.abs(L));if(O<q[0]){q[0]=O;q[1]=W}if(O>aJ[0]){aJ[0]=O;aJ[1]=W}}O=[aM[q[1]][0],ax[0],aM[aJ[1]][0]];N=[aM[q[1]][1],ax[1],aM[aJ[1]][1]];L=[aM[q[1]][2],ax[2],aM[aJ[1]][2]];var D=[0,0,0];D[1]=Math.sqrt(Math.pow(O[1]-O[0],2)+Math.pow(N[1]-N[0],2)+Math.pow(L[1]-L[0],2));D[2]=D[1]+Math.sqrt(Math.pow(O[2]-O[1],2)+Math.pow(N[2]-N[1],2)+Math.pow(L[2]-L[1],2));O=molmil.polynomialFit(D,O,2);N=molmil.polynomialFit(D,N,2);L=molmil.polynomialFit(D,L,2);var G=Math.ceil(D[2]*aL);var T=D[2]/G;var ah=[];for(aa=0;aa<K.length;aa++){ah.push(K[aa]-q[0])}ah.push(0);ah.push(aJ[0]-q[0]);J.push(0);J.push(0);H.push(0);H.push(0);var s=molmil.polynomialFit(ah,J,3);var l=molmil.polynomialFit(ah,H,3);var aG=[[molmil.polynomialCalc(0,O),molmil.polynomialCalc(0,N),molmil.polynomialCalc(0,L)]],al=0;var w=[[aK.radius||molmil.polynomialCalc(0,s),aK.radius||molmil.polynomialCalc(0,l)]];aG.push(aG[0]);w.push(w[0]);for(aa=1;aa<G+1;aa++){al+=T;aG.push([molmil.polynomialCalc(al,O),molmil.polynomialCalc(al,N),molmil.polynomialCalc(al,L)]);w.push([aK.radius||Math.max(molmil.polynomialCalc(al,s)*2,0),aK.radius||Math.max(molmil.polynomialCalc(al,l)*2,0)])}aG.push(aG[aG.length-1]);w.push(w[w.length-1]);w[0][0]=w[1][0]=(w[0][0]+w[2][0])*0.5;w[0][1]=w[0][1]=(w[0][1]+w[2][1])*0.5;w[w.length-1][0]=w[w.length-2][0]=(w[w.length-1][0]+w[w.length-3][0])*0.5;w[w.length-1][1]=w[w.length-2][1]=(w[w.length-1][1]+w[w.length-3][1])*0.5;ad.push(aG);C.push(w)}var av=[0,0];for(ac=0;ac<ad.length;ac++){for(W=1;W<ad[ac].length-1;W++){av[0]+=C[ac][W][0]+C[ac][W][1];av[1]+=2}}av=av[0]/av[1];var an=Math.max(Math.ceil(molmil.configBox.QLV_SETTINGS[aN.renderer.QLV].CB_NOVPR*0.125*av),6);var I=0,t=2/an,au=[];for(aa=0;aa<an;aa++){O=Math.cos(I*Math.PI);N=Math.sin(I*Math.PI);au.push([O,N,0]);I+=t}var af=0;for(ac=0;ac<ad.length;ac++){af+=ad[ac].length}var az=new Float32Array(((af*an)+(2*ad.length))*7);var h=new Uint8Array(az.buffer);if(molmil.configBox.OES_element_index_uint){var aO=new Uint32Array((((af-1)*an*2)+(an*2))*3)}else{var aO=new Uint16Array(((af*an*2)+(an*2))*3)}var Y=0,ag=0,d=0;var aC,aA,ay,at,ap,ao,S,Q,P;var g=mat4.create(),f=mat4.create(),U,M=[],R,ae=new Float32Array(3),ab=new Float32Array(3),o=0.0001;var V=0,aH=0;for(ac=0;ac<ad.length;ac++){aG=ad[ac];w=C[ac];M=[];R=new Float32Array(3);vec3.subtract(R,aG[1],aG[0]);vec3.normalize(R,R);M.push(R);for(W=1;W<aG.length-1;W++){R=new Float32Array(3);vec3.subtract(R,aG[W+1],aG[W-1]);vec3.normalize(R,R);M.push(R)}M.push(R);R=new Float32Array(3);M[0][0]+=M[1][0];M[0][1]+=M[1][1];M[0][2]+=M[1][2];vec3.normalize(M[0],M[0]);az[Y++]=aG[0][0];az[Y++]=aG[0][1];az[Y++]=aG[0][2];az[Y++]=-M[0][0];az[Y++]=-M[0][1];az[Y++]=-M[0][2];h[d+24]=F[0];h[d+25]=F[1];h[d+26]=F[2];h[d+27]=F[3];Y++;d+=28;M[0]=M[1];for(aa=0;aa<au.length;aa++){aO[ag++]=V+aa+2;aO[ag++]=V+aa+1;aO[ag++]=V}aO[ag-3]=V+1;V+=au.length+1;aH=V-an;for(W=0;W<aG.length;W++){if(W==0){U=Number.MAX_VALUE;if(M[0][0]<=U){U=M[0][0];ae=[1,0,0]}if(M[0][1]<=U){U=M[0][1];ae=[0,1,0]}if(M[0][2]<=U){U=M[0][2];ae=[0,0,1]}vec3.cross(R,M[0],ae);vec3.normalize(R,R);vec3.cross(ae,M[0],R);vec3.cross(ab=[0,0,0],M[0],ae)}else{vec3.cross(R,M[W-1],M[W]);if(vec3.length(R)>o){vec3.normalize(R,R);I=Math.acos(Math.max(-1,Math.min(1,vec3.dot(M[W-1],M[W]))));mat4.rotate(f,g,I,R);vec3.transformMat4(ae,ae,f)}vec3.cross(ab,M[W],ae)}S=aG[W][0];Q=aG[W][1];P=aG[W][2];at=ab[0];ap=ab[1];ao=ab[2];aC=ae[0];aA=ae[1];ay=ae[2];for(aa=0;aa<au.length;aa++,d+=28){az[Y++]=w[W][0]*au[aa][0]*aC+w[W][1]*au[aa][1]*at+S;az[Y++]=w[W][0]*au[aa][0]*aA+w[W][1]*au[aa][1]*ap+Q;az[Y++]=w[W][0]*au[aa][0]*ay+w[W][1]*au[aa][1]*ao+P;if(W==0){az[Y++]=-M[0][0];az[Y++]=-M[0][1];az[Y++]=-M[0][2]}else{if(W==aG.length-1){az[Y++]=M[W][0];az[Y++]=M[W][1];az[Y++]=M[W][2]}else{az[Y++]=au[aa][0]*aC+au[aa][1]*at;az[Y++]=au[aa][0]*aA+au[aa][1]*ap;az[Y++]=au[aa][0]*ay+au[aa][1]*ao}}h[d+24]=F[0];h[d+25]=F[1];h[d+26]=F[2];h[d+27]=F[3];Y++}if(W<aG.length-1){for(aa=0;aa<(an*2)-2;aa+=2,V+=1,aH+=1){aO[ag++]=V;aO[ag++]=aH;aO[ag++]=aH+1;aO[ag++]=aH+1;aO[ag++]=V+1;aO[ag++]=V}aO[ag++]=V;aO[ag++]=aH;aO[ag++]=aH-(an-1);aO[ag++]=aH-(an-1);aO[ag++]=V-(an-1);aO[ag++]=V;V++;aH++}}W--;az[Y++]=aG[W][0];az[Y++]=aG[W][1];az[Y++]=aG[W][2];az[Y++]=M[W][0];az[Y++]=M[W][1];az[Y++]=M[W][2];h[d+24]=F[0];h[d+25]=F[1];h[d+26]=F[2];h[d+27]=F[3];Y++;d+=28;for(aa=0;aa<au.length;aa++){aO[ag++]=V;aO[ag++]=V+aa-au.length;aO[ag++]=V+aa+1-au.length}aO[ag-1]-=au.length;V++;aH++}if(aK.skipProgram){return{vBuffer:az,iBuffer:aO}}if(typeof(aK.solid)=="undefined"){aK.solid=true}var aB=molmil.geometry.build_simple_render_program(az,aO,aN.renderer,aK);aN.renderer.programs.push(aB);aN.calculateCOG();aN.renderer.initBuffers();aN.canvas.update=true};molmil.coarseSurface=function(ad,Q,ag,aa){aa=aa||{};var B=1/Q;var M=ad.atoms;var af=ad.modelsXYZ[0];var u=[1e+99,-1e+99,1e+99,-1e+99,1e+99,-1e+99],ae,ac,n={},Y,X,W,N,L,K,s,A={},O={},o=[0,0,0,0,0,0],t,C,q=molmil.configBox.vdwR,U,J,I,F,S,H,g,y,V,P,p,l,h,d,x,w;for(ae=0;ae<M.length;ae++){ac=af[M[ae].xyz];if(ac<u[0]){u[0]=ac}if(ac>u[1]){u[1]=ac}ac=af[M[ae].xyz+1];if(ac<u[2]){u[2]=ac}if(ac>u[3]){u[3]=ac}ac=af[M[ae].xyz+2];if(ac<u[4]){u[4]=ac}if(ac>u[5]){u[5]=ac}n[M[ae].element]=1}Y=Math.ceil((u[1]-u[0]+(2*ag)+(2*1.8))/Q)+2;X=Math.ceil((u[3]-u[2]+(2*ag)+(2*1.8))/Q)+2;W=Math.ceil((u[5]-u[4]+(2*ag)+(2*1.8))/Q)+2;N=-u[0]+ag+1.8+Q;L=-u[2]+ag+1.8+Q;K=-u[4]+ag+1.8+Q;s=Y*X*W;for(ae in n){A[ae]=new Float32Array(s);O[ae]=[];for(S=0;S<s;S++){A[ae][S]=1e+99;O[ae].push(null)}n[ae]=molmil_dep.getKeyFromObject(q,ae,q.DUMMY)}for(ae=0;ae<M.length;ae++){t=A[M[ae].element];C=O[M[ae].element];U=n[M[ae].element];J=af[M[ae].xyz]+N;I=af[M[ae].xyz+1]+L;F=af[M[ae].xyz+2]+K;o[0]=0;o[1]=Y;o[2]=0;o[3]=X;o[4]=0;o[5]=W;for(S=o[0];S<o[1];S++){V=S*Q;for(H=o[2];H<o[3];H++){P=H*Q;for(g=o[4];g<o[5];g++){p=g*Q;y=S+Y*(H+X*g);l=J-V;h=I-P;d=F-p;ac=l*l+h*h+d*d;if(ac<t[y]){t[y]=ac;C[y]=U}}}}}x=new Float32Array(s);for(S=0;S<s;S++){y=1e+99;for(ae in n){U=Math.sqrt(A[ae][S])-(ag+O[ae][S]);if(U<y){y=U}}x[S]=y*B}if(!aa.deproj&&!aa.sas){var R=ag/Q;for(S=0;S<s;S++){x[S]+=R}}var D=polygonize([Y,X,W],x,0);molmil.taubinSmoothing(D.vertices,D.faces,0.5,-0.53,10);var Z,z,ab,G=[],T;for(Z=0;Z<D.vertices.length;Z++){G.push([0,0,0])}for(Z in D.vertexIndex){T=G[D.vertexIndex[Z][0]];z=D.vertexIndex[Z][1];for(ab=0;ab<z.length;ab++){vec3.add(T,T,D.face_normals[z[ab]])}vec3.normalize(T,T)}D.normals=G;molmil.taubinSmoothing(D.normals,D.faces,0.5,-0.53,10);if(aa.deproj){var E=1/Q;for(Z=0;Z<G.length;Z++){D.vertices[Z][0]=((D.vertices[Z][0]-G[Z][0]*ag*E)*Q)-N;D.vertices[Z][1]=((D.vertices[Z][1]-G[Z][1]*ag*E)*Q)-L;D.vertices[Z][2]=((D.vertices[Z][2]-G[Z][2]*ag*E)*Q)-K}}else{for(Z=0;Z<G.length;Z++){D.vertices[Z][0]=((D.vertices[Z][0])*Q)-N;D.vertices[Z][1]=((D.vertices[Z][1])*Q)-L;D.vertices[Z][2]=((D.vertices[Z][2])*Q)-K}}return D};var edgeTable=new Int32Array([0,265,515,778,1030,1295,1541,1804,2060,2309,2575,2822,3082,3331,3593,3840,400,153,915,666,1430,1183,1941,1692,2460,2197,2975,2710,3482,3219,3993,3728,560,825,51,314,1590,1855,1077,1340,2620,2869,2111,2358,3642,3891,3129,3376,928,681,419,170,1958,1711,1445,1196,2988,2725,2479,2214,4010,3747,3497,3232,1120,1385,1635,1898,102,367,613,876,3180,3429,3695,3942,2154,2403,2665,2912,1520,1273,2035,1786,502,255,1013,764,3580,3317,4095,3830,2554,2291,3065,2800,1616,1881,1107,1370,598,863,85,348,3676,3925,3167,3414,2650,2899,2137,2384,1984,1737,1475,1226,966,719,453,204,4044,3781,3535,3270,3018,2755,2505,2240,2240,2505,2755,3018,3270,3535,3781,4044,204,453,719,966,1226,1475,1737,1984,2384,2137,2899,2650,3414,3167,3925,3676,348,85,863,598,1370,1107,1881,1616,2800,3065,2291,2554,3830,4095,3317,3580,764,1013,255,502,1786,2035,1273,1520,2912,2665,2403,2154,3942,3695,3429,3180,876,613,367,102,1898,1635,1385,1120,3232,3497,3747,4010,2214,2479,2725,2988,1196,1445,1711,1958,170,419,681,928,3376,3129,3891,3642,2358,2111,2869,2620,1340,1077,1855,1590,314,51,825,560,3728,3993,3219,3482,2710,2975,2197,2460,1692,1941,1183,1430,666,915,153,400,3840,3593,3331,3082,2822,2575,2309,2060,1804,1541,1295,1030,778,515,265,0]);var triTable=new Int32Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,9,8,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,2,10,0,2,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,8,3,2,10,8,10,9,8,-1,-1,-1,-1,-1,-1,-1,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,8,11,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,11,2,1,9,11,9,8,11,-1,-1,-1,-1,-1,-1,-1,3,10,1,11,10,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,10,1,0,8,10,8,11,10,-1,-1,-1,-1,-1,-1,-1,3,9,0,3,11,9,11,10,9,-1,-1,-1,-1,-1,-1,-1,9,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,7,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,1,9,4,7,1,7,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,4,7,3,0,4,1,2,10,-1,-1,-1,-1,-1,-1,-1,9,2,10,9,0,2,8,4,7,-1,-1,-1,-1,-1,-1,-1,2,10,9,2,9,7,2,7,3,7,9,4,-1,-1,-1,-1,8,4,7,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,4,7,11,2,4,2,0,4,-1,-1,-1,-1,-1,-1,-1,9,0,1,8,4,7,2,3,11,-1,-1,-1,-1,-1,-1,-1,4,7,11,9,4,11,9,11,2,9,2,1,-1,-1,-1,-1,3,10,1,3,11,10,7,8,4,-1,-1,-1,-1,-1,-1,-1,1,11,10,1,4,11,1,0,4,7,11,4,-1,-1,-1,-1,4,7,8,9,0,11,9,11,10,11,0,3,-1,-1,-1,-1,4,7,11,4,11,9,9,11,10,-1,-1,-1,-1,-1,-1,-1,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,5,4,1,5,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,5,4,8,3,5,3,1,5,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,10,4,9,5,-1,-1,-1,-1,-1,-1,-1,5,2,10,5,4,2,4,0,2,-1,-1,-1,-1,-1,-1,-1,2,10,5,3,2,5,3,5,4,3,4,8,-1,-1,-1,-1,9,5,4,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,0,8,11,4,9,5,-1,-1,-1,-1,-1,-1,-1,0,5,4,0,1,5,2,3,11,-1,-1,-1,-1,-1,-1,-1,2,1,5,2,5,8,2,8,11,4,8,5,-1,-1,-1,-1,10,3,11,10,1,3,9,5,4,-1,-1,-1,-1,-1,-1,-1,4,9,5,0,8,1,8,10,1,8,11,10,-1,-1,-1,-1,5,4,0,5,0,11,5,11,10,11,0,3,-1,-1,-1,-1,5,4,8,5,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,9,7,8,5,7,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,3,0,9,5,3,5,7,3,-1,-1,-1,-1,-1,-1,-1,0,7,8,0,1,7,1,5,7,-1,-1,-1,-1,-1,-1,-1,1,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,7,8,9,5,7,10,1,2,-1,-1,-1,-1,-1,-1,-1,10,1,2,9,5,0,5,3,0,5,7,3,-1,-1,-1,-1,8,0,2,8,2,5,8,5,7,10,5,2,-1,-1,-1,-1,2,10,5,2,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,7,9,5,7,8,9,3,11,2,-1,-1,-1,-1,-1,-1,-1,9,5,7,9,7,2,9,2,0,2,7,11,-1,-1,-1,-1,2,3,11,0,1,8,1,7,8,1,5,7,-1,-1,-1,-1,11,2,1,11,1,7,7,1,5,-1,-1,-1,-1,-1,-1,-1,9,5,8,8,5,7,10,1,3,10,3,11,-1,-1,-1,-1,5,7,0,5,0,9,7,11,0,1,0,10,11,10,0,-1,11,10,0,11,0,3,10,5,0,8,0,7,5,7,0,-1,11,10,5,7,11,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,0,1,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,1,9,8,5,10,6,-1,-1,-1,-1,-1,-1,-1,1,6,5,2,6,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,6,5,1,2,6,3,0,8,-1,-1,-1,-1,-1,-1,-1,9,6,5,9,0,6,0,2,6,-1,-1,-1,-1,-1,-1,-1,5,9,8,5,8,2,5,2,6,3,2,8,-1,-1,-1,-1,2,3,11,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,0,8,11,2,0,10,6,5,-1,-1,-1,-1,-1,-1,-1,0,1,9,2,3,11,5,10,6,-1,-1,-1,-1,-1,-1,-1,5,10,6,1,9,2,9,11,2,9,8,11,-1,-1,-1,-1,6,3,11,6,5,3,5,1,3,-1,-1,-1,-1,-1,-1,-1,0,8,11,0,11,5,0,5,1,5,11,6,-1,-1,-1,-1,3,11,6,0,3,6,0,6,5,0,5,9,-1,-1,-1,-1,6,5,9,6,9,11,11,9,8,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,4,7,3,6,5,10,-1,-1,-1,-1,-1,-1,-1,1,9,0,5,10,6,8,4,7,-1,-1,-1,-1,-1,-1,-1,10,6,5,1,9,7,1,7,3,7,9,4,-1,-1,-1,-1,6,1,2,6,5,1,4,7,8,-1,-1,-1,-1,-1,-1,-1,1,2,5,5,2,6,3,0,4,3,4,7,-1,-1,-1,-1,8,4,7,9,0,5,0,6,5,0,2,6,-1,-1,-1,-1,7,3,9,7,9,4,3,2,9,5,9,6,2,6,9,-1,3,11,2,7,8,4,10,6,5,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,2,4,2,0,2,7,11,-1,-1,-1,-1,0,1,9,4,7,8,2,3,11,5,10,6,-1,-1,-1,-1,9,2,1,9,11,2,9,4,11,7,11,4,5,10,6,-1,8,4,7,3,11,5,3,5,1,5,11,6,-1,-1,-1,-1,5,1,11,5,11,6,1,0,11,7,11,4,0,4,11,-1,0,5,9,0,6,5,0,3,6,11,6,3,8,4,7,-1,6,5,9,6,9,11,4,7,9,7,11,9,-1,-1,-1,-1,10,4,9,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,10,6,4,9,10,0,8,3,-1,-1,-1,-1,-1,-1,-1,10,0,1,10,6,0,6,4,0,-1,-1,-1,-1,-1,-1,-1,8,3,1,8,1,6,8,6,4,6,1,10,-1,-1,-1,-1,1,4,9,1,2,4,2,6,4,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,9,2,4,9,2,6,4,-1,-1,-1,-1,0,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,3,2,8,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,10,4,9,10,6,4,11,2,3,-1,-1,-1,-1,-1,-1,-1,0,8,2,2,8,11,4,9,10,4,10,6,-1,-1,-1,-1,3,11,2,0,1,6,0,6,4,6,1,10,-1,-1,-1,-1,6,4,1,6,1,10,4,8,1,2,1,11,8,11,1,-1,9,6,4,9,3,6,9,1,3,11,6,3,-1,-1,-1,-1,8,11,1,8,1,0,11,6,1,9,1,4,6,4,1,-1,3,11,6,3,6,0,0,6,4,-1,-1,-1,-1,-1,-1,-1,6,4,8,11,6,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,10,6,7,8,10,8,9,10,-1,-1,-1,-1,-1,-1,-1,0,7,3,0,10,7,0,9,10,6,7,10,-1,-1,-1,-1,10,6,7,1,10,7,1,7,8,1,8,0,-1,-1,-1,-1,10,6,7,10,7,1,1,7,3,-1,-1,-1,-1,-1,-1,-1,1,2,6,1,6,8,1,8,9,8,6,7,-1,-1,-1,-1,2,6,9,2,9,1,6,7,9,0,9,3,7,3,9,-1,7,8,0,7,0,6,6,0,2,-1,-1,-1,-1,-1,-1,-1,7,3,2,6,7,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,11,10,6,8,10,8,9,8,6,7,-1,-1,-1,-1,2,0,7,2,7,11,0,9,7,6,7,10,9,10,7,-1,1,8,0,1,7,8,1,10,7,6,7,10,2,3,11,-1,11,2,1,11,1,7,10,6,1,6,7,1,-1,-1,-1,-1,8,9,6,8,6,7,9,1,6,11,6,3,1,3,6,-1,0,9,1,11,6,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,0,7,0,6,3,11,0,11,6,0,-1,-1,-1,-1,7,11,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,1,9,8,3,1,11,7,6,-1,-1,-1,-1,-1,-1,-1,10,1,2,6,11,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,8,6,11,7,-1,-1,-1,-1,-1,-1,-1,2,9,0,2,10,9,6,11,7,-1,-1,-1,-1,-1,-1,-1,6,11,7,2,10,3,10,8,3,10,9,8,-1,-1,-1,-1,7,2,3,6,2,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,0,8,7,6,0,6,2,0,-1,-1,-1,-1,-1,-1,-1,2,7,6,2,3,7,0,1,9,-1,-1,-1,-1,-1,-1,-1,1,6,2,1,8,6,1,9,8,8,7,6,-1,-1,-1,-1,10,7,6,10,1,7,1,3,7,-1,-1,-1,-1,-1,-1,-1,10,7,6,1,7,10,1,8,7,1,0,8,-1,-1,-1,-1,0,3,7,0,7,10,0,10,9,6,10,7,-1,-1,-1,-1,7,6,10,7,10,8,8,10,9,-1,-1,-1,-1,-1,-1,-1,6,8,4,11,8,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,6,11,3,0,6,0,4,6,-1,-1,-1,-1,-1,-1,-1,8,6,11,8,4,6,9,0,1,-1,-1,-1,-1,-1,-1,-1,9,4,6,9,6,3,9,3,1,11,3,6,-1,-1,-1,-1,6,8,4,6,11,8,2,10,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,11,0,6,11,0,4,6,-1,-1,-1,-1,4,11,8,4,6,11,0,2,9,2,10,9,-1,-1,-1,-1,10,9,3,10,3,2,9,4,3,11,3,6,4,6,3,-1,8,2,3,8,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,0,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,4,2,4,6,4,3,8,-1,-1,-1,-1,1,9,4,1,4,2,2,4,6,-1,-1,-1,-1,-1,-1,-1,8,1,3,8,6,1,8,4,6,6,10,1,-1,-1,-1,-1,10,1,0,10,0,6,6,0,4,-1,-1,-1,-1,-1,-1,-1,4,6,3,4,3,8,6,10,3,0,3,9,10,9,3,-1,10,9,4,6,10,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,5,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,5,11,7,6,-1,-1,-1,-1,-1,-1,-1,5,0,1,5,4,0,7,6,11,-1,-1,-1,-1,-1,-1,-1,11,7,6,8,3,4,3,5,4,3,1,5,-1,-1,-1,-1,9,5,4,10,1,2,7,6,11,-1,-1,-1,-1,-1,-1,-1,6,11,7,1,2,10,0,8,3,4,9,5,-1,-1,-1,-1,7,6,11,5,4,10,4,2,10,4,0,2,-1,-1,-1,-1,3,4,8,3,5,4,3,2,5,10,5,2,11,7,6,-1,7,2,3,7,6,2,5,4,9,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,6,0,6,2,6,8,7,-1,-1,-1,-1,3,6,2,3,7,6,1,5,0,5,4,0,-1,-1,-1,-1,6,2,8,6,8,7,2,1,8,4,8,5,1,5,8,-1,9,5,4,10,1,6,1,7,6,1,3,7,-1,-1,-1,-1,1,6,10,1,7,6,1,0,7,8,7,0,9,5,4,-1,4,0,10,4,10,5,0,3,10,6,10,7,3,7,10,-1,7,6,10,7,10,8,5,4,10,4,8,10,-1,-1,-1,-1,6,9,5,6,11,9,11,8,9,-1,-1,-1,-1,-1,-1,-1,3,6,11,0,6,3,0,5,6,0,9,5,-1,-1,-1,-1,0,11,8,0,5,11,0,1,5,5,6,11,-1,-1,-1,-1,6,11,3,6,3,5,5,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,11,9,11,8,11,5,6,-1,-1,-1,-1,0,11,3,0,6,11,0,9,6,5,6,9,1,2,10,-1,11,8,5,11,5,6,8,0,5,10,5,2,0,2,5,-1,6,11,3,6,3,5,2,10,3,10,5,3,-1,-1,-1,-1,5,8,9,5,2,8,5,6,2,3,8,2,-1,-1,-1,-1,9,5,6,9,6,0,0,6,2,-1,-1,-1,-1,-1,-1,-1,1,5,8,1,8,0,5,6,8,3,8,2,6,2,8,-1,1,5,6,2,1,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,6,1,6,10,3,8,6,5,6,9,8,9,6,-1,10,1,0,10,0,6,9,5,0,5,6,0,-1,-1,-1,-1,0,3,8,5,6,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,7,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,11,7,5,8,3,0,-1,-1,-1,-1,-1,-1,-1,5,11,7,5,10,11,1,9,0,-1,-1,-1,-1,-1,-1,-1,10,7,5,10,11,7,9,8,1,8,3,1,-1,-1,-1,-1,11,1,2,11,7,1,7,5,1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,7,1,7,5,7,2,11,-1,-1,-1,-1,9,7,5,9,2,7,9,0,2,2,11,7,-1,-1,-1,-1,7,5,2,7,2,11,5,9,2,3,2,8,9,8,2,-1,2,5,10,2,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,8,2,0,8,5,2,8,7,5,10,2,5,-1,-1,-1,-1,9,0,1,5,10,3,5,3,7,3,10,2,-1,-1,-1,-1,9,8,2,9,2,1,8,7,2,10,2,5,7,5,2,-1,1,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,7,0,7,1,1,7,5,-1,-1,-1,-1,-1,-1,-1,9,0,3,9,3,5,5,3,7,-1,-1,-1,-1,-1,-1,-1,9,8,7,5,9,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,5,8,4,5,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,5,0,4,5,11,0,5,10,11,11,3,0,-1,-1,-1,-1,0,1,9,8,4,10,8,10,11,10,4,5,-1,-1,-1,-1,10,11,4,10,4,5,11,3,4,9,4,1,3,1,4,-1,2,5,1,2,8,5,2,11,8,4,5,8,-1,-1,-1,-1,0,4,11,0,11,3,4,5,11,2,11,1,5,1,11,-1,0,2,5,0,5,9,2,11,5,4,5,8,11,8,5,-1,9,4,5,2,11,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,5,10,3,5,2,3,4,5,3,8,4,-1,-1,-1,-1,5,10,2,5,2,4,4,2,0,-1,-1,-1,-1,-1,-1,-1,3,10,2,3,5,10,3,8,5,4,5,8,0,1,9,-1,5,10,2,5,2,4,1,9,2,9,4,2,-1,-1,-1,-1,8,4,5,8,5,3,3,5,1,-1,-1,-1,-1,-1,-1,-1,0,4,5,1,0,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,4,5,8,5,3,9,0,5,0,3,5,-1,-1,-1,-1,9,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,11,7,4,9,11,9,10,11,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,7,9,11,7,9,10,11,-1,-1,-1,-1,1,10,11,1,11,4,1,4,0,7,4,11,-1,-1,-1,-1,3,1,4,3,4,8,1,10,4,7,4,11,10,11,4,-1,4,11,7,9,11,4,9,2,11,9,1,2,-1,-1,-1,-1,9,7,4,9,11,7,9,1,11,2,11,1,0,8,3,-1,11,7,4,11,4,2,2,4,0,-1,-1,-1,-1,-1,-1,-1,11,7,4,11,4,2,8,3,4,3,2,4,-1,-1,-1,-1,2,9,10,2,7,9,2,3,7,7,4,9,-1,-1,-1,-1,9,10,7,9,7,4,10,2,7,8,7,0,2,0,7,-1,3,7,10,3,10,2,7,4,10,1,10,0,4,0,10,-1,1,10,2,8,7,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,7,1,3,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,0,8,1,8,7,1,-1,-1,-1,-1,4,0,3,7,4,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,8,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,11,9,10,-1,-1,-1,-1,-1,-1,-1,0,1,10,0,10,8,8,10,11,-1,-1,-1,-1,-1,-1,-1,3,1,10,11,3,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,11,1,11,9,9,11,8,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,1,2,9,2,11,9,-1,-1,-1,-1,0,2,11,8,0,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,10,8,9,-1,-1,-1,-1,-1,-1,-1,9,10,2,0,9,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,0,1,8,1,10,8,-1,-1,-1,-1,1,10,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,8,9,1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,9,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,3,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]);function polygonize(C,t,E,F){var D=0,I=[],H,w,u,s,g=[0,0,0],f=[0,0,0],h=0,d=[],A={},l=[],q=[],B,p,o,n;for(H=0;H<12;H++){I.push([0,0,0])}for(s=0;s<C[2]-1;s++){for(u=0;u<C[1]-1;u++){for(w=0;w<C[0]-1;w++){if(F){grid0=F(w,u,s);grid1=F(w+1,u,s);grid2=F(w+1,u,s+1);grid3=F(w,u,s+1);grid4=F(w,u+1,s);grid5=F(w+1,u+1,s);grid6=F(w+1,u+1,s+1);grid7=F(w,u+1,s+1)}else{grid0=w+C[0]*(u+C[1]*s);grid1=(w+1)+C[0]*(u+C[1]*s);grid2=(w+1)+C[0]*(u+C[1]*(s+1));grid3=w+C[0]*(u+C[1]*(s+1));grid4=w+C[0]*((u+1)+C[1]*s);grid5=(w+1)+C[0]*((u+1)+C[1]*s);grid6=(w+1)+C[0]*((u+1)+C[1]*(s+1));grid7=w+C[0]*((u+1)+C[1]*(s+1))}D=0;if(t[grid0]<E){D|=1}if(t[grid1]<E){D|=2}if(t[grid2]<E){D|=4}if(t[grid3]<E){D|=8}if(t[grid4]<E){D|=16}if(t[grid5]<E){D|=32}if(t[grid6]<E){D|=64}if(t[grid7]<E){D|=128}if(edgeTable[D]===0){continue}if(edgeTable[D]&1){g[0]=w;g[1]=u;g[2]=s;f[0]=w+1;f[1]=u;f[2]=s;h=(E-t[grid0])/(t[grid1]-t[grid0]);vec3.lerp(I[0],g,f,h)}if(edgeTable[D]&2){g[0]=w+1;g[1]=u;g[2]=s;f[0]=w+1;f[1]=u;f[2]=s+1;h=(E-t[grid1])/(t[grid2]-t[grid1]);vec3.lerp(I[1],g,f,h)}if(edgeTable[D]&4){g[0]=w+1;g[1]=u;g[2]=s+1;f[0]=w;f[1]=u;f[2]=s+1;h=(E-t[grid2])/(t[grid3]-t[grid2]);vec3.lerp(I[2],g,f,h)}if(edgeTable[D]&8){g[0]=w;g[1]=u;g[2]=s+1;f[0]=w;f[1]=u;f[2]=s;h=(E-t[grid3])/(t[grid0]-t[grid3]);vec3.lerp(I[3],g,f,h)}if(edgeTable[D]&16){g[0]=w;g[1]=u+1;g[2]=s;f[0]=w+1;f[1]=u+1;f[2]=s;h=(E-t[grid4])/(t[grid5]-t[grid4]);vec3.lerp(I[4],g,f,h)}if(edgeTable[D]&32){g[0]=w+1;g[1]=u+1;g[2]=s;f[0]=w+1;f[1]=u+1;f[2]=s+1;h=(E-t[grid5])/(t[grid6]-t[grid5]);vec3.lerp(I[5],g,f,h)}if(edgeTable[D]&64){g[0]=w+1;g[1]=u+1;g[2]=s+1;f[0]=w;f[1]=u+1;f[2]=s+1;h=(E-t[grid6])/(t[grid7]-t[grid6]);vec3.lerp(I[6],g,f,h)}if(edgeTable[D]&128){g[0]=w;g[1]=u+1;g[2]=s+1;f[0]=w;f[1]=u+1;f[2]=s;h=(E-t[grid7])/(t[grid4]-t[grid7]);vec3.lerp(I[7],g,f,h)}if(edgeTable[D]&256){g[0]=w;g[1]=u;g[2]=s;f[0]=w;f[1]=u+1;f[2]=s;h=(E-t[grid0])/(t[grid4]-t[grid0]);vec3.lerp(I[8],g,f,h)}if(edgeTable[D]&512){g[0]=w+1;g[1]=u;g[2]=s;f[0]=w+1;f[1]=u+1;f[2]=s;h=(E-t[grid1])/(t[grid5]-t[grid1]);vec3.lerp(I[9],g,f,h)}if(edgeTable[D]&1024){g[0]=w+1;g[1]=u;g[2]=s+1;f[0]=w+1;f[1]=u+1;f[2]=s+1;h=(E-t[grid2])/(t[grid6]-t[grid2]);vec3.lerp(I[10],g,f,h)}if(edgeTable[D]&2048){g[0]=w;g[1]=u;g[2]=s+1;f[0]=w;f[1]=u+1;f[2]=s+1;h=(E-t[grid3])/(t[grid7]-t[grid3]);vec3.lerp(I[11],g,f,h)}for(H=0;triTable[16*D+H]!=-1;H+=3){p=I[triTable[16*D+H+1]];o=I[triTable[16*D+H+2]];n=I[triTable[16*D+H]];idx1=(p[0]|0)+C[0]*((p[1]|0)+C[1]*(p[2]|0));idx2=(o[0]|0)+C[0]*((o[1]|0)+C[1]*(o[2]|0));idx3=(n[0]|0)+C[0]*((n[1]|0)+C[1]*(n[2]|0));var G=[-1,-1,-1];if(!A[idx1]){A[idx1]=[l.length,[]];l.push([p[0],p[1],p[2]])}A[idx1][1].push(d.length);if(!A[idx2]){A[idx2]=[l.length,[]];l.push([o[0],o[1],o[2]])}A[idx2][1].push(d.length);if(!A[idx3]){A[idx3]=[l.length,[]];l.push([n[0],n[1],n[2]])}A[idx3][1].push(d.length);if(F){G[0]=A[idx3][0];G[1]=A[idx2][0];G[2]=A[idx1][0];vec3.sub(g,o,p);vec3.sub(f,n,p);var J=[0,0,0];vec3.cross(J,f,g)}else{G[0]=A[idx1][0];G[1]=A[idx2][0];G[2]=A[idx3][0];vec3.sub(g,o,p);vec3.sub(f,n,p);var J=[0,0,0];vec3.cross(J,g,f)}d.push(G);q.push(J)}}}}return{vertices:l,faces:d,vertexIndex:A,face_normals:q}}molmil.taubinSmoothing=function(t,g,s,z,u){var o,q,x,n=[0,0,0,0],d,l;var w=[],p=[];for(x=0;x<t.length;x++){w.push({});p.push([0,0,0])}for(q=0;q<g.length;q++){w[g[q][0]][g[q][1]]=true;w[g[q][0]][g[q][2]]=true;w[g[q][1]][g[q][0]]=true;w[g[q][1]][g[q][2]]=true;w[g[q][2]][g[q][0]]=true;w[g[q][2]][g[q][1]]=true}for(x=0;x<t.length;x++){w[x]=Object.keys(w[x])}var y=function(f){for(x=0;x<t.length;x++){n[0]=0;n[1]=0;n[2]=0;n[3]=0;for(o=0;o<w[x].length;o++){d=t[w[x][o]];n[0]+=d[0];n[1]+=d[1];n[2]+=d[2];n[3]+=1}if(n[3]==0){continue}l=1/n[3];n[0]*=l;n[1]*=l;n[2]*=l;p[x][0]=t[x][0]+f*(n[0]-t[x][0]);p[x][1]=t[x][1]+f*(n[1]-t[x][1]);p[x][2]=t[x][2]+f*(n[2]-t[x][2])}};for(var h=0;h<u;h++){y(s);for(x=0;x<t.length;x++){t[x][0]=p[x][0];t[x][1]=p[x][1];t[x][2]=p[x][2]}y(z);for(x=0;x<t.length;x++){t[x][0]=p[x][0];t[x][1]=p[x][1];t[x][2]=p[x][2]}}};molmil.lighterRGB=function(l,f,g){var d=[l[0],l[1],l[2]];var h=d[0]+d[1]+d[2];var n=((255*3-h)*f)/3;d[0]+=n;d[1]+=n;d[2]+=n;d=molmil.redistributeRGB(d);if(g){return d}else{return[Math.round(d[0]),Math.round(d[1]),Math.round(d[2])]}};molmil.redistributeRGB=function(l){var h=255;var g=Math.max(Math.max(l[0],l[1]),l[2]);if(g<=h){return l}var n=l[0]+l[1]+l[2];if(n>=3*h){return[h,h,h]}var f=(3*h-n)/(3*g-n);var d=h-f*g;l[0]=d+f*l[0];l[1]=d+f*l[1];l[2]=d+f*l[2];return l};var buCheck=molmil.buCheck=function(I,H,s,C,L){L=L||molmil.cli_soup;if(!C){for(var G=0;G<L.structures.length;G++){if(L.structures[G] instanceof molmil.entryObject){C=L.structures[G];break}}}var w={};w.displayedChains={};w.COR=JSON.parse(JSON.stringify(L.COR));w.geomRanges=JSON.parse(JSON.stringify(L.geomRanges));for(var J=0;J<C.chains.length;J++){if(C.chains[J].display){w.displayedChains[C.chains[J].name]=true}}var E=L.BUassemblies[I];var l,D;var l=JSON.parse(JSON.stringify(molmil.configBox.backboneAtoms4Display));l.CA=1;var B=0,G,J,F,K,z,u=[],q,d=[0,0,0,0],o=[0,0,0],g;var n={},y;for(B,J=0;B<E.length;B++){z=[];for(G=0;G<E[B][1].length;G++){if(L.poly_asym_ids.indexOf(E[B][1][G])!=-1){z.push(E[B][1][G])}else{n[E[B][1][G]]=z}}u.push(z);for(G=0,K=0;G<E[B][0].length;G++){F=L.BUmatrices[E[B][0][G]];if(F[0]=="identity operation"){continue}K++}J+=z.length*K}var h={},x=false,A=0;for(B=0;B<E.length;B++){z=u[B];for(G=0;G<z.length;G++){no_identity=true;if(!h.hasOwnProperty(z[G])){h[z[G]]=[]}for(J=0;J<E[B][0].length;J++){F=L.BUmatrices[E[B][0][J]];if(F[0]=="identity operation"){no_identity=false;continue}h[z[G]].push(F[1])}var f=[];if((H==1&&s==1)||(H==2&&s==1)||(H==2&&s==4)){for(J=0;J<E[B][0].length;J++){F=L.BUmatrices[E[B][0][J]];if(F[0]=="identity operation"){no_identity=false;continue}f.push(F[1])}}else{if((H==3||H==4)&&s==4){for(J=0;J<E[B][0].length;J++){F=L.BUmatrices[E[B][0][J]];if(F[0]=="identity operation"){no_identity=false;continue}f.push(F[1])}}else{if((H==3||H==4||H==5)&&(s==2||s==3||s==5)){for(J=0;J<E[B][0].length;J++){F=L.BUmatrices[E[B][0][J]];if(F[0]=="identity operation"){no_identity=false;continue}f.push(F[1])}}else{for(J=0;J<E[B][0].length;J++){F=L.BUmatrices[E[B][0][J]];if(F[0]=="identity operation"){no_identity=false;continue}f.push(F[1])}}}}for(J=0;J<f.length;J++){A++}if(!no_identity){x=true}}}w.chainInfo=h;w.NOC=A;w.no_identity=!x;var t=false;for(J=0;J<C.chains.length;J++){if(n.hasOwnProperty(C.chains[J].name)){z=n[C.chains[J].name];if(z instanceof Array){K=false;for(G=0;G<z.length;G++){if(n.hasOwnProperty(z[G])){K=true;break}}if(!K){w.displayedChains[C.chains[J].name]=false;continue}}if(!w.displayedChains[C.chains[J].name]){w.displayedChains[C.chains[J].name]=true}}else{if(w.displayedChains[C.chains[J].name]){w.displayedChains[C.chains[J].name]=false}}}w.assembly_id=I;return w};molmil.toggleBU=function(ag,P,x,C,az){az=az||molmil.cli_soup;if(!C){for(var ao=0;ao<az.structures.length;ao++){if(az.structures[ao] instanceof molmil.entryObject){C=az.structures[ao];break}}}var W=az.renderer;var w=W.gl;var af=az.models;if(!az.sceneBU){az.sceneBU={};az.sceneBU.displayedChains={};az.sceneBU.COR=JSON.parse(JSON.stringify(az.COR));az.sceneBU.geomRanges=JSON.parse(JSON.stringify(az.geomRanges))}for(av=0;av<C.chains.length;av++){if(C.chains[av].display){C.chains[av].display=az.sceneBU.displayedChains[C.chains[av].name]=true}}for(var ai=0;ai<W.programs.length;ai++){if(W.programs[ai].BUprogram){W.programs.splice(ai,1);ai--}}if(ag==-1){az.COR=JSON.parse(JSON.stringify(az.sceneBU.COR));az.geomRanges=JSON.parse(JSON.stringify(az.sceneBU.geomRanges));var S=false;for(av=0;av<C.chains.length;av++){if(!C.chains[av].display){C.chains[av].display=az.sceneBU.displayedChains[C.chains[av].name]=true;S=true}}if(az.sceneBU.no_identity){az.renderer.program1.status=az.renderer.program2.status=az.renderer.program3.status=true;az.sceneBU.no_identity=false}if(S){W.initBuffers()}az.canvas.update=true;if(az.sceneBU.assembly_id!=ag){W.camera.z=az.calcZ()}az.sceneBU.assembly_id=ag;return}var R=az.BUassemblies[ag];var J,au;var J=JSON.parse(JSON.stringify(molmil.configBox.backboneAtoms4Display));J.CA=1;var T,q,am,l,M,n,Q,ae,Z;var ai=0,an,ao,av,al,ak,aw,O,o=[],U,g=[0,0,0,0],X=[0,0,0],f;var t=0;var V={},ax;for(ai,av=0;ai<R.length;ai++){O=[];for(ao=0;ao<R[ai][1].length;ao++){if(az.poly_asym_ids.indexOf(R[ai][1][ao])!=-1){O.push(R[ai][1][ao])}else{V[R[ai][1][ao]]=O}}o.push(O);for(ao=0,aw=0;ao<R[ai][0].length;ao++){al=az.BUmatrices[R[ai][0][ao]];if(al[0]=="identity operation"){continue}aw++}t+=aw;av+=O.length*aw}var ab=[],G=true,h;if(x==2){aw=(o[0]||[]).length}else{if(x==3){aw=av}else{if(x instanceof Array){ab=x;if(!(ab[0] instanceof Array)){ab=[ab]}x=5;aw=0}}}for(ao=0,al=0;ao<aw;ao++,al++){if(al>=molmil.configBox.bu_colors.length){al=0}if(P==5){ab.push(molmil.lighterRGB(molmil.configBox.bu_colors[al],0.5))}else{ab.push(molmil.configBox.bu_colors[al])}}var ar=1e+99,L=-1e+99,E=1e+99,aj=-1e+99,ad=1e+99,u=-1e+99,z=[0,0,0],y=[0,0,0];var K={},Y=false,N=0,aa;for(ai=0,an=0;ai<R.length;ai++){O=o[ai];for(ao=0;ao<O.length;ao++){aa=null;G=true;if(!K.hasOwnProperty(O[ao])){K[O[ao]]=[]}if(az.BUcache.hasOwnProperty(O[ao])&&az.BUcache[O[ao]].hasOwnProperty(P)){av=az.BUcache[O[ao]][P];ae=av[0];Z=av[1];U=av[2];ax=av[3];aa=av[4]}else{if(P==3||P==4){var I=[],ac=[],ah,D,s=[];var ay=2;if(P==4){ay=3}U=[0,0,0,0];z[0]=z[1]=z[2]=1e+99;y[0]=y[1]=y[2]=-1e+99;for(av=0;av<C.chains.length;av++){if(C.chains[av].molecules.length<1||C.chains[av].isHet||C.chains[av].molecules[0].water){continue}if(C.chains[av].name!=O[ao]){continue}s.push(C.chains[av]);I.push(C.chains[av].displayMode);C.chains[av].displayMode=ay;ac.push(ah=[]);for(al=0;al<C.chains[av].molecules.length;al++){ah.push(C.chains[av].molecules[al].rgba);C.chains[av].molecules[al].rgba=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,C.chains[av].molecules[al].sndStruc,molmil.configBox.sndStrucColor[1]);if(C.chains[av].molecules[al].CA){D=C.chains[av].molecules[al].CA.xyz;U[0]+=C.chains[av].modelsXYZ[0][D];U[1]+=C.chains[av].modelsXYZ[0][D+1];U[2]+=C.chains[av].modelsXYZ[0][D+2];U[3]+=1;if(C.chains[av].modelsXYZ[0][D]<z[0]){z[0]=C.chains[av].modelsXYZ[0][D]}if(C.chains[av].modelsXYZ[0][D+1]<z[1]){z[1]=C.chains[av].modelsXYZ[0][D+1]}if(C.chains[av].modelsXYZ[0][D+2]<z[2]){z[2]=C.chains[av].modelsXYZ[0][D+2]}if(C.chains[av].modelsXYZ[0][D]>y[0]){y[0]=C.chains[av].modelsXYZ[0][D]}if(C.chains[av].modelsXYZ[0][D+1]>y[1]){y[1]=C.chains[av].modelsXYZ[0][D+1]}if(C.chains[av].modelsXYZ[0][D+2]>y[2]){y[2]=C.chains[av].modelsXYZ[0][D+2]}}}}U[0]/=U[3];U[1]/=U[3];U[2]/=U[3];molmil.geometry.reset();h=0;if(t>10){h--}if(t>100){h--}if(t>1000){h--}molmil.geometry.initChains(s,W,h);molmil.geometry.initCartoon(s);molmil.geometry.generateCartoon(s);ae=w.createBuffer();w.bindBuffer(w.ARRAY_BUFFER,ae);w.bufferData(w.ARRAY_BUFFER,molmil.geometry.buffer3.vertexBuffer,w.STATIC_DRAW);Z=w.createBuffer();w.bindBuffer(w.ELEMENT_ARRAY_BUFFER,Z);w.bufferData(w.ELEMENT_ARRAY_BUFFER,molmil.geometry.buffer3.indexBuffer,w.STATIC_DRAW);if(!az.BUcache.hasOwnProperty(O[ao])){az.BUcache[O[ao]]={}}az.BUcache[O[ao]][P]=[ae,Z,U,ax=molmil.geometry.buffer3.indexBuffer.length,[]];for(av=0;av<s.length;av++){s[av].displayMode=I[av];for(al=0;al<s[av].molecules.length;al++){s[av].molecules[al].rgba=ac[av][al]}}molmil.geometry.reset()}else{if(P==5){var H;for(av=0;av<C.chains.length;av++){if(C.chains[av].molecules.length<1||C.chains[av].isHet||C.chains[av].molecules[0].water){continue}if(C.chains[av].name!=O[ao]){continue}H=molmil.coarseSurface(C.chains[av],7.5,7.5*0.75,{deproj:true});l=new Float32Array(H.vertices.length*8);M=new Uint8Array(l.buffer);if(molmil.configBox.OES_element_index_uint){n=new Uint32Array(H.faces.length*3)}else{n=new Uint16Array(H.faces.length*3)}U=[0,0,0,0];z[0]=z[1]=z[2]=1e+99;y[0]=y[1]=y[2]=-1e+99;for(av=0,al=0,ak=0;av<H.vertices.length;av++,ak+=32){l[al++]=H.vertices[av][0];l[al++]=H.vertices[av][1];l[al++]=H.vertices[av][2];U[0]+=H.vertices[av][0];U[1]+=H.vertices[av][1];U[2]+=H.vertices[av][2];U[3]+=1;if(H.vertices[av][0]<z[0]){z[0]=H.vertices[av][0]}if(H.vertices[av][1]<z[1]){z[1]=H.vertices[av][1]}if(H.vertices[av][2]<z[2]){z[2]=H.vertices[av][2]}if(H.vertices[av][0]>y[0]){y[0]=H.vertices[av][0]}if(H.vertices[av][1]>y[1]){y[1]=H.vertices[av][1]}if(H.vertices[av][2]>y[2]){y[2]=H.vertices[av][2]}l[al++]=H.normals[av][0];l[al++]=H.normals[av][1];l[al++]=H.normals[av][2];al++;al++}U[0]/=U[3];U[1]/=U[3];U[2]/=U[3];for(av=0,al=0;av<H.faces.length;av++){n[al++]=H.faces[av][0];n[al++]=H.faces[av][1];n[al++]=H.faces[av][2]}ae=w.createBuffer();w.bindBuffer(w.ARRAY_BUFFER,ae);w.bufferData(w.ARRAY_BUFFER,l,w.STATIC_DRAW);Z=w.createBuffer();w.bindBuffer(w.ELEMENT_ARRAY_BUFFER,Z);w.bufferData(w.ELEMENT_ARRAY_BUFFER,n,w.STATIC_DRAW);if(!az.BUcache.hasOwnProperty(O[ao])){az.BUcache[O[ao]]={}}az.BUcache[O[ao]][P]=[ae,Z,U,ax=H.faces.length*3,[]]}}else{T=[];q={};if(P==1){for(av=0;av<C.chains.length;av++){au=C.chains[av];if(!au.bondsOK){W.soup.buildBondList(au,false)}for(aw=0;aw<au.bonds.length;aw++){if(J.hasOwnProperty(au.bonds[aw][0].atomName)&&J.hasOwnProperty(au.bonds[aw][1].atomName)&&au.bonds[aw][0].molecule.chain.name==O[ao]&&au.bonds[aw][1].molecule.chain.name==O[ao]){T.push(au.bonds[aw]);q[au.bonds[aw][0].AID]=au.bonds[aw][0];q[au.bonds[aw][1].AID]=au.bonds[aw][1]}}}}else{if(P==2){for(av=0;av<C.chains.length;av++){au=C.chains[av];for(al=0;al<au.molecules.length;al++){if(au.molecules[al].CA&&au.molecules[al].next&&au.molecules[al].chain.name==O[ao]){T.push([au.molecules[al].CA,au.molecules[al].next.CA]);q[au.molecules[al].CA.AID]=au.molecules[al].CA;q[au.molecules[al].next.CA.AID]=au.molecules[al].next.CA}}}}}AIDs=Object.keys(q);Q={};l=new Float32Array((AIDs.length)*5);M=new Uint8Array(l.buffer);if(molmil.configBox.OES_element_index_uint){n=new Uint32Array(T.length*2)}else{n=new Uint16Array(T.length*2)}U=[0,0,0,0];z[0]=z[1]=z[2]=1e+99;y[0]=y[1]=y[2]=-1e+99;if(P==2&&x==4){for(av=0,al=0,ak=0;av<AIDs.length;av++,ak+=20){f=q[AIDs[av]];au=f.chain;l[al++]=au.modelsXYZ[0][f.xyz];l[al++]=au.modelsXYZ[0][f.xyz+1];l[al++]=au.modelsXYZ[0][f.xyz+2];U[0]+=l[al-3];U[1]+=l[al-2];U[2]+=l[al-1];if(l[al-3]<z[0]){z[0]=l[al-3]}if(l[al-2]<z[1]){z[1]=l[al-2]}if(l[al-1]<z[2]){z[2]=l[al-1]}if(l[al-3]>y[0]){y[0]=l[al-3]}if(l[al-2]>y[1]){y[1]=l[al-2]}if(l[al-1]>y[2]){y[2]=l[al-1]}am=molmil_dep.getKeyFromObject(molmil.configBox.sndStrucColor,q[AIDs[av]].molecule.sndStruc,molmil.configBox.sndStrucColor[1]);M[ak+12]=am[0];M[ak+13]=am[1];M[ak+14]=am[2];M[ak+15]=am[3];al++;l[al++]=AIDs[av];Q[AIDs[av]]=av}}else{for(av=0,al=0,ak=0;av<AIDs.length;av++,ak+=20){f=q[AIDs[av]];au=f.chain;l[al++]=au.modelsXYZ[0][f.xyz];l[al++]=au.modelsXYZ[0][f.xyz+1];l[al++]=au.modelsXYZ[0][f.xyz+2];U[0]+=l[al-3];U[1]+=l[al-2];U[2]+=l[al-1];if(l[al-3]<z[0]){z[0]=l[al-3]}if(l[al-2]<z[1]){z[1]=l[al-2]}if(l[al-1]<z[2]){z[2]=l[al-1]}if(l[al-3]>y[0]){y[0]=l[al-3]}if(l[al-2]>y[1]){y[1]=l[al-2]}if(l[al-1]>y[2]){y[2]=l[al-1]}am=molmil_dep.getKeyFromObject(molmil.configBox.elementColors,q[AIDs[av]].element,molmil.configBox.elementColors.DUMMY);M[ak+12]=am[0];M[ak+13]=am[1];M[ak+14]=am[2];M[ak+15]=am[3];al++;l[al++]=AIDs[av];Q[AIDs[av]]=av}}U[0]/=AIDs.length;U[1]/=AIDs.length;U[2]/=AIDs.length;U[3]=AIDs.length;for(av=0,al=0;av<T.length;av++){n[al++]=Q[T[av][0].AID];n[al++]=Q[T[av][1].AID]}ae=w.createBuffer();w.bindBuffer(w.ARRAY_BUFFER,ae);w.bufferData(w.ARRAY_BUFFER,l,w.STATIC_DRAW);Z=w.createBuffer();w.bindBuffer(w.ELEMENT_ARRAY_BUFFER,Z);w.bufferData(w.ELEMENT_ARRAY_BUFFER,n,w.STATIC_DRAW);if(!az.BUcache.hasOwnProperty(O[ao])){az.BUcache[O[ao]]={}}az.BUcache[O[ao]][P]=[ae,Z,U,ax=n.length,[]]}}}for(av=0;av<R[ai][0].length;av++){al=az.BUmatrices[R[ai][0][av]];if(al[0]=="identity operation"){G=false;continue}K[O[ao]].push(al[1])}var ap={multiMatrix:true},aq=[],F=[];if((P==1&&x==1)||(P==2&&x==1)||(P==2&&x==4)){for(av=0;av<R[ai][0].length;av++){al=az.BUmatrices[R[ai][0][av]];if(al[0]=="identity operation"){G=false;continue}aq.push(al[1])}ap.has_ID=true;ap.lines_render=true}else{if((P==3||P==4)&&x==4){for(av=0;av<R[ai][0].length;av++){al=az.BUmatrices[R[ai][0][av]];if(al[0]=="identity operation"){G=false;continue}aq.push(al[1])}ap.solid=true;ap.has_ID=true}else{if((P==3||P==4||P==5)&&(x==2||x==3||x==5)){F=[];for(av=0;av<R[ai][0].length;av++){al=az.BUmatrices[R[ai][0][av]];if(al[0]=="identity operation"){G=false;continue}aq.push(al[1]);if(x==2){F.push(ab[ao]||[255,255,255])}else{if(x==3){F.push(ab[an++]||[255,255,255])}else{if(x==5){F.push(ab[an++]||[255,255,255])}}}if(an>=ab.length){an=0}}ap.solid=true;ap.uniform_color=true;ap.has_ID=true}else{F=[];for(av=0;av<R[ai][0].length;av++){al=az.BUmatrices[R[ai][0][av]];if(al[0]=="identity operation"){G=false;continue}aq.push(al[1]);if(x==2){F.push(ab[ao])}else{if(x==3){F.push(ab[an++])}else{if(x==5){F.push(ab[an++]||[255,255,255])}}}if(an>=ab.length){an=0}}ap.lines_render=true;ap.uniform_color=true;ap.has_ID=true}}}var d=molmil.geometry.build_simple_render_program(null,null,W,ap);d.vertexBuffer=ae;d.indexBuffer=Z;d.nElements=ax;d.BUprogram=true;d.matrices=aq;d.uniform_color=F;if(d.matrices.length){W.programs.push(d)}if(aa){z=aa[0];y=aa[1]}else{try{az.BUcache[O[ao]][P][4]=[[z[0],z[1],z[2]],[y[0],y[1],y[2]]]}catch(at){}}if(!G){if(U[3]!=0){g[0]+=U[0];g[1]+=U[1];g[2]+=U[2];g[3]+=1;if(z[0]<ar){ar=z[0]}if(z[1]<E){E=z[1]}if(z[2]<ad){ad=z[2]}if(y[0]>L){L=y[0]}if(y[1]>aj){aj=y[1]}if(y[2]>u){u=y[2]}}V[O[ao]]=1}for(av=0;av<d.matrices.length;av++){if(U[3]==0){continue}vec3.transformMat4(X,U,d.matrices[av]);g[0]+=X[0];g[1]+=X[1];g[2]+=X[2];g[3]+=1;vec3.transformMat4(X,z,d.matrices[av]);if(X[0]<ar){ar=X[0]}if(X[1]<E){E=X[1]}if(X[2]<ad){ad=X[2]}vec3.transformMat4(X,y,d.matrices[av]);if(X[0]>L){L=X[0]}if(X[1]>aj){aj=X[1]}if(X[2]>u){u=X[2]}N++}if(!G){Y=true}}}if(g[3]){g[0]/=g[3];g[1]/=g[3];g[2]/=g[3]}az.COR[0]=g[0];az.COR[1]=g[1];az.COR[2]=g[2];az.sceneBU.chainInfo=K;az.sceneBU.NOC=N;if(!Y){az.renderer.program1.status=az.renderer.program2.status=az.renderer.program3.status=false}else{az.renderer.program1.status=az.renderer.program2.status=az.renderer.program3.status=true}az.sceneBU.no_identity=!Y;var S=false;for(av=0;av<C.chains.length;av++){if(V.hasOwnProperty(C.chains[av].name)){O=V[C.chains[av].name];if(O instanceof Array){aw=false;for(ao=0;ao<O.length;ao++){if(V.hasOwnProperty(O[ao])){aw=true;break}}if(!aw){C.chains[av].display=az.sceneBU.displayedChains[C.chains[av].name]=false;S=true;continue}}if(!C.chains[av].display){C.chains[av].display=az.sceneBU.displayedChains[C.chains[av].name]=true;S=true}}else{if(C.chains[av].display){C.chains[av].display=az.sceneBU.displayedChains[C.chains[av].name]=false;S=true}}}for(av=0;av<C.chains.length;av++){if(C.chains[av].display&&C.chains[av].isHet){for(ao=0;ao<C.chains[av].atoms.length;ao++){if(!C.chains[av].atoms[ao].display){continue}aw=C.chains[av].atoms[ao].xyz;if(C.chains[av].modelsXYZ[0][aw]<ar){ar=C.chains[av].modelsXYZ[0][aw]}if(C.chains[av].modelsXYZ[0][aw+1]<E){E=C.chains[av].modelsXYZ[0][aw+1]}if(C.chains[av].modelsXYZ[0][aw+2]<ad){ad=C.chains[av].modelsXYZ[0][aw+2]}if(C.chains[av].modelsXYZ[0][aw]>L){L=C.chains[av].modelsXYZ[0][aw]}if(C.chains[av].modelsXYZ[0][aw+1]>aj){aj=C.chains[av].modelsXYZ[0][aw+1]}if(C.chains[av].modelsXYZ[0][aw+2]>u){u=C.chains[av].modelsXYZ[0][aw+2]}}}}if(ar<1000000000){az.geomRanges=[ar-g[0],L-g[0],E-g[1],aj-g[1],ad-g[2],u-g[2]]}if(g[3]==0){az.COR=JSON.parse(JSON.stringify(az.sceneBU.COR));az.geomRanges=JSON.parse(JSON.stringify(az.sceneBU.geomRanges))}if(S||!W.initBD){W.initBuffers()}if(az.sceneBU.assembly_id!=ag){W.camera.z=az.calcZ()}az.sceneBU.assembly_id=ag;az.canvas.update=true};molmil.findContacts=function(h,g,d,q){var s=q.renderer.modelId,o,n,p,l,y,x,w,f=d*d,u={};for(p=0;p<h.length;p++){o=[h[p].chain.modelsXYZ[s][h[p].xyz],h[p].chain.modelsXYZ[s][h[p].xyz+1],h[p].chain.modelsXYZ[s][h[p].xyz+2]];for(l=0;l<g.length;l++){n=[g[l].chain.modelsXYZ[s][g[l].xyz],g[l].chain.modelsXYZ[s][g[l].xyz+1],g[l].chain.modelsXYZ[s][g[l].xyz+2]];y=o[0]-n[0];x=o[1]-n[1];w=o[2]-n[2];if(y*y+x*x+w*w<f){u[g[l].AID]=g[l]}}}var t=[];for(p in u){t.push(u[p])}return t};molmil.calcHbonds=function(o,n,B){if(!(o instanceof Array)){o=[o]}if(!(n instanceof Array)){n=[n]}var g=[],f=[],l=[],h=[];var w,u,t,x,z,s={},y={};var q=function(D,E){for(x=0;x<D.atoms.length;x++){if(D.atoms[x].element=="O"&&y[D.atoms[x].AID]<3){E.push(D.atoms[x])}else{if(D.atoms[x].element=="N"&&y[D.atoms[x].AID]<4){E.push(D.atoms[x])}}}};var p=function(D,E){for(x=0;x<D.atoms.length;x++){if((D.atoms[x].element=="O"||(D.atoms[x].element=="N"&&y[D.atoms[x].AID]>2))&&s[D.atoms[x].AID]){for(z=0;z<s[D.atoms[x].AID].length;z++){E.push([D.atoms[x],s[D.atoms[x].AID][z]])}}}};for(w=0;w<o.length;w++){if(!o[w].bondsOK){B.buildBondList(o[w],false)}for(x=0;x<o[w].atoms.length;x++){y[o[w].atoms[x].AID]=0}for(x=0;x<o[w].bonds.length;x++){if(o[w].bonds[x][0].element=="H"){if(!s[o[w].bonds[x][1].AID]){s[o[w].bonds[x][1].AID]=[]}s[o[w].bonds[x][1].AID].push(o[w].bonds[x][0])}if(o[w].bonds[x][1].element=="H"){if(!s[o[w].bonds[x][0].AID]){s[o[w].bonds[x][0].AID]=[]}s[o[w].bonds[x][0].AID].push(o[w].bonds[x][1])}y[o[w].bonds[x][0].AID]++;y[o[w].bonds[x][1].AID]++}q(o[w],g);p(o[w],l)}for(w=0;w<n.length;w++){if(!n[w].bondsOK){B.buildBondList(n[w],false)}for(x=0;x<n[w].atoms.length;x++){y[n[w].atoms[x].AID]=0}for(x=0;x<n[w].bonds.length;x++){if(n[w].bonds[x][0].element=="H"){if(!s[n[w].bonds[x][1].AID]){s[n[w].bonds[x][1].AID]=[]}s[n[w].bonds[x][1].AID].push(n[w].bonds[x][0])}if(n[w].bonds[x][1].element=="H"){if(!s[n[w].bonds[x][0].AID]){s[n[w].bonds[x][0].AID]=[]}s[n[w].bonds[x][0].AID].push(n[w].bonds[x][1])}y[n[w].bonds[x][0].AID]++;y[n[w].bonds[x][1].AID]++}q(n[w],f);p(n[w],h)}var C=[];for(u=0;u<g.length;u++){for(t=0;t<h.length;t++){r=molmil.calcMMDistance(g[u],h[t][0],B);if(r<3.25){theta=molmil.calcMMAngle(g[u],h[t][1],h[t][0],B);if(Math.abs(theta-180)<30){C.push([g[u],h[t][1]])}}}}for(u=0;u<f.length;u++){for(t=0;t<l.length;t++){r=molmil.calcMMDistance(f[u],l[t][0],B);if(r<3.25){theta=molmil.calcMMAngle(f[u],l[t][1],l[t][0],B);if(Math.abs(theta-180)<30){C.push([f[u],l[t][1]])}}}}var d=[],A;for(u=0;u<C.length;u++){d.push({type:"cylinder",coords:[molmil.getAtomXYZ(C[u][0],B),molmil.getAtomXYZ(C[u][1],B)],rgba:[255,255,0,255],radius:0.05})}molmil.geometry.generator(d,B,"Hydrogen bonds",{solid:true});return C};molmil.hslToRgb123=function(u,y,t){var d,w,x;if(y==0){d=w=x=t}else{function o(l,h,g){if(g<0){g+=1}if(g>1){g-=1}if(g<1/6){return l+(h-l)*6*g}if(g<1/2){return h}if(g<2/3){return l+(h-l)*(2/3-g)*6}return l}var f=t<0.5?t*(1+y):t+y-t*y;var n=2*t-f;d=o(n,f,u+1/3);w=o(n,f,u);x=o(n,f,u-1/3)}return[d,w,x]};molmil.getAtomXYZ=function(f,d){var g=d.renderer.modelId;return[f.chain.modelsXYZ[g][f.xyz],f.chain.modelsXYZ[g][f.xyz+1],f.chain.modelsXYZ[g][f.xyz+2]]};molmil.calcMMDistance=function(f,d,g){var o=g.renderer.modelId,n,l;n=[f.chain.modelsXYZ[o][f.xyz],f.chain.modelsXYZ[o][f.xyz+1],f.chain.modelsXYZ[o][f.xyz+2]];l=[d.chain.modelsXYZ[o][d.xyz],d.chain.modelsXYZ[o][d.xyz+1],d.chain.modelsXYZ[o][d.xyz+2]];try{return vec3.distance(n,l)}catch(h){return NaN}};molmil.calcMMAngle=function(h,g,f,p){var u=p.renderer.modelId,o,n,l;o=[h.chain.modelsXYZ[u][h.xyz],h.chain.modelsXYZ[u][h.xyz+1],h.chain.modelsXYZ[u][h.xyz+2]];n=[g.chain.modelsXYZ[u][g.xyz],g.chain.modelsXYZ[u][g.xyz+1],g.chain.modelsXYZ[u][g.xyz+2]];l=[f.chain.modelsXYZ[u][f.xyz],f.chain.modelsXYZ[u][f.xyz+1],f.chain.modelsXYZ[u][f.xyz+2]];var d=180/Math.PI,t=[0,0,0],s=[0,0,0];try{vec3.subtract(t,o,n);vec3.normalize(t,t);vec3.subtract(s,l,n);vec3.normalize(s,s);return Math.acos(vec3.dot(t,s))*d}catch(q){return NaN}};molmil.calcMMTorsion=function(G,D,C,B,F){var h=F.renderer.modelId,n,g,f,d;n=[G.chain.modelsXYZ[h][G.xyz],G.chain.modelsXYZ[h][G.xyz+1],G.chain.modelsXYZ[h][G.xyz+2]];g=[D.chain.modelsXYZ[h][D.xyz],D.chain.modelsXYZ[h][D.xyz+1],D.chain.modelsXYZ[h][D.xyz+2]];f=[C.chain.modelsXYZ[h][C.xyz],C.chain.modelsXYZ[h][C.xyz+1],C.chain.modelsXYZ[h][C.xyz+2]];d=[B.chain.modelsXYZ[h][B.xyz],B.chain.modelsXYZ[h][B.xyz+1],B.chain.modelsXYZ[h][B.xyz+2]];var E=180/Math.PI,p=[0,0,0],o=[0,0,0],l=[0,0,0],u=[0,0,0],t=[0,0,0],s,q,A=[0,0,0];try{vec3.subtract(p,g,n);vec3.negate(p,p);vec3.subtract(o,f,g);vec3.normalize(o,o);vec3.subtract(l,d,f);vec3.subtract(u,p,vec3.scale(A,o,vec3.dot(p,o)));vec3.subtract(t,l,vec3.scale(A,o,vec3.dot(l,o)));s=vec3.dot(u,t);q=vec3.dot(vec3.cross(A,o,u),t);return Math.atan2(q,s)*E}catch(z){return NaN}};molmil.calculateBBTorsions=function(g,f){if(g.molecules.length<2){return}for(var d=1;d<g.molecules.length-1;d++){g.molecules[d].phiAngle=molmil.calcMMTorsion(g.molecules[d-1].C,g.molecules[d].N,g.molecules[d].CA,g.molecules[d].C,f);g.molecules[d].psiAngle=molmil.calcMMTorsion(g.molecules[d].N,g.molecules[d].CA,g.molecules[d].C,g.molecules[d+1].N,f);g.molecules[d].omegaAngle=molmil.calcMMTorsion(g.molecules[d-1].CA,g.molecules[d-1].C,g.molecules[d].N,g.molecules[d].CA,f)}g.molecules[0].psiAngle=molmil.calcMMTorsion(g.molecules[0].N,g.molecules[0].CA,g.molecules[0].C,g.molecules[1].N,f);g.molecules[d].phiAngle=molmil.calcMMTorsion(g.molecules[d-1].C,g.molecules[d].N,g.molecules[d].CA,g.molecules[d].C,f);g.molecules[d].omegaAngle=molmil.calcMMTorsion(g.molecules[d-1].CA,g.molecules[d-1].C,g.molecules[d].N,g.molecules[d].CA,f);g.molecules[0].phiAngle=g.molecules[1].phiAngle;g.molecules[d].psiAngle=g.molecules[d-1].psiAngle;g.molecules[0].omegaAngle=g.molecules[1].omegaAngle};molmil.linkCanvases=function(f){for(var d=1;d<f.length;d++){f[d].renderer.camera=f[0].renderer.camera}for(var d=0;d<f.length;d++){f[d].molmilViewer.canvases=f}};molmil.__webglNotSupported__=function(d){if(window.webglNotSupported){return webglNotSupported(d)}var f=molmil_dep.dcE("DIV");f.innerHTML='Your browser does not seem to support WebGL. Please visit the <a target="blank" class="external" href="http://get.webgl.org/">WebGL website</a> for more info on how to gain WebGL support on your browser.<br />';f.style.border="1px solid #ddd";f.style.margin=f.style.padding=".25em";d.parentNode.replaceChild(f,d);return f};molmil.calcRMSD=function(t,s,H){if(t.length!=s.length){console.log("ERROR: both structures should have the same number of atoms");return}var g=0,f=0,J=0,I=0,x=0,w=0,d=t.length,X,T;if(t instanceof Float32Array){X=t;T=s;d/=3;for(var V=0,Q=0;V<d;V++,Q+=3){g+=X[Q];J+=X[Q+1];x+=X[Q+2];f+=T[Q];I+=T[Q+1];w+=T[Q+2]}}else{X=new Float32Array(d*3);T=new Float32Array(d*3);for(var V=0,Q=0;V<d;V++,Q+=3){X[Q]=t[V].xyz[0];X[Q+1]=t[V].xyz[1];X[Q+2]=t[V].xyz[2];T[Q]=s[V].xyz[0];T[Q+1]=s[V].xyz[1];T[Q+2]=s[V].xyz[2];g+=X[Q];J+=X[Q+1];x+=X[Q+2];f+=T[Q];I+=T[Q+1];w+=T[Q+2]}}var U=0,z=0;g/=d;J/=d;x/=d;f/=d;I/=d;w/=d;for(var V=0,Q=0;V<d;V++,Q+=3){X[Q]-=g;X[Q+1]-=J;X[Q+2]-=x;T[Q]-=f;T[Q+1]-=I;T[Q+2]-=w;U+=X[Q]*X[Q]+X[Q+1]*X[Q+1]+X[Q+2]*X[Q+2];z+=T[Q]*T[Q]+T[Q+1]*T[Q+1]+T[Q+2]*T[Q+2]}var p=new Float64Array(9);for(var V=0;V<d*3;V+=3){p[0]+=X[V]*T[V];p[1]+=X[V]*T[V+1];p[2]+=X[V]*T[V+2];p[3]+=X[V+1]*T[V];p[4]+=X[V+1]*T[V+1];p[5]+=X[V+1]*T[V+2];p[6]+=X[V+2]*T[V];p[7]+=X[V+2]*T[V+1];p[8]+=X[V+2]*T[V+2]}var o=new Float64Array(16);o[0]=p[0]+p[4]+p[8];o[5]=p[0]-p[4]-p[8];o[10]=-p[0]+p[4]-p[8];o[15]=-p[0]-p[4]+p[8];o[1]=o[4]=p[5]-p[7];o[2]=o[8]=p[6]-p[2];o[3]=o[12]=p[1]-p[3];o[6]=o[9]=p[1]+p[3];o[7]=o[13]=p[2]+p[6];o[11]=o[14]=p[5]+p[7];var P=[1,1,1,1];var W=molmil.EVpowerMethod(P,o);vec4.negate(P,P);var F=[Math.sqrt(Math.max(0,(U+z)-(2*W))/d)];if(H){var G=2*P[0],E=2*P[1],D=2*P[2],C=2*P[3];var O=G*P[0]-1,M=G*P[1],L=G*P[2],K=G*P[3],B=E*P[1],A=E*P[2],y=E*P[3],l=D*P[2],h=D*P[3],N=C*P[3];var u=new Float64Array(16);u[0]=O+B;u[1]=A-K;u[2]=y+L;u[4]=A+K;u[5]=O+l;u[6]=h-M;u[8]=y-L;u[9]=h+M;u[10]=O+N;u[15]=1;F.push(u,[g,J,x],[f,I,w])}return F};molmil.EVpowerMethod=function(l,d,o){o=o||10000;var h=1e-9,n=0,f=0,g=0,p=new Float64Array(4);g=Math.sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]+l[3]*l[3]);l[0]/=g;l[1]/=g;l[2]/=g;l[3]/=g;while(n<=o){vec4.transformMat4(p,l,d);g=Math.sqrt(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]+p[3]*p[3]);l[0]=p[0]/g;l[1]=p[1]/g;l[2]=p[2]/g;l[3]=p[3]/g;if(Math.abs((g-f)/g)<h){return g}f=g;n++}return null};molmil.invertColor=function(d){return"#"+("000000"+(16777215^parseInt(d.substring(1),16)).toString(16)).slice(-6)};molmil.componentToHex=function(f){var d=f.toString(16);return d.length==1?"0"+d:d};molmil.rgbToHex=function(h,f,d){return"#"+molmil.componentToHex(h)+molmil.componentToHex(f)+molmil.componentToHex(d)};molmil.hex2rgb=function(d){d=(d.charAt(0)=="#"?d.substr(1,7):d);return[parseInt(d.substring(0,2),16),parseInt(d.substring(2,4),16),parseInt(d.substring(4,6),16)]};molmil.commandLines={};molmil.commandLine=function(canvas){this.environment={};for(var e in window){this.environment[e]=undefined}this.environment.setTimeout=function(cb,tm){window.setTimeout(cb,tm)};this.environment.clearTimeout=function(){window.clearTimeout()};this.environment.navigator=window.navigator;this.environment.window=this;this.environment.console={};this.environment.molmil=molmil;this.environment.molmil_dep=molmil_dep;this.canvas=this.environment.cli_canvas=canvas;this.soup=this.environment.cli_soup=canvas.molmilViewer;canvas.commandLine=this;this.buildGUI();this.environment.console.log=function(){if(this.debugMode){console.log.apply(console,arguments)}arguments=Array.prototype.slice.call(arguments,0);var tmp=document.createElement("div");tmp.textContent=arguments.join(", ");this.custom(tmp)};this.environment.console.warning=function(){if(this.debugMode){console.warming.apply(console,arguments)}arguments=Array.prototype.slice.call(arguments,0);var tmp=document.createElement("div");tmp.textContent=arguments.join(", ");tmp.style.color="yellow";this.custom(tmp)};this.environment.console.error=function(){if(this.debugMode){console.error.apply(console,arguments)}arguments=Array.prototype.slice.call(arguments,0);var tmp=document.createElement("div");tmp.textContent=arguments.join(", ");tmp.style.color="red";this.custom(tmp)};this.environment.console.logCommand=function(){if(this.cli.environment.scriptUrl){return}arguments=Array.prototype.slice.call(arguments,0);var tmp=document.createElement("div");tmp.textContent=arguments.join("\n");tmp.style.color="#00BFFF";this.custom(tmp,true)};this.environment.console.custom=function(obj,noPopup){if(!obj.textContent){return}this.logBox.appendChild(obj);this.logBox.scrollTop=this.logBox.scrollHeight;if(noPopup!=true){this.logBox.icon.onclick(true)}};this.environment.console.runCommand=function(command){if(!molmil.isBalancedStatement(command)){return}if(command.indexOf("{")==-1&&command.indexOf(";")!=-1){var sub_commands=command.split(";");for(var i=0;i<sub_commands.length;i++){sub_commands[i]=sub_commands[i].trim();this.logCommand(sub_commands[i]);this.cli.eval(sub_commands[i]);this.backlog.unshift(sub_commands[i])}}else{command=command.trim();this.logCommand(command);this.cli.eval(command);this.backlog.unshift(command)}this.buffer="";this.blSel=-1};this.environment.console.backlog=[];this.environment.console.buffer="";this.environment.console.blSel=-1;this.environment.console.logBox=this.logBox;this.environment.console.cli=this;this.environment.colors={red:[255,0,0,255],green:[0,255,0,255],blue:[0,0,255,255],grey:[100,100,100,255]};this.bindPymolInterface();this.icon.onclick();this.icon.onclick()};molmil.commandLine.prototype.buildGUI=function(){this.consoleBox=this.canvas.parentNode.pushNode("span");this.consoleBox.className="molmil_UI_cl_box";this.consoleBox.style.overflow="initial";this.logBox=this.consoleBox.pushNode("span");this.logBox.icon=this.icon=this.consoleBox.pushNode("span");this.icon.innerHTML="<";this.icon.title="Display command line";this.icon.className="molmil_UI_cl_icon";this.icon.style.color=molmil.invertColor(molmil.rgbToHex(molmil.configBox.BGCOLOR[0]*255,molmil.configBox.BGCOLOR[1]*255,molmil.configBox.BGCOLOR[2]*255));this.icon.onclick=function(d){if(d==true){if(this.inp.style.display!=""){this.cli.logBox.style.display="";this.cli.consoleBox.style.height="8em";this.cli.logBox.style.pointerEvents="none";this.cli.logBox.style.overflow="hidden";var f=molmil.invertColor(molmil.rgbToHex(molmil.configBox.BGCOLOR[0]*255,molmil.configBox.BGCOLOR[1]*255,molmil.configBox.BGCOLOR[2]*255));this.cli.consoleBox.style.color=f;this.logBox.scrollTop=this.logBox.scrollHeight}return}if(this.inp.style.display==""){this.innerHTML="<";this.title="Display command line";this.inp.style.display="none";this.cli.logBox.style.display="none"}else{this.innerHTML=">";this.title="Hide command line";var f=molmil.invertColor(molmil.rgbToHex(molmil.configBox.BGCOLOR[0]*255,molmil.configBox.BGCOLOR[1]*255,molmil.configBox.BGCOLOR[2]*255));this.cli.logBox.style.border="1px solid "+f;this.cli.logBox.style.borderBottom="";this.cli.logBox.style.borderRadius=".33em";this.cli.consoleBox.style.color=f;this.cli.logBox.style.backgroundColor="rgba("+molmil.configBox.BGCOLOR[0]*255+","+molmil.configBox.BGCOLOR[1]*255+","+molmil.configBox.BGCOLOR[2]*255+",.5)";this.inp.style.backgroundColor="rgb("+molmil.configBox.BGCOLOR[0]*255+","+molmil.configBox.BGCOLOR[1]*255+","+molmil.configBox.BGCOLOR[2]*255+")";this.inp.style.display="";this.cli.logBox.style.display="";this.cli.consoleBox.style.height=this.cli.consoleBox.style.maxHeight="calc("+this.cli.canvas.clientHeight+"px - 6em)";this.cli.consoleBox.style.overflow="";this.cli.logBox.style.pointerEvents="";this.inp.focus()}};this.logBox.onmouseover=function(){this.style.backgroundColor="rgba("+molmil.configBox.BGCOLOR[0]*255+","+molmil.configBox.BGCOLOR[1]*255+","+molmil.configBox.BGCOLOR[2]*255+",.85)"};this.logBox.onmouseout=function(){this.style.backgroundColor="rgba("+molmil.configBox.BGCOLOR[0]*255+","+molmil.configBox.BGCOLOR[1]*255+","+molmil.configBox.BGCOLOR[2]*255+",.25)"};this.inp=this.icon.inp=this.consoleBox.pushNode("span");this.inp.className="molmil_UI_cl_input";this.inp.style.display="none";this.inp.contentEditable=true;this.inp.cli=this.icon.cli=this;this.icon.logBox=this.inp.logBox=this.logBox;this.logBox.className="molmil_UI_cl_logbox";this.logBox.style.display="none";this.inp.console=this.environment.console;this.inp.onkeydown=function(d){var f=this.textContent;if(d.keyCode==13&&!d.shiftKey&&molmil.isBalancedStatement(f)){this.console.runCommand(f);this.textContent="";return false}if(d.keyCode==38&&d.ctrlKey){this.console.blSel++;if(this.console.blSel>=this.console.backlog.length){this.console.blSel=this.console.backlog.length-1}this.textContent=this.console.backlog[this.console.blSel]}if(d.keyCode==40&&d.ctrlKey){this.console.blSel--;if(this.console.blSel<-1){this.console.blSel=0}if(this.console.blSel==-1){this.textContent=this.console.buffer}else{this.textContent=this.console.backlog[this.console.blSel]}}if(this.console.blSel==-1){this.console.buffer=f}}};molmil.loadScript=function(f){var g=new molmil_dep.CallRemote("GET");g.ASYNC=true;var d=this.cli_canvas.commandLine;g.OnDone=function(){d.environment.scriptUrl=f.substr(0,f.lastIndexOf("/"))+"/";d.environment.console.runCommand(this.request.responseText)};g.Send(f)};molmil.commandLine.prototype.eval=function(d){if(!this.altCommandIF(this.environment,d)){this.runCommand.apply(this.environment,[d])}};molmil.commandLine.prototype.runCommand=function(command){molmil.cli_canvas=this.cli_canvas;molmil.cli_soup=this.cli_soup;command=(" "+command).replace(/(\s|;)var\s+(\w+)\s*=/g,"$1this.$2 =");command=command.replace(/(\s|;)function\s+(\w+)/g,"$1this.$2 = function");command=command.replace(/(\s|;)return\sthis;/g,"$1return window;");try{with(this){eval(command)}}catch(e){this.console.error(e.message)}molmil.cli_canvas=null;molmil.cli_soup=null};molmil.isBalancedStatement=function(g){var n="[]{}()",d=[],h,l,f;for(h=0;l=g[h];h++){f=n.indexOf(l);if(f===-1){continue}if(f%2===0){d.push(f+1)}else{if(d.pop()!==f){return false}}}return d.length===0};molmil.commandLine.prototype.bindNullInterface=function(){if(this.altCommandIF){this.environment.console.log("Previous command interface unbound.")}this.altCommandIF=function(d,f){return false}};molmil.commandLine.prototype.bindPymolInterface=function(){this.environment.console.log("Pymol-like command interface bound.");this.pyMol={};this.pyMol.keywords={select:molmil.commandLines.pyMol.selectCommand,color:molmil.commandLines.pyMol.colorCommand,set_color:molmil.commandLines.pyMol.setColorCommand,show:molmil.commandLines.pyMol.showCommand};this.altCommandIF=molmil.commandLines.pyMol.tryExecute};molmil.commandLines.pyMol={};molmil.commandLines.pyMol.tryExecute=function(d,g){var f=(g.trim().match(/^[\S]+/)||[""])[0].toLowerCase();if(!this.pyMol.keywords.hasOwnProperty(f)||!this.pyMol.keywords[f].apply(null,[d,g])){return false}return true};molmil.commandLines.pyMol.selectCommand=function(d,g){g=g.match(/select[\s]+([a-zA-Z0-9_]+)[\s]*,[\s]*(.*)/);try{d[g[1]]=molmil.commandLines.pyMol.select.apply(d,[g[2]])}catch(f){return false}return true};molmil.commandLines.pyMol.colorCommand=function(d,g){g=g.match(/color[\s]+([a-zA-Z0-9_]+)[\s]*,[\s]*(.*)/);try{molmil.commandLines.pyMol.color.apply(d,[g[1],g[2]])}catch(f){return false}return true};molmil.commandLines.pyMol.setColorCommand=function(d,g){g=g.match(/set_color[\s]+([a-zA-Z0-9_]+)[\s]*,[\s]*(.*)/);try{molmil.commandLines.pyMol.set_color.apply(d,[g[1],JSON.parse(g[2])])}catch(f){return false}return true};molmil.commandLines.pyMol.showCommand=function(d,g){g=g.match(/show[\s]+([a-zA-Z0-9_]+)[\s]*,[\s]*(.*)/);try{molmil.commandLines.pyMol.show.apply(d,[g[1],g[2]])}catch(f){return false}return true};molmil.quickSelect=molmil.commandLines.pyMol.select=molmil.commandLines.pyMol.pymolSelectEngine=function(expr,soup){if(!molmil.isBalancedStatement(expr)){throw"Incorrect statement"}var new_expr="";var word="",key,toUpper=false,ss=false,ss_conv={h:3,s:2,l:1};this.soupObject=this.soupObject||molmil.cli_soup||soup||this.cli_soup;var sub_expr_handler=function(){if(key&&word){if(toUpper){word=word.toUpperCase()}else{if(ss){if(word){word=ss_conv[word]}tmp=ss_conv[tmp]}}new_expr+=key.replace("%s",word)}else{if(word=="hydro"){new_expr+="this.soupObject.atomRef[a].molecule.water == true"}else{if(word=="hetatm"){new_expr+="this.soupObject.atomRef[a].molecule.ligand == true"}}}};for(var i=0;i<expr.length;i++){if(expr[i].match(/\s/)){toUpper=false,ss=false;if(word=="name"){key="this.soupObject.atomRef[a].atomName == '%s'";toUpper=true}else{if(word=="symbol"){key="this.soupObject.atomRef[a].element == '%s'"}else{if(word=="resn"){key="this.soupObject.atomRef[a].molecule.name.toLowerCase() == '%s'.toLowerCase()"}else{if(word=="resi"){key="this.soupObject.atomRef[a].molecule.RSID == %s"}else{if(word=="ss"){key="this.soupObject.atomRef[a].molecule.sndStruc == %s";ss=true}else{if(word=="chain"){key="this.soupObject.atomRef[a].molecule.chain.name == '%s'"}else{if(word=="hydro"){new_expr+="this.soupObject.atomRef[a].molecule.water == true"}else{if(word=="hetatm"){new_expr+="this.soupObject.atomRef[a].molecule.ligand == true"}else{if(word=="and"){new_expr+=" && "}else{if(word=="or"){new_expr+=" || "}else{if(key&&word){new_expr+=key.replace("%s",word)}else{key=""}}}}}}}}}}}word=""}else{if(expr[i]=="+"&&key){var tmp=expr.substr(i+1),pos=tmp.search(/[^a-zA-Z0-9]/),tmp=pos!=-1?tmp.substr(0,pos):tmp;if(tmp){if(toUpper){tmp=tmp.toUpperCase();word=word.toUpperCase()}if(ss){if(word){word=ss_conv[word]}tmp=ss_conv[tmp]}new_expr+=(word?key.replace("%s",word):"")+" || "+key.replace("%s",tmp);word=""}i+=pos==-1?tmp.length:pos}else{if(expr[i]=="-"){var tmp=expr.substr(i+1),pos=tmp.search(/[^a-zA-Z0-9]/),tmp=pos!=-1?tmp.substr(0,pos):tmp;new_expr+="("+key.replace(/ == %s/," >= "+word)+" && "+key.replace(/ == %s/," <= "+tmp)+")";word="";i+=pos==-1?tmp.length:pos}else{if(expr[i].match(/\(|\)|!/)){sub_expr_handler();new_expr+=expr[i];key=word=""}else{word+=expr[i]}}}}}sub_expr_handler();var list=[];new_expr="for (var a in this.soupObject.atomRef) if ("+new_expr+") list.push(this.soupObject.atomRef[a]);";try{eval(new_expr)}catch(e){this.console.error("Unable to process PyMol command: "+e)}return list};molmil.commandLines.pyMol.color=function(g,f,h){if(typeof f!="object"){if(this.hasOwnProperty(f)){f=this[f]}else{f=molmil.commandLines.pyMol.select(f)}}if(g=="default"){var d=[];for(var n=0;n<f.length;n++){d.push(f[n].molecule)}molmil.colorEntry(d,1,null,h)}else{if(g=="structure"){var d=[];for(var n=0;n<f.length;n++){d.push(f[n].molecule)}molmil.colorEntry(d,2,null,h)}else{if(g=="cpk"){molmil.colorEntry(f,3,null,h)}else{if(g=="group"){var d=[];for(var n=0;n<f.length;n++){d.push(f[n].molecule)}molmil.colorEntry(d,4,null,h)}else{if(g=="chain"){var d=[];for(var n=0;n<f.length;n++){d.push(f[n].molecule)}molmil.colorEntry(d,5,null,h)}else{if(typeof g=="string"){var l=this.colors[g];if(!l){l=JSON.parse(g);if(l[0]>1||l[1]>1||l[2]>1||l[3]>1){l=[l[0],l[1],l[2],l[3]]}}}else{var l=g}for(var n=0;n<f.length;n++){f[n].rgba=l;if(f[n].molecule.CA==f[n]){f[n].molecule.rgba=l}}if(!h){this.soupObject.renderer.initBuffers();this.soupObject.renderer.canvas.update=true}}}}}}};molmil.commandLines.pyMol.set_color=function(d,f){console.log(this);if(f[0]>1||f[1]>1||f[2]>1||f[3]>1){f=[f[0],f[1],f[2],f[3]]}this.colors[d]=f};molmil.commandLines.pyMol.show=function(d,f,g){if(typeof f!="object"){if(this.hasOwnProperty(f)){f=this[f]}else{f=molmil.commandLines.pyMol.select(f)}}if(d=="spheres"){for(var h=0;h<f.length;h++){f[h].displayMode=1;if(f[h].molecule.CA==f[h]){f[h].molecule.displayMode=0;f[h].molecule.showSC=true;f[h].molecule.chain.twoDcache=null}}}else{if(d=="ball_stick"){for(var h=0;h<f.length;h++){f[h].displayMode=2;if(f[h].molecule.CA==f[h]){f[h].molecule.displayMode=0;f[h].molecule.showSC=true;f[h].molecule.chain.twoDcache=null}}}else{if(d=="sticks"){for(var h=0;h<f.length;h++){f[h].displayMode=3;if(f[h].molecule.CA==f[h]){f[h].molecule.displayMode=0;f[h].molecule.showSC=true;f[h].molecule.chain.twoDcache=null}}}else{if(d=="lines"){for(var h=0;h<f.length;h++){f[h].displayMode=4;if(f[h].molecule.CA==f[h]){f[h].molecule.displayMode=0;f[h].molecule.showSC=true;f[h].molecule.chain.twoDcache=null}}}else{if(d=="cartoon"){for(var h=0;h<f.length;h++){f[h].displayMode=0;if(f[h].molecule.CA==f[h]){f[h].molecule.displayMode=3;f[h].molecule.showSC=false}}}else{if(d=="tube"){for(var h=0;h<f.length;h++){f[h].displayMode=0;if(f[h].molecule.CA==f[h]){f[h].molecule.displayMode=2;f[h].molecule.showSC=false}}}else{if(d=="ca-trace"){for(var h=0;h<f.length;h++){f[h].displayMode=0;if(f[h].molecule.CA==f[h]){f[h].molecule.displayMode=1;f[h].molecule.showSC=false}}}}}}}}}if(!g){this.soupObject.renderer.initBuffers();this.soupObject.renderer.canvas.update=true}};molmil.bindCanvasInputs=function(f){var d=function(h){h.preventDefault();return false};var g=function(q){q.preventDefault();var p=0,o=[];try{o=q.dataTransfer.files;p=o.length}catch(s){}var h,n,l;for(n=0;n<p;n++){h=new FileReader();h.filename=o[n].name;h.fileHandle=o[n];for(l=0;l<this.inputFunctions.length;l++){if(this.inputFunctions[l](f,h)){break}}}return false};f.addEventListener("dragover",d);f.addEventListener("dragenter",d);f.addEventListener("drop",g);f.inputFunctions=[];f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".gz",h.filename.length-3)!==-1){if(!window.hasOwnProperty("pako")){var n=molmil_dep.dcE("script");n.src=molmil.settings.src+"pako.js";document.getElementsByTagName("head")[0].appendChild(n)}h.onload=function(p){if(!window.hasOwnProperty("pako")){return molmil_dep.asyncStart(this.onload,[p],this,50)}var o={filename:h.filename.substr(0,h.filename.length-3)};o.readAsText=function(){var q=pako.inflate(new Uint8Array(p.target.result),{to:"string"});this.onload({target:{result:q}})};o.readAsArrayBuffer=function(){var q=pako.inflate(new Uint8Array(p.target.result));this.onload({target:{result:q.buffer}})};for(j=0;j<l.inputFunctions.length;j++){if(l.inputFunctions[j](l,o)){break}}};h.readAsArrayBuffer(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".pdb",h.filename.length-4)!==-1||h.filename.indexOf(".ent",h.filename.length-4)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,4,this.filename)};h.readAsText(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".cif",h.filename.length-4)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,"cif",this.filename)};h.readAsText(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".gro",h.filename.length-4)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,7,this.filename)};h.readAsText(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".trr",h.filename.length-4)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,"gromacs-trr",this.filename)};h.readAsArrayBuffer(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".xtc",h.filename.length-4)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,"gromacs-xtc",this.filename)};h.readAsArrayBuffer(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".cor",h.filename.length-4)!==-1||h.filename.indexOf(".cod",h.filename.length-4)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,"psygene-traj",this.filename)};h.readAsArrayBuffer(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".mpbf",h.filename.length-5)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,8,this.filename)};h.readAsArrayBuffer(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".ccp4",h.filename.length-5)!==-1){h.onload=function(n){l.molmilViewer.UI.ccp4_input_popup(n.target.result,this.filename)};h.readAsArrayBuffer(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".mdl",h.filename.length-4)!==-1||h.filename.indexOf(".mol",h.filename.length-4)!==-1,h.filename.indexOf(".sdf",h.filename.length-4)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,"mdl",this.filename)};h.readAsText(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".mol2",h.filename.length-5)!==-1){h.onload=function(n){l.molmilViewer.loadStructureData(n.target.result,"mol2",this.filename)};h.readAsText(h.fileHandle);return true}});f.inputFunctions.push(function(l,h){if(h.filename.indexOf(".xyz",h.filename.length-5)!==-1){h.onload=function(n){l.molmilViewer.UI.xyz_input_popup(n.target.result,this.filename)};h.readAsText(h.fileHandle);return true}})};molmil.initVideo=function(f){var d=new molmil_dep.CallRemote("POST");d.ASYNC=true;d.UI=f;d.OnDone=function(){var g=JSON.parse(this.request.responseText);if(!g.found){return this.OnError()}molmil_dep.asyncStart(this.UI.videoRenderer,[],this.UI,0)};d.OnError=function(){alert("The support server to construct the video could not be found...")};d.Send(molmil.settings.molmil_video_url+"has_molmil_video_support")};molmil.setSlab=function(g,d,f){f=f||molmil.cli_soup;if(!f.renderer.settings.slab){f.renderer.settings.slab=true;molmil.configBox.glsl_fog=false;molmil.shaderEngine.recompile(f.renderer)}f.renderer.settings.slabNear=g;f.renderer.settings.slabFar=d;f.canvas.update=true};molmil.selectAtoms=function(g,d,h){h=h||molmil.cli_soup;if(!d){h.atomSelection=[]}for(var f=0;f<g.length;f++){h.atomSelection.push(g[f])}};molmil.selectionFocus=function(f){f=f||molmil.cli_soup;var n,q,o,s=f.renderer.modelId,l=0,h=0,g=0;var d=[1e+99,-1e+99,1e+99,-1e+99,1e+99,-1e+99];for(var p=0;p<f.atomSelection.length;p++){q=f.atomSelection[p].xyz;o=f.atomSelection[p].chain.modelsXYZ[s];n=[o[q],o[q+1],o[q+2]];l+=n[0];h+=n[1];g+=n[2]}l/=f.atomSelection.length;h/=f.atomSelection.length;g/=f.atomSelection.length;for(var p=0;p<f.atomSelection.length;p++){q=f.atomSelection[p].xyz;o=f.atomSelection[p].chain.modelsXYZ[s];n=[o[q]-l,o[q+1]-h,o[q+2]-g];if(n[0]<d[0]){d[0]=n[0]}if(n[0]>d[1]){d[1]=n[0]}if(n[1]<d[2]){d[2]=n[1]}if(n[1]>d[3]){d[3]=n[1]}if(n[2]<d[4]){d[4]=n[2]}if(n[2]>d[5]){d[5]=n[2]}}f.renderer.camera.z=f.calcZ(d);f.setCOR([l,h,g]);f.renderer.camera.x=f.renderer.camera.y=0;f.renderer.modelViewMatrix=f.renderer.camera.generateMatrix();f.canvas.atomCORset=false};molmil.selectSequence=function(u,o){o=o||molmil.cli_soup;var h=[],q={A:"ALA",C:"CYS",D:"ASP",E:"GLU",F:"PHE",G:"GLY",H:"HIS",I:"ILE",K:"LYS",L:"LEU",M:"MET",N:"ASN",P:"PRO",Q:"GLN",R:"ARG",S:"SER",T:"THR",V:"VAL",W:"TRP",Y:"TYR"};molmil.AATypesBase={ALA:1,CYS:1,ASP:1,GLU:1,PHE:1,GLY:1,HIS:1,ILE:1,LYS:1,LEU:1,MET:1,ASN:1,PRO:1,GLN:1,ARG:1,SER:1,THR:1,VAL:1,TRP:1,TYR:1,ACE:1,NME:1,HIP:1,HIE:1,HID:1};for(var l=0;l<u.length;l++){if(q.hasOwnProperty(u[l])){h.push(q[u[l]])}else{h.push("***")}}var f=[],t,s,d,g;for(var p=0;p<o.chains.length;p++){for(t=0;t<o.chains[p].molecules.length;t++){g=true;for(s=t,d=0;s<Math.min(o.chains[p].molecules.length,t+h.length);s++,d++){if(o.chains[p].molecules[s].name!=h[d]){g=false;break}}if(g){for(s=t;s<t+h.length;s++){f.push(o.chains[p].molecules[s])}}}}return f};molmil.mergeStructuresToModels=function(d){};molmil.splitModelsToStructures=function(d){};if(typeof(requestAnimationFrame)!="undefined"){molmil.animate_molmilViewers()}if(!window.molmil_dep){var dep=document.createElement("script");dep.src=molmil.settings.src+"molmil_dep.js";var head=document.getElementsByTagName("head")[0];head.appendChild(dep)}molmil.initSettings();