//
// ChemDoodle Web Components 3.0.0
//
// http://web.chemdoodle.com
//
// Copyright 2009 iChemLabs, LLC.  All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// As a special exception to the GPL, any HTML file which merely makes
// function calls to this code, and for that purpose includes it by
// reference, shall be deemed a separate work for copyright law purposes.
// If you modify this code, you may extend this exception to your version
// of the code, but you are not obligated to do so. If you do not wish to
// do so, delete this exception statement from your version.
//
// As an additional exception to the GPL, you may distribute this
// packed form of the code without the copy of the GPL license normally
// required, provided you include this license notice and a URL through
// which recipients can access the corresponding unpacked source code.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// Please contact iChemLabs <http://www.ichemlabs.com/contact> for
// alternate licensing options.
//
var default_backgroundColor="#FFFFFF";var default_scale=1;var default_rotateAngle=0;var default_bondLength_2D=20;var default_angstromsPerBondLength=1.25;var default_lightDirection_3D=[-0.1,-0.1,-1];var default_lightDiffuseColor_3D="#FFFFFF";var default_lightSpecularColor_3D="#FFFFFF";var default_projectionVerticalFieldOfView_3D=45;var default_projectionWidthHeightRatio_3D=1;var default_projectionFrontCulling_3D=0.1;var default_projectionBackCulling_3D=10000;var default_atoms_display=true;var default_atoms_color="#000000";var default_atoms_font_size_2D=12;var default_atoms_font_families_2D=["Helvetica","Arial","Dialog"];var default_atoms_circles_2D=false;var default_atoms_circleDiameter_2D=10;var default_atoms_circleBorderWidth_2D=1;var default_atoms_useJMOLColors=false;var default_atoms_resolution_3D=60;var default_atoms_sphereDiameter_3D=0.8;var default_atoms_useVDWDiameters_3D=false;var default_atoms_materialAmbientColor_3D="#000000";var default_atoms_materialSpecularColor_3D="#555555";var default_atoms_materialShininess_3D=32;var default_bonds_display=true;var default_bonds_color="#000000";var default_bonds_width_2D=1;var default_bonds_saturationWidth_2D=0.2;var default_bonds_ends_2D="round";var default_bonds_useJMOLColors=false;var default_bonds_saturationAngle_2D=Math.PI/3;var default_bonds_symmetrical_2D=false;var default_bonds_clearOverlaps_2D=false;var default_bonds_overlapClearWidth_2D=0.5;var default_bonds_atomLabelBuffer_2D=0.25;var default_bonds_wedgeThickness_2D=0.22;var default_bonds_hashWidth_2D=1;var default_bonds_hashSpacing_2D=2.5;var default_bonds_resolution_3D=60;var default_bonds_cylinderDiameter_3D=0.3;var default_bonds_materialAmbientColor_3D="#222222";var default_bonds_materialSpecularColor_3D="#555555";var default_bonds_materialShininess_3D=32;function VisualSpecifications(){this.backgroundColor=default_backgroundColor;this.scale=default_scale;this.rotateAngle=default_rotateAngle;this.bondLength=default_bondLength_2D;this.angstromsPerBondLength=default_angstromsPerBondLength;this.lightDirection_3D=default_lightDirection_3D;this.lightDiffuseColor_3D=default_lightDiffuseColor_3D;this.lightSpecularColor_3D=default_lightSpecularColor_3D;this.projectionVerticalFieldOfView_3D=default_projectionVerticalFieldOfView_3D;this.projectionWidthHeightRatio_3D=default_projectionWidthHeightRatio_3D;this.projectionFrontCulling_3D=default_projectionFrontCulling_3D;this.projectionBackCulling_3D=default_projectionBackCulling_3D;this.atoms_display=default_atoms_display;this.atoms_color=default_atoms_color;this.atoms_font_size_2D=default_atoms_font_size_2D;this.atoms_font_families_2D=new Array();for(var a=0;a<default_atoms_font_families_2D.length;a++){this.atoms_font_families_2D[a]=default_atoms_font_families_2D[a]}this.atoms_circles_2D=default_atoms_circles_2D;this.atoms_circleDiameter_2D=default_atoms_circleDiameter_2D;this.atoms_circleBorderWidth_2D=default_atoms_circleBorderWidth_2D;this.atoms_useJMOLColors=default_atoms_useJMOLColors;this.atoms_resolution_3D=default_atoms_resolution_3D;this.atoms_sphereDiameter_3D=default_atoms_sphereDiameter_3D;this.atoms_useVDWDiameters_3D=default_atoms_useVDWDiameters_3D;this.atoms_materialAmbientColor_3D=default_atoms_materialAmbientColor_3D;this.atoms_materialSpecularColor_3D=default_atoms_materialSpecularColor_3D;this.atoms_materialShininess_3D=default_atoms_materialShininess_3D;this.bonds_display=default_bonds_display;this.bonds_color=default_bonds_color;this.bonds_width_2D=default_bonds_width_2D;this.bonds_saturationWidth_2D=default_bonds_saturationWidth_2D;this.bonds_ends_2D=default_bonds_ends_2D;this.bonds_useJMOLColors=default_bonds_useJMOLColors;this.bonds_saturationAngle_2D=default_bonds_saturationAngle_2D;this.bonds_symmetrical_2D=default_bonds_symmetrical_2D;this.bonds_clearOverlaps_2D=default_bonds_clearOverlaps_2D;this.bonds_overlapClearWidth_2D=default_bonds_overlapClearWidth_2D;this.bonds_atomLabelBuffer_2D=default_bonds_atomLabelBuffer_2D;this.bonds_wedgeThickness_2D=default_bonds_wedgeThickness_2D;this.bonds_hashWidth_2D=default_bonds_hashWidth_2D;this.bonds_hashSpacing_2D=default_bonds_hashSpacing_2D;this.bonds_resolution_3D=default_bonds_resolution_3D;this.bonds_cylinderDiameter_3D=default_bonds_cylinderDiameter_3D;this.bonds_materialAmbientColor_3D=default_bonds_materialAmbientColor_3D;this.bonds_materialSpecularColor_3D=default_bonds_materialSpecularColor_3D;this.bonds_materialShininess_3D=default_bonds_materialShininess_3D;this.set3DRepresentation=function(b){this.bonds_color="#777777";if(b=="Ball and Stick"){this.atoms_display=true;this.bonds_display=true;this.atoms_useVDWDiameters_3D=false;this.atoms_useJMOLColors=true;this.bonds_useJMOLColors=true;this.bonds_cylinderDiameter_3D=0.3;this.atoms_sphereDiameter_3D=1}else{if(b=="van der Waals Spheres"){this.atoms_display=true;this.bonds_display=false;this.atoms_useVDWDiameters_3D=true;this.atoms_useJMOLColors=true;this.bonds_useJMOLColors=true}else{if(b=="Stick"){this.atoms_display=true;this.bonds_display=true;this.atoms_useVDWDiameters_3D=false;this.atoms_useJMOLColors=true;this.bonds_useJMOLColors=true;this.bonds_cylinderDiameter_3D=this.atoms_sphereDiameter_3D=0.8;this.bonds_materialAmbientColor_3D=this.atoms_materialAmbientColor_3D;this.bonds_materialSpecularColor_3D=this.atoms_materialSpecularColor_3D;this.bonds_materialShininess_3D=this.atoms_materialShininess_3D}else{if(b=="Wireframe"){this.atoms_display=true;this.bonds_display=true;this.atoms_useVDWDiameters_3D=false;this.atoms_useJMOLColors=true;this.bonds_useJMOLColors=true;this.bonds_cylinderDiameter_3D=0.05;this.atoms_sphereDiameter_3D=0.15}else{alert('"'+b+'" is not recognized. Use one of the following strings:\n\n1. Ball and Stick\n2. van der Waals Spheres\n3. Stick\n4. Wireframe\n')}}}}}}var SHIFT=false;var ALT=false;var CURRENT_OVER=null;jQuery(document).ready(function(){$().keydown(function(a){if(a.keyCode==16){SHIFT=true}else{if(a.keyCode==18){ALT=true}else{if(CURRENT_OVER!=null&&CURRENT_OVER.keydown){CURRENT_OVER.prehandleEvent(a);CURRENT_OVER.keydown(a)}}}});$().keypress(function(a){if(CURRENT_OVER!=null&&CURRENT_OVER.keydown){CURRENT_OVER.prehandleEvent(a);CURRENT_OVER.keydown(a)}});$().keyup(function(a){if(a.keyCode==16){SHIFT=false}else{if(a.keyCode==18){ALT=false}else{if(CURRENT_OVER!=null&&CURRENT_OVER.keyup){CURRENT_OVER.prehandleEvent(a);CURRENT_OVER.keyup(a)}}}})});function Canvas(){this.molecule=null;this.emptyMessage=null;this.image=null;this.repaint=function(){var b=document.getElementById(this.id);if(b.getContext){var a=b.getContext("2d");if(this.image==null){a.fillStyle=this.specs.backgroundColor;a.fillRect(0,0,this.width,this.height)}else{a.drawImage(this.image,0,0)}if(this.molecule!=null){a.save();a.translate(this.width/2,this.height/2);a.rotate(this.specs.rotateAngle);a.scale(this.specs.scale,this.specs.scale);a.translate(-this.width/2,-this.height/2);this.molecule.draw(a,this.specs);a.restore()}else{if(this.emptyMessage!=null){a.fillStyle="#737683";a.textAlign="center";a.textBaseline="middle";a.font="18px Helvetica";a.fillText(this.emptyMessage,this.width/2,this.height/2)}}if(this.drawChildExtras){this.drawChildExtras(a)}}};this.setBackgroundImage=function(b){this.image=new Image();var a=this;this.image.onload=function(){a.repaint()};this.image.src=b};this.loadMolecule=function(a){this.molecule=a;this.center();this.molecule.check();if(this.afterLoadMolecule){this.afterLoadMolecule()}this.repaint()};this.center=function(){var b=document.getElementById(this.id);var e=this.molecule.getCenter3D();var a=new Atom("C",this.width/2,this.height/2,0);a.sub3D(e);for(var c=0;c<this.molecule.atoms.length;c++){this.molecule.atoms[c].add3D(a)}var d=this.molecule.getDimension();this.specs.scale=1;if(d.x>this.width||d.y>this.height){this.specs.scale=Math.min(this.width/d.x,this.height/d.y)*0.9}};this.create=function(d,b,a){this.id=d;this.width=b;this.height=a;if(BrowserDetect.browser=="Explorer"){document.writeln('<div style="border: 1px solid black;" width="'+b+'" height="'+a+'">Please install <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a>, then restart Internet Explorer.</div>')}else{document.writeln('<canvas class="ChemDoodleWebComponent" id="'+d+'" width="'+b+'" height="'+a+'"></canvas>')}this.specs=new VisualSpecifications();var c=this;$("#"+d).click(function(f){if(c.click){c.prehandleEvent(f);c.click(f)}});$("#"+d).dblclick(function(f){if(c.dblclick){c.prehandleEvent(f);c.dblclick(f)}});$("#"+d).mousedown(function(f){if(c.mousedown){c.prehandleEvent(f);c.mousedown(f)}});$("#"+d).mousemove(function(f){if(c.mousemove){c.prehandleEvent(f);c.mousemove(f)}});$("#"+d).mouseout(function(f){CURRENT_OVER=null;if(c.mouseout){c.prehandleEvent(f);c.mouseout(f)}});$("#"+d).mouseover(function(f){CURRENT_OVER=c;if(c.mouseover){c.prehandleEvent(f);c.mouseover(f)}});$("#"+d).mouseup(function(f){if(c.mouseup){c.prehandleEvent(f);c.mouseup(f)}});$("#"+d).drag(function(f){if(c.drag){c.prehandleEvent(f);c.drag(f)}});$("#"+d).rightclick(function(f){if(c.rightclick){c.prehandleEvent(f);c.rightclick(f)}});$("#"+d).rightmousedown(function(f){if(c.rightmousedown){c.prehandleEvent(f);c.rightmousedown(f)}});$("#"+d).rightmouseup(function(f){if(c.rightmouseup){c.prehandleEvent(f);c.rightmouseup(f)}});$("#"+d).keydown(function(f){alert("got to keydown");if(c.keydown){c.prehandleEvent(f);c.keydown(f)}});$("#"+d).keypress(function(f){alert("got to keypress");if(c.keypress){c.prehandleEvent(f);c.keypress(f)}});$("#"+d).keyup(function(f){alert("got to keyup");if(c.keyup){c.prehandleEvent(f);c.keyup(f)}});$("#"+d).mousewheel(function(f,g){if(c.mousewheel){c.prehandleEvent(f);c.mousewheel(f,g)}});if(this.subCreate){this.subCreate()}};this.getMolecule=function(){return this.molecule};this.prehandleEvent=function(a){a.preventDefault();var b=$("#"+this.id).offset();a.p=new Point(a.pageX-b.left,a.pageY-b.top)};return true}function AnimatorCanvas(c,b,a){if(c){this.create(c,b,a)}this.handle=null;this.timeout=33;this.startAnimation=function(){this.stopAnimation();var d=this;if(this.nextFrame){this.handle=setInterval(function(){d.nextFrame();d.repaint()},this.timeout)}};this.stopAnimation=function(){if(this.handle!=null){clearInterval(this.handle);this.handle=null}};this.isRunning=function(){return this.handle!=null};return true}AnimatorCanvas.prototype=new Canvas();function DoodleCanvas(d,c,b){if(d){this.create(d,c,b)}this.specs.atoms_useJMOLColors=true;this.specs.atoms_circleDiameter_2D=7;this.specs.atoms_circleBorderWidth_2D=0;this.isHelp=false;this.helpPos=new Point(this.width-20,20);this.tempAtom=null;this.drawChildExtras=function(f){if(this.tempAtom!=null){f.strokeStyle="#00FF00";f.fillStyle="#00FF00";f.lineWidth=1.2;for(var g=0;g<this.molecule.atoms.length;g++){if(this.molecule.atoms[g].isSelected){f.beginPath();f.moveTo(this.molecule.atoms[g].x,this.molecule.atoms[g].y);f.lineTo(this.tempAtom.x,this.tempAtom.y);f.stroke();f.beginPath();f.arc(this.tempAtom.x,this.tempAtom.y,3,0,Math.PI*2,false);f.fill();if(this.tempAtom.isOverlap){f.strokeStyle="#C10000";f.lineWidth=1.2;f.beginPath();f.arc(this.tempAtom.x,this.tempAtom.y,7,0,Math.PI*2,false);f.stroke()}}}}var e=f.createRadialGradient(this.width-20,20,10,this.width-20,20,2);e.addColorStop(0,"#00680F");e.addColorStop(1,"#FFFFFF");f.fillStyle=e;f.beginPath();f.arc(this.helpPos.x,this.helpPos.y,10,0,Math.PI*2,false);f.fill();if(this.isHelp){f.lineWidth=2;f.strokeStyle="black";f.stroke()}f.fillStyle=this.isHelp?"red":"black";f.textAlign="center";f.textBaseline="middle";f.font="14px sans-serif";f.fillText("?",this.helpPos.x,this.helpPos.y)};this.drag=function(o){var l=false;for(var m=0;m<this.molecule.atoms.length;m++){if(this.molecule.atoms[m].isSelected){l=true;if(o.p.distance(this.molecule.atoms[m])<7){var u=this.molecule.atoms[m].x;var q=this.molecule.atoms[m].y;var p=this.molecule.getAngles(this.molecule.atoms[m]);if(p.length==0){u+=this.specs.bondLength*Math.cos(-Math.PI/6);q+=this.specs.bondLength*Math.sin(-Math.PI/6)}else{if(p.length==1){var r=0;var s=null;for(var k=0;k<this.molecule.bonds.length;k++){if(this.molecule.bonds[k].contains(this.molecule.atoms[m])){s=this.molecule.bonds[k]}}if(s.bondOrder>=3){r=p[0]+Math.PI}else{var v=p[0]%Math.PI*2;if(isBetween(v,0,Math.PI/2)||isBetween(v,Math.PI,3*Math.PI/2)){r=p[0]+2*Math.PI/3}else{r=p[0]-2*Math.PI/3}}u+=this.specs.bondLength*Math.cos(r);q-=this.specs.bondLength*Math.sin(r)}else{var f=angleBetweenLargest(p);u+=this.specs.bondLength*Math.cos(f);q-=this.specs.bondLength*Math.sin(f)}}this.tempAtom=new Atom("C",u,q,0)}else{if(ALT&&SHIFT){this.tempAtom=new Atom("C",o.p.x,o.p.y,0)}else{var h=this.molecule.atoms[m].angle(o.p);var g=this.molecule.atoms[m].distance(o.p);if(!SHIFT){g=this.specs.bondLength}if(!ALT){var n=Math.floor((h+Math.PI/12)/(Math.PI/6));h=n*Math.PI/6}this.tempAtom=new Atom("C",this.molecule.atoms[m].x+g*Math.cos(h),this.molecule.atoms[m].y-g*Math.sin(h),0)}}for(var k=0;k<this.molecule.atoms.length;k++){if(this.molecule.atoms[k].distance(this.tempAtom)<5){this.tempAtom.x=this.molecule.atoms[k].x;this.tempAtom.y=this.molecule.atoms[k].y;this.tempAtom.isOverlap=true}}break}}if(!l){var t=new Point(o.p.x,o.p.y);t.sub(this.lastPoint);for(var m=0;m<this.molecule.atoms.length;m++){this.molecule.atoms[m].add(t)}for(var m=0;m<this.molecule.rings.length;m++){this.molecule.rings[m].center=this.molecule.rings[m].getCenter()}}this.lastPoint=o.p;this.repaint()};this.mousedown=function(g){this.lastPoint=g.p;if(this.isHelp){this.isHelp=false;this.repaint();window.open("http://web.chemdoodle.com/DoodlerTutorial.html");return}for(var f=0;f<this.molecule.atoms.length;f++){if(this.molecule.atoms[f].isHover){this.molecule.atoms[f].isHover=false;this.molecule.atoms[f].isSelected=true;this.drag(g);return}}for(var f=0;f<this.molecule.bonds.length;f++){if(this.molecule.bonds[f].isHover){this.molecule.bonds[f].isHover=false;this.molecule.bonds[f].bondOrder+=(this.molecule.bonds[f].bondOrder%1)+1;if(this.molecule.bonds[f].bondOrder>3){this.molecule.bonds[f].bondOrder=1}this.repaint();return}}};this.click=function(k){for(var g=0;g<this.molecule.atoms.length;g++){if(this.tempAtom!=null&&this.molecule.atoms[g].isSelected){if(this.tempAtom.isOverlap){for(var f=0;f<this.molecule.atoms.length;f++){if(this.molecule.atoms[f].distance(this.tempAtom)<5){this.tempAtom=this.molecule.atoms[f]}}}else{this.molecule.atoms[this.molecule.atoms.length]=this.tempAtom}var h=false;for(var f=0;f<this.molecule.bonds.length;f++){if(this.molecule.bonds[f].contains(this.molecule.atoms[g])&&this.molecule.bonds[f].contains(this.tempAtom)){h=true;this.molecule.bonds[f].bondOrder+=(this.molecule.bonds[f].bondOrder%1)+1;if(this.molecule.bonds[f].bondOrder>3){this.molecule.bonds[f].bondOrder=1}}}if(!h){this.molecule.bonds[this.molecule.bonds.length]=new Bond(this.molecule.atoms[g],this.tempAtom,1)}this.molecule.check()}this.molecule.atoms[g].isSelected=false}this.tempAtom=null;this.mousemove(k)};this.mousemove=function(j){if(this.tempAtom!=null){return}var g=Infinity;var h=null;for(var f=0;f<this.molecule.atoms.length;f++){this.molecule.atoms[f].isHover=false;var k=j.p.distance(this.molecule.atoms[f]);if(k<this.specs.bondLength&&k<g){g=k;h=this.molecule.atoms[f]}}for(var f=0;f<this.molecule.bonds.length;f++){this.molecule.bonds[f].isHover=false;var k=j.p.distance(this.molecule.bonds[f].getCenter());if(k<this.specs.bondLength&&k<g){g=k;h=this.molecule.bonds[f]}}if(h!=null){h.isHover=true}this.isHelp=false;if(j.p.distance(this.helpPos)<10){this.isHelp=true}this.repaint()};this.keydown=function(z){if(z.keyCode>=37&&z.keyCode<=40){var l=0;var f=0;switch(z.keyCode){case 37:l=-10;break;case 38:f=-10;break;case 39:l=10;break;case 40:f=10;break}for(var y=0;y<this.molecule.atoms.length;y++){this.molecule.atoms[y].x+=l;this.molecule.atoms[y].y+=f}for(var y=0;y<this.molecule.rings.length;y++){this.molecule.rings[y].center=this.molecule.rings[y].getCenter()}this.repaint()}else{if(z.keyCode==8||z.keyCode==127){for(var y=0;y<this.molecule.atoms.length;y++){if(this.molecule.atoms[y].isHover){for(var x=0;x<this.molecule.atoms.length;x++){this.molecule.atoms[x].visited=false}var t=[];var r=[];this.molecule.atoms[y].visited=true;for(var x=0;x<this.molecule.bonds.length;x++){if(this.molecule.bonds[x].contains(this.molecule.atoms[y])){var m=[];var p=[];var v=new Queue();v.enqueue(this.molecule.bonds[x].getNeighbor(this.molecule.atoms[y]));while(!v.isEmpty()){var B=v.dequeue();if(!B.visited){B.visited=true;m[m.length]=B;for(var w=0;w<this.molecule.bonds.length;w++){if(this.molecule.bonds[w].contains(B)&&!this.molecule.bonds[w].getNeighbor(B).visited){v.enqueue(this.molecule.bonds[w].getNeighbor(B));p[p.length]=this.molecule.bonds[w]}}}}t[t.length]=m;r[r.length]=p}}var h=-1;var n=-1;for(var x=0;x<t.length;x++){if(t[x].length>h){n=x;h=t[x].length}}if(n>-1){this.molecule.atoms=t[n];this.molecule.bonds=r[n];this.molecule.check()}else{var o=new Molecule();o.atoms[0]=new Atom("C",0,0,0);this.loadMolecule(o)}this.repaint();break}}}else{for(var y=0;y<this.molecule.atoms.length;y++){if(this.molecule.atoms[y].isHover){var A=String.fromCharCode(z.keyCode);var g=null;var s=null;var u=false;for(var x=0;x<symbols.length;x++){if(symbols[x]==this.molecule.atoms[y].label){u=true}else{if(symbols[x].charAt(0)==A){if(u&&s==null){s=symbols[x]}else{if(g==null){g=symbols[x]}}}}}if(s!=null){this.molecule.atoms[y].label=s}else{if(g!=null){this.molecule.atoms[y].label=g}}this.molecule.check();this.repaint();break}}}}};var a=new Molecule();a.atoms[0]=new Atom("C",0,0,0);this.loadMolecule(a);return true}DoodleCanvas.prototype=new Canvas();function FileCanvas(d,b,a,c){this.create(d,b,a);form='<br><form name="FileForm" enctype="multipart/form-data" method="POST" action="'+c+'" target="HiddenFileFrame"><input type="file" name="f" /><input type="submit" name="submitbutton" value="Show File" /></form><iframe id="HFF-'+d+'" name="HiddenFileFrame" height="0" width="0" style="display:none;" onLoad="GetMolFromFrame(\'HFF-'+d+"', "+d+')"></iframe>';document.writeln(form);this.emptyMessage="Click below to load file";this.repaint();return true}FileCanvas.prototype=new Canvas();function HyperlinkCanvas(f,d,a,e,b,c){this.urlOrFunction=e;this.color=b?b:"blue";this.size=c?c:2;this.openInNewWindow=true;this.hoverImage=null;if(f){this.create(f,d,a)}this.e=null;this.drawChildExtras=function(g){if(this.e!=null){if(this.hoverImage==null){g.strokeStyle=this.color;g.lineWidth=this.size*2;g.strokeRect(0,0,this.width,this.height)}else{g.drawImage(this.hoverImage,0,0)}}};this.setHoverImage=function(g){this.hoverImage=new Image();this.hoverImage.src=g};this.click=function(g){this.e=null;this.repaint();if(this.urlOrFunction instanceof Function){this.urlOrFunction()}else{if(this.openInNewWindow){window.open(this.urlOrFunction)}else{location.href=this.urlOrFunction}}};this.mouseout=function(g){this.e=null;this.repaint()};this.mouseover=function(g){this.e=g;this.repaint()};return true}HyperlinkCanvas.prototype=new Canvas();function MolGrabberCanvas(d,b,a,c){if(d){this.create(d,b,a)}form='<br><form name="MolGrabberForm" method="POST" action="'+c+'" target="HiddenMolGrabberFrame" onSubmit="ValidateMolecule(MolGrabberForm); return false;"><input type="hidden" name="dim" value="2" /><input type="text" name="q" value="" /><input type="submit" name="submitbutton" value="Show Molecule" /></form><iframe id="HMGF-'+d+'" name="HiddenMolGrabberFrame" height="0" width="0" style="display:none;" onLoad="GetMolFromFrame(\'HMGF-'+d+"', "+d+')"></iframe>';document.writeln(form);this.emptyMessage="Enter search term below";this.repaint();this.setSearchTerm=function(e){document.MolGrabberForm.q.value=e;document.MolGrabberForm.submit()};return true}MolGrabberCanvas.prototype=new Canvas();function RotatorCanvas(e,c,b,d){if(e){this.create(e,c,b)}this.rotate3D=d;var a=Math.PI/360;this.xIncrement=a;this.yIncrement=a;this.zIncrement=a;this.nextFrame=function(){if(this.molecule==null){this.stopAnimation();return}if(this.rotate3D){var m=$M([[Math.cos(this.zIncrement),-Math.sin(this.zIncrement),0],[Math.sin(this.zIncrement),Math.cos(this.zIncrement),0],[0,0,1]]);var h=$M([[Math.cos(-this.yIncrement),0,Math.sin(-this.yIncrement)],[0,1,0],[-Math.sin(-this.yIncrement),0,Math.cos(-this.yIncrement)]]);var l=$M([[1,0,0],[0,Math.cos(this.xIncrement),-Math.sin(this.xIncrement)],[0,Math.sin(this.xIncrement),Math.cos(this.xIncrement)]]);for(var k=0;k<this.molecule.atoms.length;k++){var g=this.molecule.atoms[k];var f=$V([g.x-this.width/2,g.y-this.height/2,g.z]);var j=m.x(h.x(l.x(f)));g.x=j.e(1)+this.width/2;g.y=j.e(2)+this.height/2;g.z=j.e(3)}for(var k=0;k<this.molecule.rings.length;k++){this.molecule.rings[k].center=this.molecule.rings[k].getCenter()}if(this.specs.atoms_display&&this.specs.atoms_circles_2D){this.molecule.sortAtomsByZ()}if(this.specs.bonds_display&&this.specs.bonds_clearOverlaps_2D){this.molecule.sortBondsByZ()}}else{this.specs.rotateAngle+=this.zIncrement}};return true}RotatorCanvas.prototype=new AnimatorCanvas();function SlideshowCanvas(c,b,a){if(c){this.create(c,b,a)}this.molecules=[];this.curIndex=0;this.timeout=5000;this.alpha=0;this.innerHandle=null;this.phase=0;this.drawChildExtras=function(d){d.fillStyle="rgba("+parseInt(this.specs.backgroundColor.substring(1,3),16)+", "+parseInt(this.specs.backgroundColor.substring(3,5),16)+", "+parseInt(this.specs.backgroundColor.substring(5,7),16)+", "+this.alpha+")";d.fillRect(0,0,this.width,this.height)};this.nextFrame=function(){if(this.molecules.length==0){this.stopAnimation();return}this.phase=0;var e=this;var d=1;this.innerHandle=setInterval(function(){e.alpha=d/15;e.repaint();if(d==15){e.breakInnerHandle()}d++},33)};this.breakInnerHandle=function(){if(this.innerHandle!=null){clearInterval(this.innerHandle);this.innerHandle=null}if(this.phase==0){this.curIndex++;if(this.curIndex>this.molecules.length-1){this.curIndex=0}this.alpha=1;this.loadMolecule(this.molecules[this.curIndex]);this.phase=1;var e=this;var d=1;this.innerHandle=setInterval(function(){e.alpha=(15-d)/15;e.repaint();if(d==15){e.breakInnerHandle()}d++},33)}else{if(this.phase==1){this.alpha=0;this.repaint()}}};this.addMolecule=function(d){if(this.molecules.length==0){this.loadMolecule(d)}this.molecules[this.molecules.length]=d};return true}SlideshowCanvas.prototype=new AnimatorCanvas();var curquat=new Array(4);var lastquat=new Array(4);function TransformCanvas(d,b,a,c){if(d){this.create(d,b,a)}this.lastPoint=null;this.rotate3D=c;this.useQuaternions=false;this.rotationMultMod=1.3;this.mousedown=function(f){this.lastPoint=f.p};this.rightmousedown=function(f){this.lastPoint=f.p};this.drag=function(y){if(ALT){var r=new Point(y.p.x,y.p.y);r.sub(this.lastPoint);for(var w=0;w<this.molecule.atoms.length;w++){this.molecule.atoms[w].add(r)}this.lastPoint=y.p;this.repaint()}else{if(this.rotate3D==true){var o=Math.max(this.width/4,this.height/4);if(this.useQuaternions){trackball(curquat,0,0,0,0);trackball(lastquat,(this.lastPoint.x-this.width/2)/o,-(this.lastPoint.y-this.height/2)/o,(y.p.x-this.width/2)/o,-(y.p.y-this.height/2)/o);add_quats(lastquat,curquat,curquat);var v=new Array(16);build_rotmatrix(v,curquat);for(var w=0;w<this.molecule.atoms.length;w++){var A=this.molecule.atoms[w];var p=-(A.x-this.width/2);var n=-(A.y-this.height/2);var l=-A.z;A.x=-(p*v[0]+n*v[1]+l*v[2])+this.width/2;A.y=-(p*v[4]+n*v[5]+l*v[6])+this.height/2;A.z=-(p*v[8]+n*v[9]+l*v[10])}}else{var h=y.p.x-this.lastPoint.x;var g=y.p.y-this.lastPoint.y;var f=h/o*this.rotationMultMod;var u=-g/o*this.rotationMultMod;var m=$M([[Math.cos(f),0,Math.sin(f)],[0,1,0],[-Math.sin(f),0,Math.cos(f)]]);var k=$M([[1,0,0],[0,Math.cos(u),-Math.sin(u)],[0,Math.sin(u),Math.cos(u)]]);for(var w=0;w<this.molecule.atoms.length;w++){var A=this.molecule.atoms[w];var s=$V([A.x-this.width/2,A.y-this.height/2,A.z]);var x=m.x(k.x(s));A.x=x.e(1)+this.width/2;A.y=x.e(2)+this.height/2;A.z=x.e(3)}}for(var w=0;w<this.molecule.rings.length;w++){this.molecule.rings[w].center=this.molecule.rings[w].getCenter()}this.lastPoint=y.p;if(this.specs.atoms_display&&this.specs.atoms_circles_2D){this.molecule.sortAtomsByZ()}if(this.specs.bonds_display&&this.specs.bonds_clearOverlaps_2D){this.molecule.sortBondsByZ()}this.repaint()}else{var z=new Point(this.width/2,this.height/2);var q=z.angle(this.lastPoint);var j=z.angle(y.p);this.specs.rotateAngle-=(j-q);this.lastPoint=y.p;this.repaint()}}};this.mousewheel=function(f,g){this.specs.scale+=g/100;this.repaint()};return true}TransformCanvas.prototype=new Canvas();function ViewerCanvas(c,b,a){if(c){this.create(c,b,a)}return true}ViewerCanvas.prototype=new Canvas();var NO_WEBGL_WARNING=false;function Canvas3D(c,b,a){if(c){this.create(c,b,a)}this.rotationMatrix=Matrix.I(4);this.translationMatrix=Matrix.I(4);this.afterLoadMolecule=function(){var e=this.molecule.getDimension();this.translationMatrix=Matrix.Translation($V([0,0,-Math.max(e.x,e.y)-10])).ensure4x4();this.setupScene()};this.setViewDistance=function(d){this.translationMatrix=Matrix.Translation($V([0,0,-d])).ensure4x4()};this.repaint=function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);this.gl.modelViewMatrix=this.translationMatrix.x(this.rotationMatrix);if(this.molecule!=null){this.molecule.render(this.gl,this.specs)}};this.center=function(){var e=document.getElementById(this.id);var g=this.molecule.getCenter3D();var d=new Atom("C",0,0,0);d.sub3D(g);for(var f=0;f<this.molecule.atoms.length;f++){this.molecule.atoms[f].add3D(d)}};this.subCreate=function(){try{this.gl=document.getElementById(this.id).getContext("experimental-webgl");this.gl.viewport(0,0,this.width,this.height)}catch(d){}if(!this.gl){if(!NO_WEBGL_WARNING){alert("WebGL is not installed or enabled.")}return}this.gl.program=this.gl.createProgram();this.gl.shader=new Shader();this.gl.shader.init(this.gl);this.setupScene()};this.setupScene=function(){this.gl.clearColor(parseInt(this.specs.backgroundColor.substring(1,3),16)/255,parseInt(this.specs.backgroundColor.substring(3,5),16)/255,parseInt(this.specs.backgroundColor.substring(5,7),16)/255,1);this.gl.clearDepth(1);this.gl.enable(this.gl.DEPTH_TEST);this.gl.depthFunc(this.gl.LEQUAL);this.gl.sphereBuffer=new Sphere();this.gl.sphereBuffer.generate(this.gl,1,this.specs.atoms_resolution_3D,this.specs.atoms_resolution_3D);this.gl.cylinderBuffer=new Cylinder();this.gl.cylinderBuffer.generate(this.gl,1,1,this.specs.bonds_resolution_3D);this.gl.lighting=new Light(this.specs.lightDiffuseColor_3D,this.specs.lightSpecularColor_3D,this.specs.lightDirection_3D);this.gl.lighting.lightScene(this.gl);this.gl.material=new Material(this.specs.atoms_materialAmbientColor_3D,this.specs.atoms_color,this.specs.atoms_materialSpecularColor_3D,this.specs.atoms_materialShininess_3D);this.gl.material.setup(this.gl);this.gl.projectionMatrix=makePerspective(this.specs.projectionVerticalFieldOfView_3D,this.specs.projectionWidthHeightRatio_3D,this.specs.projectionFrontCulling_3D,this.specs.projectionBackCulling_3D);this.gl.setMatrixUniforms=function(i,g){var f=this.getUniformLocation(this.program,"u_projection_matrix");this.uniformMatrix4fv(f,false,new WebGLFloatArray(i.flatten()));var e=this.getUniformLocation(this.program,"u_model_view_matrix");this.uniformMatrix4fv(e,false,new WebGLFloatArray(g.flatten()));var h=g.inverse().transpose();var d=this.getUniformLocation(this.program,"u_normal_matrix");this.uniformMatrix4fv(d,false,new WebGLFloatArray(h.flatten()))}};this.lastPoint=null;this.mousedown=function(d){this.lastPoint=d.p};this.rightmousedown=function(d){this.lastPoint=d.p};this.drag=function(i){if(ALT){var g=new Point(i.p.x,i.p.y);g.sub(this.lastPoint);this.translationMatrix=this.translationMatrix.add(Matrix.Translation($V([g.x/20,-g.y/20,0])).ensure4x4()).subtract(Matrix.I(4));this.lastPoint=i.p;this.repaint()}else{var h=Math.max(this.width/4,this.height/4);var f=i.p.x-this.lastPoint.x;var d=i.p.y-this.lastPoint.y;var j=Matrix.Rotation(f*Math.PI/180,$V([0,1,0])).ensure4x4();j=j.x(Matrix.Rotation(d*Math.PI/180,$V([1,0,0])).ensure4x4());this.rotationMatrix=j.x(this.rotationMatrix);this.lastPoint=i.p;this.repaint()}};this.mousewheel=function(d,f){this.translationMatrix=this.translationMatrix.add(Matrix.Translation($V([0,0,f])).ensure4x4()).subtract(Matrix.I(4));this.repaint()};return true}Canvas3D.prototype=new Canvas();function MolGrabberCanvas3D(d,b,a,c){if(d){this.create(d,b,a)}form='<br><form name="MolGrabberForm3D" method="POST" action="'+c+'" target="HiddenMolGrabberFrame3D" onSubmit="ValidateMolecule(MolGrabberForm3D); return false;"><input type="hidden" name="dim" value="3" /><input type="text" name="q" value="" /><input type="submit" name="submitbutton" value="Show Molecule" /></form><iframe id="HMGF3D-'+d+'" name="HiddenMolGrabberFrame3D" height="0" width="0" style="display:none;" onLoad="Get3DMolFromFrame(\'HMGF3D-'+d+"', "+d+')"></iframe>';document.writeln(form);this.emptyMessage="Enter search term below";this.setSearchTerm=function(e){document.MolGrabberForm3D.q.value=e;document.MolGrabberForm3D.submit()};return true}MolGrabberCanvas3D.prototype=new Canvas3D();function RotatorCanvas3D(d,c,b){if(d){this.create(d,c,b)}this.handle=null;this.timeout=33;this.startAnimation=function(){this.stopAnimation();var e=this;if(this.nextFrame){this.handle=setInterval(function(){e.nextFrame();e.repaint()},this.timeout)}};this.stopAnimation=function(){if(this.handle!=null){clearInterval(this.handle);this.handle=null}};this.isRunning=function(){return this.handle!=null};var a=Math.PI/360;this.xIncrement=a;this.yIncrement=a;this.zIncrement=a;this.nextFrame=function(){if(this.molecule==null){this.stopAnimation();return}var g=$M([[Math.cos(this.zIncrement),-Math.sin(this.zIncrement),0],[Math.sin(this.zIncrement),Math.cos(this.zIncrement),0],[0,0,1]]);var e=$M([[Math.cos(-this.yIncrement),0,Math.sin(-this.yIncrement)],[0,1,0],[-Math.sin(-this.yIncrement),0,Math.cos(-this.yIncrement)]]);var f=$M([[1,0,0],[0,Math.cos(this.xIncrement),-Math.sin(this.xIncrement)],[0,Math.sin(this.xIncrement),Math.cos(this.xIncrement)]]);this.rotationMatrix=this.rotationMatrix.x(g.x(e.x(f)).ensure4x4())};this.mousedown=null;this.rightmousedown=null;this.drag=null;this.mousewheel=null;return true}RotatorCanvas3D.prototype=new Canvas3D();function TransformCanvas3D(c,b,a){if(c){this.create(c,b,a)}return true}TransformCanvas3D.prototype=new Canvas3D();function ViewerCanvas3D(c,b,a){if(c){this.create(c,b,a)}this.mousedown=null;this.rightmousedown=null;this.drag=null;this.mousewheel=null;return true}ViewerCanvas3D.prototype=new Canvas3D();var LEEWAY=1.1;function getPointsPerAngstrom(){return default_bondLength_2D/default_angstromsPerBondLength}function deduceCovalentBonds(a,g){var e=getPointsPerAngstrom();if(g){e=g}for(var d=0;d<a.atoms.length;d++){for(var c=d+1;c<a.atoms.length;c++){var f=a.atoms[d];var b=a.atoms[c];if(f.distance3D(b)<(ELEMENT[f.label].covalentRadius+ELEMENT[b.label].covalentRadius)*e*LEEWAY){a.bonds[a.bonds.length]=new Bond(f,b,1)}}}}function removeHydrogens(a){var b=[];var d=[];for(var c=0;c<a.bonds.length;c++){if(a.bonds[c].a1.label!="H"&&a.bonds[c].a2.label!="H"){d[d.length]=a.bonds[c]}}for(var c=0;c<a.atoms.length;c++){if(a.atoms[c].label!="H"){b[b.length]=a.atoms[c]}}a.atoms=b;a.bonds=d}function Link(a){this.data=a;this.next=null;this.reverse=function(b){if(this.next!=null){this.next.reverse(this)}this.next=b};this.getDataArray=function(b){b[b.length]=a;if(this.next!=null){this.next.getDataArray(b)}};this.count=function(){if(this.next==null){return 1}else{return 1+this.next.count()}}}function PGraphEdge(b,a){if(b!=null){this.head=new Link(b);this.head.next=new Link(a)}this.getLast=function(){var c=this.head;while(c.next!=null){c=c.next}return c};this.getCopy=function(){var e=new PGraphEdge();var d=this.head;var c=new Link(d.data);e.head=c;while(d.next!=null){d=d.next;c.next=new Link(d.data);c=c.next}return e};this.merge=function(c){var d=this.getCopy();var f=this.head.data;if(c.head.data!=f&&c.getLast().data!=f){f=this.getLast().data}var e=c.getCopy();if(d.head.data==f){d.reverse()}if(c.head.data!=f){e.reverse()}e.head=e.head.next;d.getLast().next=e.head;return d};this.connectsTo=function(c){return this.head.data==c||this.getLast().data==c};this.isCycle=function(){return this.head.data==this.getLast().data};this.size=function(){return this.head.count()};this.reverse=function(){var c=this.getLast();this.head.reverse(null);this.head=c}}function indexOf(c,b){for(var a=0;a<c.length;a++){if(c[a]==b){return a}}return -1}function getRingsSSSR(l){var r=[];var A=[];for(var x=0;x<l.bonds.length;x++){r[r.length]=new PGraphEdge(indexOf(l.atoms,l.bonds[x].a1),indexOf(l.atoms,l.bonds[x].a2))}while(r.length>0){var z=new Array(l.atoms.length);for(var x=0;x<z.length;x++){z[x]=0}for(var x=0;x<r.length;x++){z[r[x].head.data]++;z[r[x].getLast().data]++}var c=-1;var t=Infinity;for(var x=0;x<z.length;x++){if(z[x]>0&&z[x]<t){t=z[x];c=x}}var d=[];var y=[];for(var x=0;x<r.length;x++){if(r[x].connectsTo(c)){d[d.length]=r[x]}else{y[y.length]=r[x]}}r=y;for(var x=0;x<d.length;x++){for(var w=x+1;w<d.length;w++){var s=d[x];var h=d[w];var p=s.merge(h);var a=false;var q=p.head.next;while(!a&&q!=null){var m=q.next;while(!a&&m!=null){if(m.data==q.data){a=true}m=m.next}q=q.next}if(!a){if(p.isCycle()){A[A.length]=p}else{r[r.length]=p}}}}}var f=new Array(A.length);var b=[];for(var x=0;x<A.length;x++){b[x]=A[x].size();f[x]=false}var o=l.bonds.length-l.atoms.length+(l.atoms.length>0?1:0);var v=new Array(o);for(var x=0;x<o;x++){var t=Infinity;var e=-1;for(var w=0;w<b.length;w++){if(!f[w]&&b[w]<t){t=b[w];e=w}}v[x]=[];if(e!=-1){A[e].head.getDataArray(v[x]);f[e]=true}}var n=new Array(v.length);for(var x=0;x<v.length;x++){var g=new Ring();for(var w=0;w<v[x].length-1;w++){g.atoms[w]=l.atoms[v[x][w]]}for(var w=0;w<g.atoms.length-1;w++){for(var u=0;u<l.bonds.length;u++){if(l.bonds[u].contains(g.atoms[w])&&l.bonds[u].contains(g.atoms[w+1])){g.bonds[g.bonds.length]=l.bonds[u];break}}}for(var u=0;u<l.bonds.length;u++){if(l.bonds[u].contains(g.atoms[0])&&l.bonds[u].contains(g.atoms[g.atoms.length-1])){g.bonds[g.bonds.length]=l.bonds[u];break}}n[x]=g}return n}function copy(a){for(var c=0;c<a.atoms.length;c++){a.atoms[c].metaID=c}var b=new Molecule();for(var c=0;c<a.atoms.length;c++){b.atoms[c]=new Atom(a.atoms[c].label,a.atoms[c].x,a.atoms[c].y,a.atoms[c].z)}for(var c=0;c<a.bonds.length;c++){b.bonds[c]=new Bond(b.atoms[a.bonds[c].a1.metaID],b.atoms[a.bonds[c].a2.metaID],a.bonds[c].bondOrder)}return b}function Element(c,b,a){this.symbol=c;this.name=b;this.atomicNumber=a;return true}var ELEMENT=new Array();ELEMENT.H=new Element("H","Hydrogen",1);ELEMENT.He=new Element("He","Helium",2);ELEMENT.Li=new Element("Li","Lithium",3);ELEMENT.Be=new Element("Be","Beryllium",4);ELEMENT.B=new Element("B","Boron",5);ELEMENT.C=new Element("C","Carbon",6);ELEMENT.N=new Element("N","Nitrogen",7);ELEMENT.O=new Element("O","Oxygen",8);ELEMENT.F=new Element("F","Fluorine",9);ELEMENT.Ne=new Element("Ne","Neon",10);ELEMENT.Na=new Element("Na","Sodium",11);ELEMENT.Mg=new Element("Mg","Magnesium",12);ELEMENT.Al=new Element("Al","Aluminum",13);ELEMENT.Si=new Element("Si","Silicon",14);ELEMENT.P=new Element("P","Phosphorus",15);ELEMENT.S=new Element("S","Sulfur",16);ELEMENT.Cl=new Element("Cl","Chlorine",17);ELEMENT.Ar=new Element("Ar","Argon",18);ELEMENT.K=new Element("K","Potassium",19);ELEMENT.Ca=new Element("Ca","Calcium",20);ELEMENT.Sc=new Element("Sc","Scandium",21);ELEMENT.Ti=new Element("Ti","Titanium",22);ELEMENT.V=new Element("V","Vanadium",23);ELEMENT.Cr=new Element("Cr","Chromium",24);ELEMENT.Mn=new Element("Mn","Manganese",25);ELEMENT.Fe=new Element("Fe","Iron",26);ELEMENT.Co=new Element("Co","Cobalt",27);ELEMENT.Ni=new Element("Ni","Nickel",28);ELEMENT.Cu=new Element("Cu","Copper",29);ELEMENT.Zn=new Element("Zn","Zinc",30);ELEMENT.Ga=new Element("Ga","Gallium",31);ELEMENT.Ge=new Element("Ge","Germanium",32);ELEMENT.As=new Element("As","Arsenic",33);ELEMENT.Se=new Element("Se","Selenium",34);ELEMENT.Br=new Element("Br","Bromine",35);ELEMENT.Kr=new Element("Kr","Krypton",36);ELEMENT.Rb=new Element("Rb","Rubidium",37);ELEMENT.Sr=new Element("Sr","Strontium",38);ELEMENT.Y=new Element("Y","Yttrium",39);ELEMENT.Zr=new Element("Zr","Zirconium",40);ELEMENT.Nb=new Element("Nb","Niobium",41);ELEMENT.Mo=new Element("Mo","Molybdenum",42);ELEMENT.Tc=new Element("Tc","Technetium",43);ELEMENT.Ru=new Element("Ru","Ruthenium",44);ELEMENT.Rh=new Element("Rh","Rhodium",45);ELEMENT.Pd=new Element("Pd","Palladium",46);ELEMENT.Ag=new Element("Ag","Silver",47);ELEMENT.Cd=new Element("Cd","Cadmium",48);ELEMENT.In=new Element("In","Indium",49);ELEMENT.Sn=new Element("Sn","Tin",50);ELEMENT.Sb=new Element("Sb","Antimony",51);ELEMENT.Te=new Element("Te","Tellurium",52);ELEMENT.I=new Element("I","Iodine",53);ELEMENT.Xe=new Element("Xe","Xenon",54);ELEMENT.Cs=new Element("Cs","Cesium",55);ELEMENT.Ba=new Element("Ba","Barium",56);ELEMENT.La=new Element("La","Lanthanum",57);ELEMENT.Ce=new Element("Ce","Cerium",58);ELEMENT.Pr=new Element("Pr","Praseodymium",59);ELEMENT.Nd=new Element("Nd","Neodymium",60);ELEMENT.Pm=new Element("Pm","Promethium",61);ELEMENT.Sm=new Element("Sm","Samarium",62);ELEMENT.Eu=new Element("Eu","Europium",63);ELEMENT.Gd=new Element("Gd","Gadolinium",64);ELEMENT.Tb=new Element("Tb","Terbium",65);ELEMENT.Dy=new Element("Dy","Dysprosium",66);ELEMENT.Ho=new Element("Ho","Holmium",67);ELEMENT.Er=new Element("Er","Erbium",68);ELEMENT.Tm=new Element("Tm","Thulium",69);ELEMENT.Yb=new Element("Yb","Ytterbium",70);ELEMENT.Lu=new Element("Lu","Lutetium",71);ELEMENT.Hf=new Element("Hf","Hafnium",72);ELEMENT.Ta=new Element("Ta","Tantalum",73);ELEMENT.W=new Element("W","Tungsten",74);ELEMENT.Re=new Element("Re","Rhenium",75);ELEMENT.Os=new Element("Os","Osmium",76);ELEMENT.Ir=new Element("Ir","Iridium",77);ELEMENT.Pt=new Element("Pt","Platinum",78);ELEMENT.Au=new Element("Au","Gold",79);ELEMENT.Hg=new Element("Hg","Mercury",80);ELEMENT.Tl=new Element("Tl","Thallium",81);ELEMENT.Pb=new Element("Pb","Lead",82);ELEMENT.Bi=new Element("Bi","Bismuth",83);ELEMENT.Po=new Element("Po","Polonium",84);ELEMENT.At=new Element("At","Astatine",85);ELEMENT.Rn=new Element("Rn","Radon",86);ELEMENT.Fr=new Element("Fr","Francium",87);ELEMENT.Ra=new Element("Ra","Radium",88);ELEMENT.Ac=new Element("Ac","Actinium",89);ELEMENT.Th=new Element("Th","Thorium",90);ELEMENT.Pa=new Element("Pa","Protactinium",91);ELEMENT.U=new Element("U","Uranium",92);ELEMENT.Np=new Element("Np","Neptunium",93);ELEMENT.Pu=new Element("Pu","Plutonium",94);ELEMENT.Am=new Element("Am","Americium",95);ELEMENT.Cm=new Element("Cm","Curium",96);ELEMENT.Bk=new Element("Bk","Berkelium",97);ELEMENT.Cf=new Element("Cf","Californium",98);ELEMENT.Es=new Element("Es","Einsteinium",99);ELEMENT.Fm=new Element("Fm","Fermium",100);ELEMENT.Md=new Element("Md","Mendelevium",101);ELEMENT.No=new Element("No","Nobelium",102);ELEMENT.Lr=new Element("Lr","Lawrencium",103);ELEMENT.Rf=new Element("Rf","Rutherfordium",104);ELEMENT.Db=new Element("Db","Dubnium",105);ELEMENT.Sg=new Element("Sg","Seaborgium",106);ELEMENT.Bh=new Element("Bh","Bohrium",107);ELEMENT.Hs=new Element("Hs","Hassium",108);ELEMENT.Mt=new Element("Mt","Meitnerium",109);ELEMENT.Ds=new Element("Ds","Darmstadtium",110);ELEMENT.Rg=new Element("Rg","Roentgenium",111);ELEMENT.Uub=new Element("Uub","Ununbium",112);ELEMENT.Uut=new Element("Uut","Ununtrium",113);ELEMENT.Uuq=new Element("Uuq","Ununquadium",114);ELEMENT.Uup=new Element("Uup","Ununpentium",115);ELEMENT.Uuh=new Element("Uuh","Ununhexium",116);ELEMENT.Uus=new Element("Uus","Ununseptium",117);ELEMENT.Uuo=new Element("Uuo","Ununoctium",118);var symbols=["H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr","Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Uub","Uut","Uuq","Uup","Uuh","Uus","Uuo"];ELEMENT.H.jmolColor="#FFFFFF";ELEMENT.He.jmolColor="#D9FFFF";ELEMENT.Li.jmolColor="#CC80FF";ELEMENT.Be.jmolColor="#C2FF00";ELEMENT.B.jmolColor="#FFB5B5";ELEMENT.C.jmolColor="#909090";ELEMENT.N.jmolColor="#3050F8";ELEMENT.O.jmolColor="#FF0D0D";ELEMENT.F.jmolColor="#90E050";ELEMENT.Ne.jmolColor="#B3E3F5";ELEMENT.Na.jmolColor="#AB5CF2";ELEMENT.Mg.jmolColor="#8AFF00";ELEMENT.Al.jmolColor="#BFA6A6";ELEMENT.Si.jmolColor="#F0C8A0";ELEMENT.P.jmolColor="#FF8000";ELEMENT.S.jmolColor="#FFFF30";ELEMENT.Cl.jmolColor="#1FF01F";ELEMENT.Ar.jmolColor="#80D1E3";ELEMENT.K.jmolColor="#8F40D4";ELEMENT.Ca.jmolColor="#3DFF00";ELEMENT.Sc.jmolColor="#E6E6E6";ELEMENT.Ti.jmolColor="#BFC2C7";ELEMENT.V.jmolColor="#A6A6AB";ELEMENT.Cr.jmolColor="#8A99C7";ELEMENT.Mn.jmolColor="#9C7AC7";ELEMENT.Fe.jmolColor="#E06633";ELEMENT.Co.jmolColor="#F090A0";ELEMENT.Ni.jmolColor="#50D050";ELEMENT.Cu.jmolColor="#C88033";ELEMENT.Zn.jmolColor="#7D80B0";ELEMENT.Ga.jmolColor="#C28F8F";ELEMENT.Ge.jmolColor="#668F8F";ELEMENT.As.jmolColor="#BD80E3";ELEMENT.Se.jmolColor="#FFA100";ELEMENT.Br.jmolColor="#A62929";ELEMENT.Kr.jmolColor="#5CB8D1";ELEMENT.Rb.jmolColor="#702EB0";ELEMENT.Sr.jmolColor="#00FF00";ELEMENT.Y.jmolColor="#94FFFF";ELEMENT.Zr.jmolColor="#94E0E0";ELEMENT.Nb.jmolColor="#73C2C9";ELEMENT.Mo.jmolColor="#54B5B5";ELEMENT.Tc.jmolColor="#3B9E9E";ELEMENT.Ru.jmolColor="#248F8F";ELEMENT.Rh.jmolColor="#0A7D8C";ELEMENT.Pd.jmolColor="#006985";ELEMENT.Ag.jmolColor="#C0C0C0";ELEMENT.Cd.jmolColor="#FFD98F";ELEMENT.In.jmolColor="#A67573";ELEMENT.Sn.jmolColor="#668080";ELEMENT.Sb.jmolColor="#9E63B5";ELEMENT.Te.jmolColor="#D47A00";ELEMENT.I.jmolColor="#940094";ELEMENT.Xe.jmolColor="#429EB0";ELEMENT.Cs.jmolColor="#57178F";ELEMENT.Ba.jmolColor="#00C900";ELEMENT.La.jmolColor="#70D4FF";ELEMENT.Ce.jmolColor="#FFFFC7";ELEMENT.Pr.jmolColor="#D9FFC7";ELEMENT.Nd.jmolColor="#C7FFC7";ELEMENT.Pm.jmolColor="#A3FFC7";ELEMENT.Sm.jmolColor="#8FFFC7";ELEMENT.Eu.jmolColor="#61FFC7";ELEMENT.Gd.jmolColor="#45FFC7";ELEMENT.Tb.jmolColor="#30FFC7";ELEMENT.Dy.jmolColor="#1FFFC7";ELEMENT.Ho.jmolColor="#00FF9C";ELEMENT.Er.jmolColor="#00E675";ELEMENT.Tm.jmolColor="#00D452";ELEMENT.Yb.jmolColor="#00BF38";ELEMENT.Lu.jmolColor="#00AB24";ELEMENT.Hf.jmolColor="#4DC2FF";ELEMENT.Ta.jmolColor="#4DA6FF";ELEMENT.W.jmolColor="#2194D6";ELEMENT.Re.jmolColor="#267DAB";ELEMENT.Os.jmolColor="#266696";ELEMENT.Ir.jmolColor="#175487";ELEMENT.Pt.jmolColor="#D0D0E0";ELEMENT.Au.jmolColor="#FFD123";ELEMENT.Hg.jmolColor="#B8B8D0";ELEMENT.Tl.jmolColor="#A6544D";ELEMENT.Pb.jmolColor="#575961";ELEMENT.Bi.jmolColor="#9E4FB5";ELEMENT.Po.jmolColor="#AB5C00";ELEMENT.At.jmolColor="#754F45";ELEMENT.Rn.jmolColor="#428296";ELEMENT.Fr.jmolColor="#420066";ELEMENT.Ra.jmolColor="#007D00";ELEMENT.Ac.jmolColor="#70ABFA";ELEMENT.Th.jmolColor="#00BAFF";ELEMENT.Pa.jmolColor="#00A1FF";ELEMENT.U.jmolColor="#008FFF";ELEMENT.Np.jmolColor="#0080FF";ELEMENT.Pu.jmolColor="#006BFF";ELEMENT.Am.jmolColor="#545CF2";ELEMENT.Cm.jmolColor="#785CE3";ELEMENT.Bk.jmolColor="#8A4FE3";ELEMENT.Cf.jmolColor="#A136D4";ELEMENT.Es.jmolColor="#B31FD4";ELEMENT.Fm.jmolColor="#B31FBA";ELEMENT.Md.jmolColor="#B30DA6";ELEMENT.No.jmolColor="#BD0D87";ELEMENT.Lr.jmolColor="#C70066";ELEMENT.Rf.jmolColor="#CC0059";ELEMENT.Db.jmolColor="#D1004F";ELEMENT.Sg.jmolColor="#D90045";ELEMENT.Bh.jmolColor="#E00038";ELEMENT.Hs.jmolColor="#E6002E";ELEMENT.Mt.jmolColor="#EB0026";ELEMENT.Ds.jmolColor="#000000";ELEMENT.Rg.jmolColor="#000000";ELEMENT.Uub.jmolColor="#000000";ELEMENT.Uut.jmolColor="#000000";ELEMENT.Uuq.jmolColor="#000000";ELEMENT.Uup.jmolColor="#000000";ELEMENT.Uuh.jmolColor="#000000";ELEMENT.Uus.jmolColor="#000000";ELEMENT.Uuo.jmolColor="#000000";ELEMENT.H.covalentRadius=0.31;ELEMENT.He.covalentRadius=0.28;ELEMENT.Li.covalentRadius=1.28;ELEMENT.Be.covalentRadius=0.96;ELEMENT.B.covalentRadius=0.84;ELEMENT.C.covalentRadius=0.76;ELEMENT.N.covalentRadius=0.71;ELEMENT.O.covalentRadius=0.66;ELEMENT.F.covalentRadius=0.57;ELEMENT.Ne.covalentRadius=0.58;ELEMENT.Na.covalentRadius=1.66;ELEMENT.Mg.covalentRadius=1.41;ELEMENT.Al.covalentRadius=1.21;ELEMENT.Si.covalentRadius=1.11;ELEMENT.P.covalentRadius=1.07;ELEMENT.S.covalentRadius=1.05;ELEMENT.Cl.covalentRadius=1.02;ELEMENT.Ar.covalentRadius=1.06;ELEMENT.K.covalentRadius=2.03;ELEMENT.Ca.covalentRadius=1.76;ELEMENT.Sc.covalentRadius=1.7;ELEMENT.Ti.covalentRadius=1.6;ELEMENT.V.covalentRadius=1.53;ELEMENT.Cr.covalentRadius=1.39;ELEMENT.Mn.covalentRadius=1.39;ELEMENT.Fe.covalentRadius=1.32;ELEMENT.Co.covalentRadius=1.26;ELEMENT.Ni.covalentRadius=1.24;ELEMENT.Cu.covalentRadius=1.32;ELEMENT.Zn.covalentRadius=1.22;ELEMENT.Ga.covalentRadius=1.22;ELEMENT.Ge.covalentRadius=1.2;ELEMENT.As.covalentRadius=1.19;ELEMENT.Se.covalentRadius=1.2;ELEMENT.Br.covalentRadius=1.2;ELEMENT.Kr.covalentRadius=1.16;ELEMENT.Rb.covalentRadius=2.2;ELEMENT.Sr.covalentRadius=1.95;ELEMENT.Y.covalentRadius=1.9;ELEMENT.Zr.covalentRadius=1.75;ELEMENT.Nb.covalentRadius=1.64;ELEMENT.Mo.covalentRadius=1.54;ELEMENT.Tc.covalentRadius=1.47;ELEMENT.Ru.covalentRadius=1.46;ELEMENT.Rh.covalentRadius=1.42;ELEMENT.Pd.covalentRadius=1.39;ELEMENT.Ag.covalentRadius=1.45;ELEMENT.Cd.covalentRadius=1.44;ELEMENT.In.covalentRadius=1.42;ELEMENT.Sn.covalentRadius=1.39;ELEMENT.Sb.covalentRadius=1.39;ELEMENT.Te.covalentRadius=1.38;ELEMENT.I.covalentRadius=1.39;ELEMENT.Xe.covalentRadius=1.4;ELEMENT.Cs.covalentRadius=2.44;ELEMENT.Ba.covalentRadius=2.15;ELEMENT.La.covalentRadius=2.07;ELEMENT.Ce.covalentRadius=2.04;ELEMENT.Pr.covalentRadius=2.03;ELEMENT.Nd.covalentRadius=2.01;ELEMENT.Pm.covalentRadius=1.99;ELEMENT.Sm.covalentRadius=1.98;ELEMENT.Eu.covalentRadius=1.98;ELEMENT.Gd.covalentRadius=1.96;ELEMENT.Tb.covalentRadius=1.94;ELEMENT.Dy.covalentRadius=1.92;ELEMENT.Ho.covalentRadius=1.92;ELEMENT.Er.covalentRadius=1.89;ELEMENT.Tm.covalentRadius=1.9;ELEMENT.Yb.covalentRadius=1.87;ELEMENT.Lu.covalentRadius=1.87;ELEMENT.Hf.covalentRadius=1.75;ELEMENT.Ta.covalentRadius=1.7;ELEMENT.W.covalentRadius=1.62;ELEMENT.Re.covalentRadius=1.51;ELEMENT.Os.covalentRadius=1.44;ELEMENT.Ir.covalentRadius=1.41;ELEMENT.Pt.covalentRadius=1.36;ELEMENT.Au.covalentRadius=1.36;ELEMENT.Hg.covalentRadius=1.32;ELEMENT.Tl.covalentRadius=1.45;ELEMENT.Pb.covalentRadius=1.46;ELEMENT.Bi.covalentRadius=1.48;ELEMENT.Po.covalentRadius=1.4;ELEMENT.At.covalentRadius=1.5;ELEMENT.Rn.covalentRadius=1.5;ELEMENT.Fr.covalentRadius=2.6;ELEMENT.Ra.covalentRadius=2.21;ELEMENT.Ac.covalentRadius=2.15;ELEMENT.Th.covalentRadius=2.06;ELEMENT.Pa.covalentRadius=2;ELEMENT.U.covalentRadius=1.96;ELEMENT.Np.covalentRadius=1.9;ELEMENT.Pu.covalentRadius=1.87;ELEMENT.Am.covalentRadius=1.8;ELEMENT.Cm.covalentRadius=1.69;ELEMENT.Bk.covalentRadius=0;ELEMENT.Cf.covalentRadius=0;ELEMENT.Es.covalentRadius=0;ELEMENT.Fm.covalentRadius=0;ELEMENT.Md.covalentRadius=0;ELEMENT.No.covalentRadius=0;ELEMENT.Lr.covalentRadius=0;ELEMENT.Rf.covalentRadius=0;ELEMENT.Db.covalentRadius=0;ELEMENT.Sg.covalentRadius=0;ELEMENT.Bh.covalentRadius=0;ELEMENT.Hs.covalentRadius=0;ELEMENT.Mt.covalentRadius=0;ELEMENT.Ds.covalentRadius=0;ELEMENT.Rg.covalentRadius=0;ELEMENT.Uub.covalentRadius=0;ELEMENT.Uut.covalentRadius=0;ELEMENT.Uuq.covalentRadius=0;ELEMENT.Uup.covalentRadius=0;ELEMENT.Uuh.covalentRadius=0;ELEMENT.Uus.covalentRadius=0;ELEMENT.Uuo.covalentRadius=0;ELEMENT.H.vdWRadius=1.2;ELEMENT.He.vdWRadius=1.4;ELEMENT.Li.vdWRadius=1.82;ELEMENT.Be.vdWRadius=0;ELEMENT.B.vdWRadius=0;ELEMENT.C.vdWRadius=1.7;ELEMENT.N.vdWRadius=1.55;ELEMENT.O.vdWRadius=1.52;ELEMENT.F.vdWRadius=1.47;ELEMENT.Ne.vdWRadius=1.54;ELEMENT.Na.vdWRadius=2.27;ELEMENT.Mg.vdWRadius=1.73;ELEMENT.Al.vdWRadius=0;ELEMENT.Si.vdWRadius=2.1;ELEMENT.P.vdWRadius=1.8;ELEMENT.S.vdWRadius=1.8;ELEMENT.Cl.vdWRadius=1.75;ELEMENT.Ar.vdWRadius=1.88;ELEMENT.K.vdWRadius=2.75;ELEMENT.Ca.vdWRadius=0;ELEMENT.Sc.vdWRadius=0;ELEMENT.Ti.vdWRadius=0;ELEMENT.V.vdWRadius=0;ELEMENT.Cr.vdWRadius=0;ELEMENT.Mn.vdWRadius=0;ELEMENT.Fe.vdWRadius=0;ELEMENT.Co.vdWRadius=0;ELEMENT.Ni.vdWRadius=1.63;ELEMENT.Cu.vdWRadius=1.4;ELEMENT.Zn.vdWRadius=1.39;ELEMENT.Ga.vdWRadius=1.87;ELEMENT.Ge.vdWRadius=0;ELEMENT.As.vdWRadius=1.85;ELEMENT.Se.vdWRadius=1.9;ELEMENT.Br.vdWRadius=1.85;ELEMENT.Kr.vdWRadius=2.02;ELEMENT.Rb.vdWRadius=0;ELEMENT.Sr.vdWRadius=0;ELEMENT.Y.vdWRadius=0;ELEMENT.Zr.vdWRadius=0;ELEMENT.Nb.vdWRadius=0;ELEMENT.Mo.vdWRadius=0;ELEMENT.Tc.vdWRadius=0;ELEMENT.Ru.vdWRadius=0;ELEMENT.Rh.vdWRadius=0;ELEMENT.Pd.vdWRadius=1.63;ELEMENT.Ag.vdWRadius=1.72;ELEMENT.Cd.vdWRadius=1.58;ELEMENT.In.vdWRadius=1.93;ELEMENT.Sn.vdWRadius=2.17;ELEMENT.Sb.vdWRadius=0;ELEMENT.Te.vdWRadius=2.06;ELEMENT.I.vdWRadius=1.98;ELEMENT.Xe.vdWRadius=2.16;ELEMENT.Cs.vdWRadius=0;ELEMENT.Ba.vdWRadius=0;ELEMENT.La.vdWRadius=0;ELEMENT.Ce.vdWRadius=0;ELEMENT.Pr.vdWRadius=0;ELEMENT.Nd.vdWRadius=0;ELEMENT.Pm.vdWRadius=0;ELEMENT.Sm.vdWRadius=0;ELEMENT.Eu.vdWRadius=0;ELEMENT.Gd.vdWRadius=0;ELEMENT.Tb.vdWRadius=0;ELEMENT.Dy.vdWRadius=0;ELEMENT.Ho.vdWRadius=0;ELEMENT.Er.vdWRadius=0;ELEMENT.Tm.vdWRadius=0;ELEMENT.Yb.vdWRadius=0;ELEMENT.Lu.vdWRadius=0;ELEMENT.Hf.vdWRadius=0;ELEMENT.Ta.vdWRadius=0;ELEMENT.W.vdWRadius=0;ELEMENT.Re.vdWRadius=0;ELEMENT.Os.vdWRadius=0;ELEMENT.Ir.vdWRadius=0;ELEMENT.Pt.vdWRadius=1.75;ELEMENT.Au.vdWRadius=1.66;ELEMENT.Hg.vdWRadius=1.55;ELEMENT.Tl.vdWRadius=1.96;ELEMENT.Pb.vdWRadius=2.02;ELEMENT.Bi.vdWRadius=0;ELEMENT.Po.vdWRadius=0;ELEMENT.At.vdWRadius=0;ELEMENT.Rn.vdWRadius=0;ELEMENT.Fr.vdWRadius=0;ELEMENT.Ra.vdWRadius=0;ELEMENT.Ac.vdWRadius=0;ELEMENT.Th.vdWRadius=0;ELEMENT.Pa.vdWRadius=0;ELEMENT.U.vdWRadius=1.86;ELEMENT.Np.vdWRadius=0;ELEMENT.Pu.vdWRadius=0;ELEMENT.Am.vdWRadius=0;ELEMENT.Cm.vdWRadius=0;ELEMENT.Bk.vdWRadius=0;ELEMENT.Cf.vdWRadius=0;ELEMENT.Es.vdWRadius=0;ELEMENT.Fm.vdWRadius=0;ELEMENT.Md.vdWRadius=0;ELEMENT.No.vdWRadius=0;ELEMENT.Lr.vdWRadius=0;ELEMENT.Rf.vdWRadius=0;ELEMENT.Db.vdWRadius=0;ELEMENT.Sg.vdWRadius=0;ELEMENT.Bh.vdWRadius=0;ELEMENT.Hs.vdWRadius=0;ELEMENT.Mt.vdWRadius=0;ELEMENT.Ds.vdWRadius=0;ELEMENT.Rg.vdWRadius=0;ELEMENT.Uub.vdWRadius=0;ELEMENT.Uut.vdWRadius=0;ELEMENT.Uuq.vdWRadius=0;ELEMENT.Uup.vdWRadius=0;ELEMENT.Uuh.vdWRadius=0;ELEMENT.Uus.vdWRadius=0;ELEMENT.Uuo.vdWRadius=0;function Point(a,b){this.x=a?a:0;this.y=b?b:0;this.sub=function(c){this.x-=c.x;this.y-=c.y};this.add=function(c){this.x+=c.x;this.y+=c.y};this.distance=function(c){return Math.sqrt(Math.pow(c.x-this.x,2)+Math.pow(c.y-this.y,2))};this.angleForStupidCanvasArcs=function(e){var d=e.x-this.x;var c=e.y-this.y;var f=0;if(d==0){if(c==0){f=0}else{if(c>0){f=Math.PI/2}else{f=3*Math.PI/2}}}else{if(c==0){if(d>0){f=0}else{f=Math.PI}}else{if(d<0){f=Math.atan(c/d)+Math.PI}else{if(c<0){f=Math.atan(c/d)+2*Math.PI}else{f=Math.atan(c/d)}}}}while(f<0){f+=Math.PI*2}f=f%(Math.PI*2);return f};this.angle=function(e){var d=e.x-this.x;var c=this.y-e.y;var f=0;if(d==0){if(c==0){f=0}else{if(c>0){f=Math.PI/2}else{f=3*Math.PI/2}}}else{if(c==0){if(d>0){f=0}else{f=Math.PI}}else{if(d<0){f=Math.atan(c/d)+Math.PI}else{if(c<0){f=Math.atan(c/d)+2*Math.PI}else{f=Math.atan(c/d)}}}}while(f<0){f+=Math.PI*2}f=f%(Math.PI*2);return f};return true}function Ring(){this.atoms=[];this.bonds=[];this.center=null;this.setupBonds=function(){for(var a=0;a<this.bonds.length;a++){this.bonds[a].ring=this}this.center=this.getCenter()};this.getCenter=function(){var a=minY=Infinity;var c=maxY=-Infinity;for(var b=0;b<this.atoms.length;b++){a=Math.min(this.atoms[b].x,a);minY=Math.min(this.atoms[b].y,minY);c=Math.max(this.atoms[b].x,c);maxY=Math.max(this.atoms[b].y,maxY)}return new Point((c+a)/2,(maxY+minY)/2)}}function Atom(b,a,d,c){this.x=a?a:0;this.y=d?d:0;this.z=c?c:0;this.label=b?b.replace(/\s/g,""):"C";if(!ELEMENT[this.label]){this.label="C"}this.isLone=false;this.isHover=false;this.isSelected=false;this.isOverlap=false;this.add3D=function(e){this.x+=e.x;this.y+=e.y;this.z+=e.z};this.sub3D=function(e){this.x-=e.x;this.y-=e.y;this.z-=e.z};this.distance3D=function(e){return Math.sqrt(Math.pow(e.x-this.x,2)+Math.pow(e.y-this.y,2)+Math.pow(e.z-this.z,2))};this.draw=function(e,j){e.fillStyle=j.atoms_color;if(j.atoms_useJMOLColors){e.fillStyle=ELEMENT[this.label].jmolColor}if(this.isLone||j.atoms_circles_2D){e.beginPath();e.arc(this.x,this.y,j.atoms_circleDiameter_2D/2,0,Math.PI*2,false);e.fill();if(j.atoms_circleBorderWidth_2D>0){e.lineWidth=j.atoms_circleBorderWidth_2D;e.strokeStyle="black";e.stroke(this.x,this.y,0,Math.PI*2,j.atoms_circleDiameter_2D/2)}}else{if(this.isLabelVisible()){var f=j.atoms_font_size_2D+"px ";for(var g=0;g<j.atoms_font_families_2D.length;g++){var h=",";if(g==j.atoms_font_families_2D.length-1){h=""}f=f+j.atoms_font_families_2D[g]+h}e.font=f;e.textAlign="center";e.textBaseline="middle";e.fillText(this.label,this.x,this.y)}}if(this.isHover||this.isSelected||this.isOverlap){e.strokeStyle=this.isHover?"#885110":"#0060B2";e.lineWidth=1.2;e.beginPath();e.arc(this.x,this.y,7,0,Math.PI*2,false);e.stroke()}};this.render=function(h,i){var g=h.modelViewMatrix.x(Matrix.Translation($V([this.x,this.y,this.z])).ensure4x4());var e=i.atoms_useVDWDiameters_3D?ELEMENT[this.label].vdWRadius:i.atoms_sphereDiameter_3D/2;g=g.x(Matrix.I(3).x(e).ensure4x4());h.bindBuffer(h.ARRAY_BUFFER,h.sphereBuffer.vertexPositionBuffer);h.vertexAttribPointer(h.shader.vertexPositionAttribute,h.sphereBuffer.vertexPositionBuffer.itemSize,h.FLOAT,false,0,0);var f=i.atoms_useJMOLColors?ELEMENT[this.label].jmolColor:i.atoms_color;h.material.setTempColors(h,i.atoms_materialAmbientColor_3D,f,i.atoms_materialSpecularColor_3D,i.atoms_materialShininess_3D);h.bindBuffer(h.ARRAY_BUFFER,h.sphereBuffer.vertexNormalBuffer);h.vertexAttribPointer(h.shader.vertexNormalAttribute,h.sphereBuffer.vertexNormalBuffer.itemSize,h.FLOAT,false,0,0);h.bindBuffer(h.ELEMENT_ARRAY_BUFFER,h.sphereBuffer.vertexIndexBuffer);h.setMatrixUniforms(h.projectionMatrix,g);h.drawElements(h.TRIANGLES,h.sphereBuffer.vertexIndexBuffer.numItems,h.UNSIGNED_SHORT,0)};this.isLabelVisible=function(){return this.label!="C"};return true}Atom.prototype=new Point(0,0);var BOND_STEREO_NONE="BOND_STEREO_NONE";var BOND_STEREO_PROTRUDING="BOND_STEREO_PROTRUDING";var BOND_STEREO_RECESSED="BOND_STEREO_RECESSED";var BOND_STEREO_AMBIGUOUS="BOND_STEREO_AMBIGUOUS";function Bond(c,b,a){this.a1=c;this.a2=b;this.bondOrder=a?a:1;this.stereo=BOND_STEREO_NONE;this.isHover=false;this.ring=null;this.getCenter=function(){return new Point((this.a1.x+this.a2.x)/2,(this.a1.y+this.a2.y)/2)};this.contains=function(d){return d==this.a1||d==this.a2};this.getNeighbor=function(d){if(d==this.a1){return this.a2}else{if(d==this.a2){return this.a1}}return null};this.draw=function(r,k){var n=this.a1.x;var m=this.a2.x;var O=this.a1.y;var M=this.a2.y;var B=m-n;var A=M-O;if(k.atoms_display&&!k.atoms_circles_2D&&c.isLabelVisible()){n+=B*k.bonds_atomLabelBuffer_2D;O+=A*k.bonds_atomLabelBuffer_2D}if(k.atoms_display&&!k.atoms_circles_2D&&b.isLabelVisible()){m-=B*k.bonds_atomLabelBuffer_2D;M-=A*k.bonds_atomLabelBuffer_2D}if(k.bonds_clearOverlaps_2D){var x=n+B*0.15;var l=O+A*0.15;var D=m-B*0.15;var s=M-A*0.15;r.strokeStyle=k.backgroundColor;r.lineWidth=k.bonds_width_2D+k.bonds_overlapClearWidth_2D*2;r.lineCap="round";r.beginPath();r.moveTo(x,l);r.lineTo(D,s);r.closePath();r.stroke()}r.strokeStyle=k.bonds_color;r.fillStyle=k.bonds_color;r.lineWidth=k.bonds_width_2D;r.lineCap=k.bonds_ends_2D;if(k.bonds_useJMOLColors){var j=r.createLinearGradient(n,O,m,M);j.addColorStop(0,ELEMENT[this.a1.label].jmolColor);j.addColorStop(1,ELEMENT[this.a2.label].jmolColor);r.strokeStyle=j}switch(this.bondOrder){case 1:if(this.stereo==BOND_STEREO_PROTRUDING||this.stereo==BOND_STEREO_RECESSED){var N=this.a1.distance(this.a2)*k.bonds_wedgeThickness_2D/2;var y=this.a1.angle(this.a2)+Math.PI/2;var F=m+Math.cos(y)*N;var u=M-Math.sin(y)*N;var E=m-Math.cos(y)*N;var t=M+Math.sin(y)*N;r.beginPath();r.moveTo(n,O);r.lineTo(F,u);r.lineTo(E,t);r.closePath();if(this.stereo==BOND_STEREO_PROTRUDING){r.fill()}else{r.save();r.clip();r.beginPath();r.moveTo(n,O);r.lineWidth=N*2;r.lineCap="butt";var z=0;var g=this.a1.distance(this.a2);var K=false;var i=n;var h=O;while(z<g){if(K){var d=k.bonds_hashSpacing_2D/g;i+=d*B;h+=d*A;r.moveTo(i,h);z+=k.bonds_hashSpacing_2D}else{var d=k.bonds_hashWidth_2D/g;i+=d*B;h+=d*A;r.lineTo(i,h);z+=k.bonds_hashWidth_2D}K=!K}r.stroke();r.restore()}}else{r.beginPath();r.moveTo(n,O);r.lineTo(m,M);r.stroke()}break;case 1.5:r.beginPath();r.moveTo(n,O);r.lineTo(m,M);r.stroke();break;case 2:if(this.stereo==BOND_STEREO_AMBIGUOUS){var N=this.a1.distance(this.a2)*k.bonds_saturationWidth_2D/2;var y=this.a1.angle(this.a2)+Math.PI/2;var I=n-Math.cos(y)*N;var w=O+Math.sin(y)*N;var H=n+Math.cos(y)*N;var v=O-Math.sin(y)*N;var F=m+Math.cos(y)*N;var u=M-Math.sin(y)*N;var E=m-Math.cos(y)*N;var t=M+Math.sin(y)*N;r.beginPath();r.moveTo(I,w);r.lineTo(F,u);r.moveTo(H,v);r.lineTo(E,t);r.stroke()}else{if(!k.bonds_symmetrical_2D&&(this.ring!=null||this.a1.label=="C"&&this.a2.label=="C")){r.beginPath();r.moveTo(n,O);r.lineTo(m,M);var C=0;var g=this.a1.distance(this.a2);var o=this.a1.angle(this.a2);var y=o+Math.PI/2;var N=g*k.bonds_saturationWidth_2D;var G=k.bonds_saturationAngle_2D;if(G<Math.PI/2){C=-(N/Math.tan(G))}if(Math.abs(C)<g/2){var q=n-Math.cos(o)*C;var p=m+Math.cos(o)*C;var f=O+Math.sin(o)*C;var e=M-Math.sin(o)*C;var I=q-Math.cos(y)*N;var w=f+Math.sin(y)*N;var H=q+Math.cos(y)*N;var v=f-Math.sin(y)*N;var F=p-Math.cos(y)*N;var u=e+Math.sin(y)*N;var E=p+Math.cos(y)*N;var t=e-Math.sin(y)*N;var L=this.ring==null||(this.ring.center.angle(c)>this.ring.center.angle(b)&&!(this.ring.center.angle(c)-this.ring.center.angle(b)>Math.PI)||(this.ring.center.angle(c)-this.ring.center.angle(b)<-Math.PI));if(L){r.moveTo(I,w);r.lineTo(F,u)}else{r.moveTo(H,v);r.lineTo(E,t)}r.stroke()}}else{var N=this.a1.distance(this.a2)*k.bonds_saturationWidth_2D/2;var y=this.a1.angle(this.a2)+Math.PI/2;var I=n-Math.cos(y)*N;var w=O+Math.sin(y)*N;var H=n+Math.cos(y)*N;var v=O-Math.sin(y)*N;var F=m+Math.cos(y)*N;var u=M-Math.sin(y)*N;var E=m-Math.cos(y)*N;var t=M+Math.sin(y)*N;r.beginPath();r.moveTo(I,w);r.lineTo(E,t);r.moveTo(H,v);r.lineTo(F,u);r.stroke()}}break;case 3:var N=this.a1.distance(this.a2)*k.bonds_saturationWidth_2D;var y=this.a1.angle(this.a2)+Math.PI/2;var I=n-Math.cos(y)*N;var w=O+Math.sin(y)*N;var H=n+Math.cos(y)*N;var v=O-Math.sin(y)*N;var F=m+Math.cos(y)*N;var u=M-Math.sin(y)*N;var E=m-Math.cos(y)*N;var t=M+Math.sin(y)*N;r.beginPath();r.moveTo(I,w);r.lineTo(E,t);r.moveTo(H,v);r.lineTo(F,u);r.moveTo(n,O);r.lineTo(m,M);r.stroke();break}if(this.isHover){var o=this.a1.angleForStupidCanvasArcs(this.a2)+Math.PI/2;r.strokeStyle="#885110";r.lineWidth=1.2;r.beginPath();var J=o+Math.PI;J=J%(Math.PI*2);r.arc(this.a1.x,this.a1.y,6,o,J,false);r.stroke();r.beginPath();o+=Math.PI;J=o+Math.PI;J=J%(Math.PI*2);r.arc(this.a2.x,this.a2.y,7,o,J,false);r.stroke()}};this.render=function(j,e){var d=j.modelViewMatrix.x(Matrix.Translation($V([this.a1.x,this.a1.y,this.a1.z])).ensure4x4());var i=$V([this.a2.x-this.a1.x,this.a2.y-this.a1.y,this.a2.z-this.a1.z]);if(e.bonds_useJMOLColors){i.x(0.5)}if(this.a1.x==this.a2.x&&this.a1.z==this.a2.z){if(this.a2.y<this.a1.y){d=d.x(Matrix.RotationZ(Math.PI).ensure4x4())}}else{var h=$V([0,1,0]);var f=h.angleFrom(i);var k=h.cross(i);d=d.x(Matrix.Rotation(f,k).ensure4x4())}var l=e.bonds_useJMOLColors?this.a1.distance3D(this.a2)/2:this.a1.distance3D(this.a2);if(l==0){return false}d=d.x($M([[e.bonds_cylinderDiameter_3D/2,0,0],[0,l,0],[0,0,e.bonds_cylinderDiameter_3D/2]]).ensure4x4());var g=e.bonds_useJMOLColors?ELEMENT[this.a1.label].jmolColor:e.bonds_color;j.material.setTempColors(j,e.bonds_materialAmbientColor_3D,g,e.bonds_materialSpecularColor_3D,e.bonds_materialShininess_3D);j.bindBuffer(j.ARRAY_BUFFER,j.cylinderBuffer.vertexNormalBuffer);j.vertexAttribPointer(j.shader.vertexNormalAttribute,j.cylinderBuffer.vertexNormalBuffer.itemSize,j.FLOAT,false,0,0);j.bindBuffer(j.ARRAY_BUFFER,j.cylinderBuffer.vertexPositionBuffer);j.vertexAttribPointer(j.shader.vertexPositionAttribute,j.cylinderBuffer.vertexPositionBuffer.itemSize,j.FLOAT,false,0,0);j.setMatrixUniforms(j.projectionMatrix,d);j.drawArrays(j.TRIANGLE_STRIP,0,j.cylinderBuffer.vertexPositionBuffer.numItems);if(e.bonds_useJMOLColors){var d=j.modelViewMatrix.x(Matrix.Translation($V([this.a2.x,this.a2.y,this.a2.z])).ensure4x4());i.x(-1);if(this.a1.x==this.a2.x&&this.a1.z==this.a2.z){if(this.a2.y>this.a1.y){d=d.x(Matrix.RotationZ(Math.PI).ensure4x4())}}else{var h=$V([0,1,0]);var f=h.angleFrom(i);var k=h.cross(i);d=d.x(Matrix.Rotation(f-Math.PI,k).ensure4x4())}d=d.x($M([[e.bonds_cylinderDiameter_3D/2,0,0],[0,l*1.001,0],[0,0,e.bonds_cylinderDiameter_3D/2]]).ensure4x4());j.material.setTempColors(j,e.bonds_materialAmbientColor_3D,ELEMENT[this.a2.label].jmolColor,e.bonds_materialSpecularColor_3D,e.bonds_materialShininess_3D);j.bindBuffer(j.ARRAY_BUFFER,j.cylinderBuffer.vertexNormalBuffer);j.vertexAttribPointer(j.shader.vertexNormalAttribute,j.cylinderBuffer.vertexNormalBuffer.itemSize,j.FLOAT,false,0,0);j.bindBuffer(j.ARRAY_BUFFER,j.cylinderBuffer.vertexPositionBuffer);j.vertexAttribPointer(j.shader.vertexPositionAttribute,j.cylinderBuffer.vertexPositionBuffer.itemSize,j.FLOAT,false,0,0);j.setMatrixUniforms(j.projectionMatrix,d);j.drawArrays(j.TRIANGLE_STRIP,0,j.cylinderBuffer.vertexPositionBuffer.numItems)}};return true}function Molecule(){this.atoms=[];this.bonds=[];this.rings=[];this.findRings=true;this.draw=function(a,c){if(c.bonds_display==true){for(var b=0;b<this.bonds.length;b++){this.bonds[b].draw(a,c)}}if(c.atoms_display==true){for(var b=0;b<this.atoms.length;b++){this.atoms[b].draw(a,c)}}};this.render=function(b,c){if(c.bonds_display==true){for(var a=0;a<this.bonds.length;a++){this.bonds[a].render(b,c)}}if(c.atoms_display==true){for(var a=0;a<this.atoms.length;a++){this.atoms[a].render(b,c)}}};this.getCenter3D=function(){if(this.atoms.length==1){return new Atom("C",this.atoms[0].x,this.atoms[0].y,this.atoms[0].z)}var a=minY=minZ=Infinity;var c=maxY=maxZ=-Infinity;for(var b=0;b<this.atoms.length;b++){a=Math.min(this.atoms[b].x,a);minY=Math.min(this.atoms[b].y,minY);minZ=Math.min(this.atoms[b].z,minZ);c=Math.max(this.atoms[b].x,c);maxY=Math.max(this.atoms[b].y,maxY);maxZ=Math.max(this.atoms[b].z,maxZ)}return new Atom("C",(c+a)/2,(maxY+minY)/2,(maxZ+minZ)/2)};this.getCenter=function(){if(this.atoms.length==1){return new Point(this.atoms[0].x,this.atoms[0].y)}var a=minY=Infinity;var c=maxY=-Infinity;for(var b=0;b<this.atoms.length;b++){a=Math.min(this.atoms[b].x,a);minY=Math.min(this.atoms[b].y,minY);c=Math.max(this.atoms[b].x,c);maxY=Math.max(this.atoms[b].y,maxY)}return new Point((c+a)/2,(maxY+minY)/2)};this.getDimension=function(){if(this.atoms.length==1){return new Point(0,0)}var a=minY=Infinity;var c=maxY=-Infinity;for(var b=0;b<this.atoms.length;b++){a=Math.min(this.atoms[b].x,a);minY=Math.min(this.atoms[b].y,minY);c=Math.max(this.atoms[b].x,c);maxY=Math.max(this.atoms[b].y,maxY)}return new Point(c-a,maxY-minY)};this.check=function(){for(var c=0;c<this.atoms.length;c++){this.atoms[c].isLone=false;if(this.atoms[c].label=="C"){var a=0;for(var b=0;b<this.bonds.length;b++){if(this.bonds[b].a1==this.atoms[c]||this.bonds[b].a2==this.atoms[c]){a++}}if(a==0){this.atoms[c].isLone=true}}}if(this.findRings){this.rings=getRingsSSSR(this);for(var c=0;c<this.rings.length;c++){this.rings[c].setupBonds()}}this.sortAtomsByZ();this.sortBondsByZ()};this.getAngles=function(b){var d=[];for(var c=0;c<this.bonds.length;c++){if(this.bonds[c].contains(b)){d[d.length]=b.angle(this.bonds[c].getNeighbor(b))}}d.sort();return d};this.sortAtomsByZ=function(){for(var b=1;b<this.atoms.length;b++){var a=b;while(a>0&&this.atoms[a].z<this.atoms[a-1].z){var c=this.atoms[a];this.atoms[a]=this.atoms[a-1];this.atoms[a-1]=c;a--}}};this.sortBondsByZ=function(){for(var b=1;b<this.bonds.length;b++){var a=b;while(a>0&&(this.bonds[a].a1.z+this.bonds[a].a2.z)<(this.bonds[a-1].a1.z+this.bonds[a-1].a2.z)){var c=this.bonds[a];this.bonds[a]=this.bonds[a-1];this.bonds[a-1]=c;a--}}};return true}function Cube(){this.vertexPositionBuffer;this.vertexNormalBuffer;this.vertexColorBuffer;this.vertexIndexBuffer;this.generate=function(h){this.vertexPositionBuffer=h.createBuffer();h.bindBuffer(h.ARRAY_BUFFER,this.vertexPositionBuffer);vertices=[-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,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,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,];h.bufferData(h.ARRAY_BUFFER,new WebGLFloatArray(vertices),h.STATIC_DRAW);this.vertexPositionBuffer.itemSize=3;this.vertexPositionBuffer.numItems=24;this.vertexColorBuffer=h.createBuffer();h.bindBuffer(h.ARRAY_BUFFER,this.vertexColorBuffer);var b=[[1,0,0,1],[1,1,0,1],[0,1,0,1],[1,0.5,0.5,1],[1,0,1,1],[0,0,1,1],];var g=[];for(var f in b){var d=b[f];for(var e=0;e<4;e++){g=g.concat(d)}}h.bufferData(h.ARRAY_BUFFER,new WebGLFloatArray(g),h.STATIC_DRAW);this.vertexColorBuffer.itemSize=4;this.vertexColorBuffer.numItems=24;this.vertexNormalBuffer=h.createBuffer();h.bindBuffer(h.ARRAY_BUFFER,this.vertexNormalBuffer);var c=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,];h.bufferData(h.ARRAY_BUFFER,new WebGLFloatArray(c),h.STATIC_DRAW);this.vertexNormalBuffer.itemSize=3;this.vertexNormalBuffer.numItems=24;this.vertexIndexBuffer=h.createBuffer();h.bindBuffer(h.ELEMENT_ARRAY_BUFFER,this.vertexIndexBuffer);var a=[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23];h.bufferData(h.ELEMENT_ARRAY_BUFFER,new WebGLUnsignedShortArray(a),h.STATIC_DRAW);this.vertexIndexBuffer.itemSize=1;this.vertexIndexBuffer.numItems=36}}function Cylinder(){this.vertexNormalBuffer;this.vertexPositionBuffer;this.vertexIndexBuffer;this.generate=function(f,g,k,d){var j=[];var a=[];for(var e=0;e<d;e++){var c=e*2*Math.PI/d;var h=Math.cos(c);var b=Math.sin(c);a.push(h,0,b);j.push(g*h,0,g*b);a.push(h,0,b);j.push(g*h,k,g*b)}a.push(1,0,0);j.push(g,0,0);a.push(1,0,0);j.push(g,k,0);this.vertexNormalBuffer=f.createBuffer();f.bindBuffer(f.ARRAY_BUFFER,this.vertexNormalBuffer);f.bufferData(f.ARRAY_BUFFER,new WebGLFloatArray(a),f.STATIC_DRAW);this.vertexNormalBuffer.itemSize=3;this.vertexNormalBuffer.numItems=a.length/3;this.vertexPositionBuffer=f.createBuffer();f.bindBuffer(f.ARRAY_BUFFER,this.vertexPositionBuffer);f.bufferData(f.ARRAY_BUFFER,new WebGLFloatArray(j),f.STATIC_DRAW);this.vertexPositionBuffer.itemSize=3;this.vertexPositionBuffer.numItems=j.length/3}}function Light(a,c,b){this.diffuseRGB=[parseInt(a.substring(1,3),16)/255,parseInt(a.substring(3,5),16)/255,parseInt(a.substring(5,7),16)/255];this.specularRGB=[parseInt(c.substring(1,3),16)/255,parseInt(c.substring(3,5),16)/255,parseInt(c.substring(5,7),16)/255];this.direction=b;this.lightScene=function(k){var i="u_light.";k.uniform3f(k.getUniformLocation(k.program,i+"diffuse_color"),this.diffuseRGB[0],this.diffuseRGB[1],this.diffuseRGB[2]);k.uniform3f(k.getUniformLocation(k.program,i+"specular_color"),this.specularRGB[0],this.specularRGB[1],this.specularRGB[2]);var h=Vector.create(this.direction);var d=h.toUnitVector().x(-1);var j=d.flatten();k.uniform3f(k.getUniformLocation(k.program,i+"direction"),j[0],j[1],j[2]);var g=[0,0,0];var e=[g[0]+j[0],g[1]+j[1],g[2]+j[2]];var f=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(f==0){e=[0,0,1]}else{e[0]/=f;e[1]/=f;e[2]/=f}k.uniform3f(k.getUniformLocation(k.program,i+"half_vector"),e[0],e[1],e[2])}}function Material(a,c,d,b){this.ambientColor=a;this.diffuseColor=c;this.specularColor=d;this.shininess=b;this.setup=function(e){this.setTempColors(e,this.ambientColor,this.diffuseColor,this.specularColor,this.shininess)};this.setTempColors=function(j,e,h,i,f){var g="u_material.";j.uniform3f(j.getUniformLocation(j.program,g+"ambient_color"),parseInt(e.substring(1,3),16)/255,parseInt(e.substring(3,5),16)/255,parseInt(e.substring(5,7),16)/255);j.uniform3f(j.getUniformLocation(j.program,g+"diffuse_color"),parseInt(h.substring(1,3),16)/255,parseInt(h.substring(3,5),16)/255,parseInt(h.substring(5,7),16)/255);j.uniform3f(j.getUniformLocation(j.program,g+"specular_color"),parseInt(i.substring(1,3),16)/255,parseInt(i.substring(3,5),16)/255,parseInt(i.substring(5,7),16)/255);j.uniform1f(j.getUniformLocation(j.program,g+"shininess"),f)}}function Shader(){this.vertexPositionAttribute;this.vertexNormalAttribute;this.vertexColorAttribute;this.init=function(c){var b=this.getShader(c,"vertex-shader");if(b==null){b=this.loadDefaultVertexShader(c)}var a=this.getShader(c,"fragment-shader");if(a==null){a=this.loadDefaultFragmentShader(c)}c.attachShader(c.program,b);c.attachShader(c.program,a);c.linkProgram(c.program);if(!c.getProgramParameter(c.program,c.LINK_STATUS)){alert("Could not initialize shaders!")}c.useProgram(c.program);this.vertexPositionAttribute=c.getAttribLocation(c.program,"a_vertex_position");c.enableVertexAttribArray(this.vertexPositionAttribute);this.vertexNormalAttribute=c.getAttribLocation(c.program,"a_vertex_normal");c.enableVertexAttribArray(this.vertexNormalAttribute)};this.getShader=function(e,f){var b=document.getElementById(f);if(!b){return null}var d="";var a=b.firstChild;while(a){if(a.nodeType==3){d+=a.textContent}a=a.nextSibling}var c;if(b.type=="x-shader/x-fragment"){c=e.createShader(e.FRAGMENT_SHADER)}else{if(b.type=="x-shader/x-vertex"){c=e.createShader(e.VERTEX_SHADER)}else{return null}}e.shaderSource(c,d);e.compileShader(c);if(!e.getShaderParameter(c,e.COMPILE_STATUS)){alert(e.getShaderInfoLog(c));return null}return c};this.loadDefaultVertexShader=function(c){var b="";b+="struct Light";b+="{";b+="vec3 diffuse_color;";b+="vec3 specular_color;";b+="vec3 direction;";b+="vec3 half_vector;";b+="};";b+="struct Material";b+="{";b+="vec3 ambient_color;";b+="vec3 diffuse_color;";b+="vec3 specular_color;";b+="float shininess;";b+="};";b+="attribute vec3 a_vertex_position;";b+="attribute vec3 a_vertex_normal;";b+="uniform Light u_light;";b+="uniform Material u_material;";b+="uniform mat4 u_model_view_matrix;";b+="uniform mat4 u_projection_matrix;";b+="uniform mat4 u_normal_matrix;";b+="varying vec4 v_diffuse;";b+="varying vec4 v_ambient;";b+="varying vec3 v_normal;";b+="varying vec3 v_light_direction;";b+="void main(void)";b+="{";b+="v_normal = normalize((u_normal_matrix * vec4(a_vertex_normal, 1.0)).xyz);";b+="vec4 diffuse = vec4(u_light.diffuse_color, 1.0);";b+="v_light_direction = u_light.direction;";b+="v_ambient = vec4(u_material.ambient_color, 1.0);";b+="v_diffuse = vec4(u_material.diffuse_color, 1.0) * diffuse;";b+="gl_Position = u_projection_matrix * u_model_view_matrix * vec4(a_vertex_position, 1.0);";b+="}";var a=c.createShader(c.VERTEX_SHADER);c.shaderSource(a,b);c.compileShader(a);if(!c.getShaderParameter(a,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(a));return null}return a};this.loadDefaultFragmentShader=function(c){var b="";b+="struct Light";b+="{";b+="vec3 diffuse_color;";b+="vec3 specular_color;";b+="vec3 direction;";b+="vec3 half_vector;";b+="};";b+="struct Material";b+="{";b+="vec3 ambient_color;";b+="vec3 diffuse_color;";b+="vec3 specular_color;";b+="float shininess;";b+="};";b+="uniform Light u_light;";b+="uniform Material u_material;";b+="varying vec4 v_diffuse;";b+="varying vec4 v_ambient;";b+="varying vec3 v_normal;";b+="varying vec3 v_light_direction;";b+="void main(void)";b+="{";b+="float nDotL = max(dot(v_normal, v_light_direction), 0.0);";b+="vec4 color = vec4(v_diffuse.rgb*nDotL, v_diffuse.a);";b+="float nDotHV = max(dot(v_normal, u_light.half_vector), 0.0);";b+="vec4 specular = vec4(u_material.specular_color * u_light.specular_color, 1.0);";b+="color+=vec4(specular.rgb * pow(nDotHV, u_material.shininess), specular.a);";b+="gl_FragColor = color+v_ambient;";b+="}";var a=c.createShader(c.FRAGMENT_SHADER);c.shaderSource(a,b);c.compileShader(a);if(!c.getShaderParameter(a,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(a));return null}return a}}function Sphere(){this.vertexNormalBuffer;this.vertexPositionBuffer;this.vertexIndexBuffer;this.generate=function(r,d,e,f){var n=[];var m=[];for(var t=0;t<=e;t++){var h=t*Math.PI/e;var q=Math.sin(h);var o=Math.cos(h);for(var i=0;i<=f;i++){var b=i*2*Math.PI/f;var p=Math.sin(b);var c=Math.cos(b);var l=c*q;var k=o;var j=p*q;m.push(l);m.push(k);m.push(j);n.push(d*l);n.push(d*k);n.push(d*j)}}var a=[];f+=1;for(var t=0;t<e;t++){for(var i=0;i<f;i++){var g=(t*f)+(i%f);var s=g+f;a.push(g);a.push(s);a.push(g+1);if(i<f-1){a.push(s);a.push(s+1);a.push(g+1)}}}this.vertexNormalBuffer=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,this.vertexNormalBuffer);r.bufferData(r.ARRAY_BUFFER,new WebGLFloatArray(m),r.STATIC_DRAW);this.vertexNormalBuffer.itemSize=3;this.vertexNormalBuffer.numItems=m.length/3;this.vertexPositionBuffer=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,this.vertexPositionBuffer);r.bufferData(r.ARRAY_BUFFER,new WebGLFloatArray(n),r.STATIC_DRAW);this.vertexPositionBuffer.itemSize=3;this.vertexPositionBuffer.numItems=n.length/3;this.vertexIndexBuffer=r.createBuffer();r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this.vertexIndexBuffer);r.bufferData(r.ELEMENT_ARRAY_BUFFER,new WebGLUnsignedShortArray(a),r.STREAM_DRAW);this.vertexIndexBuffer.itemSize=1;this.vertexIndexBuffer.numItems=a.length}}function ValidateMolecule(a){if(a.q.value.match(/^$|^ +$/)){alert("You must enter a molecule value.");return false}a.submit();return true}function GetMolFromFrame(b,a){if(!a){return}var c=document.getElementById(b).contentDocument.body.innerHTML;if(c.match("^ChemDoodle Web Components Query Error.")){alert(c)}else{var c=readMOL(c);removeHydrogens(c);a.loadMolecule(c)}}function Get3DMolFromFrame(b,a){if(!a){return}var c=document.getElementById(b).contentDocument.body.innerHTML;if(c.match("^ChemDoodle Web Components Query Error.")){alert(c)}else{var c=readMOL(c,1);a.loadMolecule(c)}}function GetPdbFromFrameDEMO(b,a){if(!a){return}var c=document.getElementById(b).contentDocument.body.innerHTML;if(c.match("^ChemDoodle Web Components Query Error.")){alert(c)}else{a.loadMolecule(readPDB(c))}}function readMOL(f,n){var h=default_bondLength_2D;if(n){default_bondLength_2D=n}var e=new Molecule();if(f==null||f.length==0){return e}var a=f.split("\n");var l=a[3];var d=parseInt(parseInt(l.substring(0,3)));var j=parseInt(parseInt(l.substring(3,6)));for(var c=0;c<d;c++){var o=a[4+c];e.atoms[c]=new Atom(o.substring(31,34),parseFloat(o.substring(0,10))*default_bondLength_2D,-parseFloat(o.substring(10,20))*default_bondLength_2D,parseFloat(o.substring(20,30))*default_bondLength_2D)}for(var c=0;c<j;c++){var o=a[4+d+c];var m=parseInt(o.substring(6,9));var g=parseInt(o.substring(9,12));if(m>3){switch(m){case 4:m=1.5;break;default:m=1;break}}var k=new Bond(e.atoms[parseInt(o.substring(0,3))-1],e.atoms[parseInt(o.substring(3,6))-1],m);switch(g){case 3:k.stereo=BOND_STEREO_AMBIGUOUS;break;case 1:k.stereo=BOND_STEREO_PROTRUDING;break;case 6:k.stereo=BOND_STEREO_RECESSED;break}e.bonds[c]=k}if(n){default_bondLength_2D=h}return e}function writeMOL(d){var h="Molecule from ChemDoodle Web Components\n\nhttp://www.ichemlabs.com\n";h=h+fit(d.atoms.length.toString(),3)+fit(d.bonds.length.toString(),3)+"  0  0  0  0            999 v2000\n";var j=d.getCenter();for(var g=0;g<d.atoms.length;g++){var e=d.atoms[g];h=h+fit(((e.x-j.x)/default_bondLength_2D).toFixed(4),10)+fit((-(e.y-j.y)/default_bondLength_2D).toFixed(4),10)+fit((e.z/default_bondLength_2D).toFixed(4),10)+" "+fit(e.label,3)+" 0  0  0  0  0  0\n"}for(var g=0;g<d.bonds.length;g++){var c=d.bonds[g];var f=0;if(c.stereo==BOND_STEREO_AMBIGUOUS){f=3}else{if(c.stereo==BOND_STEREO_PROTRUDING){f=1}else{if(c.stereo==BOND_STEREO_RECESSED){f=6}}}h=h+fit((indexOf(d.atoms,c.a1)+1).toString(),3)+fit((indexOf(d.atoms,c.a2)+1).toString(),3)+fit(c.bondOrder.toString(),3)+"  "+f+"     0  0\n"}h=h+"M  END";return h}function fit(d,c){var b=d.length;var e="";for(var a=0;a<c-b;a++){e=e+" "}return e+d}function readPDB(e,g){var a=new Molecule();if(e==null||e.length==0){return a}var d=e.split("\n");var f=getPointsPerAngstrom();if(g){f=g}for(var c=0;c<d.length;c++){var b=d[c];if(b.indexOf("ATOM")==0||b.indexOf("HETATM")==0){a.atoms[a.atoms.length]=new Atom(b.substring(76,78),parseFloat(b.substring(30,38))*f,-parseFloat(b.substring(46,54))*f,parseFloat(b.substring(38,46)*f))}}if(g){deduceCovalentBonds(a,g)}else{deduceCovalentBonds(a)}return a}function angleBetweenLargest(g){if(g.length==0){return 0}if(g.length==1){return g[0]+Math.PI}var e=0;var f=0;var a=-1;for(var c=0;c<g.length-1;c++){var b=g[c+1]-g[c];if(b>e){e=b;f=(g[c+1]+g[c])/2;a=c}}var d=g[0]+Math.PI*2-g[g.length-1];if(d>e){f=g[0]-d/2;e=d;if(f<0){f+=Math.PI*2}a=g.length-1}return f}function isBetween(a,c,b){return a>=c&&a<=b}function getRGB(a,b){return[parseInt(a.substring(1,3),16)/255*b,parseInt(a.substring(3,5),16)/255*b,parseInt(a.substring(5,7),16)/255*b]};