/* 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(x2){drawTick(context,x,middle,.5*tickSize)}}}context.closePath();context.stroke();for(i=0;i1){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-101&&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(prvTouchDis0){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(leftleft&&key[rightIndex]>middleElement){rightIndex--}}else{while(leftIndexmiddleElement){leftIndex++}while(rightIndex>left&&key[rightIndex]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;h0){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;i0){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;i0){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;i0){atom2color[item[i]]="lime"}else{atom2color[item[i]]="red"}atomTVS[item[i]]=item[i+1]}context.globalAlpha=.3;for(i=0;i0){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;i0){tp1=k;p++;for(j=0;j0){tp2=k;p++;for(j=0;j=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-1){scaledData[k]=new Array(3);colorList[k]=new Array(2);nameList[k]=item2[0];for(j=1;j=2e4){display[i]=true;ndisplay++;if(!xe[txi]||!ye[tyi]){if(x[i]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-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;i0){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-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(prvTouchDis0){for(i=0;i-1){scaledData[k]=new Array(4);colorList[k]=new Array(2);nameList[k]=item2[0];for(j=1;j.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;idisNum&&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=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-markerSize0){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-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(prvTouchDis5':" ▴";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?' 6':" ▾";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?' 6':" ▾";this.appendChild(sortfwdind);row_array=[];col=this.sorttable_columnindex;rows=this.sorttable_tbody.rows;for(var j=0;j12){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=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]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;i6){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;i0){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;i0){data=cdata.trim().split("\n");for(h=0;h-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(prvTouchDis6){zoom=6}if(prv!=zoom){newLevel=true;getTiles();prvTouchDis=0}}}}function whenTouchEnd(event){move=false;lastClicked=Date.now()}function whenTouchLeave(event){move=false}}