From c7e005df2e5dee2cbedd716d5a087f2c6695c8c9 Mon Sep 17 00:00:00 2001 From: David Koes Date: Thu, 19 May 2016 12:03:30 -0400 Subject: [PATCH] update release --- release/3Dmol-min.js | 711 +++++++++++---------- release/3Dmol-nojquery-min.js | 711 +++++++++++---------- release/3Dmol-nojquery.js | 1107 +++++++++++++++++++++++++++------ release/3Dmol.js | 1107 +++++++++++++++++++++++++++------ 4 files changed, 2600 insertions(+), 1036 deletions(-) diff --git a/release/3Dmol-min.js b/release/3Dmol-min.js index fc70f88aa..1417a581f 100644 --- a/release/3Dmol-min.js +++ b/release/3Dmol-min.js @@ -185,6 +185,20 @@ h||"fixed"===h)&&-1c;c++){var d=f();b[d]=f()}return b}function c(c){var d=b.subarray(a,a+c);return a+=c,d}function k(c){var d=b.subarray(a,a+c);a+=c;if(65535c;c++)b[c]=f();return b}function f(){var f,h,l,m=b[a];if(0===(128&m))return a++,m;if(128===(240&m))return h=15&m,a++,g(h);if(144===(240&m))return h=15&m,a++,d(h);if(160===(224&m))return h=31&m,a++,k(h);if(224===(224&m))return f=e.getInt8(a),a++,f;switch(m){case 192:return a++,null;case 194:return a++,!1;case 195:return a++,!0;case 196:return h=e.getUint8(a+1),a+=2,c(h);case 197:return h=e.getUint16(a+1),a+=3,c(h);case 198:return h=e.getUint32(a+1),a+=5,c(h); +case 199:return h=e.getUint8(a+1),l=e.getUint8(a+2),a+=3,[l,c(h)];case 200:return h=e.getUint16(a+1),l=e.getUint8(a+3),a+=4,[l,c(h)];case 201:return h=e.getUint32(a+1),l=e.getUint8(a+5),a+=6,[l,c(h)];case 202:return f=e.getFloat32(a+1),a+=5,f;case 203:return f=e.getFloat64(a+1),a+=9,f;case 204:return f=b[a+1],a+=2,f;case 205:return f=e.getUint16(a+1),a+=3,f;case 206:return f=e.getUint32(a+1),a+=5,f;case 207:return a+=9,0;case 208:return f=e.getInt8(a+1),a+=2,f;case 209:return f=e.getInt16(a+1),a+= +3,f;case 210:return f=e.getInt32(a+1),a+=5,f;case 211:return a+=9,0;case 212:return l=e.getUint8(a+1),a+=2,[l,c(1)];case 213:return l=e.getUint8(a+1),a+=2,[l,c(2)];case 214:return l=e.getUint8(a+1),a+=2,[l,c(4)];case 215:return l=e.getUint8(a+1),a+=2,[l,c(8)];case 216:return l=e.getUint8(a+1),a+=2,[l,c(16)];case 217:return h=e.getUint8(a+1),a+=2,k(h);case 218:return h=e.getUint16(a+1),a+=3,k(h);case 219:return h=e.getUint32(a+1),a+=5,k(h);case 220:return h=e.getUint16(a+1),a+=3,d(h);case 221:return h= +e.getUint32(a+1),a+=5,d(h);case 222:return h=e.getUint16(a+1),a+=3,g(h);case 223:return h=e.getUint32(a+1),a+=5,g(h)}throw Error("Unknown type 0x"+m.toString(16));}var a=0,e=new DataView(b.buffer);return f()}function A(b){return new Uint8Array(b.buffer,b.byteOffset,b.byteLength)}function H(b){return new Int8Array(b.buffer,b.byteOffset,b.byteLength)}function n(b,g){var c,k,d;d=(b.byteOffset,b.byteLength);g||(g=new Int32Array(d/4));k=c=0;for(d/=4;d>c;++c,k+=4)g[c]=b[k]<<24^b[k+1]<<16^b[k+2]<<8^b[k+ +3]<<0;return g}function w(b,g,c){var k=b.length;g=1/g;c||(c=new Float32Array(k));for(var d=0;k>d;++d)c[d]=b[d]*g;return c}function u(b,g){var c,k;if(!g){var d=0;c=0;for(k=b.length;k>c;c+=2)d+=b[c+1];g=new b.constructor(d)}c=d=0;for(k=b.length;k>c;c+=2)for(var f=b[c],a=b[c+1],e=0;a>e;++e)g[d]=f,d+=1;return g}function B(b){for(var g=1,c=b.length;c>g;++g)b[g]+=b[g-1];return b}function z(b,g,c,k){var d=b.length/4/2+g.length/2;k||(k=new Float32Array(d));d=new Int32Array(k.buffer,k.byteOffset,k.byteLength/ +4);b=n(b);var f=void 0,a,e,r;r=(g.byteOffset,g.byteLength);f||(f=new Int16Array(r/2));e=a=0;for(r/=2;r>a;++a,e+=2)f[a]=g[e]<<8^g[e+1]<<0;g=f;f=b.length/2+g.length;d||(d=new Int32Array(f));e=a=f=0;for(r=b.length;r>e;e+=2){var h=b[e+1];d[f]=b[e];0!==e&&(d[f]+=d[f-1]);for(var f=f+1,l=0;h>l;++l)d[f]=d[f-1]+g[a],f+=1,a+=1}return w(d,c,k)}function I(b,g,c){var k=c?new Int32Array(c.buffer,c.byteOffset,c.byteLength/4):void 0;b=u(n(b),k);return w(b,g,c)}function J(b,g){function c(a){return k?-1===k.indexOf(a): +!0}g=g||{};var k=g.ignoreFields,d=(b.numBonds||0,b.numAtoms||0),f=b.groupTypeList.length/4,a={numGroups:f,numChains:b.chainIdList.length/4,numModels:b.chainsPerModel.length};"mmtfVersion mmtfProducer unitCell spaceGroup structureId title depositionDate releaseDate experimentalMethods resolution rFree rWork bioAssemblyList entityList groupList numBonds numAtoms groupsPerChain chainsPerModel".split(" ").forEach(function(c){void 0!==b[c]&&(a[c]=b[c])});b.bondAtomList&&c("bondAtomList")&&(a.bondAtomList= +n(b.bondAtomList));b.bondOrderList&&c("bondOrderList")&&(a.bondOrderList=A(b.bondOrderList));a.xCoordList=z(b.xCoordBig,b.xCoordSmall,1E3);a.yCoordList=z(b.yCoordBig,b.yCoordSmall,1E3);a.zCoordList=z(b.zCoordBig,b.zCoordSmall,1E3);b.bFactorBig&&b.bFactorSmall&&c("bFactorList")&&(a.bFactorList=z(b.bFactorBig,b.bFactorSmall,100));b.atomIdList&&c("atomIdList")&&(a.atomIdList=B(u(n(b.atomIdList))));b.altLocList&&c("altLocList")&&(a.altLocList=u(n(b.altLocList),new Uint8Array(d)));b.occupancyList&&c("occupancyList")&& +(a.occupancyList=I(b.occupancyList,100));a.groupIdList=B(u(n(b.groupIdList)));a.groupTypeList=n(b.groupTypeList);b.secStructList&&c("secStructList")&&(a.secStructList=H(b.secStructList));b.insCodeList&&c("insCodeList")&&(a.insCodeList=u(n(b.insCodeList),new Uint8Array(f)));b.sequenceIndexList&&c("sequenceIndexList")&&(a.sequenceIndexList=B(u(n(b.sequenceIndexList))));a.chainIdList=A(b.chainIdList);return b.chainNameList&&c("chainNameList")&&(a.chainNameList=A(b.chainNameList)),a}function G(b){return String.fromCharCode.apply(null, +b).replace(/\0/g,"")}y.decode=function(b,g){b instanceof ArrayBuffer&&(b=new Uint8Array(b));var c;return c=b instanceof Uint8Array?v(b):b,J(c,g)};y.traverse=function(b,g){var c,k,d,f,a=g.onModel,e=g.onChain,r=g.onGroup,h=g.onAtom,l=g.onBond,m=0,s=0,t=0,p=0,n=b.chainNameList,u=b.secStructList,y=b.insCodeList,v=b.sequenceIndexList,z=b.bFactorList,A=b.altLocList,B=b.occupancyList,F=b.bondAtomList,w=b.bondOrderList;if(b.chainsPerModel.forEach(function(g){a&&a({chainCount:g,modelIndex:m});for(c=0;g>c;++c){var w= +b.groupsPerChain[s];if(e){var q=G(b.chainIdList.subarray(4*s,4*s+4)),C=null;n&&(C=G(n.subarray(4*s,4*s+4)));e({groupCount:w,chainIndex:s,modelIndex:m,chainId:q,chainName:C})}for(k=0;w>k;++k){q=b.groupList[b.groupTypeList[t]];C=q.atomNameList.length;if(r){var x=null;u&&(x=u[t]);var D=null;b.insCodeList&&(D=String.fromCharCode(y[t]));var E=null;v&&(E=v[t]);r({atomCount:C,groupIndex:t,chainIndex:s,modelIndex:m,groupId:b.groupIdList[t],groupType:b.groupTypeList[t],groupName:q.groupName,singleLetterCode:q.singleLetterCode, +chemCompType:q.chemCompType,secStruct:x,insCode:D,sequenceIndex:E})}if(l)for(x=q.bondAtomList,d=0,f=q.bondOrderList.length;f>d;++d)l({atomIndex1:p+x[2*d],atomIndex2:p+x[2*d+1],bondOrder:q.bondOrderList[d]});for(d=0;C>d;++d)h&&(x=null,z&&(x=z[p]),D=null,A&&(D=String.fromCharCode(A[p])),E=null,B&&(E=B[p]),h({atomIndex:p,groupIndex:t,chainIndex:s,modelIndex:m,atomId:b.atomIdList[p],element:q.elementList[d],atomName:q.atomNameList[d],atomCharge:q.atomChargeList[d],xCoord:b.xCoordList[p],yCoord:b.yCoordList[p], +zCoord:b.zCoordList[p],bFactor:x,altLoc:D,occupancy:E})),p+=1;t+=1}s+=1}m+=1}),l&&F)for(d=0,f=F.length;f>d;d+=2)l({atomIndex1:F[d],atomIndex2:F[d+1],bondOrder:w?w[d/2]:null})}}); (function(P){"object"===typeof exports&&"undefined"!==typeof module?module.exports=P():"function"===typeof define&&define.amd?define([],P):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).pako=P()})(function(){return function p(u,c,F){function x(g,m){if(!c[g]){if(!u[g]){var h="function"==typeof require&&require;if(!m&&h)return h(g,!0);if(f)return f(g,!0);h=Error("Cannot find module '"+g+"'");throw h.code="MODULE_NOT_FOUND",h;}h=c[g]={exports:{}}; u[g][0].call(h.exports,function(h){var f=u[g][1][h];return x(f?f:h)},h,h.exports,p,u,c,F)}return c[g].exports}for(var f="function"==typeof require&&require,h=0;hF.x?A:F.x,q=q>F.y?q:F.y,B=B>F.z?B:F.z,F.symmetries&&m))for(var g=0;gF.symmetries[g].x?A:F.symmetries[g].x,q=q>F.symmetries[g].y?q:F.symmetries[g].y,B=B>F.symmetries[g].z?B:F.symmetries[g].z}return[[d,p,y],[A,q,B],[f/t,w/t,h/t]]};$3Dmol.getAtomProperty=function(b,c){var d=null;b.properties&&"undefined"!=typeof b.properties[c]?d=b.properties[c]:"undefined"!=typeof b[c]&&(d=b[c]);return d}; -$3Dmol.getPropertyRange=function(b,c){for(var d=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,y=0,A=b.length;yp&&(p=q))}isFinite(d)||isFinite(p)?isFinite(d)?isFinite(p)||(p=d):d=p:d=p=0;return[d,p]};var $3Dmol=$3Dmol||{};$3Dmol.Math={clamp:function(b,c,d){return Math.min(Math.max(b,c),d)},degToRad:function(){var b=Math.PI/180;return function(c){return c*b}}()}; +$.ajaxTransport("+binary",function(b,c,d){if(window.FormData&&(b.dataType&&"binary"==b.dataType||b.data&&(window.ArrayBuffer&&b.data instanceof ArrayBuffer||window.Blob&&b.data instanceof Blob)))return{send:function(c,d){var A=new XMLHttpRequest,y=b.url,z=b.type,f=b.async||!0,h=b.responseType||"blob",l=b.data||null,m=b.username||null,w=b.password||null;A.addEventListener("load",function(){var c={};c[b.dataType]=A.response;d(A.status,A.statusText,c,A.getAllResponseHeaders())});A.open(z,y,f,m,w);for(var e in c)A.setRequestHeader(e, +c[e]);A.responseType=h;A.send(l)},abort:function(){d.abort()}}});$3Dmol.createViewer=function(b,c){"string"===$.type(b)&&(b=$("#"+b));if(b){c=c||{};try{return new $3Dmol.GLViewer(b,c)}catch(d){throw"error creating viewer: "+d;}}};$3Dmol.viewers={}; +$3Dmol.download=function(b,c,d,p){var t="",A="",y=c.addModel();if("mmtf:"===b.substr(0,5)){A=d&&d.pdbUri?d.pdbUri:"http://mmtf.rcsb.org/full/";b=b.substr(5).toUpperCase();var z;$.ajax({url:A+b+".mmtf",type:"GET",dataType:"binary",responseType:"arraybuffer",processData:!1}).done(function(b,h,l){y.addMolData(b,"mmtf");c.zoomTo();c.render();p&&p(y)}).fail(function(b,c){console.log(c)})}else{if("pdb:"===b.substr(0,4)){A=d&&d.pdbUri?d.pdbUri:"http://www.rcsb.org/pdb/files/";t=d&&d.format?d.format:"pdb"; +b=b.substr(4).toUpperCase();if(!b.match(/^[1-9][A-Za-z0-9]{3}$/)){alert("Wrong PDB ID");return}z=d&&d.format?A+b+"."+d.format:A+b+".pdb"}else if("cid:"==b.substr(0,4)){t="sdf";b=b.substr(4);if(!b.match(/^[0-9]+$/)){alert("Wrong Compound ID");return}z="http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+b+"/SDF?record_type=3d"}$.get(z,function(b){y.addMolData(b,t,d);c.zoomTo();c.render();p&&p(y)})}return y};$3Dmol.SurfaceType={VDW:1,MS:2,SAS:3,SES:4}; +$3Dmol.mergeGeos=function(b,c){var d=c.geometry;void 0!==d&&b.geometryGroups.push(d.geometryGroups[0])};$3Dmol.multiLineString=function(b){return b.toString().replace(/^[^\/]+\/\*!?/,"").replace(/\*\/[^\/]+$/,"")};$3Dmol.syncSurface=!1;if(0<=window.navigator.userAgent.indexOf("MSIE ")||0<=window.navigator.userAgent.indexOf("Trident/"))$3Dmol.syncSurface=!0; +$3Dmol.specStringToObject=function(b){if("object"===typeof b||"undefined"===typeof b||null==b)return b;b=b.replace(/%7E/,"~");var c=function(b){return $.isNumeric(b)?Math.floor(parseFloat(b))==parseInt(b)?parseFloat(b):0<=b.indexOf(".")?parseFloat(b):parseInt(b):"true"===b?!0:"false"===b?!1:b},d={};if("all"===b)return d;b=b.split(";");for(var p=0;pG.x?A:G.x,y=y>G.y?y:G.y,z=z>G.z?z:G.z,G.symmetries&&w))for(var g=0;gG.symmetries[g].x?A:G.symmetries[g].x,y=y>G.symmetries[g].y?y:G.symmetries[g].y,z=z>G.symmetries[g].z?z:G.symmetries[g].z}return[[d,p,t],[A,y,z],[f/m,h/m,l/m]]};$3Dmol.getAtomProperty=function(b,c){var d=null;b.properties&&"undefined"!=typeof b.properties[c]?d=b.properties[c]:"undefined"!=typeof b[c]&&(d=b[c]);return d}; +$3Dmol.getPropertyRange=function(b,c){for(var d=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,t=0,A=b.length;tp&&(p=y))}isFinite(d)||isFinite(p)?isFinite(d)?isFinite(p)||(p=d):d=p:d=p=0;return[d,p]};"function"===typeof define&&define.amd&&define("$3Dmol",$3Dmol);var $3Dmol=$3Dmol||{};$3Dmol.Math={clamp:function(b,c,d){return Math.min(Math.max(b,c),d)},degToRad:function(){var b=Math.PI/180;return function(c){return c*b}}()}; $3Dmol.Quaternion=function(b,c,d,p){this.x=b||0;this.y=c||0;this.z=d||0;this.w=void 0!==p?p:1}; $3Dmol.Quaternion.prototype={constructor:$3Dmol.Quaternion,set:function(b,c,d,p){this.x=b;this.y=c;this.z=d;this.w=p;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;this.w=b.w;return this},conjugate:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},inverse:function(){return this.conjugate().normalize()},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var b=this.length();0===b?(this.z=this.y=this.x=0,this.w=1): -(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},multiply:function(b){return this.multiplyQuaternions(this,b)},multiplyQuaternions:function(b,c){var d=b.x,p=b.y,y=b.z,A=b.w,q=c.x,B=c.y,f=c.z,w=c.w;this.x=d*w+A*q+p*f-y*B;this.y=p*w+A*B+y*q-d*f;this.z=y*w+A*f+d*B-p*q;this.w=A*w-d*q-p*B-y*f}};$3Dmol.Vector2=function(b,c){this.x=b||0;this.y=c||0}; +(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},multiply:function(b){return this.multiplyQuaternions(this,b)},multiplyQuaternions:function(b,c){var d=b.x,p=b.y,t=b.z,A=b.w,y=c.x,z=c.y,f=c.z,h=c.w;this.x=d*h+A*y+p*f-t*z;this.y=p*h+A*z+t*y-d*f;this.z=t*h+A*f+d*z-p*y;this.w=A*h-d*y-p*z-t*f}};$3Dmol.Vector2=function(b,c){this.x=b||0;this.y=c||0}; $3Dmol.Vector2.prototype={constructor:$3Dmol.Vector2,set:function(b,c){this.x=b;this.y=c;return this},subVectors:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;return this},copy:function(b){this.x=b.x;this.y=b.y;return this},clone:function(){return new $3Dmol.Vector2(this.x,this.y)}};$3Dmol.Vector3=function(b,c,d){this.x=b||0;this.y=c||0;this.z=d||0}; $3Dmol.Vector3.prototype={constructor:$3Dmol.Vector3,set:function(b,c,d){this.x=b;this.y=c;this.z=d;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;return this},add:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;return this},addVectors:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;this.z=b.z+c.z;return this},sub:function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z;return this},subVectors:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;this.z=b.z-c.z;return this},multiplyScalar:function(b){this.x*= b;this.y*=b;this.z*=b;return this},divideScalar:function(b){0!==b?(this.x/=b,this.y/=b,this.z/=b):this.z=this.y=this.x=0;return this},max:function(b){this.x=Math.max(this.x,b.x);this.y=Math.max(this.y,b.y);this.z=Math.max(this.z,b.z);return this},min:function(b){this.x=Math.min(this.x,b.x);this.y=Math.min(this.y,b.y);this.z=Math.min(this.z,b.z);return this},distanceTo:function(b){return Math.sqrt(this.distanceToSquared(b))},distanceToSquared:function(b){var c=this.x-b.x,d=this.y-b.y;b=this.z-b.z; -return c*c+d*d+b*b},applyMatrix4:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;this.x=b[0]*c+b[4]*d+b[8]*p+b[12];this.y=b[1]*c+b[5]*d+b[9]*p+b[13];this.z=b[2]*c+b[6]*d+b[10]*p+b[14];return this},applyProjection:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;var y=b[3]*c+b[7]*d+b[11]*p+b[15];this.x=(b[0]*c+b[4]*d+b[8]*p+b[12])/y;this.y=(b[1]*c+b[5]*d+b[9]*p+b[13])/y;this.z=(b[2]*c+b[6]*d+b[10]*p+b[14])/y;return this},applyQuaternion:function(b){var c=this.x,d=this.y,p=this.z,y=b.x, -A=b.y,q=b.z,B,f,w;B=2*(d*q-p*A);f=2*(p*y-c*q);w=2*(c*A-d*y);this.x=c+b.w*B+(f*q-w*A);this.y=d+b.w*f+(w*y-B*q);this.z=p+b.w*w+(B*A-f*y);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},normalize:function(){return this.divideScalar(this.length())},cross:function(b){var c=this.x,d=this.y, -p=this.z;this.x=d*b.z-p*b.y;this.y=p*b.x-c*b.z;this.z=c*b.y-d*b.x;return this},crossVectors:function(b,c){this.x=b.y*c.z-b.z*c.y;this.y=b.z*c.x-b.x*c.z;this.z=b.x*c.y-b.y*c.x;return this},getPositionFromMatrix:function(b){this.x=b.elements[12];this.y=b.elements[13];this.z=b.elements[14];return this},setEulerFromRotationMatrix:function(b,c){var d=b.elements,p=d[0],y=d[4],A=d[8],q=d[5],B=d[9],f=d[6],d=d[10];void 0===c||"XYZ"===c?(this.y=Math.asin($3Dmol.Math.clamp(A,-1,1)),.99999>Math.abs(A)?(this.x= -Math.atan2(-B,d),this.z=Math.atan2(-y,p)):(this.x=Math.atan2(f,q),this.z=0)):console.error("Error with vector's setEulerFromRotationMatrix: Unknown order: "+c);return this},rotateAboutVector:function(b,c){b.normalize();var d=Math.cos(c),p=Math.sin(c),y=this.clone().multiplyScalar(d),p=b.clone().cross(this).multiplyScalar(p),d=b.clone().multiplyScalar(b.clone().dot(this)).multiplyScalar(1-d),y=y.add(p).add(d);this.x=y.x;this.y=y.y;this.z=y.z;return this},clone:function(){return new $3Dmol.Vector3(this.x, -this.y,this.z)}};$3Dmol.Matrix3=function(b,c,d,p,y,A,q,B,f){this.elements=new Float32Array(9);this.set(void 0!==b?b:1,c||0,d||0,p||0,void 0!==y?y:1,A||0,q||0,B||0,void 0!==f?f:1)}; -$3Dmol.Matrix3.prototype={constructor:$3Dmol.Matrix3,set:function(b,c,d,p,y,A,q,B,f){var w=this.elements;w[0]=b;w[3]=c;w[6]=d;w[1]=p;w[4]=y;w[7]=A;w[2]=q;w[5]=B;w[8]=f;return this},identity:function(){this.set(1,0,0,0,1,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8])},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[3]*=b;c[6]*=b;c[1]*=b;c[4]*=b;c[7]*=b;c[2]*=b;c[5]*=b;c[8]*=b;return this},getInverse:function(b,c){var d=b.elements, +return c*c+d*d+b*b},applyMatrix4:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;this.x=b[0]*c+b[4]*d+b[8]*p+b[12];this.y=b[1]*c+b[5]*d+b[9]*p+b[13];this.z=b[2]*c+b[6]*d+b[10]*p+b[14];return this},applyProjection:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;var t=b[3]*c+b[7]*d+b[11]*p+b[15];this.x=(b[0]*c+b[4]*d+b[8]*p+b[12])/t;this.y=(b[1]*c+b[5]*d+b[9]*p+b[13])/t;this.z=(b[2]*c+b[6]*d+b[10]*p+b[14])/t;return this},applyQuaternion:function(b){var c=this.x,d=this.y,p=this.z,t=b.x, +A=b.y,y=b.z,z,f,h;z=2*(d*y-p*A);f=2*(p*t-c*y);h=2*(c*A-d*t);this.x=c+b.w*z+(f*y-h*A);this.y=d+b.w*f+(h*t-z*y);this.z=p+b.w*h+(z*A-f*t);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},normalize:function(){return this.divideScalar(this.length())},cross:function(b){var c=this.x,d=this.y, +p=this.z;this.x=d*b.z-p*b.y;this.y=p*b.x-c*b.z;this.z=c*b.y-d*b.x;return this},crossVectors:function(b,c){this.x=b.y*c.z-b.z*c.y;this.y=b.z*c.x-b.x*c.z;this.z=b.x*c.y-b.y*c.x;return this},getPositionFromMatrix:function(b){this.x=b.elements[12];this.y=b.elements[13];this.z=b.elements[14];return this},setEulerFromRotationMatrix:function(b,c){var d=b.elements,p=d[0],t=d[4],A=d[8],y=d[5],z=d[9],f=d[6],d=d[10];void 0===c||"XYZ"===c?(this.y=Math.asin($3Dmol.Math.clamp(A,-1,1)),.99999>Math.abs(A)?(this.x= +Math.atan2(-z,d),this.z=Math.atan2(-t,p)):(this.x=Math.atan2(f,y),this.z=0)):console.error("Error with vector's setEulerFromRotationMatrix: Unknown order: "+c);return this},rotateAboutVector:function(b,c){b.normalize();var d=Math.cos(c),p=Math.sin(c),t=this.clone().multiplyScalar(d),p=b.clone().cross(this).multiplyScalar(p),d=b.clone().multiplyScalar(b.clone().dot(this)).multiplyScalar(1-d),t=t.add(p).add(d);this.x=t.x;this.y=t.y;this.z=t.z;return this},clone:function(){return new $3Dmol.Vector3(this.x, +this.y,this.z)}};$3Dmol.Matrix3=function(b,c,d,p,t,A,y,z,f){this.elements=new Float32Array(9);this.set(void 0!==b?b:1,c||0,d||0,p||0,void 0!==t?t:1,A||0,y||0,z||0,void 0!==f?f:1)}; +$3Dmol.Matrix3.prototype={constructor:$3Dmol.Matrix3,set:function(b,c,d,p,t,A,y,z,f){var h=this.elements;h[0]=b;h[3]=c;h[6]=d;h[1]=p;h[4]=t;h[7]=A;h[2]=y;h[5]=z;h[8]=f;return this},identity:function(){this.set(1,0,0,0,1,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8])},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[3]*=b;c[6]*=b;c[1]*=b;c[4]*=b;c[7]*=b;c[2]*=b;c[5]*=b;c[8]*=b;return this},getInverse:function(b,c){var d=b.elements, p=this.elements;p[0]=d[10]*d[5]-d[6]*d[9];p[1]=-d[10]*d[1]+d[2]*d[9];p[2]=d[6]*d[1]-d[2]*d[5];p[3]=-d[10]*d[4]+d[6]*d[8];p[4]=d[10]*d[0]-d[2]*d[8];p[5]=-d[6]*d[0]+d[2]*d[4];p[6]=d[9]*d[4]-d[5]*d[8];p[7]=-d[9]*d[0]+d[1]*d[8];p[8]=d[5]*d[0]-d[1]*d[4];d=d[0]*p[0]+d[1]*p[3]+d[2]*p[6];if(0===d){if(c)throw Error("Matrix3.getInverse(): can't invert matrix, determinant is 0");console.warn("Matrix3.getInverse(): can't invert matrix, determinant is 0");this.identity();return this}this.multiplyScalar(1/d);return this}, getDeterminant:function(){var b=this.elements;return b[0]*b[4]*b[8]+b[1]*b[5]*b[6]+b[2]*b[3]*b[7]-b[2]*b[4]*b[6]-b[1]*b[3]*b[8]-b[0]*b[5]*b[7]},transpose:function(){var b,c=this.elements;b=c[1];c[1]=c[3];c[3]=b;b=c[2];c[2]=c[6];c[6]=b;b=c[5];c[5]=c[7];c[7]=b;return this},clone:function(){var b=this.elements;return new $3Dmol.Matrix3(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8])}}; -$3Dmol.Matrix4=function(b,c,d,p,y,A,q,B,f,w,h,t,m,e,F,g){var x=this.elements=new Float32Array(16);x[0]=void 0!==b?b:1;x[4]=c||0;x[8]=d||0;x[12]=p||0;x[1]=y||0;x[5]=void 0!==A?A:1;x[9]=q||0;x[13]=B||0;x[2]=f||0;x[6]=w||0;x[10]=void 0!==h?h:1;x[14]=t||0;x[3]=m||0;x[7]=e||0;x[11]=F||0;x[15]=void 0!==g?g:1}; -$3Dmol.Matrix4.prototype={constructor:$3Dmol.Matrix4,set:function(b,c,d,p,y,A,q,B,f,w,h,t,m,e,F,g){var x=this.elements;x[0]=b;x[4]=c;x[8]=d;x[12]=p;x[1]=y;x[5]=A;x[9]=q;x[13]=B;x[2]=f;x[6]=w;x[10]=h;x[14]=t;x[3]=m;x[7]=e;x[11]=F;x[15]=g;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15]);return this},matrix3FromTopLeft:function(){var b=this.elements; -return new $3Dmol.Matrix3(b[0],b[4],b[8],b[1],b[5],b[9],b[2],b[6],b[10])},setRotationFromEuler:function(b,c){var d=this.elements,p=b.x,y=b.y,A=b.z,q=Math.cos(p),p=Math.sin(p),B=Math.cos(y),y=Math.sin(y),f=Math.cos(A),A=Math.sin(A);if(void 0===c||"XYZ"===c){var w=q*f,h=q*A,t=p*f,m=p*A;d[0]=B*f;d[4]=-B*A;d[8]=y;d[1]=h+t*y;d[5]=w-m*y;d[9]=-p*B;d[2]=m-w*y;d[6]=t+h*y;d[10]=q*B}else console.error("Error with matrix4 setRotationFromEuler. Order: "+c);return this},setRotationFromQuaternion:function(b){var c= -this.elements,d=b.x,p=b.y,y=b.z,A=b.w,q=d+d,B=p+p,f=y+y;b=d*q;var w=d*B,d=d*f,h=p*B,p=p*f,y=y*f,q=A*q,B=A*B,A=A*f;c[0]=1-(h+y);c[4]=w-A;c[8]=d+B;c[1]=w+A;c[5]=1-(b+y);c[9]=p-q;c[2]=d-B;c[6]=p+q;c[10]=1-(b+h);return this},lookAt:function(){var b=new $3Dmol.Vector3,c=new $3Dmol.Vector3,d=new $3Dmol.Vector3;return function(p,y,A){var q=this.elements;d.subVectors(p,y).normalize();0===d.length()&&(d.z=1);b.crossVectors(A,d).normalize();0===b.length()&&(d.x+=1E-4,b.crossVectors(A,d).normalize());c.crossVectors(d, -b);q[0]=b.x;q[4]=c.x;q[8]=d.x;q[1]=b.y;q[5]=c.y;q[9]=d.y;q[2]=b.z;q[6]=c.z;q[10]=d.z;return this}}(),multiplyMatrices:function(b,c){var d=b.elements,p=c.elements,y=this.elements,A=d[0],q=d[4],B=d[8],f=d[12],w=d[1],h=d[5],t=d[9],m=d[13],e=d[2],F=d[6],g=d[10],x=d[14],u=d[3],s=d[7],l=d[11],d=d[15],E=p[0],M=p[4],C=p[8],G=p[12],z=p[1],H=p[5],L=p[9],N=p[13],J=p[2],I=p[6],K=p[10],O=p[14],Q=p[3],W=p[7],P=p[11],p=p[15];y[0]=A*E+q*z+B*J+f*Q;y[4]=A*M+q*H+B*I+f*W;y[8]=A*C+q*L+B*K+f*P;y[12]=A*G+q*N+B*O+f*p;y[1]= -w*E+h*z+t*J+m*Q;y[5]=w*M+h*H+t*I+m*W;y[9]=w*C+h*L+t*K+m*P;y[13]=w*G+h*N+t*O+m*p;y[2]=e*E+F*z+g*J+x*Q;y[6]=e*M+F*H+g*I+x*W;y[10]=e*C+F*L+g*K+x*P;y[14]=e*G+F*N+g*O+x*p;y[3]=u*E+s*z+l*J+d*Q;y[7]=u*M+s*H+l*I+d*W;y[11]=u*C+s*L+l*K+d*P;y[15]=u*G+s*N+l*O+d*p;return this},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[4]*=b;c[8]*=b;c[12]*=b;c[1]*=b;c[5]*=b;c[9]*=b;c[13]*=b;c[2]*=b;c[6]*=b;c[10]*=b;c[14]*=b;c[3]*=b;c[7]*=b;c[11]*=b;c[15]*=b;return this},transpose:function(){var b=this.elements,c; -c=b[1];b[1]=b[4];b[4]=c;c=b[2];b[2]=b[8];b[8]=c;c=b[6];b[6]=b[9];b[9]=c;c=b[3];b[3]=b[12];b[12]=c;c=b[7];b[7]=b[13];b[13]=c;c=b[11];b[11]=b[14];b[14]=c;return this},getPosition:function(){var b=new $3Dmol.Vector3;return function(){console.warn("DEPRECATED: Matrix4's .getPosition() has been removed. Use Vector3.getPositionFromMatrix( matrix ) instead.");var c=this.elements;return b.set(c[12],c[13],c[14])}}(),setPosition:function(b){var c=this.elements;c[12]=b.x;c[13]=b.y;c[14]=b.z;return this},getInverse:function(b, -c){var d=this.elements,p=b.elements,y=p[0],A=p[4],q=p[8],B=p[12],f=p[1],w=p[5],h=p[9],t=p[13],m=p[2],e=p[6],F=p[10],g=p[14],x=p[3],u=p[7],s=p[11],l=p[15];d[0]=h*g*u-t*F*u+t*e*s-w*g*s-h*e*l+w*F*l;d[4]=B*F*u-q*g*u-B*e*s+A*g*s+q*e*l-A*F*l;d[8]=q*t*u-B*h*u+B*w*s-A*t*s-q*w*l+A*h*l;d[12]=B*h*e-q*t*e-B*w*F+A*t*F+q*w*g-A*h*g;d[1]=t*F*x-h*g*x-t*m*s+f*g*s+h*m*l-f*F*l;d[5]=q*g*x-B*F*x+B*m*s-y*g*s-q*m*l+y*F*l;d[9]=B*h*x-q*t*x-B*f*s+y*t*s+q*f*l-y*h*l;d[13]=q*t*m-B*h*m+B*f*F-y*t*F-q*f*g+y*h*g;d[2]=w*g*x-t*e*x+ -t*m*u-f*g*u-w*m*l+f*e*l;d[6]=B*e*x-A*g*x-B*m*u+y*g*u+A*m*l-y*e*l;d[10]=A*t*x-B*w*x+B*f*u-y*t*u-A*f*l+y*w*l;d[14]=B*w*m-A*t*m-B*f*e+y*t*e+A*f*g-y*w*g;d[3]=h*e*x-w*F*x-h*m*u+f*F*u+w*m*s-f*e*s;d[7]=A*F*x-q*e*x+q*m*u-y*F*u-A*m*s+y*e*s;d[11]=q*w*x-A*h*x-q*f*u+y*h*u+A*f*s-y*w*s;d[15]=A*h*m-q*w*m+q*f*e-y*h*e-A*f*F+y*w*F;d=p[0]*d[0]+p[1]*d[4]+p[2]*d[8]+p[3]*d[12];if(0===d){if(c)throw Error("Matrix4.getInverse(): can't invert matrix, determinant is 0");console.warn("Matrix4.getInverse(): can't invert matrix, determinant is 0"); -this.identity();return this}this.multiplyScalar(1/d);return this},isReflected:function(){return 0>this.matrix3FromTopLeft().getDeterminant()},compose:function(){var b=new $3Dmol.Matrix4,c=new $3Dmol.Matrix4;return function(d,p,y){var A=this.elements;b.identity();b.setRotationFromQuaternion(p);c.makeScale(y.x,y.y,y.z);this.multiplyMatrices(b,c);A[12]=d.x;A[13]=d.y;A[14]=d.z;return this}}(),decompose:function(){var b=new $3Dmol.Vector3,c=new $3Dmol.Vector3,d=new $3Dmol.Vector3,p=new $3Dmol.Matrix4; -return function(y,A,q){var B=this.elements;b.set(B[0],B[1],B[2]);c.set(B[4],B[5],B[6]);d.set(B[8],B[9],B[10]);y=y instanceof $3Dmol.Vector3?y:new $3Dmol.Vector3;A=A instanceof $3Dmol.Quaternion?A:new $3Dmol.Quaternion;q=q instanceof $3Dmol.Vector3?q:new $3Dmol.Vector3;q.x=b.length();q.y=c.length();q.z=d.length();y.x=B[12];y.y=B[13];y.z=B[14];p.copy(this);p.elements[0]/=q.x;p.elements[1]/=q.x;p.elements[2]/=q.x;p.elements[4]/=q.y;p.elements[5]/=q.y;p.elements[6]/=q.y;p.elements[8]/=q.z;p.elements[9]/= -q.z;p.elements[10]/=q.z;A.setFromRotationMatrix(p);return[y,A,q]}}(),scale:function(b){var c=this.elements,d=b.x,p=b.y;b=b.z;c[0]*=d;c[4]*=p;c[8]*=b;c[1]*=d;c[5]*=p;c[9]*=b;c[2]*=d;c[6]*=p;c[10]*=b;c[3]*=d;c[7]*=p;c[11]*=b;return this},getMaxScaleOnAxis:function(){var b=this.elements;return Math.sqrt(Math.max(b[0]*b[0]+b[1]*b[1]+b[2]*b[2],Math.max(b[4]*b[4]+b[5]*b[5]+b[6]*b[6],b[8]*b[8]+b[9]*b[9]+b[10]*b[10])))},makeFrustum:function(b,c,d,p,y,A){var q=this.elements;q[0]=2*y/(c-b);q[4]=0;q[8]=(c+b)/ -(c-b);q[12]=0;q[1]=0;q[5]=2*y/(p-d);q[9]=(p+d)/(p-d);q[13]=0;q[2]=0;q[6]=0;q[10]=-(A+y)/(A-y);q[14]=-2*A*y/(A-y);q[3]=0;q[7]=0;q[11]=-1;q[15]=0;return this},makePerspective:function(b,c,d,p){b=d*Math.tan($3Dmol.Math.degToRad(.5*b));var y=-b;return this.makeFrustum(y*c,b*c,y,b,d,p)},isEqual:function(b){b=b.elements;var c=this.elements;return c[0]==b[0]&&c[4]==b[4]&&c[8]==b[8]&&c[12]==b[12]&&c[1]==b[1]&&c[5]==b[5]&&c[9]==b[9]&&c[13]==b[13]&&c[2]==b[2]&&c[6]==b[6]&&c[10]==b[10]&&c[14]==b[14]&&c[3]== -b[3]&&c[7]==b[7]&&c[11]==b[11]&&c[15]==b[15]?!0:!1},clone:function(){var b=this.elements;return new $3Dmol.Matrix4(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15])},isIdentity:function(){var b=this.elements;return 1==b[0]&&0==b[4]&&0==b[8]&&0==b[12]&&0==b[1]&&1==b[5]&&0==b[9]&&0==b[13]&&0==b[2]&&0==b[6]&&1==b[10]&&0==b[14]&&0==b[3]&&0==b[7]&&0==b[11]&&1==b[15]?!0:!1}}; -$3Dmol.Ray=function(b,c){this.origin=void 0!==b?b:new $3Dmol.Vector3;this.direction=void 0!==c?c:new $3Dmol.Vector3}; +$3Dmol.Matrix4=function(b,c,d,p,t,A,y,z,f,h,l,m,w,e,G,g){if("undefined"===typeof c&&"undefined"!==typeof b)this.elements=new Float32Array(b);else{var s=this.elements=new Float32Array(16);s[0]=void 0!==b?b:1;s[4]=c||0;s[8]=d||0;s[12]=p||0;s[1]=t||0;s[5]=void 0!==A?A:1;s[9]=y||0;s[13]=z||0;s[2]=f||0;s[6]=h||0;s[10]=void 0!==l?l:1;s[14]=m||0;s[3]=w||0;s[7]=e||0;s[11]=G||0;s[15]=void 0!==g?g:1}}; +$3Dmol.Matrix4.prototype={constructor:$3Dmol.Matrix4,set:function(b,c,d,p,t,A,y,z,f,h,l,m,w,e,G,g){var s=this.elements;s[0]=b;s[4]=c;s[8]=d;s[12]=p;s[1]=t;s[5]=A;s[9]=y;s[13]=z;s[2]=f;s[6]=h;s[10]=l;s[14]=m;s[3]=w;s[7]=e;s[11]=G;s[15]=g;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15]);return this},matrix3FromTopLeft:function(){var b=this.elements; +return new $3Dmol.Matrix3(b[0],b[4],b[8],b[1],b[5],b[9],b[2],b[6],b[10])},setRotationFromEuler:function(b,c){var d=this.elements,p=b.x,t=b.y,A=b.z,y=Math.cos(p),p=Math.sin(p),z=Math.cos(t),t=Math.sin(t),f=Math.cos(A),A=Math.sin(A);if(void 0===c||"XYZ"===c){var h=y*f,l=y*A,m=p*f,w=p*A;d[0]=z*f;d[4]=-z*A;d[8]=t;d[1]=l+m*t;d[5]=h-w*t;d[9]=-p*z;d[2]=w-h*t;d[6]=m+l*t;d[10]=y*z}else console.error("Error with matrix4 setRotationFromEuler. Order: "+c);return this},setRotationFromQuaternion:function(b){var c= +this.elements,d=b.x,p=b.y,t=b.z,A=b.w,y=d+d,z=p+p,f=t+t;b=d*y;var h=d*z,d=d*f,l=p*z,p=p*f,t=t*f,y=A*y,z=A*z,A=A*f;c[0]=1-(l+t);c[4]=h-A;c[8]=d+z;c[1]=h+A;c[5]=1-(b+t);c[9]=p-y;c[2]=d-z;c[6]=p+y;c[10]=1-(b+l);return this},lookAt:function(){var b=new $3Dmol.Vector3,c=new $3Dmol.Vector3,d=new $3Dmol.Vector3;return function(p,t,A){var y=this.elements;d.subVectors(p,t).normalize();0===d.length()&&(d.z=1);b.crossVectors(A,d).normalize();0===b.length()&&(d.x+=1E-4,b.crossVectors(A,d).normalize());c.crossVectors(d, +b);y[0]=b.x;y[4]=c.x;y[8]=d.x;y[1]=b.y;y[5]=c.y;y[9]=d.y;y[2]=b.z;y[6]=c.z;y[10]=d.z;return this}}(),multiplyMatrices:function(b,c){var d=b.elements,p=c.elements,t=this.elements,A=d[0],y=d[4],z=d[8],f=d[12],h=d[1],l=d[5],m=d[9],w=d[13],e=d[2],G=d[6],g=d[10],s=d[14],u=d[3],x=d[7],q=d[11],d=d[15],N=p[0],I=p[4],D=p[8],C=p[12],B=p[1],F=p[5],J=p[9],L=p[13],K=p[2],H=p[6],M=p[10],O=p[14],R=p[3],V=p[7],P=p[11],p=p[15];t[0]=A*N+y*B+z*K+f*R;t[4]=A*I+y*F+z*H+f*V;t[8]=A*D+y*J+z*M+f*P;t[12]=A*C+y*L+z*O+f*p;t[1]= +h*N+l*B+m*K+w*R;t[5]=h*I+l*F+m*H+w*V;t[9]=h*D+l*J+m*M+w*P;t[13]=h*C+l*L+m*O+w*p;t[2]=e*N+G*B+g*K+s*R;t[6]=e*I+G*F+g*H+s*V;t[10]=e*D+G*J+g*M+s*P;t[14]=e*C+G*L+g*O+s*p;t[3]=u*N+x*B+q*K+d*R;t[7]=u*I+x*F+q*H+d*V;t[11]=u*D+x*J+q*M+d*P;t[15]=u*C+x*L+q*O+d*p;return this},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[4]*=b;c[8]*=b;c[12]*=b;c[1]*=b;c[5]*=b;c[9]*=b;c[13]*=b;c[2]*=b;c[6]*=b;c[10]*=b;c[14]*=b;c[3]*=b;c[7]*=b;c[11]*=b;c[15]*=b;return this},makeTranslation:function(b,c,d){this.set(1, +0,0,b,0,1,0,c,0,0,1,d,0,0,0,1);return this},transpose:function(){var b=this.elements,c;c=b[1];b[1]=b[4];b[4]=c;c=b[2];b[2]=b[8];b[8]=c;c=b[6];b[6]=b[9];b[9]=c;c=b[3];b[3]=b[12];b[12]=c;c=b[7];b[7]=b[13];b[13]=c;c=b[11];b[11]=b[14];b[14]=c;return this},getPosition:function(){var b=new $3Dmol.Vector3;return function(){console.warn("DEPRECATED: Matrix4's .getPosition() has been removed. Use Vector3.getPositionFromMatrix( matrix ) instead.");var c=this.elements;return b.set(c[12],c[13],c[14])}}(),setPosition:function(b){var c= +this.elements;c[12]=b.x;c[13]=b.y;c[14]=b.z;return this},getInverse:function(b,c){var d=this.elements,p=b.elements,t=p[0],A=p[4],y=p[8],z=p[12],f=p[1],h=p[5],l=p[9],m=p[13],w=p[2],e=p[6],G=p[10],g=p[14],s=p[3],u=p[7],x=p[11],q=p[15];d[0]=l*g*u-m*G*u+m*e*x-h*g*x-l*e*q+h*G*q;d[4]=z*G*u-y*g*u-z*e*x+A*g*x+y*e*q-A*G*q;d[8]=y*m*u-z*l*u+z*h*x-A*m*x-y*h*q+A*l*q;d[12]=z*l*e-y*m*e-z*h*G+A*m*G+y*h*g-A*l*g;d[1]=m*G*s-l*g*s-m*w*x+f*g*x+l*w*q-f*G*q;d[5]=y*g*s-z*G*s+z*w*x-t*g*x-y*w*q+t*G*q;d[9]=z*l*s-y*m*s-z*f* +x+t*m*x+y*f*q-t*l*q;d[13]=y*m*w-z*l*w+z*f*G-t*m*G-y*f*g+t*l*g;d[2]=h*g*s-m*e*s+m*w*u-f*g*u-h*w*q+f*e*q;d[6]=z*e*s-A*g*s-z*w*u+t*g*u+A*w*q-t*e*q;d[10]=A*m*s-z*h*s+z*f*u-t*m*u-A*f*q+t*h*q;d[14]=z*h*w-A*m*w-z*f*e+t*m*e+A*f*g-t*h*g;d[3]=l*e*s-h*G*s-l*w*u+f*G*u+h*w*x-f*e*x;d[7]=A*G*s-y*e*s+y*w*u-t*G*u-A*w*x+t*e*x;d[11]=y*h*s-A*l*s-y*f*u+t*l*u+A*f*x-t*h*x;d[15]=A*l*w-y*h*w+y*f*e-t*l*e-A*f*G+t*h*G;d=p[0]*d[0]+p[1]*d[4]+p[2]*d[8]+p[3]*d[12];if(0===d){if(c)throw Error("Matrix4.getInverse(): can't invert matrix, determinant is 0"); +console.warn("Matrix4.getInverse(): can't invert matrix, determinant is 0");this.identity();return this}this.multiplyScalar(1/d);return this},isReflected:function(){return 0>this.matrix3FromTopLeft().getDeterminant()},compose:function(){var b=new $3Dmol.Matrix4,c=new $3Dmol.Matrix4;return function(d,p,t){var A=this.elements;b.identity();b.setRotationFromQuaternion(p);c.makeScale(t.x,t.y,t.z);this.multiplyMatrices(b,c);A[12]=d.x;A[13]=d.y;A[14]=d.z;return this}}(),decompose:function(){var b=new $3Dmol.Vector3, +c=new $3Dmol.Vector3,d=new $3Dmol.Vector3,p=new $3Dmol.Matrix4;return function(t,A,y){var z=this.elements;b.set(z[0],z[1],z[2]);c.set(z[4],z[5],z[6]);d.set(z[8],z[9],z[10]);t=t instanceof $3Dmol.Vector3?t:new $3Dmol.Vector3;A=A instanceof $3Dmol.Quaternion?A:new $3Dmol.Quaternion;y=y instanceof $3Dmol.Vector3?y:new $3Dmol.Vector3;y.x=b.length();y.y=c.length();y.z=d.length();t.x=z[12];t.y=z[13];t.z=z[14];p.copy(this);p.elements[0]/=y.x;p.elements[1]/=y.x;p.elements[2]/=y.x;p.elements[4]/=y.y;p.elements[5]/= +y.y;p.elements[6]/=y.y;p.elements[8]/=y.z;p.elements[9]/=y.z;p.elements[10]/=y.z;A.setFromRotationMatrix(p);return[t,A,y]}}(),scale:function(b){var c=this.elements,d=b.x,p=b.y;b=b.z;c[0]*=d;c[4]*=p;c[8]*=b;c[1]*=d;c[5]*=p;c[9]*=b;c[2]*=d;c[6]*=p;c[10]*=b;c[3]*=d;c[7]*=p;c[11]*=b;return this},getMaxScaleOnAxis:function(){var b=this.elements;return Math.sqrt(Math.max(b[0]*b[0]+b[1]*b[1]+b[2]*b[2],Math.max(b[4]*b[4]+b[5]*b[5]+b[6]*b[6],b[8]*b[8]+b[9]*b[9]+b[10]*b[10])))},makeFrustum:function(b,c,d,p, +t,A){var y=this.elements;y[0]=2*t/(c-b);y[4]=0;y[8]=(c+b)/(c-b);y[12]=0;y[1]=0;y[5]=2*t/(p-d);y[9]=(p+d)/(p-d);y[13]=0;y[2]=0;y[6]=0;y[10]=-(A+t)/(A-t);y[14]=-2*A*t/(A-t);y[3]=0;y[7]=0;y[11]=-1;y[15]=0;return this},makePerspective:function(b,c,d,p){b=d*Math.tan($3Dmol.Math.degToRad(.5*b));var t=-b;return this.makeFrustum(t*c,b*c,t,b,d,p)},makeOrthographic:function(b,c,d,p,t,A){var y=this.elements,z=1/(c-b),f=1/(d-p),h=1/(A-t);y[0]=2*z;y[4]=0;y[8]=0;y[12]=-((c+b)*z);y[1]=0;y[5]=2*f;y[9]=0;y[13]=-((d+ +p)*f);y[2]=0;y[6]=0;y[10]=-2*h;y[14]=-((A+t)*h);y[3]=0;y[7]=0;y[11]=0;y[15]=1;return this},isEqual:function(b){b=b.elements;var c=this.elements;return c[0]==b[0]&&c[4]==b[4]&&c[8]==b[8]&&c[12]==b[12]&&c[1]==b[1]&&c[5]==b[5]&&c[9]==b[9]&&c[13]==b[13]&&c[2]==b[2]&&c[6]==b[6]&&c[10]==b[10]&&c[14]==b[14]&&c[3]==b[3]&&c[7]==b[7]&&c[11]==b[11]&&c[15]==b[15]?!0:!1},clone:function(){var b=this.elements;return new $3Dmol.Matrix4(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11], +b[15])},isIdentity:function(){var b=this.elements;return 1==b[0]&&0==b[4]&&0==b[8]&&0==b[12]&&0==b[1]&&1==b[5]&&0==b[9]&&0==b[13]&&0==b[2]&&0==b[6]&&1==b[10]&&0==b[14]&&0==b[3]&&0==b[7]&&0==b[11]&&1==b[15]?!0:!1}};$3Dmol.Ray=function(b,c){this.origin=void 0!==b?b:new $3Dmol.Vector3;this.direction=void 0!==c?c:new $3Dmol.Vector3}; $3Dmol.Ray.prototype={constructor:$3Dmol.Ray,set:function(b,c){this.origin.copy(b);this.direction.copy(c);return this},copy:function(b){this.origin.copy(b.origin);this.direction.copy(b.direction);return this},at:function(b,c){return(c||new $3Dmol.Vector3).copy(this.direction).multiplyScalar(b).add(this.origin)},recast:function(){var b=new $3Dmol.Vector3;return function(c){this.origin.copy(this.at(c,b));return this}}(),closestPointToPoint:function(b,c){var d=c||new $3Dmol.Vector3;d.subVectors(b,this.origin); var p=d.dot(this.direction);return d.copy(this.direction).multiplyScalar(p).add(this.origin)},distanceToPoint:function(b){var c=new $3Dmol.Vector3;return function(b){var p=c.subVectors(b,this.origin).dot(this.direction);c.copy(this.direction).multiplyScalar(p).add(this.origin);return c.distanceTo(b)}}(),isIntersectionCylinder:function(){},isIntersectionSphere:function(b){return this.distanceToPoint(b.center)<=b.radius},isIntersectionPlane:function(b){return 0!==b.normal.dot(this.direction)||0===b.distanceToPoint(this.origin)? !0:!1},distanceToPlane:function(b){var c=b.normal.dot(this.direction);if(0===c){if(0===b.distanceToPoint(this.origin))return 0}else return-(this.origin.dot(b.normal)+b.constant)/c},intersectPlane:function(b,c){var d=this.distanceToPlane(b);return void 0===d?void 0:this.at(d,c)},applyMatrix4:function(b){this.direction.add(this.origin).applyMatrix4(b);this.origin.applyMatrix4(b);this.direction.sub(this.origin);return this},equals:function(b){return b.origin.equals(this.origin)&&b.direction.equals(this.direction)}, @@ -276,7 +292,7 @@ $3Dmol.Cylinder=function(b,c,d){this.c1=void 0!==b?b:new $3Dmol.Vector3;this.c2= $3Dmol.Cylinder.prototype={constructor:$3Dmol.Cylinder,copy:function(b){this.c1.copy(b.c1);this.c2.copy(b.c2);this.direction.copy(b.direction);this.radius=b.radius;return this},lengthSq:function(){var b=new $3Dmol.Vector3;return function(){return b.subVectors(this.c2,this.c1).lengthSq()}}(),applyMatrix4:function(b){this.direction.add(this.c1).applyMatrix4(b);this.c1.applyMatrix4(b);this.c2.applyMatrix4(b);this.direction.sub(this.c1).normalize();this.radius*=b.getMaxScaleOnAxis();return this}}; $3Dmol.Triangle=function(b,c,d){this.a=void 0!==b?b:new $3Dmol.Vector3;this.b=void 0!==c?c:new $3Dmol.Vector3;this.c=void 0!==d?d:new $3Dmol.Vector3}; $3Dmol.Triangle.prototype={constructor:$3Dmol.Triangle,copy:function(b){this.a.copy(b.a);this.b.copy(b.b);this.c.copy(b.c);return this},applyMatrix4:function(b){this.a.applyMatrix4(b);this.b.applyMatrix4(b);this.c.applyMatrix4(b);return this},getNormal:function(){var b=new $3Dmol.Vector3;return function(){var c=this.a.clone();c.sub(this.b);b.subVectors(this.c,this.b);c.cross(b);c.normalize();return c}}()}; -$3Dmol.EventDispatcher=function(){var b={};this.addEventListener=function(c,d){void 0===b[c]&&(b[c]=[]);-1===b[c].indexOf(d)&&b[c].push(d)};this.removeEventListener=function(c,d){var p=b[c].indexOf(d);-1!==p&&b[c].splice(p,1)};this.dispatchEvent=function(c){var d=b[c.type];if(void 0!==d){c.target=this;for(var p=0,y=d.length;p>16&255)/255;this.g=(b>>8&255)/255;this.b=(b&255)/255;return this},getHex:function(){var b=Math.round(255*this.r),c=Math.round(255*this.g),d=Math.round(255*this.b);return b<<16|c<<8|d},clone:function(){return new $3Dmol.Color(this.r, this.g,this.b)},copy:function(b){this.r=b.r;this.g=b.g;this.b=b.b;return this},scaled:function(){var b={};b.r=Math.round(255*this.r);b.g=Math.round(255*this.g);b.b=Math.round(255*this.b);b.a=1;return b}}; $3Dmol.Object3D=function(){this.id=$3Dmol.Object3DIDCount++;this.name="";this.parent=void 0;this.children=[];this.position=new $3Dmol.Vector3;this.rotation=new $3Dmol.Vector3;this.matrix=new $3Dmol.Matrix4;this.matrixWorld=new $3Dmol.Matrix4;this.quaternion=new $3Dmol.Quaternion;this.eulerOrder="XYZ";this.up=new $3Dmol.Vector3(0,1,0);this.scale=new $3Dmol.Vector3(1,1,1);this.rotationAutoUpdate=this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.useQuaternion=!1;this.visible=!0}; @@ -285,32 +301,33 @@ remove:function(b){var c=this.children.indexOf(b);if(-1!==c){b.parent=void 0;thi !0},updateMatrixWorld:function(b){!0===this.matrixAutoUpdate&&this.updateMatrix();if(!0===this.matrixWorldNeedsUpdate||!0===b)void 0===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix);this.matrixWorldNeedsUpdate=!1;for(b=0;bd.vertexArray.length/3)d=c(this);return d},addGeoGroup:function(){return c(this)},setUpNormals:function(b){b=b||!1;for(var c=0;cL||(A.copy(this.ray.direction).multiplyScalar(L).add(this.ray.origin),A.sub(p.a),q.copy(p.b).sub(p.a),B.copy(p.c).sub(p.a),z=q.dot(B), -G=q.lengthSq(),H=B.lengthSq(),H=(G*A.dot(B)-z*A.dot(q))/(G*H-z*z),0>H||1z||1=I?L=Math.sqrt(N):L=(H-z*G-Math.sqrt(I))/J,z=z*H-G,0>z||z*z>d.lengthSq()||0>H||s.push({clickable:u,distance:L}))));M=0;for(C=l.line.length;Mx)break a; -L=0>=I?x:x-Math.sqrt(I);s.push({clickable:u,distance:L});break a}}}e.sort(w);return e};return b}();$3Dmol.Projector=function(){new $3Dmol.Matrix4;var b=new $3Dmol.Matrix4;this.projectVector=function(c,d){d.matrixWorldInverse.getInverse(d.matrixWorld);b.multiplyMatrices(d.projectionMatrix,d.matrixWorldInverse);return c.applyProjection(b)};this.unprojectVector=function(c,d){d.projectionMatrixInverse.getInverse(d.projectionMatrix);b.multiplyMatrices(d.matrixWorld,d.projectionMatrixInverse);return c.applyProjection(b)}}; -$3Dmol.Camera=function(b,c,d,p){$3Dmol.Object3D.call(this);this.fov=void 0!==b?b:50;this.aspect=void 0!==c?c:1;this.near=void 0!==d?d:.1;this.far=void 0!==p?p:2E3;this.projectionMatrix=new $3Dmol.Matrix4;this.projectionMatrixInverse=new $3Dmol.Matrix4;this.matrixWorldInverse=new $3Dmol.Matrix4;this.updateProjectionMatrix()};$3Dmol.Camera.prototype=Object.create($3Dmol.Object3D.prototype); -$3Dmol.Camera.prototype.lookAt=function(b){this.matrix.lookAt(this.position,b,this.up);this.rotationAutoUpdate&&(!1===this.useQuaternion?this.rotation.setEulerFromRotationMatrix(this.matrix,this.eulerOrder):this.quaternion.copy(this.matrix.decompose()[1]))};$3Dmol.Camera.prototype.updateProjectionMatrix=function(){this.projectionMatrix.makePerspective(this.fov,this.aspect,this.near,this.far);this.projectionMatrixInverse.getInverse(this.projectionMatrix)}; -$3Dmol.SpritePlugin=function(){function b(b,c){return b.z!==c.z?c.z-b.z:c.id-b.id}var c,d,p,y,A,q,B,f,w,h;this.init=function(b){c=b.context;d=b;p=b.getPrecision();y=new Float32Array(16);A=new Uint16Array(6);b=0;y[b++]=-1;y[b++]=-1;y[b++]=0;y[b++]=0;y[b++]=1;y[b++]=-1;y[b++]=1;y[b++]=0;y[b++]=1;y[b++]=1;y[b++]=1;y[b++]=1;y[b++]=-1;y[b++]=1;y[b++]=0;y[b++]=1;b=0;A[b++]=0;A[b++]=1;A[b++]=2;A[b++]=0;A[b++]=2;A[b++]=3;q=c.createBuffer();B=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,q);c.bufferData(c.ARRAY_BUFFER, -y,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,B);c.bufferData(c.ELEMENT_ARRAY_BUFFER,A,c.STATIC_DRAW);b=$3Dmol.ShaderLib.sprite;var m=p,e=c.createProgram(),F=c.createShader(c.FRAGMENT_SHADER),g=c.createShader(c.VERTEX_SHADER),m="precision "+m+" float;\n";c.shaderSource(F,m+b.fragmentShader);c.shaderSource(g,m+b.vertexShader);c.compileShader(F);c.compileShader(g);c.getShaderParameter(F,c.COMPILE_STATUS)&&c.getShaderParameter(g,c.COMPILE_STATUS)?(c.attachShader(e,F),c.attachShader(e,g),c.linkProgram(e), -c.getProgramParameter(e,c.LINK_STATUS)||console.error("Could not initialize shader"),b=e):(console.error(c.getShaderInfoLog(F)),console.error("could not initialize shader"),b=null);f=b;w={};h={};w.position=c.getAttribLocation(f,"position");w.uv=c.getAttribLocation(f,"uv");h.uvOffset=c.getUniformLocation(f,"uvOffset");h.uvScale=c.getUniformLocation(f,"uvScale");h.rotation=c.getUniformLocation(f,"rotation");h.scale=c.getUniformLocation(f,"scale");h.alignment=c.getUniformLocation(f,"alignment");h.color= -c.getUniformLocation(f,"color");h.map=c.getUniformLocation(f,"map");h.opacity=c.getUniformLocation(f,"opacity");h.useScreenCoordinates=c.getUniformLocation(f,"useScreenCoordinates");h.screenPosition=c.getUniformLocation(f,"screenPosition");h.modelViewMatrix=c.getUniformLocation(f,"modelViewMatrix");h.projectionMatrix=c.getUniformLocation(f,"projectionMatrix");h.fogType=c.getUniformLocation(f,"fogType");h.fogDensity=c.getUniformLocation(f,"fogDensity");h.fogNear=c.getUniformLocation(f,"fogNear");h.fogFar= -c.getUniformLocation(f,"fogFar");h.fogColor=c.getUniformLocation(f,"fogColor");h.alphaTest=c.getUniformLocation(f,"alphaTest")};this.render=function(t,m,e,F){var g=t.__webglSprites,x=g.length;if(x){var u=w,s=h,l=.5*e,E=.5*F;c.useProgram(f);c.enableVertexAttribArray(u.position);c.enableVertexAttribArray(u.uv);c.disable(c.CULL_FACE);c.enable(c.BLEND);c.bindBuffer(c.ARRAY_BUFFER,q);c.vertexAttribPointer(u.position,2,c.FLOAT,!1,16,0);c.vertexAttribPointer(u.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, -B);c.uniformMatrix4fv(s.projectionMatrix,!1,m.projectionMatrix.elements);c.activeTexture(c.TEXTURE0);c.uniform1i(s.map,0);var p=u=0;(u=t.fog)?(c.uniform3f(s.fogColor,u.color.r,u.color.g,u.color.b),c.uniform1f(s.fogNear,u.near),c.uniform1f(s.fogFar,u.far),c.uniform1i(s.fogType,1),p=u=1):(c.uniform1i(s.fogType,0),p=u=0);var C,y,z,H=[];for(C=0;CJ||(A.copy(this.ray.direction).multiplyScalar(J).add(this.ray.origin),A.sub(p.a),y.copy(p.b).sub(p.a),z.copy(p.c).sub(p.a),B=y.dot(z), +C=y.lengthSq(),F=z.lengthSq(),F=(C*A.dot(z)-B*A.dot(y))/(C*F-B*B),0>F||1B||1=H?J=Math.sqrt(L):J=(F-B*C-Math.sqrt(H))/K,B=B*F-C,0>B||B*B>d.lengthSq()||0>F||x.push({clickable:u,distance:J}))));I=0;for(D=q.line.length;Is)break a; +J=0>=H?s:s-Math.sqrt(H);x.push({clickable:u,distance:J});break a}}}e.sort(h);return e};return b}();$3Dmol.Projector=function(){new $3Dmol.Matrix4;var b=new $3Dmol.Matrix4;this.projectVector=function(c,d){d.matrixWorldInverse.getInverse(d.matrixWorld);b.multiplyMatrices(d.projectionMatrix,d.matrixWorldInverse);return c.applyProjection(b)};this.unprojectVector=function(c,d){d.projectionMatrixInverse.getInverse(d.projectionMatrix);b.multiplyMatrices(d.matrixWorld,d.projectionMatrixInverse);return c.applyProjection(b)}}; +$3Dmol.Camera=function(b,c,d,p,t){$3Dmol.Object3D.call(this);this.fov=void 0!==b?b:50;this.aspect=void 0!==c?c:1;this.near=void 0!==d?d:.1;this.far=void 0!==p?p:2E3;this.projectionMatrix=new $3Dmol.Matrix4;this.projectionMatrixInverse=new $3Dmol.Matrix4;this.matrixWorldInverse=new $3Dmol.Matrix4;this.right=this.position.z*Math.tan(Math.PI/180*b);this.left=-this.right;this.top=this.right/this.aspect;this.bottom=-this.top;this.ortho=!!t;this.updateProjectionMatrix()};$3Dmol.Camera.prototype=Object.create($3Dmol.Object3D.prototype); +$3Dmol.Camera.prototype.lookAt=function(b){this.matrix.lookAt(this.position,b,this.up);this.rotationAutoUpdate&&(!1===this.useQuaternion?this.rotation.setEulerFromRotationMatrix(this.matrix,this.eulerOrder):this.quaternion.copy(this.matrix.decompose()[1]))}; +$3Dmol.Camera.prototype.updateProjectionMatrix=function(){this.ortho?this.projectionMatrix.makeOrthographic(this.left,this.right,this.top,this.bottom,this.near,this.far):this.projectionMatrix.makePerspective(this.fov,this.aspect,this.near,this.far);this.projectionMatrixInverse.getInverse(this.projectionMatrix)}; +$3Dmol.SpritePlugin=function(){function b(b,c){return b.z!==c.z?c.z-b.z:c.id-b.id}var c,d,p,t,A,y,z,f,h,l;this.init=function(b){c=b.context;d=b;p=b.getPrecision();t=new Float32Array(16);A=new Uint16Array(6);b=0;t[b++]=-1;t[b++]=-1;t[b++]=0;t[b++]=0;t[b++]=1;t[b++]=-1;t[b++]=1;t[b++]=0;t[b++]=1;t[b++]=1;t[b++]=1;t[b++]=1;t[b++]=-1;t[b++]=1;t[b++]=0;t[b++]=1;b=0;A[b++]=0;A[b++]=1;A[b++]=2;A[b++]=0;A[b++]=2;A[b++]=3;y=c.createBuffer();z=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y);c.bufferData(c.ARRAY_BUFFER, +t,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,z);c.bufferData(c.ELEMENT_ARRAY_BUFFER,A,c.STATIC_DRAW);b=$3Dmol.ShaderLib.sprite;var w=p,e=c.createProgram(),G=c.createShader(c.FRAGMENT_SHADER),g=c.createShader(c.VERTEX_SHADER),w="precision "+w+" float;\n";c.shaderSource(G,w+b.fragmentShader);c.shaderSource(g,w+b.vertexShader);c.compileShader(G);c.compileShader(g);c.getShaderParameter(G,c.COMPILE_STATUS)&&c.getShaderParameter(g,c.COMPILE_STATUS)?(c.attachShader(e,G),c.attachShader(e,g),c.linkProgram(e), +c.getProgramParameter(e,c.LINK_STATUS)||console.error("Could not initialize shader"),b=e):(console.error(c.getShaderInfoLog(G)),console.error("could not initialize shader"),b=null);f=b;h={};l={};h.position=c.getAttribLocation(f,"position");h.uv=c.getAttribLocation(f,"uv");l.uvOffset=c.getUniformLocation(f,"uvOffset");l.uvScale=c.getUniformLocation(f,"uvScale");l.rotation=c.getUniformLocation(f,"rotation");l.scale=c.getUniformLocation(f,"scale");l.alignment=c.getUniformLocation(f,"alignment");l.color= +c.getUniformLocation(f,"color");l.map=c.getUniformLocation(f,"map");l.opacity=c.getUniformLocation(f,"opacity");l.useScreenCoordinates=c.getUniformLocation(f,"useScreenCoordinates");l.screenPosition=c.getUniformLocation(f,"screenPosition");l.modelViewMatrix=c.getUniformLocation(f,"modelViewMatrix");l.projectionMatrix=c.getUniformLocation(f,"projectionMatrix");l.fogType=c.getUniformLocation(f,"fogType");l.fogDensity=c.getUniformLocation(f,"fogDensity");l.fogNear=c.getUniformLocation(f,"fogNear");l.fogFar= +c.getUniformLocation(f,"fogFar");l.fogColor=c.getUniformLocation(f,"fogColor");l.alphaTest=c.getUniformLocation(f,"alphaTest")};this.render=function(m,w,e,G){var g=m.__webglSprites,s=g.length;if(s){var u=h,x=l,q=.5*e,t=.5*G;c.useProgram(f);c.enableVertexAttribArray(u.position);c.enableVertexAttribArray(u.uv);c.disable(c.CULL_FACE);c.enable(c.BLEND);c.bindBuffer(c.ARRAY_BUFFER,y);c.vertexAttribPointer(u.position,2,c.FLOAT,!1,16,0);c.vertexAttribPointer(u.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, +z);c.uniformMatrix4fv(x.projectionMatrix,!1,w.projectionMatrix.elements);c.activeTexture(c.TEXTURE0);c.uniform1i(x.map,0);var p=u=0;(u=m.fog)?(c.uniform3f(x.fogColor,u.color.r,u.color.g,u.color.b),c.uniform1f(x.fogNear,u.near),c.uniform1f(x.fogFar,u.far),c.uniform1i(x.fogType,1),p=u=1):(c.uniform1i(x.fogType,0),p=u=0);var D,C,B,F=[];for(D=0;D 0.0) {\n vec3 cp;\n if( dotp1 < 0.0) { cp = p1;\n } else {\n cp = p2;\n }\n vec3 diff = p-cp;\n A = dot(v,v);\n B = dot(diff,v)*2.0;\n C = dot(diff,diff)-r*r;\n det = (B*B) - (4.0*C);\n if(det < 0.0) discard;\n sqrtDet = sqrt(det);\n posT = (-B+sqrtDet)/(2.0);\n negT = (-B-sqrtDet)/(2.0);\n float t = min(posT,negT);\n qi = p+v*t;\n norm = normalize(qi-cp);\n } else {\n norm = normalize(qi-(dotp1*va + p1));\n }\n vec4 clipPos = projectionMatrix * vec4(qi, 1.0);\n float ndcDepth = clipPos.z / clipPos.w;\n float depth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;\n gl_FragDepthEXT = depth;"}; @@ -401,274 +418,290 @@ vertexShader:"uniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuni uniforms:{opacity:{type:"f",value:1},fogColor:{type:"c",value:new $3Dmol.Color(1,1,1)},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},directionalLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]}}},sprite:{fragmentShader:"uniform vec3 color;\nuniform sampler2D map;\nuniform float opacity;\nuniform int fogType;\nuniform vec3 fogColor;\nuniform float fogDensity;\nuniform float fogNear;\nuniform float fogFar;\nuniform float alphaTest;\nvarying vec2 vUV;\nvoid main() {\n vec4 texture = texture2D(map, vUV);\n if (texture.a < alphaTest) discard;\n gl_FragColor = vec4(color * texture.xyz, texture.a * opacity);\n if (fogType > 0) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor = 0.0;\n if (fogType == 1) {\n fogFactor = smoothstep(fogNear, fogFar, depth);\n }\n else {\n const float LOG2 = 1.442695;\n float fogFactor = exp2(- fogDensity * fogDensity * depth * depth * LOG2);\n fogFactor = 1.0 - clamp(fogFactor, 0.0, 1.0);\n }\n gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), fogFactor);\n }\n}", vertexShader:"uniform int useScreenCoordinates;\nuniform vec3 screenPosition;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float rotation;\nuniform vec2 scale;\nuniform vec2 alignment;\nuniform vec2 uvOffset;\nuniform vec2 uvScale;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\n vUV = uvOffset + uv * uvScale;\n vec2 alignedPosition = position + alignment;\n vec2 rotatedPosition;\n rotatedPosition.x = ( cos(rotation) * alignedPosition.x - sin(rotation) * alignedPosition.y ) * scale.x;\n rotatedPosition.y = ( sin(rotation) * alignedPosition.x + cos(rotation) * alignedPosition.y ) * scale.y;\n vec4 finalPosition;\n if(useScreenCoordinates != 0) {\n finalPosition = vec4(screenPosition.xy + rotatedPosition, screenPosition.z, 1.0);\n }\n else {\n finalPosition = projectionMatrix * modelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); finalPosition /= finalPosition.w;\n finalPosition.xy += rotatedPosition; \n }\n gl_Position = finalPosition;\n}", uniforms:{}}};"undefined"===typeof console&&(console={log:function(){}}); -$3Dmol.ProteinSurface=function(){var b=0,c=0,d=0,p=2,y=0,A=0,q=0,B=0,f=null,w=null,h=null,t=0,m=0,e=0,F=0,g=0,x=0,u={H:1.2,Li:1.82,Na:2.27,K:2.75,C:1.7,N:1.55,O:1.52,F:1.47,P:1.8,S:1.8,CL:1.75,BR:1.85,SE:1.9,ZN:1.39,CU:1.4,NI:1.63,X:2},s=function(b){return b.elem&&"undefined"!=typeof u[b.elem]?b.elem:"X"},l={},E={},M,C,G=[new Int32Array([1,0,0]),new Int32Array([-1,0,0]),new Int32Array([0,1,0]),new Int32Array([0,-1,0]),new Int32Array([0,0,1]),new Int32Array([0,0,-1]),new Int32Array([1,1,0]),new Int32Array([1, +$3Dmol.ProteinSurface=function(){var b=0,c=0,d=0,p=2,t=0,A=0,y=0,z=0,f=null,h=null,l=null,m=0,w=0,e=0,G=0,g=0,s=0,u={H:1.2,Li:1.82,Na:2.27,K:2.75,C:1.7,N:1.55,O:1.52,F:1.47,P:1.8,S:1.8,CL:1.75,BR:1.85,SE:1.9,ZN:1.39,CU:1.4,NI:1.63,X:2},x=function(b){return b.elem&&"undefined"!=typeof u[b.elem]?b.elem:"X"},q={},N={},I,D,C=[new Int32Array([1,0,0]),new Int32Array([-1,0,0]),new Int32Array([0,1,0]),new Int32Array([0,-1,0]),new Int32Array([0,0,1]),new Int32Array([0,0,-1]),new Int32Array([1,1,0]),new Int32Array([1, -1,0]),new Int32Array([-1,1,0]),new Int32Array([-1,-1,0]),new Int32Array([1,0,1]),new Int32Array([1,0,-1]),new Int32Array([-1,0,1]),new Int32Array([-1,0,-1]),new Int32Array([0,1,1]),new Int32Array([0,1,-1]),new Int32Array([0,-1,1]),new Int32Array([0,-1,-1]),new Int32Array([1,1,1]),new Int32Array([1,1,-1]),new Int32Array([1,-1,1]),new Int32Array([-1,1,1]),new Int32Array([1,-1,-1]),new Int32Array([-1,-1,1]),new Int32Array([-1,1,-1]),new Int32Array([-1,-1,-1])];this.getFacesAndVertices=function(e){var g= -{},q,m;q=0;for(m=e.length;qf?l[e][indx]=-1:(h=Math.sqrt(f-h),l[e][indx]=Math.floor(h)),indx++};this.fillvoxels=function(b,c){var e,q;e=0;for(q=f.length;eca;ca++)for(X=-1;2>X;X++)for(D=-1;2>D;D++)if(0!==ca&&0!==X&&0!==D)for(z=ca*G,C=D*M,V=0;V<=l[U][T];V++)F=V*X,B=w+z,u=m+F,Z=t+C,0>B||0>u||0>Z||B>=q||u>=A||Z>=y||(Z=B*ea+u*y+Z,f[Z]&1?(x=g[h[Z]],x.serial!=e.serial&&(B=w+z-Math.floor(.5+p*(x.x+b)),u=m+F-Math.floor(.5+p*(x.y+c)),x=t+C-Math.floor(.5+p*(x.z+d)),z*z+F*F+C*CX;X++)for(D=-1;2>D;D++)for(ba=-1;2>ba;ba++)if(0!==X&&0!==D&&0!==ba)for(F=X*V,G=ba*Z,ca=0;ca<=l[T][z];ca++)C=ca*D,B=w+F,u=m+C,M=t+G,0>B||0>u||0> -M||B>=q||u>=A||M>=y||(M=B*ea+u*y+M,f[M]&2?(x=g[h[M]],x.serial!=e.serial&&(B=w+F-Math.floor(.5+p*(x.x+b)),u=m+C-Math.floor(.5+p*(x.y+c)),x=t+G-Math.floor(.5+p*(x.z+d)),F*F+C*C+G*Gh;){var e=i+G[h][0],g=j+G[h][2],w=k+G[h][1];if(-1b&&(b=0);m-=.5/(.1+b);for(b=0;b=m)&&(f[l]|=4)};this.fastoneshell=function(b,c){var h,e,g,m,l,t,d,s,B,u,x,z=[];if(0===b.length)return z;tnv={ix:-1,iy:-1,iz:-1};var F=A*y;d=0;for(B=b.length;ds;s++)tnv.ix=h+G[s][0],tnv.iy= -e+G[s][1],tnv.iz=g+G[s][2],tnv.ixs;s++)tnv.ix=h+G[s][0],tnv.iy=e+G[s][1],tnv.iz=g+G[s][2],tnv.ixs;s++)tnv.ix=h+G[s][0],tnv.iy=e+G[s][1],tnv.iz=g+G[s][2],tnv.ixf?q[e][indx]=-1:(l=Math.sqrt(f-l),q[e][indx]=Math.floor(l)),indx++};this.fillvoxels=function(b,c){var e,g;e=0;for(g=f.length;eE;E++)for(aa=-1;2>aa;aa++)for(T=-1;2>T;T++)if(0!==E&&0!==aa&&0!==T)for(G=E*C,D=T*I,Y=0;Y<=q[W][U];Y++)B=Y*aa,z=g+G,s=w+B,ba=m+D,0>z||0>s||0>ba||z>=y||s>=A||ba>=t||(ba=z*X+s*t+ba,f[ba]&1?(u=h[l[ba]],u.serial!=e.serial&&(z=g+G-Math.floor(.5+p*(u.x+b)),s=w+B-Math.floor(.5+p*(u.y+c)),u=m+D-Math.floor(.5+p*(u.z+d)),G*G+B*B+D*Daa;aa++)for(T=-1;2>T;T++)for(Z=-1;2>Z;Z++)if(0!==aa&&0!==T&&0!==Z)for(B=aa*Y,C=Z*ba,E=0;E<=q[U][G];E++)D=E*T,z=g+B,s=w+D,I=m+C,0>z||0>s||0>I|| +z>=y||s>=A||I>=t||(I=z*X+s*t+I,f[I]&2?(u=h[l[I]],u.serial!=e.serial&&(z=g+B-Math.floor(.5+p*(u.x+b)),s=w+D-Math.floor(.5+p*(u.y+c)),u=m+C-Math.floor(.5+p*(u.z+d)),B*B+D*D+C*Cl;){var e=i+C[l][0],h=j+C[l][2],g=k+C[l][1];if(-1b&&(b=0);w-=.5/(.1+b);for(b=0;b=w)&&(f[m]|=4)};this.fastoneshell=function(b,c){var l,e,g,m,w,d,q,z,x,s,u,G=[];if(0===b.length)return G;tnv={ix:-1,iy:-1,iz:-1};var B=A*t;q=0;for(x=b.length;qz;z++)tnv.ix=l+C[z][0],tnv.iy=e+ +C[z][1],tnv.iz=g+C[z][2],tnv.ixz;z++)tnv.ix=l+C[z][0],tnv.iy=e+C[z][1],tnv.iz=g+C[z][2],tnv.ixz;z++)tnv.ix=l+C[z][0],tnv.iy=e+C[z][1],tnv.iz=g+C[z][2],tnv.ixs;++s)l[e+3*s]=d.r,l[e+1+3*s]=d.g,l[e+2+3*s]=d.b;0t&&(c.transparent= -!0,c.opacity=t);c.vertexColors=$3Dmol.FaceColors;t=new $3Dmol.Mesh(h,c);b.add(t)},d=function(c,d,f,w,h){0!==d.length&&(h=void 0===h?5:h,w=new $3Dmol.Geometry,b(d,h),d=new $3Dmol.LineBasicMaterial({linewidth:f}),d.vertexColors=!0,d=new $3Dmol.Line(w,d),d.type=$3Dmol.LineStrip,c.add(d))},p=function(q,d,f,w,h,t,m){m&&"default"!==m||(m="rectangle");if("edged"===m){if(!(2>d.length)){var e,F;e=d[0];F=d[d.length-1];d=w||axisDIV;e=b(e,d);F=b(F,d);if(h){d=new $3Dmol.Geometry(!0);var g=[],x,u,s,l,E,p=[[0,2, --6,-8],[-4,-2,6,4],[7,-1,-5,3],[-3,5,1,-7]],C,y,z,A,L,N,J,I;L=0;for(N=e.length;LJ;++J)I[C+3*J]=y.r,I[C+1+3*J]=y.g,I[C+2+3*J]=y.b;if(0J;J++)if(I=[w+p[J][0],w+p[J][1],w+p[J][2],w+p[J][3]],s=m.faceidx,K[s]=I[0],K[s+1]=I[1],K[s+2]=I[3],K[s+3]=I[1],K[s+4]= -I[2],K[s+5]=I[3],m.faceidx+=6,z.clickable||A.clickable){E=g[I[3]].clone();s=g[I[0]].clone();var O=g[I[2]].clone();l=g[I[1]].clone();E.atom=g[I[3]].atom||null;O.atom=g[I[2]].atom||null;s.atom=g[I[0]].atom||null;l.atom=g[I[1]].atom||null;if(C){var Q=E.clone().add(s).multiplyScalar(.5),W=O.clone().add(l).multiplyScalar(.5),P=E.clone().add(l).multiplyScalar(.5);0===J%2?(A.clickable&&(I=new $3Dmol.Triangle(Q,P,E),u=new $3Dmol.Triangle(W,O,P),E=new $3Dmol.Triangle(P,O,E),A.intersectionShape.triangle.push(I), -A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(E)),z.clickable&&(I=new $3Dmol.Triangle(s,l,P),u=new $3Dmol.Triangle(l,W,P),E=new $3Dmol.Triangle(s,P,Q),z.intersectionShape.triangle.push(I),z.intersectionShape.triangle.push(u),z.intersectionShape.triangle.push(E))):(z.clickable&&(I=new $3Dmol.Triangle(Q,P,E),u=new $3Dmol.Triangle(W,O,P),E=new $3Dmol.Triangle(P,O,E),z.intersectionShape.triangle.push(I),z.intersectionShape.triangle.push(u),z.intersectionShape.triangle.push(E)), -A.clickable&&(I=new $3Dmol.Triangle(s,l,P),u=new $3Dmol.Triangle(l,W,P),E=new $3Dmol.Triangle(s,P,Q),A.intersectionShape.triangle.push(I),A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(E)))}else z.clickable&&(I=new $3Dmol.Triangle(s,l,E),u=new $3Dmol.Triangle(l,O,E),z.intersectionShape.triangle.push(I),z.intersectionShape.triangle.push(u))}m.vertices+=8;A=z}f=g.length-8;m=d.updateGeoGroup(8);J=m.vertexArray;I=m.colorArray;K=m.faceArray;w=m.vertices;C=3*w;s=m.faceidx;for(L= -0;4>L;L++)g.push(g[2*L]),g.push(g[f+2*L]),h=g[2*L],z=g[f+2*L],J[C+6*L]=h.x,J[C+1+6*L]=h.y,J[C+2+6*L]=h.z,J[C+3+6*L]=z.x,J[C+4+6*L]=z.y,J[C+5+6*L]=z.z,I[C+6*L]=y.r,I[C+1+6*L]=y.g,I[C+2+6*L]=y.b,I[C+3+6*L]=y.r,I[C+4+6*L]=y.g,I[C+5+6*L]=y.b;I=[w,w+2,w+6,w+4];u=[w+1,w+5,w+7,w+3];K[s]=I[0];K[s+1]=I[1];K[s+2]=I[3];K[s+3]=I[1];K[s+4]=I[2];K[s+5]=I[3];K[s+6]=u[0];K[s+7]=u[1];K[s+8]=u[3];K[s+9]=u[1];K[s+10]=u[2];K[s+11]=u[3];m.faceidx+=12;m.vertices+=8;d.initTypedArrays();d.setUpNormals();f=new $3Dmol.MeshDoubleLambertMaterial; -f.vertexColors=$3Dmol.FaceColors;"number"===typeof t&&0<=t&&1>t&&(f.transparent=!0,f.opacity=t);t=new $3Dmol.Mesh(d,f);q.add(t)}else c(q,e,F,f,d,t)}}else if("rectangle"===m||"oval"===m||"parabola"===m)if(y=m,z=d.length,!(2>z||2>d[0].length)){w=w||axisDIV;for(A=0;At&&(f.transparent=!0,f.opacity=t);t=new $3Dmol.Mesh(w, -f);q.add(t)}else c(q,d[0],d[z-1],f,w,t)}},y=function(b,c){if(b&&c&&b.chain===c.chain){if(b.reschain===c.reschain&&(b.resi===c.resi||b.resi===c.resi-1))return!0;if(b.resif.distanceToSquared(d))return!0}}return!1},A=function(b,c,f,d,h,t,m,e,F){var g,x={ALA:5,ARG:11,ASN:8,ASP:8,CYS:6,GLN:9,GLU:9,GLY:4,HIS:10,ILE:8,LEU:8,LYS:9,MET:8,PHE:11,PRO:7,SER:6,THR:7,TRP:14,TYR:12,VAL:7};if(d&&h&&m){var u=h.sub(d);u.normalize(); -e=(e=e[parseInt(F)+x[m.resn]])?new $3Dmol.Vector3(e.x,e.y,e.z):new $3Dmol.Vector3(0,0,0);e.sub(d);"arrow start"===m.ss&&(h=e.clone().multiplyScalar(.3).cross(h),d.add(h),h=e.clone().cross(u).normalize(),u.rotateAboutVector(h,.43));m.style.cartoon.ribbon?h=m.style.cartoon.thickness||.4:m.style.cartoon.width?h=m.style.cartoon.width:"c"===m.ss?h="P"===m.atom?.8:.5:"arrow start"===m.ss?(h=1.3,g=!0):h="arrow end"===m.ss?.5:"h"===m.ss&&m.style.cartoon.tubes||"tube start"===m.ss?.5:1.3;null!=t&&0>u.dot(t)&& -u.negate();u.multiplyScalar(h);for(t=0;tP.opacity&&(l.transparent=!0,l.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,l),b.add(P),P=null):l&&(P.opacity&&l.style.cartoon.opacity?P.opacity!=l.style.cartoon.opacity&&(console.log("Warning: a trace-style chain's opacity is ambiguous"),P.opacity=1):P.opacity=parseFloat(l.style.cartoon.opacity)|| -1),l=E,M=C}else{u||(u=new $3Dmol.Geometry(!0));if(E&&"C"===E.elem&&"CA"===E.atom||H&&("P"===E.atom||0==E.atom.indexOf("O5"))){if(W)if("tube end"===E.ss)W=!1,H=new $3Dmol.Vector3(E.x,E.y,E.z),$3Dmol.GLDraw.drawCylinder(u,Q,H,2,$3Dmol.CC.color(M),1,1),E.ss="h";else continue;if(l&&(!y(l,E)||l.style.cartoon.style!==E.style.cartoon.style||"tube start"===l.ss)){"tube start"===l.ss&&(W=!0,Q=new $3Dmol.Vector3(l.x,l.y,l.z),l.ss="h");O&&(H=I?(new $3Dmol.Vector3).addVectors(l,I).multiplyScalar(.5):new $3Dmol.Vector3(l.x, -l.y,l.z),$3Dmol.GLDraw.drawCylinder(u,H,O,.4,$3Dmol.CC.color(O.color),0,2),H=A(R,m,!t,I,K,J,l,c,z),S.push(C),H&&S.push(C),O=null);for(z=0;!G&&zR.opacity&&(z.transparent=!0,z.opacity=R.opacity),u=new $3Dmol.Mesh(u,z),b.add(u),u=null);R=[];for(z=0;zR.opacity&&(z.transparent=!0,z.opacity=R.opacity),u=new $3Dmol.Mesh(u,z),b.add(u));null!=P&&0P.opacity&&(l.transparent=!0,l.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,l),b.add(P))}}();$3Dmol=$3Dmol||{}; -$3Dmol.GLDraw=function(){var b={},c=function(){var b=new $3Dmol.Vector3;return function(c){b.set(c[0],c[1],c[2]);var f=b.x,d=b.y,h=b.z,t=Math.sqrt(f*f+d*d);1E-4>t?(c=0,t=1):(c=-f/t,t=d/t);d=-c*f+t*d;f=Math.sqrt(d*d+h*h);1E-4>f?(h=0,d=1):(h/=f,d/=f);f=new Float32Array(9);f[0]=t;f[1]=c;f[2]=0;f[3]=-c*d;f[4]=t*d;f[5]=h;f[6]=c*h;f[7]=-t*h;f[8]=d;return f}}(),d=function(){var b=[],c=Math.pow(2,4),f,d=Math.pow(2,2),h=c/d,t;b[0]=new $3Dmol.Vector3(-1,0,0);b[h]=new $3Dmol.Vector3(0,0,1);b[2*h]=new $3Dmol.Vector3(1, -0,0);b[3*h]=new $3Dmol.Vector3(0,0,-1);for(f=3;4>=f;f++){d=Math.pow(2,f-1);h=c/d;for(t=0;t=x;x++){var u=0===x||10===x?!0:!1,s=5===x?!0:!1,l=[],E=[];for(g=0;g<=f;g++)if(s){var p=gMath.abs(p.x)&&(p.x=0),1E-5>Math.abs(p.y)&&(p.y=0),1E-5>Math.abs(p.z)&&(p.z=0),t=c?new $3Dmol.Vector3(0,Math.cos(0+y*F), -0):new $3Dmol.Vector3(p.x,p.y,p.z),t.normalize(),w.push(p),h.push(t),l.push(w.length-1)):l.push(w.length-f)}s&&m.push(E);m.push(l)}f={vertices:w,normals:h,verticesRows:m,w:f,h:10};return this.cache[c][b]=f}},y=0;b.drawCylinder=function(b,d,f,w,h,t,m){if(d&&f){y++;var e=t||m,F=!1;1==t&&1==m&&(F=!0);h=h||{r:0,g:0,b:0};var g=[f.x,f.y,f.z];g[0]-=d.x;g[1]-=d.y;g[2]-=d.z;var g=c(g),x=p.getVerticesForRadius(w,F);w=x.w;var F=x.h,u=e?F*w+2:2*w;b=b.updateGeoGroup(u);var s=x.vertices,l=x.normals,x=x.verticesRows, -E=x[F/2],A=x[F/2+1],C=b.vertices,G,z,H,L,N,J,I=b.vertexArray,K=b.normalArray,O=b.colorArray,Q=b.faceArray;for(H=0;Hb&&(f=10,d=8);var h=2*Math.PI,t=Math.PI,m,e;for(e=0;e<=d;e++){var p=[];for(m=0;m<=f;m++){var g=m/f,x=e/d,u={};u.x=-b*Math.cos(0+ -g*h)*Math.sin(0+x*t);u.y=b*Math.cos(0+x*t);u.z=b*Math.sin(0+g*h)*Math.sin(0+x*t);g=new $3Dmol.Vector3(u.x,u.y,u.z);g.normalize();c.vertices.push(u);c.normals.push(g);p.push(c.vertices.length-1)}c.verticesRows.push(p)}return this.cache[b]=c}};b.drawSphere=function(b,c,f,d){new $3Dmol.Vector3(c.x,c.y,c.z);var h=A.getVerticesForRadius(f),t=h.vertices,m=h.normals;b=b.updateGeoGroup(t.length);for(var e=b.vertices,p=b.vertexArray,g=b.colorArray,x=b.faceArray,u=b.lineArray,s=b.normalArray,l=0,E=t.length;l< -E;++l){var y=3*(e+l),C=t[l];p[y]=C.x+c.x;p[y+1]=C.y+c.y;p[y+2]=C.z+c.z;g[y]=d.r;g[y+1]=d.g;g[y+2]=d.b}b.vertices+=t.length;h=h.verticesRows;p=h.length-1;for(d=0;dg.lengthSq()&&(g=f.clone(),1E-4l;l++)d[g+3*l]=c.x,d[g+3*l+1]=c.y,d[g+3*l+2]=c.z;c=b.normalArray;m=b.colorArray;for(l=0;4>l;l++)m[g+3*l]=e.r,m[g+3*l+1]=e.g,m[g+3*l+2]=e.b;c[g+0]=-h;c[g+1]=h;c[g+2]=0;c[g+3]=-h;c[g+4]=-h;c[g+5]=0;c[g+6]=h;c[g+7]=-h;c[g+8]=0;c[g+9]=h;c[g+10]=h;c[g+11]=0;b.vertices+=4;h=b.faceArray; -e=b.faceidx;h[e+0]=f;h[e+1]=f+1;h[e+2]=f+2;h[e+3]=f+2;h[e+4]=f+3;h[e+5]=f;b.faceidx+=6},z=function(b,c){if(b.style.sphere){var h=b.style.sphere;if(!h.hidden){var e=s(b,h),h=$3Dmol.getColorFromStyle(b,h);G(c,b,e,h)}}},H=function(b,c,h,e,f,g,d){b=b.updateGeoGroup(4);g=b.vertices;d=b.vertexArray;var m=b.colorArray,l=b.radiusArray,t=b.normalArray,w=f.r,s=f.g;f=f.b;for(var u=3*g,x=0;4>x;x++){d[u]=c.x;t[u]=h.x;m[u]=w;u++;d[u]=c.y;t[u]=h.y;m[u]=s;u++;d[u]=c.z;t[u]=h.z;if(2>x)m[u]=f;else{var q=u,p=-f;0== -p&&(p=-1E-4);m[q]=p}u++}b.vertices+=4;l[g]=-e;l[g+1]=e;l[g+2]=-e;l[g+3]=e;c=b.faceArray;h=b.faceidx;c[h+0]=g;c[h+1]=g+1;c[h+2]=g+2;c[h+3]=g+2;c[h+4]=g+3;c[h+5]=g;b.faceidx+=6};this.getCrystData=function(){return e.cryst?e.cryst:null};this.getSymmetries=function(){"undefined"==typeof e.symmetries&&(e.symmetries=[F]);return e.symmetries};this.setSymmetries=function(b){e.symmetries="undefined"==typeof b?[F]:b};this.getID=function(){return b};this.getFrames=function(){return f};this.setFrame=function(b){0!= -f.length&&(B=0<=b&&b=m)d=h;else{f=$3Dmol.getExtent(h);e=[[],[],[]];for(g=0;3>g;g++)e[0][g]=f[0][g]-m,e[1][g]=f[1][g]+m,e[2][g]=f[2][g];m=[];for(g=0;g=e[0][0]&&d<=e[1][0]&&l>=e[0][1]&&l<=e[1][1]&&t>=e[0][2]&&t<=e[1][2]&&(d>=f[0][0]&&d<=f[1][0]&&l>=f[0][1]&&l<=f[1][1]&&t>=f[0][2]&&t<=f[1][2]||m.push(B[g]))}d=m}l=h.length;for(f=0;f=d||(g={b:g,e:d},d=f.bondOrder[e],1!=d&&(g.o=d),c.b.push(g))}}return c}; -this.globj=function(b,c){if(null===h){var f=B,d=c,d=d||{},m=new $3Dmol.Object3D,u=[],x={},q={},p=M,y=null,F=null;d.supportsImposters?(p=z,y=new $3Dmol.Geometry(!0),y.imposter=!0,F=new $3Dmol.Geometry(!0,!0),F.imposter=!0,F.sphereGeometry=y,F.drawnCaps={}):(d.supportsAIA?(p=C,y=new $3Dmol.Geometry(!1,!0,!0),y.instanced=!0):y=new $3Dmol.Geometry(!0),F=new $3Dmol.Geometry(!0));var A,L,ca,X,D={},ba=[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY];A=0;for(ca=f.length;Axa;xa++){var Ma=3*Ja.vertices;Ja.vertices++;$a[Ma]=T.x+Ia[xa][0];$a[Ma+1]=T.y+Ia[xa][1];$a[Ma+2]=T.z+Ia[xa][2];Ua[Ma]=Ta.r;Ua[Ma+1]=Ta.g;Ua[Ma+2]=Ta.b;if(Za){var Va=new $3Dmol.Vector3(Ia[xa][0],Ia[xa][1],Ia[xa][2]);Va.multiplyScalar(.1);Va.set(Va.x+ -T.x,Va.y+T.y,Va.z+T.z);T.intersectionShape.line.push(Va)}}}}var fa=U,zb=f,kb=x;if(fa.style.line){var rb=fa.style.line;if(!rb.hidden){var lb=rb.linewidth||1;kb[lb]||(kb[lb]=new $3Dmol.Geometry);for(var ta=kb[lb].updateGeoGroup(6*fa.bonds.length),ja=ta.vertexArray,ka=ta.colorArray,Ea=0;Ea=Oa.serial)){var Ca=new $3Dmol.Vector3(fa.x,fa.y,fa.z),Qa=new $3Dmol.Vector3(Oa.x,Oa.y,Oa.z),fb=Ca.clone().add(Qa).multiplyScalar(.5),sb= -!1;fa.clickable&&(void 0===fa.intersectionShape&&(fa.intersectionShape={sphere:[],cylinder:[],line:[],triangle:[]}),fa.intersectionShape.line.push(Ca),fa.intersectionShape.line.push(Qa));var pa=$3Dmol.getColorFromStyle(fa,fa.style.line),Fa=$3Dmol.getColorFromStyle(Oa,Oa.style.line);if(fa.bondStyles&&fa.bondStyles[Ea]){var Pa=fa.bondStyles[Ea];if(!Pa.iswire)continue;Pa.radius&&(bondR=Pa.radius);Pa.singleBond&&(sb=!0);"undefined"!=typeof Pa.color1&&(pa=$3Dmol.CC.color(Pa.color1));"undefined"!=typeof Pa.color2&& -(Fa=$3Dmol.CC.color(Pa.color2))}var la=3*ta.vertices;if(1fa.bondOrder[Ea]&&!sb){var Wa=l(fa,Oa,Ea),Da=Qa.clone();Da.sub(Ca);if(2==fa.bondOrder[Ea])if(Wa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Wa),p1b=Ca.clone(),p1b.sub(Wa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),pa==Fa)ta.vertices+=4,E(ja,ka,la,p1a,p2a,pa),E(ja,ka,la+6,p1b,p2b,pa);else{ta.vertices+=8;Da.multiplyScalar(.5);var Ra=p1a.clone();Ra.add(Da);var Sa=p1b.clone();Sa.add(Da);E(ja,ka,la,p1a,Ra,pa);E(ja, -ka,la+6,Ra,p2a,Fa);E(ja,ka,la+12,p1b,Sa,pa);E(ja,ka,la+18,Sa,p2b,Fa)}else 3==fa.bondOrder[Ea]&&(Wa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Wa),p1b=Ca.clone(),p1b.sub(Wa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),pa==Fa?(ta.vertices+=6,E(ja,ka,la,Ca,Qa,pa),E(ja,ka,la+6,p1a,p2a,pa),E(ja,ka,la+12,p1b,p2b,pa)):(ta.vertices+=12,Da.multiplyScalar(.5),Ra=p1a.clone(),Ra.add(Da),Sa=p1b.clone(),Sa.add(Da),E(ja,ka,la,Ca,fb,pa),E(ja,ka,la+6,fb,Qa,Fa),E(ja,ka,la+12,p1a,Ra,pa),E(ja,ka,la+18,Ra, -p2a,Fa),E(ja,ka,la+24,p1b,Sa,pa),E(ja,ka,la+30,Sa,p2b,Fa)))}else pa==Fa?(ta.vertices+=2,E(ja,ka,la,Ca,Qa,pa)):(ta.vertices+=4,E(ja,ka,la,Ca,fb,pa),E(ja,ka,la+6,fb,Qa,Fa))}}}}var Y=U,Ab=f,ga=F;if(Y.style.stick){var gb=Y.style.stick;if(!gb.hidden){var ab=gb.radius||.25,ua=ab,tb=gb.singleBonds||!1,bb=0,cb=0,ma=$3Dmol.getColorFromStyle(Y,gb),na=void 0,ya=void 0;!Y.capDrawn&&4>Y.bonds.length&&(bb=2);var ia=$3Dmol.GLDraw.drawCylinder;ga.imposter&&(ia=H);for(var oa=0;oaha.bonds.length&& -(cb=2),ma!=Ga?(na=(new $3Dmol.Vector3).addVectors(qa,Aa).multiplyScalar(.5),ia(ga,qa,na,ua,ma,bb,0),ia(ga,na,Aa,ua,Ga,0,cb)):ia(ga,qa,Aa,ua,ma,bb,cb),Y.clickable||ha.clickable){na=(new $3Dmol.Vector3).addVectors(qa,Aa).multiplyScalar(.5);if(Y.clickable){var Bb=new $3Dmol.Cylinder(qa,na,ua),Cb=new $3Dmol.Sphere(qa,ua);Y.intersectionShape.cylinder.push(Bb);Y.intersectionShape.sphere.push(Cb)}if(ha.clickable){var Db=new $3Dmol.Cylinder(Aa,na,ua),Eb=new $3Dmol.Sphere(Aa,ua);ha.intersectionShape.cylinder.push(Db); -ha.intersectionShape.sphere.push(Eb)}}}else if(1ba[1]&&(ba[1]=U.resi)),u.push(U))}}if(0D.sphere&&0<=D.sphere&&(Ya.transparent=!0,Ya.opacity=D.sphere);eb=new $3Dmol.Mesh(y,Ya);m.add(eb)}if(0D.stick&&0<=D.stick&&(hb.transparent=!0,hb.opacity=D.stick);F.initTypedArrays();hb.wireframe&&F.setUpWireframe();xb=new $3Dmol.Mesh(F,hb)}m.add(xb)}for(A in x)if(x.hasOwnProperty(A)){var ob=A,pb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>D.line&&0<=D.line&&(pb.transparent=!0,pb.opacity=D.line);x[A].initTypedArrays();var Gb=new $3Dmol.Line(x[A],pb,$3Dmol.LinePieces); -m.add(Gb)}for(A in q)if(q.hasOwnProperty(A)){var ob=A,qb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>D.cross&&0<=D.cross&&(qb.transparent=!0,qb.opacity=D.cross);q[A].initTypedArrays();var Hb=new $3Dmol.Line(q[A],qb,$3Dmol.LinePieces);m.add(Hb)}if(g&&e.symmetries&&0MOLECULE/gm)?"mol2":b.match(/^HETATM/gm)||b.match(/^ATOM/gm)?"pdb":b.match(/^.*\n.*\n.\s*(\d+)\s+(\d+)/gm)?"sdf":"xyz",console.log("Best guess: "+ -c)));return(0,$3Dmol.Parsers[c])(b,d)};b.setAtomDefaults=function(b,d){for(var p=0;pb.mid?b.mid:.618034;var m=b.start,e=b.end,w=b.radius,g=b.radiusRatio,x=b.mid;if(m&&e){var c=f.updateGeoGroup(51),u=e.clone();u.sub(m).multiplyScalar(x);var s=m.clone().add(u),x=u.clone().negate();this.intersectionShape.cylinder.push(new $3Dmol.Cylinder(m.clone(),s.clone(),w));this.intersectionShape.sphere.push(new $3Dmol.Sphere(m.clone(), -w));var l=[];l[0]=u.clone();1E-4this.opacity?!0:!1,opacity:this.opacity, -wireframeLinewidth:this.linewidth}):new $3Dmol.MeshLambertMaterial({wireframe:this.wireframe,side:this.side,transparent:1>this.opacity?!0:!1,opacity:this.opacity,wireframeLinewidth:this.linewidth});d=new $3Dmol.Mesh(f,d);q.add(d);d=new $3Dmol.LineBasicMaterial({linewidth:this.linewidth,color:this.color});d=new $3Dmol.Line(w,d,$3Dmol.LinePieces);q.add(d);B=q.clone();b.add(B)}};this.removegl=function(b){B&&(void 0!==B.geometry&&B.geometry.dispose(),void 0!==B.material&&B.material.dispose(),b.remove(B), -B=null);q=null}}var c=function(b,c,q){var p=q.faceArr;0!==q.vertexArr.length&&0!==p.length||console.warn("Error adding custom shape component: No vertices and/or face indices supplied!");p=q.color;"undefined"==typeof p&&(p=b.color);for(var p=$3Dmol.CC.color(p),f=$3Dmol.splitMesh(q),w=0,h=f.length;wx;++x)q[e+3*x]=G.r,q[e+1+3*x]=G.g,q[e+2+3*x]=G.b;0m&&(c.transparent= +!0,c.opacity=m);c.vertexColors=$3Dmol.FaceColors;m=new $3Dmol.Mesh(l,c);b.add(m)},d=function(c,d,f,h,l){0!==d.length&&(l=void 0===l?5:l,h=new $3Dmol.Geometry,b(d,l),d=new $3Dmol.LineBasicMaterial({linewidth:f}),d.vertexColors=!0,d=new $3Dmol.Line(h,d),d.type=$3Dmol.LineStrip,c.add(d))},p=function(d,z,f,h,l,m,w){w&&"default"!==w||(w="rectangle");if("edged"===w){if(!(2>z.length)){var e,G;e=z[0];G=z[z.length-1];z=h||axisDIV;e=b(e,z);G=b(G,z);if(l){z=new $3Dmol.Geometry(!0);var g=[],s,u,x,q,t,p=[[0,2, +-6,-8],[-4,-2,6,4],[7,-1,-5,3],[-3,5,1,-7]],D,C,B,A,J,L,K,H;J=0;for(L=e.length;JK;++K)H[D+3*K]=C.r,H[D+1+3*K]=C.g,H[D+2+3*K]=C.b;if(0K;K++)if(H=[h+p[K][0],h+p[K][1],h+p[K][2],h+p[K][3]],x=w.faceidx,M[x]=H[0],M[x+1]=H[1],M[x+2]=H[3],M[x+3]=H[1],M[x+4]= +H[2],M[x+5]=H[3],w.faceidx+=6,B.clickable||A.clickable){t=g[H[3]].clone();x=g[H[0]].clone();var O=g[H[2]].clone();q=g[H[1]].clone();t.atom=g[H[3]].atom||null;O.atom=g[H[2]].atom||null;x.atom=g[H[0]].atom||null;q.atom=g[H[1]].atom||null;if(D){var R=t.clone().add(x).multiplyScalar(.5),V=O.clone().add(q).multiplyScalar(.5),P=t.clone().add(q).multiplyScalar(.5);0===K%2?(A.clickable&&(H=new $3Dmol.Triangle(R,P,t),u=new $3Dmol.Triangle(V,O,P),t=new $3Dmol.Triangle(P,O,t),A.intersectionShape.triangle.push(H), +A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(t)),B.clickable&&(H=new $3Dmol.Triangle(x,q,P),u=new $3Dmol.Triangle(q,V,P),t=new $3Dmol.Triangle(x,P,R),B.intersectionShape.triangle.push(H),B.intersectionShape.triangle.push(u),B.intersectionShape.triangle.push(t))):(B.clickable&&(H=new $3Dmol.Triangle(R,P,t),u=new $3Dmol.Triangle(V,O,P),t=new $3Dmol.Triangle(P,O,t),B.intersectionShape.triangle.push(H),B.intersectionShape.triangle.push(u),B.intersectionShape.triangle.push(t)), +A.clickable&&(H=new $3Dmol.Triangle(x,q,P),u=new $3Dmol.Triangle(q,V,P),t=new $3Dmol.Triangle(x,P,R),A.intersectionShape.triangle.push(H),A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(t)))}else B.clickable&&(H=new $3Dmol.Triangle(x,q,t),u=new $3Dmol.Triangle(q,O,t),B.intersectionShape.triangle.push(H),B.intersectionShape.triangle.push(u))}w.vertices+=8;A=B}f=g.length-8;w=z.updateGeoGroup(8);K=w.vertexArray;H=w.colorArray;M=w.faceArray;h=w.vertices;D=3*h;x=w.faceidx;for(J= +0;4>J;J++)g.push(g[2*J]),g.push(g[f+2*J]),l=g[2*J],B=g[f+2*J],K[D+6*J]=l.x,K[D+1+6*J]=l.y,K[D+2+6*J]=l.z,K[D+3+6*J]=B.x,K[D+4+6*J]=B.y,K[D+5+6*J]=B.z,H[D+6*J]=C.r,H[D+1+6*J]=C.g,H[D+2+6*J]=C.b,H[D+3+6*J]=C.r,H[D+4+6*J]=C.g,H[D+5+6*J]=C.b;H=[h,h+2,h+6,h+4];u=[h+1,h+5,h+7,h+3];M[x]=H[0];M[x+1]=H[1];M[x+2]=H[3];M[x+3]=H[1];M[x+4]=H[2];M[x+5]=H[3];M[x+6]=u[0];M[x+7]=u[1];M[x+8]=u[3];M[x+9]=u[1];M[x+10]=u[2];M[x+11]=u[3];w.faceidx+=12;w.vertices+=8;z.initTypedArrays();z.setUpNormals();f=new $3Dmol.MeshDoubleLambertMaterial; +f.vertexColors=$3Dmol.FaceColors;"number"===typeof m&&0<=m&&1>m&&(f.transparent=!0,f.opacity=m);m=new $3Dmol.Mesh(z,f);d.add(m)}else c(d,e,G,f,z,m)}}else if("rectangle"===w||"oval"===w||"parabola"===w)if(C=w,B=z.length,!(2>B||2>z[0].length)){h=h||axisDIV;for(A=0;Am&&(f.transparent=!0,f.opacity=m);m=new $3Dmol.Mesh(h, +f);d.add(m)}else c(d,z[0],z[B-1],f,h,m)}},t=function(b,c){if(b&&c&&b.chain===c.chain){if(b.reschain===c.reschain&&(b.resi===c.resi||b.resi===c.resi-1))return!0;if(b.resif.distanceToSquared(h))return!0}}return!1},A=function(b,c,f,h,l,d,w,e,t){var g,s={ALA:5,ARG:11,ASN:8,ASP:8,CYS:6,GLN:9,GLU:9,GLY:4,HIS:10,ILE:8,LEU:8,LYS:9,MET:8,PHE:11,PRO:7,SER:6,THR:7,TRP:14,TYR:12,VAL:7};if(h&&l&&w){var u=l.sub(h);u.normalize(); +e=(e=e[parseInt(t)+s[w.resn]])?new $3Dmol.Vector3(e.x,e.y,e.z):new $3Dmol.Vector3(0,0,0);e.sub(h);"arrow start"===w.ss&&(l=e.clone().multiplyScalar(.3).cross(l),h.add(l),l=e.clone().cross(u).normalize(),u.rotateAboutVector(l,.43));w.style.cartoon.ribbon?l=w.style.cartoon.thickness||.4:w.style.cartoon.width?l=w.style.cartoon.width:"c"===w.ss?l="P"===w.atom?.8:.5:"arrow start"===w.ss?(l=1.3,g=!0):l="arrow end"===w.ss?.5:"h"===w.ss&&w.style.cartoon.tubes||"tube start"===w.ss?.5:1.3;null!=d&&0>u.dot(d)&& +u.negate();u.multiplyScalar(l);for(d=0;dP.opacity&&(q.transparent=!0,q.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,q),b.add(P),P=null):q&&(P.opacity&&q.style.cartoon.opacity?P.opacity!=q.style.cartoon.opacity&&(console.log("Warning: a trace-style chain's opacity is ambiguous"),P.opacity=1):P.opacity=parseFloat(q.style.cartoon.opacity)|| +1),q=N,I=D}else{u||(u=new $3Dmol.Geometry(!0));if(N&&"C"===N.elem&&"CA"===N.atom||F&&("P"===N.atom||0==N.atom.indexOf("O5"))){if(V)if("tube end"===N.ss)V=!1,F=new $3Dmol.Vector3(N.x,N.y,N.z),$3Dmol.GLDraw.drawCylinder(u,R,F,2,$3Dmol.CC.color(I),1,1),N.ss="h";else continue;if(q&&(!t(q,N)||q.style.cartoon.style!==N.style.cartoon.style||"tube start"===q.ss)){"tube start"===q.ss&&(V=!0,R=new $3Dmol.Vector3(q.x,q.y,q.z),q.ss="h");O&&(F=H?(new $3Dmol.Vector3).addVectors(q,H).multiplyScalar(.5):new $3Dmol.Vector3(q.x, +q.y,q.z),$3Dmol.GLDraw.drawCylinder(u,F,O,.4,$3Dmol.CC.color(O.color),0,2),F=A(Q,w,!m,H,M,K,q,c,B),S.push(D),F&&S.push(D),O=null);for(B=0;!C&&BQ.opacity&&(B.transparent=!0,B.opacity=Q.opacity),u=new $3Dmol.Mesh(u,B),b.add(u),u=null);Q=[];for(B=0;BQ.opacity&&(B.transparent=!0,B.opacity=Q.opacity),u=new $3Dmol.Mesh(u,B),b.add(u));null!=P&&0P.opacity&&(q.transparent=!0,q.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,q),b.add(P))}}();$3Dmol=$3Dmol||{}; +$3Dmol.GLDraw=function(){var b={},c=function(){var b=new $3Dmol.Vector3;return function(c){b.set(c[0],c[1],c[2]);var f=b.x,h=b.y,l=b.z,d=Math.sqrt(f*f+h*h);1E-4>d?(c=0,d=1):(c=-f/d,d=h/d);h=-c*f+d*h;f=Math.sqrt(h*h+l*l);1E-4>f?(l=0,h=1):(l/=f,h/=f);f=new Float32Array(9);f[0]=d;f[1]=c;f[2]=0;f[3]=-c*h;f[4]=d*h;f[5]=l;f[6]=c*l;f[7]=-d*l;f[8]=h;return f}}(),d=function(){var b=[],c=Math.pow(2,4),f,d=Math.pow(2,2),l=c/d,m;b[0]=new $3Dmol.Vector3(-1,0,0);b[l]=new $3Dmol.Vector3(0,0,1);b[2*l]=new $3Dmol.Vector3(1, +0,0);b[3*l]=new $3Dmol.Vector3(0,0,-1);for(f=3;4>=f;f++){d=Math.pow(2,f-1);l=c/d;for(m=0;m=s;s++){var u=0===s||10===s?!0:!1,x=5===s?!0:!1,q=[],p=[];for(g=0;g<=f;g++)if(x){var A=gMath.abs(A.x)&&(A.x=0),1E-5>Math.abs(A.y)&&(A.y=0),1E-5>Math.abs(A.z)&&(A.z=0),m=c?new $3Dmol.Vector3(0,Math.cos(0+D*t), +0):new $3Dmol.Vector3(A.x,A.y,A.z),m.normalize(),h.push(A),l.push(m),q.push(h.length-1)):q.push(h.length-f)}x&&w.push(p);w.push(q)}f={vertices:h,normals:l,verticesRows:w,w:f,h:10};return this.cache[c][b]=f}},t=0;b.drawCylinder=function(b,d,f,h,l,m,w){if(d&&f){t++;var e=m||w,G=!1;1==m&&1==w&&(G=!0);l=l||{r:0,g:0,b:0};var g=[f.x,f.y,f.z];g[0]-=d.x;g[1]-=d.y;g[2]-=d.z;var g=c(g),s=p.getVerticesForRadius(h,G);h=s.w;var G=s.h,u=e?G*h+2:2*h;b=b.updateGeoGroup(u);var x=s.vertices,q=s.normals,s=s.verticesRows, +A=s[G/2],I=s[G/2+1],D=b.vertices,C,B,F,J,L,K,H=b.vertexArray,M=b.normalArray,O=b.colorArray,R=b.faceArray;for(F=0;Fb&&(f=10,d=8);var l=2*Math.PI,m=Math.PI,w,e;for(e=0;e<=d;e++){var t=[];for(w=0;w<=f;w++){var g=w/f,s=e/d,u={};u.x=-b*Math.cos(0+ +g*l)*Math.sin(0+s*m);u.y=b*Math.cos(0+s*m);u.z=b*Math.sin(0+g*l)*Math.sin(0+s*m);g=new $3Dmol.Vector3(u.x,u.y,u.z);g.normalize();c.vertices.push(u);c.normals.push(g);t.push(c.vertices.length-1)}c.verticesRows.push(t)}return this.cache[b]=c}};b.drawSphere=function(b,c,f,d){new $3Dmol.Vector3(c.x,c.y,c.z);var l=A.getVerticesForRadius(f),m=l.vertices,w=l.normals;b=b.updateGeoGroup(m.length);for(var e=b.vertices,t=b.vertexArray,g=b.colorArray,s=b.faceArray,u=b.lineArray,x=b.normalArray,q=0,p=m.length;q< +p;++q){var I=3*(e+q),D=m[q];t[I]=D.x+c.x;t[I+1]=D.y+c.y;t[I+2]=D.z+c.z;g[I]=d.r;g[I+1]=d.g;g[I+2]=d.b}b.vertices+=m.length;l=l.verticesRows;t=l.length-1;for(d=0;dd.lengthSq()&&(d=f.clone(),1E-4m;m++)g[d+3*m]=c.x,g[d+3*m+1]=c.y,g[d+3*m+2]=c.z;c=b.normalArray;h=b.colorArray;for(m=0;4>m;m++)h[d+3*m]=e.r,h[d+3*m+1]=e.g,h[d+3*m+2]=e.b;c[d+0]=-l;c[d+1]=l;c[d+2]=0;c[d+3]=-l;c[d+4]=-l;c[d+5]=0;c[d+6]=l;c[d+7]=-l;c[d+8]=0;c[d+9]=l;c[d+10]=l;c[d+11]=0;b.vertices+=4;l=b.faceArray; +e=b.faceidx;l[e+0]=f;l[e+1]=f+1;l[e+2]=f+2;l[e+3]=f+2;l[e+4]=f+3;l[e+5]=f;b.faceidx+=6},B=function(b,c){if(b.style.sphere){var l=b.style.sphere;if(!l.hidden){var e=x(b,l),l=$3Dmol.getColorFromStyle(b,l);C(c,b,e,l)}}},F=function(b,c,l,e,f,d,g){b=b.updateGeoGroup(4);d=b.vertices;g=b.vertexArray;var h=b.colorArray,m=b.radiusArray,w=b.normalArray,q=f.r,u=f.g;f=f.b;for(var s=3*d,x=0;4>x;x++){g[s]=c.x;w[s]=l.x;h[s]=q;s++;g[s]=c.y;w[s]=l.y;h[s]=u;s++;g[s]=c.z;w[s]=l.z;if(2>x)h[s]=f;else{var t=s,y=-f;0== +y&&(y=-1E-4);h[t]=y}s++}b.vertices+=4;m[d]=-e;m[d+1]=e;m[d+2]=-e;m[d+3]=e;c=b.faceArray;l=b.faceidx;c[l+0]=d;c[l+1]=d+1;c[l+2]=d+2;c[l+3]=d+2;c[l+4]=d+3;c[l+5]=d;b.faceidx+=6};this.getCrystData=function(){return e.cryst?e.cryst:null};this.getSymmetries=function(){"undefined"==typeof e.symmetries&&(e.symmetries=[G]);return e.symmetries};this.setSymmetries=function(b){e.symmetries="undefined"==typeof b?[G]:b};this.getID=function(){return b};this.getFrames=function(){return f};this.setFrame=function(b){0!= +f.length&&(z=0<=b&&b=h)g=l;else{d=$3Dmol.getExtent(l);e=[[],[],[]];for(f=0;3>f;f++)e[0][f]=d[0][f]-h,e[1][f]=d[1][f]+h,e[2][f]=d[2][f];h=[];for(f=0;f=e[0][0]&&g<=e[1][0]&&m>=e[0][1]&&m<=e[1][1]&&w>=e[0][2]&&w<=e[1][2]&&(g>=d[0][0]&&g<=d[1][0]&&m>=d[0][1]&&m<=d[1][1]&&w>=d[0][2]&&w<=d[1][2]||h.push(z[f]))}g=h}m=l.length; +for(d=0;d=g||(f={b:f,e:g},g=e.bondOrder[d],1!=g&&(f.o=g),c.b.push(f))}}return c};this.globj=function(b,c){if(null===l){var d=z,f=c,f=f||{},w=new $3Dmol.Object3D,s=[],u={},t={},y=I,A=null,p=null;f.supportsImposters?(y=B,A=new $3Dmol.Geometry(!0),A.imposter=!0,p=new $3Dmol.Geometry(!0,!0),p.imposter=!0,p.sphereGeometry=A,p.drawnCaps={}):(f.supportsAIA?(y=D,A=new $3Dmol.Geometry(!1,!0,!0),A.instanced=!0):A=new $3Dmol.Geometry(!0),p=new $3Dmol.Geometry(!0)); +var G,J,E,aa,T={},Z=[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY];G=0;for(E=d.length;GBa;Ba++){var Ha=3*Na.vertices;Na.vertices++;Pa[Ha]=U.x+Ga[Ba][0];Pa[Ha+1]=U.y+Ga[Ba][1];Pa[Ha+2]= +U.z+Ga[Ba][2];ab[Ha]=Oa.r;ab[Ha+1]=Oa.g;ab[Ha+2]=Oa.b;if(Ta){var Qa=new $3Dmol.Vector3(Ga[Ba][0],Ga[Ba][1],Ga[Ba][2]);Qa.multiplyScalar(.1);Qa.set(Qa.x+U.x,Qa.y+U.y,Qa.z+U.z);U.intersectionShape.line.push(Qa)}}}}var fa=W,zb=d,kb=u;if(fa.style.line){var rb=fa.style.line;if(!rb.hidden){var lb=rb.linewidth||1;kb[lb]||(kb[lb]=new $3Dmol.Geometry);for(var ua=kb[lb].updateGeoGroup(6*fa.bonds.length),ka=ua.vertexArray,la=ua.colorArray,Ia=0;Ia=Ra.serial)){var Ca=new $3Dmol.Vector3(fa.x,fa.y,fa.z),Ua=new $3Dmol.Vector3(Ra.x,Ra.y,Ra.z),gb=Ca.clone().add(Ua).multiplyScalar(.5),sb=!1;fa.clickable&&(void 0===fa.intersectionShape&&(fa.intersectionShape={sphere:[],cylinder:[],line:[],triangle:[]}),fa.intersectionShape.line.push(Ca),fa.intersectionShape.line.push(Ua));var qa=$3Dmol.getColorFromStyle(fa,fa.style.line),Ja=$3Dmol.getColorFromStyle(Ra,Ra.style.line);if(fa.bondStyles&&fa.bondStyles[Ia]){var Sa=fa.bondStyles[Ia];if(!Sa.iswire)continue; +Sa.radius&&(bondR=Sa.radius);Sa.singleBond&&(sb=!0);"undefined"!=typeof Sa.color1&&(qa=$3Dmol.CC.color(Sa.color1));"undefined"!=typeof Sa.color2&&(Ja=$3Dmol.CC.color(Sa.color2))}var ma=3*ua.vertices;if(1fa.bondOrder[Ia]&&!sb){var Xa=q(fa,Ra,Ia),Da=Ua.clone();Da.sub(Ca);if(2==fa.bondOrder[Ia])if(Xa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Xa),p1b=Ca.clone(),p1b.sub(Xa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),qa==Ja)ua.vertices+=4,N(ka,la,ma,p1a,p2a,qa),N(ka,la, +ma+6,p1b,p2b,qa);else{ua.vertices+=8;Da.multiplyScalar(.5);var Va=p1a.clone();Va.add(Da);var Wa=p1b.clone();Wa.add(Da);N(ka,la,ma,p1a,Va,qa);N(ka,la,ma+6,Va,p2a,Ja);N(ka,la,ma+12,p1b,Wa,qa);N(ka,la,ma+18,Wa,p2b,Ja)}else 3==fa.bondOrder[Ia]&&(Xa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Xa),p1b=Ca.clone(),p1b.sub(Xa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),qa==Ja?(ua.vertices+=6,N(ka,la,ma,Ca,Ua,qa),N(ka,la,ma+6,p1a,p2a,qa),N(ka,la,ma+12,p1b,p2b,qa)):(ua.vertices+=12,Da.multiplyScalar(.5), +Va=p1a.clone(),Va.add(Da),Wa=p1b.clone(),Wa.add(Da),N(ka,la,ma,Ca,gb,qa),N(ka,la,ma+6,gb,Ua,Ja),N(ka,la,ma+12,p1a,Va,qa),N(ka,la,ma+18,Va,p2a,Ja),N(ka,la,ma+24,p1b,Wa,qa),N(ka,la,ma+30,Wa,p2b,Ja)))}else qa==Ja?(ua.vertices+=2,N(ka,la,ma,Ca,Ua,qa)):(ua.vertices+=4,N(ka,la,ma,Ca,gb,qa),N(ka,la,ma+6,gb,Ua,Ja))}}}}var ca=W,Ab=d,ia=p;if(ca.style.stick){var Ya=ca.style.stick;if(!Ya.hidden){var bb=Ya.radius||.25,va=bb,tb=Ya.singleBonds||!1,cb=0,db=0,na=$3Dmol.getColorFromStyle(ca,Ya),oa=void 0,ya=void 0; +!ca.capDrawn&&4>ca.bonds.length&&(cb=2);var ja=$3Dmol.GLDraw.drawCylinder;ia.imposter&&(ja=F);for(var pa=0;paha.bonds.length&&(db=2),na!=Ka?(oa=(new $3Dmol.Vector3).addVectors(ra,Aa).multiplyScalar(.5),ja(ia,ra,oa,va,na,cb,0),ja(ia,oa,Aa,va,Ka,0,db)):ja(ia,ra,Aa,va,na,cb,db),ca.clickable||ha.clickable){oa=(new $3Dmol.Vector3).addVectors(ra,Aa).multiplyScalar(.5);if(ca.clickable){var Bb=new $3Dmol.Cylinder(ra,oa,va),Cb=new $3Dmol.Sphere(ra,va);ca.intersectionShape.cylinder.push(Bb);ca.intersectionShape.sphere.push(Cb)}if(ha.clickable){var Db= +new $3Dmol.Cylinder(Aa,oa,va),Eb=new $3Dmol.Sphere(Aa,va);ha.intersectionShape.cylinder.push(Db);ha.intersectionShape.sphere.push(Eb)}}}else if(1Z[1]&&(Z[1]=W.resi)),s.push(W))}}if(0T.sphere&&0<=T.sphere&&($a.transparent=!0,$a.opacity=T.sphere);fb=new $3Dmol.Mesh(A,$a);w.add(fb)}if(0T.stick&&0<=T.stick&&(hb.transparent=!0,hb.opacity=T.stick);p.initTypedArrays();hb.wireframe&&p.setUpWireframe();xb=new $3Dmol.Mesh(p,hb)}w.add(xb)}for(G in u)if(u.hasOwnProperty(G)){var ob=G,pb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>T.line&&0<=T.line&&(pb.transparent=!0,pb.opacity=T.line);u[G].initTypedArrays();var Gb=new $3Dmol.Line(u[G], +pb,$3Dmol.LinePieces);w.add(Gb)}for(G in t)if(t.hasOwnProperty(G)){var ob=G,qb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>T.cross&&0<=T.cross&&(qb.transparent=!0,qb.opacity=T.cross);t[G].initTypedArrays();var Hb=new $3Dmol.Line(t[G],qb,$3Dmol.LinePieces);w.add(Hb)}if(g&&e.symmetries&&0MOLECULE/gm)?"mol2":b.match(/^HETATM/gm)||b.match(/^ATOM/gm)?"pdb":b.match(/^.*\n.*\n.\s*(\d+)\s+(\d+)/gm)?"sdf":"xyz",console.log("Best guess: "+c)));return(0,$3Dmol.Parsers[c])(b,d)};b.setAtomDefaults=function(b,d){for(var t=0;tb.mid?b.mid:.618034;var h=b.start,e=b.end,t=b.radius,g=b.radiusRatio,s=b.mid;if(h&&e){var c=f.updateGeoGroup(51),u=e.clone();u.sub(h).multiplyScalar(s);var x=h.clone().add(u),s=u.clone().negate();this.intersectionShape.cylinder.push(new $3Dmol.Cylinder(h.clone(),x.clone(),t));this.intersectionShape.sphere.push(new $3Dmol.Sphere(h.clone(), +t));var q=[];q[0]=u.clone();1E-4 +this.opacity?!0:!1,opacity:this.opacity,wireframeLinewidth:this.linewidth}):new $3Dmol.MeshLambertMaterial({wireframe:this.wireframe,side:this.side,transparent:1>this.opacity?!0:!1,opacity:this.opacity,wireframeLinewidth:this.linewidth});d=new $3Dmol.Mesh(f,d);y.add(d);d=new $3Dmol.LineBasicMaterial({linewidth:this.linewidth,color:this.color});d=new $3Dmol.Line(h,d,$3Dmol.LinePieces);y.add(d);z=y.clone();b.add(z)}};this.removegl=function(b){z&&(void 0!==z.geometry&&z.geometry.dispose(),void 0!==z.material&& +z.material.dispose(),b.remove(z),z=null);y=null}}var c=function(b,c,p){var z=p.faceArr;0!==p.vertexArr.length&&0!==z.length||console.warn("Error adding custom shape component: No vertices and/or face indices supplied!");z=p.color;"undefined"==typeof z&&(z=b.color);for(var z=$3Dmol.CC.color(z),f=$3Dmol.splitMesh(p),h=0,l=f.length;hb.vertexArr.length)return[b];var c=[{vertexArr:[],normalArr:[],faceArr:[]}];b.colorArr&&(c.colorArr=[]);for(var d=[],p=[],y=0,A=b.faceArr,q=0,B=A.length;qw;w++){var h=A[q+w];d[h]!==y&&(d[h]=y,p[h]=f.vertexArr.length,f.vertexArr.push(b.vertexArr[h]),b.normalArr&&b.normalArr[h]&&f.normalArr.push(b.normalArr[h]),b.colorArr&&b.colorArr[h]&&f.colorArr.push(b.colorArr[h]));f.faceArr.push(p[h])}64E3<=f.vertexArr.length&&(c.push({vertexArr:[], -normalArr:[],faceArr:[]}),b.colorArr&&(c.colorArr=[]),y++)}return c}; -$3Dmol.GLViewer=function(){return function(b,c){function d(b){var c=[];"undefined"===typeof b&&(b={});var f=[],g;if("undefined"===typeof b.model)for(g=0;gb&&(b=i);return b+1},T=function(b){if(J){var c=G.position.z-I.position.z;1>c&&(c=1);G.near=c+O;1>G.near&&(G.near=1);G.far=c+Q;G.near+1>G.far&&(G.far=G.near+1);G instanceof $3Dmol.Camera?G.fov=20:(G.right=c*Math.tan(Math.PI/180*20),G.left=-G.right,G.top=G.right/ -E,G.bottom=-G.top);G.updateProjectionMatrix();J.fog.near=G.near+.4*(G.far-G.near);J.fog.far=G.far;C.render(J,G);if(!b&&0b&&(b=80),I.position.z=X+d*b,150c||1h&&(h=5);O=-h/1.9;Q=h/2;h=f[1][0]-f[0][0];m=f[1][1]-f[0][1];c=f[1][2]-f[0][2];h=Math.sqrt(h*h+m*m+c*c);5>h&&(h=5);f=25;for(h=0;hf&&(f=m));h=2*Math.sqrt(f);I.position.z=-(.5*h/Math.tan(Math.PI/180*G.fov/2)-150);T();return this};this.setSlab=function(b,c){O=b;Q=c};this.getSlab=function(b){return{near:O,far:Q}};this.addLabel=function(b,c){var e=new $3Dmol.Label(b,c); -e.setContext();K.add(e.sprite);x.push(e);T();return e};this.addResLabels=function(b,c){p("addResLabels",b,this,c);return this};this.removeLabel=function(b){for(var c=0;cl){b.start=e;b.end=f;c.addLine(b);break}s.addVectors(e,h);b.start=e;b.end=s;c.addLine(b); -e=s.clone();t+=d;s.addVectors(e,m);e=s.clone();t+=w}}else c.addLine(b);g.push(c);return c};this.addUnitCell=function(b){var c=new $3Dmol.GLShape({wireframe:!0});c.shapePosition=g.length;var e=b.getCrystData();if(e){b=e.a;var f=e.b,d=e.c,h=e.alpha,m=e.beta,e=e.gamma,h=h*Math.PI/180,m=m*Math.PI/180,e=e*Math.PI/180,l;l=Math.cos(m);h=(Math.cos(h)-Math.cos(m)*Math.cos(e))/Math.sin(e);m=Math.sqrt(Math.max(0,1-l*l-h*h));b=new $3Dmol.Matrix4(b,f*Math.cos(e),d*l,0,0,f*Math.sin(e),d*h,0,0,0,d*m,0,0,0,0,1); -f=[new $3Dmol.Vector3(0,0,0),new $3Dmol.Vector3(1,0,0),new $3Dmol.Vector3(0,1,0),new $3Dmol.Vector3(0,0,1),new $3Dmol.Vector3(1,1,0),new $3Dmol.Vector3(0,1,1),new $3Dmol.Vector3(1,0,1),new $3Dmol.Vector3(1,1,1)];for(d=0;db&&(b=e[c].getFrames().length);return b};this.animate=function(b){S=!0;var c=100,e="forward",f=0;b=b||{};b.interval&&(c=b.interval);b.loop&&(e=b.loop);b.reps&&(f=b.reps);var d=this.getFrames(),g=this,h=0,m=1,l=0,w=d*f,s=setInterval(function(){var b=e;"forward"==b?(g.setFrame(h), -h=(h+m)%d):"backward"==b?(g.setFrame(d-1-h),h=(h+m)%d):(g.setFrame(h),h+=m,m*=0==h%(d-1)?-1:1);g.render();++l!=w&&g.isAnimated()||clearInterval(s)},c);return this};this.stopAnimate=function(){S=!1;return this};this.isAnimated=function(){return S};this.addModel=function(b,c,f){var d=new $3Dmol.GLModel(e.length,q);d.addMolData(b,c,f);e.push(d);return d};this.addModels=function(b,c,f){f=f||{};f.multimodel=!0;f.frames=!0;b=$3Dmol.GLModel.parseMolData(b,c,f);for(c=0;cc[1][0]||d.yc[1][1]||d.zc[1][2]||f.push(e))}return f},Ta=function(b){return(b[1][0]-b[0][0])*(b[1][1]-b[0][1])*(b[1][2]-b[0][2])},$a=function(b,c,f){var e=[],d=function(b){var c=[];c[0]=[b[0][0],b[0][1],b[0][2]];c[1]=[b[1][0],b[1][1],b[1][2]];return c},h=function(b){if(64E3>Ta(b))return[b];var c=b[1][0]-b[0][0],f=b[1][1]-b[0][1],e=b[1][2]-b[0][2],f=c>f&&c>e?0:f>c&&f>e?1:2,e=d(b),c=d(b);b=(b[1][f]-b[0][f])/2+b[0][f];e[1][f]=b;c[0][f]=b;b=h(e); -c=h(c);return b.concat(c)};b=h(b);for(var g=0,m=b.length;g= -p.length)){var d;d=b;var g=p[c].extent,l=p[c].atoms,m=p[c].toshow,w=new $3Dmol.ProteinSurface;w.initparm(g,1===d?!1:!0,x);w.fillvoxels(y,l);w.buildboundary();d==$3Dmol.SurfaceType.SES&&(w.fastdistancemap(),w.boundingatom(!1),w.fillvoxelswaals(y,l));w.marchingcube(d);d=w.getFacesAndVertices(m);d=Ua(e,d,u);$3Dmol.mergeGeos(f.geo,d);h.render();setTimeout(ga,1,c+1)}},1,0);else{g=[];0>b&&(b=0);t=0;for(q=4;tB&&(y=B);var f=(B+q)/2;"undefined"!=typeof d&&(f=d);y<=f?(q=Math.floor(255*Math.sqrt((y-q)/(f-q))),q=16711680+256*q+q):(q=Math.floor(255*Math.sqrt(1-(y-f)/(B-f))),q=65536*q+256*q+255);return q};this.range=function(){return"undefined"!=typeof b&&"undefined"!= +$3Dmol.splitMesh=function(b){if(64E3>b.vertexArr.length)return[b];var c=[{vertexArr:[],normalArr:[],faceArr:[]}];b.colorArr&&(c.colorArr=[]);for(var d=[],p=[],t=0,A=b.faceArr,y=0,z=A.length;yh;h++){var l=A[y+h];d[l]!==t&&(d[l]=t,p[l]=f.vertexArr.length,f.vertexArr.push(b.vertexArr[l]),b.normalArr&&b.normalArr[l]&&f.normalArr.push(b.normalArr[l]),b.colorArr&&b.colorArr[l]&&f.colorArr.push(b.colorArr[l]));f.faceArr.push(p[l])}64E3<=f.vertexArr.length&&(c.push({vertexArr:[], +normalArr:[],faceArr:[]}),b.colorArr&&(c.colorArr=[]),t++)}return c}; +$3Dmol.GLViewer=function(){return function(b,c){function d(b){var c=[];"undefined"===typeof b&&(b={});var d=[],f;if("undefined"===typeof b.model)for(f=0;fb&&(b=i);return b+1},U=function(){var b=C.position.z-H.position.z;1>b&&(b=1);C.near=b+O;1>C.near&&(C.near=1);C.far=b+R;C.near+1>C.far&&(C.far=C.near+1);C.fov=20;C.right=b*Math.tan(Math.PI/180*20);C.left=-C.right;C.top=C.right/N;C.bottom=-C.top;C.updateProjectionMatrix(); +K.fog.near=C.near+.4*(C.far-C.near);K.fog.far=C.far},X=function(b){if(K&&(U(),D.render(K,C),!b&&0b&&(b=80),H.position.z=aa+l*b,150c||1l&&(l=5);O=-l/1.9;R=l/2;l=f[1][0]-f[0][0];h=f[1][1]-f[0][1];c=f[1][2]-f[0][2];l=Math.sqrt(l*l+h*h+c*c);5>l&&(l=5);f=25;for(l=0;lf&&(f=h));l=2*Math.sqrt(f);H.position.z=-(.5*l/Math.tan(Math.PI/180*C.fov/2)-150);X();return this}; +this.setSlab=function(b,c){O=b;R=c};this.getSlab=function(b){return{near:O,far:R}};this.addLabel=function(b,c){var d=new $3Dmol.Label(b,c);d.setContext();M.add(d.sprite);s.push(d);X();return d};this.addResLabels=function(b,c){p("addResLabels",b,this,c);return this};this.removeLabel=function(b){for(var c=0;cm){b.start=d;b.end=e;c.addLine(b);break}s.addVectors(d,l);b.start=d;b.end=s;c.addLine(b);d=s.clone();w+=f;s.addVectors(d,h);d=s.clone();w+=q}}else c.addLine(b);g.push(c);return c};this.addUnitCell=function(b){var c=new $3Dmol.GLShape({wireframe:!0});c.shapePosition=g.length;var d=b.getCrystData();if(d){b=d.a;var e=d.b,f=d.c,l=d.alpha,h=d.beta,d=d.gamma,l=l*Math.PI/180,h=h*Math.PI/180,d=d*Math.PI/180,m;m=Math.cos(h);l=(Math.cos(l)-Math.cos(h)*Math.cos(d))/ +Math.sin(d);h=Math.sqrt(Math.max(0,1-m*m-l*l));b=new $3Dmol.Matrix4(b,e*Math.cos(d),f*m,0,0,e*Math.sin(d),f*l,0,0,0,f*h,0,0,0,0,1);e=[new $3Dmol.Vector3(0,0,0),new $3Dmol.Vector3(1,0,0),new $3Dmol.Vector3(0,1,0),new $3Dmol.Vector3(0,0,1),new $3Dmol.Vector3(1,1,0),new $3Dmol.Vector3(0,1,1),new $3Dmol.Vector3(1,0,1),new $3Dmol.Vector3(1,1,1)];for(f=0;fb&&(b=e[c].getFrames().length);return b};this.animate=function(b){S=!0;var c=100,d="forward",e=0;b=b||{};b.interval&&(c=b.interval);b.loop&&(d=b.loop); +b.reps&&(e=b.reps);var f=this.getFrames(),l=this,h=0,g=1,m=0,q=f*e,s=setInterval(function(){var b=d;"forward"==b?(l.setFrame(h),h=(h+g)%f):"backward"==b?(l.setFrame(f-1-h),h=(h+g)%f):(l.setFrame(h),h+=g,g*=0==h%(f-1)?-1:1);l.render();++m!=q&&l.isAnimated()||clearInterval(s)},c);return this};this.stopAnimate=function(){S=!1;return this};this.isAnimated=function(){return S};this.addModel=function(b,c,d){var f=new $3Dmol.GLModel(e.length,y);f.addMolData(b,c,d);e.push(f);return f};this.addModels=function(b, +c,d){d=d||{};d.multimodel=!0;d.frames=!0;b=$3Dmol.GLModel.parseMolData(b,c,d);for(c=0;cc[1][0]||f.yc[1][1]||f.zc[1][2]||d.push(e))}return d},Pa=function(b){return(b[1][0]-b[0][0])*(b[1][1]-b[0][1])*(b[1][2]-b[0][2])},ab=function(b,c,d){var e=[],f=function(b){var c=[];c[0]=[b[0][0],b[0][1],b[0][2]];c[1]=[b[1][0],b[1][1],b[1][2]];return c},l=function(b){if(64E3>Pa(b))return[b]; +var c=b[1][0]-b[0][0],d=b[1][1]-b[0][1],e=b[1][2]-b[0][2],d=c>d&&c>e?0:d>c&&d>e?1:2,e=f(b),c=f(b);b=(b[1][d]-b[0][d])/2+b[0][d];e[1][d]=b;c[0][d]=b;b=l(e);c=l(c);return b.concat(c)};b=l(b);for(var h=0,g=b.length;h=t.length)){var d;d=b;var h=t[c].extent,g=t[c].atoms,m=t[c].toshow,q=new $3Dmol.ProteinSurface;q.initparm(h,1===d?!1:!0,x);q.fillvoxels(y,g);q.buildboundary();d==$3Dmol.SurfaceType.SES&&(q.fastdistancemap(),q.boundingatom(!1),q.fillvoxelswaals(y,g));q.marchingcube(d);d=q.getFacesAndVertices(m);d=Ba(e,d,p);$3Dmol.mergeGeos(f.geo, +d);l.render();setTimeout(Ya,1,c+1)}},1,0);else{h=[];0>b&&(b=0);w=0;for(u=4;wz&&(t=z);var f=(z+y)/2;"undefined"!=typeof d&&(f=d);t<=f?(y=Math.floor(255*Math.sqrt((t-y)/(f-y))),y=16711680+256*y+y):(y=Math.floor(255*Math.sqrt(1-(t-f)/(z-f))),y=65536*y+256*y+255);return y};this.range=function(){return"undefined"!=typeof b&&"undefined"!= typeof c?[b,c]:null}}; -$3Dmol.Gradient.ROYGB=function(b,c){var d=1;"undefined"==typeof c&&$.isArray(b)&&2<=b.length&&(c=b[1],b=b[0]);cq&&(p=q);var B=(A+q)/2,f=(A+B)/2,w=(B+q)/2;pq&&(p=q);var B=(p-A)/(q-A)*5/6+.5;A=Math.sin(Math.PI*B);A*=255*A;q=Math.sin(Math.PI*(B+1/3));q*=255*q;B=Math.sin(Math.PI*(B+2/3));return 65536*Math.floor(A)+256*Math.floor(255*B*B)+1*Math.floor(q)};this.range=function(){return"undefined"!=typeof b&& +$3Dmol.Gradient.ROYGB=function(b,c){var d=1;"undefined"==typeof c&&$.isArray(b)&&2<=b.length&&(c=b[1],b=b[0]);cy&&(p=y);var z=(A+y)/2,f=(A+z)/2,h=(z+y)/2;py&&(p=y);var z=(p-A)/(y-A)*5/6+.5;A=Math.sin(Math.PI*z);A*=255*A;y=Math.sin(Math.PI*(z+1/3));y*=255*y;z=Math.sin(Math.PI*(z+2/3));return 65536*Math.floor(A)+256*Math.floor(255*z*z)+1*Math.floor(y)};this.range=function(){return"undefined"!=typeof b&& "undefined"!=typeof c?[b,c]:null}};$3Dmol.LabelCount=0;$3Dmol.Label=function(b,c){this.id=$3Dmol.LabelCount++;this.stylespec=c||{};this.canvas=document.createElement("canvas");this.canvas.width=134;this.canvas.height=35;this.context=this.canvas.getContext("2d");this.sprite=new $3Dmol.Sprite;this.text=b}; -$3Dmol.Label.prototype={constructor:$3Dmol.Label,getStyle:function(){return this.stylespec},setContext:function(){var b=function(b,d,p){"undefined"!=typeof b&&(p=b instanceof $3Dmol.Color?b.scaled():$3Dmol.CC.color(b).scaled());"undefined"!=typeof d&&(p.a=parseFloat(d));return p};return function(){var c=this.stylespec,d="undefined"==typeof c.useScreen?!1:c.useScreen,p=c.showBackground;if("0"===p||"false"===p)p=!1;"undefined"==typeof p&&(p=!0);var y=c.font?c.font:"sans-serif",A=parseInt(c.fontSize)? -parseInt(c.fontSize):18,q=b(c.fontColor,c.fontOpacity,{r:255,g:255,b:255,a:1}),B=c.padding?c.padding:4,f=c.borderThickness?c.borderThickness:0,w=b(c.backgroundColor,c.backgroundOpacity,{r:0,g:0,b:0,a:1}),h=b(c.borderColor,c.borderOpacity,w),t=c.position?c.position:{x:-10,y:1,z:1},m=void 0!==c.inFront?c.inFront:!0;if("false"===m||"0"===m)m=!1;var e=c.alignment||$3Dmol.SpriteAlignment.topLeft,F="";c.bold&&(F="bold ");this.context.font=F+A+"px "+y;var g=this.context.measureText(this.text).width;p|| -(f=0);var x=g+2.5*f+2*B,u=1.25*A+2*f+2*B;if(c.backgroundImage){var F=c.backgroundImage,s=c.backgroundWidth?c.backgroundWidth:F.width,l=c.backgroundHeight?c.backgroundHeight:F.height;s>x&&(x=s);l>u&&(u=l)}this.canvas.width=x;this.canvas.height=u;this.context.clearRect(0,0,this.canvas.width,this.canvas.height);F="";c.bold&&(F="bold ");this.context.font=F+A+"px "+y;this.context.fillStyle="rgba("+w.r+","+w.g+","+w.b+","+w.a+")";this.context.strokeStyle="rgba("+h.r+","+h.g+","+h.b+","+h.a+")";this.context.lineWidth= -f;p&&(p=this.context,w=y=f,x-=2*f,u-=2*f,h=0u[b]&&(u[b]=q.length,q.push(m));return u[b]},s=new Int32Array(12),l=w?p:c,w=w?y:d;for(f=0;fG;++G)C|=!!(b[(e*(f+((G&4)>>2))+E+((G&2)>>1))*F+M+(G&1)]&2)<w;w++)e[w]=Array(c.length);w=0;for(h=c.length;we[0][w])f[w].x=c[w].x,f[w].y=c[w].y,f[w].z=c[w].z;else if(3==e[0][w]||4==e[0][w]){f[w].x=0;f[w].y=0;t=f[w].z=0;for(m=e[0][w];tMath.abs(e.resi-m.resi)||(pt.length)return h;for(var m=t[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),e=Math.abs(parseFloat(m[0])),m=t[3].replace(/^\s+/,"").replace(/\s+/g, -" ").split(" "),m=0t.length);){var m=parseInt(t[0]);if(isNaN(m)||0>=m)break;if(t.lengthm.length);){var e=parseInt(m[3].substr(0,3));if(isNaN(e)|| -0>=e)break;var p=parseInt(m[3].substr(3,3)),g=4;if(m.length<4+e+p)break;for(var q=[],u=d[d.length-1].length,s=u+e,l,e=u;eM;M++)for(G=C[M].split("+"),H=0;HMOLECULE/), -p=b.search(/@ATOM/);if(-1==e||-1==p)break;var e=[],g=m[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),x=parseInt(g[0]),p=0;1ATOM"==m[s]){u=s+1;break}s=d[d.length-1].length;for(x=s+x;sBOND"==m[u++]){s=!0;break}if(s&&p)for(s=0;sd)return!1;var m=b.y-c.y,m=m*m;if(m>d)return!1;var e=b.z-c.z,e=e*e;if(e>d)return!1;p=p+m+e;return isNaN(p)?!1:.5>p?!1:p>d?!1:!0},B=function(b,c,d){var p=d.length,m=p,e,q;if(!c)for(c=0;cz;z++){if(J=parseInt(H.substr([11,16,21,26][z],5)),J=M[J], -I=h[h.length-1][J],void 0!==N&&void 0!==I)if(L[[u,J]])for(L[[u,J]]+=1,I=0;I=N;N++)if(H=C[G].replace(/^\s*/,""),parseInt(H.substr(18,1))==N)z.elements[N-1]=parseFloat(H.substr(23,10)),z.elements[N-1+4]=parseFloat(H.substr(33,10)),z.elements[N-1+8]=parseFloat(H.substr(43,10)),z.elements[N-1+12]=parseFloat(H.substr(53)),G++;else for(;"BIOMT"==H.substr(13,5);)G++,H=C[G].replace(/^\s*/, -"");z.elements[3]=0;z.elements[7]=0;z.elements[11]=0;z.elements[15]=1;g[g.length-1].symmetries.push(z);G--}}(new Date).getTime();for(N=0;Ns[z][3]||(u.ss="s",u.resi==s[z][1]&&(u.ssbegin=!0),u.resi==s[z][3]&&(u.ssend=!0));for(z=0;zl[z][3]|| -(u.ss="h",u.resi==l[z][1]?u.ssbegin=!0:u.resi==l[z][3]&&(u.ssend=!0))}}return h};b.pqr=b.PQR=function(b,c){var h=[[]],p,m=!c.noSecondaryStructure,e=[],q=b.split(/\r?\n|\r/),g,x;for(g=0;gp;p++)s=parseInt(x.substr([11,16,21, -26][p],5)),l=h[h.length-1][e[s]],void 0!==u&&void 0!==l&&(u.bonds.push(e[s]),u.bondOrder.push(1));for(g=0;gs&&(s=x);q>u&&(u=q)}this.canvas.width=s;this.canvas.height=u;this.context.clearRect(0,0,this.canvas.width,this.canvas.height);G="";c.bold&&(G="bold ");this.context.font=G+A+"px "+t;this.context.fillStyle="rgba("+h.r+","+h.g+","+h.b+","+h.a+")";this.context.strokeStyle="rgba("+l.r+","+l.g+","+l.b+","+l.a+")";this.context.lineWidth= +f;p&&(p=this.context,h=t=f,s-=2*f,u-=2*f,l=0x[b]&&(x[b]=y.length,y.push(q));return x[b]},q=new Int32Array(12),N=h?p:c,h=h?t:d;for(f=0;fB;++B)C|=!!(b[(G*(f+((B&4)>>2))+I+((B&2)>>1))*g+D+(B&1)]&2)<h;h++)e[h]=Array(c.length);h=0;for(l=c.length;he[0][h])f[h].x=c[h].x,f[h].y=c[h].y,f[h].z=c[h].z;else if(3==e[0][h]||4==e[0][h]){f[h].x=0;f[h].y=0;m=f[h].z=0;for(w=e[0][h];mMath.abs(e.resi-w.resi)||(pg.length)return d;if(g[1].match(/\d+/))m=parseFloat(g[1]);else return console.log("Warning: second line of the vasp structure file must be a number"), +d;if(0>m)return console.log("Warning: Vasp implementation for negative lattice lengths is not yet available"),d;w=new Float32Array(g[2].replace(/^\s+/,"").split(/\s+/));e=new Float32Array(g[3].replace(/^\s+/,"").split(/\s+/));p=new Float32Array(g[4].replace(/^\s+/,"").split(/\s+/));var s=g[5].replace(/\s+/,"").replace(/\s+$/,"").split(/\s+/),u=new Int16Array(g[6].replace(/^\s+/,"").split(/\s+/)),t=g[7].replace(/\s+/,"");if(t.match(/C/))t="cartesian";else if(t.match(/D/))t="direct";else return console.log("Warning: Unknown vasp mode in POSCAR file: mode must be either C(artesian) or D(irect)"), +d;if(s.length!=u.length)return console.log("Warning: declaration of atomary species wrong:"),console.log(s),console.log(u),d;g.splice(0,8);for(var q=0,y=0,z=s.length;ym.length)return l;for(var w=m[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),e=Math.abs(parseFloat(w[0])),w=m[3].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),w=0m.length);){var w=parseInt(m[0]);if(isNaN(w)||0>=w)break;if(m.lengthp.length);){var e=parseInt(p[3].substr(0,3));if(isNaN(e)||0>=e)break;var t=parseInt(p[3].substr(3,3)),g=4;if(p.length<4+e+t)break;for(var s=[],u=d[d.length-1].length,x=u+e,q,e=u;eI;I++)for(C=D[I].split("+"),F=0;FMOLECULE/),t=b.search(/@ATOM/);if(-1==e||-1==t)break;var e=[],g=p[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),s=parseInt(g[0]),t=0;1ATOM"==p[x]){u=x+1;break}x=d[d.length-1].length;for(s=x+s;xBOND"==p[u++]){x=!0;break}if(x&&t)for(x=0;xd)return!1;var p=b.y-c.y,p=p*p;if(p>d)return!1;var e=b.z-c.z,e=e*e;if(e>d)return!1;m=m+p+e;return isNaN(m)?!1:.5>m?!1:m>d?!1:!0},z=function(b,c,d){var m=d.length,p=m,e,t;if(!c)for(c=0;cB;B++){if(K=parseInt(F.substr([11,16,21,26][B],5)),K=I[K],H=l[l.length-1][K],void 0!==L&&void 0!==H)if(J[[u,K]])for(J[[u,K]]+=1,H=0;H=L;L++)if(F=D[C].replace(/^\s*/,""),parseInt(F.substr(18,1))==L)B.elements[L-1]=parseFloat(F.substr(23,10)), +B.elements[L-1+4]=parseFloat(F.substr(33,10)),B.elements[L-1+8]=parseFloat(F.substr(43,10)),B.elements[L-1+12]=parseFloat(F.substr(53)),C++;else for(;"BIOMT"==F.substr(13,5);)C++,F=D[C].replace(/^\s*/,"");B.elements[3]=0;B.elements[7]=0;B.elements[11]=0;B.elements[15]=1;g[g.length-1].symmetries.push(B);C--}}(new Date).getTime();for(L=0;Lx[B][3]||(u.ss="s",u.resi==x[B][1]&&(u.ssbegin=!0),u.resi==x[B][3]&&(u.ssend=!0));for(B=0;Bq[B][3]||(u.ss="h",u.resi==q[B][1]?u.ssbegin=!0:u.resi==q[B][3]&&(u.ssend=!0))}}return l};b.pqr=b.PQR=function(b,c){var l=[[]],m,p=!c.noSecondaryStructure;l.modelData=[{symmetries:[]}];var e=[],y=b.split(/\r?\n|\r/),g,s;for(g=0;gm;m++)x=parseInt(s.substr([11,16,21,26][m],5)),q=l[l.length-1][e[x]],void 0!==u&&void 0!==q&&(u.bonds.push(e[x]),u.bondOrder.push(1));for(g=0;gaa,chain:Y,resi:T,icode:ga,rescode:T+(" "!=ga?"^"+ga:""),serial:Na,atom:Fa,bonds:[],ss:2==aa?"h":3==aa?"s":"c",bondOrder:[],properties:{charge:Ga,occupancy:Ea},b:X})}s+=1}aa=E.bondAtomList;L=0;for(K=E.bondOrderList.length;L=s){V=L;break}Z=Q[Z];U=Q[U];X=S[Z];ga=S[U];X&&ga&&(X.bonds.push(U),X.bondOrder.push(T),ga.bonds.push(Z),ga.bondOrder.push(T))}c.multimodel&&(c.onemol||p.push([]))}for(H=0;Hb||b>=this.size.x||0>c||c>=this.size.y||0>d||d>=this.size.z?0:this.data[b*this.size.y*this.size.z+c*this.size.z+d]}; -$3Dmol.VolumeData.prototype.cube=function(b){b=b.replace(/^\s+/,"").split(/[\n\r]+/);if(!(6>b.length)){var c=b[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),d=parseFloat(c[0]),p=Math.abs(d),y=this.origin=new $3Dmol.Vector3(parseFloat(c[1]),parseFloat(c[2]),parseFloat(c[3])),c=b[3].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),A=0d&&c++;b=b.splice(p+c).join(" ");b=b.replace(/^\s+/,"");b=b.split(/[\s\r]+/);this.data=new Float32Array(b)}}; -$3Dmol.VolumeData.prototype.ccp4=function(b){var c,d,p,y,A,q,B,f,w,h,t,m,e,F,g,x=new Int32Array(b,0,56);m=new Float32Array(b,0,56);c=x[0];d=x[1];p=x[2];y=x[4];A=x[5];q=x[6];B=Math.abs(x[7]);f=Math.abs(x[8]);w=Math.abs(x[9]);h=m[10];t=m[11];m=m[12];xVox=h/c;yVox=t/d;zVox=m/p;switch(x[16]){case 1:e=y;g=F=0;break;case 2:F=y;g=e=0;break;case 3:g=y,F=e=0}switch(x[17]){case 1:e=A;g=F=0;break;case 2:F=A;g=e=0;break;case 3:g=A,F=e=0}switch(x[18]){case 1:e=q;g=F=0;break;case 2:F=q;g=e=0;break;case 3:g=q,F= -e=0}this.origin=new $3Dmol.Vector3(e,F,g);c=x[23];this.size={x:B,y:f,z:w};this.unit=new $3Dmol.Vector3(xVox,yVox,zVox);new Int8Array(b);this.data=new Float32Array(b,1024+c)}; +$3Dmol.VolumeData.prototype.vasp=function(b){var c=b.replace(/^\s+/,"").split(/[\n\r]/),d=$3Dmol.Parsers.vasp(b)[0].length;if(0==d)console.log("No good formating of CHG or CHGCAR file, not atomic information provided in the file."),this.data=[];else{var p=parseFloat(c[1]),t;t=c[2].replace(/^\s+/,"").split(/\s+/);b=(new $3Dmol.Vector3(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]))).multiplyScalar(1.889725992*p);t=c[3].replace(/^\s+/,"").split(/\s+/);var A=(new $3Dmol.Vector3(parseFloat(t[0]), +parseFloat(t[1]),parseFloat(t[2]))).multiplyScalar(1.889725992*p);t=c[4].replace(/^\s+/,"").split(/\s+/);t=(new $3Dmol.Vector3(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]))).multiplyScalar(1.889725992*p);p=b.x*(A.y*t.z-t.y*A.z)-A.x*(b.y*t.z-t.y*b.z)+t.x*(b.y*A.z-A.y*b.z);p=Math.abs(p)/Math.pow(1.889725992,3);p=1/p;c.splice(0,8+d+1);var y=c[0].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),d=Math.abs(y[0]),z=Math.abs(y[1]),y=Math.abs(y[2]),f=this.origin=new $3Dmol.Vector3(0,0,0);this.size= +{x:d,y:z,z:y};this.unit=new $3Dmol.Vector3(b.x,A.y,t.z);b=b.multiplyScalar(1/(1.889725992*d));A=A.multiplyScalar(1/(1.889725992*z));t=t.multiplyScalar(1/(1.889725992*y));if(0!=b.y||0!=b.z||0!=A.x||0!=A.z||0!=t.x||0!=t.y)this.matrix=new $3Dmol.Matrix4(b.x,A.x,t.x,0,b.y,A.y,t.y,0,b.z,A.z,t.z,0,0,0,0,1),this.matrix=this.matrix.multiplyMatrices(this.matrix,(new $3Dmol.Matrix4).makeTranslation(f.x,f.y,f.z)),this.origin=new $3Dmol.Vector3(0,0,0),this.unit=new $3Dmol.Vector3(1,1,1);c.splice(0,1);c=c.join(" "); +c=c.replace(/^\s+/,"");c=c.split(/[\s\r]+/);c.splice(d*z*y+1);c=new Float32Array(c);for(b=0;bb.length)){var c=b[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),d=parseFloat(c[0]),p=Math.abs(d),t=this.origin=new $3Dmol.Vector3(parseFloat(c[1]),parseFloat(c[2]),parseFloat(c[3])),c=b[3].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),A=0d&&t++;b=b.splice(p+t).join(" ");b=b.replace(/^\s+/,"");b=b.split(/[\s\r]+/);this.data=new Float32Array(b)}}; +$3Dmol.VolumeData.prototype.ccp4=function(b){var c,d,p,t,A,y,z,f,h,l,m,w,e,G,g,s,u,x,q,N,I,D,C,B,F;b=new Int8Array(b);D=new Int32Array(b.buffer,0,56);var J=new Float32Array(b.buffer,0,56);d=new DataView(b.buffer);String.fromCharCode(d.getUint8(208),d.getUint8(209),d.getUint8(210),d.getUint8(211));c=[d.getUint8(212),d.getUint8(213)];if(17===c[0]&&17===c[1])for(c=b.byteLength,t=0;tc)self.atomData=b.atoms,self.volume=b.volume,self.ps=new ProteinSurface;else{var d=self.ps;d.initparm(b.expandedExtent,1==c?!1:!0,self.volume);d.fillvoxels(self.atomData,b.extendedAtoms);d.buildboundary();if(4===c||2===c)d.fastdistancemap(),d.boundingatom(!1),d.fillvoxelswaals(self.atomData,b.extendedAtoms);d.marchingcube(c);b=d.getFacesAndVertices(b.atomsToShow);self.postMessage(b)}}}.toString().replace(/(^.*?\{|\}$)/g, "");$3Dmol.workerString+="; var ProteinSurface="+$3Dmol.ProteinSurface.toString().replace(/\$3Dmol.MarchingCube./g,"MarchingCube.");$3Dmol.workerString+=",MarchingCube=("+$3Dmol.MarchingCubeInitializer.toString()+")();";$3Dmol.SurfaceWorker=window.URL.createObjectURL(new Blob([$3Dmol.workerString],{type:"text/javascript"}));$3Dmol.workerString=$3Dmol.workerString;$3Dmol.SurfaceWorker=$3Dmol.SurfaceWorker; diff --git a/release/3Dmol-nojquery-min.js b/release/3Dmol-nojquery-min.js index 8566c0aab..cc190426f 100644 --- a/release/3Dmol-nojquery-min.js +++ b/release/3Dmol-nojquery-min.js @@ -1,3 +1,17 @@ +!function(y,v){"object"==typeof exports&&"undefined"!=typeof module?v(exports):"function"==typeof define&&define.amd?define(["exports"],v):v(y.MMTF=y.MMTF||{})}(this,function(y){function v(b){function g(a){for(var b={},c=0;a>c;c++){var d=f();b[d]=f()}return b}function c(c){var d=b.subarray(a,a+c);return a+=c,d}function k(c){var d=b.subarray(a,a+c);a+=c;if(65535c;c++)b[c]=f();return b}function f(){var f,h,l,m=b[a];if(0===(128&m))return a++,m;if(128===(240&m))return h=15&m,a++,g(h);if(144===(240&m))return h=15&m,a++,d(h);if(160===(224&m))return h=31&m,a++,k(h);if(224===(224&m))return f=e.getInt8(a),a++,f;switch(m){case 192:return a++,null;case 194:return a++,!1;case 195:return a++,!0;case 196:return h=e.getUint8(a+1),a+=2,c(h);case 197:return h=e.getUint16(a+1),a+=3,c(h);case 198:return h=e.getUint32(a+1),a+=5,c(h); +case 199:return h=e.getUint8(a+1),l=e.getUint8(a+2),a+=3,[l,c(h)];case 200:return h=e.getUint16(a+1),l=e.getUint8(a+3),a+=4,[l,c(h)];case 201:return h=e.getUint32(a+1),l=e.getUint8(a+5),a+=6,[l,c(h)];case 202:return f=e.getFloat32(a+1),a+=5,f;case 203:return f=e.getFloat64(a+1),a+=9,f;case 204:return f=b[a+1],a+=2,f;case 205:return f=e.getUint16(a+1),a+=3,f;case 206:return f=e.getUint32(a+1),a+=5,f;case 207:return a+=9,0;case 208:return f=e.getInt8(a+1),a+=2,f;case 209:return f=e.getInt16(a+1),a+= +3,f;case 210:return f=e.getInt32(a+1),a+=5,f;case 211:return a+=9,0;case 212:return l=e.getUint8(a+1),a+=2,[l,c(1)];case 213:return l=e.getUint8(a+1),a+=2,[l,c(2)];case 214:return l=e.getUint8(a+1),a+=2,[l,c(4)];case 215:return l=e.getUint8(a+1),a+=2,[l,c(8)];case 216:return l=e.getUint8(a+1),a+=2,[l,c(16)];case 217:return h=e.getUint8(a+1),a+=2,k(h);case 218:return h=e.getUint16(a+1),a+=3,k(h);case 219:return h=e.getUint32(a+1),a+=5,k(h);case 220:return h=e.getUint16(a+1),a+=3,d(h);case 221:return h= +e.getUint32(a+1),a+=5,d(h);case 222:return h=e.getUint16(a+1),a+=3,g(h);case 223:return h=e.getUint32(a+1),a+=5,g(h)}throw Error("Unknown type 0x"+m.toString(16));}var a=0,e=new DataView(b.buffer);return f()}function A(b){return new Uint8Array(b.buffer,b.byteOffset,b.byteLength)}function H(b){return new Int8Array(b.buffer,b.byteOffset,b.byteLength)}function n(b,g){var c,k,d;d=(b.byteOffset,b.byteLength);g||(g=new Int32Array(d/4));k=c=0;for(d/=4;d>c;++c,k+=4)g[c]=b[k]<<24^b[k+1]<<16^b[k+2]<<8^b[k+ +3]<<0;return g}function w(b,g,c){var k=b.length;g=1/g;c||(c=new Float32Array(k));for(var d=0;k>d;++d)c[d]=b[d]*g;return c}function u(b,g){var c,k;if(!g){var d=0;c=0;for(k=b.length;k>c;c+=2)d+=b[c+1];g=new b.constructor(d)}c=d=0;for(k=b.length;k>c;c+=2)for(var f=b[c],a=b[c+1],e=0;a>e;++e)g[d]=f,d+=1;return g}function B(b){for(var g=1,c=b.length;c>g;++g)b[g]+=b[g-1];return b}function z(b,g,c,k){var d=b.length/4/2+g.length/2;k||(k=new Float32Array(d));d=new Int32Array(k.buffer,k.byteOffset,k.byteLength/ +4);b=n(b);var f=void 0,a,e,r;r=(g.byteOffset,g.byteLength);f||(f=new Int16Array(r/2));e=a=0;for(r/=2;r>a;++a,e+=2)f[a]=g[e]<<8^g[e+1]<<0;g=f;f=b.length/2+g.length;d||(d=new Int32Array(f));e=a=f=0;for(r=b.length;r>e;e+=2){var h=b[e+1];d[f]=b[e];0!==e&&(d[f]+=d[f-1]);for(var f=f+1,l=0;h>l;++l)d[f]=d[f-1]+g[a],f+=1,a+=1}return w(d,c,k)}function I(b,g,c){var k=c?new Int32Array(c.buffer,c.byteOffset,c.byteLength/4):void 0;b=u(n(b),k);return w(b,g,c)}function J(b,g){function c(a){return k?-1===k.indexOf(a): +!0}g=g||{};var k=g.ignoreFields,d=(b.numBonds||0,b.numAtoms||0),f=b.groupTypeList.length/4,a={numGroups:f,numChains:b.chainIdList.length/4,numModels:b.chainsPerModel.length};"mmtfVersion mmtfProducer unitCell spaceGroup structureId title depositionDate releaseDate experimentalMethods resolution rFree rWork bioAssemblyList entityList groupList numBonds numAtoms groupsPerChain chainsPerModel".split(" ").forEach(function(c){void 0!==b[c]&&(a[c]=b[c])});b.bondAtomList&&c("bondAtomList")&&(a.bondAtomList= +n(b.bondAtomList));b.bondOrderList&&c("bondOrderList")&&(a.bondOrderList=A(b.bondOrderList));a.xCoordList=z(b.xCoordBig,b.xCoordSmall,1E3);a.yCoordList=z(b.yCoordBig,b.yCoordSmall,1E3);a.zCoordList=z(b.zCoordBig,b.zCoordSmall,1E3);b.bFactorBig&&b.bFactorSmall&&c("bFactorList")&&(a.bFactorList=z(b.bFactorBig,b.bFactorSmall,100));b.atomIdList&&c("atomIdList")&&(a.atomIdList=B(u(n(b.atomIdList))));b.altLocList&&c("altLocList")&&(a.altLocList=u(n(b.altLocList),new Uint8Array(d)));b.occupancyList&&c("occupancyList")&& +(a.occupancyList=I(b.occupancyList,100));a.groupIdList=B(u(n(b.groupIdList)));a.groupTypeList=n(b.groupTypeList);b.secStructList&&c("secStructList")&&(a.secStructList=H(b.secStructList));b.insCodeList&&c("insCodeList")&&(a.insCodeList=u(n(b.insCodeList),new Uint8Array(f)));b.sequenceIndexList&&c("sequenceIndexList")&&(a.sequenceIndexList=B(u(n(b.sequenceIndexList))));a.chainIdList=A(b.chainIdList);return b.chainNameList&&c("chainNameList")&&(a.chainNameList=A(b.chainNameList)),a}function G(b){return String.fromCharCode.apply(null, +b).replace(/\0/g,"")}y.decode=function(b,g){b instanceof ArrayBuffer&&(b=new Uint8Array(b));var c;return c=b instanceof Uint8Array?v(b):b,J(c,g)};y.traverse=function(b,g){var c,k,d,f,a=g.onModel,e=g.onChain,r=g.onGroup,h=g.onAtom,l=g.onBond,m=0,s=0,t=0,p=0,n=b.chainNameList,u=b.secStructList,y=b.insCodeList,v=b.sequenceIndexList,z=b.bFactorList,A=b.altLocList,B=b.occupancyList,F=b.bondAtomList,w=b.bondOrderList;if(b.chainsPerModel.forEach(function(g){a&&a({chainCount:g,modelIndex:m});for(c=0;g>c;++c){var w= +b.groupsPerChain[s];if(e){var q=G(b.chainIdList.subarray(4*s,4*s+4)),C=null;n&&(C=G(n.subarray(4*s,4*s+4)));e({groupCount:w,chainIndex:s,modelIndex:m,chainId:q,chainName:C})}for(k=0;w>k;++k){q=b.groupList[b.groupTypeList[t]];C=q.atomNameList.length;if(r){var x=null;u&&(x=u[t]);var D=null;b.insCodeList&&(D=String.fromCharCode(y[t]));var E=null;v&&(E=v[t]);r({atomCount:C,groupIndex:t,chainIndex:s,modelIndex:m,groupId:b.groupIdList[t],groupType:b.groupTypeList[t],groupName:q.groupName,singleLetterCode:q.singleLetterCode, +chemCompType:q.chemCompType,secStruct:x,insCode:D,sequenceIndex:E})}if(l)for(x=q.bondAtomList,d=0,f=q.bondOrderList.length;f>d;++d)l({atomIndex1:p+x[2*d],atomIndex2:p+x[2*d+1],bondOrder:q.bondOrderList[d]});for(d=0;C>d;++d)h&&(x=null,z&&(x=z[p]),D=null,A&&(D=String.fromCharCode(A[p])),E=null,B&&(E=B[p]),h({atomIndex:p,groupIndex:t,chainIndex:s,modelIndex:m,atomId:b.atomIdList[p],element:q.elementList[d],atomName:q.atomNameList[d],atomCharge:q.atomChargeList[d],xCoord:b.xCoordList[p],yCoord:b.yCoordList[p], +zCoord:b.zCoordList[p],bFactor:x,altLoc:D,occupancy:E})),p+=1;t+=1}s+=1}m+=1}),l&&F)for(d=0,f=F.length;f>d;d+=2)l({atomIndex1:F[d],atomIndex2:F[d+1],bondOrder:w?w[d/2]:null})}}); (function(P){"object"===typeof exports&&"undefined"!==typeof module?module.exports=P():"function"===typeof define&&define.amd?define([],P):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).pako=P()})(function(){return function p(u,c,F){function x(g,m){if(!c[g]){if(!u[g]){var h="function"==typeof require&&require;if(!m&&h)return h(g,!0);if(f)return f(g,!0);h=Error("Cannot find module '"+g+"'");throw h.code="MODULE_NOT_FOUND",h;}h=c[g]={exports:{}}; u[g][0].call(h.exports,function(h){var f=u[g][1][h];return x(f?f:h)},h,h.exports,p,u,c,F)}return c[g].exports}for(var f="function"==typeof require&&require,h=0;hF.x?A:F.x,q=q>F.y?q:F.y,B=B>F.z?B:F.z,F.symmetries&&m))for(var g=0;gF.symmetries[g].x?A:F.symmetries[g].x,q=q>F.symmetries[g].y?q:F.symmetries[g].y,B=B>F.symmetries[g].z?B:F.symmetries[g].z}return[[d,p,y],[A,q,B],[f/t,w/t,h/t]]};$3Dmol.getAtomProperty=function(b,c){var d=null;b.properties&&"undefined"!=typeof b.properties[c]?d=b.properties[c]:"undefined"!=typeof b[c]&&(d=b[c]);return d}; -$3Dmol.getPropertyRange=function(b,c){for(var d=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,y=0,A=b.length;yp&&(p=q))}isFinite(d)||isFinite(p)?isFinite(d)?isFinite(p)||(p=d):d=p:d=p=0;return[d,p]};var $3Dmol=$3Dmol||{};$3Dmol.Math={clamp:function(b,c,d){return Math.min(Math.max(b,c),d)},degToRad:function(){var b=Math.PI/180;return function(c){return c*b}}()}; +$.ajaxTransport("+binary",function(b,c,d){if(window.FormData&&(b.dataType&&"binary"==b.dataType||b.data&&(window.ArrayBuffer&&b.data instanceof ArrayBuffer||window.Blob&&b.data instanceof Blob)))return{send:function(c,d){var A=new XMLHttpRequest,y=b.url,z=b.type,f=b.async||!0,h=b.responseType||"blob",l=b.data||null,m=b.username||null,w=b.password||null;A.addEventListener("load",function(){var c={};c[b.dataType]=A.response;d(A.status,A.statusText,c,A.getAllResponseHeaders())});A.open(z,y,f,m,w);for(var e in c)A.setRequestHeader(e, +c[e]);A.responseType=h;A.send(l)},abort:function(){d.abort()}}});$3Dmol.createViewer=function(b,c){"string"===$.type(b)&&(b=$("#"+b));if(b){c=c||{};try{return new $3Dmol.GLViewer(b,c)}catch(d){throw"error creating viewer: "+d;}}};$3Dmol.viewers={}; +$3Dmol.download=function(b,c,d,p){var t="",A="",y=c.addModel();if("mmtf:"===b.substr(0,5)){A=d&&d.pdbUri?d.pdbUri:"http://mmtf.rcsb.org/full/";b=b.substr(5).toUpperCase();var z;$.ajax({url:A+b+".mmtf",type:"GET",dataType:"binary",responseType:"arraybuffer",processData:!1}).done(function(b,h,l){y.addMolData(b,"mmtf");c.zoomTo();c.render();p&&p(y)}).fail(function(b,c){console.log(c)})}else{if("pdb:"===b.substr(0,4)){A=d&&d.pdbUri?d.pdbUri:"http://www.rcsb.org/pdb/files/";t=d&&d.format?d.format:"pdb"; +b=b.substr(4).toUpperCase();if(!b.match(/^[1-9][A-Za-z0-9]{3}$/)){alert("Wrong PDB ID");return}z=d&&d.format?A+b+"."+d.format:A+b+".pdb"}else if("cid:"==b.substr(0,4)){t="sdf";b=b.substr(4);if(!b.match(/^[0-9]+$/)){alert("Wrong Compound ID");return}z="http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/"+b+"/SDF?record_type=3d"}$.get(z,function(b){y.addMolData(b,t,d);c.zoomTo();c.render();p&&p(y)})}return y};$3Dmol.SurfaceType={VDW:1,MS:2,SAS:3,SES:4}; +$3Dmol.mergeGeos=function(b,c){var d=c.geometry;void 0!==d&&b.geometryGroups.push(d.geometryGroups[0])};$3Dmol.multiLineString=function(b){return b.toString().replace(/^[^\/]+\/\*!?/,"").replace(/\*\/[^\/]+$/,"")};$3Dmol.syncSurface=!1;if(0<=window.navigator.userAgent.indexOf("MSIE ")||0<=window.navigator.userAgent.indexOf("Trident/"))$3Dmol.syncSurface=!0; +$3Dmol.specStringToObject=function(b){if("object"===typeof b||"undefined"===typeof b||null==b)return b;b=b.replace(/%7E/,"~");var c=function(b){return $.isNumeric(b)?Math.floor(parseFloat(b))==parseInt(b)?parseFloat(b):0<=b.indexOf(".")?parseFloat(b):parseInt(b):"true"===b?!0:"false"===b?!1:b},d={};if("all"===b)return d;b=b.split(";");for(var p=0;pG.x?A:G.x,y=y>G.y?y:G.y,z=z>G.z?z:G.z,G.symmetries&&w))for(var g=0;gG.symmetries[g].x?A:G.symmetries[g].x,y=y>G.symmetries[g].y?y:G.symmetries[g].y,z=z>G.symmetries[g].z?z:G.symmetries[g].z}return[[d,p,t],[A,y,z],[f/m,h/m,l/m]]};$3Dmol.getAtomProperty=function(b,c){var d=null;b.properties&&"undefined"!=typeof b.properties[c]?d=b.properties[c]:"undefined"!=typeof b[c]&&(d=b[c]);return d}; +$3Dmol.getPropertyRange=function(b,c){for(var d=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,t=0,A=b.length;tp&&(p=y))}isFinite(d)||isFinite(p)?isFinite(d)?isFinite(p)||(p=d):d=p:d=p=0;return[d,p]};"function"===typeof define&&define.amd&&define("$3Dmol",$3Dmol);var $3Dmol=$3Dmol||{};$3Dmol.Math={clamp:function(b,c,d){return Math.min(Math.max(b,c),d)},degToRad:function(){var b=Math.PI/180;return function(c){return c*b}}()}; $3Dmol.Quaternion=function(b,c,d,p){this.x=b||0;this.y=c||0;this.z=d||0;this.w=void 0!==p?p:1}; $3Dmol.Quaternion.prototype={constructor:$3Dmol.Quaternion,set:function(b,c,d,p){this.x=b;this.y=c;this.z=d;this.w=p;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;this.w=b.w;return this},conjugate:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},inverse:function(){return this.conjugate().normalize()},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var b=this.length();0===b?(this.z=this.y=this.x=0,this.w=1): -(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},multiply:function(b){return this.multiplyQuaternions(this,b)},multiplyQuaternions:function(b,c){var d=b.x,p=b.y,y=b.z,A=b.w,q=c.x,B=c.y,f=c.z,w=c.w;this.x=d*w+A*q+p*f-y*B;this.y=p*w+A*B+y*q-d*f;this.z=y*w+A*f+d*B-p*q;this.w=A*w-d*q-p*B-y*f}};$3Dmol.Vector2=function(b,c){this.x=b||0;this.y=c||0}; +(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},multiply:function(b){return this.multiplyQuaternions(this,b)},multiplyQuaternions:function(b,c){var d=b.x,p=b.y,t=b.z,A=b.w,y=c.x,z=c.y,f=c.z,h=c.w;this.x=d*h+A*y+p*f-t*z;this.y=p*h+A*z+t*y-d*f;this.z=t*h+A*f+d*z-p*y;this.w=A*h-d*y-p*z-t*f}};$3Dmol.Vector2=function(b,c){this.x=b||0;this.y=c||0}; $3Dmol.Vector2.prototype={constructor:$3Dmol.Vector2,set:function(b,c){this.x=b;this.y=c;return this},subVectors:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;return this},copy:function(b){this.x=b.x;this.y=b.y;return this},clone:function(){return new $3Dmol.Vector2(this.x,this.y)}};$3Dmol.Vector3=function(b,c,d){this.x=b||0;this.y=c||0;this.z=d||0}; $3Dmol.Vector3.prototype={constructor:$3Dmol.Vector3,set:function(b,c,d){this.x=b;this.y=c;this.z=d;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;return this},add:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;return this},addVectors:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;this.z=b.z+c.z;return this},sub:function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z;return this},subVectors:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;this.z=b.z-c.z;return this},multiplyScalar:function(b){this.x*= b;this.y*=b;this.z*=b;return this},divideScalar:function(b){0!==b?(this.x/=b,this.y/=b,this.z/=b):this.z=this.y=this.x=0;return this},max:function(b){this.x=Math.max(this.x,b.x);this.y=Math.max(this.y,b.y);this.z=Math.max(this.z,b.z);return this},min:function(b){this.x=Math.min(this.x,b.x);this.y=Math.min(this.y,b.y);this.z=Math.min(this.z,b.z);return this},distanceTo:function(b){return Math.sqrt(this.distanceToSquared(b))},distanceToSquared:function(b){var c=this.x-b.x,d=this.y-b.y;b=this.z-b.z; -return c*c+d*d+b*b},applyMatrix4:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;this.x=b[0]*c+b[4]*d+b[8]*p+b[12];this.y=b[1]*c+b[5]*d+b[9]*p+b[13];this.z=b[2]*c+b[6]*d+b[10]*p+b[14];return this},applyProjection:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;var y=b[3]*c+b[7]*d+b[11]*p+b[15];this.x=(b[0]*c+b[4]*d+b[8]*p+b[12])/y;this.y=(b[1]*c+b[5]*d+b[9]*p+b[13])/y;this.z=(b[2]*c+b[6]*d+b[10]*p+b[14])/y;return this},applyQuaternion:function(b){var c=this.x,d=this.y,p=this.z,y=b.x, -A=b.y,q=b.z,B,f,w;B=2*(d*q-p*A);f=2*(p*y-c*q);w=2*(c*A-d*y);this.x=c+b.w*B+(f*q-w*A);this.y=d+b.w*f+(w*y-B*q);this.z=p+b.w*w+(B*A-f*y);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},normalize:function(){return this.divideScalar(this.length())},cross:function(b){var c=this.x,d=this.y, -p=this.z;this.x=d*b.z-p*b.y;this.y=p*b.x-c*b.z;this.z=c*b.y-d*b.x;return this},crossVectors:function(b,c){this.x=b.y*c.z-b.z*c.y;this.y=b.z*c.x-b.x*c.z;this.z=b.x*c.y-b.y*c.x;return this},getPositionFromMatrix:function(b){this.x=b.elements[12];this.y=b.elements[13];this.z=b.elements[14];return this},setEulerFromRotationMatrix:function(b,c){var d=b.elements,p=d[0],y=d[4],A=d[8],q=d[5],B=d[9],f=d[6],d=d[10];void 0===c||"XYZ"===c?(this.y=Math.asin($3Dmol.Math.clamp(A,-1,1)),.99999>Math.abs(A)?(this.x= -Math.atan2(-B,d),this.z=Math.atan2(-y,p)):(this.x=Math.atan2(f,q),this.z=0)):console.error("Error with vector's setEulerFromRotationMatrix: Unknown order: "+c);return this},rotateAboutVector:function(b,c){b.normalize();var d=Math.cos(c),p=Math.sin(c),y=this.clone().multiplyScalar(d),p=b.clone().cross(this).multiplyScalar(p),d=b.clone().multiplyScalar(b.clone().dot(this)).multiplyScalar(1-d),y=y.add(p).add(d);this.x=y.x;this.y=y.y;this.z=y.z;return this},clone:function(){return new $3Dmol.Vector3(this.x, -this.y,this.z)}};$3Dmol.Matrix3=function(b,c,d,p,y,A,q,B,f){this.elements=new Float32Array(9);this.set(void 0!==b?b:1,c||0,d||0,p||0,void 0!==y?y:1,A||0,q||0,B||0,void 0!==f?f:1)}; -$3Dmol.Matrix3.prototype={constructor:$3Dmol.Matrix3,set:function(b,c,d,p,y,A,q,B,f){var w=this.elements;w[0]=b;w[3]=c;w[6]=d;w[1]=p;w[4]=y;w[7]=A;w[2]=q;w[5]=B;w[8]=f;return this},identity:function(){this.set(1,0,0,0,1,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8])},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[3]*=b;c[6]*=b;c[1]*=b;c[4]*=b;c[7]*=b;c[2]*=b;c[5]*=b;c[8]*=b;return this},getInverse:function(b,c){var d=b.elements, +return c*c+d*d+b*b},applyMatrix4:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;this.x=b[0]*c+b[4]*d+b[8]*p+b[12];this.y=b[1]*c+b[5]*d+b[9]*p+b[13];this.z=b[2]*c+b[6]*d+b[10]*p+b[14];return this},applyProjection:function(b){var c=this.x,d=this.y,p=this.z;b=b.elements;var t=b[3]*c+b[7]*d+b[11]*p+b[15];this.x=(b[0]*c+b[4]*d+b[8]*p+b[12])/t;this.y=(b[1]*c+b[5]*d+b[9]*p+b[13])/t;this.z=(b[2]*c+b[6]*d+b[10]*p+b[14])/t;return this},applyQuaternion:function(b){var c=this.x,d=this.y,p=this.z,t=b.x, +A=b.y,y=b.z,z,f,h;z=2*(d*y-p*A);f=2*(p*t-c*y);h=2*(c*A-d*t);this.x=c+b.w*z+(f*y-h*A);this.y=d+b.w*f+(h*t-z*y);this.z=p+b.w*h+(z*A-f*t);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},normalize:function(){return this.divideScalar(this.length())},cross:function(b){var c=this.x,d=this.y, +p=this.z;this.x=d*b.z-p*b.y;this.y=p*b.x-c*b.z;this.z=c*b.y-d*b.x;return this},crossVectors:function(b,c){this.x=b.y*c.z-b.z*c.y;this.y=b.z*c.x-b.x*c.z;this.z=b.x*c.y-b.y*c.x;return this},getPositionFromMatrix:function(b){this.x=b.elements[12];this.y=b.elements[13];this.z=b.elements[14];return this},setEulerFromRotationMatrix:function(b,c){var d=b.elements,p=d[0],t=d[4],A=d[8],y=d[5],z=d[9],f=d[6],d=d[10];void 0===c||"XYZ"===c?(this.y=Math.asin($3Dmol.Math.clamp(A,-1,1)),.99999>Math.abs(A)?(this.x= +Math.atan2(-z,d),this.z=Math.atan2(-t,p)):(this.x=Math.atan2(f,y),this.z=0)):console.error("Error with vector's setEulerFromRotationMatrix: Unknown order: "+c);return this},rotateAboutVector:function(b,c){b.normalize();var d=Math.cos(c),p=Math.sin(c),t=this.clone().multiplyScalar(d),p=b.clone().cross(this).multiplyScalar(p),d=b.clone().multiplyScalar(b.clone().dot(this)).multiplyScalar(1-d),t=t.add(p).add(d);this.x=t.x;this.y=t.y;this.z=t.z;return this},clone:function(){return new $3Dmol.Vector3(this.x, +this.y,this.z)}};$3Dmol.Matrix3=function(b,c,d,p,t,A,y,z,f){this.elements=new Float32Array(9);this.set(void 0!==b?b:1,c||0,d||0,p||0,void 0!==t?t:1,A||0,y||0,z||0,void 0!==f?f:1)}; +$3Dmol.Matrix3.prototype={constructor:$3Dmol.Matrix3,set:function(b,c,d,p,t,A,y,z,f){var h=this.elements;h[0]=b;h[3]=c;h[6]=d;h[1]=p;h[4]=t;h[7]=A;h[2]=y;h[5]=z;h[8]=f;return this},identity:function(){this.set(1,0,0,0,1,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8])},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[3]*=b;c[6]*=b;c[1]*=b;c[4]*=b;c[7]*=b;c[2]*=b;c[5]*=b;c[8]*=b;return this},getInverse:function(b,c){var d=b.elements, p=this.elements;p[0]=d[10]*d[5]-d[6]*d[9];p[1]=-d[10]*d[1]+d[2]*d[9];p[2]=d[6]*d[1]-d[2]*d[5];p[3]=-d[10]*d[4]+d[6]*d[8];p[4]=d[10]*d[0]-d[2]*d[8];p[5]=-d[6]*d[0]+d[2]*d[4];p[6]=d[9]*d[4]-d[5]*d[8];p[7]=-d[9]*d[0]+d[1]*d[8];p[8]=d[5]*d[0]-d[1]*d[4];d=d[0]*p[0]+d[1]*p[3]+d[2]*p[6];if(0===d){if(c)throw Error("Matrix3.getInverse(): can't invert matrix, determinant is 0");console.warn("Matrix3.getInverse(): can't invert matrix, determinant is 0");this.identity();return this}this.multiplyScalar(1/d);return this}, getDeterminant:function(){var b=this.elements;return b[0]*b[4]*b[8]+b[1]*b[5]*b[6]+b[2]*b[3]*b[7]-b[2]*b[4]*b[6]-b[1]*b[3]*b[8]-b[0]*b[5]*b[7]},transpose:function(){var b,c=this.elements;b=c[1];c[1]=c[3];c[3]=b;b=c[2];c[2]=c[6];c[6]=b;b=c[5];c[5]=c[7];c[7]=b;return this},clone:function(){var b=this.elements;return new $3Dmol.Matrix3(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8])}}; -$3Dmol.Matrix4=function(b,c,d,p,y,A,q,B,f,w,h,t,m,e,F,g){var x=this.elements=new Float32Array(16);x[0]=void 0!==b?b:1;x[4]=c||0;x[8]=d||0;x[12]=p||0;x[1]=y||0;x[5]=void 0!==A?A:1;x[9]=q||0;x[13]=B||0;x[2]=f||0;x[6]=w||0;x[10]=void 0!==h?h:1;x[14]=t||0;x[3]=m||0;x[7]=e||0;x[11]=F||0;x[15]=void 0!==g?g:1}; -$3Dmol.Matrix4.prototype={constructor:$3Dmol.Matrix4,set:function(b,c,d,p,y,A,q,B,f,w,h,t,m,e,F,g){var x=this.elements;x[0]=b;x[4]=c;x[8]=d;x[12]=p;x[1]=y;x[5]=A;x[9]=q;x[13]=B;x[2]=f;x[6]=w;x[10]=h;x[14]=t;x[3]=m;x[7]=e;x[11]=F;x[15]=g;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15]);return this},matrix3FromTopLeft:function(){var b=this.elements; -return new $3Dmol.Matrix3(b[0],b[4],b[8],b[1],b[5],b[9],b[2],b[6],b[10])},setRotationFromEuler:function(b,c){var d=this.elements,p=b.x,y=b.y,A=b.z,q=Math.cos(p),p=Math.sin(p),B=Math.cos(y),y=Math.sin(y),f=Math.cos(A),A=Math.sin(A);if(void 0===c||"XYZ"===c){var w=q*f,h=q*A,t=p*f,m=p*A;d[0]=B*f;d[4]=-B*A;d[8]=y;d[1]=h+t*y;d[5]=w-m*y;d[9]=-p*B;d[2]=m-w*y;d[6]=t+h*y;d[10]=q*B}else console.error("Error with matrix4 setRotationFromEuler. Order: "+c);return this},setRotationFromQuaternion:function(b){var c= -this.elements,d=b.x,p=b.y,y=b.z,A=b.w,q=d+d,B=p+p,f=y+y;b=d*q;var w=d*B,d=d*f,h=p*B,p=p*f,y=y*f,q=A*q,B=A*B,A=A*f;c[0]=1-(h+y);c[4]=w-A;c[8]=d+B;c[1]=w+A;c[5]=1-(b+y);c[9]=p-q;c[2]=d-B;c[6]=p+q;c[10]=1-(b+h);return this},lookAt:function(){var b=new $3Dmol.Vector3,c=new $3Dmol.Vector3,d=new $3Dmol.Vector3;return function(p,y,A){var q=this.elements;d.subVectors(p,y).normalize();0===d.length()&&(d.z=1);b.crossVectors(A,d).normalize();0===b.length()&&(d.x+=1E-4,b.crossVectors(A,d).normalize());c.crossVectors(d, -b);q[0]=b.x;q[4]=c.x;q[8]=d.x;q[1]=b.y;q[5]=c.y;q[9]=d.y;q[2]=b.z;q[6]=c.z;q[10]=d.z;return this}}(),multiplyMatrices:function(b,c){var d=b.elements,p=c.elements,y=this.elements,A=d[0],q=d[4],B=d[8],f=d[12],w=d[1],h=d[5],t=d[9],m=d[13],e=d[2],F=d[6],g=d[10],x=d[14],u=d[3],s=d[7],l=d[11],d=d[15],E=p[0],M=p[4],C=p[8],G=p[12],z=p[1],H=p[5],L=p[9],N=p[13],J=p[2],I=p[6],K=p[10],O=p[14],Q=p[3],W=p[7],P=p[11],p=p[15];y[0]=A*E+q*z+B*J+f*Q;y[4]=A*M+q*H+B*I+f*W;y[8]=A*C+q*L+B*K+f*P;y[12]=A*G+q*N+B*O+f*p;y[1]= -w*E+h*z+t*J+m*Q;y[5]=w*M+h*H+t*I+m*W;y[9]=w*C+h*L+t*K+m*P;y[13]=w*G+h*N+t*O+m*p;y[2]=e*E+F*z+g*J+x*Q;y[6]=e*M+F*H+g*I+x*W;y[10]=e*C+F*L+g*K+x*P;y[14]=e*G+F*N+g*O+x*p;y[3]=u*E+s*z+l*J+d*Q;y[7]=u*M+s*H+l*I+d*W;y[11]=u*C+s*L+l*K+d*P;y[15]=u*G+s*N+l*O+d*p;return this},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[4]*=b;c[8]*=b;c[12]*=b;c[1]*=b;c[5]*=b;c[9]*=b;c[13]*=b;c[2]*=b;c[6]*=b;c[10]*=b;c[14]*=b;c[3]*=b;c[7]*=b;c[11]*=b;c[15]*=b;return this},transpose:function(){var b=this.elements,c; -c=b[1];b[1]=b[4];b[4]=c;c=b[2];b[2]=b[8];b[8]=c;c=b[6];b[6]=b[9];b[9]=c;c=b[3];b[3]=b[12];b[12]=c;c=b[7];b[7]=b[13];b[13]=c;c=b[11];b[11]=b[14];b[14]=c;return this},getPosition:function(){var b=new $3Dmol.Vector3;return function(){console.warn("DEPRECATED: Matrix4's .getPosition() has been removed. Use Vector3.getPositionFromMatrix( matrix ) instead.");var c=this.elements;return b.set(c[12],c[13],c[14])}}(),setPosition:function(b){var c=this.elements;c[12]=b.x;c[13]=b.y;c[14]=b.z;return this},getInverse:function(b, -c){var d=this.elements,p=b.elements,y=p[0],A=p[4],q=p[8],B=p[12],f=p[1],w=p[5],h=p[9],t=p[13],m=p[2],e=p[6],F=p[10],g=p[14],x=p[3],u=p[7],s=p[11],l=p[15];d[0]=h*g*u-t*F*u+t*e*s-w*g*s-h*e*l+w*F*l;d[4]=B*F*u-q*g*u-B*e*s+A*g*s+q*e*l-A*F*l;d[8]=q*t*u-B*h*u+B*w*s-A*t*s-q*w*l+A*h*l;d[12]=B*h*e-q*t*e-B*w*F+A*t*F+q*w*g-A*h*g;d[1]=t*F*x-h*g*x-t*m*s+f*g*s+h*m*l-f*F*l;d[5]=q*g*x-B*F*x+B*m*s-y*g*s-q*m*l+y*F*l;d[9]=B*h*x-q*t*x-B*f*s+y*t*s+q*f*l-y*h*l;d[13]=q*t*m-B*h*m+B*f*F-y*t*F-q*f*g+y*h*g;d[2]=w*g*x-t*e*x+ -t*m*u-f*g*u-w*m*l+f*e*l;d[6]=B*e*x-A*g*x-B*m*u+y*g*u+A*m*l-y*e*l;d[10]=A*t*x-B*w*x+B*f*u-y*t*u-A*f*l+y*w*l;d[14]=B*w*m-A*t*m-B*f*e+y*t*e+A*f*g-y*w*g;d[3]=h*e*x-w*F*x-h*m*u+f*F*u+w*m*s-f*e*s;d[7]=A*F*x-q*e*x+q*m*u-y*F*u-A*m*s+y*e*s;d[11]=q*w*x-A*h*x-q*f*u+y*h*u+A*f*s-y*w*s;d[15]=A*h*m-q*w*m+q*f*e-y*h*e-A*f*F+y*w*F;d=p[0]*d[0]+p[1]*d[4]+p[2]*d[8]+p[3]*d[12];if(0===d){if(c)throw Error("Matrix4.getInverse(): can't invert matrix, determinant is 0");console.warn("Matrix4.getInverse(): can't invert matrix, determinant is 0"); -this.identity();return this}this.multiplyScalar(1/d);return this},isReflected:function(){return 0>this.matrix3FromTopLeft().getDeterminant()},compose:function(){var b=new $3Dmol.Matrix4,c=new $3Dmol.Matrix4;return function(d,p,y){var A=this.elements;b.identity();b.setRotationFromQuaternion(p);c.makeScale(y.x,y.y,y.z);this.multiplyMatrices(b,c);A[12]=d.x;A[13]=d.y;A[14]=d.z;return this}}(),decompose:function(){var b=new $3Dmol.Vector3,c=new $3Dmol.Vector3,d=new $3Dmol.Vector3,p=new $3Dmol.Matrix4; -return function(y,A,q){var B=this.elements;b.set(B[0],B[1],B[2]);c.set(B[4],B[5],B[6]);d.set(B[8],B[9],B[10]);y=y instanceof $3Dmol.Vector3?y:new $3Dmol.Vector3;A=A instanceof $3Dmol.Quaternion?A:new $3Dmol.Quaternion;q=q instanceof $3Dmol.Vector3?q:new $3Dmol.Vector3;q.x=b.length();q.y=c.length();q.z=d.length();y.x=B[12];y.y=B[13];y.z=B[14];p.copy(this);p.elements[0]/=q.x;p.elements[1]/=q.x;p.elements[2]/=q.x;p.elements[4]/=q.y;p.elements[5]/=q.y;p.elements[6]/=q.y;p.elements[8]/=q.z;p.elements[9]/= -q.z;p.elements[10]/=q.z;A.setFromRotationMatrix(p);return[y,A,q]}}(),scale:function(b){var c=this.elements,d=b.x,p=b.y;b=b.z;c[0]*=d;c[4]*=p;c[8]*=b;c[1]*=d;c[5]*=p;c[9]*=b;c[2]*=d;c[6]*=p;c[10]*=b;c[3]*=d;c[7]*=p;c[11]*=b;return this},getMaxScaleOnAxis:function(){var b=this.elements;return Math.sqrt(Math.max(b[0]*b[0]+b[1]*b[1]+b[2]*b[2],Math.max(b[4]*b[4]+b[5]*b[5]+b[6]*b[6],b[8]*b[8]+b[9]*b[9]+b[10]*b[10])))},makeFrustum:function(b,c,d,p,y,A){var q=this.elements;q[0]=2*y/(c-b);q[4]=0;q[8]=(c+b)/ -(c-b);q[12]=0;q[1]=0;q[5]=2*y/(p-d);q[9]=(p+d)/(p-d);q[13]=0;q[2]=0;q[6]=0;q[10]=-(A+y)/(A-y);q[14]=-2*A*y/(A-y);q[3]=0;q[7]=0;q[11]=-1;q[15]=0;return this},makePerspective:function(b,c,d,p){b=d*Math.tan($3Dmol.Math.degToRad(.5*b));var y=-b;return this.makeFrustum(y*c,b*c,y,b,d,p)},isEqual:function(b){b=b.elements;var c=this.elements;return c[0]==b[0]&&c[4]==b[4]&&c[8]==b[8]&&c[12]==b[12]&&c[1]==b[1]&&c[5]==b[5]&&c[9]==b[9]&&c[13]==b[13]&&c[2]==b[2]&&c[6]==b[6]&&c[10]==b[10]&&c[14]==b[14]&&c[3]== -b[3]&&c[7]==b[7]&&c[11]==b[11]&&c[15]==b[15]?!0:!1},clone:function(){var b=this.elements;return new $3Dmol.Matrix4(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15])},isIdentity:function(){var b=this.elements;return 1==b[0]&&0==b[4]&&0==b[8]&&0==b[12]&&0==b[1]&&1==b[5]&&0==b[9]&&0==b[13]&&0==b[2]&&0==b[6]&&1==b[10]&&0==b[14]&&0==b[3]&&0==b[7]&&0==b[11]&&1==b[15]?!0:!1}}; -$3Dmol.Ray=function(b,c){this.origin=void 0!==b?b:new $3Dmol.Vector3;this.direction=void 0!==c?c:new $3Dmol.Vector3}; +$3Dmol.Matrix4=function(b,c,d,p,t,A,y,z,f,h,l,m,w,e,G,g){if("undefined"===typeof c&&"undefined"!==typeof b)this.elements=new Float32Array(b);else{var s=this.elements=new Float32Array(16);s[0]=void 0!==b?b:1;s[4]=c||0;s[8]=d||0;s[12]=p||0;s[1]=t||0;s[5]=void 0!==A?A:1;s[9]=y||0;s[13]=z||0;s[2]=f||0;s[6]=h||0;s[10]=void 0!==l?l:1;s[14]=m||0;s[3]=w||0;s[7]=e||0;s[11]=G||0;s[15]=void 0!==g?g:1}}; +$3Dmol.Matrix4.prototype={constructor:$3Dmol.Matrix4,set:function(b,c,d,p,t,A,y,z,f,h,l,m,w,e,G,g){var s=this.elements;s[0]=b;s[4]=c;s[8]=d;s[12]=p;s[1]=t;s[5]=A;s[9]=y;s[13]=z;s[2]=f;s[6]=h;s[10]=l;s[14]=m;s[3]=w;s[7]=e;s[11]=G;s[15]=g;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(b){b=b.elements;this.set(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15]);return this},matrix3FromTopLeft:function(){var b=this.elements; +return new $3Dmol.Matrix3(b[0],b[4],b[8],b[1],b[5],b[9],b[2],b[6],b[10])},setRotationFromEuler:function(b,c){var d=this.elements,p=b.x,t=b.y,A=b.z,y=Math.cos(p),p=Math.sin(p),z=Math.cos(t),t=Math.sin(t),f=Math.cos(A),A=Math.sin(A);if(void 0===c||"XYZ"===c){var h=y*f,l=y*A,m=p*f,w=p*A;d[0]=z*f;d[4]=-z*A;d[8]=t;d[1]=l+m*t;d[5]=h-w*t;d[9]=-p*z;d[2]=w-h*t;d[6]=m+l*t;d[10]=y*z}else console.error("Error with matrix4 setRotationFromEuler. Order: "+c);return this},setRotationFromQuaternion:function(b){var c= +this.elements,d=b.x,p=b.y,t=b.z,A=b.w,y=d+d,z=p+p,f=t+t;b=d*y;var h=d*z,d=d*f,l=p*z,p=p*f,t=t*f,y=A*y,z=A*z,A=A*f;c[0]=1-(l+t);c[4]=h-A;c[8]=d+z;c[1]=h+A;c[5]=1-(b+t);c[9]=p-y;c[2]=d-z;c[6]=p+y;c[10]=1-(b+l);return this},lookAt:function(){var b=new $3Dmol.Vector3,c=new $3Dmol.Vector3,d=new $3Dmol.Vector3;return function(p,t,A){var y=this.elements;d.subVectors(p,t).normalize();0===d.length()&&(d.z=1);b.crossVectors(A,d).normalize();0===b.length()&&(d.x+=1E-4,b.crossVectors(A,d).normalize());c.crossVectors(d, +b);y[0]=b.x;y[4]=c.x;y[8]=d.x;y[1]=b.y;y[5]=c.y;y[9]=d.y;y[2]=b.z;y[6]=c.z;y[10]=d.z;return this}}(),multiplyMatrices:function(b,c){var d=b.elements,p=c.elements,t=this.elements,A=d[0],y=d[4],z=d[8],f=d[12],h=d[1],l=d[5],m=d[9],w=d[13],e=d[2],G=d[6],g=d[10],s=d[14],u=d[3],x=d[7],q=d[11],d=d[15],N=p[0],I=p[4],D=p[8],C=p[12],B=p[1],F=p[5],J=p[9],L=p[13],K=p[2],H=p[6],M=p[10],O=p[14],R=p[3],V=p[7],P=p[11],p=p[15];t[0]=A*N+y*B+z*K+f*R;t[4]=A*I+y*F+z*H+f*V;t[8]=A*D+y*J+z*M+f*P;t[12]=A*C+y*L+z*O+f*p;t[1]= +h*N+l*B+m*K+w*R;t[5]=h*I+l*F+m*H+w*V;t[9]=h*D+l*J+m*M+w*P;t[13]=h*C+l*L+m*O+w*p;t[2]=e*N+G*B+g*K+s*R;t[6]=e*I+G*F+g*H+s*V;t[10]=e*D+G*J+g*M+s*P;t[14]=e*C+G*L+g*O+s*p;t[3]=u*N+x*B+q*K+d*R;t[7]=u*I+x*F+q*H+d*V;t[11]=u*D+x*J+q*M+d*P;t[15]=u*C+x*L+q*O+d*p;return this},multiplyScalar:function(b){var c=this.elements;c[0]*=b;c[4]*=b;c[8]*=b;c[12]*=b;c[1]*=b;c[5]*=b;c[9]*=b;c[13]*=b;c[2]*=b;c[6]*=b;c[10]*=b;c[14]*=b;c[3]*=b;c[7]*=b;c[11]*=b;c[15]*=b;return this},makeTranslation:function(b,c,d){this.set(1, +0,0,b,0,1,0,c,0,0,1,d,0,0,0,1);return this},transpose:function(){var b=this.elements,c;c=b[1];b[1]=b[4];b[4]=c;c=b[2];b[2]=b[8];b[8]=c;c=b[6];b[6]=b[9];b[9]=c;c=b[3];b[3]=b[12];b[12]=c;c=b[7];b[7]=b[13];b[13]=c;c=b[11];b[11]=b[14];b[14]=c;return this},getPosition:function(){var b=new $3Dmol.Vector3;return function(){console.warn("DEPRECATED: Matrix4's .getPosition() has been removed. Use Vector3.getPositionFromMatrix( matrix ) instead.");var c=this.elements;return b.set(c[12],c[13],c[14])}}(),setPosition:function(b){var c= +this.elements;c[12]=b.x;c[13]=b.y;c[14]=b.z;return this},getInverse:function(b,c){var d=this.elements,p=b.elements,t=p[0],A=p[4],y=p[8],z=p[12],f=p[1],h=p[5],l=p[9],m=p[13],w=p[2],e=p[6],G=p[10],g=p[14],s=p[3],u=p[7],x=p[11],q=p[15];d[0]=l*g*u-m*G*u+m*e*x-h*g*x-l*e*q+h*G*q;d[4]=z*G*u-y*g*u-z*e*x+A*g*x+y*e*q-A*G*q;d[8]=y*m*u-z*l*u+z*h*x-A*m*x-y*h*q+A*l*q;d[12]=z*l*e-y*m*e-z*h*G+A*m*G+y*h*g-A*l*g;d[1]=m*G*s-l*g*s-m*w*x+f*g*x+l*w*q-f*G*q;d[5]=y*g*s-z*G*s+z*w*x-t*g*x-y*w*q+t*G*q;d[9]=z*l*s-y*m*s-z*f* +x+t*m*x+y*f*q-t*l*q;d[13]=y*m*w-z*l*w+z*f*G-t*m*G-y*f*g+t*l*g;d[2]=h*g*s-m*e*s+m*w*u-f*g*u-h*w*q+f*e*q;d[6]=z*e*s-A*g*s-z*w*u+t*g*u+A*w*q-t*e*q;d[10]=A*m*s-z*h*s+z*f*u-t*m*u-A*f*q+t*h*q;d[14]=z*h*w-A*m*w-z*f*e+t*m*e+A*f*g-t*h*g;d[3]=l*e*s-h*G*s-l*w*u+f*G*u+h*w*x-f*e*x;d[7]=A*G*s-y*e*s+y*w*u-t*G*u-A*w*x+t*e*x;d[11]=y*h*s-A*l*s-y*f*u+t*l*u+A*f*x-t*h*x;d[15]=A*l*w-y*h*w+y*f*e-t*l*e-A*f*G+t*h*G;d=p[0]*d[0]+p[1]*d[4]+p[2]*d[8]+p[3]*d[12];if(0===d){if(c)throw Error("Matrix4.getInverse(): can't invert matrix, determinant is 0"); +console.warn("Matrix4.getInverse(): can't invert matrix, determinant is 0");this.identity();return this}this.multiplyScalar(1/d);return this},isReflected:function(){return 0>this.matrix3FromTopLeft().getDeterminant()},compose:function(){var b=new $3Dmol.Matrix4,c=new $3Dmol.Matrix4;return function(d,p,t){var A=this.elements;b.identity();b.setRotationFromQuaternion(p);c.makeScale(t.x,t.y,t.z);this.multiplyMatrices(b,c);A[12]=d.x;A[13]=d.y;A[14]=d.z;return this}}(),decompose:function(){var b=new $3Dmol.Vector3, +c=new $3Dmol.Vector3,d=new $3Dmol.Vector3,p=new $3Dmol.Matrix4;return function(t,A,y){var z=this.elements;b.set(z[0],z[1],z[2]);c.set(z[4],z[5],z[6]);d.set(z[8],z[9],z[10]);t=t instanceof $3Dmol.Vector3?t:new $3Dmol.Vector3;A=A instanceof $3Dmol.Quaternion?A:new $3Dmol.Quaternion;y=y instanceof $3Dmol.Vector3?y:new $3Dmol.Vector3;y.x=b.length();y.y=c.length();y.z=d.length();t.x=z[12];t.y=z[13];t.z=z[14];p.copy(this);p.elements[0]/=y.x;p.elements[1]/=y.x;p.elements[2]/=y.x;p.elements[4]/=y.y;p.elements[5]/= +y.y;p.elements[6]/=y.y;p.elements[8]/=y.z;p.elements[9]/=y.z;p.elements[10]/=y.z;A.setFromRotationMatrix(p);return[t,A,y]}}(),scale:function(b){var c=this.elements,d=b.x,p=b.y;b=b.z;c[0]*=d;c[4]*=p;c[8]*=b;c[1]*=d;c[5]*=p;c[9]*=b;c[2]*=d;c[6]*=p;c[10]*=b;c[3]*=d;c[7]*=p;c[11]*=b;return this},getMaxScaleOnAxis:function(){var b=this.elements;return Math.sqrt(Math.max(b[0]*b[0]+b[1]*b[1]+b[2]*b[2],Math.max(b[4]*b[4]+b[5]*b[5]+b[6]*b[6],b[8]*b[8]+b[9]*b[9]+b[10]*b[10])))},makeFrustum:function(b,c,d,p, +t,A){var y=this.elements;y[0]=2*t/(c-b);y[4]=0;y[8]=(c+b)/(c-b);y[12]=0;y[1]=0;y[5]=2*t/(p-d);y[9]=(p+d)/(p-d);y[13]=0;y[2]=0;y[6]=0;y[10]=-(A+t)/(A-t);y[14]=-2*A*t/(A-t);y[3]=0;y[7]=0;y[11]=-1;y[15]=0;return this},makePerspective:function(b,c,d,p){b=d*Math.tan($3Dmol.Math.degToRad(.5*b));var t=-b;return this.makeFrustum(t*c,b*c,t,b,d,p)},makeOrthographic:function(b,c,d,p,t,A){var y=this.elements,z=1/(c-b),f=1/(d-p),h=1/(A-t);y[0]=2*z;y[4]=0;y[8]=0;y[12]=-((c+b)*z);y[1]=0;y[5]=2*f;y[9]=0;y[13]=-((d+ +p)*f);y[2]=0;y[6]=0;y[10]=-2*h;y[14]=-((A+t)*h);y[3]=0;y[7]=0;y[11]=0;y[15]=1;return this},isEqual:function(b){b=b.elements;var c=this.elements;return c[0]==b[0]&&c[4]==b[4]&&c[8]==b[8]&&c[12]==b[12]&&c[1]==b[1]&&c[5]==b[5]&&c[9]==b[9]&&c[13]==b[13]&&c[2]==b[2]&&c[6]==b[6]&&c[10]==b[10]&&c[14]==b[14]&&c[3]==b[3]&&c[7]==b[7]&&c[11]==b[11]&&c[15]==b[15]?!0:!1},clone:function(){var b=this.elements;return new $3Dmol.Matrix4(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11], +b[15])},isIdentity:function(){var b=this.elements;return 1==b[0]&&0==b[4]&&0==b[8]&&0==b[12]&&0==b[1]&&1==b[5]&&0==b[9]&&0==b[13]&&0==b[2]&&0==b[6]&&1==b[10]&&0==b[14]&&0==b[3]&&0==b[7]&&0==b[11]&&1==b[15]?!0:!1}};$3Dmol.Ray=function(b,c){this.origin=void 0!==b?b:new $3Dmol.Vector3;this.direction=void 0!==c?c:new $3Dmol.Vector3}; $3Dmol.Ray.prototype={constructor:$3Dmol.Ray,set:function(b,c){this.origin.copy(b);this.direction.copy(c);return this},copy:function(b){this.origin.copy(b.origin);this.direction.copy(b.direction);return this},at:function(b,c){return(c||new $3Dmol.Vector3).copy(this.direction).multiplyScalar(b).add(this.origin)},recast:function(){var b=new $3Dmol.Vector3;return function(c){this.origin.copy(this.at(c,b));return this}}(),closestPointToPoint:function(b,c){var d=c||new $3Dmol.Vector3;d.subVectors(b,this.origin); var p=d.dot(this.direction);return d.copy(this.direction).multiplyScalar(p).add(this.origin)},distanceToPoint:function(b){var c=new $3Dmol.Vector3;return function(b){var p=c.subVectors(b,this.origin).dot(this.direction);c.copy(this.direction).multiplyScalar(p).add(this.origin);return c.distanceTo(b)}}(),isIntersectionCylinder:function(){},isIntersectionSphere:function(b){return this.distanceToPoint(b.center)<=b.radius},isIntersectionPlane:function(b){return 0!==b.normal.dot(this.direction)||0===b.distanceToPoint(this.origin)? !0:!1},distanceToPlane:function(b){var c=b.normal.dot(this.direction);if(0===c){if(0===b.distanceToPoint(this.origin))return 0}else return-(this.origin.dot(b.normal)+b.constant)/c},intersectPlane:function(b,c){var d=this.distanceToPlane(b);return void 0===d?void 0:this.at(d,c)},applyMatrix4:function(b){this.direction.add(this.origin).applyMatrix4(b);this.origin.applyMatrix4(b);this.direction.sub(this.origin);return this},equals:function(b){return b.origin.equals(this.origin)&&b.direction.equals(this.direction)}, @@ -89,7 +105,7 @@ $3Dmol.Cylinder=function(b,c,d){this.c1=void 0!==b?b:new $3Dmol.Vector3;this.c2= $3Dmol.Cylinder.prototype={constructor:$3Dmol.Cylinder,copy:function(b){this.c1.copy(b.c1);this.c2.copy(b.c2);this.direction.copy(b.direction);this.radius=b.radius;return this},lengthSq:function(){var b=new $3Dmol.Vector3;return function(){return b.subVectors(this.c2,this.c1).lengthSq()}}(),applyMatrix4:function(b){this.direction.add(this.c1).applyMatrix4(b);this.c1.applyMatrix4(b);this.c2.applyMatrix4(b);this.direction.sub(this.c1).normalize();this.radius*=b.getMaxScaleOnAxis();return this}}; $3Dmol.Triangle=function(b,c,d){this.a=void 0!==b?b:new $3Dmol.Vector3;this.b=void 0!==c?c:new $3Dmol.Vector3;this.c=void 0!==d?d:new $3Dmol.Vector3}; $3Dmol.Triangle.prototype={constructor:$3Dmol.Triangle,copy:function(b){this.a.copy(b.a);this.b.copy(b.b);this.c.copy(b.c);return this},applyMatrix4:function(b){this.a.applyMatrix4(b);this.b.applyMatrix4(b);this.c.applyMatrix4(b);return this},getNormal:function(){var b=new $3Dmol.Vector3;return function(){var c=this.a.clone();c.sub(this.b);b.subVectors(this.c,this.b);c.cross(b);c.normalize();return c}}()}; -$3Dmol.EventDispatcher=function(){var b={};this.addEventListener=function(c,d){void 0===b[c]&&(b[c]=[]);-1===b[c].indexOf(d)&&b[c].push(d)};this.removeEventListener=function(c,d){var p=b[c].indexOf(d);-1!==p&&b[c].splice(p,1)};this.dispatchEvent=function(c){var d=b[c.type];if(void 0!==d){c.target=this;for(var p=0,y=d.length;p>16&255)/255;this.g=(b>>8&255)/255;this.b=(b&255)/255;return this},getHex:function(){var b=Math.round(255*this.r),c=Math.round(255*this.g),d=Math.round(255*this.b);return b<<16|c<<8|d},clone:function(){return new $3Dmol.Color(this.r, this.g,this.b)},copy:function(b){this.r=b.r;this.g=b.g;this.b=b.b;return this},scaled:function(){var b={};b.r=Math.round(255*this.r);b.g=Math.round(255*this.g);b.b=Math.round(255*this.b);b.a=1;return b}}; $3Dmol.Object3D=function(){this.id=$3Dmol.Object3DIDCount++;this.name="";this.parent=void 0;this.children=[];this.position=new $3Dmol.Vector3;this.rotation=new $3Dmol.Vector3;this.matrix=new $3Dmol.Matrix4;this.matrixWorld=new $3Dmol.Matrix4;this.quaternion=new $3Dmol.Quaternion;this.eulerOrder="XYZ";this.up=new $3Dmol.Vector3(0,1,0);this.scale=new $3Dmol.Vector3(1,1,1);this.rotationAutoUpdate=this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.useQuaternion=!1;this.visible=!0}; @@ -98,32 +114,33 @@ remove:function(b){var c=this.children.indexOf(b);if(-1!==c){b.parent=void 0;thi !0},updateMatrixWorld:function(b){!0===this.matrixAutoUpdate&&this.updateMatrix();if(!0===this.matrixWorldNeedsUpdate||!0===b)void 0===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix);this.matrixWorldNeedsUpdate=!1;for(b=0;bd.vertexArray.length/3)d=c(this);return d},addGeoGroup:function(){return c(this)},setUpNormals:function(b){b=b||!1;for(var c=0;cL||(A.copy(this.ray.direction).multiplyScalar(L).add(this.ray.origin),A.sub(p.a),q.copy(p.b).sub(p.a),B.copy(p.c).sub(p.a),z=q.dot(B), -G=q.lengthSq(),H=B.lengthSq(),H=(G*A.dot(B)-z*A.dot(q))/(G*H-z*z),0>H||1z||1=I?L=Math.sqrt(N):L=(H-z*G-Math.sqrt(I))/J,z=z*H-G,0>z||z*z>d.lengthSq()||0>H||s.push({clickable:u,distance:L}))));M=0;for(C=l.line.length;Mx)break a; -L=0>=I?x:x-Math.sqrt(I);s.push({clickable:u,distance:L});break a}}}e.sort(w);return e};return b}();$3Dmol.Projector=function(){new $3Dmol.Matrix4;var b=new $3Dmol.Matrix4;this.projectVector=function(c,d){d.matrixWorldInverse.getInverse(d.matrixWorld);b.multiplyMatrices(d.projectionMatrix,d.matrixWorldInverse);return c.applyProjection(b)};this.unprojectVector=function(c,d){d.projectionMatrixInverse.getInverse(d.projectionMatrix);b.multiplyMatrices(d.matrixWorld,d.projectionMatrixInverse);return c.applyProjection(b)}}; -$3Dmol.Camera=function(b,c,d,p){$3Dmol.Object3D.call(this);this.fov=void 0!==b?b:50;this.aspect=void 0!==c?c:1;this.near=void 0!==d?d:.1;this.far=void 0!==p?p:2E3;this.projectionMatrix=new $3Dmol.Matrix4;this.projectionMatrixInverse=new $3Dmol.Matrix4;this.matrixWorldInverse=new $3Dmol.Matrix4;this.updateProjectionMatrix()};$3Dmol.Camera.prototype=Object.create($3Dmol.Object3D.prototype); -$3Dmol.Camera.prototype.lookAt=function(b){this.matrix.lookAt(this.position,b,this.up);this.rotationAutoUpdate&&(!1===this.useQuaternion?this.rotation.setEulerFromRotationMatrix(this.matrix,this.eulerOrder):this.quaternion.copy(this.matrix.decompose()[1]))};$3Dmol.Camera.prototype.updateProjectionMatrix=function(){this.projectionMatrix.makePerspective(this.fov,this.aspect,this.near,this.far);this.projectionMatrixInverse.getInverse(this.projectionMatrix)}; -$3Dmol.SpritePlugin=function(){function b(b,c){return b.z!==c.z?c.z-b.z:c.id-b.id}var c,d,p,y,A,q,B,f,w,h;this.init=function(b){c=b.context;d=b;p=b.getPrecision();y=new Float32Array(16);A=new Uint16Array(6);b=0;y[b++]=-1;y[b++]=-1;y[b++]=0;y[b++]=0;y[b++]=1;y[b++]=-1;y[b++]=1;y[b++]=0;y[b++]=1;y[b++]=1;y[b++]=1;y[b++]=1;y[b++]=-1;y[b++]=1;y[b++]=0;y[b++]=1;b=0;A[b++]=0;A[b++]=1;A[b++]=2;A[b++]=0;A[b++]=2;A[b++]=3;q=c.createBuffer();B=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,q);c.bufferData(c.ARRAY_BUFFER, -y,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,B);c.bufferData(c.ELEMENT_ARRAY_BUFFER,A,c.STATIC_DRAW);b=$3Dmol.ShaderLib.sprite;var m=p,e=c.createProgram(),F=c.createShader(c.FRAGMENT_SHADER),g=c.createShader(c.VERTEX_SHADER),m="precision "+m+" float;\n";c.shaderSource(F,m+b.fragmentShader);c.shaderSource(g,m+b.vertexShader);c.compileShader(F);c.compileShader(g);c.getShaderParameter(F,c.COMPILE_STATUS)&&c.getShaderParameter(g,c.COMPILE_STATUS)?(c.attachShader(e,F),c.attachShader(e,g),c.linkProgram(e), -c.getProgramParameter(e,c.LINK_STATUS)||console.error("Could not initialize shader"),b=e):(console.error(c.getShaderInfoLog(F)),console.error("could not initialize shader"),b=null);f=b;w={};h={};w.position=c.getAttribLocation(f,"position");w.uv=c.getAttribLocation(f,"uv");h.uvOffset=c.getUniformLocation(f,"uvOffset");h.uvScale=c.getUniformLocation(f,"uvScale");h.rotation=c.getUniformLocation(f,"rotation");h.scale=c.getUniformLocation(f,"scale");h.alignment=c.getUniformLocation(f,"alignment");h.color= -c.getUniformLocation(f,"color");h.map=c.getUniformLocation(f,"map");h.opacity=c.getUniformLocation(f,"opacity");h.useScreenCoordinates=c.getUniformLocation(f,"useScreenCoordinates");h.screenPosition=c.getUniformLocation(f,"screenPosition");h.modelViewMatrix=c.getUniformLocation(f,"modelViewMatrix");h.projectionMatrix=c.getUniformLocation(f,"projectionMatrix");h.fogType=c.getUniformLocation(f,"fogType");h.fogDensity=c.getUniformLocation(f,"fogDensity");h.fogNear=c.getUniformLocation(f,"fogNear");h.fogFar= -c.getUniformLocation(f,"fogFar");h.fogColor=c.getUniformLocation(f,"fogColor");h.alphaTest=c.getUniformLocation(f,"alphaTest")};this.render=function(t,m,e,F){var g=t.__webglSprites,x=g.length;if(x){var u=w,s=h,l=.5*e,E=.5*F;c.useProgram(f);c.enableVertexAttribArray(u.position);c.enableVertexAttribArray(u.uv);c.disable(c.CULL_FACE);c.enable(c.BLEND);c.bindBuffer(c.ARRAY_BUFFER,q);c.vertexAttribPointer(u.position,2,c.FLOAT,!1,16,0);c.vertexAttribPointer(u.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, -B);c.uniformMatrix4fv(s.projectionMatrix,!1,m.projectionMatrix.elements);c.activeTexture(c.TEXTURE0);c.uniform1i(s.map,0);var p=u=0;(u=t.fog)?(c.uniform3f(s.fogColor,u.color.r,u.color.g,u.color.b),c.uniform1f(s.fogNear,u.near),c.uniform1f(s.fogFar,u.far),c.uniform1i(s.fogType,1),p=u=1):(c.uniform1i(s.fogType,0),p=u=0);var C,y,z,H=[];for(C=0;CJ||(A.copy(this.ray.direction).multiplyScalar(J).add(this.ray.origin),A.sub(p.a),y.copy(p.b).sub(p.a),z.copy(p.c).sub(p.a),B=y.dot(z), +C=y.lengthSq(),F=z.lengthSq(),F=(C*A.dot(z)-B*A.dot(y))/(C*F-B*B),0>F||1B||1=H?J=Math.sqrt(L):J=(F-B*C-Math.sqrt(H))/K,B=B*F-C,0>B||B*B>d.lengthSq()||0>F||x.push({clickable:u,distance:J}))));I=0;for(D=q.line.length;Is)break a; +J=0>=H?s:s-Math.sqrt(H);x.push({clickable:u,distance:J});break a}}}e.sort(h);return e};return b}();$3Dmol.Projector=function(){new $3Dmol.Matrix4;var b=new $3Dmol.Matrix4;this.projectVector=function(c,d){d.matrixWorldInverse.getInverse(d.matrixWorld);b.multiplyMatrices(d.projectionMatrix,d.matrixWorldInverse);return c.applyProjection(b)};this.unprojectVector=function(c,d){d.projectionMatrixInverse.getInverse(d.projectionMatrix);b.multiplyMatrices(d.matrixWorld,d.projectionMatrixInverse);return c.applyProjection(b)}}; +$3Dmol.Camera=function(b,c,d,p,t){$3Dmol.Object3D.call(this);this.fov=void 0!==b?b:50;this.aspect=void 0!==c?c:1;this.near=void 0!==d?d:.1;this.far=void 0!==p?p:2E3;this.projectionMatrix=new $3Dmol.Matrix4;this.projectionMatrixInverse=new $3Dmol.Matrix4;this.matrixWorldInverse=new $3Dmol.Matrix4;this.right=this.position.z*Math.tan(Math.PI/180*b);this.left=-this.right;this.top=this.right/this.aspect;this.bottom=-this.top;this.ortho=!!t;this.updateProjectionMatrix()};$3Dmol.Camera.prototype=Object.create($3Dmol.Object3D.prototype); +$3Dmol.Camera.prototype.lookAt=function(b){this.matrix.lookAt(this.position,b,this.up);this.rotationAutoUpdate&&(!1===this.useQuaternion?this.rotation.setEulerFromRotationMatrix(this.matrix,this.eulerOrder):this.quaternion.copy(this.matrix.decompose()[1]))}; +$3Dmol.Camera.prototype.updateProjectionMatrix=function(){this.ortho?this.projectionMatrix.makeOrthographic(this.left,this.right,this.top,this.bottom,this.near,this.far):this.projectionMatrix.makePerspective(this.fov,this.aspect,this.near,this.far);this.projectionMatrixInverse.getInverse(this.projectionMatrix)}; +$3Dmol.SpritePlugin=function(){function b(b,c){return b.z!==c.z?c.z-b.z:c.id-b.id}var c,d,p,t,A,y,z,f,h,l;this.init=function(b){c=b.context;d=b;p=b.getPrecision();t=new Float32Array(16);A=new Uint16Array(6);b=0;t[b++]=-1;t[b++]=-1;t[b++]=0;t[b++]=0;t[b++]=1;t[b++]=-1;t[b++]=1;t[b++]=0;t[b++]=1;t[b++]=1;t[b++]=1;t[b++]=1;t[b++]=-1;t[b++]=1;t[b++]=0;t[b++]=1;b=0;A[b++]=0;A[b++]=1;A[b++]=2;A[b++]=0;A[b++]=2;A[b++]=3;y=c.createBuffer();z=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y);c.bufferData(c.ARRAY_BUFFER, +t,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,z);c.bufferData(c.ELEMENT_ARRAY_BUFFER,A,c.STATIC_DRAW);b=$3Dmol.ShaderLib.sprite;var w=p,e=c.createProgram(),G=c.createShader(c.FRAGMENT_SHADER),g=c.createShader(c.VERTEX_SHADER),w="precision "+w+" float;\n";c.shaderSource(G,w+b.fragmentShader);c.shaderSource(g,w+b.vertexShader);c.compileShader(G);c.compileShader(g);c.getShaderParameter(G,c.COMPILE_STATUS)&&c.getShaderParameter(g,c.COMPILE_STATUS)?(c.attachShader(e,G),c.attachShader(e,g),c.linkProgram(e), +c.getProgramParameter(e,c.LINK_STATUS)||console.error("Could not initialize shader"),b=e):(console.error(c.getShaderInfoLog(G)),console.error("could not initialize shader"),b=null);f=b;h={};l={};h.position=c.getAttribLocation(f,"position");h.uv=c.getAttribLocation(f,"uv");l.uvOffset=c.getUniformLocation(f,"uvOffset");l.uvScale=c.getUniformLocation(f,"uvScale");l.rotation=c.getUniformLocation(f,"rotation");l.scale=c.getUniformLocation(f,"scale");l.alignment=c.getUniformLocation(f,"alignment");l.color= +c.getUniformLocation(f,"color");l.map=c.getUniformLocation(f,"map");l.opacity=c.getUniformLocation(f,"opacity");l.useScreenCoordinates=c.getUniformLocation(f,"useScreenCoordinates");l.screenPosition=c.getUniformLocation(f,"screenPosition");l.modelViewMatrix=c.getUniformLocation(f,"modelViewMatrix");l.projectionMatrix=c.getUniformLocation(f,"projectionMatrix");l.fogType=c.getUniformLocation(f,"fogType");l.fogDensity=c.getUniformLocation(f,"fogDensity");l.fogNear=c.getUniformLocation(f,"fogNear");l.fogFar= +c.getUniformLocation(f,"fogFar");l.fogColor=c.getUniformLocation(f,"fogColor");l.alphaTest=c.getUniformLocation(f,"alphaTest")};this.render=function(m,w,e,G){var g=m.__webglSprites,s=g.length;if(s){var u=h,x=l,q=.5*e,t=.5*G;c.useProgram(f);c.enableVertexAttribArray(u.position);c.enableVertexAttribArray(u.uv);c.disable(c.CULL_FACE);c.enable(c.BLEND);c.bindBuffer(c.ARRAY_BUFFER,y);c.vertexAttribPointer(u.position,2,c.FLOAT,!1,16,0);c.vertexAttribPointer(u.uv,2,c.FLOAT,!1,16,8);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, +z);c.uniformMatrix4fv(x.projectionMatrix,!1,w.projectionMatrix.elements);c.activeTexture(c.TEXTURE0);c.uniform1i(x.map,0);var p=u=0;(u=m.fog)?(c.uniform3f(x.fogColor,u.color.r,u.color.g,u.color.b),c.uniform1f(x.fogNear,u.near),c.uniform1f(x.fogFar,u.far),c.uniform1i(x.fogType,1),p=u=1):(c.uniform1i(x.fogType,0),p=u=0);var D,C,B,F=[];for(D=0;D 0.0) {\n vec3 cp;\n if( dotp1 < 0.0) { cp = p1;\n } else {\n cp = p2;\n }\n vec3 diff = p-cp;\n A = dot(v,v);\n B = dot(diff,v)*2.0;\n C = dot(diff,diff)-r*r;\n det = (B*B) - (4.0*C);\n if(det < 0.0) discard;\n sqrtDet = sqrt(det);\n posT = (-B+sqrtDet)/(2.0);\n negT = (-B-sqrtDet)/(2.0);\n float t = min(posT,negT);\n qi = p+v*t;\n norm = normalize(qi-cp);\n } else {\n norm = normalize(qi-(dotp1*va + p1));\n }\n vec4 clipPos = projectionMatrix * vec4(qi, 1.0);\n float ndcDepth = clipPos.z / clipPos.w;\n float depth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;\n gl_FragDepthEXT = depth;"}; @@ -214,274 +231,290 @@ vertexShader:"uniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuni uniforms:{opacity:{type:"f",value:1},fogColor:{type:"c",value:new $3Dmol.Color(1,1,1)},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},directionalLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]}}},sprite:{fragmentShader:"uniform vec3 color;\nuniform sampler2D map;\nuniform float opacity;\nuniform int fogType;\nuniform vec3 fogColor;\nuniform float fogDensity;\nuniform float fogNear;\nuniform float fogFar;\nuniform float alphaTest;\nvarying vec2 vUV;\nvoid main() {\n vec4 texture = texture2D(map, vUV);\n if (texture.a < alphaTest) discard;\n gl_FragColor = vec4(color * texture.xyz, texture.a * opacity);\n if (fogType > 0) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor = 0.0;\n if (fogType == 1) {\n fogFactor = smoothstep(fogNear, fogFar, depth);\n }\n else {\n const float LOG2 = 1.442695;\n float fogFactor = exp2(- fogDensity * fogDensity * depth * depth * LOG2);\n fogFactor = 1.0 - clamp(fogFactor, 0.0, 1.0);\n }\n gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), fogFactor);\n }\n}", vertexShader:"uniform int useScreenCoordinates;\nuniform vec3 screenPosition;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float rotation;\nuniform vec2 scale;\nuniform vec2 alignment;\nuniform vec2 uvOffset;\nuniform vec2 uvScale;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\n vUV = uvOffset + uv * uvScale;\n vec2 alignedPosition = position + alignment;\n vec2 rotatedPosition;\n rotatedPosition.x = ( cos(rotation) * alignedPosition.x - sin(rotation) * alignedPosition.y ) * scale.x;\n rotatedPosition.y = ( sin(rotation) * alignedPosition.x + cos(rotation) * alignedPosition.y ) * scale.y;\n vec4 finalPosition;\n if(useScreenCoordinates != 0) {\n finalPosition = vec4(screenPosition.xy + rotatedPosition, screenPosition.z, 1.0);\n }\n else {\n finalPosition = projectionMatrix * modelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); finalPosition /= finalPosition.w;\n finalPosition.xy += rotatedPosition; \n }\n gl_Position = finalPosition;\n}", uniforms:{}}};"undefined"===typeof console&&(console={log:function(){}}); -$3Dmol.ProteinSurface=function(){var b=0,c=0,d=0,p=2,y=0,A=0,q=0,B=0,f=null,w=null,h=null,t=0,m=0,e=0,F=0,g=0,x=0,u={H:1.2,Li:1.82,Na:2.27,K:2.75,C:1.7,N:1.55,O:1.52,F:1.47,P:1.8,S:1.8,CL:1.75,BR:1.85,SE:1.9,ZN:1.39,CU:1.4,NI:1.63,X:2},s=function(b){return b.elem&&"undefined"!=typeof u[b.elem]?b.elem:"X"},l={},E={},M,C,G=[new Int32Array([1,0,0]),new Int32Array([-1,0,0]),new Int32Array([0,1,0]),new Int32Array([0,-1,0]),new Int32Array([0,0,1]),new Int32Array([0,0,-1]),new Int32Array([1,1,0]),new Int32Array([1, +$3Dmol.ProteinSurface=function(){var b=0,c=0,d=0,p=2,t=0,A=0,y=0,z=0,f=null,h=null,l=null,m=0,w=0,e=0,G=0,g=0,s=0,u={H:1.2,Li:1.82,Na:2.27,K:2.75,C:1.7,N:1.55,O:1.52,F:1.47,P:1.8,S:1.8,CL:1.75,BR:1.85,SE:1.9,ZN:1.39,CU:1.4,NI:1.63,X:2},x=function(b){return b.elem&&"undefined"!=typeof u[b.elem]?b.elem:"X"},q={},N={},I,D,C=[new Int32Array([1,0,0]),new Int32Array([-1,0,0]),new Int32Array([0,1,0]),new Int32Array([0,-1,0]),new Int32Array([0,0,1]),new Int32Array([0,0,-1]),new Int32Array([1,1,0]),new Int32Array([1, -1,0]),new Int32Array([-1,1,0]),new Int32Array([-1,-1,0]),new Int32Array([1,0,1]),new Int32Array([1,0,-1]),new Int32Array([-1,0,1]),new Int32Array([-1,0,-1]),new Int32Array([0,1,1]),new Int32Array([0,1,-1]),new Int32Array([0,-1,1]),new Int32Array([0,-1,-1]),new Int32Array([1,1,1]),new Int32Array([1,1,-1]),new Int32Array([1,-1,1]),new Int32Array([-1,1,1]),new Int32Array([1,-1,-1]),new Int32Array([-1,-1,1]),new Int32Array([-1,1,-1]),new Int32Array([-1,-1,-1])];this.getFacesAndVertices=function(e){var g= -{},q,m;q=0;for(m=e.length;qf?l[e][indx]=-1:(h=Math.sqrt(f-h),l[e][indx]=Math.floor(h)),indx++};this.fillvoxels=function(b,c){var e,q;e=0;for(q=f.length;eca;ca++)for(X=-1;2>X;X++)for(D=-1;2>D;D++)if(0!==ca&&0!==X&&0!==D)for(z=ca*G,C=D*M,V=0;V<=l[U][T];V++)F=V*X,B=w+z,u=m+F,Z=t+C,0>B||0>u||0>Z||B>=q||u>=A||Z>=y||(Z=B*ea+u*y+Z,f[Z]&1?(x=g[h[Z]],x.serial!=e.serial&&(B=w+z-Math.floor(.5+p*(x.x+b)),u=m+F-Math.floor(.5+p*(x.y+c)),x=t+C-Math.floor(.5+p*(x.z+d)),z*z+F*F+C*CX;X++)for(D=-1;2>D;D++)for(ba=-1;2>ba;ba++)if(0!==X&&0!==D&&0!==ba)for(F=X*V,G=ba*Z,ca=0;ca<=l[T][z];ca++)C=ca*D,B=w+F,u=m+C,M=t+G,0>B||0>u||0> -M||B>=q||u>=A||M>=y||(M=B*ea+u*y+M,f[M]&2?(x=g[h[M]],x.serial!=e.serial&&(B=w+F-Math.floor(.5+p*(x.x+b)),u=m+C-Math.floor(.5+p*(x.y+c)),x=t+G-Math.floor(.5+p*(x.z+d)),F*F+C*C+G*Gh;){var e=i+G[h][0],g=j+G[h][2],w=k+G[h][1];if(-1b&&(b=0);m-=.5/(.1+b);for(b=0;b=m)&&(f[l]|=4)};this.fastoneshell=function(b,c){var h,e,g,m,l,t,d,s,B,u,x,z=[];if(0===b.length)return z;tnv={ix:-1,iy:-1,iz:-1};var F=A*y;d=0;for(B=b.length;ds;s++)tnv.ix=h+G[s][0],tnv.iy= -e+G[s][1],tnv.iz=g+G[s][2],tnv.ixs;s++)tnv.ix=h+G[s][0],tnv.iy=e+G[s][1],tnv.iz=g+G[s][2],tnv.ixs;s++)tnv.ix=h+G[s][0],tnv.iy=e+G[s][1],tnv.iz=g+G[s][2],tnv.ixf?q[e][indx]=-1:(l=Math.sqrt(f-l),q[e][indx]=Math.floor(l)),indx++};this.fillvoxels=function(b,c){var e,g;e=0;for(g=f.length;eE;E++)for(aa=-1;2>aa;aa++)for(T=-1;2>T;T++)if(0!==E&&0!==aa&&0!==T)for(G=E*C,D=T*I,Y=0;Y<=q[W][U];Y++)B=Y*aa,z=g+G,s=w+B,ba=m+D,0>z||0>s||0>ba||z>=y||s>=A||ba>=t||(ba=z*X+s*t+ba,f[ba]&1?(u=h[l[ba]],u.serial!=e.serial&&(z=g+G-Math.floor(.5+p*(u.x+b)),s=w+B-Math.floor(.5+p*(u.y+c)),u=m+D-Math.floor(.5+p*(u.z+d)),G*G+B*B+D*Daa;aa++)for(T=-1;2>T;T++)for(Z=-1;2>Z;Z++)if(0!==aa&&0!==T&&0!==Z)for(B=aa*Y,C=Z*ba,E=0;E<=q[U][G];E++)D=E*T,z=g+B,s=w+D,I=m+C,0>z||0>s||0>I|| +z>=y||s>=A||I>=t||(I=z*X+s*t+I,f[I]&2?(u=h[l[I]],u.serial!=e.serial&&(z=g+B-Math.floor(.5+p*(u.x+b)),s=w+D-Math.floor(.5+p*(u.y+c)),u=m+C-Math.floor(.5+p*(u.z+d)),B*B+D*D+C*Cl;){var e=i+C[l][0],h=j+C[l][2],g=k+C[l][1];if(-1b&&(b=0);w-=.5/(.1+b);for(b=0;b=w)&&(f[m]|=4)};this.fastoneshell=function(b,c){var l,e,g,m,w,d,q,z,x,s,u,G=[];if(0===b.length)return G;tnv={ix:-1,iy:-1,iz:-1};var B=A*t;q=0;for(x=b.length;qz;z++)tnv.ix=l+C[z][0],tnv.iy=e+ +C[z][1],tnv.iz=g+C[z][2],tnv.ixz;z++)tnv.ix=l+C[z][0],tnv.iy=e+C[z][1],tnv.iz=g+C[z][2],tnv.ixz;z++)tnv.ix=l+C[z][0],tnv.iy=e+C[z][1],tnv.iz=g+C[z][2],tnv.ixs;++s)l[e+3*s]=d.r,l[e+1+3*s]=d.g,l[e+2+3*s]=d.b;0t&&(c.transparent= -!0,c.opacity=t);c.vertexColors=$3Dmol.FaceColors;t=new $3Dmol.Mesh(h,c);b.add(t)},d=function(c,d,f,w,h){0!==d.length&&(h=void 0===h?5:h,w=new $3Dmol.Geometry,b(d,h),d=new $3Dmol.LineBasicMaterial({linewidth:f}),d.vertexColors=!0,d=new $3Dmol.Line(w,d),d.type=$3Dmol.LineStrip,c.add(d))},p=function(q,d,f,w,h,t,m){m&&"default"!==m||(m="rectangle");if("edged"===m){if(!(2>d.length)){var e,F;e=d[0];F=d[d.length-1];d=w||axisDIV;e=b(e,d);F=b(F,d);if(h){d=new $3Dmol.Geometry(!0);var g=[],x,u,s,l,E,p=[[0,2, --6,-8],[-4,-2,6,4],[7,-1,-5,3],[-3,5,1,-7]],C,y,z,A,L,N,J,I;L=0;for(N=e.length;LJ;++J)I[C+3*J]=y.r,I[C+1+3*J]=y.g,I[C+2+3*J]=y.b;if(0J;J++)if(I=[w+p[J][0],w+p[J][1],w+p[J][2],w+p[J][3]],s=m.faceidx,K[s]=I[0],K[s+1]=I[1],K[s+2]=I[3],K[s+3]=I[1],K[s+4]= -I[2],K[s+5]=I[3],m.faceidx+=6,z.clickable||A.clickable){E=g[I[3]].clone();s=g[I[0]].clone();var O=g[I[2]].clone();l=g[I[1]].clone();E.atom=g[I[3]].atom||null;O.atom=g[I[2]].atom||null;s.atom=g[I[0]].atom||null;l.atom=g[I[1]].atom||null;if(C){var Q=E.clone().add(s).multiplyScalar(.5),W=O.clone().add(l).multiplyScalar(.5),P=E.clone().add(l).multiplyScalar(.5);0===J%2?(A.clickable&&(I=new $3Dmol.Triangle(Q,P,E),u=new $3Dmol.Triangle(W,O,P),E=new $3Dmol.Triangle(P,O,E),A.intersectionShape.triangle.push(I), -A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(E)),z.clickable&&(I=new $3Dmol.Triangle(s,l,P),u=new $3Dmol.Triangle(l,W,P),E=new $3Dmol.Triangle(s,P,Q),z.intersectionShape.triangle.push(I),z.intersectionShape.triangle.push(u),z.intersectionShape.triangle.push(E))):(z.clickable&&(I=new $3Dmol.Triangle(Q,P,E),u=new $3Dmol.Triangle(W,O,P),E=new $3Dmol.Triangle(P,O,E),z.intersectionShape.triangle.push(I),z.intersectionShape.triangle.push(u),z.intersectionShape.triangle.push(E)), -A.clickable&&(I=new $3Dmol.Triangle(s,l,P),u=new $3Dmol.Triangle(l,W,P),E=new $3Dmol.Triangle(s,P,Q),A.intersectionShape.triangle.push(I),A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(E)))}else z.clickable&&(I=new $3Dmol.Triangle(s,l,E),u=new $3Dmol.Triangle(l,O,E),z.intersectionShape.triangle.push(I),z.intersectionShape.triangle.push(u))}m.vertices+=8;A=z}f=g.length-8;m=d.updateGeoGroup(8);J=m.vertexArray;I=m.colorArray;K=m.faceArray;w=m.vertices;C=3*w;s=m.faceidx;for(L= -0;4>L;L++)g.push(g[2*L]),g.push(g[f+2*L]),h=g[2*L],z=g[f+2*L],J[C+6*L]=h.x,J[C+1+6*L]=h.y,J[C+2+6*L]=h.z,J[C+3+6*L]=z.x,J[C+4+6*L]=z.y,J[C+5+6*L]=z.z,I[C+6*L]=y.r,I[C+1+6*L]=y.g,I[C+2+6*L]=y.b,I[C+3+6*L]=y.r,I[C+4+6*L]=y.g,I[C+5+6*L]=y.b;I=[w,w+2,w+6,w+4];u=[w+1,w+5,w+7,w+3];K[s]=I[0];K[s+1]=I[1];K[s+2]=I[3];K[s+3]=I[1];K[s+4]=I[2];K[s+5]=I[3];K[s+6]=u[0];K[s+7]=u[1];K[s+8]=u[3];K[s+9]=u[1];K[s+10]=u[2];K[s+11]=u[3];m.faceidx+=12;m.vertices+=8;d.initTypedArrays();d.setUpNormals();f=new $3Dmol.MeshDoubleLambertMaterial; -f.vertexColors=$3Dmol.FaceColors;"number"===typeof t&&0<=t&&1>t&&(f.transparent=!0,f.opacity=t);t=new $3Dmol.Mesh(d,f);q.add(t)}else c(q,e,F,f,d,t)}}else if("rectangle"===m||"oval"===m||"parabola"===m)if(y=m,z=d.length,!(2>z||2>d[0].length)){w=w||axisDIV;for(A=0;At&&(f.transparent=!0,f.opacity=t);t=new $3Dmol.Mesh(w, -f);q.add(t)}else c(q,d[0],d[z-1],f,w,t)}},y=function(b,c){if(b&&c&&b.chain===c.chain){if(b.reschain===c.reschain&&(b.resi===c.resi||b.resi===c.resi-1))return!0;if(b.resif.distanceToSquared(d))return!0}}return!1},A=function(b,c,f,d,h,t,m,e,F){var g,x={ALA:5,ARG:11,ASN:8,ASP:8,CYS:6,GLN:9,GLU:9,GLY:4,HIS:10,ILE:8,LEU:8,LYS:9,MET:8,PHE:11,PRO:7,SER:6,THR:7,TRP:14,TYR:12,VAL:7};if(d&&h&&m){var u=h.sub(d);u.normalize(); -e=(e=e[parseInt(F)+x[m.resn]])?new $3Dmol.Vector3(e.x,e.y,e.z):new $3Dmol.Vector3(0,0,0);e.sub(d);"arrow start"===m.ss&&(h=e.clone().multiplyScalar(.3).cross(h),d.add(h),h=e.clone().cross(u).normalize(),u.rotateAboutVector(h,.43));m.style.cartoon.ribbon?h=m.style.cartoon.thickness||.4:m.style.cartoon.width?h=m.style.cartoon.width:"c"===m.ss?h="P"===m.atom?.8:.5:"arrow start"===m.ss?(h=1.3,g=!0):h="arrow end"===m.ss?.5:"h"===m.ss&&m.style.cartoon.tubes||"tube start"===m.ss?.5:1.3;null!=t&&0>u.dot(t)&& -u.negate();u.multiplyScalar(h);for(t=0;tP.opacity&&(l.transparent=!0,l.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,l),b.add(P),P=null):l&&(P.opacity&&l.style.cartoon.opacity?P.opacity!=l.style.cartoon.opacity&&(console.log("Warning: a trace-style chain's opacity is ambiguous"),P.opacity=1):P.opacity=parseFloat(l.style.cartoon.opacity)|| -1),l=E,M=C}else{u||(u=new $3Dmol.Geometry(!0));if(E&&"C"===E.elem&&"CA"===E.atom||H&&("P"===E.atom||0==E.atom.indexOf("O5"))){if(W)if("tube end"===E.ss)W=!1,H=new $3Dmol.Vector3(E.x,E.y,E.z),$3Dmol.GLDraw.drawCylinder(u,Q,H,2,$3Dmol.CC.color(M),1,1),E.ss="h";else continue;if(l&&(!y(l,E)||l.style.cartoon.style!==E.style.cartoon.style||"tube start"===l.ss)){"tube start"===l.ss&&(W=!0,Q=new $3Dmol.Vector3(l.x,l.y,l.z),l.ss="h");O&&(H=I?(new $3Dmol.Vector3).addVectors(l,I).multiplyScalar(.5):new $3Dmol.Vector3(l.x, -l.y,l.z),$3Dmol.GLDraw.drawCylinder(u,H,O,.4,$3Dmol.CC.color(O.color),0,2),H=A(R,m,!t,I,K,J,l,c,z),S.push(C),H&&S.push(C),O=null);for(z=0;!G&&zR.opacity&&(z.transparent=!0,z.opacity=R.opacity),u=new $3Dmol.Mesh(u,z),b.add(u),u=null);R=[];for(z=0;zR.opacity&&(z.transparent=!0,z.opacity=R.opacity),u=new $3Dmol.Mesh(u,z),b.add(u));null!=P&&0P.opacity&&(l.transparent=!0,l.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,l),b.add(P))}}();$3Dmol=$3Dmol||{}; -$3Dmol.GLDraw=function(){var b={},c=function(){var b=new $3Dmol.Vector3;return function(c){b.set(c[0],c[1],c[2]);var f=b.x,d=b.y,h=b.z,t=Math.sqrt(f*f+d*d);1E-4>t?(c=0,t=1):(c=-f/t,t=d/t);d=-c*f+t*d;f=Math.sqrt(d*d+h*h);1E-4>f?(h=0,d=1):(h/=f,d/=f);f=new Float32Array(9);f[0]=t;f[1]=c;f[2]=0;f[3]=-c*d;f[4]=t*d;f[5]=h;f[6]=c*h;f[7]=-t*h;f[8]=d;return f}}(),d=function(){var b=[],c=Math.pow(2,4),f,d=Math.pow(2,2),h=c/d,t;b[0]=new $3Dmol.Vector3(-1,0,0);b[h]=new $3Dmol.Vector3(0,0,1);b[2*h]=new $3Dmol.Vector3(1, -0,0);b[3*h]=new $3Dmol.Vector3(0,0,-1);for(f=3;4>=f;f++){d=Math.pow(2,f-1);h=c/d;for(t=0;t=x;x++){var u=0===x||10===x?!0:!1,s=5===x?!0:!1,l=[],E=[];for(g=0;g<=f;g++)if(s){var p=gMath.abs(p.x)&&(p.x=0),1E-5>Math.abs(p.y)&&(p.y=0),1E-5>Math.abs(p.z)&&(p.z=0),t=c?new $3Dmol.Vector3(0,Math.cos(0+y*F), -0):new $3Dmol.Vector3(p.x,p.y,p.z),t.normalize(),w.push(p),h.push(t),l.push(w.length-1)):l.push(w.length-f)}s&&m.push(E);m.push(l)}f={vertices:w,normals:h,verticesRows:m,w:f,h:10};return this.cache[c][b]=f}},y=0;b.drawCylinder=function(b,d,f,w,h,t,m){if(d&&f){y++;var e=t||m,F=!1;1==t&&1==m&&(F=!0);h=h||{r:0,g:0,b:0};var g=[f.x,f.y,f.z];g[0]-=d.x;g[1]-=d.y;g[2]-=d.z;var g=c(g),x=p.getVerticesForRadius(w,F);w=x.w;var F=x.h,u=e?F*w+2:2*w;b=b.updateGeoGroup(u);var s=x.vertices,l=x.normals,x=x.verticesRows, -E=x[F/2],A=x[F/2+1],C=b.vertices,G,z,H,L,N,J,I=b.vertexArray,K=b.normalArray,O=b.colorArray,Q=b.faceArray;for(H=0;Hb&&(f=10,d=8);var h=2*Math.PI,t=Math.PI,m,e;for(e=0;e<=d;e++){var p=[];for(m=0;m<=f;m++){var g=m/f,x=e/d,u={};u.x=-b*Math.cos(0+ -g*h)*Math.sin(0+x*t);u.y=b*Math.cos(0+x*t);u.z=b*Math.sin(0+g*h)*Math.sin(0+x*t);g=new $3Dmol.Vector3(u.x,u.y,u.z);g.normalize();c.vertices.push(u);c.normals.push(g);p.push(c.vertices.length-1)}c.verticesRows.push(p)}return this.cache[b]=c}};b.drawSphere=function(b,c,f,d){new $3Dmol.Vector3(c.x,c.y,c.z);var h=A.getVerticesForRadius(f),t=h.vertices,m=h.normals;b=b.updateGeoGroup(t.length);for(var e=b.vertices,p=b.vertexArray,g=b.colorArray,x=b.faceArray,u=b.lineArray,s=b.normalArray,l=0,E=t.length;l< -E;++l){var y=3*(e+l),C=t[l];p[y]=C.x+c.x;p[y+1]=C.y+c.y;p[y+2]=C.z+c.z;g[y]=d.r;g[y+1]=d.g;g[y+2]=d.b}b.vertices+=t.length;h=h.verticesRows;p=h.length-1;for(d=0;dg.lengthSq()&&(g=f.clone(),1E-4l;l++)d[g+3*l]=c.x,d[g+3*l+1]=c.y,d[g+3*l+2]=c.z;c=b.normalArray;m=b.colorArray;for(l=0;4>l;l++)m[g+3*l]=e.r,m[g+3*l+1]=e.g,m[g+3*l+2]=e.b;c[g+0]=-h;c[g+1]=h;c[g+2]=0;c[g+3]=-h;c[g+4]=-h;c[g+5]=0;c[g+6]=h;c[g+7]=-h;c[g+8]=0;c[g+9]=h;c[g+10]=h;c[g+11]=0;b.vertices+=4;h=b.faceArray; -e=b.faceidx;h[e+0]=f;h[e+1]=f+1;h[e+2]=f+2;h[e+3]=f+2;h[e+4]=f+3;h[e+5]=f;b.faceidx+=6},z=function(b,c){if(b.style.sphere){var h=b.style.sphere;if(!h.hidden){var e=s(b,h),h=$3Dmol.getColorFromStyle(b,h);G(c,b,e,h)}}},H=function(b,c,h,e,f,g,d){b=b.updateGeoGroup(4);g=b.vertices;d=b.vertexArray;var m=b.colorArray,l=b.radiusArray,t=b.normalArray,w=f.r,s=f.g;f=f.b;for(var u=3*g,x=0;4>x;x++){d[u]=c.x;t[u]=h.x;m[u]=w;u++;d[u]=c.y;t[u]=h.y;m[u]=s;u++;d[u]=c.z;t[u]=h.z;if(2>x)m[u]=f;else{var q=u,p=-f;0== -p&&(p=-1E-4);m[q]=p}u++}b.vertices+=4;l[g]=-e;l[g+1]=e;l[g+2]=-e;l[g+3]=e;c=b.faceArray;h=b.faceidx;c[h+0]=g;c[h+1]=g+1;c[h+2]=g+2;c[h+3]=g+2;c[h+4]=g+3;c[h+5]=g;b.faceidx+=6};this.getCrystData=function(){return e.cryst?e.cryst:null};this.getSymmetries=function(){"undefined"==typeof e.symmetries&&(e.symmetries=[F]);return e.symmetries};this.setSymmetries=function(b){e.symmetries="undefined"==typeof b?[F]:b};this.getID=function(){return b};this.getFrames=function(){return f};this.setFrame=function(b){0!= -f.length&&(B=0<=b&&b=m)d=h;else{f=$3Dmol.getExtent(h);e=[[],[],[]];for(g=0;3>g;g++)e[0][g]=f[0][g]-m,e[1][g]=f[1][g]+m,e[2][g]=f[2][g];m=[];for(g=0;g=e[0][0]&&d<=e[1][0]&&l>=e[0][1]&&l<=e[1][1]&&t>=e[0][2]&&t<=e[1][2]&&(d>=f[0][0]&&d<=f[1][0]&&l>=f[0][1]&&l<=f[1][1]&&t>=f[0][2]&&t<=f[1][2]||m.push(B[g]))}d=m}l=h.length;for(f=0;f=d||(g={b:g,e:d},d=f.bondOrder[e],1!=d&&(g.o=d),c.b.push(g))}}return c}; -this.globj=function(b,c){if(null===h){var f=B,d=c,d=d||{},m=new $3Dmol.Object3D,u=[],x={},q={},p=M,y=null,F=null;d.supportsImposters?(p=z,y=new $3Dmol.Geometry(!0),y.imposter=!0,F=new $3Dmol.Geometry(!0,!0),F.imposter=!0,F.sphereGeometry=y,F.drawnCaps={}):(d.supportsAIA?(p=C,y=new $3Dmol.Geometry(!1,!0,!0),y.instanced=!0):y=new $3Dmol.Geometry(!0),F=new $3Dmol.Geometry(!0));var A,L,ca,X,D={},ba=[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY];A=0;for(ca=f.length;Axa;xa++){var Ma=3*Ja.vertices;Ja.vertices++;$a[Ma]=T.x+Ia[xa][0];$a[Ma+1]=T.y+Ia[xa][1];$a[Ma+2]=T.z+Ia[xa][2];Ua[Ma]=Ta.r;Ua[Ma+1]=Ta.g;Ua[Ma+2]=Ta.b;if(Za){var Va=new $3Dmol.Vector3(Ia[xa][0],Ia[xa][1],Ia[xa][2]);Va.multiplyScalar(.1);Va.set(Va.x+ -T.x,Va.y+T.y,Va.z+T.z);T.intersectionShape.line.push(Va)}}}}var fa=U,zb=f,kb=x;if(fa.style.line){var rb=fa.style.line;if(!rb.hidden){var lb=rb.linewidth||1;kb[lb]||(kb[lb]=new $3Dmol.Geometry);for(var ta=kb[lb].updateGeoGroup(6*fa.bonds.length),ja=ta.vertexArray,ka=ta.colorArray,Ea=0;Ea=Oa.serial)){var Ca=new $3Dmol.Vector3(fa.x,fa.y,fa.z),Qa=new $3Dmol.Vector3(Oa.x,Oa.y,Oa.z),fb=Ca.clone().add(Qa).multiplyScalar(.5),sb= -!1;fa.clickable&&(void 0===fa.intersectionShape&&(fa.intersectionShape={sphere:[],cylinder:[],line:[],triangle:[]}),fa.intersectionShape.line.push(Ca),fa.intersectionShape.line.push(Qa));var pa=$3Dmol.getColorFromStyle(fa,fa.style.line),Fa=$3Dmol.getColorFromStyle(Oa,Oa.style.line);if(fa.bondStyles&&fa.bondStyles[Ea]){var Pa=fa.bondStyles[Ea];if(!Pa.iswire)continue;Pa.radius&&(bondR=Pa.radius);Pa.singleBond&&(sb=!0);"undefined"!=typeof Pa.color1&&(pa=$3Dmol.CC.color(Pa.color1));"undefined"!=typeof Pa.color2&& -(Fa=$3Dmol.CC.color(Pa.color2))}var la=3*ta.vertices;if(1fa.bondOrder[Ea]&&!sb){var Wa=l(fa,Oa,Ea),Da=Qa.clone();Da.sub(Ca);if(2==fa.bondOrder[Ea])if(Wa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Wa),p1b=Ca.clone(),p1b.sub(Wa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),pa==Fa)ta.vertices+=4,E(ja,ka,la,p1a,p2a,pa),E(ja,ka,la+6,p1b,p2b,pa);else{ta.vertices+=8;Da.multiplyScalar(.5);var Ra=p1a.clone();Ra.add(Da);var Sa=p1b.clone();Sa.add(Da);E(ja,ka,la,p1a,Ra,pa);E(ja, -ka,la+6,Ra,p2a,Fa);E(ja,ka,la+12,p1b,Sa,pa);E(ja,ka,la+18,Sa,p2b,Fa)}else 3==fa.bondOrder[Ea]&&(Wa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Wa),p1b=Ca.clone(),p1b.sub(Wa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),pa==Fa?(ta.vertices+=6,E(ja,ka,la,Ca,Qa,pa),E(ja,ka,la+6,p1a,p2a,pa),E(ja,ka,la+12,p1b,p2b,pa)):(ta.vertices+=12,Da.multiplyScalar(.5),Ra=p1a.clone(),Ra.add(Da),Sa=p1b.clone(),Sa.add(Da),E(ja,ka,la,Ca,fb,pa),E(ja,ka,la+6,fb,Qa,Fa),E(ja,ka,la+12,p1a,Ra,pa),E(ja,ka,la+18,Ra, -p2a,Fa),E(ja,ka,la+24,p1b,Sa,pa),E(ja,ka,la+30,Sa,p2b,Fa)))}else pa==Fa?(ta.vertices+=2,E(ja,ka,la,Ca,Qa,pa)):(ta.vertices+=4,E(ja,ka,la,Ca,fb,pa),E(ja,ka,la+6,fb,Qa,Fa))}}}}var Y=U,Ab=f,ga=F;if(Y.style.stick){var gb=Y.style.stick;if(!gb.hidden){var ab=gb.radius||.25,ua=ab,tb=gb.singleBonds||!1,bb=0,cb=0,ma=$3Dmol.getColorFromStyle(Y,gb),na=void 0,ya=void 0;!Y.capDrawn&&4>Y.bonds.length&&(bb=2);var ia=$3Dmol.GLDraw.drawCylinder;ga.imposter&&(ia=H);for(var oa=0;oaha.bonds.length&& -(cb=2),ma!=Ga?(na=(new $3Dmol.Vector3).addVectors(qa,Aa).multiplyScalar(.5),ia(ga,qa,na,ua,ma,bb,0),ia(ga,na,Aa,ua,Ga,0,cb)):ia(ga,qa,Aa,ua,ma,bb,cb),Y.clickable||ha.clickable){na=(new $3Dmol.Vector3).addVectors(qa,Aa).multiplyScalar(.5);if(Y.clickable){var Bb=new $3Dmol.Cylinder(qa,na,ua),Cb=new $3Dmol.Sphere(qa,ua);Y.intersectionShape.cylinder.push(Bb);Y.intersectionShape.sphere.push(Cb)}if(ha.clickable){var Db=new $3Dmol.Cylinder(Aa,na,ua),Eb=new $3Dmol.Sphere(Aa,ua);ha.intersectionShape.cylinder.push(Db); -ha.intersectionShape.sphere.push(Eb)}}}else if(1ba[1]&&(ba[1]=U.resi)),u.push(U))}}if(0D.sphere&&0<=D.sphere&&(Ya.transparent=!0,Ya.opacity=D.sphere);eb=new $3Dmol.Mesh(y,Ya);m.add(eb)}if(0D.stick&&0<=D.stick&&(hb.transparent=!0,hb.opacity=D.stick);F.initTypedArrays();hb.wireframe&&F.setUpWireframe();xb=new $3Dmol.Mesh(F,hb)}m.add(xb)}for(A in x)if(x.hasOwnProperty(A)){var ob=A,pb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>D.line&&0<=D.line&&(pb.transparent=!0,pb.opacity=D.line);x[A].initTypedArrays();var Gb=new $3Dmol.Line(x[A],pb,$3Dmol.LinePieces); -m.add(Gb)}for(A in q)if(q.hasOwnProperty(A)){var ob=A,qb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>D.cross&&0<=D.cross&&(qb.transparent=!0,qb.opacity=D.cross);q[A].initTypedArrays();var Hb=new $3Dmol.Line(q[A],qb,$3Dmol.LinePieces);m.add(Hb)}if(g&&e.symmetries&&0MOLECULE/gm)?"mol2":b.match(/^HETATM/gm)||b.match(/^ATOM/gm)?"pdb":b.match(/^.*\n.*\n.\s*(\d+)\s+(\d+)/gm)?"sdf":"xyz",console.log("Best guess: "+ -c)));return(0,$3Dmol.Parsers[c])(b,d)};b.setAtomDefaults=function(b,d){for(var p=0;pb.mid?b.mid:.618034;var m=b.start,e=b.end,w=b.radius,g=b.radiusRatio,x=b.mid;if(m&&e){var c=f.updateGeoGroup(51),u=e.clone();u.sub(m).multiplyScalar(x);var s=m.clone().add(u),x=u.clone().negate();this.intersectionShape.cylinder.push(new $3Dmol.Cylinder(m.clone(),s.clone(),w));this.intersectionShape.sphere.push(new $3Dmol.Sphere(m.clone(), -w));var l=[];l[0]=u.clone();1E-4this.opacity?!0:!1,opacity:this.opacity, -wireframeLinewidth:this.linewidth}):new $3Dmol.MeshLambertMaterial({wireframe:this.wireframe,side:this.side,transparent:1>this.opacity?!0:!1,opacity:this.opacity,wireframeLinewidth:this.linewidth});d=new $3Dmol.Mesh(f,d);q.add(d);d=new $3Dmol.LineBasicMaterial({linewidth:this.linewidth,color:this.color});d=new $3Dmol.Line(w,d,$3Dmol.LinePieces);q.add(d);B=q.clone();b.add(B)}};this.removegl=function(b){B&&(void 0!==B.geometry&&B.geometry.dispose(),void 0!==B.material&&B.material.dispose(),b.remove(B), -B=null);q=null}}var c=function(b,c,q){var p=q.faceArr;0!==q.vertexArr.length&&0!==p.length||console.warn("Error adding custom shape component: No vertices and/or face indices supplied!");p=q.color;"undefined"==typeof p&&(p=b.color);for(var p=$3Dmol.CC.color(p),f=$3Dmol.splitMesh(q),w=0,h=f.length;wx;++x)q[e+3*x]=G.r,q[e+1+3*x]=G.g,q[e+2+3*x]=G.b;0m&&(c.transparent= +!0,c.opacity=m);c.vertexColors=$3Dmol.FaceColors;m=new $3Dmol.Mesh(l,c);b.add(m)},d=function(c,d,f,h,l){0!==d.length&&(l=void 0===l?5:l,h=new $3Dmol.Geometry,b(d,l),d=new $3Dmol.LineBasicMaterial({linewidth:f}),d.vertexColors=!0,d=new $3Dmol.Line(h,d),d.type=$3Dmol.LineStrip,c.add(d))},p=function(d,z,f,h,l,m,w){w&&"default"!==w||(w="rectangle");if("edged"===w){if(!(2>z.length)){var e,G;e=z[0];G=z[z.length-1];z=h||axisDIV;e=b(e,z);G=b(G,z);if(l){z=new $3Dmol.Geometry(!0);var g=[],s,u,x,q,t,p=[[0,2, +-6,-8],[-4,-2,6,4],[7,-1,-5,3],[-3,5,1,-7]],D,C,B,A,J,L,K,H;J=0;for(L=e.length;JK;++K)H[D+3*K]=C.r,H[D+1+3*K]=C.g,H[D+2+3*K]=C.b;if(0K;K++)if(H=[h+p[K][0],h+p[K][1],h+p[K][2],h+p[K][3]],x=w.faceidx,M[x]=H[0],M[x+1]=H[1],M[x+2]=H[3],M[x+3]=H[1],M[x+4]= +H[2],M[x+5]=H[3],w.faceidx+=6,B.clickable||A.clickable){t=g[H[3]].clone();x=g[H[0]].clone();var O=g[H[2]].clone();q=g[H[1]].clone();t.atom=g[H[3]].atom||null;O.atom=g[H[2]].atom||null;x.atom=g[H[0]].atom||null;q.atom=g[H[1]].atom||null;if(D){var R=t.clone().add(x).multiplyScalar(.5),V=O.clone().add(q).multiplyScalar(.5),P=t.clone().add(q).multiplyScalar(.5);0===K%2?(A.clickable&&(H=new $3Dmol.Triangle(R,P,t),u=new $3Dmol.Triangle(V,O,P),t=new $3Dmol.Triangle(P,O,t),A.intersectionShape.triangle.push(H), +A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(t)),B.clickable&&(H=new $3Dmol.Triangle(x,q,P),u=new $3Dmol.Triangle(q,V,P),t=new $3Dmol.Triangle(x,P,R),B.intersectionShape.triangle.push(H),B.intersectionShape.triangle.push(u),B.intersectionShape.triangle.push(t))):(B.clickable&&(H=new $3Dmol.Triangle(R,P,t),u=new $3Dmol.Triangle(V,O,P),t=new $3Dmol.Triangle(P,O,t),B.intersectionShape.triangle.push(H),B.intersectionShape.triangle.push(u),B.intersectionShape.triangle.push(t)), +A.clickable&&(H=new $3Dmol.Triangle(x,q,P),u=new $3Dmol.Triangle(q,V,P),t=new $3Dmol.Triangle(x,P,R),A.intersectionShape.triangle.push(H),A.intersectionShape.triangle.push(u),A.intersectionShape.triangle.push(t)))}else B.clickable&&(H=new $3Dmol.Triangle(x,q,t),u=new $3Dmol.Triangle(q,O,t),B.intersectionShape.triangle.push(H),B.intersectionShape.triangle.push(u))}w.vertices+=8;A=B}f=g.length-8;w=z.updateGeoGroup(8);K=w.vertexArray;H=w.colorArray;M=w.faceArray;h=w.vertices;D=3*h;x=w.faceidx;for(J= +0;4>J;J++)g.push(g[2*J]),g.push(g[f+2*J]),l=g[2*J],B=g[f+2*J],K[D+6*J]=l.x,K[D+1+6*J]=l.y,K[D+2+6*J]=l.z,K[D+3+6*J]=B.x,K[D+4+6*J]=B.y,K[D+5+6*J]=B.z,H[D+6*J]=C.r,H[D+1+6*J]=C.g,H[D+2+6*J]=C.b,H[D+3+6*J]=C.r,H[D+4+6*J]=C.g,H[D+5+6*J]=C.b;H=[h,h+2,h+6,h+4];u=[h+1,h+5,h+7,h+3];M[x]=H[0];M[x+1]=H[1];M[x+2]=H[3];M[x+3]=H[1];M[x+4]=H[2];M[x+5]=H[3];M[x+6]=u[0];M[x+7]=u[1];M[x+8]=u[3];M[x+9]=u[1];M[x+10]=u[2];M[x+11]=u[3];w.faceidx+=12;w.vertices+=8;z.initTypedArrays();z.setUpNormals();f=new $3Dmol.MeshDoubleLambertMaterial; +f.vertexColors=$3Dmol.FaceColors;"number"===typeof m&&0<=m&&1>m&&(f.transparent=!0,f.opacity=m);m=new $3Dmol.Mesh(z,f);d.add(m)}else c(d,e,G,f,z,m)}}else if("rectangle"===w||"oval"===w||"parabola"===w)if(C=w,B=z.length,!(2>B||2>z[0].length)){h=h||axisDIV;for(A=0;Am&&(f.transparent=!0,f.opacity=m);m=new $3Dmol.Mesh(h, +f);d.add(m)}else c(d,z[0],z[B-1],f,h,m)}},t=function(b,c){if(b&&c&&b.chain===c.chain){if(b.reschain===c.reschain&&(b.resi===c.resi||b.resi===c.resi-1))return!0;if(b.resif.distanceToSquared(h))return!0}}return!1},A=function(b,c,f,h,l,d,w,e,t){var g,s={ALA:5,ARG:11,ASN:8,ASP:8,CYS:6,GLN:9,GLU:9,GLY:4,HIS:10,ILE:8,LEU:8,LYS:9,MET:8,PHE:11,PRO:7,SER:6,THR:7,TRP:14,TYR:12,VAL:7};if(h&&l&&w){var u=l.sub(h);u.normalize(); +e=(e=e[parseInt(t)+s[w.resn]])?new $3Dmol.Vector3(e.x,e.y,e.z):new $3Dmol.Vector3(0,0,0);e.sub(h);"arrow start"===w.ss&&(l=e.clone().multiplyScalar(.3).cross(l),h.add(l),l=e.clone().cross(u).normalize(),u.rotateAboutVector(l,.43));w.style.cartoon.ribbon?l=w.style.cartoon.thickness||.4:w.style.cartoon.width?l=w.style.cartoon.width:"c"===w.ss?l="P"===w.atom?.8:.5:"arrow start"===w.ss?(l=1.3,g=!0):l="arrow end"===w.ss?.5:"h"===w.ss&&w.style.cartoon.tubes||"tube start"===w.ss?.5:1.3;null!=d&&0>u.dot(d)&& +u.negate();u.multiplyScalar(l);for(d=0;dP.opacity&&(q.transparent=!0,q.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,q),b.add(P),P=null):q&&(P.opacity&&q.style.cartoon.opacity?P.opacity!=q.style.cartoon.opacity&&(console.log("Warning: a trace-style chain's opacity is ambiguous"),P.opacity=1):P.opacity=parseFloat(q.style.cartoon.opacity)|| +1),q=N,I=D}else{u||(u=new $3Dmol.Geometry(!0));if(N&&"C"===N.elem&&"CA"===N.atom||F&&("P"===N.atom||0==N.atom.indexOf("O5"))){if(V)if("tube end"===N.ss)V=!1,F=new $3Dmol.Vector3(N.x,N.y,N.z),$3Dmol.GLDraw.drawCylinder(u,R,F,2,$3Dmol.CC.color(I),1,1),N.ss="h";else continue;if(q&&(!t(q,N)||q.style.cartoon.style!==N.style.cartoon.style||"tube start"===q.ss)){"tube start"===q.ss&&(V=!0,R=new $3Dmol.Vector3(q.x,q.y,q.z),q.ss="h");O&&(F=H?(new $3Dmol.Vector3).addVectors(q,H).multiplyScalar(.5):new $3Dmol.Vector3(q.x, +q.y,q.z),$3Dmol.GLDraw.drawCylinder(u,F,O,.4,$3Dmol.CC.color(O.color),0,2),F=A(Q,w,!m,H,M,K,q,c,B),S.push(D),F&&S.push(D),O=null);for(B=0;!C&&BQ.opacity&&(B.transparent=!0,B.opacity=Q.opacity),u=new $3Dmol.Mesh(u,B),b.add(u),u=null);Q=[];for(B=0;BQ.opacity&&(B.transparent=!0,B.opacity=Q.opacity),u=new $3Dmol.Mesh(u,B),b.add(u));null!=P&&0P.opacity&&(q.transparent=!0,q.opacity=P.opacity,delete P.opacity),P=new $3Dmol.Mesh(P,q),b.add(P))}}();$3Dmol=$3Dmol||{}; +$3Dmol.GLDraw=function(){var b={},c=function(){var b=new $3Dmol.Vector3;return function(c){b.set(c[0],c[1],c[2]);var f=b.x,h=b.y,l=b.z,d=Math.sqrt(f*f+h*h);1E-4>d?(c=0,d=1):(c=-f/d,d=h/d);h=-c*f+d*h;f=Math.sqrt(h*h+l*l);1E-4>f?(l=0,h=1):(l/=f,h/=f);f=new Float32Array(9);f[0]=d;f[1]=c;f[2]=0;f[3]=-c*h;f[4]=d*h;f[5]=l;f[6]=c*l;f[7]=-d*l;f[8]=h;return f}}(),d=function(){var b=[],c=Math.pow(2,4),f,d=Math.pow(2,2),l=c/d,m;b[0]=new $3Dmol.Vector3(-1,0,0);b[l]=new $3Dmol.Vector3(0,0,1);b[2*l]=new $3Dmol.Vector3(1, +0,0);b[3*l]=new $3Dmol.Vector3(0,0,-1);for(f=3;4>=f;f++){d=Math.pow(2,f-1);l=c/d;for(m=0;m=s;s++){var u=0===s||10===s?!0:!1,x=5===s?!0:!1,q=[],p=[];for(g=0;g<=f;g++)if(x){var A=gMath.abs(A.x)&&(A.x=0),1E-5>Math.abs(A.y)&&(A.y=0),1E-5>Math.abs(A.z)&&(A.z=0),m=c?new $3Dmol.Vector3(0,Math.cos(0+D*t), +0):new $3Dmol.Vector3(A.x,A.y,A.z),m.normalize(),h.push(A),l.push(m),q.push(h.length-1)):q.push(h.length-f)}x&&w.push(p);w.push(q)}f={vertices:h,normals:l,verticesRows:w,w:f,h:10};return this.cache[c][b]=f}},t=0;b.drawCylinder=function(b,d,f,h,l,m,w){if(d&&f){t++;var e=m||w,G=!1;1==m&&1==w&&(G=!0);l=l||{r:0,g:0,b:0};var g=[f.x,f.y,f.z];g[0]-=d.x;g[1]-=d.y;g[2]-=d.z;var g=c(g),s=p.getVerticesForRadius(h,G);h=s.w;var G=s.h,u=e?G*h+2:2*h;b=b.updateGeoGroup(u);var x=s.vertices,q=s.normals,s=s.verticesRows, +A=s[G/2],I=s[G/2+1],D=b.vertices,C,B,F,J,L,K,H=b.vertexArray,M=b.normalArray,O=b.colorArray,R=b.faceArray;for(F=0;Fb&&(f=10,d=8);var l=2*Math.PI,m=Math.PI,w,e;for(e=0;e<=d;e++){var t=[];for(w=0;w<=f;w++){var g=w/f,s=e/d,u={};u.x=-b*Math.cos(0+ +g*l)*Math.sin(0+s*m);u.y=b*Math.cos(0+s*m);u.z=b*Math.sin(0+g*l)*Math.sin(0+s*m);g=new $3Dmol.Vector3(u.x,u.y,u.z);g.normalize();c.vertices.push(u);c.normals.push(g);t.push(c.vertices.length-1)}c.verticesRows.push(t)}return this.cache[b]=c}};b.drawSphere=function(b,c,f,d){new $3Dmol.Vector3(c.x,c.y,c.z);var l=A.getVerticesForRadius(f),m=l.vertices,w=l.normals;b=b.updateGeoGroup(m.length);for(var e=b.vertices,t=b.vertexArray,g=b.colorArray,s=b.faceArray,u=b.lineArray,x=b.normalArray,q=0,p=m.length;q< +p;++q){var I=3*(e+q),D=m[q];t[I]=D.x+c.x;t[I+1]=D.y+c.y;t[I+2]=D.z+c.z;g[I]=d.r;g[I+1]=d.g;g[I+2]=d.b}b.vertices+=m.length;l=l.verticesRows;t=l.length-1;for(d=0;dd.lengthSq()&&(d=f.clone(),1E-4m;m++)g[d+3*m]=c.x,g[d+3*m+1]=c.y,g[d+3*m+2]=c.z;c=b.normalArray;h=b.colorArray;for(m=0;4>m;m++)h[d+3*m]=e.r,h[d+3*m+1]=e.g,h[d+3*m+2]=e.b;c[d+0]=-l;c[d+1]=l;c[d+2]=0;c[d+3]=-l;c[d+4]=-l;c[d+5]=0;c[d+6]=l;c[d+7]=-l;c[d+8]=0;c[d+9]=l;c[d+10]=l;c[d+11]=0;b.vertices+=4;l=b.faceArray; +e=b.faceidx;l[e+0]=f;l[e+1]=f+1;l[e+2]=f+2;l[e+3]=f+2;l[e+4]=f+3;l[e+5]=f;b.faceidx+=6},B=function(b,c){if(b.style.sphere){var l=b.style.sphere;if(!l.hidden){var e=x(b,l),l=$3Dmol.getColorFromStyle(b,l);C(c,b,e,l)}}},F=function(b,c,l,e,f,d,g){b=b.updateGeoGroup(4);d=b.vertices;g=b.vertexArray;var h=b.colorArray,m=b.radiusArray,w=b.normalArray,q=f.r,u=f.g;f=f.b;for(var s=3*d,x=0;4>x;x++){g[s]=c.x;w[s]=l.x;h[s]=q;s++;g[s]=c.y;w[s]=l.y;h[s]=u;s++;g[s]=c.z;w[s]=l.z;if(2>x)h[s]=f;else{var t=s,y=-f;0== +y&&(y=-1E-4);h[t]=y}s++}b.vertices+=4;m[d]=-e;m[d+1]=e;m[d+2]=-e;m[d+3]=e;c=b.faceArray;l=b.faceidx;c[l+0]=d;c[l+1]=d+1;c[l+2]=d+2;c[l+3]=d+2;c[l+4]=d+3;c[l+5]=d;b.faceidx+=6};this.getCrystData=function(){return e.cryst?e.cryst:null};this.getSymmetries=function(){"undefined"==typeof e.symmetries&&(e.symmetries=[G]);return e.symmetries};this.setSymmetries=function(b){e.symmetries="undefined"==typeof b?[G]:b};this.getID=function(){return b};this.getFrames=function(){return f};this.setFrame=function(b){0!= +f.length&&(z=0<=b&&b=h)g=l;else{d=$3Dmol.getExtent(l);e=[[],[],[]];for(f=0;3>f;f++)e[0][f]=d[0][f]-h,e[1][f]=d[1][f]+h,e[2][f]=d[2][f];h=[];for(f=0;f=e[0][0]&&g<=e[1][0]&&m>=e[0][1]&&m<=e[1][1]&&w>=e[0][2]&&w<=e[1][2]&&(g>=d[0][0]&&g<=d[1][0]&&m>=d[0][1]&&m<=d[1][1]&&w>=d[0][2]&&w<=d[1][2]||h.push(z[f]))}g=h}m=l.length; +for(d=0;d=g||(f={b:f,e:g},g=e.bondOrder[d],1!=g&&(f.o=g),c.b.push(f))}}return c};this.globj=function(b,c){if(null===l){var d=z,f=c,f=f||{},w=new $3Dmol.Object3D,s=[],u={},t={},y=I,A=null,p=null;f.supportsImposters?(y=B,A=new $3Dmol.Geometry(!0),A.imposter=!0,p=new $3Dmol.Geometry(!0,!0),p.imposter=!0,p.sphereGeometry=A,p.drawnCaps={}):(f.supportsAIA?(y=D,A=new $3Dmol.Geometry(!1,!0,!0),A.instanced=!0):A=new $3Dmol.Geometry(!0),p=new $3Dmol.Geometry(!0)); +var G,J,E,aa,T={},Z=[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY];G=0;for(E=d.length;GBa;Ba++){var Ha=3*Na.vertices;Na.vertices++;Pa[Ha]=U.x+Ga[Ba][0];Pa[Ha+1]=U.y+Ga[Ba][1];Pa[Ha+2]= +U.z+Ga[Ba][2];ab[Ha]=Oa.r;ab[Ha+1]=Oa.g;ab[Ha+2]=Oa.b;if(Ta){var Qa=new $3Dmol.Vector3(Ga[Ba][0],Ga[Ba][1],Ga[Ba][2]);Qa.multiplyScalar(.1);Qa.set(Qa.x+U.x,Qa.y+U.y,Qa.z+U.z);U.intersectionShape.line.push(Qa)}}}}var fa=W,zb=d,kb=u;if(fa.style.line){var rb=fa.style.line;if(!rb.hidden){var lb=rb.linewidth||1;kb[lb]||(kb[lb]=new $3Dmol.Geometry);for(var ua=kb[lb].updateGeoGroup(6*fa.bonds.length),ka=ua.vertexArray,la=ua.colorArray,Ia=0;Ia=Ra.serial)){var Ca=new $3Dmol.Vector3(fa.x,fa.y,fa.z),Ua=new $3Dmol.Vector3(Ra.x,Ra.y,Ra.z),gb=Ca.clone().add(Ua).multiplyScalar(.5),sb=!1;fa.clickable&&(void 0===fa.intersectionShape&&(fa.intersectionShape={sphere:[],cylinder:[],line:[],triangle:[]}),fa.intersectionShape.line.push(Ca),fa.intersectionShape.line.push(Ua));var qa=$3Dmol.getColorFromStyle(fa,fa.style.line),Ja=$3Dmol.getColorFromStyle(Ra,Ra.style.line);if(fa.bondStyles&&fa.bondStyles[Ia]){var Sa=fa.bondStyles[Ia];if(!Sa.iswire)continue; +Sa.radius&&(bondR=Sa.radius);Sa.singleBond&&(sb=!0);"undefined"!=typeof Sa.color1&&(qa=$3Dmol.CC.color(Sa.color1));"undefined"!=typeof Sa.color2&&(Ja=$3Dmol.CC.color(Sa.color2))}var ma=3*ua.vertices;if(1fa.bondOrder[Ia]&&!sb){var Xa=q(fa,Ra,Ia),Da=Ua.clone();Da.sub(Ca);if(2==fa.bondOrder[Ia])if(Xa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Xa),p1b=Ca.clone(),p1b.sub(Xa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),qa==Ja)ua.vertices+=4,N(ka,la,ma,p1a,p2a,qa),N(ka,la, +ma+6,p1b,p2b,qa);else{ua.vertices+=8;Da.multiplyScalar(.5);var Va=p1a.clone();Va.add(Da);var Wa=p1b.clone();Wa.add(Da);N(ka,la,ma,p1a,Va,qa);N(ka,la,ma+6,Va,p2a,Ja);N(ka,la,ma+12,p1b,Wa,qa);N(ka,la,ma+18,Wa,p2b,Ja)}else 3==fa.bondOrder[Ia]&&(Xa.multiplyScalar(.1),p1a=Ca.clone(),p1a.add(Xa),p1b=Ca.clone(),p1b.sub(Xa),p2a=p1a.clone(),p2a.add(Da),p2b=p1b.clone(),p2b.add(Da),qa==Ja?(ua.vertices+=6,N(ka,la,ma,Ca,Ua,qa),N(ka,la,ma+6,p1a,p2a,qa),N(ka,la,ma+12,p1b,p2b,qa)):(ua.vertices+=12,Da.multiplyScalar(.5), +Va=p1a.clone(),Va.add(Da),Wa=p1b.clone(),Wa.add(Da),N(ka,la,ma,Ca,gb,qa),N(ka,la,ma+6,gb,Ua,Ja),N(ka,la,ma+12,p1a,Va,qa),N(ka,la,ma+18,Va,p2a,Ja),N(ka,la,ma+24,p1b,Wa,qa),N(ka,la,ma+30,Wa,p2b,Ja)))}else qa==Ja?(ua.vertices+=2,N(ka,la,ma,Ca,Ua,qa)):(ua.vertices+=4,N(ka,la,ma,Ca,gb,qa),N(ka,la,ma+6,gb,Ua,Ja))}}}}var ca=W,Ab=d,ia=p;if(ca.style.stick){var Ya=ca.style.stick;if(!Ya.hidden){var bb=Ya.radius||.25,va=bb,tb=Ya.singleBonds||!1,cb=0,db=0,na=$3Dmol.getColorFromStyle(ca,Ya),oa=void 0,ya=void 0; +!ca.capDrawn&&4>ca.bonds.length&&(cb=2);var ja=$3Dmol.GLDraw.drawCylinder;ia.imposter&&(ja=F);for(var pa=0;paha.bonds.length&&(db=2),na!=Ka?(oa=(new $3Dmol.Vector3).addVectors(ra,Aa).multiplyScalar(.5),ja(ia,ra,oa,va,na,cb,0),ja(ia,oa,Aa,va,Ka,0,db)):ja(ia,ra,Aa,va,na,cb,db),ca.clickable||ha.clickable){oa=(new $3Dmol.Vector3).addVectors(ra,Aa).multiplyScalar(.5);if(ca.clickable){var Bb=new $3Dmol.Cylinder(ra,oa,va),Cb=new $3Dmol.Sphere(ra,va);ca.intersectionShape.cylinder.push(Bb);ca.intersectionShape.sphere.push(Cb)}if(ha.clickable){var Db= +new $3Dmol.Cylinder(Aa,oa,va),Eb=new $3Dmol.Sphere(Aa,va);ha.intersectionShape.cylinder.push(Db);ha.intersectionShape.sphere.push(Eb)}}}else if(1Z[1]&&(Z[1]=W.resi)),s.push(W))}}if(0T.sphere&&0<=T.sphere&&($a.transparent=!0,$a.opacity=T.sphere);fb=new $3Dmol.Mesh(A,$a);w.add(fb)}if(0T.stick&&0<=T.stick&&(hb.transparent=!0,hb.opacity=T.stick);p.initTypedArrays();hb.wireframe&&p.setUpWireframe();xb=new $3Dmol.Mesh(p,hb)}w.add(xb)}for(G in u)if(u.hasOwnProperty(G)){var ob=G,pb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>T.line&&0<=T.line&&(pb.transparent=!0,pb.opacity=T.line);u[G].initTypedArrays();var Gb=new $3Dmol.Line(u[G], +pb,$3Dmol.LinePieces);w.add(Gb)}for(G in t)if(t.hasOwnProperty(G)){var ob=G,qb=new $3Dmol.LineBasicMaterial({linewidth:ob,vertexColors:!0});1>T.cross&&0<=T.cross&&(qb.transparent=!0,qb.opacity=T.cross);t[G].initTypedArrays();var Hb=new $3Dmol.Line(t[G],qb,$3Dmol.LinePieces);w.add(Hb)}if(g&&e.symmetries&&0MOLECULE/gm)?"mol2":b.match(/^HETATM/gm)||b.match(/^ATOM/gm)?"pdb":b.match(/^.*\n.*\n.\s*(\d+)\s+(\d+)/gm)?"sdf":"xyz",console.log("Best guess: "+c)));return(0,$3Dmol.Parsers[c])(b,d)};b.setAtomDefaults=function(b,d){for(var t=0;tb.mid?b.mid:.618034;var h=b.start,e=b.end,t=b.radius,g=b.radiusRatio,s=b.mid;if(h&&e){var c=f.updateGeoGroup(51),u=e.clone();u.sub(h).multiplyScalar(s);var x=h.clone().add(u),s=u.clone().negate();this.intersectionShape.cylinder.push(new $3Dmol.Cylinder(h.clone(),x.clone(),t));this.intersectionShape.sphere.push(new $3Dmol.Sphere(h.clone(), +t));var q=[];q[0]=u.clone();1E-4 +this.opacity?!0:!1,opacity:this.opacity,wireframeLinewidth:this.linewidth}):new $3Dmol.MeshLambertMaterial({wireframe:this.wireframe,side:this.side,transparent:1>this.opacity?!0:!1,opacity:this.opacity,wireframeLinewidth:this.linewidth});d=new $3Dmol.Mesh(f,d);y.add(d);d=new $3Dmol.LineBasicMaterial({linewidth:this.linewidth,color:this.color});d=new $3Dmol.Line(h,d,$3Dmol.LinePieces);y.add(d);z=y.clone();b.add(z)}};this.removegl=function(b){z&&(void 0!==z.geometry&&z.geometry.dispose(),void 0!==z.material&& +z.material.dispose(),b.remove(z),z=null);y=null}}var c=function(b,c,p){var z=p.faceArr;0!==p.vertexArr.length&&0!==z.length||console.warn("Error adding custom shape component: No vertices and/or face indices supplied!");z=p.color;"undefined"==typeof z&&(z=b.color);for(var z=$3Dmol.CC.color(z),f=$3Dmol.splitMesh(p),h=0,l=f.length;hb.vertexArr.length)return[b];var c=[{vertexArr:[],normalArr:[],faceArr:[]}];b.colorArr&&(c.colorArr=[]);for(var d=[],p=[],y=0,A=b.faceArr,q=0,B=A.length;qw;w++){var h=A[q+w];d[h]!==y&&(d[h]=y,p[h]=f.vertexArr.length,f.vertexArr.push(b.vertexArr[h]),b.normalArr&&b.normalArr[h]&&f.normalArr.push(b.normalArr[h]),b.colorArr&&b.colorArr[h]&&f.colorArr.push(b.colorArr[h]));f.faceArr.push(p[h])}64E3<=f.vertexArr.length&&(c.push({vertexArr:[], -normalArr:[],faceArr:[]}),b.colorArr&&(c.colorArr=[]),y++)}return c}; -$3Dmol.GLViewer=function(){return function(b,c){function d(b){var c=[];"undefined"===typeof b&&(b={});var f=[],g;if("undefined"===typeof b.model)for(g=0;gb&&(b=i);return b+1},T=function(b){if(J){var c=G.position.z-I.position.z;1>c&&(c=1);G.near=c+O;1>G.near&&(G.near=1);G.far=c+Q;G.near+1>G.far&&(G.far=G.near+1);G instanceof $3Dmol.Camera?G.fov=20:(G.right=c*Math.tan(Math.PI/180*20),G.left=-G.right,G.top=G.right/ -E,G.bottom=-G.top);G.updateProjectionMatrix();J.fog.near=G.near+.4*(G.far-G.near);J.fog.far=G.far;C.render(J,G);if(!b&&0b&&(b=80),I.position.z=X+d*b,150c||1h&&(h=5);O=-h/1.9;Q=h/2;h=f[1][0]-f[0][0];m=f[1][1]-f[0][1];c=f[1][2]-f[0][2];h=Math.sqrt(h*h+m*m+c*c);5>h&&(h=5);f=25;for(h=0;hf&&(f=m));h=2*Math.sqrt(f);I.position.z=-(.5*h/Math.tan(Math.PI/180*G.fov/2)-150);T();return this};this.setSlab=function(b,c){O=b;Q=c};this.getSlab=function(b){return{near:O,far:Q}};this.addLabel=function(b,c){var e=new $3Dmol.Label(b,c); -e.setContext();K.add(e.sprite);x.push(e);T();return e};this.addResLabels=function(b,c){p("addResLabels",b,this,c);return this};this.removeLabel=function(b){for(var c=0;cl){b.start=e;b.end=f;c.addLine(b);break}s.addVectors(e,h);b.start=e;b.end=s;c.addLine(b); -e=s.clone();t+=d;s.addVectors(e,m);e=s.clone();t+=w}}else c.addLine(b);g.push(c);return c};this.addUnitCell=function(b){var c=new $3Dmol.GLShape({wireframe:!0});c.shapePosition=g.length;var e=b.getCrystData();if(e){b=e.a;var f=e.b,d=e.c,h=e.alpha,m=e.beta,e=e.gamma,h=h*Math.PI/180,m=m*Math.PI/180,e=e*Math.PI/180,l;l=Math.cos(m);h=(Math.cos(h)-Math.cos(m)*Math.cos(e))/Math.sin(e);m=Math.sqrt(Math.max(0,1-l*l-h*h));b=new $3Dmol.Matrix4(b,f*Math.cos(e),d*l,0,0,f*Math.sin(e),d*h,0,0,0,d*m,0,0,0,0,1); -f=[new $3Dmol.Vector3(0,0,0),new $3Dmol.Vector3(1,0,0),new $3Dmol.Vector3(0,1,0),new $3Dmol.Vector3(0,0,1),new $3Dmol.Vector3(1,1,0),new $3Dmol.Vector3(0,1,1),new $3Dmol.Vector3(1,0,1),new $3Dmol.Vector3(1,1,1)];for(d=0;db&&(b=e[c].getFrames().length);return b};this.animate=function(b){S=!0;var c=100,e="forward",f=0;b=b||{};b.interval&&(c=b.interval);b.loop&&(e=b.loop);b.reps&&(f=b.reps);var d=this.getFrames(),g=this,h=0,m=1,l=0,w=d*f,s=setInterval(function(){var b=e;"forward"==b?(g.setFrame(h), -h=(h+m)%d):"backward"==b?(g.setFrame(d-1-h),h=(h+m)%d):(g.setFrame(h),h+=m,m*=0==h%(d-1)?-1:1);g.render();++l!=w&&g.isAnimated()||clearInterval(s)},c);return this};this.stopAnimate=function(){S=!1;return this};this.isAnimated=function(){return S};this.addModel=function(b,c,f){var d=new $3Dmol.GLModel(e.length,q);d.addMolData(b,c,f);e.push(d);return d};this.addModels=function(b,c,f){f=f||{};f.multimodel=!0;f.frames=!0;b=$3Dmol.GLModel.parseMolData(b,c,f);for(c=0;cc[1][0]||d.yc[1][1]||d.zc[1][2]||f.push(e))}return f},Ta=function(b){return(b[1][0]-b[0][0])*(b[1][1]-b[0][1])*(b[1][2]-b[0][2])},$a=function(b,c,f){var e=[],d=function(b){var c=[];c[0]=[b[0][0],b[0][1],b[0][2]];c[1]=[b[1][0],b[1][1],b[1][2]];return c},h=function(b){if(64E3>Ta(b))return[b];var c=b[1][0]-b[0][0],f=b[1][1]-b[0][1],e=b[1][2]-b[0][2],f=c>f&&c>e?0:f>c&&f>e?1:2,e=d(b),c=d(b);b=(b[1][f]-b[0][f])/2+b[0][f];e[1][f]=b;c[0][f]=b;b=h(e); -c=h(c);return b.concat(c)};b=h(b);for(var g=0,m=b.length;g= -p.length)){var d;d=b;var g=p[c].extent,l=p[c].atoms,m=p[c].toshow,w=new $3Dmol.ProteinSurface;w.initparm(g,1===d?!1:!0,x);w.fillvoxels(y,l);w.buildboundary();d==$3Dmol.SurfaceType.SES&&(w.fastdistancemap(),w.boundingatom(!1),w.fillvoxelswaals(y,l));w.marchingcube(d);d=w.getFacesAndVertices(m);d=Ua(e,d,u);$3Dmol.mergeGeos(f.geo,d);h.render();setTimeout(ga,1,c+1)}},1,0);else{g=[];0>b&&(b=0);t=0;for(q=4;tB&&(y=B);var f=(B+q)/2;"undefined"!=typeof d&&(f=d);y<=f?(q=Math.floor(255*Math.sqrt((y-q)/(f-q))),q=16711680+256*q+q):(q=Math.floor(255*Math.sqrt(1-(y-f)/(B-f))),q=65536*q+256*q+255);return q};this.range=function(){return"undefined"!=typeof b&&"undefined"!= +$3Dmol.splitMesh=function(b){if(64E3>b.vertexArr.length)return[b];var c=[{vertexArr:[],normalArr:[],faceArr:[]}];b.colorArr&&(c.colorArr=[]);for(var d=[],p=[],t=0,A=b.faceArr,y=0,z=A.length;yh;h++){var l=A[y+h];d[l]!==t&&(d[l]=t,p[l]=f.vertexArr.length,f.vertexArr.push(b.vertexArr[l]),b.normalArr&&b.normalArr[l]&&f.normalArr.push(b.normalArr[l]),b.colorArr&&b.colorArr[l]&&f.colorArr.push(b.colorArr[l]));f.faceArr.push(p[l])}64E3<=f.vertexArr.length&&(c.push({vertexArr:[], +normalArr:[],faceArr:[]}),b.colorArr&&(c.colorArr=[]),t++)}return c}; +$3Dmol.GLViewer=function(){return function(b,c){function d(b){var c=[];"undefined"===typeof b&&(b={});var d=[],f;if("undefined"===typeof b.model)for(f=0;fb&&(b=i);return b+1},U=function(){var b=C.position.z-H.position.z;1>b&&(b=1);C.near=b+O;1>C.near&&(C.near=1);C.far=b+R;C.near+1>C.far&&(C.far=C.near+1);C.fov=20;C.right=b*Math.tan(Math.PI/180*20);C.left=-C.right;C.top=C.right/N;C.bottom=-C.top;C.updateProjectionMatrix(); +K.fog.near=C.near+.4*(C.far-C.near);K.fog.far=C.far},X=function(b){if(K&&(U(),D.render(K,C),!b&&0b&&(b=80),H.position.z=aa+l*b,150c||1l&&(l=5);O=-l/1.9;R=l/2;l=f[1][0]-f[0][0];h=f[1][1]-f[0][1];c=f[1][2]-f[0][2];l=Math.sqrt(l*l+h*h+c*c);5>l&&(l=5);f=25;for(l=0;lf&&(f=h));l=2*Math.sqrt(f);H.position.z=-(.5*l/Math.tan(Math.PI/180*C.fov/2)-150);X();return this}; +this.setSlab=function(b,c){O=b;R=c};this.getSlab=function(b){return{near:O,far:R}};this.addLabel=function(b,c){var d=new $3Dmol.Label(b,c);d.setContext();M.add(d.sprite);s.push(d);X();return d};this.addResLabels=function(b,c){p("addResLabels",b,this,c);return this};this.removeLabel=function(b){for(var c=0;cm){b.start=d;b.end=e;c.addLine(b);break}s.addVectors(d,l);b.start=d;b.end=s;c.addLine(b);d=s.clone();w+=f;s.addVectors(d,h);d=s.clone();w+=q}}else c.addLine(b);g.push(c);return c};this.addUnitCell=function(b){var c=new $3Dmol.GLShape({wireframe:!0});c.shapePosition=g.length;var d=b.getCrystData();if(d){b=d.a;var e=d.b,f=d.c,l=d.alpha,h=d.beta,d=d.gamma,l=l*Math.PI/180,h=h*Math.PI/180,d=d*Math.PI/180,m;m=Math.cos(h);l=(Math.cos(l)-Math.cos(h)*Math.cos(d))/ +Math.sin(d);h=Math.sqrt(Math.max(0,1-m*m-l*l));b=new $3Dmol.Matrix4(b,e*Math.cos(d),f*m,0,0,e*Math.sin(d),f*l,0,0,0,f*h,0,0,0,0,1);e=[new $3Dmol.Vector3(0,0,0),new $3Dmol.Vector3(1,0,0),new $3Dmol.Vector3(0,1,0),new $3Dmol.Vector3(0,0,1),new $3Dmol.Vector3(1,1,0),new $3Dmol.Vector3(0,1,1),new $3Dmol.Vector3(1,0,1),new $3Dmol.Vector3(1,1,1)];for(f=0;fb&&(b=e[c].getFrames().length);return b};this.animate=function(b){S=!0;var c=100,d="forward",e=0;b=b||{};b.interval&&(c=b.interval);b.loop&&(d=b.loop); +b.reps&&(e=b.reps);var f=this.getFrames(),l=this,h=0,g=1,m=0,q=f*e,s=setInterval(function(){var b=d;"forward"==b?(l.setFrame(h),h=(h+g)%f):"backward"==b?(l.setFrame(f-1-h),h=(h+g)%f):(l.setFrame(h),h+=g,g*=0==h%(f-1)?-1:1);l.render();++m!=q&&l.isAnimated()||clearInterval(s)},c);return this};this.stopAnimate=function(){S=!1;return this};this.isAnimated=function(){return S};this.addModel=function(b,c,d){var f=new $3Dmol.GLModel(e.length,y);f.addMolData(b,c,d);e.push(f);return f};this.addModels=function(b, +c,d){d=d||{};d.multimodel=!0;d.frames=!0;b=$3Dmol.GLModel.parseMolData(b,c,d);for(c=0;cc[1][0]||f.yc[1][1]||f.zc[1][2]||d.push(e))}return d},Pa=function(b){return(b[1][0]-b[0][0])*(b[1][1]-b[0][1])*(b[1][2]-b[0][2])},ab=function(b,c,d){var e=[],f=function(b){var c=[];c[0]=[b[0][0],b[0][1],b[0][2]];c[1]=[b[1][0],b[1][1],b[1][2]];return c},l=function(b){if(64E3>Pa(b))return[b]; +var c=b[1][0]-b[0][0],d=b[1][1]-b[0][1],e=b[1][2]-b[0][2],d=c>d&&c>e?0:d>c&&d>e?1:2,e=f(b),c=f(b);b=(b[1][d]-b[0][d])/2+b[0][d];e[1][d]=b;c[0][d]=b;b=l(e);c=l(c);return b.concat(c)};b=l(b);for(var h=0,g=b.length;h=t.length)){var d;d=b;var h=t[c].extent,g=t[c].atoms,m=t[c].toshow,q=new $3Dmol.ProteinSurface;q.initparm(h,1===d?!1:!0,x);q.fillvoxels(y,g);q.buildboundary();d==$3Dmol.SurfaceType.SES&&(q.fastdistancemap(),q.boundingatom(!1),q.fillvoxelswaals(y,g));q.marchingcube(d);d=q.getFacesAndVertices(m);d=Ba(e,d,p);$3Dmol.mergeGeos(f.geo, +d);l.render();setTimeout(Ya,1,c+1)}},1,0);else{h=[];0>b&&(b=0);w=0;for(u=4;wz&&(t=z);var f=(z+y)/2;"undefined"!=typeof d&&(f=d);t<=f?(y=Math.floor(255*Math.sqrt((t-y)/(f-y))),y=16711680+256*y+y):(y=Math.floor(255*Math.sqrt(1-(t-f)/(z-f))),y=65536*y+256*y+255);return y};this.range=function(){return"undefined"!=typeof b&&"undefined"!= typeof c?[b,c]:null}}; -$3Dmol.Gradient.ROYGB=function(b,c){var d=1;"undefined"==typeof c&&$.isArray(b)&&2<=b.length&&(c=b[1],b=b[0]);cq&&(p=q);var B=(A+q)/2,f=(A+B)/2,w=(B+q)/2;pq&&(p=q);var B=(p-A)/(q-A)*5/6+.5;A=Math.sin(Math.PI*B);A*=255*A;q=Math.sin(Math.PI*(B+1/3));q*=255*q;B=Math.sin(Math.PI*(B+2/3));return 65536*Math.floor(A)+256*Math.floor(255*B*B)+1*Math.floor(q)};this.range=function(){return"undefined"!=typeof b&& +$3Dmol.Gradient.ROYGB=function(b,c){var d=1;"undefined"==typeof c&&$.isArray(b)&&2<=b.length&&(c=b[1],b=b[0]);cy&&(p=y);var z=(A+y)/2,f=(A+z)/2,h=(z+y)/2;py&&(p=y);var z=(p-A)/(y-A)*5/6+.5;A=Math.sin(Math.PI*z);A*=255*A;y=Math.sin(Math.PI*(z+1/3));y*=255*y;z=Math.sin(Math.PI*(z+2/3));return 65536*Math.floor(A)+256*Math.floor(255*z*z)+1*Math.floor(y)};this.range=function(){return"undefined"!=typeof b&& "undefined"!=typeof c?[b,c]:null}};$3Dmol.LabelCount=0;$3Dmol.Label=function(b,c){this.id=$3Dmol.LabelCount++;this.stylespec=c||{};this.canvas=document.createElement("canvas");this.canvas.width=134;this.canvas.height=35;this.context=this.canvas.getContext("2d");this.sprite=new $3Dmol.Sprite;this.text=b}; -$3Dmol.Label.prototype={constructor:$3Dmol.Label,getStyle:function(){return this.stylespec},setContext:function(){var b=function(b,d,p){"undefined"!=typeof b&&(p=b instanceof $3Dmol.Color?b.scaled():$3Dmol.CC.color(b).scaled());"undefined"!=typeof d&&(p.a=parseFloat(d));return p};return function(){var c=this.stylespec,d="undefined"==typeof c.useScreen?!1:c.useScreen,p=c.showBackground;if("0"===p||"false"===p)p=!1;"undefined"==typeof p&&(p=!0);var y=c.font?c.font:"sans-serif",A=parseInt(c.fontSize)? -parseInt(c.fontSize):18,q=b(c.fontColor,c.fontOpacity,{r:255,g:255,b:255,a:1}),B=c.padding?c.padding:4,f=c.borderThickness?c.borderThickness:0,w=b(c.backgroundColor,c.backgroundOpacity,{r:0,g:0,b:0,a:1}),h=b(c.borderColor,c.borderOpacity,w),t=c.position?c.position:{x:-10,y:1,z:1},m=void 0!==c.inFront?c.inFront:!0;if("false"===m||"0"===m)m=!1;var e=c.alignment||$3Dmol.SpriteAlignment.topLeft,F="";c.bold&&(F="bold ");this.context.font=F+A+"px "+y;var g=this.context.measureText(this.text).width;p|| -(f=0);var x=g+2.5*f+2*B,u=1.25*A+2*f+2*B;if(c.backgroundImage){var F=c.backgroundImage,s=c.backgroundWidth?c.backgroundWidth:F.width,l=c.backgroundHeight?c.backgroundHeight:F.height;s>x&&(x=s);l>u&&(u=l)}this.canvas.width=x;this.canvas.height=u;this.context.clearRect(0,0,this.canvas.width,this.canvas.height);F="";c.bold&&(F="bold ");this.context.font=F+A+"px "+y;this.context.fillStyle="rgba("+w.r+","+w.g+","+w.b+","+w.a+")";this.context.strokeStyle="rgba("+h.r+","+h.g+","+h.b+","+h.a+")";this.context.lineWidth= -f;p&&(p=this.context,w=y=f,x-=2*f,u-=2*f,h=0u[b]&&(u[b]=q.length,q.push(m));return u[b]},s=new Int32Array(12),l=w?p:c,w=w?y:d;for(f=0;fG;++G)C|=!!(b[(e*(f+((G&4)>>2))+E+((G&2)>>1))*F+M+(G&1)]&2)<w;w++)e[w]=Array(c.length);w=0;for(h=c.length;we[0][w])f[w].x=c[w].x,f[w].y=c[w].y,f[w].z=c[w].z;else if(3==e[0][w]||4==e[0][w]){f[w].x=0;f[w].y=0;t=f[w].z=0;for(m=e[0][w];tMath.abs(e.resi-m.resi)||(pt.length)return h;for(var m=t[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),e=Math.abs(parseFloat(m[0])),m=t[3].replace(/^\s+/,"").replace(/\s+/g, -" ").split(" "),m=0t.length);){var m=parseInt(t[0]);if(isNaN(m)||0>=m)break;if(t.lengthm.length);){var e=parseInt(m[3].substr(0,3));if(isNaN(e)|| -0>=e)break;var p=parseInt(m[3].substr(3,3)),g=4;if(m.length<4+e+p)break;for(var q=[],u=d[d.length-1].length,s=u+e,l,e=u;eM;M++)for(G=C[M].split("+"),H=0;HMOLECULE/), -p=b.search(/@ATOM/);if(-1==e||-1==p)break;var e=[],g=m[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),x=parseInt(g[0]),p=0;1ATOM"==m[s]){u=s+1;break}s=d[d.length-1].length;for(x=s+x;sBOND"==m[u++]){s=!0;break}if(s&&p)for(s=0;sd)return!1;var m=b.y-c.y,m=m*m;if(m>d)return!1;var e=b.z-c.z,e=e*e;if(e>d)return!1;p=p+m+e;return isNaN(p)?!1:.5>p?!1:p>d?!1:!0},B=function(b,c,d){var p=d.length,m=p,e,q;if(!c)for(c=0;cz;z++){if(J=parseInt(H.substr([11,16,21,26][z],5)),J=M[J], -I=h[h.length-1][J],void 0!==N&&void 0!==I)if(L[[u,J]])for(L[[u,J]]+=1,I=0;I=N;N++)if(H=C[G].replace(/^\s*/,""),parseInt(H.substr(18,1))==N)z.elements[N-1]=parseFloat(H.substr(23,10)),z.elements[N-1+4]=parseFloat(H.substr(33,10)),z.elements[N-1+8]=parseFloat(H.substr(43,10)),z.elements[N-1+12]=parseFloat(H.substr(53)),G++;else for(;"BIOMT"==H.substr(13,5);)G++,H=C[G].replace(/^\s*/, -"");z.elements[3]=0;z.elements[7]=0;z.elements[11]=0;z.elements[15]=1;g[g.length-1].symmetries.push(z);G--}}(new Date).getTime();for(N=0;Ns[z][3]||(u.ss="s",u.resi==s[z][1]&&(u.ssbegin=!0),u.resi==s[z][3]&&(u.ssend=!0));for(z=0;zl[z][3]|| -(u.ss="h",u.resi==l[z][1]?u.ssbegin=!0:u.resi==l[z][3]&&(u.ssend=!0))}}return h};b.pqr=b.PQR=function(b,c){var h=[[]],p,m=!c.noSecondaryStructure,e=[],q=b.split(/\r?\n|\r/),g,x;for(g=0;gp;p++)s=parseInt(x.substr([11,16,21, -26][p],5)),l=h[h.length-1][e[s]],void 0!==u&&void 0!==l&&(u.bonds.push(e[s]),u.bondOrder.push(1));for(g=0;gs&&(s=x);q>u&&(u=q)}this.canvas.width=s;this.canvas.height=u;this.context.clearRect(0,0,this.canvas.width,this.canvas.height);G="";c.bold&&(G="bold ");this.context.font=G+A+"px "+t;this.context.fillStyle="rgba("+h.r+","+h.g+","+h.b+","+h.a+")";this.context.strokeStyle="rgba("+l.r+","+l.g+","+l.b+","+l.a+")";this.context.lineWidth= +f;p&&(p=this.context,h=t=f,s-=2*f,u-=2*f,l=0x[b]&&(x[b]=y.length,y.push(q));return x[b]},q=new Int32Array(12),N=h?p:c,h=h?t:d;for(f=0;fB;++B)C|=!!(b[(G*(f+((B&4)>>2))+I+((B&2)>>1))*g+D+(B&1)]&2)<h;h++)e[h]=Array(c.length);h=0;for(l=c.length;he[0][h])f[h].x=c[h].x,f[h].y=c[h].y,f[h].z=c[h].z;else if(3==e[0][h]||4==e[0][h]){f[h].x=0;f[h].y=0;m=f[h].z=0;for(w=e[0][h];mMath.abs(e.resi-w.resi)||(pg.length)return d;if(g[1].match(/\d+/))m=parseFloat(g[1]);else return console.log("Warning: second line of the vasp structure file must be a number"), +d;if(0>m)return console.log("Warning: Vasp implementation for negative lattice lengths is not yet available"),d;w=new Float32Array(g[2].replace(/^\s+/,"").split(/\s+/));e=new Float32Array(g[3].replace(/^\s+/,"").split(/\s+/));p=new Float32Array(g[4].replace(/^\s+/,"").split(/\s+/));var s=g[5].replace(/\s+/,"").replace(/\s+$/,"").split(/\s+/),u=new Int16Array(g[6].replace(/^\s+/,"").split(/\s+/)),t=g[7].replace(/\s+/,"");if(t.match(/C/))t="cartesian";else if(t.match(/D/))t="direct";else return console.log("Warning: Unknown vasp mode in POSCAR file: mode must be either C(artesian) or D(irect)"), +d;if(s.length!=u.length)return console.log("Warning: declaration of atomary species wrong:"),console.log(s),console.log(u),d;g.splice(0,8);for(var q=0,y=0,z=s.length;ym.length)return l;for(var w=m[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),e=Math.abs(parseFloat(w[0])),w=m[3].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),w=0m.length);){var w=parseInt(m[0]);if(isNaN(w)||0>=w)break;if(m.lengthp.length);){var e=parseInt(p[3].substr(0,3));if(isNaN(e)||0>=e)break;var t=parseInt(p[3].substr(3,3)),g=4;if(p.length<4+e+t)break;for(var s=[],u=d[d.length-1].length,x=u+e,q,e=u;eI;I++)for(C=D[I].split("+"),F=0;FMOLECULE/),t=b.search(/@ATOM/);if(-1==e||-1==t)break;var e=[],g=p[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),s=parseInt(g[0]),t=0;1ATOM"==p[x]){u=x+1;break}x=d[d.length-1].length;for(s=x+s;xBOND"==p[u++]){x=!0;break}if(x&&t)for(x=0;xd)return!1;var p=b.y-c.y,p=p*p;if(p>d)return!1;var e=b.z-c.z,e=e*e;if(e>d)return!1;m=m+p+e;return isNaN(m)?!1:.5>m?!1:m>d?!1:!0},z=function(b,c,d){var m=d.length,p=m,e,t;if(!c)for(c=0;cB;B++){if(K=parseInt(F.substr([11,16,21,26][B],5)),K=I[K],H=l[l.length-1][K],void 0!==L&&void 0!==H)if(J[[u,K]])for(J[[u,K]]+=1,H=0;H=L;L++)if(F=D[C].replace(/^\s*/,""),parseInt(F.substr(18,1))==L)B.elements[L-1]=parseFloat(F.substr(23,10)), +B.elements[L-1+4]=parseFloat(F.substr(33,10)),B.elements[L-1+8]=parseFloat(F.substr(43,10)),B.elements[L-1+12]=parseFloat(F.substr(53)),C++;else for(;"BIOMT"==F.substr(13,5);)C++,F=D[C].replace(/^\s*/,"");B.elements[3]=0;B.elements[7]=0;B.elements[11]=0;B.elements[15]=1;g[g.length-1].symmetries.push(B);C--}}(new Date).getTime();for(L=0;Lx[B][3]||(u.ss="s",u.resi==x[B][1]&&(u.ssbegin=!0),u.resi==x[B][3]&&(u.ssend=!0));for(B=0;Bq[B][3]||(u.ss="h",u.resi==q[B][1]?u.ssbegin=!0:u.resi==q[B][3]&&(u.ssend=!0))}}return l};b.pqr=b.PQR=function(b,c){var l=[[]],m,p=!c.noSecondaryStructure;l.modelData=[{symmetries:[]}];var e=[],y=b.split(/\r?\n|\r/),g,s;for(g=0;gm;m++)x=parseInt(s.substr([11,16,21,26][m],5)),q=l[l.length-1][e[x]],void 0!==u&&void 0!==q&&(u.bonds.push(e[x]),u.bondOrder.push(1));for(g=0;gaa,chain:Y,resi:T,icode:ga,rescode:T+(" "!=ga?"^"+ga:""),serial:Na,atom:Fa,bonds:[],ss:2==aa?"h":3==aa?"s":"c",bondOrder:[],properties:{charge:Ga,occupancy:Ea},b:X})}s+=1}aa=E.bondAtomList;L=0;for(K=E.bondOrderList.length;L=s){V=L;break}Z=Q[Z];U=Q[U];X=S[Z];ga=S[U];X&&ga&&(X.bonds.push(U),X.bondOrder.push(T),ga.bonds.push(Z),ga.bondOrder.push(T))}c.multimodel&&(c.onemol||p.push([]))}for(H=0;Hb||b>=this.size.x||0>c||c>=this.size.y||0>d||d>=this.size.z?0:this.data[b*this.size.y*this.size.z+c*this.size.z+d]}; -$3Dmol.VolumeData.prototype.cube=function(b){b=b.replace(/^\s+/,"").split(/[\n\r]+/);if(!(6>b.length)){var c=b[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),d=parseFloat(c[0]),p=Math.abs(d),y=this.origin=new $3Dmol.Vector3(parseFloat(c[1]),parseFloat(c[2]),parseFloat(c[3])),c=b[3].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),A=0d&&c++;b=b.splice(p+c).join(" ");b=b.replace(/^\s+/,"");b=b.split(/[\s\r]+/);this.data=new Float32Array(b)}}; -$3Dmol.VolumeData.prototype.ccp4=function(b){var c,d,p,y,A,q,B,f,w,h,t,m,e,F,g,x=new Int32Array(b,0,56);m=new Float32Array(b,0,56);c=x[0];d=x[1];p=x[2];y=x[4];A=x[5];q=x[6];B=Math.abs(x[7]);f=Math.abs(x[8]);w=Math.abs(x[9]);h=m[10];t=m[11];m=m[12];xVox=h/c;yVox=t/d;zVox=m/p;switch(x[16]){case 1:e=y;g=F=0;break;case 2:F=y;g=e=0;break;case 3:g=y,F=e=0}switch(x[17]){case 1:e=A;g=F=0;break;case 2:F=A;g=e=0;break;case 3:g=A,F=e=0}switch(x[18]){case 1:e=q;g=F=0;break;case 2:F=q;g=e=0;break;case 3:g=q,F= -e=0}this.origin=new $3Dmol.Vector3(e,F,g);c=x[23];this.size={x:B,y:f,z:w};this.unit=new $3Dmol.Vector3(xVox,yVox,zVox);new Int8Array(b);this.data=new Float32Array(b,1024+c)}; +$3Dmol.VolumeData.prototype.vasp=function(b){var c=b.replace(/^\s+/,"").split(/[\n\r]/),d=$3Dmol.Parsers.vasp(b)[0].length;if(0==d)console.log("No good formating of CHG or CHGCAR file, not atomic information provided in the file."),this.data=[];else{var p=parseFloat(c[1]),t;t=c[2].replace(/^\s+/,"").split(/\s+/);b=(new $3Dmol.Vector3(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]))).multiplyScalar(1.889725992*p);t=c[3].replace(/^\s+/,"").split(/\s+/);var A=(new $3Dmol.Vector3(parseFloat(t[0]), +parseFloat(t[1]),parseFloat(t[2]))).multiplyScalar(1.889725992*p);t=c[4].replace(/^\s+/,"").split(/\s+/);t=(new $3Dmol.Vector3(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]))).multiplyScalar(1.889725992*p);p=b.x*(A.y*t.z-t.y*A.z)-A.x*(b.y*t.z-t.y*b.z)+t.x*(b.y*A.z-A.y*b.z);p=Math.abs(p)/Math.pow(1.889725992,3);p=1/p;c.splice(0,8+d+1);var y=c[0].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),d=Math.abs(y[0]),z=Math.abs(y[1]),y=Math.abs(y[2]),f=this.origin=new $3Dmol.Vector3(0,0,0);this.size= +{x:d,y:z,z:y};this.unit=new $3Dmol.Vector3(b.x,A.y,t.z);b=b.multiplyScalar(1/(1.889725992*d));A=A.multiplyScalar(1/(1.889725992*z));t=t.multiplyScalar(1/(1.889725992*y));if(0!=b.y||0!=b.z||0!=A.x||0!=A.z||0!=t.x||0!=t.y)this.matrix=new $3Dmol.Matrix4(b.x,A.x,t.x,0,b.y,A.y,t.y,0,b.z,A.z,t.z,0,0,0,0,1),this.matrix=this.matrix.multiplyMatrices(this.matrix,(new $3Dmol.Matrix4).makeTranslation(f.x,f.y,f.z)),this.origin=new $3Dmol.Vector3(0,0,0),this.unit=new $3Dmol.Vector3(1,1,1);c.splice(0,1);c=c.join(" "); +c=c.replace(/^\s+/,"");c=c.split(/[\s\r]+/);c.splice(d*z*y+1);c=new Float32Array(c);for(b=0;bb.length)){var c=b[2].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),d=parseFloat(c[0]),p=Math.abs(d),t=this.origin=new $3Dmol.Vector3(parseFloat(c[1]),parseFloat(c[2]),parseFloat(c[3])),c=b[3].replace(/^\s+/,"").replace(/\s+/g," ").split(" "),A=0d&&t++;b=b.splice(p+t).join(" ");b=b.replace(/^\s+/,"");b=b.split(/[\s\r]+/);this.data=new Float32Array(b)}}; +$3Dmol.VolumeData.prototype.ccp4=function(b){var c,d,p,t,A,y,z,f,h,l,m,w,e,G,g,s,u,x,q,N,I,D,C,B,F;b=new Int8Array(b);D=new Int32Array(b.buffer,0,56);var J=new Float32Array(b.buffer,0,56);d=new DataView(b.buffer);String.fromCharCode(d.getUint8(208),d.getUint8(209),d.getUint8(210),d.getUint8(211));c=[d.getUint8(212),d.getUint8(213)];if(17===c[0]&&17===c[1])for(c=b.byteLength,t=0;tc)self.atomData=b.atoms,self.volume=b.volume,self.ps=new ProteinSurface;else{var d=self.ps;d.initparm(b.expandedExtent,1==c?!1:!0,self.volume);d.fillvoxels(self.atomData,b.extendedAtoms);d.buildboundary();if(4===c||2===c)d.fastdistancemap(),d.boundingatom(!1),d.fillvoxelswaals(self.atomData,b.extendedAtoms);d.marchingcube(c);b=d.getFacesAndVertices(b.atomsToShow);self.postMessage(b)}}}.toString().replace(/(^.*?\{|\}$)/g, "");$3Dmol.workerString+="; var ProteinSurface="+$3Dmol.ProteinSurface.toString().replace(/\$3Dmol.MarchingCube./g,"MarchingCube.");$3Dmol.workerString+=",MarchingCube=("+$3Dmol.MarchingCubeInitializer.toString()+")();";$3Dmol.SurfaceWorker=window.URL.createObjectURL(new Blob([$3Dmol.workerString],{type:"text/javascript"}));$3Dmol.workerString=$3Dmol.workerString;$3Dmol.SurfaceWorker=$3Dmol.SurfaceWorker; diff --git a/release/3Dmol-nojquery.js b/release/3Dmol-nojquery.js index 290ce79ec..f2a457473 100644 --- a/release/3Dmol-nojquery.js +++ b/release/3Dmol-nojquery.js @@ -1,4 +1,4 @@ -/* pako 0.2.7 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;oe;e++){var n=a();t[n]=a()}return t}function e(t){var e=r.subarray(i,i+t);return i+=t,e}function n(t){var e=r.subarray(i,i+t);i+=t;var n=65535;if(t>n){for(var o=[],a=0;ae;e++)t[e]=a();return t}function a(){var a,s,c,d=r[i];if(0===(128&d))return i++,d;if(128===(240&d))return s=15&d,i++,t(s);if(144===(240&d))return s=15&d,i++,o(s);if(160===(224&d))return s=31&d,i++,n(s);if(224===(224&d))return a=u.getInt8(i),i++,a;switch(d){case 192:return i++,null;case 194:return i++,!1;case 195:return i++,!0;case 196:return s=u.getUint8(i+1),i+=2,e(s);case 197:return s=u.getUint16(i+1),i+=3,e(s);case 198:return s=u.getUint32(i+1),i+=5,e(s);case 199:return s=u.getUint8(i+1),c=u.getUint8(i+2),i+=3,[c,e(s)];case 200:return s=u.getUint16(i+1),c=u.getUint8(i+3),i+=4,[c,e(s)];case 201:return s=u.getUint32(i+1),c=u.getUint8(i+5),i+=6,[c,e(s)];case 202:return a=u.getFloat32(i+1),i+=5,a;case 203:return a=u.getFloat64(i+1),i+=9,a;case 204:return a=r[i+1],i+=2,a;case 205:return a=u.getUint16(i+1),i+=3,a;case 206:return a=u.getUint32(i+1),i+=5,a;case 207:return i+=9,0;case 208:return a=u.getInt8(i+1),i+=2,a;case 209:return a=u.getInt16(i+1),i+=3,a;case 210:return a=u.getInt32(i+1),i+=5,a;case 211:return i+=9,0;case 212:return c=u.getUint8(i+1),i+=2,[c,e(1)];case 213:return c=u.getUint8(i+1),i+=2,[c,e(2)];case 214:return c=u.getUint8(i+1),i+=2,[c,e(4)];case 215:return c=u.getUint8(i+1),i+=2,[c,e(8)];case 216:return c=u.getUint8(i+1),i+=2,[c,e(16)];case 217:return s=u.getUint8(i+1),i+=2,n(s);case 218:return s=u.getUint16(i+1),i+=3,n(s);case 219:return s=u.getUint32(i+1),i+=5,n(s);case 220:return s=u.getUint16(i+1),i+=3,o(s);case 221:return s=u.getUint32(i+1),i+=5,o(s);case 222:return s=u.getUint16(i+1),i+=3,t(s);case 223:return s=u.getUint32(i+1),i+=5,t(s)}throw new Error("Unknown type 0x"+d.toString(16))}var i=0,u=new DataView(r.buffer);return a()}function e(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function n(r){return new Int8Array(r.buffer,r.byteOffset,r.byteLength)}function o(r,t){var e,n,o,a=(r.byteOffset,r.byteLength);for(t||(t=new Int16Array(a/2)),e=0,n=0,o=a/2;o>e;++e,n+=2)t[e]=r[n]<<8^r[n+1]<<0;return t}function a(r,t){var e,n,o,a=(r.byteOffset,r.byteLength);for(t||(t=new Int32Array(a/4)),e=0,n=0,o=a/4;o>e;++e,n+=4)t[e]=r[n]<<24^r[n+1]<<16^r[n+2]<<8^r[n+3]<<0;return t}function i(r){return new Int32Array(r.buffer,r.byteOffset,r.byteLength/4)}function u(r,t,e){var n=r.length,o=1/t;e||(e=new Float32Array(n));for(var a=0;n>a;++a)e[a]=r[a]*o;return e}function s(r,t){var e,n;if(!t){var o=0;for(e=0,n=r.length;n>e;e+=2)o+=r[e+1];t=new r.constructor(o)}var a=0;for(e=0,n=r.length;n>e;e+=2)for(var i=r[e],u=r[e+1],s=0;u>s;++s)t[a]=i,a+=1;return t}function c(r){for(var t=1,e=r.length;e>t;++t)r[t]+=r[t-1];return r}function d(r,t,e){var n=r.length/2+t.length;e||(e=new Int32Array(n));for(var o=0,a=0,i=0,u=r.length;u>i;i+=2){var s=r[i],c=r[i+1];e[o]=s,0!==i&&(e[o]+=e[o-1]),o+=1;for(var d=0;c>d;++d)e[o]=e[o-1]+t[a],o+=1,a+=1}return e}function f(r,t,e,n){var s=r.length/4/2+t.length/2;n||(n=new Float32Array(s));var c=i(n),f=d(a(r),o(t),c);return u(f,e,n)}function g(r,t,e){var n=e?i(e):void 0,o=s(a(r),n);return u(o,t,e)}function l(r,t){function o(r){return i?-1===i.indexOf(r):!0}t=t||{};var i=t.ignoreFields,u=(r.numBonds||0,r.numAtoms||0),d=r.groupTypeList.length/4,l=r.chainIdList.length/4,m=r.chainsPerModel.length,L={numGroups:d,numChains:l,numModels:m};["mmtfVersion","mmtfProducer","unitCell","spaceGroup","structureId","title","depositionDate","releaseDate","experimentalMethods","resolution","rFree","rWork","bioAssemblyList","entityList","groupList","numBonds","numAtoms","groupsPerChain","chainsPerModel"].forEach(function(t){void 0!==r[t]&&(L[t]=r[t])});var h="bondAtomList";r[h]&&o(h)&&(L[h]=a(r[h]));var y="bondOrderList";r[y]&&o(y)&&(L[y]=e(r[y])),L.xCoordList=f(r.xCoordBig,r.xCoordSmall,1e3),L.yCoordList=f(r.yCoordBig,r.yCoordSmall,1e3),L.zCoordList=f(r.zCoordBig,r.zCoordSmall,1e3);var p="bFactorList",v="bFactorBig",C="bFactorSmall";r[v]&&r[C]&&o(p)&&(L[p]=f(r[v],r[C],100));var I="atomIdList";r[I]&&o(I)&&(L[I]=c(s(a(r[I]))));var b="altLocList";r[b]&&o(b)&&(L[b]=s(a(r[b]),new Uint8Array(u)));var U="occupancyList";r[U]&&o(U)&&(L[U]=g(r[U],100)),L.groupIdList=c(s(a(r.groupIdList))),L.groupTypeList=a(r.groupTypeList);var x="secStructList";r[x]&&o(x)&&(L[x]=n(r[x]));var A="insCodeList";r[A]&&o(A)&&(L[A]=s(a(r[A]),new Uint8Array(d)));var w="sequenceIndexList";r[w]&&o(w)&&(L[w]=c(s(a(r[w])))),L.chainIdList=e(r.chainIdList);var F="chainNameList";return r[F]&&o(F)&&(L[F]=e(r[F])),L}function m(r){return String.fromCharCode.apply(null,r).replace(/\0/g,"")}function L(r,t){var e,n,o,a,i=t.onModel,u=t.onChain,s=t.onGroup,c=t.onAtom,d=t.onBond,f=0,g=0,l=0,L=0,h=r.chainNameList,y=r.secStructList,p=r.insCodeList,v=r.sequenceIndexList,C=r.bFactorList,I=r.altLocList,b=r.occupancyList,U=r.bondAtomList,x=r.bondOrderList;if(r.chainsPerModel.forEach(function(t){for(i&&i({chainCount:t,modelIndex:f}),e=0;t>e;++e){var U=r.groupsPerChain[g];if(u){var x=m(r.chainIdList.subarray(4*g,4*g+4)),A=null;h&&(A=m(h.subarray(4*g,4*g+4))),u({groupCount:U,chainIndex:g,modelIndex:f,chainId:x,chainName:A})}for(n=0;U>n;++n){var w=r.groupList[r.groupTypeList[l]],F=w.atomNameList.length;if(s){var S=null;y&&(S=y[l]);var O=null;r.insCodeList&&(O=String.fromCharCode(p[l]));var M=null;v&&(M=v[l]),s({atomCount:F,groupIndex:l,chainIndex:g,modelIndex:f,groupId:r.groupIdList[l],groupType:r.groupTypeList[l],groupName:w.groupName,singleLetterCode:w.singleLetterCode,chemCompType:w.chemCompType,secStruct:S,insCode:O,sequenceIndex:M})}if(d){var T=w.bondAtomList;for(o=0,a=w.bondOrderList.length;a>o;++o)d({atomIndex1:L+T[2*o],atomIndex2:L+T[2*o+1],bondOrder:w.bondOrderList[o]})}for(o=0;F>o;++o){if(c){var B=null;C&&(B=C[L]);var N=null;I&&(N=String.fromCharCode(I[L]));var P=null;b&&(P=b[L]),c({atomIndex:L,groupIndex:l,chainIndex:g,modelIndex:f,atomId:r.atomIdList[L],element:w.elementList[o],atomName:w.atomNameList[o],atomCharge:w.atomChargeList[o],xCoord:r.xCoordList[L],yCoord:r.yCoordList[L],zCoord:r.zCoordList[L],bFactor:B,altLoc:N,occupancy:P})}L+=1}l+=1}g+=1}f+=1}),d&&U)for(o=0,a=U.length;a>o;o+=2)d({atomIndex1:U[o],atomIndex2:U[o+1],bondOrder:x?x[o/2]:null})}function h(r,e){r instanceof ArrayBuffer&&(r=new Uint8Array(r));var n;return n=r instanceof Uint8Array?t(r):r,l(n,e)}var y=L;r.decode=h,r.traverse=y});/* pako 0.2.7 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o +* +*/ + +// use this transport for "binary" data type +$.ajaxTransport( + "+binary", + function(options, originalOptions, jqXHR) { + // check for conditions and support for blob / arraybuffer response type + if (window.FormData + && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) { + return { + // create new XMLHttpRequest + send : function(headers, callback) { + // setup all variables + var xhr = new XMLHttpRequest(), url = options.url, type = options.type, async = options.async || true, + // blob or arraybuffer. Default is blob + dataType = options.responseType || "blob", data = options.data + || null, username = options.username + || null, password = options.password + || null; + + xhr.addEventListener('load', function() { + var data = {}; + data[options.dataType] = xhr.response; + // make callback and send data + callback(xhr.status, xhr.statusText, + data, + xhr.getAllResponseHeaders()); + }); + + xhr.open(type, url, async, username, + password); + + // setup custom headers + for ( var i in headers) { + xhr.setRequestHeader(i, headers[i]); + } + + xhr.responseType = dataType; + xhr.send(data); + }, + abort : function() { + jqXHR.abort(); + } + }; + } + }); + /** * Create and initialize an appropriate viewer at supplied HTML element using specification in config @@ -3162,35 +3218,57 @@ $3Dmol.download = function(query, viewer, options, callback) { var type = ""; var pdbUri = ""; var m = viewer.addModel(); - if (query.substr(0, 4) === 'pdb:') { - pdbUri = options && options.pdbUri ? options.pdbUri : "http://www.rcsb.org/pdb/files/"; - type = options && options.format ? options.format : "pdb"; - query = query.substr(4).toUpperCase(); - if (!query.match(/^[1-9][A-Za-z0-9]{3}$/)) { - alert("Wrong PDB ID"); return; - } - if (options && options.format) - uri = pdbUri + query + "." + options.format; - else - uri = pdbUri + query + ".pdb"; - - } else if (query.substr(0, 4) == 'cid:') { - type = "sdf"; - query = query.substr(4); - if (!query.match(/^[0-9]+$/)) { - alert("Wrong Compound ID"); return; - } - uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/" + query + - "/SDF?record_type=3d"; + + if (query.substr(0, 5) === 'mmtf:') { + pdbUri = options && options.pdbUri ? options.pdbUri : "http://mmtf.rcsb.org/full/"; + query = query.substr(5).toUpperCase(); + var uri = pdbUri + query + ".mmtf"; + + $.ajax({url:uri, + type: "GET", + dataType: "binary", + responseType: "arraybuffer", + processData: false}).done( + function(ret, txt, response) { + m.addMolData(ret, 'mmtf'); + viewer.zoomTo(); + viewer.render(); + if(callback) callback(m); + }).fail(function(e,txt) { + console.log(txt); + }); } - - $.get(uri, function(ret) { - m.addMolData(ret, type, options); - viewer.zoomTo(); - viewer.render(); - if(callback) callback(m); - - }); + else { + if (query.substr(0, 4) === 'pdb:') { + pdbUri = options && options.pdbUri ? options.pdbUri : "http://www.rcsb.org/pdb/files/"; + type = options && options.format ? options.format : "pdb"; + query = query.substr(4).toUpperCase(); + if (!query.match(/^[1-9][A-Za-z0-9]{3}$/)) { + alert("Wrong PDB ID"); return; + } + if (options && options.format) + uri = pdbUri + query + "." + options.format; + else + uri = pdbUri + query + ".pdb"; + + } else if (query.substr(0, 4) == 'cid:') { + type = "sdf"; + query = query.substr(4); + if (!query.match(/^[0-9]+$/)) { + alert("Wrong Compound ID"); return; + } + uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/" + query + + "/SDF?record_type=3d"; + } + + $.get(uri, function(ret) { + m.addMolData(ret, type, options); + viewer.zoomTo(); + viewer.render(); + if(callback) callback(m); + + }); + } return m; }; @@ -3295,6 +3373,7 @@ $3Dmol.specStringToObject = function(str) { } var ret = {}; + if(str === 'all') return ret; var fields = str.split(';'); for(var i = 0; i < fields.length; i++) { var fv = fields[i].split(':'); @@ -3424,6 +3503,12 @@ $3Dmol.getPropertyRange = function (atomlist, prop) { return [ min, max ]; } +//hackish way to work with requirejs - doesn't actually work yet +//since we doing use the require optimizer to combine modules +if( typeof(define) === 'function' && define.amd) { + define('$3Dmol',$3Dmol); +} + /* * math-like functionality * quaternion, vector, matrix @@ -4037,13 +4122,17 @@ $3Dmol.Matrix3.prototype = { /** @constructor */ $3Dmol.Matrix4 = function(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) { - var te = this.elements = new Float32Array( 16 ); - - te[0] = ( n11 !== undefined ) ? n11 : 1; te[4] = n12 || 0; te[8] = n13 || 0; te[12] = n14 || 0; - te[1] = n21 || 0; te[5] = ( n22 !== undefined ) ? n22 : 1; te[9] = n23 || 0; te[13] = n24 || 0; - te[2] = n31 || 0; te[6] = n32 || 0; te[10] = ( n33 !== undefined ) ? n33 : 1; te[14] = n34 || 0; - te[3] = n41 || 0; te[7] = n42 || 0; te[11] = n43 || 0; te[15] = ( n44 !== undefined ) ? n44 : 1; - + if(typeof(n12) === 'undefined' && typeof(n11) !== 'undefined') { + //passing list like initialization + this.elements = new Float32Array(n11); + } else { + var te = this.elements = new Float32Array( 16 ); + + te[0] = ( n11 !== undefined ) ? n11 : 1; te[4] = n12 || 0; te[8] = n13 || 0; te[12] = n14 || 0; + te[1] = n21 || 0; te[5] = ( n22 !== undefined ) ? n22 : 1; te[9] = n23 || 0; te[13] = n24 || 0; + te[2] = n31 || 0; te[6] = n32 || 0; te[10] = ( n33 !== undefined ) ? n33 : 1; te[14] = n34 || 0; + te[3] = n41 || 0; te[7] = n42 || 0; te[11] = n43 || 0; te[15] = ( n44 !== undefined ) ? n44 : 1; + } }; $3Dmol.Matrix4.prototype = { @@ -4239,6 +4328,21 @@ $3Dmol.Matrix4.prototype = { return this; }, + makeTranslation: function ( x, y, z ) { + + this.set( + + 1, 0, 0, x, + 0, 1, 0, y, + 0, 0, 1, z, + 0, 0, 0, 1 + + ); + + return this; + + }, + transpose: function () { var te = this.elements; var tmp; @@ -4460,6 +4564,27 @@ $3Dmol.Matrix4.prototype = { return this.makeFrustum( xmin, xmax, ymin, ymax, near, far ); }, + + makeOrthographic: function ( left, right, top, bottom, near, far ) { + + var te = this.elements; + var w = 1.0 / ( right - left ); + var h = 1.0 / ( top - bottom ); + var p = 1.0 / ( far - near ); + + var x = ( right + left ) * w; + var y = ( top + bottom ) * h; + var z = ( far + near ) * p; + + te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x; + te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y; + te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z; + te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1; + + return this; + + }, + isEqual : function (m) { var me = m.elements; var te = this.elements; @@ -5769,7 +5894,7 @@ $3Dmol.Projector = function () { */ /** @constructor */ -$3Dmol.Camera = function(fov, aspect, near, far) { +$3Dmol.Camera = function(fov, aspect, near, far, ortho) { $3Dmol.Object3D.call(this); @@ -5782,6 +5907,14 @@ $3Dmol.Camera = function(fov, aspect, near, far) { this.projectionMatrixInverse = new $3Dmol.Matrix4(); this.matrixWorldInverse = new $3Dmol.Matrix4(); + var center = this.position.z; + this.right = center * Math.tan(Math.PI / 180 * fov); + this.left = -this.right; + this.top = this.right / this.aspect; + this.bottom = -this.top; + + this.ortho = !!ortho; + this.updateProjectionMatrix(); }; @@ -5807,7 +5940,12 @@ $3Dmol.Camera.prototype.lookAt = function(vector){ $3Dmol.Camera.prototype.updateProjectionMatrix = function () { - this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far ); + if(this.ortho) { + this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far ); + } else { + this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far ); + } + this.projectionMatrixInverse.getInverse(this.projectionMatrix); }; @@ -7040,7 +7178,7 @@ $3Dmol.Renderer = function(parameters) { _oldPolygonOffset = null, _oldPolygonOffsetFactor = null, _oldPolygonOffsetUnits = null, _oldLineWidth = null, - _viewportX = 0, _viewportY = 0, _viewportWidth = 0, _viewportHeight = 0, _currentWidth = 0, _currentHeight = 0, + _viewportWidth = 0, _viewportHeight = 0, _currentWidth = 0, _currentHeight = 0, _enabledAttributes = {}, // camera matrices cache @@ -7130,26 +7268,13 @@ $3Dmol.Renderer = function(parameters) { this.setSize = function(width, height) { - _canvas.width = width * this.devicePixelRatio; - _canvas.height = height * this.devicePixelRatio; + _viewportWidth = _canvas.width = width * this.devicePixelRatio; + _viewportHeight = _canvas.height = height * this.devicePixelRatio; _canvas.style.width = width + 'px'; _canvas.style.height = height + 'px'; - this.setViewport(0, 0, _canvas.width, _canvas.height); - - }; - - this.setViewport = function(x, y, width, height) { - - _viewportX = x !== undefined ? x : 0; - _viewportY = y !== undefined ? y : 0; - - _viewportWidth = width !== undefined ? width : _canvas.width; - _viewportHeight = height !== undefined ? height : _canvas.height; - - _gl.viewport(_viewportX, _viewportY, _viewportWidth, _viewportHeight); - + _gl.viewport(0, 0, _gl.drawingBufferWidth, _gl.drawingBufferHeight); }; this.clear = function(color, depth, stencil) { @@ -10570,7 +10695,10 @@ $(document).ready(function() { $(".viewer_3Dmoljs").each( function() { var viewerdiv = $(this); var datauri = null; - + if(viewerdiv.css('position') == 'static') { + //slight hack - canvas needs this element to be positioned + viewerdiv.css('position','relative'); + } var callback = (typeof(window[viewerdiv.data("callback")]) === 'function') ? window[viewerdiv.data("callback")] : null; @@ -10873,6 +11001,14 @@ $3Dmol.getColorFromStyle = function(atom, style) { if(val != null) { color = scheme.valueToHex(val, range); } + } else if(typeof(style.colorscheme.prop) != 'undefined' && + typeof(style.colorscheme.map) != 'undefined') { + //apply a discrete property mapping + var prop = style.colorscheme.prop; + var val = $3Dmol.getAtomProperty(atom, prop); + if( typeof style.colorscheme.map[val] != 'undefined' ) { + color = style.colorscheme.map[val]; + } } } else if(typeof(style.colorfunc) != "undefined") { @@ -10882,7 +11018,15 @@ $3Dmol.getColorFromStyle = function(atom, style) { var C = $3Dmol.CC.color(color); return C; -} +}; + +/** Preset secondary structure color scheme + * @struct + */ +$3Dmol.ssColors = $3Dmol.ssColors || {}; +//names are in helix-sheet-coil order +$3Dmol.ssColors.pyMOL = {'h': 0xff0000, 's': 0xffff00, 'c': 0x00ff00}; +$3Dmol.ssColors.Jmol = {'h': 0xff0080, 's': 0xffc800, 'c': 0xffffff}; /** Preset element coloring - from individual element colors to entire mappings (e.g. '$3Dmol.elementColors.Jmol' colors atoms with Jmol stylings) * @struct @@ -14630,6 +14774,11 @@ $3Dmol.GLModel = (function() { for (var i = 0; i < frames.length; i++) { this.setAtomDefaults(frames[i], id); } + + if(options.vibrate && options.vibrate.frames && options.vibrate.amplitude) { + //fill in vibrational modes + this.vibrate(options.vibrate.frames, options.vibrate.amplitude); + } }; @@ -16208,12 +16357,13 @@ $3Dmol.GLShape = (function() { voxel : voxel, unitCube : data.unit, origin : data.origin, + matrix: data.matrix, nX : nX, nY : nY, nZ : nZ }); - if (!voxel) + if (!voxel && smoothness > 0) $3Dmol.MarchingCube.laplacianSmooth(smoothness, verts, faces); drawCustom(this, geo, { @@ -16488,7 +16638,7 @@ $3Dmol.GLViewer = (function() { renderer.domElement.style.left = "0px"; renderer.domElement.style.zIndex = "0"; - var camera = new $3Dmol.Camera(fov, ASPECT, NEAR, FAR); + var camera = new $3Dmol.Camera(fov, ASPECT, NEAR, FAR, config.orthographic); camera.position = new $3Dmol.Vector3(camerax, 0, CAMERA_Z); var lookingAt = new $3Dmol.Vector3(); camera.lookAt(lookingAt); @@ -16540,14 +16690,13 @@ $3Dmol.GLViewer = (function() { camera.far = center + slabFar; if (camera.near + 1 > camera.far) camera.far = camera.near + 1; - if (camera instanceof $3Dmol.Camera) { - camera.fov = fov; - } else { - camera.right = center * Math.tan(Math.PI / 180 * fov); - camera.left = -camera.right; - camera.top = camera.right / ASPECT; - camera.bottom = -camera.top; - } + + camera.fov = fov; + camera.right = center * Math.tan(Math.PI / 180 * fov); + camera.left = -camera.right; + camera.top = camera.right / ASPECT; + camera.bottom = -camera.top; + camera.updateProjectionMatrix(); scene.fog.near = camera.near + fogStart * (camera.far - camera.near); @@ -16742,7 +16891,6 @@ $3Dmol.GLViewer = (function() { currentModelPos = modelGroup.position.clone(); cslabNear = slabNear; cslabFar = slabFar; - }; var _handleMouseScroll = this._handleMouseScroll = function(ev) { // Zoom @@ -16750,11 +16898,15 @@ $3Dmol.GLViewer = (function() { if (!scene) return; var scaleFactor = (CAMERA_Z - rotationGroup.position.z) * 0.85; + var mult = 1.0; + if(ev.originalEvent.ctrlKey) { + mult = -1.0; //this is a pinch event turned into a wheel event (or they're just holding down the ctrl) + } if (ev.originalEvent.detail) { // Webkit - rotationGroup.position.z += scaleFactor + rotationGroup.position.z += mult * scaleFactor * ev.originalEvent.detail / 10; } else if (ev.originalEvent.wheelDelta) { // Firefox - rotationGroup.position.z -= scaleFactor + rotationGroup.position.z -= mult * scaleFactor * ev.originalEvent.wheelDelta / 400; } if(rotationGroup.position.z > CAMERA_Z) rotationGroup.position.z = CAMERA_Z*0.999; //avoid getting stuck @@ -16788,6 +16940,7 @@ $3Dmol.GLViewer = (function() { mode = 2; dy = (newdist - touchDistanceStart) * 2 / (WIDTH + HEIGHT); + console.log("pinch "+touchDistanceStart+" dy "+dy); } else if (ev.originalEvent.targetTouches && ev.originalEvent.targetTouches.length == 3) { // translate @@ -16919,11 +17072,27 @@ $3Dmol.GLViewer = (function() { }; /** - * Enable outline - * @function $eDmol.GLViewer#outline + * Set view projection scheme. Either orthographic or perspective. + * Default is perspective. Orthographic can also be enabled on viewer creation + * by setting orthographic to true in the config object. + * + * @function $3Dmol.GLViewer#setProjection + * + * @example + * myviewer.setProjection("orthographic"); + * + */ + this.setProjection = function(proj) { + camera.ortho = (proj === "orthographic"); + setSlabAndFog(); + }; + + /** + * Set global view styles. + * @function $3Dmol.GLViewer#setViewStyle * * @example - * myviewer.outline() + * myviewer.setViewStyle({style:"outline", color:"black", width:0.1}) * */ this.setViewStyle = function(parameters) { @@ -16934,12 +17103,12 @@ $3Dmol.GLViewer = (function() { renderer.enableOutline(params); } else { renderer.disableOutline(); - } + } return this; } if(config.style) { //enable setting style in constructor - this.setViewStyle(config.style); + this.setViewStyle(config); } /** @@ -18546,7 +18715,7 @@ $3Dmol.GLViewer = (function() { /** * Adds an explicit mesh as a surface object. - * + * @function $3Dmol.GLViewer#addMesh * @param {$3Dmol.Mesh} * mesh * @param {Object} @@ -18828,7 +18997,7 @@ $3Dmol.GLViewer = (function() { /** * Set the surface material to something else, must render change - * + * @function $3Dmol.GLViewer#setSurfaceMaterialStyle * @param {number} surf - Surface ID to apply changes to * @param {matSpec} style - new material style specification */ @@ -18846,7 +19015,7 @@ $3Dmol.GLViewer = (function() { /** * Remove surface with given ID - * + * @function $3Dmol.GLViewer#removeSurface * @param {number} surf - surface id */ this.removeSurface = function(surf) { @@ -19456,6 +19625,7 @@ $3Dmol.MarchingCubeInitializer = function() { var fulltable = !!(spec.fulltable); var origin = (spec.hasOwnProperty('origin') && spec.origin.hasOwnProperty('x')) ? spec.origin : {x:0, y:0, z:0}; var voxel = !!(spec.voxel); + var transform = spec.matrix; //if this is set, it overrides origin and unitCube var nX = spec.nX || 0; var nY = spec.nY || 0; @@ -19481,7 +19651,7 @@ $3Dmol.MarchingCubeInitializer = function() { // the edge (p1,p2) var getVertex = function(i, j, k, code, p1, p2) { - var pt = {x: origin.x, y: origin.y, z: origin.z}; + var pt = {x:0,y:0,z:0}; var val1 = !!(code & (1 << p1)); var val2 = !!(code & (1 << p2)); @@ -19497,11 +19667,17 @@ $3Dmol.MarchingCubeInitializer = function() { j++; if (p & 4) i++; - - pt.x += unitCube.x*i; - pt.y += unitCube.y*j; - pt.z += unitCube.z*k; - + + if(transform) { + pt = new $3Dmol.Vector3(i,j,k); + pt = pt.applyMatrix4(transform); + pt = {x: pt.x, y: pt.y, z: pt.z}; //remove vector gunk + } else { + pt.x = origin.x+unitCube.x*i; + pt.y = origin.y+unitCube.y*j; + pt.z = origin.z+unitCube.z*k; + } + var index = ((nY * i) + j) * nZ + k; //Have to add option to do voxels @@ -20398,6 +20574,94 @@ $3Dmol.Parsers = (function() { } }; + /** + * @param {string} + * str + * @param {Object} + * options + */ + parsers.vasp = parsers.VASP = function (str, options) { + var atoms = [[]]; + var lattice = {}; + + var lines = str.replace(/^\s+/, "").split(/[\n\r]/); + + if (lines.length < 3){ + return atoms; + } + + if (lines[1].match(/\d+/)) { + lattice.length = parseFloat(lines[1]); + } else { + console.log("Warning: second line of the vasp structure file must be a number"); + return atoms; + } + + if (lattice.length<0) { + console.log("Warning: Vasp implementation for negative lattice lengths is not yet available"); + return atoms; + } + + lattice.xVec = new Float32Array(lines[2].replace(/^\s+/, "").split(/\s+/)); + lattice.yVec = new Float32Array(lines[3].replace(/^\s+/, "").split(/\s+/)); + lattice.zVec = new Float32Array(lines[4].replace(/^\s+/, "").split(/\s+/)); + + + var atomSymbols=lines[5].replace(/\s+/, "").replace(/\s+$/,"").split(/\s+/); + var atomSpeciesNumber=new Int16Array(lines[6].replace(/^\s+/, "").split(/\s+/)); + var vaspMode=lines[7].replace(/\s+/, ""); + + + if (vaspMode.match(/C/)) { + vaspMode = "cartesian"; + }else if (vaspMode.match(/D/)){ + vaspMode="direct"; + } else { + console.log("Warning: Unknown vasp mode in POSCAR file: mode must be either C(artesian) or D(irect)"); + return atoms; + } + + if (atomSymbols.length != atomSpeciesNumber.length) { + console.log("Warning: declaration of atomary species wrong:"); + console.log(atomSymbols); + console.log(atomSpeciesNumber); + return atoms; + } + + lines.splice(0,8); + + var atomCounter = 0; + + for (var i = 0, len = atomSymbols.length; i < len; i++) { + var atomSymbol = atomSymbols[i]; + for (var j = 0, atomLen = atomSpeciesNumber[i]; j < atomLen; j++) { + + var coords = new Float32Array(lines[atomCounter + j].replace(/^\s+/, "").split(/\s+/)); + + atom={}; + atom.elem = atomSymbol; + if (vaspMode == "cartesian") { + atom.x = lattice.length*coords[0]; + atom.y = lattice.length*coords[1]; + atom.z = lattice.length*coords[2]; + } else { + atom.x = lattice.length*(coords[0]*lattice.xVec[0] + coords[1]*lattice.yVec[0] + coords[2]*lattice.zVec[0]); + atom.y = lattice.length*(coords[0]*lattice.xVec[1] + coords[1]*lattice.yVec[1] + coords[2]*lattice.zVec[1]); + atom.z = lattice.length*(coords[0]*lattice.xVec[2] + coords[1]*lattice.yVec[2] + coords[2]*lattice.zVec[2]); + } + + atom.bonds=[]; + + atoms[0].push(atom); + } + atomCounter += atomSpeciesNumber[i]; + } + + return atoms; + + + } + /** * @param {string} * str @@ -20996,7 +21260,7 @@ $3Dmol.Parsers = (function() { for (var i = 0; i < atoms.length; i++) { assignBonds(atoms[i]); computeSecondaryStructure(atoms[i]); - processSymmetries(modelData[modelData.length-1].symmetries, copyMatrix, atoms[i]); + processSymmetries(modelData[i].symmetries, copyMatrix, atoms[i]); } return atoms; @@ -21455,7 +21719,7 @@ $3Dmol.Parsers = (function() { // starttime)); if (!noAssembly) - processSymmetries(modelData[modelData.length-1].symmetries, copyMatrix, atoms[n]); + processSymmetries(modelData[n].symmetries, copyMatrix, atoms[n]); if (computeStruct || !hasStruct) { starttime = (new Date()).getTime(); @@ -21520,7 +21784,10 @@ $3Dmol.Parsers = (function() { var start = atoms[atoms.length-1].length; var atom; var computeStruct = !options.noSecondaryStructure; - + var noAssembly = !options.doAssembly; // don't assemble by default + var copyMatrix = !options.duplicateAssemblyAtoms; //default true + var modelData = atoms.modelData = [{symmetries:[]}]; + var serialToIndex = []; // map from pdb serial to index in atoms var lines = str.split(/\r?\n|\r/); var i, j, k, line; @@ -21617,7 +21884,233 @@ $3Dmol.Parsers = (function() { return atoms; }; + + var fromCharCode = function( charCodeArray ){ + return String.fromCharCode.apply( null, charCodeArray ).replace(/\0/g, ''); + }; + + var convertSS = function(val) { + //convert mmtf code to 3dmol code + if(val == 2) return 'h'; + if(val == 3) return 's'; + return 'c'; + }; + + //mmtf shoul be passed as a binary UInt8Array buffer + parsers.mmtf = parsers.MMTF = function(bindata, options) { + + var noH = !options.keepH; // suppress hydrogens by default + + var mmtfData = MMTF.decode( bindata ); + var atoms = [[]]; + var modelData = atoms.modelData = []; + + // setup index counters + var modelIndex = 0; + var chainIndex = 0; + var groupIndex = 0; + var atomIndex = 0; + + // setup optional fields + var chainNameList = mmtfData.chainNameList; + var secStructList = mmtfData.secStructList; + var insCodeList = mmtfData.insCodeList; + var sequenceIndexList = mmtfData.sequenceIndexList; + var bFactorList = mmtfData.bFactorList; + var altLocList = mmtfData.altLocList; + var occupancyList = mmtfData.occupancyList; + var bondAtomList = mmtfData.bondAtomList; + var bondOrderList = mmtfData.bondOrderList; + + var numModels = mmtfData.numModels; + if (numModels == 0) return atoms; + if (!options.multimodel) numModels = 1; //first only + // hoisted loop variables + var i, j, k, kl, m, n; + + //extract symmetries - only take first assembly, apply to all models (ignoring changes for now) + var noAssembly = !options.doAssembly; // don't assemble by default + var copyMatrix = !options.duplicateAssemblyAtoms; //default true + var assemblyIndex = options.assemblyIndex ? options.assemblyIndex : 0; + + var symmetries = []; + if(mmtfData.bioAssemblyList && mmtfData.bioAssemblyList.length > 0) { + var transforms = mmtfData.bioAssemblyList[assemblyIndex].transformList; + for(i = 0, n = transforms.length; i < n; i++) { + var matrix = new $3Dmol.Matrix4(transforms[i].matrix); + matrix.transpose(); + symmetries.push(matrix); + } + } + + var bondAtomListStart = 0; //for current model + //loop over models, + for (m = 0; m < numModels; m++ ) { + var modelChainCount = mmtfData.chainsPerModel[m]; + var matoms = atoms[atoms.length-1]; + var serialToIndex = []; // map to matoms index, needed for noh + + modelData.push({symmetries:symmetries}); + for( i = 0; i < modelChainCount; ++i ){ + + var chainGroupCount = mmtfData.groupsPerChain[ chainIndex ]; + var chainId = fromCharCode( + mmtfData.chainIdList.subarray( chainIndex * 4, chainIndex * 4 + 4 ) + ); + + var startGroup = groupIndex; + for( j = 0; j < chainGroupCount; ++j ){ //over residues (groups) + + var groupData = mmtfData.groupList[ mmtfData.groupTypeList[ groupIndex ] ]; + var groupAtomCount = groupData.atomNameList.length; + var secStruct = 0; + if( secStructList ){ + secStruct = secStructList[ groupIndex ]; + } + var insCode = null; + if( mmtfData.insCodeList ){ + insCode = String.fromCharCode( insCodeList[ groupIndex ] ); + } + var sequenceIndex = null; + if( sequenceIndexList ){ + sequenceIndex = sequenceIndexList[ groupIndex ]; + } + + var groupId = mmtfData.groupIdList[ groupIndex ]; + var groupName = groupData.groupName; + var startAtom = atomIndex; + + for( k = 0; k < groupAtomCount; ++k ){ + + var element = groupData.elementList[ k ]; + if(noH && element == 'H') { + atomIndex += 1; + continue; + } + + var bFactor = ''; + if( bFactorList ){ + bFactor = bFactorList[ atomIndex ]; + } + var altLoc = ' '; + if( altLocList ){ + altLoc = String.fromCharCode( altLocList[ atomIndex ] ); + } + var occupancy = ''; + if( occupancyList ){ + occupancy = occupancyList[ atomIndex ]; + } + + var atomId = mmtfData.atomIdList[ atomIndex ]; + var atomName = groupData.atomNameList[ k ]; + var atomCharge = groupData.atomChargeList[ k ]; + var xCoord = mmtfData.xCoordList[ atomIndex ]; + var yCoord = mmtfData.yCoordList[ atomIndex ]; + var zCoord = mmtfData.zCoordList[ atomIndex ]; + + serialToIndex[atomIndex] = matoms.length; + matoms.push({ + 'resn' : groupName, + 'x' : xCoord, + 'y' : yCoord, + 'z' : zCoord, + 'elem' : element, + 'hetflag' : secStruct < 0, + 'chain' : chainId, + 'resi' : groupId, + 'icode' : altLoc, + 'rescode' : groupId + (altLoc != ' ' ? "^" + altLoc : ""), // combo + // resi + // and + // icode + 'serial' : atomId, + 'atom' : atomName, + 'bonds' : [], + 'ss' : convertSS(secStruct), + 'bondOrder' : [], + 'properties' : {charge: atomCharge, occupancy:occupancy}, + 'b' : bFactor, + }); + + atomIndex += 1; + } + + // intra group bonds + var groupBondAtomList = groupData.bondAtomList; + for( k = 0, kl = groupData.bondOrderList.length; k < kl; ++k ){ + var atomIndex1 = startAtom + groupBondAtomList[ k * 2 ]; + var atomIndex2 = startAtom + groupBondAtomList[ k * 2 + 1 ]; + var bondOrder = groupData.bondOrderList[ k ]; + + //I assume bonds are only recorded once + var i1 = serialToIndex[atomIndex1]; + var i2 = serialToIndex[atomIndex2]; + var a1 = matoms[i1]; + var a2 = matoms[i2]; + if(a1 && a2) { + a1.bonds.push(i2) + a1.bondOrder.push(bondOrder); + a2.bonds.push(i1); + a2.bondOrder.push(bondOrder); + } + } + + groupIndex += 1; + } + + //reset for bonds + groupIndex = startGroup; + for( j = 0; j < chainGroupCount; ++j ){ //over residues (groups) + + groupIndex += 1; + + } + + chainIndex += 1; + } + + + // inter group bonds + if( bondAtomList ){ + for( k = bondAtomListStart, kl = bondAtomList.length; k < kl; k += 2 ){ + var atomIndex1 = bondAtomList[ k ]; + var atomIndex2 = bondAtomList[ k + 1 ]; + var bondOrder = bondOrderList ? bondOrderList[ k / 2 ] : 1; + + if(atomIndex1 >= atomIndex) { + bondAtomListStart = k; + break; //on next model + } + //I assume bonds are only recorded once + var i1 = serialToIndex[atomIndex1]; + var i2 = serialToIndex[atomIndex2]; + var a1 = matoms[i1]; + var a2 = matoms[i2]; + if(a1 && a2) { + a1.bonds.push(i2) + a1.bondOrder.push(bondOrder); + a2.bonds.push(i1); + a2.bondOrder.push(bondOrder); + } + } + } + + if (options.multimodel) { + if (!options.onemol) atoms.push([]); + } + modelIndex += 1; + } + + + for (var n = 0; n < atoms.length; n++) { + if (!noAssembly) + processSymmetries(modelData[n].symmetries, copyMatrix, atoms[n]); + } + + return atoms; + }; + return parsers; })(); var $3Dmol = $3Dmol || {}; @@ -21985,8 +22478,9 @@ $3Dmol.applyPartialCharges = function(atom, keepexisting) { * @class * @param {string} str - volumetric data * @param {string} format - format of supplied data (cube) + * @param {Object} options - normalize (zero mean, unit variance), negate */ -$3Dmol.VolumeData = function(str, format) { +$3Dmol.VolumeData = function(str, format, options) { this.unit = { x : 1, @@ -22006,10 +22500,49 @@ $3Dmol.VolumeData = function(str, format) { this.data = new Float32Array([]); // actual floating point data, arranged // x->y->z + this.matrix = null; //if set must transform data format = format.toLowerCase(); + + if(/\.gz$/.test(format)) { + //unzip gzipped files + format = format.replace(/\.gz$/,''); + try { + str = pako.inflate(str); + } catch(err) { + console.log(err); + } + } + if (this[format]) { this[format](str); } + + if(options) { + if(options.negate) { + for(var i = 0, n = this.data.length; i < n; i++) { + this.data[i] = -this.data[i]; + } + } + if(options.normalize) { + var total = 0.0; + for(var i = 0, n = this.data.length; i < n; i++) { + total += this.data[i]; + } + var mean = total/this.data.length; + console.log("computed mean: "+mean); + total = 0; + for(var i = 0, n = this.data.length; i < n; i++) { + var diff = this.data[i]-mean; + total += diff*diff; //variance is ave of squared difference with mean + } + var variance = total/this.data.length; + console.log("Computed variance: "+variance); + //now normalize + for(var i = 0, n = this.data.length; i < n; i++) { + this.data[i] = (this.data[i]-mean)/variance; + } + } + } }; /** @@ -22037,6 +22570,111 @@ $3Dmol.VolumeData.prototype.getVal = function(x,y,z) { return this.data[x*this.size.y*this.size.z + y*this.size.z + z]; }; +/* + * parse vasp data + * Essentially this parser converts the CHGCAR data into + * cube data. It has been adapted from 'chg2cube.pl' found in + * http://theory.cm.utexas.edu/vtsttools/ + */ +$3Dmol.VolumeData.prototype.vasp = function(str) { + + var lines = str.replace(/^\s+/, "").split(/[\n\r]/); + + var atomicData = $3Dmol.Parsers.vasp(str)[0]; + var natoms = atomicData.length; + + if (natoms == 0) { + console.log("No good formating of CHG or CHGCAR file, not atomic information provided in the file."); + this.data = []; + return; + } + + + + // Assume atomic units + var unittype = "bohr/hartree"; + var l_units = 1.889725992; + var e_units = 0.036749309; + + // copied from $3Dmol.Parsers.vasp + var convFactor = parseFloat(lines[1]); + // This is how Vasp reads in the basis We need the l_units in order to + // compute the volume of the cell. Afterwards to obtain the axis for the + // voxels we have to remove this unit and divide by the number of voxels in + // each dimension + var v; + v=lines[2].replace(/^\s+/, "").split(/\s+/); + var xVec = new $3Dmol.Vector3(parseFloat(v[0]),parseFloat(v[1]),parseFloat(v[2])).multiplyScalar(convFactor*l_units); + v=lines[3].replace(/^\s+/, "").split(/\s+/); + var yVec = new $3Dmol.Vector3(parseFloat(v[0]),parseFloat(v[1]),parseFloat(v[2])).multiplyScalar(convFactor*l_units); + v=lines[4].replace(/^\s+/, "").split(/\s+/); + var zVec = new $3Dmol.Vector3(parseFloat(v[0]),parseFloat(v[1]),parseFloat(v[2])).multiplyScalar(convFactor*l_units); + + // correct volume for non-orthognal box (expansion by minors) + var vol = xVec.x*(yVec.y*zVec.z - zVec.y*yVec.z) - yVec.x*(xVec.y*zVec.z - zVec.y*xVec.z) + zVec.x*(xVec.y*yVec.z - yVec.y*xVec.z); + + vol = Math.abs(vol)/(Math.pow(l_units,3)); + var vol_scale = 1.0/(vol); //This Only for CHGCAR files + + // We splice the structure information + // 2 (header) + 3 (vectors) + 2 (atoms) + 1 (vaspMode) + natoms (coords) + 1 (blank line) + lines.splice(0,2+3+2+1+natoms+1); + + + var lineArr = lines[0].replace(/^\s+/, "").replace(/\s+/g, " ").split(" "); + + var nX = Math.abs(lineArr[0]); + var nY = Math.abs(lineArr[1]); + var nZ = Math.abs(lineArr[2]); + + var origin = this.origin = new $3Dmol.Vector3(0,0,0); + + this.size = {x:nX, y:nY, z:nZ}; + this.unit = new $3Dmol.Vector3(xVec.x, yVec.y, zVec.z); + + // resize the vectors accordingly + xVec = xVec.multiplyScalar(1/(l_units*nX)); + yVec = yVec.multiplyScalar(1/(l_units*nY)); + zVec = zVec.multiplyScalar(1/(l_units*nZ)); + + if (xVec.y != 0 || xVec.z != 0 || yVec.x != 0 || yVec.z != 0 || zVec.x != 0 + || zVec.y != 0) { + //need a transformation matrix + this.matrix = new $3Dmol.Matrix4(xVec.x, yVec.x, zVec.x, 0, xVec.y, yVec.y, zVec.y, 0, xVec.z, yVec.z, zVec.z, 0, 0,0,0,1); + //include translation in matrix + this.matrix = this.matrix.multiplyMatrices(this.matrix, + new $3Dmol.Matrix4().makeTranslation(origin.x, origin.y, origin.z)); + //all translation and scaling done by matrix, so reset origin and unit + this.origin = new $3Dmol.Vector3(0,0,0); + this.unit = new $3Dmol.Vector3(1,1,1); + } + + + lines.splice(0,1); //Remove the dimension line + var raw = lines.join(" "); + + raw = raw.replace(/^\s+/,''); + raw = raw.split(/[\s\r]+/); + raw.splice(nX*nY*nZ+1); + + var preConvertedData = new Float32Array(raw); //We still have to format it to get the density + + for (var i = 0; i< preConvertedData.length; i++){ + preConvertedData[i] = preConvertedData[i]*vol_scale*e_units; + } + + this.data = preConvertedData; + + //console.log(xVec); + //console.log(yVec); + //console.log(zVec); + //console.log(this.unit); + //console.log(this.origin); + //console.log(this.matrix); + //console.log(this.data); + +}; + // parse cube data $3Dmol.VolumeData.prototype.cube = function(str) { var lines = str.replace(/^\s+/, "").split(/[\n\r]+/); @@ -22085,9 +22723,17 @@ $3Dmol.VolumeData.prototype.cube = function(str) { this.unit = new $3Dmol.Vector3(xVec.x, yVec.y, zVec.z); if (xVec.y != 0 || xVec.z != 0 || yVec.x != 0 || yVec.z != 0 || zVec.x != 0 - || zVec.y != 0) - console - .log("Warning: Cube file is not axis aligned. This isn't going to look right."); + || zVec.y != 0) { + //need a transformation matrix + this.matrix = new $3Dmol.Matrix4(xVec.x, yVec.x, zVec.x, 0, xVec.y, yVec.y, zVec.y, 0, xVec.z, yVec.z, zVec.z, 0, 0,0,0,1); + //include translation in matrix + this.matrix = this.matrix.multiplyMatrices(this.matrix, + new $3Dmol.Matrix4().makeTranslation(origin.x, origin.y, origin.z)); + //all translation and scaling done by matrix, so reset origin and unit + this.origin = new $3Dmol.Vector3(0,0,0); + this.unit = new $3Dmol.Vector3(1,1,1); + } + var headerlines = 6; if(atomsnum < 0) headerlines++; //see: http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/cubeplugin.html var raw = lines.splice(natoms + headerlines).join(" "); @@ -22101,94 +22747,197 @@ $3Dmol.VolumeData.prototype.cube = function(str) { $3Dmol.VolumeData.prototype.ccp4 = function(bin) { // http://www.ccp4.ac.uk/html/maplib.html#description - - var header = {}; - - var intView = new Int32Array( bin, 0, 56 ); - var floatView = new Float32Array( bin, 0, 56 ); - - //# of columns (fastest changing),rows, sections (slowest changing) - header.NX = intView[ 0 ]; - header.NY = intView[ 1 ]; - header.NZ = intView[ 2 ]; - - // mode - // 0 image : signed 8-bit bytes range -128 to 127 - // 1 image : 16-bit halfwords - // 2 image : 32-bit reals - // 3 transform : complex 16-bit integers - // 4 transform : complex 32-bit reals - // 6 image : unsigned 16-bit range 0 to 65535 - // 16 image: unsigned char * 3 (for rgb data, non-standard) - header.MODE = intView[ 3 ]; - - //position of first column, first row, and first section (voxel grid units) - header.NCSTART = intView[ 4 ]; - header.NRSTART = intView[ 5 ]; - header.NSSTART = intView[ 6 ]; - - //intervals per unit cell repeat along X,Y Z - header.MX = Math.abs(intView[ 7 ]); - header.MY = Math.abs(intView[ 8 ]); - header.MZ = Math.abs(intView[ 9 ]); - - //Map lengths along X,Y,Z in Ã…ngstroms - header.xlen = floatView[ 10 ]; - header.ylen = floatView[ 11 ]; - header.zlen = floatView[ 12 ]; - - //single voxel lengths - xVox = header.xlen / header.NX; - yVox = header.ylen / header.NY; - zVox = header.zlen / header.NZ; - - // cell angle - header.alpha = floatView[ 13 ]; - header.beta = floatView[ 14 ]; - header.gamma = floatView[ 15 ]; - - //relationship of X,Y,Z axes to columns, rows, sections - header.MAPC = intView[ 16 ]; - switch (header.MAPC){ - case 1: header.NXSTART = header.NCSTART; header.NYSTART = 0; header.NZSTART = 0; break; - case 2: header.NYSTART = header.NCSTART; header.NXSTART = 0; header.NZSTART = 0; break; - case 3: header.NZSTART = header.NCSTART; header.NXSTART = 0; header.NYSTART = 0; break; - } - header.MAPR = intView[ 17 ]; - switch (header.MAPR){ - case 1: header.NXSTART = header.NRSTART; header.NYSTART = 0; header.NZSTART = 0; break; - case 2: header.NYSTART = header.NRSTART; header.NXSTART = 0; header.NZSTART = 0; break; - case 3: header.NZSTART = header.NRSTART; header.NXSTART = 0; header.NYSTART = 0; break; - } - header.MAPS = intView[ 18 ]; - switch (header.MAPS){ - case 1: header.NXSTART = header.NSSTART; header.NYSTART = 0; header.NZSTART = 0; break; - case 2: header.NYSTART = header.NSSTART; header.NXSTART = 0; header.NZSTART = 0; break; - case 3: header.NZSTART = header.NSSTART; header.NXSTART = 0; header.NYSTART = 0; break; - } - - //Origin Position - this.origin = new $3Dmol.Vector3(header.NXSTART, header.NYSTART, header.NZSTART); - - //Minimum, maximum, average density - header.DMIN = floatView[ 19 ]; - header.DMAX = floatView[ 20 ]; - header.DMEAN = floatView[ 21 ]; - - // space group number 0 or 1 (default=0) - header.ISPG = intView[ 22 ]; - - // number of bytes used for symmetry data (0 or 80) - header.NSYMBT = intView[23]; - - // machine stamp - header.ARMS = floatView[54]; - - this.size = {x:header.MX, y:header.MY, z:header.MZ}; - this.unit = new $3Dmol.Vector3(xVox, yVox, zVox ); - var byteData = new Int8Array(bin); - this.data = new Float32Array(bin, 1024 + header.NSYMBT); - + //code from ngl: https://github.com/arose/ngl/blob/master/js/ngl/parser.js + var header = {}; + bin = new Int8Array(bin); + var intView = new Int32Array( bin.buffer, 0, 56 ); + var floatView = new Float32Array( bin.buffer, 0, 56 ); + var dv = new DataView( bin.buffer ); + + + // 53 MAP Character string 'MAP ' to identify file type + header.MAP = String.fromCharCode( + dv.getUint8( 52 * 4 ), dv.getUint8( 52 * 4 + 1 ), + dv.getUint8( 52 * 4 + 2 ), dv.getUint8( 52 * 4 + 3 ) + ); + + // 54 MACHST Machine stamp indicating machine type which wrote file + // 17 and 17 for big-endian or 68 and 65 for little-endian + header.MACHST = [ dv.getUint8( 53 * 4 ), dv.getUint8( 53 * 4 + 1 ) ]; + + // swap byte order when big endian + if( header.MACHST[ 0 ] === 17 && header.MACHST[ 1 ] === 17 ){ + var n = bin.byteLength; + for( var i = 0; i < n; i+=4 ){ + dv.setFloat32( i, dv.getFloat32( i ), true ); + } + } + + header.NX = intView[ 0 ]; // NC - columns (fastest changing) + header.NY = intView[ 1 ]; // NR - rows + header.NZ = intView[ 2 ]; // NS - sections (slowest changing) + + // mode + // 0 image : signed 8-bit bytes range -128 to 127 + // 1 image : 16-bit halfwords + // 2 image : 32-bit reals + // 3 transform : complex 16-bit integers + // 4 transform : complex 32-bit reals + // 6 image : unsigned 16-bit range 0 to 65535 + // 16 image: unsigned char * 3 (for rgb data, non-standard) + // + // Note: Mode 2 is the normal mode used in the CCP4 programs. + // Other modes than 2 and 0 may NOT WORK + header.MODE = intView[ 3 ]; + + // start + header.NXSTART = intView[ 4 ]; // NCSTART - first column + header.NYSTART = intView[ 5 ]; // NRSTART - first row + header.NZSTART = intView[ 6 ]; // NSSTART - first section + + // intervals + header.MX = intView[ 7 ]; // intervals along x + header.MY = intView[ 8 ]; // intervals along y + header.MZ = intView[ 9 ]; // intervals along z + + // cell length (Angstroms in CCP4) + header.xlen = floatView[ 10 ]; + header.ylen = floatView[ 11 ]; + header.zlen = floatView[ 12 ]; + + // cell angle (Degrees) + header.alpha = floatView[ 13 ]; + header.beta = floatView[ 14 ]; + header.gamma = floatView[ 15 ]; + + // axis correspondence (1,2,3 for X,Y,Z) + header.MAPC = intView[ 16 ]; // column + header.MAPR = intView[ 17 ]; // row + header.MAPS = intView[ 18 ]; // section + + // density statistics + header.DMIN = floatView[ 19 ]; + header.DMAX = floatView[ 20 ]; + header.DMEAN = floatView[ 21 ]; + + // space group number 0 or 1 (default=0) + header.ISPG = intView[ 22 ]; + + // number of bytes used for symmetry data (0 or 80) + header.NSYMBT = intView[ 23 ]; + + // Flag for skew transformation, =0 none, =1 if foll + header.LSKFLG = intView[ 24 ]; + + // 26-34 SKWMAT Skew matrix S (in order S11, S12, S13, S21 etc) if + // LSKFLG .ne. 0. + // 35-37 SKWTRN Skew translation t if LSKFLG != 0. + // Skew transformation is from standard orthogonal + // coordinate frame (as used for atoms) to orthogonal + // map frame, as Xo(map) = S * (Xo(atoms) - t) + + // 38 future use (some of these are used by the MSUBSX routines + // . " in MAPBRICK, MAPCONT and FRODO) + // . " (all set to zero by default) + // . " + // 52 " + + // 50-52 origin in X,Y,Z used for transforms + header.originX = floatView[ 49 ]; + header.originY = floatView[ 50 ]; + header.originZ = floatView[ 51 ]; + + // 53 MAP Character string 'MAP ' to identify file type + // => see top of this parser + + // 54 MACHST Machine stamp indicating machine type which wrote file + // => see top of this parser + + // Rms deviation of map from mean density + header.ARMS = floatView[ 54 ]; + + // 56 NLABL Number of labels being used + // 57-256 LABEL(20,10) 10 80 character text labels (ie. A4 format) + console.log("Map has min,mean,average,rmsddv: "+header.DMIN+","+header.DMAX+","+header.DMEAN+","+header.ARMS); + + //create transformation matrix, code mostly copied from ngl + var h = header; + var basisX = [ + h.xlen, + 0, + 0 + ]; + + var basisY = [ + h.ylen * Math.cos( Math.PI / 180.0 * h.gamma ), + h.ylen * Math.sin( Math.PI / 180.0 * h.gamma ), + 0 + ]; + + var basisZ = [ + h.zlen * Math.cos( Math.PI / 180.0 * h.beta ), + h.zlen * ( + Math.cos( Math.PI / 180.0 * h.alpha ) + - Math.cos( Math.PI / 180.0 * h.gamma ) + * Math.cos( Math.PI / 180.0 * h.beta ) + ) / Math.sin( Math.PI / 180.0 * h.gamma ), + 0 + ]; + basisZ[ 2 ] = Math.sqrt( + h.zlen * h.zlen * Math.sin( Math.PI / 180.0 * h.beta ) * + Math.sin( Math.PI / 180.0 * h.beta ) - basisZ[ 1 ] * basisZ[ 1 ] + ); + + var basis = [ 0, basisX, basisY, basisZ ]; + var nxyz = [ 0, h.MX, h.MY, h.MZ ]; + var mapcrs = [ 0, h.MAPC, h.MAPR, h.MAPS ]; + + this.matrix = new $3Dmol.Matrix4(); + + this.matrix.set( + + basis[ mapcrs[1] ][0] / nxyz[ mapcrs[1] ], + basis[ mapcrs[2] ][0] / nxyz[ mapcrs[2] ], + basis[ mapcrs[3] ][0] / nxyz[ mapcrs[3] ], + 0, + + basis[ mapcrs[1] ][1] / nxyz[ mapcrs[1] ], + basis[ mapcrs[2] ][1] / nxyz[ mapcrs[2] ], + basis[ mapcrs[3] ][1] / nxyz[ mapcrs[3] ], + 0, + + basis[ mapcrs[1] ][2] / nxyz[ mapcrs[1] ], + basis[ mapcrs[2] ][2] / nxyz[ mapcrs[2] ], + basis[ mapcrs[3] ][2] / nxyz[ mapcrs[3] ], + 0, + + 0, 0, 0, 1 + + ); + //include translation in matrix + this.matrix = this.matrix.multiplyMatrices(this.matrix, + new $3Dmol.Matrix4().makeTranslation( + h.NXSTART + h.originX, + h.NYSTART + h.originY, + h.NZSTART + h.originZ)); + //all translation and scaling done by matrix, so reset origin and unit + this.origin = new $3Dmol.Vector3(0,0,0); + this.unit = new $3Dmol.Vector3(1,1,1); + this.size = {x:header.NX, y:header.NY, z:header.NZ}; + var data = new Float32Array(bin.buffer, 1024 + header.NSYMBT); + //data must by (slowest changing) x,y,z (fastest changing) + + var NX = header.NX, NY = header.NY, NZ = header.NZ; + this.data = new Float32Array(NX*NY*NZ); + for(var i = 0; i < NX; i++) { + for(var j = 0; j < NY; j++) { + for(var k = 0; k < NZ; k++) { + //should I be concerned that I'm not using mapc? + this.data[((i*NY)+j)*NZ+k] = data[((k*NY)+j)*NX+i]; + } + } + } + }; //Hackish way to create webworker (independent of $3Dmol namespace) within minified file $3Dmol.workerString = function(){ diff --git a/release/3Dmol.js b/release/3Dmol.js index 47b31c5e0..455a52468 100644 --- a/release/3Dmol.js +++ b/release/3Dmol.js @@ -10349,7 +10349,7 @@ if ( typeof noGlobal === strundefined ) { return jQuery; })); -/* pako 0.2.7 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;oe;e++){var n=a();t[n]=a()}return t}function e(t){var e=r.subarray(i,i+t);return i+=t,e}function n(t){var e=r.subarray(i,i+t);i+=t;var n=65535;if(t>n){for(var o=[],a=0;ae;e++)t[e]=a();return t}function a(){var a,s,c,d=r[i];if(0===(128&d))return i++,d;if(128===(240&d))return s=15&d,i++,t(s);if(144===(240&d))return s=15&d,i++,o(s);if(160===(224&d))return s=31&d,i++,n(s);if(224===(224&d))return a=u.getInt8(i),i++,a;switch(d){case 192:return i++,null;case 194:return i++,!1;case 195:return i++,!0;case 196:return s=u.getUint8(i+1),i+=2,e(s);case 197:return s=u.getUint16(i+1),i+=3,e(s);case 198:return s=u.getUint32(i+1),i+=5,e(s);case 199:return s=u.getUint8(i+1),c=u.getUint8(i+2),i+=3,[c,e(s)];case 200:return s=u.getUint16(i+1),c=u.getUint8(i+3),i+=4,[c,e(s)];case 201:return s=u.getUint32(i+1),c=u.getUint8(i+5),i+=6,[c,e(s)];case 202:return a=u.getFloat32(i+1),i+=5,a;case 203:return a=u.getFloat64(i+1),i+=9,a;case 204:return a=r[i+1],i+=2,a;case 205:return a=u.getUint16(i+1),i+=3,a;case 206:return a=u.getUint32(i+1),i+=5,a;case 207:return i+=9,0;case 208:return a=u.getInt8(i+1),i+=2,a;case 209:return a=u.getInt16(i+1),i+=3,a;case 210:return a=u.getInt32(i+1),i+=5,a;case 211:return i+=9,0;case 212:return c=u.getUint8(i+1),i+=2,[c,e(1)];case 213:return c=u.getUint8(i+1),i+=2,[c,e(2)];case 214:return c=u.getUint8(i+1),i+=2,[c,e(4)];case 215:return c=u.getUint8(i+1),i+=2,[c,e(8)];case 216:return c=u.getUint8(i+1),i+=2,[c,e(16)];case 217:return s=u.getUint8(i+1),i+=2,n(s);case 218:return s=u.getUint16(i+1),i+=3,n(s);case 219:return s=u.getUint32(i+1),i+=5,n(s);case 220:return s=u.getUint16(i+1),i+=3,o(s);case 221:return s=u.getUint32(i+1),i+=5,o(s);case 222:return s=u.getUint16(i+1),i+=3,t(s);case 223:return s=u.getUint32(i+1),i+=5,t(s)}throw new Error("Unknown type 0x"+d.toString(16))}var i=0,u=new DataView(r.buffer);return a()}function e(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function n(r){return new Int8Array(r.buffer,r.byteOffset,r.byteLength)}function o(r,t){var e,n,o,a=(r.byteOffset,r.byteLength);for(t||(t=new Int16Array(a/2)),e=0,n=0,o=a/2;o>e;++e,n+=2)t[e]=r[n]<<8^r[n+1]<<0;return t}function a(r,t){var e,n,o,a=(r.byteOffset,r.byteLength);for(t||(t=new Int32Array(a/4)),e=0,n=0,o=a/4;o>e;++e,n+=4)t[e]=r[n]<<24^r[n+1]<<16^r[n+2]<<8^r[n+3]<<0;return t}function i(r){return new Int32Array(r.buffer,r.byteOffset,r.byteLength/4)}function u(r,t,e){var n=r.length,o=1/t;e||(e=new Float32Array(n));for(var a=0;n>a;++a)e[a]=r[a]*o;return e}function s(r,t){var e,n;if(!t){var o=0;for(e=0,n=r.length;n>e;e+=2)o+=r[e+1];t=new r.constructor(o)}var a=0;for(e=0,n=r.length;n>e;e+=2)for(var i=r[e],u=r[e+1],s=0;u>s;++s)t[a]=i,a+=1;return t}function c(r){for(var t=1,e=r.length;e>t;++t)r[t]+=r[t-1];return r}function d(r,t,e){var n=r.length/2+t.length;e||(e=new Int32Array(n));for(var o=0,a=0,i=0,u=r.length;u>i;i+=2){var s=r[i],c=r[i+1];e[o]=s,0!==i&&(e[o]+=e[o-1]),o+=1;for(var d=0;c>d;++d)e[o]=e[o-1]+t[a],o+=1,a+=1}return e}function f(r,t,e,n){var s=r.length/4/2+t.length/2;n||(n=new Float32Array(s));var c=i(n),f=d(a(r),o(t),c);return u(f,e,n)}function g(r,t,e){var n=e?i(e):void 0,o=s(a(r),n);return u(o,t,e)}function l(r,t){function o(r){return i?-1===i.indexOf(r):!0}t=t||{};var i=t.ignoreFields,u=(r.numBonds||0,r.numAtoms||0),d=r.groupTypeList.length/4,l=r.chainIdList.length/4,m=r.chainsPerModel.length,L={numGroups:d,numChains:l,numModels:m};["mmtfVersion","mmtfProducer","unitCell","spaceGroup","structureId","title","depositionDate","releaseDate","experimentalMethods","resolution","rFree","rWork","bioAssemblyList","entityList","groupList","numBonds","numAtoms","groupsPerChain","chainsPerModel"].forEach(function(t){void 0!==r[t]&&(L[t]=r[t])});var h="bondAtomList";r[h]&&o(h)&&(L[h]=a(r[h]));var y="bondOrderList";r[y]&&o(y)&&(L[y]=e(r[y])),L.xCoordList=f(r.xCoordBig,r.xCoordSmall,1e3),L.yCoordList=f(r.yCoordBig,r.yCoordSmall,1e3),L.zCoordList=f(r.zCoordBig,r.zCoordSmall,1e3);var p="bFactorList",v="bFactorBig",C="bFactorSmall";r[v]&&r[C]&&o(p)&&(L[p]=f(r[v],r[C],100));var I="atomIdList";r[I]&&o(I)&&(L[I]=c(s(a(r[I]))));var b="altLocList";r[b]&&o(b)&&(L[b]=s(a(r[b]),new Uint8Array(u)));var U="occupancyList";r[U]&&o(U)&&(L[U]=g(r[U],100)),L.groupIdList=c(s(a(r.groupIdList))),L.groupTypeList=a(r.groupTypeList);var x="secStructList";r[x]&&o(x)&&(L[x]=n(r[x]));var A="insCodeList";r[A]&&o(A)&&(L[A]=s(a(r[A]),new Uint8Array(d)));var w="sequenceIndexList";r[w]&&o(w)&&(L[w]=c(s(a(r[w])))),L.chainIdList=e(r.chainIdList);var F="chainNameList";return r[F]&&o(F)&&(L[F]=e(r[F])),L}function m(r){return String.fromCharCode.apply(null,r).replace(/\0/g,"")}function L(r,t){var e,n,o,a,i=t.onModel,u=t.onChain,s=t.onGroup,c=t.onAtom,d=t.onBond,f=0,g=0,l=0,L=0,h=r.chainNameList,y=r.secStructList,p=r.insCodeList,v=r.sequenceIndexList,C=r.bFactorList,I=r.altLocList,b=r.occupancyList,U=r.bondAtomList,x=r.bondOrderList;if(r.chainsPerModel.forEach(function(t){for(i&&i({chainCount:t,modelIndex:f}),e=0;t>e;++e){var U=r.groupsPerChain[g];if(u){var x=m(r.chainIdList.subarray(4*g,4*g+4)),A=null;h&&(A=m(h.subarray(4*g,4*g+4))),u({groupCount:U,chainIndex:g,modelIndex:f,chainId:x,chainName:A})}for(n=0;U>n;++n){var w=r.groupList[r.groupTypeList[l]],F=w.atomNameList.length;if(s){var S=null;y&&(S=y[l]);var O=null;r.insCodeList&&(O=String.fromCharCode(p[l]));var M=null;v&&(M=v[l]),s({atomCount:F,groupIndex:l,chainIndex:g,modelIndex:f,groupId:r.groupIdList[l],groupType:r.groupTypeList[l],groupName:w.groupName,singleLetterCode:w.singleLetterCode,chemCompType:w.chemCompType,secStruct:S,insCode:O,sequenceIndex:M})}if(d){var T=w.bondAtomList;for(o=0,a=w.bondOrderList.length;a>o;++o)d({atomIndex1:L+T[2*o],atomIndex2:L+T[2*o+1],bondOrder:w.bondOrderList[o]})}for(o=0;F>o;++o){if(c){var B=null;C&&(B=C[L]);var N=null;I&&(N=String.fromCharCode(I[L]));var P=null;b&&(P=b[L]),c({atomIndex:L,groupIndex:l,chainIndex:g,modelIndex:f,atomId:r.atomIdList[L],element:w.elementList[o],atomName:w.atomNameList[o],atomCharge:w.atomChargeList[o],xCoord:r.xCoordList[L],yCoord:r.yCoordList[L],zCoord:r.zCoordList[L],bFactor:B,altLoc:N,occupancy:P})}L+=1}l+=1}g+=1}f+=1}),d&&U)for(o=0,a=U.length;a>o;o+=2)d({atomIndex1:U[o],atomIndex2:U[o+1],bondOrder:x?x[o/2]:null})}function h(r,e){r instanceof ArrayBuffer&&(r=new Uint8Array(r));var n;return n=r instanceof Uint8Array?t(r):r,l(n,e)}var y=L;r.decode=h,r.traverse=y});/* pako 0.2.7 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o +* +*/ + +// use this transport for "binary" data type +$.ajaxTransport( + "+binary", + function(options, originalOptions, jqXHR) { + // check for conditions and support for blob / arraybuffer response type + if (window.FormData + && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) { + return { + // create new XMLHttpRequest + send : function(headers, callback) { + // setup all variables + var xhr = new XMLHttpRequest(), url = options.url, type = options.type, async = options.async || true, + // blob or arraybuffer. Default is blob + dataType = options.responseType || "blob", data = options.data + || null, username = options.username + || null, password = options.password + || null; + + xhr.addEventListener('load', function() { + var data = {}; + data[options.dataType] = xhr.response; + // make callback and send data + callback(xhr.status, xhr.statusText, + data, + xhr.getAllResponseHeaders()); + }); + + xhr.open(type, url, async, username, + password); + + // setup custom headers + for ( var i in headers) { + xhr.setRequestHeader(i, headers[i]); + } + + xhr.responseType = dataType; + xhr.send(data); + }, + abort : function() { + jqXHR.abort(); + } + }; + } + }); + /** * Create and initialize an appropriate viewer at supplied HTML element using specification in config @@ -13513,35 +13569,57 @@ $3Dmol.download = function(query, viewer, options, callback) { var type = ""; var pdbUri = ""; var m = viewer.addModel(); - if (query.substr(0, 4) === 'pdb:') { - pdbUri = options && options.pdbUri ? options.pdbUri : "http://www.rcsb.org/pdb/files/"; - type = options && options.format ? options.format : "pdb"; - query = query.substr(4).toUpperCase(); - if (!query.match(/^[1-9][A-Za-z0-9]{3}$/)) { - alert("Wrong PDB ID"); return; - } - if (options && options.format) - uri = pdbUri + query + "." + options.format; - else - uri = pdbUri + query + ".pdb"; - - } else if (query.substr(0, 4) == 'cid:') { - type = "sdf"; - query = query.substr(4); - if (!query.match(/^[0-9]+$/)) { - alert("Wrong Compound ID"); return; - } - uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/" + query + - "/SDF?record_type=3d"; + + if (query.substr(0, 5) === 'mmtf:') { + pdbUri = options && options.pdbUri ? options.pdbUri : "http://mmtf.rcsb.org/full/"; + query = query.substr(5).toUpperCase(); + var uri = pdbUri + query + ".mmtf"; + + $.ajax({url:uri, + type: "GET", + dataType: "binary", + responseType: "arraybuffer", + processData: false}).done( + function(ret, txt, response) { + m.addMolData(ret, 'mmtf'); + viewer.zoomTo(); + viewer.render(); + if(callback) callback(m); + }).fail(function(e,txt) { + console.log(txt); + }); } - - $.get(uri, function(ret) { - m.addMolData(ret, type, options); - viewer.zoomTo(); - viewer.render(); - if(callback) callback(m); - - }); + else { + if (query.substr(0, 4) === 'pdb:') { + pdbUri = options && options.pdbUri ? options.pdbUri : "http://www.rcsb.org/pdb/files/"; + type = options && options.format ? options.format : "pdb"; + query = query.substr(4).toUpperCase(); + if (!query.match(/^[1-9][A-Za-z0-9]{3}$/)) { + alert("Wrong PDB ID"); return; + } + if (options && options.format) + uri = pdbUri + query + "." + options.format; + else + uri = pdbUri + query + ".pdb"; + + } else if (query.substr(0, 4) == 'cid:') { + type = "sdf"; + query = query.substr(4); + if (!query.match(/^[0-9]+$/)) { + alert("Wrong Compound ID"); return; + } + uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/" + query + + "/SDF?record_type=3d"; + } + + $.get(uri, function(ret) { + m.addMolData(ret, type, options); + viewer.zoomTo(); + viewer.render(); + if(callback) callback(m); + + }); + } return m; }; @@ -13646,6 +13724,7 @@ $3Dmol.specStringToObject = function(str) { } var ret = {}; + if(str === 'all') return ret; var fields = str.split(';'); for(var i = 0; i < fields.length; i++) { var fv = fields[i].split(':'); @@ -13775,6 +13854,12 @@ $3Dmol.getPropertyRange = function (atomlist, prop) { return [ min, max ]; } +//hackish way to work with requirejs - doesn't actually work yet +//since we doing use the require optimizer to combine modules +if( typeof(define) === 'function' && define.amd) { + define('$3Dmol',$3Dmol); +} + /* * math-like functionality * quaternion, vector, matrix @@ -14388,13 +14473,17 @@ $3Dmol.Matrix3.prototype = { /** @constructor */ $3Dmol.Matrix4 = function(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) { - var te = this.elements = new Float32Array( 16 ); - - te[0] = ( n11 !== undefined ) ? n11 : 1; te[4] = n12 || 0; te[8] = n13 || 0; te[12] = n14 || 0; - te[1] = n21 || 0; te[5] = ( n22 !== undefined ) ? n22 : 1; te[9] = n23 || 0; te[13] = n24 || 0; - te[2] = n31 || 0; te[6] = n32 || 0; te[10] = ( n33 !== undefined ) ? n33 : 1; te[14] = n34 || 0; - te[3] = n41 || 0; te[7] = n42 || 0; te[11] = n43 || 0; te[15] = ( n44 !== undefined ) ? n44 : 1; - + if(typeof(n12) === 'undefined' && typeof(n11) !== 'undefined') { + //passing list like initialization + this.elements = new Float32Array(n11); + } else { + var te = this.elements = new Float32Array( 16 ); + + te[0] = ( n11 !== undefined ) ? n11 : 1; te[4] = n12 || 0; te[8] = n13 || 0; te[12] = n14 || 0; + te[1] = n21 || 0; te[5] = ( n22 !== undefined ) ? n22 : 1; te[9] = n23 || 0; te[13] = n24 || 0; + te[2] = n31 || 0; te[6] = n32 || 0; te[10] = ( n33 !== undefined ) ? n33 : 1; te[14] = n34 || 0; + te[3] = n41 || 0; te[7] = n42 || 0; te[11] = n43 || 0; te[15] = ( n44 !== undefined ) ? n44 : 1; + } }; $3Dmol.Matrix4.prototype = { @@ -14590,6 +14679,21 @@ $3Dmol.Matrix4.prototype = { return this; }, + makeTranslation: function ( x, y, z ) { + + this.set( + + 1, 0, 0, x, + 0, 1, 0, y, + 0, 0, 1, z, + 0, 0, 0, 1 + + ); + + return this; + + }, + transpose: function () { var te = this.elements; var tmp; @@ -14811,6 +14915,27 @@ $3Dmol.Matrix4.prototype = { return this.makeFrustum( xmin, xmax, ymin, ymax, near, far ); }, + + makeOrthographic: function ( left, right, top, bottom, near, far ) { + + var te = this.elements; + var w = 1.0 / ( right - left ); + var h = 1.0 / ( top - bottom ); + var p = 1.0 / ( far - near ); + + var x = ( right + left ) * w; + var y = ( top + bottom ) * h; + var z = ( far + near ) * p; + + te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x; + te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y; + te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z; + te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1; + + return this; + + }, + isEqual : function (m) { var me = m.elements; var te = this.elements; @@ -16120,7 +16245,7 @@ $3Dmol.Projector = function () { */ /** @constructor */ -$3Dmol.Camera = function(fov, aspect, near, far) { +$3Dmol.Camera = function(fov, aspect, near, far, ortho) { $3Dmol.Object3D.call(this); @@ -16133,6 +16258,14 @@ $3Dmol.Camera = function(fov, aspect, near, far) { this.projectionMatrixInverse = new $3Dmol.Matrix4(); this.matrixWorldInverse = new $3Dmol.Matrix4(); + var center = this.position.z; + this.right = center * Math.tan(Math.PI / 180 * fov); + this.left = -this.right; + this.top = this.right / this.aspect; + this.bottom = -this.top; + + this.ortho = !!ortho; + this.updateProjectionMatrix(); }; @@ -16158,7 +16291,12 @@ $3Dmol.Camera.prototype.lookAt = function(vector){ $3Dmol.Camera.prototype.updateProjectionMatrix = function () { - this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far ); + if(this.ortho) { + this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far ); + } else { + this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far ); + } + this.projectionMatrixInverse.getInverse(this.projectionMatrix); }; @@ -17391,7 +17529,7 @@ $3Dmol.Renderer = function(parameters) { _oldPolygonOffset = null, _oldPolygonOffsetFactor = null, _oldPolygonOffsetUnits = null, _oldLineWidth = null, - _viewportX = 0, _viewportY = 0, _viewportWidth = 0, _viewportHeight = 0, _currentWidth = 0, _currentHeight = 0, + _viewportWidth = 0, _viewportHeight = 0, _currentWidth = 0, _currentHeight = 0, _enabledAttributes = {}, // camera matrices cache @@ -17481,26 +17619,13 @@ $3Dmol.Renderer = function(parameters) { this.setSize = function(width, height) { - _canvas.width = width * this.devicePixelRatio; - _canvas.height = height * this.devicePixelRatio; + _viewportWidth = _canvas.width = width * this.devicePixelRatio; + _viewportHeight = _canvas.height = height * this.devicePixelRatio; _canvas.style.width = width + 'px'; _canvas.style.height = height + 'px'; - this.setViewport(0, 0, _canvas.width, _canvas.height); - - }; - - this.setViewport = function(x, y, width, height) { - - _viewportX = x !== undefined ? x : 0; - _viewportY = y !== undefined ? y : 0; - - _viewportWidth = width !== undefined ? width : _canvas.width; - _viewportHeight = height !== undefined ? height : _canvas.height; - - _gl.viewport(_viewportX, _viewportY, _viewportWidth, _viewportHeight); - + _gl.viewport(0, 0, _gl.drawingBufferWidth, _gl.drawingBufferHeight); }; this.clear = function(color, depth, stencil) { @@ -20921,7 +21046,10 @@ $(document).ready(function() { $(".viewer_3Dmoljs").each( function() { var viewerdiv = $(this); var datauri = null; - + if(viewerdiv.css('position') == 'static') { + //slight hack - canvas needs this element to be positioned + viewerdiv.css('position','relative'); + } var callback = (typeof(window[viewerdiv.data("callback")]) === 'function') ? window[viewerdiv.data("callback")] : null; @@ -21224,6 +21352,14 @@ $3Dmol.getColorFromStyle = function(atom, style) { if(val != null) { color = scheme.valueToHex(val, range); } + } else if(typeof(style.colorscheme.prop) != 'undefined' && + typeof(style.colorscheme.map) != 'undefined') { + //apply a discrete property mapping + var prop = style.colorscheme.prop; + var val = $3Dmol.getAtomProperty(atom, prop); + if( typeof style.colorscheme.map[val] != 'undefined' ) { + color = style.colorscheme.map[val]; + } } } else if(typeof(style.colorfunc) != "undefined") { @@ -21233,7 +21369,15 @@ $3Dmol.getColorFromStyle = function(atom, style) { var C = $3Dmol.CC.color(color); return C; -} +}; + +/** Preset secondary structure color scheme + * @struct + */ +$3Dmol.ssColors = $3Dmol.ssColors || {}; +//names are in helix-sheet-coil order +$3Dmol.ssColors.pyMOL = {'h': 0xff0000, 's': 0xffff00, 'c': 0x00ff00}; +$3Dmol.ssColors.Jmol = {'h': 0xff0080, 's': 0xffc800, 'c': 0xffffff}; /** Preset element coloring - from individual element colors to entire mappings (e.g. '$3Dmol.elementColors.Jmol' colors atoms with Jmol stylings) * @struct @@ -24981,6 +25125,11 @@ $3Dmol.GLModel = (function() { for (var i = 0; i < frames.length; i++) { this.setAtomDefaults(frames[i], id); } + + if(options.vibrate && options.vibrate.frames && options.vibrate.amplitude) { + //fill in vibrational modes + this.vibrate(options.vibrate.frames, options.vibrate.amplitude); + } }; @@ -26559,12 +26708,13 @@ $3Dmol.GLShape = (function() { voxel : voxel, unitCube : data.unit, origin : data.origin, + matrix: data.matrix, nX : nX, nY : nY, nZ : nZ }); - if (!voxel) + if (!voxel && smoothness > 0) $3Dmol.MarchingCube.laplacianSmooth(smoothness, verts, faces); drawCustom(this, geo, { @@ -26839,7 +26989,7 @@ $3Dmol.GLViewer = (function() { renderer.domElement.style.left = "0px"; renderer.domElement.style.zIndex = "0"; - var camera = new $3Dmol.Camera(fov, ASPECT, NEAR, FAR); + var camera = new $3Dmol.Camera(fov, ASPECT, NEAR, FAR, config.orthographic); camera.position = new $3Dmol.Vector3(camerax, 0, CAMERA_Z); var lookingAt = new $3Dmol.Vector3(); camera.lookAt(lookingAt); @@ -26891,14 +27041,13 @@ $3Dmol.GLViewer = (function() { camera.far = center + slabFar; if (camera.near + 1 > camera.far) camera.far = camera.near + 1; - if (camera instanceof $3Dmol.Camera) { - camera.fov = fov; - } else { - camera.right = center * Math.tan(Math.PI / 180 * fov); - camera.left = -camera.right; - camera.top = camera.right / ASPECT; - camera.bottom = -camera.top; - } + + camera.fov = fov; + camera.right = center * Math.tan(Math.PI / 180 * fov); + camera.left = -camera.right; + camera.top = camera.right / ASPECT; + camera.bottom = -camera.top; + camera.updateProjectionMatrix(); scene.fog.near = camera.near + fogStart * (camera.far - camera.near); @@ -27093,7 +27242,6 @@ $3Dmol.GLViewer = (function() { currentModelPos = modelGroup.position.clone(); cslabNear = slabNear; cslabFar = slabFar; - }; var _handleMouseScroll = this._handleMouseScroll = function(ev) { // Zoom @@ -27101,11 +27249,15 @@ $3Dmol.GLViewer = (function() { if (!scene) return; var scaleFactor = (CAMERA_Z - rotationGroup.position.z) * 0.85; + var mult = 1.0; + if(ev.originalEvent.ctrlKey) { + mult = -1.0; //this is a pinch event turned into a wheel event (or they're just holding down the ctrl) + } if (ev.originalEvent.detail) { // Webkit - rotationGroup.position.z += scaleFactor + rotationGroup.position.z += mult * scaleFactor * ev.originalEvent.detail / 10; } else if (ev.originalEvent.wheelDelta) { // Firefox - rotationGroup.position.z -= scaleFactor + rotationGroup.position.z -= mult * scaleFactor * ev.originalEvent.wheelDelta / 400; } if(rotationGroup.position.z > CAMERA_Z) rotationGroup.position.z = CAMERA_Z*0.999; //avoid getting stuck @@ -27139,6 +27291,7 @@ $3Dmol.GLViewer = (function() { mode = 2; dy = (newdist - touchDistanceStart) * 2 / (WIDTH + HEIGHT); + console.log("pinch "+touchDistanceStart+" dy "+dy); } else if (ev.originalEvent.targetTouches && ev.originalEvent.targetTouches.length == 3) { // translate @@ -27270,11 +27423,27 @@ $3Dmol.GLViewer = (function() { }; /** - * Enable outline - * @function $eDmol.GLViewer#outline + * Set view projection scheme. Either orthographic or perspective. + * Default is perspective. Orthographic can also be enabled on viewer creation + * by setting orthographic to true in the config object. + * + * @function $3Dmol.GLViewer#setProjection + * + * @example + * myviewer.setProjection("orthographic"); + * + */ + this.setProjection = function(proj) { + camera.ortho = (proj === "orthographic"); + setSlabAndFog(); + }; + + /** + * Set global view styles. + * @function $3Dmol.GLViewer#setViewStyle * * @example - * myviewer.outline() + * myviewer.setViewStyle({style:"outline", color:"black", width:0.1}) * */ this.setViewStyle = function(parameters) { @@ -27285,12 +27454,12 @@ $3Dmol.GLViewer = (function() { renderer.enableOutline(params); } else { renderer.disableOutline(); - } + } return this; } if(config.style) { //enable setting style in constructor - this.setViewStyle(config.style); + this.setViewStyle(config); } /** @@ -28897,7 +29066,7 @@ $3Dmol.GLViewer = (function() { /** * Adds an explicit mesh as a surface object. - * + * @function $3Dmol.GLViewer#addMesh * @param {$3Dmol.Mesh} * mesh * @param {Object} @@ -29179,7 +29348,7 @@ $3Dmol.GLViewer = (function() { /** * Set the surface material to something else, must render change - * + * @function $3Dmol.GLViewer#setSurfaceMaterialStyle * @param {number} surf - Surface ID to apply changes to * @param {matSpec} style - new material style specification */ @@ -29197,7 +29366,7 @@ $3Dmol.GLViewer = (function() { /** * Remove surface with given ID - * + * @function $3Dmol.GLViewer#removeSurface * @param {number} surf - surface id */ this.removeSurface = function(surf) { @@ -29807,6 +29976,7 @@ $3Dmol.MarchingCubeInitializer = function() { var fulltable = !!(spec.fulltable); var origin = (spec.hasOwnProperty('origin') && spec.origin.hasOwnProperty('x')) ? spec.origin : {x:0, y:0, z:0}; var voxel = !!(spec.voxel); + var transform = spec.matrix; //if this is set, it overrides origin and unitCube var nX = spec.nX || 0; var nY = spec.nY || 0; @@ -29832,7 +30002,7 @@ $3Dmol.MarchingCubeInitializer = function() { // the edge (p1,p2) var getVertex = function(i, j, k, code, p1, p2) { - var pt = {x: origin.x, y: origin.y, z: origin.z}; + var pt = {x:0,y:0,z:0}; var val1 = !!(code & (1 << p1)); var val2 = !!(code & (1 << p2)); @@ -29848,11 +30018,17 @@ $3Dmol.MarchingCubeInitializer = function() { j++; if (p & 4) i++; - - pt.x += unitCube.x*i; - pt.y += unitCube.y*j; - pt.z += unitCube.z*k; - + + if(transform) { + pt = new $3Dmol.Vector3(i,j,k); + pt = pt.applyMatrix4(transform); + pt = {x: pt.x, y: pt.y, z: pt.z}; //remove vector gunk + } else { + pt.x = origin.x+unitCube.x*i; + pt.y = origin.y+unitCube.y*j; + pt.z = origin.z+unitCube.z*k; + } + var index = ((nY * i) + j) * nZ + k; //Have to add option to do voxels @@ -30749,6 +30925,94 @@ $3Dmol.Parsers = (function() { } }; + /** + * @param {string} + * str + * @param {Object} + * options + */ + parsers.vasp = parsers.VASP = function (str, options) { + var atoms = [[]]; + var lattice = {}; + + var lines = str.replace(/^\s+/, "").split(/[\n\r]/); + + if (lines.length < 3){ + return atoms; + } + + if (lines[1].match(/\d+/)) { + lattice.length = parseFloat(lines[1]); + } else { + console.log("Warning: second line of the vasp structure file must be a number"); + return atoms; + } + + if (lattice.length<0) { + console.log("Warning: Vasp implementation for negative lattice lengths is not yet available"); + return atoms; + } + + lattice.xVec = new Float32Array(lines[2].replace(/^\s+/, "").split(/\s+/)); + lattice.yVec = new Float32Array(lines[3].replace(/^\s+/, "").split(/\s+/)); + lattice.zVec = new Float32Array(lines[4].replace(/^\s+/, "").split(/\s+/)); + + + var atomSymbols=lines[5].replace(/\s+/, "").replace(/\s+$/,"").split(/\s+/); + var atomSpeciesNumber=new Int16Array(lines[6].replace(/^\s+/, "").split(/\s+/)); + var vaspMode=lines[7].replace(/\s+/, ""); + + + if (vaspMode.match(/C/)) { + vaspMode = "cartesian"; + }else if (vaspMode.match(/D/)){ + vaspMode="direct"; + } else { + console.log("Warning: Unknown vasp mode in POSCAR file: mode must be either C(artesian) or D(irect)"); + return atoms; + } + + if (atomSymbols.length != atomSpeciesNumber.length) { + console.log("Warning: declaration of atomary species wrong:"); + console.log(atomSymbols); + console.log(atomSpeciesNumber); + return atoms; + } + + lines.splice(0,8); + + var atomCounter = 0; + + for (var i = 0, len = atomSymbols.length; i < len; i++) { + var atomSymbol = atomSymbols[i]; + for (var j = 0, atomLen = atomSpeciesNumber[i]; j < atomLen; j++) { + + var coords = new Float32Array(lines[atomCounter + j].replace(/^\s+/, "").split(/\s+/)); + + atom={}; + atom.elem = atomSymbol; + if (vaspMode == "cartesian") { + atom.x = lattice.length*coords[0]; + atom.y = lattice.length*coords[1]; + atom.z = lattice.length*coords[2]; + } else { + atom.x = lattice.length*(coords[0]*lattice.xVec[0] + coords[1]*lattice.yVec[0] + coords[2]*lattice.zVec[0]); + atom.y = lattice.length*(coords[0]*lattice.xVec[1] + coords[1]*lattice.yVec[1] + coords[2]*lattice.zVec[1]); + atom.z = lattice.length*(coords[0]*lattice.xVec[2] + coords[1]*lattice.yVec[2] + coords[2]*lattice.zVec[2]); + } + + atom.bonds=[]; + + atoms[0].push(atom); + } + atomCounter += atomSpeciesNumber[i]; + } + + return atoms; + + + } + /** * @param {string} * str @@ -31347,7 +31611,7 @@ $3Dmol.Parsers = (function() { for (var i = 0; i < atoms.length; i++) { assignBonds(atoms[i]); computeSecondaryStructure(atoms[i]); - processSymmetries(modelData[modelData.length-1].symmetries, copyMatrix, atoms[i]); + processSymmetries(modelData[i].symmetries, copyMatrix, atoms[i]); } return atoms; @@ -31806,7 +32070,7 @@ $3Dmol.Parsers = (function() { // starttime)); if (!noAssembly) - processSymmetries(modelData[modelData.length-1].symmetries, copyMatrix, atoms[n]); + processSymmetries(modelData[n].symmetries, copyMatrix, atoms[n]); if (computeStruct || !hasStruct) { starttime = (new Date()).getTime(); @@ -31871,7 +32135,10 @@ $3Dmol.Parsers = (function() { var start = atoms[atoms.length-1].length; var atom; var computeStruct = !options.noSecondaryStructure; - + var noAssembly = !options.doAssembly; // don't assemble by default + var copyMatrix = !options.duplicateAssemblyAtoms; //default true + var modelData = atoms.modelData = [{symmetries:[]}]; + var serialToIndex = []; // map from pdb serial to index in atoms var lines = str.split(/\r?\n|\r/); var i, j, k, line; @@ -31968,7 +32235,233 @@ $3Dmol.Parsers = (function() { return atoms; }; + + var fromCharCode = function( charCodeArray ){ + return String.fromCharCode.apply( null, charCodeArray ).replace(/\0/g, ''); + }; + + var convertSS = function(val) { + //convert mmtf code to 3dmol code + if(val == 2) return 'h'; + if(val == 3) return 's'; + return 'c'; + }; + + //mmtf shoul be passed as a binary UInt8Array buffer + parsers.mmtf = parsers.MMTF = function(bindata, options) { + + var noH = !options.keepH; // suppress hydrogens by default + + var mmtfData = MMTF.decode( bindata ); + var atoms = [[]]; + var modelData = atoms.modelData = []; + + // setup index counters + var modelIndex = 0; + var chainIndex = 0; + var groupIndex = 0; + var atomIndex = 0; + + // setup optional fields + var chainNameList = mmtfData.chainNameList; + var secStructList = mmtfData.secStructList; + var insCodeList = mmtfData.insCodeList; + var sequenceIndexList = mmtfData.sequenceIndexList; + var bFactorList = mmtfData.bFactorList; + var altLocList = mmtfData.altLocList; + var occupancyList = mmtfData.occupancyList; + var bondAtomList = mmtfData.bondAtomList; + var bondOrderList = mmtfData.bondOrderList; + + var numModels = mmtfData.numModels; + if (numModels == 0) return atoms; + if (!options.multimodel) numModels = 1; //first only + // hoisted loop variables + var i, j, k, kl, m, n; + + //extract symmetries - only take first assembly, apply to all models (ignoring changes for now) + var noAssembly = !options.doAssembly; // don't assemble by default + var copyMatrix = !options.duplicateAssemblyAtoms; //default true + var assemblyIndex = options.assemblyIndex ? options.assemblyIndex : 0; + + var symmetries = []; + if(mmtfData.bioAssemblyList && mmtfData.bioAssemblyList.length > 0) { + var transforms = mmtfData.bioAssemblyList[assemblyIndex].transformList; + for(i = 0, n = transforms.length; i < n; i++) { + var matrix = new $3Dmol.Matrix4(transforms[i].matrix); + matrix.transpose(); + symmetries.push(matrix); + } + } + + var bondAtomListStart = 0; //for current model + //loop over models, + for (m = 0; m < numModels; m++ ) { + var modelChainCount = mmtfData.chainsPerModel[m]; + var matoms = atoms[atoms.length-1]; + var serialToIndex = []; // map to matoms index, needed for noh + + modelData.push({symmetries:symmetries}); + for( i = 0; i < modelChainCount; ++i ){ + + var chainGroupCount = mmtfData.groupsPerChain[ chainIndex ]; + var chainId = fromCharCode( + mmtfData.chainIdList.subarray( chainIndex * 4, chainIndex * 4 + 4 ) + ); + + var startGroup = groupIndex; + for( j = 0; j < chainGroupCount; ++j ){ //over residues (groups) + + var groupData = mmtfData.groupList[ mmtfData.groupTypeList[ groupIndex ] ]; + var groupAtomCount = groupData.atomNameList.length; + var secStruct = 0; + if( secStructList ){ + secStruct = secStructList[ groupIndex ]; + } + var insCode = null; + if( mmtfData.insCodeList ){ + insCode = String.fromCharCode( insCodeList[ groupIndex ] ); + } + var sequenceIndex = null; + if( sequenceIndexList ){ + sequenceIndex = sequenceIndexList[ groupIndex ]; + } + + var groupId = mmtfData.groupIdList[ groupIndex ]; + var groupName = groupData.groupName; + var startAtom = atomIndex; + + for( k = 0; k < groupAtomCount; ++k ){ + + var element = groupData.elementList[ k ]; + if(noH && element == 'H') { + atomIndex += 1; + continue; + } + + var bFactor = ''; + if( bFactorList ){ + bFactor = bFactorList[ atomIndex ]; + } + var altLoc = ' '; + if( altLocList ){ + altLoc = String.fromCharCode( altLocList[ atomIndex ] ); + } + var occupancy = ''; + if( occupancyList ){ + occupancy = occupancyList[ atomIndex ]; + } + + var atomId = mmtfData.atomIdList[ atomIndex ]; + var atomName = groupData.atomNameList[ k ]; + var atomCharge = groupData.atomChargeList[ k ]; + var xCoord = mmtfData.xCoordList[ atomIndex ]; + var yCoord = mmtfData.yCoordList[ atomIndex ]; + var zCoord = mmtfData.zCoordList[ atomIndex ]; + + serialToIndex[atomIndex] = matoms.length; + matoms.push({ + 'resn' : groupName, + 'x' : xCoord, + 'y' : yCoord, + 'z' : zCoord, + 'elem' : element, + 'hetflag' : secStruct < 0, + 'chain' : chainId, + 'resi' : groupId, + 'icode' : altLoc, + 'rescode' : groupId + (altLoc != ' ' ? "^" + altLoc : ""), // combo + // resi + // and + // icode + 'serial' : atomId, + 'atom' : atomName, + 'bonds' : [], + 'ss' : convertSS(secStruct), + 'bondOrder' : [], + 'properties' : {charge: atomCharge, occupancy:occupancy}, + 'b' : bFactor, + }); + + atomIndex += 1; + } + + // intra group bonds + var groupBondAtomList = groupData.bondAtomList; + for( k = 0, kl = groupData.bondOrderList.length; k < kl; ++k ){ + var atomIndex1 = startAtom + groupBondAtomList[ k * 2 ]; + var atomIndex2 = startAtom + groupBondAtomList[ k * 2 + 1 ]; + var bondOrder = groupData.bondOrderList[ k ]; + + //I assume bonds are only recorded once + var i1 = serialToIndex[atomIndex1]; + var i2 = serialToIndex[atomIndex2]; + var a1 = matoms[i1]; + var a2 = matoms[i2]; + if(a1 && a2) { + a1.bonds.push(i2) + a1.bondOrder.push(bondOrder); + a2.bonds.push(i1); + a2.bondOrder.push(bondOrder); + } + } + + groupIndex += 1; + } + + //reset for bonds + groupIndex = startGroup; + for( j = 0; j < chainGroupCount; ++j ){ //over residues (groups) + + groupIndex += 1; + + } + + chainIndex += 1; + } + + + // inter group bonds + if( bondAtomList ){ + for( k = bondAtomListStart, kl = bondAtomList.length; k < kl; k += 2 ){ + var atomIndex1 = bondAtomList[ k ]; + var atomIndex2 = bondAtomList[ k + 1 ]; + var bondOrder = bondOrderList ? bondOrderList[ k / 2 ] : 1; + + if(atomIndex1 >= atomIndex) { + bondAtomListStart = k; + break; //on next model + } + //I assume bonds are only recorded once + var i1 = serialToIndex[atomIndex1]; + var i2 = serialToIndex[atomIndex2]; + var a1 = matoms[i1]; + var a2 = matoms[i2]; + if(a1 && a2) { + a1.bonds.push(i2) + a1.bondOrder.push(bondOrder); + a2.bonds.push(i1); + a2.bondOrder.push(bondOrder); + } + } + } + + if (options.multimodel) { + if (!options.onemol) atoms.push([]); + } + modelIndex += 1; + } + + + for (var n = 0; n < atoms.length; n++) { + if (!noAssembly) + processSymmetries(modelData[n].symmetries, copyMatrix, atoms[n]); + } + + return atoms; + }; + return parsers; })(); var $3Dmol = $3Dmol || {}; @@ -32336,8 +32829,9 @@ $3Dmol.applyPartialCharges = function(atom, keepexisting) { * @class * @param {string} str - volumetric data * @param {string} format - format of supplied data (cube) + * @param {Object} options - normalize (zero mean, unit variance), negate */ -$3Dmol.VolumeData = function(str, format) { +$3Dmol.VolumeData = function(str, format, options) { this.unit = { x : 1, @@ -32357,10 +32851,49 @@ $3Dmol.VolumeData = function(str, format) { this.data = new Float32Array([]); // actual floating point data, arranged // x->y->z + this.matrix = null; //if set must transform data format = format.toLowerCase(); + + if(/\.gz$/.test(format)) { + //unzip gzipped files + format = format.replace(/\.gz$/,''); + try { + str = pako.inflate(str); + } catch(err) { + console.log(err); + } + } + if (this[format]) { this[format](str); } + + if(options) { + if(options.negate) { + for(var i = 0, n = this.data.length; i < n; i++) { + this.data[i] = -this.data[i]; + } + } + if(options.normalize) { + var total = 0.0; + for(var i = 0, n = this.data.length; i < n; i++) { + total += this.data[i]; + } + var mean = total/this.data.length; + console.log("computed mean: "+mean); + total = 0; + for(var i = 0, n = this.data.length; i < n; i++) { + var diff = this.data[i]-mean; + total += diff*diff; //variance is ave of squared difference with mean + } + var variance = total/this.data.length; + console.log("Computed variance: "+variance); + //now normalize + for(var i = 0, n = this.data.length; i < n; i++) { + this.data[i] = (this.data[i]-mean)/variance; + } + } + } }; /** @@ -32388,6 +32921,111 @@ $3Dmol.VolumeData.prototype.getVal = function(x,y,z) { return this.data[x*this.size.y*this.size.z + y*this.size.z + z]; }; +/* + * parse vasp data + * Essentially this parser converts the CHGCAR data into + * cube data. It has been adapted from 'chg2cube.pl' found in + * http://theory.cm.utexas.edu/vtsttools/ + */ +$3Dmol.VolumeData.prototype.vasp = function(str) { + + var lines = str.replace(/^\s+/, "").split(/[\n\r]/); + + var atomicData = $3Dmol.Parsers.vasp(str)[0]; + var natoms = atomicData.length; + + if (natoms == 0) { + console.log("No good formating of CHG or CHGCAR file, not atomic information provided in the file."); + this.data = []; + return; + } + + + + // Assume atomic units + var unittype = "bohr/hartree"; + var l_units = 1.889725992; + var e_units = 0.036749309; + + // copied from $3Dmol.Parsers.vasp + var convFactor = parseFloat(lines[1]); + // This is how Vasp reads in the basis We need the l_units in order to + // compute the volume of the cell. Afterwards to obtain the axis for the + // voxels we have to remove this unit and divide by the number of voxels in + // each dimension + var v; + v=lines[2].replace(/^\s+/, "").split(/\s+/); + var xVec = new $3Dmol.Vector3(parseFloat(v[0]),parseFloat(v[1]),parseFloat(v[2])).multiplyScalar(convFactor*l_units); + v=lines[3].replace(/^\s+/, "").split(/\s+/); + var yVec = new $3Dmol.Vector3(parseFloat(v[0]),parseFloat(v[1]),parseFloat(v[2])).multiplyScalar(convFactor*l_units); + v=lines[4].replace(/^\s+/, "").split(/\s+/); + var zVec = new $3Dmol.Vector3(parseFloat(v[0]),parseFloat(v[1]),parseFloat(v[2])).multiplyScalar(convFactor*l_units); + + // correct volume for non-orthognal box (expansion by minors) + var vol = xVec.x*(yVec.y*zVec.z - zVec.y*yVec.z) - yVec.x*(xVec.y*zVec.z - zVec.y*xVec.z) + zVec.x*(xVec.y*yVec.z - yVec.y*xVec.z); + + vol = Math.abs(vol)/(Math.pow(l_units,3)); + var vol_scale = 1.0/(vol); //This Only for CHGCAR files + + // We splice the structure information + // 2 (header) + 3 (vectors) + 2 (atoms) + 1 (vaspMode) + natoms (coords) + 1 (blank line) + lines.splice(0,2+3+2+1+natoms+1); + + + var lineArr = lines[0].replace(/^\s+/, "").replace(/\s+/g, " ").split(" "); + + var nX = Math.abs(lineArr[0]); + var nY = Math.abs(lineArr[1]); + var nZ = Math.abs(lineArr[2]); + + var origin = this.origin = new $3Dmol.Vector3(0,0,0); + + this.size = {x:nX, y:nY, z:nZ}; + this.unit = new $3Dmol.Vector3(xVec.x, yVec.y, zVec.z); + + // resize the vectors accordingly + xVec = xVec.multiplyScalar(1/(l_units*nX)); + yVec = yVec.multiplyScalar(1/(l_units*nY)); + zVec = zVec.multiplyScalar(1/(l_units*nZ)); + + if (xVec.y != 0 || xVec.z != 0 || yVec.x != 0 || yVec.z != 0 || zVec.x != 0 + || zVec.y != 0) { + //need a transformation matrix + this.matrix = new $3Dmol.Matrix4(xVec.x, yVec.x, zVec.x, 0, xVec.y, yVec.y, zVec.y, 0, xVec.z, yVec.z, zVec.z, 0, 0,0,0,1); + //include translation in matrix + this.matrix = this.matrix.multiplyMatrices(this.matrix, + new $3Dmol.Matrix4().makeTranslation(origin.x, origin.y, origin.z)); + //all translation and scaling done by matrix, so reset origin and unit + this.origin = new $3Dmol.Vector3(0,0,0); + this.unit = new $3Dmol.Vector3(1,1,1); + } + + + lines.splice(0,1); //Remove the dimension line + var raw = lines.join(" "); + + raw = raw.replace(/^\s+/,''); + raw = raw.split(/[\s\r]+/); + raw.splice(nX*nY*nZ+1); + + var preConvertedData = new Float32Array(raw); //We still have to format it to get the density + + for (var i = 0; i< preConvertedData.length; i++){ + preConvertedData[i] = preConvertedData[i]*vol_scale*e_units; + } + + this.data = preConvertedData; + + //console.log(xVec); + //console.log(yVec); + //console.log(zVec); + //console.log(this.unit); + //console.log(this.origin); + //console.log(this.matrix); + //console.log(this.data); + +}; + // parse cube data $3Dmol.VolumeData.prototype.cube = function(str) { var lines = str.replace(/^\s+/, "").split(/[\n\r]+/); @@ -32436,9 +33074,17 @@ $3Dmol.VolumeData.prototype.cube = function(str) { this.unit = new $3Dmol.Vector3(xVec.x, yVec.y, zVec.z); if (xVec.y != 0 || xVec.z != 0 || yVec.x != 0 || yVec.z != 0 || zVec.x != 0 - || zVec.y != 0) - console - .log("Warning: Cube file is not axis aligned. This isn't going to look right."); + || zVec.y != 0) { + //need a transformation matrix + this.matrix = new $3Dmol.Matrix4(xVec.x, yVec.x, zVec.x, 0, xVec.y, yVec.y, zVec.y, 0, xVec.z, yVec.z, zVec.z, 0, 0,0,0,1); + //include translation in matrix + this.matrix = this.matrix.multiplyMatrices(this.matrix, + new $3Dmol.Matrix4().makeTranslation(origin.x, origin.y, origin.z)); + //all translation and scaling done by matrix, so reset origin and unit + this.origin = new $3Dmol.Vector3(0,0,0); + this.unit = new $3Dmol.Vector3(1,1,1); + } + var headerlines = 6; if(atomsnum < 0) headerlines++; //see: http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/cubeplugin.html var raw = lines.splice(natoms + headerlines).join(" "); @@ -32452,94 +33098,197 @@ $3Dmol.VolumeData.prototype.cube = function(str) { $3Dmol.VolumeData.prototype.ccp4 = function(bin) { // http://www.ccp4.ac.uk/html/maplib.html#description - - var header = {}; - - var intView = new Int32Array( bin, 0, 56 ); - var floatView = new Float32Array( bin, 0, 56 ); - - //# of columns (fastest changing),rows, sections (slowest changing) - header.NX = intView[ 0 ]; - header.NY = intView[ 1 ]; - header.NZ = intView[ 2 ]; - - // mode - // 0 image : signed 8-bit bytes range -128 to 127 - // 1 image : 16-bit halfwords - // 2 image : 32-bit reals - // 3 transform : complex 16-bit integers - // 4 transform : complex 32-bit reals - // 6 image : unsigned 16-bit range 0 to 65535 - // 16 image: unsigned char * 3 (for rgb data, non-standard) - header.MODE = intView[ 3 ]; - - //position of first column, first row, and first section (voxel grid units) - header.NCSTART = intView[ 4 ]; - header.NRSTART = intView[ 5 ]; - header.NSSTART = intView[ 6 ]; - - //intervals per unit cell repeat along X,Y Z - header.MX = Math.abs(intView[ 7 ]); - header.MY = Math.abs(intView[ 8 ]); - header.MZ = Math.abs(intView[ 9 ]); - - //Map lengths along X,Y,Z in Ã…ngstroms - header.xlen = floatView[ 10 ]; - header.ylen = floatView[ 11 ]; - header.zlen = floatView[ 12 ]; - - //single voxel lengths - xVox = header.xlen / header.NX; - yVox = header.ylen / header.NY; - zVox = header.zlen / header.NZ; - - // cell angle - header.alpha = floatView[ 13 ]; - header.beta = floatView[ 14 ]; - header.gamma = floatView[ 15 ]; - - //relationship of X,Y,Z axes to columns, rows, sections - header.MAPC = intView[ 16 ]; - switch (header.MAPC){ - case 1: header.NXSTART = header.NCSTART; header.NYSTART = 0; header.NZSTART = 0; break; - case 2: header.NYSTART = header.NCSTART; header.NXSTART = 0; header.NZSTART = 0; break; - case 3: header.NZSTART = header.NCSTART; header.NXSTART = 0; header.NYSTART = 0; break; - } - header.MAPR = intView[ 17 ]; - switch (header.MAPR){ - case 1: header.NXSTART = header.NRSTART; header.NYSTART = 0; header.NZSTART = 0; break; - case 2: header.NYSTART = header.NRSTART; header.NXSTART = 0; header.NZSTART = 0; break; - case 3: header.NZSTART = header.NRSTART; header.NXSTART = 0; header.NYSTART = 0; break; - } - header.MAPS = intView[ 18 ]; - switch (header.MAPS){ - case 1: header.NXSTART = header.NSSTART; header.NYSTART = 0; header.NZSTART = 0; break; - case 2: header.NYSTART = header.NSSTART; header.NXSTART = 0; header.NZSTART = 0; break; - case 3: header.NZSTART = header.NSSTART; header.NXSTART = 0; header.NYSTART = 0; break; - } - - //Origin Position - this.origin = new $3Dmol.Vector3(header.NXSTART, header.NYSTART, header.NZSTART); - - //Minimum, maximum, average density - header.DMIN = floatView[ 19 ]; - header.DMAX = floatView[ 20 ]; - header.DMEAN = floatView[ 21 ]; - - // space group number 0 or 1 (default=0) - header.ISPG = intView[ 22 ]; - - // number of bytes used for symmetry data (0 or 80) - header.NSYMBT = intView[23]; - - // machine stamp - header.ARMS = floatView[54]; - - this.size = {x:header.MX, y:header.MY, z:header.MZ}; - this.unit = new $3Dmol.Vector3(xVox, yVox, zVox ); - var byteData = new Int8Array(bin); - this.data = new Float32Array(bin, 1024 + header.NSYMBT); - + //code from ngl: https://github.com/arose/ngl/blob/master/js/ngl/parser.js + var header = {}; + bin = new Int8Array(bin); + var intView = new Int32Array( bin.buffer, 0, 56 ); + var floatView = new Float32Array( bin.buffer, 0, 56 ); + var dv = new DataView( bin.buffer ); + + + // 53 MAP Character string 'MAP ' to identify file type + header.MAP = String.fromCharCode( + dv.getUint8( 52 * 4 ), dv.getUint8( 52 * 4 + 1 ), + dv.getUint8( 52 * 4 + 2 ), dv.getUint8( 52 * 4 + 3 ) + ); + + // 54 MACHST Machine stamp indicating machine type which wrote file + // 17 and 17 for big-endian or 68 and 65 for little-endian + header.MACHST = [ dv.getUint8( 53 * 4 ), dv.getUint8( 53 * 4 + 1 ) ]; + + // swap byte order when big endian + if( header.MACHST[ 0 ] === 17 && header.MACHST[ 1 ] === 17 ){ + var n = bin.byteLength; + for( var i = 0; i < n; i+=4 ){ + dv.setFloat32( i, dv.getFloat32( i ), true ); + } + } + + header.NX = intView[ 0 ]; // NC - columns (fastest changing) + header.NY = intView[ 1 ]; // NR - rows + header.NZ = intView[ 2 ]; // NS - sections (slowest changing) + + // mode + // 0 image : signed 8-bit bytes range -128 to 127 + // 1 image : 16-bit halfwords + // 2 image : 32-bit reals + // 3 transform : complex 16-bit integers + // 4 transform : complex 32-bit reals + // 6 image : unsigned 16-bit range 0 to 65535 + // 16 image: unsigned char * 3 (for rgb data, non-standard) + // + // Note: Mode 2 is the normal mode used in the CCP4 programs. + // Other modes than 2 and 0 may NOT WORK + header.MODE = intView[ 3 ]; + + // start + header.NXSTART = intView[ 4 ]; // NCSTART - first column + header.NYSTART = intView[ 5 ]; // NRSTART - first row + header.NZSTART = intView[ 6 ]; // NSSTART - first section + + // intervals + header.MX = intView[ 7 ]; // intervals along x + header.MY = intView[ 8 ]; // intervals along y + header.MZ = intView[ 9 ]; // intervals along z + + // cell length (Angstroms in CCP4) + header.xlen = floatView[ 10 ]; + header.ylen = floatView[ 11 ]; + header.zlen = floatView[ 12 ]; + + // cell angle (Degrees) + header.alpha = floatView[ 13 ]; + header.beta = floatView[ 14 ]; + header.gamma = floatView[ 15 ]; + + // axis correspondence (1,2,3 for X,Y,Z) + header.MAPC = intView[ 16 ]; // column + header.MAPR = intView[ 17 ]; // row + header.MAPS = intView[ 18 ]; // section + + // density statistics + header.DMIN = floatView[ 19 ]; + header.DMAX = floatView[ 20 ]; + header.DMEAN = floatView[ 21 ]; + + // space group number 0 or 1 (default=0) + header.ISPG = intView[ 22 ]; + + // number of bytes used for symmetry data (0 or 80) + header.NSYMBT = intView[ 23 ]; + + // Flag for skew transformation, =0 none, =1 if foll + header.LSKFLG = intView[ 24 ]; + + // 26-34 SKWMAT Skew matrix S (in order S11, S12, S13, S21 etc) if + // LSKFLG .ne. 0. + // 35-37 SKWTRN Skew translation t if LSKFLG != 0. + // Skew transformation is from standard orthogonal + // coordinate frame (as used for atoms) to orthogonal + // map frame, as Xo(map) = S * (Xo(atoms) - t) + + // 38 future use (some of these are used by the MSUBSX routines + // . " in MAPBRICK, MAPCONT and FRODO) + // . " (all set to zero by default) + // . " + // 52 " + + // 50-52 origin in X,Y,Z used for transforms + header.originX = floatView[ 49 ]; + header.originY = floatView[ 50 ]; + header.originZ = floatView[ 51 ]; + + // 53 MAP Character string 'MAP ' to identify file type + // => see top of this parser + + // 54 MACHST Machine stamp indicating machine type which wrote file + // => see top of this parser + + // Rms deviation of map from mean density + header.ARMS = floatView[ 54 ]; + + // 56 NLABL Number of labels being used + // 57-256 LABEL(20,10) 10 80 character text labels (ie. A4 format) + console.log("Map has min,mean,average,rmsddv: "+header.DMIN+","+header.DMAX+","+header.DMEAN+","+header.ARMS); + + //create transformation matrix, code mostly copied from ngl + var h = header; + var basisX = [ + h.xlen, + 0, + 0 + ]; + + var basisY = [ + h.ylen * Math.cos( Math.PI / 180.0 * h.gamma ), + h.ylen * Math.sin( Math.PI / 180.0 * h.gamma ), + 0 + ]; + + var basisZ = [ + h.zlen * Math.cos( Math.PI / 180.0 * h.beta ), + h.zlen * ( + Math.cos( Math.PI / 180.0 * h.alpha ) + - Math.cos( Math.PI / 180.0 * h.gamma ) + * Math.cos( Math.PI / 180.0 * h.beta ) + ) / Math.sin( Math.PI / 180.0 * h.gamma ), + 0 + ]; + basisZ[ 2 ] = Math.sqrt( + h.zlen * h.zlen * Math.sin( Math.PI / 180.0 * h.beta ) * + Math.sin( Math.PI / 180.0 * h.beta ) - basisZ[ 1 ] * basisZ[ 1 ] + ); + + var basis = [ 0, basisX, basisY, basisZ ]; + var nxyz = [ 0, h.MX, h.MY, h.MZ ]; + var mapcrs = [ 0, h.MAPC, h.MAPR, h.MAPS ]; + + this.matrix = new $3Dmol.Matrix4(); + + this.matrix.set( + + basis[ mapcrs[1] ][0] / nxyz[ mapcrs[1] ], + basis[ mapcrs[2] ][0] / nxyz[ mapcrs[2] ], + basis[ mapcrs[3] ][0] / nxyz[ mapcrs[3] ], + 0, + + basis[ mapcrs[1] ][1] / nxyz[ mapcrs[1] ], + basis[ mapcrs[2] ][1] / nxyz[ mapcrs[2] ], + basis[ mapcrs[3] ][1] / nxyz[ mapcrs[3] ], + 0, + + basis[ mapcrs[1] ][2] / nxyz[ mapcrs[1] ], + basis[ mapcrs[2] ][2] / nxyz[ mapcrs[2] ], + basis[ mapcrs[3] ][2] / nxyz[ mapcrs[3] ], + 0, + + 0, 0, 0, 1 + + ); + //include translation in matrix + this.matrix = this.matrix.multiplyMatrices(this.matrix, + new $3Dmol.Matrix4().makeTranslation( + h.NXSTART + h.originX, + h.NYSTART + h.originY, + h.NZSTART + h.originZ)); + //all translation and scaling done by matrix, so reset origin and unit + this.origin = new $3Dmol.Vector3(0,0,0); + this.unit = new $3Dmol.Vector3(1,1,1); + this.size = {x:header.NX, y:header.NY, z:header.NZ}; + var data = new Float32Array(bin.buffer, 1024 + header.NSYMBT); + //data must by (slowest changing) x,y,z (fastest changing) + + var NX = header.NX, NY = header.NY, NZ = header.NZ; + this.data = new Float32Array(NX*NY*NZ); + for(var i = 0; i < NX; i++) { + for(var j = 0; j < NY; j++) { + for(var k = 0; k < NZ; k++) { + //should I be concerned that I'm not using mapc? + this.data[((i*NY)+j)*NZ+k] = data[((k*NY)+j)*NX+i]; + } + } + } + }; //Hackish way to create webworker (independent of $3Dmol namespace) within minified file $3Dmol.workerString = function(){