/* Copyright (c) 2016 Cheminformatic.com */ function selectElementContents(id){var body=document.body,range,sel;var el=document.getElementById(id);if(document.createRange&&window.getSelection){range=document.createRange();sel=window.getSelection();sel.removeAllRanges();try{range.selectNodeContents(el);sel.addRange(range)}catch(e){range.selectNode(el);sel.addRange(range)}}else if(body.createTextRange){range=body.createTextRange();range.moveToElementText(el);range.select()}}function launchNetVis(action,data){var form=document.createElement("form");form.target="_blank";form.method="post";form.action=action;var input=document.createElement("input");input.type="text";input.name="data";input.value=data;form.appendChild(input);document.body.appendChild(form);form.submit()}function launchAction(action,data){var form=document.createElement("form");form.target="_blank";form.method="post";form.action=action;var input=document.createElement("input");input.type="text";input.name="smiles";input.value=data;form.appendChild(input);document.body.appendChild(form);form.submit()}function addCutPosition(canvasName,length,cut,dir,width,height){var cutPosDiv=document.getElementById(canvasName);cutPosDiv.onwheel=function(event){event.preventDefault()};cutPosDiv.onmousewheel=function(event){event.preventDefault()};cutPosDiv.ontouch=function(event){event.preventDefault()};var canvas=document.createElement("canvas");canvas.setAttribute("width",width);canvas.setAttribute("height",height);canvas.setAttribute("id","canvas");cutPosDiv.appendChild(canvas);if(typeof G_vmlCanvasManager!="undefined"){canvas=G_vmlCanvasManager.initElement(canvas)}var context=canvas.getContext("2d");var crect=canvas.getBoundingClientRect();var crect_left=crect.left;var crect_top=crect.top;canvas.addEventListener("mousedown",whenMouseDown,false);canvas.addEventListener("mousemove",whenMouseMove,false);canvas.addEventListener("mouseup",whenMouseUp,false);canvas.addEventListener("mouseout",whenMouseOut,false);canvas.addEventListener("mousewheel",whenMouseWheel,false);canvas.addEventListener("touchstart",whenTouchStart,false);canvas.addEventListener("touchmove",whenTouchMove,false);canvas.addEventListener("touchend",whenTouchEnd,false);canvas.addEventListener("touchleave",whenTouchLeave,false);var fontSize=10;var fontFamily="Arial";var font=fontSize+"px "+fontFamily;var zoomLevel=1;var startX=0;var mdx,mdy;var move=false;var margin=5;var tickSize=10;var tickSpace=(width-2*margin)/length;var ux=tickSpace;var seqBegin=1;var seqEnd=length;var middle=height/2;var acut=cut.split(",");var adir=dir.split(",");drawCutPosition(seqBegin,seqEnd);function drawCutPosition(begin,end){var h,i,c,n,curLength;var m,x,z;curLength=end-begin+1;context.clearRect(0,0,width,height);context.beginPath();context.fillStyle="black";context.strokeStyle="black";m=startX+margin;drawLine(context,margin,middle,width-margin,middle);drawTick(context,margin,middle,3*tickSize);drawTick(context,width-margin,middle,3*tickSize);context.textAlign="center";z=zoomLevel-1;context.fillText("Z="+z,margin+10,10);drawCopyright1(context,width-80,margin+5);if(ux>10){n=10}else if(ux>8){n=20}else if(ux>6){n=30}else if(ux>4){n=40}else if(ux>0){n=50}for(h=begin;h<=end;h++){i=h-begin+1;x=m+ux*i;if(x<width){if(i%n==0){drawTick(context,x,middle,2*tickSize);context.fillText(h,x,middle+1.7*tickSize)}if(ux>2){drawTick(context,x,middle,.5*tickSize)}}}context.closePath();context.stroke();for(i=0;i<acut.length;i++){c=parseInt(acut[i]);if(begin<=c&&c<=end){if(adir[i]=="+"){context.beginPath();context.strokeStyle="blue";drawLine(context,m+ux*c,middle-tickSize-8,m+ux*c,middle-tickSize-18);context.fillStyle="blue";context.fillText(i+1,m+ux*c,middle-tickSize-22);context.closePath();context.stroke()}else{context.beginPath();context.strokeStyle="red";drawLine(context,m+ux*c,middle+tickSize+10,m+ux*c,height-4*margin);context.fillStyle="red";context.fillText(i+1,m+ux*c,height-2*margin);context.closePath();context.stroke()}}}}function whenMouseDown(event){event.preventDefault();mdx=event.pageX;mdy=event.pageY;move=true;var m=crect_left+margin+10;if(m-10<mdx&&mdx<m+10&&crect_top-10<mdy&&mdy<crect_top+10){zoomLevel=1;startX=0;ux=zoomLevel*tickSpace;drawCutPosition(seqBegin,seqEnd)}}function whenMouseMove(event){event.preventDefault();if(move&&zoomLevel>1){var x=event.pageX;var y=event.pageY;startX+=x-mdx;if(startX>0){startX=0}drawCutPosition(seqBegin,seqEnd);mdx=x}}function whenMouseUp(event){move=false}function whenMouseOut(event){move=false}function whenMouseWheel(event){event.preventDefault();mdx=event.pageX-crect_left;var prv=zoomLevel;zoomLevel+=event.wheelDelta/120;if(zoomLevel<1){zoomLevel=1;startX=0}ux=zoomLevel*tickSpace;startX=mdx-zoomLevel*(mdx-startX)/prv;if(startX>0){startX=0}drawCutPosition(seqBegin,seqEnd)}var prvTouchDis;function whenTouchStart(event){event.preventDefault();if(event.targetTouches.length==1){var touch=event.targetTouches[0];mdx=touch.pageX;mdy=touch.pageY}move=true;prvTouchDis=0;var m=crect_left+margin+10;if(m-10<mdx&&mdx<m+10&&crect_top-10<mdy&&mdy<crect_top+10){zoomLevel=1;startX=0;ux=zoomLevel*tickSpace;drawCutPosition(seqBegin,seqEnd)}}function whenTouchMove(event){event.preventDefault();var touch,x1,x2,prv,dis;if(move){if(zoomLevel>1&&event.targetTouches.length==1){touch=event.targetTouches[0];x1=touch.pageX-crect_left;startX+=x1-mdx;if(startX>0){startX=0}drawCutPosition(seqBegin,seqEnd);mdx=x1}else if(event.targetTouches.length==2){touch=event.targetTouches[0];x1=touch.pageX-crect_left;touch=event.targetTouches[1];x2=touch.pageX-crect_left;mdx=(x1+x2)/2;prv=zoomLevel;dis=(x1-x2)*(x1-x2);if(prvTouchDis==0){prvTouchDis=dis}else if(prvTouchDis<dis){zoomLevel++;move=false}else if(dis<prvTouchDis){zoomLevel--;move=false}if(zoomLevel<=1){zoomLevel=1;startX=0}ux=zoomLevel*tickSpace;startX=mdx-zoomLevel*(mdx-startX)/prv;if(startX>0){startX=0}drawCutPosition(seqBegin,seqEnd)}}}function whenTouchEnd(event){move=false}function whenTouchLeave(event){move=false}}navigator.sayswho=function(){var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(M[1])){tem=/\brv[ :]+(\d+)/g.exec(ua)||[];return"IE "+(tem[1]||"")}if(M[1]==="Chrome"){tem=ua.match(/\b(OPR|Edge)\/(\d+)/);if(tem!=null)return tem.slice(1).join(" ").replace("OPR","Opera")}M=M[2]?[M[1],M[2]]:[navigator.appName,navigator.appVersion,"-?"];if((tem=ua.match(/version\/(\d+)/i))!=null)M.splice(1,1,tem[1]);return M.join(" ")}();function createXMLHttpRequest(){if(typeof XMLHttpRequest!="undefined"){return new XMLHttpRequest}else if(typeof ActiveXObject!="undefined"){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}throw new Error("This browser does not support XMLHttpRequest.")}else{throw new Error("XMLHttpRequest not supported")}}function isNumeric(n){return!isNaN(parseFloat(n))&&isFinite(n)}function drawLine(ctx,x1,y1,x2,y2){ctx.moveTo(x1,y1);ctx.lineTo(x2,y2)}function drawTick(ctx,x,y,s){drawLine(ctx,x,y,x,y-s/2);drawLine(ctx,x,y,x,y+s/2)}function drawCopyright1(ctx,x,y){var thisDate=new Date;var thisYear=thisDate.getFullYear();var copyright;if(thisYear==2015){copyright="© "+thisYear+" Cheminformatic.com"}else{copyright="© 2015-"+thisYear+" Cheminformatic.com"}ctx.fillText(copyright,x,y)}function drawCopyright2(ctx,x,y){var copyright="© CI";ctx.fillText(x,y,copyright,x,y)}function quickSort(key,list,left,right,asc){var i,leftIndex,rightIndex;var middleElement,temp;leftIndex=left;rightIndex=right;if(left<right){i=Math.floor((right+left)/2);middleElement=key[i];while(leftIndex<=rightIndex){if(asc){while(leftIndex<right&&key[leftIndex]<middleElement){leftIndex++}while(rightIndex>left&&key[rightIndex]>middleElement){rightIndex--}}else{while(leftIndex<right&&key[leftIndex]>middleElement){leftIndex++}while(rightIndex>left&&key[rightIndex]<middleElement){rightIndex--}}if(leftIndex<=rightIndex){if(key[leftIndex]!=key[rightIndex]){temp=key[leftIndex];key[leftIndex]=key[rightIndex];key[rightIndex]=temp;i=list[leftIndex];list[leftIndex]=list[rightIndex];list[rightIndex]=i}leftIndex++;rightIndex--}}if(left<rightIndex){quickSort(key,list,left,rightIndex,asc)}if(leftIndex<right){quickSort(key,list,leftIndex,right,asc)}}}function Minitialize(m){var i;for(i=0;i<16;i++){m[i]=0}m[0]=m[5]=m[10]=m[15]=1}function Mmultiply(m,rhs){var lm=[];lm[0]=m[0]*rhs[0]+m[1]*rhs[4]+m[2]*rhs[8];lm[4]=m[4]*rhs[0]+m[5]*rhs[4]+m[6]*rhs[8];lm[8]=m[8]*rhs[0]+m[9]*rhs[4]+m[10]*rhs[8];lm[12]=m[12]*rhs[0]+m[13]*rhs[4]+m[14]*rhs[8]+rhs[12];lm[1]=m[0]*rhs[1]+m[1]*rhs[5]+m[2]*rhs[9];lm[5]=m[4]*rhs[1]+m[5]*rhs[5]+m[6]*rhs[9];lm[9]=m[8]*rhs[1]+m[9]*rhs[5]+m[10]*rhs[9];lm[13]=m[12]*rhs[1]+m[13]*rhs[5]+m[14]*rhs[9]+rhs[13];lm[2]=m[0]*rhs[2]+m[1]*rhs[6]+m[2]*rhs[10];lm[6]=m[4]*rhs[2]+m[5]*rhs[6]+m[6]*rhs[10];lm[10]=m[8]*rhs[2]+m[9]*rhs[6]+m[10]*rhs[10];lm[14]=m[12]*rhs[2]+m[13]*rhs[6]+m[14]*rhs[10]+rhs[14];m[0]=lm[0];m[4]=lm[4];m[8]=lm[8];m[12]=lm[12];m[1]=lm[1];m[5]=lm[5];m[9]=lm[9];m[13]=lm[13];m[2]=lm[2];m[6]=lm[6];m[10]=lm[10];m[14]=lm[14]}function Mtranslate(m,x,y,z){m[12]=m[12]+x;m[13]=m[13]+y;m[14]=m[14]+z}function Mxrotate(m,theta){var ct,st;var nm=[];theta=theta*(Math.PI/180);ct=Math.cos(theta);st=Math.sin(theta);nm[1]=m[1]*ct+m[2]*st;nm[5]=m[5]*ct+m[6]*st;nm[9]=m[9]*ct+m[10]*st;nm[13]=m[13]*ct+m[14]*st;nm[2]=m[2]*ct-m[1]*st;nm[6]=m[6]*ct-m[5]*st;nm[10]=m[10]*ct-m[9]*st;nm[14]=m[14]*ct-m[13]*st;m[13]=nm[13];m[1]=nm[1];m[5]=nm[5];m[9]=nm[9];m[14]=nm[14];m[2]=nm[2];m[6]=nm[6];m[10]=nm[10]}function Myrotate(m,theta){var ct,st;var nm=[];theta=theta*(Math.PI/180);ct=Math.cos(theta);st=Math.sin(theta);nm[0]=m[0]*ct+m[2]*st;nm[4]=m[4]*ct+m[6]*st;nm[8]=m[8]*ct+m[10]*st;nm[12]=m[12]*ct+m[14]*st;nm[2]=m[2]*ct-m[0]*st;nm[6]=m[6]*ct-m[4]*st;nm[10]=m[10]*ct-m[8]*st;nm[14]=m[14]*ct-m[12]*st;m[12]=nm[12];m[0]=nm[0];m[4]=nm[4];m[8]=nm[8];m[14]=nm[14];m[2]=nm[2];m[6]=nm[6];m[10]=nm[10]}function Mzrotate(m,theta){var ct,st;var nm=[];theta=theta*(Math.PI/180);ct=Math.cos(theta);st=Math.sin(theta);nm[1]=m[1]*ct+m[0]*st;nm[5]=m[5]*ct+m[4]*st;nm[9]=m[9]*ct+m[8]*st;nm[13]=m[13]*ct+m[12]*st;nm[0]=m[0]*ct-m[1]*st;nm[4]=m[4]*ct-m[5]*st;nm[8]=m[8]*ct-m[9]*st;nm[12]=m[12]*ct-m[13]*st;m[13]=nm[13];m[1]=nm[1];m[5]=nm[5];m[9]=nm[9];m[12]=nm[12];m[0]=nm[0];m[4]=nm[4];m[8]=nm[8]}function Mscale(m,x,y,z){m[0]=m[0]*x;m[4]=m[4]*x;m[8]=m[8]*x;m[12]=m[12]*x;m[1]=m[1]*y;m[5]=m[5]*y;m[9]=m[9]*y;m[13]=m[13]*y;m[2]=m[2]*z;m[6]=m[6]*z;m[10]=m[10]*z;m[14]=m[14]*z}function gluProject(width,height,mm,x3,y3,z3,winxyz){var i,r,c;var m=[];var transformation=[];var result=[];var rhw;for(i=0;i<16;i++){m[i]=0}m[0]=m[5]=m[10]=m[15]=1;for(r=0;r<4;++r){transformation[r]=new Array(4);for(c=0;c<4;++c){transformation[r][c]=0;for(i=0;i<4;++i){transformation[r][c]+=m[r+i*4]*mm[i+c*4]}}}for(r=0;r<4;++r){result[r]=0;result[r]+=transformation[r][0]*x3;result[r]+=transformation[r][1]*y3;result[r]+=transformation[r][2]*z3;result[r]+=transformation[r][3]*1}rhw=1/result[3];winxyz[0]=Math.round((result[0]*rhw+1)*width/2);winxyz[1]=Math.round((1-result[1]*rhw)*height/2);winxyz[2]=result[2]}var g_molDrawingWidth;var g_molDrawingHeight;var g_numOfStrPerRow=5;var g_fontFamily="Arial";var g_fontSize=10;var g_maxNumOfMols=20;var g_numOfMols;var g_mol=new Array;var g_doubleX=new Array(6);var g_doubleY=new Array(6);var g_strSize=0;function incStrSize(){g_strSize=g_strSize+50}function decStrSize(){g_strSize=g_strSize-50;if(g_strSize<50){g_strSize=50}}function resizeStrInTable(id){var i,j;var cell;var divs;var strDiv;var table=document.getElementById(id);for(i=0;i<table.rows.length;i++){for(j=0;j<table.rows[i].cells.length;j++){cell=table.rows[i].cells[j];divs=cell.getElementsByTagName("div");if(divs.length>0){divs[0].removeChild(divs[0].lastChild);strDiv=divs[0].getAttribute("id");addStructure(strDiv)}}}}function addStructure(div_id){var strDiv=document.getElementById(div_id);parseStructureData(strDiv.getAttribute("data-mol"));canvas=document.createElement("canvas");canvas.setAttribute("width",g_molDrawingWidth);canvas.setAttribute("height",g_molDrawingHeight);canvas.setAttribute("id","canvas");strDiv.appendChild(canvas);if(typeof G_vmlCanvasManager!="undefined"){canvas=G_vmlCanvasManager.initElement(canvas)}context=canvas.getContext("2d");context.font=g_fontSize+"px "+g_fontFamily;for(var h=0;h<g_mol.length;h++){drawStructure(context,g_strSize/2,g_strSize/2,h)}}function parseStructureData(data){var h,i,j;data=data.replace(/===/g,"\n");data=data.replace(/\r\n/g,"\n");var item1=data.split("$$$$\n");g_numOfMols=item1.length-1;if(g_maxNumOfMols<g_numOfMols){g_numOfMols=g_maxNumOfMols}if(g_numOfMols<g_numOfStrPerRow){g_molDrawingWidth=g_strSize*g_numOfMols;g_molDrawingHeight=g_strSize}else{g_molDrawingWidth=g_strSize*g_numOfStrPerRow;g_molDrawingHeight=g_strSize*Math.ceil(g_numOfMols/g_numOfStrPerRow)}g_mol.length=0;for(h=0;h<g_numOfMols;h++){g_mol[h]=new Object;g_mol[h].name="";g_mol[h].scale=g_mol[h].diagLength=0;g_mol[h].minx=g_mol[h].miny=g_mol[h].minz=g_mol[h].maxx=g_mol[h].maxy=g_mol[h].maxz=g_mol[h].centerX=g_mol[h].centerY=g_mol[h].centerZ=0;g_mol[h].numOfAtoms=g_mol[h].numOfBonds=g_mol[h].chiralFlag=0;g_mol[h].atomX=new Array;g_mol[h].atomY=new Array;g_mol[h].atomZ=new Array;g_mol[h].atomType=new Array;g_mol[h].massDiff=new Array;g_mol[h].atomCharge=new Array;g_mol[h].atomStereo=new Array;g_mol[h].bond1=new Array;g_mol[h].bond2=new Array;g_mol[h].bondType=new Array;g_mol[h].bondStereo=new Array;g_mol[h].atchAtoms=new Array;g_mol[h].numOfAtchAtoms=new Array;g_mol[h].atchAtomsBtype=new Array;g_mol[h].TV="";g_mol[h].atom_color="";g_mol[h].bond_color="";g_mol[h].idx=0;g_mol[h].x1=0;g_mol[h].y1=0;g_mol[h].x2=0;g_mol[h].y2=0;var item2=item1[h].split("\n");if(item2.length<4){console.log("Problem with the structure.");return}g_mol[h].name=item2[0];g_mol[h].numOfAtoms=parseInt(item2[3].substr(0,3));g_mol[h].numOfBonds=parseInt(item2[3].substr(3,3));g_mol[h].chiralFlag=parseInt(item2[3].substr(12,3));for(i=0;i<g_mol[h].numOfAtoms;i++){g_mol[h].atomX[i]=parseFloat(item2[4+i].substr(0,10));g_mol[h].atomY[i]=parseFloat(item2[4+i].substr(10,10));g_mol[h].atomZ[i]=parseFloat(item2[4+i].substr(20,10));g_mol[h].atomType[i]=item2[4+i].substr(31,3).trim();g_mol[h].massDiff[i]=parseInt(item2[4+i].substr(34,2));j=parseInt(item2[4+i].substr(36,3));if(j==0){g_mol[h].atomCharge[i]=0}else if(j==1){g_mol[h].atomCharge[i]=3}else if(j==2){g_mol[h].atomCharge[i]=2}else if(j==3){g_mol[h].atomCharge[i]=1}else if(j==5){g_mol[h].atomCharge[i]=-1}else if(j==6){g_mol[h].atomCharge[i]=-2}else if(j==7){g_mol[h].atomCharge[i]=-3}else{g_mol[h].atomCharge[i]=0}g_mol[h].atomStereo[i]=parseInt(item2[4+i].substr(39,3));if(i==0){g_mol[h].minx=g_mol[h].maxx=g_mol[h].atomX[i];g_mol[h].miny=g_mol[h].maxy=g_mol[h].atomY[i];g_mol[h].minz=g_mol[h].maxz=g_mol[h].atomZ[i]}else{if(g_mol[h].atomX[i]<g_mol[h].minx){g_mol[h].minx=g_mol[h].atomX[i]}if(g_mol[h].maxx<g_mol[h].atomX[i]){g_mol[h].maxx=g_mol[h].atomX[i]}if(g_mol[h].atomY[i]<g_mol[h].miny){g_mol[h].miny=g_mol[h].atomY[i]}if(g_mol[h].maxy<g_mol[h].atomY[i]){g_mol[h].maxy=g_mol[h].atomY[i]}if(g_mol[h].atomZ[i]<g_mol[h].minz){g_mol[h].minz=g_mol[h].atomZ[i]}if(g_mol[h].maxz<g_mol[h].atomZ[i]){g_mol[h].maxz=g_mol[h].atomZ[i]}}}for(i=0;i<g_mol[h].numOfAtoms;i++){g_mol[h].numOfAtchAtoms[i]=0;g_mol[h].atchAtoms[i]=new Array(10);for(j=0;j<10;j++){g_mol[h].atchAtoms[i][j]=0}g_mol[h].atchAtomsBtype[i]=new Array(10);for(j=0;j<10;j++){g_mol[h].atchAtomsBtype[i][j]=0}}for(i=0;i<g_mol[h].numOfBonds;i++){g_mol[h].bond1[i]=parseInt(item2[4+g_mol[h].numOfAtoms+i].substr(0,3))-1;g_mol[h].bond2[i]=parseInt(item2[4+g_mol[h].numOfAtoms+i].substr(3,3))-1;j=parseInt(item2[4+g_mol[h].numOfAtoms+i].substr(6,3));if(j==1){g_mol[h].bondType[i]=0}else if(j==2){g_mol[h].bondType[i]=1}else if(j==3){g_mol[h].bondType[i]=2}else if(j==4){g_mol[h].bondType[i]=4}else if(j==5){g_mol[h].bondType[i]=6}else if(j==6){g_mol[h].bondType[i]=6}else if(j==7){g_mol[h].bondType[i]=6}else if(j==8){g_mol[h].bondType[i]=6}g_mol[h].bondStereo[i]=parseInt(item2[4+g_mol[h].numOfAtoms+i].substr(9,3));g_mol[h].atchAtoms[g_mol[h].bond1[i]][g_mol[h].numOfAtchAtoms[g_mol[h].bond1[i]]]=g_mol[h].bond2[i];g_mol[h].atchAtomsBtype[g_mol[h].bond1[i]][g_mol[h].numOfAtchAtoms[g_mol[h].bond1[i]]]=g_mol[h].bondType[i];g_mol[h].atchAtoms[g_mol[h].bond2[i]][g_mol[h].numOfAtchAtoms[g_mol[h].bond2[i]]]=g_mol[h].bond1[i];g_mol[h].atchAtomsBtype[g_mol[h].bond2[i]][g_mol[h].numOfAtchAtoms[g_mol[h].bond2[i]]]=g_mol[h].bondType[i];g_mol[h].numOfAtchAtoms[g_mol[h].bond1[i]]++;g_mol[h].numOfAtchAtoms[g_mol[h].bond2[i]]++}i=4+g_mol[h].numOfAtoms+g_mol[h].numOfBonds;while(i<item2.length){if(item2[i].match(/ATOM_TVS/)){i++;g_mol[h].TV=item2[i]}else if(item2[i].match(/ATOM_COLOR/)){i++;g_mol[h].atom_color=item2[i]}else if(item2[i].match(/BOND_COLOR/)){i++;g_mol[h].bond_color=item2[i]}else{i++}}if(g_mol[h].numOfAtoms>0){g_mol[h].centerX=(g_mol[h].minx+g_mol[h].maxx)/2;g_mol[h].centerY=(g_mol[h].miny+g_mol[h].maxy)/2;g_mol[h].centerZ=(g_mol[h].minz+g_mol[h].maxz)/2;for(i=0;i<g_mol[h].numOfAtoms;i++){g_mol[h].atomX[i]=g_mol[h].atomX[i]-g_mol[h].centerX;g_mol[h].atomY[i]=g_mol[h].atomY[i]-g_mol[h].centerY;g_mol[h].atomZ[i]=g_mol[h].atomZ[i]-g_mol[h].centerZ}g_mol[h].minx=g_mol[h].minx-g_mol[h].centerX;g_mol[h].maxx=g_mol[h].maxx-g_mol[h].centerX;g_mol[h].miny=g_mol[h].miny-g_mol[h].centerY;g_mol[h].maxy=g_mol[h].maxy-g_mol[h].centerY;g_mol[h].minz=g_mol[h].minz-g_mol[h].centerZ;g_mol[h].maxz=g_mol[h].maxz-g_mol[h].centerZ;g_mol[h].diagLength=(g_mol[h].maxx-g_mol[h].minx)*(g_mol[h].maxx-g_mol[h].minx);g_mol[h].diagLength=g_mol[h].diagLength+(g_mol[h].maxy-g_mol[h].miny)*(g_mol[h].maxy-g_mol[h].miny);g_mol[h].diagLength=g_mol[h].diagLength+(g_mol[h].maxz-g_mol[h].minz)*(g_mol[h].maxz-g_mol[h].minz);g_mol[h].diagLength=Math.sqrt(g_mol[h].diagLength);if(g_mol[h].diagLength<1e-4){g_mol[h].diagLength=10}g_mol[h].scale=.7*Math.sqrt(g_strSize*g_strSize+g_strSize*g_strSize)/g_mol[h].diagLength}}}function drawStructure(context,stx,sty,h){var i,j,b1,b2,a1,a2,c;var x1,y1,x2,y2;var xoffset=g_fontSize/3;var yoffset=g_fontSize/2;var atomToBeDisplayed=new Array;var checkCatom=new Array;var checkCbond=new Array;var atomColor;var item1,item2;var atom2color=new Array;var bond2color=new Array;if(g_mol[h].name=="frag"){g_mol[h].name=""}context.textAlign="center";context.strokeStyle="black";context.fillStyle="black";context.fillText(g_mol[h].name,stx+g_mol[h].x2,sty+g_mol[h].y2+g_strSize/2);for(i=0;i<g_mol[h].numOfAtoms;i++){checkCatom[i]=checkCbond[i]=0;atomToBeDisplayed[i]=true}atom2color.length=0;if(g_mol[h].atom_color.match(",")){item1=g_mol[h].atom_color.split(";");for(i=0;i<item1.length;i++){item2=item1[i].split(",");for(j=1;j<item2.length;j++){atom2color[item2[j]]=item2[0]}}}bond2color.length=0;if(g_mol[h].bond_color.match(",")){item1=g_mol[h].bond_color.split(";");for(i=0;i<item1.length;i++){item2=item1[i].split(",");for(j=1;j<item2.length;j++){bond2color[item2[j]]=item2[0]}}}for(i=0;i<g_mol[h].numOfBonds;i++){b1=g_mol[h].bond1[i];b2=g_mol[h].bond2[i];a1=g_mol[h].atomType[b1];a2=g_mol[h].atomType[b2];checkCatom[b1]=checkCatom[b2]=1;if(g_mol[h].bondType[i]==0||g_mol[h].bondType[i]==3){if(g_mol[h].bondStereo[i]==0&&(a1=="C"&&a2=="H"||a1=="H"&&a2=="C")){if(a1=="H"){atomToBeDisplayed[b1]=false}if(a2=="H"){atomToBeDisplayed[b2]=false}}else{if(g_mol[h].bondStereo[i]==1||g_mol[h].bondStereo[i]==6){ndbp(h,0,b1,b2);g_doubleX[0]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[0];g_doubleY[0]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[0];g_doubleX[1]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[1];g_doubleY[1]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[1];g_doubleX[3]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[3];g_doubleY[3]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[3];if(g_mol[h].bondStereo[i]==1){context.beginPath();if(bond2color.length==0){context.fillStyle="black"}else{context.fillStyle=bond2color[i]}context.moveTo(g_doubleX[0],g_doubleY[0]);context.lineTo(g_doubleX[1],g_doubleY[1]);context.lineTo(g_doubleX[3],g_doubleY[3]);context.lineTo(g_doubleX[0],g_doubleY[0]);context.closePath();context.fill();context.stroke()}else if(g_mol[h].bondStereo[i]==6){context.beginPath();if(bond2color.length>0){context.strokeStyle=bond2color[i];context.fillStyle=bond2color[i]}context.moveTo(g_doubleX[0],g_doubleY[0]);context.lineTo(g_doubleX[1],g_doubleY[1]);context.lineTo(g_doubleX[3],g_doubleY[3]);context.lineTo(g_doubleX[0],g_doubleY[0]);context.closePath();context.stroke()}}else{x1=stx+g_mol[h].x2+g_mol[h].scale*g_mol[h].atomX[b1];y1=sty+g_mol[h].y2-g_mol[h].scale*g_mol[h].atomY[b1];x2=stx+g_mol[h].x2+g_mol[h].scale*g_mol[h].atomX[b2];y2=sty+g_mol[h].y2-g_mol[h].scale*g_mol[h].atomY[b2];context.beginPath();if(bond2color.length>0){context.strokeStyle=bond2color[i];context.fillStyle=bond2color[i]}context.moveTo(x1,y1);context.lineTo(x2,y2);context.closePath();context.stroke()}}}else if(g_mol[h].bondType[i]==4&&(g_mol[h].checkCbond[b1]>1||g_mol[h].checkCbond[b2]>1)){x1=stx+g_mol[h].x2+g_mol[h].scale*g_mol[h].atomX[b1];y1=sty+g_mol[h].y2-g_mol[h].scale*g_mol[h].atomY[b1];x2=stx+g_mol[h].x2+g_mol[h].scale*g_mol[h].atomX[b2];y2=sty+g_mol[h].y2-g_mol[h].scale*g_mol[h].atomY[b2];context.beginPath();if(bond2color.length>0){context.strokeStyle=bond2color[i];context.fillStyle=bond2color[i]}context.moveTo(x1,y1);context.lineTo(x2,y2);context.closePath();context.stroke()}else if(g_mol[h].bondType[i]==2||g_mol[h].bondType[i]==1&&(g_mol[h].numOfAtchAtoms[b1]==1||g_mol[h].numOfAtchAtoms[b2]==1)){ndbp(h,g_mol[h].bondType[i],b1,b2);if(g_mol[h].bondType[i]==2){g_doubleX[0]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[0];g_doubleY[0]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[0];g_doubleX[1]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[1];g_doubleY[1]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[1];g_doubleX[2]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[2];g_doubleY[2]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[2];g_doubleX[3]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[3];g_doubleY[3]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[3];g_doubleX[4]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[4];g_doubleY[4]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[4];g_doubleX[5]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[5];g_doubleY[5]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[5];context.beginPath();if(bond2color.length>0){context.strokeStyle=bond2color[i];context.fillStyle=bond2color[i]}context.moveTo(g_doubleX[0],g_doubleY[0]);context.lineTo(g_doubleX[1],g_doubleY[1]);context.moveTo(g_doubleX[2],g_doubleY[2]);context.lineTo(g_doubleX[3],g_doubleY[3]);context.moveTo(g_doubleX[4],g_doubleY[4]);context.lineTo(g_doubleX[5],g_doubleY[5]);context.closePath();context.stroke()}else{g_doubleX[0]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[0];g_doubleY[0]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[0];g_doubleX[1]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[1];g_doubleY[1]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[1];g_doubleX[2]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[2];g_doubleY[2]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[2];g_doubleX[3]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[3];g_doubleY[3]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[3];context.beginPath();if(bond2color.length>0){context.strokeStyle=bond2color[i];context.fillStyle=bond2color[i]}context.moveTo(g_doubleX[0],g_doubleY[0]);context.lineTo(g_doubleX[1],g_doubleY[1]);context.moveTo(g_doubleX[2],g_doubleY[2]);context.lineTo(g_doubleX[3],g_doubleY[3]);context.closePath();context.stroke()}}else if(g_mol[h].bondType[i]==1||g_mol[h].bondType[i]==4){if(g_mol[h].bondType[i]==4){if(a1=="C"){checkCbond[b1]=checkCbond[b1]+2}if(a2=="C"){checkCbond[b2]=checkCbond[b2]+2}}ndbp(h,g_mol[h].bondType[i],b1,b2);g_doubleX[0]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[0];g_doubleY[0]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[0];g_doubleX[1]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[1];g_doubleY[1]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[1];g_doubleX[2]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[2];g_doubleY[2]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[2];g_doubleX[3]=stx+g_mol[h].x2+g_mol[h].scale*g_doubleX[3];g_doubleY[3]=sty+g_mol[h].y2-g_mol[h].scale*g_doubleY[3];context.beginPath();if(bond2color.length>0){context.strokeStyle=bond2color[i];context.fillStyle=bond2color[i]}context.moveTo(g_doubleX[0],g_doubleY[0]);context.lineTo(g_doubleX[1],g_doubleY[1]);context.moveTo(g_doubleX[2],g_doubleY[2]);context.lineTo(g_doubleX[3],g_doubleY[3]);context.closePath();context.stroke()}}for(i=0;i<g_mol[h].numOfAtoms;i++){x1=stx+g_mol[h].x2+g_mol[h].scale*g_mol[h].atomX[i];y1=sty+g_mol[h].y2-g_mol[h].scale*g_mol[h].atomY[i];a1=g_mol[h].atomType[i];if(a1=="H"&&g_mol[h].massDiff[i]==1){a1="D"}if(a1=="H"&&g_mol[h].massDiff[i]==2){a1="T"}if(0<g_mol[h].numOfAtchAtoms[i]){k=g_mol[h].atchAtoms[i][0];a2=g_mol[h].atomType[k]}if(!atomToBeDisplayed[i]&&a1=="H"&&a2=="C"){}else if(a1!="C"||g_mol[h].numOfAtoms==1||checkCatom[i]==0){if(a1=="N"){atomColor="blue"}else if(a1=="O"){atomColor="red"}else{atomColor="black"}if(g_mol[h].atomCharge[i]!=0){if(g_mol[h].atomCharge[i]==1){a1=a1+"+"}else if(g_mol[h].atomCharge[i]==-1){a1=a1+"-"}}context.beginPath();context.rect(x1-yoffset,y1-yoffset,2*yoffset,2*yoffset);context.fillStyle="white";context.fill();context.lineWidth=0;context.strokeStyle="white";context.stroke();context.textAlign="start";if(atom2color.length>0){context.strokeStyle=atom2color[i];context.fillStyle=atom2color[i]}else{context.strokeStyle="black";context.fillStyle="black"}context.fillText(g_mol[h].atomType[i],x1-xoffset,y1+yoffset)}}if(g_mol[h].TV.match(",")){var item=g_mol[h].TV.split(",");var atomTVS=new Array;var tw=g_strSize;var th=g_strSize;var size;tw=Math.sqrt(tw*tw+th*th);atom2color.length=0;for(i=0;i<item.length;i=i+2){if(item[i+1]>0){atom2color[item[i]]="lime"}else{atom2color[item[i]]="red"}atomTVS[item[i]]=item[i+1]}context.globalAlpha=.3;for(i=0;i<g_mol[h].numOfAtoms;i++){if(atom2color[i]=="lime"||atom2color[i]=="red"){x1=stx+g_mol[h].x2+g_mol[h].scale*g_mol[h].atomX[i];y1=sty+g_mol[h].y2-g_mol[h].scale*g_mol[h].atomY[i];size=.06*Math.log(1.2+Math.abs(atomTVS[i]))*tw;context.beginPath();context.arc(x1,y1,size,0,2*Math.PI,true);context.fillStyle=atom2color[i];context.fill();context.lineWidth=0;context.strokeStyle=atom2color[i];context.stroke()}}context.globalAlpha=1}}function ndbp(h,bt,at1,at2){var i,j,k,p,n,tp1,tn1,tp2,tn2;var cx,cy,a,b,d,ad,bd,tempx,tempy,tempd,offset;var pi,theta;var tx=new Array(g_mol[h].numOfAtoms);var ty=new Array(g_mol[h].numOfAtoms);pi=3.141592653589793;if(bt>0){if(g_mol[h].atomX[at1]>g_mol[h].atomX[at2]){i=at1;at1=at2;at2=i}}cx=g_mol[h].atomX[at1];cy=g_mol[h].atomY[at1];for(i=0;i<g_mol[h].numOfAtoms;i++){tx[i]=g_mol[h].atomX[i];ty[i]=g_mol[h].atomY[i];tx[i]=tx[i]-cx;ty[i]=ty[i]-cy}a=tx[at2];b=ty[at2];d=Math.sqrt(a*a+b*b);ad=a/d;bd=b/d;for(i=0;i<g_mol[h].numOfAtoms;i++){tempx=tx[i]*ad+ty[i]*bd;tempy=tx[i]*bd-ty[i]*ad;tx[i]=tempx;ty[i]=tempy}for(i=0;i<6;i++){g_doubleX[i]=0;g_doubleY[i]=0}if(bt==2){offset=.16*d;if(g_mol[h].atomType[at1]!="C"&&g_mol[h].atomType[at2]!="C"){g_doubleX[0]=tx[at1]+offset;g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2]-offset;g_doubleY[1]=ty[at2];g_doubleX[2]=tx[at1]+offset;g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2]-offset;g_doubleY[3]=ty[at2]-offset;g_doubleX[4]=tx[at1]+offset;g_doubleY[4]=ty[at1]+offset;g_doubleX[5]=tx[at2]-offset;g_doubleY[5]=ty[at2]+offset}else if(g_mol[h].atomType[at1]!="C"){g_doubleX[0]=tx[at1]+offset;g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2];g_doubleY[1]=ty[at2];g_doubleX[2]=tx[at1]+offset;g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2];g_doubleY[3]=ty[at2]-offset;g_doubleX[4]=tx[at1]+offset;g_doubleY[4]=ty[at1]+offset;g_doubleX[5]=tx[at2];g_doubleY[5]=ty[at2]+offset}else if(g_mol[h].atomType[at2]!="C"){g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2]-offset;g_doubleY[1]=ty[at2];g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2]-offset;g_doubleY[3]=ty[at2]-offset;g_doubleX[4]=tx[at1];g_doubleY[4]=ty[at1]+offset;g_doubleX[5]=tx[at2]-offset;g_doubleY[5]=ty[at2]+offset}else{g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2];g_doubleY[1]=ty[at2];g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2];g_doubleY[3]=ty[at2]-offset;g_doubleX[4]=tx[at1];g_doubleY[4]=ty[at1]+offset;g_doubleX[5]=tx[at2];g_doubleY[5]=ty[at2]+offset}}else if(bt==0){offset=.08*d;if(g_mol[h].atomType[at1]!="C"&&g_mol[h].atomType[at2]!="C"){g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2]-offset;g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1];g_doubleX[3]=tx[at2]-offset;g_doubleY[3]=ty[at2]-offset}else if(g_mol[h].atomType[at1]!="C"){g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2];g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1];g_doubleX[3]=tx[at2];g_doubleY[3]=ty[at2]-offset}else if(g_mol[h].atomType[at2]!="C"){g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2]-offset;g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1];g_doubleX[3]=tx[at2]-offset;g_doubleY[3]=ty[at2]-offset}else{g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2];g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1];g_doubleX[3]=tx[at2];g_doubleY[3]=ty[at2]-offset}}else if(bt==1||bt==4){if(bt==1&&(g_mol[h].numOfAtchAtoms[at1]==1||g_mol[h].numOfAtchAtoms[at2]==1)){offset=.08*d;if(g_mol[h].atomType[at1]!="C"&&g_mol[h].atomType[at2]!="C"){g_doubleX[0]=tx[at1]+offset;g_doubleY[0]=ty[at1]+offset;g_doubleX[1]=tx[at2]-offset;g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1]+offset;g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2]-offset;g_doubleY[3]=ty[at2]-offset}else if(g_mol[h].atomType[at1]!="C"){g_doubleX[0]=tx[at1]+offset;g_doubleY[0]=ty[at1]+offset;g_doubleX[1]=tx[at2];g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1]+offset;g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2];g_doubleY[3]=ty[at2]-offset}else if(g_mol[h].atomType[at2]!="C"){g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1]+offset;g_doubleX[1]=tx[at2]-offset;g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2]-offset;g_doubleY[3]=ty[at2]-offset}else{g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1]+offset;g_doubleX[1]=tx[at2];g_doubleY[1]=ty[at2]+offset;g_doubleX[2]=tx[at1];g_doubleY[2]=ty[at1]-offset;g_doubleX[3]=tx[at2];g_doubleY[3]=ty[at2]-offset}}else{p=n=0;tp1=tn1=tp2=tn2=-1;for(i=0;i<g_mol[h].numOfAtchAtoms[at1];i++){k=g_mol[h].atchAtoms[at1][i];if(k!=at2){if(ty[k]>0){tp1=k;p++;for(j=0;j<g_mol[h].numOfAtchAtoms[k];j++){if(g_mol[h].atchAtoms[k][j]!=at1){if(g_mol[h].atchAtomsBtype[k][j]==1||g_mol[h].atchAtomsBtype[k][j]==4){p++}}}}else{tn1=k;n++;for(j=0;j<g_mol[h].numOfAtchAtoms[k];j++){if(g_mol[h].atchAtoms[k][j]!=at1){if(g_mol[h].atchAtomsBtype[k][j]==1||g_mol[h].atchAtomsBtype[k][j]==4){n++}}}}}}for(i=0;i<g_mol[h].numOfAtchAtoms[at2];i++){k=g_mol[h].atchAtoms[at2][i];if(k!=at1){if(ty[k]>0){tp2=k;p++;for(j=0;j<g_mol[h].numOfAtchAtoms[k];j++){if(g_mol[h].atchAtoms[k][j]!=at2){if(g_mol[h].atchAtomsBtype[k][j]==1||g_mol[h].atchAtomsBtype[k][j]==4){p++}}}}else{tn2=k;n++;for(j=0;j<g_mol[h].numOfAtchAtoms[k];j++){if(g_mol[h].atchAtoms[k][j]!=at2){if(g_mol[h].atchAtomsBtype[k][j]==1||g_mol[h].atchAtomsBtype[k][j]==4){n++}}}}}}offset=.2*d;g_doubleX[0]=tx[at1];g_doubleY[0]=ty[at1];g_doubleX[1]=tx[at2];g_doubleY[1]=ty[at2];if(p>=n){if(tp1>-1){tempd=(ty[tp1]-ty[at1])/(tx[tp1]-tx[at1]);if(tempd>0){theta=Math.atan(tempd)/2}else{theta=(pi-Math.atan(Math.abs(tempd)))/2}g_doubleX[2]=tx[at1]+offset/Math.tan(theta)}else{g_doubleX[2]=tx[at1]}if(tp2>-1){tempd=(ty[tp2]-ty[at2])/(tx[tp2]-tx[at2]);if(tempd>=0){theta=(pi-Math.atan(tempd))/2}else{theta=Math.atan(Math.abs(tempd))/2}g_doubleX[3]=tx[at2]-offset/Math.tan(theta)}else{g_doubleX[3]=tx[at2]}g_doubleY[2]=ty[at1]-offset;g_doubleY[3]=ty[at2]-offset}else{if(tn1>-1){tempd=(ty[tn1]-ty[at1])/(tx[tn1]-tx[at1]);if(tempd>=0){theta=(pi-Math.atan(tempd))/2}else{theta=Math.atan(Math.abs(tempd))/2}g_doubleX[2]=tx[at1]+offset/Math.tan(theta)}else{g_doubleX[2]=tx[at1]}if(tn2>-1){tempd=(ty[tn2]-ty[at2])/(tx[tn2]-tx[at2]);if(tempd>0){theta=Math.atan(tempd)/2}else{theta=(pi-Math.atan(Math.abs(tempd)))/2}g_doubleX[3]=tx[at2]-offset/Math.tan(theta)}else{g_doubleX[3]=tx[at2]}g_doubleY[2]=ty[at1]+offset;g_doubleY[3]=ty[at2]+offset}}}tempx=g_doubleX[0]*ad-g_doubleY[0]*bd;tempy=g_doubleY[0]*ad+g_doubleX[0]*bd;g_doubleX[0]=tempx;g_doubleY[0]=tempy;g_doubleX[0]=g_doubleX[0]+cx;g_doubleY[0]=g_doubleY[0]+cy;tempx=g_doubleX[1]*ad-g_doubleY[1]*bd;tempy=g_doubleY[1]*ad+g_doubleX[1]*bd;g_doubleX[1]=tempx;g_doubleY[1]=tempy;g_doubleX[1]=g_doubleX[1]+cx;g_doubleY[1]=g_doubleY[1]+cy;tempx=g_doubleX[2]*ad-g_doubleY[2]*bd;tempy=g_doubleY[2]*ad+g_doubleX[2]*bd;g_doubleX[2]=tempx;g_doubleY[2]=tempy;g_doubleX[2]=g_doubleX[2]+cx;g_doubleY[2]=g_doubleY[2]+cy;tempx=g_doubleX[3]*ad-g_doubleY[3]*bd;tempy=g_doubleY[3]*ad+g_doubleX[3]*bd;g_doubleX[3]=tempx;g_doubleY[3]=tempy;g_doubleX[3]=g_doubleX[3]+cx;g_doubleY[3]=g_doubleY[3]+cy;if(bt==2){tempx=g_doubleX[4]*ad-g_doubleY[4]*bd;tempy=g_doubleY[4]*ad+g_doubleX[4]*bd;g_doubleX[4]=tempx;g_doubleY[4]=tempy;g_doubleX[4]=g_doubleX[4]+cx;g_doubleY[4]=g_doubleY[4]+cy;tempx=g_doubleX[5]*ad-g_doubleY[5]*bd;tempy=g_doubleY[5]*ad+g_doubleX[5]*bd;g_doubleX[5]=tempx;g_doubleY[5]=tempy;g_doubleX[5]=g_doubleX[5]+cx;g_doubleY[5]=g_doubleY[5]+cy}}function add2DScatterPlot(divid,w,h){if(g_strSize==0){g_strSize=150}var scatterDiv=document.getElementById(divid);while(scatterDiv.hasChildNodes()){scatterDiv.removeChild(scatterDiv.lastChild)}scatterDiv.onwheel=function(event){event.preventDefault()};scatterDiv.onmousewheel=function(event){event.preventDefault()};scatterDiv.ontouch=function(event){event.preventDefault()};var width=w;var height=h;var canvas=document.createElement("canvas");var offcan=document.createElement("canvas");canvas.setAttribute("width",width);canvas.setAttribute("height",height);canvas.setAttribute("id","canvas");scatterDiv.appendChild(canvas);offcan.width=canvas.width;offcan.height=canvas.height;if(typeof G_vmlCanvasManager!="undefined"){canvas=G_vmlCanvasManager.initElement(canvas)}var context=canvas.getContext("2d");var offctx=offcan.getContext("2d");var crect=canvas.getBoundingClientRect();var crect_left;var crect_top;if(navigator.sayswho.match(/Chrome/)){crect_left=crect.left+window.scrollX;crect_top=crect.top+window.scrollY}else{crect_left=crect.left;crect_top=crect.top}var lastClicked;var translate=false;canvas.addEventListener("mousedown",whenMouseDown,false);canvas.addEventListener("mousemove",whenMouseMove,false);canvas.addEventListener("mouseup",whenMouseUp,false);canvas.addEventListener("mouseout",whenMouseOut,false);canvas.addEventListener("mousewheel",whenMouseWheel,false);canvas.addEventListener("touchstart",whenTouchStart,false);canvas.addEventListener("touchmove",whenTouchMove,false);canvas.addEventListener("touchend",whenTouchEnd,false);canvas.addEventListener("touchleave",whenTouchLeave,false);var fontSize=12;var fontFamily="Arial";var font=fontSize+"px "+fontFamily;var zoom=0;var pzoom=0;var nameList=[];var scaledData=[];var colMin=[];var colMax=[];var colorList=[];var headList=[];var markerSize=10;var moveMargin=50;var numOfXGrids=5;var numOfYGrids=5;var mx=sx1=sx2=psx2=0;var my=sy1=sy2=psy2=0;var startX=moveMargin;var startY=height-moveMargin;var red2green=false;var molList=[];var findItemsInGraph;var myRequest=createXMLHttpRequest();var selItem;var url;var curMol;var prvTouchDis;parseData(scatterDiv.getAttribute("data-tsv"));drawData();this.zoomIn=function(){pzoom=zoom;zoom++;if(pzoom!=zoom){drawData()}};this.zoomOut=function(){pzoom=zoom;zoom--;if(zoom<=0){pzoom=zoom=0;startX=moveMargin;startY=height-moveMargin}drawData()};this.removeAll=function(){molList.length=0;drawData()};this.reverseColor=function(){red2green=!red2green;colorData(red2green);drawData()};function parseData(data){var i,j,k,min,max,mid,item1,item2;var headerExist;if(scaledData.length>0){for(i=0;i<scaledData.length;i++){scaledData[i].length=0}scaledData.length=0;nameList.length=0;colorList.length=0;headList.length=0}data=data.replace(/\r\n/g,"\n");item1=data.split("\n");headerExist=false;for(i=0;i<item1.length;i++){if(item1[i].match(" ")){item2=item1[i].split(" ")}else{item2=item1[i].split(" ")}if(i==0){k=0;for(j=1;j<item2.length;j++){headList[j-1]=item2[j];if(isNumeric(item2[j])){k++}}if(k==item2.length-1){headList[0]="x";headList[1]="y";headList[2]="z"}else{headerExist=true}}if(headerExist){k=i-1}else{k=i}if(k>-1){scaledData[k]=new Array(3);colorList[k]=new Array(2);nameList[k]=item2[0];for(j=1;j<item2.length;j++){scaledData[k][j-1]=parseFloat(item2[j])}}}for(j=0;j<3;j++){min=max=0;for(i=0;i<scaledData.length;i++){if(i==0){min=max=scaledData[i][j]}else{if(scaledData[i][j]<min){min=scaledData[i][j]}if(max<scaledData[i][j]){max=scaledData[i][j]}}}if(j<2){if(max==min){for(i=0;i<scaledData.length;i++){scaledData[i][j]=.5}colMin[j]=min-.5;colMax[j]=max+.5}else{for(i=0;i<scaledData.length;i++){scaledData[i][j]=(scaledData[i][j]-min)/(max-min)}colMin[j]=min;colMax[j]=max}}else{colMin[j]=min;colMax[j]=max}}colorData(true)}function colorData(r2g){var i,min,max,mid,val,r,g;if(r2g){red2green=true}else{red2green=false}min=colMin[2];max=colMax[2];mid=(min+max)/2;for(i=0;i<scaledData.length;i++){val=scaledData[i][2];if(r2g){if(val<mid){r=255;g=Math.round(255*(val-min)/(mid-min))}else{r=255-Math.round(255*(val-mid)/(max-mid));g=255}}else{if(val<mid){r=Math.round(255*(val-min)/(mid-min));g=255}else{r=255;g=255-Math.round(255*(val-mid)/(max-mid))}}if(r<0){r=0}if(255<r){r=255}if(g<0){g=0}if(255<g){g=255}colorList[i][0]=r;colorList[i][1]=g}}function drawBox(){var i,nw,nh,ux,uy,u;nw=width-2*moveMargin;nh=height-2*moveMargin;ux=nw/numOfXGrids;uy=nh/numOfYGrids;offctx.strokeStyle="lightgray";offctx.beginPath();for(i=0;i<=numOfXGrids;i++){drawLine(offctx,moveMargin+i*ux,moveMargin,moveMargin+i*ux,height-moveMargin+markerSize)}for(i=0;i<=numOfYGrids;i++){drawLine(offctx,moveMargin-markerSize,height-moveMargin-i*uy,width-moveMargin,height-moveMargin-i*uy)}offctx.closePath();offctx.stroke();offctx.fillStyle="black";u=(colMax[0]-colMin[0])/numOfXGrids;for(i=0;i<=numOfXGrids;i++){offctx.fillText((colMin[0]+i*u).toPrecision(4),moveMargin+i*ux,height-moveMargin+markerSize+10)}u=(colMax[1]-colMin[1])/numOfYGrids;offctx.translate(moveMargin,height-moveMargin);offctx.rotate(-Math.PI/2);for(i=0;i<=numOfYGrids;i++){offctx.fillText((colMin[1]+i*u).toPrecision(4),i*uy,-markerSize-2)}offctx.rotate(Math.PI/2);offctx.translate(-moveMargin,-height+moveMargin)}function drawData(){var min=[];var max=[];var minId=[];var maxId=[];var x=[];var y=[];var display=[];var xe=[];var ye=[];var posUsed=[];var i,j,isFirst,ndisplay,txi,tyi,key;var nw=width-2*moveMargin;var nh=height-2*moveMargin;var tx,ty,dx,dy;offctx.font=font;offctx.fillStyle="white";offctx.fillRect(0,0,width,height);posUsed.length=0;if(zoom==0&&startX==moveMargin&&startY==height-moveMargin){drawBox()}if(zoom!=pzoom){tx=Math.pow(2,zoom)*(mx-startX);tx=tx/Math.pow(2,pzoom);ty=Math.pow(2,zoom)*(my-startY);ty=ty/Math.pow(2,pzoom);startX=mx-tx;startY=my-ty;pzoom=zoom}isFirst=true;ndisplay=0;for(i=0;i<width;i++){xe[i]=false}for(i=0;i<height;i++){ye[i]=false}for(i=0;i<scaledData.length;i++){display[i]=false;tx=startX+Math.pow(2,zoom)*nw*scaledData[i][0];ty=startY-Math.pow(2,zoom)*nh*scaledData[i][1];txi=Math.round(tx);tyi=Math.round(ty);x[i]=txi;y[i]=tyi;if(moveMargin<=tx&&tx<=width-moveMargin&&moveMargin<=ty&&ty<=height-moveMargin){if(isFirst){isFirst=false;min[0]=max[0]=x[i];min[1]=max[1]=y[i];minId[0]=maxId[0]=i;minId[1]=maxId[1]=i}if(translate&&scaledData.length>=2e4){display[i]=true;ndisplay++;if(!xe[txi]||!ye[tyi]){if(x[i]<min[0]){min[0]=x[i];minId[0]=i}if(max[0]<x[i]){max[0]=x[i];maxId[0]=i}if(min[1]<y[i]){min[1]=y[i];minId[1]=i}if(y[i]<max[1]){max[1]=y[i];maxId[1]=i}xe[txi]=ye[tyi]=true}}else{if(!xe[txi]||!ye[tyi]){xe[txi]=ye[tyi]=true}key=x[i]+","+y[i];if(posUsed[key]==null){display[i]=true;if(x[i]<min[0]){min[0]=x[i];minId[0]=i}if(max[0]<x[i]){max[0]=x[i];maxId[0]=i}if(min[1]<y[i]){min[1]=y[i];minId[1]=i}if(y[i]<max[1]){max[1]=y[i];maxId[1]=i}posUsed[key]=i}else{posUsed[key]=posUsed[key]+","+i}}}}for(i=0;i<molList.length;i++){dx=molList[i].x2-molList[i].x1;dy=molList[i].y2-molList[i].y1;molList[i].x1=x[molList[i].idx]-startX;molList[i].y1=y[molList[i].idx]-startY;molList[i].x2=molList[i].x1+dx;molList[i].y2=molList[i].y1+dy}offctx.beginPath();offctx.strokeStyle="black";drawLine(offctx,moveMargin,height-moveMargin,width-moveMargin,height-moveMargin);drawLine(offctx,moveMargin,moveMargin,moveMargin,height-moveMargin);offctx.closePath();offctx.stroke();min[0]=(colMax[0]-colMin[0])*scaledData[minId[0]][0]+colMin[0];max[0]=(colMax[0]-colMin[0])*scaledData[maxId[0]][0]+colMin[0];min[1]=(colMax[1]-colMin[1])*scaledData[minId[1]][1]+colMin[1];max[1]=(colMax[1]-colMin[1])*scaledData[maxId[1]][1]+colMin[1];offctx.beginPath();offctx.strokeStyle="darkGray";drawLine(offctx,x[minId[0]],moveMargin,x[minId[0]],height-moveMargin+markerSize);if(minId[0]!=maxId[0]){drawLine(offctx,x[maxId[0]],moveMargin,x[maxId[0]],height-moveMargin+markerSize)}offctx.closePath();offctx.stroke();offctx.fillStyle="black";offctx.fillText(min[0].toPrecision(4),x[minId[0]],height-moveMargin+markerSize+10);if(minId[0]!=maxId[0]){offctx.fillText(max[0].toPrecision(4),x[maxId[0]],height-moveMargin+markerSize+10)}offctx.beginPath();offctx.strokeStyle="darkGray";drawLine(offctx,moveMargin-markerSize,y[minId[1]],width-moveMargin,y[minId[1]]);if(minId[1]!=maxId[1]){drawLine(offctx,moveMargin-markerSize,y[maxId[1]],width-moveMargin,y[maxId[1]])}if(minId[1]!=maxId[1]){drawLine(offctx,moveMargin-markerSize,y[maxId[1]],width-moveMargin,y[maxId[1]])}offctx.closePath();offctx.stroke();offctx.translate(moveMargin,y[minId[1]]);offctx.rotate(-Math.PI/2);offctx.fillText(min[1].toPrecision(4),0,-markerSize-2);offctx.rotate(Math.PI/2);offctx.translate(-moveMargin,-y[minId[1]]);if(minId[1]!=maxId[1]){offctx.translate(moveMargin,y[maxId[1]]);offctx.rotate(-Math.PI/2);offctx.fillText(max[1].toPrecision(4),0,-markerSize-2);offctx.rotate(Math.PI/2);offctx.translate(-moveMargin,-y[maxId[1]])}offctx.strokeStyle="black";offctx.beginPath();offctx.rect(0,0,width,height);for(i=0;i<scaledData.length;i++){if(ndisplay>1e3&&translate&&scaledData.length>=2e4){if(display[i]&&Math.floor(Math.random()*100)%100==0){offctx.fillStyle="rgba("+colorList[i][0]+","+colorList[i][1]+",0,1)";offctx.fillRect(x[i]-markerSize,y[i]-markerSize,2*markerSize,2*markerSize);offctx.strokeStyle="black";if(xe[Math.round(x[i])]){drawLine(offctx,x[i],height-10,x[i],height)}if(ye[Math.round(y[i])]){drawLine(offctx,0,y[i],10,y[i])}}}else{if(display[i]){offctx.fillStyle="rgba("+colorList[i][0]+","+colorList[i][1]+",0,1)";offctx.fillRect(x[i]-markerSize,y[i]-markerSize,2*markerSize,2*markerSize);if(findItemsInGraph){if(x[i]-markerSize<sx1&&sx1<x[i]+markerSize&&(y[i]-markerSize<sy1&&sy1<y[i]+markerSize)){selItem=i;findItemsInGraph=false;if(selItem>-1){if(nameList[selItem].match(/CHEMBL/)||nameList[selItem].match(/_/)){scatterDiv.style.cursor="wait";url="http://cheminformatic.com/getstr.php?id=";url+=nameList[selItem];myRequest.open("GET",url,true);myRequest.onreadystatechange=processData;myRequest.send(null)}}}}offctx.strokeStyle="black";txi=Math.round(x[i]);tyi=Math.round(y[i]);if(xe[txi]){xe[txi]=false;drawLine(offctx,x[i],height-10,x[i],height)}if(ye[tyi]){ye[tyi]=false;drawLine(offctx,0,y[i],10,y[i])}}}}offctx.closePath();offctx.stroke();var label,fo;fo=2;offctx.fillStyle="black";offctx.fillText(headList[2],width/2-fo*headList[2].length,20);if(red2green){label="red ("+colMin[2]+") to green ("+colMax[2]+")"}else{label="green ("+colMin[2]+") to red ("+colMax[2]+")"}offctx.fillText(label,width/2-fo*label.length,35);offctx.fillText(headList[0],width/2-fo*headList[0].length,height-14);offctx.translate(markerSize,height/2);offctx.rotate(-Math.PI/2);offctx.fillText(headList[1],0-fo*headList[1].length,10);drawCopyright1(offctx,0-65,width-20);offctx.rotate(Math.PI/2);offctx.translate(-markerSize,-height/2);drawStructures();context.drawImage(offcan,0,0)}function drawStructures(){var i;for(i=0;i<molList.length;i++){g_mol.length=0;g_mol[0]=molList[i];offctx.beginPath();offctx.strokeStyle="black";drawLine(offctx,startX+g_mol[0].x1,startY+g_mol[0].y1,startX+g_mol[0].x2+g_strSize/2,startY+g_mol[0].y2+g_strSize/2);offctx.closePath();offctx.stroke();offctx.fillStyle="white";offctx.fillRect(startX+g_mol[0].x2,startY+g_mol[0].y2,g_strSize,g_strSize);drawStructure(offctx,startX+g_strSize/2,startY+g_strSize/2,0);offctx.beginPath();offctx.strokeStyle="gray";offctx.rect(startX+g_mol[0].x2,startY+g_mol[0].y2,g_strSize,g_strSize);offctx.closePath();offctx.stroke()}}function processData(){if(myRequest.readyState==4){if(myRequest.status==200){var data=myRequest.responseText.split("\n");var mdata,cdata;var item;var h,i;var f;mdata="";cdata="";for(i=0;i<data.length;i++){if(data[i].match(/===/)){mdata+=data[i]+"\n"}else{cdata+=data[i]+"\n"}}if(mdata==""){alert("Not found.")}else{parseStructureData(mdata.trim());if(g_numOfMols>0){g_mol[0].idx=selItem;g_mol[0].x1=g_mol[0].x2=sx1-startX;g_mol[0].y1=g_mol[0].y2=sy1-startY;molList[molList.length]=g_mol[0]}drawData()}}else{alert("HTTP error: "+myRequest.status)}scatterDiv.style.cursor="default"}}function submitRequest(){findItemsInGraph=true;selItem=-1;drawData()}function curSelMol(){var i,cx,cy,x,y;curMol=-1;cx=sx1-startX;cy=sy1-startY;for(i=0;i<molList.length;i++){x=molList[i].x2;y=molList[i].y2;if(x<=cx&&cx<=x+g_strSize&&y<=cy&&cy<=y+g_strSize){curMol=i;break}}}function whenMouseDown(event){event.preventDefault();tranlate=false;sx1=sx2=psx2=event.pageX-crect_left;sy1=sy2=psy2=event.pageY-crect_top;curSelMol();if(Date.now()-lastClicked<200){if(curMol>-1){window.open("http://cheminformatic.com/chembl/activity.php?"+molList[curMol].name)}else{submitRequest()}}else if(curMol==-1){translate=true}}function whenMouseMove(event){event.preventDefault();mx=sx2=event.pageX-crect_left;my=sy2=event.pageY-crect_top;if(translate){startX=startX+(sx2-psx2);startY=startY+(sy2-psy2);drawData()}else if(curMol>-1){var x,y;x=molList[curMol].x2+(sx2-psx2);y=molList[curMol].y2+(sy2-psy2);molList[curMol].x2=x;molList[curMol].y2=y;drawData()}psx2=sx2;psy2=sy2}function whenMouseUp(event){translate=false;curMol=-1;drawData();lastClicked=Date.now()}function whenMouseOut(event){translate=false;curMol=-1}function whenMouseWheel(event){event.preventDefault();translate=false;pzoom=zoom;if(event.wheelDelta<0){zoom--}else{zoom++}if(zoom<=0){pzoom=zoom=0;startX=moveMargin;startY=height-moveMargin}drawData()}function whenTouchStart(event){event.preventDefault();if(event.targetTouches.length==1){var touch=event.targetTouches[0];mx=sx1=sx2=psx2=touch.pageX-crect_left;my=sy1=sy2=psy2=touch.pageY-crect_top;translate=false;curSelMol();if(Date.now()-lastClicked<200){if(curMol>-1){window.open("http://cheminformatic.com/chembl/activity.php?"+molList[curMol].name)}else{submitRequest()}}else if(curMol==-1){translate=true}}prvTouchDis=0}function whenTouchMove(event){event.preventDefault();var touch,tdis,tx1,ty1,tx2,ty2;if(event.targetTouches.length==1){touch=event.targetTouches[0];mx=sx2=touch.pageX-crect_left;my=sy2=touch.pageY-crect_top;if(translate){startX=startX+(sx2-psx2);startY=startY+(sy2-psy2);drawData()}else if(curMol>-1){var x,y;x=molList[curMol].x2+(sx2-psx2);y=molList[curMol].y2+(sy2-psy2);molList[curMol].x2=x;molList[curMol].y2=y;drawData()}psx2=sx2;psy2=sy2}else if(event.targetTouches.length==2){touch=event.targetTouches[0];tx1=touch.pageX-crect_left;ty1=touch.pageY-crect_top;touch=event.targetTouches[1];tx2=touch.pageX-crect_left;ty2=touch.pageY-crect_top;pzoom=zoom;tdis=(tx1-tx2)*(tx1-tx2)+(ty1-ty2)*(ty1-ty2);if(prvTouchDis==0){prvTouchDis=tdis}else if(prvTouchDis<tdis){zoom++;translate=false}else if(tdis<prvTouchDis){zoom--;translate=false}mx=(tx1+tx2)/2;my=(ty1+ty2)/2;if(zoom<=0){pzoom=zoom=0;startX=moveMargin;startY=height-moveMargin;prvTouchDis=0}drawData()}}function whenTouchEnd(event){translate=false;lastClicked=Date.now()}function whenTouchLeave(event){translate=false}}function add3DScatterPlot(divid,w,h){if(g_strSize==0){g_strSize=150}var scatterDiv=document.getElementById(divid);while(scatterDiv.hasChildNodes()){scatterDiv.removeChild(scatterDiv.lastChild)}scatterDiv.onwheel=function(event){event.preventDefault()};scatterDiv.onmousewheel=function(event){event.preventDefault()};scatterDiv.ontouch=function(event){event.preventDefault()};var width=w;var height=h;var canvas=document.createElement("canvas");var offcan=document.createElement("canvas");canvas.setAttribute("width",width);canvas.setAttribute("height",height);canvas.setAttribute("id","canvas");scatterDiv.appendChild(canvas);offcan.width=canvas.width;offcan.height=canvas.height;if(typeof G_vmlCanvasManager!="undefined"){canvas=G_vmlCanvasManager.initElement(canvas)}var context=canvas.getContext("2d");var offctx=offcan.getContext("2d");var crect=canvas.getBoundingClientRect();var crect_left;var crect_top;if(navigator.sayswho.match(/Chrome/)){crect_left=crect.left+window.scrollX;crect_top=crect.top+window.scrollY}else{crect_left=crect.left;crect_top=crect.top}var lastClicked;var action="STOP";canvas.addEventListener("mousedown",whenMouseDown,false);canvas.addEventListener("mousemove",whenMouseMove,false);canvas.addEventListener("mouseup",whenMouseUp,false);canvas.addEventListener("mouseout",whenMouseOut,false);canvas.addEventListener("mousewheel",whenMouseWheel,false);canvas.addEventListener("touchstart",whenTouchStart,false);canvas.addEventListener("touchmove",whenTouchMove,false);canvas.addEventListener("touchend",whenTouchEnd,false);canvas.addEventListener("touchleave",whenTouchLeave,false);var fontSize=12;var fontFamily="Arial";var font=fontSize+"px "+fontFamily;var zoom=0;var pzoom=0;var nameList=[];var scaledData=[];var colMin=[];var colMax=[];var minVal=[];var maxVal=[];var colorList=[];var headList=[];var modelMat=[];var tmpMat=[];var xRot,yRot;var markerSize=10;var moveMargin=50;var numOfXGrids=5;var numOfYGrids=5;var numOfZGrids=5;var mx=sx1=sx2=psx2=0;var my=sy1=sy2=psy2=0;var startX=moveMargin;var startY=height-moveMargin;var red2green=false;var molList=[];var findItemsInGraph;var myRequest=createXMLHttpRequest();var selItem;var url;var curMol,curScale;var prvTouchDis;parseData(scatterDiv.getAttribute("data-tsv"));drawData();this.zoomIn=function(){action="SCALE";curScale=1.2;drawData();action="STOP"};this.zoomOut=function(){action="SCALE";curScale=.8;drawData();action="STOP"};this.removeAll=function(){molList.length=0;drawData()};this.reverseColor=function(){red2green=!red2green;colorData(red2green);drawData()};function parseData(data){var i,j,k,min,max,mid,item1,item2;var headerExist;if(scaledData.length>0){for(i=0;i<scaledData.length;i++){scaledData[i].length=0}scaledData.length=0;nameList.length=0;colorList.length=0;headList.length=0}data=data.replace(/\r\n/g,"\n");item1=data.split("\n");headerExist=false;for(i=0;i<item1.length;i++){if(item1[i].match(" ")){item2=item1[i].split(" ")}else{item2=item1[i].split(" ")}if(i==0){k=0;for(j=1;j<item2.length;j++){headList[j-1]=item2[j];if(isNumeric(item2[j])){k++}}if(k==item2.length-1){headList[0]="x";headList[1]="y";headList[2]="z";headList[3]="c"}else{headerExist=true}}if(headerExist){k=i-1}else{k=i}if(k>-1){scaledData[k]=new Array(4);colorList[k]=new Array(2);nameList[k]=item2[0];for(j=1;j<item2.length;j++){scaledData[k][j-1]=parseFloat(item2[j])}}}for(j=0;j<4;j++){min=max=0;for(i=0;i<scaledData.length;i++){if(i==0){min=max=scaledData[i][j]}else{if(scaledData[i][j]<min){min=scaledData[i][j]}if(max<scaledData[i][j]){max=scaledData[i][j]}}}if(j<3){if(max==min){for(i=0;i<scaledData.length;i++){scaledData[i][j]=.5}colMin[j]=min-.5;colMax[j]=max+.5}else{for(i=0;i<scaledData.length;i++){scaledData[i][j]=(scaledData[i][j]-min)/(max-min)-.5}colMin[j]=min;colMax[j]=max}}else{colMin[j]=min;colMax[j]=max}}colorData(true);minVal[0]=minVal[1]=minVal[2]=-.5;maxVal[0]=maxVal[1]=maxVal[2]=.5;Minitialize(modelMat)}function colorData(r2g){var i,min,max,mid,val,r,g;if(r2g){red2green=true}else{red2green=false}min=colMin[3];max=colMax[3];mid=(min+max)/2;for(i=0;i<scaledData.length;i++){val=scaledData[i][3];if(r2g){if(val<mid){r=255;g=Math.round(255*(val-min)/(mid-min))}else{r=255-Math.round(255*(val-mid)/(max-mid));g=255}}else{if(val<mid){r=Math.round(255*(val-min)/(mid-min));g=255}else{r=255;g=255-Math.round(255*(val-mid)/(max-mid))}}if(r<0){r=0}if(255<r){r=255}if(g<0){g=0}if(255<g){g=255}colorList[i][0]=r;colorList[i][1]=g}}function drawBox(drawAll){var i,xp0,yp0,xp1,yp1,xp2,yp2,xp3,yp3;var minx,miny,minz,maxx,maxy,maxz;var zp0,zp1,zp2,zp3,f,ux,uy,uz,u;var winxyz=[];minx=minVal[0];miny=minVal[1];minz=minVal[2];maxx=maxVal[0];maxy=maxVal[1];maxz=maxVal[2];if(drawAll){offctx.beginPath();offctx.strokeStyle="gray";ux=1/numOfXGrids;uy=1/numOfYGrids;uz=1/numOfZGrids;for(i=1;i<=numOfYGrids;i++){gluProject(width,height,modelMat,minx,miny+i*uy,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];gluProject(width,height,modelMat,maxx,miny+i*uy,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];drawLine(offctx,xp0,yp0,xp1,yp1)}for(i=1;i<=numOfZGrids;i++){gluProject(width,height,modelMat,minx,miny,minz+i*uz,winxyz);xp0=winxyz[0];yp0=winxyz[1];gluProject(width,height,modelMat,maxx,miny,minz+i*uz,winxyz);xp1=winxyz[0];yp1=winxyz[1];drawLine(offctx,xp0,yp0,xp1,yp1)}for(i=1;i<=numOfXGrids;i++){gluProject(width,height,modelMat,minx+i*ux,miny,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];gluProject(width,height,modelMat,minx+i*ux,maxy,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];drawLine(offctx,xp0,yp0,xp1,yp1)}for(i=1;i<=numOfZGrids;i++){gluProject(width,height,modelMat,minx,miny,minz+i*uz,winxyz);xp0=winxyz[0];yp0=winxyz[1];gluProject(width,height,modelMat,minx,maxy,minz+i*uz,winxyz);xp1=winxyz[0];yp1=winxyz[1];drawLine(offctx,xp0,yp0,xp1,yp1)}for(i=1;i<=numOfXGrids;i++){gluProject(width,height,modelMat,minx+i*ux,miny,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];gluProject(width,height,modelMat,minx+i*ux,miny,maxz,winxyz);xp1=winxyz[0];yp1=winxyz[1];drawLine(offctx,xp0,yp0,xp1,yp1)}for(i=1;i<=numOfYGrids;i++){gluProject(width,height,modelMat,minx,miny+i*uy,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];gluProject(width,height,modelMat,minx,miny+i*uy,maxz,winxyz);xp1=winxyz[0];yp1=winxyz[1];drawLine(offctx,xp0,yp0,xp1,yp1)}offctx.closePath();offctx.stroke();offctx.fillStyle="black";u=(colMax[0]-colMin[0])/numOfXGrids;for(i=1;i<=numOfXGrids;i++){gluProject(width,height,modelMat,minx+i*ux,miny,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];f=colMin[0]+i*u;offctx.fillText(f.toPrecision(4),xp0,yp0)}u=(colMax[1]-colMin[1])/numOfYGrids;for(i=1;i<=numOfYGrids;i++){gluProject(width,height,modelMat,minx,miny+i*uy,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];f=colMin[1]+i*u;offctx.fillText(f.toPrecision(4),xp0,yp0)}u=(colMax[2]-colMin[2])/numOfYGrids;for(i=1;i<=numOfZGrids;i++){gluProject(width,height,modelMat,minx,miny,minz+i*uz,winxyz);xp0=winxyz[0];yp0=winxyz[1];f=colMin[2]+i*u;offctx.fillText(f.toPrecision(4),xp0,yp0)}}offctx.beginPath();offctx.strokeStyle="black";gluProject(width,height,modelMat,maxx,maxy,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,maxx,miny,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,minx,maxy,minz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,maxx,maxy,maxz,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}gluProject(width,height,modelMat,maxx,maxy,maxz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,maxx,maxy,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,maxx,miny,maxz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,minx,maxy,maxz,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}gluProject(width,height,modelMat,maxx,miny,maxz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,maxx,miny,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,maxx,maxy,maxz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,minx,miny,maxz,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}gluProject(width,height,modelMat,maxx,miny,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,maxx,miny,maxz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,maxx,maxy,minz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,minx,miny,minz,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}gluProject(width,height,modelMat,minx,maxy,maxz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,minx,maxy,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,maxx,maxy,maxz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,minx,miny,maxz,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}gluProject(width,height,modelMat,minx,maxy,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,minx,maxy,maxz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,maxx,maxy,minz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,minx,miny,minz,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}gluProject(width,height,modelMat,minx,miny,maxz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,minx,miny,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,maxx,miny,maxz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,minx,maxy,maxz,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}f=.2;gluProject(width,height,modelMat,minx,miny,minz,winxyz);xp0=winxyz[0];yp0=winxyz[1];zp0=winxyz[2];gluProject(width,height,modelMat,maxx+f,miny,minz,winxyz);xp1=winxyz[0];yp1=winxyz[1];gluProject(width,height,modelMat,minx,maxy+f,minz,winxyz);xp2=winxyz[0];yp2=winxyz[1];gluProject(width,height,modelMat,minx,miny,maxz+f,winxyz);xp3=winxyz[0];yp3=winxyz[1];if(drawAll||zp0>.5){drawLine(offctx,xp0,yp0,xp1,yp1);drawLine(offctx,xp0,yp0,xp2,yp2);drawLine(offctx,xp0,yp0,xp3,yp3)}offctx.closePath();offctx.stroke();if(!drawAll){offctx.fillStyle="black";offctx.fillText(headList[0],xp1,yp1);offctx.fillText(headList[1],xp2,yp2);offctx.fillText(headList[2],xp3,yp3)}}function drawData(){var n,disNum,ranfra;var lookup=[];var order=[];var display=[];var x2=[];var y2=[];var z2=[];var x3=[];var y3=[];var posUsed=[];var i,j;var winxyz=[];offctx.font=font;offctx.fillStyle="white";offctx.fillRect(0,0,width,height);n=scaledData.length;disNum=1e4;if(action=="XYROTATE"||action=="SCALE"){Minitialize(tmpMat);if(action=="XYROTATE"){Mxrotate(tmpMat,xRot);Myrotate(tmpMat,yRot);if(scaledData.length>disNum){n=disNum}}else if(action=="SCALE"){Mscale(tmpMat,curScale,curScale,curScale)}Mmultiply(modelMat,tmpMat)}drawBox(true);posUsed.length=0;ranfra=scaledData.length;for(i=0;i<n;i++){if(scaledData.length>disNum&&action=="XYROTATE"){j=Math.round(ranfra*Math.random());if(j>=scaledData.length){j=scaledData.length-1}}else{j=i}order[i]=i;lookup[i]=j;gluProject(width,height,modelMat,scaledData[j][0],scaledData[j][1],scaledData[j][2],winxyz);x2[i]=winxyz[0];y2[i]=winxyz[1];z2[i]=winxyz[2]}quickSort(z2,order,0,n-1,false);for(h=0;h<n;h++){i=order[h];j=lookup[i];x=x2[i];y=y2[i];display[i]=false;key=x+","+y;if(posUsed[key]==null){display[i]=true;posUsed[key]=posUsed[key]+","+j}else{posUsed[key]=posUsed[key]+","+j}}x3.length=0;y3.length=0;k=-1;for(h=n-1;h>=0;h--){i=order[h];x=x2[i];y=y2[i];if(display[i]){offctx.fillStyle="rgba("+colorList[i][0]+","+colorList[i][1]+",0,1)";offctx.fillRect(x-markerSize,y-markerSize,2*markerSize,2*markerSize);if(findItemsInGraph){if(x-markerSize<sx1&&sx1<x+markerSize&&y-markerSize<sy1&&sy1<y+markerSize){selItem=i;findItemsInGraph=false;if(nameList[selItem].match(/CHEMBL/)||nameList[selItem].match(/_/)){scatterDiv.style.cursor="wait";url="http://cheminformatic.com/getstr.php?id=";url+=nameList[selItem];myRequest.open("GET",url,true);myRequest.onreadystatechange=processData;myRequest.send(null)}}}}}for(i=0;i<molList.length;i++){molList[i].x1=x2[molList[i].idx]-startX;molList[i].y1=y2[molList[i].idx]-startY}x3.length=0;y3.length=0;lookup.length=0;order.length=0;display.length=0;x2.length=0;y2.length=0;z2.length=0;drawBox(false);var label,fo;fo=2;offctx.fillStyle="black";offctx.fillText(headList[3],width/2-fo*headList[3].length,20);if(red2green){label="red ("+colMin[3]+") to green ("+colMax[3]+")"}else{label="green ("+colMin[3]+") to red ("+colMax[3]+")"}offctx.fillText(label,width/2-fo*label.length,35);drawCopyright1(offctx,width/2-50,height-20);drawStructures();context.drawImage(offcan,0,0)}function drawStructures(){var i;for(i=0;i<molList.length;i++){g_mol.length=0;g_mol[0]=molList[i];offctx.beginPath();offctx.strokeStyle="black";drawLine(offctx,startX+g_mol[0].x1,startY+g_mol[0].y1,startX+g_mol[0].x2+g_strSize/2,startY+g_mol[0].y2+g_strSize/2);offctx.closePath();offctx.stroke();offctx.fillStyle="white";offctx.fillRect(startX+g_mol[0].x2,startY+g_mol[0].y2,g_strSize,g_strSize);drawStructure(offctx,startX+g_strSize/2,startY+g_strSize/2,0);offctx.beginPath();offctx.strokeStyle="gray";offctx.rect(startX+g_mol[0].x2,startY+g_mol[0].y2,g_strSize,g_strSize);offctx.closePath();offctx.stroke()}}function processData(){if(myRequest.readyState==4){if(myRequest.status==200){var data=myRequest.responseText.split("\n");var mdata,cdata;var item;var h,i;var f;mdata="";cdata="";for(i=0;i<data.length;i++){if(data[i].match(/===/)){mdata+=data[i]+"\n"}else{cdata+=data[i]+"\n"}}if(mdata==""){alert("Not found.")}else{parseStructureData(mdata.trim());if(g_numOfMols>0){g_mol[0].idx=selItem;g_mol[0].x1=g_mol[0].x2=sx1-startX;g_mol[0].y1=g_mol[0].y2=sy1-startY;molList[molList.length]=g_mol[0]}drawData()}}else{alert("HTTP error: "+myRequest.status)}scatterDiv.style.cursor="default"}}function submitRequest(){findItemsInGraph=true;selItem=-1;drawData()}function curSelMol(){var i,cx,cy,x,y;curMol=-1;cx=sx1-startX;cy=sy1-startY;for(i=0;i<molList.length;i++){x=molList[i].x2;y=molList[i].y2;if(x<=cx&&cx<=x+g_strSize&&y<=cy&&cy<=y+g_strSize){curMol=i;break}}}function whenMouseDown(event){event.preventDefault();action="STOP";sx1=sx2=psx2=event.pageX-crect_left;sy1=sy2=psy2=event.pageY-crect_top;curSelMol();if(Date.now()-lastClicked<200){if(curMol>-1){window.open("http://cheminformatic.com/chembl/activity.php?"+molList[curMol].name)}else{submitRequest()}}else if(curMol==-1){action="XYROTATE"}}function whenMouseMove(event){event.preventDefault();mx=sx2=event.pageX-crect_left;my=sy2=event.pageY-crect_top;if(curMol>-1){var x,y;x=molList[curMol].x2+(sx2-psx2);y=molList[curMol].y2+(sy2-psy2);molList[curMol].x2=x;molList[curMol].y2=y;drawData()}else if(action=="XYROTATE"){xRot=(psy2-sy2)*360/width;yRot=(sx2-psx2)*360/height;drawData()}psx2=sx2;psy2=sy2}function whenMouseUp(event){action="STOP";curMol=-1;drawData();lastClicked=Date.now()}function whenMouseOut(event){action="STOP";curMol=-1}function whenMouseWheel(event){event.preventDefault();action="SCALE";if(event.wheelDelta<0){curScale=.8}else{curScale=1.2}drawData()}function whenTouchStart(event){event.preventDefault();if(event.targetTouches.length==1){var touch=event.targetTouches[0];mx=sx1=sx2=psx2=touch.pageX-crect_left;my=sy1=sy2=psy2=touch.pageY-crect_top;action="STOP";curSelMol();if(Date.now()-lastClicked<200){if(curMol>-1){window.open("http://cheminformatic.com/chembl/activity.php?"+molList[curMol].name);}else{submitRequest()}}else if(curMol==-1){action="XYROTATE"}}prvTouchDis=0}function whenTouchMove(event){event.preventDefault();var touch,tdis,tx1,ty1,tx2,ty2;if(event.targetTouches.length==1){touch=event.targetTouches[0];mx=sx2=touch.pageX-crect_left;my=sy2=touch.pageY-crect_top;if(action=="XYROTATE"){xRot=(psy2-sy2)*360/width;yRot=(sx2-psx2)*360/height;drawData()}else if(curMol>-1){var x,y;x=molList[curMol].x2+(sx2-psx2);y=molList[curMol].y2+(sy2-psy2);molList[curMol].x2=x;molList[curMol].y2=y;drawData()}psx2=sx2;psy2=sy2}else if(event.targetTouches.length==2){touch=event.targetTouches[0];tx1=touch.pageX-crect_left;ty1=touch.pageY-crect_top;touch=event.targetTouches[1];tx2=touch.pageX-crect_left;ty2=touch.pageY-crect_top;tdis=(tx1-tx2)*(tx1-tx2)+(ty1-ty2)*(ty1-ty2);if(prvTouchDis==0){prvTouchDis=tdis}else if(prvTouchDis<tdis){curScale=.8;action="STOP"}else if(tdis<prvTouchDis){curScale=1.2;action="STOP"}drawData()}}function whenTouchEnd(event){action="STOP";curMol=-1;drawData();lastClicked=Date.now()}function whenTouchLeave(event){action="STOP";curMol=-1}}var stIsIE=false;sorttable={init:function(){if(arguments.callee.done)return;arguments.callee.done=true;if(_timer)clearInterval(_timer);if(!document.createElement||!document.getElementsByTagName)return;sorttable.DATE_RE=/^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/;forEach(document.getElementsByTagName("table"),function(table){if(table.className.search(/\bsortable\b/)!=-1){sorttable.makeSortable(table)}});var iframes=parent.document.getElementsByTagName("iframe");for(var i=0;i<iframes.length;i++){forEach(iframes[i].contentDocument.getElementsByTagName("table"),function(table){if(table.className.search(/\bsortable\b/)!=-1){sorttable.makeSortable(table)}})}iframes=document.getElementsByTagName("iframe");for(var i=0;i<iframes.length;i++){forEach(iframes[i].contentDocument.getElementsByTagName("table"),function(table){if(table.className.search(/\bsortable\b/)!=-1){sorttable.makeSortable(table)}})}},makeSortable:function(table){if(table.getElementsByTagName("thead").length==0){the=document.createElement("thead");the.appendChild(table.rows[0]);table.insertBefore(the,table.firstChild)}if(table.tHead==null)table.tHead=table.getElementsByTagName("thead")[0];if(table.tHead.rows.length!=1)return;sortbottomrows=[];for(var i=0;i<table.rows.length;i++){if(table.rows[i].className.search(/\bsortbottom\b/)!=-1){sortbottomrows[sortbottomrows.length]=table.rows[i]}}if(sortbottomrows){if(table.tFoot==null){tfo=document.createElement("tfoot");table.appendChild(tfo)}for(var i=0;i<sortbottomrows.length;i++){tfo.appendChild(sortbottomrows[i])}delete sortbottomrows}headrow=table.tHead.rows[0].cells;for(var i=0;i<headrow.length;i++){if(!headrow[i].className.match(/\bsorttable_nosort\b/)){mtch=headrow[i].className.match(/\bsorttable_([a-z0-9]+)\b/);if(mtch){override=mtch[1]}if(mtch&&typeof sorttable["sort_"+override]=="function"){headrow[i].sorttable_sortfunction=sorttable["sort_"+override]}else{headrow[i].sorttable_sortfunction=sorttable.guessType(table,i)}headrow[i].sorttable_columnindex=i;headrow[i].sorttable_tbody=table.tBodies[0];dean_addEvent(headrow[i],"click",sorttable.innerSortFunction=function(e){if(this.className.search(/\bsorttable_sorted\b/)!=-1){sorttable.reverse(this.sorttable_tbody);this.className=this.className.replace("sorttable_sorted","sorttable_sorted_reverse");this.removeChild(document.getElementById("sorttable_sortfwdind"));sortrevind=document.createElement("span");sortrevind.id="sorttable_sortrevind";sortrevind.innerHTML=stIsIE?' <font face="webdings">5</font>':" ▴";this.appendChild(sortrevind);return}if(this.className.search(/\bsorttable_sorted_reverse\b/)!=-1){sorttable.reverse(this.sorttable_tbody);this.className=this.className.replace("sorttable_sorted_reverse","sorttable_sorted");this.removeChild(document.getElementById("sorttable_sortrevind"));sortfwdind=document.createElement("span");sortfwdind.id="sorttable_sortfwdind";sortfwdind.innerHTML=stIsIE?' <font face="webdings">6</font>':" ▾";this.appendChild(sortfwdind);return}theadrow=this.parentNode;forEach(theadrow.childNodes,function(cell){if(cell.nodeType==1){cell.className=cell.className.replace("sorttable_sorted_reverse","");cell.className=cell.className.replace("sorttable_sorted","")}});sortfwdind=document.getElementById("sorttable_sortfwdind");if(sortfwdind){sortfwdind.parentNode.removeChild(sortfwdind)}sortrevind=document.getElementById("sorttable_sortrevind");if(sortrevind){sortrevind.parentNode.removeChild(sortrevind)}this.className+=" sorttable_sorted";sortfwdind=document.createElement("span");sortfwdind.id="sorttable_sortfwdind";sortfwdind.innerHTML=stIsIE?' <font face="webdings">6</font>':" ▾";this.appendChild(sortfwdind);row_array=[];col=this.sorttable_columnindex;rows=this.sorttable_tbody.rows;for(var j=0;j<rows.length;j++){row_array[row_array.length]=[sorttable.getInnerText(rows[j].cells[col]),rows[j]]}row_array.sort(this.sorttable_sortfunction);tb=this.sorttable_tbody;for(var j=0;j<row_array.length;j++){tb.appendChild(row_array[j][1])}delete row_array})}}},guessType:function(table,column){sortfn=sorttable.sort_alpha;for(var i=0;i<table.tBodies[0].rows.length;i++){text=sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);if(text!=""){if(text.match(/^-?[�$�]?[\d,.]+%?$/)){return sorttable.sort_numeric}possdate=text.match(sorttable.DATE_RE);if(possdate){first=parseInt(possdate[1]);second=parseInt(possdate[2]);if(first>12){return sorttable.sort_ddmm}else if(second>12){return sorttable.sort_mmdd}else{sortfn=sorttable.sort_ddmm}}}}return sortfn},getInnerText:function(node){if(!node)return"";hasInputs=typeof node.getElementsByTagName=="function"&&node.getElementsByTagName("input").length;if(node.getAttribute("sorttable_customkey")!=null){return node.getAttribute("sorttable_customkey")}else if(typeof node.textContent!="undefined"&&!hasInputs){return node.textContent.replace(/^\s+|\s+$/g,"")}else if(typeof node.innerText!="undefined"&&!hasInputs){return node.innerText.replace(/^\s+|\s+$/g,"")}else if(typeof node.text!="undefined"&&!hasInputs){return node.text.replace(/^\s+|\s+$/g,"")}else{switch(node.nodeType){case 3:if(node.nodeName.toLowerCase()=="input"){return node.value.replace(/^\s+|\s+$/g,"")}case 4:return node.nodeValue.replace(/^\s+|\s+$/g,"");break;case 1:case 11:var innerText="";for(var i=0;i<node.childNodes.length;i++){innerText+=sorttable.getInnerText(node.childNodes[i])}return innerText.replace(/^\s+|\s+$/g,"");break;default:return""}}},reverse:function(tbody){newrows=[];for(var i=0;i<tbody.rows.length;i++){newrows[newrows.length]=tbody.rows[i]}for(var i=newrows.length-1;i>=0;i--){tbody.appendChild(newrows[i])}delete newrows},sort_numeric:function(a,b){aa=parseFloat(a[0].replace(/[^0-9.-]/g,""));if(isNaN(aa))aa=0;bb=parseFloat(b[0].replace(/[^0-9.-]/g,""));if(isNaN(bb))bb=0;return aa-bb},sort_alpha:function(a,b){if(a[0]==b[0])return 0;if(a[0]<b[0])return-1;return 1},sort_ddmm:function(a,b){mtch=a[0].match(sorttable.DATE_RE);y=mtch[3];m=mtch[2];d=mtch[1];if(m.length==1)m="0"+m;if(d.length==1)d="0"+d;dt1=y+m+d;mtch=b[0].match(sorttable.DATE_RE);y=mtch[3];m=mtch[2];d=mtch[1];if(m.length==1)m="0"+m;if(d.length==1)d="0"+d;dt2=y+m+d;if(dt1==dt2)return 0;if(dt1<dt2)return-1;return 1},sort_mmdd:function(a,b){mtch=a[0].match(sorttable.DATE_RE);y=mtch[3];d=mtch[2];m=mtch[1];if(m.length==1)m="0"+m;if(d.length==1)d="0"+d;dt1=y+m+d;mtch=b[0].match(sorttable.DATE_RE);y=mtch[3];d=mtch[2];m=mtch[1];if(m.length==1)m="0"+m;if(d.length==1)d="0"+d;dt2=y+m+d;if(dt1==dt2)return 0;if(dt1<dt2)return-1;return 1},shaker_sort:function(list,comp_func){var b=0;var t=list.length-1;var swap=true;while(swap){swap=false;for(var i=b;i<t;++i){if(comp_func(list[i],list[i+1])>0){var q=list[i];list[i]=list[i+1];list[i+1]=q;swap=true}}t--;if(!swap)break;for(var i=t;i>b;--i){if(comp_func(list[i],list[i-1])<0){var q=list[i];list[i]=list[i-1];list[i-1]=q;swap=true}}b++}}};if(document.addEventListener){document.addEventListener("DOMContentLoaded",sorttable.init,false)}if(/WebKit/i.test(navigator.userAgent)){var _timer=setInterval(function(){if(/loaded|complete/.test(document.readyState)){sorttable.init()}},10)}window.onload=sorttable.init;function dean_addEvent(element,type,handler){if(element.addEventListener){element.addEventListener(type,handler,false)}else{if(!handler.$$guid)handler.$$guid=dean_addEvent.guid++;if(!element.events)element.events={};var handlers=element.events[type];if(!handlers){handlers=element.events[type]={};if(element["on"+type]){handlers[0]=element["on"+type]}}handlers[handler.$$guid]=handler;element["on"+type]=handleEvent}}dean_addEvent.guid=1;function removeEvent(element,type,handler){if(element.removeEventListener){element.removeEventListener(type,handler,false)}else{if(element.events&&element.events[type]){delete element.events[type][handler.$$guid]}}}function handleEvent(event){var returnValue=true;event=event||fixEvent(((this.ownerDocument||this.document||this).parentWindow||window).event);var handlers=this.events[event.type];for(var i in handlers){this.$$handleEvent=handlers[i];if(this.$$handleEvent(event)===false){returnValue=false}}return returnValue}function fixEvent(event){event.preventDefault=fixEvent.preventDefault;event.stopPropagation=fixEvent.stopPropagation;return event}fixEvent.preventDefault=function(){this.returnValue=false};fixEvent.stopPropagation=function(){this.cancelBubble=true};if(!Array.forEach){Array.forEach=function(array,block,context){for(var i=0;i<array.length;i++){block.call(context,array[i],i,array)}}}Function.prototype.forEach=function(object,block,context){for(var key in object){if(typeof this.prototype[key]=="undefined"){block.call(context,object[key],key,object)}}};String.forEach=function(string,block,context){Array.forEach(string.split(""),function(chr,index){block.call(context,chr,index,string)})};var forEach=function(object,block,context){if(object){var resolve=Object;if(object instanceof Function){resolve=Function}else if(object.forEach instanceof Function){object.forEach(block,context);return}else if(typeof object=="string"){resolve=String}else if(typeof object.length=="number"){resolve=Array}resolve.forEach(object,block,context)}};function addTV(divid,width,height){if(g_strSize==0){g_strSize=150}var tvDiv=document.getElementById(divid);while(tvDiv.hasChildNodes()){tvDiv.removeChild(tvDiv.lastChild)}tvDiv.onwheel=function(event){event.preventDefault()};tvDiv.onmousewheel=function(event){event.preventDefault()};tvDiv.ontouch=function(event){event.preventDefault()};var canvas=document.createElement("canvas");var offcan=document.createElement("canvas");canvas.setAttribute("width",width);canvas.setAttribute("height",height);canvas.setAttribute("id","canvas");tvDiv.appendChild(canvas);offcan.width=canvas.width;offcan.height=canvas.height;if(typeof G_vmlCanvasManager!="undefined"){canvas=G_vmlCanvasManager.initElement(canvas)}var context=canvas.getContext("2d");var offctx=offcan.getContext("2d");var crect=canvas.getBoundingClientRect();var crect_left;var crect_top;if(navigator.sayswho.match(/Chrome/)){crect_left=crect.left+window.scrollX;crect_top=crect.top+window.scrollY}else{crect_left=crect.left;crect_top=crect.top}var lastClicked;canvas.addEventListener("mousedown",whenMouseDown,false);canvas.addEventListener("mousemove",whenMouseMove,false);canvas.addEventListener("mouseup",whenMouseUp,false);canvas.addEventListener("mouseout",whenMouseOut,false);canvas.addEventListener("mousewheel",whenMouseWheel,false);canvas.addEventListener("touchstart",whenTouchStart,false);canvas.addEventListener("touchmove",whenTouchMove,false);canvas.addEventListener("touchend",whenTouchEnd,false);canvas.addEventListener("touchleave",whenTouchLeave,false);var fontSize=10;var fontFamily="Arial";var font=fontSize+"px "+fontFamily;var zoom=0;var tileSize=256;var numOfTilesInOneSide=1;var tileRadius=2;var curSize=256;var tsx=width/2-tileSize/2;var tsy=height/2-tileSize/2;var mx=tsx;my=tsy;var curi=0;curj=0;var move=false;var margin=50;var sx1,sx2,psx2,sy1,sy2,psy2;var newLevel;var tileImgs=[];var prvTouchDis=0;var myRequest=createXMLHttpRequest();var molList=[];var curMol;var colorList=[];var targetList=[];var curCid="CHEMBL1288156";targetList[0]="CYP450";colorList[0]="red";targetList[1]="GPCR";colorList[1]="lime";targetList[2]="Ion Channel";colorList[2]="deepskyblue";targetList[3]="Kinase";colorList[3]="blue";targetList[4]="Nuclear";colorList[4]="orange";targetList[5]="PDE";colorList[5]="violet";targetList[6]="Phosphatase";colorList[6]="purple";targetList[7]="Protease";colorList[7]="yellow";targetList[8]="Multiple";colorList[8]="black";targetList[9]="Other";colorList[9]="silver";targetList[10]="Ring";colorList[10]="green";tvDiv.style.cursor="default";newLevel=true;getTiles();this.removeAll=function(){molList.length=0;drawTiles()};this.zoomIn=function(){var prv;prv=zoom;zoom++;if(zoom>6){zoom=6}if(prv!=zoom){newLevel=true;getTiles()}};this.zoomOut=function(){var prv;prv=zoom;zoom--;if(zoom<0){zoom=0}if(prv!=zoom){newLevel=true;getTiles()}};this.find=function(cid){var query;if(cid==""){query=prompt("Please enter ChEMBL ID:",curCid)}else{query=curCid=cid}if(query.match(/CHEMBL/)){var url="http://cheminformatic.com/mmpnet/node2str.php?dir="+divid+"&q="+query;myRequest.open("GET",url,true);myRequest.onreadystatechange=processData;myRequest.send(null)}};function getTiles(){var i,j,ib,ie,jb,je,ii,jj;var x,y,f,dx,dy;tvDiv.style.cursor="wait";if(newLevel){numOfTilesInOneSide=Math.pow(2,zoom);if(tileImgs.length>0){for(i=0;i<tileImgs.length;i++){tileImgs[i].length=0}tileImgs.length=0}for(i=0;i<numOfTilesInOneSide;i++){tileImgs[i]=new Array(numOfTilesInOneSide)}prvSize=curSize;curSize=tileSize*numOfTilesInOneSide;x=curSize*(mx-tsx);x=x/prvSize;y=curSize*(my-tsy);y=y/prvSize;curi=Math.floor(x/tileSize);curj=Math.floor(y/tileSize);tsx=mx-Math.round(x);tsy=my-Math.round(y);newLevel=false;f=curSize/prvSize;for(i=0;i<molList.length;i++){x=molList[i].x1;y=molList[i].y1;dx=molList[i].x2-x;dy=molList[i].y2-y;molList[i].x1=f*x;molList[i].y1=f*y;x=molList[i].x1+dx;y=molList[i].y1+dy;molList[i].x2=x;molList[i].y2=y}}else{tsx=tsx+(sx2-psx2);tsy=tsy+(sy2-psy2);curi=Math.floor((sx2-tsx)/tileSize);curj=Math.floor((sy2-tsy)/tileSize)}if(tileImgs.length>0){ib=curi-tileRadius;ie=curi+tileRadius;jb=curj-tileRadius;je=curj+tileRadius;if(ib<0){ib=0}if(ib>numOfTilesInOneSide-1){ib=numOfTilesInOneSide-1}if(ie<0){ie=0}if(ie>numOfTilesInOneSide-1){ie=numOfTilesInOneSide-1}if(jb<0){jb=0}if(jb>numOfTilesInOneSide-1){jb=numOfTilesInOneSide-1}if(je<0){je=0}if(je>numOfTilesInOneSide-1){je=numOfTilesInOneSide-1}ii=jj=-1;for(i=ib;i<=ie;i++){for(j=jb;j<=je;j++){if(!tileImgs[i][j]){tileImgs[i][j]=new Image;tileImgs[i][j].src="http://cheminformatic.com/tile/"+divid+"/z"+zoom+"x"+i+"y"+j+".png";ii=i;jj=j}}}if(ii>-1&&jj>-1){tileImgs[ii][jj].onload=function(){drawTiles()}}else{drawTiles()}}}function drawTiles(){var i,j,n,ib,ie,jb,je,x,y;n=tileRadius;ib=curi-n;ie=curi+n;jb=curj-n;je=curj+n;if(ib<0){ib=0}if(ib>numOfTilesInOneSide-1){ib=numOfTilesInOneSide-1}if(ie<0){ie=0}if(ie>numOfTilesInOneSide-1){ie=numOfTilesInOneSide-1}if(jb<0){jb=0}if(jb>numOfTilesInOneSide-1){jb=numOfTilesInOneSide-1}if(je<0){je=0}if(je>numOfTilesInOneSide-1){je=numOfTilesInOneSide-1}offctx.fillStyle="white";offctx.fillRect(0,0,width,height);for(i=ib;i<=ie;i++){x=tsx+tileSize*i;for(j=jb;j<=je;j++){y=tsy+tileSize*j;if(tileImgs[i][j]){offctx.drawImage(tileImgs[i][j],x,y)}}}offctx.beginPath();offctx.strokeStyle="black";offctx.fillStyle="black";offctx.rect(0,0,width,height);offctx.closePath();offctx.stroke();drawStructuresOnTiles();offctx.beginPath();for(i=0;i<targetList.length;i++){offctx.fillStyle=colorList[i];offctx.fillRect(4,4+12*i,10,10);offctx.fillStyle="black";offctx.fillText(targetList[i],17,13+12*i)}offctx.fillText("Z="+zoom,4,20+12*targetList.length);drawCopyright1(offctx,width-140,height-10);offctx.closePath();offctx.stroke();context.drawImage(offcan,0,0);tvDiv.style.cursor="default"}function drawStructuresOnTiles(){var i;for(i=0;i<molList.length;i++){g_mol.length=0;g_mol[0]=molList[i];offctx.beginPath();offctx.strokeStyle="black";drawLine(offctx,tsx+g_mol[0].x1,tsy+g_mol[0].y1,tsx+g_mol[0].x2+g_strSize/2,tsy+g_mol[0].y2+g_strSize/2);offctx.closePath();offctx.stroke();offctx.fillStyle="white";offctx.fillRect(tsx+g_mol[0].x2,tsy+g_mol[0].y2,g_strSize,g_strSize);drawStructure(offctx,tsx+g_strSize/2,tsy+g_strSize/2,0);offctx.beginPath();offctx.strokeStyle="gray";offctx.rect(tsx+g_mol[0].x2,tsy+g_mol[0].y2,g_strSize,g_strSize);offctx.closePath();offctx.stroke()}}function processData(){if(myRequest.readyState==4){if(myRequest.status==200){var data=myRequest.responseText.split("\n");var mdata,cdata;var item;var h,i;var f;mdata="";cdata="";for(i=0;i<data.length;i++){if(data[i].match(/===/)){mdata+=data[i]+"\n"}else{cdata+=data[i]+"\n"}}if(mdata==""){alert("Not found.")}else{parseStructureData(mdata.trim());if(g_numOfMols>0){data=cdata.trim().split("\n");for(h=0;h<data.length;h++){item=data[h].split(" ");i=parseInt(item[0]);f=curSize/(64*tileSize);g_mol[i].x1=g_mol[i].x2=f*parseFloat(item[2]);g_mol[i].y1=g_mol[i].y2=f*parseFloat(item[3]);molList[molList.length]=g_mol[i]}drawTiles()}}tvDiv.style.cursor="default"}else{alert("HTTP error: "+myRequest.status)}}}function submitRequest(){tvDiv.style.cursor="wait";var x,y,f,tx,ty;x=sx1-tsx;y=sy1-tsy;f=64*tileSize/curSize;x=f*x;y=f*y;tx=Math.floor(x/tileSize);ty=Math.floor(y/tileSize);var url="http://cheminformatic.com/mmpnet/node2str.php?dir="+divid+"&x="+x+"&y="+y+"&tx="+tx+"&ty="+ty;myRequest.open("GET",url,true);myRequest.onreadystatechange=processData;myRequest.send(null)}function curSelMol(){var i,cx,cy,x,y;curMol=-1;cx=sx1-tsx;cy=sy1-tsy;for(i=0;i<molList.length;i++){x=molList[i].x2;y=molList[i].y2;if(x<=cx&&cx<=x+g_strSize&&y<=cy&&cy<=y+g_strSize){curMol=i;break}}}function whenMouseDown(event){event.preventDefault();sx1=sx2=psx2=event.pageX-crect_left;sy1=sy2=psy2=event.pageY-crect_top;curSelMol();move=true;if(Date.now()-lastClicked<200){if(curMol>-1){window.open("http://cheminformatic.com/chembl/activity.php?"+molList[curMol].name)}else{submitRequest()}}}function whenMouseMove(event){event.preventDefault();mx=sx2=event.pageX-crect_left;my=sy2=event.pageY-crect_top;if(move){if(curMol>-1){var x,y;x=molList[curMol].x2+(sx2-psx2);y=molList[curMol].y2+(sy2-psy2);molList[curMol].x2=x;molList[curMol].y2=y;drawTiles()}else{getTiles()}psx2=sx2;psy2=sy2}}function whenMouseUp(event){move=false;lastClicked=Date.now()}function whenMouseOut(event){move=false}function whenMouseWheel(event){event.preventDefault();var prv;prv=zoom;if(event.wheelDelta<0){zoom--}else{zoom++}if(zoom<0){zoom=0}else if(zoom>6){zoom=6}if(prv!=zoom){newLevel=true;getTiles()}}function whenTouchStart(event){event.preventDefault();if(event.targetTouches.length==1){var touch=event.targetTouches[0];mx=sx1=sx2=psx2=touch.pageX-crect_left;my=sy1=sy2=psy2=touch.pageY-crect_top;curSelMol();if(Date.now()-lastClicked<200){if(curMol>-1){window.open("http://cheminformatic.com/chembl/activity.php?"+molList[curMol].name)}else{submitRequest()}}}move=true;prvTouchDis=0}function whenTouchMove(event){event.preventDefault();var touch,tdis,tx1,ty1,tx2,ty2,prv;if(move){if(event.targetTouches.length==1){touch=event.targetTouches[0];mx=sx2=touch.pageX-crect_left;my=sy2=touch.pageY-crect_top;if(curMol>-1){x=molList[curMol].x2+(sx2-psx2);y=molList[curMol].y2+(sy2-psy2);molList[curMol].x2=x;molList[curMol].y2=y;drawTiles()}else{getTiles()}psx2=sx2;psy2=sy2}else if(event.targetTouches.length==2){touch=event.targetTouches[0];tx1=touch.pageX-crect_left;ty1=touch.pageY-crect_top;touch=event.targetTouches[1];tx2=touch.pageX-crect_left;ty2=touch.pageY-crect_top;prv=zoom;tdis=(tx1-tx2)*(tx1-tx2)+(ty1-ty2)*(ty1-ty2);if(prvTouchDis==0){prvTouchDis=tdis}else if(prvTouchDis<tdis){zoom++;move=false}else if(tdis<prvTouchDis){zoom--;move=false}mx=(tx1+tx2)/2;my=(ty1+ty2)/2;if(zoom<0){zoom=0}else if(zoom>6){zoom=6}if(prv!=zoom){newLevel=true;getTiles();prvTouchDis=0}}}}function whenTouchEnd(event){move=false;lastClicked=Date.now()}function whenTouchLeave(event){move=false}}