From 2b07a0b2a50464fd3d9b00473edcd646b904504f Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 24 Sep 2020 13:25:06 -0400 Subject: [PATCH] Fix PV Protein Viewer build --- client/gulpfile.js | 1 + config/plugins/visualizations/pv/package.json | 5 ++- config/plugins/visualizations/pv/src/pv.js | 37 +++++++++++-------- config/plugins/visualizations/pv/static/pv.js | 5 --- 4 files changed, 25 insertions(+), 23 deletions(-) delete mode 100644 config/plugins/visualizations/pv/static/pv.js diff --git a/client/gulpfile.js b/client/gulpfile.js index 45ba4957fab..af08c7f185e 100644 --- a/client/gulpfile.js +++ b/client/gulpfile.js @@ -18,6 +18,7 @@ const PLUGIN_BUILD_DIRS = [ "media_player", "mvpapp", "openlayers", + "pv", ]; const paths = { diff --git a/config/plugins/visualizations/pv/package.json b/config/plugins/visualizations/pv/package.json index 57f402c98da..15185285aa3 100644 --- a/config/plugins/visualizations/pv/package.json +++ b/config/plugins/visualizations/pv/package.json @@ -10,10 +10,11 @@ "dependencies": { "babel-preset-env": "^1.6.1", "backbone": "^1.3.3", + "bio-pv": "^1.8.1", "bootstrap": "^3.3.7", - "jquery": "^3.1.1", + "jquery": "^3.5.1", "parcel-bundler": "^1.4.1", - "bio-pv": "^1.8.1" + "underscore": "^1.11.0" }, "scripts": { "build": "parcel build src/pv.js -d static" diff --git a/config/plugins/visualizations/pv/src/pv.js b/config/plugins/visualizations/pv/src/pv.js index 5aa7a62a72f..1bd83d3ee7e 100644 --- a/config/plugins/visualizations/pv/src/pv.js +++ b/config/plugins/visualizations/pv/src/pv.js @@ -1,35 +1,40 @@ import * as pv from "bio-pv"; +import _ from "underscore"; +import $ from "jquery"; + _.extend(window.bundleEntries || {}, { - load: function(options) { + load: function (options) { var settings = options.chart.settings; var viewer = pv.Viewer(document.getElementById(options.targets[0]), { - quality: settings.get('quality'), - width: 'auto', - height: 'auto', + quality: settings.get("quality"), + width: "auto", + height: "auto", antialias: true, - outline: true + outline: true, }); - $.ajax( { + $.ajax({ url: options.dataset.download_url, cache: true, - success: function(response) { + success: function (response) { var structure = pv.io.pdb(response); var viewer_options = {}; - _.each(settings.attributes, function(value, key) { - viewer_options[key.replace('viewer|', '')] = value; + _.each(settings.attributes, function (value, key) { + viewer_options[key.replace("viewer|", "")] = value; }); viewer.clear(); - viewer.renderAs('protein', structure, viewer_options.mode, viewer_options); + viewer.renderAs("protein", structure, viewer_options.mode, viewer_options); viewer.centerOn(structure); viewer.autoZoom(); - options.chart.state('ok', 'Chart drawn.'); + options.chart.state("ok", "Chart drawn."); options.process.resolve(); }, - error: function() { - options.chart.state('ok', 'Failed to load pdb file.'); + error: function () { + options.chart.state("ok", "Failed to load pdb file."); options.process.resolve(); - } + }, }); - $(window).resize(function() { viewer.fitParent() }); - } + $(window).resize(function () { + viewer.fitParent(); + }); + }, }); diff --git a/config/plugins/visualizations/pv/static/pv.js b/config/plugins/visualizations/pv/static/pv.js deleted file mode 100644 index f65940bb99f..00000000000 --- a/config/plugins/visualizations/pv/static/pv.js +++ /dev/null @@ -1,5 +0,0 @@ -require=function(r,e,n){function t(n,o){function i(r){return t(i.resolve(r))}function f(e){return r[n][1][e]||e}if(!e[n]){if(!r[n]){var c="function"==typeof require&&require;if(!o&&c)return c(n,!0);if(u)return u(n,!0);var l=new Error("Cannot find module '"+n+"'");throw l.code="MODULE_NOT_FOUND",l}i.resolve=f;var a=e[n]=new t.Module;r[n][0].call(a.exports,i,a,a.exports)}return e[n].exports}function o(){this.bundle=t,this.exports={}}var u="function"==typeof require&&require;t.Module=o,t.modules=r,t.cache=e,t.parent=u;for(var i=0;i0&&(a=1/Math.sqrt(a),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a),t},s.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},s.cross=function(t,e,r){var n=e[0],i=e[1],a=e[2],s=r[0],o=r[1],h=r[2];return t[0]=i*h-a*o,t[1]=a*s-n*h,t[2]=n*o-i*s,t},s.lerp=function(t,e,r,n){var i=e[0],a=e[1],s=e[2];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=s+n*(r[2]-s),t},s.random=function(t,e){e=e||1;var r=2*n()*Math.PI,i=2*n()-1,a=Math.sqrt(1-i*i)*e;return t[0]=Math.cos(r)*a,t[1]=Math.sin(r)*a,t[2]=i*e,t},s.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12],t[1]=r[1]*n+r[5]*i+r[9]*a+r[13],t[2]=r[2]*n+r[6]*i+r[10]*a+r[14],t},s.transformMat3=function(t,e,r){var n=e[0],i=e[1],a=e[2];return t[0]=n*r[0]+i*r[3]+a*r[6],t[1]=n*r[1]+i*r[4]+a*r[7],t[2]=n*r[2]+i*r[5]+a*r[8],t},s.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],s=r[0],o=r[1],h=r[2],u=r[3],l=u*n+o*a-h*i,c=u*i+h*n-s*a,d=u*a+s*i-o*n,f=-s*n-o*i-h*a;return t[0]=l*u+f*-s+c*-h-d*-o,t[1]=c*u+f*-o+d*-s-l*-h,t[2]=d*u+f*-h+l*-o-c*-s,t},s.forEach=(a=s.create(),function(t,e,r,n,i,s){var o,h;for(e||(e=3),r||(r=0),h=n?Math.min(n*e+r,t.length):t.length,o=r;o0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t[3]=e[3]*s),t},o.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},o.lerp=function(t,e,r,n){var i=e[0],a=e[1],s=e[2],o=e[3];return t[0]=i+n*(r[0]-i),t[1]=a+n*(r[1]-a),t[2]=s+n*(r[2]-s),t[3]=o+n*(r[3]-o),t},o.random=function(t,e){return e=e||1,t[0]=n(),t[1]=n(),t[2]=n(),t[3]=n(),o.normalize(t,t),o.scale(t,t,e),t},o.transformMat4=function(t,e,r){var n=e[0],i=e[1],a=e[2],s=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*s,t[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*s,t[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*s,t[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*s,t},o.transformQuat=function(t,e,r){var n=e[0],i=e[1],a=e[2],s=r[0],o=r[1],h=r[2],u=r[3],l=u*n+o*a-h*i,c=u*i+h*n-s*a,d=u*a+s*i-o*n,f=-s*n-o*i-h*a;return t[0]=l*u+f*-s+c*-h-d*-o,t[1]=c*u+f*-o+d*-s-l*-h,t[2]=d*u+f*-h+l*-o-c*-s,t},o.forEach=function(){var t=o.create();return function(e,r,n,i,a,s){var o,h;for(r||(r=4),n||(n=0),h=i?Math.min(i*r+n,e.length):e.length,o=n;o.999999?(t[0]=0,t[1]=0,t[2]=0,t[3]=1,t):(s.cross(l,e,r),t[0]=l[0],t[1]=l[1],t[2]=l[2],t[3]=1+n,m.normalize(t,t))}),m.setAxes=(f=h.create(),function(t,e,r,n){return f[0]=r[0],f[3]=r[1],f[6]=r[2],f[1]=n[0],f[4]=n[1],f[7]=n[2],f[2]=e[0],f[5]=e[1],f[8]=e[2],m.normalize(t,m.fromMat3(t,f))}),m.clone=o.clone,m.fromValues=o.fromValues,m.copy=o.copy,m.set=o.set,m.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},m.setAxisAngle=function(t,e,r){r*=.5;var n=Math.sin(r);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(r),t},m.add=o.add,m.multiply=function(t,e,r){var n=e[0],i=e[1],a=e[2],s=e[3],o=r[0],h=r[1],u=r[2],l=r[3];return t[0]=n*l+s*o+i*u-a*h,t[1]=i*l+s*h+a*o-n*u,t[2]=a*l+s*u+n*h-i*o,t[3]=s*l-n*o-i*h-a*u,t},m.mul=m.multiply,m.scale=o.scale,m.rotateX=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],s=e[3],o=Math.sin(r),h=Math.cos(r);return t[0]=n*h+s*o,t[1]=i*h+a*o,t[2]=a*h-i*o,t[3]=s*h-n*o,t},m.rotateY=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],s=e[3],o=Math.sin(r),h=Math.cos(r);return t[0]=n*h-a*o,t[1]=i*h+s*o,t[2]=a*h+n*o,t[3]=s*h-i*o,t},m.rotateZ=function(t,e,r){r*=.5;var n=e[0],i=e[1],a=e[2],s=e[3],o=Math.sin(r),h=Math.cos(r);return t[0]=n*h+i*o,t[1]=i*h-n*o,t[2]=a*h+s*o,t[3]=s*h-a*o,t},m.calculateW=function(t,e){var r=e[0],n=e[1],i=e[2];return t[0]=r,t[1]=n,t[2]=i,t[3]=-Math.sqrt(Math.abs(1-r*r-n*n-i*i)),t},m.dot=o.dot,m.lerp=o.lerp,m.slerp=function(t,e,r,n){var i,a,s,o,h,u=e[0],l=e[1],c=e[2],d=e[3],f=r[0],_=r[1],m=r[2],v=r[3];return(a=u*f+l*_+c*m+d*v)<0&&(a=-a,f=-f,_=-_,m=-m,v=-v),1-a>1e-6?(i=Math.acos(a),s=Math.sin(i),o=Math.sin((1-n)*i)/s,h=Math.sin(n*i)/s):(o=1-n,h=n),t[0]=o*u+h*f,t[1]=o*l+h*_,t[2]=o*c+h*m,t[3]=o*d+h*v,t},m.invert=function(t,e){var r=e[0],n=e[1],i=e[2],a=e[3],s=r*r+n*n+i*i+a*a,o=s?1/s:0;return t[0]=-r*o,t[1]=-n*o,t[2]=-i*o,t[3]=a*o,t},m.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},m.length=o.length,m.len=m.length,m.squaredLength=o.squaredLength,m.sqrLen=m.squaredLength,m.normalize=o.normalize,m.fromMat3=(_="undefined"!=typeof Int8Array?new Int8Array([1,2,0]):[1,2,0],function(t,e){var r,n=e[0]+e[4]+e[8];if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(e[7]-e[5])*r,t[1]=(e[2]-e[6])*r,t[2]=(e[3]-e[1])*r;else{var i=0;e[4]>e[0]&&(i=1),e[8]>e[3*i+i]&&(i=2);var a=_[i],s=_[a];r=Math.sqrt(e[3*i+i]-e[3*a+a]-e[3*s+s]+1),t[i]=.5*r,r=.5/r,t[3]=(e[3*s+a]-e[3*a+s])*r,t[a]=(e[3*a+i]+e[3*i+a])*r,t[s]=(e[3*s+i]+e[3*i+s])*r}return t}),m.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},t.quat=m,t}(),e=function(){var e=t.vec4,r={rgb:{}},n=r.rgb;r.rgb.create=e.create,r.rgb.scale=e.scale,r.rgb.copy=e.copy,r.rgb.fromValues=e.fromValues,r.rgb.mix=function(t,e,r,n){var i=1-n;return t[0]=e[0]*n+r[0]*i,t[1]=e[1]*n+r[1]*i,t[2]=e[2]*n+r[2]*i,t[3]=e[3]*n+r[3]*i,t};var i={white:n.fromValues(1,1,1,1),black:n.fromValues(0,0,0,1),grey:n.fromValues(.5,.5,.5,1),lightgrey:n.fromValues(.8,.8,.8,1),darkgrey:n.fromValues(.3,.3,.3,1),red:n.fromValues(1,0,0,1),darkred:n.fromValues(.5,0,0,1),lightred:n.fromValues(1,.5,.5,1),green:n.fromValues(0,1,0,1),darkgreen:n.fromValues(0,.5,0,1),lightgreen:n.fromValues(.5,1,.5,1),blue:n.fromValues(0,0,1,1),darkblue:n.fromValues(0,0,.5,1),lightblue:n.fromValues(.5,.5,1,1),yellow:n.fromValues(1,1,0,1),darkyellow:n.fromValues(.5,.5,0,1),lightyellow:n.fromValues(1,1,.5,1),cyan:n.fromValues(0,1,1,1),darkcyan:n.fromValues(0,.5,.5,1),lightcyan:n.fromValues(.5,1,1,1),magenta:n.fromValues(1,0,1,1),darkmagenta:n.fromValues(.5,0,.5,1),lightmagenta:n.fromValues(1,.5,1,1),orange:n.fromValues(1,.5,0,1),darkorange:n.fromValues(.5,.25,0,1),lightorange:n.fromValues(1,.75,.5,1)};function a(t,e){this._colors=t;for(var n=0;n0&&"#"===t[0])return r.hex2rgb(t)}return 3===t.length?[t[0],t[1],t[2],1]:t},a.prototype={colorAt:function(t,r){if(r<=this._stops[0])return e.copy(t,this._colors[0]);if(r>=this._stops[this._stops.length-1])return e.copy(t,this._colors[this._stops.length-1]);for(var i=0,a=1;ar);++a)i=a;var s=i+1,o=this._stops[i],h=(r-o)/(this._stops[s]-o);return n.mix(t,this._colors[s],this._colors[i],h)}};var s={};r.gradient=function(t,e){if("string"==typeof t)return s[t];if("equal"===(e=e||"equal")){e=[];for(var r=0;r0?s.max:1));var u=[0,0,0,0];t.colorAt(u,h),n[i]=u[0],n[i+1]=u[1],n[i+2]=u[2],n[i+3]=u[3]},function(t){var e=t.chains();this.chainLimits={};for(var r=0;r1?1/(e.length-1):1},function(){this.chainIndices=null})};var l,c=(l=e.create(),function(t,e,r,n){r.colorAt(l,n),t[e+0]=l[0],t[e+1]=l[1],t[e+2]=l[2],t[e+3]=l[3]});function d(t,e,r,n,i){return e||(e=o("rainbow")),new h(function(r,n,a){var s=0;this._min!==this._max&&(s=(i(r).prop(t)-this._min)/(this._max-this._min)),c(n,a,e,s)},function(e){if(void 0!==r)return this._min=r[0],void(this._max=r[1]);r=function(t,e,r){var n=null,i=null;return t[e](function(t){var e=t.prop(r);null!==n||null!==i?(n=Math.min(n,e),i=Math.max(i,e)):n=i=e}),{min:n,max:i}}(e,n,t),this._min=r.min,this._max=r.max},function(){})}return r.byAtomProp=function(t,e,r){return d(t,e,r,"eachAtom",function(t){return t})},r.byResidueProp=function(t,e,r){return d(t,e,r,"eachResidue",function(t){return t.residue()})},r.interpolateColor=function(t,r){for(var n=new Float32Array(4*(r*(t.length/4-1)+1)),i=0,a=e.create(),s=e.create(),o=1/r,h=0;h=e&&(null===n||athis.MAX_ID)return null;this._unusedRangeStart=h;var u=new t(this,o,h);return this._usedCount++,u},clear:function(){this._objects={},this._unusedRangeStart=1,this._free=[],this._usedCount=0},recycle:function(t){for(var e=t._start;e0&&0===this._usedCount&&this.clear()},objectForId:function(t){return this._objects[t]}},e}(),n=function(){var t={};function e(t,e){return t>1;;){var o=t[s];if(n(r,o))a=s;else{if(!n(o,r))return s;i=s}var h=i+a>>1;if(h===s)return-1;s=h}return-1},t.indexFirstLargerEqualThan=function(t,r,n){if(n=n||e,0===t.length||n(t[t.length-1],r))return-1;for(var i=0,a=t.length,s=i+a>>1;;){var o=t[s];n(r,o)?a=s:n(o,r)?i=s+1:a=s;var h=i+a>>1;if(h===s)return s;s=h}},t.indexLastSmallerThan=function(t,r,n){if(n=n||e,0===t.length||n(t[t.length-1],r))return t.length-1;if(n(r,t[0])||!n(t[0],r))return-1;for(var i=0,a=t.length,s=i+a>>1;;){var o=t[s];n(r,o)||!n(o,r)?a=s:i=s;var h=i+a>>1;if(h===s)return s;s=h}},t.indexLastSmallerEqualThan=function(t,r,n){if(n=n||e,0===t.length||n(t[t.length-1],r))return t.length-1;if(n(r,t[0]))return-1;for(var i=0,a=t.length,s=i+a>>1;;){n(r,t[s])?a=s:i=s;var o=i+a>>1;if(o===s)return s;s=o}},r.prototype={min:function(){return this._min},max:function(){return this._max},length:function(){return this._max-this._min},empty:function(){return this._empty},center:function(){return.5*(this._max+this._min)},extend:function(t){this._min-=t,this._max+=t},update:function(t){this._empty?(this._min=this._max=t,this._empty=!1):tthis._max&&(this._max=t)}},t.Range=r,t}(),i=function(){function t(t){if("complete"!==document.readyState&&"loaded"!==document.readyState&&"interactive"!==document.readyState)return!1;if(void 0===t)try{var e=document.createElement("canvas");return!(!window.WebGLRenderingContext||!e.getContext("experimental-webgl"))}catch(t){return!1}return!!t}function e(t,e){this._width=e.width,this._antialias=e.antialias,this._height=e.height,this._resize=!1,this._lastTimestamp=null,this._domElement=t,this._initCanvas(),this._backgroundColor=e.backgroundColor,this._forceManualAntialiasing=e.forceManualAntialiasing}return e.prototype={_ensureSize:function(){if(this._resize){this._resize=!1;var t=this._width*this._samples,e=this._height*this._samples;this._realWidth=t,this._realHeight=e,this._gl.viewport(0,0,t,e),this._canvas.width=t,this._canvas.height=e,this._samples>1&&this._initManualAntialiasing(this._samples)}},resize:function(t,e){t===this._width&&e===this._height||(this._resize=!0,this._width=t,this._height=e)},fitParent:function(){var t=this._domElement.getBoundingClientRect();this.resize(t.width,t.height)},gl:function(){return this._gl},imageData:function(){return this._canvas.toDataURL()},_initContext:function(){try{var t={antialias:this._antialias&&!this._forceManualAntialiasing,preserveDrawingBuffer:!0};this._gl=this._canvas.getContext("experimental-webgl",t)}catch(t){return!1}return!!this._gl},_initManualAntialiasing:function(t){var e=1/t,r="translate("+.5*-(1-e)*this._realWidth+"px, "+.5*-(1-e)*this._realHeight+"px)"+" "+("scale("+e+", "+e+")");this._canvas.style.webkitTransform=r,this._canvas.style.transform=r,this._canvas.style.ieTransform=r,this._canvas.width=this._realWidth,this._canvas.height=this._realHeight},initGL:function(){var t=1;if(!this._initContext())return!1;var e=this._gl;return e.getContextAttributes().antialias&&!this._forceManualAntialiasing||!this._antialias||(t=2),this._realWidth=this._width*t,this._realHeight=this._height*t,this._samples=t,t>1&&this._initManualAntialiasing(t),e.viewportWidth=this._realWidth,e.viewportHeight=this._realHeight,e.clearColor(this._backgroundColor[0],this._backgroundColor[1],this._backgroundColor[2],1),e.lineWidth(2),e.cullFace(e.FRONT),e.enable(e.CULL_FACE),e.enable(e.DEPTH_TEST),!0},_shaderFromString:function(t,e,r){var n,i=this._gl;if("fragment"===e)n=i.createShader(i.FRAGMENT_SHADER);else{if("vertex"!==e)return null;n=i.createShader(i.VERTEX_SHADER)}var a=t.replace("${PRECISION}",r);return i.shaderSource(n,a),i.compileShader(n),i.getShaderParameter(n,i.COMPILE_STATUS)?n:null},initShader:function(t,e,r){var i=this._gl,a=this._shaderFromString(e,"fragment",r),s=this._shaderFromString(t,"vertex",r),o=i.createProgram();if(i.attachShader(o,s),i.attachShader(o,a),i.linkProgram(o),!i.getProgramParameter(o,i.LINK_STATUS))return null;var h=n.bind(i,i.getAttribLocation),u=n.bind(i,i.getUniformLocation);return o.posAttrib=h(o,"attrPos"),o.colorAttrib=h(o,"attrColor"),o.normalAttrib=h(o,"attrNormal"),o.objIdAttrib=h(o,"attrObjId"),o.selectAttrib=h(o,"attrSelect"),o.symId=u(o,"symId"),o.projection=u(o,"projectionMat"),o.modelview=u(o,"modelviewMat"),o.rotation=u(o,"rotationMat"),o.fog=u(o,"fog"),o.fogFar=u(o,"fogFar"),o.fogNear=u(o,"fogNear"),o.fogColor=u(o,"fogColor"),o.outlineColor=u(o,"outlineColor"),o.outlineWidth=u(o,"outlineWidth"),o.relativePixelSize=u(o,"relativePixelSize"),o.screenDoorTransparency=u(o,"screenDoorTransparency"),o.selectionColor=u(o,"selectionColor"),o.pointSize=u(o,"pointSize"),o.zoom=u(o,"zoom"),o},on:function(t,e){this._canvas.addEventListener(t,e,!1)},removeEventListener:function(t,e){this._canvas.removeEventListener(t,e,!1)},onWheel:function(t,e){"onwheel"in this._canvas?this.on("wheel",t):this.on("mousewheel",e)},domElement:function(){return this._canvas},bind:function(){this._ensureSize(),this._gl.viewport(0,0,this._realWidth,this._realHeight)},superSamplingFactor:function(){return this._samples},viewportWidth:function(){return this._realWidth},viewportHeight:function(){return this._realHeight},width:function(){return this._width},height:function(){return this._height},_initCanvas:function(){this._canvas=document.createElement("canvas"),this._canvas.width=this._width,this._canvas.height=this._height,this._domElement.appendChild(this._canvas)},isWebGLSupported:function(){return t(this._gl)},destroy:function(){this._canvas.width=1,this._canvas.height=1,this._canvas.parentElement.removeChild(this._canvas),this._canvas=null}},{Canvas:e,isWebGLSupported:t}}(),a=function(){function t(t,e){this._width=e.width,this._height=e.height,this._colorBufferWidth=this._width,this._colorBufferHeight=this._height,this._gl=t,this._colorHandle=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,this._colorHandle),this._depthHandle=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,this._depthHandle),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,this._width,this._height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this._depthHandle),this._colorTexture=t.createTexture(),this._initColorBuffer()}return t.prototype={width:function(){return this._width},height:function(){return this._height},bind:function(){var t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,this._colorHandle),t.bindRenderbuffer(t.RENDERBUFFER,this._depthHandle),this._colorBufferWidth===this._width&&this._colorBufferHeight===this._height||this._resizeBuffers(),t.viewport(0,0,this._width,this._height)},colorTexture:function(){return this._colorTexture},_initColorBuffer:function(){this.bind();var t=this._gl;t.bindTexture(t.TEXTURE_2D,this._colorTexture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this._width,this._height,0,t.RGBA,t.UNSIGNED_BYTE,null),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this._colorTexture,0),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null),this.release()},_resizeBuffers:function(){var t=this._gl;t.bindRenderbuffer(t.RENDERBUFFER,this._depthHandle),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,this._width,this._height),t.bindTexture(t.TEXTURE_2D,this._colorTexture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this._width,this._height,0,t.RGBA,t.UNSIGNED_BYTE,null),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this._colorTexture,0),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this._depthHandle),t.bindTexture(t.TEXTURE_2D,null),this._colorBufferWidth=this._width,this._colorBufferHeight=this._height},resize:function(t,e){this._width=t,this._height=e},release:function(){var t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindRenderbuffer(t.RENDERBUFFER,null)}},t}(),s=function(){function t(t){this._freeArrays=[],this._bufferType=t}return t.prototype.request=function(t){for(var e=-1,r=null,n=0;n=t&&(null===r||i68719476735&&(this._stateId=0)},setScreenDoorTransparency:function(t){this._screenDoorTransparency=t,this._incrementStateId()},setOutlineWidth:function(t){this._outlineWidth!==t&&(this._outlineWidth=t,this._incrementStateId())},setRotation:function(t){16===t.length?a.copy(this._rotation,t):a.fromMat3(this._rotation,t),this._updateModelViewMat=!0},upsamplingFactor:function(){return this._upsamplingFactor},setUpsamplingFactor:function(t){if(this._upsamplingFactor!==t){this._incrementStateId(),this._upsamplingFactor=t;var e=this._upsamplingFactor/this._width,r=this._upsamplingFactor/this._height;this._relativePixelSize=new Float32Array([e,r])}},mainAxes:function(){return[i.fromValues(this._rotation[0],this._rotation[4],this._rotation[8]),i.fromValues(this._rotation[1],this._rotation[5],this._rotation[9]),i.fromValues(this._rotation[2],this._rotation[6],this._rotation[10])]},fieldOfViewY:function(){return this._fovY},setFieldOfViewY:function(t){this._fovY=t,this._updateProjectionMat=!0},aspectRatio:function(){return this._width/this._height},rotation:function(){return this._rotation},_updateIfRequired:function(){var t=!1;return this._updateModelViewMat&&(a.identity(this._camModelView),a.translate(this._camModelView,this._camModelView,[-this._center[0],-this._center[1],-this._center[2]]),a.mul(this._camModelView,this._rotation,this._camModelView),a.identity(this._translation),a.translate(this._translation,this._translation,[0,0,-this._zoom]),a.mul(this._camModelView,this._translation,this._camModelView),t=!0),this._updateProjectionMat&&(a.identity(this._projection),a.perspective(this._projection,this._fovY,this._width/this._height,this._near,this._far),t=!0),this._updateProjectionMat=!1,this._updateModelViewMat=!1,t&&this._incrementStateId(),t},setViewportSize:function(t,e){this._updateProjectionMat=!0,this._width=t,this._height=e,this._relativePixelSize=new Float32Array([this._upsamplingFactor/t,this._upsamplingFactor/e])},viewportWidth:function(){return this._width},viewportHeight:function(){return this._height},setCenter:function(t){this._updateModelViewMat=!0,i.copy(this._center,t)},fog:function(t){return void 0!==t&&t!==this._fog&&(this._fog=t,this._incrementStateId()),this._fog},rotateZ:(n=a.create(),function(t){a.identity(n),this._updateModelViewMat=!0,a.rotate(n,n,t,[0,0,1]),a.mul(this._rotation,n,this._rotation)}),rotateX:function(){var t=a.create();return function(e){a.identity(t),this._updateModelViewMat=!0,a.rotate(t,t,e,[1,0,0]),a.mul(this._rotation,t,this._rotation)}}(),rotateY:function(){var t=a.create();return function(e){a.identity(t),this._updateModelViewMat=!0,a.rotate(t,t,e,[0,1,0]),a.mul(this._rotation,t,this._rotation)}}(),panX:function(t){return this.panXY(t,0)},panY:function(t){return this.panXY(0,t)},panXY:(e=a.create(),r=i.create(),function(t,n){a.transpose(e,this._rotation),this._updateModelViewMat=!0,i.set(r,-t,n,0),i.transformMat4(r,r,e),i.add(r,r,this._center),this.setCenter(r)}),nearOffset:function(){return this._near},farOffset:function(){return this._far},setNearFar:function(t,e){t===this._near&&e===this._far||(this._near=t,this._far=e,this._updateProjectionMat=!0)},setFogNearFar:function(t,e){this._fogNear=t,this._fogFar=e,this._updateProjectionMat=!0},setZoom:function(t){return this._updateModelViewMat=!0,this._zoom=t,this._zoom},zoom:function(t){if(void 0===t)return this._zoom;this._updateModelViewMat=!0;var e=1+.1*t;return this._zoom=Math.min(1e3,Math.max(2,e*this._zoom)),this._zoom},center:function(){return this._center},setFogColor:function(t){this._fogColor=i.clone(t)},currentShader:function(){return this._currentShader},invalidateCurrentShader:function(){this._currentShader=null},setOutlineColor:function(t){this._outlineColor=i.clone(t)},setSelectionColor:function(t){this._selectionColor=i.clone(t)},bind:function(t,e){var r=!1,n=this._gl;if(this._currentShader!==t&&(this._currentShader=t,n.useProgram(t),r=!0),r=this._updateIfRequired()||r,e?(a.mul(this._modelView,this._camModelView,e),n.uniformMatrix4fv(t.modelview,!1,this._modelView)):n.uniformMatrix4fv(t.modelview,!1,this._camModelView),this._stateId!==t.stateId){t.stateId=this._stateId,n.uniformMatrix4fv(t.projection,!1,this._projection),t.rotation&&n.uniformMatrix4fv(t.rotation,!1,this._rotation),n.uniform1i(t.fog,this._fog);var i=this._zoom;n.uniform1f(t.fogFar,this._fogFar+i),n.uniform1f(t.zoom,this._zoom),n.uniform1f(t.fogNear,this._fogNear+i),n.uniform3fv(t.fogColor,this._fogColor),n.uniform3fv(t.outlineColor,this._outlineColor),n.uniform3fv(t.selectionColor,this._selectionColor),n.uniform2fv(t.relativePixelSize,this._relativePixelSize),n.uniform1f(t.outlineWidth,this._outlineWidth),n.uniform1i(t.screenDoorTransparency,this._screenDoorTransparency)}}},s}(),h={PRELUDE_FS:"\nprecision ${PRECISION} float;\nuniform bool screenDoorTransparency;\nvec4 handleAlpha(vec4 inColor) {\n if (screenDoorTransparency) {\n ivec2 pxCoord = ivec2(gl_FragCoord.xy);\n ivec2 mod = pxCoord - (pxCoord/2) * 2;\n if (inColor.a < 0.99 &&\n (inColor.a < 0.01 || mod.x != 0 || mod.y != 0)) { discard; }\n return vec4(inColor.rgb, 1.0);\n } else {\n if (inColor.a == 0.0) { discard; }\n return inColor;\n } \n} \nuniform vec3 selectionColor;\n\nvec3 handleSelect(vec3 inColor, float vertSelect) { \n return mix(inColor, selectionColor, step(0.5, vertSelect) * 0.7); \n} \n\nuniform bool fog;\nuniform float fogNear;\nuniform float fogFar;\nuniform vec3 fogColor;\nvec3 handleFog(vec3 inColor) {\n if (fog) {\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n float fogFactor = smoothstep(fogNear, fogFar, depth);\n return mix(inColor, fogColor, fogFactor);\n } else {\n return inColor;\n }\n}",LINES_FS:"\nvarying vec4 vertColor;\nvarying vec3 vertNormal;\n\nvoid main(void) {\n gl_FragColor = handleAlpha(vertColor);\n gl_FragColor.rgb = handleFog(gl_FragColor.rgb);\n}",SELECT_LINES_FS:"\nprecision ${PRECISION} float;\n\nvarying float vertSelect;\nvarying vec3 vertNormal;\nuniform float fogNear;\nuniform float fogFar;\nuniform vec3 fogColor;\nuniform bool fog;\nuniform vec3 selectionColor;\n\nvoid main(void) {\n gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(selectionColor, 1.0), \n vertSelect);\n gl_FragColor.a = step(0.5, vertSelect);\n if (gl_FragColor.a == 0.0) { discard; }\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n if (fog) {\n float fog_factor = smoothstep(fogNear, fogFar, depth);\n gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w),\n fog_factor);\n }\n}",SELECT_LINES_VS:"\nattribute vec3 attrPos;\nattribute float attrSelect;\n\nuniform mat4 projectionMat;\nuniform mat4 modelviewMat;\nuniform float pointSize;\nvarying float vertSelect;\nvoid main(void) {\n gl_Position = projectionMat * modelviewMat * vec4(attrPos, 1.0);\n gl_Position.z += gl_Position.w * 0.000001; \n float distToCamera = vec4(modelviewMat * vec4(attrPos, 1.0)).z;\n gl_PointSize = pointSize * 200.0 / abs(distToCamera); \n vertSelect = attrSelect;\n}",SELECT_VS:"\nprecision ${PRECISION} float;\nuniform mat4 projectionMat;\nuniform mat4 modelviewMat;\nuniform float pointSize;\nattribute vec3 attrPos;\nattribute float attrObjId;\n\nvarying float objId;\n\nvoid main(void) {\n gl_Position = projectionMat * modelviewMat * vec4(attrPos, 1.0);\n float distToCamera = vec4(modelviewMat * vec4(attrPos, 1.0)).z;\n gl_PointSize = pointSize * 200.0 / abs(distToCamera); \n objId = attrObjId;\n}",SELECT_FS:"\nprecision ${PRECISION} float;\n\nvarying float objId;\nuniform int symId;\n\nint intMod(int x, int y) { \n int z = x/y;\n return x-y*z;\n}\nvoid main(void) {\n // ints are only required to be 7bit...\n int integralObjId = int(objId+0.5);\n int red = intMod(integralObjId, 256);\n integralObjId/=256;\n int green = intMod(integralObjId, 256);\n integralObjId/=256;\n int blue = intMod(integralObjId, 256);\n int alpha = symId;\n gl_FragColor = vec4(float(red), float(green), \n float(blue), float(alpha))/255.0;\n}",LINES_VS:"\nattribute vec3 attrPos;\nattribute vec4 attrColor;\n\nuniform mat4 projectionMat;\nuniform mat4 modelviewMat;\nvarying vec4 vertColor;\nuniform float pointSize;\nvoid main(void) {\n gl_Position = projectionMat * modelviewMat * vec4(attrPos, 1.0);\n float distToCamera = vec4(modelviewMat * vec4(attrPos, 1.0)).z;\n gl_PointSize = pointSize * 200.0 / abs(distToCamera); \n vertColor = attrColor;\n}",HEMILIGHT_FS:"\nvarying vec4 vertColor;\nvarying vec3 vertNormal;\nvarying float vertSelect;\n\nvoid main(void) {\n float dp = dot(vertNormal, vec3(0.0, 0.0, 1.0));\n float hemi = min(1.0, max(0.0, dp)*0.6+0.5);\n gl_FragColor = vec4(vertColor.rgb*hemi, vertColor.a);\n gl_FragColor.rgb = handleFog(handleSelect(gl_FragColor.rgb, vertSelect));\n gl_FragColor = handleAlpha(gl_FragColor);\n}",PHONG_FS:"\nvarying vec4 vertColor;\nvarying vec3 vertNormal;\nvarying vec3 vertPos;\nuniform float zoom;\nvarying float vertSelect;\n\nvoid main(void) {\n vec3 eyePos = vec3(0.0, 0.0, zoom);\n float dp = dot(vertNormal, normalize(eyePos - vertPos));\n float hemi = min(1.0, max(0.3, dp)+0.2);\n //hemi *= vertColor.a;\n vec3 rgbColor = vertColor.rgb * hemi; \n rgbColor += min(vertColor.rgb, 0.8) * pow(max(0.0, dp), 18.0);\n rgbColor = handleSelect(rgbColor, vertSelect);\n gl_FragColor = vec4(clamp(rgbColor, 0.0, 1.0), vertColor.a);\n gl_FragColor.rgb = handleFog(gl_FragColor.rgb);\n gl_FragColor = handleAlpha(gl_FragColor);\n}",HEMILIGHT_VS:"\nattribute vec3 attrPos;\nattribute vec4 attrColor;\nattribute vec3 attrNormal;\nattribute float attrSelect;\n\nuniform mat4 projectionMat;\nuniform mat4 modelviewMat;\nvarying vec4 vertColor;\nvarying vec3 vertNormal;\nvarying vec3 vertPos;\nvarying float vertSelect;\nvoid main(void) {\n vertPos = (modelviewMat * vec4(attrPos, 1.0)).xyz;\n gl_Position = projectionMat * modelviewMat * vec4(attrPos, 1.0);\n vec4 n = (modelviewMat * vec4(attrNormal, 0.0));\n vertNormal = n.xyz;\n vertColor = attrColor;\n vertSelect = attrSelect;\n}",OUTLINE_FS:"\nvarying float vertAlpha;\nvarying float vertSelect;\n\nuniform vec3 outlineColor;\n\nvoid main() {\n gl_FragColor = vec4(mix(outlineColor, selectionColor, \n step(0.5, vertSelect)), \n vertAlpha);\n gl_FragColor.rgb = handleFog(gl_FragColor.rgb);\n gl_FragColor = handleAlpha(gl_FragColor);\n}",OUTLINE_VS:"\nprecision ${PRECISION} float;\n\nattribute vec3 attrPos;\nattribute vec3 attrNormal;\nattribute vec4 attrColor;\nattribute float attrSelect;\n\nuniform vec3 outlineColor;\nuniform mat4 projectionMat;\nuniform mat4 modelviewMat;\nvarying float vertAlpha;\nvarying float vertSelect;\nuniform vec2 relativePixelSize;\nuniform float outlineWidth;\n\nvoid main(void) {\n gl_Position = projectionMat * modelviewMat * vec4(attrPos, 1.0);\n vec4 normal = modelviewMat * vec4(attrNormal, 0.0);\n vertAlpha = attrColor.a;\n vertSelect = attrSelect;\n vec2 expansion = relativePixelSize * \n (outlineWidth + 2.0 * step(0.5, attrSelect));\n vec2 offset = normal.xy * expansion;\n gl_Position.xy += gl_Position.w * offset;\n}",TEXT_VS:"\nprecision ${PRECISION} float;\n\nattribute vec3 attrCenter;\nattribute vec2 attrCorner;\nuniform mat4 projectionMat;\nuniform mat4 modelviewMat;\nuniform mat4 rotationMat;\nvarying vec2 vertTex;\nuniform float width;\nuniform float height;\nvoid main() { \n vec4 pos = modelviewMat* vec4(attrCenter, 1.0);\n pos.z += 4.0;\n gl_Position = projectionMat * pos;\n gl_Position.xy += vec2(width,height)*attrCorner*gl_Position.w; \n vertTex = (attrCorner+abs(attrCorner))/(2.0*abs(attrCorner)); \n}",TEXT_FS:"\nprecision ${PRECISION} float;\n\nuniform mat4 projectionMat;\nuniform mat4 modelviewMat;\nuniform sampler2D sampler;\nuniform float xScale;\nuniform float yScale;\nvarying vec2 vertTex;\nvoid main() { \n vec2 texCoord = vec2(vertTex.x*xScale, vertTex.y*yScale);\n gl_FragColor = texture2D(sampler, texCoord);\n if (gl_FragColor.a == 0.0) { discard; }\n}"},u=function(){function t(t,e,r){this._element=t,this._element.addEventListener("touchmove",n.bind(this,this._touchMove)),this._element.addEventListener("touchstart",n.bind(this,this._touchStart)),this._element.addEventListener("touchend",n.bind(this,this._touchEnd)),this._element.addEventListener("touchcancel",n.bind(this,this._touchEnd)),this._touchState={scale:1,rotation:0,center:null},this._lastSingleTap=null,this._viewer=e,this._cam=r}function e(t,e){var r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function r(t,e){var r=e.x-t.x,n=e.y-t.y;return Math.atan2(n,r)}return t.prototype={_extractEventAttributes:function(t,n){var i,a,s,o={};o.center=function(t){for(var e=0,r=0,n=0;n300)&r-this._lastMouseDownTime<300){var n=this._canvas.domElement().getBoundingClientRect(),i=this._viewer.pick({x:t.clientX-n.left,y:t.clientY-n.top});this._viewer._dispatchEvent(t,"click",i)}this._lastMouseUpTime=r,e.removeEventListener("mousemove",this._mouseRotateListener),e.removeEventListener("mousemove",this._mousePanListener),e.removeEventListener("mouseup",this._mouseUpListener),document.removeEventListener("mouseup",this._mouseUpListener),document.removeEventListener("mousemove",this._mouseRotateListener),document.removeEventListener("mousemove",this._mousePanListener)},setCam:function(t){this._cam=t},_init:function(){return this._mousePanListener=n.bind(this,this._mousePan),this._mouseRotateListener=n.bind(this,this._mouseRotate),this._mouseUpListener=n.bind(this,this._mouseUp),this._canvas.onWheel(n.bind(this,this._mouseWheelFF),n.bind(this,this._mouseWheel)),this._canvas.on("dblclick",n.bind(this,this._mouseDoubleClick)),this._canvas.on("mousedown",n.bind(this,this._mouseDown)),!0},_mouseWheel:function(t){this._cam.zoom(t.wheelDelta<0?-1:1),t.preventDefault(),this._viewer.requestRedraw()},_mouseWheelFF:function(t){this._cam.zoom(t.deltaY<0?1:-1),t.preventDefault(),this._viewer.requestRedraw()},_mouseDoubleClick:function(t){var e=this._canvas.domElement().getBoundingClientRect(),r=this._viewer.pick({x:t.clientX-e.left,y:t.clientY-e.top});this._viewer._dispatchEvent(t,"doubleClick",r),this._viewer.requestRedraw()},_mouseDown:function(t){0===t.button&&(this._lastMouseDownTime=(new Date).getTime(),t.preventDefault(),!0===t.shiftKey?(this._canvas.on("mousemove",this._mousePanListener),document.addEventListener("mousemove",this._mousePanListener,!1)):(this._canvas.on("mousemove",this._mouseRotateListener),document.addEventListener("mousemove",this._mouseRotateListener,!1)),this._canvas.on("mouseup",this._mouseUpListener),document.addEventListener("mouseup",this._mouseUpListener,!1),this._lastMousePos={x:t.pageX,y:t.pageY})},_mouseRotate:function(t){var e={x:t.pageX,y:t.pageY},r=e.x-this._lastMousePos.x,n=e.y-this._lastMousePos.y;this._cam.rotateX(.005*n),this._cam.rotateY(.005*r),this._lastMousePos=e,this._viewer.requestRedraw()},_mousePan:function(t){var e={x:t.pageX,y:t.pageY},r=e.x-this._lastMousePos.x,n=e.y-this._lastMousePos.y,i=.002*Math.tan(.5*this._cam.fieldOfViewY())*this._cam.zoom();this._cam.panXY(i*r,i*n),this._lastMousePos=e,this._viewer.requestRedraw()}},t}(),c=function(){var e,r,n=t.vec3,i=t.vec4,a=t.mat3,s=t.quat,o=(e=n.create(),function(t,r,i){return n.cross(e,t,r),Math.atan2(n.dot(e,i),n.dot(t,r))}),h=function(){var t=n.create();return function(e,r){return n.copy(t,r),Math.abs(r[0])g[1]&&g[0]>g[2]?0:g[1]>g[2]?1:2,u=(h+1)%3,l=(h+2)%3;if(0===p[h])break;var c=(f[3*l+l]-f[3*u+u])/(2*p[h]),A=c>0?1:-1,b=A/((c*=A)+(c<1e6?Math.sqrt(c*c+1):c)),y=1/Math.sqrt(b*b+1);if(1===y)break;if(i.set(v,0,0,0,0),v[h]=A*Math.sqrt((1-y)/2),v[h]*=-1,v[3]=Math.sqrt(1-v[h]*v[h]),1===v[3])break;e=s.mul(e,e,v),s.normalize(e,e)}return e});return c.prototype.center=function(){return this._center},c.prototype.radius=function(){return this._radius},{signedAngle:o,axisRotation:function(t,e,r){var n=Math.sin(r),i=Math.cos(r),a=e[0],s=e[1],o=e[2],h=a*a,u=a*s,l=a*o,c=s*s,d=s*o,f=o*o;return t[0]=h+i-h*i,t[1]=u-i*u-n*o,t[2]=l-i*l+n*s,t[3]=u-i*u+n*o,t[4]=c+i-i*c,t[5]=d-i*d-n*a,t[6]=l-i*l-n*s,t[7]=d-i*d+n*a,t[8]=f+i-i*f,t},ortho:h,diagonalizer:A,catmullRomSpline:function(t,e,r,i,a,s){a=a||!1,i=i||.5;var o=null,h=3*l(e,r,a);o=s?s.request(h):new Float32Array(h);var c,d,f,_=0,m=1/r,v=n.create(),p=n.create(),g=n.create(),A=n.create(),b=n.create(),y=n.create();for(n.set(A,t[0],t[1],t[2]),n.set(b,t[3],t[4],t[5]),a?(n.set(g,t[t.length-3],t[t.length-2],t[t.length-1]),n.sub(v,b,g),n.scale(v,v,i)):(n.set(g,t[0],t[1],t[2]),n.set(v,0,0,0)),c=1,f=e-1;ct)return r[n].matrix(t);t-=r[n].matrices().length}return null},showRelated:function(){return this._showRelated},select:function(t){return this.structure().select(t)},structure:function(){return this._vertAssocs[0]._structure},getColorForAtom:function(t,e){return this._vertAssocs[0].getColorForAtom(t,e)},addIdRange:function(t){this._idRanges.push(t)},destroy:function(){F.prototype.destroy.call(this);for(var t=0;t=this._indexData.length||(this._indexData[n++]=t,this._indexData[n++]=e,this._indexData[n++]=r,this._numTriangles+=1,this._ready=!1)},bindBuffers:function(){var t=this._ready,e=this._gl;D.prototype.bindBuffers.call(this),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t||e.bufferData(e.ELEMENT_ARRAY_BUFFER,this._indexData,e.STATIC_DRAW)},bindAttribs:function(t){var e=this._gl,r=this._BYTES_PER_VERT;e.enableVertexAttribArray(t.posAttrib),e.vertexAttribPointer(t.posAttrib,3,e.FLOAT,!1,r,this._POS_BYTE_OFFSET),-1!==t.normalAttrib&&(e.enableVertexAttribArray(t.normalAttrib),e.vertexAttribPointer(t.normalAttrib,3,e.FLOAT,!1,r,this._NORMAL_BYTE_OFFSET)),-1!==t.colorAttrib&&(e.vertexAttribPointer(t.colorAttrib,4,e.FLOAT,!1,r,this._COLOR_BYTE_OFFSET),e.enableVertexAttribArray(t.colorAttrib)),-1!==t.objIdAttrib&&(e.vertexAttribPointer(t.objIdAttrib,1,e.FLOAT,!1,r,this._OBJID_BYTE_OFFSET),e.enableVertexAttribArray(t.objIdAttrib)),-1!==t.selectAttrib&&(e.vertexAttribPointer(t.selectAttrib,1,e.FLOAT,!1,r,this._SELECT_BYTE_OFFSET),e.enableVertexAttribArray(t.selectAttrib))},releaseAttribs:function(t){var e=this._gl;e.disableVertexAttribArray(t.posAttrib),-1!==t.colorAttrib&&e.disableVertexAttribArray(t.colorAttrib),-1!==t.normalAttrib&&e.disableVertexAttribArray(t.normalAttrib),-1!==t.objIdAttrib&&e.disableVertexAttribArray(t.objIdAttrib),-1!==t.selectAttrib&&e.disableVertexAttribArray(t.selectAttrib)},bind:function(t){this.bindBuffers(),this.bindAttribs(t)},draw:function(){var t=this._gl;t.drawElements(t.TRIANGLES,3*this._numTriangles,t.UNSIGNED_SHORT,0)}}),t}(),m=function(t){function e(e,r,n,i){t.call(this,r,n,i),this._chain=e}function r(t,e,r,n,i,a){V.call(this,e,r,n,i,a),this._chain=t}return n.derive(e,t,{chain:function(){return this._chain},drawSymmetryRelated:function(t,e,r){this.bind(e);for(var n=0;nb.maxVerts()&&(T=b.numVerts(),s.addAssoc(h,b,E,w,T),b=a.vertArrayWithSpaceFor(Z),w=0,W(b,e,n,j,t,r,C,!0,d,0,$)),z&&(s.addAssoc(h,b,E,w,T),W(b,e,n,"A",t,r,C,!1,d,0,$),D+=d.arrowSkip),T=b.numVerts(),D===V-1&&(T+=1),s.addAssoc(h,b,E,w,T),E+=1,z&&(E+=d.arrowSkip)}return b.addVertex(e,t,r,p[p.length-1]),function(t,e,r){for(var n=e+r,i=0;ib-A.numVerts()&&(A=l.vertArrayWithSpaceFor(g)),g-=T;var M=A.numVerts();m.protoCyl.addTransformed(A,i,x,m.radius,t,o,h,R,C),S=A.numVerts(),S-=(S-M)/2,m.protoSphere.addTransformed(A,s,m.radius,h,C),R=C,d.addAssoc(_,A,E,y,S),y=S,u.copy(o,h)}d.setPerResidueColors(_,w),d.addAssoc(_,A,f.length()-1,y,A.numVerts())}}}();return A}(d,function(t,e){var r=m.MeshChainData;function i(t,e,r){I.call(this,t),this._indexedVAs=[],this._float32Allocator=e,this._uint16Allocator=r,this._remainingVerts=null,this._remainingIndices=null}return n.derive(i,I,{_boundedVertArraySize:function(t){return Math.min(65536,t)},addChainVertArray:function(t,e,n){this._remainingVerts=e,this._remainingIndices=n;var i=new r(t.name(),this._gl,this._boundedVertArraySize(e),n,this._float32Allocator,this._uint16Allocator);return this._indexedVAs.push(i),i},addVertArray:function(t,r){this._remainingVerts=t,this._remainingIndices=r;var n=new e(this._gl,this._boundedVertArraySize(t),r,this._float32Allocator,this._uint16Allocator);return this._indexedVAs.push(n),n},vertArrayWithSpaceFor:function(t){var n=this._indexedVAs[this._indexedVAs.length-1];if(n.maxVerts()-n.numVerts()>=t)return n;this._remainingVerts-=n.numVerts(),this._remainingIndices-=n.numIndices(),t=this._boundedVertArraySize(this._remainingVerts);var i=null;return i=n instanceof r?new r(n.chain(),this._gl,t,this._remainingIndices,this._float32Allocator,this._uint16Allocator):new e(this._gl,t,this._remainingIndices,this._float32Allocator,this._uint16Allocator),this._indexedVAs.push(i),i},vertArray:function(t){return this._indexedVAs[t]},destroy:function(){I.prototype.destroy.call(this);for(var t=0;t1?a.push(e.interpolateColor(o,this._interpolation)):a.push(o)}for(n=0;n1?n.push(c.interpolateScalars(a,this._interpolation)):n.push(a)}for(e=0;e1?a.push(e.interpolateColor(o,this._interpolation)):a.push(o)}for(n=0;n0},add:function(t){this._animations.push(t)},remove:function(t){this._animations=this._animations.filter(function(e){return e!==t})}},{AnimationControl:_,move:function(t,e,r){return new u(t,e,r)},rotate:function(t,e,r){return new l(t,e,r)},zoom:function(t,e,r){return new h(t,e,r)},rockAndRoll:function(){return new d([0,1,0],2e3)},spin:function(t,e){return new f(t,e)}}}(),b=function(){function t(t,e){this.near=t,this.far=e}function e(t){t=t||{},this._near=t.near||.1,this._far=t.far||400}function r(){this._far=100}return e.prototype.update=function(){return new t(this._near,this._far)},r.prototype.update=function(e,r){for(var n=r.center(),i=null,a=0;a1}function f(t,e){e.length()<2||t.push(e)}function _(t,e,r){if(0===t.length)return!0;if(!e)return!1;var n=o(r.num(),r.insCode()),i=t[t.length-1];return o(i.num(),i.insCode())=t&&c.num()<=e&&a.push(c)}return a},prop:function(t){return this[t]()}},n.derive(c,l,{name:function(){return this._name},full:function(){return this},addResidue:function(t,e,r){var n=new a(this,t,e,r=r||"\0");return this._rnumsOrdered=_(this._residues,this._rnumsOrdered,n),this._residues.push(n),n},assignSS:function(t,e,r){for(var n=o(t[0],t[1]),i=o(e[0],e[1]),a=1;a=i||s.setSS(r)}},eachBackboneTrace:function(t){this._cacheBackboneTraces();for(var e=0;e0)){for(var t=new r.BackboneTrace,e=null,n=0;n=this._atoms.length&&t<0?null:this._atoms[t]},centralAtom:function(){return this.isAminoacid()?this.atom("CA"):this.isNucleotide()?this.atom("C3'"):null},center:function(){var t=0,e=r.create();return this.eachAtom(function(n){r.add(e,e,n.pos()),t+=1}),t>0&&r.scale(e,e,1/t),e},isAminoacid:function(){return this._isAminoacid},isNucleotide:function(){return this._isNucleotide}},n.derive(o,s,{_deduceType:function(){this._isNucleotide=null!==this.atom("P")&&null!==this.atom("C3'"),this._isAminoacid=null!==this.atom("N")&&null!==this.atom("CA")&&null!==this.atom("C")&&null!==this.atom("O")},name:function(){return this._name},insCode:function(){return this._insCode},num:function(){return this._num},full:function(){return this},addAtom:function(t,e,r,n,a,s){var o=new i(this,t,e,r,this.structure().nextAtomIndex(),n,a,s);return this._atoms.push(o),o},ss:function(){return this._ss},setSS:function(t){this._ss=t},index:function(){return this._index},atoms:function(){return this._atoms},chain:function(){return this._chain},structure:function(){return this._chain.structure()}}),n.derive(h,s,{addAtom:function(t,e){if(e)for(var r=0;r0?this.posAt(e,n-1):this.posAt(e,n),ne&&this._trace[e].index()=this._trace.length)break;for(var a=this._trace[e].index();t.length>r&&t[r].full().index()=t.length)break;for(var s=e;t.length>r&&this._trace.length>e&&t[r].full().index()===this._trace[e].index();)++r,++e;var h=e;n.push(new o(this,s,h))}return n}},s.prototype.smoothPosAt=s.prototype.posAt,s.prototype.smoothNormalAt=s.prototype.normalAt,o.prototype={length:function(){return this._length},residueAt:function(t){return this._fullTrace.residueAt(this._fullTraceBegin+t)},_interpolate:(n=a.create(),i=a.create(),function(t,e,r,s){return this.tangentAt(n,e),this.tangentAt(i,r),a.scale(n,n,s),a.scale(i,i,s),c.cubicHermiteInterpolate(t,this.centralAtomAt(e).pos(),n,this.centralAtomAt(r).pos(),i,.5,0),t}),smoothPosAt:function(t,e,r){if(0===e&&!this._isNTerminal)return this._interpolate(t,e,e+1,r);if(e===this._length-1&&!this._isCTerminal)return this._interpolate(t,e-1,e,r);var n=this.centralAtomAt(e);return a.copy(t,n.pos()),t},smoothNormalAt:function(t,e){return this._fullTrace.normalAt(t,e+this._fullTraceBegin),t},posAt:function(t,e){var r=this.centralAtomAt(e),n=null;return a.copy(t,r.pos()),0!==e||this._isNTerminal||(n=this.centralAtomAt(e+1),a.add(t,t,n.pos()),a.scale(t,t,.5)),e!==this._length-1||this._isCTerminal||(n=this.centralAtomAt(e-1),a.add(t,t,n.pos()),a.scale(t,t,.5)),t},centralAtomAt:function(t){return this.residueAt(t).centralAtom()},fullTraceIndex:function(t){return this._fullTraceBegin+t},tangentAt:function(t,e){return this._fullTrace.tangentAt(t,e+this._fullTraceBegin)}},{TraceSubset:o,BackboneTrace:s}}()),L=t.vec3,S={Bond:function(t,e){var r={atom_one:t,atom_two:e};return{atom_one:function(){return r.atom_one},atom_two:function(){return r.atom_two},mid_point:function(t){return t||(t=L.create()),L.add(t,r.atom_one.pos(),r.atom_two.pos()),L.scale(t,t,.5),t}}}},w=function(){function t(t,e){for(var r=0;rn)){if(l||(l=h.addChain(c[f].full(),!1)),u||(u=l.addResidue(_[v].full(),i)),i){d=!0;break}u.addAtom(p[g].full());break}}}return h}),createEmptyView:function(){return new m(this.full())}},n.derive(_,f,{addAssembly:function(t){this._assemblies.push(t)},setAssemblies:function(t){this._assemblies=t},assemblies:function(){return this._assemblies},chains:function(){return this._chains},full:function(){return this},containsResidue:function(t){return t.full().structure()===this},chainByName:function(t){for(var e=0;eA*A&&t.connect(f,p)}r._deduceType(),null!==e&&(r.isAminoacid()&&e.isAminoacid()&&(i=t,a=r,o=e.atom("C"),h=a.atom("N"),o&&h&&s.sqrDist(o.pos(),h.pos())<1.6*1.6&&i.connect(h,o)),r.isNucleotide()&&e.isNucleotide()&&function(t,e,r){var n=e.atom("O3'"),i=r.atom("P");n&&i&&s.sqrDist(n.pos(),i.pos())<1.7*1.7&&t.connect(n,i)}(t,e,r)),e=r})}}),n.derive(m,f,{full:function(){return this._mol},assemblies:function(){return this._mol.assemblies()},addChain:function(t,e){var r=new h(this,t.full());if(this._chains.push(r),e)for(var n=t.residues(),i=0;i(e=Math.abs(e))?t*Math.sqrt(1+e*e/t/t):0==e?t:e*Math.sqrt(1+t*t/e/e)}var p=0,g=0,A=0,b=0,y=0,R=0,C=0;for(a=0;a=0&&(g=-g),A=p*g-C,u[a][a]=p-g,s=h;s=0&&(g=-g),A=p*g-C,u[a][a+1]=p-g,s=h;sb&&(b=y)}for(a=c-1;-1!=a;a+=-1){if(0!=g){for(A=g*u[a][a+1],s=h;s=49)throw"Error: no convergence.";for(b=f[h],g=v(p=(((y=f[o-1])-R)*(y+R)+((g=d[o-1])-(A=d[o]))*(g+A))/(2*A*y),1),p=p<0?((b-R)*(b+R)+A*(y/(p-g)-A))/b:((b-R)*(b+R)+A*(y/(p+g)-A))/b,i=1,C=1,a=h+1;a=0;s--)if(f[s]=t.length())){var u=i.dist(t.posAt(r,o),t.posAt(n,o+h));if(Math.abs(u-a[h-2])>s)return!1}return!0}),s=function(t,e){return a(t,e,[5.45,5.18,6.37],2.1)},o=function(t,e){return a(t,e,[6.1,10.4,13],1.42)};function h(t){for(var e=0;e122||n>90&&n<97);)++r,n=e.charCodeAt(r);return e[r]}var i=e.charCodeAt(0);return i>=48&&i<=57?e[1]:e.substr(0,2)}return t[1]}function s(t){this._helices=[],this._sheets=[],this._conect=[],this._serialToAtomMap={},this._structure=new P.Mol,this._remark350Reader=new i,this._currChain=null,this._currRes=null,this._currAtom=null,this._options={},this._options.conectRecords=!!t.conectRecords}function o(t){return t.split(/\r\n|\r|\n/g)}function h(t,e){for(var r=e||{},n=o(t),i=new s(r),a=[],h=0;he||r.push(i))}return this._conect.push({from:e,to:r}),!0},processLine:function(t){var e=t.substr(0,6);return"ATOM "===e||"HETATM"===e?this.parseAndAddAtom(t)?this.CONTINUE:this.ERROR:"REMARK"===e?("350"===t.substr(7,3)&&this._remark350Reader.nextLine(t),this.CONTINUE):"HELIX "===e?this.parseHelixRecord(t)?this.CONTINUE:this.ERROR:"SHEET "===e?this.parseSheetRecord(t)?this.CONTINUE:this.ERROR:this._options.conectRecords&&"CONECT"===e?this.parseConectRecord(t)?this.CONTINUE:this.ERROR:"END "===e?this.FILE_END:"ENDMDL"===e?this.MODEL_COMPLETE:this.CONTINUE},finish:function(){if(null===this._currChain)return null;var t,e=null;for(t=0;t