!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("three"),require("chroma-js"),require("signals"),require("sprintf-js")):"function"==typeof define&&define.amd?define(["exports","three","chroma-js","signals","sprintf-js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).NGL={},t.three,t.chroma,t.signalsWrapper,t.sprintfJs)}(this,(function(t,e,i,r,n){"use strict";function s(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,r.get?r:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var o=s(i),a=s(r);function c(t){if("undefined"==typeof window)return;const e=new RegExp(`${t}=([^&#=]*)`).exec(window.location.search);return e?decodeURIComponent(e[1]):void 0}function l(t,e){return void 0!==t?t:e}function u(t,e){const i=Object.assign({},t);for(const r in e){void 0===t[r]&&(i[r]=e[r])}return i}function h(t,e){for(const i in e){const r=e[i];void 0!==r&&(t[i]=r)}return t}function d(){if("undefined"==typeof window)return!1;const t=window.navigator.userAgent;return/Opera|OPR/.test(t)?"Opera":/Chrome/i.test(t)?"Chrome":/Firefox/i.test(t)?"Firefox":/Mobile(\/.*)? Safari/i.test(t)?"Mobile Safari":/MSIE/i.test(t)?"Internet Explorer":!!/Safari/i.test(t)&&"Safari"}function m(t){window.open(t,"_blank")||(window.location.href=t)}function f(t,e="download"){if(!t)return;const i="Safari"===d(),r=/CriOS\/[\d]+/.test(window.navigator.userAgent),n=document.createElement("a");function s(t){m(r?t:t.replace(/^data:[^;]*;/,"data:attachment/file;"))}if("undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob)navigator.msSaveOrOpenBlob(t,e);else if((i||r)&&FileReader)if(t instanceof Blob){var o=new FileReader;o.onloadend=function(){s(o.result)},o.readAsDataURL(t)}else s(t);else{let i=!1;t instanceof Blob&&(t=URL.createObjectURL(t),i=!0),"download"in n?(n.style.display="hidden",document.body.appendChild(n),n.href=t,n.download=e,n.target="_blank",n.click(),document.body.removeChild(n)):m(t),i&&window.URL.revokeObjectURL(t)}}function p(t,e){return t<e?-1:t>e?1:0}function g(t,e,i=p){let r=0,n=t.length-1;for(;r<=n;){const s=r+n>>1,o=i(e,t[s]);if(o>0)r=s+1;else{if(!(o<0))return s;n=s-1}}return-r-1}function y(t,e,i){const r=function(t,e){let i=t.length-1;if(t[i]<e)return-1;let r=0;for(;r<=i;){const n=r+i>>1;t[n]>=e?i=n-1:r=n+1}return i+1}(t,e),n=function(t,e){if(t[0]>e)return-1;let i=0,r=t.length-1;for(;i<=r;){const n=i+r>>1;t[n]>e?r=n-1:i=n+1}return i-1}(t,i);return-1===r||-1===n||r>n?0:n-r+1}function b(t){return t.sort().filter((function(t,e,i){return 0===e||t!==i[e-1]}))}function _(t){const e=28672;if(t.length>e){const i=[];for(let r=0;r<t.length;r+=e)i.push(String.fromCharCode.apply(null,t.subarray(r,r+e)));return i.join("")}return String.fromCharCode.apply(null,t)}function x(t,e){switch(t){case"int8":return new Int8Array(e);case"int16":return new Int16Array(e);case"int32":return new Int32Array(e);case"uint8":return new Uint8Array(e);case"uint16":return new Uint16Array(e);case"uint32":return new Uint32Array(e);case"float32":return new Float32Array(e);default:throw new Error("arrayType unknown: "+t)}}function v(t,e){return new(e>65535?Uint32Array:Uint16Array)(t)}function w(t){return t.buffer&&t.buffer instanceof ArrayBuffer?t.buffer:t}function A(t,e){return void 0===t?t=new e:Array.isArray(t)&&(t=(new e).fromArray(t)),t}function S(t){return A(t,e.Vector3)}function C(t){return A(t,e.Matrix4)}function P(t){return A(t,e.Quaternion)}function I(t){return e=t,i=Float32Array,e instanceof i?e:new i(e);var e,i}function k(t){return l(t,"").toString().toLowerCase()}class M{constructor(t){this.name=t,this._dict={}}add(t,e){this._dict[k(t)]=e}get(t){return this._dict[k(t)]}get names(){return Object.keys(this._dict)}}function T(t){return.01745*t}const D="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),B=new Array(36);function F(){let t,e=0;for(let i=0;i<36;i++)8===i||13===i||18===i||23===i?B[i]="-":14===i?B[i]="4":(e<=2&&(e=33554432+16777216*Math.random()|0),t=15&e,e>>=4,B[i]=D[19===i?3&t|8:t]);return B.join("")}function E(t,e,i){return Math.max(e,Math.min(i,t))}function O(t,e,i){return t+(e-t)*i}function $(t,e,i,r,n,s){const o=(i-t)*s,a=(r-e)*s,c=n*n;return(2*e-2*i+o+a)*(n*c)+(-3*e+3*i-2*o-a)*c+o*n+e}function R(t,e,i){var r;return r=function(t,e,i){return(t-e)/(i-e)}(i,t,e),(i=E(r,0,1))*i*(3-2*i)}var L="sRGB";const N={scale:"uniform",mode:"hcl",domain:[0,1],value:16777215,reverse:!1},z=new e.Color;function V(t,e,i){const r=i.value;return i.value=function(t,e){let i=r.bind(this,t,e)();return"linear"==L?(z.set(i),z.convertSRGBToLinear(),z.getHex()):i},i}class U{constructor(t={}){this.parameters=u(t,N),"string"==typeof this.parameters.value&&(this.parameters.value=z.set(this.parameters.value).getHex()),this.parameters.structure&&(this.atomProxy=this.parameters.structure.getAtomProxy())}getScale(t={}){const e=u(t,this.parameters);return"rainbow"===e.scale?e.scale=["red","orange","yellow","green","blue"]:"rwb"===e.scale&&(e.scale=["red","white","blue"]),e.reverse&&(e.domain=e.domain.slice().reverse()),o.scale(e.scale).mode(e.mode).domain(e.domain).out("num")}colorToArray(t,e=[],i=0){return e[i]=(t>>16&255)/255,e[i+1]=(t>>8&255)/255,e[i+2]=(255&t)/255,e}atomColorToArray(t,e,i){return this.colorToArray(this.atomColor?this.atomColor(t):0,e,i)}bondColor(t,e){return this.atomProxy&&this.atomColor?(this.atomProxy.index=e?t.atomIndex1:t.atomIndex2,this.atomColor(this.atomProxy)):0}bondColorToArray(t,e,i,r){return this.colorToArray(this.bondColor(t,e),i,r)}volumeColorToArray(t,e,i){return this.colorToArray(this.volumeColor?this.volumeColor(t):0,e,i)}positionColorToArray(t,e,i){return this.colorToArray(this.positionColor?this.positionColor(t):0,e,i)}}var j;!function(t){t[t.PROTEIN=1]="PROTEIN",t[t.NUCLEIC=2]="NUCLEIC",t[t.RNA=3]="RNA",t[t.DNA=4]="DNA",t[t.POLYMER=5]="POLYMER",t[t.WATER=6]="WATER",t[t.HELIX=7]="HELIX",t[t.SHEET=8]="SHEET",t[t.TURN=9]="TURN",t[t.BACKBONE=10]="BACKBONE",t[t.SIDECHAIN=11]="SIDECHAIN",t[t.ALL=12]="ALL",t[t.HETERO=13]="HETERO",t[t.ION=14]="ION",t[t.SACCHARIDE=15]="SACCHARIDE",t[t.SUGAR=15]="SUGAR",t[t.BONDED=16]="BONDED",t[t.RING=17]="RING",t[t.AROMATICRING=18]="AROMATICRING",t[t.METAL=19]="METAL",t[t.POLARH=20]="POLARH",t[t.NONE=21]="NONE"}(j||(j={}));const G=["*","","ALL"],H=["NONE"],q=[j.BACKBONE,j.SIDECHAIN,j.BONDED,j.RING,j.AROMATICRING,j.METAL,j.POLARH],W=[j.POLYMER,j.WATER],X=["ALA","GLY","SER"],Y=["CYS","SER","THR"],K=["ALA","ILE","LEU","MET","PHE","PRO","TRP","VAL"],Z=["PHE","TRP","TYR","HIS"],Q=["ASN","GLN"],J=["ASP","GLU"],tt=["ARG","HIS","LYS"],et=["ARG","ASP","GLU","HIS","LYS"],it=["ASN","ARG","ASP","CYS","GLY","GLN","GLU","HIS","LYS","SER","THR","TYR"],rt=["ALA","ILE","LEU","MET","PHE","PRO","TRP","VAL"],nt=["HIS","PHE","PRO","TRP","TYR"],st=["ALA","GLY","ILE","LEU","VAL"];function ot(t,e){if(void 0===e.atomname&&void 0===e.element&&void 0===e.altloc&&void 0===e.atomindex&&void 0===e.keyword&&void 0===e.inscode&&void 0===e.resname&&void 0===e.sstruc&&void 0===e.resno&&void 0===e.chainname&&void 0===e.model)return-1;if(void 0!==e.keyword){if(e.keyword===j.BACKBONE&&!t.isBackbone())return!1;if(e.keyword===j.SIDECHAIN&&!t.isSidechain())return!1;if(e.keyword===j.BONDED&&!t.isBonded())return!1;if(e.keyword===j.RING&&!t.isRing())return!1;if(e.keyword===j.AROMATICRING&&!t.isAromatic())return!1;if(e.keyword===j.HETERO&&!t.isHetero())return!1;if(e.keyword===j.PROTEIN&&!t.isProtein())return!1;if(e.keyword===j.NUCLEIC&&!t.isNucleic())return!1;if(e.keyword===j.RNA&&!t.isRna())return!1;if(e.keyword===j.DNA&&!t.isDna())return!1;if(e.keyword===j.POLYMER&&!t.isPolymer())return!1;if(e.keyword===j.WATER&&!t.isWater())return!1;if(e.keyword===j.HELIX&&!t.isHelix())return!1;if(e.keyword===j.SHEET&&!t.isSheet())return!1;if(e.keyword===j.TURN&&!t.isTurn())return!1;if(e.keyword===j.ION&&!t.isIon())return!1;if(e.keyword===j.SACCHARIDE&&!t.isSaccharide())return!1;if(e.keyword===j.METAL&&!t.isMetal())return!1;if(e.keyword===j.POLARH&&!t.isPolarHydrogen())return!1}if(void 0!==e.atomname&&e.atomname!==t.atomname)return!1;if(void 0!==e.element&&e.element!==t.element)return!1;if(void 0!==e.altloc&&e.altloc!==t.altloc)return!1;if(void 0!==e.atomindex&&g(e.atomindex,t.index)<0)return!1;if(void 0!==e.resname)if(Array.isArray(e.resname)){if(!e.resname.includes(t.resname))return!1}else if(e.resname!==t.resname)return!1;if(void 0!==e.sstruc&&e.sstruc!==t.sstruc)return!1;if(void 0!==e.resno)if(Array.isArray(e.resno)&&2===e.resno.length){if(e.resno[0]>t.resno||e.resno[1]<t.resno)return!1}else if(e.resno!==t.resno)return!1;return(void 0===e.inscode||e.inscode===t.inscode)&&((void 0===e.chainname||e.chainname===t.chainname)&&(void 0===e.model||e.model===t.modelIndex))}function at(t,e){if(void 0===e.resname&&void 0===e.resno&&void 0===e.inscode&&void 0===e.sstruc&&void 0===e.model&&void 0===e.chainname&&void 0===e.atomindex&&(void 0===e.keyword||q.includes(e.keyword)))return-1;if(void 0!==e.keyword){if(e.keyword===j.HETERO&&!t.isHetero())return!1;if(e.keyword===j.PROTEIN&&!t.isProtein())return!1;if(e.keyword===j.NUCLEIC&&!t.isNucleic())return!1;if(e.keyword===j.RNA&&!t.isRna())return!1;if(e.keyword===j.DNA&&!t.isDna())return!1;if(e.keyword===j.POLYMER&&!t.isPolymer())return!1;if(e.keyword===j.WATER&&!t.isWater())return!1;if(e.keyword===j.HELIX&&!t.isHelix())return!1;if(e.keyword===j.SHEET&&!t.isSheet())return!1;if(e.keyword===j.TURN&&!t.isTurn())return!1;if(e.keyword===j.ION&&!t.isIon())return!1;if(e.keyword===j.SACCHARIDE&&!t.isSaccharide())return!1}if(void 0!==e.atomindex&&0===y(e.atomindex,t.atomOffset,t.atomEnd))return!1;if(void 0!==e.resname)if(Array.isArray(e.resname)){if(!e.resname.includes(t.resname))return!1}else if(e.resname!==t.resname)return!1;if(void 0!==e.sstruc&&e.sstruc!==t.sstruc)return!1;if(void 0!==e.resno)if(Array.isArray(e.resno)&&2===e.resno.length){if(e.resno[0]>t.resno||e.resno[1]<t.resno)return!1}else if(e.resno!==t.resno)return!1;return(void 0===e.inscode||e.inscode===t.inscode)&&((void 0===e.chainname||e.chainname===t.chainname)&&(void 0===e.model||e.model===t.modelIndex))}function ct(t,e){if(!(void 0!==e.chainname||void 0!==e.model||void 0!==e.atomindex||void 0!==e.keyword&&W.includes(e.keyword)&&t.entity))return-1;if(void 0!==e.keyword){if(e.keyword===j.POLYMER&&!t.entity.isPolymer())return!1;if(e.keyword===j.WATER&&!t.entity.isWater())return!1}return(void 0===e.atomindex||0!==y(e.atomindex,t.atomOffset,t.atomEnd))&&((void 0===e.chainname||e.chainname===t.chainname)&&(void 0===e.model||e.model===t.modelIndex))}function lt(t,e){return void 0===e.model&&void 0===e.atomindex?-1:(void 0===e.atomindex||0!==y(e.atomindex,t.atomOffset,t.atomEnd))&&(void 0===e.model||e.model===t.index)}function ut(t,e){if(null===t)return!1;if(t.error)return!1;if(!t.rules||0===t.rules.length)return!1;const i=t.rules.length,r=!t.negate,n=!!t.negate,s=[];for(let r=0;r<i;++r){const i=t.rules[r];i.hasOwnProperty("operator")&&(s[r]=ut(i,e))}return function(o){const a="AND"===t.operator;let c=!1;for(let l=0;l<i;++l){const i=t.rules[l];let u;if(i.hasOwnProperty("operator")){const t=s[l];if(u=!1!==t?t(o):-1,-1===u){c=!0;continue}if(!0===u){if(a)continue;return r}if(a)return n}else{if(i.keyword===j.ALL){if(a)continue;return r}if(i.keyword===j.NONE){if(a)continue;return n}if(u=e(o,i),-1!==u){if(!0===u){if(a)continue;return r}if(a)return n}else c=!0}}return c?-1:a?r:n}}function ht(t,e){if(t.error)return t;if(!t.rules||0===t.rules.length)return t;const i=t.rules.length,r={operator:t.operator,rules:[]};t.hasOwnProperty("negate")&&(r.negate=t.negate);for(let n=0;n<i;++n){const i=t.rules[n];if(i.hasOwnProperty("operator")){const t=ht(i,e);null!==t&&r.rules.push(t)}else e(i)||r.rules.push(i)}return r.rules.length>0?t:null}function dt(t,e=!1){let i=t;return e&&(i=ht(t,(function(t){return void 0!==t.keyword&&!q.includes(t.keyword)||(void 0!==t.model||(void 0!==t.chainname||(void 0!==t.resname||(void 0!==t.resno||void 0!==t.sstruc))))}))),ut(i,ot)}function mt(t,e=!1){let i=t;return e&&(i=ht(t,(function(t){return!(void 0===t.keyword||!q.includes(t.keyword))||(void 0!==t.model||(void 0!==t.chainname||(void 0!==t.atomname||(void 0!==t.element||void 0!==t.altloc))))}))),ut(i,at)}function ft(t,e=!1){let i=t;return e&&(i=ht(t,(function(t){return void 0!==t.keyword&&!W.includes(t.keyword)||(void 0!==t.resname||(void 0!==t.resno||(void 0!==t.atomname||(void 0!==t.element||(void 0!==t.altloc||(void 0!==t.sstruc||void 0!==t.inscode))))))}))),ut(i,ct)}function pt(t,e=!1){let i=t;return e&&(i=ht(t,(function(t){return void 0!==t.keyword||(void 0!==t.chainname||(void 0!==t.resname||(void 0!==t.resno||(void 0!==t.atomname||(void 0!==t.element||(void 0!==t.altloc||(void 0!==t.sstruc||void 0!==t.inscode)))))))}))),ut(i,lt)}class gt{constructor(t){this.signals={stringChanged:new r.Signal},this.setString(t)}get type(){return"selection"}setString(t,e){if(void 0===t&&(t=this.string||""),t===this.string)return;try{this.selection=function(t){let e={operator:void 0,rules:[]};if(!t)return e;let i,r,n=e;const s=[];"("===(t=t.replace(/\(/g," ( ").replace(/\)/g," ) ").trim()).charAt(0)&&")"===t.substr(-1)&&(t=t.slice(1,-1).trim());const o=t.split(/\s+/),a=t=>{i={operator:t,rules:[]},void 0===n?(n=i,e=i):(n.rules.push(i),s.push(n),n=i)},c=function(t){r=n,n=s.pop(),void 0===n&&(a(t),l(r))},l=function(t){n.rules.push(t)};let u=!1;for(let t=0;t<o.length;++t){const e=o[t],i=e.toUpperCase();if("("===e){u=!1,a();continue}if(")"===e){c(),n.negate&&c();continue}if(u>0)if("NOT"===i)u=1;else if(1===u)u=2;else{if(2!==u)throw new Error("something went wrong with 'not'");u=!1,c()}if("AND"===i){if("OR"===n.operator){const t=n.rules.pop();a("AND"),l(t)}else n.operator="AND";continue}if("OR"===i){"AND"===n.operator?c("OR"):n.operator="OR";continue}if("NOT"===e.toUpperCase()){u=1,a(),n.negate=!0;continue}if(+i!=+i){const t=j[i];if(void 0!==t){l({keyword:t});continue}}if("HYDROGEN"===i){l({operator:"OR",rules:[{element:"H"},{element:"D"}]});continue}if("SMALL"===i){l({resname:X});continue}if("NUCLEOPHILIC"===i){l({resname:Y});continue}if("HYDROPHOBIC"===i){l({resname:K});continue}if("AROMATIC"===i){l({resname:Z});continue}if("AMIDE"===i){l({resname:Q});continue}if("ACIDIC"===i){l({resname:J});continue}if("BASIC"===i){l({resname:tt});continue}if("CHARGED"===i){l({resname:et});continue}if("POLAR"===i){l({resname:it});continue}if("NONPOLAR"===i){l({resname:rt});continue}if("CYCLIC"===i){l({resname:nt});continue}if("ALIPHATIC"===i){l({resname:st});continue}if("SIDECHAINATTACHED"===i){l({operator:"OR",rules:[{keyword:j.SIDECHAIN},{operator:"AND",negate:!1,rules:[{keyword:j.PROTEIN},{operator:"OR",negate:!1,rules:[{atomname:"CA"},{atomname:"BB"}]}]},{operator:"AND",negate:!1,rules:[{resname:"PRO"},{atomname:"N"}]},{operator:"AND",negate:!1,rules:[{keyword:j.NUCLEIC},{operator:"OR",negate:!0,rules:[{atomname:"P"},{atomname:"OP1"},{atomname:"OP2"},{atomname:"O3'"},{atomname:"O3*"},{atomname:"HO3'"},{atomname:"O5'"},{atomname:"O5*"},{atomname:"HO5'"},{atomname:"C5'"},{atomname:"C5*"},{atomname:"H5'"},{atomname:"H5''"}]}]}]});continue}if("APOLARH"===i){l({operator:"AND",negate:!1,rules:[{element:"H"},{negate:!0,operator:void 0,rules:[{keyword:j.POLARH}]}]});continue}if("LIGAND"===i){l({operator:"AND",rules:[{operator:"OR",rules:[{operator:"AND",rules:[{keyword:j.HETERO},{negate:!0,operator:void 0,rules:[{keyword:j.POLYMER}]}]},{negate:!0,operator:void 0,rules:[{keyword:j.POLYMER}]}]},{negate:!0,operator:void 0,rules:[{operator:"OR",rules:[{keyword:j.WATER},{keyword:j.ION}]}]}]});continue}if(-1!==G.indexOf(i)){l({keyword:j.ALL});continue}if("@"===e.charAt(0)){const t=e.substr(1).split(",").map((t=>parseInt(t)));t.sort((function(t,e){return t-e})),l({atomindex:t});continue}if("#"===e.charAt(0)){console.error("# for element selection deprecated, use _"),l({element:i.substr(1)});continue}if("_"===e.charAt(0)){l({element:i.substr(1)});continue}if("["===e[0]&&"]"===e[e.length-1]){const t=i.substr(1,e.length-2).split(","),r=t.length>1?t:t[0];l({resname:r});continue}if(e.length>=1&&e.length<=4&&"^"!==e[0]&&":"!==e[0]&&"."!==e[0]&&"%"!==e[0]&&"/"!==e[0]&&isNaN(parseInt(e))){l({resname:i});continue}const r={operator:"AND",rules:[]},s=e.split("/");if(s.length>1&&s[1]){if(isNaN(parseInt(s[1])))throw new Error("model must be an integer");r.rules.push({model:parseInt(s[1])})}const h=s[0].split("%");h.length>1&&r.rules.push({altloc:h[1]});const d=h[0].split(".");if(d.length>1&&d[1]){if(d[1].length>4)throw new Error("atomname must be one to four characters");r.rules.push({atomname:d[1].substring(0,4).toUpperCase()})}const m=d[0].split(":");m.length>1&&m[1]&&r.rules.push({chainname:m[1]});const f=m[0].split("^");if(f.length>1&&r.rules.push({inscode:f[1]}),f[0]){let t,e;"-"===f[0][0]&&(f[0]=f[0].substr(1),t=!0),f[0].includes("--")&&(f[0]=f[0].replace("--","-"),e=!0);let i=f[0].split("-");if(1===i.length){let e=parseInt(i[0]);if(isNaN(e))throw new Error("resi must be an integer");t&&(e*=-1),r.rules.push({resno:e})}else{if(2!==i.length)throw new Error("resi range must contain one '-'");{const n=i.map((t=>parseInt(t)));t&&(n[0]*=-1),e&&(n[1]*=-1),r.rules.push({resno:[n[0],n[1]]})}}}if(1===r.rules.length)l(r.rules[0]);else{if(!(r.rules.length>1))throw new Error("empty selection chunk");l(r)}}return void 0===e.operator&&1===e.rules.length&&e.rules[0].hasOwnProperty("operator")&&(e=e.rules[0]),e}(t)}catch(t){this.selection={error:t.message}}const i=this.selection;this.string=t,this.test=dt(i),this.residueTest=mt(i),this.chainTest=ft(i),this.modelTest=pt(i),this.atomOnlyTest=dt(i,!0),this.residueOnlyTest=mt(i,!0),this.chainOnlyTest=ft(i,!0),this.modelOnlyTest=pt(i,!0),e||this.signals.stringChanged.dispatch(this.string)}isAllSelection(){return G.includes(this.string.toUpperCase())}isNoneSelection(){return H.includes(this.string.toUpperCase())}}class yt extends U{constructor(t){super(t),this.colormakerList=[],this.selectionList=[];(t.dataList||[]).forEach((t=>{const[i,r,n={}]=t;$t.hasScheme(i)?Object.assign(n,{scheme:i,structure:this.parameters.structure}):Object.assign(n,{scheme:"uniform",value:new e.Color(i).getHex()}),this.colormakerList.push($t.getScheme(n)),this.selectionList.push(new gt(r))}))}atomColor(t){for(let e=0,i=this.selectionList.length;e<i;++e){const i=this.selectionList[e].test;if(i&&i(t))return this.colormakerList[e].atomColor(t)}return 16777215}}const bt={"":"",OrRd:"[S] Orange-Red",PuBu:"[S] Purple-Blue",BuPu:"[S] Blue-Purple",Oranges:"[S] Oranges",BuGn:"[S] Blue-Green",YlOrBr:"[S] Yellow-Orange-Brown",YlGn:"[S] Yellow-Green",Reds:"[S] Reds",RdPu:"[S] Red-Purple",Greens:"[S] Greens",YlGnBu:"[S] Yellow-Green-Blue",Purples:"[S] Purples",GnBu:"[S] Green-Blue",Greys:"[S] Greys",YlOrRd:"[S] Yellow-Orange-Red",PuRd:"[S] Purple-Red",Blues:"[S] Blues",PuBuGn:"[S] Purple-Blue-Green",Viridis:"[D] Viridis",Spectral:"[D] Spectral",RdYlGn:"[D] Red-Yellow-Green",RdBu:"[D] Red-Blue",PiYG:"[D] Pink-Yellowgreen",PRGn:"[D] Purplered-Green",RdYlBu:"[D] Red-Yellow-Blue",BrBG:"[D] Brown-Bluegreen",RdGy:"[D] Red-Grey",PuOr:"[D] Purple-Orange",Set1:"[Q] Set1",Set2:"[Q] Set2",Set3:"[Q] Set3",Dark2:"[Q] Dark2",Paired:"[Q] Paired",Pastel1:"[Q] Pastel1",Pastel2:"[Q] Pastel2",Accent:"[Q] Accent",rainbow:"[?] Rainbow",rwb:"[?] Red-White-Blue"},_t={"":"",rgb:"Red Green Blue",hsv:"Hue Saturation Value",hsl:"Hue Saturation Lightness",hsi:"Hue Saturation Intensity",lab:"CIE L*a*b*",hcl:"Hue Chroma Lightness"};function xt(t){const e=t;return t.forEach((function(t){t.__deps&&Array.prototype.push.apply(e,xt(t.__deps))})),e}function vt(t){return b(xt(t)).map((function(t){return t.toString()})).join("\n\n\n")}function wt(t){const e=t.data.__name,i=t.data.__postId;if(void 0===e)console.error("message __name undefined");else if(void 0===self.func)console.error("worker func undefined",e);else{const e=function(t,e){t=t||{},void 0!==i&&(t.__postId=i);try{self.postMessage(t,e)}catch(e){console.error("self.postMessage:",e),self.postMessage(t)}};self.func(t,e)}}function At(t,e){let i="'use strict';\n\n"+vt(e);return i+="\n\n\nself.func = "+t.toString()+";",i+="\n\n\nself.onmessage = "+wt.toString()+";",new Blob([i],{type:"application/javascript"})}const St=d();let Ct=!1;try{const t=Object.defineProperty({},"passive",{get:function(){Ct=!0}});window.addEventListener("test",(t=>{}),t)}catch(t){}const Pt="undefined"!=typeof window&&void 0!==window.orientation;let It=!1;function kt(t){It=t}let Mt=!1;function Tt(t){Mt=t}const Dt={log:Function.prototype.bind.call(console.log,console),info:Function.prototype.bind.call(console.info,console),warn:Function.prototype.bind.call(console.warn,console),error:Function.prototype.bind.call(console.error,console),time:Function.prototype.bind.call(console.time,console),timeEnd:Function.prototype.bind.call(console.timeEnd,console)};let Bt={color:"green",labelColor:8421504,labelAttachment:"bottom-center",labelSize:.7,labelZOffset:.5,labelYOffset:.1,labelBorder:!0,labelBorderColor:13882323,labelBorderWidth:.25,lineOpacity:.8,linewidth:5,opacity:.6,labelUnit:"angstrom",arcVisible:!0,planeVisible:!1};var Ft;t.Debug=!!(Ft=c("debug"))&&("string"!=typeof Ft||/^1|true|t|yes|y$/i.test(Ft));const Et=["ngl","js"],Ot=new class{constructor(){this.activeWorkerCount=0,this._funcDict={},this._depsDict={},this._blobDict={}}add(t,e,i){this._funcDict[t]=e,this._depsDict[t]=i}get(t){return this._blobDict[t]||(this._blobDict[t]=At(this._funcDict[t],this._depsDict[t])),this._blobDict[t]}},$t=new class{constructor(){this.schemes={},this.userSchemes={}}getScheme(t){const e=((t||{}).scheme||"").toLowerCase();let i;return i=e in this.schemes?this.schemes[e]:e in this.userSchemes?this.userSchemes[e]:U,new i(t)}getSchemes(){const t={};return Object.keys(this.schemes).forEach((function(e){t[e]=e})),Object.keys(this.userSchemes).forEach((function(e){t[e]=e.split("|")[1]})),t}getScales(){return bt}getModes(){return _t}add(t,e){t=t.toLowerCase(),this.schemes[t]=e}addScheme(t,e){return function(t){return t instanceof U}(t)||(t=this._createScheme(t)),this._addUserScheme(t,e)}_addUserScheme(t,e){e=e||"";const i=`${F()}|${e}`.toLowerCase();return this.userSchemes[i]=t,i}removeScheme(t){t=t.toLowerCase(),delete this.userSchemes[t]}_createScheme(t){return class extends U{constructor(e){super(e),t.call(this,e)}}}addSelectionScheme(t,e){return this._addUserScheme(class extends yt{constructor(e){super(Object.assign({dataList:t},e))}},e)}hasScheme(t){return(t=t.toLowerCase())in this.schemes||t in this.userSchemes}},Rt=new M("datasource"),Lt=new M("representatation"),Nt=new class extends M{constructor(){super("parser")}__hasObjName(t,e){const i=this.get(t);return i&&i.prototype.__objName===e}isTrajectory(t){return this.__hasObjName(t,"frames")}isStructure(t){return this.__hasObjName(t,"structure")}isVolume(t){return this.__hasObjName(t,"volume")}isSurface(t){return this.__hasObjName(t,"surface")}isBinary(t){const e=this.get(t);return e&&e.prototype.isBinary}isXml(t){const e=this.get(t);return e&&e.prototype.isXml}isJson(t){const e=this.get(t);return e&&e.prototype.isJson}getTrajectoryExtensions(){return this.names.filter((t=>this.isTrajectory(t)))}getStructureExtensions(){return this.names.filter((t=>this.isStructure(t)))}getVolumeExtensions(){return this.names.filter((t=>this.isVolume(t)))}getSurfaceExtensions(){return this.names.filter((t=>this.isSurface(t)))}},zt=new M("shader"),Vt=new M("decompressor"),Ut=new M("component"),jt=new M("buffer"),Gt=new M("picker");t.ListingDatasource=void 0,t.TrajectoryDatasource=void 0;class Ht{constructor(t,e={}){this.chunkSize=10485760,this.newline="\n",this.__pointer=0,this.__partialLine="",this.compressed=l(e.compressed,!1),this.binary=l(e.binary,!1),this.json=l(e.json,!1),this.xml=l(e.xml,!1),this.src=t}isBinary(){return this.binary||this.compressed}read(){return this._read().then((t=>{const e=this.compressed?Vt.get(this.compressed):void 0;return this.compressed&&e?this.data=e(t):((this.binary||this.compressed)&&t instanceof ArrayBuffer&&(t=new Uint8Array(t)),this.data=t),this.data}))}_chunk(t,e){return e=Math.min(this.data.length,e),0===t&&this.data.length===e?this.data:this.isBinary()?this.data.subarray(t,e):this.data.substring(t,e)}chunk(t){const e=t+this.chunkSize;return this._chunk(t,e)}peekLines(t){const e=this.data,i=e.length,r=this.isBinary()?this.newline.charCodeAt(0):this.newline;let n,s=0;for(n=0;n<i&&(e[n]===r&&++s,s!==t);++n);const o=this._chunk(0,n+1);return this.chunkToLines(o,"",n>i).lines}chunkCount(){return Math.floor(this.data.length/this.chunkSize)+1}asText(){return this.isBinary()?_(this.data):this.data}chunkToLines(t,e,i){const r=this.newline;if(!this.isBinary()&&t.length===this.data.length)return{lines:t.split(r),partialLine:""};let n=[];const s=this.isBinary()?_(t):t,o=s.lastIndexOf(r);if(-1===o)e+=s;else{const t=e+s.substr(0,o);n=n.concat(t.split(r)),e=o===s.length-r.length?"":s.substr(o+r.length)}return i&&""!==e&&n.push(e),{lines:n,partialLine:e}}nextChunk(){const t=this.__pointer;if(!(t>this.data.length))return this.__pointer+=this.chunkSize,this.chunk(t)}nextChunkOfLines(){const t=this.nextChunk();if(void 0===t)return;const e=this.__pointer>this.data.length,i=this.chunkToLines(t,this.__partialLine,e);return this.__partialLine=i.partialLine,i.lines}eachChunk(t){const e=this.chunkSize,i=this.data.length,r=this.chunkCount();for(let n=0;n<i;n+=e){t(this.chunk(n),Math.round(n/e),r)}}eachChunkOfLines(t){this.eachChunk(((e,i,r)=>{const n=i===r+1,s=this.chunkToLines(e,this.__partialLine,n);this.__partialLine=s.partialLine,t(s.lines,i,r)}))}dispose(){delete this.src}}class qt extends Ht{_read(){return new Promise(((t,e)=>{const i=this.src,r=new FileReader;r.onload=e=>{e.target&&t(e.target.result)},r.onerror=t=>e(t),this.binary||this.compressed?r.readAsArrayBuffer(i):r.readAsText(i)}))}}class Wt extends Ht{_read(){return new Promise(((t,e)=>{const i=this.src,r=new XMLHttpRequest;r.open("GET",i,!0),r.addEventListener("load",(()=>{if(200===r.status||304===r.status||0===r.status)try{t(r.response)}catch(t){e(t)}else e(r.statusText)}),!1),r.addEventListener("error",(t=>e("network error")),!1),this.isBinary()?r.responseType="arraybuffer":this.json?r.responseType="json":this.xml?r.responseType="document":r.responseType="text",r.send()}))}}class Xt{constructor(t,e={}){this.parameters=u(e,{ext:"",compressed:!1,binary:Nt.isBinary(e.ext||""),name:"",dir:"",path:"",protocol:""});const i={compressed:this.parameters.compressed,binary:this.parameters.binary,json:Nt.isJson(this.parameters.ext),xml:Nt.isXml(this.parameters.ext)};"undefined"!=typeof File&&t instanceof File||"undefined"!=typeof Blob&&t instanceof Blob?this.streamer=new qt(t,i):this.streamer=new Wt(t,i)}}class Yt extends Xt{constructor(t,e={}){super(t,e),this.parserParams={voxelSize:e.voxelSize,firstModelOnly:e.firstModelOnly,asTrajectory:e.asTrajectory,cAlphaOnly:e.cAlphaOnly,delimiter:e.delimiter,comment:e.comment,columnNames:e.columnNames,inferBonds:e.inferBonds,name:this.parameters.name,path:this.parameters.path}}load(){return new(Nt.get(this.parameters.ext))(this.streamer,this.parserParams).parse()}}class Kt{constructor(t,e,i){this.name=e,this.path=i,this.signals={elementAdded:new r.Signal,elementRemoved:new r.Signal,nameChanged:new r.Signal},this.type="Script",this.dir=i.substring(0,i.lastIndexOf("/")+1);try{this.fn=new Function("stage","__name","__path","__dir",t)}catch(t){Dt.error("Script compilation failed",t),this.fn=function(){}}}run(t){return new Promise(((e,i)=>{try{this.fn.apply(null,[t,this.name,this.path,this.dir]),e()}catch(t){Dt.error("Script.fn",t),i(t)}}))}}class Zt extends Xt{load(){return this.streamer.read().then((()=>new Kt(this.streamer.asText(),this.parameters.name,this.parameters.path)))}}function Qt(t){const e=Vt.names;let i,r,n="";i=t instanceof File?t.name:t instanceof Blob?"":t;const s=i.lastIndexOf("?"),o=-1!==s?i.substring(s):"";i=i.substring(0,-1===s?i.length:s);const a=i.replace(/^.*[\\/]/,"");let c=a.substring(0,a.lastIndexOf("."));const l=a.split(".");let u=l.length>1?(l.pop()||"").toLowerCase():"";const h=i.match(/^(.+):\/\/(.+)$/);h&&(n=h[1].toLowerCase(),i=h[2]||"");const d=i.substring(0,i.lastIndexOf("/")+1);if(e.includes(u)){r=u;const t=i.length-u.length-1;u=(i.substr(0,t).split(".").pop()||"").toLowerCase();const e=c.length-u.length-1;c=c.substr(0,e)}else r=!1;return{path:i,name:a,ext:u,base:c,dir:d,compressed:r,protocol:n,query:o,src:t}}function Jt(t){let e=Qt(t);const i=Rt.get(e.protocol);return i&&(e=Qt(i.getUrl(e.src)),!e.ext&&i.getExt&&(e.ext=i.getExt(t))),e}function te(t,e={}){const i=Object.assign(Jt(t),e);let r;return Nt.names.includes(i.ext)?r=new Yt(i.src,i):Et.includes(i.ext)&&(r=new Zt(i.src,i)),r?r.load():Promise.reject(new Error(`autoLoad: ext '${i.ext}' unknown`))}class ee{getBlob(){return new Blob([this.getData()],{type:this.mimeType})}download(t,e){t=l(t,this.defaultName),e=l(e,this.defaultExt),f(this.getBlob(),`${t}.${e}`)}}const ie=[];class re{constructor(t,e={}){this._mark=0,this._marks=[],this.offset=0,this.littleEndian=!0;let i=!1;void 0===t&&(t=8192),"number"==typeof t?t=new ArrayBuffer(t):i=!0;const r=e.offset?e.offset>>>0:0;let n=t.byteLength-r,s=r;t instanceof ArrayBuffer||(t.byteLength!==t.buffer.byteLength&&(s=t.byteOffset+r),t=t.buffer),this._lastWrittenByte=i?n:0,this.buffer=t,this.length=n,this.byteLength=n,this.byteOffset=s,this._data=new DataView(this.buffer,s,n)}available(t){return void 0===t&&(t=1),this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t){return void 0===t&&(t=1),this.offset+=t,this}seek(t){return this.offset=t,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const t=this._marks.pop();if(void 0===t)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t){if(void 0===t&&(t=1),!this.available(t)){const e=2*(this.offset+t),i=new Uint8Array(e);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=e,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(t){void 0===t&&(t=1);for(var e=new Uint8Array(t),i=0;i<t;i++)e[i]=this.readByte();return e}readInt16(){var t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){var t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){var t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){var t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){var t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){var t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){ie.length=t;for(var e=0;e<t;e++)ie[e]=this.readChar();return ie.join("")}writeBoolean(t=!1){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(var e=0;e<t.length;e++)this._data.setUint8(this.offset++,t[e]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(var e=0;e<t.length;e++)this.writeUint8(t.charCodeAt(e));return this}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this._lastWrittenByte)}_updateLastWrittenByte(){this.offset>this._lastWrittenByte&&(this._lastWrittenByte=this.offset)}}class ne{constructor(){this.count=0,this.signals={countChanged:new a.Signal}}clear(){this.change(-this.count)}change(t){this.count+=t,this.signals.countChanged.dispatch(t,this.count),this.count<0&&Dt.warn("Counter.count below zero",this.count)}increment(){this.change(1)}decrement(){this.change(-1)}listen(t){this.change(t.count),t.signals.countChanged.add(this.change,this)}unlisten(t){const e=t.signals.countChanged;e.has(this.change,this)&&e.remove(this.change,this)}onZeroOnce(t,e){if(0===this.count)t.call(e);else{const i=()=>{0===this.count&&(this.signals.countChanged.remove(i,this),t.call(e))};this.signals.countChanged.add(i,this)}}dispose(){this.clear(),this.signals.countChanged.dispose()}}zt.add("shader/BasicLine.vert","void main(){\n#include begin_vertex\n#include project_vertex\n}"),zt.add("shader/BasicLine.frag","uniform vec3 uColor;\n#include common\n#include fog_pars_fragment\nvoid main(){\ngl_FragColor = vec4( uColor, 1.0 );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n}"),zt.add("shader/Quad.vert","varying vec2 vUv;\nvoid main() {\nvUv = uv;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"),zt.add("shader/Quad.frag","varying vec2 vUv;\nuniform sampler2D tForeground;\nuniform float scale;\nvoid main() {\nvec4 foreground = texture2D( tForeground, vUv );\ngl_FragColor = foreground * scale;\n}");class se{constructor(){this.signals={updated:new a.Signal},this.maxDuration=-1/0,this.minDuration=1/0,this.avgDuration=14,this.lastDuration=1/0,this.prevFpsTime=0,this.lastFps=1/0,this.lastFrames=1,this.frames=0,this.count=0,this.begin()}update(){this.startTime=this.end(),this.currentTime=this.startTime,this.signals.updated.dispatch()}begin(){this.startTime=window.performance.now(),this.lastFrames=this.frames}end(){const t=window.performance.now();return this.count+=1,this.frames+=1,this.lastDuration=t-this.startTime,this.minDuration=Math.min(this.minDuration,this.lastDuration),this.maxDuration=Math.max(this.maxDuration,this.lastDuration),this.avgDuration-=this.avgDuration/30,this.avgDuration+=this.lastDuration/30,t>this.prevFpsTime+1e3&&(this.lastFps=this.frames,this.prevFpsTime=t,this.frames=0),t}}zt.add("shader/chunk/fog_fragment.glsl","#ifdef USE_FOG\nfloat depth = length( vViewPosition );\n#ifdef FOG_EXP2\nfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif"),zt.add("shader/chunk/interior_fragment.glsl","if( gl_FrontFacing == false ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}"),zt.add("shader/chunk/matrix_scale.glsl","float matrixScale( in mat4 m ){\nvec4 r = m[ 0 ];\nreturn sqrt( r[ 0 ] * r[ 0 ] + r[ 1 ] * r[ 1 ] + r[ 2 ] * r[ 2 ] );\n}"),zt.add("shader/chunk/nearclip_vertex.glsl","#ifdef NEAR_CLIP\nif( vViewPosition.z < clipNear - 5.0 )\ngl_Position.z = 2.0 * gl_Position.w;\n#endif"),zt.add("shader/chunk/nearclip_fragment.glsl","#ifdef NEAR_CLIP\nif( vViewPosition.z < clipNear )\ndiscard;\n#endif"),zt.add("shader/chunk/opaque_back_fragment.glsl","#ifdef OPAQUE_BACK\n#ifdef FLIP_SIDED\nif( gl_FrontFacing == true ){\ngl_FragColor.a = 1.0;\n}\n#else\nif( gl_FrontFacing == false ){\ngl_FragColor.a = 1.0;\n}\n#endif\n#endif"),zt.add("shader/chunk/radiusclip_vertex.glsl","#ifdef RADIUS_CLIP\nif( distance( vViewPosition, vClipCenter ) > clipRadius + 5.0 )\ngl_Position.z = 2.0 * gl_Position.w;\n#endif"),zt.add("shader/chunk/radiusclip_fragment.glsl","#ifdef RADIUS_CLIP\nif( distance( vViewPosition, vClipCenter ) > clipRadius )\ndiscard;\n#endif"),zt.add("shader/chunk/unpack_color.glsl","vec3 unpackColor(float f) {\nvec3 color;\ncolor.r = floor(f / 256.0 / 256.0);\ncolor.g = floor((f - color.r * 256.0 * 256.0) / 256.0);\ncolor.b = floor(f - color.r * 256.0 * 256.0 - color.g * 256.0);\nreturn color / 255.0;\n}");const oe=/^(?!\/\/)\s*#include\s+(\S+)/gim,ae={};function ce(t,i={}){let r=t+"|";for(const t in i)r+=t+":"+i[t];if(!ae[r]){const n=function(t){if(void 0===t)return"";const e=[];for(const i in t){const r=t[i];r&&e.push(`#define ${i} ${r}`)}return e.join("\n")+"\n"}(i);let s=zt.get(`shader/${t}`);if(!s)throw new Error(`empty shader, '${t}'`);s=s.replace(oe,(function(t,i){const r=`shader/chunk/${i}.glsl`,n=zt.get(r)||e.ShaderChunk[i];if(!n)throw new Error(`empty chunk, '${i}'`);return n})),ae[r]=n+s}return ae[r]}if("undefined"!=typeof WebGLRenderingContext){const e=WebGLRenderingContext.prototype,i=e.getShaderParameter;e.getShaderParameter=function(){return!t.Debug||i.apply(this,arguments)};const r=e.getShaderInfoLog;e.getShaderInfoLog=function(){return t.Debug?r.apply(this,arguments):""};const n=e.getProgramParameter;e.getProgramParameter=function(i,r){return!t.Debug&&r===e.LINK_STATUS||n.apply(this,arguments)};const s=e.getProgramInfoLog;e.getProgramInfoLog=function(){return t.Debug?s.apply(this,arguments):""}}const le=[[[0,0]],[[4,4],[-4,-4]],[[-2,-6],[6,-2],[-6,2],[2,6]],[[1,-3],[-1,3],[5,1],[-3,-5],[-5,5],[-7,-1],[3,7],[7,-7]],[[1,1],[-1,-3],[-3,2],[4,-1],[-5,-2],[2,5],[5,3],[3,-5],[-2,6],[0,-7],[-4,-6],[-6,4],[-8,0],[7,-4],[6,7],[-7,-8]],[[-4,-7],[-7,-5],[-3,-5],[-5,-4],[-1,-4],[-2,-2],[-6,-1],[-4,0],[-7,1],[-1,2],[-6,3],[-3,3],[-7,6],[-3,6],[-5,7],[-1,7],[5,-7],[1,-6],[6,-5],[4,-4],[2,-3],[7,-2],[1,-1],[4,-1],[2,1],[6,2],[0,4],[4,4],[2,5],[7,5],[5,6],[3,7]]];le.forEach((t=>{t.forEach((t=>{t[0]*=.0625,t[1]*=.0625}))}));class ue{constructor(t,e,i,r){this.canvas=document.createElement("canvas"),this._viewer=i,this._factor=l(r.factor,2),this._antialias=l(r.antialias,!1),this._onProgress=r.onProgress,this._onFinish=r.onFinish,this._antialias&&(this._factor*=2),this._n=this._factor*this._factor,this._width=this._viewer.width,this._height=this._viewer.height,this._antialias?(this.canvas.width=this._width*this._factor/2,this.canvas.height=this._height*this._factor/2):(this.canvas.width=this._width*this._factor,this.canvas.height=this._height*this._factor),this._ctx=this.canvas.getContext("2d"),this._viewerSampleLevel=i.sampleLevel,this._viewer.setSampling(-1)}_renderTile(t){const e=this._viewer,i=this._width,r=this._height,n=this._factor,s=t%n*i,o=Math.floor(t/n)*r;if(e.camera.setViewOffset(i*n,r*n,s,o,i,r),e.render(),this._antialias){const t=Math.round((s+i)/2)-Math.round(s/2),n=Math.round((o+r)/2)-Math.round(o/2);this._ctx.drawImage(e.renderer.domElement,Math.round(s/2),Math.round(o/2),t,n)}else this._ctx.drawImage(e.renderer.domElement,Math.floor(s),Math.floor(o),Math.ceil(i),Math.ceil(r));"function"==typeof this._onProgress&&this._onProgress(t+1,this._n,!1)}_finalize(){this._viewer.setSampling(this._viewerSampleLevel),this._viewer.camera.view=null,"function"==typeof this._onFinish&&this._onFinish(this._n+1,this._n,!1)}render(){for(let t=0;t<=this._n;++t)t===this._n?this._finalize():this._renderTile(t)}renderAsync(){let t=0;const e=this._n,i=()=>{t===e?this._finalize():this._renderTile(t),t+=1};for(let t=0;t<=e;++t)setTimeout(i,0)}}const he=2*Math.PI,de=180/Math.PI;function me(t,e,i=1,r=0,n){const s=n?n.length:t.length/i;let o=0,a=0;if(n)for(let c=0;c<s;++c){const s=(t[n[c]*i+r]+e)%e/e*he-Math.PI;o+=Math.cos(s),a+=Math.sin(s)}else for(let n=r;n<s;n+=i){const i=(t[n]+e)%e/e*he-Math.PI;o+=Math.cos(i),a+=Math.sin(i)}o/=s,a/=s;return(Math.atan2(a,o)+Math.PI)/he*e}function fe(t,e,i,r=0){const n=t.length,s=i||new Float32Array(n);for(let i=0;i<n;i+=3)s[r+i+0]=(t[i+0]+e[i+0])/2,s[r+i+1]=(t[i+1]+e[i+1])/2,s[r+i+2]=(t[i+2]+e[i+2])/2;return s}function pe(t,e){const i=t.length,r=new Float32Array(i);for(let n=0;n<i;n+=3)r[n+0]=e[n+0]-t[n+0],r[n+1]=e[n+1]-t[n+1],r[n+2]=e[n+2]-t[n+2];return r}function ge(t,e,i){const r=i||new Float32Array(t);for(let i=0;i<t;++i)r[i]=e;return r}function ye(t,e,i,r,n){const s=n||new Float32Array(3*t);for(let n=0;n<t;++n){const t=3*n;s[t+0]=e,s[t+1]=i,s[t+2]=r}return s}function be(t){const e=new Float32Array(t);for(let i=0;i<t;++i)e[i]=i;return e}function _e(t,e,i=0,r){const n=r||new Float32Array(t*e);for(let r=0;r<t;++r){const t=i+r*e;for(let i=0;i<e;++i)n[t+i]=r}return n}function xe(t,e){const i=t.length,r=new Float32Array(i*e);for(let n=0;n<i;++n){const i=n*e,s=t[n];for(let t=0;t<e;++t)r[i+t]=s}return r}function ve(t,e,i,r,n){for(let s=0;s<n;++s)e[r+s]=t[i+s]}function we(t,e,i,r){ve(t,t,e,i,r)}function Ae(t){let e=-1/0;for(let i=0,r=t.length;i<r;++i)t[i]>e&&(e=t[i]);return e}function Se(t){let e=1/0;for(let i=0,r=t.length;i<r;++i)t[i]<e&&(e=t[i]);return e}function Ce(t,e=1,i=0){const r=t.length;let n=0;for(let s=i;s<r;s+=e)n+=t[s];return n}function Pe(t,e=1,i=0){return Ce(t,e,i)/(t.length/e)}const Ie={trim:!1,factor:1,antialias:!1,transparent:!1,onProgress:void 0};function ke(t,i={}){const{trim:r,factor:n,antialias:s,transparent:o}=u(i,Ie),a=t.renderer,c=t.camera,l=a.getClearAlpha(),h=a.getClearColor(new e.Color);function d(e=!1){let i=n;s&&(i*=2),e&&(i=1/i),t.scene.traverse((function(t){const e=t.material;e&&e.linewidth&&(e.linewidth*=i),e&&e.uniforms&&e.uniforms.size&&void 0===e.uniforms.size.__seen&&(e.uniforms.size.value*=i,e.uniforms.size.__seen=!0),e&&e.uniforms&&e.uniforms.linewidth&&void 0===e.uniforms.linewidth.__seen&&(e.uniforms.linewidth.value*=i,e.uniforms.linewidth.__seen=!0)})),t.scene.traverse((function(t){const e=t.material;e&&e.uniforms&&e.uniforms.size&&delete e.uniforms.size.__seen,e&&e.uniforms&&e.uniforms.linewidth&&delete e.uniforms.linewidth.__seen}))}function m(t){if(r){const e=h;return function(t,e,i,r,n){const s=t.height,o=t.width,a=t.getContext("2d").getImageData(0,0,o,s).data;let c,l,u,h;for(u=!1,l=0;l<s;l++){for(c=0;c<o;c++)if(h=4*(l*o+c),a[h]!==e||a[h+1]!==i||a[h+2]!==r||a[h+3]!==n){u=!0;break}if(u)break}const d=l;for(u=!1,c=0;c<o;c++){for(l=0;l<s;l++)if(h=4*(l*o+c),a[h]!==e||a[h+1]!==i||a[h+2]!==r||a[h+3]!==n){u=!0;break}if(u)break}const m=c;for(u=!1,l=s-1;l>=0;l--){for(c=o-1;c>=0;c--)if(h=4*(l*o+c),a[h]!==e||a[h+1]!==i||a[h+2]!==r||a[h+3]!==n){u=!0;break}if(u)break}const f=l;for(u=!1,c=o-1;c>=0;c--){for(l=s-1;l>=0;l--)if(h=4*(l*o+c),a[h]!==e||a[h+1]!==i||a[h+2]!==r||a[h+3]!==n){u=!0;break}if(u)break}const p=c,g=document.createElement("canvas");return g.width=p-m,g.height=f-d,g.getContext("2d").drawImage(t,m,d,g.width,g.height,0,0,g.width,g.height),g}(t,o?0:255*e.r,o?0:255*e.g,o?0:255*e.b,o?0:255)}return t}function f(t,e,r){"function"==typeof i.onProgress&&i.onProgress(t,e,r)}return new Promise((function(e,i){const r=new ue(a,c,t,{factor:n,antialias:s,onProgress:f,onFinish:function(n,s){m(r.canvas).toBlob((function(r){a.setClearAlpha(l),d(!0),t.requestRender(),f(s,s,!0),r?e(r):i("error creating image")}),"image/png")}});a.setClearAlpha(o?0:1),d(),r.renderAsync()}))}const Me=new e.Vector3,Te=new e.Matrix4,De=new e.Matrix4;const Be=new e.Vector2,Fe=new e.Matrix4,Ee=new e.Matrix4;function Oe(t,e){Fe.copy(e.projectionMatrix).invert(),Ee.copy(e.projectionMatrix).transpose(),t.traverse((function(t){const e=t.material;if(!e)return;const i=e.uniforms;i&&(i.projectionMatrixInverse&&i.projectionMatrixInverse.value.copy(Fe),i.projectionMatrixTranspose&&i.projectionMatrixTranspose.value.copy(Ee))}))}function $e(t,e,i){const r=t.createShader(i);if(!r)return void console.log(`error creating WebGL shader ${i}`);t.shaderSource(r,e),t.compileShader(r);return t.getShaderParameter(r,t.COMPILE_STATUS)?r:(console.log(`error compiling shader ${r}: ${t.getShaderInfoLog(r)}`),t.deleteShader(r),null)}function Re(t,e){const i=t.getExtension(e);return i||console.log(`extension '${e}' not available`),i}const Le=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]);function Ne(t){const e=document.createElement("canvas");e.width=16,e.height=16,e.style.width="16px",e.style.height="16px";const i=e.getContext("webgl")||e.getContext("experimental-webgl");if(!i)return console.log(`error creating webgl context for ${t}`),!1;if(!(i instanceof WebGLRenderingContext))return console.log("Got unexpected type for WebGL rendering context"),!1;Re(i,"OES_texture_float"),Re(i,"OES_texture_half_float"),Re(i,"WEBGL_color_buffer_float");const r=$e(i,"\nattribute vec4 a_position;\n\nvoid main() {\n  gl_Position = a_position;\n}",i.VERTEX_SHADER),n=$e(i,"\nprecision mediump float;\nuniform vec4 u_color;\nuniform sampler2D u_texture;\n\nvoid main() {\n  gl_FragColor = texture2D(u_texture, vec2(0.5, 0.5)) * u_color;\n}",i.FRAGMENT_SHADER);if(!r||!n)return!1;const s=function(t,e,i,r){const n=t.createProgram();return n?(e.forEach((e=>t.attachShader(n,e))),i&&i.forEach(((e,i)=>{t.bindAttribLocation(n,r?r[i]:i,e)})),t.linkProgram(n),t.getProgramParameter(n,t.LINK_STATUS)?n:(console.log(`error linking program: ${t.getProgramInfoLog(n)}`),t.deleteProgram(n),null)):void console.log("error creating WebGL program")}(i,[r,n]);if(!s)return console.log("error creating WebGL program"),!1;i.useProgram(s);const o=i.getAttribLocation(s,"a_position"),a=i.getUniformLocation(s,"u_color");if(!a)return console.log("error getting 'u_color' uniform location"),!1;const c=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,Le,i.STATIC_DRAW),i.enableVertexAttribArray(o),i.vertexAttribPointer(o,2,i.FLOAT,!1,0,0);const l=i.createTexture(),u=new Uint8Array([255,255,255,255]);i.bindTexture(i.TEXTURE_2D,l),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,1,1,0,i.RGBA,i.UNSIGNED_BYTE,u);const h=i.createTexture();i.bindTexture(i.TEXTURE_2D,h),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,1,1,0,i.RGBA,t,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const d=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,d),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,h,0);if(i.checkFramebufferStatus(i.FRAMEBUFFER)!==i.FRAMEBUFFER_COMPLETE)return console.log(`error creating framebuffer for ${t}`),!1;i.bindTexture(i.TEXTURE_2D,l),i.uniform4fv(a,[0,10,20,1]),i.drawArrays(i.TRIANGLES,0,6),i.bindTexture(i.TEXTURE_2D,h),i.bindFramebuffer(i.FRAMEBUFFER,null),i.clearColor(1,0,0,1),i.clear(i.COLOR_BUFFER_BIT),i.uniform4fv(a,[0,.1,.05,1]),i.drawArrays(i.TRIANGLES,0,6);const m=new Uint8Array(4);if(i.readPixels(0,0,1,1,i.RGBA,i.UNSIGNED_BYTE,m),0!==m[0]||m[1]<248||m[2]<248||m[3]<254)return console.log(`not able to actually render to ${t} texture`),!1;if(t===i.FLOAT){i.bindFramebuffer(i.FRAMEBUFFER,d);const t=new Float32Array(4);i.readPixels(0,0,1,1,i.RGBA,i.FLOAT,t);const e=i.getError();if(e)return console.log(`error reading pixels as float: '${function(t,e){switch(e){case t.NO_ERROR:return"no error";case t.INVALID_ENUM:return"invalid enum";case t.INVALID_VALUE:return"invalid value";case t.INVALID_OPERATION:return"invalid operation";case t.INVALID_FRAMEBUFFER_OPERATION:return"invalid framebuffer operation";case t.OUT_OF_MEMORY:return"out of memory";case t.CONTEXT_LOST_WEBGL:return"context lost"}return"unknown error"}(i,e)}'`),!1}return!0}const ze=new Float32Array(100),Ve=new Uint8Array(100),Ue=[12,7,13,17,11,6,8,18,16,2,14,22,10,1,3,9,19,23,21,15,5,0,4,24,20],je=new e.Matrix4;function Ge(t,e,i,r,n){const s=n.uniforms,o=[];if(s&&(s.objectId&&(s.objectId.value=It?this.id:this.id/255,o.push("objectId")),(s.modelViewMatrixInverse||s.modelViewMatrixInverseTranspose||s.modelViewProjectionMatrix||s.modelViewProjectionMatrixInverse)&&this.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,this.matrixWorld),s.modelViewMatrixInverse&&(s.modelViewMatrixInverse.value.copy(this.modelViewMatrix).invert(),o.push("modelViewMatrixInverse")),s.modelViewMatrixInverseTranspose&&(s.modelViewMatrixInverse?s.modelViewMatrixInverseTranspose.value.copy(s.modelViewMatrixInverse.value).transpose():s.modelViewMatrixInverseTranspose.value.copy(this.modelViewMatrix).invert().transpose(),o.push("modelViewMatrixInverseTranspose")),s.modelViewProjectionMatrix&&(s.modelViewProjectionMatrix.value.multiplyMatrices(i.projectionMatrix,this.modelViewMatrix),o.push("modelViewProjectionMatrix")),s.modelViewProjectionMatrixInverse&&(s.modelViewProjectionMatrix?(je.copy(s.modelViewProjectionMatrix.value),s.modelViewProjectionMatrixInverse.value.copy(je.invert())):(je.multiplyMatrices(i.projectionMatrix,this.modelViewMatrix),s.modelViewProjectionMatrixInverse.value.copy(je.invert())),o.push("modelViewProjectionMatrixInverse")),o.length)){const e=t.properties.get(n);if(e.program){const i=t.getContext(),r=e.program;i.useProgram(r.program);const n=r.getUniforms();o.forEach((function(t){n.setValue(i,t,s[t].value)}))}}}class He{constructor(t){if(this.boundingBox=new e.Box3,this.boundingBoxSize=new e.Vector3,this.boundingBoxLength=0,this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0,points:0}},this.distVector=new e.Vector3,this.signals={ticked:new r.Signal,rendered:new r.Signal},"string"==typeof t){const e=document.getElementById(t);this.container=null===e?document.createElement("div"):e}else t instanceof HTMLElement?this.container=t:this.container=document.createElement("div");if(this.container===document.body)this.width=window.innerWidth||1,this.height=window.innerHeight||1;else{const t=this.container.getBoundingClientRect();this.width=t.width||1,this.height=t.height||1,this.container.style.overflow="hidden"}this.wrapper=document.createElement("div"),this.wrapper.style.position="relative",this.container.appendChild(this.wrapper),this._initParams(),this._initStats(),this._initCamera(),this._initScene(),!1!==this._initRenderer()?(this._initHelper(),this.setBackground(),this.setFog(),this.animate=this.animate.bind(this)):Dt.error("Viewer: could not initialize renderer")}_initParams(){this.parameters={fogColor:new e.Color(0),fogNear:50,fogFar:100,backgroundColor:new e.Color(0),cameraType:"perspective",cameraFov:40,cameraEyeSep:.3,cameraZ:-80,clipNear:0,clipFar:100,clipDist:10,clipMode:"scene",clipScale:"relative",lightColor:new e.Color(14540253),lightIntensity:1.2,ambientColor:new e.Color(14540253),ambientIntensity:.3,sampleLevel:0,outputColorSpace:"srgb-linear"}}_initCamera(){const t=new e.Vector3(0,0,0),{width:i,height:r}=this;this.perspectiveCamera=new e.PerspectiveCamera(this.parameters.cameraFov,i/r),this.perspectiveCamera.position.z=this.parameters.cameraZ,this.perspectiveCamera.lookAt(t),this.orthographicCamera=new e.OrthographicCamera(i/-2,i/2,r/2,r/-2),this.orthographicCamera.position.z=this.parameters.cameraZ,this.orthographicCamera.lookAt(t),this.stereoCamera=new e.StereoCamera,this.stereoCamera.aspect=.5,this.stereoCamera.eyeSep=this.parameters.cameraEyeSep;const n=this.parameters.cameraType;if("orthographic"===n)this.camera=this.orthographicCamera;else{if("perspective"!==n&&"stereo"!==n)throw new Error(`Unknown cameraType '${n}'`);this.camera=this.perspectiveCamera}this.camera.updateProjectionMatrix()}_initStats(){this.stats=new se}_initScene(){this.scene||(this.scene=new e.Scene,this.scene.name="scene"),this.rotationGroup=new e.Group,this.rotationGroup.name="rotationGroup",this.scene.add(this.rotationGroup),this.translationGroup=new e.Group,this.translationGroup.name="translationGroup",this.rotationGroup.add(this.translationGroup),this.modelGroup=new e.Group,this.modelGroup.name="modelGroup",this.translationGroup.add(this.modelGroup),this.pickingGroup=new e.Group,this.pickingGroup.name="pickingGroup",this.translationGroup.add(this.pickingGroup),this.backgroundGroup=new e.Group,this.backgroundGroup.name="backgroundGroup",this.translationGroup.add(this.backgroundGroup),this.helperGroup=new e.Group,this.helperGroup.name="helperGroup",this.translationGroup.add(this.helperGroup),this.scene.fog=new e.Fog(this.parameters.fogColor.getHex()),this.directionalLight=new e.DirectionalLight(this.parameters.lightColor.getHex(),this.parameters.lightIntensity),this.scene.add(this.directionalLight),this.ambientLight=new e.AmbientLight(this.parameters.ambientColor.getHex(),this.parameters.ambientIntensity),this.scene.add(this.ambientLight)}_initRenderer(){const i=window.devicePixelRatio,{width:r,height:n}=this;try{this.renderer=new e.WebGLRenderer({preserveDrawingBuffer:!0,alpha:!0,antialias:!0})}catch(t){return this.wrapper.innerHTML='<div style="display:flex;align-items:center;justify-content:center;height:100%;"><p style="padding:15px;text-align:center;">Your browser/graphics card does not seem to support <a target="_blank" href="https://en.wikipedia.org/wiki/WebGL">WebGL</a>.<br/><br/>Find out how to get it <a target="_blank" href="http://get.webgl.org/">here</a>.</p></div>',!1}this.renderer.setPixelRatio(i),this.renderer.setSize(r,n),this.renderer.autoClear=!1,this.renderer.sortObjects=!0,this.renderer.outputColorSpace=this.parameters.outputColorSpace,this.renderer.useLegacyLights=!0;const s=this.renderer.getContext();this.renderer.capabilities.isWebGL2?(Tt(!0),kt(this.renderer.extensions.get("EXT_color_buffer_float")),this.supportsHalfFloat=!0):(Tt(this.renderer.extensions.get("EXT_frag_depth")),this.renderer.extensions.get("OES_element_index_uint"),kt(this.renderer.extensions.get("OES_texture_float")&&this.renderer.extensions.get("WEBGL_color_buffer_float")||this.renderer.extensions.get("OES_texture_float")&&Ne(s.FLOAT)),this.renderer.extensions.get("OES_texture_float"),this.supportsHalfFloat=this.renderer.extensions.get("OES_texture_half_float")&&Ne(36193)),this.wrapper.appendChild(this.renderer.domElement);const o=r*i,a=n*i;t.Debug&&console.log(JSON.stringify({Browser:St,OES_texture_float:!!this.renderer.extensions.get("OES_texture_float"),OES_texture_half_float:!!this.renderer.extensions.get("OES_texture_half_float"),WEBGL_color_buffer_float:!!this.renderer.extensions.get("WEBGL_color_buffer_float"),"testTextureSupport Float":Ne(s.FLOAT),"testTextureSupport HalfFloat":Ne(36193),"this.supportsHalfFloat":this.supportsHalfFloat,SupportsReadPixelsFloat:It},null,2)),this.pickingTarget=new e.WebGLRenderTarget(o,a,{minFilter:e.NearestFilter,magFilter:e.NearestFilter,stencilBuffer:!1,format:e.RGBAFormat,type:It?e.FloatType:e.UnsignedByteType}),this.pickingTarget.texture.generateMipmaps=!1,this.pickingTarget.texture.colorSpace=this.parameters.outputColorSpace,this.renderer.setRenderTarget(this.pickingTarget),this.renderer.clear(),this.renderer.setRenderTarget(null),this.sampleTarget=new e.WebGLRenderTarget(o,a,{minFilter:e.LinearFilter,magFilter:e.LinearFilter,format:e.RGBAFormat,type:this.supportsHalfFloat?e.HalfFloatType:It?e.FloatType:e.UnsignedByteType}),this.sampleTarget.texture.colorSpace=this.parameters.outputColorSpace,this.holdTarget=new e.WebGLRenderTarget(o,a,{minFilter:e.NearestFilter,magFilter:e.NearestFilter,format:e.RGBAFormat,type:this.supportsHalfFloat?e.HalfFloatType:It?e.FloatType:e.UnsignedByteType}),this.holdTarget.texture.colorSpace=this.parameters.outputColorSpace,this.compositeUniforms={tForeground:new e.Uniform(this.sampleTarget.texture),scale:new e.Uniform(1)},this.compositeMaterial=new e.ShaderMaterial({uniforms:this.compositeUniforms,vertexShader:ce("Quad.vert"),fragmentShader:ce("Quad.frag"),premultipliedAlpha:!0,transparent:!0,blending:e.AdditiveBlending,depthTest:!1,depthWrite:!1}),this.compositeCamera=new e.OrthographicCamera(-1,1,1,-1,0,1),this.compositeScene=new e.Scene,this.compositeScene.name="compositeScene",this.compositeScene.add(new e.Mesh(new e.PlaneGeometry(2,2),this.compositeMaterial))}_initHelper(){const t=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),i=new Float32Array(24),r=new e.BufferGeometry;r.setIndex(new e.BufferAttribute(t,1)),r.setAttribute("position",new e.BufferAttribute(i,3));const n=new e.ShaderMaterial({uniforms:{uColor:{value:new e.Color("skyblue")}},vertexShader:ce("BasicLine.vert"),fragmentShader:ce("BasicLine.frag")});this.boundingBoxMesh=new e.LineSegments(r,n),this.helperGroup.add(this.boundingBoxMesh)}updateHelper(){const t=this.boundingBoxMesh.geometry.attributes.position,e=t.array,{min:i,max:r}=this.boundingBox;e[0]=r.x,e[1]=r.y,e[2]=r.z,e[3]=i.x,e[4]=r.y,e[5]=r.z,e[6]=i.x,e[7]=i.y,e[8]=r.z,e[9]=r.x,e[10]=i.y,e[11]=r.z,e[12]=r.x,e[13]=r.y,e[14]=i.z,e[15]=i.x,e[16]=r.y,e[17]=i.z,e[18]=i.x,e[19]=i.y,e[20]=i.z,e[21]=r.x,e[22]=i.y,e[23]=i.z,t.needsUpdate=!0,this.boundingBox.isEmpty()||this.boundingBoxMesh.geometry.computeBoundingSphere()}get cameraDistance(){return Math.abs(this.camera.position.z)}set cameraDistance(t){this.camera.position.z=-t}add(e,i){i?i.forEach((t=>this.addBuffer(e,t))):this.addBuffer(e),e.group.name="meshGroup",e.wireframeGroup.name="wireframeGroup",e.parameters.background?(this.backgroundGroup.add(e.group),this.backgroundGroup.add(e.wireframeGroup)):(this.modelGroup.add(e.group),this.modelGroup.add(e.wireframeGroup)),e.pickable&&this.pickingGroup.add(e.pickingGroup),t.Debug&&this.updateHelper()}addBuffer(t,i){function r(n){n instanceof e.Group?n.children.forEach(r):(n.userData.buffer=t,n.userData.instance=i,n.onBeforeRender=Ge)}const n=t.getMesh();i&&n.applyMatrix4(i.matrix),r(n),t.group.add(n);const s=t.getWireframeMesh();if(i&&(s.matrix.copy(n.matrix),s.position.copy(n.position),s.quaternion.copy(n.quaternion),s.scale.copy(n.scale)),r(s),t.wireframeGroup.add(s),t.pickable){const e=t.getPickingMesh();i&&(e.matrix.copy(n.matrix),e.position.copy(n.position),e.quaternion.copy(n.quaternion),e.scale.copy(n.scale)),r(e),t.pickingGroup.add(e)}i?this._updateBoundingBox(t.geometry,t.matrix,i.matrix):this._updateBoundingBox(t.geometry,t.matrix)}remove(e){this.translationGroup.children.forEach((function(t){t.remove(e.group),t.remove(e.wireframeGroup)})),e.pickable&&this.pickingGroup.remove(e.pickingGroup),this.updateBoundingBox(),t.Debug&&this.updateHelper()}_updateBoundingBox(t,e,i){const r=this.boundingBox;function n(t,e,i){null==t.boundingBox&&t.computeBoundingBox();const n=t.boundingBox.clone();e&&n.applyMatrix4(e),i&&n.applyMatrix4(i),n.min.equals(n.max)&&n.expandByScalar(5),r.union(n)}function s(t){if(void 0!==t.geometry){let e,i;t.userData.buffer&&(e=t.userData.buffer.matrix),t.userData.instance&&(i=t.userData.instance.matrix),n(t.geometry,e,i)}}t?n(t,e,i):(r.makeEmpty(),this.modelGroup.traverse(s),this.backgroundGroup.traverse(s)),r.getSize(this.boundingBoxSize),this.boundingBoxLength=this.boundingBoxSize.length()}updateBoundingBox(){this._updateBoundingBox(),t.Debug&&this.updateHelper()}getPickingPixels(){const{width:t,height:e}=this,i=t*e*4,r=It?new Float32Array(i):new Uint8Array(i);return this.render(!0),this.renderer.readRenderTargetPixels(this.pickingTarget,0,0,t,e,r),r}getImage(t){return new Promise((e=>{if(t){const{width:t,height:i}=this,r=t*i*4;let n=this.getPickingPixels();if(It){const t=new Uint8Array(r);for(let e=0;e<r;++e)t[e]=Math.round(255*n[e]);n=t}const s=document.createElement("canvas");s.width=t,s.height=i;const o=s.getContext("2d"),a=o.getImageData(0,0,t,i);a.data.set(n),o.putImageData(a,0,0),s.toBlob(e,"image/png")}else this.renderer.domElement.toBlob(e,"image/png")}))}makeImage(t={}){return ke(this,t)}setLight(t,e,i,r){const n=this.parameters;void 0!==t&&n.lightColor.set(t),void 0!==e&&(n.lightIntensity=e),void 0!==i&&n.ambientColor.set(i),void 0!==r&&(n.ambientIntensity=r),this.requestRender()}setFog(t,e,i){const r=this.parameters;void 0!==t&&r.fogColor.set(t),void 0!==e&&(r.fogNear=e),void 0!==i&&(r.fogFar=i),this.requestRender()}setBackground(t){const e=this.parameters;t&&e.backgroundColor.set(t),this.setFog(e.backgroundColor),this.renderer.setClearColor(e.backgroundColor,0),this.renderer.domElement.style.backgroundColor=e.backgroundColor.getStyle(),this.requestRender()}setSampling(t){void 0!==t&&(this.parameters.sampleLevel=t,this.sampleLevel=t),this.requestRender()}setOutputEncoding(t){this.parameters.outputColorSpace=t,this.renderer.outputColorSpace=t,this.pickingTarget.texture.colorSpace=t,this.sampleTarget.texture.colorSpace=t,this.holdTarget.texture.colorSpace=t}setColorWorkflow(t){if("srgb-linear"!=t&&"srgb"!=t)throw new Error(`setColorWorkflow: invalid color workflow ${t}`);L="srgb-linear"==t?"linear":"sRGB",this.setOutputEncoding("srgb-linear"==t?"srgb":"srgb-linear"),this.requestRender()}setCamera(t,e,i){const r=this.parameters;if(t&&(r.cameraType=t),e&&(r.cameraFov=e),i&&(r.cameraEyeSep=i),"orthographic"===r.cameraType)this.camera!==this.orthographicCamera&&(this.camera=this.orthographicCamera,this.camera.position.copy(this.perspectiveCamera.position),this.camera.up.copy(this.perspectiveCamera.up),this.updateZoom());else{if("perspective"!==r.cameraType&&"stereo"!==r.cameraType)throw new Error(`Unknown cameraType '${r.cameraType}'`);this.camera!==this.perspectiveCamera&&(this.camera=this.perspectiveCamera,this.camera.position.copy(this.orthographicCamera.position),this.camera.up.copy(this.orthographicCamera.up))}this.perspectiveCamera.fov=r.cameraFov,this.stereoCamera.eyeSep=r.cameraEyeSep,this.camera.updateProjectionMatrix(),this.requestRender()}setClip(t,e,i,r,n){const s=this.parameters;void 0!==t&&(s.clipNear=t),void 0!==e&&(s.clipFar=e),void 0!==i&&(s.clipDist=i),void 0!==r&&(s.clipMode=r),void 0!==n&&(s.clipScale=n),this.requestRender()}setSize(t,e){this.width=t||1,this.height=e||1,this.perspectiveCamera.aspect=this.width/this.height,this.orthographicCamera.left=-this.width/2,this.orthographicCamera.right=this.width/2,this.orthographicCamera.top=this.height/2,this.orthographicCamera.bottom=-this.height/2,this.camera.updateProjectionMatrix();const i=window.devicePixelRatio;this.renderer.setPixelRatio(i),this.renderer.setSize(t,e);const r=this.width*i,n=this.height*i;this.pickingTarget.setSize(r,n),this.sampleTarget.setSize(r,n),this.holdTarget.setSize(r,n),this.requestRender()}handleResize(){if(this.container===document.body)this.setSize(window.innerWidth,window.innerHeight);else{const t=this.container.getBoundingClientRect();this.setSize(t.width,t.height)}}updateInfo(t){const{memory:e,render:i}=this.info;if(t)e.programs=0,e.geometries=0,e.textures=0,i.calls=0,i.vertices=0,i.points=0;else{const t=this.renderer.info,r=t.memory,n=t.render;e.geometries=r.geometries,e.textures=r.textures,i.calls+=n.calls,i.faces+=n.triangles,i.points+=n.points}}animate(){this.signals.ticked.dispatch(this.stats);if(window.performance.now()-this.stats.startTime>500&&!this.isStill&&this.sampleLevel<3&&-1!==this.sampleLevel){const e=this.sampleLevel;this.sampleLevel=3,this.renderPending=!0,this.render(),this.isStill=!0,this.sampleLevel=e,t.Debug&&Dt.log("rendered still frame")}this.frameRequest=window.requestAnimationFrame(this.animate)}pick(t,e){if("stereo"===this.parameters.cameraType)return{pid:0,instance:void 0,picker:void 0};t*=window.devicePixelRatio,e*=window.devicePixelRatio,t=Math.max(t-2,0),e=Math.max(e-2,0);let i,r,n=0;const s=It?ze:Ve;this.render(!0),this.renderer.readRenderTargetPixels(this.pickingTarget,t,e,5,5,s);for(let t=0;t<Ue.length;t++){const e=4*Ue[t],o=Math.round(s[e+3]),a=this.pickingGroup.getObjectById(o);a&&(i=a.userData.instance,r=a.userData.buffer.picking,n=It?Math.round(255*s[e])<<16&16711680|Math.round(255*s[e+1])<<8&65280|255&Math.round(255*s[e+2]):s[e]<<16|s[e+1]<<8|s[e+2])}return{pid:n,instance:i,picker:r}}requestRender(){this.renderPending||(window.performance.now()-this.stats.startTime>22&&(this.stats.begin(),this.isStill=!1),this.renderPending=!0,window.requestAnimationFrame((()=>{this.render(),this.stats.update()})))}updateZoom(){const t=T(this.perspectiveCamera.fov),e=2*Math.tan(t/2)*this.cameraDistance;this.orthographicCamera.zoom=this.height/e}absoluteToRelative(t){return 50*(1-t/this.bRadius)}relativeToAbsolute(t){return this.bRadius*(1-t/50)}__updateClipping(){const t=this.parameters;this.bRadius=Math.max(10,.5*this.boundingBoxLength),isFinite(this.bRadius)||(this.bRadius=50),this.camera.getWorldPosition(this.distVector),this.cDist=this.distVector.length(),this.cDist||(this.cameraDistance=Math.abs(t.cameraZ),this.cDist=Math.abs(t.cameraZ));const e=this.scene.fog;if(e.color.set(t.fogColor),"camera"===t.clipMode)this.camera.near=t.clipNear,this.camera.far=t.clipFar,e.near=t.fogNear,e.far=t.fogFar;else if("absolute"===t.clipScale)this.camera.near=this.cDist-t.clipNear,this.camera.far=this.cDist+t.clipFar,e.near=this.cDist-t.fogNear,e.far=this.cDist+t.fogFar;else{const i=(50-t.clipNear)/50,r=-(50-t.clipFar)/50;this.camera.near=this.cDist-this.bRadius*i,this.camera.far=this.cDist+this.bRadius*r;const n=(50-t.fogNear)/50,s=-(50-t.fogFar)/50;e.near=this.cDist-this.bRadius*n,e.far=this.cDist+this.bRadius*s}"camera"!==t.clipMode&&("PerspectiveCamera"===this.camera.type?(this.camera.near=Math.max(.1,t.clipDist,this.camera.near),this.camera.far=Math.max(1,this.camera.far),e.near=Math.max(.1,e.near),e.far=Math.max(1,e.far)):"OrthographicCamera"===this.camera.type&&t.clipDist>0&&(this.camera.near=Math.max(t.clipDist,this.camera.near)))}__updateCamera(){const t=this.camera;t.updateMatrix(),t.updateMatrixWorld(!0),t.updateProjectionMatrix(),function(t,i,r,n,s){let o=new e.Vector2;r.getSize(o);const a=o.height,c=r.getPixelRatio(),l="OrthographicCamera"===i.type;Be.set(o.width,o.height),Fe.copy(i.projectionMatrix).invert(),Ee.copy(i.projectionMatrix).transpose(),t.traverse((function(t){const e=t.material;if(!e)return;const i=e.uniforms;if(i){if(e.clipNear){const t=(50-e.clipNear)/50,r=n-s*t;i.clipNear.value=r}i.canvasHeight&&(i.canvasHeight.value=a),i.resolution&&i.resolution.value.copy(Be),i.pixelRatio&&(i.pixelRatio.value=c),i.projectionMatrixInverse&&i.projectionMatrixInverse.value.copy(Fe),i.projectionMatrixTranspose&&i.projectionMatrixTranspose.value.copy(Ee),i.ortho&&(i.ortho.value=l)}}))}(this.scene,t,this.renderer,this.cDist,this.bRadius),function(t,i){t.traverseVisible((function(t){if(!(t instanceof e.Points&&t.userData.buffer.parameters.sortParticles))return;const r=t.geometry.attributes,n=r.position.count;if(0===n)return;let s,o,a,c,l,u,h,d;Te.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),De.multiplyMatrices(i.projectionMatrix,Te),t.userData.sortData?(s=t.userData.sortData,a=s.__zArray,o=s.__sortArray,c=s.__cmpFn):(a=new Float32Array(n),o=new Uint32Array(n),c=function(t,e){const i=a[t],r=a[e];return i>r?1:i<r?-1:0},s={__zArray:a,__sortArray:o,__cmpFn:c},t.userData.sortData=s);for(let t=0;t<n;++t)Me.fromArray(r.position.array,3*t),Me.applyMatrix4(De),a[t]=-Me.z,o[t]=t;!function(t,e,i=0,r){e=e||function(t,e){return t>e?1:t<e?-1:0};const n=[];let s,o,a,c=-1,l=i,u=r=(r||t.length)-1;function h(e,i){const r=t[e];t[e]=t[i],t[i]=r}for(;;)if(u-l<=25){for(let i=l+1;i<=u;++i){for(s=t[i],o=i-1;o>=l&&e(t[o],s)>0;)t[o+1]=t[o],--o;t[o+1]=s}if(-1===c)break;u=n[c--],l=n[c--]}else{for(o=l+1,a=u,h(l+u>>1,o),e(t[l],t[u])>0&&h(l,u),e(t[o],t[u])>0&&h(o,u),e(t[l],t[o])>0&&h(l,o),s=t[o];;){do{o++}while(e(t[o],s)<0);do{a--}while(e(t[a],s)>0);if(a<o)break;h(o,a)}t[l+1]=t[a],t[a]=s,u-o+1>=a-l?(n[++c]=o,n[++c]=u,u=a-1):(n[++c]=l,n[++c]=a-1,l=o)}}(o,c);for(let t in r){const e=r[t],i=e.array,a=e.itemSize;s[t]||(s[t]=new Float32Array(a*n)),d=s[t],s[t]=i;for(let t=0;t<n;++t){l=o[t];for(let e=0;e<a;++e)u=l*a+e,h=t*a+e,d[h]=i[u]}r[t].array=d,r[t].needsUpdate=!0}}))}(this.scene,t)}__setVisibility(t,e,i,r){this.modelGroup.visible=t,this.pickingGroup.visible=e,this.backgroundGroup.visible=i,this.helperGroup.visible=r}__updateLights(){this.directionalLight.color.set(this.parameters.lightColor),this.directionalLight.intensity=this.parameters.lightIntensity,this.distVector.copy(this.camera.position).setLength(100*this.boundingBoxLength),this.directionalLight.position.copy(this.camera.position).add(this.distVector),this.ambientLight.color.set(this.parameters.ambientColor),this.ambientLight.intensity=this.parameters.ambientIntensity}__renderPickingGroup(t){this.renderer.setRenderTarget(this.pickingTarget||null),this.renderer.clear(),this.__setVisibility(!1,!0,!1,!1),this.renderer.render(this.scene,t),this.renderer.setRenderTarget(null),this.updateInfo()}__renderModelGroup(e,i){this.renderer.setRenderTarget(i||null),this.renderer.clear(),this.__setVisibility(!1,!1,!0,!1),this.renderer.render(this.scene,e),this.renderer.clear(!1,!0,!0),this.updateInfo(),this.__setVisibility(!0,!1,!1,t.Debug),this.renderer.render(this.scene,e),this.renderer.setRenderTarget(null),this.updateInfo()}__renderSuperSample(t,e){const i=le[Math.max(0,Math.min(this.sampleLevel,5))],r=1/i.length;this.compositeUniforms.tForeground.value=this.sampleTarget.texture;let n=this.sampleTarget.width;const s=this.sampleTarget.height;"stereo"===this.parameters.cameraType&&(n/=2);for(let e=0;e<i.length;++e){const o=i[e];t.setViewOffset(n,s,o[0],o[1],n,s),t.updateProjectionMatrix(),Oe(this.scene,t);let a=r;a+=.03125*((e+.5)/i.length-.5),this.compositeUniforms.scale.value=a,this.__renderModelGroup(t,this.sampleTarget),this.renderer.setRenderTarget(this.holdTarget),0===e&&this.renderer.clear(),this.renderer.render(this.compositeScene,this.compositeCamera)}this.compositeUniforms.scale.value=1,this.compositeUniforms.tForeground.value=this.holdTarget.texture,t.clearViewOffset(),this.renderer.setRenderTarget(e||null),this.renderer.clear(),this.renderer.render(this.compositeScene,this.compositeCamera)}__renderStereo(t=!1,i){const r=this.stereoCamera;r.update(this.perspectiveCamera);const n=this.renderer;let s=new e.Vector2;n.getSize(s),n.setScissorTest(!0),n.setScissor(0,0,s.width/2,s.height),n.setViewport(0,0,s.width/2,s.height),Oe(this.scene,r.cameraL),this.__render(t,r.cameraL),n.setScissor(s.width/2,0,s.width/2,s.height),n.setViewport(s.width/2,0,s.width/2,s.height),Oe(this.scene,r.cameraR),this.__render(t,r.cameraR),n.setScissorTest(!1),n.setViewport(0,0,s.width,s.height)}__render(t=!1,e,i){t?this.lastRenderedPicking||this.__renderPickingGroup(e):this.sampleLevel>0&&"stereo"!==this.parameters.cameraType?this.__renderSuperSample(e,i):this.__renderModelGroup(e,i)}render(t=!1,e){if(this.rendering)Dt.warn("'tried to call 'render' from within 'render'");else{this.rendering=!0;try{this.__updateClipping(),this.__updateCamera(),this.__updateLights(),this.updateInfo(!0),"stereo"===this.parameters.cameraType?this.__renderStereo(t,e):this.__render(t,this.camera,e),this.lastRenderedPicking=t}finally{this.rendering=!1,this.renderPending=!1}this.signals.rendered.dispatch()}}clear(){Dt.log("scene cleared"),this.scene.remove(this.rotationGroup),this._initScene(),this.renderer.clear()}dispose(){this.renderer.dispose(),window.cancelAnimationFrame(this.frameRequest)}}function qe(t){const e=t.touches[0].pageX-t.touches[1].pageX,i=t.touches[0].pageY-t.touches[1].pageY;return Math.sqrt(e*e+i*i)}class We{constructor(t,i={}){this.domElement=t,this.signals={moved:new r.Signal,scrolled:new r.Signal,dragged:new r.Signal,dropped:new r.Signal,clicked:new r.Signal,hovered:new r.Signal,doubleClicked:new r.Signal},this.position=new e.Vector2,this.prevPosition=new e.Vector2,this.down=new e.Vector2,this.canvasPosition=new e.Vector2,this.prevClickCP=new e.Vector2,this.moving=!1,this.hovering=!0,this.scrolled=!1,this.lastMoved=1/0,this.which=0,this.buttons=0,this.pressed=!1,this.altKey=!1,this.ctrlKey=!1,this.metaKey=!1,this.shiftKey=!1,this.domElement.style.touchAction="none",this.hoverTimeout=l(i.hoverTimeout,50),this.handleScroll=l(i.handleScroll,!0),this.doubleClickSpeed=l(i.doubleClickSpeed,500),this._listen=this._listen.bind(this),this._onMousewheel=this._onMousewheel.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMousedown=this._onMousedown.bind(this),this._onMouseup=this._onMouseup.bind(this),this._onContextmenu=this._onContextmenu.bind(this),this._onTouchstart=this._onTouchstart.bind(this),this._onTouchend=this._onTouchend.bind(this),this._onTouchmove=this._onTouchmove.bind(this),this._listen();const n={passive:!1};document.addEventListener("mousewheel",this._onMousewheel,n),document.addEventListener("wheel",this._onMousewheel,n),document.addEventListener("MozMousePixelScroll",this._onMousewheel,n),document.addEventListener("mousemove",this._onMousemove,n),document.addEventListener("mousedown",this._onMousedown,n),document.addEventListener("mouseup",this._onMouseup,n),document.addEventListener("contextmenu",this._onContextmenu,n),document.addEventListener("touchstart",this._onTouchstart,n),document.addEventListener("touchend",this._onTouchend,n),document.addEventListener("touchmove",this._onTouchmove,n)}get key(){let t=0;return this.altKey&&(t+=1),this.ctrlKey&&(t+=2),this.metaKey&&(t+=4),this.shiftKey&&(t+=8),t}setParameters(t={}){this.hoverTimeout=l(t.hoverTimeout,this.hoverTimeout)}_listen(){const t=window.performance.now(),e=this.canvasPosition;this.doubleClickPending&&t-this.lastClicked>this.doubleClickSpeed&&(this.doubleClickPending=!1),t-this.lastMoved>this.hoverTimeout&&(this.moving=!1),(this.scrolled||!this.moving&&!this.hovering)&&(this.scrolled=!1,-1!==this.hoverTimeout&&this.overElement&&(this.hovering=!0,this.signals.hovered.dispatch(e.x,e.y))),this.frameRequest=window.requestAnimationFrame(this._listen)}_onMousewheel(t){if(t.target!==this.domElement||!this.handleScroll)return;t.preventDefault(),this._setKeys(t);let e=0;"deltaY"in t&&"deltaMode"in t&&void 0!==t.deltaY&&void 0!==t.deltaMode?e=t.deltaMode===WheelEvent.DOM_DELTA_PIXEL?.025*-t.deltaY:t.deltaMode===WheelEvent.DOM_DELTA_LINE?-t.deltaY*(2.5/3):2.5*-t.deltaY:"deltaY"in t&&!("detail"in t)?e=.025*-t.deltaY:void 0!==t.wheelDelta?e=.025*-t.wheelDelta:void 0!==t.wheelDeltaY?e=.025*-t.wheelDeltaY:void 0!==t.detail&&(e=-t.detail/3),this.signals.scrolled.dispatch(e),setTimeout((()=>{this.scrolled=!0}),this.hoverTimeout)}_onMousemove(t){t.target===this.domElement?(t.preventDefault(),this.overElement=!0):this.overElement=!1,this._setKeys(t),this.moving=!0,this.hovering=!1,this.lastMoved=window.performance.now(),this.prevPosition.copy(this.position),this.position.set(t.clientX,t.clientY),this._setCanvasPosition(t);const e=this.prevPosition.x-this.position.x,i=this.prevPosition.y-this.position.y;this.signals.moved.dispatch(e,i),this.pressed&&this.signals.dragged.dispatch(e,i)}_onMousedown(t){t.target===this.domElement&&(t.preventDefault(),this._setKeys(t),this.moving=!1,this.hovering=!1,this.down.set(t.clientX,t.clientY),this.position.set(t.clientX,t.clientY),this.which=t.which,this.buttons=function(t){if("object"==typeof t){if("buttons"in t)return t.buttons;if("which"in t){const e=t.which;if(2===e)return 4;if(3===e)return 2;if(e>0)return 1<<e-1}else if("button"in t){const e=t.button;if(1===e)return 4;if(2===e)return 2;if(e>=0)return 1<<e}}return 0}(t),this.pressed=!0,this._setCanvasPosition(t))}_onMouseup(t){t.target===this.domElement&&t.preventDefault(),this._setKeys(t);const e=this.canvasPosition;this._distance()<4&&(this.lastClicked=window.performance.now(),this.doubleClickPending&&this.prevClickCP.distanceTo(e)<4&&(this.signals.doubleClicked.dispatch(e.x,e.y),this.doubleClickPending=!1),this.signals.clicked.dispatch(e.x,e.y),this.doubleClickPending=!0,this.prevClickCP.copy(e)),this.which=void 0,this.buttons=void 0,this.pressed=void 0}_onContextmenu(t){t.target===this.domElement&&t.preventDefault()}_onTouchstart(t){if(t.target===this.domElement)switch(t.preventDefault(),this.pressed=!0,t.touches.length){case 1:this.moving=!1,this.hovering=!1,this.down.set(t.touches[0].pageX,t.touches[0].pageY),this.position.set(t.touches[0].pageX,t.touches[0].pageY),this._setCanvasPosition(t.touches[0]);break;case 2:this.down.set((t.touches[0].pageX+t.touches[1].pageX)/2,(t.touches[0].pageY+t.touches[1].pageY)/2),this.position.set((t.touches[0].pageX+t.touches[1].pageX)/2,(t.touches[0].pageY+t.touches[1].pageY)/2),this.lastTouchDistance=qe(t)}}_onTouchend(t){t.target===this.domElement&&t.preventDefault(),this.which=void 0,this.buttons=void 0,this.pressed=void 0}_onTouchmove(t){switch(t.target===this.domElement?(t.preventDefault(),this.overElement=!0):this.overElement=!1,t.touches.length){case 1:{this._setKeys(t),this.which=1,this.buttons=1,this.moving=!0,this.hovering=!1,this.lastMoved=window.performance.now(),this.prevPosition.copy(this.position),this.position.set(t.touches[0].pageX,t.touches[0].pageY),this._setCanvasPosition(t.touches[0]);const e=this.prevPosition.x-this.position.x,i=this.prevPosition.y-this.position.y;this.signals.moved.dispatch(e,i),this.pressed&&this.signals.dragged.dispatch(e,i);break}case 2:{const e=qe(t),i=e-this.lastTouchDistance;if(this.lastTouchDistance=e,this.prevPosition.copy(this.position),this.position.set((t.touches[0].pageX+t.touches[1].pageX)/2,(t.touches[0].pageY+t.touches[1].pageY)/2),Math.abs(i)>2&&this.handleScroll&&this.position.distanceTo(this.prevPosition)<2)this.which=0,this.buttons=0,this.signals.scrolled.dispatch(i/2);else{this.which=3,this.buttons=2;const t=this.prevPosition.x-this.position.x,e=this.prevPosition.y-this.position.y;this.signals.moved.dispatch(t,e),this.pressed&&this.signals.dragged.dispatch(t,e)}}}}_distance(){return this.position.distanceTo(this.down)}_setCanvasPosition(t){const e=this.domElement.getBoundingClientRect();let i,r;"clientX"in t&&"clientY"in t?(i=t.clientX-e.left,r=t.clientY-e.top):(i=t.offsetX,r=t.offsetY),this.canvasPosition.set(i,e.height-r)}_setKeys(t){this.altKey=t.altKey,this.ctrlKey=t.ctrlKey,this.metaKey=t.metaKey,this.shiftKey=t.shiftKey}dispose(){document.removeEventListener("mousewheel",this._onMousewheel),document.removeEventListener("wheel",this._onMousewheel),document.removeEventListener("MozMousePixelScroll",this._onMousewheel),document.removeEventListener("mousemove",this._onMousemove),document.removeEventListener("mousedown",this._onMousedown),document.removeEventListener("mouseup",this._onMouseup),document.removeEventListener("contextmenu",this._onContextmenu),document.removeEventListener("touchstart",this._onTouchstart),document.removeEventListener("touchend",this._onTouchend),document.removeEventListener("touchmove",this._onTouchmove),window.cancelAnimationFrame(this.frameRequest)}}const Xe=new e.Matrix4,Ye=new e.Matrix4,Ke=new e.Matrix4,Ze=new e.Matrix4,Qe=new e.Matrix4,Je=new e.Vector3,ti=new e.Quaternion,ei=new e.Quaternion,ii=new e.Matrix4,ri=new e.Vector3,ni=new e.Vector3;class si{constructor(t,e={}){this.stage=t,this.rotateSpeed=l(e.rotateSpeed,2),this.zoomSpeed=l(e.zoomSpeed,1.2),this.panSpeed=l(e.panSpeed,1),this.viewer=t.viewer,this.mouse=t.mouseObserver,this.controls=t.viewerControls}get component(){return this.stage.transformComponent}get atom(){return this.stage.transformAtom}_setPanVector(t,e,i=0){const r=this.controls.getCanvasScaleFactor(i);ri.set(t,e,0),ri.multiplyScalar(this.panSpeed*r)}_getRotateXY(t,e){return[this.rotateSpeed*-t*.01,this.rotateSpeed*e*.01]}_getCameraRotation(t){return t.extractRotation(this.viewer.camera.matrixWorld),t.multiply(Ye.makeRotationY(Math.PI)),t}_transformPanVector(){this.component&&(ii.extractRotation(this.component.transform),ii.premultiply(this.viewer.rotationGroup.matrix),ii.invert(),ii.multiply(this._getCameraRotation(Ze)),ri.applyMatrix4(ii))}zoom(t){this.controls.zoom(this.zoomSpeed*t*.02)}pan(t,e){this._setPanVector(t,e),ii.copy(this.viewer.rotationGroup.matrix).invert(),ii.multiply(this._getCameraRotation(Ze)),ri.applyMatrix4(ii),this.controls.translate(ri)}panComponent(t,e){this.component&&(this._setPanVector(t,e),this._transformPanVector(),this.component.position.add(ri),this.component.updateMatrix())}panAtom(t,e){this.atom&&this.component&&(this.atom.positionToVector3(ni),ni.add(this.viewer.translationGroup.position),ni.applyMatrix4(this.viewer.rotationGroup.matrix),this._setPanVector(t,e,ni.z),this._transformPanVector(),this.atom.positionAdd(ri),this.component.updateRepresentations({position:!0}))}rotate(t,e){const[i,r]=this._getRotateXY(t,e);this._getCameraRotation(Ze),Je.set(1,0,0),Je.applyMatrix4(Ze),ti.setFromAxisAngle(Je,r),Je.set(0,1,0),Je.applyMatrix4(Ze),ei.setFromAxisAngle(Je,i),ti.multiply(ei),Ze.makeRotationFromQuaternion(ti),this.controls.applyMatrix(Ze)}zRotate(t,e){const i=this.rotateSpeed*((-t+e)/-2)*.01;Ke.makeRotationZ(i),this.controls.applyMatrix(Ke)}rotateComponent(t,e){if(!this.component)return;const[i,r]=this._getRotateXY(t,e);this._getCameraRotation(Qe),Ze.extractRotation(this.component.transform),Ze.premultiply(this.viewer.rotationGroup.matrix),Ze.invert(),Ze.premultiply(Qe),Je.set(1,0,0),Je.applyMatrix4(Ze),Xe.makeRotationAxis(Je,r),Je.set(0,1,0),Je.applyMatrix4(Ze),Ye.makeRotationAxis(Je,i),Xe.multiply(Ye),ti.setFromRotationMatrix(Xe),this.component.quaternion.premultiply(ti),this.component.quaternion.normalize(),this.component.updateMatrix()}}const oi=new e.Vector3;class ai{constructor(t,e){this.stage=e,this.pid=t.pid,this.picker=t.picker,this.instance=t.instance,this.stage=e,this.controls=e.viewerControls,this.mouse=e.mouseObserver}get type(){return this.picker.type}get altKey(){return this.mouse.altKey}get ctrlKey(){return this.mouse.ctrlKey}get metaKey(){return this.mouse.metaKey}get shiftKey(){return this.mouse.shiftKey}get canvasPosition(){return this.mouse.canvasPosition}get component(){return this.stage.getComponentsByObject(this.picker.data).list[0]}get object(){return this.picker.getObject(this.pid)}get position(){return this.picker.getPosition(this.pid,this.instance,this.component)}get closestBondAtom(){if("bond"!==this.type||!this.bond)return;const t=this.bond,e=this.controls,i=this.canvasPosition,r=t.atom1.positionToVector3(),n=t.atom2.positionToVector3();r.applyMatrix4(this.component.matrix),n.applyMatrix4(this.component.matrix);const s=e.getPositionOnCanvas(r),o=e.getPositionOnCanvas(n);return c=s,l=o,(a=i).distanceTo(c)<a.distanceTo(l)?t.atom1:t.atom2;var a,c,l}get closeAtom(){const t=this.canvasPosition,e=this.closestBondAtom;if(!e)return;const i=e.positionToVector3().applyMatrix4(this.component.matrix),r=this.controls.getPositionOnCanvas(i);e.positionToVector3(oi),this.instance&&oi.applyMatrix4(this.instance.matrix),oi.applyMatrix4(this.component.matrix);const n=this.controls.viewer;oi.add(n.translationGroup.position),oi.applyMatrix4(n.rotationGroup.matrix);const s=this.controls.getCanvasScaleFactor(oi.z),o=this.component.getMaxRepresentationRadius(e.index);return t.distanceTo(r)<=o/s?e:void 0}get arrow(){return this._objectIfType("arrow")}get atom(){return this._objectIfType("atom")}get axes(){return this._objectIfType("axes")}get bond(){return this._objectIfType("bond")}get box(){return this._objectIfType("box")}get cone(){return this._objectIfType("cone")}get clash(){return this._objectIfType("clash")}get contact(){return this._objectIfType("contact")}get cylinder(){return this._objectIfType("cylinder")}get distance(){return this._objectIfType("distance")}get ellipsoid(){return this._objectIfType("ellipsoid")}get icosahedron(){return this._objectIfType("icosahedron")}get octahedron(){return this._objectIfType("octahedron")}get point(){return this._objectIfType("point")}get mesh(){return this._objectIfType("mesh")}get slice(){return this._objectIfType("slice")}get sphere(){return this._objectIfType("sphere")}get tetrahedron(){return this._objectIfType("tetrahedron")}get torus(){return this._objectIfType("torus")}get surface(){return this._objectIfType("surface")}get unitcell(){return this._objectIfType("unitcell")}get unknown(){return this._objectIfType("unknown")}get volume(){return this._objectIfType("volume")}get wideline(){return this._objectIfType("wideline")}_objectIfType(t){return this.type===t?this.object:void 0}getLabel(){const t=this.atom||this.closeAtom;let e="nothing";return this.arrow?e=this.arrow.name:t?e=`atom: ${t.qualifiedName()} (${t.structure.name})`:this.axes?e="axes":this.bond?e=`bond: ${this.bond.atom1.qualifiedName()} - ${this.bond.atom2.qualifiedName()} (${this.bond.structure.name})`:this.box?e=this.box.name:this.cone?e=this.cone.name:this.clash?e=`clash: ${this.clash.clash.sele1} - ${this.clash.clash.sele2}`:this.contact?e=`${this.contact.type}: ${this.contact.atom1.qualifiedName()} - ${this.contact.atom2.qualifiedName()} (${this.contact.atom1.structure.name})`:this.cylinder?e=this.cylinder.name:this.distance?e=`distance: ${this.distance.atom1.qualifiedName()} - ${this.distance.atom2.qualifiedName()} (${this.distance.structure.name})`:this.ellipsoid?e=this.ellipsoid.name:this.icosahedron?e=this.icosahedron.name:this.octahedron?e=this.octahedron.name:this.point?e=this.point.name:this.mesh?e=`mesh: ${this.mesh.name||this.mesh.serial} (${this.mesh.shape.name})`:this.slice?e=`slice: ${this.slice.value.toPrecision(3)} (${this.slice.volume.name})`:this.sphere?e=this.sphere.name:this.surface?e=`surface: ${this.surface.surface.name}`:this.tetrahedron?e=this.tetrahedron.name:this.torus?e=this.torus.name:this.unitcell?e=`unitcell: ${this.unitcell.unitcell.spacegroup} (${this.unitcell.structure.name})`:this.unknown?e="unknown":this.volume?e=`volume: ${this.volume.value.toPrecision(3)} (${this.volume.volume.name})`:this.wideline&&(e=this.wideline.name),e}}class ci{constructor(t){this.stage=t,this.viewer=t.viewer}pick(t,e){const i=this.viewer.pick(t,e);if(i.picker&&"ignore"!==i.picker.type&&void 0!==i.pid){const t=i.picker.array;if(!(t&&i.pid>=t.length))return new ai(i,this.stage);console.error("pid >= picker.array.length")}}}const li=new e.Quaternion,ui=new e.Vector3,hi=new e.Vector3,di=new e.Vector3,mi=new e.Vector3,fi=new e.Matrix4,pi=new e.Vector3,gi=new e.Matrix4;class yi{constructor(t){this.stage=t,this.signals={changed:new a.Signal},this.viewer=t.viewer}get position(){return this.viewer.translationGroup.position}get rotation(){return this.viewer.rotationGroup.quaternion}changed(t=!1){this.viewer.requestRender(),t||this.signals.changed.dispatch()}getPositionOnCanvas(t,i){const r=A(i,e.Vector2);const n=this.viewer;return di.copy(t).add(n.translationGroup.position).applyMatrix4(n.rotationGroup.matrix).project(n.camera),r.set((di.x+1)*n.width/2,(di.y+1)*n.height/2)}getCanvasScaleFactor(t=0){const i=this.viewer.camera;if(i instanceof e.OrthographicCamera)return 1/i.zoom;{t=Math.abs(t),t+=this.getCameraDistance();const e=T(i.fov);return 2*t*Math.tan(e/2)/this.viewer.height}}getOrientation(t){const e=C(t);e.copy(this.viewer.rotationGroup.matrix);const i=this.getCameraDistance();return e.scale(mi.set(i,i,i)),e.setPosition(this.viewer.translationGroup.position),e}orient(t,e){C(t).decompose(ui,li,hi);const i=this.viewer;i.rotationGroup.setRotationFromQuaternion(li),i.translationGroup.position.copy(ui),i.cameraDistance=hi.z,i.updateZoom(),this.changed(e)}translate(t){this.viewer.translationGroup.position.add(S(t)),this.changed()}center(t){this.viewer.translationGroup.position.copy(S(t)).negate(),this.changed()}zoom(t){this.distance(this.getCameraDistance()*(1-t))}getCameraDistance(){return this.viewer.cameraDistance}distance(t){this.viewer.cameraDistance=Math.max(Math.abs(t),.2),this.viewer.updateZoom(),this.changed()}spin(t,e){fi.copy(this.viewer.rotationGroup.matrix).invert(),pi.copy(S(t)).applyMatrix4(fi),this.viewer.rotationGroup.rotateOnAxis(pi,e),this.changed()}rotate(t){this.viewer.rotationGroup.setRotationFromQuaternion(P(t)),this.changed()}align(t){gi.copy(C(t)).invert(),this.viewer.rotationGroup.setRotationFromMatrix(gi),this.changed()}applyMatrix(t){this.viewer.rotationGroup.applyMatrix4(C(t)),this.changed()}}class bi{constructor(t,e,...i){this.pausedTime=-1,this.elapsedDuration=0,this.pausedDuration=0,this.ignoreGlobalToggle=!1,this._paused=!1,this._resolveList=[],this.duration=l(t,1e3),this.controls=e,this.startTime=window.performance.now(),this._init(...i)}get done(){return 1===this.alpha}get paused(){return this._paused}tick(t){if(!this._paused)return this.elapsedDuration=t.currentTime-this.startTime-this.pausedDuration,0===this.duration?this.alpha=1:this.alpha=R(0,1,this.elapsedDuration/this.duration),this._tick(t),this.done&&this._resolveList.forEach((t=>t())),this.done}pause(t){t&&(this._hold=!0),-1===this.pausedTime&&(this.pausedTime=window.performance.now()),this._paused=!0}resume(t){!t&&this._hold||(this.pausedDuration+=window.performance.now()-this.pausedTime,this._paused=!1,this._hold=!1,this.pausedTime=-1)}toggle(){this._paused?this.resume():this.pause()}then(t){let e;return e=this.done?Promise.resolve():new Promise((t=>this._resolveList.push(t))),e.then(t)}}class _i extends bi{constructor(t,e,...i){super(l(t,1/0),e,...i)}_init(t,i){Array.isArray(t)?this.axis=(new e.Vector3).fromArray(t):this.axis=l(t,new e.Vector3(0,1,0)),this.angle=l(i,.01)}_tick(t){this.axis&&this.angle&&this.controls.spin(this.axis,this.angle*t.lastDuration/16)}}class xi extends bi{constructor(t,e,...i){super(l(t,1/0),e,...i),this.angleSum=0,this.direction=1}_init(t,i,r){Array.isArray(t)?this.axis=(new e.Vector3).fromArray(t):this.axis=l(t,new e.Vector3(0,1,0)),this.angleStep=l(i,.01),this.angleEnd=l(r,.2)}_tick(t){if(!this.axis||!this.angleStep||!this.angleEnd)return;const e=R(0,1,Math.abs(this.angleSum)/this.angleEnd),i=this.angleStep*this.direction*(1.1-e);this.controls.spin(this.axis,i*t.lastDuration/16),this.angleSum+=this.angleStep,this.angleSum>=this.angleEnd&&(this.direction*=-1,this.angleSum=-this.angleEnd)}}class vi extends bi{_init(t,i){this.moveFrom=S(l(t,new e.Vector3)),this.moveTo=S(l(i,new e.Vector3))}_tick(){this.controls.position.lerpVectors(this.moveFrom,this.moveTo,this.alpha).negate(),this.controls.changed()}}class wi extends bi{_init(t,e){this.zoomFrom=t,this.zoomTo=e}_tick(){this.controls.distance(O(this.zoomFrom,this.zoomTo,this.alpha))}}class Ai extends bi{constructor(){super(...arguments),this._currentRotation=new e.Quaternion}_init(t,i){this.rotateFrom=P(t),this.rotateTo=P(i),this._currentRotation=new e.Quaternion}_tick(){this._currentRotation.copy(this.rotateFrom).slerp(this.rotateTo,this.alpha),this.controls.rotate(this._currentRotation)}}class Si extends bi{_init(t,e,i){this.valueFrom=t,this.valueTo=e,this.callback=i}_tick(){this.callback(O(this.valueFrom,this.valueTo,this.alpha))}}class Ci extends bi{_init(t){this.callback=t}_tick(){1===this.alpha&&this.callback()}}class Pi{constructor(t=[]){this._resolveList=[],this._list=t}get done(){return this._list.every((t=>t.done))}then(t){let e;return e=this.done?Promise.resolve():new Promise((t=>{this._resolveList.push(t),this._list.forEach((t=>{t.then((()=>{this._resolveList.forEach((t=>{t()})),this._resolveList.length=0}))}))})),e.then(t)}}class Ii{constructor(t){this.stage=t,this.animationList=[],this.finishedList=[],this.viewer=t.viewer,this.controls=t.viewerControls}get paused(){return this.animationList.every((t=>t.paused))}add(t){return 0===t.duration?t.tick(this.viewer.stats):this.animationList.push(t),t}remove(t){const e=this.animationList,i=e.indexOf(t);i>-1&&e.splice(i,1)}run(t){const e=this.finishedList,i=this.animationList,r=i.length;for(let n=0;n<r;++n){const r=i[n];r.tick(t)&&e.push(r)}const n=e.length;if(n){for(let t=0;t<n;++t)this.remove(e[t]);e.length=0}}spin(t,e,i){return this.add(new _i(i,this.controls,t,e))}rock(t,e,i,r){return this.add(new xi(r,this.controls,t,e,i))}rotate(t,e){const i=this.viewer.rotationGroup.quaternion.clone();return this.add(new Ai(e,this.controls,i,t))}move(t,e){const i=this.controls.position.clone().negate();return this.add(new vi(e,this.controls,i,t))}zoom(t,e){const i=this.viewer.camera.position.z;return this.add(new wi(e,this.controls,i,t))}zoomMove(t,e,i){return new Pi([this.move(t,i),this.zoom(e,i)])}orient(t,i){const r=new e.Vector3,n=new e.Quaternion,s=new e.Vector3;return C(t).decompose(r,n,s),new Pi([this.move(r.negate(),i),this.rotate(n,i),this.zoom(-s.x,i)])}value(t,e,i,r){return this.add(new Si(r,this.controls,t,e,i))}timeout(t,e){return this.add(new Ci(e,this.controls,t))}spinComponent(t,e,i,r){return this.add(new _i(r,t.controls,e,i))}rockComponent(t,e,i,r,n){return this.add(new xi(n,t.controls,e,i,r))}moveComponent(t,e,i){const r=t.controls.position.clone().negate();return this.add(new vi(i,t.controls,r,e))}pause(){this.animationList.forEach((t=>t.pause()))}resume(){this.animationList.forEach((t=>t.resume()))}toggle(){this.paused?this.resume():this.pause()}clear(){this.animationList.length=0}dispose(){this.clear()}}class ki{constructor(t,e){if(this.fn=t,this.queue=[],this.pending=!1,this.next=this.next.bind(this),e){for(let t=0,i=e.length;t<i;++t)this.queue.push(e[t]);this.next()}}run(t){this.fn(t,this.next)}next(){const t=this.queue.shift();void 0!==t?(this.pending=!0,setTimeout((()=>this.run(t)))):this.pending=!1}push(t){this.queue.push(t),this.pending||this.next()}kill(){this.queue.length=0}length(){return this.queue.length}}class Mi{constructor(t,e,i){this.type="",this.parameters={lazy:{type:"boolean"},clipNear:{type:"range",step:1,max:100,min:0,buffer:!0},clipRadius:{type:"number",precision:1,max:1e3,min:0,buffer:!0},clipCenter:{type:"vector3",precision:1,buffer:!0},flatShaded:{type:"boolean",buffer:!0},opacity:{type:"range",step:.01,max:1,min:0,buffer:!0},depthWrite:{type:"boolean",buffer:!0},side:{type:"select",buffer:!0,options:{front:"front",back:"back",double:"double"}},wireframe:{type:"boolean",buffer:!0},colorData:{type:"hidden",update:"color"},colorScheme:{type:"select",update:"color",options:{}},colorScale:{type:"select",update:"color",options:$t.getScales()},colorReverse:{type:"boolean",update:"color"},colorValue:{type:"color",update:"color"},colorDomain:{type:"hidden",update:"color"},colorMode:{type:"select",update:"color",options:$t.getModes()},roughness:{type:"range",step:.01,max:1,min:0,buffer:!0},metalness:{type:"range",step:.01,max:1,min:0,buffer:!0},diffuse:{type:"color",buffer:!0},diffuseInterior:{type:"boolean",buffer:!0},useInteriorColor:{type:"boolean",buffer:!0},interiorColor:{type:"color",buffer:!0},interiorDarkening:{type:"range",step:.01,max:1,min:0,buffer:!0},matrix:{type:"hidden",buffer:!0},disablePicking:{type:"boolean",rebuild:!0}},this.viewer=e,this.tasks=new ne,this.queue=new ki(this.make.bind(this)),this.bufferList=[],this.parameters.colorScheme&&(this.parameters.colorScheme.options=$t.getSchemes()),this.toBePrepared=!1}init(t){const i=t||{};this.clipNear=l(i.clipNear,0),this.clipRadius=l(i.clipRadius,0),this.clipCenter=l(i.clipCenter,new e.Vector3),this.flatShaded=l(i.flatShaded,!1),this.side=l(i.side,"double"),this.opacity=l(i.opacity,1),this.depthWrite=l(i.depthWrite,!0),this.wireframe=l(i.wireframe,!1),this.setColor(i.color,i),this.colorData=l(i.colorData,void 0),this.colorScheme=l(i.colorScheme,"uniform"),this.colorScale=l(i.colorScale,""),this.colorReverse=l(i.colorReverse,!1),this.colorValue=l(i.colorValue,9474192),this.colorDomain=l(i.colorDomain,void 0),this.colorMode=l(i.colorMode,"hcl"),this.visible=l(i.visible,!0),this.quality=l(i.quality,void 0),this.roughness=l(i.roughness,.4),this.metalness=l(i.metalness,0),this.diffuse=l(i.diffuse,16777215),this.diffuseInterior=l(i.diffuseInterior,!1),this.useInteriorColor=l(i.useInteriorColor,!1),this.interiorColor=l(i.interiorColor,2236962),this.interiorDarkening=l(i.interiorDarkening,0),this.lazy=l(i.lazy,!1),this.lazyProps={build:!1,bufferParams:{},what:{}},this.matrix=l(i.matrix,new e.Matrix4),this.disablePicking=l(i.disablePicking,!1);const r=this.parameters;!0===r.sphereDetail&&(r.sphereDetail={type:"integer",max:3,min:0,rebuild:"impostor"}),!0===r.radialSegments&&(r.radialSegments={type:"integer",max:25,min:5,rebuild:"impostor"}),!0===r.openEnded&&(r.openEnded={type:"boolean",rebuild:"impostor",buffer:!0}),!0===r.disableImpostor&&(r.disableImpostor={type:"boolean",rebuild:!0}),"low"===i.quality?(r.sphereDetail&&(this.sphereDetail=0),r.radialSegments&&(this.radialSegments=5)):"medium"===i.quality?(r.sphereDetail&&(this.sphereDetail=1),r.radialSegments&&(this.radialSegments=10)):"high"===i.quality?(r.sphereDetail&&(this.sphereDetail=2),r.radialSegments&&(this.radialSegments=20)):(r.sphereDetail&&(this.sphereDetail=l(i.sphereDetail,1)),r.radialSegments&&(this.radialSegments=l(i.radialSegments,10))),r.openEnded&&(this.openEnded=l(i.openEnded,!0)),r.disableImpostor&&(this.disableImpostor=l(i.disableImpostor,!1))}getColorParams(t){return Object.assign({data:this.colorData,scheme:this.colorScheme,scale:this.colorScale,reverse:this.colorReverse,value:this.colorValue,domain:this.colorDomain,mode:this.colorMode,colorSpace:this.colorSpace},t)}getBufferParams(t={}){return Object.assign({clipNear:this.clipNear,clipRadius:this.clipRadius,clipCenter:this.clipCenter,flatShaded:this.flatShaded,opacity:this.opacity,depthWrite:this.depthWrite,side:this.side,wireframe:this.wireframe,roughness:this.roughness,metalness:this.metalness,diffuse:this.diffuse,diffuseInterior:this.diffuseInterior,useInteriorColor:this.useInteriorColor,interiorColor:this.interiorColor,interiorDarkening:this.interiorDarkening,matrix:this.matrix,disablePicking:this.disablePicking},t)}setColor(t,i){const r=Object.keys($t.getSchemes());if("string"==typeof t&&r.includes(t.toLowerCase()))i?i.colorScheme=t:this.setParameters({colorScheme:t});else if(void 0!==t){let r=new e.Color(t).getHex();i?(i.colorScheme="uniform",i.colorValue=r):this.setParameters({colorScheme:"uniform",colorValue:r})}return this}prepare(t){}create(){}update(t){this.build()}build(t){if(!this.lazy||this.visible&&this.opacity){if(!this.toBePrepared)return this.tasks.increment(),void this.make();this.queue.length()>0?(this.tasks.change(1-this.queue.length()),this.queue.kill()):this.tasks.increment(),this.queue.push(t||!1)}else this.lazyProps.build=!0}make(e,i){t.Debug&&Dt.time("Representation.make "+this.type);const r=()=>{e?(this.update(e),this.viewer.requestRender(),this.tasks.decrement(),i&&i()):(this.clear(),this.create(),this.manualAttach||this.disposed||(t.Debug&&Dt.time("Representation.attach "+this.type),this.attach((()=>{t.Debug&&Dt.timeEnd("Representation.attach "+this.type),this.tasks.decrement(),i&&i()})))),t.Debug&&Dt.timeEnd("Representation.make "+this.type)};this.toBePrepared?this.prepare(r):r()}attach(t){this.setVisibility(this.visible),t()}setVisibility(t,e){if(this.visible=t,this.visible&&this.opacity){const t=this.lazyProps,e=t.bufferParams,i=t.what;if(t.build)return t.build=!1,this.build(),this;(Object.keys(e).length||Object.keys(i).length)&&(t.bufferParams={},t.what={},this.updateParameters(e,i))}return this.bufferList.forEach((function(e){e.setVisibility(t)})),e||this.viewer.requestRender(),this}setParameters(t,e={},i=!1){const r=t||{},n=this.parameters,s={};this.opacity||void 0===r.opacity||(this.lazyProps.build?(this.lazyProps.build=!1,i=!0):(Object.assign(s,this.lazyProps.bufferParams),Object.assign(e,this.lazyProps.what),this.lazyProps.bufferParams={},this.lazyProps.what={})),this.setColor(r.color,r);for(let t in r)if(void 0!==r[t]&&null!=n[t]&&(n[t].int&&(r[t]=parseInt(r[t])),n[t].float&&(r[t]=parseFloat(r[t])),r[t]!==this[t]||r[t].equals&&!r[t].equals(this[t]))){if(this[t]&&this[t].copy&&r[t].copy?this[t].copy(r[t]):this[t]&&this[t].set?this[t].set(r[t]):this[t]=r[t],n[t].buffer)if(!0===n[t].buffer)s[t]=r[t];else{s[n[t].buffer]=r[t]}n[t].update&&(e[n[t].update]=!0),!n[t].rebuild||"impostor"===n[t].rebuild&&Mt&&!this.disableImpostor||(i=!0)}return i?this.build():this.updateParameters(s,e),this}updateParameters(t={},e){if(this.lazy&&(!this.visible||!this.opacity)&&!1===t.hasOwnProperty("opacity"))return Object.assign(this.lazyProps.bufferParams,t),void Object.assign(this.lazyProps.what,e);this.bufferList.forEach((function(e){e.setParameters(t)})),Object.keys(e).length&&this.update(e),this.viewer.requestRender()}getParameters(){const t={lazy:this.lazy,visible:this.visible,quality:this.quality};return Object.keys(this.parameters).forEach((e=>{null!==this.parameters[e]&&(t[e]=this[e])})),t}clear(){this.bufferList.forEach((t=>{this.viewer.remove(t),t.dispose()})),this.bufferList.length=0,this.viewer.requestRender()}dispose(){this.disposed=!0,this.queue.kill(),this.tasks.dispose(),this.clear()}}class Ti{constructor(e){this.pending=0,this.postCount=0,this.onmessageDict={},this.onerrorDict={},this.name=e,this.blobUrl=window.URL.createObjectURL(Ot.get(e)),this.worker=new Worker(this.blobUrl),Ot.activeWorkerCount+=1,this.worker.onmessage=i=>{this.pending-=1;const r=i.data.__postId;t.Debug&&Dt.timeEnd("Worker.postMessage "+e+" #"+r);const n=this.onmessageDict[r];n&&n.call(this.worker,i),delete this.onmessageDict[r],delete this.onerrorDict[r]},this.worker.onerror=t=>{if(this.pending-=1,t.data){const i=t.data.__postId,r=this.onerrorDict[i];r?r.call(this.worker,t):Dt.error("Worker.onerror",i,e,t),delete this.onmessageDict[i],delete this.onerrorDict[i]}else Dt.error("Worker.onerror",e,t)}}post(e={},i,r,n){this.onmessageDict[this.postCount]=r,this.onerrorDict[this.postCount]=n,e.__name=this.name,e.__postId=this.postCount,e.__debug=t.Debug,t.Debug&&Dt.time(`Worker.postMessage ${this.name} #${this.postCount}`);try{this.worker.postMessage(e,i)}catch(t){Dt.error("worker.post:",t),this.worker.postMessage(e)}return this.pending+=1,this.postCount+=1,this}terminate(){this.worker?(this.worker.terminate(),window.URL.revokeObjectURL(this.blobUrl),Ot.activeWorkerCount-=1):Dt.log("no worker to terminate")}}class Di{constructor(t,e=2){this.pool=[],this.count=0,this.maxCount=Math.min(8,e),this.name=t}post(t={},e,i,r){const n=this.getNextWorker();return n?n.post(t,e,i,r):console.error("unable to get worker from pool"),this}terminate(){this.pool.forEach((function(t){t.terminate()}))}getNextWorker(){let t,e=1/0;for(let i=0;i<this.maxCount;++i){if(i>=this.count){t=new Ti(this.name),this.pool.push(t),this.count+=1;break}const r=this.pool[i];if(0===r.pending){t=r;break}r.pending<e&&(e=r.pending,t=r)}return t}}function Bi(t){const i=t.length,r=i/3;let n=0,s=0,o=0;for(let e=0;e<i;e+=3)n+=t[e+0],s+=t[e+1],o+=t[e+2];return new e.Vector3(n/r,s/r,o/r)}function Fi(t,e,i){return i?t.sub(i).projectOnVector(e).add(i):t.projectOnVector(e),t}function Ei(t){let e=1/0,i=1/0,r=1/0,n=-1/0,s=-1/0,o=-1/0;for(let a=0,c=t.length;a<c;a+=3){const c=t[a],l=t[a+1],u=t[a+2];c<e&&(e=c),l<i&&(i=l),u<r&&(r=u),c>n&&(n=c),l>s&&(s=l),u>o&&(o=u)}return[Li([e,i,r]),Li([n,s,o])]}function Oi(t,e){for(let i=0,r=e.length;i<r;i+=3){const r=e[i],n=e[i+1],s=e[i+2];e[i]=t[0]*r+t[4]*n+t[8]*s+t[12],e[i+1]=t[1]*r+t[5]*n+t[9]*s+t[13],e[i+2]=t[2]*r+t[6]*n+t[10]*s+t[14]}}function $i(t,e){for(let i=0,r=e.length;i<r;i+=3){const r=e[i],n=e[i+1],s=e[i+2];e[i]=t[0]*r+t[3]*n+t[6]*s,e[i+1]=t[1]*r+t[4]*n+t[7]*s,e[i+2]=t[2]*r+t[5]*n+t[8]*s}}function Ri(t){for(let e=0,i=t.length;e<i;e+=3){const i=t[e],r=t[e+1],n=t[e+2],s=i*i+r*r+n*n;if(s>0){const o=1/Math.sqrt(s);t[e]=i*o,t[e+1]=r*o,t[e+2]=n*o}}}function Li(t){return new Float32Array(t||3)}function Ni(t,e,i){const r=e[0],n=e[1],s=e[2],o=i[0],a=i[1],c=i[2];t[0]=n*c-s*a,t[1]=s*o-r*c,t[2]=r*a-n*o}function zi(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Vi(t,e,i){t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2]}function Ui(t,e,i){t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2]}function ji(t,e,i=0){t[0]=e[i],t[1]=e[i+1],t[2]=e[i+2]}function Gi(t,e,i=0){e[i]=t[0],e[i+1]=t[1],e[i+2]=t[2]}function Hi(t){return t[0]*t[0]+t[1]*t[1]+t[2]*t[2]}function qi(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2])}function Wi(t,e,i){Xi(t,e,1/i)}function Xi(t,e,i){t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i}function Yi(t,e){const i=Hi(e);0==i?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):Xi(t,e,1/Math.sqrt(i))}function Ki(t,e,i){t[0]=e[0]-i,t[1]=e[1]-i,t[2]=e[2]-i}function Zi(t,e,i){t[0]=e[0]+i,t[1]=e[1]+i,t[2]=e[2]+i}function Qi(t,e){t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2])}function Ji(t,e){t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2])}function tr(t,e){t[0]=-e[0],t[1]=-e[1],t[2]=-e[2]}function er(t,e){const i=t[0],r=t[1],n=t[2],s=e[0],o=e[1],a=e[2],c=r*a-n*o,l=n*s-i*a,u=i*o-r*s,h=Math.sqrt(c*c+l*l+u*u),d=i*s+r*o+n*a;return Math.atan2(h,d)}function ir(t,i=9){const r=Math.floor(i/2),n=t.position1.length/3,s=3*(r*n),o=1/i,a=pe(t.position1,t.position2),c=new Float32Array(s),l=new Float32Array(s),u=new e.Vector3;for(let e=0;e<n;++e){const i=3*e;u.set(a[i],a[i+1],a[i+2]);const n=t.position1[i],s=t.position1[i+1],h=t.position1[i+2];for(let t=0;t<r;++t){const e=r*i+3*t,a=o*(2*t+1),d=o*(2*t+2);c[e]=n+u.x*a,c[e+1]=s+u.y*a,c[e+2]=h+u.z*a,l[e]=n+u.x*d,l[e+1]=s+u.y*d,l[e+2]=h+u.z*d}}const h=fe(c,l),d=function(t,e){const i=t.length/3,r=new Float32Array(i*e*3);for(let n=0;n<i;++n){const i=3*n,s=n*e*3,o=t[i+0],a=t[i+1],c=t[i+2];for(let t=0;t<e;++t){const e=s+3*t;r[e+0]=o,r[e+1]=a,r[e+2]=c}}return r}(t.color,r),m={position:h,position1:c,position2:l,color:d,color2:d};return t.radius&&(m.radius=xe(t.radius,r)),t.picking&&t.picking.array&&(t.picking.array=xe(t.picking.array,r),m.picking=t.picking),t.primitiveId&&(m.primitiveId=xe(t.primitiveId,r)),m}function rr(t,i=.1){const r=pe(t.position1,t.position2),n=[],s=[],o=[],a=t.radius?[]:void 0,c=t.picking?[]:void 0,l=t.primitiveId?[]:void 0,u=new e.Vector3,h=t.position1.length/3;let d=0;for(let e=0;e<h;++e){const h=3*e;u.set(r[h],r[h+1],r[h+2]);const m=u.length()/i,f=Math.floor(m/2),p=1/m,g=t.position1[h],y=t.position1[h+1],b=t.position1[h+2];for(let i=0;i<f;++i){const r=3*d+3*i,m=p*(2*i+1),f=p*(2*i+2);n[r]=g+u.x*m,n[r+1]=y+u.y*m,n[r+2]=b+u.z*m,s[r]=g+u.x*f,s[r+1]=y+u.y*f,s[r+2]=b+u.z*f,t.color&&(o[r]=t.color[h],o[r+1]=t.color[h+1],o[r+2]=t.color[h+2]),a&&(a[d+i]=t.radius[e]),c&&(t.picking.array?c[d+i]=t.picking.array[e]:c[d+i]=e),l&&(l[d+i]=t.primitiveId[e])}d+=f}const m=new Float32Array(n),f=new Float32Array(s),p=fe(m,f),g=new Float32Array(o),y={position:p,position1:m,position2:f,color:g,color2:g};return a&&(y.radius=new Float32Array(a)),c&&t.picking&&(t.picking.array=new Float32Array(c),y.picking=t.picking),l&&(y.primitiveId=new Float32Array(l)),y}function nr(t,i=.1){const r=pe(t.position1,t.position2),n=[],s=[],o=[],a=t.radius?[]:void 0,c=t.picking?[]:void 0,l=t.primitiveId?[]:void 0,u=new e.Vector3,h=t.position1.length/3;let d=i,m=!0,f=0,p=0,g=0;for(let e=0;e<h;++e){const h=3*e,y=t.position1[h],b=t.position1[h+1],_=t.position1[h+2];u.set(r[h],r[h+1],r[h+2]);const x=u.length();m&&(n[p]=y,n[p+1]=b,n[p+2]=_);let v=d;const w=1/x;for(;v<x;){const t=m?s:n;t[p]=y+u.x*v*w,t[p+1]=b+u.y*v*w,t[p+2]=_+u.z*v*w,m&&(f++,p=3*f),m=!m,d=i,v+=i}m&&(s[p]=t.position2[h],s[p+1]=t.position2[h+1],s[p+2]=t.position2[h+2],f++,p=3*f),d=v-x;for(let i=g;i<f;i++){if(t.color){const e=3*i;o[e]=t.color[h],o[e+1]=t.color[h+1],o[e+2]=t.color[h+2]}a&&(a[i]=t.radius[e]),c&&(t.picking.array?c[i]=t.picking.array[e]:c[i]=e),l&&(l[i]=t.primitiveId[e])}g=f}if(!m&&h>0){const e=3*f;s[e]=t.position2[3*h-3],s[e+1]=t.position2[3*h-2],s[e+1]=t.position2[3*h-1]}const y=new Float32Array(n),b=new Float32Array(s),_=fe(y,b),x=new Float32Array(o),v={position:_,position1:y,position2:b,color:x,color2:x};return a&&(v.radius=new Float32Array(a)),c&&t.picking&&(t.picking.array=new Float32Array(c),v.picking=t.picking),l&&(v.primitiveId=new Float32Array(l)),v}Di.prototype.constructor=Di,Ei.__deps=[Li],Wi.__deps=[Xi],Yi.__deps=[Xi,Hi];const sr=new e.Vector3;class or{static get Picker(){return Gt.get(this.type)}static get Buffer(){return jt.get(this.type)}static getShapeKey(t){return this.type+t[0].toUpperCase()+t.substr(1)}static expandBoundingBox(t,e){}static valueToShape(t,e,i){const r=t._primitiveData[this.getShapeKey(e)];switch(this.fields[e]){case"v3":case"c":!function(t,e){void 0!==t.toArray?t=t.toArray():void 0!==t.x?t=[t.x,t.y,t.z]:void 0!==t.r&&(t=[t.r,t.g,t.b]),e.push.apply(e,t)}(i,r);break;default:r.push(i)}}static objectToShape(t,e){Object.keys(this.fields).forEach((i=>{this.valueToShape(t,i,e[i])})),this.valueToShape(t,"name",e.name),this.expandBoundingBox(t.boundingBox,e)}static valueFromShape(t,i,r){const n=t._primitiveData[this.getShapeKey(r)];switch(this.fields[r]){case"v3":return(new e.Vector3).fromArray(n,3*i);case"c":return(new e.Color).fromArray(n,3*i);default:return n[i]}}static objectFromShape(t,e){let i=this.valueFromShape(t,e,"name");void 0===i&&(i=`${this.type}: ${e} (${t.name})`);const r={shape:t,name:i};return Object.keys(this.fields).forEach((i=>{r[i]=this.valueFromShape(t,e,i)})),r}static arrayFromShape(t,e){const i=t._primitiveData[this.getShapeKey(e)];return"s"===this.fields[e]?i:new Float32Array(i)}static dataFromShape(t){const e={};return this.Picker&&(e.picking=new this.Picker(t)),Object.keys(this.fields).forEach((i=>{e[i]=this.arrayFromShape(t,i)})),e}static bufferFromShape(t,e){return new this.Buffer(this.dataFromShape(t),e)}}or.type="",or.fields={};class ar extends or{static positionFromShape(t,e){return this.valueFromShape(t,e,"position")}static expandBoundingBox(t,e){t.expandByPoint(sr.fromArray(e.position))}}ar.type="sphere",ar.fields={position:"v3",color:"c",radius:"f"};class cr extends or{static positionFromShape(t,e){return this.valueFromShape(t,e,"position")}static expandBoundingBox(t,e){t.expandByPoint(sr.fromArray(e.position))}}cr.type="box",cr.fields={position:"v3",color:"c",size:"f",heightAxis:"v3",depthAxis:"v3"};class lr extends cr{}lr.type="octahedron";class ur extends cr{}ur.type="tetrahedron";class hr extends cr{}hr.type="icosahedron";class dr extends or{static positionFromShape(t,e){const i=this.valueFromShape(t,e,"position1"),r=this.valueFromShape(t,e,"position2");return i.add(r).multiplyScalar(.5)}static expandBoundingBox(t,e){t.expandByPoint(sr.fromArray(e.position1)),t.expandByPoint(sr.fromArray(e.position2))}static bufferFromShape(t,e={}){let i=this.dataFromShape(t);return"cylinder"===this.type&&e.dashedCylinder&&(i=rr(i)),new this.Buffer(i,e)}}dr.type="cylinder",dr.fields={position1:"v3",position2:"v3",color:"c",radius:"f"};class mr extends dr{}mr.type="arrow";class fr extends dr{}fr.type="cone";class pr extends ar{}pr.type="ellipsoid",pr.fields={position:"v3",color:"c",radius:"f",majorAxis:"v3",minorAxis:"v3"};class gr extends pr{}gr.type="torus";class yr extends or{static positionFromShape(t,e){return this.valueFromShape(t,e,"position")}static expandBoundingBox(t,e){t.expandByPoint(sr.fromArray(e.position))}}yr.type="text",yr.fields={position:"v3",color:"c",size:"f",text:"s"};class br extends or{static positionFromShape(t,e){return this.valueFromShape(t,e,"position")}static expandBoundingBox(t,e){t.expandByPoint(sr.fromArray(e.position))}}br.type="point",br.fields={position:"v3",color:"c"};class _r extends or{static positionFromShape(t,e){const i=this.valueFromShape(t,e,"position1"),r=this.valueFromShape(t,e,"position2");return i.add(r).multiplyScalar(.5)}static expandBoundingBox(t,e){t.expandByPoint(sr.fromArray(e.position1)),t.expandByPoint(sr.fromArray(e.position2))}}_r.type="wideline",_r.fields={position1:"v3",position2:"v3",color:"c"};class xr{constructor(t,i){this.exp=3;const r=i||function(t){const{x:i,y:r,z:n}=t,s=new e.Box3,o=i.length,{min:a,max:c}=s;for(let t=0;t<o;t++)a.x=Math.min(i[t],a.x),a.y=Math.min(r[t],a.y),a.z=Math.min(n[t],a.z),c.x=Math.max(i[t],c.x),c.y=Math.max(r[t],c.y),c.z=Math.max(n[t],c.z);return s}(t);this.minX=r.min.x,this.minY=r.min.y,this.minZ=r.min.z,this.boundX=1+(r.max.x-this.minX>>this.exp),this.boundY=1+(r.max.y-this.minY>>this.exp),this.boundZ=1+(r.max.z-this.minZ>>this.exp);const n=this.boundX*this.boundY*this.boundZ,s=void 0!==t.count?t.count:t.x.length,o=t.x,a=t.y,c=t.z;let l=0;const u=new Uint32Array(n),h=new Int32Array(s);for(let t=0;t<s;++t){const e=o[t]-this.minX>>this.exp,i=a[t]-this.minY>>this.exp,r=c[t]-this.minZ>>this.exp,n=(e*this.boundY+i)*this.boundZ+r;1===(u[n]+=1)&&(l+=1),h[t]=n}const d=new Uint16Array(l);for(let t=0,e=0;t<n;++t){const i=u[t];i>0&&(u[t]=e+1,d[e]=i,e+=1)}const m=new Uint32Array(l);for(let t=1;t<l;++t)m[t]+=m[t-1]+d[t-1];const f=new Uint16Array(l),p=new Int32Array(s);for(let t=0;t<s;++t){const e=u[h[t]];if(e>0){const i=e-1;p[m[i]+f[i]]=t,f[i]+=1}}this.grid=u,this.bucketCount=d,this.bucketOffset=m,this.bucketArray=p,this.xArray=o,this.yArray=a,this.zArray=c}within(t,e,i,r){const n=[];return this.eachWithin(t,e,i,r,(t=>n.push(t))),n}eachWithin(t,e,i,r,n){const s=r*r,o=Math.max(0,t-r-this.minX>>this.exp),a=Math.max(0,e-r-this.minY>>this.exp),c=Math.max(0,i-r-this.minZ>>this.exp),l=Math.min(this.boundX,1+(t+r-this.minX>>this.exp)),u=Math.min(this.boundY,1+(e+r-this.minY>>this.exp)),h=Math.min(this.boundZ,1+(i+r-this.minZ>>this.exp));for(let r=o;r<l;++r)for(let o=a;o<u;++o)for(let a=c;a<h;++a){const c=(r*this.boundY+o)*this.boundZ+a,l=this.grid[c];if(l>0){const r=l-1,o=this.bucketOffset[r],a=o+this.bucketCount[r];for(let r=o;r<a;++r){const o=this.bucketArray[r],a=this.xArray[o]-t,c=this.yArray[o]-e,l=this.zArray[o]-i,u=a*a+c*c+l*l;u<=s&&n(o,u)}}}}}class vr{constructor(t=0){this._fields=this._defaultFields,this._init(0)}get _defaultFields(){return[]}_init(t){this.length=t,this.count=0;for(let t=0,e=this._fields.length;t<e;++t){const[e,i,r]=this._fields[t];this._initField(e,i,r)}}_initField(t,e,i){this[t]=x(i,this.length*e)}addField(t,e,i){this._fields.push([t,e,i]),this._initField(t,e,i)}resize(t){this.length=Math.round(t||0),this.count=Math.min(this.count,this.length);for(let t=0,e=this._fields.length;t<e;++t){const e=this._fields[t][0],i=this._fields[t][1],r=this.length*i,n=new this[e].constructor(r);this[e].length>r?n.set(this[e].subarray(0,r)):n.set(this[e]),this[e]=n}}growIfFull(){if(this.count>=this.length){const t=Math.round(1.5*this.length);this.resize(Math.max(256,t))}}copyFrom(t,e,i,r){for(let n=0,s=this._fields.length;n<s;++n){const s=this._fields[n][0],o=this._fields[n][1],a=this[s],c=t[s];for(let t=0;t<r;++t){const r=o*(e+t),n=o*(i+t);for(let t=0;t<o;++t)a[r+t]=c[n+t]}}}copyWithin(t,e,i){for(let r=0,n=this._fields.length;r<n;++r){const n=this._fields[r][0],s=this._fields[r][1],o=this[n];for(let r=0;r<i;++r){const i=s*(t+r),n=s*(e+r);for(let t=0;t<s;++t)o[i+t]=o[n+t]}}}sort(t){Dt.time("Store.sort");const e=this,i=new this.constructor(1);!function r(n,s){if(n<s){let c=Math.floor((n+s)/2),l=n,u=s;do{for(;t(l,c)<0;)l+=1;for(;t(u,c)>0;)u-=1;l<=u&&(l===c?c=u:u===c&&(c=l),(o=l)!==(a=u)&&(i.copyFrom(e,0,o,1),e.copyWithin(o,a,1),e.copyFrom(i,a,0,1)),l+=1,u-=1)}while(l<=u);r(n,u),r(l,s)}var o,a}(0,this.count-1),Dt.timeEnd("Store.sort")}clear(){this.count=0}dispose(){for(let t=0,e=this._fields.length;t<e;++t){delete this[this._fields[t][0]]}}}class wr extends vr{get _defaultFields(){return[["index1",1,"int32"],["index2",1,"int32"],["type",1,"int8"]]}addContact(t,e,i){this.growIfFull();const r=this.count;t<e?(this.index1[r]=t,this.index2[r]=e):(this.index2[r]=t,this.index1[r]=e),i&&(this.type[r]=i),this.count+=1}}function Ar(t){return 16843009*((t=(858993459&(t-=t>>>1&1431655765))+(t>>>2&858993459))+(t>>>4)&252645135)>>>24}class Sr{constructor(t,e){this.length=t,this._words=new Uint32Array(t+32>>>5),!0===e&&this.setAll()}get(t){return!!(this._words[t>>>5]&1<<t)}set(t){this._words[t>>>5]|=1<<t}clear(t){this._words[t>>>5]&=~(1<<t)}flip(t){this._words[t>>>5]^=1<<t}_assignRange(t,e,i){if(e<t)return;const r=this._words,n=!0===i?4294967295:0,s=t>>>5,o=e>>>5;for(let t=s+1;t<o;++t)r[t]=n;const a=s<<5,c=o<<5;if(!0===i)if(e-t<32)for(let i=t,n=e+1;i<n;++i)r[i>>>5]|=1<<i;else{for(let e=t,i=a+32;e<i;++e)r[e>>>5]|=1<<e;for(let t=c,i=e+1;t<i;++t)r[t>>>5]|=1<<t}else if(e-t<32)for(let i=t,n=e+1;i<n;++i)r[i>>>5]&=~(1<<i);else{for(let e=t,i=a+32;e<i;++e)r[e>>>5]&=~(1<<e);for(let t=c,i=e+1;t<i;++t)r[t>>>5]&=~(1<<t)}return this}setRange(t,e){return this._assignRange(t,e,!0)}clearRange(t,e){return this._assignRange(t,e,!1)}setBits(...t){const e=this._words,i=t.length;for(let r=0;r<i;++r){const i=t[r];e[i>>>5]|=1<<i}return this}clearBits(...t){const e=this._words,i=t.length;for(let r=0;r<i;++r){const i=t[r];e[i>>>5]&=~(1<<i)}return this}setAll(){return this._assignRange(0,this.length-1,!0)}clearAll(){return this._assignRange(0,this.length-1,!1)}flipAll(){const t=this._words.length,e=this._words,i=32-this.length%32;for(let i=0;i<t-1;++i)e[i]=~e[i];return e[t-1]=~(e[t-1]<<i)>>>i,this}_isRangeValue(t,e,i){if(e<t)return;const r=this._words,n=!0===i?4294967295:0,s=t>>>5,o=e>>>5;for(let t=s+1;t<o;++t)if(r[t]!==n)return!1;if(e-t<32){for(let n=t,s=e+1;n<s;++n)if(!!(r[n>>>5]&1<<n)!==i)return!1}else{const n=o<<5;for(let e=t,n=(s<<5)+32;e<n;++e)if(!!(r[e>>>5]&1<<e)!==i)return!1;for(let t=n,s=e+1;t<s;++t)if(!!(r[t>>>5]&1<<t)!==i)return!1}return!0}isRangeSet(t,e){return this._isRangeValue(t,e,!0)}isRangeClear(t,e){return this._isRangeValue(t,e,!1)}isAllSet(){return this._isRangeValue(0,this.length-1,!0)}isAllClear(){return this._isRangeValue(0,this.length-1,!1)}isSet(...t){const e=this._words,i=t.length;for(let r=0;r<i;++r){const i=t[r];if(!(e[i>>>5]&1<<i))return!1}return!0}isClear(...t){const e=this._words,i=t.length;for(let r=0;r<i;++r){const i=t[r];if(e[i>>>5]&1<<i)return!1}return!0}isEqualTo(t){const e=this._words,i=t._words,r=Math.min(e.length,i.length);for(let t=0;t<r;++t)if(e[t]!==i[t])return!1;return!0}getSize(){const t=this._words.length,e=this._words;let i=0;for(let r=0;r<t;++r)i+=Ar(e[r]);return i}difference(t){const e=this._words,i=t._words,r=Math.min(e.length,i.length);for(let t=0;t<r;++t)e[t]=e[t]&~i[t];for(let t=e.length;t<r;++t)e[t]=0;return this}union(t){const e=this._words,i=t._words,r=Math.min(e.length,i.length);for(let t=0;t<r;++t)e[t]|=i[t];for(let t=e.length;t<r;++t)e[t]=0;return this}intersection(t){const e=this._words,i=t._words,r=Math.min(e.length,i.length);for(let t=0;t<r;++t)e[t]&=i[t];for(let t=e.length;t<r;++t)e[t]=0;return this}intersects(t){const e=this._words,i=t._words,r=Math.min(e.length,i.length);for(let t=0;t<r;++t)if(e[t]&i[t])return!0;return!1}getIntersectionSize(t){const e=this._words,i=t._words,r=Math.min(e.length,i.length);let n=0;for(let t=0;t<r;++t)n+=Ar(e[t]&i[t]);return n}makeIntersection(t){const e=this._words,i=t._words,r=Math.min(e.length,i.length),n=new Uint32Array(r),s=Object.create(Sr.prototype);s._words=n,s.length=Math.min(this.length,t.length);for(let t=0;t<r;++t)n[t]=e[t]&i[t];return s}forEach(t){const e=this._words.length,i=this._words;let r=0;for(let n=0;n<e;++n){let e=i[n];for(;0!==e;){const i=e&-e;t((n<<5)+Ar(i-1),r),e^=i,++r}}}toArray(){const t=this._words,e=new Array(this.getSize()),i=this._words.length;let r=0;for(let n=0;n<i;++n){let i=t[n];for(;0!==i;){const t=i&-i;e[r++]=(n<<5)+Ar(t-1),i^=t}}return e}toString(){return"{"+this.toArray().join(",")+"}"}toSeleString(){const t=this.toArray().join(",");return t?"@"+t:"NONE"}clone(){const t=Object.create(Sr.prototype);return t.length=this.length,t._words=new Uint32Array(this._words),t}}function Cr(t){const{edgeCount:e,nodeCount:i,nodeArray1:r,nodeArray2:n}=t,s=new Uint8Array(i),o=new Int32Array(i);for(let t=0;t<e;++t)s[r[t]]+=1,s[n[t]]+=1;for(let t=1;t<i;++t)o[t]+=o[t-1]+s[t-1];const a=2*e,c=new Int32Array(a);for(let t=0;t<a;++t)c[t]=-1;for(let t=0;t<e;++t){const e=r[t],i=n[t];let s=o[e];for(;-1!==c[s]&&s<a;)s+=1;c[s]=t;let l=o[i];for(;-1!==c[l]&&l<a;)l+=1;c[l]=t}return{countArray:s,offsetArray:o,indexArray:c}}function Pr(t=0,e=0){return{type:t,group:e,x:0,y:0,z:0,atomSet:[]}}function Ir(t,e){t.x+=e.x,t.y+=e.y,t.z+=e.z,t.atomSet.push(e.index)}function kr(t,e){const i=e.atomSet.length;if(i>0){const{types:r,groups:n,centers:s,atomSets:o}=t;r.push(e.type),n.push(e.group),s.x.push(e.x/i),s.y.push(e.y/i),s.z.push(e.z/i),o.push(e.atomSet)}}const Mr=0,Tr=["D-BETA-PEPTIDE, C-GAMMA LINKING","D-GAMMA-PEPTIDE, C-DELTA LINKING","D-PEPTIDE COOH CARBOXY TERMINUS","D-PEPTIDE NH3 AMINO TERMINUS","D-PEPTIDE LINKING","L-BETA-PEPTIDE, C-GAMMA LINKING","L-GAMMA-PEPTIDE, C-DELTA LINKING","L-PEPTIDE COOH CARBOXY TERMINUS","L-PEPTIDE NH3 AMINO TERMINUS","L-PEPTIDE LINKING","PEPTIDE LINKING","PEPTIDE-LIKE"],Dr=["RNA OH 3 PRIME TERMINUS","RNA OH 5 PRIME TERMINUS","RNA LINKING"],Br=["DNA OH 3 PRIME TERMINUS","DNA OH 5 PRIME TERMINUS","DNA LINKING","L-DNA LINKING","L-RNA LINKING"],Fr=["D-SACCHARIDE","D-SACCHARIDE 1,4 AND 1,4 LINKING","D-SACCHARIDE 1,4 AND 1,6 LINKING","L-SACCHARIDE","L-SACCHARIDE 1,4 AND 1,4 LINKING","L-SACCHARIDE 1,4 AND 1,6 LINKING","SACCHARIDE"],Er=["NON-POLYMER"].concat(["OTHER"],Fr),Or=["h","g","i"],$r=["e","b"],Rr=["s","t","l",""],Lr={H:1,D:1,T:1,HE:2,LI:3,BE:4,B:5,C:6,N:7,O:8,F:9,NE:10,NA:11,MG:12,AL:13,SI:14,P:15,S:16,CL:17,AR:18,K:19,CA:20,SC:21,TI:22,V:23,CR:24,MN:25,FE:26,CO:27,NI:28,CU:29,ZN:30,GA:31,GE:32,AS:33,SE:34,BR:35,KR:36,RB:37,SR:38,Y:39,ZR:40,NB:41,MO:42,TC:43,RU:44,RH:45,PD:46,AG:47,CD:48,IN:49,SN:50,SB:51,TE:52,I:53,XE:54,CS:55,BA:56,LA:57,CE:58,PR:59,ND:60,PM:61,SM:62,EU:63,GD:64,TB:65,DY:66,HO:67,ER:68,TM:69,YB:70,LU:71,HF:72,TA:73,W:74,RE:75,OS:76,IR:77,PT:78,AU:79,HG:80,TL:81,PB:82,BI:83,PO:84,AT:85,RN:86,FR:87,RA:88,AC:89,TH:90,PA:91,U:92,NP:93,PU:94,AM:95,CM:96,BK:97,CF:98,ES:99,FM:100,MD:101,NO:102,LR:103,RF:104,DB:105,SG:106,BH:107,HS:108,MT:109,DS:110,RG:111,CN:112,NH:113,FL:114,MC:115,LV:116,TS:117,OG:118},Nr={1:1.1,2:1.4,3:1.81,4:1.53,5:1.92,6:1.7,7:1.55,8:1.52,9:1.47,10:1.54,11:2.27,12:1.73,13:1.84,14:2.1,15:1.8,16:1.8,17:1.75,18:1.88,19:2.75,20:2.31,21:2.3,22:2.15,23:2.05,24:2.05,25:2.05,26:2.05,27:2,28:2,29:2,30:2.1,31:1.87,32:2.11,33:1.85,34:1.9,35:1.83,36:2.02,37:3.03,38:2.49,39:2.4,40:2.3,41:2.15,42:2.1,43:2.05,44:2.05,45:2,46:2.05,47:2.1,48:2.2,49:2.2,50:1.93,51:2.17,52:2.06,53:1.98,54:2.16,55:3.43,56:2.68,57:2.5,58:2.48,59:2.47,60:2.45,61:2.43,62:2.42,63:2.4,64:2.38,65:2.37,66:2.35,67:2.33,68:2.32,69:2.3,70:2.28,71:2.27,72:2.25,73:2.2,74:2.1,75:2.05,76:2,77:2,78:2.05,79:2.1,80:2.05,81:1.96,82:2.02,83:2.07,84:1.97,85:2.02,86:2.2,87:3.48,88:2.83,89:2,90:2.4,91:2,92:2.3,93:2,94:2,95:2,96:2,97:2,98:2,99:2,100:2,101:2,102:2,103:2,104:2,105:2,106:2,107:2,108:2,109:2,110:2,111:2,112:2,113:2,114:2,115:2,116:2,117:2,118:2},zr={1:.31,2:.28,3:1.28,4:.96,5:.84,6:.76,7:.71,8:.66,9:.57,10:.58,11:1.66,12:1.41,13:1.21,14:1.11,15:1.07,16:1.05,17:1.02,18:1.06,19:2.03,20:1.76,21:1.7,22:1.6,23:1.53,24:1.39,25:1.39,26:1.32,27:1.26,28:1.24,29:1.32,30:1.22,31:1.22,32:1.2,33:1.19,34:1.2,35:1.2,36:1.16,37:2.2,38:1.95,39:1.9,40:1.75,41:1.64,42:1.54,43:1.47,44:1.46,45:1.42,46:1.39,47:1.45,48:1.44,49:1.42,50:1.39,51:1.39,52:1.38,53:1.39,54:1.4,55:2.44,56:2.15,57:2.07,58:2.04,59:2.03,60:2.01,61:1.99,62:1.98,63:1.98,64:1.96,65:1.94,66:1.92,67:1.92,68:1.89,69:1.9,70:1.87,71:1.87,72:1.75,73:1.7,74:1.62,75:1.51,76:1.44,77:1.41,78:1.36,79:1.36,80:1.32,81:1.45,82:1.46,83:1.48,84:1.4,85:1.5,86:1.5,87:2.6,88:2.21,89:2.15,90:2.06,91:2,92:1.96,93:1.9,94:1.87,95:1.8,96:1.69,97:1.6,98:1.6,99:1.6,100:1.6,101:1.6,102:1.6,103:1.6,104:1.6,105:1.6,106:1.6,107:1.6,108:1.6,109:1.6,110:1.6,111:1.6,112:1.6,113:1.6,114:1.6,115:1.6,116:1.6,117:1.6,118:1.6},Vr={1:[1],2:[0],3:[1],4:[2],5:[3],6:[4],7:[3],8:[2],9:[1],10:[0],11:[1],12:[2],13:[6],14:[6],15:[3,5,7],16:[2,4,6],17:[1],18:[0],19:[1],20:[2],31:[3],32:[4],33:[3,5],34:[2,4,6],35:[1],36:[0],37:[1],38:[2],49:[3],50:[4],51:[3,5],52:[2],53:[1,2,5],54:[0,2],55:[1],56:[2],81:[3],82:[4],83:[3],84:[2],85:[1],86:[0],87:[1],88:[2]},Ur={1:1,2:2,3:1,4:2,5:3,6:4,7:5,8:6,9:7,10:8,11:1,12:2,13:3,14:4,15:5,16:6,17:7,18:8,19:1,20:2,21:3,22:4,23:5,24:6,25:7,26:8,27:9,28:10,29:11,30:2,31:3,32:4,33:5,34:6,35:7,36:8,37:1,38:2,39:3,40:4,41:5,42:6,43:7,44:8,45:9,46:10,47:11,48:2,49:3,50:4,51:5,52:6,53:7,54:8,55:1,56:2,57:3,58:4,59:3,60:4,61:5,62:6,63:7,64:8,65:9,66:10,67:11,68:12,69:13,70:14,71:15,72:4,73:5,74:6,75:7,76:8,77:9,78:10,79:11,80:2,81:3,82:4,83:5,84:6,85:7,86:8,87:1,88:2,89:3,90:4,91:3,92:4,93:5,94:6,95:7,96:8,97:9,98:10,99:11,100:12,101:13,102:14,103:15,104:2,105:2,106:2,107:2,108:2,109:2,110:2,111:2,112:2,113:3,114:4,115:5,116:6,117:7,118:8},jr={ALA:[.17,.5,.33],ARG:[.81,1.81,1],ASN:[.42,.85,.43],ASP:[1.23,3.64,2.41],ASH:[-.07,.43,.5],CYS:[-.24,-.02,.22],GLN:[.58,.77,.19],GLU:[2.02,3.63,1.61],GLH:[-.01,.11,.12],GLY:[.01,1.15,1.14],HIS:[.17,.11,-.06],ILE:[-.31,-1.12,-.81],LEU:[-.56,-1.25,-.69],LYS:[.99,2.8,1.81],MET:[-.23,-.67,-.44],PHE:[-1.13,-1.71,-.58],PRO:[.45,.14,-.31],SER:[.13,.46,.33],THR:[.14,.25,.11],TRP:[-1.85,-2.09,-.24],TYR:[-.94,-.71,.23],VAL:[.07,-.46,-.53]},Gr=[0,0,0],Hr={HIS:"H",ARG:"R",LYS:"K",ILE:"I",PHE:"F",LEU:"L",TRP:"W",ALA:"A",MET:"M",PRO:"P",CYS:"C",ASN:"N",VAL:"V",GLY:"G",SER:"S",GLN:"Q",TYR:"Y",ASP:"D",GLU:"E",THR:"T",SEC:"U",PYL:"O"},qr=Object.keys(Hr),Wr=["A","C","T","G","U","I"],Xr=["DA","DC","DT","DG","DU","DI"],Yr=["A","G","I","DA","DG","DI"],Kr=Wr.concat(Xr),Zr=["SOL","WAT","HOH","H2O","W","DOD","D3O","TIP3","TIP4","SPC"],Qr=["118","119","1AL","1CU","2FK","2HP","2OF","3CO","3MT","3NI","3OF","3P8","4MO","4PU","543","6MO","ACT","AG","AL","ALF","AM","ATH","AU","AU3","AUC","AZI","BA","BCT","BEF","BF4","BO4","BR","BS3","BSY","CA","CAC","CD","CD1","CD3","CD5","CE","CHT","CL","CO","CO3","CO5","CON","CR","CS","CSB","CU","CU1","CU3","CUA","CUZ","CYN","DME","DMI","DSC","DTI","DY","E4N","EDR","EMC","ER3","EU","EU3","F","FE","FE2","FPO","GA","GD3","GEP","HAI","HG","HGC","IN","IOD","IR","IR3","IRI","IUM","K","KO4","LA","LCO","LCP","LI","LU","MAC","MG","MH2","MH3","MLI","MLT","MMC","MN","MN3","MN5","MN6","MO1","MO2","MO3","MO4","MO5","MO6","MOO","MOS","MOW","MW1","MW2","MW3","NA","NA2","NA5","NA6","NAO","NAW","NCO","NET","NH4","NI","NI1","NI2","NI3","NO2","NO3","NRU","O4M","OAA","OC1","OC2","OC3","OC4","OC5","OC6","OC7","OC8","OCL","OCM","OCN","OCO","OF1","OF2","OF3","OH","OS","OS4","OXL","PB","PBM","PD","PDV","PER","PI","PO3","PO4","PR","PT","PT4","PTN","RB","RH3","RHD","RU","SB","SCN","SE4","SEK","SM","SMO","SO3","SO4","SR","T1A","TB","TBA","TCN","TEA","TH","THE","TL","TMA","TRA","UNX","V","VN3","VO4","W","WO5","Y1","YB","YB2","YH","YT3","ZCM","ZN","ZN2","ZN3","ZNO","ZO3","OHX"],Jr=["045","0AT","0BD","0MK","0NZ","0TS","0V4","0XY","0YT","10M","147","149","14T","15L","16G","18T","18Y","1AR","1BW","1GL","1GN","1JB","1LL","1NA","1S3","26M","26Q","26R","26V","26W","26Y","27C","289","291","293","2DG","2F8","2FG","2FL","2FP","2GL","2M4","2M5","32O","34V","3CM","3DO","3DY","3FM","3LR","3MF","3MG","3SA","3ZW","46D","46M","46Z","48Z","4CQ","4GC","4NN","50A","5DI","5GF","5MM","5RP","5SA","5SP","64K","6PG","6SA","7JZ","7SA","A1Q","A2G","AAB","AAL","AAO","ABC","ABD","ABE","ABF","ABL","ACG","ACI","ACR","ACX","ADA","ADG","ADR","AF1","AFD","AFL","AFO","AFP","AFR","AGC","AGH","AGL","AHR","AIG","ALL","ALX","AMU","AOG","AOS","ARA","ARB","ARE","ARI","ASG","ASO","AXP","AXR","B0D","B16","B2G","B4G","B6D","B8D","B9D","BBK","BCD","BDG","BDP","BDR","BEM","BFP","BGC","BGL","BGP","BGS","BHG","BMA","BMX","BNG","BNX","BOG","BRI","BXF","BXP","BXX","BXY","C3X","C4X","C5X","CAP","CBI","CBK","CBS","CDR","CEG","CGF","CHO","CR1","CR6","CRA","CT3","CTO","CTR","CTT","D6G","DAF","DAG","DDA","DDB","DDL","DEL","DFR","DFX","DG0","DGC","DGD","DGM","DGS","DIG","DLF","DLG","DMU","DNO","DOM","DP5","DQQ","DQR","DR2","DR3","DR4","DRI","DSR","DT6","DVC","E4P","E5G","EAG","EBG","EBQ","EGA","EJT","EPG","ERE","ERI","F1P","F1X","F6P","FBP","FCA","FCB","FCT","FDP","FDQ","FFC","FIX","FMO","FRU","FSI","FU4","FUB","FUC","FUD","FUL","FXP","G16","G1P","G2F","G3I","G4D","G4S","G6D","G6P","G6S","GAC","GAD","GAL","GC1","GC4","GCD","GCN","GCO","GCS","GCT","GCU","GCV","GCW","GCX","GE1","GFG","GFP","GIV","GL0","GL2","GL5","GL6","GL7","GL9","GLA","GLB","GLC","GLD","GLF","GLG","GLO","GLP","GLS","GLT","GLW","GMH","GN1","GNX","GP1","GP4","GPH","GPM","GQ1","GQ2","GQ4","GS1","GS4","GSA","GSD","GTE","GTH","GTK","GTR","GTZ","GU0","GU1","GU2","GU3","GU4","GU5","GU6","GU8","GU9","GUF","GUP","GUZ","GYP","GYV","H2P","HDL","HMS","HS2","HSD","HSG","HSH","HSJ","HSQ","HSR","HSU","HSX","HSY","HSZ","IAB","IDG","IDR","IDS","IDT","IDU","IDX","IDY","IMK","IN1","IPT","ISL","KBG","KD2","KDA","KDM","KDO","KFN","KO1","KO2","KTU","L6S","LAG","LAI","LAK","LAO","LAT","LB2","LBT","LCN","LDY","LGC","LGU","LM2","LMT","LMU","LOG","LOX","LPK","LSM","LTM","LVZ","LXB","LXZ","M1F","M3M","M6P","M8C","MA1","MA2","MA3","MAB","MAG","MAL","MAN","MAT","MAV","MAW","MBG","MCU","MDA","MDM","MDP","MFA","MFB","MFU","MG5","MGA","MGL","MLB","MMA","MMN","MN0","MRP","MTT","MUG","MVP","MXY","N1L","N9S","NAA","NAG","NBG","NDG","NED","NG1","NG6","NGA","NGB","NGC","NGE","NGF","NGL","NGS","NGY","NHF","NM6","NM9","NTF","NTO","NTP","NXD","NYT","OPG","OPM","ORP","OX2","P3M","P53","P6P","PA5","PNA","PNG","PNW","PRP","PSJ","PSV","PTQ","QDK","QPS","QV4","R1P","R1X","R2B","R5P","RAA","RAE","RAF","RAM","RAO","RAT","RB5","RBL","RCD","RDP","REL","RER","RF5","RG1","RGG","RHA","RIB","RIP","RNS","RNT","ROB","ROR","RPA","RST","RUB","RUU","RZM","S6P","S7P","SA0","SCR","SDD","SF6","SF9","SG4","SG5","SG6","SG7","SGA","SGC","SGD","SGN","SGS","SHB","SHG","SI3","SIO","SOE","SOL","SSG","SUC","SUP","SUS","T6P","T6T","TAG","TCB","TDG","TGK","TGY","TH1","TIA","TM5","TM6","TM9","TMR","TMX","TOA","TOC","TRE","TYV","UCD","UDC","VG1","X0X","X1X","X2F","X4S","X5S","X6X","XBP","XDN","XDP","XIF","XIM","XLF","XLS","XMM","XUL","XXR","XYP","XYS","YO5","Z3Q","Z6J","Z9M","ZDC","ZDM"],tn=["CA","C","N","O","O1","O2","OC1","OC2","OX1","OXT","OT1","OT2","H","H1","H2","H3","HA","HN","BB"],en=["P","OP1","OP2","HOP2","HOP3","O2'","O3'","O4'","O5'","C1'","C2'","C3'","C4'","C5'","H1'","H2'","H2''","HO2'","H3'","H4'","H5'","H5''","HO3'","HO5'","O2*","O3*","O4*","O5*","C1*","C2*","C3*","C4*","C5*"],rn={1:{trace:"CA",direction1:"C",direction2:["O","OC1","O1","OX1","OXT","OT1","OT2"],backboneStart:"N",backboneEnd:"C"},2:{trace:["C4'","C4*"],direction1:["C1'","C1*"],direction2:["C3'","C3*"],backboneStart:"P",backboneEnd:["O3'","O3*"]},3:{trace:["C3'","C3*"],direction1:["C2'","C2*"],direction2:["O4'","O4*"],backboneStart:"P",backboneEnd:["O3'","O3*"]},4:{trace:["CA","BB"],backboneStart:["CA","BB"],backboneEnd:["CA","BB"]},5:{trace:["C4'","C4*","P"],backboneStart:["C4'","C4*","P"],backboneEnd:["C4'","C4*","P"]},6:{trace:["C3'","C3*","C2'","P"],backboneStart:["C3'","C3*","C2'","P"],backboneEnd:["C3'","C3*","C2'","P"]}};rn[Mr]={};const nn={HD:"H",HS:"H",A:"C",NA:"N",NS:"N",OA:"O",OS:"O",SA:"S",G0:"C",G1:"C",G2:"C",G3:"C",CG0:"C",CG1:"C",CG2:"C",CG3:"C",W:"O"};function sn(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;default:return 8}}const on=new Map([[2,T(180)],[3,T(120)],[4,T(109.4721)],[6,T(90)]]);function an(t,i){let r=[];const n=new e.Vector3,s=new e.Vector3;return n.subVectors(i,t),t.eachBondedAtom((e=>{1!==e.number&&(s.subVectors(e,t),r.push(n.angleTo(s)))})),r}function cn(t,i){const r=t.clone(),n=new e.Vector3;n.subVectors(i,t);const s=[new e.Vector3,new e.Vector3];let o=0;if(t.eachBondedAtom((e=>{o>1||1!==e.number&&(r.index=e.index,s[o++].subVectors(e,t))})),1===o&&r.eachBondedAtom((e=>{o>1||1!==e.number&&e.index!==t.index&&s[o++].subVectors(e,t)})),2!==o)return;const a=s[0].cross(s[1]);return Math.abs(Math.PI/2-a.angleTo(n))}function ln(t,e){const i=t.structure,r=i.atomCount,n=new Int8Array(r),s=new Int8Array(r),o=new Int8Array(r),a=new Int8Array(r);return i.eachAtom((t=>{const i=t.index,[r,c,l,u]=function(t,e){const i=t.bondToElementCount(1);let r=t.formalCharge||0;const n="always"===e.assignCharge||"auto"===e.assignCharge&&0===r,s="always"===e.assignH||"auto"===e.assignH&&0===i,o=t.bondCount,a=function(t){let e=0;return t.eachBond((t=>e+=t.bondOrder)),e}(t),c=function(t){const e=t.structure.getBondProxy(),i=t.number,r=8===i||7===i;if(r&&4===t.bondCount)return!1;let n=!1;return t.eachBond((i=>{if(i.bondOrder>1)n=!0;else if(r){const r=i.getOtherAtom(t);r.eachBond((t=>{if(t.bondOrder>1){const e=r.number;if((15===e||16===e)&&8===t.getOtherAtom(r).number)return;n=!0}}),e)}})),n}(t),l=a-o>0;let u=0,h=8;switch(t.number){case 1:n&&(0===o?(r=1,h=0):1===o&&(r=0,h=1));break;case 6:n&&(r=0),s&&(u=Math.max(0,4-a-Math.abs(r))),h=sn(o+u+Math.max(0,-r));break;case 7:if(n)if(s)if(c&&a<4)r=o-i==1&&a-i==2?1:0;else{let e=!1;t.eachBondedAtom((t=>{(16===t.number||t.isMetal())&&(e=!0)})),r=e?0:1}else r=a-3;s&&(u=Math.max(0,3-a+r)),h=sn(c&&!l?o+u-r:o+u+1-r);break;case 8:n&&(s||(r=a-2),1===a&&t.eachBondedAtom((e=>{e.eachBond((i=>{const n=i.getOtherAtom(e);n.index!==t.index&&8===n.number&&2===i.bondOrder&&(r=-1)}))}))),s&&(u=Math.max(0,2-a+r)),h=sn(c&&!l?o+u-r+1:o+u-r+2);break;case 16:n&&(s||(r=a<=3&&!t.bondToElementCount(8)?a-2:0)),s&&a<2&&(u=Math.max(0,2-a+r)),a<=3&&(h=sn(o+u-r+2));break;case 9:case 17:case 35:case 53:case 85:n&&(r=a-1);break;case 3:case 11:case 19:case 37:case 55:case 87:n&&(r=1-a);break;case 4:case 12:case 20:case 38:case 56:case 88:n&&(r=2-a);break;default:console.warn("Requested charge, protonation for an unhandled element",t.element)}return[r,u,u+i,h]}(t,e);n[i]=r,s[i]=c,o[i]=l,a[i]=u})),{charge:n,implicitH:s,totalH:o,idealGeometry:a}}function un(t){if(t["@valenceModel"])return t["@valenceModel"];const e=ln(t,{assignCharge:"auto",assignH:"auto"});return t["@valenceModel"]=e,e}function hn(t){return 15===t.number&&t.bondToElementCount(8)===t.bondCount}const dn=["ARG","HIS","LYS"],mn=["GLU","ASP"];function fn(t,e){return 2===t&&1===e||1===t&&2===e}function pn(t,e){return 3===t&&3===e}function gn(t,e){return 3===t&&1===e||1===t&&3===e}function yn(t){return"HIS"===t.resname&&7==t.number&&t.isRing()}function bn(t,e){return 5===t&&4===e||4===t&&5===e}function _n(t,e){return 9===t&&5===e||5===t&&9===e}const xn=[3,11,19,37,55,12,20,38,56,13,31,49,81,21,50,82,83,51,80];function vn(t,e){return 12===t?11===e||12===e:13===t?10===e:void 0}const wn=[17,35,53,85];const An=[7,8,16],Sn=[6,7,15,16];const Cn=T(180),Pn=T(120);function In(t,e,i){return!Mn(t,e,i)&&(t.modelIndex!==e.modelIndex||t.altloc&&e.altloc&&t.altloc!==e.altloc)}const kn={maxHydrophobicDist:4,maxHbondDist:3.5,maxHbondSulfurDist:4.1,maxHbondAccAngle:45,maxHbondDonAngle:45,maxHbondAccPlaneAngle:90,maxHbondDonPlaneAngle:30,maxPiStackingDist:5.5,maxPiStackingOffset:2,maxPiStackingAngle:30,maxCationPiDist:6,maxCationPiOffset:2,maxIonicDist:5,maxHalogenBondDist:4,maxHalogenBondAngle:30,maxMetalDist:3,refineSaltBridges:!0,masterModelIndex:-1,lineOfSightDistFactor:1};function Mn(t,e,i){return t.modelIndex===i&&e.modelIndex!==i||e.modelIndex===i&&t.modelIndex!==i}function Tn(t,e,i){return!Mn(t,e,i)&&(t.modelIndex!==e.modelIndex||t.residueIndex===e.residueIndex||t.altloc&&e.altloc&&t.altloc!==e.altloc)}function Dn(e){const i={types:[],groups:[],centers:{x:[],y:[],z:[]},atomSets:[]};return t.Debug&&Dt.time("calculateFeatures"),function(t,e){const{charge:i}=un(t.data),r={};t.eachResidue((t=>{if(dn.includes(t.resname)){const i=Pr(1);t.eachAtom((t=>{7===t.number&&t.isSidechain()&&Ir(i,t)})),kr(e,i)}else qr.includes(t.resname)||t.isNucleic()||(t.eachAtom((t=>{let i=!1;const n=Pr(1);!function(t){let e=0;return 6===t.number&&3===t.bondCount&&3===t.bondToElementCount(7)&&t.eachBondedAtom((t=>{t.bondCount-t.bondToElementCount(1)==1&&++e})),2===e}(t)?function(t){let e=0;return 6===t.number&&3===t.bondCount&&2===t.bondToElementCount(7)&&1===t.bondToElementCount(6)&&t.eachBondedAtom((t=>{t.bondCount-t.bondToElementCount(1)==1&&++e})),2===e}(t)&&(n.group=9,i=!0):(n.group=8,i=!0),i&&(t.eachBondedAtom((t=>{7===t.number&&(r[t.index]=!0,Ir(n,t))})),kr(e,n))})),t.eachAtom((t=>{const n=Pr(1);i[t.index]>0&&(r[t.index]||(Ir(n,t),kr(e,n)))})))}))}(e,i),function(t,e){const{charge:i}=un(t.data),r={};t.eachResidue((t=>{if(mn.includes(t.resname)){const i=Pr(2);t.eachAtom((t=>{8===t.number&&t.isSidechain()&&Ir(i,t)})),kr(e,i)}else if(Kr.includes(t.resname)){const i=Pr(2);t.eachAtom((t=>{hn(t)&&(i.group=6,t.eachBondedAtom((t=>{8===t.number&&Ir(i,t)})),kr(e,i))}))}else qr.includes(t.resname)||Kr.includes(t.resname)||(t.eachAtom((t=>{let i=!1;const n=Pr(2);!function(t){return 16===t.number&&3===t.bondToElementCount(8)}(t)?hn(t)?(n.group=6,i=!0):function(t){return 16===t.number&&4===t.bondToElementCount(8)}(t)?(n.group=5,i=!0):function(t){let e=0;return 6===t.number&&2===t.bondToElementCount(8)&&1===t.bondToElementCount(6)&&t.eachBondedAtom((t=>{8===t.number&&t.bondCount-t.bondToElementCount(1)==1&&++e})),2===e}(t)&&(n.group=10,i=!0):(n.group=4,i=!0),i&&(t.eachBondedAtom((t=>{8===t.number&&(r[t.index]=!0,Ir(n,t))})),kr(e,n))})),t.eachAtom((t=>{const n=Pr(2);i[t.index]<0&&(r[t.index]||(Ir(n,t),kr(e,n)))})))}))}(e,i),function(t,e){const i=t.getAtomProxy();t.eachResidue((t=>{const r=t.getAromaticRings();if(r){const n=t.atomOffset;r.forEach((t=>{const r=Pr(3);t.forEach((t=>{i.index=t+n,Ir(r,i)})),kr(e,r)}))}}))}(e,i),function(t,e){const{charge:i,implicitH:r,idealGeometry:n}=un(t.data);t.eachAtom((t=>{const s=Pr(5),o=t.number;if(8===o)Ir(s,t),kr(e,s);else if(7===o){if(yn(t))Ir(s,t),kr(e,s);else if(i[t.index]<1){const i=t.bondCount+r[t.index],o=n[t.index];(4===o&&i<4||3===o&&i<3||2===o&&i<2)&&(Ir(s,t),kr(e,s))}}else 16===o&&("CYS"!==t.resname&&"MET"!==t.resname&&-1!==t.formalCharge||(Ir(s,t),kr(e,s)))}))}(e,i),function(t,e){const{totalH:i}=un(t.data);t.eachAtom((t=>{const r=Pr(4),n=t.number;(yn(t)||i[t.index]>0&&(7===n||8===n||16===n))&&(Ir(r,t),kr(e,r))}))}(e,i),function(t,e){const{totalH:i}=un(t.data);t.eachAtom((t=>{if(6===t.number&&i[t.index]>0&&(t.bondToElementCount(7)>0||t.bondToElementCount(8)>0||function(t){if(!t.isAromatic())return!1;const e=t.residueType.getRings();if(!e)return!1;let i=!1;return e.rings.forEach((e=>{i||e.some((e=>t.index-t.residueAtomOffset===e))&&(i=e.some((e=>{const i=t.residueType.atomTypeIdList[e],r=t.atomMap.get(i).number;return 7===r||8===r})))})),i}(t))){const i=Pr(9);Ir(i,t),kr(e,i)}}))}(e,i),function(t,e){t.eachAtom((t=>{let i=!1,r=!1;const n=qr.includes(t.resname),s=Kr.includes(t.resname);if(n||s?n?8===t.number?(["ASP","GLU","SER","THR","TYR","ASN","GLN"].includes(t.resname)&&t.isSidechain()||t.isBackbone())&&(i=!0,r=!0):16===t.number&&"CYS"===t.resname?(i=!0,r=!0):7===t.number&&"HIS"===t.resname&&t.isSidechain()&&(i=!0):s&&(8===t.number&&t.isBackbone()?(i=!0,r=!0):["N3","N4","N7"].includes(t.atomname)?i=!0:["O2","O4","O6"].includes(t.atomname)&&(i=!0,r=!0)):t.isHalogen()||8===t.number||16===t.number?(i=!0,r=!0):7===t.number&&(i=!0),i){const i=Pr(11);Ir(i,t),kr(e,i)}if(r){const i=Pr(10);Ir(i,t),kr(e,i)}}))}(e,i),function(t,e){t.eachAtom((t=>{if(t.isTransitionMetal()||30===t.number||48===t.number){const i=Pr(12);Ir(i,t),kr(e,i)}else if(xn.includes(t.number)){const i=Pr(13);Ir(i,t),kr(e,i)}}))}(e,i),function(t,e){t.eachAtom((t=>{const i=Pr(8);let r=!1;6===t.number?(r=!0,t.eachBondedAtom((t=>{const e=t.number;6!==e&&1!==e&&(r=!1)}))):9===t.number&&(r=!0),r&&(Ir(i,t),kr(e,i))}))}(e,i),function(t,e){t.eachAtom((t=>{if(An.includes(t.number)){let i=!1;if(t.eachBondedAtom((t=>{Sn.includes(t.number)&&(i=!0)})),i){const i=Pr(7);Ir(i,t),kr(e,i)}}}))}(e,i),function(t,e){t.eachAtom((t=>{if(wn.includes(t.number)&&1===t.bondToElementCount(6)){const i=Pr(6);Ir(i,t),kr(e,i)}}))}(e,i),t.Debug&&Dt.timeEnd("calculateFeatures"),i}function Bn(i,r=kn){const n=function(t){const{types:e,centers:i}=t;return{features:t,spatialHash:new xr(i),contactStore:new wr,featureSet:new Sr(e.length,!1)}}(Dn(i));t.Debug&&Dt.time("calculateContacts"),function(t,i,r={}){const n=l(r.maxIonicDist,kn.maxIonicDist),s=l(r.maxPiStackingDist,kn.maxPiStackingDist),o=l(r.maxPiStackingOffset,kn.maxPiStackingOffset),a=l(r.maxPiStackingAngle,kn.maxPiStackingAngle),c=l(r.maxCationPiDist,kn.maxCationPiDist),u=l(r.maxCationPiOffset,kn.maxCationPiOffset),h=l(r.masterModelIndex,kn.masterModelIndex),d=Math.max(n+2,s,c),m=s*s,f=c*c,{features:p,spatialHash:g,contactStore:y,featureSet:b}=i,{types:_,centers:x,atomSets:v}=p,{x:w,y:A,z:S}=x,C=_.length,P=t.atomStore.x,I=t.atomStore.y,k=t.atomStore.z,M=t.getAtomProxy(),T=t.getAtomProxy(),D=function(t,e,i){const r=t.length,n=e.length;for(let s=0;s<r;++s){M.index=t[s];for(let t=0;t<n;++t)if(T.index=e[t],M.distanceTo(T)<=i)return!0}return!1},B=new e.Vector3,F=new e.Vector3,E=new e.Vector3,O=new e.Vector3,$=new e.Vector3,R=new e.Vector3,L=new e.Vector3,N=function(t,e){B.set(P[t[0]],I[t[0]],k[t[0]]),F.set(P[t[1]],I[t[1]],k[t[1]]),E.set(P[t[2]],I[t[2]],k[t[2]]),O.subVectors(B,F),$.subVectors(B,E),e.crossVectors(O,$)},z=function(t,e,i){return B.set(w[t],A[t],S[t]),F.set(w[e],A[e],S[e]),B.sub(F).projectOnPlane(i).add(F).distanceTo(F)},V=function(t,e,i){b.setBits(t,e),y.addContact(t,e,i)};for(let t=0;t<C;++t)g.eachWithin(w[t],A[t],S[t],d,((e,i)=>{if(e<=t)return;if(M.index=v[t][0],T.index=v[e][0],Tn(M,T,h))return;const r=_[t],s=_[e];if(fn(r,s))D(v[t],v[e],n)&&V(t,e,1);else if(pn(r,s)){if(i<=m){N(v[t],R),N(v[e],L);const i=57.29578*R.angleTo(L);Math.min(z(t,e,L),z(e,t,R))<=o&&(i<=a||i>=180-a||i<=a+90&&i>=90-a)&&V(t,e,3)}}else if(gn(r,s)&&i<=f){const[i,n]=3===r?[t,e]:[e,t];N(v[i],R),z(n,i,R)<=u&&V(i,n,2)}}))}(i,n,r),function(t,e,i={}){const r=l(i.maxHbondDist,kn.maxHbondDist),n=l(i.maxHbondSulfurDist,kn.maxHbondSulfurDist),s=T(l(i.maxHbondAccAngle,kn.maxHbondAccAngle)),o=T(l(i.maxHbondDonAngle,kn.maxHbondDonAngle)),a=T(l(i.maxHbondAccPlaneAngle,kn.maxHbondAccPlaneAngle)),c=T(l(i.maxHbondDonPlaneAngle,kn.maxHbondDonPlaneAngle)),u=l(i.masterModelIndex,kn.masterModelIndex),h=Math.max(r,n),d=r*r,{features:m,spatialHash:f,contactStore:p,featureSet:g}=e,{types:y,centers:b,atomSets:_}=m,{x:x,y:v,z:w}=b,A=y.length,{idealGeometry:S}=un(t.data),C=t.getAtomProxy(),P=t.getAtomProxy();for(let t=0;t<A;++t)f.eachWithin(x[t],v[t],w[t],h,((e,i)=>{if(e<=t)return;const r=y[t],n=y[e],l=_n(r,n);if(!l&&!bn(r,n))return;const[h,m]=5===n?[t,e]:[e,t];if(C.index=_[h][0],P.index=_[m][0],P.index===C.index)return;if(Tn(C,P,u))return;if(16!==C.number&&16!==P.number&&i>d)return;if(C.connectedTo(P))return;const f=an(C,P),b=on.get(S[C.index])||T(120);if(f.some((t=>Math.abs(b-t)>o)))return;if(3===S[C.index]){const t=cn(C,P);if(void 0!==t&&t>c)return}const x=an(P,C),v=on.get(S[P.index])||T(120);if(x.some((t=>v-t>s)))return;if(3===S[P.index]){const t=cn(P,C);if(void 0!==t&&t>a)return}g.setBits(h,m);const w=l?8:function(t,e){return t.isWater()&&e.isWater()}(A=C,I=P)?9:function(t,e){return t.isBackbone()&&e.isBackbone()}(A,I)?10:4;var A,I;p.addContact(h,m,w)}))}(i,n,r),function(t,e,i={}){const r=l(i.maxMetalDist,kn.maxMetalDist),n=l(i.masterModelIndex,kn.masterModelIndex),{features:s,spatialHash:o,contactStore:a,featureSet:c}=e,{types:u,centers:h,atomSets:d}=s,{x:m,y:f,z:p}=h,g=u.length,y=t.getAtomProxy(),b=t.getAtomProxy();for(let t=0;t<g;++t)o.eachWithin(m[t],f[t],p[t],r,((e,i)=>{if(e<=t)return;if(y.index=d[t][0],b.index=d[e][0],Tn(y,b,n))return;const r=y.isMetal(),s=b.isMetal();if(!r&&!s)return;const[o,l]=r?[u[t],u[e]]:[u[e],u[t]];vn(o,l)&&(c.setBits(t,e),a.addContact(t,e,7))}))}(i,n,r),function(t,e,i={}){const r=l(i.maxHydrophobicDist,kn.maxHydrophobicDist),n=l(i.masterModelIndex,kn.masterModelIndex),{features:s,spatialHash:o,contactStore:a,featureSet:c}=e,{types:u,centers:h,atomSets:d}=s,{x:m,y:f,z:p}=h,g=u.length,y=t.getAtomProxy(),b=t.getAtomProxy();for(let t=0;t<g;++t)o.eachWithin(m[t],f[t],p[t],r,((e,i)=>{var r,s;e<=t||(y.index=d[t][0],b.index=d[e][0],Tn(y,b,n)||9===y.number&&9===b.number||y.connectedTo(b)||(r=u[t],s=u[e],8===r&&8===s&&(c.setBits(t,e),a.addContact(t,e,6))))}))}(i,n,r),function(t,e,i={}){const r=l(i.maxHalogenBondDist,kn.maxHalogenBondDist),n=T(l(i.maxHalogenBondAngle,kn.maxHalogenBondAngle)),s=l(i.masterModelIndex,kn.masterModelIndex),{features:o,spatialHash:a,contactStore:c,featureSet:u}=e,{types:h,centers:d,atomSets:m}=o,{x:f,y:p,z:g}=d,y=h.length,b=t.getAtomProxy(),_=t.getAtomProxy();for(let t=0;t<y;++t)a.eachWithin(f[t],p[t],g[t],r,((e,i)=>{if(e<=t)return;if(b.index=m[t][0],_.index=m[e][0],Tn(b,_,s))return;if(r=h[t],o=h[e],!(7===r&&6===o||6===r&&7===o))return;var r,o;const[a,l]=6===h[t]?[b,_]:[_,b],d=an(a,l);if(1!==d.length)return;if(Cn-d[0]>n)return;const f=an(l,a);0!==f.length&&(f.some((t=>Pn-t>n))||(u.setBits(t,e),c.addContact(t,e,5)))}))}(i,n,r);const s=function(t){const{index1:e,index2:i,count:r}=t.contactStore,n=Cr({nodeArray1:e,nodeArray2:i,edgeCount:r,nodeCount:t.featureSet.length}),s=new Sr(t.contactStore.count,!0);return Object.assign({adjacencyList:n,contactSet:s},t)}(n);return function(i,r,n={}){t.Debug&&Dt.time("refineLineOfSight");const s=l(n.lineOfSightDistFactor,kn.lineOfSightDistFactor),o=l(n.masterModelIndex,kn.masterModelIndex),a=i.spatialHash,{contactSet:c,contactStore:u,features:h}=r,{index1:d,index2:m}=u,{centers:f,atomSets:p}=h,{x:g,y:y,z:b}=f,_=i.getAtomProxy(),x=i.getAtomProxy(),v=i.getAtomProxy(),w=new e.Vector3,A=new e.Vector3,S=3*s,C=s*s;c.forEach((e=>{w.set(g[d[e]],y[d[e]],b[d[e]]),A.set(g[m[e]],y[m[e]],b[m[e]]);const i=(w.x+A.x)/2,r=(w.y+A.y)/2,n=(w.z+A.z)/2,s=p[d[e]],l=p[m[e]];_.index=s[0],x.index=l[0],a.eachWithin(i,r,n,S,((i,r)=>{v.index=i,1!==v.number&&v.vdw*v.vdw*C>r&&!In(_,v,o)&&!In(x,v,o)&&!s.includes(i)&&!l.includes(i)&&w.distanceToSquared(v)>1&&A.distanceToSquared(v)>1&&(c.clear(e),t.Debug&&Dt.log("removing",_.qualifiedName(),x.qualifiedName(),"because",v.qualifiedName()))}))})),t.Debug&&Dt.timeEnd("refineLineOfSight")}(i,s,r),function(t,e){const{contactSet:i,contactStore:r,features:n}=e,{type:s,index1:o,index2:a}=r,{atomSets:c}=n,l=t.getAtomProxy(),u=t.getAtomProxy(),h={},d=function(t,e,r){const[n,s]=h[r]||[1/0,-1];t<n?(-1!==s&&i.clear(s),h[r]=[t,e]):i.clear(e)};i.forEach((t=>{if(6!==s[t])return;l.index=c[o[t]][0],u.index=c[a[t]][0];const e=l.distanceTo(u);d(e,t,`${l.index}|${u.residueIndex}`),d(e,t,`${u.index}|${l.residueIndex}`)}))}(i,s),r.refineSaltBridges&&function(t,e){const{contactSet:i,contactStore:r,features:n}=e,{type:s,index1:o,index2:a}=r,{atomSets:c}=n,l={},u=function(t,e){l[t]||(l[t]=[]),l[t].push(e)};i.forEach((t=>{1===s[t]&&(c[o[t]].forEach((e=>u(e,t))),c[a[t]].forEach((e=>u(e,t))))})),i.forEach((t=>{if(!function(t){return 4===t||9===t||10===t}(s[t]))return;const e=l[c[o[t]][0]],r=l[c[a[t]][0]];if(!e||!r)return;const n=e.length;for(let s=0;s<n;++s)if(r.includes(e[s]))return void i.clear(t)}))}(0,s),function(t,e){const{contactSet:i,contactStore:r,features:n}=e,{type:s,index1:o,index2:a}=r,{atomSets:c}=n,l={},u=function(t,e){l[t]||(l[t]=[]),l[t].push(e)};i.forEach((t=>{3===s[t]&&(c[o[t]].forEach((e=>u(e,t))),c[a[t]].forEach((e=>u(e,t))))})),i.forEach((t=>{if(6!==s[t]&&2!==s[t])return;const e=l[c[o[t]][0]],r=l[c[a[t]][0]];if(!e||!r)return;const n=e.length;for(let s=0;s<n;++s)if(r.includes(e[s]))return void i.clear(t)}))}(0,s),function(t,e){const{contactSet:i,contactStore:r,features:n}=e,{type:s,index1:o,index2:a}=r,{atomSets:c}=n,l={},u=function(t,e){l[t]||(l[t]=[]),l[t].push(e)};i.forEach((t=>{1===s[t]&&(c[o[t]].forEach((e=>u(e,t))),c[a[t]].forEach((e=>u(e,t))))})),i.forEach((t=>{if(7!==s[t])return;const e=l[c[o[t]][0]],r=l[c[a[t]][0]];if(!e||!r)return;const n=e.length;for(let t=0;t<n;++t)if(r.includes(e[t]))return void i.clear(e[t])}))}(0,s),t.Debug&&Dt.timeEnd("calculateContacts"),s}function Fn(t){switch(t){case 4:case 9:case 10:return"hydrogen bond";case 6:return"hydrophobic contact";case 5:return"halogen bond";case 1:return"ionic interaction";case 7:return"metal coordination";case 2:return"cation-pi interaction";case 3:return"pi-pi stacking";case 8:return"weak hydrogen bond";default:return"unknown contact"}}const En={hydrogenBond:!0,hydrophobic:!0,halogenBond:!0,ionicInteraction:!0,metalCoordination:!0,cationPi:!0,piStacking:!0,weakHydrogenBond:!0,waterHydrogenBond:!0,backboneHydrogenBond:!0,radius:1,filterSele:""},On=new e.Color;function $n(t,e,i){const r=u(i,En),n=[];r.hydrogenBond&&n.push(4),r.hydrophobic&&n.push(6),r.halogenBond&&n.push(5),r.ionicInteraction&&n.push(1),r.metalCoordination&&n.push(7),r.cationPi&&n.push(2),r.piStacking&&n.push(3),r.weakHydrogenBond&&n.push(8),r.waterHydrogenBond&&n.push(9),r.backboneHydrogenBond&&n.push(10);const{features:s,contactSet:o,contactStore:a}=t,{centers:c,atomSets:l}=s,{x:h,y:d,z:m}=c,{index1:f,index2:p,type:g}=a,y=[],b=[],_=[],x=[],v=[];let w;return r.filterSele&&(w=Array.isArray(r.filterSele)?r.filterSele.map((t=>e.getAtomSet(new gt(t)))):e.getAtomSet(new gt(r.filterSele))),o.forEach((t=>{const e=g[t];if(!n.includes(e))return;if(w){const e=l[f[t]][0],i=l[p[t]][0];if(Array.isArray(w)){if(!(w[0].isSet(e)&&w[1].isSet(i)||w[1].isSet(e)&&w[0].isSet(i)))return}else if(!w.isSet(e)&&!w.isSet(i))return}const i=f[t],s=p[t];y.push(h[i],d[i],m[i]),b.push(h[s],d[s],m[s]),_.push(...function(t){switch(t){case 4:case 9:case 10:return On.setHex(2851770).toArray();case 6:return On.setHex(8421504).toArray();case 5:return On.setHex(4259775).toArray();case 1:return On.setHex(15779860).toArray();case 7:return On.setHex(9191577).toArray();case 2:return On.setHex(16744448).toArray();case 3:return On.setHex(9220966).toArray();case 8:return On.setHex(12967404).toArray();default:return On.setHex(13421772).toArray()}}(e)),x.push(r.radius),v.push(t)})),{position1:new Float32Array(y),position2:new Float32Array(b),color:new Float32Array(_),color2:new Float32Array(_),radius:new Float32Array(x),picking:new Un(v,t,e)}}class Rn{constructor(t){this.array=t}get type(){return""}get data(){return{}}getIndex(t){return this.array?this.array[t]:t}getObject(t){return{}}_applyTransformations(t,e,i){return e&&t.applyMatrix4(e.matrix),i&&t.applyMatrix4(i.matrix),t}_getPosition(t){return new e.Vector3}getPosition(t,e,i){return this._applyTransformations(this._getPosition(t),e,i)}}class Ln extends Rn{constructor(t){super(),this.shape=t}get primitive(){}get data(){return this.shape}get type(){return this.primitive.type}getObject(t){return this.primitive.objectFromShape(this.shape,this.getIndex(t))}_getPosition(t){return this.primitive.positionFromShape(this.shape,this.getIndex(t))}}class Nn extends Rn{constructor(t,e){super(t),this.structure=e}get type(){return"atom"}get data(){return this.structure}getObject(t){return this.structure.getAtomProxy(this.getIndex(t))}_getPosition(t){return(new e.Vector3).copy(this.getObject(t))}}class zn extends Rn{constructor(t){super(),this.axes=t}get type(){return"axes"}get data(){return this.axes}getObject(){return{axes:this.axes}}_getPosition(){return this.axes.center.clone()}}class Vn extends Rn{constructor(t,e,i){super(t),this.structure=e,this.bondStore=i||e.bondStore}get type(){return"bond"}get data(){return this.structure}getObject(t){const e=this.structure.getBondProxy(this.getIndex(t));return e.bondStore=this.bondStore,e}_getPosition(t){const i=this.getObject(t);return(new e.Vector3).copy(i.atom1).add(i.atom2).multiplyScalar(.5)}}class Un extends Rn{constructor(t,e,i){super(t),this.contacts=e,this.structure=i}get type(){return"contact"}get data(){return this.contacts}getObject(t){const i=this.getIndex(t),{features:r,contactStore:n}=this.contacts,{centers:s,atomSets:o}=r,{x:a,y:c,z:l}=s,{index1:u,index2:h,type:d}=n,m=u[i],f=h[i];return{center1:new e.Vector3(a[m],c[m],l[m]),center2:new e.Vector3(a[f],c[f],l[f]),atom1:this.structure.getAtomProxy(o[m][0]),atom2:this.structure.getAtomProxy(o[f][0]),type:Fn(d[i])}}_getPosition(t){const{center1:i,center2:r}=this.getObject(t);return(new e.Vector3).addVectors(i,r).multiplyScalar(.5)}}class jn extends Rn{constructor(t,e,i){super(t),this.validation=e,this.structure=i}get type(){return"clash"}get data(){return this.validation}getObject(t){const e=this.validation,i=this.getIndex(t);return{validation:e,index:i,clash:e.clashArray[i]}}_getAtomProxyFromSele(t){const e=new gt(t),i=this.structure.getAtomIndices(e)[0];return this.structure.getAtomProxy(i)}_getPosition(t){const i=this.getObject(t).clash,r=this._getAtomProxyFromSele(i.sele1),n=this._getAtomProxyFromSele(i.sele2);return(new e.Vector3).copy(r).add(n).multiplyScalar(.5)}}class Gn extends Vn{get type(){return"distance"}}class Hn extends Rn{get type(){return"ignore"}}class qn extends Ln{constructor(t,e){super(t),this.mesh=e}get type(){return"mesh"}getObject(){const t=this.mesh;return{shape:this.shape,name:t.name,serial:t.serial}}_getPosition(){return this.__position||(this.__position=Bi(this.mesh.position)),this.__position}}class Wn extends Rn{constructor(t,e){super(t),this.surface=e}get type(){return"surface"}get data(){return this.surface}getObject(t){return{surface:this.surface,index:this.getIndex(t)}}_getPosition(){return this.surface.center.clone()}}class Xn extends Rn{constructor(t,e){super(),this.unitcell=t,this.structure=e}get type(){return"unitcell"}get data(){return this.unitcell}getObject(){return{unitcell:this.unitcell,structure:this.structure}}_getPosition(){return this.unitcell.getCenter(this.structure)}}class Yn extends Rn{constructor(t,e){super(t),this.volume=e}get type(){return"volume"}get data(){return this.volume}getObject(t){const e=this.volume,i=this.getIndex(t);return{volume:e,index:i,value:e.data[i]}}_getPosition(t){const i=this.volume.position,r=this.getIndex(t);return new e.Vector3(i[3*r],i[3*r+1],i[3*r+2])}}class Kn extends Yn{get type(){return"slice"}}function Zn(){return new Uint32Array([0,265,515,778,1030,1295,1541,1804,2060,2309,2575,2822,3082,3331,3593,3840,400,153,915,666,1430,1183,1941,1692,2460,2197,2975,2710,3482,3219,3993,3728,560,825,51,314,1590,1855,1077,1340,2620,2869,2111,2358,3642,3891,3129,3376,928,681,419,170,1958,1711,1445,1196,2988,2725,2479,2214,4010,3747,3497,3232,1120,1385,1635,1898,102,367,613,876,3180,3429,3695,3942,2154,2403,2665,2912,1520,1273,2035,1786,502,255,1013,764,3580,3317,4095,3830,2554,2291,3065,2800,1616,1881,1107,1370,598,863,85,348,3676,3925,3167,3414,2650,2899,2137,2384,1984,1737,1475,1226,966,719,453,204,4044,3781,3535,3270,3018,2755,2505,2240,2240,2505,2755,3018,3270,3535,3781,4044,204,453,719,966,1226,1475,1737,1984,2384,2137,2899,2650,3414,3167,3925,3676,348,85,863,598,1370,1107,1881,1616,2800,3065,2291,2554,3830,4095,3317,3580,764,1013,255,502,1786,2035,1273,1520,2912,2665,2403,2154,3942,3695,3429,3180,876,613,367,102,1898,1635,1385,1120,3232,3497,3747,4010,2214,2479,2725,2988,1196,1445,1711,1958,170,419,681,928,3376,3129,3891,3642,2358,2111,2869,2620,1340,1077,1855,1590,314,51,825,560,3728,3993,3219,3482,2710,2975,2197,2460,1692,1941,1183,1430,666,915,153,400,3840,3593,3331,3082,2822,2575,2309,2060,1804,1541,1295,1030,778,515,265,0])}function Qn(){return new Int32Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,9,8,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,2,10,0,2,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,8,3,2,10,8,10,9,8,-1,-1,-1,-1,-1,-1,-1,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,8,11,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,11,2,1,9,11,9,8,11,-1,-1,-1,-1,-1,-1,-1,3,10,1,11,10,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,10,1,0,8,10,8,11,10,-1,-1,-1,-1,-1,-1,-1,3,9,0,3,11,9,11,10,9,-1,-1,-1,-1,-1,-1,-1,9,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,7,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,1,9,4,7,1,7,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,4,7,3,0,4,1,2,10,-1,-1,-1,-1,-1,-1,-1,9,2,10,9,0,2,8,4,7,-1,-1,-1,-1,-1,-1,-1,2,10,9,2,9,7,2,7,3,7,9,4,-1,-1,-1,-1,8,4,7,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,4,7,11,2,4,2,0,4,-1,-1,-1,-1,-1,-1,-1,9,0,1,8,4,7,2,3,11,-1,-1,-1,-1,-1,-1,-1,4,7,11,9,4,11,9,11,2,9,2,1,-1,-1,-1,-1,3,10,1,3,11,10,7,8,4,-1,-1,-1,-1,-1,-1,-1,1,11,10,1,4,11,1,0,4,7,11,4,-1,-1,-1,-1,4,7,8,9,0,11,9,11,10,11,0,3,-1,-1,-1,-1,4,7,11,4,11,9,9,11,10,-1,-1,-1,-1,-1,-1,-1,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,5,4,1,5,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,5,4,8,3,5,3,1,5,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,10,4,9,5,-1,-1,-1,-1,-1,-1,-1,5,2,10,5,4,2,4,0,2,-1,-1,-1,-1,-1,-1,-1,2,10,5,3,2,5,3,5,4,3,4,8,-1,-1,-1,-1,9,5,4,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,0,8,11,4,9,5,-1,-1,-1,-1,-1,-1,-1,0,5,4,0,1,5,2,3,11,-1,-1,-1,-1,-1,-1,-1,2,1,5,2,5,8,2,8,11,4,8,5,-1,-1,-1,-1,10,3,11,10,1,3,9,5,4,-1,-1,-1,-1,-1,-1,-1,4,9,5,0,8,1,8,10,1,8,11,10,-1,-1,-1,-1,5,4,0,5,0,11,5,11,10,11,0,3,-1,-1,-1,-1,5,4,8,5,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,9,7,8,5,7,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,3,0,9,5,3,5,7,3,-1,-1,-1,-1,-1,-1,-1,0,7,8,0,1,7,1,5,7,-1,-1,-1,-1,-1,-1,-1,1,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,7,8,9,5,7,10,1,2,-1,-1,-1,-1,-1,-1,-1,10,1,2,9,5,0,5,3,0,5,7,3,-1,-1,-1,-1,8,0,2,8,2,5,8,5,7,10,5,2,-1,-1,-1,-1,2,10,5,2,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,7,9,5,7,8,9,3,11,2,-1,-1,-1,-1,-1,-1,-1,9,5,7,9,7,2,9,2,0,2,7,11,-1,-1,-1,-1,2,3,11,0,1,8,1,7,8,1,5,7,-1,-1,-1,-1,11,2,1,11,1,7,7,1,5,-1,-1,-1,-1,-1,-1,-1,9,5,8,8,5,7,10,1,3,10,3,11,-1,-1,-1,-1,5,7,0,5,0,9,7,11,0,1,0,10,11,10,0,-1,11,10,0,11,0,3,10,5,0,8,0,7,5,7,0,-1,11,10,5,7,11,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,0,1,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,1,9,8,5,10,6,-1,-1,-1,-1,-1,-1,-1,1,6,5,2,6,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,6,5,1,2,6,3,0,8,-1,-1,-1,-1,-1,-1,-1,9,6,5,9,0,6,0,2,6,-1,-1,-1,-1,-1,-1,-1,5,9,8,5,8,2,5,2,6,3,2,8,-1,-1,-1,-1,2,3,11,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,0,8,11,2,0,10,6,5,-1,-1,-1,-1,-1,-1,-1,0,1,9,2,3,11,5,10,6,-1,-1,-1,-1,-1,-1,-1,5,10,6,1,9,2,9,11,2,9,8,11,-1,-1,-1,-1,6,3,11,6,5,3,5,1,3,-1,-1,-1,-1,-1,-1,-1,0,8,11,0,11,5,0,5,1,5,11,6,-1,-1,-1,-1,3,11,6,0,3,6,0,6,5,0,5,9,-1,-1,-1,-1,6,5,9,6,9,11,11,9,8,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,4,7,3,6,5,10,-1,-1,-1,-1,-1,-1,-1,1,9,0,5,10,6,8,4,7,-1,-1,-1,-1,-1,-1,-1,10,6,5,1,9,7,1,7,3,7,9,4,-1,-1,-1,-1,6,1,2,6,5,1,4,7,8,-1,-1,-1,-1,-1,-1,-1,1,2,5,5,2,6,3,0,4,3,4,7,-1,-1,-1,-1,8,4,7,9,0,5,0,6,5,0,2,6,-1,-1,-1,-1,7,3,9,7,9,4,3,2,9,5,9,6,2,6,9,-1,3,11,2,7,8,4,10,6,5,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,2,4,2,0,2,7,11,-1,-1,-1,-1,0,1,9,4,7,8,2,3,11,5,10,6,-1,-1,-1,-1,9,2,1,9,11,2,9,4,11,7,11,4,5,10,6,-1,8,4,7,3,11,5,3,5,1,5,11,6,-1,-1,-1,-1,5,1,11,5,11,6,1,0,11,7,11,4,0,4,11,-1,0,5,9,0,6,5,0,3,6,11,6,3,8,4,7,-1,6,5,9,6,9,11,4,7,9,7,11,9,-1,-1,-1,-1,10,4,9,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,10,6,4,9,10,0,8,3,-1,-1,-1,-1,-1,-1,-1,10,0,1,10,6,0,6,4,0,-1,-1,-1,-1,-1,-1,-1,8,3,1,8,1,6,8,6,4,6,1,10,-1,-1,-1,-1,1,4,9,1,2,4,2,6,4,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,9,2,4,9,2,6,4,-1,-1,-1,-1,0,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,3,2,8,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,10,4,9,10,6,4,11,2,3,-1,-1,-1,-1,-1,-1,-1,0,8,2,2,8,11,4,9,10,4,10,6,-1,-1,-1,-1,3,11,2,0,1,6,0,6,4,6,1,10,-1,-1,-1,-1,6,4,1,6,1,10,4,8,1,2,1,11,8,11,1,-1,9,6,4,9,3,6,9,1,3,11,6,3,-1,-1,-1,-1,8,11,1,8,1,0,11,6,1,9,1,4,6,4,1,-1,3,11,6,3,6,0,0,6,4,-1,-1,-1,-1,-1,-1,-1,6,4,8,11,6,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,10,6,7,8,10,8,9,10,-1,-1,-1,-1,-1,-1,-1,0,7,3,0,10,7,0,9,10,6,7,10,-1,-1,-1,-1,10,6,7,1,10,7,1,7,8,1,8,0,-1,-1,-1,-1,10,6,7,10,7,1,1,7,3,-1,-1,-1,-1,-1,-1,-1,1,2,6,1,6,8,1,8,9,8,6,7,-1,-1,-1,-1,2,6,9,2,9,1,6,7,9,0,9,3,7,3,9,-1,7,8,0,7,0,6,6,0,2,-1,-1,-1,-1,-1,-1,-1,7,3,2,6,7,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,11,10,6,8,10,8,9,8,6,7,-1,-1,-1,-1,2,0,7,2,7,11,0,9,7,6,7,10,9,10,7,-1,1,8,0,1,7,8,1,10,7,6,7,10,2,3,11,-1,11,2,1,11,1,7,10,6,1,6,7,1,-1,-1,-1,-1,8,9,6,8,6,7,9,1,6,11,6,3,1,3,6,-1,0,9,1,11,6,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,0,7,0,6,3,11,0,11,6,0,-1,-1,-1,-1,7,11,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,1,9,8,3,1,11,7,6,-1,-1,-1,-1,-1,-1,-1,10,1,2,6,11,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,8,6,11,7,-1,-1,-1,-1,-1,-1,-1,2,9,0,2,10,9,6,11,7,-1,-1,-1,-1,-1,-1,-1,6,11,7,2,10,3,10,8,3,10,9,8,-1,-1,-1,-1,7,2,3,6,2,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,0,8,7,6,0,6,2,0,-1,-1,-1,-1,-1,-1,-1,2,7,6,2,3,7,0,1,9,-1,-1,-1,-1,-1,-1,-1,1,6,2,1,8,6,1,9,8,8,7,6,-1,-1,-1,-1,10,7,6,10,1,7,1,3,7,-1,-1,-1,-1,-1,-1,-1,10,7,6,1,7,10,1,8,7,1,0,8,-1,-1,-1,-1,0,3,7,0,7,10,0,10,9,6,10,7,-1,-1,-1,-1,7,6,10,7,10,8,8,10,9,-1,-1,-1,-1,-1,-1,-1,6,8,4,11,8,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,6,11,3,0,6,0,4,6,-1,-1,-1,-1,-1,-1,-1,8,6,11,8,4,6,9,0,1,-1,-1,-1,-1,-1,-1,-1,9,4,6,9,6,3,9,3,1,11,3,6,-1,-1,-1,-1,6,8,4,6,11,8,2,10,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,11,0,6,11,0,4,6,-1,-1,-1,-1,4,11,8,4,6,11,0,2,9,2,10,9,-1,-1,-1,-1,10,9,3,10,3,2,9,4,3,11,3,6,4,6,3,-1,8,2,3,8,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,0,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,4,2,4,6,4,3,8,-1,-1,-1,-1,1,9,4,1,4,2,2,4,6,-1,-1,-1,-1,-1,-1,-1,8,1,3,8,6,1,8,4,6,6,10,1,-1,-1,-1,-1,10,1,0,10,0,6,6,0,4,-1,-1,-1,-1,-1,-1,-1,4,6,3,4,3,8,6,10,3,0,3,9,10,9,3,-1,10,9,4,6,10,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,5,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,5,11,7,6,-1,-1,-1,-1,-1,-1,-1,5,0,1,5,4,0,7,6,11,-1,-1,-1,-1,-1,-1,-1,11,7,6,8,3,4,3,5,4,3,1,5,-1,-1,-1,-1,9,5,4,10,1,2,7,6,11,-1,-1,-1,-1,-1,-1,-1,6,11,7,1,2,10,0,8,3,4,9,5,-1,-1,-1,-1,7,6,11,5,4,10,4,2,10,4,0,2,-1,-1,-1,-1,3,4,8,3,5,4,3,2,5,10,5,2,11,7,6,-1,7,2,3,7,6,2,5,4,9,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,6,0,6,2,6,8,7,-1,-1,-1,-1,3,6,2,3,7,6,1,5,0,5,4,0,-1,-1,-1,-1,6,2,8,6,8,7,2,1,8,4,8,5,1,5,8,-1,9,5,4,10,1,6,1,7,6,1,3,7,-1,-1,-1,-1,1,6,10,1,7,6,1,0,7,8,7,0,9,5,4,-1,4,0,10,4,10,5,0,3,10,6,10,7,3,7,10,-1,7,6,10,7,10,8,5,4,10,4,8,10,-1,-1,-1,-1,6,9,5,6,11,9,11,8,9,-1,-1,-1,-1,-1,-1,-1,3,6,11,0,6,3,0,5,6,0,9,5,-1,-1,-1,-1,0,11,8,0,5,11,0,1,5,5,6,11,-1,-1,-1,-1,6,11,3,6,3,5,5,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,11,9,11,8,11,5,6,-1,-1,-1,-1,0,11,3,0,6,11,0,9,6,5,6,9,1,2,10,-1,11,8,5,11,5,6,8,0,5,10,5,2,0,2,5,-1,6,11,3,6,3,5,2,10,3,10,5,3,-1,-1,-1,-1,5,8,9,5,2,8,5,6,2,3,8,2,-1,-1,-1,-1,9,5,6,9,6,0,0,6,2,-1,-1,-1,-1,-1,-1,-1,1,5,8,1,8,0,5,6,8,3,8,2,6,2,8,-1,1,5,6,2,1,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,6,1,6,10,3,8,6,5,6,9,8,9,6,-1,10,1,0,10,0,6,9,5,0,5,6,0,-1,-1,-1,-1,0,3,8,5,6,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,7,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,11,7,5,8,3,0,-1,-1,-1,-1,-1,-1,-1,5,11,7,5,10,11,1,9,0,-1,-1,-1,-1,-1,-1,-1,10,7,5,10,11,7,9,8,1,8,3,1,-1,-1,-1,-1,11,1,2,11,7,1,7,5,1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,7,1,7,5,7,2,11,-1,-1,-1,-1,9,7,5,9,2,7,9,0,2,2,11,7,-1,-1,-1,-1,7,5,2,7,2,11,5,9,2,3,2,8,9,8,2,-1,2,5,10,2,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,8,2,0,8,5,2,8,7,5,10,2,5,-1,-1,-1,-1,9,0,1,5,10,3,5,3,7,3,10,2,-1,-1,-1,-1,9,8,2,9,2,1,8,7,2,10,2,5,7,5,2,-1,1,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,7,0,7,1,1,7,5,-1,-1,-1,-1,-1,-1,-1,9,0,3,9,3,5,5,3,7,-1,-1,-1,-1,-1,-1,-1,9,8,7,5,9,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,5,8,4,5,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,5,0,4,5,11,0,5,10,11,11,3,0,-1,-1,-1,-1,0,1,9,8,4,10,8,10,11,10,4,5,-1,-1,-1,-1,10,11,4,10,4,5,11,3,4,9,4,1,3,1,4,-1,2,5,1,2,8,5,2,11,8,4,5,8,-1,-1,-1,-1,0,4,11,0,11,3,4,5,11,2,11,1,5,1,11,-1,0,2,5,0,5,9,2,11,5,4,5,8,11,8,5,-1,9,4,5,2,11,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,5,10,3,5,2,3,4,5,3,8,4,-1,-1,-1,-1,5,10,2,5,2,4,4,2,0,-1,-1,-1,-1,-1,-1,-1,3,10,2,3,5,10,3,8,5,4,5,8,0,1,9,-1,5,10,2,5,2,4,1,9,2,9,4,2,-1,-1,-1,-1,8,4,5,8,5,3,3,5,1,-1,-1,-1,-1,-1,-1,-1,0,4,5,1,0,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,4,5,8,5,3,9,0,5,0,3,5,-1,-1,-1,-1,9,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,11,7,4,9,11,9,10,11,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,7,9,11,7,9,10,11,-1,-1,-1,-1,1,10,11,1,11,4,1,4,0,7,4,11,-1,-1,-1,-1,3,1,4,3,4,8,1,10,4,7,4,11,10,11,4,-1,4,11,7,9,11,4,9,2,11,9,1,2,-1,-1,-1,-1,9,7,4,9,11,7,9,1,11,2,11,1,0,8,3,-1,11,7,4,11,4,2,2,4,0,-1,-1,-1,-1,-1,-1,-1,11,7,4,11,4,2,8,3,4,3,2,4,-1,-1,-1,-1,2,9,10,2,7,9,2,3,7,7,4,9,-1,-1,-1,-1,9,10,7,9,7,4,10,2,7,8,7,0,2,0,7,-1,3,7,10,3,10,2,7,4,10,1,10,0,4,0,10,-1,1,10,2,8,7,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,7,1,3,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,0,8,1,8,7,1,-1,-1,-1,-1,4,0,3,7,4,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,8,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,11,9,10,-1,-1,-1,-1,-1,-1,-1,0,1,10,0,10,8,8,10,11,-1,-1,-1,-1,-1,-1,-1,3,1,10,11,3,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,11,1,11,9,9,11,8,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,1,2,9,2,11,9,-1,-1,-1,-1,0,2,11,8,0,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,10,8,9,-1,-1,-1,-1,-1,-1,-1,9,10,2,0,9,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,0,1,8,1,10,8,-1,-1,-1,-1,1,10,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,8,9,1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,9,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,3,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1])}function Jn(t,e,i,r,n){var s,o,a,c,l,u,h,d=[[0,4,4,4,2,0,0,0,2,2,0,0],[4,0,4,4,0,8,0,0,0,8,8,0],[4,4,0,4,0,0,8,0,0,0,8,8],[4,4,4,0,0,0,0,1,1,0,0,1],[2,0,0,0,0,8,8,8,2,2,0,0],[0,8,0,0,8,0,8,8,0,8,8,0],[0,0,8,0,8,8,0,8,0,0,8,8],[0,0,0,1,8,8,8,0,1,0,0,1],[2,0,0,1,2,0,0,1,0,2,0,1],[2,8,0,0,2,8,0,0,2,0,8,0],[0,8,8,0,0,8,8,0,0,8,0,8],[0,0,8,1,0,0,8,1,1,0,8,0]],m=0,f=!1,p=!1,g=!1,y=!1,b=-1,_=e*i*r,x=e,w=e*i,A=new Int32Array(12),S=[],C=[],P=[],I=[],k=Zn(),M=Qn();function T(t,e,i){return t+(e-t)*i}function D(t,n,s){return w*(s=(s+h)%r)+x*(n=(n+u)%i)+(t=(t+l)%e)}function B(t,e,i,r,c,l,u){var h=3*t;if(o[h]<0){var d=(m-l)/(u-l),p=s,g=3*a;if(S[g]=i+d,S[g+1]=r,S[g+2]=c,!f){var y=3*t;C[g]=b*T(p[y],p[y+3],d),C[g+1]=b*T(p[y+1],p[y+4],d),C[g+2]=b*T(p[y+2],p[y+5],d)}n&&(I[a]=n[t+Math.round(d)]),o[h]=a,A[e]=a,a+=1}else A[e]=o[h]}function F(t,e,i,r,c,l,u){var h=3*t+1;if(o[h]<0){var d=(m-l)/(u-l),p=s,g=3*a;if(S[g]=i,S[g+1]=r+d,S[g+2]=c,!f){var y=3*t,_=y+3*x;C[g]=b*T(p[y],p[_],d),C[g+1]=b*T(p[y+1],p[_+1],d),C[g+2]=b*T(p[y+2],p[_+2],d)}n&&(I[a]=n[t+Math.round(d)*x]),o[h]=a,A[e]=a,a+=1}else A[e]=o[h]}function E(t,e,i,r,c,l,u){var h=3*t+2;if(o[h]<0){var d=(m-l)/(u-l),p=s,g=3*a;if(S[g]=i,S[g+1]=r,S[g+2]=c+d,!f){var y=3*t,_=y+3*w;C[g]=b*T(p[y],p[_],d),C[g+1]=b*T(p[y+1],p[_+1],d),C[g+2]=b*T(p[y+2],p[_+2],d)}n&&(I[a]=n[t+Math.round(d)*w]),o[h]=a,A[e]=a,a+=1}else A[e]=o[h]}function O(e){var i=3*e;0===s[i]&&(s[i]=t[(e-1+_)%_]-t[(e+1)%_],s[i+1]=t[(e-x+_)%_]-t[(e+x)%_],s[i+2]=t[(e-w+_)%_]-t[(e+w)%_])}function $(e,i,r,n,s){var o,a,l,u,h,b,_;g?(n=D(e,i,r),o=D(e+1,i,r),a=D(e,i+1,r),l=D(e,i,r+1),u=D(e+1,i+1,r),h=D(e+1,i,r+1),b=D(e,i+1,r+1),_=D(e+1,i+1,r+1)):(o=n+1,u=(a=n+x)+1,h=(l=n+w)+1,_=(b=a+w)+1);var v=0,S=t[n],C=t[o],I=t[a],T=t[u],$=t[l],R=t[h],L=t[b],N=t[_];S<m&&(v|=1),C<m&&(v|=2),I<m&&(v|=8),T<m&&(v|=4),$<m&&(v|=16),R<m&&(v|=32),L<m&&(v|=128),N<m&&(v|=64);var z=k[v];if(0===z)return 0;var V=e+1,U=i+1,j=r+1;1&z&&(f||(O(n),O(o)),B(n,0,e,i,r,S,C)),2&z&&(f||(O(o),O(u)),F(o,1,V,i,r,C,T)),4&z&&(f||(O(a),O(u)),B(a,2,e,U,r,I,T)),8&z&&(f||(O(n),O(a)),F(n,3,e,i,r,S,I)),16&z&&(f||(O(l),O(h)),B(l,4,e,i,j,$,R)),32&z&&(f||(O(h),O(_)),F(h,5,V,i,j,R,N)),64&z&&(f||(O(b),O(_)),B(b,6,e,U,j,L,N)),128&z&&(f||(O(l),O(b)),F(l,7,e,i,j,$,L)),256&z&&(f||(O(n),O(l)),E(n,8,e,i,r,S,$)),512&z&&(f||(O(o),O(h)),E(o,9,V,i,r,C,R)),1024&z&&(f||(O(u),O(_)),E(u,10,V,U,r,T,N)),2048&z&&(f||(O(a),O(b)),E(a,11,e,U,r,I,L));for(var G,H,q,W=v<<4,X=0;-1!==M[W+X];)G=M[W+X],H=M[W+X+1],q=M[W+X+2],p?(d[G][H]&s&&(P[c++]=A[G],P[c++]=A[H]),d[H][q]&s&&(P[c++]=A[H],P[c++]=A[q]),d[G][q]&s&&(P[c++]=A[G],P[c++]=A[q])):(P[c++]=A[y?G:H],P[c++]=A[y?H:G],P[c++]=A[q]),X+=3}function R(n,s,a,c,l,u){let h,d,p,y,b,_,v,A,S,C,P,I,k;if(n=void 0!==n?n:0,s=void 0!==s?s:0,a=void 0!==a?a:0,c=void 0!==c?c:e-1,l=void 0!==l?l:i-1,u=void 0!==u?u:r-1,g||(f?(n=Math.max(0,n),s=Math.max(0,s),a=Math.max(0,a),c=Math.min(e-1,c),l=Math.min(i-1,l),u=Math.min(r-1,u)):(n=Math.max(1,n),s=Math.max(1,s),a=Math.max(1,a),c=Math.min(e-2,c),l=Math.min(i-2,l),u=Math.min(r-2,u))),g)for(A=n-2,S=s-2,C=a-2,P=c+2,I=l+2,k=u+2,b=C;b<k;++b)for(y=S;y<I;++y)for(p=A;p<P;++p)d=3*D(p,y,b),o[d]=-1,o[d+1]=-1,o[d+2]=-1;else for(A=Math.max(0,n-2),S=Math.max(0,s-2),C=Math.max(0,a-2),P=Math.min(e,c+2),I=Math.min(i,l+2),k=Math.min(r,u+2),b=C;b<k;++b)for(v=w*b,y=S;y<I;++y)for(_=v+x*y,p=A;p<P;++p)h=3*(_+p),o[h]=-1,o[h+1]=-1,o[h+2]=-1;if(!g){var M,T=n,B=s,F=a,E=c,O=l,R=u;for(M=!1,b=a;b<u;++b){for(y=s;y<l;++y){for(p=n;p<c;++p)if(h=e*i*b+e*y+p,t[h]>=m){F=b,M=!0;break}if(M)break}if(M)break}for(M=!1,y=s;y<l;++y){for(b=F;b<u;++b){for(p=n;p<c;++p)if(h=e*i*b+e*y+p,t[h]>=m){B=y,M=!0;break}if(M)break}if(M)break}for(M=!1,p=n;p<c;++p){for(y=B;y<l;++y){for(b=F;b<u;++b)if(h=e*i*b+e*y+p,t[h]>=m){T=p,M=!0;break}if(M)break}if(M)break}for(M=!1,b=u;b>=a;--b){for(y=l;y>=s;--y){for(p=c;p>=n;--p)if(h=e*i*b+e*y+p,t[h]>=m){R=b,M=!0;break}if(M)break}if(M)break}for(M=!1,y=l;y>=s;--y){for(b=R;b>=a;--b){for(p=c;p>=n;--p)if(h=e*i*b+e*y+p,t[h]>=m){O=y,M=!0;break}if(M)break}if(M)break}for(M=!1,p=c;p>=n;--p){for(y=O;y>=s;--y){for(b=R;b>=a;--b)if(h=e*i*b+e*y+p,t[h]>=m){E=p,M=!0;break}if(M)break}if(M)break}f?(n=Math.max(0,T-1),s=Math.max(0,B-1),a=Math.max(0,F-1),c=Math.min(e-1,E+1),l=Math.min(i-1,O+1),u=Math.min(r-1,R+1)):(n=Math.max(1,T-1),s=Math.max(1,B-1),a=Math.max(1,F-1),c=Math.min(e-2,E+1),l=Math.min(i-2,O+1),u=Math.min(r-2,R+1))}var L=15;for(b=a;b<u;++b,L&=-5)for(v=w*b,L|=2,y=s;y<l;++y,L&=-3)for(_=v+x*y,L|=1,p=n;p<c;++p,L&=-2)h=_+p,$(p,y,b,h,L)}this.triangulate=function(t,d,x,w,A){y=(m=t)<0,p=w,g=A,(f=d||p)||(b=m>0?-1:1,s||(s=new Float32Array(3*_)));var k=3*_;if(o&&o.length===k||(o=new Int32Array(k)),a=0,c=0,void 0!==x){var M=x[0].map(Math.round),T=x[1].map(Math.round);l=e*Math.ceil(Math.abs(M[0])/e),u=i*Math.ceil(Math.abs(M[1])/i),h=r*Math.ceil(Math.abs(M[2])/r),R(M[0],M[1],M[2],T[0],T[1],T[2])}else l=u=h=0,R();return S.length=3*a,f||(C.length=3*a),P.length=c,n&&(I.length=a),{position:new Float32Array(S),normal:f?void 0:new Float32Array(C),index:v(P,S.length/3),atomindex:n?new Int32Array(I):void 0,contour:p}}}Gt.add("arrow",class extends Ln{get primitive(){return mr}}),Gt.add("box",class extends Ln{get primitive(){return cr}}),Gt.add("cone",class extends Ln{get primitive(){return fr}}),Gt.add("cylinder",class extends Ln{get primitive(){return dr}}),Gt.add("ellipsoid",class extends Ln{get primitive(){return pr}}),Gt.add("icosahedron",class extends Ln{get primitive(){return hr}}),Gt.add("octahedron",class extends Ln{get primitive(){return lr}}),Gt.add("sphere",class extends Ln{get primitive(){return ar}}),Gt.add("tetrahedron",class extends Ln{get primitive(){return ur}}),Gt.add("torus",class extends Ln{get primitive(){return gr}}),Gt.add("point",class extends Ln{get primitive(){return br}}),Gt.add("wideline",class extends Ln{get primitive(){return _r}}),Object.assign(Jn,{__deps:[Zn,Qn,v]});class ts{constructor(t,e){this.cols=t,this.rows=e,this.size=this.cols*this.rows,this.data=new Float32Array(this.size)}copyTo(t){t.data.set(this.data)}}function es(t,e){let i=0,r=0;const n=e.rows,s=e.cols;let o=0,a=0,c=0;const l=e.data,u=t.data;for(;i<n;a+=1,o+=s,i++)for(c=a,r=0;r<s;c+=n,r++)u[c]=l[o+r]}function is(t,e,i){let r=0,n=0,s=0,o=0,a=0,c=0,l=0;const u=e.cols,h=e.rows,d=i.rows,m=e.data,f=i.data,p=t.data;let g=0;for(;r<h;o+=u,r++)for(c=0,n=0;n<d;l++,n++){for(a=o,g=0,s=0;s<u;a++,c++,s++)g+=m[a]*f[c];p[l]=g}}function rs(t,e,i){const r=t.data,n=e.data,s=i.data,o=n[0],a=n[1],c=n[2],l=n[3],u=n[4],h=n[5],d=n[6],m=n[7],f=n[8],p=s[0],g=s[1],y=s[2],b=s[3],_=s[4],x=s[5],v=s[6],w=s[7],A=s[8];r[0]=o*p+a*b+c*v,r[1]=o*g+a*_+c*w,r[2]=o*y+a*x+c*A,r[3]=l*p+u*b+h*v,r[4]=l*g+u*_+h*w,r[5]=l*y+u*x+h*A,r[6]=d*p+m*b+f*v,r[7]=d*g+m*_+f*w,r[8]=d*y+m*x+f*A}function ns(t){const e=t.rows,i=t.cols,r=t.data,n=new Array(i);for(let t=0;t<i;++t)n[t]=0;for(let t=0,s=0;t<e;++t)for(let t=0;t<i;++t,++s)n[t]+=r[s];for(let t=0;t<i;++t)n[t]/=e;return n}function ss(t,e){const i=t.rows,r=t.cols,n=t.data;for(let t=0,s=0;t<i;++t)for(let t=0;t<r;++t,++s)n[s]-=e[t]}function os(t,e,i,r){r=t[e],t[e]=t[i],t[i]=r}function as(t,e){return(t=Math.abs(t))>(e=Math.abs(e))?(e/=t,t*Math.sqrt(1+e*e)):e>0?(t/=e,e*Math.sqrt(1+t*t)):0}const cs=1.192092896e-7,ls=1e-37;function us(t,e,i,r){let n=0,s=0;const o=t.rows,a=t.cols;let c=o,l=a;c<l&&(n=1,s=c,c=l,l=s);const u=new ts(c,c),h=new ts(1,l),d=new ts(l,l);if(0===n)es(u,t);else{for(s=0;s<a*o;s++)u.data[s]=t.data[s];for(;s<l*c;s++)u.data[s]=0}if(function(t,e,i,r,n,s,o,a){const c=2*cs,l=ls;let u=0,h=0,d=0,m=0;const f=Math.max(s,30);let p=0,g=0,y=0,b=0,_=0,x=0,v=0,w=0,A=0,S=0,C=0,P=0,I=0,k=0,M=0,T=0,D=0,B=4660,F=0,E=0,O=0;const $=new Float64Array(o<<3);for(;u<o;u++){for(d=0,C=0;d<s;d++)w=t[u*e+d],C+=w*w;if($[u]=C,r){for(d=0;d<o;d++)r[u*n+d]=0;r[u*n+u]=1}}for(;m<f;m++){for(_=0,u=0;u<o-1;u++)for(h=u+1;h<o;h++){for(p=u*e|0,g=h*e|0,M=$[u],T=0,D=$[h],d=2,T+=t[p]*t[g],T+=t[p+1]*t[g+1];d<s;d++)T+=t[p+d]*t[g+d];if(!(Math.abs(T)<=c*Math.sqrt(M*D))){for(T*=2,P=M-D,I=as(T,P),P<0?(k=.5*(I-P),v=Math.sqrt(k/I),x=T/(I*v*2)):(x=Math.sqrt((I+P)/(2*I)),v=T/(I*x*2)),M=0,D=0,d=2,A=x*t[p]+v*t[g],S=-v*t[p]+x*t[g],t[p]=A,t[g]=S,M+=A*A,D+=S*S,A=x*t[p+1]+v*t[g+1],S=-v*t[p+1]+x*t[g+1],t[p+1]=A,t[g+1]=S,M+=A*A,D+=S*S;d<s;d++)A=x*t[p+d]+v*t[g+d],S=-v*t[p+d]+x*t[g+d],t[p+d]=A,t[g+d]=S,M+=A*A,D+=S*S;if($[u]=M,$[h]=D,_=1,r)for(y=u*n|0,b=h*n|0,d=2,A=x*r[y]+v*r[b],S=-v*r[y]+x*r[b],r[y]=A,r[b]=S,A=x*r[y+1]+v*r[b+1],S=-v*r[y+1]+x*r[b+1],r[y+1]=A,r[b+1]=S;d<o;d++)A=x*r[y+d]+v*r[b+d],S=-v*r[y+d]+x*r[b+d],r[y+d]=A,r[b+d]=S}}if(0===_)break}for(u=0;u<o;u++){for(d=0,C=0;d<s;d++)w=t[u*e+d],C+=w*w;$[u]=Math.sqrt(C)}for(u=0;u<o-1;u++){for(h=u,d=u+1;d<o;d++)$[h]<$[d]&&(h=d);if(u!==h&&(os($,u,h,C),r)){for(d=0;d<s;d++)os(t,u*e+d,h*e+d,w);for(d=0;d<o;d++)os(r,u*n+d,h*n+d,w)}}for(u=0;u<o;u++)i[u]=$[u];if(r)for(u=0;u<a;u++){for(C=u<o?$[u]:0;C<=l;){for(E=1/s,d=0;d<s;d++)B=214013*B+2531011,F=256&B>>16?E:-E,t[u*e+d]=F;for(m=0;m<2;m++)for(h=0;h<u;h++){for(C=0,d=0;d<s;d++)C+=t[u*e+d]*t[h*e+d];for(O=0,d=0;d<s;d++)w=t[u*e+d]-C*t[h*e+d],t[u*e+d]=w,O+=Math.abs(w);for(O=O?1/O:0,d=0;d<s;d++)t[u*e+d]*=O}for(C=0,d=0;d<s;d++)w=t[u*e+d],C+=w*w;C=Math.sqrt(C)}for(v=1/C,d=0;d<s;d++)t[u*e+d]*=v}}(u.data,c,h.data,d.data,l,c,l,c),e){for(s=0;s<l;s++)e.data[s]=h.data[s];for(;s<a;s++)e.data[s]=0}0===n?(i&&es(i,u),r&&es(r,d)):(i&&es(i,d),r&&es(r,u))}function hs(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function ds(t,e,i,r,n,s,o,a,c,l,u,h,d,m,f,p,g){t[0]=e,t[4]=i,t[8]=r,t[12]=n,t[1]=s,t[5]=o,t[9]=a,t[13]=c,t[2]=l,t[6]=u,t[10]=h,t[14]=d,t[3]=m,t[7]=f,t[11]=p,t[15]=g}function ms(t,e,i){const r=e[0],n=e[4],s=e[8],o=e[12],a=e[1],c=e[5],l=e[9],u=e[13],h=e[2],d=e[6],m=e[10],f=e[14],p=e[3],g=e[7],y=e[11],b=e[15],_=i[0],x=i[4],v=i[8],w=i[12],A=i[1],S=i[5],C=i[9],P=i[13],I=i[2],k=i[6],M=i[10],T=i[14],D=i[3],B=i[7],F=i[11],E=i[15];t[0]=r*_+n*A+s*I+o*D,t[4]=r*x+n*S+s*k+o*B,t[8]=r*v+n*C+s*M+o*F,t[12]=r*w+n*P+s*T+o*E,t[1]=a*_+c*A+l*I+u*D,t[5]=a*x+c*S+l*k+u*B,t[9]=a*v+c*C+l*M+u*F,t[13]=a*w+c*P+l*T+u*E,t[2]=h*_+d*A+m*I+f*D,t[6]=h*x+d*S+m*k+f*B,t[10]=h*v+d*C+m*M+f*F,t[14]=h*w+d*P+m*T+f*E,t[3]=p*_+g*A+y*I+b*D,t[7]=p*x+g*S+y*k+b*B,t[11]=p*v+g*C+y*M+b*F,t[15]=p*w+g*P+y*T+b*E}function fs(t,e,i,r){ds(t,e,0,0,0,0,i,0,0,0,0,r,0,0,0,0,1)}function ps(t,e,i,r){ds(t,1,0,0,e,0,1,0,i,0,0,1,r,0,0,0,1)}function gs(t,e){const i=Math.cos(e),r=Math.sin(e);ds(t,i,0,r,0,0,1,0,0,-r,0,i,0,0,0,0,1)}function ys(){return new Float32Array([1,0,0,0,1,0,0,0,1])}function bs(t,e){const i=Li([e[0],e[1],e[2]]),r=Li([e[4],e[5],e[6]]),n=Li([e[8],e[9],e[10]]),s=Li();Ni(s,r,n),t[0]=s[0],t[1]=s[1],t[2]=s[2],Ni(s,n,i),t[3]=s[0],t[4]=s[1],t[5]=s[2],Ni(s,i,r),t[6]=s[0],t[7]=s[1],t[8]=s[2]}function _s(t,e,i,r){i=i||1,r=r||!0;const n=t.length/3,s=e.length/3;let o;r&&(o=new Float32Array(3*n));const a=new Float32Array(3*n);let c;const l=new Array(20);for(c=0;c<20;++c)l[c]=new Uint32Array(n);for(c=0;c<n;++c)l[0][c]=0;let u,h,d;for(c=0;c<s;++c){var m=3*c,f=3*c+1,p=3*c+2;for(d=!0,u=0,h=l[0][e[m]];u<h;++u)if(e[f]===l[u+1][e[m]]){d=!1;break}for(d&&(l[0][e[m]]++,l[l[0][e[m]]][e[m]]=e[f]),d=!0,u=0,h=l[0][e[m]];u<h;++u)if(e[p]===l[u+1][e[m]]){d=!1;break}for(d&&(l[0][e[m]]++,l[l[0][e[m]]][e[m]]=e[p]),d=!0,u=0,h=l[0][e[f]];u<h;++u)if(e[m]===l[u+1][e[f]]){d=!1;break}for(d&&(l[0][e[f]]++,l[l[0][e[f]]][e[f]]=e[m]),d=!0,u=0,h=l[0][e[f]];u<h;++u)if(e[p]===l[u+1][e[f]]){d=!1;break}for(d&&(l[0][e[f]]++,l[l[0][e[f]]][e[f]]=e[p]),d=!0,u=0;u<l[0][e[p]];++u)if(e[m]===l[u+1][e[p]]){d=!1;break}for(d&&(l[0][e[p]]++,l[l[0][e[p]]][e[p]]=e[m]),d=!0,u=0,h=l[0][e[p]];u<h;++u)if(e[f]===l[u+1][e[p]]){d=!1;break}d&&(l[0][e[p]]++,l[l[0][e[p]]][e[p]]=e[f])}for(var g,y,b,_,x,v=.5,w=.75/4.5,A=0;A<i;++A){for(c=0;c<n;++c)if(g=3*c,(b=l[0][c])<3)a[g]=t[g],a[g+1]=t[g+1],a[g+2]=t[g+2];else if(3===b||4===b){for(a[g]=0,a[g+1]=0,a[g+2]=0,u=0;u<b;++u)y=3*l[u+1][c],a[g]+=t[y],a[g+1]+=t[y+1],a[g+2]+=t[y+2];a[g]+=v*t[g],a[g+1]+=v*t[g+1],a[g+2]+=v*t[g+2],x=v+b,a[g]/=x,a[g+1]/=x,a[g+2]/=x}else{for(a[g]=0,a[g+1]=0,a[g+2]=0,u=0;u<b;++u)y=3*l[u+1][c],a[g]+=t[y],a[g+1]+=t[y+1],a[g+2]+=t[y+2];a[g]+=1*t[g],a[g+1]+=1*t[g+1],a[g+2]+=1*t[g+2],_=1+b,a[g]/=_,a[g+1]/=_,a[g+2]/=_}if(t.set(a),r){xs(t,e,o);var S=3*n;for(g=0;g<S;g+=3)t[g]+=-1*w*o[g],t[g+1]+=-1*w*o[g+1],t[g+2]+=-1*w*o[g+2]}}}function xs(t,e,i){var r,n;if(void 0===i)i=new Float32Array(t.length);else for(r=0,n=i.length;r<n;r++)i[r]=0;var s=new Float32Array(3),o=new Float32Array(3),a=new Float32Array(3),c=new Float32Array(3),l=new Float32Array(3);if(e)for(r=0,n=e.length;r<n;r+=3){var u=3*e[r],h=3*e[r+1],d=3*e[r+2];ji(s,t,u),ji(o,t,h),ji(a,t,d),Vi(c,a,o),Vi(l,s,o),Ni(c,c,l),i[u]+=c[0],i[u+1]+=c[1],i[u+2]+=c[2],i[h]+=c[0],i[h+1]+=c[1],i[h+2]+=c[2],i[d]+=c[0],i[d+1]+=c[1],i[d+2]+=c[2]}else for(r=0,n=t.length;r<n;r+=9)ji(s,t,r),ji(o,t,r+3),ji(a,t,r+6),Vi(c,a,o),Vi(l,s,o),Ni(c,c,l),i[r]=c[0],i[r+1]=c[1],i[r+2]=c[2],i[r+3]=c[0],i[r+4]=c[1],i[r+5]=c[2],i[r+6]=c[0],i[r+7]=c[1],i[r+8]=c[2];return Ri(i),i}function vs(t){for(var e={},i=0,r=t.length;i<r;++i)e[t[i]]=!0;return e}function ws(t,e,i,r,n){var s=1/r*3;Ki(t,t,n+(s+=i)),Zi(e,e,n+s),Xi(t,t,r),Qi(t,t),Wi(t,t,r),Xi(e,e,r),Ji(e,e),Wi(e,e,r);var o=new Float32Array(3);Vi(o,e,t),Xi(o,o,r),Ji(o,o),Zi(o,o,1);var a=256*Math.pow(10,6),c=o[0]*o[1]*o[2]*3;a<=c&&(Xi(t,t,r*=Math.pow(a/c,1/3)),Qi(t,t),Wi(t,t,r),Xi(e,e,r),Ji(e,e),Wi(e,e,r),Vi(o,e,t),Xi(o,o,r),Ji(o,o),Zi(o,o,1));var l=new Float32Array(t);tr(l,l);var u=hs(),h=hs();gs(h,T(90)),ms(u,u,h);var d=hs();fs(d,-1/r,1/r,1/r),ms(u,u,d);var m=hs();return ps(m,-r*l[2],-r*l[1],-r*l[0]),ms(u,u,m),{dim:o,tran:l,matrix:u,scaleFactor:r}}fs.__deps=[ds],ps.__deps=[ds],gs.__deps=[ds],bs.__deps=[Li,Ni],Object.assign(_s,{__deps:[xs]}),Object.assign(xs,{__deps:[Vi,Ni,ji,Ri]}),Object.assign(ws,{__deps:[T,Ki,Zi,Wi,Xi,Qi,Ji,Vi,tr,hs,ms,ps,fs,gs]});class As{constructor(t,i,r){this.name=t||"",this.path=i||"",this.info={},this.center=new e.Vector3,this.boundingBox=new e.Box3,r instanceof e.BufferGeometry||r instanceof e.Group?this.fromGeometry(r):r&&(this.set(r.position,r.index,r.normal,r.color,r.atomindex,r.contour),this.boundingBox.setFromArray(r.position),this.boundingBox.getCenter(this.center))}get type(){return"Surface"}set(t,e,i,r,n,s=!1){this.position=t,this.index=e,this.normal=i,this.color=r,this.atomindex=n,this.size=t.length/3,this.contour=s}fromGeometry(i){let r,n,s,o;if(t.Debug&&Dt.time("GeometrySurface.fromGeometry"),r=i instanceof e.BufferGeometry?i:i[0],r.boundingBox||r.computeBoundingBox(),this.boundingBox.copy(r.boundingBox),this.boundingBox.getCenter(this.center),r instanceof e.BufferGeometry){const t=r.attributes,e=!!t.normal&&t.normal.array;(!e||0===e[0]&&0===e[1]&&0===e[2])&&r.computeVertexNormals(),n=t.position.array,s=t.index?t.index.array:null,o=t.normal.array}this.set(n,s,o,undefined,void 0),t.Debug&&Dt.timeEnd("GeometrySurface.setGeometry")}getPosition(){return this.position}getColor(t){const i=t||{};i.surface=this;const r=this.size,n=new Float32Array(3*r),s=$t.getScheme(i);if(s.volumeColor||"random"===i.scheme)for(let t=0;t<r;++t)s.volumeColorToArray(t,n,3*t);else if(s.positionColor){const t=new e.Vector3,i=this.position;for(let e=0;e<r;++e){var o=3*e;t.set(i[o],i[o+1],i[o+2]),s.positionColorToArray(t,n,o)}}else if(s.atomColor&&this.atomindex){const t=i.structure.getAtomProxy(),e=this.atomindex;for(let i=0;i<r;++i)t.index=e[i],s.atomColorToArray(t,n,3*i)}else{const t=new e.Color(i.value);ye(r,t.r,t.g,t.b,n)}return n}getPicking(t){return this.atomindex&&t?new Nn(this.atomindex,t):new Wn(be(this.size),this)}getNormal(){return this.normal}getSize(t,e){return ge(this.size,t*e)}getIndex(){return this.index}getFilteredIndex(t,e){if(t&&this.atomindex){const i=new gt(t),r=e.getAtomSet(i),n=[],s=this.atomindex,o=this.index,a=o.length,c=this.contour?2:3;let l=0;for(let t=0;t<a;t+=c){let e=!0;for(let i=0;i<c;i++){const n=s[o[t+i]];if(!r.get(n)){e=!1;break}}if(e)for(let e=0;e<c;e++,l++)n[l]=o[t+e]}return v(n,this.position.length/3)}return this.index}getAtomindex(){return this.atomindex}dispose(){}}function Ss(t,e,i,r,n){var s=new Jn(t,e,i,r,n);this.getSurface=function(t,e,i,r,n,o=!1){const a=s.triangulate(t,e,i,n,o);if(e&&!n&&(_s(a.position,a.index,e,!0),a.normal=xs(a.position,a.index)),r&&(Oi(r,a.position),a.normal)){const t=ys();bs(t,r),$i(t,a.normal)}return a}}Object.assign(Ss,{__deps:[_s,xs,Jn,Oi,$i,ys,bs]}),Ot.add("surf",(function(t,e){const i=t.data.args,r=t.data.params;if(i&&(self.volsurf=new Ss(i[0],i[1],i[2],i[3],i[4])),r){const t=self.volsurf.getSurface(r.isolevel,r.smooth,r.box,r.matrix,r.contour,r.wrap),i=[t.position.buffer,t.index.buffer];t.normal&&i.push(t.normal.buffer),t.atomindex&&i.push(t.atomindex.buffer);e({sd:t,p:r},i)}}),[Ss]);class Cs{constructor(t,i,r,n,s,o,a){this.name=t,this.path=i,this.matrix=new e.Matrix4,this.normalMatrix=new e.Matrix3,this.inverseMatrix=new e.Matrix4,this.center=new e.Vector3,this.boundingBox=new e.Box3,this.setData(r,n,s,o,a)}get type(){return"Volume"}setData(t,e,i,r,n){this.nx=e||1,this.ny=i||1,this.nz=r||1,this.data=t||new Float32Array(1),this.setAtomindex(n),delete this._position,delete this._min,delete this._max,delete this._mean,delete this._rms,this.worker&&this.worker.terminate()}setStats(t,e,i,r){this._min=t,this._max=e,this._mean=i,this._rms=r}setMatrix(t){this.matrix.copy(t);const i=this.boundingBox,r=this.center,n=this.nx-1,s=this.ny-1,o=this.nz-1;i.makeEmpty(),i.expandByPoint(r.set(n,s,o)),i.expandByPoint(r.set(n,s,0)),i.expandByPoint(r.set(n,0,o)),i.expandByPoint(r.set(n,0,0)),i.expandByPoint(r.set(0,s,o)),i.expandByPoint(r.set(0,0,o)),i.expandByPoint(r.set(0,s,0)),i.expandByPoint(r.set(0,0,0)),i.applyMatrix4(this.matrix),i.getCenter(this.center);const a=this.matrix.elements,c=new e.Vector3(a[0],a[1],a[2]),l=new e.Vector3(a[4],a[5],a[6]),u=new e.Vector3(a[8],a[9],a[10]),h=new e.Vector3,d=this.normalMatrix.elements;h.crossVectors(l,u),d[0]=h.x,d[1]=h.y,d[2]=h.z,h.crossVectors(u,c),d[3]=h.x,d[4]=h.y,d[5]=h.z,h.crossVectors(c,l),d[6]=h.x,d[7]=h.y,d[8]=h.z,this.inverseMatrix.copy(this.matrix).invert()}setAtomindex(t){this.atomindex=t}getBox(t,i,r){return r||(r=new e.Box3),r.set(t,t),r.expandByScalar(i),r.applyMatrix4(this.inverseMatrix),r.min.round(),r.max.round(),r}_getBox(t,i){if(!t||!i)return;this.__box||(this.__box=new e.Box3);const r=this.getBox(t,i,this.__box);return[r.min.toArray(),r.max.toArray()]}_makeSurface(t,e,i){const r=this.name+"@"+e.toPrecision(2),n=new As(r,"",t);return n.info.isolevel=e,n.info.smooth=i,n.info.volume=this,n}getSurface(t,e,i,r,n,s=!1){t=isNaN(t)?this.getValueForSigma(2):t,e=l(e,0),void 0===this.volsurf&&(this.volsurf=new Ss(this.data,this.nx,this.ny,this.nz,this.atomindex));const o=this._getBox(i,r),a=this.volsurf.getSurface(t,e,o,this.matrix.elements,n,s);return this._makeSurface(a,t,e)}getSurfaceWorker(t,e,i,r,n,s,o){if(t=isNaN(t)?this.getValueForSigma(2):t,e=e||0,window.hasOwnProperty("Worker")){void 0===this.workerPool&&(this.workerPool=new Di("surf",2));const a={},c=this.workerPool.getNextWorker();0===c.postCount&&Object.assign(a,{args:[this.data,this.nx,this.ny,this.nz,this.atomindex]}),Object.assign(a,{params:{isolevel:t,smooth:e,box:this._getBox(i,r),matrix:this.matrix.elements,contour:n,wrap:s}}),c.post(a,void 0,(t=>{const e=t.data.sd,i=t.data.p;o(this._makeSurface(e,i.isolevel,i.smooth))}),(a=>{console.warn("Volume.getSurfaceWorker error - trying without worker",a);const c=this.getSurface(t,e,i,r,n,s);o(c)}))}else{const a=this.getSurface(t,e,i,r,n,s);o(a)}}getValueForSigma(t){return this.mean+l(t,2)*this.rms}getSigmaForValue(t){return(l(t,0)-this.mean)/this.rms}get position(){if(!this._position){const t=this.nz,e=this.ny,i=this.nx,r=new Float32Array(i*e*t*3);let n=0;for(let s=0;s<t;++s)for(let t=0;t<e;++t)for(let e=0;e<i;++e)r[n+0]=e,r[n+1]=t,r[n+2]=s,n+=3;Oi(this.matrix.elements,r),this._position=r}return this._position}getDataAtomindex(){return this.atomindex}getDataPosition(){return this.position}getDataColor(t){const e=t||{};e.volume=this,e.scale=e.scale||"Spectral",e.domain=e.domain||[this.min,this.max];const i=$t.getScheme(e),r=this.position.length/3,n=new Float32Array(3*r);for(let t=0;t<r;++t)i.volumeColorToArray(t,n,3*t);return n}getDataPicking(){const t=be(this.position.length/3);return new Yn(t,this)}getDataSize(t,e){const i=this.data,r=this.position.length/3;let n;switch(t){case"value":case"deviation":n=new Float32Array(i);break;case"abs-value":n=new Float32Array(i);for(let t=0;t<r;++t)n[t]=Math.abs(n[t]);break;case"value-min":{n=new Float32Array(i);const t=this.min;for(let e=0;e<r;++e)n[e]-=t;break}default:n=ge(r,t)}if(1!==e)for(let t=0;t<r;++t)n[t]*=e;return n}get min(){return void 0===this._min&&(this._min=Se(this.data)),this._min}get max(){return void 0===this._max&&(this._max=Ae(this.data)),this._max}get sum(){return void 0===this._sum&&(this._sum=Ce(this.data)),this._sum}get mean(){return void 0===this._mean&&(this._mean=Pe(this.data)),this._mean}get rms(){return void 0===this._rms&&(this._rms=function(t){const e=t.length;let i=0;for(let r=0;r<e;++r){const e=t[r];i+=e*e}return Math.sqrt(i/e)}(this.data)),this._rms}clone(){const t=new Cs(this.name,this.path,this.data,this.nx,this.ny,this.nz,this.atomindex);return t.matrix.copy(this.matrix),t.header=Object.assign({},this.header),t}dispose(){this.workerPool&&this.workerPool.terminate()}}function Ps(t){return"front"===t?e.FrontSide:"back"===t?e.BackSide:e.DoubleSide}zt.add("shader/Mesh.vert","#define STANDARD\nuniform float clipNear;\nuniform vec3 clipCenter;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#if defined( PICKING )\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#elif defined( NOLIGHT )\nvarying vec3 vColor;\n#else\n#include color_pars_vertex\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#endif\n#endif\n#include common\nvoid main(){\n#if defined( PICKING )\nvPickingColor = unpackColor( primitiveId );\n#elif defined( NOLIGHT )\nvColor = color;\n#else\n#include color_vertex\n#include beginnormal_vertex\n#include defaultnormal_vertex\n#ifndef FLAT_SHADED\nvNormal = normalize( transformedNormal );\n#endif\n#endif\n#include begin_vertex\n#include project_vertex\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )\nvViewPosition = -mvPosition.xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n}"),zt.add("shader/Mesh.frag","#define STANDARD\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 interiorColor;\nuniform float interiorDarkening;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float clipNear;\nuniform float clipRadius;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#if defined( PICKING )\nuniform float objectId;\nvarying vec3 vPickingColor;\n#elif defined( NOLIGHT )\nvarying vec3 vColor;\n#else\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#endif\n#include common\n#include color_pars_fragment\n#include fog_pars_fragment\n#include bsdfs\n#include lights_pars_begin\n#include lights_physical_pars_fragment\n#endif\nvoid main(){\n#include nearclip_fragment\n#include radiusclip_fragment\n#if defined( PICKING )\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#elif defined( NOLIGHT )\ngl_FragColor = vec4( vColor, opacity );\n#else\nvec4 diffuseColor = vec4( diffuse, opacity );\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\nvec3 totalEmissiveLight = emissive;\n#include color_fragment\n#include roughnessmap_fragment\n#include metalnessmap_fragment\n#include normal_fragment_begin\n#include lights_physical_fragment\n#include lights_fragment_begin\n#include lights_fragment_end\nvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;\n#include interior_fragment\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#include opaque_back_fragment\n#endif\n}");const Is={f:1,v2:2,v3:3,c:3};function ks(t,e){t.matrix.copy(e),t.matrix.decompose(t.position,t.quaternion,t.scale),t.matrixWorldNeedsUpdate=!0}const Ms={opaqueBack:!1,side:"double",opacity:1,depthWrite:!0,clipNear:0,clipRadius:0,clipCenter:new e.Vector3,flatShaded:!1,wireframe:!1,roughness:.4,metalness:0,diffuse:16777215,diffuseInterior:!1,useInteriorColor:!1,interiorColor:14540253,interiorDarkening:0,forceTransparent:!1,matrix:new e.Matrix4,disablePicking:!1,sortParticles:!1,background:!1},Ts={opaqueBack:{updateShader:!0},side:{updateShader:!0,property:!0},opacity:{uniform:!0},depthWrite:{property:!0},clipNear:{updateShader:!0,property:!0},clipRadius:{updateShader:!0,uniform:!0},clipCenter:{uniform:!0},flatShaded:{updateShader:!0},background:{updateShader:!0},wireframe:{updateVisibility:!0},roughness:{uniform:!0},metalness:{uniform:!0},diffuse:{uniform:!0},diffuseInterior:{updateShader:!0},useInteriorColor:{updateShader:!0},interiorColor:{uniform:!0},interiorDarkening:{uniform:!0},matrix:{}};class Ds{constructor(t,i={}){this.parameterTypes=Ts,this.geometry=new e.BufferGeometry,this.indexVersion=0,this.wireframeIndexVersion=-1,this.group=new e.Group,this.wireframeGroup=new e.Group,this.pickingGroup=new e.Group,this.vertexShader="",this.fragmentShader="",this.isImpostor=!1,this.isText=!1,this.isSurface=!1,this.isPoint=!1,this.isLine=!1,this.dynamic=!0,this.visible=!0,this.wireframeIndexCount=0,this.parameters=u(i,this.defaultParameters),this.uniforms=e.UniformsUtils.merge([e.UniformsLib.common,{fogColor:{value:new e.Color(0)},fogNear:{value:0},fogFar:{value:0},opacity:{value:this.parameters.opacity},clipNear:{value:0},clipRadius:{value:this.parameters.clipRadius},clipCenter:{value:this.parameters.clipCenter}},{emissive:{value:new e.Color(0)},roughness:{value:this.parameters.roughness},metalness:{value:this.parameters.metalness},interiorColor:{value:new e.Color(this.parameters.interiorColor)},interiorDarkening:{value:this.parameters.interiorDarkening}},e.UniformsLib.lights]),this.uniforms.diffuse.value.set(this.parameters.diffuse),this.pickingUniforms={clipNear:{value:0},objectId:{value:0},opacity:{value:this.parameters.opacity}};const r=t.position||t.position1;this._positionDataSize=r?r.length/3:0,t.primitiveId||(t.primitiveId=be(this._positionDataSize)),this.addAttributes({position:{type:"v3",value:t.position},color:{type:"c",value:t.color},primitiveId:{type:"f",value:t.primitiveId}}),i.matrix&&(this.matrix=i.matrix),t.index&&this.initIndex(t.index),this.picking=t.picking,this.makeWireframeGeometry()}get defaultParameters(){return Ms}set matrix(t){this.setMatrix(t)}get matrix(){return this.group.matrix.clone()}get transparent(){return this.parameters.opacity<1||this.parameters.forceTransparent}get size(){return this._positionDataSize}get attributeSize(){return this.size}get pickable(){return!!this.picking&&!this.parameters.disablePicking}setMatrix(t){ks(this.group,t),ks(this.wireframeGroup,t),ks(this.pickingGroup,t)}initIndex(t){this.geometry.setIndex(new e.BufferAttribute(t,1));const i=this.geometry.getIndex();i?i.setUsage(this.dynamic?e.DynamicDrawUsage:e.StaticDrawUsage):Dt.error("Index is null")}makeMaterial(){const t=Ps(this.parameters.side),i=new e.ShaderMaterial({uniforms:this.uniforms,vertexShader:"",fragmentShader:"",depthTest:!0,transparent:this.transparent,depthWrite:this.parameters.depthWrite,lights:!0,fog:!0,side:t});i.vertexColors=!0,i.extensions.derivatives=!0,i.extensions.fragDepth=this.isImpostor;const r=new e.ShaderMaterial({uniforms:this.uniforms,vertexShader:"",fragmentShader:"",depthTest:!0,transparent:this.transparent,depthWrite:this.parameters.depthWrite,lights:!1,fog:!0,side:t});r.vertexColors=!0;const n=new e.ShaderMaterial({uniforms:this.pickingUniforms,vertexShader:"",fragmentShader:"",depthTest:!0,transparent:!1,depthWrite:this.parameters.depthWrite,lights:!1,fog:!1,side:t,blending:e.NoBlending});n.vertexColors=!0,n.extensions.fragDepth=this.isImpostor,i.clipNear=this.parameters.clipNear,r.clipNear=this.parameters.clipNear,n.clipNear=this.parameters.clipNear,this.material=i,this.wireframeMaterial=r,this.pickingMaterial=n,this.updateShader()}makeWireframeGeometry(){this.makeWireframeIndex();const t=this.geometry,i=this.wireframeIndex,r=new e.BufferGeometry;r.attributes=t.attributes,i&&(r.setIndex(new e.BufferAttribute(i,1).setUsage(this.dynamic?e.DynamicDrawUsage:e.StaticDrawUsage)),r.setDrawRange(0,this.wireframeIndexCount)),this.wireframeGeometry=r}makeWireframeIndex(){const t=[];function e(e,i){if(e>i){const t=e;e=i,i=t}const r=t[e];return void 0===r?(t[e]=[i],!0):!r.includes(i)&&(r.push(i),!0)}const i=this.geometry,r=i.index;if(this.parameters.wireframe)if(r){const n=r.array;let s,o=n.length;if(i.drawRange.count!==1/0&&(o=i.drawRange.count),this.wireframeIndex&&this.wireframeIndex.length>2*o)s=this.wireframeIndex;else{s=v(2*o,i.attributes.position.count)}let a=0;t.length=0;for(let t=0;t<o;t+=3){const i=n[t+0],r=n[t+1],o=n[t+2];e(i,r)&&(s[a+0]=i,s[a+1]=r,a+=2),e(r,o)&&(s[a+0]=r,s[a+1]=o,a+=2),e(o,i)&&(s[a+0]=o,s[a+1]=i,a+=2)}this.wireframeIndex=s,this.wireframeIndexCount=a,this.wireframeIndexVersion=this.indexVersion}else{const t=i.attributes.position.count;let e;e=this.wireframeIndex&&this.wireframeIndex.length>2*t?this.wireframeIndex:v(2*t,t);for(let i=0,r=0;i<t;i+=3)e[r+0]=i,e[r+1]=i+1,e[r+2]=i+1,e[r+3]=i+2,e[r+4]=i+2,e[r+5]=i,r+=6;this.wireframeIndex=e,this.wireframeIndexCount=2*t,this.wireframeIndexVersion=this.indexVersion}else this.wireframeIndex=new Uint16Array(0),this.wireframeIndexCount=0}updateWireframeIndex(){if(this.wireframeGeometry&&this.wireframeIndex){if(this.wireframeGeometry.setDrawRange(0,1/0),this.wireframeIndexVersion<this.indexVersion&&this.makeWireframeIndex(),this.wireframeGeometry.index&&this.wireframeIndex.length>this.wireframeGeometry.index.array.length)this.wireframeGeometry.setIndex(new e.BufferAttribute(this.wireframeIndex,1).setUsage(this.dynamic?e.DynamicDrawUsage:e.StaticDrawUsage));else{const t=this.wireframeGeometry.getIndex();if(!t)return void Dt.error("Index is null");t.set(this.wireframeIndex),t.needsUpdate=this.wireframeIndexCount>0,t.updateRange.count=this.wireframeIndexCount}this.wireframeGeometry.setDrawRange(0,this.wireframeIndexCount)}}getRenderOrder(){let t=0;return this.isText?t=1:this.transparent&&(t=this.isSurface?3:2),t}_getMesh(t){this.material||this.makeMaterial();const i=this.geometry,r=this[t];let n;return n=this.isLine?new e.LineSegments(i,r):this.isPoint?new e.Points(i,r):new e.Mesh(i,r),n.frustumCulled=!1,n.renderOrder=this.getRenderOrder(),n}getMesh(){return this._getMesh("material")}getWireframeMesh(){let t;return this.material||this.makeMaterial(),this.wireframeGeometry||this.makeWireframeGeometry(),t=new e.LineSegments(this.wireframeGeometry,this.wireframeMaterial),t.frustumCulled=!1,t.renderOrder=this.getRenderOrder(),t}getPickingMesh(){return this._getMesh("pickingMaterial")}getShader(t,e){return ce(t,this.getDefines(e))}getVertexShader(t){return this.getShader(this.vertexShader,t)}getFragmentShader(t){return this.getShader(this.fragmentShader,t)}getDefines(t){const e={};return this.parameters.clipNear&&(e.NEAR_CLIP=1),this.parameters.clipRadius&&(e.RADIUS_CLIP=1),"picking"===t?e.PICKING=1:(("background"===t||this.parameters.background)&&(e.NOLIGHT=1),this.parameters.flatShaded&&(e.FLAT_SHADED=1),this.parameters.opaqueBack&&(e.OPAQUE_BACK=1),this.parameters.diffuseInterior&&(e.DIFFUSE_INTERIOR=1),this.parameters.useInteriorColor&&(e.USE_INTERIOR_COLOR=1)),e}getParameters(){return this.parameters}addUniforms(t){this.uniforms=e.UniformsUtils.merge([this.uniforms,t]),this.pickingUniforms=e.UniformsUtils.merge([this.pickingUniforms,t])}addAttributes(t){for(let i in t){let r;const n=t[i],s=this.attributeSize*Is[n.type];n.value?(s!==n.value.length&&Dt.error("attribute value has wrong length",i),r=n.value):r=x("float32",s),this.geometry.setAttribute(i,new e.BufferAttribute(r,Is[n.type]).setUsage(this.dynamic?e.DynamicDrawUsage:e.StaticDrawUsage))}}updateRenderOrder(){const t=this.getRenderOrder();function e(e){e.renderOrder=t}this.group.children.forEach(e),this.pickingGroup&&this.pickingGroup.children.forEach(e)}updateShader(){const t=this.material,e=this.wireframeMaterial,i=this.pickingMaterial;t.vertexShader=this.getVertexShader(),t.fragmentShader=this.getFragmentShader(),t.needsUpdate=!0,e.vertexShader=this.getShader("Line.vert"),e.fragmentShader=this.getShader("Line.frag"),e.needsUpdate=!0,i.vertexShader=this.getVertexShader("picking"),i.fragmentShader=this.getFragmentShader("picking"),i.needsUpdate=!0}setParameters(t){const e=t,i=this.parameterTypes,r=this.parameters,n={},s={};let o=!1,a=!1;for(const t in e){const c=e[t];void 0!==c&&(r[t]=c,void 0!==i[t]&&(i[t].property&&(!0!==i[t].property?n[i[t].property]=c:n[t]=c),i[t].uniform&&(!0!==i[t].uniform?s[i[t].uniform]=c:s[t]=c),i[t].updateShader&&(o=!0),i[t].updateVisibility&&(a=!0),this.dynamic&&"wireframe"===t&&!0===c&&this.updateWireframeIndex(),"forceTransparent"===t&&(n.transparent=this.transparent),"matrix"===t&&(this.matrix=c)))}this.setProperties(n),this.setUniforms(s),o&&this.updateShader(),a&&this.setVisibility(this.visible)}setAttributes(t){const i=this.geometry,r=i.attributes;for(const n in t){if("picking"===n)continue;const s=t[n],o=s.length;if("index"===n){const t=i.getIndex();if(!t){Dt.error("Index is null");continue}i.setDrawRange(0,1/0),o>t.array.length?i.setIndex(new e.BufferAttribute(s,1).setUsage(this.dynamic?e.DynamicDrawUsage:e.StaticDrawUsage)):(t.set(s),t.needsUpdate=o>0,t.updateRange.count=o,i.setDrawRange(0,o)),this.indexVersion++,this.parameters.wireframe&&this.updateWireframeIndex()}else{const t=r[n];o>t.array.length?i.setAttribute(n,new e.BufferAttribute(s,t.itemSize).setUsage(this.dynamic?e.DynamicDrawUsage:e.StaticDrawUsage)):(r[n].set(s),r[n].needsUpdate=o>0,r[n].updateRange.count=o)}}}setUniforms(t){if(!t)return;const e=this.material.uniforms,i=this.wireframeMaterial.uniforms,r=this.pickingMaterial.uniforms;for(let n in t)"opacity"===n&&this.setProperties({transparent:this.transparent}),void 0!==e[n]&&(e[n].value.isVector3?e[n].value.copy(t[n]):e[n].value.set?e[n].value.set(t[n]):e[n].value=t[n]),void 0!==i[n]&&(i[n].value.isVector3?i[n].value.copy(t[n]):i[n].value.set?i[n].value.set(t[n]):i[n].value=t[n]),void 0!==r[n]&&(r[n].value.isVector3?r[n].value.copy(t[n]):r[n].value.set?r[n].value.set(t[n]):r[n].value=t[n])}setProperties(t){if(!t)return;const e=this.material,i=this.wireframeMaterial,r=this.pickingMaterial;for(const n in t){const s=n;let o=t[s];"transparent"===s?this.updateRenderOrder():"side"===s&&(o=Ps(o)),e[s]=o,i[s]=o,r[s]=o}e.needsUpdate=!0,i.needsUpdate=!0,r.needsUpdate=!0}setVisibility(t){this.visible=t,this.parameters.wireframe?(this.group.visible=!1,this.wireframeGroup.visible=t,this.pickable&&(this.pickingGroup.visible=!1)):(this.group.visible=t,this.wireframeGroup.visible=!1,this.pickable&&(this.pickingGroup.visible=t))}dispose(){this.material&&this.material.dispose(),this.wireframeMaterial&&this.wireframeMaterial.dispose(),this.pickingMaterial&&this.pickingMaterial.dispose(),this.geometry.dispose(),this.wireframeGeometry&&this.wireframeGeometry.dispose()}toJSON(){var t={};for(var e in this)"group"!==e&&"wireframeGroup"!==e&&"pickingGroup"!=e&&"picking"!==e&&(t[e]=this[e]);return t}}class Bs extends Ds{constructor(t,e={}){super(t,e),this.vertexShader="Mesh.vert",this.fragmentShader="Mesh.frag",this.addAttributes({normal:{type:"v3",value:t.normal}}),void 0===t.normal&&this.geometry.computeVertexNormals()}}class Fs extends Bs{constructor(){super(...arguments),this.isSurface=!0}}function Es(t){t.visible=!0}function Os(t){t.visible=!1}class $s{constructor(t){this.group=new e.Group,this.wireframeGroup=new e.Group,this.pickingGroup=new e.Group,this.frontMeshes=[],this.backMeshes=[],this.size=t.size,this.side=t.parameters.side,this.visible=t.visible,this.geometry=t.geometry,this.picking=t.picking,this.group=new e.Group,this.wireframeGroup=new e.Group,this.pickingGroup=new e.Group,this.matrix=t.matrix;const i=t,r=new t.constructor({position:new Float32Array(0)});i.makeMaterial(),r.makeMaterial(),r.picking=t.picking,r.geometry=t.geometry,r.wireframeGeometry=t.wireframeGeometry,r.setParameters(t.getParameters()),r.updateShader(),i.setParameters({side:"front"}),r.setParameters({side:"back",opacity:r.parameters.opacity}),this.buffer=t,this.frontBuffer=i,this.backBuffer=r}set matrix(t){Ds.prototype.setMatrix.call(this,t)}get matrix(){return this.group.matrix.clone()}get pickable(){return!!this.picking&&!this.parameters.disablePicking}get parameters(){return this.buffer.parameters}getParameters(){const t=Object.assign({},this.buffer.parameters);return t.side=this.side,t}getMesh(t){let i,r;return t?(r=this.backBuffer.getPickingMesh(),i=this.frontBuffer.getPickingMesh()):(r=this.backBuffer.getMesh(),i=this.frontBuffer.getMesh()),this.frontMeshes.push(i),this.backMeshes.push(r),this.setParameters({side:this.side}),(new e.Group).add(r,i)}getWireframeMesh(){return this.buffer.getWireframeMesh()}getPickingMesh(){return this.getMesh(!0)}setAttributes(t){this.buffer.setAttributes(t)}setParameters(t){"front"===(t=Object.assign({},t)).side?(this.frontMeshes.forEach(Es),this.backMeshes.forEach(Os)):"back"===t.side?(this.frontMeshes.forEach(Os),this.backMeshes.forEach(Es)):"double"===t.side&&(this.frontMeshes.forEach(Es),this.backMeshes.forEach(Es)),void 0!==t.side&&(this.side=t.side),delete t.side,void 0!==t.matrix&&(this.matrix=t.matrix),delete t.matrix,this.frontBuffer.setParameters(t),void 0!==t.wireframe&&(this.wireframe=t.wireframe,this.setVisibility(this.visible)),delete t.wireframe,this.backBuffer.setParameters(t)}setVisibility(t){this.visible=t,this.parameters.wireframe?(this.group.visible=!1,this.wireframeGroup.visible=t,this.pickable&&(this.pickingGroup.visible=!1)):(this.group.visible=t,this.wireframeGroup.visible=!1,this.pickable&&(this.pickingGroup.visible=t))}dispose(){this.frontBuffer.dispose(),this.backBuffer.dispose()}toJSON(){var t={};for(var e in this)["side","size","visible","matrix","parameters"].includes(e)&&(t[e]=this[e]);return t}}zt.add("shader/Line.vert","uniform float clipNear;\nuniform vec3 clipCenter;\nvarying vec3 vViewPosition;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#include color_pars_vertex\nvoid main(){\n#include color_vertex\n#include begin_vertex\n#include project_vertex\nvViewPosition = -mvPosition.xyz;\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n}"),zt.add("shader/Line.frag","uniform float opacity;\nuniform float clipNear;\nuniform float clipRadius;\nvarying vec3 vViewPosition;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#include common\n#include color_pars_fragment\n#include fog_pars_fragment\nvoid main(){\n#include nearclip_fragment\n#include radiusclip_fragment\ngl_FragColor = vec4( vColor, opacity );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n}");class Rs extends Ds{constructor(){super(...arguments),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag"}}class Ls extends Mi{constructor(t,i,r){super(t,i,r),this.type="surface",this.parameters=Object.assign({isolevelType:{type:"select",options:{value:"value",sigma:"sigma"}},isolevel:{type:"number",precision:2,max:1e3,min:-1e3},negateIsolevel:{type:"boolean"},isolevelScroll:{type:"boolean"},smooth:{type:"integer",precision:1,max:10,min:0},background:{type:"boolean",rebuild:!0},opaqueBack:{type:"boolean",buffer:!0},boxSize:{type:"integer",precision:1,max:100,min:0},colorVolume:{type:"hidden"},contour:{type:"boolean",rebuild:!0},useWorker:{type:"boolean",rebuild:!0},wrap:{type:"boolean",rebuild:!0}},this.parameters),t instanceof Cs?(this.surface=void 0,this.volume=t):(this.surface=t,this.volume=void 0),this.boxCenter=new e.Vector3,this.__boxCenter=new e.Vector3,this.box=new e.Box3,this.__box=new e.Box3,this._position=new e.Vector3,this.inverseMatrix=new e.Matrix4,this.setBox=function(){this._position.copy(i.translationGroup.position).negate(),this._position.applyMatrix4(this.inverseMatrix),this._position.equals(this.boxCenter)||this.setParameters({boxCenter:this._position})},this.toBePrepared=!0,this.viewer.signals.ticked.add(this.setBox,this),this.init(r)}init(t){const e=t||{};e.colorScheme=l(e.colorScheme,"uniform"),e.colorValue=l(e.colorValue,14540253),this.isolevelType=l(e.isolevelType,"sigma"),this.isolevel=l(e.isolevel,2),this.negateIsolevel=l(e.negateIsolevel,!1),this.isolevelScroll=l(e.isolevelScroll,!1),this.smooth=l(e.smooth,0),this.background=l(e.background,!1),this.opaqueBack=l(e.opaqueBack,!0),this.boxSize=l(e.boxSize,0),this.colorVolume=l(e.colorVolume,void 0),this.contour=l(e.contour,!1),this.useWorker=l(e.useWorker,!0),this.wrap=l(e.wrap,!1),super.init(e),this.inverseMatrix.copy(this.matrix).invert(),this.build()}attach(t){this.bufferList.forEach((t=>{this.viewer.add(t)})),this.setVisibility(this.visible),t()}prepare(t){if(this.volume){let e;if(e="sigma"===this.isolevelType?this.volume.getValueForSigma(this.isolevel):this.isolevel,this.negateIsolevel&&(e*=-1),!this.surface||this.__isolevel!==e||this.__smooth!==this.smooth||this.__contour!==this.contour||this.__wrap!==this.wrap||this.__boxSize!==this.boxSize||this.boxSize>0&&!this.__boxCenter.equals(this.boxCenter)){this.__isolevel=e,this.__smooth=this.smooth,this.__contour=this.contour,this.__wrap=this.wrap,this.__boxSize=this.boxSize,this.__boxCenter.copy(this.boxCenter),this.__box.copy(this.box);const i=e=>{this.surface=e,t()};this.useWorker?this.volume.getSurfaceWorker(e,this.smooth,this.boxCenter,this.boxSize,this.contour,this.wrap,i):i(this.volume.getSurface(e,this.smooth,this.boxCenter,this.boxSize,this.contour,this.wrap))}else t()}else t()}create(){const t={position:this.surface.getPosition(),color:this.surface.getColor(this.getColorParams()),index:this.surface.getIndex()};let e;if(this.contour)e=new Rs(t,this.getBufferParams({wireframe:!1}));else{Object.assign(t,{normal:this.surface.getNormal(),picking:this.surface.getPicking()});const i=new Fs(t,this.getBufferParams({background:this.background,opaqueBack:this.opaqueBack,dullInterior:!1}));e=new $s(i)}this.bufferList.push(e)}update(t){if(0===this.bufferList.length)return;const e={};(t=t||{}).position&&(e.position=this.surface.getPosition()),t.color&&(e.color=this.surface.getColor(this.getColorParams())),t.index&&(e.index=this.surface.getIndex()),t.normal&&(e.normal=this.surface.getNormal()),this.bufferList.forEach((function(t){t.setAttributes(e)}))}setParameters(t,e,i){return t&&void 0!==t.isolevelType&&this.volume&&("value"===this.isolevelType&&"sigma"===t.isolevelType?this.isolevel=this.volume.getSigmaForValue(this.isolevel):"sigma"===this.isolevelType&&"value"===t.isolevelType&&(this.isolevel=this.volume.getValueForSigma(this.isolevel)),this.isolevelType=t.isolevelType),t&&t.boxCenter&&(this.boxCenter.copy(t.boxCenter),delete t.boxCenter),t&&t.wireframe&&(t.contour||void 0===t.contour&&this.contour)&&(t.wireframe=!1),super.setParameters(t,e,i),t.matrix&&this.inverseMatrix.copy(t.matrix).invert(),this.volume&&this.volume.getBox(this.boxCenter,this.boxSize,this.box),t&&void 0!==t.colorVolume&&e&&(e.color=!0),this.surface&&(void 0!==t.isolevel||void 0!==t.negateIsolevel||void 0!==t.smooth||void 0!==t.wrap||void 0!==t.boxSize||this.boxSize>0&&!this.__box.equals(this.box))&&this.build({position:!0,color:!0,index:!0,normal:!this.contour}),this}getColorParams(){const t=super.getColorParams();return t.volume=this.colorVolume,t}dispose(){this.viewer.signals.ticked.remove(this.setBox,this),super.dispose()}}class Ns{static zoomScroll(t,e){t.trackballControls.zoom(e)}static clipNearScroll(t,e){const i=t.getParameters();t.setParameters({clipNear:i.clipNear+e/10})}static focusScroll(t,e){const i=t.getFocus(),r=Math.sign(e)*function(t,e,i){if(t>e)return t;const r=t/e;return((2*i-e)*r+(2*e-3*i))*r*r+i}((100-i)/10,5,.2);t.setFocus(i+r)}static zoomFocusScroll(t,e){t.trackballControls.zoom(e);const i=t.viewer.camera.position.z;t.setFocus(100-Math.abs(i/8))}static isolevelScroll(t,e){const i=Math.sign(e)/10;t.eachRepresentation(((t,e)=>{if(t.repr instanceof Ls){const e=t.getParameters();e.isolevelScroll&&t.setParameters({isolevel:e.isolevel+i})}}))}static panDrag(t,e,i){t.trackballControls.pan(e,i)}static rotateDrag(t,e,i){t.trackballControls.rotate(e,i)}static zRotateDrag(t,e,i){t.trackballControls.zRotate(e,i)}static zoomDrag(t,e,i){t.trackballControls.zoom((e+i)/-2)}static zoomFocusDrag(t,e,i){t.trackballControls.zoom((e+i)/-2);const r=t.viewer.camera.position.z;t.setFocus(100-Math.abs(r/8))}static panComponentDrag(t,e,i){t.trackballControls.panComponent(e,i)}static panAtomDrag(t,e,i){t.trackballControls.panAtom(e,i)}static rotateComponentDrag(t,e,i){t.trackballControls.rotateComponent(e,i)}static movePick(t,e){e&&t.animationControls.move(e.position.clone())}static tooltipPick(t,e){const i=t.tooltip;if(t.getParameters().tooltip&&e){const t=e.mouse.position;i.innerText=e.getLabel(),i.style.bottom=window.innerHeight-t.y+3+"px",i.style.left=t.x+3+"px",i.style.display="block"}else i.style.display="none"}static measurePick(t,e){if(e&&(e.atom||e.bond)){const t=e.atom||e.closestBondAtom;e.component.measurePick(t)}else t.measureClear()}}const zs={default:[["scroll",Ns.zoomScroll],["scroll-shift",Ns.focusScroll],["scroll-ctrl",Ns.isolevelScroll],["scroll-shift-ctrl",Ns.zoomFocusScroll],["drag-left",Ns.rotateDrag],["drag-right",Ns.panDrag],["drag-ctrl-left",Ns.panDrag],["drag-ctrl-right",Ns.zRotateDrag],["drag-shift-left",Ns.zoomDrag],["drag-middle",Ns.zoomFocusDrag],["drag-ctrl-shift-right",Ns.panComponentDrag],["drag-ctrl-shift-left",Ns.rotateComponentDrag],["clickPick-right",Ns.measurePick],["clickPick-ctrl-left",Ns.measurePick],["clickPick-middle",Ns.movePick],["clickPick-left",Ns.movePick],["hoverPick",Ns.tooltipPick]],pymol:[["drag-left",Ns.rotateDrag],["drag-middle",Ns.panDrag],["drag-right",Ns.zoomDrag],["scroll",Ns.focusScroll],["drag-shift-right",Ns.focusScroll],["clickPick-ctrl+shift-middle",Ns.movePick],["hoverPick",Ns.tooltipPick]],coot:[["scroll",Ns.isolevelScroll],["drag-left",Ns.rotateDrag],["drag-middle",Ns.panDrag],["drag-ctrl-left",Ns.panDrag],["drag-right",Ns.zoomFocusDrag],["drag-ctrl-right",Ns.focusScroll],["clickPick-middle",Ns.movePick],["hoverPick",Ns.tooltipPick]],astexviewer:[["drag-left",Ns.rotateDrag],["drag-ctrl-left",Ns.panDrag],["drag-shift-left",Ns.zoomDrag],["scroll",Ns.focusScroll],["clickPick-middle",Ns.movePick],["hoverPick",Ns.tooltipPick]]};function Vs(t){const e=t.split(/[-+]/);let i="";e.includes("scroll")&&(i="scroll"),e.includes("drag")&&(i="drag"),e.includes("click")&&(i="click"),e.includes("doubleClick")&&(i="doubleClick"),e.includes("hover")&&(i="hover"),e.includes("clickPick")&&(i="clickPick"),e.includes("hoverPick")&&(i="hoverPick");let r=0;e.includes("alt")&&(r+=1),e.includes("ctrl")&&(r+=2),e.includes("meta")&&(r+=4),e.includes("shift")&&(r+=8);let n=0;return e.includes("left")&&(n+=1),e.includes("right")&&(n+=2),e.includes("middle")&&(n+=4),[i,r,n]}class Us{constructor(t,e={}){this.stage=t,this.actionList=[],this.mouse=t.mouseObserver,this.disabled=e.disabled||!1,this.preset(e.preset||"default")}run(t,...e){if(this.disabled)return;const i=this.mouse.key||0,r=this.mouse.buttons||0;this.actionList.forEach((n=>{n.type===t&&n.key===i&&n.button===r&&n.callback(this.stage,...e)}))}add(t,e){const[i,r,n]=Vs(t);this.actionList.push({type:i,key:r,button:n,callback:e})}remove(t,e){const i=t.includes("*"),[r,n,s]=Vs(t),o=this.actionList.filter((function(t){return!((t.type===r||i&&""===r)&&(t.key===n||i&&0===n)&&(t.button===s||i&&0===s)&&(t.callback===e||void 0===e))}));this.actionList=o}preset(t){this.clear();(zs[t]||[]).forEach((t=>this.add(t[0],t[1])))}clear(){this.actionList.length=0}}class js{static autoView(t){t.autoView(1e3)}static toggleAnimations(t){t.animationControls.toggle()}static toggleRock(t){t.toggleRock()}static toggleSpin(t){t.toggleSpin()}static toggleAntialiasing(t){const e=t.getParameters();t.setParameters({sampleLevel:-1===e.sampleLevel?0:-1})}}const Gs={default:[["i",js.toggleSpin],["k",js.toggleRock],["p",js.toggleAnimations],["a",js.toggleAntialiasing],["r",js.autoView]]};class Hs{constructor(t,e={}){this.stage=t,this.actionList=[],this.disabled=e.disabled||!1,this.preset(e.preset||"default")}run(t){this.disabled||this.actionList.forEach((e=>{e.key===t&&e.callback(this.stage)}))}add(t,e){this.actionList.push({key:t,callback:e})}remove(t,e){const i=this.actionList.filter((function(i){return!(i.key===t&&(i.callback===e||void 0===e))}));this.actionList=i}preset(t){this.clear();(Gs[t]||[]).forEach((t=>this.add(t[0],t[1])))}clear(){this.actionList.length=0}}class qs{constructor(t){this.stage=t,this.stage=t,this.mouse=t.mouseObserver,this.controls=t.mouseControls,this.mouse.signals.clicked.add(this._onClick,this),this.mouse.signals.hovered.add(this._onHover,this)}_onClick(t,e){const i=this.stage.pickingControls.pick(t,e);this.stage.signals.clicked.dispatch(i),this.controls.run("clickPick",i)}_onHover(t,e){const i=this.stage.pickingControls.pick(t,e);i&&this.mouse.down.equals(this.mouse.position)&&(this.stage.transformComponent=i.component,this.stage.transformAtom=i.atom),this.stage.signals.hovered.dispatch(i),this.controls.run("hoverPick",i)}dispose(){this.mouse.signals.clicked.remove(this._onClick,this),this.mouse.signals.hovered.remove(this._onHover,this)}}class Ws{constructor(t){this.stage=t,this.stage=t,this.mouse=t.mouseObserver,this.controls=t.mouseControls,this.mouse.signals.moved.add(this._onMove,this),this.mouse.signals.scrolled.add(this._onScroll,this),this.mouse.signals.dragged.add(this._onDrag,this),this.mouse.signals.clicked.add(this._onClick,this),this.mouse.signals.hovered.add(this._onHover,this),this.mouse.signals.doubleClicked.add(this._onDblclick,this)}_onMove(){this.stage.tooltip.style.display="none"}_onScroll(t){this.controls.run("scroll",t)}_onDrag(t,e){this.controls.run("drag",t,e)}_onClick(t,e){this.controls.run("click",t,e)}_onDblclick(t,e){this.controls.run("doubleClick",t,e)}_onHover(t,e){this.controls.run("hover",t,e)}dispose(){this.mouse.signals.moved.remove(this._onMove,this),this.mouse.signals.scrolled.remove(this._onScroll,this),this.mouse.signals.dragged.remove(this._onDrag,this),this.mouse.signals.clicked.remove(this._onClick,this),this.mouse.signals.hovered.remove(this._onHover,this)}}class Xs{constructor(t){this.stage=t,this.viewer=t.viewer,this.animationControls=t.animationControls,this.viewer.signals.ticked.add(this._onTick,this)}_onTick(t){this.animationControls.run(t)}dispose(){this.viewer.signals.ticked.remove(this._onTick,this)}}const Ys=!!Ct&&{passive:!0};class Ks{constructor(t){this.stage=t,this.stage=t,this.controls=t.keyControls,this.domElement=t.viewer.renderer.domElement,this.domElement.setAttribute("tabIndex","-1"),this.domElement.style.outline="none",this._focusDomElement=this._focusDomElement.bind(this),this._onKeydown=this._onKeydown.bind(this),this._onKeyup=this._onKeyup.bind(this),this._onKeypress=this._onKeypress.bind(this),this.domElement.addEventListener("mousedown",this._focusDomElement),this.domElement.addEventListener("touchstart",this._focusDomElement,Ys),this.domElement.addEventListener("keydown",this._onKeydown),this.domElement.addEventListener("keyup",this._onKeyup),this.domElement.addEventListener("keypress",this._onKeypress)}_onKeydown(){}_onKeyup(){}_onKeypress(t){let e;e="key"in KeyboardEvent.prototype?t.key:String.fromCharCode(t.which||t.keyCode),this.controls.run(e)}_focusDomElement(){this.domElement.focus()}dispose(){this.domElement.removeEventListener("mousedown",this._focusDomElement),this.domElement.removeEventListener("touchstart",this._focusDomElement,Ys),this.domElement.removeEventListener("keydown",this._onKeypress),this.domElement.removeEventListener("keyup",this._onKeypress),this.domElement.removeEventListener("keypress",this._onKeypress)}}class Zs{constructor(t,i,r,n={}){this.component=t,this.position=i,this.offsetX=l(n.offsetX,0),this.offsetY=l(n.offsetY,0),this.visible=l(n.visible,!0),this.stage=t.stage,this.viewer=t.stage.viewer,this._viewerPosition=new e.Vector3,this._updateViewerPosition(),this._canvasPosition=new e.Vector2,this._cameraPosition=new e.Vector3,this.element=document.createElement("div"),Object.assign(this.element.style,{display:"block",position:"absolute",pointerEvents:"none",whiteSpace:"nowrap",left:"-10000px"}),this.viewer.wrapper.appendChild(this.element),this.setContent(r),this.updateVisibility(),this.viewer.signals.rendered.add(this._update,this),this.component.signals.matrixChanged.add(this._updateViewerPosition,this)}setContent(t){const e=this.element.style.display;if("none"===e&&(this.element.style.left="-10000px",this.element.style.display="block"),t instanceof HTMLElement)this.element.appendChild(t);else{const e=document.createElement("div");e.innerText=t,Object.assign(e.style,{backgroundColor:"rgba( 0, 0, 0, 0.6 )",color:"lightgrey",padding:"8px",fontFamily:"sans-serif"}),this.element.appendChild(e)}this._clientRect=this.element.getBoundingClientRect(),"none"===e&&(this.element.style.display=e)}setVisibility(t){this.visible=t,this.updateVisibility()}getVisibility(){return this.visible&&this.component.parameters.visible}updateVisibility(){this.element.style.display=this.getVisibility()?"block":"none"}_updateViewerPosition(){this._viewerPosition.copy(this.position).applyMatrix4(this.component.matrix)}_update(){if(!this.getVisibility())return;const t=this.element.style,e=this._canvasPosition,i=this._viewerPosition,r=this._clientRect;if(this._cameraPosition.copy(i).add(this.viewer.translationGroup.position).applyMatrix4(this.viewer.rotationGroup.matrix).sub(this.viewer.camera.position),this._cameraPosition.z<0)return void(t.display="none");t.display="block";const n=this._cameraPosition.length(),s=this.viewer.scene.fog;t.opacity=(1-R(s.near,s.far,n)).toString(),t.zIndex=Math.round(100*(s.far-n)).toString(),this.stage.viewerControls.getPositionOnCanvas(i,e),t.bottom=this.offsetX+e.y+r.height/2+"px",t.left=this.offsetY+e.x-r.width/2+"px"}dispose(){this.viewer.wrapper.removeChild(this.element),this.viewer.signals.ticked.remove(this._update,this),this.component.signals.matrixChanged.remove(this._updateViewerPosition,this)}}const Qs=new e.Matrix4,Js=new e.Vector3,to=new e.Quaternion;class eo{constructor(t){this.component=t,this.signals={changed:new a.Signal},this.stage=t.stage,this.viewer=t.stage.viewer}get position(){return this.component.position}get rotation(){return this.component.quaternion}changed(){this.component.updateMatrix(),this.viewer.requestRender(),this.signals.changed.dispatch()}spin(t,e){Qs.copy(this.viewer.rotationGroup.matrix).invert(),Js.copy(S(t)).applyMatrix4(Qs),Qs.extractRotation(this.component.transform),Qs.premultiply(this.viewer.rotationGroup.matrix),Qs.invert(),Js.copy(S(t)),Js.applyMatrix4(Qs),Qs.makeRotationAxis(Js,e),to.setFromRotationMatrix(Qs),this.component.quaternion.premultiply(to),this.changed()}}const io={"":"",vdw:"by vdW radius",covalent:"by covalent radius",sstruc:"by secondary structure",bfactor:"by bfactor",size:"size",data:"data",explicit:"explicit"};class ro{constructor(t={}){this.max=10,this.type=l(t.type,"size"),this.scale=l(t.scale,1),this.size=l(t.size,1),this.data=l(t.data,{})}atomRadius(t){let e;switch(this.type){case"vdw":e=t.vdw;break;case"covalent":e=t.covalent;break;case"bfactor":e=t.bfactor||1;break;case"sstruc":const i=t.sstruc;e="h"===i||"g"===i||"i"===i||"e"===i||"b"===i?.25:en.includes(t.atomname)?.4:.1;break;case"data":e=l(this.data[t.index],1);break;case"explicit":e=t.radius,null===e&&(e=this.size);break;default:e=this.size}return Math.min(e*this.scale,this.max)}}ro.types=io;const no=new e.Vector3(-1,-1,-1),so=new e.Matrix4;class oo{constructor(t){const i=t.rows,r=i/3,n=new ts(i,3),s=new ts(3,3),o=new ts(1,3),a=new ts(3,3),c=new ts(3,3),l=ns(t);ss(t,l),es(n,t),is(s,n,n),us(s,o,a,c);const u=new e.Vector3(l[0],l[1],l[2]),h=new e.Vector3(a.data[0],a.data[3],a.data[6]),d=new e.Vector3(a.data[1],a.data[4],a.data[7]),m=new e.Vector3(a.data[2],a.data[5],a.data[8]),f=h.clone().multiplyScalar(Math.sqrt(o.data[0]/r)),p=d.clone().multiplyScalar(Math.sqrt(o.data[1]/r)),g=m.clone().multiplyScalar(Math.sqrt(o.data[2]/r));this.begA=u.clone().sub(f),this.endA=u.clone().add(f),this.begB=u.clone().sub(p),this.endB=u.clone().add(p),this.begC=u.clone().sub(g),this.endC=u.clone().add(g),this.center=u,this.vecA=f,this.vecB=p,this.vecC=g,this.normVecA=h,this.normVecB=d,this.normVecC=m}getBasisMatrix(t=new e.Matrix4){const i=t;return i.makeBasis(this.normVecB,this.normVecA,this.normVecC),i.determinant()<0&&i.scale(no),i}getRotationQuaternion(t=new e.Quaternion){const i=t;return i.setFromRotationMatrix(this.getBasisMatrix(so)),i.invert()}getProjectedScaleForAtoms(t){let i=-1/0,r=-1/0,n=-1/0,s=-1/0,o=-1/0,a=-1/0;const c=new e.Vector3,l=new e.Vector3,u=this.center,h=this.normVecA,d=this.normVecB,m=this.normVecC;return t.eachAtom((function(t){Fi(c.copy(t),h,u);const e=l.subVectors(c,u).normalize().dot(h),f=c.distanceTo(u);e>0?f>i&&(i=f):f>r&&(r=f),Fi(c.copy(t),d,u);const p=l.subVectors(c,u).normalize().dot(d),g=c.distanceTo(u);p>0?g>n&&(n=g):g>s&&(s=g),Fi(c.copy(t),m,u);const y=l.subVectors(c,u).normalize().dot(m),b=c.distanceTo(u);y>0?b>o&&(o=b):b>a&&(a=b)})),{d1a:i,d2a:n,d3a:o,d1b:-r,d2b:-s,d3b:-a}}}class ao{constructor(t,e,i,r){this.volume=t,this.setFilter(e,i,r)}get header(){return this.volume.header}get matrix(){return this.volume.matrix}get normalMatrix(){return this.volume.normalMatrix}get inverseMatrix(){return this.volume.inverseMatrix}get center(){return this.volume.center}get boundingBox(){return this.volume.boundingBox}get min(){return this.volume.min}get max(){return this.volume.max}get mean(){return this.volume.mean}get rms(){return this.volume.rms}_getFilterHash(t,e,i){return JSON.stringify([t,e,i])}setFilter(t,e,i){isNaN(t)&&this.header&&(t=this.header.DMEAN+2*this.header.ARMS),t=void 0===t||isNaN(t)?-1/0:t,e=l(e,1/0),i=l(i,!1);const r=this.volume.data,n=this.volume.position,s=this.volume.atomindex,o=this._getFilterHash(t,e,i);if(o!==this._filterHash){if(t===-1/0&&e===1/0)this.data=r,this.position=n,this.atomindex=s;else{const o=r.length;this._dataBuffer||(this._dataBuffer=new ArrayBuffer(4*o),this._positionBuffer=new ArrayBuffer(3*o*4),s&&(this._atomindexBuffer=new ArrayBuffer(4*o)));const a=new Float32Array(this._dataBuffer),c=new Float32Array(this._positionBuffer);let l;s&&(l=new Uint32Array(this._atomindexBuffer));let u=0;for(let h=0;h<o;++h){const o=3*h,d=r[h];if(!i&&d>=t&&d<=e||i&&(d<t||d>e)){const t=3*u;a[u]=d,c[t+0]=n[o+0],c[t+1]=n[o+1],c[t+2]=n[o+2],s&&l&&(l[u]=s[h]),u+=1}}this.data=new Float32Array(this._dataBuffer,0,u),this.position=new Float32Array(this._positionBuffer,0,3*u),s&&(this.atomindex=new Int32Array(this._atomindexBuffer,0,u))}this._filterHash=o}}}ao.prototype.getValueForSigma=Cs.prototype.getValueForSigma,ao.prototype.getSigmaForValue=Cs.prototype.getSigmaForValue,ao.prototype.getDataAtomindex=Cs.prototype.getDataAtomindex,ao.prototype.getDataPosition=Cs.prototype.getDataPosition,ao.prototype.getDataColor=Cs.prototype.getDataColor,ao.prototype.getDataPicking=Cs.prototype.getDataPicking,ao.prototype.getDataSize=Cs.prototype.getDataSize;class co{constructor(t,e){const i=Cr({nodeArray1:t.atomIndex1,nodeArray2:t.atomIndex2,edgeCount:t.count,nodeCount:e});this.countArray=i.countArray,this.offsetArray=i.offsetArray,this.indexArray=i.indexArray}}class lo extends vr{get _defaultFields(){return[["atomIndex1",1,"int32"],["atomIndex2",1,"int32"],["bondOrder",1,"int8"]]}addBond(t,e,i){this.growIfFull();const r=this.count,n=t.index,s=e.index;n<s?(this.atomIndex1[r]=n,this.atomIndex2[r]=s):(this.atomIndex2[r]=n,this.atomIndex1[r]=s),i&&(this.bondOrder[r]=i),this.count+=1}addBondIfConnected(t,e,i){return!!t.connectedTo(e)&&(this.addBond(t,e,i),!0)}}class uo extends vr{get _defaultFields(){return[["residueIndex",1,"uint32"],["atomTypeId",1,"uint16"],["x",1,"float32"],["y",1,"float32"],["z",1,"float32"],["serial",1,"int32"],["bfactor",1,"float32"],["altloc",1,"uint8"],["occupancy",1,"float32"]]}setAltloc(t,e){this.altloc[t]=e.charCodeAt(0)}getAltloc(t){const e=this.altloc[t];return e?String.fromCharCode(e):""}}class ho extends vr{get _defaultFields(){return[["chainIndex",1,"uint32"],["atomOffset",1,"uint32"],["atomCount",1,"uint32"],["residueTypeId",1,"uint16"],["resno",1,"int32"],["sstruc",1,"uint8"],["inscode",1,"uint8"]]}setSstruc(t,e){this.sstruc[t]=e.charCodeAt(0)}getSstruc(t){const e=this.sstruc[t];return e?String.fromCharCode(e):""}setInscode(t,e){this.inscode[t]=e.charCodeAt(0)}getInscode(t){const e=this.inscode[t];return e?String.fromCharCode(e):""}}class mo extends vr{get _defaultFields(){return[["entityIndex",1,"uint16"],["modelIndex",1,"uint16"],["residueOffset",1,"uint32"],["residueCount",1,"uint32"],["chainname",4,"uint8"],["chainid",4,"uint8"]]}setChainname(t,e){const i=4*t;this.chainname[i]=e.charCodeAt(0),this.chainname[i+1]=e.charCodeAt(1),this.chainname[i+2]=e.charCodeAt(2),this.chainname[i+3]=e.charCodeAt(3)}getChainname(t){let e="";for(let i=0;i<4;++i){const r=this.chainname[4*t+i];if(!r)break;e+=String.fromCharCode(r)}return e}setChainid(t,e){const i=4*t;this.chainid[i]=e.charCodeAt(0),this.chainid[i+1]=e.charCodeAt(1),this.chainid[i+2]=e.charCodeAt(2),this.chainid[i+3]=e.charCodeAt(3)}getChainid(t){let e="";for(let i=0;i<4;++i){const r=this.chainid[4*t+i];if(!r)break;e+=String.fromCharCode(r)}return e}}class fo extends vr{get _defaultFields(){return[["chainOffset",1,"uint32"],["chainCount",1,"uint32"]]}}class po{constructor(t){this.polymer=t,this.size=t.residueCount}getCenterIterator(t=0){const i=this.getPosition().center,r=i.length/3;let n=0,s=-1;const o=[new e.Vector3,new e.Vector3,new e.Vector3,new e.Vector3];return{size:r,next:function(){const t=this.get(s);return s+=1,t},get:function(e){e=Math.min(r-1,Math.max(0,e));const s=o[n%4],a=3*e;if(s.fromArray(i,a),t){const n=Math.min(t,e,r-e-1);for(let t=1;t<=n;++t){const e=3*t,r=(n+1-t)/(n+1);s.x+=r*i[a-e+0]+r*i[a+e+0],s.y+=r*i[a-e+1]+r*i[a+e+1],s.z+=r*i[a-e+2]+r*i[a+e+2]}s.x/=n+1,s.y/=n+1,s.z/=n+1}return n+=1,s},reset:function(){n=0,s=-1}}}getColor(t){const e=this.polymer,i=e.structure,r=e.residueCount,n=e.residueIndexStart,s=new Float32Array(3*r),o=t||{};o.structure=i;const a=$t.getScheme(o),c=i.getResidueProxy(),l=i.getAtomProxy();for(let t=0;t<r;++t)c.index=n+t,l.index=c.traceAtomIndex,a.atomColorToArray(l,s,3*t);return{color:s}}getPicking(){const t=this.polymer,e=t.structure,i=t.residueCount,r=t.residueIndexStart,n=new Float32Array(i),s=e.getResidueProxy();for(let t=0;t<i;++t)s.index=r+t,n[t]=s.traceAtomIndex;return{picking:new Nn(n,e)}}getSize(t){const e=this.polymer,i=e.structure,r=e.residueCount,n=e.residueIndexStart,s=new Float32Array(r),o=new ro(t),a=i.getResidueProxy(),c=i.getAtomProxy();for(let t=0;t<r;++t)a.index=n+t,c.index=a.traceAtomIndex,s[t]=o.atomRadius(c);return{size:s}}getPosition(){const t=this.polymer,i=t.structure,r=t.residueCount,n=r-3,s=new Float32Array(3*r),o=new Float32Array(3*r),a=new Float32Array(r),c=new Float32Array(r),l=new Float32Array(r),u=new Float32Array(r),h=new Float32Array(3*r),d=new e.Vector3,m=new e.Vector3,f=new e.Vector3,p=new e.Vector3,g=new e.Vector3,y=new e.Vector3,b=new e.Vector3,_=new e.Vector3,x=new e.Vector3,v=new e.Vector3,w=new e.Vector3,A=new e.Vector3(0,0,0),S="trace",C=i.getAtomProxy(),P=i.getAtomProxy(t.getAtomIndexByType(0,S)),I=i.getAtomProxy(t.getAtomIndexByType(1,S)),k=i.getAtomProxy(t.getAtomIndexByType(2,S));for(let e=0;e<n;++e){C.index=P.index,P.index=I.index,I.index=k.index,k.index=t.getAtomIndexByType(e+3,S);const i=3*e;d.subVectors(P,C),m.subVectors(I,P),f.subVectors(k,I),p.subVectors(d,m),g.subVectors(m,f),x.crossVectors(p,g).normalize(),x.toArray(o,i),e>0&&(a[e]=x.angleTo(v));const r=Math.cos(p.angleTo(g));u[e]=180/Math.PI*Math.acos(r);const n=p.length(),_=g.length();c[e]=Math.sqrt(_*n)/Math.max(2,2*(1-r)),l[e]=Math.abs(m.dot(x)),y.copy(p).multiplyScalar(c[e]/n),b.copy(g).multiplyScalar(c[e]/_),y.subVectors(P,y),b.subVectors(I,b),y.toArray(s,i+3),b.toArray(s,i+6),w.subVectors(C,A),w.toArray(h,i),v.copy(x),A.copy(y)}y.fromArray(s,3),b.fromArray(s,6),x.subVectors(y,b).normalize(),C.index=t.getAtomIndexByType(0,S),A.copy(C),_.copy(C),Fi(_,x,y),_.toArray(s,0),w.subVectors(A,y),w.toArray(h,0),y.fromArray(s,3*r-6),b.fromArray(s,3*r-9),x.subVectors(y,b).normalize(),C.index=t.getAtomIndexByType(r-1,S),A.copy(C),_.copy(C),Fi(_,x,y),_.toArray(s,3*r-3);for(let e=r-3;e<r;++e)y.fromArray(s,3*e),C.index=t.getAtomIndexByType(e,S),A.copy(C),w.subVectors(A,y),w.toArray(h,3*e);const M=new Float32Array(r),T=new Float32Array(r),D=new Float32Array(r),B=new Float32Array(r);M[1]=c[0],T[1]=u[0],D[1]=c[0];for(let t=2;t<r-2;++t)M[t]=.5*(c[t-2]+c[t-1]),T[t]=.5*(u[t-2]+u[t-1]),D[t]=.5*(l[t-2]+l[t-1]),y.fromArray(o,3*(t-2)),b.fromArray(o,3*(t-1)),B[t]=180/Math.PI*Math.acos(Math.cos(y.angleTo(b)));M[r-2]=c[r-4],T[r-2]=u[r-4],D[r-2]=l[r-4];const F=new Float32Array(3*r);ve(o,F,0,0,3),ve(o,F,0,3,3);for(let t=2;t<r-2;++t)y.fromArray(o,3*(t-2)),b.fromArray(o,3*(t-1)),x.addVectors(b,y).multiplyScalar(.5).normalize(),x.toArray(F,3*t);return ve(o,F,3*r-12,3*r-6,3),ve(o,F,3*r-12,3*r-3,3),{center:s,axis:F,bending:B,radius:M,rise:D,twist:T,resdir:h}}}class go{constructor(t){this.polymer=t,this.helixorient=new po(t),this.position=this.helixorient.getPosition()}getAxis(t,i,r,n,s){t=t||30,i=i||2.5,r=void 0!==r&&r;const o=this.polymer,a=o.structure,c=o.residueCount,l=o.residueIndexStart,u=this.position,h=n||{};h.structure=a;const d=$t.getScheme(h),m=new ro(s);let f=0,p=0;const g=[],y=[],b=[],_=[],x=[],v=[],w=[],A=[],S=[];let C,P,I=new Float32Array(3*c),k=new Float32Array(3*c);const M=new e.Vector3,T=new e.Vector3,D=a.getResidueProxy(),B=a.getResidueProxy(),F=a.getAtomProxy(),E=new e.Vector3,O=new e.Vector3;let $=!1;for(let e=0;e<c;++e)if(D.index=l+e,E.fromArray(u.center,3*e),e===c-1?$=!0:(B.index=l+e+1,O.fromArray(u.center,3*e+3),(r&&D.sstruc!==B.sstruc||E.distanceTo(O)>i||u.bending[e]>t)&&($=!0)),$){if(e-f<4){f=e,$=!1;continue}F.index=D.traceAtomIndex,I=u.axis.subarray(3*f+3,3*e),k=u.center.subarray(3*f,3*e+3),C=Bi(I).normalize(),P=Bi(k),M.fromArray(k),Fi(M,C,P),T.fromArray(k,k.length-3),Fi(T,C,P),C.subVectors(T,M),C.toArray(g,p),P.toArray(y,p),M.toArray(b,p),T.toArray(_,p),d.atomColorToArray(F,x,p),v.push(F.index),w.push(m.atomRadius(F)),A.push(l+f),S.push(l+e+1-f),p+=3,f=e,$=!1}const R=new Float32Array(v);return{axis:new Float32Array(g),center:new Float32Array(y),begin:new Float32Array(b),end:new Float32Array(_),color:new Float32Array(x),picking:new Nn(R,a),size:new Float32Array(w),residueOffset:A,residueCount:S}}}class yo{constructor(t){this.scoreFunction=t,this.content=[],this.scoreFunction=t}push(t){this.content.push(t),this.bubbleUp(this.content.length-1)}pop(){const t=this.content[0],e=this.content.pop();return e&&this.content.length>0&&(this.content[0]=e,this.sinkDown(0)),t}peek(){return this.content[0]}remove(t){const e=this.content.length;for(let i=0;i<e;i++)if(this.content[i]===t){const r=this.content.pop();return void(r&&i!==e-1&&(this.content[i]=r,this.scoreFunction(r)<this.scoreFunction(t)?this.bubbleUp(i):this.sinkDown(i)))}throw new Error("Node not found.")}size(){return this.content.length}bubbleUp(t){const e=this.content[t];for(;t>0;){const i=Math.floor((t+1)/2)-1,r=this.content[i];if(!(this.scoreFunction(e)<this.scoreFunction(r)))break;this.content[i]=e,this.content[t]=r,t=i}}sinkDown(t){const e=this.content.length,i=this.content[t],r=this.scoreFunction(i);let n=0,s=0;for(;;){const o=2*(t+1),a=o-1;let c=null;if(a<e){const t=this.content[a];n=this.scoreFunction(t),n<r&&(c=a)}if(o<e){const t=this.content[o];s=this.scoreFunction(t),s<(null===c?r:n)&&(c=o)}if(null===c)break;this.content[t]=this.content[c],this.content[c]=i,t=c}}}
/**
     * Kdtree
     * @class
     * @author Alexander Rose <alexander.rose@weirdbyte.de>, 2016
     * @author Roman Bolzern <roman.bolzern@fhnw.ch>, 2013
     * @author I4DS http://www.fhnw.ch/i4ds, 2013
     * @license MIT License <http://www.opensource.org/licenses/mit-license.php>
     * @description
     * k-d Tree for typed arrays of 3d points (e.g. for Float32Array), in-place
     * provides fast nearest neighbour search
     *
     * Based on https://github.com/ubilabs/kd-tree-javascript by Ubilabs
     *
     * Further information (including mathematical properties)
     * http://en.wikipedia.org/wiki/Binary_tree
     * http://en.wikipedia.org/wiki/K-d_tree
     *
     * @example
     * points: [x, y, z, x, y, z, x, y, z, ...]
     * metric: function(a, b){
     *    return Math.pow(a[0]-b[0], 2) + Math.pow(a[1]-b[1], 2) + Math.pow(a[2]-b[2], 2);
     * }
     *
     * @param {Float32Array} points - points
     * @param {Function} metric - metric
     */class bo{constructor(t,e){this.points=t,this.metric=e,this.maxDepth=0,this.currentNode=0;const i=t.length/3,r=new Uint32Array(i);for(let t=0;t<i;++t)r[t]=t;this.indices=r,this.nodes=new Int32Array(4*i),this.rootIndex=this.buildTree(0,-1,0,i)}buildTree(t,e,i,r){t>this.maxDepth&&(this.maxDepth=t);const n=r-i;if(0===n)return-1;const s=4*this.currentNode,o=this.nodes;if(this.currentNode+=1,1===n)return o[s]=i,o[s+1]=-1,o[s+2]=-1,o[s+3]=e,s;const a=this.indices,c=this.points,l=i+Math.floor(n/2),u=t%3;let h,d,m,f,p,g=i,y=r-1;for(;y>g;){for(m=g+y>>1,f=c[3*a[m]+u],d=a[m],a[m]=a[y],a[y]=d,p=g,h=g;h<y;++h)c[3*a[h]+u]<f&&(d=a[p],a[p]=a[h],a[h]=d,++p);if(d=a[y],a[y]=a[p],a[p]=d,m=p,l===m)break;l<m?y=m-1:g=m+1}return o[s]=l,o[s+1]=this.buildTree(t+1,s,i,l),o[s+2]=this.buildTree(t+1,s,l+1,r),o[s+3]=e,s}getNodeDepth(t){const e=this.nodes[t+3];return-1===e?0:this.getNodeDepth(e)+1}nearest(t,e,i){const r=new yo((t=>-t[1])),n=this.nodes,s=this.points,o=this.indices,a=c=>{let l,u;const h=this.getNodeDepth(c)%3,d=3*o[n[c]],m=[s[d+0],s[d+1],s[d+2]],f=this.metric(t,m);function p(t,i){r.push([t,i]),r.size()>e&&r.pop()}const g=n[c+1],y=n[c+2];if(-1===y&&-1===g)return void((r.size()<e||f<r.peek()[1])&&f<=i&&p(c,f));l=-1===y?g:-1===g?y:t[h]<=s[d+h]?g:y,a(l),(r.size()<e||f<r.peek()[1])&&f<=i&&p(c,f);const b=[];for(let e=0;e<3;e+=1)b[e]=e===h?t[e]:s[d+e];const _=this.metric(b,m);(r.size()<e||Math.abs(_)<r.peek()[1])&&Math.abs(_)<=i&&(u=l===g?y:g,-1!==u&&a(u))};a(this.rootIndex);const c=[];for(let t=0,i=Math.min(r.size(),e);t<i;t+=1)c.push(r.content[t]);return c}verify(t,e=0){let i=1;if(void 0===t&&(t=this.rootIndex),-1===t)throw new Error("node is null");const r=e%3,n=this.nodes,s=this.points,o=this.indices,a=n[t+1],c=n[t+2];if(-1!==a){if(s[3*o[n[a]]+r]>s[3*o[n[t]]+r])throw new Error("left child is > parent!");i+=this.verify(a,e+1)}if(-1!==c){if(s[3*o[n[c]]+r]<s[3*o[n[t]]+r])throw new Error("right child is < parent!");i+=this.verify(c,e+1)}return i}}class _o{constructor(t,e=0){this.structure=t,this.index=e,this.chainStore=t.chainStore,this.residueStore=t.residueStore,this.atomStore=t.atomStore,this.residueMap=t.residueMap,this.atomMap=t.atomMap}get bondHash(){return this.structure.bondHash}get entity(){return this.structure.entityList[this.entityIndex]}get entityIndex(){return this.chainStore.entityIndex[this.chainIndex]}get modelIndex(){return this.chainStore.modelIndex[this.chainIndex]}get chainIndex(){return this.residueStore.chainIndex[this.residueIndex]}get residue(){return console.warn("residue - might be expensive"),this.structure.getResidueProxy(this.residueIndex)}get residueIndex(){return this.atomStore.residueIndex[this.index]}set residueIndex(t){this.atomStore.residueIndex[this.index]=t}get sstruc(){return this.residueStore.getSstruc(this.residueIndex)}get inscode(){return this.residueStore.getInscode(this.residueIndex)}get resno(){return this.residueStore.resno[this.residueIndex]}get chainname(){return this.chainStore.getChainname(this.chainIndex)}get chainid(){return this.chainStore.getChainid(this.chainIndex)}get residueType(){return this.residueMap.get(this.residueStore.residueTypeId[this.residueIndex])}get atomType(){return this.atomMap.get(this.atomStore.atomTypeId[this.index])}get residueAtomOffset(){return this.residueStore.atomOffset[this.residueIndex]}get resname(){return this.residueType.resname}get hetero(){return this.residueType.hetero}get atomname(){return this.atomType.atomname}get number(){return this.atomType.number}get element(){return this.atomType.element}get vdw(){return this.atomType.vdw}get covalent(){return this.atomType.covalent}get x(){return this.atomStore.x[this.index]}set x(t){this.atomStore.x[this.index]=t}get y(){return this.atomStore.y[this.index]}set y(t){this.atomStore.y[this.index]=t}get z(){return this.atomStore.z[this.index]}set z(t){this.atomStore.z[this.index]=t}get serial(){return this.atomStore.serial[this.index]}set serial(t){this.atomStore.serial[this.index]=t}get bfactor(){return this.atomStore.bfactor[this.index]}set bfactor(t){this.atomStore.bfactor[this.index]=t}get occupancy(){return this.atomStore.occupancy[this.index]}set occupancy(t){this.atomStore.occupancy[this.index]=t}get altloc(){return this.atomStore.getAltloc(this.index)}set altloc(t){this.atomStore.setAltloc(this.index,t)}get partialCharge(){return this.atomStore.partialCharge?this.atomStore.partialCharge[this.index]:null}set partialCharge(t){this.atomStore.partialCharge&&(this.atomStore.partialCharge[this.index]=t)}get radius(){return this.atomStore.radius?this.atomStore.radius[this.index]:null}set radius(t){this.atomStore.radius&&(this.atomStore.radius[this.index]=t)}get formalCharge(){return this.atomStore.formalCharge?this.atomStore.formalCharge[this.index]:null}set formalCharge(t){this.atomStore.formalCharge&&(this.atomStore.formalCharge[this.index]=t)}get aromatic(){return this.atomStore.aromatic?this.atomStore.aromatic[this.index]:this.residueType.isAromatic(this)?1:0}set aromatic(t){this.atomStore.aromatic&&(this.atomStore.aromatic[this.index]=t)}get bondCount(){return this.bondHash.countArray[this.index]}eachBond(t,e){e=e||this.structure._bp;const i=this.index,r=this.bondHash,n=r.indexArray,s=r.countArray[i],o=r.offsetArray[i];for(let i=0;i<s;++i)e.index=n[o+i],t(e)}eachBondedAtom(t,e){const i=e||this.structure._ap,r=this.index;this.eachBond((function(e){i.index=r!==e.atomIndex1?e.atomIndex1:e.atomIndex2,t(i)})),this.index=r}hasBondTo(t){let e=!1;return this.eachBondedAtom((function(i){t.index===i.index&&(e=!0)})),e}bondToElementCount(t){let e=0;const i=this.index;return this.eachBondedAtom((function(i){i.number===t&&(e+=1)})),this.index=i,e}hasBondToElement(t){return this.bondToElementCount(t)>0}isBackbone(){const t=this.residueType.backboneIndexList;return t.length>0&&t.includes(this.index-this.residueAtomOffset)}isPolymer(){if(this.structure.entityList.length>0)return this.entity.isPolymer();{const t=this.residueType.moleculeType;return 3===t||4===t||5===t}}isSidechain(){return this.isPolymer()&&!this.isBackbone()}isCg(){const t=this.residueType.backboneType;return 4===t||5===t||6===t}isTrace(){return this.index===this.residueType.traceAtomIndex+this.residueAtomOffset}isHetero(){return 1===this.residueType.hetero}isProtein(){return 3===this.residueType.moleculeType}isNucleic(){const t=this.residueType.moleculeType;return 4===t||5===t}isRna(){return 4===this.residueType.moleculeType}isDna(){return 5===this.residueType.moleculeType}isWater(){return 1===this.residueType.moleculeType}isIon(){return 2===this.residueType.moleculeType}isSaccharide(){return 6===this.residueType.moleculeType}isHelix(){return Or.includes(this.sstruc)}isSheet(){return $r.includes(this.sstruc)}isTurn(){return Rr.includes(this.sstruc)&&this.isProtein()}isBonded(){return 0!==this.bondHash.countArray[this.index]}isRing(){return void 0!==this.residueType.getRings().atomRings[this.index-this.residueAtomOffset]}isAromatic(){return 1===this.aromatic}isPolarHydrogen(){let t=!1;return 1!==this.number||(t=!this.hasBondToElement(6)),t}isMetal(){return this.atomType.isMetal()}isNonmetal(){return this.atomType.isNonmetal()}isMetalloid(){return this.atomType.isMetalloid()}isHalogen(){return this.atomType.isHalogen()}isDiatomicNonmetal(){return this.atomType.isDiatomicNonmetal()}isPolyatomicNonmetal(){return this.atomType.isPolyatomicNonmetal()}isAlkaliMetal(){return this.atomType.isAlkaliMetal()}isAlkalineEarthMetal(){return this.atomType.isAlkalineEarthMetal()}isNobleGas(){return this.atomType.isNobleGas()}isTransitionMetal(){return this.atomType.isTransitionMetal()}isPostTransitionMetal(){return this.atomType.isPostTransitionMetal()}isLanthanide(){return this.atomType.isLanthanide()}isActinide(){return this.atomType.isActinide()}getDefaultValence(){return this.atomType.getDefaultValence()}getValenceList(){return this.atomType.getValenceList()}getOuterShellElectronCount(){return this.atomType.getOuterShellElectronCount()}distanceTo(t){const e=this.atomStore,i=t.atomStore,r=this.index,n=t.index,s=e.x[r]-i.x[n],o=e.y[r]-i.y[n],a=e.z[r]-i.z[n],c=s*s+o*o+a*a;return Math.sqrt(c)}connectedTo(t){const e=this.atomStore,i=t.atomStore,r=this.index,n=t.index;if(e.altloc&&i.altloc){const t=e.altloc[r],s=i.altloc[n];if(0!==t&&0!==s&&32!==t&&32!==s&&t!==s)return!1}const s=e.x[r]-i.x[n],o=e.y[r]-i.y[n],a=e.z[r]-i.z[n],c=s*s+o*o+a*a;if(c<48&&this.isCg())return!0;if(isNaN(c))return!1;const l=this.covalent+t.covalent,u=l+.3,h=l-.5;return c<u*u&&c>h*h}positionFromArray(t,e=0){return this.x=t[e+0],this.y=t[e+1],this.z=t[e+2],this}positionToArray(t=[],e=0){const i=this.index,r=this.atomStore;return t[e+0]=r.x[i],t[e+1]=r.y[i],t[e+2]=r.z[i],t}positionToVector3(t){return void 0===t&&(t=new e.Vector3),t.x=this.x,t.y=this.y,t.z=this.z,t}positionFromVector3(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}positionAdd(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}positionSub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}getResidueBonds(t=!1){const e=this.residueAtomOffset,i=this.index-this.residueAtomOffset,r=this.residueType.getBonds(),n=r.atomIndices1,s=r.atomIndices2;let o,a,c,l;for(t||(l=[]),o=n.indexOf(i);-1!==o;){if(c=s[o]+e,!l)return c;l.push(c),o=n.indexOf(i,o+1)}for(a=s.indexOf(i);-1!==a;){if(c=n[a]+e,!l)return c;l.push(c),a=s.indexOf(i,a+1)}return l}qualifiedName(t=!1){var e="";return this.resname&&!t&&(e+="["+this.resname+"]"),void 0!==this.resno&&(e+=this.resno),this.inscode&&(e+="^"+this.inscode),this.chainname&&(e+=":"+this.chainname),this.atomname&&(e+="."+this.atomname),this.altloc&&(e+="%"+this.altloc),this.structure.modelStore.count>1&&(e+="/"+this.modelIndex),e}clone(){return new _o(this.structure,this.index)}toObject(){return{index:this.index,residueIndex:this.residueIndex,resname:this.resname,x:this.x,y:this.y,z:this.z,element:this.element,chainname:this.chainname,resno:this.resno,serial:this.serial,vdw:this.vdw,covalent:this.covalent,hetero:this.hetero,bfactor:this.bfactor,altloc:this.altloc,atomname:this.atomname,modelIndex:this.modelIndex}}}function xo(t,e){const i=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return i*i+r*r+n*n}function vo(t,e){return Math.sqrt(xo(t,e))}const wo=new Float32Array(3);class Ao{constructor(e,i=!1){t.Debug&&Dt.time("Kdtree build");const r=i?xo:vo,n=new Float32Array(3*e.atomCount),s=new Uint32Array(e.atomCount);let o=0;e.eachAtom((function(t){n[o+0]=t.x,n[o+1]=t.y,n[o+2]=t.z,s[o/3]=t.index,o+=3})),this.atomIndices=s,this.points=n,this.kdtree=new bo(n,r),t.Debug&&Dt.timeEnd("Kdtree build")}nearest(t,i,r){t instanceof e.Vector3?t.toArray(wo):t instanceof _o&&t.positionToArray(wo);const n=this.kdtree.nearest(wo,i,r),s=this.kdtree.indices,o=this.kdtree.nodes,a=this.atomIndices,c=[];for(let t=0,e=n.length;t<e;++t){const e=n[t],i=e[0],r=e[1];c.push({index:a[s[o[i]]],distance:r})}return c}}const So={" ":"X","!":"Y","#":"Z",$:"-X","%":"-Y","&":"-Z","'":"Y+1/2","(":"1/2+X",")":"1/2+Y","*":"1/2-X","+":"1/2+Z",",":"1/2-Y","-":"1/2-Z",".":"X+1/2","/":"Z+1/2",0:"-X+1/2",1:"-Y+1/2",2:"-Z+1/2",3:"1/4+X",4:"1/4-Y",5:"1/4+Z",6:"1/4-X",7:"1/4+Y",8:"3/4-Y",9:"3/4+Z",":":"3/4+Y",";":"3/4+X","<":"3/4-X","=":"1/4-Z",">":"3/4-Z","?":"X-Y","@":"Y-X",A:"Z+1/3",B:"Z+2/3",C:"X+2/3",D:"Y+1/3",E:"-Y+2/3",F:"X-Y+1/3",G:"Y-X+2/3",H:"-X+1/3",I:"X+1/3",J:"Y+2/3",K:"-Y+1/3",L:"X-Y+2/3",M:"Y-X+1/3",N:"-X+2/3",O:"2/3+X",P:"1/3+Y",Q:"1/3+Z",R:"2/3-Y",S:"1/3+X-Y",T:"2/3+Y-X",U:"1/3-X",V:"2/3-X",W:"1/3-Y",X:"1/3-Z",Y:"2/3+Y",Z:"1/3+Y-X","[":"2/3+X-Y","]":"1/3+X","^":"2/3+Z",_:"2/3-Z","`":"5/6+Z",a:"1/6+Z",b:"5/6-Z",c:"1/6-Z",d:"Z+5/6",e:"Z+1/6",f:"Z+1/4",g:"+Y"},Co={"P 1":" !#","P -1":" !#$%&","P 1 2 1":" !#$!&","P 1 21 1":" !#$'&","C 1 2 1":" !#$!&()#*)&","P 1 m 1":" !# %#","P 1 c 1":" !# %+","C 1 m 1":" !# %#()#(,#","C 1 c 1":" !# %+()#(,+","P 1 2/m 1":" !# %#$!&$%&","P 1 21/m 1":" !#$)&$%& ,#","C 1 2/m 1":" !# %#$!&$%&()#(,#*)&*,&","P 1 2/c 1":" !#$!-$%& %+","P 1 21/c 1":" !#$%&$)- ,+","C 1 2/c 1":" !#$!-$%& %+()#*)-*,&(,+","P 2 2 2":" !#$%#$!& %&","P 2 2 21":" !#$%+$!- %&","P 21 21 2":" !#$%#*)&(,&","P 21 21 21":" !#*%+$)-(,&","C 2 2 21":" !#$%+$!- %&()#*,+*)-(,&","C 2 2 2":" !#$%#$!& %&()#*,#*)&(,&","F 2 2 2":" !#$%#$!& %& )+$,+$)- ,-(!+*%+*!-(%-()#*,#*)&(,&","I 2 2 2":" !#$%# %&$!&.'/01/.120'2","I 21 21 21":" !#*%+$)-(,&()+$,#*!& %-","P m m 2":" !#$%# %#$!#","P m c 21":" !#$%+ %+$!#","P c c 2":" !#$%# %+$!+","P m a 2":" !#$%#(%#*!#","P c a 21":" !#$%+(%#*!+","P n c 2":" !#$%# ,+$)+","P m n 21":" !#*%+(%+$!#","P b a 2":" !#$%#(,#*)#","P n a 21":" !#$%+(,#*)+","P n n 2":" !#$%#(,+*)+","C m m 2":" !#$%# %#$!#()#*,#(,#*)#","C m c 21":" !#$%+ %+$!#()#*,+(,+*)#","C c c 2":" !#$%# %+$!+()#*,#(,+*)+","A m m 2":" !#$%# %#$!# )+$,+ ,+$)+","A b m 2":" !#$%# ,#$)# )+$,+ %+$!+","A m a 2":" !#$%#(%#*!# )+$,+(,+*)+","A b a 2":" !#$%#(,#*)# )+$,+(%+*!+","F m m 2":" !#$%# %#$!# )+$,+ ,+$)+(!+*%+(%+*!+()#*,#(,#*)#","F d d 2":" !#$%#345675 )+$,+3896:9(!+*%+;49<79()#*,#;85<:5","I m m 2":" !#$%# %#$!#()+*,+(,+*)+","I b a 2":" !#$%#(,#*)#()+*,+ %+$!+","I m a 2":" !#$%#(%#*!#()+*,+ ,+$)+","P 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!#","P 2/n 2/n 2/n":" !#$%#$!& %&*,-()-(,+*)+","P 2/c 2/c 2/m":" !#$%#$!- %-$%& !& %+$!+","P 2/b 2/a 2/n":" !#$%#$!& %&*,&()&(,#*)#","P 21/m 2/m 2/a":" !#*%#$!&(%&$%&(!& %#*!#","P 2/n 21/n 2/a":" !#*%#*)- ,-$%&(!&(,+$)+","P 2/m 2/n 21/a":" !#*%+*!- %&$%&(!-(%+$!#","P 21/c 2/c 2/a":" !#*%#$!-(%-$%&(!& %+*!+","P 21/b 21/a 2/m":" !#$%#*)&(,&$%& !&(,#*)#","P 21/c 21/c 2/n":" !#*,#$)-(%-$%&()& ,+*!+","P 2/b 21/c 21/m":" !#$%+$)- ,&$%& !- ,+$)#","P 21/n 21/n 2/m":" !#$%#*)-(,-$%& !&(,+*)+","P 21/m 21/m 2/n":" !#$%#*'&.,&*,&.'& %#$!#","P 21/b 2/c 21/n":" !#*,+$!-(,&$%&()- %+*)#","P 21/b 21/c 21/a":" !#*%+$)-(,&$%&(!- ,+*)#","P 21/n 21/m 21/a":" !#0%/$'&.12$%&.!2 1#0'/","C 2/m 2/c 21/m":" !#$%+$!- %&$%& !- %+$!#()#*,+*)-(,&*,&()-(,+*)#","C 2/m 2/c 21/a":" !#$,+$)- %&$%& )- ,+$!#()#*%+*!-(,&*,&(!-(%+*)#","C 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!#()#*,#*)&(,&*,&()&(,#*)#","C 2/c 2/c 2/m":" !#$%#$!- %-$%& !& %+$!+()#*,#*)-(,-*,&()&(,+*)+","C 2/m 2/m 2/a":" !#$,#$)& %&$%& )& ,#$!#()#*%#*!&(,&*,&(!&(%#*)#","C 2/c 2/c 2/a":" !#*,#$!&(,&$,-(!- ,+*!+()#$%#*)& %&*%- )-(%+$)+","F 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!# )+$,+$)- ,-$,- )- ,+$)+(!+*%+*!-(%-*%-(!-(%+*!+()#*,#*)&(,&*,&()&(,#*)#","F 2/d 2/d 2/d":" !#$%#$!& %&64=37=345675 )+$,+$)- ,-68>3:>3896:9(!+*%+*!-(%-<4>;7>;49<79()#*,#*)&(,&<8=;:=;85<:5","I 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!#()+*,+*)-(,-*,-()-(,+*)+","I 2/b 2/a 2/m":" !#$%#*)&(,&$%& !&(,#*)#()+*,+$!- %-*,-()- %+$!+","I 21/b 21/c 21/a":" !#*%+$)-(,&$%&(!- ,+*)#()+$,#*!& %-*,- )&(%#$!+","I 21/m 21/m 21/a":" !#$,#$)& %&$%& )& ,#$!#()+*%+*!-(,-*,-(!-(%+*)+","P 4":" !#$%#% #!$#","P 41":" !#$%+% 5!$9","P 42":" !#$%#% +!$+","P 43":" !#$%+% 9!$5","I 4":" !#$%#% #!$#()+*,+,(+)*+","I 41":" !#*,+%(5)$9()+$%#, 9!*5","P -4":" !#$%#!$&% &","I -4":" !#$%#!$&% &()+*,+)*-,(-","P 4/m":" !#$%#% #!$#$%& !&!$&% &","P 42/m":" !#$%#% +!$+$%& !&!$-% -","P 4/n":" !#$%#,(#)*#*,&()&!$&% &","P 42/n":" !#$%#,(+)*+*,-()-!$&% &","I 4/m":" !#$%#% #!$#$%& !&!$&% &()+*,+,(+)*+*,-()-)*-,(-","I 41/a":" !#*,+%(5)$9$,=(!>!$&,(-()+$%#, 9!*5*%> )=)*-% &","P 4 2 2":" !#$%#% #!$#$!& %&! &%$&","P 4 21 2":" !#$%#,(#)*#*)&(,&! &%$&","P 41 2 2":" !#$%+% 5!$9$!& %-! >%$=","P 41 21 2":" !#$%+,(5)*9*)=(,>! &%$-","P 42 2 2":" !#$%#% +!$+$!& %&! -%$-","P 42 21 2":" !#$%#,(+)*+*)-(,-! &%$&","P 43 2 2":" !#$%+% 9!$5$!& %-! =%$>","P 43 21 2":" !#$%+,(9)*5*)>(,=! &%$-","I 4 2 2":" !#$%#% #!$#$!& %&! &%$&()+*,+,(+)*+*)-(,-)(-,*-","I 41 2 2":" !#*,+%(5)$9*!> ,=)(-%$&()+$%#, 9!*5$)=(%>! &,*-","P 4 m m":" !#$%#% #!$# %#$!#%$#! #","P 4 b m":" !#$%#% #!$#(,#*)#,*#)(#","P 42 c m":" !#$%#% +!$+ %+$!+%$#! #","P 42 n m":" !#$%#,(+)*+(,+*)+%$#! #","P 4 c c":" !#$%#% #!$# %+$!+%$+! +","P 4 n c":" !#$%#% #!$#(,+*)+,*+)(+","P 42 m c":" !#$%#% +!$+ %#$!#%$+! +","P 42 b c":" !#$%#% +!$+(,#*)#,*+)(+","I 4 m m":" !#$%#% #!$# %#$!#%$#! #()+*,+,(+)*+(,+*)+,*+)(+","I 4 c m":" !#$%#% #!$# %+$!+%$+! +()+*,+,(+)*+(,#*)#,*#)(#","I 41 m d":" !#*,+%(5)$9 %#*)+%*5) 9()+$%#, 9!*5(,+$!#,$9!(5","I 41 c d":" !#*,+%(5)$9 %+*)#%*9) 5()+$%#, 9!*5(,#$!+,$5!(9","P -4 2 m":" !#$%#% &!$&$!& %&%$#! #","P -4 2 c":" !#$%#% &!$&$!- %-%$+! +","P -4 21 m":" !#$%#% &!$&*)&(,&,*#)(#","P -4 21 c":" !#$%#% &!$&*)-(,-,*+)(+","P -4 m 2":" !#$%#!$&% & %#$!#! &%$&","P -4 c 2":" !#$%#% &!$& %+$!+! -%$-","P -4 b 2":" !#$%#% &!$&(,#*)#)(&,*&","P -4 n 2":" !#$%#% &!$&(,+*)+)(-,*-","I -4 m 2":" !#$%#% &!$& %#$!#! &%$&()+*,+,(-)*-(,+*)+)(-,*-","I -4 c 2":" !#$%#% &!$& %+$!+! -%$-()+*,+,(-)*-(,#*)#)(&,*&","I -4 2 m":" !#$%#% &!$&$!& %&%$#! #()+*,+,(-)*-*)-(,-,*+)(+","I -4 2 d":" !#$%#% &!$&*!>(%>,$9) 9()+*,+,(-)*-$)= ,=%*5!(5","P 4/m 2/m 2/m":" !#$%#% #!$#$!& %&! &%$&$%& !&!$&% & %#$!#%$#! #","P 4/m 2/c 2/c":" !#$%#% #!$#$!- %-! -%$-$%& !&!$&% & %+$!+%$+! +","P 4/n 2/b 2/m":" !#$%#% #!$#$!& %&! &%$&*,&()&)*&,(&(,#*)#,*#)(#","P 4/n 2/n 2/c":" !#$%#% #!$#$!& %&! &%$&*,-()-)*-,(-(,+*)+,*+)(+","P 4/m 21/b 2/m":" !#$%#% #!$#*)&(,&)(&,*&$%& !&!$&% &(,#*)#,*#)(#","P 4/m 21/n 2/c":" !#$%#% #!$#*)-(,-)(-,*-$%& !&!$&% &(,+*)+,*+)(+","P 4/n 21/m 2/m":" !#$%#,(#)*#*)&(,&! &%$&*,&()&!$&% & %#$!#,*#)(#","P 4/n 2/c 2/c":" !#$%#,(#)*#*)-(,-! -%$-*,&()&!$&% & %+$!+,*+)(+","P 42/m 2/m 2/c":" !#$%#% +!$+$!& %&! -%$-$%& !&!$-% - %#$!#%$+! +","P 42/m 2/c 2/m":" !#$%#% +!$+$!- %-! &%$&$%& !&!$-% - %+$!+%$#! #","P 42/n 2/b 2/c":" !#$%#,(+)*+$!- %-)(&,*&*,-()-!$&% &(,#*)#%$+! +","P 42/n 2/n 2/m":" !#$%#,(+)*+$!& %&)(-,*-*,-()-!$&% &(,+*)+%$#! #","P 42/m 21/b 2/c":" !#$%#% +!$+*)&(,&)(-,*-$%& !&!$-% -(,#*)#,*+)(+","P 42/m 21/n 2/m":" !#$%#,./'*/*'-.,-! &%$&$%& !&'*-,.-.,/*'/%$#! #","P 42/n 21/m 2/c":" !#$%#,(+)*+*)-(,-! &%$&*,-()-!$&% & %#$!#,*+)(+","P 42/n 21/c 2/m":" !#$%#,(+)*+*)&(,&! -%$-*,-()-!$&% & %+$!+,*#)(#","I 4/m 2/m 2/m":" !#$%#% #!$#$!& %&! &%$&$%& !&!$&% & %#$!#%$#! #()+*,+,(+)*+*)-(,-)(-,*-*,-()-)*-,(-(,+*)+,*+)(+","I 4/m 2/c 2/m":" !#$%#% #!$#$!- %-! -%$-$%& !&!$&% & %+$!+%$+! +()+*,+,(+)*+*)&(,&)(&,*&*,-()-)*-,(-(,#*)#,*#)(#","I 41/a 2/m 2/d":" !#*,+%(5)$9*!> ,=)(-%$&$,=(!>!$&,(-(,+$!#,$9!(5()+$%#, 9!*5$)=(%>! &,*-*%> )=)*-% & %#*)+%*5) 9","I 41/a 2/c 2/d":" !#*,+%(5)$9*!= ,>)(&%$-$,=(!>!$&,(-(,#$!+,$5!(9()+$%#, 9!*5$)>(%=! -,*&*%> )=)*-% & %+*)#%*9) 5","P 3":" !#%?#@$#","P 31":" !#%?A@$B","P 32":" !#%?B@$A","H 3":" !#%?#@$#CDAEFAGHAIJBKLBMNB","R 3":" !## !!# ","P -3":" !#%?#@$#$%&!@&? &","H -3":" !#%?#@$#$%&!@&? &OPQRSQTUQVWXYZX[]X]Y^W[^ZV^UR_PT_SO_","R -3":" !## !!# $%&&$%%&$","P 3 1 2":" !#%?#@$#%$&@!& ?&","P 3 2 1":" !#%?#@$#! &?%&$@&","P 31 1 2":" !#%?Q@$^%$_@!X ?&","P 31 2 1":" !#%?A@$B! &?%_$@X","P 32 1 2":" !#%?^@$Q%$X@!_ ?&","P 32 2 1":" !#%?B@$A! &?%X$@_","H 3 2":" !#%?#@$#! &?%&$@&OPQRSQTUQY]X[WXVZX]Y^W[^ZV^PO_SR_UT_","R 3 2":" !## !!# %$&$&%&%$","P 3 m 1":" !#%?#@$#%$#@!# ?#","P 3 1 m":" !#%?#@$#! #?%#$@#","P 3 c 1":" !#%?#@$#%$+@!+ ?+","P 3 1 c":" !#%?#@$#! +?%+$@+","H 3 m":" !#%?#@$#%$#@!# ?#OPQRSQTUQRUQTPQOSQ]Y^W[^ZV^WV^ZY^][^","R 3 m":" !## !!# ! # #!#! ","H 3 c":" !#%?#@$#%$+@!+ ?+OPQRSQTUQRU`TP`OS`]Y^W[^ZV^WVaZYa][a","R 3 c":" !## !!# '././'/'.","P -3 1 2/m":" !#%?#@$#%$&@!& ?&$%&!@&? &! #?%#$@#","P -3 1 2/c":" !#%?#@$#%$-@!- ?-$%&!@&? &! +?%+$@+","P -3 2/m 1":" !#%?#@$#! &?%&$@&$%&!@&? &%$#@!# ?#","P -3 2/c 1":" !#%?#@$#! -?%-$@-$%&!@&? &%$+@!+ ?+","H -3 2/m":" !#%?#@$#! &?%&$@&$%&!@&? &%$#@!# ?#OPQRSQTUQY]X[WXVZXVWXYZX[]XRUQTPQOSQ]Y^W[^ZV^PO_SR_UT_UR_PT_SO_WV^ZY^][^","R -3 2/m":" !## !!# %$&$&%&%$$%&&$%%&$! # #!#! ","H -3 2/c":" !#%?#@$#! -?%-$@-$%&!@&? &%$+@!+ ?+OPQRSQTUQY]b[WbVZbVWXYZX[]XRU`TP`OS`]Y^W[^ZV^POcSRcUTcUR_PT_SO_WVaZYa][a","R -3 2/c":" !## !!# 102021210$%&&$%%&$'././'/'.","P 6":" !#%?#@$#$%#!@#? #","P 61":" !#%?A@$B$%/!@d? e","P 65":" !#%?B@$A$%/!@e? d","P 62":" !#%?^@$Q$%#!@^? Q","P 64":" !#%?Q@$^$%#!@Q? ^","P 63":" !#%?#@$#$%+!@+? +","P -6":" !#%?#@$# !&%?&@$&","P 6/m":" !#%?#@$#$%#!@#? #$%&!@&? & !&%?&@$&","P 63/m":" !#%?#@$#$%+!@+? +$%&!@&? & !-%?-@$-","P 6 2 2":" !#%?#@$#$%#!@#? #! &?%&$@&%$&@!& ?&","P 61 2 2":" !#%?Q@$^$%+!@`? a! X?%&$@_%$b@!- ?c","P 65 2 2":" !#%?^@$Q$%+!@a? `! _?%&$@X%$c@!- ?b","P 62 2 2":" !#%?^@$Q$%#!@^? Q! _?%&$@X%$_@!& ?X","P 64 2 2":" !#%?Q@$^$%#!@Q? ^! X?%&$@_%$X@!& ?_","P 63 2 2":" !#%?#@$#$%+!@+? +! &?%&$@&%$-@!- ?-","P 6 m m":" !#%?#@$#$%#!@#? #%$#@!# ?#! #?%#$@#","P 6 c c":" !#%?#@$#$%#!@#? #%$+@!+ ?+! +?%+$@+","P 63 c m":" !#%?#@$#$%+!@+? +%$+@!+ ?+! #?%#$@#","P 63 m c":" !#%?#@$#$%+!@+? +%$#@!# ?#! +?%+$@+","P -6 m 2":" !#%?#@$# !&%?&@$&%$#@!# ?#%$&@!& ?&","P -6 c 2":" !#%?#@$# !-%?-@$-%$+@!+ ?+%$&@!& ?&","P -6 2 m":" !#%?#@$# !&%?&@$&! &?%&$@&! #?%#$@#","P -6 2 c":" !#%?#@$# !-%?-@$-! &?%&$@&! +?%+$@+","P 6/m 2/m 2/m":" !#%?#@$#$%#!@#? #! &?%&$@&%$&@!& ?&$%&!@&? & !&@$&%?&%$#@!# ?#! #?%#$@#","P 6/m 2/c 2/c":" !#%?#@$#$%#!@#? #! -?%-$@-%$-@!- ?-$%&!@&? & !&@$&%?&%$+@!+ ?+! +?%+$@+","P 63/m 2/c 2/m":" !#%?#@$#$%+!@+? +! -?%-$@-%$&@!& ?&$%&!@&? & !-@$-%?-%$+@!+ ?+! #?%#$@#","P 63/m 2/m 2/c":" !#%?#@$#$%+!@+? +! &?%&$@&%$-@!- ?-$%&!@&? & !-@$-%?-%$#@!# ?#! +?%+$@+","P 2 3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ","F 2 3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%&  )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-((!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- ","I 2 3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-(","P 21 3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(","I 21 3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- ","P 2/m -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& $%& !& %#$!#&$%& !# %#$!%&$!& %# !#$","P 2/n -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& *,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*","F 2/m -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& $%& !& %#$!#&$%& !# %#$!%&$!& %# !#$ )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-($,- )- ,+$)+&*,&()#(,#*)%-*!-(%+(!+*(!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(*%-(!-(%+*!+-$,- )+ ,+$),&*)&(,#()#*()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- *,&()&(,#*)#-*%-(!+(%+*!,-$)- ,+ )+$","F 2/d -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& 64=37=345675=64=375345674=67=3453756 )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(68>3:>3896:9=<8=;:5;85<:4><7>;49;79<(!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(<4>;7>;49<79>68>3:93896:8=<:=;85;:5<()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- <8=;:=;8f<:f><4>;79;49<78>6:>3893:96","I 2/m -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& $%& !& %#$!#&$%& !# %#$!%&$!& %# !#$()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-(*,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*","P 21/a -3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&($%&(!- ,+*)#&$%-(!+ ,#*)%&$!-(,+ )#*","I 21/a -3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&($%&(!- ,+*)#&$%-(!+ ,#*)%&$!-(,+ )#*()+$,#*g& %-+()#$,&*!- %)+(,#$!&*%- *,- )&(%#$!+-*,& )#(%+$!,-*)& %#(!+$","P 4 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$","P 42 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*","F 4 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$ )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(!(-%*-!*+%(+ +,$+)$-, -)#)*#,(&)(&,*(!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&() -,$-)$+, +(#,*#)*&,(&)+!*+%(-!(-%*()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- )(&,*&)*#,(#(+%*+!*-%(-!+)$+, -) -,$","F 41 3 2":" !#$,+*)&(%-# !+$,&*)-(%!# ,+$)&*%-(:3>46=7<98;5;58<976=43>:97<58;>:3=46 )+$%#*!-(,&#()+*%&$!- ,!+(,#*)-$%& :;=4<>765839;94<5:6>83=79:6543>7;=8<(!+*,#$)- %&+ )#$%-*!&(,)#(%+*!&$,- 73=86>:<54;935469:<=8;>7576983=:;>4<()#*%+$!& ,-+(!#*,-$)& %)+ %#$!-*,&(7;>8<=:69435398657<>4;=:5:<94;=73>86","I 4 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-()(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*","P 43 3 2":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(7;>46=:<5839398<5:6=4;>75:<983>7;=46","P 41 3 2":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(:3=8<>7694;5;54697<>83=:97654;=:3>8<","I 41 3 2":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(:3=8<>7694;5;54697<>83=:97654;=:3>8<()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- 7;>46=:<5839398<5:6=4;>75:<983>7;=46","P -4 3 m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! #%$#!$&% & #!$#%$&! &%#! #%$&!$&% ","F -4 3 m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! #%$#!$&% & #!$#%$&! &%#! #%$&!$&%  )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(!(+%*+!*-%(- +)$+,$-) -,#)(#,*&)*&,((!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&() +,$+)$-, -(#)*#,*&)(&,+!(+%*-!*-%(()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- )(#,*#)*&,(&(+!*+%*-!(-%+) +,$-)$-, ","I -4 3 m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! #%$#!$&% & #!$#%$&! &%#! #%$&!$&% ()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-()(+,*+)*-,(-(+)*+,*-)(-,+)(+,*-)*-,(","P -4 3 n":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(+,*+)*-,(-(+)*+,*-)(-,+)(+,*-)*-,(","F -4 3 c":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(+,*+)*-,(-(+)*+,*-)(-,+)(+,*-)*-,( )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-() #,$#)$&, &(#!*#%*&!(&%+! +%$-!$-% (!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(!(#%*#!*&%(& +!$+%$-! -%#) #,$&)$&, ()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- ! +%$+!$-% - #)$#,$&) &,#!(#%*&!*&%(","I -4 3 d":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(7354<9:6>8;=357<946>:;=857394<>:6=8;()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- :;98657<=43>;9:658<=73>49:;586=7<>43","P 4/m -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$%$#! #% &!$&$&! &% #!$#%&% &!$#%$#! ","P 4/n -3 2/n":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$*,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)(","P 42/m -3 2/n":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)(","P 42/n -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,**,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*%$#! #% &!$&$&! &% #!$#%&% &!$#%$#! ","F 4/m -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$%$#! #% &!$&$&! &% #!$#%&% &!$#%$#!  )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(!(-%*-!*+%(+ +,$+)$-, -)#)*#,(&)(&,*$,- )- ,+$)+&*,&()#(,#*)%-*!-(%+(!+*%*+!(+%(-!*-$-) -, +)$+,&,(&)*#,*#)((!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&() -,$-)$+, +(#,*#)*&,(&)+!*+%(-!(-%**%-(!-(%+*!+-$,- )+ ,+$),&*)&(,#()#*,$+) +, -)$-*&)(&,(#)*#,-%(-!*+%*+!(()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- )(&,*&)*#,(#(+%*+!*-%(-!+)$+, -) -,$*,&()&(,#*)#-*%-(!+(%+*!,-$)- ,+ )+$,*#)(#,(&)*&*-!(-%(+!*+%-, -)$+,$+) ","F 4/m -3 2/c":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)( )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-() &,$&)$#, #(#%*#!*&%(&!+!$+% -! -%$$,- )- ,+$)+&*,&()#(,#*)%-*!-(%+(!+*,$#) #, &)$&*&!(&%(#!*#%-% -!$+%$+! (!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(!(&%*&!*#%(# +%$+!$-% -!#)$#, &) &,$*%-(!-(%+*!+-$,- )+ ,+$),&*)&(,#()#*%*#!(#%(&!*&$-! -% +!$+%&, &)$#,$#) ()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- ! -%$-!$+% + #,$#)$&, &)#!*#%(&!(&%**,&()&(,#*)#-*%-(!+(%+*!,-$)- ,+ )+$%$+! +% -!$-$&) &, #)$#,&%(&!*#%*#!(","F 41/d -3 2/m":" !#$,+*)&(%-# !+$,&*)-(%!# ,+$)&*%-(:3>46=7<98;5;58<976=43>:97<58;>:3=4664=3:>;85<79=64>3:5;89<74=6:>385;79<,$+! #%(-)*&*&)(-% #!$+,-%(&)*+,$#!  )+$%#*!-(,&#()+*%&$!- ,!+(,#*)-$%& :;=4<>765839;94<5:6>83=79:6543>7;=8<68>37=;49<:5=<8>;753496:4><:=;893756,*#!(+% &)$-*-!(&, +)$#%-, &!$+%*#)((!+*,#$)- %&+ )#$%-*!&(,)#(%+*!&$,- 73=86>:<54;935469:<=8;>7576983=:;>4<<4>;:=389675>68=379;45<:8=<7>;453:96%$#) +,(&!*-$&! -,(#)*+%&% -)$#,*+!(()#*%+$!& ,-+(!#*,-$)& %)+ %#$!-*,&(7;>8<=:69435398657<>4;=:5:<94;=73>86<8=;7>3456:9><4=;:9385678>67=349;:5<%*+)(#, -!$&$-) &%(+!*#,&,(-!*#%$+) ","F 41/d -3 2/c":" !#$,+*)&(%-# !+$,&*)-(%!# ,+$)&*%-(:3>46=7<98;5;58<976=43>:97<58;>:3=46<8>;7=3496:5><8=;793456:8><7=;493:56%*#)(+, &!$-$-! &,(+)*#%&, -!$#%*+)( )+$%#*!-(,&#()+*%&$!- ,!+(,#*)-$%& :;=4<>765839;94<5:6>83=79:6543>7;=8<<4=;:>385679>64=3:9;85<78=67>345;:9<%$+) #,(-!*&$&) -%(#!*+,&%(-)*#,$+! (!+*,#$)- %&+ )#$%-*!&(,)#(%+*!&$,- 73=86>:<54;935469:<=8;>7576983=:;>4<68=37>;45<:9=<4>;:5389674>6:=389;75<,*+!(#% -)$&*-)(&% +!$#,-,(&!*+%$#) ()#*%+$!& ,-+(!#*,-$)& %)+ %#$!-*,&(7;>8<=:69435398657<>4;=:5:<94;=73>8664>3:=;89<75=68>375;49<:4=<:>;853796,$#! +%(&)*-*&!(-, #)$+%-% &)$+,*#!(","I 4/m -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$%$#! #% &!$&$&! &% #!$#%&% &!$#%$#! ()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-()(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,**,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)(","I 41/a -3 2/d":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(:3=8<>7694;5;54697<>83=:97654;=:3>8<$%&(!- ,+*)#&$%-(!+ ,#*)%&$!-(,+ )#*4<97358;=:6>6>:;=8357<94=8;>:694<573()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- 7;>46=:<5839398<5:6=4;>75:<983>7;=46*,- )&(%#$!+-*,& )#(%+$!,-*)& %#(!+$865:;943>7<=<=73>4;9:658>43=7<5869:;","P 1 1 2":" !#$%#","P 1 1 21":" !#$%+","B 1 1 2":" !#$%#(g+*%+","A 1 2 1":" !#$!& )+$)-","C 1 21 1":" !#$)&()#*!&","I 1 2 1":" !#$!&.'/0'2","I 1 21 1":" !#$)&.'/0!-","P 1 1 m":" !# !&","P 1 1 b":" !# )&","B 1 1 m":" !# !&(!+(!-","B 1 1 b":" !# )&(!+()-","P 1 1 2/m":" !# !&$%#$%&","P 1 1 21/m":" !#$%+$%& !-","B 1 1 2/m":" !# !&$%#$%&(!+(!-*%+*%-","P 1 1 2/b":" !#$,#$%& )&","P 1 1 21/b":" !#$%&$,+ )-","B 1 1 2/b":" !#$,#$%& )&(!+*,+*%-()-","P 21 2 2":" !#$!&(%&*%#","P 2 21 2":" !# ,&$)&$%#","P 21 21 2 (a)":" !#*,#.%&$'&","P 21 2 21":" !#$!&(%-*%+","P 2 21 21":" !# %&$)-$,+","C 2 2 21a)":" !#*%+(,&$)-()#$,+ %&*!-","C 2 2 2a":" !#*,#.%&$'&()#$%# ,&*!&","F 2 2 2a":" !#*,#.%&$'& '/*%/.12$!2.!/$,/ %20'2.'#$%# 1&0!&","I 2 2 2a":" !#*,#.%&$'&()+$%+*!- ,-","P 21/m 21/m 2/n a":" !#*,#$)&(%&$%&.'& ,#*!#","P 42 21 2a":" !#*,#%.+'$+$'&.%&! -,*-","I 2 3a":" !#*,#.%&$'&!# ,- '&$%/$# !-*!/$%&.%()+$%+ ,-*!-)+(%&(!-*,#*+()&$)#*,- ,"},Po=/^[1-9]$/;function Io(t){let e="";return t.length>0&&(e=":"+b(t).join(" OR :")),new gt(e)}class ko{constructor(t=""){this.name=t,this.partList=[]}get type(){return"Assembly"}addPart(t,e){const i=new Mo(t,e);return this.partList.push(i),i}getAtomCount(t){return this.partList.reduce(((e,i)=>e+i.getAtomCount(t)),0)}getResidueCount(t){return this.partList.reduce(((e,i)=>e+i.getResidueCount(t)),0)}getInstanceCount(){let t=0;return this.partList.forEach((function(e){t+=e.matrixList.length})),t}isIdentity(t){if(1!==this.partList.length)return!1;const i=this.partList[0];if(1!==i.matrixList.length)return!1;if(!(new e.Matrix4).equals(i.matrixList[0]))return!1;let r=[];return t.eachChain((function(t){r.push(t.chainname)})),r=b(r),i.chainList.length===r.length}getBoundingBox(t){const i=new e.Box3;return this.partList.forEach((function(e){const r=e.getBoundingBox(t);i.expandByPoint(r.min),i.expandByPoint(r.max)})),i}getCenter(t){return this.getBoundingBox(t).getCenter(new e.Vector3)}getSelection(){let t=[];return this.partList.forEach((function(e){t=t.concat(e.chainList)})),Io(t)}}class Mo{constructor(t=[],e=[]){this.matrixList=t,this.chainList=e}get type(){return"AssemblyPart"}_getCount(t,e){let i=0;return t.eachChain((t=>{(0===this.chainList.length||this.chainList.includes(t.chainname))&&(i+=t[e])})),this.matrixList.length*i}getAtomCount(t){return this._getCount(t,"atomCount")}getResidueCount(t){return this._getCount(t,"residueCount")}getBoundingBox(t){const i=new e.Box3,r=new e.Box3,n=this.getSelection(),s=t.getBoundingBox(n);return this.matrixList.forEach((function(t){r.copy(s).applyMatrix4(t),i.expandByPoint(r.min),i.expandByPoint(r.max)})),i}getSelection(){return Io(this.chainList)}getView(t){const e=this.getSelection();return e?t.getView(e):t}getInstanceList(){const t=[];for(let e=0,i=this.matrixList.length;e<i;++e)t.push({id:e+1,name:e,matrix:this.matrixList[e]});return t}}class To{constructor(t){this.structure=t,this.currentModelindex=null,this.currentChainid=null,this.currentResname=null,this.currentResno=null,this.currentInscode=void 0,this.currentHetero=null,this.previousResname="",this.previousHetero=null,this.ai=-1,this.ri=-1,this.ci=-1,this.mi=-1}addResidueType(t){var e,i;const r=this.structure.atomStore,n=this.structure.residueStore,s=this.structure.residueMap,o=null===(e=this.structure.chemCompMap)||void 0===e?void 0:e.dict[this.previousResname],a=n.atomCount[t],c=n.atomOffset[t],l=new Array(a);for(let t=0;t<a;++t)l[t]=r.atomTypeId[c+t];const u=null==o?void 0:o.chemCompType,h=o?null===(i=this.structure.chemCompMap)||void 0===i?void 0:i.getBonds(this.previousResname,l):void 0;n.residueTypeId[t]=s.add(this.previousResname,l,this.previousHetero,u,h)}addAtom(t,e,i,r,n,s,o,a){const c=this.structure.atomStore,l=this.structure.residueStore,u=this.structure.chainStore,h=this.structure.modelStore;let d=!1,m=!1,f=!1;this.currentModelindex!==t?(d=!0,m=!0,f=!0,this.mi+=1,this.ci+=1,this.ri+=1):this.currentChainid!==i?(m=!0,f=!0,this.ci+=1,this.ri+=1):this.currentResno===n&&this.currentResname===r&&this.currentInscode===a||(f=!0,this.ri+=1),this.ai+=1,d&&(h.growIfFull(),h.chainOffset[this.mi]=this.ci,h.chainCount[this.mi]=0,h.count+=1,u.modelIndex[this.ci]=this.mi),m&&(u.growIfFull(),u.setChainname(this.ci,e),u.setChainid(this.ci,i),u.residueOffset[this.ci]=this.ri,u.residueCount[this.ci]=0,u.count+=1,u.modelIndex[this.ci]=this.mi,h.chainCount[this.mi]+=1,l.chainIndex[this.ri]=this.ci),f&&(this.previousResname=this.currentResname,this.previousHetero=this.currentHetero,this.ri>0&&this.addResidueType(this.ri-1),l.growIfFull(),l.resno[this.ri]=n,void 0!==o&&(l.sstruc[this.ri]=o.charCodeAt(0)),void 0!==a&&(l.inscode[this.ri]=a.charCodeAt(0)),l.atomOffset[this.ri]=this.ai,l.atomCount[this.ri]=0,l.count+=1,l.chainIndex[this.ri]=this.ci,u.residueCount[this.ci]+=1),c.count+=1,c.residueIndex[this.ai]=this.ri,l.atomCount[this.ri]+=1,this.currentModelindex=t,this.currentChainid=i,this.currentResname=r,this.currentResno=n,this.currentInscode=a,this.currentHetero=s}finalize(){this.previousResname=this.currentResname,this.previousHetero=this.currentHetero,this.ri>-1&&this.addResidueType(this.ri)}}function Do(e,i){if(!i)return;t.Debug&&Dt.time("assignSecondaryStructure");const r=[];e.eachModel((function(t){t.eachChain((function(t){r.push(t.chainname)}))}));const n=r.slice().sort(),s=[];n.forEach((function(t){s.push(r.indexOf(t))}));const o=i.helices.filter((function(t){return g(n,t[0])>=0}));o.sort((function(t,e){const i=t[0],r=e[0],o=t[1],a=e[1];if(i===r)return o===a?0:o<a?-1:1;{const t=g(n,i),e=g(n,r);return s[t]<s[e]?-1:1}}));const a=e.residueStore;e.eachModel((function(t){let e=0;const i=o.length;if(0===i)return;let r=o[e],n=!1,s=!1;t.eachChain((function(t){let c=!1;if(t.chainname===r[0]){const l=t.residueCount,u=t.residueOffset,h=u+l;for(let l=u;l<h;++l)if(a.resno[l]===r[1]&&a.getInscode(l)===r[2]&&(n=!0),n&&(a.sstruc[l]=r[6],a.resno[l]===r[4]&&a.getInscode(l)===r[5]&&(n=!1,e+=1,e<i?(l=u-1,r=o[e],c=t.chainname!==r[0]):s=!0)),c||s)return}}))}));const c=i.sheets.filter((function(t){return g(n,t[0])>=0}));c.sort((function(t,e){const i=t[0],r=e[0];if(i===r)return 0;const o=g(n,i),a=g(n,r);return s[o]<s[a]?-1:1}));const l="e".charCodeAt(0);e.eachModel((function(t){let e=0;const i=c.length;if(0===i)return;let r=c[e],n=!1,s=!1;t.eachChain((function(t){let o=!1;if(t.chainname===r[0]){const u=t.residueCount,h=t.residueOffset,d=h+u;for(let u=h;u<d;++u)if(a.resno[u]===r[1]&&a.getInscode(u)===r[2]&&(n=!0),n&&(a.sstruc[u]=l,a.resno[u]===r[4]&&a.getInscode(u)===r[5]&&(n=!1,e+=1,e<i?(u=h-1,r=c[e],o=t.chainname!==r[0]):s=!0)),o||s)return}}))})),t.Debug&&Dt.timeEnd("assignSecondaryStructure")}const Bo=function(){const i=function(t,e,i,r){const n=t.structure,s=t.residueIndexStart,o=n.getResidueProxy(),a=n.getResidueProxy(),c=n.getAtomProxy(),l=n.getAtomProxy();for(let n=Math.max(0,e-2);n<=e;++n)for(let e=2;e<5;++e){if(n+e>=t.residueCount)continue;o.index=s+n,a.index=s+n+e,c.index=o.traceAtomIndex,l.index=a.traceAtomIndex;const u=c.distanceTo(l);if(Math.abs(u-i[e-2])>r)return!1}return!0},r=function(t,e){return i(t,e,[5.45,5.18,6.37],2.1)},n=function(t,e){return i(t,e,[6.1,10.4,13],1.42)};return function(i){t.Debug&&Dt.time("calculateSecondaryStructure"),i.eachPolymer((function(t){if(t.residueCount<4)return;if(t.isCg())!function(t){const i=t.residueStore,r=t.residueIndexStart,n=new go(t).position,s=new e.Vector3,o=new e.Vector3;for(let e=0,a=t.residueCount;e<a;++e){s.fromArray(n.center,3*e),o.fromArray(n.center,3*e+3);const t=s.distanceTo(o);t<2&&t>1&&n.bending[e]<20&&(i.sstruc[r+e]="h".charCodeAt(0),i.sstruc[r+e+1]="h".charCodeAt(0))}}(t);else{if(!t.isProtein())return;!function(t){const e=t.residueStore,i=t.residueIndexStart;for(let s=0,o=t.residueCount;s<o;++s){let o="c";r(t,s)?o="h":n(t,s)&&(o="e"),e.sstruc[i+s]=o.charCodeAt(0)}}(t)}let i,s=0;t.eachResidue((function(t){t.sstruc===i?s+=1:(1===s&&(t.index-=1,t.sstruc="c"),s=1,i=t.sstruc)}))})),t.Debug&&Dt.timeEnd("calculateSecondaryStructure")}}(),Fo="ABCDEFGHIJKLMNOPQRSTUVWXYZ";function Eo(t){const e=Fo.length;let i=t,r=0,n=Fo[i%e];for(;i>=e;)i=Math.floor(i/e),n+=Fo[i%e],r+=1;return r>=5&&Dt.warn("chainname overflow"),n}function Oo(e,i=!1){t.Debug&&Dt.time("calculateChainnames");let r=!0;if(e.eachChain((function(t){t.chainname&&(r=!1)})),r){const t=e.modelStore,r=e.chainStore,n=e.residueStore,s=function(e,i,s,o){const a=r.count;for(let t=0;t<o;++t)n.chainIndex[s+t]=a;r.growIfFull(),r.modelIndex[a]=e,r.setChainname(a,i),r.setChainid(a,i),r.residueOffset[a]=s,r.residueCount[a]=o,r.count+=1,t.chainCount[e]+=1},o=e.getAtomProxy(),a=e.getAtomProxy();let c=0,l=0,u=0,h=0;const d=[];1===n.count?d.push({mIndex:0,chainname:"A",rStart:0,rCount:1}):e.eachResidueN(2,(function(t,e){let r=!1;const s=t.backboneType,m=e.backboneType,f=Mr;h=t.index,t.modelIndex!==e.modelIndex||t.moleculeType!==e.moleculeType?r=!0:s!==f&&s===m&&(o.index=t.backboneEndAtomIndex,a.index=e.backboneStartAtomIndex,r=i?!o.hasBondTo(a):!o.connectedTo(a)),r||e.index!==n.count-1||(r=!0,h=e.index),r&&(d.push({mIndex:l,chainname:Eo(c),rStart:u,rCount:h-u+1}),c+=1,t.modelIndex!==e.modelIndex&&(c=0,l+=1),e.index===n.count-1&&h!==e.index&&d.push({mIndex:l,chainname:Eo(c),rStart:n.count-1,rCount:1}),u=e.index,h=e.index)})),r.count=0,t.chainCount.fill(0,0,t.count),t.chainOffset.fill(0,0,t.count),d.forEach((function(t){s(t.mIndex,t.chainname,t.rStart,t.rCount)}));let m=0;e.eachModel((function(e){t.chainOffset[e.index]=m,m+=t.chainCount[e.index]}))}t.Debug&&Dt.timeEnd("calculateChainnames")}function $o(e,i="all"){"none"!==i&&(t.Debug&&Dt.time("calculateBonds"),No(e,!1,i),zo(e),t.Debug&&Dt.timeEnd("calculateBonds"))}const Ro={"HIS|CD2|CG":2,"HIS|CE1|ND1":2,"ARG|CZ|NH2":2,"PHE|CE1|CZ":2,"PHE|CD2|CE2":2,"PHE|CD1|CG":2,"TRP|CD1|CG":2,"TRP|CD2|CE2":2,"TRP|CE3|CZ3":2,"TRP|CH2|CZ2":2,"ASN|CG|OD1":2,"GLN|CD|OE1":2,"TYR|CD1|CG":2,"TYR|CD2|CE2":2,"TYR|CE1|CZ":2,"ASP|CG|OD1":2,"GLU|CD|OE1":2,"G|C8|N7":2,"G|C4|C5":2,"G|C2|N3":2,"G|C6|O6":2,"C|C4|N3":2,"C|C5|C6":2,"C|C2|O2":2,"A|C2|N3":2,"A|C6|N1":2,"A|C4|C5":2,"A|C8|N7":2,"U|C5|C6":2,"U|C2|O2":2,"U|C4|O4":2,"DG|C8|N7":2,"DG|C4|C5":2,"DG|C2|N3":2,"DG|C6|O6":2,"DC|C4|N3":2,"DC|C5|C6":2,"DC|C2|O2":2,"DA|C2|N3":2,"DA|C6|N1":2,"DA|C4|C5":2,"DA|C8|N7":2,"DT|C5|C6":2,"DT|C2|O2":2,"DT|C4|O4":2};function Lo(t,e,i){return[e,i]=e<i?[e,i]:[i,e],qr.includes(t)&&"C"===e&&"O"===i||Kr.includes(t)&&"OP1"===e&&"P"===i?2:Ro[`${t}|${e}|${i}`]||1}function No(e,i=!1,r="all"){t.Debug&&Dt.time("calculateBondsWithin");const n=e.bondStore,s=e.rungBondStore,o=e.getAtomSet(!1),a=e.getAtomProxy(),c=e.getAtomProxy(),l=e.getBondProxy(),u=i?null:function(e){t.Debug&&Dt.time("calculateAtomBondMap");var i=[];return e.eachBond((function(t){var e=t.atomIndex1,r=t.atomIndex2;void 0===i[e]&&(i[e]=[]),i[e][r]=t.index})),t.Debug&&Dt.timeEnd("calculateAtomBondMap"),i}(e);let h;i||"auto"!==r||(h=new Set,u.forEach(((t,e)=>{h.add(e),t.forEach((t=>{h.add(t)}))}))),e.eachResidue((function(t){if(!i&&u){const e=t.atomCount,i=t.atomOffset;if(e>500)return void Dt.warn("more than 500 atoms, skip residue for auto-bonding",t.qualifiedName());if("auto"===r&&t.hetero)for(let e=t.atomOffset;e<t.atomEnd;e++)if(h.has(e))return;const s=t.getBonds(),o=s.atomIndices1,d=s.atomIndices2,m=s.bondOrders,f=o.length;for(let e=0;e<f;++e){const r=o[e],s=d[e],h=r+i,f=s+i,p=u[h];if(void 0!==p&&void 0!==p[f]){l.index=p[f];m[t.residueType.getBondIndex(r,s)]=l.bondOrder}else a.index=h,c.index=f,n.addBond(a,c,m[e])}}const e=t.residueType.traceAtomIndex,d=t.residueType.rungEndAtomIndex;-1!==e&&-1!==d&&(a.index=t.traceAtomIndex,c.index=t.rungEndAtomIndex,s.addBond(a,c),o.set(a.index),o.set(c.index))})),e.atomSetDict.rung=o,t.Debug&&Dt.timeEnd("calculateBondsWithin")}function zo(e,i=!1,r=!1){t.Debug&&Dt.time("calculateBondsBetween");const n=e.bondStore,s=e.backboneBondStore,o=e.getAtomSet(!1),a=e.getAtomProxy(),c=e.getAtomProxy();function l(t,e){const l=t.backboneType,u=e.backboneType;if(l!==Mr&&l===u){a.index=t.backboneEndAtomIndex,c.index=e.backboneStartAtomIndex;let l=!1,u=!1;r&&a.hasBondTo(c)?(l=!1,u=!0):a.connectedTo(c)&&(l=!i,u=!0),l&&n.addBond(a,c,1),u&&(a.index=t.traceAtomIndex,c.index=e.traceAtomIndex,s.addBond(a,c),o.set(a.index),o.set(c.index))}}0===s.count&&s.resize(e.residueStore.count),e.eachResidueN(2,l);const u=e.getResidueProxy(),h=e.getResidueProxy();if(e.eachChain((function(t){0!==t.residueCount&&(u.index=t.residueOffset,h.index=t.residueOffset+t.residueCount-1,l(h,u))})),e.atomSetDict.backbone=o,!i){t.Debug&&Dt.time("calculateBondsBetween inter");const i=e.spatialHash;e.eachResidue((function(t){t.backboneType!==Mr||t.isWater()||t.eachAtom((function(t){t.isMetal()||i.eachWithin(t.x,t.y,t.z,4,(function(e){c.index=e,t.modelIndex!==c.modelIndex||t.residueIndex===c.residueIndex||c.isMetal()||n.addBondIfConnected(t,c,1)}))}))})),t.Debug&&Dt.timeEnd("calculateBondsBetween inter")}t.Debug&&Dt.timeEnd("calculateBondsBetween")}function Vo(i){if(!i.unitcell)return;t.Debug&&Dt.time("buildUnitcellAssembly");const r=i.unitcell,n=i.center.clone().applyMatrix4(r.cartToFrac),s=n.clone().floor(),o=function(t){const i=Co[t],r={};if(void 0===i)return console.warn(`spacegroup '${t}' not found in symop library`),r;const n=[];for(let t=0,e=i.length;t<e;t+=3){const e=[];for(let r=0;r<3;++r)e.push(So[i[t+r]]);n.push(e)}return n.forEach((function(t){let i=0;const n=(new e.Matrix4).set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),s=n.elements;r[t.toString()]=n,t.forEach((function(t){let e=!1,r=!1;for(let n=0,o=t.length;n<o;++n){const o=t[n];if("-"===o)e=!0;else if("+"===o)e=!1;else if("/"===o)r=!0;else if("X"===o)s[0+i]=e?-1:1;else if("Y"===o)s[4+i]=e?-1:1;else if("Z"===o)s[8+i]=e?-1:1;else if(Po.test(o)){const t=parseInt(o);r?s[12+i]/=t:s[12+i]=t}else Dt.warn(`getSymmetryOperations: unknown token '${o}'`)}i+=1}))})),r}(r.spacegroup),a=new e.Vector3,c=new e.Vector3;function l(t){const e=[];return Object.keys(o).forEach((function(i){const l=o[i].clone();a.copy(n).applyMatrix4(l).floor(),c.setFromMatrixPosition(l),c.sub(a),c.add(s),t&&c.add(t),l.setPosition(c),l.multiplyMatrices(r.fracToCart,l),l.multiply(r.cartToFrac),e.push(l)})),e}const u=new ko("UNITCELL"),h=l(),d=[];if(i.biomolDict.NCS){d.push(new e.Matrix4,...i.biomolDict.NCS.partList[0].matrixList);const t=[];h.forEach((e=>{d.forEach((i=>{t.push(e.clone().multiply(i))}))})),u.addPart(t)}else u.addPart(h);const m=new e.Vector3,f=new ko("SUPERCELL"),p=Array.prototype.concat.call(l(m.set(1,0,0)),l(m.set(0,1,0)),l(m.set(0,0,1)),l(m.set(-1,0,0)),l(m.set(0,-1,0)),l(m.set(0,0,-1)),l(m.set(1,1,0)),l(m.set(1,0,1)),l(m.set(0,1,1)),l(m.set(-1,-1,0)),l(m.set(-1,0,-1)),l(m.set(0,-1,-1)),l(m.set(1,-1,-1)),l(m.set(1,1,-1)),l(m.set(1,-1,1)),l(m.set(-1,1,1)),l(m.set(-1,-1,1)),l(m.set(-1,1,-1)),l(m.set(0,1,-1)),l(m.set(0,-1,1)),l(m.set(1,0,-1)),l(m.set(-1,0,1)),l(m.set(1,-1,0)),l(m.set(-1,1,0)),l(),l(m.set(1,1,1)),l(m.set(-1,-1,-1)));if(i.biomolDict.NCS){const t=[];p.forEach((function(e){d.forEach((function(i){t.push(e.clone().multiply(i))}))})),f.addPart(t)}else f.addPart(p);i.biomolDict.UNITCELL=u,i.biomolDict.SUPERCELL=f,t.Debug&&Dt.timeEnd("buildUnitcellAssembly")}const Uo=["H","C","O","N","S","P"],jo=["NA","CL","FE"];function Go(t){let e=t.toUpperCase(),i=0,r=0;for(let t=0;t<e.length;t++)if(e.charCodeAt(t)<65){if(r>0)break;++i}else r=t+1;(i>0||r<e.length)&&(e=e.substring(i,r));const n=e.length;if(0===n)return"";if(1===n)return e;if(2===n){if(-1!==jo.indexOf(e))return e;if(-1!==Uo.indexOf(e[0]))return e[0];if(e in Lr)return e}return n>=3&&-1!==Uo.indexOf(e[0])?e[0]:""}function Ho(t){const e=t.bondHash,i=e.countArray,r=e.offsetArray,n=e.indexArray,s=t.getBondProxy();t.eachResidue((function(t){const e=t.residueType;if(void 0!==e.bonds)return;var o=t.atomOffset,a=[],c=[],l=[],u={};const h=o+t.atomCount;t.eachAtom((function(t){const e=t.index,d=r[e];for(let t=0,r=i[e];t<r;++t){s.index=n[d+t];let e=s.atomIndex1;if(e<o||e>=h)continue;let i=s.atomIndex2;if(i<o||i>=h)continue;if(e>i){const t=i;i=e,e=t}const r=e+"|"+i;void 0===u[r]&&(u[r]=!0,a.push(e-o),c.push(i-o),l.push(s.bondOrder))}})),e.bonds={atomIndices1:a,atomIndices2:c,bondOrders:l}}))}const qo=[3,11,19,37,55,87],Wo=[4,12,20,38,56,88],Xo=[6,15,16,34],Yo=[1,7,8,9,17,35,53],Ko=[2,10,18,36,54,86],Zo=[13,30,31,48,49,50,80,81,82,83,84,85,112],Qo=[5,14,32,33,51,52,85],Jo=[9,17,35,53,85];class ta{constructor(t,e,i){this.structure=t,this.atomname=e,i=i||Go(e),this.element=i,this.number=Lr[i]||0,this.vdw=Nr[this.number]||2,this.covalent=zr[this.number]||1.6}getDefaultValence(){const t=Vr[this.number];return t?t[0]:-1}getValenceList(){return Vr[this.number]||[]}getOuterShellElectronCount(){return Ur[this.number]||2}isMetal(){return this.isAlkaliMetal()||this.isAlkalineEarthMetal()||this.isLanthanide()||this.isActinide()||this.isTransitionMetal()||this.isPostTransitionMetal()}isNonmetal(){return this.isDiatomicNonmetal()||this.isPolyatomicNonmetal()||this.isNobleGas()}isMetalloid(){return Qo.includes(this.number)}isHalogen(){return Jo.includes(this.number)}isDiatomicNonmetal(){return Yo.includes(this.number)}isPolyatomicNonmetal(){return Xo.includes(this.number)}isAlkaliMetal(){return qo.includes(this.number)}isAlkalineEarthMetal(){return Wo.includes(this.number)}isNobleGas(){return Ko.includes(this.number)}isTransitionMetal(){const t=this.number;return t>=21&&t<=29||t>=39&&t<=47||t>=72&&t<=79||t>=104&&t<=108}isPostTransitionMetal(){return Zo.includes(this.number)}isLanthanide(){return this.number>=57&&this.number<=71}isActinide(){return this.number>=89&&this.number<=103}}class ea{constructor(t){this.structure=t,this.dict={},this.list=[],this.structure=t}add(t,e){const i=function(t,e){return t+"|"+e}(t=t.toUpperCase(),e=e?e.toUpperCase():Go(t));let r=this.dict[i];if(void 0===r){const n=new ta(this.structure,t,e);r=this.list.length,this.dict[i]=r,this.list.push(n)}return r}get(t){return this.list[t]}}class ia{constructor(t,e,i,r,n,s){this.structure=t,this.bondReferenceAtomIndices=[],this.resname=e,this.atomTypeIdList=i,this.hetero=r?1:0,this.chemCompType=n,this.bonds=s,this.atomCount=i.length,this.moleculeType=this.getMoleculeType(),this.backboneType=this.getBackboneType(0),this.backboneEndType=this.getBackboneType(-1),this.backboneStartType=this.getBackboneType(1),this.backboneIndexList=this.getBackboneIndexList();const o=rn[this.backboneType],a=rn[this.backboneStartType],c=rn[this.backboneEndType],u=this.getAtomIndexByName(o.trace);this.traceAtomIndex=l(u,-1);const h=this.getAtomIndexByName(o.direction1);this.direction1AtomIndex=l(h,-1);const d=this.getAtomIndexByName(o.direction2);this.direction2AtomIndex=l(d,-1);const m=this.getAtomIndexByName(a.backboneStart);this.backboneStartAtomIndex=l(m,-1);const f=this.getAtomIndexByName(c.backboneEnd);let p;this.backboneEndAtomIndex=l(f,-1),p=Yr.includes(e)?this.getAtomIndexByName("N1"):this.getAtomIndexByName("N3"),this.rungEndAtomIndex=l(p,-1)}getBackboneIndexList(){const t=[];let e;switch(this.moleculeType){case 3:e=tn;break;case 4:case 5:e=en;break;default:return t}const i=this.structure.atomMap,r=this.atomTypeIdList;for(let n=0,s=this.atomCount;n<s;++n){const s=i.get(r[n]);e.includes(s.atomname)&&t.push(n)}return t}getMoleculeType(){return this.isProtein()?3:this.isRna()?4:this.isDna()?5:this.isWater()?1:this.isIon()?2:this.isSaccharide()?6:0}getBackboneType(t){return this.hasProteinBackbone(t)?1:this.hasRnaBackbone(t)?2:this.hasDnaBackbone(t)?3:this.hasCgProteinBackbone(t)?4:this.hasCgRnaBackbone(t)?5:this.hasCgDnaBackbone(t)?6:Mr}isProtein(){return this.chemCompType?Tr.includes(this.chemCompType):this.hasAtomWithName("CA","C","N")||qr.includes(this.resname)}isCg(){const t=this.backboneType;return 4===t||5===t||6===t}isNucleic(){return this.isRna()||this.isDna()}isRna(){return this.chemCompType?Dr.includes(this.chemCompType):1!==this.hetero&&(this.hasAtomWithName(["P","O3'","O3*"],["C4'","C4*"],["O2'","O2*","F2'","F2*"])||Wr.includes(this.resname)&&this.hasAtomWithName(["O2'","O2*","F2'","F2*"]))}isDna(){return this.chemCompType?Br.includes(this.chemCompType):1!==this.hetero&&(this.hasAtomWithName(["P","O3'","O3*"],["C3'","C3*"])&&!this.hasAtomWithName(["O2'","O2*","F2'","F2*"])||Xr.includes(this.resname))}isHetero(){return 1===this.hetero}isIon(){return Qr.includes(this.resname)}isWater(){return Zr.includes(this.resname)}isSaccharide(){return this.chemCompType?Fr.includes(this.chemCompType):Jr.includes(this.resname)}isStandardAminoacid(){return qr.includes(this.resname)}isStandardBase(){return Kr.includes(this.resname)}hasBackboneAtoms(t,e){const i=rn[e];return-1===t?this.hasAtomWithName(i.trace,i.backboneEnd,i.direction1,i.direction2):0===t?this.hasAtomWithName(i.trace,i.direction1,i.direction2):1===t?this.hasAtomWithName(i.trace,i.backboneStart,i.direction1,i.direction2):this.hasAtomWithName(i.trace,i.backboneStart,i.backboneEnd,i.direction1,i.direction2)}hasProteinBackbone(t){return this.isProtein()&&this.hasBackboneAtoms(t,1)}hasRnaBackbone(t){return this.isRna()&&this.hasBackboneAtoms(t,2)}hasDnaBackbone(t){return this.isDna()&&this.hasBackboneAtoms(t,3)}hasCgProteinBackbone(t){return this.atomCount<7&&this.isProtein()&&this.hasBackboneAtoms(t,4)}hasCgRnaBackbone(t){return this.atomCount<11&&this.isRna()&&this.hasBackboneAtoms(t,5)}hasCgDnaBackbone(t){return this.atomCount<11&&this.isDna()&&this.hasBackboneAtoms(t,6)}hasBackbone(t){return this.hasProteinBackbone(t)||this.hasRnaBackbone(t)||this.hasDnaBackbone(t)||this.hasCgProteinBackbone(t)||this.hasCgRnaBackbone(t)||this.hasCgDnaBackbone(t)}getAtomIndexByName(t){const e=this.atomCount,i=this.structure.atomMap,r=this.atomTypeIdList;if(Array.isArray(t))for(let n=0;n<e;++n){const e=r[n];if(t.includes(i.get(e).atomname))return n}else for(let n=0;n<e;++n){const e=r[n];if(t===i.get(e).atomname)return n}}hasAtomWithName(...t){const e=t.length;for(let i=0;i<e;++i)if(void 0!==t[i]&&void 0===this.getAtomIndexByName(t[i]))return!1;return!0}getBonds(e){return void 0===this.bonds&&(this.bonds=function(e){const i=e.structure,r=i.getAtomProxy(),n=i.getAtomProxy(),s=e.atomCount,o=e.atomOffset,a=o+s-1,c=[],l=[],u=[];if(s>500)t.Debug&&Dt.warn("more than 500 atoms, skip residue for auto-bonding",e.qualifiedName());else if(s>50){const t=new Ao(e,!0),i=e.isCg()?1.2:2.3;for(let e=o;e<a;++e){r.index=e;const s=r.covalent+i+.3,a=t.nearest(r,1/0,s*s),h=a.length;for(let t=0;t<h;++t)n.index=a[t].index,r.index<n.index&&r.connectedTo(n)&&(c.push(r.index-o),l.push(n.index-o),u.push(Lo(r.resname,r.atomname,n.atomname)))}}else for(let t=o;t<a;++t){r.index=t;for(let e=t+1;e<=a;++e)n.index=e,r.connectedTo(n)&&(c.push(t-o),l.push(e-o),u.push(Lo(r.resname,r.atomname,n.atomname)))}return{atomIndices1:c,atomIndices2:l,bondOrders:u}}(e)),this.bonds}getRings(){return void 0===this.rings&&this.calculateRings(),this.rings}getBondGraph(){return void 0===this.bondGraph&&this.calculateBondGraph(),this.bondGraph}getAromatic(t){return void 0===this.aromaticAtoms&&this.calculateAromatic(this.structure.getResidueProxy(t.residueIndex)),this.aromaticAtoms}getAromaticRings(t){return void 0===this.aromaticRings&&this.calculateAromatic(t),this.aromaticRings}calculateBondGraph(){const t=this.bondGraph={},e=this.getBonds(),i=e.atomIndices1.length,r=e.atomIndices1,n=e.atomIndices2;for(let e=0;e<i;++e){const i=r[e],s=n[e];(t[i]=t[i]||[]).push(s);(t[s]=t[s]||[]).push(i)}}calculateRings(){const t=function(t,e){const i={count:e,visited:new Int32Array(e),queue:new Int32Array(e),pred:new Int32Array(e),left:new Int32Array(aa),right:new Int32Array(aa),color:new Int32Array(e),currentColor:0,rings:[],atomRings:[],bonds:t};for(let t=0;t<e;t++)i.visited[t]=-1,i.pred[t]=-1;return i}(this.getBondGraph(),this.atomCount);for(let e=0;e<t.count;e++)t.visited[e]>=0||oa(t,e);this.rings={atomRings:t.atomRings,rings:t.rings}}isAromatic(t){return this.aromaticAtoms=this.getAromatic(t),1===this.aromaticAtoms[t.index-t.residueAtomOffset]}calculateAromatic(t){const e=this.aromaticAtoms=new Uint8Array(this.atomCount),i=this.getRings().rings,r=i.map((e=>function(t){if(t.some((t=>!ra.includes(t.number))))return!1;let e=0;const i=new ts(3,t.length),r=i.data;t.forEach((t=>{r[e+0]=t.x,r[e+1]=t.y,r[e+2]=t.z,e+=3}));return new oo(i).vecC.length()<na}(e.map((e=>this.structure.getAtomProxy(e+t.atomOffset)))))),n=this.aromaticRings=[];i.forEach(((t,i)=>{r[i]&&(n.push(t),t.forEach((t=>e[t]=1)))}))}assignBondReferenceAtomIndices(){const t=this.getBondGraph(),e=this.getRings(),i=e.atomRings,r=e.rings,n=this.bonds,s=n.atomIndices1,o=n.atomIndices2,a=n.bondOrders,c=this.bondReferenceAtomIndices,l=n.atomIndices1.length;c.length=0;for(let e=0;e<l;++e){if(a[e]<=1)continue;let n;const l=s[e],u=o[e],h=i[l],d=i[u];if(h&&d)for(let t=0;t<h.length;t++)if(-1!==d.indexOf(h[t])){n=r[h[t]];break}if(t[l].length>1)for(let i=0;i<t[l].length;++i){const r=t[l][i];if(r!==u&&(void 0===n||-1!==n.indexOf(r))){c[e]=r;break}}else if(t[u].length>1)for(let i=0;i<t[u].length;++i){const r=t[u][i];if(r!==l&&(void 0===n||-1!==n.indexOf(r))){c[e]=r;break}}}}getBondIndex(t,e){const i=this.bonds,r=i.atomIndices1,n=i.atomIndices2;let s=r.indexOf(t),o=n.indexOf(e);const a=o;for(;-1!==s;){for(;-1!==o;){if(s===o)return s;o=n.indexOf(e,o+1)}s=r.indexOf(t,s+1),o=a}}getBondReferenceAtomIndex(t,e){const i=this.getBondIndex(t,e);if(void 0!==i)return 0===this.bondReferenceAtomIndices.length&&this.assignBondReferenceAtomIndices(),this.bondReferenceAtomIndices[i]}}const ra=[5,6,7,8,14,15,16,32,33,50,51,83],na=.05;function sa(t,e,i){if(i<e)return;const{pred:r,color:n,left:s,right:o}=t,a=++t.currentColor;let c=e;for(let t=0;t<aa&&(n[c]=a,c=r[c],!(c<0));t++);let l=0,u=0,h=!1,d=0;c=i;for(let t=0;t<aa;t++){if(n[c]===a){d=c,h=!0;break}if(o[u++]=c,c=r[c],c<0)break}if(!h)return;c=e;for(let t=0;t<aa&&(s[l++]=c,d!==c)&&(c=r[c],!(c<0));t++);const m=l+u,f=new Array(m);let p=0;for(let t=0;t<l;t++)f[p++]=s[t];for(let t=u-1;t>=0;t--)f[p++]=o[t];const g=t.rings.length;for(let e=0;e<m;++e){const i=f[e];t.atomRings[i]?t.atomRings[i].push(g):t.atomRings[i]=[g]}t.rings.push(f)}function oa(t,e){const{bonds:i,visited:r,queue:n,pred:s}=t;r[e]=1,n[0]=e;let o=0,a=1;for(;o<a;){const e=n[o++],c=0;if(void 0===i[e])continue;const l=i[e].length;for(let o=c;o<l;o++){const c=i[e][o];r[c]>0?s[c]!==e&&s[e]!==c&&sa(t,e,c):(r[c]=1,n[a++]=c,s[c]=e)}}}const aa=4;class ca{constructor(t){this.structure=t,this.dict={},this.list=[]}add(t,e,i,r="",n){const s=function(t,e,i,r=""){return t+"|"+e.join(",")+"|"+(i?1:0)+"|"+r}(t=t.toUpperCase(),e,i,r);let o=this.dict[s];if(void 0===o){const a=new ia(this.structure,t,e,i,r,n);o=this.list.length,this.dict[s]=o,this.list.push(a)}return o}get(t){return this.list[t]}}class la{constructor(t,i=0){this.structure=t,this.index=i,this.bondStore=t.bondStore,this._v12=new e.Vector3,this._v13=new e.Vector3,this._ap1=this.structure.getAtomProxy(),this._ap2=this.structure.getAtomProxy(),this._ap3=this.structure.getAtomProxy()}get atom1(){return this.structure.getAtomProxy(this.atomIndex1)}get atom2(){return this.structure.getAtomProxy(this.atomIndex2)}get atomIndex1(){return this.bondStore.atomIndex1[this.index]}set atomIndex1(t){this.bondStore.atomIndex1[this.index]=t}get atomIndex2(){return this.bondStore.atomIndex2[this.index]}set atomIndex2(t){this.bondStore.atomIndex2[this.index]=t}get bondOrder(){return this.bondStore.bondOrder[this.index]}set bondOrder(t){this.bondStore.bondOrder[this.index]=t}getOtherAtomIndex(t){return t===this.atomIndex1?this.atomIndex2:this.atomIndex1}getOtherAtom(t){return this.structure.getAtomProxy(this.getOtherAtomIndex(t.index))}getReferenceAtomIndex(){const t=this._ap1,e=this._ap2;if(t.index=this.atomIndex1,e.index=this.atomIndex2,t.residueIndex!==e.residueIndex)return;const i=t.index-t.residueAtomOffset,r=e.index-e.residueAtomOffset,n=t.residueType.getBondReferenceAtomIndex(i,r);if(void 0!==n)return n+t.residueAtomOffset;console.warn("No reference atom found",t.index,e.index)}calculateShiftDir(t=new e.Vector3){const i=this._ap1,r=this._ap2,n=this._ap3,s=this._v12,o=this._v13;i.index=this.atomIndex1,r.index=this.atomIndex2;const a=this.getReferenceAtomIndex();s.subVectors(i,r).normalize(),void 0!==a?(n.index=a,o.subVectors(i,n)):o.copy(i),o.normalize();let c=s.dot(o);return 1-Math.abs(c)<1e-5&&(o.set(1,0,0),c=s.dot(o),1-Math.abs(c)<1e-5&&(o.set(0,1,0),c=s.dot(o))),t.copy(o.sub(s.multiplyScalar(c))).normalize()}qualifiedName(){return this.atomIndex1+"="+this.atomIndex2}clone(){return new la(this.structure,this.index)}toObject(){return{atomIndex1:this.atomIndex1,atomIndex2:this.atomIndex2,bondOrder:this.bondOrder}}}class ua{constructor(t,e=0){this.structure=t,this.index=e,this.chainStore=t.chainStore,this.residueStore=t.residueStore,this.atomStore=t.atomStore,this.residueMap=t.residueMap,this.atomMap=t.atomMap}get entity(){return this.structure.entityList[this.entityIndex]}get entityIndex(){return this.chainStore.entityIndex[this.chainIndex]}get chain(){return this.structure.getChainProxy(this.chainIndex)}get chainIndex(){return this.residueStore.chainIndex[this.index]}set chainIndex(t){this.residueStore.chainIndex[this.index]=t}get atomOffset(){return this.residueStore.atomOffset[this.index]}set atomOffset(t){this.residueStore.atomOffset[this.index]=t}get atomCount(){return this.residueStore.atomCount[this.index]}set atomCount(t){this.residueStore.atomCount[this.index]=t}get atomEnd(){return this.atomOffset+this.atomCount-1}get modelIndex(){return this.chainStore.modelIndex[this.chainIndex]}get chainname(){return this.chainStore.getChainname(this.chainIndex)}get chainid(){return this.chainStore.getChainid(this.chainIndex)}get resno(){return this.residueStore.resno[this.index]}set resno(t){this.residueStore.resno[this.index]=t}get sstruc(){return this.residueStore.getSstruc(this.index)}set sstruc(t){this.residueStore.setSstruc(this.index,t)}get inscode(){return this.residueStore.getInscode(this.index)}set inscode(t){this.residueStore.setInscode(this.index,t)}get residueType(){return this.residueMap.get(this.residueStore.residueTypeId[this.index])}get resname(){return this.residueType.resname}get hetero(){return this.residueType.hetero}get moleculeType(){return this.residueType.moleculeType}get backboneType(){return this.residueType.backboneType}get backboneStartType(){return this.residueType.backboneStartType}get backboneEndType(){return this.residueType.backboneEndType}get traceAtomIndex(){return this.residueType.traceAtomIndex+this.atomOffset}get direction1AtomIndex(){return this.residueType.direction1AtomIndex+this.atomOffset}get direction2AtomIndex(){return this.residueType.direction2AtomIndex+this.atomOffset}get backboneStartAtomIndex(){return this.residueType.backboneStartAtomIndex+this.atomOffset}get backboneEndAtomIndex(){return this.residueType.backboneEndAtomIndex+this.atomOffset}get rungEndAtomIndex(){return this.residueType.rungEndAtomIndex+this.atomOffset}get x(){let t=0;for(let e=this.atomOffset;e<=this.atomEnd;++e)t+=this.atomStore.x[e];return t/this.atomCount}get y(){let t=0;for(let e=this.atomOffset;e<=this.atomEnd;++e)t+=this.atomStore.y[e];return t/this.atomCount}get z(){let t=0;for(let e=this.atomOffset;e<=this.atomEnd;++e)t+=this.atomStore.z[e];return t/this.atomCount}eachAtom(t,e){const i=this.atomCount,r=this.atomOffset,n=this.structure._ap,s=r+i;if(e&&e.atomOnlyTest){const i=e.atomOnlyTest;for(let e=r;e<s;++e)n.index=e,i(n)&&t(n)}else for(let e=r;e<s;++e)n.index=e,t(n)}positionToArray(t=[],e=0){return t[e+0]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}isProtein(){return 3===this.residueType.moleculeType}isNucleic(){const t=this.residueType.moleculeType;return 4===t||5===t}isRna(){return 4===this.residueType.moleculeType}isDna(){return 5===this.residueType.moleculeType}isCg(){const t=this.residueType.backboneType;return 4===t||5===t||6===t}isPolymer(){if(this.structure.entityList.length>0)return this.entity.isPolymer();{const t=this.residueType.moleculeType;return 3===t||4===t||5===t}}isHetero(){return 1===this.residueType.hetero}isWater(){return 1===this.residueType.moleculeType}isIon(){return 2===this.residueType.moleculeType}isSaccharide(){return 6===this.residueType.moleculeType}isStandardAminoacid(){return this.residueType.isStandardAminoacid()}isStandardBase(){return this.residueType.isStandardBase()}isHelix(){return Or.includes(this.sstruc)}isSheet(){return $r.includes(this.sstruc)}isTurn(){return Rr.includes(this.sstruc)&&this.isProtein()}getAtomType(t){return this.atomMap.get(this.atomStore.atomTypeId[t])}getResname1(){return Hr[this.resname.toUpperCase()]||"X"}getBackboneType(t){switch(t){case-1:return this.residueType.backboneStartType;case 1:return this.residueType.backboneEndType;default:return this.residueType.backboneType}}getAtomIndexByName(t){let e=this.residueType.getAtomIndexByName(t);return void 0!==e&&(e+=this.atomOffset),e}hasAtomWithName(t){return this.residueType.hasAtomWithName(t)}getAtomnameList(){console.warn("getAtomnameList - might be expensive");const t=this.atomCount,e=this.atomOffset,i=new Array(t);for(let r=0;r<t;++r)i[r]=this.getAtomType(e+r).atomname;return i}connectedTo(t){const e=this.structure.getAtomProxy(this.backboneEndAtomIndex),i=this.structure.getAtomProxy(t.backboneStartAtomIndex);return!(!e||!i)&&e.connectedTo(i)}getNextConnectedResidue(){const t=this.chainStore.residueOffset[this.chainIndex],e=this.chainStore.residueCount[this.chainIndex],i=this.index+1;if(i<t+e){const t=this.structure.getResidueProxy(i);if(this.connectedTo(t))return t}else if(i===t+e){const e=this.structure.getResidueProxy(t);if(this.connectedTo(e))return e}}getPreviousConnectedResidue(t){const e=this.chainStore.residueOffset[this.chainIndex],i=this.index-1;if(i>=e){const e=l(t,this.structure.getResidueProxy());if(e.index=i,e.connectedTo(this))return e}else if(i===e-1){const i=this.chainStore.residueCount[this.chainIndex],r=l(t,this.structure.getResidueProxy());if(r.index=e+i-1,r.connectedTo(this))return r}}getBonds(){return this.residueType.getBonds(this)}getRings(){return this.residueType.getRings()}getAromaticRings(){return this.residueType.getAromaticRings(this)}qualifiedName(t=!1){let e="";return this.resname&&!t&&(e+="["+this.resname+"]"),void 0!==this.resno&&(e+=this.resno),this.inscode&&(e+="^"+this.inscode),this.chain&&(e+=":"+this.chainname),e+="/"+this.modelIndex,e}clone(){return new ua(this.structure,this.index)}toObject(){return{index:this.index,chainIndex:this.chainIndex,atomOffset:this.atomOffset,atomCount:this.atomCount,resno:this.resno,resname:this.resname,sstruc:this.sstruc}}}class ha{constructor(t,e,i){this.structure=t,this.residueIndexStart=e,this.residueIndexEnd=i,this.chainStore=t.chainStore,this.residueStore=t.residueStore,this.atomStore=t.atomStore,this.residueCount=i-e+1;const r=this.structure.getResidueProxy(this.residueIndexStart),n=this.structure.getResidueProxy(this.residueIndexEnd);this.isPrevConnected=void 0!==r.getPreviousConnectedResidue();const s=n.getNextConnectedResidue();this.isNextConnected=void 0!==s,this.isNextNextConnected=void 0!==s&&void 0!==s.getNextConnectedResidue(),this.isCyclic=n.connectedTo(r),this.__residueProxy=this.structure.getResidueProxy()}get chainIndex(){return this.residueStore.chainIndex[this.residueIndexStart]}get modelIndex(){return this.chainStore.modelIndex[this.chainIndex]}get chainname(){return this.chainStore.getChainname(this.chainIndex)}isProtein(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.isProtein()}isCg(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.isCg()}isNucleic(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.isNucleic()}getMoleculeType(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.moleculeType}getBackboneType(t){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.getBackboneType(t)}getAtomIndexByType(t,e){this.isCyclic?-1===t?t=this.residueCount-1:t===this.residueCount&&(t=0):(-1!==t||this.isPrevConnected||(t+=1),t!==this.residueCount||this.isNextNextConnected||(t-=1));const i=this.__residueProxy;let r;switch(i.index=this.residueIndexStart+t,e){case"trace":r=i.traceAtomIndex;break;case"direction1":r=i.direction1AtomIndex;break;case"direction2":r=i.direction2AtomIndex;break;default:r=i.getAtomIndexByName(e)}return r}eachAtom(t,e){this.eachResidue((function(i){i.eachAtom(t,e)}))}eachAtomN(t,e,i){const r=this.residueCount,n=new Array(t);for(let e=0;e<t;++e)n[e]=this.structure.getAtomProxy(this.getAtomIndexByType(e,i));e.apply(this,n);for(var s=t;s<r;++s){for(let e=1;e<t;++e)n[e-1].index=n[e].index;n[t-1].index=this.getAtomIndexByType(s,i),e.apply(this,n)}}eachResidue(t){const e=this.structure.getResidueProxy(),i=this.residueCount,r=this.residueIndexStart;for(let n=0;n<i;++n)e.index=r+n,t(e)}qualifiedName(){const t=this.structure.getResidueProxy(this.residueIndexStart),e=this.structure.getResidueProxy(this.residueIndexEnd);return t.qualifiedName()+" - "+e.qualifiedName()}}class da{constructor(t,e=0){this.structure=t,this.index=e,this.chainStore=t.chainStore,this.residueStore=t.residueStore}get entity(){return this.structure.entityList[this.entityIndex]}get model(){return this.structure.getModelProxy(this.modelIndex)}get entityIndex(){return this.chainStore.entityIndex[this.index]}set entityIndex(t){this.chainStore.entityIndex[this.index]=t}get modelIndex(){return this.chainStore.modelIndex[this.index]}set modelIndex(t){this.chainStore.modelIndex[this.index]=t}get residueOffset(){return this.chainStore.residueOffset[this.index]}set residueOffset(t){this.chainStore.residueOffset[this.index]=t}get residueCount(){return this.chainStore.residueCount[this.index]}set residueCount(t){this.chainStore.residueCount[this.index]=t}get residueEnd(){return this.residueOffset+this.residueCount-1}get atomOffset(){return this.residueStore.atomOffset[this.residueOffset]}get atomEnd(){return this.residueStore.atomOffset[this.residueEnd]+this.residueStore.atomCount[this.residueEnd]-1}get atomCount(){return 0===this.residueCount?0:this.atomEnd-this.atomOffset+1}get chainname(){return this.chainStore.getChainname(this.index)}set chainname(t){this.chainStore.setChainname(this.index,t)}get chainid(){return this.chainStore.getChainid(this.index)}set chainid(t){this.chainStore.setChainid(this.index,t)}eachAtom(t,e){this.eachResidue((function(i){i.eachAtom(t,e)}),e)}eachResidue(t,e){const i=this.residueCount,r=this.residueOffset,n=this.structure._rp,s=r+i;if(e&&e.test){const i=e.residueOnlyTest;if(i)for(let e=r;e<s;++e)n.index=e,i(n)&&t(n);else for(let e=r;e<s;++e)n.index=e,t(n)}else for(let e=r;e<s;++e)n.index=e,t(n)}eachResidueN(t,e){const i=this.residueCount,r=this.residueOffset,n=r+i;if(i<t)return;const s=new Array(t);for(let e=0;e<t;++e)s[e]=this.structure.getResidueProxy(r+e);e.apply(this,s);for(let i=r+t;i<n;++i){for(let e=0;e<t;++e)s[e].index+=1;e.apply(this,s)}}eachPolymer(t,e){let i=0,r=0;const n=e?e.residueOnlyTest:void 0,s=this.model.structure,o=this.residueCount,a=this.residueOffset,c=a+o,l=this.structure.getResidueProxy(),u=this.structure.getResidueProxy(a),h=this.structure.getAtomProxy(),d=this.structure.getAtomProxy();let m=!0;for(let e=a+1;e<c;++e){l.index=u.index,u.index=e;const o=m?l.backboneEndType:l.backboneType,a=u.backboneType;m&&(i=l.index,m=!1),r=u.index,o!==Mr&&o===a?(h.index=l.backboneEndAtomIndex,d.index=u.backboneStartAtomIndex,h&&d&&h.connectedTo(d)&&(!n||n(l)&&n(u))||(l.index-i>1&&t(new ha(s,i,l.index)),i=r)):(o!==Mr&&l.index-i>1&&t(new ha(s,i,l.index)),i=r)}r-i>1&&this.structure.getResidueProxy(i).backboneEndType&&t(new ha(s,i,r))}qualifiedName(){return":"+this.chainname+"/"+this.modelIndex}clone(){return new da(this.structure,this.index)}toObject(){return{index:this.index,residueOffset:this.residueOffset,residueCount:this.residueCount,chainname:this.chainname}}}class ma{constructor(t,e=0){this.structure=t,this.index=e,this.modelStore=t.modelStore,this.chainStore=t.chainStore,this.residueStore=t.residueStore}get chainOffset(){return this.modelStore.chainOffset[this.index]}set chainOffset(t){this.modelStore.chainOffset[this.index]=t}get chainCount(){return this.modelStore.chainCount[this.index]}set chainCount(t){this.modelStore.chainCount[this.index]=t}get residueOffset(){return this.chainStore.residueOffset[this.chainOffset]}get atomOffset(){return this.residueStore.atomOffset[this.residueOffset]}get chainEnd(){return this.chainOffset+this.chainCount-1}get residueEnd(){return this.chainStore.residueOffset[this.chainEnd]+this.chainStore.residueCount[this.chainEnd]-1}get atomEnd(){return this.residueStore.atomOffset[this.residueEnd]+this.residueStore.atomCount[this.residueEnd]-1}get residueCount(){return 0===this.chainCount?0:this.residueEnd-this.residueOffset+1}get atomCount(){return 0===this.residueCount?0:this.atomEnd-this.atomOffset+1}eachAtom(t,e){this.eachChain((function(i){i.eachAtom(t,e)}),e)}eachResidue(t,e){this.eachChain((function(i){i.eachResidue(t,e)}),e)}eachPolymer(t,e){if(e&&e.chainOnlyTest){const i=e.chainOnlyTest;this.eachChain((function(r){i(r)&&r.eachPolymer(t,e)}))}else this.eachChain((function(i){i.eachPolymer(t,e)}))}eachChain(t,e){const i=this.chainCount,r=this.chainOffset,n=this.structure._cp,s=r+i;if(e&&e.test){const i=e.chainOnlyTest;if(i)for(let e=r;e<s;++e)n.index=e,i(n)&&t(n);else for(let e=r;e<s;++e)n.index=e,t(n)}else for(let e=r;e<s;++e)n.index=e,t(n)}qualifiedName(){return"/"+this.index}clone(){return new ma(this.structure,this.index)}toObject(){return{index:this.index,chainOffset:this.chainOffset,chainCount:this.chainCount}}}class fa{constructor(t="",e=""){this.signals={refreshed:new r.Signal},this.init(t,e)}init(t,i){this.name=t,this.path=i,this.title="",this.id="",this.data={structure:this,"@spatialLookup":void 0,"@valenceModel":void 0},this.header={},this.extraData={},this.atomSetCache={},this.atomSetDict={},this.biomolDict={},this.entityList=[],this.unitcell=void 0,this.frames=[],this.boxes=[],this.validation=void 0,this.bondStore=new lo(0),this.backboneBondStore=new lo(0),this.rungBondStore=new lo(0),this.atomStore=new uo(0),this.residueStore=new ho(0),this.chainStore=new mo(0),this.modelStore=new fo(0),this.atomMap=new ea(this),this.residueMap=new ca(this),this.chemCompMap=void 0,this.bondHash=void 0,this.spatialHash=void 0,this.atomSet=void 0,this.bondSet=void 0,this.center=new e.Vector3,this.boundingBox=new e.Box3,this._bp=this.getBondProxy(),this._ap=this.getAtomProxy(),this._rp=this.getResidueProxy(),this._cp=this.getChainProxy()}get type(){return"Structure"}finalizeAtoms(){this.atomSet=this.getAtomSet(),this.atomCount=this.atomStore.count,this.boundingBox=this.getBoundingBox(void 0,this.boundingBox),this.center=this.boundingBox.getCenter(new e.Vector3),this.spatialHash=new xr(this.atomStore,this.boundingBox)}finalizeBonds(){this.bondSet=this.getBondSet(),this.bondCount=this.bondStore.count,this.bondHash=new co(this.bondStore,this.atomStore.count),this.atomSetCache={},this.atomSetDict.rung||(this.atomSetDict.rung=this.getAtomSet(!1));for(let t in this.atomSetDict)this.atomSetCache["__"+t]=this.atomSetDict[t].clone()}getBondProxy(t){return new la(this,t)}getAtomProxy(t){return new _o(this,t)}getResidueProxy(t){return new ua(this,t)}getChainProxy(t){return new da(this,t)}getModelProxy(t){return new ma(this,t)}getBondSet(){const t=this.bondStore.count,e=new Sr(t),i=this.atomSet;if(i)if(i.isAllSet())e.setAll();else if(i.isAllClear())e.clearAll();else{const r=this.getBondProxy();for(let n=0;n<t;++n)r.index=n,i.isSet(r.atomIndex1,r.atomIndex2)&&e.set(r.index)}else e.setAll();return e}getBackboneBondSet(){const t=this.backboneBondStore.count,e=new Sr(t),i=this.atomSetCache.__backbone;if(i){const r=this.getBondProxy();r.bondStore=this.backboneBondStore;for(let n=0;n<t;++n)r.index=n,i.isSet(r.atomIndex1,r.atomIndex2)&&e.set(r.index)}else e.setAll();return e}getRungBondSet(){const t=this.rungBondStore.count,e=new Sr(t),i=this.atomSetCache.__rung;if(i){const r=this.getBondProxy();r.bondStore=this.rungBondStore;for(let n=0;n<t;++n)r.index=n,i.isSet(r.atomIndex1,r.atomIndex2)&&e.set(r.index)}else e.setAll();return e}getAtomSet(t){const e=this.atomStore.count;if(void 0===t)return new Sr(e,!0);if(t instanceof Sr)return t;if(!0===t)return new Sr(e,!0);if(t&&t.test){const i=t.string;if(i in this.atomSetCache)return this.atomSetCache[i];if(""===i)return new Sr(e,!0);{const r=new Sr(e);return this.eachAtom((function(t){r.set(t.index)}),t),this.atomSetCache[i]=r,r}}return!1===t?new Sr(e):new Sr(e,!0)}getAtomSetWithinSelection(t,e){const i=this.spatialHash,r=this.getAtomSet(!1),n=this.getAtomProxy();return i?(this.getAtomSet(t).forEach((function(t){n.index=t,i.within(n.x,n.y,n.z,e).forEach((function(t){r.set(t)}))})),r):r}getAtomSetWithinPoint(t,e){const i=t,r=this.getAtomSet(!1);return this.spatialHash?(this.spatialHash.within(i.x,i.y,i.z,e).forEach((function(t){r.set(t)})),r):r}getAtomSetWithinVolume(t,e,i,r,n){const s=new ao(t,i,r,n),o=s.getDataPosition(),a=o.length,c=s.matrix.getMaxScaleOnAxis(),l=this.getAtomSet(!1);if(!this.spatialHash)return l;for(let t=0;t<a;t+=3)this.spatialHash.within(o[t],o[t+1],o[t+2],c).forEach((function(t){l.set(t)}));return l}getAtomSetWithinGroup(t){const e=this.atomStore.residueIndex,i=this.getAtomSet(!1),r=this.getResidueProxy();return this.getAtomSet(t).forEach((function(t){r.index=e[t];for(let t=r.atomOffset;t<=r.atomEnd;++t)i.set(t)})),i}getSelection(){}getStructure(){return this}eachEntity(t,e){this.entityList.forEach((function(i){void 0!==e&&i.getEntityType()!==e||t(i)}))}eachBond(t,e){const i=this.getBondProxy();let r;if(e&&e.test&&(r=this.getBondSet(),this.bondSet&&r.intersection(this.bondSet)),r)r.forEach((function(e){i.index=e,t(i)}));else{const e=this.bondStore.count;for(let r=0;r<e;++r)i.index=r,t(i)}}eachAtom(t,e){if(e&&e.test)this.eachModel((function(i){i.eachAtom(t,e)}),e);else{const e=this.atomStore.count,i=this.getAtomProxy();for(let r=0;r<e;++r)i.index=r,t(i)}}eachResidue(t,e){if(e&&e.test){const i=this.modelStore.count,r=this.getModelProxy(),n=e.modelOnlyTest;if(n)for(let s=0;s<i;++s)r.index=s,n(r)&&r.eachResidue(t,e);else for(let n=0;n<i;++n)r.index=n,r.eachResidue(t,e)}else{const e=this.residueStore.count,i=this.getResidueProxy();for(let r=0;r<e;++r)i.index=r,t(i)}}eachResidueN(t,e){const i=this.residueStore.count;if(i<t)return;const r=new Array(t);for(let e=0;e<t;++e)r[e]=this.getResidueProxy(e);e.apply(this,r);for(let n=t;n<i;++n){for(let e=0;e<t;++e)r[e].index+=1;e.apply(this,r)}}eachPolymer(t,e){if(e&&e.modelOnlyTest){const i=e.modelOnlyTest;this.eachModel((function(r){i(r)&&r.eachPolymer(t,e)}))}else this.eachModel((function(i){i.eachPolymer(t,e)}))}eachChain(t,e){if(e&&e.test)this.eachModel((function(i){i.eachChain(t,e)}));else{const e=this.chainStore.count,i=this.getChainProxy();for(let r=0;r<e;++r)i.index=r,t(i)}}eachModel(t,e){const i=this.modelStore.count,r=this.getModelProxy();if(e&&e.test){const n=e.modelOnlyTest;if(n)for(let e=0;e<i;++e)r.index=e,n(r)&&t(r);else for(let e=0;e<i;++e)r.index=e,t(r)}else for(let e=0;e<i;++e)r.index=e,t(r)}getAtomData(t){const e=Object.assign({},t);e.colorParams&&(e.colorParams.structure=this.getStructure());const i=e.what,r=l(e.atomSet,this.atomSet);let n,s;const o={},a=this.getAtomProxy(),c=r.getSize();i&&!i.position||(o.position=new Float32Array(3*c)),i&&!i.color||!e.colorParams||(o.color=new Float32Array(3*c),s=$t.getScheme(e.colorParams)),i&&!i.picking||(o.picking=new Nn(new Float32Array(c),this.getStructure())),i&&!i.radius||(o.radius=new Float32Array(c),n=new ro(e.radiusParams)),i&&!i.index||(o.index=new Uint32Array(c));const{position:u,color:h,picking:d,radius:m,index:f}=o;return r.forEach(((t,e)=>{const i=3*e;a.index=t,u&&a.positionToArray(u,i),h&&s.atomColorToArray(a,h,i),d&&(d.array[e]=t),m&&(m[e]=n.atomRadius(a)),f&&(f[e]=t)})),o}getBondData(t){const i=Object.assign({},t);i.colorParams&&(i.colorParams.structure=this.getStructure());const r=i.what,n=l(i.bondSet,this.bondSet),s=l(i.multipleBond,"off"),o="off"!==s,a="offset"===s,c=l(i.bondScale,.4),u=l(i.bondSpacing,1);let h,d;const m={},f=this.getBondProxy();i.bondStore&&(f.bondStore=i.bondStore);const p=this.getAtomProxy(),g=this.getAtomProxy();let y;if(o){const t=f.bondStore.bondOrder;y=0,n.forEach((function(e){y+=t[e]}))}else y=n.getSize();r&&!r.position||(m.position1=new Float32Array(3*y),m.position2=new Float32Array(3*y)),r&&!r.color||!i.colorParams||(m.color=new Float32Array(3*y),m.color2=new Float32Array(3*y),d=$t.getScheme(i.colorParams)),r&&!r.picking||(m.picking=new Vn(new Float32Array(y),this.getStructure(),i.bondStore)),(!r||r.radius||o&&r.position)&&(h=new ro(i.radiusParams)),r&&!r.radius||(m.radius=new Float32Array(y),i.radius2&&(m.radius2=new Float32Array(y)));const{position1:b,position2:_,color:x,color2:v,picking:w,radius:A,radius2:S}=m;let C,P,I,k,M,T,D=0;const B=new e.Vector3,F=new e.Vector3,E=new e.Vector3;return n.forEach((t=>{if(P=3*D,f.index=t,p.index=f.atomIndex1,g.index=f.atomIndex2,k=f.bondOrder,b)if(o&&k>1){const t=h.atomRadius(p);T=t*c/(.5*k),f.calculateShiftDir(E),a?(M=2*u*t,E.multiplyScalar(M),E.negate(),F.subVectors(g,p).multiplyScalar(Math.max(.1,M/1.88)),p.positionToArray(b,P),g.positionToArray(_,P),k>=2&&(B.addVectors(p,E).add(F).toArray(b,P+3),B.addVectors(g,E).sub(F).toArray(_,P+3),k>=3&&(B.subVectors(p,E).add(F).toArray(b,P+6),B.subVectors(g,E).sub(F).toArray(_,P+6)))):(M=(u-c)*t,E.multiplyScalar(M),2===k?(B.addVectors(p,E).toArray(b,P),B.subVectors(p,E).toArray(b,P+3),B.addVectors(g,E).toArray(_,P),B.subVectors(g,E).toArray(_,P+3)):3===k?(p.positionToArray(b,P),B.addVectors(p,E).toArray(b,P+3),B.subVectors(p,E).toArray(b,P+6),g.positionToArray(_,P),B.addVectors(g,E).toArray(_,P+3),B.subVectors(g,E).toArray(_,P+6)):(p.positionToArray(b,P),g.positionToArray(_,P)))}else p.positionToArray(b,P),g.positionToArray(_,P);if(x&&v&&(d.bondColorToArray(f,1,x,P),d.bondColorToArray(f,0,v,P),o&&k>1))for(C=1;C<k;++C)I=3*C+P,we(x,P,I,3),we(v,P,I,3);if(w&&w.array&&(w.array[D]=t,o&&k>1))for(C=1;C<k;++C)w.array[D+C]=t;if(A&&(A[D]=h.atomRadius(p),o&&k>1))for(T=A[D]*c/(a?1:.5*k),C=a?1:0;C<k;++C)A[D+C]=T;if(S&&(S[D]=h.atomRadius(g),o&&k>1))for(T=S[D]*c/(a?1:.5*k),C=a?1:0;C<k;++C)S[D+C]=T;D+=o?k:1})),m}getBackboneAtomData(t){return t=Object.assign({atomSet:this.atomSetCache.__backbone},t),this.getAtomData(t)}getBackboneBondData(t){return t=Object.assign({bondSet:this.getBackboneBondSet(),bondStore:this.backboneBondStore},t),this.getBondData(t)}getRungAtomData(t){return t=Object.assign({atomSet:this.atomSetCache.__rung},t),this.getAtomData(t)}getRungBondData(t){return t=Object.assign({bondSet:this.getRungBondSet(),bondStore:this.rungBondStore},t),this.getBondData(t)}getBoundingBox(i,r){t.Debug&&Dt.time("getBoundingBox"),r=r||new e.Box3;let n=1/0,s=1/0,o=1/0,a=-1/0,c=-1/0,l=-1/0;return this.eachAtom((t=>{const e=t.x,i=t.y,r=t.z;e<n&&(n=e),i<s&&(s=i),r<o&&(o=r),e>a&&(a=e),i>c&&(c=i),r>l&&(l=r)}),i),r.min.set(n,s,o),r.max.set(a,c,l),t.Debug&&Dt.timeEnd("getBoundingBox"),r}getPrincipalAxes(e){t.Debug&&Dt.time("getPrincipalAxes");let i=0;const r=new ts(3,this.atomCount),n=r.data;return this.eachAtom((t=>{n[i+0]=t.x,n[i+1]=t.y,n[i+2]=t.z,i+=3}),e),t.Debug&&Dt.timeEnd("getPrincipalAxes"),new oo(r)}atomCenter(t){return t?this.getBoundingBox(t).getCenter(new e.Vector3):this.center.clone()}hasCoords(){if(void 0===this._hasCoords){const t=this.atomStore;this._hasCoords=0!==Se(t.x)||0!==Ae(t.x)||0!==Se(t.y)||0!==Ae(t.y)||0!==Se(t.z)||0!==Ae(t.z)||t.count/this.modelStore.count==1}return this._hasCoords}getSequence(t){const e=[],i=this.getResidueProxy();return this.eachAtom((function(t){i.index=t.residueIndex,t.index===i.traceAtomIndex&&e.push(i.getResname1())}),t),e}getAtomIndices(t){if(t&&t.string){const e=[];return this.eachAtom((function(t){e.push(t.index)}),t),new Uint32Array(e)}{const t={what:{index:!0}};return this.getAtomData(t).index}}getChainnameCount(t){const e=new Set;return this.eachChain((function(t){t.residueCount&&e.add(t.chainname)}),t),e.size}updatePosition(t,e=!0){let i=0;this.eachAtom((function(e){e.positionFromArray(t,i),i+=3}),void 0),this._hasCoords=void 0,e&&this.refreshPosition()}refreshPosition(){this.getBoundingBox(void 0,this.boundingBox),this.boundingBox.getCenter(this.center),this.spatialHash=new xr(this.atomStore,this.boundingBox),this.signals.refreshed.dispatch(this)}dispose(){this.frames&&(this.frames.length=0),this.boxes&&(this.boxes.length=0),this.bondStore.dispose(),this.backboneBondStore.dispose(),this.rungBondStore.dispose(),this.atomStore.dispose(),this.residueStore.dispose(),this.chainStore.dispose(),this.modelStore.dispose(),delete this.bondSet,delete this.atomSet}}const pa=new e.Box3,ga=[mr,cr,fr,dr,pr,lr,ar,ur,yr,gr,br,_r,hr],ya={aspectRatio:1.5,sphereDetail:2,radialSegments:50,disableImpostor:!1,openEnded:!1,dashedCylinder:!1,labelParams:{},pointSize:2,sizeAttenuation:!1,useTexture:!0,linewidth:2};class ba{constructor(t="shape",i={}){this.boundingBox=new e.Box3,this.bufferList=[],this.meshCount=0,this._primitiveData={},this.name=t,this.parameters=u(i,ya),ga.forEach((t=>{Object.keys(t.fields).forEach((e=>{this._primitiveData[t.getShapeKey(e)]=[]})),this._primitiveData[t.getShapeKey("name")]=[]}))}addBuffer(t){this.bufferList.push(t);const e=t.geometry;return e.boundingBox||e.computeBoundingBox(),this.boundingBox.union(e.boundingBox),this}addMesh(t,e,i,r,n){let s;t=I(t),e=I(e),Array.isArray(i)&&(i=v(i,t.length)),r&&(r=I(r)),s=void 0===r||0==r.length?{position:t,color:e,index:i}:{position:t,color:e,index:i,normal:r};const o=new qn(this,Object.assign({serial:this.meshCount,name:n},s)),a=new Bs(Object.assign({picking:o},s));return this.bufferList.push(a),pa.setFromArray(t),this.boundingBox.union(pa),this.meshCount+=1,this}addSphere(t,e,i,r){return ar.objectToShape(this,{position:t,color:e,radius:i,name:r}),this}addEllipsoid(t,e,i,r,n,s){return pr.objectToShape(this,{position:t,color:e,radius:i,majorAxis:r,minorAxis:n,name:s}),this}addTorus(t,e,i,r,n,s){return gr.objectToShape(this,{position:t,color:e,radius:i,majorAxis:r,minorAxis:n,name:s}),this}addCylinder(t,e,i,r,n){return dr.objectToShape(this,{position1:t,position2:e,color:i,radius:r,name:n}),this}addCone(t,e,i,r,n){return fr.objectToShape(this,{position1:t,position2:e,color:i,radius:r,name:n}),this}addArrow(t,e,i,r,n){return mr.objectToShape(this,{position1:t,position2:e,color:i,radius:r,name:n}),this}addBox(t,e,i,r,n,s){return cr.objectToShape(this,{position:t,color:e,size:i,heightAxis:r,depthAxis:n,name:s}),this}addOctahedron(t,e,i,r,n,s){return lr.objectToShape(this,{position:t,color:e,size:i,heightAxis:r,depthAxis:n,name:s}),this}addTetrahedron(t,e,i,r,n,s){return ur.objectToShape(this,{position:t,color:e,size:i,heightAxis:r,depthAxis:n,name:s}),this}addIcosahedron(t,e,i,r,n,s){return hr.objectToShape(this,{position:t,color:e,size:i,heightAxis:r,depthAxis:n,name:s}),this}addText(t,e,i,r){return yr.objectToShape(this,{position:t,color:e,size:i,text:r}),this}addPoint(t,e,i){return br.objectToShape(this,{position:t,color:e,name:i}),this}addWideline(t,e,i,r,n){return this.parameters.linewidth=r,_r.objectToShape(this,{position1:t,position2:e,color:i,name:n}),this}addLabel(t,e,i,r){return console.warn("Shape.addLabel is deprecated, use .addText instead"),this.addText(t,e,i,r)}getBufferList(){const t=[];return ga.forEach((e=>{this._primitiveData[e.getShapeKey("color")].length&&t.push(e.bufferFromShape(this,this.parameters))})),this.bufferList.concat(t)}dispose(){this.bufferList.forEach((function(t){t.dispose()})),this.bufferList.length=0,ga.forEach((t=>{Object.keys(t.fields).forEach((e=>{this._primitiveData[t.getShapeKey(e)].length=0})),this._primitiveData[t.getShapeKey("name")].length=0}))}get center(){return this._center||(this._center=this.boundingBox.getCenter(new e.Vector3)),this._center}get type(){return"Shape"}}class _a extends Mi{constructor(t,e,i){Array.isArray(t)||(t=[t]),super(t,e,i),this.type="buffer",this.parameters=Object.assign({},this.parameters,{colorScheme:null,colorScale:null,colorValue:null,colorDomain:null,colorMode:null}),this.buffer=t,this.init(i)}init(t){super.init(t),this.build()}create(){this.bufferList.push.apply(this.bufferList,this.buffer)}attach(t){this.bufferList.forEach((t=>{this.viewer.add(t),t.setParameters(this.getBufferParams())})),this.setVisibility(this.visible),t()}}const xa=new e.Matrix4,va=new e.Matrix3;class wa extends Bs{constructor(t,e={},i){super(function(t,e){const i=e.attributes.position.array,r=e.index?e.index.array:void 0,n=t.position.length/3,s=i.length/3,o=n*s,a=new Float32Array(3*o),c=new Float32Array(3*o),l=new Float32Array(3*o);let u;return r&&(u=v(n*r.length,o)),{position:a,color:l,index:u,normal:c,primitiveId:t.primitiveId||_e(n,s),picking:t.picking}}(t,i),e),this.updateNormals=!1;const r=i.attributes.position.array,n=i.attributes.normal.array,s=i.index?i.index.array:void 0;this.geoPosition=r,this.geoNormal=n,this.geoIndex=s,this.positionCount=t.position.length/3,this.geoPositionCount=r.length/3,this.transformedGeoPosition=new Float32Array(3*this.geoPositionCount),this.transformedGeoNormal=new Float32Array(3*this.geoPositionCount);const o=this.geometry.attributes;if(this.meshPosition=o.position.array,this.meshColor=o.color.array,this.meshNormal=o.normal.array,this.setAttributes(t),s){const t=this.geometry.getIndex();if(!t)return void Dt.error("Index is null");this.meshIndex=t.array,this.makeIndex()}}setAttributes(t={},e=!1){const i=this.geometry.attributes;let r,n,s,o,a,c,l,u,h;const d=this.updateNormals;t.position&&(r=t.position,s=this.geoPosition,l=this.meshPosition,a=this.transformedGeoPosition,i.position.needsUpdate=!0,(d||e)&&(o=this.geoNormal,h=this.meshNormal,c=this.transformedGeoNormal,i.normal.needsUpdate=!0)),t.color&&(n=t.color,u=this.meshColor,i.color.needsUpdate=!0);const m=this.positionCount,f=this.geoPositionCount;for(let t=0;t<m;++t){let i,m;const p=t*f*3,g=3*t;if(r&&a&&l&&h&&s&&o&&(a.set(s),xa.makeTranslation(r[g],r[g+1],r[g+2]),this.applyPositionTransform(xa,t,g),Oi(xa.elements,a),l.set(a,p),d&&c?(c.set(o),va.getNormalMatrix(xa),$i(va.elements,c),h.set(c,p)):e&&h.set(o,p)),n&&u)for(i=0;i<f;++i)m=p+3*i,u[m]=n[g],u[m+1]=n[g+1],u[m+2]=n[g+2]}}makeIndex(){const t=this.geoIndex,e=this.meshIndex;if(!t)return;const i=this.positionCount,r=this.geoPositionCount,n=3*(t.length/3);for(let s=0;s<i;++s){const i=s*n,o=i+n;e.set(t,i);for(let t=i;t<o;++t)e[t]+=s*r}}}const Aa=new e.Vector3,Sa=Object.assign({sphereDetail:1},Ms);class Ca extends wa{constructor(t,i={}){super(t,i,new e.IcosahedronGeometry(1,l(i.sphereDetail,1))),this.setAttributes(t,!0)}get defaultParameters(){return Sa}applyPositionTransform(t,e){const i=this._radius[e];Aa.set(i,i,i),t.scale(Aa)}setAttributes(t={},e){t.radius&&(this._radius=t.radius),super.setAttributes(t,e)}}zt.add("shader/SphereImpostor.vert","uniform mat4 projectionMatrixInverse;\nuniform float clipNear;\nvarying float vRadius;\nvarying float vRadiusSq;\nvarying vec3 vPoint;\nvarying vec3 vPointViewPosition;\nattribute vec2 mapping;\nattribute float radius;\n#ifdef PICKING\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\n#include color_pars_vertex\n#endif\n#include matrix_scale\nconst mat4 D = mat4(\n1.0, 0.0, 0.0, 0.0,\n0.0, 1.0, 0.0, 0.0,\n0.0, 0.0, 1.0, 0.0,\n0.0, 0.0, 0.0, -1.0\n);\nmat4 transposeM( in mat4 inMatrix ) {\nvec4 i0 = inMatrix[0];\nvec4 i1 = inMatrix[1];\nvec4 i2 = inMatrix[2];\nvec4 i3 = inMatrix[3];\nmat4 outMatrix = mat4(\nvec4(i0.x, i1.x, i2.x, i3.x),\nvec4(i0.y, i1.y, i2.y, i3.y),\nvec4(i0.z, i1.z, i2.z, i3.z),\nvec4(i0.w, i1.w, i2.w, i3.w)\n);\nreturn outMatrix;\n}\nvoid ComputePointSizeAndPositionInClipCoordSphere(){\nvec2 xbc;\nvec2 ybc;\nmat4 T = mat4(\nradius, 0.0, 0.0, 0.0,\n0.0, radius, 0.0, 0.0,\n0.0, 0.0, radius, 0.0,\nposition.x, position.y, position.z, 1.0\n);\nmat4 R = transposeM( projectionMatrix * modelViewMatrix * T );\nfloat A = dot( R[ 3 ], D * R[ 3 ] );\nfloat B = -2.0 * dot( R[ 0 ], D * R[ 3 ] );\nfloat C = dot( R[ 0 ], D * R[ 0 ] );\nxbc[ 0 ] = ( -B - sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );\nxbc[ 1 ] = ( -B + sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );\nfloat sx = abs( xbc[ 0 ] - xbc[ 1 ] ) * 0.5;\nA = dot( R[ 3 ], D * R[ 3 ] );\nB = -2.0 * dot( R[ 1 ], D * R[ 3 ] );\nC = dot( R[ 1 ], D * R[ 1 ] );\nybc[ 0 ] = ( -B - sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );\nybc[ 1 ] = ( -B + sqrt( B * B - 4.0 * A * C ) ) / ( 2.0 * A );\nfloat sy = abs( ybc[ 0 ] - ybc[ 1 ] ) * 0.5;\ngl_Position.xy = vec2( 0.5 * ( xbc.x + xbc.y ), 0.5 * ( ybc.x + ybc.y ) );\ngl_Position.xy -= mapping * vec2( sx, sy );\ngl_Position.xy *= gl_Position.w;\n}\nvoid main(void){\n#ifdef PICKING\nvPickingColor = unpackColor( primitiveId );\n#else\n#include color_vertex\n#endif\nvRadius = radius * matrixScale( modelViewMatrix );\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nmvPosition.z -= vRadius;\ngl_Position = projectionMatrix * vec4( mvPosition.xyz, 1.0 );\nComputePointSizeAndPositionInClipCoordSphere();\nvRadiusSq = vRadius * vRadius;\nvec4 vPoint4 = projectionMatrixInverse * gl_Position;\nvPoint = vPoint4.xyz / vPoint4.w;\nvPointViewPosition = -mvPosition.xyz / mvPosition.w;\n}"),zt.add("shader/SphereImpostor.frag","#define STANDARD\n#define IMPOSTOR\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 interiorColor;\nuniform float interiorDarkening;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float clipNear;\nuniform mat4 projectionMatrix;\nuniform float ortho;\nvarying float vRadius;\nvarying float vRadiusSq;\nvarying vec3 vPoint;\nvarying vec3 vPointViewPosition;\n#ifdef PICKING\nuniform float objectId;\nvarying vec3 vPickingColor;\n#else\n#include common\n#include color_pars_fragment\n#include fog_pars_fragment\n#include bsdfs\n#include lights_pars_begin\n#include lights_physical_pars_fragment\n#endif\nbool flag2 = false;\nbool interior = false;\nvec3 cameraPos;\nvec3 cameraNormal;\nfloat calcDepth( in vec3 cameraPos ){\nvec2 clipZW = cameraPos.z * projectionMatrix[2].zw + projectionMatrix[3].zw;\nreturn 0.5 + 0.5 * clipZW.x / clipZW.y;\n}\nfloat calcClip( vec3 cameraPos ){\nreturn dot( vec4( cameraPos, 1.0 ), vec4( 0.0, 0.0, 1.0, clipNear - 0.5 ) );\n}\nbool Impostor( out vec3 cameraPos, out vec3 cameraNormal ){\nvec3 cameraSpherePos = -vPointViewPosition;\ncameraSpherePos.z += vRadius;\nvec3 rayOrigin = mix( vec3( 0.0, 0.0, 0.0 ), vPoint, ortho );\nvec3 rayDirection = mix( normalize( vPoint ), vec3( 0.0, 0.0, 1.0 ), ortho );\nvec3 cameraSphereDir = mix( cameraSpherePos, rayOrigin - cameraSpherePos, ortho );\nfloat B = dot( rayDirection, cameraSphereDir );\nfloat det = B * B + vRadiusSq - dot( cameraSphereDir, cameraSphereDir );\nif( det < 0.0 ){\ndiscard;\nreturn false;\n}\nfloat sqrtDet = sqrt( det );\nfloat posT = mix( B + sqrtDet, B + sqrtDet, ortho );\nfloat negT = mix( B - sqrtDet, sqrtDet - B, ortho );\ncameraPos = rayDirection * negT + rayOrigin;\n#ifdef NEAR_CLIP\nif( calcDepth( cameraPos ) <= 0.0 ){\ncameraPos = rayDirection * posT + rayOrigin;\ninterior = true;\n}else if( calcClip( cameraPos ) > 0.0 ){\ncameraPos = rayDirection * posT + rayOrigin;\ninterior = true;\nflag2 = true;\n}\n#else\nif( calcDepth( cameraPos ) <= 0.0 ){\ncameraPos = rayDirection * posT + rayOrigin;\ninterior = true;\n}\n#endif\ncameraNormal = normalize( cameraPos - cameraSpherePos );\ncameraNormal *= float(!interior) * 2.0 - 1.0;\nreturn !interior;\n}\nvoid main(void){\nbool flag = Impostor( cameraPos, cameraNormal );\n#ifdef NEAR_CLIP\nif( calcClip( cameraPos ) > 0.0 )\ndiscard;\n#endif\ngl_FragDepthEXT = calcDepth( cameraPos );\nif( !flag ){\n#ifdef NEAR_CLIP\nif( flag2 ){\ngl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( clipNear - 0.5 ) ) ) + ( 0.0000001 / vRadius ) );\n}else if( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n#else\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n#endif\n}\nif (gl_FragDepthEXT < 0.0)\ndiscard;\nif (gl_FragDepthEXT > 1.0)\ndiscard;\n#ifdef PICKING\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 vNormal = cameraNormal;\nvec3 vViewPosition = -cameraPos;\nvec4 diffuseColor = vec4( diffuse, opacity );\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\nvec3 totalEmissiveLight = emissive;\n#include color_fragment\n#include roughnessmap_fragment\n#include metalnessmap_fragment\n#include normal_fragment_begin\n#include lights_physical_fragment\n#include lights_fragment_begin\n#include lights_fragment_end\nvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;\nif( interior ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");class Pa extends Ds{constructor(t,e,i={}){super(e,i),this.index=v(this.indexSize,this.attributeSize),this.makeIndex(),this.initIndex(this.index),this.addAttributes({mapping:{type:t,value:null}}),this.setAttributes({primitiveId:be(this.size)})}get attributeSize(){return this.size*this.mappingSize}get indexSize(){return this.size*this.mappingIndicesSize}addAttributes(t){const e={};for(const i in t){const r=t[i];e[i]={type:r.type,value:null}}super.addAttributes(e)}getAttributeIndex(t){return 3*t*this.mappingSize}setAttributes(t){t&&!t.position&&t.position1&&t.position2&&(t.position=fe(t.position1,t.position2));const e=this.size,i=this.mappingSize,r=this.geometry.attributes;let n,s,o,a,c,l,u;for(const h in t)if("index"!==h&&"picking"!==h){s=t[h],n=r[h],o=n.itemSize,a=n.array;for(let t=0;t<e;++t){c=t*o,l=c*i;for(let t=0;t<i;++t){u=l+o*t;for(let t=0;t<o;++t)a[u+t]=s[c+t]}}n.needsUpdate=!0}}makeMapping(){const t=this.size,e=this.mapping,i=this.mappingSize,r=this.mappingItemSize,n=this.geometry.attributes.mapping.array;for(let s=0;s<t;s++)n.set(e,s*r*i)}makeIndex(){const t=this.size,e=this.mappingSize,i=this.mappingIndices,r=this.mappingIndicesSize,n=this.index;for(let s=0;s<t;s++){const t=s*r,o=s*e;n.set(i,t);for(let e=0;e<r;++e)n[t+e]+=o}}}const Ia=new Float32Array([-1,1,-1,-1,1,1,1,-1]),ka=new Uint16Array([0,1,2,1,3,2]);class Ma extends Pa{constructor(t,e={}){super("v2",t,e)}get mapping(){return Ia}get mappingIndices(){return ka}get mappingIndicesSize(){return 6}get mappingSize(){return 4}get mappingItemSize(){return 2}}class Ta extends Ma{constructor(t,i={}){super(t,i),this.isImpostor=!0,this.vertexShader="SphereImpostor.vert",this.fragmentShader="SphereImpostor.frag",this.addUniforms({projectionMatrixInverse:{value:new e.Matrix4},ortho:{value:0}}),this.addAttributes({radius:{type:"f",value:null}}),this.setAttributes(t),this.makeMapping()}}Object.assign({disableImpostor:!1},Sa);const Da=class{constructor(t,e){return!Mt||e&&e.disableImpostor?new Ca(t,e):new Ta(t,e)}};function Ba(t,e,i,r){const n=i-t,s=r-e;return Math.sqrt(n*n+s*s)}jt.add("sphere",Da),zt.add("shader/Point.vert","uniform float clipNear;\nuniform float clipRadius;\nuniform vec3 clipCenter;\nuniform float size;\nuniform float canvasHeight;\nuniform float pixelRatio;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#if defined( PICKING )\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\n#include color_pars_vertex\nvarying vec3 vViewPosition;\n#endif\n#include common\nvoid main(){\n#if defined( PICKING )\nvPickingColor = unpackColor( primitiveId );\n#else\n#include color_vertex\n#endif\n#include begin_vertex\n#include project_vertex\n#ifdef USE_SIZEATTENUATION\ngl_PointSize = size * pixelRatio * ( ( canvasHeight / 2.0 ) / -mvPosition.z );\n#else\ngl_PointSize = size * pixelRatio;\n#endif\n#ifndef PICKING\nvViewPosition = -mvPosition.xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n#include radiusclip_vertex\n}"),zt.add("shader/Point.frag","uniform vec3 diffuse;\nuniform float opacity;\nuniform float clipNear;\nuniform float clipRadius;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n#if defined( PICKING )\nuniform float objectId;\nvarying vec3 vPickingColor;\n#else\n#include common\n#include color_pars_fragment\n#include fog_pars_fragment\n#include alphatest_pars_fragment\nvarying vec3 vViewPosition;\n#endif\nvoid main(){\n#include nearclip_fragment\n#include radiusclip_fragment\n#if defined( PICKING )\n#ifdef USE_MAP\nif( texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) ).a < 0.5 )\ndiscard;\n#endif\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 outgoingLight = vec3( 0.0 );\nvec4 diffuseColor = vec4( diffuse, 1.0 );\n#ifdef USE_MAP\ndiffuseColor *= texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) );\n#endif\n#include color_fragment\n#include alphatest_fragment\noutgoingLight = diffuseColor.rgb;\ngl_FragColor = vec4( outgoingLight, diffuseColor.a * opacity );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const Fa=Object.assign({pointSize:1,sizeAttenuation:!0,sortParticles:!1,alphaTest:.5,useTexture:!1,forceTransparent:!1,edgeBleach:0},Ms),Ea=Object.assign({pointSize:{uniform:"size"},sizeAttenuation:{updateShader:!0},sortParticles:{},alphaTest:{uniform:!0},useTexture:{updateShader:!0},forceTransparent:{},edgeBleach:{uniform:!0}},Ts);class Oa extends Ds{constructor(t,e={}){super(t,e),this.parameterTypes=Ea,this.vertexShader="Point.vert",this.fragmentShader="Point.frag",this.isPoint=!0,this.addUniforms({size:{value:this.parameters.pointSize},canvasHeight:{value:1},pixelRatio:{value:1},map:{value:null},alphaTest:{value:this.parameters.alphaTest}})}get defaultParameters(){return Fa}makeMaterial(){super.makeMaterial(),this.makeTexture();const t=this.material,e=this.wireframeMaterial,i=this.pickingMaterial;t.uniforms.map.value=this.tex,t.needsUpdate=!0,e.uniforms.map.value=this.tex,e.needsUpdate=!0,i.uniforms.map.value=this.tex,i.needsUpdate=!0}makeTexture(){this.tex&&this.tex.dispose(),this.tex=function(t){const i=t||{},r=l(i.width,256),n=l(i.height,256),s=[r/2,n/2],o=Math.min(r/2,n/2),a=l(i.delta,1/(o+1))*o;let c=0,u=0;const h=new Uint8Array(r*n*4);for(let t=0,e=h.length;t<e;t+=4){const e=1-R(o-a,o,Ba(c,u,s[0],s[1]));h[t]=255*e,h[t+1]=255*e,h[t+2]=255*e,h[t+3]=255*e,++c===r&&(c=0,u++)}const d=new e.DataTexture(h,r,n);return d.needsUpdate=!0,d}({delta:this.parameters.edgeBleach})}getDefines(t){const e=super.getDefines(t);return this.parameters.sizeAttenuation&&(e.USE_SIZEATTENUATION=1),this.parameters.useTexture&&(e.USE_MAP=1),this.parameters.alphaTest>0&&this.parameters.alphaTest<=1&&(e.USE_ALPHATEST=1),e}setUniforms(t){t&&void 0!==t.edgeBleach&&(this.makeTexture(),t.map=this.tex),super.setUniforms(t)}dispose(){super.dispose(),this.tex&&this.tex.dispose()}}jt.add("point",Oa);class $a extends Mi{constructor(t,e,i){super(t,e,i),this.type="dot",this.parameters=Object.assign({thresholdType:{type:"select",rebuild:!0,options:{value:"value",sigma:"sigma"}},thresholdMin:{type:"number",precision:3,max:1/0,min:-1/0,rebuild:!0},thresholdMax:{type:"number",precision:3,max:1/0,min:-1/0,rebuild:!0},thresholdOut:{type:"boolean",rebuild:!0},dotType:{type:"select",rebuild:!0,options:{"":"",sphere:"sphere",point:"point"}},radiusType:{type:"select",options:{"":"",value:"value","abs-value":"abs-value","value-min":"value-min",deviation:"deviation",size:"size"}},radius:{type:"number",precision:3,max:10,min:.001,property:"size"},scale:{type:"number",precision:3,max:10,min:.001},sphereDetail:!0,disableImpostor:!0,pointSize:{type:"number",precision:1,max:100,min:0,buffer:!0},sizeAttenuation:{type:"boolean",buffer:!0},sortParticles:{type:"boolean",rebuild:!0},useTexture:{type:"boolean",buffer:!0},alphaTest:{type:"range",step:.001,max:1,min:0,buffer:!0},forceTransparent:{type:"boolean",buffer:!0},edgeBleach:{type:"range",step:.001,max:1,min:0,buffer:!0}},this.parameters,{colorScheme:{type:"select",update:"color",options:{"":"",value:"value",uniform:"uniform",random:"random"}}}),t instanceof Cs?(this.surface=void 0,this.volume=new ao(t)):(this.surface=t,this.volume=void 0),this.init(i)}init(t){var e=t||{};e.colorScheme=l(e.colorScheme,"uniform"),e.colorValue=l(e.colorValue,14540253),this.thresholdType=l(e.thresholdType,"sigma"),this.thresholdMin=l(e.thresholdMin,2),this.thresholdMax=l(e.thresholdMax,1/0),this.thresholdOut=l(e.thresholdOut,!1),this.dotType=l(e.dotType,"point"),this.radius=l(e.radius,.1),this.scale=l(e.scale,1),this.pointSize=l(e.pointSize,1),this.sizeAttenuation=l(e.sizeAttenuation,!0),this.sortParticles=l(e.sortParticles,!1),this.useTexture=l(e.useTexture,!1),this.alphaTest=l(e.alphaTest,.5),this.forceTransparent=l(e.forceTransparent,!1),this.edgeBleach=l(e.edgeBleach,0),super.init(e),this.build()}attach(t){this.bufferList.forEach((t=>{this.viewer.add(t)})),this.setVisibility(this.visible),t()}create(){var t={};if(this.volume){var e,i,r=this.volume;"sigma"===this.thresholdType?(e=r.getValueForSigma(this.thresholdMin),i=r.getValueForSigma(this.thresholdMax)):(e=this.thresholdMin,i=this.thresholdMax),r.setFilter(e,i,this.thresholdOut),Object.assign(t,{position:r.getDataPosition(),color:r.getDataColor(this.getColorParams())}),"sphere"===this.dotType&&Object.assign(t,{radius:r.getDataSize(this.radius,this.scale),picking:r.getDataPicking()})}else{var n=this.surface;Object.assign(t,{position:n.getPosition(),color:n.getColor(this.getColorParams())}),"sphere"===this.dotType&&Object.assign(t,{radius:n.getSize(this.radius,this.scale),picking:n.getPicking()})}"sphere"===this.dotType?this.dotBuffer=new Da(t,this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!1})):this.dotBuffer=new Oa(t,this.getBufferParams({pointSize:this.pointSize,sizeAttenuation:this.sizeAttenuation,sortParticles:this.sortParticles,useTexture:this.useTexture,alphaTest:this.alphaTest,forceTransparent:this.forceTransparent,edgeBleach:this.edgeBleach})),this.bufferList.push(this.dotBuffer)}update(t={}){if(0===this.bufferList.length)return;const e={};t.color&&(this.volume?Object.assign(e,{color:this.volume.getDataColor(this.getColorParams())}):Object.assign(e,{color:this.surface.getColor(this.getColorParams())})),"sphere"===this.dotType&&(t.radius||t.scale)&&(this.volume?Object.assign(e,{radius:this.volume.getDataSize(this.radius,this.scale)}):Object.assign(e,{radius:this.surface.getSize(this.radius,this.scale)})),this.dotBuffer.setAttributes(e)}setParameters(t,e={},i){return t&&void 0!==t.thresholdType&&this.volume instanceof Cs&&("value"===this.thresholdType&&"sigma"===t.thresholdType?(this.thresholdMin=this.volume.getSigmaForValue(this.thresholdMin),this.thresholdMax=this.volume.getSigmaForValue(this.thresholdMax)):"sigma"===this.thresholdType&&"value"===t.thresholdType&&(this.thresholdMin=this.volume.getValueForSigma(this.thresholdMin),this.thresholdMax=this.volume.getValueForSigma(this.thresholdMax)),this.thresholdType=t.thresholdType),t&&void 0!==t.radiusType&&("radius"===t.radiusType?this.radius=.1:this.radius=parseFloat(t.radiusType),e.radius=!0,"sphere"!==this.dotType||Mt&&!this.disableImpostor||(i=!0)),t&&void 0!==t.radius&&(e.radius=!0,"sphere"!==this.dotType||Mt&&!this.disableImpostor||(i=!0)),t&&void 0!==t.scale&&(e.scale=!0,"sphere"!==this.dotType||Mt&&!this.disableImpostor||(i=!0)),super.setParameters(t,e,i),this}}zt.add("shader/Image.vert","uniform float clipRadius;\nuniform vec3 clipCenter;\nvarying vec2 vUv;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\nvoid main() {\n#include begin_vertex\n#include project_vertex\nvUv = uv;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvViewPosition = -mvPosition.xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n}"),zt.add("shader/Image.frag","uniform sampler2D map;\nuniform float opacity;\nuniform vec2 mapSize;\nuniform float clipNear;\nuniform float clipRadius;\nvarying vec2 vUv;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#if defined( PICKING )\nuniform sampler2D pickingMap;\nuniform float objectId;\n#else\n#include fog_pars_fragment\n#endif\n#if defined( CUBIC_INTERPOLATION )\n#if defined( CATMULROM_FILTER ) || defined( MITCHELL_FILTER )\n#if defined( CATMULROM_FILTER )\nconst float B = 0.0;\nconst float C = 0.5;\n#elif defined( MITCHELL_FILTER )\nconst float B = 0.333;\nconst float C = 0.333;\n#endif\nfloat applyFilter( float x ){\nfloat f = x;\nif( f < 0.0 ){\nf = -f;\n}\nif( f < 1.0 ){\nreturn ( ( 12.0 - 9.0 * B - 6.0 * C ) * ( f * f * f ) +\n( -18.0 + 12.0 * B + 6.0 *C ) * ( f * f ) +\n( 6.0 - 2.0 * B ) ) / 6.0;\n}else if( f >= 1.0 && f < 2.0 ){\nreturn ( ( -B - 6.0 * C ) * ( f * f * f )\n+ ( 6.0 * B + 30.0 * C ) * ( f *f ) +\n( - ( 12.0 * B ) - 48.0 * C ) * f +\n8.0 * B + 24.0 * C ) / 6.0;\n}else{\nreturn 0.0;\n}\n}\n#elif defined( BSPLINE_FILTER )\nfloat applyFilter( float x ){\nfloat f = x;\nif( f < 0.0 ){\nf = -f;\n}\nif( f >= 0.0 && f <= 1.0 ){\nreturn ( 2.0 / 3.0 ) + ( 0.5 ) * ( f * f * f ) - ( f * f );\n}else if( f > 1.0 && f <= 2.0 ){\nreturn 1.0 / 6.0 * pow( ( 2.0 - f ), 3.0 );\n}\nreturn 1.0;\n}\n#else\nfloat applyFilter( float x ){\nreturn 1.0;\n}\n#endif\nvec4 biCubic( sampler2D tex, vec2 texCoord ){\nvec2 texelSize = 1.0 / mapSize;\ntexCoord -= texelSize / 2.0;\nvec4 nSum = vec4( 0.0 );\nfloat nDenom = 0.0;\nvec2 cell = fract( texCoord * mapSize );\nfor( float m = -1.0; m <= 2.0; ++m ){\nfor( float n = -1.0; n <= 2.0; ++n ){\nvec4 vecData = texture2D(\ntex, texCoord + texelSize * vec2( m, n )\n);\nfloat c = applyFilter( m - cell.x ) * applyFilter( -n + cell.y );\nnSum += vecData * c;\nnDenom += c;\n}\n}\nreturn nSum / nDenom;\n}\n#endif\nvoid main(){\n#include nearclip_fragment\n#include radiusclip_fragment\n#if defined( CUBIC_INTERPOLATION )\ngl_FragColor = biCubic( map, vUv );\n#else\ngl_FragColor = texture2D( map, vUv );\n#endif\n#if defined( PICKING )\nif( gl_FragColor.a < 0.3 )\ndiscard;\ngl_FragColor = vec4( texture2D( pickingMap, vUv ).xyz, objectId );\n#else\nif( gl_FragColor.a < 0.01 )\ndiscard;\ngl_FragColor.a *= opacity;\n#include fog_fragment\n#endif\n}");const Ra=new Uint16Array([0,1,2,1,3,2]),La=new Float32Array([0,1,0,0,1,1,1,0]),Na=Object.assign({filter:"nearest",forceTransparent:!0},Ms),za=Object.assign({filter:{updateShader:!0,uniform:!0}},Ts);class Va extends Ds{constructor(t,i){super({position:t.position,index:Ra,picking:t.picking},i),this.parameterTypes=za,this.alwaysTransparent=!0,this.hasWireframe=!1,this.vertexShader="Image.vert",this.fragmentShader="Image.frag";const{imageData:r,width:n,height:s}=t,o=new e.DataTexture(r,n,s);o.flipY=!0,this.tex=o;const a=r.length,c=new Uint8Array(a);for(let t=0;t<a;t+=4){const e=t/4;c[t]=e>>16&255,c[t+1]=e>>8&255,c[t+2]=255&e}const l=new e.DataTexture(c,n,s);l.flipY=!0,l.minFilter=e.NearestFilter,l.magFilter=e.NearestFilter,this.pickingTex=l,this.addUniforms({map:{value:o},pickingMap:{value:l},mapSize:{value:new e.Vector2(n,s)}}),this.geometry.setAttribute("uv",new e.BufferAttribute(La,2))}get defaultParameters(){return Na}getDefines(t){const e=super.getDefines(t),i=this.parameters.filter;return i.startsWith("cubic")&&(e.CUBIC_INTERPOLATION=1,i.endsWith("bspline")?e.BSPLINE_FILTER=1:i.endsWith("catmulrom")?e.CATMULROM_FILTER=1:i.endsWith("mitchell")&&(e.MITCHELL_FILTER=1)),e}updateTexture(){const t=this.tex,i=this.parameters.filter;i.startsWith("cubic")?(t.minFilter=e.NearestFilter,t.magFilter=e.NearestFilter):"linear"===i?(t.minFilter=e.LinearFilter,t.magFilter=e.LinearFilter):(t.minFilter=e.NearestFilter,t.magFilter=e.NearestFilter),t.needsUpdate=!0,this.pickingTex.needsUpdate=!0}makeMaterial(){super.makeMaterial(),this.updateTexture();const t=this.material;t.uniforms.map.value=this.tex,t.blending=e.NormalBlending,t.needsUpdate=!0;const i=this.wireframeMaterial;i.uniforms.map.value=this.tex,i.blending=e.NormalBlending,i.needsUpdate=!0;const r=this.pickingMaterial;r.uniforms.map.value=this.tex,r.uniforms.pickingMap.value=this.pickingTex,r.blending=e.NormalBlending,r.needsUpdate=!0}setUniforms(t){t&&void 0!==t.filter&&(this.updateTexture(),t.map=this.tex),super.setUniforms(t)}}class Ua{constructor(t,e){const i=e||{};this.dimension=l(i.dimension,"x"),this.positionType=l(i.positionType,"percent"),this.position=l(i.position,30),this.thresholdType=l(i.thresholdType,"sigma"),this.thresholdMin=l(i.thresholdMin,-1/0),this.thresholdMax=l(i.thresholdMax,1/0),this.normalize=l(i.normalize,!1),this.volume=t}getPositionFromCoordinate(t){const i=this.dimension,r=this.volume,n=r.matrix,s=(new e.Vector3).setFromMatrixPosition(n)[i],o=(new e.Vector3).setFromMatrixScale(n)[i];let a;return a="x"===i?r.nx:"y"===i?r.ny:r.nz,Math.round(((t-s)/(a/100)+1)/o)}getData(t){t=t||{};const i=this.volume,r=i.data,n=i.matrix;let s;function o(t){return Math.round(t/100*(s-1))}function a(t,e,r,n){return 3*(r*i.ny*i.nx+e*i.nx+t)+n}s="coordinate"===this.positionType?this.getPositionFromCoordinate(this.position):this.position;const c=new Float32Array(12),l=new e.Vector3;let u,h,d,m,f,p=0,g=0,y=0,b=i.nx,_=i.ny,x=i.nz;function v(t,e,i,r){l.set(t,e,i).applyMatrix4(n).toArray(c,r)}"x"===this.dimension?(d=o(i.nx),m=i.ny-1,f=i.nz-1,u=i.nz,h=i.ny,p=d,b=p+1,v(d,0,0,0),v(d,m,0,3),v(d,0,f,6),v(d,m,f,9)):"y"===this.dimension?(d=i.nx-1,m=o(i.ny),f=i.nz-1,u=i.nz,h=i.nx,g=m,_=g+1,v(0,m,0,0),v(d,m,0,3),v(0,m,f,6),v(d,m,f,9)):"z"===this.dimension&&(d=i.nx-1,m=i.ny-1,f=o(i.nz),u=i.nx,h=i.ny,y=f,x=y+1,v(0,0,f,0),v(0,m,f,3),v(d,0,f,6),v(d,m,f,9));let w=0,A=0;const S=new Uint8Array(u*h*4),C=new Float32Array(u*h);let P,I;"sigma"===this.thresholdType?(P=i.getValueForSigma(this.thresholdMin),I=i.getValueForSigma(this.thresholdMax)):(P=this.thresholdMin,I=this.thresholdMax);const k=Object.assign({},t.colorParams,{volume:i});this.normalize&&(k.domain=[0,1]);const M=$t.getScheme(k),T=new Float32Array(3),D=M.getScale();let B,F=0,E=0;if(this.normalize){F=1/0,B=-1/0;for(let t=g;t<_;++t)for(let e=p;e<b;++e)for(let i=y;i<x;++i){const n=r[a(e,t,i,0)/3];n<F&&(F=n),n>B&&(B=n)}E=B-F}for(let t=g;t<_;++t)for(let e=p;e<b;++e)for(let i=y;i<x;++i){const n=a(e,t,i,0)/3;let s=r[n];this.normalize&&(s=(s-F)/E),M.colorToArray(D(s),T),S[w]=Math.round(255*T[0]),S[w+1]=Math.round(255*T[1]),S[w+2]=Math.round(255*T[2]),S[w+3]=s>P&&s<I?255:0,C[A]=n,++A,w+=4}const O=new Kn(C,i);return{position:c,imageData:S,width:u,height:h,picking:O}}}class ja extends Mi{constructor(t,e,i){super(t,e,i),this.type="slice",this.parameters=Object.assign({filter:{type:"select",buffer:!0,options:{nearest:"nearest",linear:"linear","cubic-bspline":"cubic-bspline","cubic-catmulrom":"cubic-catmulrom","cubic-mitchell":"cubic-mitchell"}},positionType:{type:"select",rebuild:!0,options:{percent:"percent",coordinate:"coordinate"}},position:{type:"range",step:.1,max:100,min:1,rebuild:!0},dimension:{type:"select",rebuild:!0,options:{x:"x",y:"y",z:"z"}},thresholdType:{type:"select",rebuild:!0,options:{value:"value",sigma:"sigma"}},thresholdMin:{type:"number",precision:3,max:1/0,min:-1/0,rebuild:!0},thresholdMax:{type:"number",precision:3,max:1/0,min:-1/0,rebuild:!0},normalize:{type:"boolean",rebuild:!0}},this.parameters,{flatShaded:null,side:null,wireframe:null,linewidth:null,colorScheme:null,roughness:null,metalness:null,diffuse:null}),this.volume=t,this.init(i)}init(t){const e=this.volume,i=t||{};i.colorDomain=l(i.colorDomain,[e.min,e.max]),i.colorScheme=l(i.colorScheme,"value"),i.colorScale=l(i.colorScale,"Spectral"),this.colorScheme="value",this.dimension=l(i.dimension,"x"),this.filter=l(i.filter,"cubic-bspline"),this.positionType=l(i.positionType,"percent"),this.position=l(i.position,30),this.thresholdType=l(i.thresholdType,"sigma"),this.thresholdMin=l(i.thresholdMin,-1/0),this.thresholdMax=l(i.thresholdMax,1/0),this.normalize=l(i.normalize,!1),super.init(i),this.build()}attach(t){this.bufferList.forEach((t=>{this.viewer.add(t)})),this.setVisibility(this.visible),t()}create(){const t=new Ua(this.volume,{positionType:this.positionType,position:this.position,dimension:this.dimension,thresholdType:this.thresholdType,thresholdMin:this.thresholdMin,thresholdMax:this.thresholdMax,normalize:this.normalize}),e=new Va(t.getData({colorParams:this.getColorParams()}),this.getBufferParams({filter:this.filter}));this.bufferList.push(e)}}function Ga(t){Dt.error(`makeRepresentation: representation type ${t} unknown`)}const Ha={name:"some element",status:""};class qa{constructor(t,e={}){this.stage=t,this.signals={statusChanged:new r.Signal,nameChanged:new r.Signal,disposed:new r.Signal},this.parameters=u(e,this.defaultParameters),this.uuid=F()}get defaultParameters(){return Ha}get name(){return this.parameters.name}setStatus(t){return this.parameters.status=t,this.signals.statusChanged.dispatch(t),this}setName(t){return this.parameters.name=t,this.signals.nameChanged.dispatch(t),this}dispose(){this.signals.disposed.dispatch()}}const Wa=Object.assign({visible:!0},Ha);class Xa extends qa{constructor(t,e,i={},n){super(t,Object.assign({name:e.type},i)),this.parent=n,this.signals=Object.assign({visibilityChanged:new r.Signal,parametersChanged:new r.Signal},this.signals),this.setRepresentation(e)}get defaultParameters(){return Wa}get visible(){return this.parameters.visible}get type(){return"representation"}getType(){return this.repr.type}setRepresentation(t){this._disposeRepresentation(),this.repr=t,this.stage.tasks.listen(this.repr.tasks),this.updateVisibility()}_disposeRepresentation(){this.repr&&(this.stage.tasks.unlisten(this.repr.tasks),this.repr.dispose())}dispose(){this.parent&&this.parent.hasRepresentation(this)?this.parent.removeRepresentation(this):(this._disposeRepresentation(),this.signals.disposed.dispatch())}setVisibility(t){return this.parameters.visible=t,this.updateVisibility(),this.signals.visibilityChanged.dispatch(this.parameters.visible),this}getVisibility(){return this.parent?this.parent.parameters.visible&&this.parameters.visible:this.parameters.visible}toggleVisibility(){return this.setVisibility(!this.parameters.visible)}updateVisibility(){this.repr.setVisibility(this.getVisibility())}update(t){return this.repr.update(t),this}build(t){return this.repr.build(t),this}setSelection(t){const e=this.repr;return e.setSelection&&e.setSelection(t),this}setParameters(t){return this.repr.setParameters(t),this.signals.parametersChanged.dispatch(this.repr.getParameters()),this}getParameters(){return this.repr.getParameters()}setColor(t){return this.repr.setColor(t),this}}const Ya=new e.Matrix4,Ka=new e.Vector3,Za={name:"",status:"",visible:!0};class Qa{constructor(t,i,n={}){this.stage=t,this.object=i,this.signals={representationAdded:new r.Signal,representationRemoved:new r.Signal,visibilityChanged:new r.Signal,matrixChanged:new r.Signal,statusChanged:new r.Signal,nameChanged:new r.Signal,disposed:new r.Signal},this.reprList=[],this.annotationList=[],this.matrix=new e.Matrix4,this.position=new e.Vector3,this.quaternion=new e.Quaternion,this.scale=new e.Vector3(1,1,1),this.transform=new e.Matrix4,this.parameters=u(n,this.defaultParameters),this.uuid=F(),this.viewer=t.viewer,this.controls=new eo(this)}get defaultParameters(){return Za}get name(){return this.parameters.name}get status(){return this.parameters.status}get visible(){return this.parameters.visible}setPosition(t){return Array.isArray(t)?this.position.fromArray(t):this.position.copy(t),this.updateMatrix(),this}setRotation(t){if(Array.isArray(t))if(3===t.length){const i=(new e.Euler).fromArray(t);this.quaternion.setFromEuler(i)}else this.quaternion.fromArray(t);else t instanceof e.Euler?this.quaternion.setFromEuler(t):this.quaternion.copy(t);return this.updateMatrix(),this}setScale(t){return this.scale.set(t,t,t),this.updateMatrix(),this}setTransform(t){return this.transform.copy(t),this.updateMatrix(),this}updateMatrix(){const t=this.getCenterUntransformed(Ka);this.matrix.makeTranslation(-t.x,-t.y,-t.z),Ya.makeRotationFromQuaternion(this.quaternion),this.matrix.premultiply(Ya),Ya.makeScale(this.scale.x,this.scale.y,this.scale.z),this.matrix.premultiply(Ya);const e=this.position;Ya.makeTranslation(e.x+t.x,e.y+t.y,e.z+t.z),this.matrix.premultiply(Ya),this.matrix.premultiply(this.transform),this.updateRepresentationMatrices(),this.stage.viewer.updateBoundingBox(),this.signals.matrixChanged.dispatch(this.matrix)}updateRepresentationMatrices(){this.reprList.forEach((t=>{t.setParameters({matrix:this.matrix})}))}addAnnotation(t,e,i){const r=new Zs(this,t,e,i);return this.annotationList.push(r),r}eachAnnotation(t){this.annotationList.slice().forEach(t)}removeAnnotation(t){const e=this.annotationList.indexOf(t);-1!==e&&(this.annotationList.splice(e,1),t.dispose())}removeAllAnnotations(){this.eachAnnotation((t=>t.dispose())),this.annotationList.length=0}_addRepresentation(e,i,r,n=!1){const s=r||{},o=this.stage.getParameters();s.matrix=this.matrix.clone(),s.quality=s.quality||o.quality,s.disableImpostor=l(s.disableImpostor,!o.impostor),s.useWorker=l(s.useWorker,o.workerDefault),s.visible=l(s.visible,!0);const a=Object.assign({},s,{visible:this.parameters.visible&&s.visible}),c=function(e,i,r,n){var s;if(t.Debug&&Dt.time("makeRepresentation "+e),i instanceof fa){if(!(s=Lt.get(e)))return void Ga(e)}else if(i instanceof As)if("surface"===e)s=Ls;else{if("dot"!==e)return void Ga(e);s=$a}else if(i instanceof Cs)if("surface"===e)s=Ls;else if("dot"===e)s=$a;else{if("slice"!==e)return void Ga(e);s=ja}else if(i instanceof ba)s=_a,i=i.getBufferList();else{if("buffer"!==e)return void Dt.error("makeRepresentation: object "+i+" unknown");s=_a}const o=new s(i,r,n);return t.Debug&&Dt.timeEnd("makeRepresentation "+e),o}(e,i,this.viewer,a),u=new Xa(this.stage,c,s,this);return n||(this.reprList.push(u),this.signals.representationAdded.dispatch(u)),u}addBufferRepresentation(t,e){return this._addRepresentation.call(this,"buffer",t,e)}hasRepresentation(t){return-1!==this.reprList.indexOf(t)}eachRepresentation(t){this.reprList.slice().forEach(t)}removeRepresentation(t){const e=this.reprList.indexOf(t);-1!==e&&(this.reprList.splice(e,1),t.dispose(),this.signals.representationRemoved.dispatch(t))}updateRepresentations(t){this.reprList.forEach((e=>e.update(t))),this.stage.viewer.requestRender()}removeAllRepresentations(){this.eachRepresentation((t=>t.dispose()))}dispose(){this.removeAllAnnotations(),this.removeAllRepresentations(),this.reprList.length=0,this.signals.disposed.dispatch()}setVisibility(t){return this.parameters.visible=t,this.eachRepresentation((t=>t.updateVisibility())),this.eachAnnotation((t=>t.updateVisibility())),this.signals.visibilityChanged.dispatch(t),this}setStatus(t){return this.parameters.status=t,this.signals.statusChanged.dispatch(t),this}setName(t){return this.parameters.name=t,this.signals.nameChanged.dispatch(t),this}getBox(...t){return this.getBoxUntransformed(...t).clone().applyMatrix4(this.matrix)}getCenter(...t){return this.getCenterUntransformed(...t).clone().applyMatrix4(this.matrix)}getZoom(...t){return this.stage.getZoomForBox(this.getBox(...t))}getBoxUntransformed(...t){return new e.Box3}getCenterUntransformed(...t){return this.getBoxUntransformed().getCenter(new e.Vector3)}autoView(t){this.stage.animationControls.zoomMove(this.getCenter(),this.getZoom(),l(t,0))}}class Ja{constructor(t=[]){this.list=t;const e=t.length;for(let i=0;i<e;++i){t[i].signals.disposed.add(this._remove,this)}}_remove(t){const e=this.list.indexOf(t);-1!==e&&this.list.splice(e,1)}get first(){return this.list.length>0?this.list[0]:void 0}forEach(t){return this.list.forEach(t),this}dispose(){return this.forEach((t=>t.dispose()))}}class tc extends Ja{setParameters(t){return this.forEach((e=>e.setParameters(t)))}setVisibility(t){return this.forEach((e=>e.setVisibility(t)))}setSelection(t){return this.forEach((e=>e.setSelection(t)))}setColor(t){return this.forEach((e=>e.setColor(t)))}update(t){return this.forEach((e=>e.update(t)))}build(t){return this.forEach((e=>e.build(t)))}dispose(t){return this.forEach((t=>t.dispose()))}}const ec=Object.assign({defaultStep:1,defaultTimeout:50,defaultInterpolateType:"",defaultInterpolateStep:5,defaultMode:"loop",defaultDirection:"forward",initialFrame:0},Ha);class ic extends qa{constructor(t,e,i={}){super(t,Object.assign({name:e.name},i)),this.trajectory=e,this.signals=Object.assign(this.signals,{frameChanged:new r.Signal,playerChanged:new r.Signal,countChanged:new r.Signal,parametersChanged:new r.Signal}),e.signals.frameChanged.add((t=>{this.signals.frameChanged.dispatch(t)})),e.signals.playerChanged.add((t=>{this.signals.playerChanged.dispatch(t)})),e.signals.countChanged.add((t=>{this.signals.countChanged.dispatch(t)})),void 0!==i.initialFrame&&this.setFrame(i.initialFrame)}get defaultParameters(){return ec}get type(){return"trajectory"}setFrame(t){this.trajectory.setFrame(t)}setParameters(t={}){this.trajectory.setParameters(t),this.signals.parametersChanged.dispatch(t)}dispose(){this.trajectory.dispose(),super.dispose()}}class rc{constructor(t,e){this.name=t,this.path=e,this.coordinates=[],this.boxes=[],this.times=[],this.timeOffset=0,this.deltaTime=1}get type(){return"Frames"}}class nc{constructor(t,i){let r,n;if(this.A=new ts(3,3),this.W=new ts(1,3),this.U=new ts(3,3),this.V=new ts(3,3),this.VH=new ts(3,3),this.R=new ts(3,3),this.tmp=new ts(3,3),this.c=new ts(3,3),t instanceof fa)r=t.atomCount;else{if(!(t instanceof Float32Array))return;r=t.length/3}if(i instanceof fa)n=i.atomCount;else{if(!(i instanceof Float32Array))return;n=i.length/3}const s=Math.min(r,n),o=new ts(3,s),a=new ts(3,s);this.coords1t=new ts(s,3),this.coords2t=new ts(s,3),this.transformationMatrix=new e.Matrix4,this.c.data.set([1,0,0,0,1,0,0,0,-1]),this.prepCoords(t,o,s,!1),this.prepCoords(i,a,s,!1),this._superpose(o,a)}_superpose(e,i){this.mean1=ns(e),this.mean2=ns(i),ss(e,this.mean1),ss(i,this.mean2),es(this.coords1t,e),es(this.coords2t,i),is(this.A,this.coords2t,this.coords1t),us(this.A,this.W,this.U,this.V),function(t,e){const i=t.data,r=e.data,n=i[4],s=i[8],o=i[5],a=i[7],c=i[0],l=c*n,u=c*o,h=i[3],d=i[1],m=h*d,f=i[2],p=h*f,g=i[6],y=g*d,b=g*f,_=1/(l*s-u*a-m*s+p*a+y*o-b*n);r[0]=(n*s-o*a)*_,r[1]=-(d*s-f*a)*_,r[2]=-(-d*o+f*n)*_,r[3]=-(h*s-o*g)*_,r[4]=(c*s-b)*_,r[5]=-(u-p)*_,r[6]=-(-h*a+n*g)*_,r[7]=-(c*a-y)*_,r[8]=(l-m)*_}(this.V,this.VH),rs(this.R,this.U,this.VH),function(t){const e=t.data;return e[0]*e[4]*e[8]-e[0]*e[5]*e[7]-e[3]*e[1]*e[8]+e[3]*e[2]*e[7]+e[6]*e[1]*e[5]-e[6]*e[2]*e[4]}(this.R)<0&&(t.Debug&&Dt.log("R not a right handed system"),rs(this.tmp,this.c,this.VH),rs(this.R,this.U,this.tmp));const r=new ts(4,4),n=new ts(4,4),s=new ts(4,4),o=new ts(4,4),a=new ts(4,4),c=new ts(4,4),l=this.R.data,u=this.mean1,h=this.mean2;o.data.set([1,0,0,-u[0],0,1,0,-u[1],0,0,1,-u[2],0,0,0,1]),a.data.set([l[0],l[1],l[2],0,l[3],l[4],l[5],0,l[6],l[7],l[8],0,0,0,0,1]),c.data.set([1,0,0,h[0],0,1,0,h[1],0,0,1,h[2],0,0,0,1]),es(n,o),is(r,a,n),es(s,r),is(n,c,s),es(r,n),this.transformationMatrix.elements=r.data}prepCoords(t,e,i,r){let n=0;const s=e.data;let o=3,a=3*i;if(r&&(a=4*i,o=4),t instanceof fa)t.eachAtom((function(t){n<a&&(s[n+0]=t.x,s[n+1]=t.y,s[n+2]=t.z,r&&(s[n+3]=1),n+=o)}));else if(t instanceof Float32Array)for(;n<a;n+=o)n<a&&(s[n]=t[n],s[n+1]=t[n+1],s[n+2]=t[n+2],r&&(s[n+3]=1));else Dt.warn("prepCoords: input type unknown")}transform(t){let i;if(t instanceof fa)i=t.atomCount;else{if(!(t instanceof Float32Array))return;i=t.length/3}const r=new ts(4,i),n=new ts(i,4);this.prepCoords(t,r,i,!0);const s=this.transformationMatrix,o=s.determinant();if(!o)return o;const a=new ts(4,4);a.data=s.elements,function(t,e,i){let r=0,n=0,s=0,o=0,a=0,c=0,l=0,u=0;const h=e.cols,d=e.rows,m=i.cols,f=e.data,p=i.data,g=t.data;let y=0;for(;r<d;o+=h,r++)for(l=0,n=0;n<m;u++,l++,n++){for(c=l,a=o,y=0,s=0;s<h;a++,c+=m,s++)y+=f[a]*p[c];g[u]=y}}(n,r,a);let c=0;const l=n.data;if(t instanceof fa){t.eachAtom((function(t){t.x=l[c],t.y=l[c+1],t.z=l[c+2],c+=4}));const i=new e.Matrix4;i.copy(s).invert();const r=t.biomolDict;for(let t in r)if(r.hasOwnProperty(t)){r[t].partList.forEach((function(t){t.matrixList.forEach((function(t){t.premultiply(s),t.multiply(i)}))}))}}else if(t instanceof Float32Array){const e=4*i;for(;c<e;c+=4)t[c]=l[c],t[c+1]=l[c+1],t[c+2]=l[c+2]}else Dt.warn("transform: input type unknown");return this.transformationMatrix}}const sc={step:1,timeout:50,start:0,end:0,interpolateType:"",interpolateStep:5,mode:"loop",direction:"forward"};class oc{constructor(t,e={}){this.signals={startedRunning:new r.Signal,haltedRunning:new r.Signal},this._run=!1,this._previousTime=0,this._currentTime=0,this._currentStep=1,t.signals.playerChanged.add((t=>{t!==this&&this.pause()}),this);const i=l(t.frameCount,1);this.traj=t,this.parameters=u(e,sc),this.parameters.end=Math.min(l(e.end,i-1),i-1),this.parameters.step=l(e.step,Math.ceil((i+1)/100)),this._currentFrame=this.parameters.start,this._direction="bounce"===this.parameters.direction?"forward":this.parameters.direction,t.signals.countChanged.add((t=>{this.parameters.end=Math.min(l(this.parameters.end,t-1),t-1)}),this),this._animate=this._animate.bind(this)}get isRunning(){return this._run}setParameters(t={}){h(this.parameters,t),void 0!==t.direction&&"bounce"!==this.parameters.direction&&(this._direction=this.parameters.direction)}_animate(){if(!this._run)return;this._currentTime=window.performance.now();const t=this._currentTime-this._previousTime,e=this.parameters.interpolateType?this.parameters.interpolateStep:1,i=this.parameters.timeout/e,r=this.traj;if(r&&r.frameCount&&!r.inProgress&&t>=i)if(this.parameters.interpolateType)if(this._currentStep>this.parameters.interpolateStep&&(this._currentStep=1),1===this._currentStep&&(this._currentFrame=this._nextInterpolated()),r.hasFrame(this._currentFrame)){this._currentStep+=1;const t=this._currentStep/(this.parameters.interpolateStep+1),[e,i,n,s]=this._currentFrame;r.setFrameInterpolated(e,i,n,s,t,this.parameters.interpolateType),this._previousTime=this._currentTime}else r.loadFrame(this._currentFrame);else{const t=this._next();r.hasFrame(t)?(r.setFrame(t),this._previousTime=this._currentTime):r.loadFrame(t)}window.requestAnimationFrame(this._animate)}_next(){const t=this.parameters;let e;return e="forward"===this._direction?this.traj.currentFrame+t.step:this.traj.currentFrame-t.step,(e>t.end||e<t.start)&&("bounce"===t.direction&&("forward"===this._direction?this._direction="backward":this._direction="forward"),"once"===t.mode?(this.pause(),e="forward"===t.direction?t.end:"backward"===t.direction||"forward"===this._direction?t.start:t.end):"forward"===this._direction?(e=t.start,t.interpolateType&&(e=Math.min(t.end,e+t.step))):(e=t.end,t.interpolateType&&(e=Math.max(t.start,e-t.step)))),e}_nextInterpolated(){const t=this.parameters,e=this._next();let i,r,n;return"forward"===this._direction?(i=Math.max(t.start,e-t.step),r=Math.max(t.start,e-2*t.step),n=Math.max(t.start,e-3*t.step)):(i=Math.min(t.end,e+t.step),r=Math.min(t.end,e+2*t.step),n=Math.min(t.end,e+3*t.step)),[e,i,r,n]}toggle(){this._run?this.pause():this.play()}play(){if(!this._run){this.traj.player!==this&&this.traj.setPlayer(this),this._currentStep=1;const t=this.parameters,e=this.traj.currentFrame;let i=Math.ceil(e/t.step)*t.step;"forward"===t.direction&&e>=t.end?i=t.start:"backward"===t.direction&&e<=t.start&&(i=t.end),this.traj.setFrame(i),this._run=!0,this._animate(),this.signals.startedRunning.dispatch()}}pause(){this._run=!1,this.signals.haltedRunning.dispatch()}stop(){this.pause(),this.traj.setFrame(this.parameters.start)}}class ac{constructor(t,e,i={}){this.signals={countChanged:new r.Signal,frameChanged:new r.Signal,playerChanged:new r.Signal},this.frameCache={},this.loadQueue={},this.boxCache={},this.pathCache={},this.frameCacheSize=0,this._frameCount=0,this._currentFrame=-1,this._disposed=!1,this.deltaTime=l(i.deltaTime,0),this.timeOffset=l(i.timeOffset,0),this.centerPbc=l(i.centerPbc,!1),this.removePbc=l(i.removePbc,!1),this.removePeriodicity=l(i.removePeriodicity,!1),this.superpose=l(i.superpose,!1),this.name=t.replace(/^.*[\\/]/,""),this.trajPath=t,this.selection=new gt(l(i.sele,"backbone and not hydrogen")),this.selection.signals.stringChanged.add((()=>{this.selectionIndices=this.structure.getAtomIndices(this.selection),this._resetCache(),this._saveInitialCoords(),this.setFrame(this._currentFrame)}))}get frameCount(){return this._frameCount}get currentFrame(){return this._currentFrame}_init(t){this.setStructure(t),this._loadFrameCount(),this.setPlayer(new oc(this))}_loadFrameCount(){}setStructure(t){this.structure=t,this.atomCount=t.atomCount,this.backboneIndices=this._getIndices(new gt("backbone and not hydrogen")),this._makeAtomIndices(),this._saveStructureCoords(),this.selectionIndices=this._getIndices(this.selection),this._resetCache(),this._saveInitialCoords(),this.setFrame(this._currentFrame)}_saveInitialCoords(){this.structure.hasCoords()?(this.initialCoords=new Float32Array(this.structureCoords),this._makeSuperposeCoords()):this.frameCache[0]?(this.initialCoords=new Float32Array(this.frameCache[0]),this._makeSuperposeCoords()):this.loadFrame(0,(()=>this._saveInitialCoords()))}_saveStructureCoords(){this.structureCoords=this.structure.getAtomData({what:{position:!0}}).position}setSelection(t){return this.selection.setString(t),this}_getIndices(t){let e=0;const i=t.test,r=[];return i&&this.structure.eachAtom((t=>{i(t)&&r.push(e),e+=1})),r}_makeSuperposeCoords(){const t=3*this.selectionIndices.length;this.coords1=new Float32Array(t),this.coords2=new Float32Array(t);const e=this.initialCoords,i=this.coords2;for(let r=0;r<t;r+=3){const t=3*this.selectionIndices[r/3];i[r+0]=e[t+0],i[r+1]=e[t+1],i[r+2]=e[t+2]}}_makeAtomIndices(){Dt.error("Trajectory._makeAtomIndices not implemented")}_resetCache(){this.frameCache={},this.loadQueue={},this.boxCache={},this.pathCache={},this.frameCacheSize=0,this.initialCoords=new Float32Array(0)}setParameters(t={}){let e=!1;void 0!==t.centerPbc&&t.centerPbc!==this.centerPbc&&(this.centerPbc=t.centerPbc,e=!0),void 0!==t.removePeriodicity&&t.removePeriodicity!==this.removePeriodicity&&(this.removePeriodicity=t.removePeriodicity,e=!0),void 0!==t.removePbc&&t.removePbc!==this.removePbc&&(this.removePbc=t.removePbc,e=!0),void 0!==t.superpose&&t.superpose!==this.superpose&&(this.superpose=t.superpose,e=!0),this.deltaTime=l(t.deltaTime,this.deltaTime),this.timeOffset=l(t.timeOffset,this.timeOffset),e&&(this._resetCache(),this.setFrame(this._currentFrame))}hasFrame(t){return Array.isArray(t)?t.every((t=>!!this.frameCache[t])):!!this.frameCache[t]}setFrame(t,e){return void 0===t||(this.inProgress=!0,-1===t||this.frameCache[t]?(this._updateStructure(t),e&&e()):this.loadFrame(t,(()=>{this._updateStructure(t),e&&e()}))),this}_interpolate(t,e,i,r,n,s){const o=this.frameCache;let a;a="spline"===s?function(t,e,i,r,n){const s=t.length,o=new Float32Array(s);for(let a=0;a<s;a+=3){const s=a+1,c=a+2;o[a]=$(r[a],i[a],e[a],t[a],n,1),o[s]=$(r[s],i[s],e[s],t[s],n,1),o[c]=$(r[c],i[c],e[c],t[c],n,1)}return o}(o[t],o[e],o[i],o[r],n):function(t,e,i){const r=t.length,n=new Float32Array(r);for(let s=0;s<r;s+=3){const r=s+1,o=s+2;n[s]=O(e[s],t[s],i),n[r]=O(e[r],t[r],i),n[o]=O(e[o],t[o],i)}return n}(o[t],o[e],n),this.structure.updatePosition(a),this._currentFrame=t,this.signals.frameChanged.dispatch(t)}setFrameInterpolated(t,e,i,r,n,s,o){if(void 0===t)return this;const a=this.frameCache,c=[];return a[r]||c.push(r),a[i]||c.push(i),a[e]||c.push(e),a[t]||c.push(t),c.length?this.loadFrame(c,(()=>{this._interpolate(t,e,i,r,n,s),o&&o()})):(this._interpolate(t,e,i,r,n,s),o&&o()),this}loadFrame(t,e){Array.isArray(t)?t.forEach((t=>{this.loadQueue[t]||this.frameCache[t]||(this.loadQueue[t]=!0,this._loadFrame(t,(()=>{delete this.loadQueue[t]})))})):this.loadQueue[t]||this.frameCache[t]||(this.loadQueue[t]=!0,this._loadFrame(t,(()=>{delete this.loadQueue[t],e&&e()})))}_loadFrame(t,e){Dt.error("Trajectory._loadFrame not implemented",t,e)}_updateStructure(t){this._disposed?console.error("updateStructure: traj disposed"):(-1===t?this.structureCoords&&this.structure.updatePosition(this.structureCoords):this.structure.updatePosition(this.frameCache[t]),this.structure.trajectory={name:this.trajPath,frame:t},this._currentFrame=t,this.inProgress=!1,this.signals.frameChanged.dispatch(t))}_doSuperpose(t){const e=3*this.selectionIndices.length,i=this.coords1,r=this.coords2;for(let r=0;r<e;r+=3){const e=3*this.selectionIndices[r/3];i[r+0]=t[e+0],i[r+1]=t[e+1],i[r+2]=t[e+2]}new nc(i,r).transform(t)}_process(t,e,i,r){if(this._setFrameCount(r),e){if(this.backboneIndices.length>0&&this.centerPbc){const t=[e[0],e[4],e[8]],r=function(t,e,i){return[me(e,i[0],3,0,t),me(e,i[1],3,1,t),me(e,i[2],3,2,t)]}(this.backboneIndices,i,t);!function(t,e,i){if(0===i[0]||0===i[8]||0===i[4])return;const r=t.length,n=i[0],s=i[1],o=i[2],a=-e[0]+n+n/2,c=-e[1]+s+s/2,l=-e[2]+o+o/2;for(let e=0;e<r;e+=3)t[e+0]=(t[e+0]+a)%n,t[e+1]=(t[e+1]+c)%s,t[e+2]=(t[e+2]+l)%o}(i,r,t)}if(this.removePeriodicity){const t=function(t){return[Pe(t,3,0),Pe(t,3,1),Pe(t,3,2)]}(i);!function(t,e,i){if(0===e[0]||0===e[8]||0===e[4])return;const r=t.length;for(let n=3;n<r;n+=3)for(let r=0;r<3;++r){const s=(t[n+r]-i[r])/e[3*r+r];Math.abs(s)>.5&&(t[n+r]-=e[3*r+r]*Math.round(s))}}(i,e,t)}this.removePbc&&function(t,e){if(0===e[0]||0===e[8]||0===e[4])return;const i=t.length;for(let r=3;r<i;r+=3)for(let i=0;i<3;++i){const n=t[r+i]-t[r-3+i];if(Math.abs(n)>.9*e[3*i+i])if(n>0)for(let n=0;n<3;++n)t[r+n]-=e[3*i+n];else for(let n=0;n<3;++n)t[r+n]+=e[3*i+n]}}(i,e)}this.selectionIndices.length>0&&this.coords1&&this.superpose&&this._doSuperpose(i),this.frameCache[t]=i,this.boxCache[t]=e,this.frameCacheSize+=1}_setFrameCount(t){t!==this._frameCount&&(this._frameCount=t,this.signals.countChanged.dispatch(t))}dispose(){this._resetCache(),this._disposed=!0,this.player&&this.player.stop()}setPlayer(t){this.player=t,this.signals.playerChanged.dispatch(t)}getFrameTime(t){return this.timeOffset+t*this.deltaTime}}class cc extends ac{constructor(t,e,i){const r=i||{};r.timeOffset=l(r.timeOffset,t.timeOffset),r.deltaTime=l(r.deltaTime,t.deltaTime),super("",e,r),this.name=t.name,this.path=t.path,this.frames=t.coordinates,this.boxes=t.boxes,this._init(e)}get type(){return"frames"}_makeAtomIndices(){"StructureView"===this.structure.type?this.atomIndices=this.structure.getAtomIndices():this.atomIndices=void 0}_loadFrame(t,e){let i;const r=this.frames[t];if(this.atomIndices){const t=this.atomIndices,e=t.length;i=new Float32Array(3*e);for(let n=0;n<e;++n){const e=3*n,s=3*t[n];i[e+0]=r[s+0],i[e+1]=r[s+1],i[e+2]=r[s+2]}}else i=new Float32Array(r);const n=this.boxes[t],s=this.frames.length;this._process(t,n,i,s),"function"==typeof e&&e()}_loadFrameCount(){this.frames&&this._setFrameCount(this.frames.length)}}class lc extends ac{constructor(t,e,i){super("",e,i),this._init(e)}get type(){return"structure"}_makeAtomIndices(){this.structure.atomSet&&this.structure.atomSet.getSize()<this.structure.atomStore.count?this.atomIndices=this.structure.getAtomIndices():this.atomIndices=void 0}_loadFrame(t,e){let i;const r=this.structure,n=r.frames[t];if(this.atomIndices){const t=this.atomIndices,e=t.length;i=new Float32Array(3*e);for(let r=0;r<e;++r){const e=3*r,s=3*t[r];i[e+0]=n[s+0],i[e+1]=n[s+1],i[e+2]=n[s+2]}}else i=new Float32Array(n);const s=r.boxes[t],o=r.frames.length;this._process(t,s,i,o),"function"==typeof e&&e()}_loadFrameCount(){this._setFrameCount(this.structure.frames.length)}}class uc extends ac{constructor(t,e,i){super(t,e,i),this._init(e)}get type(){return"remote"}_makeAtomIndices(){const t=[];if("StructureView"===this.structure.type){const e=this.structure.getAtomIndices(),i=e.length;let r=e[0],n=e[0];for(let s=1;s<i;++s){const i=e[s];n+1<i&&(t.push([r,n+1]),r=i),n=i}t.push([r,n+1])}else t.push([0,this.atomCount]);this.atomIndices=t}_loadFrame(e,i){const r=new XMLHttpRequest,n=t.TrajectoryDatasource.getFrameUrl(this.trajPath,e),s=t.TrajectoryDatasource.getFrameParams(this.trajPath,this.atomIndices);r.open("POST",n,!0),r.responseType="arraybuffer",r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.addEventListener("load",(()=>{const t=r.response;if(!t)return void Dt.error(`empty arrayBuffer for '${n}'`);const s=new Int32Array(t,0,1)[0],o=new Float32Array(t,8,9),a=new Float32Array(t,44);this._process(e,o,a,s),"function"==typeof i&&i()}),!1),r.send(s)}_loadFrameCount(){const e=new XMLHttpRequest,i=t.TrajectoryDatasource.getCountUrl(this.trajPath);e.open("GET",i,!0),e.addEventListener("load",(()=>{this._setFrameCount(parseInt(e.response))}),!1),e.send()}}class hc extends ac{constructor(t,e,i){super("",e,i),this.requestCallback=t,this._init(e)}get type(){return"callback"}_makeAtomIndices(){const t=[];if("StructureView"===this.structure.type){const e=this.structure.getAtomIndices(),i=e.length;let r=e[0],n=e[0];for(let s=1;s<i;++s){const i=e[s];n+1<i&&(t.push([r,n+1]),r=i),n=i}t.push([r,n+1])}else t.push([0,this.atomCount]);this.atomIndices=t}_loadFrame(t,e){this.requestCallback(((t,i,r,n)=>{this._process(t,i,r,n),"function"==typeof e&&e()}),t,this.atomIndices)}_loadFrameCount(){this.requestCallback((t=>this._setFrameCount(t)))}}fa.prototype.getView=function(t){return new dc(this,t)};class dc extends fa{constructor(t,i){super(),this.structure=t,this.selection=i,this.center=new e.Vector3,this.boundingBox=new e.Box3,this._bp=this.getBondProxy(),this._ap=this.getAtomProxy(),this._rp=this.getResidueProxy(),this._cp=this.getChainProxy(),this.selection&&this.selection.signals.stringChanged.add(this.refresh,this),this.structure.signals.refreshed.add(this.refresh,this),this.refresh()}init(){}get type(){return"StructureView"}get name(){return this.structure.name}get path(){return this.structure.path}get title(){return this.structure.title}get id(){return this.structure.id}get data(){return this.structure.data}get atomSetDict(){return this.structure.atomSetDict}get biomolDict(){return this.structure.biomolDict}get entityList(){return this.structure.entityList}get unitcell(){return this.structure.unitcell}get frames(){return this.structure.frames}get boxes(){return this.structure.boxes}get validation(){return this.structure.validation}get bondStore(){return this.structure.bondStore}get backboneBondStore(){return this.structure.backboneBondStore}get rungBondStore(){return this.structure.rungBondStore}get atomStore(){return this.structure.atomStore}get residueStore(){return this.structure.residueStore}get chainStore(){return this.structure.chainStore}get modelStore(){return this.structure.modelStore}get atomMap(){return this.structure.atomMap}get residueMap(){return this.structure.residueMap}get bondHash(){return this.structure.bondHash}get spatialHash(){return this.structure.spatialHash}get _hasCoords(){return this.structure._hasCoords}set _hasCoords(t){this.structure._hasCoords=t}refresh(){t.Debug&&Dt.time("StructureView.refresh"),this.atomSetCache={};const i=this.structure;if(this.selection.isAllSelection()&&i!==this&&i.atomSet&&i.bondSet){this.atomSet=i.atomSet.clone(),this.bondSet=i.bondSet.clone();for(let t in this.atomSetDict){const e=this.atomSetDict[t];this.atomSetCache["__"+t]=e.clone()}this.atomCount=i.atomCount,this.bondCount=i.bondCount,this.boundingBox.copy(i.boundingBox),this.center.copy(i.center)}else if(this.selection.isNoneSelection()&&i!==this&&i.atomSet&&i.bondSet){this.atomSet=new Sr(i.atomCount),this.bondSet=new Sr(i.bondCount);for(let t in this.atomSetDict)this.atomSetCache["__"+t]=new Sr(i.atomCount);this.atomCount=0,this.bondCount=0,this.boundingBox.makeEmpty(),this.center.set(0,0,0)}else{this.atomSet=this.getAtomSet(this.selection,!0),i.atomSet&&(this.atomSet=this.atomSet.intersection(i.atomSet)),this.bondSet=this.getBondSet();for(let t in this.atomSetDict){const e=this.atomSetDict[t];this.atomSetCache["__"+t]=e.makeIntersection(this.atomSet)}this.atomCount=this.atomSet.getSize(),this.bondCount=this.bondSet.getSize(),this.boundingBox=this.getBoundingBox(),this.center=this.boundingBox.getCenter(new e.Vector3)}t.Debug&&Dt.timeEnd("StructureView.refresh"),this.signals.refreshed.dispatch()}setSelection(t){this.selection=t,this.refresh()}getSelection(t){const e=[];t&&t.string&&e.push(t.string);const i=this.structure.getSelection();i&&i.string&&e.push(i.string),this.selection&&this.selection.string&&e.push(this.selection.string);let r="";return e.length>0&&(r=`( ${e.join(" ) AND ( ")} )`),new gt(r)}getStructure(){return this.structure.getStructure()}eachBond(t,e){this.structure.eachBond(t,this.getSelection(e))}eachAtom(t,e){const i=this.getAtomProxy(),r=this.getAtomSet(e),n=this.atomStore.count;if(r.getSize()<n)r.forEach((function(e){i.index=e,t(i)}));else for(let e=0;e<n;++e)i.index=e,t(i)}eachResidue(t,e){this.structure.eachResidue(t,this.getSelection(e))}eachResidueN(t,e){console.error("StructureView.eachResidueN() not implemented")}eachChain(t,e){this.structure.eachChain(t,this.getSelection(e))}eachModel(t,e){this.structure.eachModel(t,this.getSelection(e))}getAtomSet(t,e=!1){let i=this.structure.getAtomSet(t);return!e&&this.atomSet&&(i=i.makeIntersection(this.atomSet)),i}getAtomIndices(t){return this.structure.getAtomIndices(this.getSelection(t))}refreshPosition(){return this.structure.refreshPosition()}dispose(){this.selection&&this.selection.signals.stringChanged.remove(this.refresh,this),this.structure.signals.refreshed.remove(this.refresh,this),this.structure=new fa,delete this.atomSet,delete this.bondSet}}const mc=[[4,0,-2,-1,-2,0,-2,-1,-1,-1,-1,-2,-1,-1,-1,1,0,0,-3,-2],[0,9,-3,-4,-2,-3,-3,-1,-3,-1,-1,-3,-3,-3,-3,-1,-1,-1,-2,-2],[-2,-3,6,2,-3,-1,-1,-3,-1,-4,-3,1,-1,0,-2,0,-1,-3,-4,-3],[-1,-4,2,5,-3,-2,0,-3,1,-3,-2,0,-1,2,0,0,-1,-2,-3,-2],[-2,-2,-3,-3,6,-3,-1,0,-3,0,0,-3,-4,-3,-3,-2,-2,-1,1,3],[0,-3,-1,-2,-3,6,-2,-4,-2,-4,-3,0,-2,-2,-2,0,-2,-3,-2,-3],[-2,-3,-1,0,-1,-2,8,-3,-1,-3,-2,1,-2,0,0,-1,-2,-3,-2,2],[-1,-1,-3,-3,0,-4,-3,4,-3,2,1,-3,-3,-3,-3,-2,-1,3,-3,-1],[-1,-3,-1,1,-3,-2,-1,-3,5,-2,-1,0,-1,1,2,0,-1,-2,-3,-2],[-1,-1,-4,-3,0,-4,-3,2,-2,4,2,-3,-3,-2,-2,-2,-1,1,-2,-1],[-1,-1,-3,-2,0,-3,-2,1,-1,2,5,-2,-2,0,-1,-1,-1,1,-1,-1],[-2,-3,1,0,-3,0,1,-3,0,-3,-2,6,-2,0,0,1,0,-3,-4,-2],[-1,-3,-1,-1,-4,-2,-2,-3,-1,-3,-2,-2,7,-1,-2,-1,-1,-2,-4,-3],[-1,-3,0,2,-3,-2,0,-3,1,-2,0,0,-1,5,1,0,-1,-2,-2,-1],[-1,-3,-2,0,-3,-2,0,-3,2,-2,-1,0,-2,1,5,-1,-1,-3,-3,-2],[1,-1,0,0,-2,0,-1,-2,0,-2,-1,1,-1,0,-1,4,1,-2,-3,-2],[0,-1,-1,-1,-2,-2,-2,-1,-1,-1,-1,0,-1,-1,-1,1,5,0,-2,-2],[0,-1,-3,-2,-1,-3,-3,3,-2,1,1,-3,-2,-2,-3,-2,0,4,-3,-1],[-3,-2,-4,-3,1,-2,-2,-3,-3,-2,-1,-4,-4,-2,-3,-3,-2,-3,11,2],[-2,-2,-3,-2,3,-3,2,-1,-2,-1,-1,-2,-3,-1,-2,-2,-2,-1,2,7]];function fc(t,e){let i,r=0;const n={};return e.forEach((function(e){i=0;const s={};e.forEach((function(e){s[t[i++]]=e})),n[t[r++]]=s})),n}const pc={blosum62:fc("ARNDCQEGHILKMFPSTWYVBZ?",[[4,-1,-2,-2,0,-1,-1,0,-2,-1,-1,-1,-1,-2,-1,1,0,-3,-2,0,-2,-1,0],[-1,5,0,-2,-3,1,0,-2,0,-3,-2,2,-1,-3,-2,-1,-1,-3,-2,-3,-1,0,-1],[-2,0,6,1,-3,0,0,0,1,-3,-3,0,-2,-3,-2,1,0,-4,-2,-3,3,0,-1],[-2,-2,1,6,-3,0,2,-1,-1,-3,-4,-1,-3,-3,-1,0,-1,-4,-3,-3,4,1,-1],[0,-3,-3,-3,9,-3,-4,-3,-3,-1,-1,-3,-1,-2,-3,-1,-1,-2,-2,-1,-3,-3,-2],[-1,1,0,0,-3,5,2,-2,0,-3,-2,1,0,-3,-1,0,-1,-2,-1,-2,0,3,-1],[-1,0,0,2,-4,2,5,-2,0,-3,-3,1,-2,-3,-1,0,-1,-3,-2,-2,1,4,-1],[0,-2,0,-1,-3,-2,-2,6,-2,-4,-4,-2,-3,-3,-2,0,-2,-2,-3,-3,-1,-2,-1],[-2,0,1,-1,-3,0,0,-2,8,-3,-3,-1,-2,-1,-2,-1,-2,-2,2,-3,0,0,-1],[-1,-3,-3,-3,-1,-3,-3,-4,-3,4,2,-3,1,0,-3,-2,-1,-3,-1,3,-3,-3,-1],[-1,-2,-3,-4,-1,-2,-3,-4,-3,2,4,-2,2,0,-3,-2,-1,-2,-1,1,-4,-3,-1],[-1,2,0,-1,-3,1,1,-2,-1,-3,-2,5,-1,-3,-1,0,-1,-3,-2,-2,0,1,-1],[-1,-1,-2,-3,-1,0,-2,-3,-2,1,2,-1,5,0,-2,-1,-1,-1,-1,1,-3,-1,-1],[-2,-3,-3,-3,-2,-3,-3,-3,-1,0,0,-3,0,6,-4,-2,-2,1,3,-1,-3,-3,-1],[-1,-2,-2,-1,-3,-1,-1,-2,-2,-3,-3,-1,-2,-4,7,-1,-1,-4,-3,-2,-2,-1,-2],[1,-1,1,0,-1,0,0,0,-1,-2,-2,0,-1,-2,-1,4,1,-3,-2,-2,0,0,0],[0,-1,0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1,1,5,-2,-2,0,-1,-1,0],[-3,-3,-4,-4,-2,-2,-3,-2,-2,-3,-2,-3,-1,1,-4,-3,-2,11,2,-3,-4,-3,-2],[-2,-2,-2,-3,-2,-1,-2,-3,2,-1,-1,-2,-1,3,-3,-2,-2,2,7,-1,-3,-2,-1],[0,-3,-3,-3,-1,-2,-2,-3,-3,3,1,-2,1,-1,-2,-2,0,-3,-1,4,-3,-2,-1],[-2,-1,3,4,-3,0,1,-1,0,-3,-4,0,-3,-3,-2,0,-1,-4,-3,-3,4,1,-1],[-1,0,0,1,-3,3,4,-2,0,-3,-3,1,-1,-3,-1,0,-1,-3,-2,-2,1,4,-1],[0,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,0,0,-2,-1,-1,-1,-1,-1]]),blosum62x:fc("ACDEFGHIKLMNPQRSTVWY",mc)};class gc{constructor(t,e,i=-10,r=-1,n="blosum62"){this.seq1=t,this.seq2=e,this.gapPenalty=i,this.gapExtensionPenalty=r,n&&(this.substMatrix=pc[n])}initMatrices(){this.n=this.seq1.length,this.m=this.seq2.length,this.score=void 0,this.ali="",this.S=[],this.V=[],this.H=[];for(let t=0;t<=this.n;++t){this.S[t]=[],this.V[t]=[],this.H[t]=[];for(let e=0;e<=this.m;++e)this.S[t][e]=0,this.V[t][e]=0,this.H[t][e]=0}for(let t=0;t<=this.n;++t)this.S[t][0]=this.gap(0),this.H[t][0]=-1/0;for(let t=0;t<=this.m;++t)this.S[0][t]=this.gap(0),this.V[0][t]=-1/0;this.S[0][0]=0}gap(t){return this.gapPenalty+t*this.gapExtensionPenalty}makeScoreFn(){const t=this.seq1,e=this.seq2,i=this.substMatrix;return i?function(r,n){const s=t[r],o=e[n];try{return i[s][o]}catch(t){return-4}}:(Dt.warn("Alignment: no subst matrix"),function(i,r){return t[i]===e[r]?5:-3})}calc(){t.Debug&&Dt.time("Alignment.calc"),this.initMatrices();const e=this.gap(0),i=this.makeScoreFn(),r=this.gapExtensionPenalty,n=this.V,s=this.H,o=this.S,a=this.n,c=this.m;let l,u,h,d,m;for(let t=1;t<=a;++t){u=o[t-1],l=n[t-1],h=n[t],d=s[t],m=o[t];for(let n=1;n<=c;++n)h[n]=Math.max(u[n]+e,l[n]+r),d[n]=Math.max(m[n-1]+e,d[n-1]+r),m[n]=Math.max(u[n-1]+i(t-1,n-1),h[n],d[n])}t.Debug&&Dt.timeEnd("Alignment.calc"),t.Debug&&Dt.log(this.S,this.V,this.H)}trace(){t.Debug&&Dt.time("Alignment.trace"),this.ali1="",this.ali2="";const e=this.makeScoreFn();let i,r=this.n,n=this.m;for(this.S[r][n]>=this.V[r][n]?(i="S",this.score=this.S[r][n]):this.V[r][n]>=this.H[r][n]?(i="V",this.score=this.V[r][n]):(i="H",this.score=this.H[r][n]),t.Debug&&Dt.log("Alignment: SCORE",this.score),t.Debug&&Dt.log("Alignment: S, V, H",this.S[r][n],this.V[r][n],this.H[r][n]);r>0&&n>0;)"S"===i?this.S[r][n]===this.S[r-1][n-1]+e(r-1,n-1)?(this.ali1=this.seq1[r-1]+this.ali1,this.ali2=this.seq2[n-1]+this.ali2,--r,--n,i="S"):this.S[r][n]===this.V[r][n]?i="V":this.S[r][n]===this.H[r][n]?i="H":(--r,--n):"V"===i?this.V[r][n]===this.V[r-1][n]+this.gapExtensionPenalty?(this.ali1=this.seq1[r-1]+this.ali1,this.ali2="-"+this.ali2,--r,i="V"):this.V[r][n]===this.S[r-1][n]+this.gap(0)?(this.ali1=this.seq1[r-1]+this.ali1,this.ali2="-"+this.ali2,--r,i="S"):--r:"H"===i?this.H[r][n]===this.H[r][n-1]+this.gapExtensionPenalty?(this.ali1="-"+this.ali1,this.ali2=this.seq2[n-1]+this.ali2,--n,i="H"):this.H[r][n]===this.S[r][n-1]+this.gap(0)?(this.ali1="-"+this.ali1,this.ali2=this.seq2[n-1]+this.ali2,--n,i="S"):--n:Dt.error("Alignment: no matrix");for(;r>0;)this.ali1=this.seq1[r-1]+this.ali1,this.ali2="-"+this.ali2,--r;for(;n>0;)this.ali1="-"+this.ali1,this.ali2=this.seq2[n-1]+this.ali2,--n;t.Debug&&Dt.timeEnd("Alignment.trace"),t.Debug&&Dt.log([this.ali1,this.ali2])}}function yc(t,e,i=!1,r="",n=""){let s,o,a,c,l;if(i){let i=t,u=e;r&&n&&(i=t.getView(new gt(r)),u=e.getView(new gt(n)));const h=i.getSequence(),d=u.getSequence(),m=new gc(h.join(""),d.join(""));let f,p;m.calc(),m.trace(),s=0,o=0,a=m.ali1.length;const g=[],y=[];for(let t=0;t<a;++t){const e=m.ali1[t],i=m.ali2[t];f=0,p=0,"-"===e?y[o]=!1:(y[o]=!0,f=1),"-"===i?g[s]=!1:(g[s]=!0,p=1),s+=f,o+=p}const b=[],_=[],x=i.getAtomProxy(),v=u.getAtomProxy();s=0,i.eachResidue((function(t){void 0!==t.traceAtomIndex&&t.traceAtomIndex===t.getAtomIndexByName("CA")&&(g[s]&&(x.index=t.getAtomIndexByName("CA"),b.push(x.x,x.y,x.z)),s+=1)})),s=0,u.eachResidue((function(t){void 0!==t.traceAtomIndex&&t.traceAtomIndex===t.getAtomIndexByName("CA")&&(y[s]&&(v.index=t.getAtomIndexByName("CA"),_.push(v.x,v.y,v.z)),s+=1)})),c=new Float32Array(b),l=new Float32Array(_)}else{c=t.getView(new gt(`${r} and .CA`)),l=e.getView(new gt(`${n} and .CA`))}const u=new nc(c,l).transform(t);return t.refreshPosition(),u}const bc=Object.assign({sele:"",defaultAssembly:""},Za);class _c extends Qa{constructor(t,e,i={}){super(t,e,Object.assign({name:e.name},i)),this.structure=e,this.trajList=[],this.signals=Object.assign(this.signals,{trajectoryAdded:new r.Signal,trajectoryRemoved:new r.Signal,defaultAssemblyChanged:new r.Signal}),this.initSelection(this.parameters.sele),this.pickBuffer=function(t){let e=0,i=0;const r=[];return{has:function(t){return-1!==r.indexOf(t)},get:function(t){return r[t]},push:function(n){r[e]=n,e=(t+e+1)%t,++i},get count(){return i},get data(){return r.slice(0,Math.min(i,t))},clear:function(){i=0,e=0,r.length=0}}}(4),this.pickDict=function(){const t={};return{has:function(e){return void 0!==t[JSON.stringify(e)]},add:function(e,i){t[JSON.stringify(e)]=i},del:function(e){delete t[JSON.stringify(e)]},get values(){return Object.keys(t).map((e=>t[e]))}}}(),this.spacefillRepresentation=this.addRepresentation("spacefill",{sele:"none",opacity:Bt.opacity,color:Bt.color,disablePicking:!0,radiusType:"data"},!0),this.distanceRepresentation=this.addRepresentation("distance",Bt,!0),this.angleRepresentation=this.addRepresentation("angle",Bt,!0),this.dihedralRepresentation=this.addRepresentation("dihedral",Bt,!0),this.measureRepresentations=new tc([this.spacefillRepresentation,this.distanceRepresentation,this.angleRepresentation,this.dihedralRepresentation]),this.setDefaultAssembly(this.parameters.defaultAssembly),this.structure.signals.refreshed.add((()=>{this.updateRepresentations({position:!0})}))}get defaultParameters(){return bc}get type(){return"structure"}initSelection(t){this.selection=new gt(t),this.structureView=new dc(this.structure,this.selection),this.selection.signals.stringChanged.add((()=>{this.structureView.setSelection(this.selection),this.rebuildRepresentations(),this.rebuildTrajectories()}))}setSelection(t){return this.parameters.sele=t,this.selection.setString(t),this}setDefaultAssembly(t){if(void 0===this.structure.biomolDict[t]&&(t=""),this.parameters.defaultAssembly!==t){const e={defaultAssembly:t};this.reprList.forEach((t=>t.setParameters(e))),this.measureRepresentations.setParameters(e),this.parameters.defaultAssembly=t,this.signals.defaultAssemblyChanged.dispatch(t)}return this}rebuildRepresentations(){this.reprList.forEach((t=>{t.build()})),this.measureRepresentations.build()}rebuildTrajectories(){this.trajList.forEach((t=>{t.trajectory.setStructure(this.structureView)}))}updateRepresentations(t){super.updateRepresentations(t),this.measureRepresentations.update(t)}updateRepresentationMatrices(){super.updateRepresentationMatrices(),this.measureRepresentations.setParameters({matrix:this.matrix})}addRepresentation(t,e={},i=!1){e.defaultAssembly=this.parameters.defaultAssembly;const r=this._addRepresentation(t,this.structureView,e,i);return i||r.signals.parametersChanged.add((()=>this.measureUpdate())),r}addTrajectory(t="",e={}){const i=function(t,e,i){let r;return r=t&&t instanceof rc?new cc(t,e,i):!t&&e.frames?new lc(t,e,i):t&&"function"==typeof t?new hc(t,e,i):new uc(t,e,i),r}(t,this.structureView,e),r=new ic(this.stage,i,e);return this.trajList.push(r),this.signals.trajectoryAdded.dispatch(r),r}removeTrajectory(t){const e=this.trajList.indexOf(t);-1!==e&&this.trajList.splice(e,1),t.dispose(),this.signals.trajectoryRemoved.dispatch(t)}dispose(){this.trajList.slice().forEach((t=>t.dispose())),this.trajList.length=0,this.structure.dispose(),this.measureRepresentations.dispose(),super.dispose()}autoView(t,e){"number"==typeof t&&(e=t,t=""),this.stage.animationControls.zoomMove(this.getCenter(t),this.getZoom(t),l(e,0))}getBoxUntransformed(t){let e;return e=t?this.structureView.getBoundingBox(new gt(t)):this.structureView.boundingBox,e}getCenterUntransformed(t){return t&&"string"==typeof t?this.structure.atomCenter(new gt(t)):this.structure.center}superpose(t,e,i,r){return yc(this.structureView,t.structureView,e,i,r),this.updateRepresentations({position:!0}),this}getMaxRepresentationRadius(t){let e=0;const i=this.structure.getAtomProxy(t);return this.eachRepresentation((t=>{if(t.getVisibility()){const r=t.repr;e=Math.max(r.getAtomRadius(i),e)}})),e}measurePick(t){const e=this.pickBuffer.count;if(this.lastPick===t.index&&e>=1){if(e>1){const t=this.pickBuffer.data,i=this.pickBuffer.data.sort();this.pickDict.has(i)?this.pickDict.del(i):this.pickDict.add(i,t),2===e?this.distanceRepresentation.setParameters({atomPair:this.pickDict.values.filter((t=>2===t.length))}):3===e?this.angleRepresentation.setParameters({atomTriple:this.pickDict.values.filter((t=>3===t.length))}):4===e&&this.dihedralRepresentation.setParameters({atomQuad:this.pickDict.values.filter((t=>4===t.length))})}this.pickBuffer.clear(),this.lastPick=void 0}else this.pickBuffer.has(t.index)||this.pickBuffer.push(t.index),this.lastPick=t.index;this.measureUpdate()}measureClear(){this.pickBuffer.clear(),this.lastPick=void 0,this.spacefillRepresentation.setSelection("none")}measureBuild(){const t=this.measureData();this.distanceRepresentation.setParameters({atomPair:t.distance}),this.angleRepresentation.setParameters({atomTriple:t.angle}),this.dihedralRepresentation.setParameters({atomQuad:t.dihedral})}measureUpdate(){const t=this.pickBuffer.data,e={};t.forEach((t=>{const i=Math.max(.1,this.getMaxRepresentationRadius(t));e[t]=i*(2.3-R(.1,2,i))})),this.spacefillRepresentation.setSelection(t.length?"@"+t.join(","):"none"),t.length&&this.spacefillRepresentation.setParameters({radiusData:e})}measureData(){const t=this.pickDict.values;return{distance:t.filter((t=>2===t.length)),angle:t.filter((t=>3===t.length)),dihedral:t.filter((t=>4===t.length))}}removeAllMeasurements(t){const e=this.pickDict,i=e.values,r=function(t){i.filter((e=>e.length===t)).forEach((t=>e.del(t.slice().sort())))};(!t||1&t)&&r(2),(!t||2&t)&&r(3),(!t||4&t)&&r(4),this.measureBuild()}removeMeasurement(t){this.pickDict.del(t.slice().sort()),this.measureBuild()}addMeasurement(t){if(t.length<2||t.length>4)return;const e=t.slice().sort();this.pickDict.has(e)||this.pickDict.add(e,t),this.measureBuild()}}Ut.add("structure",_c),Ut.add("structureview",_c);class xc extends Qa{constructor(t,e,i={}){super(t,e,Object.assign({name:e.name},i)),this.surface=e}get type(){return"surface"}addRepresentation(t,e={}){return this._addRepresentation(t,this.surface,e)}getBoxUntransformed(){return this.surface.boundingBox}getCenterUntransformed(){return this.surface.center}dispose(){this.surface.dispose(),super.dispose()}}Ut.add("surface",xc);class vc extends Qa{constructor(t,e,i={}){super(t,e,Object.assign({name:e.name},i)),this.volume=e}get type(){return"volume"}addRepresentation(t,e={}){return this._addRepresentation(t,this.volume,e)}getBoxUntransformed(){return this.volume.boundingBox}getCenterUntransformed(){return this.volume.center}dispose(){this.volume.dispose(),super.dispose()}}Ut.add("volume",vc);class wc extends Ja{addRepresentation(t,e){return this.forEach((i=>i.addRepresentation(t,e)))}autoView(t){return this.forEach((e=>e.autoView(t)))}}function Ac(t,e){return t instanceof RegExp?null!==e.name.match(t):e.name===t}const Sc=new e.Vector3,Cc={impostor:!0,quality:"medium",workerDefault:!0,sampleLevel:0,backgroundColor:"black",rotateSpeed:2,zoomSpeed:1.2,panSpeed:1,clipNear:0,clipFar:100,clipDist:10,clipMode:"scene",clipScale:"relative",fogNear:50,fogFar:100,cameraFov:40,cameraEyeSep:.3,cameraType:"perspective",lightColor:14540253,lightIntensity:1.2,ambientColor:14540253,ambientIntensity:.3,hoverTimeout:0,tooltip:!0,mousePreset:"default"};class Pc extends Qa{constructor(t,e,i={}){super(t,e,Object.assign({name:e.name},i)),this.shape=e}get type(){return"shape"}addRepresentation(t,e={}){return this._addRepresentation(t,this.shape,e)}getBoxUntransformed(){return this.shape.boundingBox}getCenterUntransformed(){return this.shape.center}dispose(){this.shape.dispose(),super.dispose()}}function Ic(t,e,i,r){var n,s=arguments.length,o=s<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,r);else for(var a=t.length-1;a>=0;a--)(n=t[a])&&(o=(s<3?n(o):s>3?n(e,i,o):n(e,i))||o);return s>3&&o&&Object.defineProperty(e,i,o),o}function kc(t,e,i,r){return new(i||(i=Promise))((function(n,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){t.done?n(t.value):function(t){return t instanceof i?t:new i((function(e){e(t)}))}(t.value).then(o,a)}c((r=r.apply(t,e||[])).next())}))}Ut.add("shape",Pc),"function"==typeof SuppressedError&&SuppressedError;class Mc extends U{constructor(t){super(t),t.scale||(this.parameters.scale="rainbow",this.parameters.reverse=l(t.reverse,!0)),this.scalePerModel={},t.structure.eachModel((t=>{this.parameters.domain=[t.atomOffset,t.atomEnd],this.scalePerModel[t.index]=this.getScale()}))}atomColor(t){return this.scalePerModel[t.modelIndex](t.index)}}Ic([V],Mc.prototype,"atomColor",null),$t.add("atomindex",Mc);class Tc extends U{constructor(t){if(super(t),t.scale||(this.parameters.scale="OrRd"),!t.domain){let e,i=1/0,r=-1/0;t.sele&&(e=new gt(t.sele)),t.structure.eachAtom((function(t){const e=t.bfactor;i=Math.min(i,e),r=Math.max(r,e)}),e),this.parameters.domain=[i,r]}this.bfactorScale=this.getScale()}atomColor(t){return this.bfactorScale(t.bfactor)}}Ic([V],Tc.prototype,"atomColor",null),$t.add("bfactor",Tc);class Dc extends U{constructor(t){super(t),this.chainidDictPerModel={},this.scalePerModel={},t.scale||(this.parameters.scale="Spectral"),t.structure.eachModel((t=>{let e=0;const i={};t.eachChain((function(t){void 0===i[t.chainid]&&(i[t.chainid]=e,e+=1)})),this.parameters.domain=[0,e-1],this.chainidDictPerModel[t.index]=i,this.scalePerModel[t.index]=this.getScale()}))}atomColor(t){const e=this.chainidDictPerModel[t.modelIndex];return this.scalePerModel[t.modelIndex](e[t.chainid])}}Ic([V],Dc.prototype,"atomColor",null),$t.add("chainid",Dc);class Bc extends U{constructor(t){super(t),this.scalePerModel={},t.scale||(this.parameters.scale="Spectral"),t.structure.eachModel((t=>{this.parameters.domain=[t.chainOffset,t.chainEnd],this.scalePerModel[t.index]=this.getScale()}))}atomColor(t){return this.scalePerModel[t.modelIndex](t.chainIndex)}}Ic([V],Bc.prototype,"atomColor",null),$t.add("chainindex",Bc);class Fc extends U{constructor(t){super(t),this.chainnameDictPerModel={},this.scalePerModel={},t.scale||(this.parameters.scale="Spectral"),t.structure.eachModel((t=>{let e=0;const i={};t.eachChain((function(t){void 0===i[t.chainname]&&(i[t.chainname]=e,e+=1)})),this.parameters.domain=[0,e-1],this.chainnameDictPerModel[t.index]=i,this.scalePerModel[t.index]=this.getScale()}))}atomColor(t){const e=this.chainnameDictPerModel[t.modelIndex];return this.scalePerModel[t.modelIndex](e[t.chainname])}}Ic([V],Fc.prototype,"atomColor",null),$t.add("chainname",Fc);class Ec extends U{constructor(t){super(t),this.rsrzDict={},this.rsccDict={},t.scale||(this.parameters.scale="RdYlBu"),this.rsrzScale=this.getScale({domain:[2,0]}),this.rsccScale=this.getScale({domain:[.678,1]});const e=t.structure.validation;e&&(this.rsrzDict=e.rsrzDict,this.rsccDict=e.rsccDict)}atomColor(t){let e=t.resno+"";t.inscode&&(e+="^"+t.inscode),t.chainname&&(e+=":"+t.chainname),e+="/"+t.modelIndex;const i=this.rsrzDict[e];if(void 0!==i)return this.rsrzScale(i);const r=this.rsccDict[e];return void 0!==r?this.rsccScale(r):9474192}}Ic([V],Ec.prototype,"atomColor",null),$t.add("densityfit",Ec);const Oc={ARG:{CD:.1,CZ:.5,NE:-.1},ASN:{CG:.55,OD1:-.55},ASP:{CB:-.16,CG:.36,OD1:-.6,OD2:-.6},CYS:{CB:.19,SG:-.19},GLN:{CD:.55,OE1:-.55},GLU:{CD:.36,CG:-.16,OE1:-.6,OE2:-.6},HIS:{CB:.1,CD2:.2,CE1:.45,CG:.15,ND1:.05,NE2:.05},LYS:{CE:.25,NZ:.75},MET:{CE:.06,CG:.06,SD:-.12},PTR:{C:.55,CA:.1,CZ:.25,N:-.35,O:-.55,O1P:-.85,O2P:-.85,O3P:-.85,OG1:-1.1,P:1.4},SEP:{C:.55,CA:.1,CB:.25,N:-.35,O:-.55,O1P:-.85,O2P:-.85,O3P:-.85,OG1:-1.1,P:1.4},SER:{CB:.25,OG:-.25},THR:{CB:.25,OG1:-.25},TPO:{C:.55,CA:.1,CB:.25,N:-.35,O:-.55,OG1:-1.1,O1P:-.85,O2P:-.85,O3P:-.85,P:1.4},TRP:{CD1:.06,CD2:.1,CE2:-.04,CE3:-.03,CG:-.03,NE1:-.06},TYR:{CZ:.25,OH:-.25},backbone:{C:.55,O:-.55,N:-.35,CA:.1}};class $c extends U{constructor(t){super(t),this.delta=new e.Vector3,this.hCharges=[],t.scale||(this.parameters.scale="rwb"),t.domain||(this.parameters.domain=[-50,50]),this.scale=this.getScale(),this.charges=new Float32Array(t.structure.atomCount);const i=[];t.structure.eachAtom((t=>{var r;if(this.charges[t.index]=(null!==(r=t).partialCharge?r.partialCharge:r.isProtein()&&(Oc[r.resname]&&Oc[r.resname][r.atomname]||Oc.backbone[r.atomname])||0)*t.occupancy,"N"===t.atomname){if(t.bondCount>=3)return;if(t.bondToElementCount(1))return;const r=function(t,i=new e.Vector3){let r=!1,n=!1,s=!1;return i.set(2*t.x,2*t.y,2*t.z),t.eachBondedAtom((function(t){if(!r)return"H"===t.atomname?(i.set(t.x,t.y,t.z),void(r=!0)):void(n||"CA"!==t.atomname?s||"C"!==t.atomname||(s=!0,i.sub(t)):(i.sub(t),n=!0))})),r?i:n&&s?(i.normalize(),i.multiplyScalar(1.04),i.add(t),i):void 0}(t);void 0!==r&&(i.push(r),this.hCharges.push(.25*t.occupancy))}}));const r=t.structure.getBoundingBox();r.expandByScalar(1.04),this.hStore=function(t){const e=t.length,i=new Float32Array(e),r=new Float32Array(e),n=new Float32Array(e);for(let e=0;e<t.length;e++){const s=t[e];i[e]=s.x,r[e]=s.y,n[e]=s.z}return{x:i,y:r,z:n,count:e}}(i),this.hHash=new xr(this.hStore,r),this.hash=new xr(t.structure.atomStore,r)}positionColor(t){const e=this.charges,i=this.hCharges;let r=0;return this.hash.eachWithin(t.x,t.y,t.z,12,((t,i)=>{const n=e[t];0!==n&&(r+=n/i)})),this.hHash.eachWithin(t.x,t.y,t.z,12,((t,e)=>{const n=i[t];0!==n&&(r+=n/e)})),this.scale(332*r)}}Ic([V],$c.prototype,"positionColor",null),$t.add("electrostatic",$c);const Rc={H:16777215,HE:14286847,LI:13402367,BE:12779264,B:16758197,C:9474192,N:3166456,O:16715021,F:9494608,NE:11789301,NA:11230450,MG:9109248,AL:12560038,SI:1578e4,P:16744448,S:16777008,CL:2093087,AR:8442339,K:9388244,CA:4062976,SC:15132390,TI:12567239,V:10921643,CR:9083335,MN:10255047,FE:14706227,CO:15765664,NI:5296208,CU:13140019,ZN:8224944,GA:12750735,GE:6721423,AS:12419299,SE:16752896,BR:10889513,KR:6076625,RB:7351984,SR:65280,Y:9764863,ZR:9756896,NB:7586505,MO:5551541,TC:3907230,RU:2396047,RH:687500,PD:27013,AG:12632256,CD:16767375,IN:10909043,SN:6717568,SB:10380213,TE:13924864,I:9699476,XE:9699476,CS:5707663,BA:51456,LA:7394559,CE:16777159,PR:14286791,ND:13107143,PM:10747847,SM:9437127,EU:6422471,GD:4587463,TB:3211207,DY:2097095,HO:65436,ER:58997,TM:54354,YB:48952,LU:43812,HF:5096191,TA:5089023,W:2200790,RE:2522539,OS:2516630,IR:1528967,PT:13684960,AU:16765219,HG:12105936,TL:10900557,PB:5724513,BI:10375093,PO:11230208,AT:7688005,RN:4358806,FR:4325478,RA:32e3,AC:7384058,TH:47871,PA:41471,U:36863,NP:33023,PU:27647,AM:5528818,CM:7888099,BK:9064419,CF:10565332,ES:11739092,FM:11739066,MD:11734438,NO:12389767,LR:13041766,RF:13369433,DB:13697103,SG:14221381,BH:14680120,HS:15073326,MT:15400998,DS:16777215,RG:16777215,CN:16777215,UUT:16777215,FL:16777215,UUP:16777215,LV:16777215,UUH:16777215,D:16777152,T:16777120};class Lc extends U{constructor(t){t.value=l(t.value,Rc.C),super(t)}atomColor(t){const e=t.element;return"C"===e?this.parameters.value:Rc[e]||16777215}}Ic([V],Lc.prototype,"atomColor",null),$t.add("element",Lc);class Nc extends U{constructor(t){super(t),t.scale||(this.parameters.scale="Spectral"),t.domain||(this.parameters.domain=[0,t.structure.entityList.length-1]),this.entityindexScale=this.getScale()}atomColor(t){return this.entityindexScale(t.entityIndex)}}Ic([V],Nc.prototype,"atomColor",null),$t.add("entityindex",Nc);class zc extends U{atomColor(t){const e=t.entity;switch(e?e.entityType:void 0){case 1:return 8374655;case 2:return 16629894;case 3:return 12496596;case 4:return 3697840;default:return 16777113}}}Ic([V],zc.prototype,"atomColor",null),$t.add("entitytype",zc);class Vc extends U{constructor(t){super(t),this.geoAtomDict={},this.geoDict={};const e=t.structure.validation;e&&(this.geoAtomDict=e.geoAtomDict,this.geoDict=e.geoDict)}atomColor(t){let e,i=t.resno+"";t.inscode&&(i+="^"+t.inscode),t.chainname&&(i+=":"+t.chainname),i+="/"+t.modelIndex;const r=this.geoAtomDict[i];if(void 0!==r){const i=r[t.atomname]||0;n=i,e=16843009*((n=(858993459&(n-=n>>1&1431655765))+(n>>2&858993459))+(n>>4)&252645135)>>24}else e=this.geoDict[i]||0;var n;return 0===e?2188972:1===e?16703627:2===e?16018755:e>=3?10813478:9474192}}Ic([V],Vc.prototype,"atomColor",null),$t.add("geoquality",Vc);class Uc extends U{constructor(t){super(t),this.resHF={},t.scale||(this.parameters.scale="RdYlGn");for(const t in jr)this.resHF[t]=jr[t][0];if(this.defaultResidueHydrophobicity=Gr[0],!t.domain){let t=1/0,e=-1/0;for(const i in this.resHF){const r=this.resHF[i];t=Math.min(t,r),e=Math.max(e,r)}this.parameters.domain=[t,0,e]}this.hfScale=this.getScale()}atomColor(t){return this.hfScale(this.resHF[t.resname]||this.defaultResidueHydrophobicity)}}Ic([V],Uc.prototype,"atomColor",null),$t.add("hydrophobicity",Uc);class jc extends U{constructor(t){super(t),t.scale||(this.parameters.scale="rainbow"),t.domain||(this.parameters.domain=[0,t.structure.modelStore.count]),this.modelindexScale=this.getScale()}atomColor(t){return this.modelindexScale(t.modelIndex)}}Ic([V],jc.prototype,"atomColor",null),$t.add("modelindex",jc);class Gc extends U{atomColor(t){switch(t.residueType.moleculeType){case 1:return 3697840;case 2:return 15729279;case 3:return 12496596;case 4:return 16629894;case 5:return 12540695;case 6:return 8374655;default:return 16777113}}}Ic([V],Gc.prototype,"atomColor",null),$t.add("moleculetype",Gc);class Hc extends U{constructor(t){super(t),t.scale||(this.parameters.scale="PuBu"),t.domain||(this.parameters.domain=[0,1]),this.occupancyScale=this.getScale()}atomColor(t){return this.occupancyScale(t.occupancy)}}Ic([V],Hc.prototype,"atomColor",null),$t.add("occupancy",Hc);class qc extends U{constructor(t){super(t),t.scale||(this.parameters.scale="rwb"),t.domain||(this.parameters.domain=[-1,1]),this.partialchargeScale=this.getScale()}atomColor(t){return this.partialchargeScale(t.partialCharge||0)}}function Wc(){return 16777215*Math.random()}Ic([V],qc.prototype,"atomColor",null),$t.add("partialcharge",qc);class Xc extends U{atomColor(){return Wc()}volumeColor(){return Wc()}positionColor(){return Wc()}}Ic([V],Xc.prototype,"atomColor",null),Ic([V],Xc.prototype,"volumeColor",null),Ic([V],Xc.prototype,"positionColor",null),$t.add("random",Xc);class Yc extends U{constructor(t){super(t),this.rciDict={},t.scale||(this.parameters.scale="RdYlBu"),this.rciScale=this.getScale({domain:[.6,0]});const e=t.structure.validation;e&&(this.rciDict=e.rciDict)}atomColor(t){let e=`[${t.resname}]${t.resno}`;t.chainname&&(e+=":"+t.chainname);const i=this.rciDict[e];return void 0!==i?this.rciScale(i):9474192}}Ic([V],Yc.prototype,"atomColor",null),$t.add("randomcoilindex",Yc);class Kc extends U{constructor(t){super(t),this.scalePerChain={},t.scale||(this.parameters.scale="rainbow",this.parameters.reverse=l(t.reverse,!0)),t.structure.eachChain((t=>{this.parameters.domain=[t.residueOffset,t.residueEnd],this.scalePerChain[t.index]=this.getScale()}))}atomColor(t){return this.scalePerChain[t.chainIndex](t.residueIndex)}}Ic([V],Kc.prototype,"atomColor",null),$t.add("residueindex",Kc);const Zc={ALA:9240460,ARG:124,ASN:16743536,ASP:10485826,CYS:16777072,GLN:16731212,GLU:6684672,GLY:16777215,HIS:7368959,ILE:19456,LEU:4546117,LYS:4671416,MET:12099650,PHE:5459026,PRO:5395026,SER:16740418,THR:12078080,TRP:5195264,TYR:9203788,VAL:16747775,ASX:16711935,GLX:16711935,ASH:16711935,GLH:16711935,A:14423100,G:3329330,I:10145074,X:8190976,C:16766720,T:4286945,U:4251856,D:35723,DA:14423100,DG:3329330,DI:10145074,DX:8190976,DC:16766720,DT:4286945,DU:4251856,DD:35723};class Qc extends U{atomColor(t){return Zc[t.resname]||16711935}}Ic([V],Qc.prototype,"atomColor",null),$t.add("resname",Qc);const Jc=16711808,tl=10485888,el=6291584,il=16762880,rl=6324479,nl=16777215,sl=11403518,ol=16580962,al=10921722;class cl extends U{constructor(t){super(t),this.residueProxy=t.structure.getResidueProxy()}atomColor(t){const e=t.sstruc,i=this.residueProxy;return"h"===e?Jc:"g"===e?tl:"i"===e?el:"e"===e||"b"===e?il:"t"===e?rl:(i.index=t.residueIndex,i.isDna()?sl:i.isRna()?ol:i.isSaccharide()?al:i.isProtein()||"s"===e||"l"===e?nl:8421504)}}Ic([V],cl.prototype,"atomColor",null),$t.add("sstruc",cl);class ll extends U{constructor(t){var e,i;super(t),t.scale||(this.parameters.scale="rwb"),this.atomData=null===(e=this.parameters.data)||void 0===e?void 0:e.atomData,this.bondData=null===(i=this.parameters.data)||void 0===i?void 0:i.bondData,this.scale=this.getScale(this.parameters)}atomColor(t){var e;const i=null===(e=this.atomData)||void 0===e?void 0:e[t.index];return void 0!==i?this.scale(i):this.parameters.value}bondColor(t,e){var i;const r=null===(i=this.bondData)||void 0===i?void 0:i[t.index];return void 0!==r?this.scale(r):this.atomProxy?(this.atomProxy.index=e?t.atomIndex1:t.atomIndex2,this.atomColor(this.atomProxy)):this.parameters.value}}Ic([V],ll.prototype,"atomColor",null),Ic([V],ll.prototype,"bondColor",null),$t.add("structuredata",ll);class ul extends U{atomColor(){return this.parameters.value}bondColor(){return this.parameters.value}valueColor(){return this.parameters.value}volumeColor(){return this.parameters.value}}Ic([V],ul.prototype,"atomColor",null),Ic([V],ul.prototype,"bondColor",null),Ic([V],ul.prototype,"valueColor",null),Ic([V],ul.prototype,"volumeColor",null),$t.add("uniform",ul);class hl extends U{constructor(t){super(t),this.valueScale=this.getScale()}volumeColor(t){return this.valueScale(this.parameters.volume.data[t])}}Ic([V],hl.prototype,"volumeColor",null),$t.add("value",hl);class dl extends U{constructor(t){super(t),this.vec=new e.Vector3,this.valueScale=this.getScale()}positionColor(t){const e=this.parameters.volume;if(!e||!e.inverseMatrix)return this.parameters.value;const i=this.vec,r=e.data,n=e.nx,s=e.ny,o=n*s;i.copy(t),i.applyMatrix4(e.inverseMatrix);const a=Math.floor(i.x),c=Math.floor(i.y),l=Math.floor(i.z),u=(l*s+c)*n+a,h=u+1,d=u+n,m=u+o,f=d+1,p=m+1,g=d+o,y=g+1,b=r[u],_=r[h],x=r[d],v=r[m],w=r[f],A=r[p],S=r[g],C=r[y],P=i.x-a,I=i.y-c,k=i.z-l,M=O(b,_,P),T=O(v,A,P),D=O(x,w,P),B=O(S,C,P),F=O(M,D,I),E=O(T,B,I),$=O(F,E,k);return this.valueScale($)}}Ic([V],dl.prototype,"positionColor",null),$t.add("volume",dl);class ml extends Mi{constructor(t,e,i){const r=i||{};if(super(t,e,r),this.type="structure",this.parameters=Object.assign({radiusType:{type:"select",options:ro.types},radiusData:{type:"hidden"},radiusSize:{type:"number",precision:3,max:10,min:.001},radiusScale:{type:"number",precision:3,max:10,min:.001},assembly:null,defaultAssembly:{type:"hidden"}},this.parameters),this.selection=new gt(r.sele),this.dataList=[],this.structure=t,this.structureView=this.structure.getView(this.selection),t.biomolDict){const e={default:"default","":t.unitcell?"AU":"FULL"};Object.keys(t.biomolDict).forEach((function(t){e[t]=t})),this.parameters.assembly={type:"select",options:e,rebuild:!0}}else this.parameters.assembly=null}get defaultScale(){return{vdw:1,covalent:1,bfactor:.01,sstruc:1}}init(t){const e=t||{};e.colorScheme=l(e.colorScheme,"element"),this.setRadius(e.radius,e),this.radiusType=l(e.radiusType,"vdw"),this.radiusData=l(e.radiusData,{}),this.radiusSize=l(e.radiusSize,1),this.radiusScale=l(e.radiusScale,1),this.assembly=l(e.assembly,"default"),this.defaultAssembly=l(e.defaultAssembly,""),"auto"===e.quality&&(e.quality=this.getQuality()),super.init(e),this.selection.signals.stringChanged.add((()=>{this.build()})),this.build()}setRadius(t,e){const i=Object.keys(io);return"string"==typeof t&&i.includes(t.toLowerCase())?e.radiusType=t:void 0!==t&&(e.radiusType="size",e.radiusSize=t),this}getAssembly(){const t="default"===this.assembly?this.defaultAssembly:this.assembly;return this.structure.biomolDict[t]}getQuality(){let t;const e=this.structureView,i=this.getAssembly();t=i?i.getAtomCount(e):e.atomCount,Pt&&(t*=4);return e.atomStore.count/e.residueStore.count<2&&(t*=10),t<15e3?"high":t<8e4?"medium":"low"}create(){if(0===this.structureView.atomCount)return;if(!this.structureView.hasCoords())return void(this.needsBuild=!0);this.needsBuild=!1;const t=this.getAssembly();if(t)t.partList.forEach(((t,e)=>{const i=t.getView(this.structureView);if(0===i.atomCount)return;const r=this.createData(i,e);r&&(r.sview=i,r.instanceList=t.getInstanceList(),this.dataList.push(r))}));else{const t=this.createData(this.structureView,0);t&&(t.sview=this.structureView,this.dataList.push(t))}}update(t){!this.lazy||this.visible?this.needsBuild?this.build():this.dataList.forEach((e=>{e.bufferList.length>0&&this.updateData(t,e)}),this):Object.assign(this.lazyProps.what,t)}updateData(t,e){this.build()}getColorParams(){return Object.assign(Object.assign({},super.getColorParams()),{structure:this.structure})}getRadiusParams(t){return{type:this.radiusType,scale:this.radiusScale,size:this.radiusSize,data:this.radiusData}}getAtomParams(t,e){return Object.assign({what:t,colorParams:this.getColorParams(),radiusParams:this.getRadiusParams()},e)}getBondParams(t,e){return Object.assign({what:t,colorParams:this.getColorParams(),radiusParams:this.getRadiusParams()},e)}getAtomRadius(t){if(this.structureView.atomSet.isSet(t.index)){return new ro(this.getRadiusParams()).atomRadius(t)}return 0}setSelection(t,e){return this.selection.setString(t,e),this}setParameters(t,e={},i=!1){const r=t||{};return this.setRadius(r.radius,r),void 0===r.radiusType&&void 0===r.radiusData&&void 0===r.radiusSize&&void 0===r.radiusScale||(e.radius=!0,Mt&&!this.disableImpostor||(i=!0)),void 0!==r.defaultAssembly&&r.defaultAssembly!==this.defaultAssembly&&("default"===this.assembly&&void 0===r.assembly||"default"===r.assembly)&&(i=!0),super.setParameters(r,e,i),this}getParameters(){return Object.assign(super.getParameters(),{sele:this.selection?this.selection.string:void 0,defaultAssembly:this.defaultAssembly})}attach(t){const e=this.viewer,i=this.bufferList;this.dataList.forEach((function(t){t.bufferList.forEach((function(r){i.push(r),e.add(r,t.instanceList)}))})),this.setVisibility(this.visible),t()}clear(){this.dataList.length=0,super.clear()}dispose(){this.structureView.dispose(),super.dispose()}}class fl extends ml{constructor(t,e,i){super(t,e,i),this.n=0,this.parameters=Object.assign({labelVisible:{type:"boolean"},labelSize:{type:"number",precision:3,max:10,min:.001},labelColor:{type:"color"},labelFontFamily:{type:"select",options:{"sans-serif":"sans-serif",monospace:"monospace",serif:"serif"},buffer:"fontFamily"},labelFontStyle:{type:"select",options:{normal:"normal",italic:"italic"},buffer:"fontStyle"},labelFontWeight:{type:"select",options:{normal:"normal",bold:"bold"},buffer:"fontWeight"},labelsdf:{type:"boolean",buffer:"sdf"},labelXOffset:{type:"number",precision:1,max:20,min:-20,buffer:"xOffset"},labelYOffset:{type:"number",precision:1,max:20,min:-20,buffer:"yOffset"},labelZOffset:{type:"number",precision:1,max:20,min:-20,buffer:"zOffset"},labelAttachment:{type:"select",options:{"bottom-left":"bottom-left","bottom-center":"bottom-center","bottom-right":"bottom-right","middle-left":"middle-left","middle-center":"middle-center","middle-right":"middle-right","top-left":"top-left","top-center":"top-center","top-right":"top-right"},rebuild:!0},labelBorder:{type:"boolean",buffer:"showBorder"},labelBorderColor:{type:"color",buffer:"borderColor"},labelBorderWidth:{type:"number",precision:2,max:.3,min:0,buffer:"borderWidth"},labelBackground:{type:"boolean",rebuild:!0},labelBackgroundColor:{type:"color",buffer:"backgroundColor"},labelBackgroundMargin:{type:"number",precision:2,max:2,min:0,rebuild:!0},labelBackgroundOpacity:{type:"range",step:.01,max:1,min:0,buffer:"backgroundOpacity"},labelFixedSize:{type:"boolean",buffer:"fixedSize"},lineOpacity:{type:"range",min:0,max:1,step:.01},linewidth:{type:"integer",max:50,min:1,buffer:!0}},this.parameters,{flatShaded:null})}init(t){const e=t||{};this.labelVisible=l(e.labelVisible,!0),this.labelSize=l(e.labelSize,2),this.labelColor=l(e.labelColor,16777215),this.labelFontFamily=l(e.labelFontFamily,"sans-serif"),this.labelFontStyle=l(e.labelFontstyle,"normal"),this.labelFontWeight=l(e.labelFontWeight,"bold"),this.labelsdf=l(e.labelsdf,"Chrome"===St),this.labelXOffset=l(e.labelXOffset,0),this.labelYOffset=l(e.labelYOffset,0),this.labelZOffset=l(e.labelZOffset,.5),this.labelAttachment=l(e.labelAttachment,"bottom-left"),this.labelBorder=l(e.labelBorder,!1),this.labelBorderColor=l(e.labelBorderColor,"lightgrey"),this.labelBorderWidth=l(e.labelBorderWidth,.15),this.labelBackground=l(e.labelBackground,!1),this.labelBackgroundColor=l(e.labelBackgroundColor,"lightgrey"),this.labelBackgroundMargin=l(e.labelBackgroundMargin,.5),this.labelBackgroundOpacity=l(e.labelBackgroundOpacity,1),this.labelFixedSize=l(e.labelFixedSize,!1),this.lineOpacity=l(e.lineOpacity,1),this.linewidth=l(e.linewidth,2),super.init(e)}update(t){t.position?this.build():super.update(t)}updateData(t,i){const r={};if(t&&!t.labelSize||Object.assign(r,{size:ge(this.n,this.labelSize)}),!t||t.labelColor){const t=new e.Color(this.labelColor);Object.assign(r,{color:ye(this.n,t.r,t.g,t.b)})}this.textBuffer.setAttributes(r)}setParameters(t,e={},i=!1){return t&&t.labelSize&&(e.labelSize=!0),t&&(t.labelColor||0===t.labelColor)&&(e.labelColor=!0,i=!0),super.setParameters(t,e,i),t&&void 0!==t.opacity&&this.textBuffer.setParameters({opacity:1}),t&&void 0!==t.labelVisible&&this.setVisibility(this.visible),this}setVisibility(t,e){return super.setVisibility(t,!0),this.textBuffer&&this.textBuffer.setVisibility(this.labelVisible&&this.visible),e||this.viewer.requestRender(),this}getLabelBufferParams(t={}){return super.getBufferParams(Object.assign({fontFamily:this.labelFontFamily,fontStyle:this.labelFontStyle,fontWeight:this.labelFontWeight,sdf:this.labelsdf,xOffset:this.labelXOffset,yOffset:this.labelYOffset,zOffset:this.labelZOffset,attachment:this.labelAttachment,showBorder:this.labelBorder,borderColor:this.labelBorderColor,borderWidth:this.labelBorderWidth,showBackground:this.labelBackground,backgroundColor:this.labelBackgroundColor,backgroundMargin:this.labelBackgroundMargin,backgroundOpacity:this.labelBackgroundOpacity,fixedSize:this.labelFixedSize,disablePicking:!0,visible:this.labelVisible},t,{opacity:1}))}getAtomRadius(){return 0}}function pl(t,e){const i=t.getAtomProxy(),r=new gt,n=e.length;if(0===n)return new Float32Array(0);const s=e[0].length,o=t.getAtomSet(),a=new Float32Array(n*s*3);let c=0;return e.forEach((function(e){let n=!1;for(let l=0;l<s;l++){const s=e[l];if("number"==typeof s&&Number.isInteger(s)){if(!o.get(s)){n=!0;break}i.index=s}else{r.setString(s);const e=t.getAtomIndices(r);if(!e.length){n=!0;break}i.index=e[0]}let u=c+3*l;a[u++]=i.x,a[u++]=i.y,a[u++]=i.z}n||(c+=3*s)})),a.subarray(0,c)}function gl(t,e,i,r,n){const s=Math.cos(n),o=Math.sin(n);t[0]=e[0]+i[0]*s+r[0]*o,t[1]=e[1]+i[1]*s+r[1]*o,t[2]=e[2]+i[2]*s+r[2]*o}function yl(t,e,i,r,n,s,o){for(let a=0;a<e;a++){for(let n=0;n<i;n++)r[n]=t[n*e+a];bl(r,n,s,o,i);for(let r=0;r<i;r++)t[r*e+a]=n[r]}for(let a=0;a<i;a++){for(let i=0;i<e;i++)r[i]=t[a*e+i];bl(r,n,s,o,e);for(let i=0;i<e;i++)t[a*e+i]=Math.sqrt(n[i])}}function bl(t,e,i,r,n){i[0]=0,r[0]=Number.MIN_SAFE_INTEGER,r[1]=Number.MAX_SAFE_INTEGER;for(let e=1,s=0;e<n;e++){let n=(t[e]+e*e-(t[i[s]]+i[s]*i[s]))/(2*e-2*i[s]);for(;n<=r[s];)s--,n=(t[e]+e*e-(t[i[s]]+i[s]*i[s]))/(2*e-2*i[s]);s++,i[s]=e,r[s]=n,r[s+1]=Number.MAX_SAFE_INTEGER}for(let s=0,o=0;s<n;s++){for(;r[o+1]<s;)o++;e[s]=(s-i[o])*(s-i[o])+t[i[o]]}}zt.add("shader/SDFFont.vert","uniform float clipNear;\nuniform float clipRadius;\nuniform vec3 clipCenter;\nuniform float xOffset;\nuniform float yOffset;\nuniform float zOffset;\nuniform bool ortho;\nuniform float canvasHeight;\nuniform float pixelRatio;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )\nvarying vec3 vViewPosition;\n#endif\nvarying vec2 texCoord;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#if defined( PICKING )\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\n#include color_pars_vertex\n#endif\nattribute vec2 mapping;\nattribute vec2 inputTexCoord;\nattribute float inputSize;\n#include matrix_scale\n#include common\nvoid main(void){\n#if defined( PICKING )\nvPickingColor = unpackColor( primitiveId );\n#else\n#include color_vertex\n#endif\ntexCoord = inputTexCoord;\nfloat scale = matrixScale( modelViewMatrix );\nfloat _xOffset = xOffset * scale;\nfloat _yOffset = yOffset * scale;\nfloat _zOffset = zOffset * scale;\nif( texCoord.x == 10.0 ){\n_zOffset -= 0.001;\n}\nvec4 cameraPos = modelViewMatrix * vec4( position, 1.0 );\n#ifdef FIXED_SIZE\nif ( ortho ) {\nscale /= pixelRatio * (( canvasHeight / 2.0 ) / -cameraPosition.z) * 0.1;\n} else {\nscale /= pixelRatio * (( canvasHeight / 2.0 ) / -cameraPos.z) * 0.1;\n}\n#endif\nvec4 cameraCornerPos = vec4( cameraPos.xyz, 1.0 );\ncameraCornerPos.xy += mapping * inputSize * 0.01 * scale;\ncameraCornerPos.x += _xOffset;\ncameraCornerPos.y += _yOffset;\nif( ortho ){\ncameraCornerPos.xyz += normalize( -cameraPosition ) * _zOffset;\n} else {\ncameraCornerPos.xyz += normalize( -cameraCornerPos.xyz ) * _zOffset;\n}\ngl_Position = projectionMatrix * cameraCornerPos;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || ( !defined( PICKING ) && !defined( NOLIGHT ) )\nvViewPosition = -cameraCornerPos.xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n#include radiusclip_vertex\n}"),zt.add("shader/SDFFont.frag","uniform sampler2D fontTexture;\nuniform float opacity;\nuniform bool showBorder;\nuniform vec3 borderColor;\nuniform float borderWidth;\nuniform vec3 backgroundColor;\nuniform float backgroundOpacity;\nuniform float clipNear;\nuniform float clipRadius;\nvarying vec3 vViewPosition;\nvarying vec2 texCoord;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#if defined( PICKING )\nuniform float objectId;\nvarying vec3 vPickingColor;\nconst vec3 vColor = vec3( 0.0 );\n#else\n#include common\n#include color_pars_fragment\n#include fog_pars_fragment\n#endif\nconst float gamma = 2.2 * 1.4142 / 128.0;\nconst float padding = 0.75;\nvoid main(){\n#include nearclip_fragment\n#include radiusclip_fragment\nif( texCoord.x > 1.0 ){\ngl_FragColor = vec4( backgroundColor, backgroundOpacity );\n}else{\nfloat sdf = texture2D( fontTexture, texCoord ).a;\nif( showBorder ) sdf += borderWidth;\nfloat a = smoothstep(padding - gamma, padding + gamma, sdf);\nif( a < 0.2 ) discard;\na *= opacity;\nvec3 outgoingLight = vColor;\nif( showBorder && sdf < ( padding + borderWidth ) ){\noutgoingLight = borderColor;\n}\ngl_FragColor = vec4( outgoingLight, a );\n}\n#if defined( PICKING )\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const _l={};const xl={font:"sans-serif",size:36,style:"normal",variant:"normal",weight:"normal",outline:3,width:1024,height:1024};class vl{constructor(t={}){this.gamma=1,this.mapped={},this.scratchW=0,this.scratchH=0,this.currentX=0,this.currentY=0,this.cutoff=.25,this.parameters=u(t,xl);const i=this.parameters;this.radius=i.size/8,this.padding=i.size/3;const r=this.lineHeight=i.size+2*i.outline+Math.round(i.size/4),n=this.maxWidth=i.width/4,s=this.canvas=document.createElement("canvas");s.width=n,s.height=r;const o=this.context=this.canvas.getContext("2d",{willReadFrequently:!0});o.font=`${i.style} ${i.variant} ${i.weight} ${i.size}px ${i.font}`,o.fillStyle="black",o.textAlign="left",o.textBaseline="bottom",o.lineJoin="round",this.gridOuter=new Float64Array(r*n),this.gridInner=new Float64Array(r*n),this.f=new Float64Array(Math.max(r,n)),this.d=new Float64Array(Math.max(r,n)),this.z=new Float64Array(Math.max(r,n)+1),this.v=new Int16Array(Math.max(r,n)),this.data=new Uint8Array(i.width*i.height*4),this.canvas2=document.createElement("canvas"),this.canvas2.width=i.width,this.canvas2.height=i.height,this.context2=this.canvas2.getContext("2d"),this.placeholder=this.map(String.fromCharCode(65533));for(let t=32;t<=126;++t)this.map(String.fromCharCode(t));this.map(String.fromCharCode(176)),this.map(String.fromCharCode(8491)),this.texture=new e.CanvasTexture(this.canvas2),this.texture.flipY=!1,this.texture.needsUpdate=!0}map(t){const e=this.parameters;return void 0===this.mapped[t]&&(this.draw(t),this.currentX+this.scratchW>e.width&&(this.currentX=0,this.currentY+=this.scratchH),this.currentY+this.scratchH>e.height&&console.warn("canvas to small"),this.mapped[t]={x:this.currentX,y:this.currentY,w:this.scratchW,h:this.scratchH},this.context2.drawImage(this.canvas,0,0,this.scratchW,this.scratchH,this.currentX,this.currentY,this.scratchW,this.scratchH),this.currentX+=this.scratchW),this.mapped[t]}get(t){return this.mapped[t]||this.placeholder}draw(t){const e=this.parameters,i=this.lineHeight,r=e.outline,n=this.context,s=this.maxWidth,o=r,a=i-e.outline,c=n.measureText(t),l=Math.min(s,Math.ceil(c.width+2*o+1)),u=l*i;n.clearRect(0,0,l,i),n.fillText(t,o,a);const h=n.getImageData(0,0,l,i),d=h.data;for(let t=0;t<u;t++){const e=h.data[4*t+3]/255;this.gridOuter[t]=1===e?0:0===e?Number.MAX_SAFE_INTEGER:Math.pow(Math.max(0,.5-e),2),this.gridInner[t]=1===e?Number.MAX_SAFE_INTEGER:0===e?0:Math.pow(Math.max(0,e-.5),2)}yl(this.gridOuter,l,i,this.f,this.d,this.v,this.z),yl(this.gridInner,l,i,this.f,this.d,this.v,this.z);for(let t=0;t<u;t++){const e=this.gridOuter[t]-this.gridInner[t];d[4*t+3]=Math.max(0,Math.min(255,Math.round(255-255*(e/this.radius+this.cutoff))))}n.putImageData(h,0,0),this.scratchW=l,this.scratchH=i}}const wl=Object.assign({fontFamily:"sans-serif",fontStyle:"normal",fontWeight:"bold",fontSize:36,xOffset:0,yOffset:0,zOffset:.5,attachment:"bottom-left",showBorder:!1,borderColor:"lightgrey",borderWidth:.15,showBackground:!1,backgroundColor:"lightgrey",backgroundMargin:.5,backgroundOpacity:1,forceTransparent:!0,fixedSize:!1},Ms),Al=Object.assign({fontFamily:{uniform:!0},fontStyle:{uniform:!0},fontWeight:{uniform:!0},fontSize:{uniform:!0},xOffset:{uniform:!0},yOffset:{uniform:!0},zOffset:{uniform:!0},showBorder:{uniform:!0},borderColor:{uniform:!0},borderWidth:{uniform:!0},backgroundColor:{uniform:!0},backgroundOpacity:{uniform:!0},fixedSize:{updateShader:!0}},Ts);function Sl(t,e){const i=t.position.length/3;let r=0;for(let e=0;e<i;++e)r+=t.text[e].length;return e.showBackground&&(r+=i),r}class Cl extends Ma{constructor(t,i={}){super({position:new Float32Array(3*Sl(t,i)),color:new Float32Array(3*Sl(t,i)),picking:new Hn},i),this.parameterTypes=Al,this.alwaysTransparent=!0,this.hasWireframe=!1,this.isText=!0,this.vertexShader="SDFFont.vert",this.fragmentShader="SDFFont.frag",this.text=t.text,this.positionCount=t.position.length/3,this.addUniforms({fontTexture:{value:null},xOffset:{value:this.parameters.xOffset},yOffset:{value:this.parameters.yOffset},zOffset:{value:this.parameters.zOffset},ortho:{value:!1},showBorder:{value:this.parameters.showBorder},borderColor:{value:new e.Color(this.parameters.borderColor)},borderWidth:{value:this.parameters.borderWidth},backgroundColor:{value:new e.Color(this.parameters.backgroundColor)},backgroundOpacity:{value:this.parameters.backgroundOpacity},canvasHeight:{value:1},pixelRatio:{value:1}}),this.addAttributes({inputTexCoord:{type:"v2",value:null},inputSize:{type:"f",value:null}}),this.setAttributes(t),this.makeTexture(),this.makeMapping()}get defaultParameters(){return wl}makeMaterial(){super.makeMaterial();const t=this.texture,e=this.material;e.transparent=!0,e.extensions.derivatives=!0,e.lights=!1,e.uniforms.fontTexture.value=t,e.needsUpdate=!0;const i=this.wireframeMaterial;i.transparent=!0,i.extensions.derivatives=!0,i.lights=!1,i.uniforms.fontTexture.value=t,i.needsUpdate=!0;const r=this.pickingMaterial;r.extensions.derivatives=!0,r.lights=!1,r.uniforms.fontTexture.value=t,r.needsUpdate=!0}setAttributes(t={}){let e,i,r,n,s,o;const a=this.text,c=this.geometry.attributes;t.position&&(e=t.position,n=c.position.array,c.position.needsUpdate=!0),t.size&&(i=t.size,s=c.inputSize.array,c.inputSize.needsUpdate=!0),t.color&&(r=t.color,o=c.color.array,c.color.needsUpdate=!0);const l=this.positionCount;let u,h,d,m,f,p=0;for(let t=0;t<l;++t)for(h=3*t,d=a[t],f=d.length,this.parameters.showBackground&&(f+=1),m=0;m<f;++m,++p)for(let a=0;a<4;a++)u=4*p*3+3*a,e&&(n[u]=e[h],n[u+1]=e[h+1],n[u+2]=e[h+2]),i&&(s[4*p+a]=i[t]),r&&(o[u]=r[h],o[u+1]=r[h+1],o[u+2]=r[h+2])}makeTexture(){this.textAtlas=function(t){const e=JSON.stringify(t);return void 0===_l[e]&&(_l[e]=new vl(t)),_l[e]}({font:this.parameters.fontFamily,style:this.parameters.fontStyle,weight:this.parameters.fontWeight,size:this.parameters.fontSize}),this.texture=this.textAtlas.texture}makeMapping(){const t=this.textAtlas,e=this.text,i=this.parameters.attachment,r=t.lineHeight*this.parameters.backgroundMargin*.1-10,n=this.geometry.attributes,s=n.inputTexCoord.array,o=n.mapping.array,a=this.positionCount;let c,l,u,h,d,m,f,p,g=0;for(let n=0;n<a;++n){for(u=e[n],h=0,m=u.length,d=0;d<m;++d)c=t.get(u[d]),h+=c.w-2*t.parameters.outline;for(p=i.startsWith("top")?t.lineHeight/1.25:i.startsWith("middle")?t.lineHeight/2.5:0,f=i.endsWith("right")?h:i.endsWith("center")?h/2:0,f+=t.parameters.outline,p+=t.parameters.outline,this.parameters.showBackground&&(l=2*g*4,o[l+0]=-t.lineHeight/6-f-r,o[l+1]=t.lineHeight-p+r,o[l+2]=-t.lineHeight/6-f-r,o[l+3]=0-p-r,o[l+4]=h+t.lineHeight/6-f+2*t.parameters.outline+r,o[l+5]=t.lineHeight-p+r,o[l+6]=h+t.lineHeight/6-f+2*t.parameters.outline+r,o[l+7]=0-p-r,s[l+0]=10,s[l+2]=10,s[l+4]=10,s[l+6]=10,g+=1),h=0,d=0;d<m;++d,++g){c=t.get(u[d]),l=2*g*4,o[l+0]=h-f,o[l+1]=c.h-p,o[l+2]=h-f,o[l+3]=0-p,o[l+4]=h+c.w-f,o[l+5]=c.h-p,o[l+6]=h+c.w-f,o[l+7]=0-p;const e=t.parameters.width,i=t.parameters.height,r=[c.x/e,c.y/i,c.x/e,(c.y+c.h)/i,(c.x+c.w)/e,c.y/i,(c.x+c.w)/e,(c.y+c.h)/i];s.set(r,l),h+=c.w-2*t.parameters.outline}}n.inputTexCoord.needsUpdate=!0,n.mapping.needsUpdate=!0}getDefines(t){const e=super.getDefines(t);return this.parameters.fixedSize&&(e.FIXED_SIZE=1),e}setUniforms(t){!t||void 0===t.fontFamily&&void 0===t.fontStyle&&void 0===t.fontWeight&&void 0===t.fontSize||(this.makeTexture(),this.makeMapping(),this.texture.needsUpdate=!0,t.fontTexture=this.texture),super.setUniforms(t)}}jt.add("text",Cl),zt.add("shader/WideLine.vert","\nuniform float clipNear;\nuniform vec3 clipCenter;\nuniform float linewidth;\nuniform vec2 resolution;\nuniform mat4 projectionMatrixInverse;\nattribute vec2 mapping;\nattribute vec3 position1;\nattribute vec3 position2;\n#ifdef PICKING\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\nattribute vec3 color2;\nvarying vec3 vColor;\nvarying vec3 vColor2;\nvarying float flag;\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\nvoid trimSegment( const in vec4 start, inout vec4 end ) {\nfloat a = projectionMatrix[ 2 ][ 2 ]; float b = projectionMatrix[ 3 ][ 2 ]; float nearEstimate = - 0.5 * b / a;\nfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\nend.xyz = mix( start.xyz, end.xyz, alpha );\n}\nvoid main() {\nfloat aspect = resolution.x / resolution.y;\n#ifdef PICKING\nvPickingColor = unpackColor( primitiveId );\n#else\nflag = mapping.y;\nvColor = color;\nvColor2 = color2;\n#endif\nvec4 start = modelViewMatrix * vec4( position1, 1.0 );\nvec4 end = modelViewMatrix * vec4( position2, 1.0 );\nbool perspective = ( projectionMatrix[ 2 ][ 3 ] == -1.0 ); if ( perspective ) {\nif ( start.z < 0.0 && end.z >= 0.0 ) {\ntrimSegment( start, end );\n} else if ( end.z < 0.0 && start.z >= 0.0 ) {\ntrimSegment( end, start );\n}\n}\nvec4 clipStart = projectionMatrix * start;\nvec4 clipEnd = projectionMatrix * end;\nvec2 ndcStart = clipStart.xy / clipStart.w;\nvec2 ndcEnd = clipEnd.xy / clipEnd.w;\nvec2 dir = ndcEnd - ndcStart;\ndir.x *= aspect;\ndir = normalize( dir );\nvec2 offset = vec2( dir.y, - dir.x );\ndir.x /= aspect;\noffset.x /= aspect;\nif ( mapping.x < 0.0 ) offset *= - 1.0;\noffset *= linewidth;\noffset /= resolution.y;\nvec4 clip = ( mapping.y < 0.5 ) ? clipStart : clipEnd;\noffset *= clip.w;\nclip.xy += offset;\ngl_Position = clip;\n#ifndef PICKING\nvViewPosition = ( projectionMatrixInverse * clip ).xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n}"),zt.add("shader/WideLine.frag","uniform vec3 diffuse;\nuniform float opacity;\nuniform float clipNear;\nuniform float clipRadius;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#ifdef PICKING\nuniform float objectId;\nvarying vec3 vPickingColor;\n#else\n#include common\n#include fog_pars_fragment\nvarying vec3 vViewPosition;\nvarying vec3 vColor;\nvarying vec3 vColor2;\nvarying float flag;\n#endif\nvoid main() {\n#include nearclip_fragment\n#include radiusclip_fragment\n#if defined( PICKING )\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 outgoingLight = vec3( 0.0 );\nvec4 diffuseColor = vec4( diffuse, 1.0 );\nif ( flag < 0.0 ) {\ndiffuseColor.rgb *= vColor;\n} else {\ndiffuseColor.rgb *= vColor2;\n}\n#include alphatest_fragment\noutgoingLight = diffuseColor.rgb;\ngl_FragColor = vec4( outgoingLight, diffuseColor.a * opacity );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const Pl=Object.assign({linewidth:2},Ms),Il=Object.assign({linewidth:{uniform:!0}},Ts);class kl extends Ma{constructor(t,i={}){super(t,i),this.parameterTypes=Il,this.vertexShader="WideLine.vert",this.fragmentShader="WideLine.frag",!t.color2&&t.color&&(t.color2=t.color),this.addUniforms({linewidth:{value:this.parameters.linewidth},resolution:{value:new e.Vector2},projectionMatrixInverse:{value:new e.Matrix4}}),this.addAttributes({position1:{type:"v3",value:null},position2:{type:"v3",value:null},color2:{type:"c",value:null}}),this.setAttributes(t),this.makeMapping()}get defaultParameters(){return Pl}setParameters(t){super.setParameters(t)}}jt.add("wideline",kl);class Ml extends fl{constructor(t,e,i){super(t,e,i),this.type="angle",this.parameters=Object.assign({atomTriple:{type:"hidden",rebuild:!0},vectorVisible:{type:"boolean",default:!0},arcVisible:{type:"boolean",default:!0},sectorVisible:{type:"boolean",default:!0}},this.parameters),this.init(i)}init(t){const e=t||{};e.side=l(e.side,"double"),e.opacity=l(e.opacity,.5),this.atomTriple=l(e.atomTriple,[]),this.arcVisible=l(e.arcVisible,!0),this.sectorVisible=l(e.sectorVisible,!0),this.vectorVisible=l(e.vectorVisible,!0),super.init(e)}createData(t){if(!t.atomCount||!this.atomTriple.length)return;const i=function(t,e){return function(t){const e=[],i=t.length/9;for(let r=0;r<i;r++){let i=!0;for(let e=r;e<r+3;e+=3)t[e]===t[e+3]&&t[e+1]===t[e+4]&&t[e+2]===t[e+5]&&(i=!1);i&&e.push(r)}const r=new Float32Array(9*e.length);let n=0;return e.forEach((function(e){ve(t,r,9*e,9*n,9),n++})),r}(pl(t,e))}(t,this.atomTriple),r=function(t,e={}){const i=l(e.angleStep,Math.PI/90),r=t.length/9,n=new Float32Array(r),s=new Float32Array(3*r),o=new Array(r),a=new Float32Array(6*r),c=new Float32Array(6*r),u=new Array(r),h=new Array(r),d=new Array(r);let m=0;const f=Li(),p=Li(),g=Li(),y=Li(),b=Li(),_=Li(),x=Li(),v=Li(),w=Li();for(var A=0;A<r;A++){let e=9*A;ji(f,t,e),ji(p,t,e+3),ji(g,t,e+6);let r=6*A;Gi(f,a,r),Gi(p,c,r),Gi(p,a,r+3),Gi(g,c,r+3),Vi(y,f,p),Vi(b,g,p),Yi(y,y),Yi(b,b),Ni(_,y,b);const l=qi(_),S=zi(y,b),C=n[A]=Math.atan2(l,S);o[A]=(de*C).toFixed(1)+String.fromCharCode(176),0===qi(_)&&(_[0]=1,_[1]=0,_[2]=0),Ni(x,_,y),Yi(x,x),gl(v,p,y,x,C/2),Gi(v,s,3*A);const P=Math.ceil(C/i),I=new Float32Array(9*P);d[A]=I;const k=new Float32Array(3*P),M=new Float32Array(3*P);u[A]=k,h[A]=M,Ui(w,p,y);const T=function(t,e){const i=9*e,r=3*e;Gi(p,I,i),Gi(w,I,i+3),Gi(w,k,r),gl(w,p,y,x,t),Gi(w,I,i+6),Gi(w,M,r)};let D=0;for(let t=i;t<C;t+=i)T(t,D),D++;T(C,D),m+=P}const S=3*m,C=9*m,P=new Float32Array(S),I=new Float32Array(S),k=new Float32Array(C);let M=0,T=0;for(let t=0;t<r;t++){const e=u[t],i=h[t];ve(e,P,0,T,e.length),ve(i,I,0,T,i.length),T+=e.length;const r=d[t];ve(r,k,0,M,r.length),M+=r.length}return{labelPosition:s,labelText:o,vectorPosition1:a,vectorPosition2:c,arcPosition1:P,arcPosition2:I,sectorPosition:k}}(i),n=this.n=r.labelPosition.length/3,s=new e.Color(this.labelColor);this.textBuffer=new Cl({position:r.labelPosition,size:ge(n,this.labelSize),color:ye(n,s.r,s.g,s.b),text:r.labelText},this.getLabelBufferParams());const o=new e.Color(this.colorValue);return this.vectorBuffer=new kl(nr({position1:r.vectorPosition1,position2:r.vectorPosition2,color:ye(2*n,o.r,o.g,o.b),color2:ye(2*n,o.r,o.g,o.b)}),this.getBufferParams({linewidth:this.linewidth,visible:this.vectorVisible,opacity:this.lineOpacity})),this.arcLength=r.arcPosition1.length/3,this.arcBuffer=new kl(nr({position1:r.arcPosition1,position2:r.arcPosition2,color:ye(this.arcLength,o.r,o.g,o.b),color2:ye(this.arcLength,o.r,o.g,o.b)}),this.getBufferParams({linewidth:this.linewidth,visible:this.arcVisible,opacity:this.lineOpacity})),this.sectorLength=r.sectorPosition.length/3,this.sectorBuffer=new Bs({position:r.sectorPosition,color:ye(this.sectorLength,o.r,o.g,o.b)},this.getBufferParams({visible:this.sectorVisible})),{bufferList:[this.textBuffer,this.vectorBuffer,this.arcBuffer,this.sectorBuffer]}}updateData(t,i){super.updateData(t,i);const r={},n={},s={};if(t.color){const t=new e.Color(this.colorValue);Object.assign(r,{color:ye(2*this.n,t.r,t.g,t.b),color2:ye(2*this.n,t.r,t.g,t.b)}),Object.assign(n,{color:ye(this.arcLength,t.r,t.g,t.b),color2:ye(this.arcLength,t.r,t.g,t.b)}),Object.assign(s,{color:ye(this.sectorLength,t.r,t.g,t.b)})}this.vectorBuffer.setAttributes(r),this.arcBuffer.setAttributes(n),this.sectorBuffer.setAttributes(s)}setParameters(t){return super.setParameters(t,{},!1),!t||void 0===t.vectorVisible&&void 0===t.arcVisible&&void 0===t.sectorVisible||this.setVisibility(this.visible),t&&t.lineOpacity&&(this.vectorBuffer.setParameters({opacity:t.lineOpacity}),this.arcBuffer.setParameters({opacity:t.lineOpacity})),t&&void 0!==t.opacity&&(this.vectorBuffer.setParameters({opacity:this.lineOpacity}),this.arcBuffer.setParameters({opacity:this.lineOpacity})),t&&t.linewidth&&(this.vectorBuffer.setParameters({linewidth:t.linewidth}),this.arcBuffer.setParameters({linewidth:t.linewidth})),this}setVisibility(t,e){return super.setVisibility(t,!0),this.vectorBuffer&&this.vectorBuffer.setVisibility(this.vectorVisible&&this.visible),this.arcBuffer&&this.arcBuffer.setVisibility(this.arcVisible&&this.visible),this.sectorBuffer&&this.sectorBuffer.setVisibility(this.sectorVisible&&this.visible),e||this.viewer.requestRender(),this}}Lt.add("angle",Ml);const Tl=new e.Vector3,Dl=new e.Vector3,Bl=new e.Vector3,Fl=new e.Vector3(0,1,0),El=Object.assign({radialSegments:1,openEnded:!0},Ms);function Ol(t={}){const i=l(t.radialSegments,10),r=l(t.openEnded,!0),n=(new e.Matrix4).makeRotationX(Math.PI/2),s=new e.CylinderGeometry(1,1,1,i,1,r);return s.applyMatrix4(n),s}class $l extends wa{constructor(t,e={}){super(function(t,e={}){const i=Ol(e),r=t.position1.length,n=i.attributes.position.array.length/3,s=r/3,o=new Float32Array(2*s*n);return _e(s,n,0,o),_e(s,n,s*n,o),{position:new Float32Array(2*r),color:new Float32Array(2*r),primitiveId:o,picking:t.picking}}(t,e),e,Ol(e)),this.updateNormals=!0;const i=t.position1.length,r=t.radius.length;this.__center=new Float32Array(i),this._position=new Float32Array(2*i),this._color=new Float32Array(2*i),this._from=new Float32Array(2*i),this._to=new Float32Array(2*i),this._radius=new Float32Array(2*r),this.setAttributes(t,!0)}get defaultParameters(){return El}applyPositionTransform(t,e,i){Dl.fromArray(this._from,i),Bl.fromArray(this._to,i),t.lookAt(Dl,Bl,Fl);const r=this._radius[e];Tl.set(r,r,Dl.distanceTo(Bl)),t.scale(Tl)}setAttributes(t={},e){const i={};t.position1&&t.position2&&(fe(t.position1,t.position2,this.__center),fe(t.position1,this.__center,this._position),fe(this.__center,t.position2,this._position,t.position1.length),this._from.set(t.position1),this._from.set(this.__center,t.position1.length),this._to.set(this.__center),this._to.set(t.position2,this.__center.length),i.position=this._position),t.color&&t.color2&&(this._color.set(t.color),this._color.set(t.color2,t.color.length),i.color=this._color),t.radius&&(this._radius.set(t.radius),this._radius.set(t.radius,t.radius.length),i.radius=this._radius),super.setAttributes(i,e)}}zt.add("shader/CylinderImpostor.vert","\nattribute vec3 mapping;\nattribute vec3 position1;\nattribute vec3 position2;\nattribute float radius;\nvarying vec3 axis;varying vec4 base_radius;varying vec4 end_b;varying vec3 U;varying vec3 V;\nvarying vec4 w;\n#ifdef PICKING\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\nattribute vec3 color2;\nvarying vec3 vColor1;\nvarying vec3 vColor2;\n#endif\nuniform mat4 modelViewMatrixInverse;\nuniform float ortho;\n#include matrix_scale\nvoid main(){\n#ifdef PICKING\nvPickingColor = unpackColor( primitiveId );\n#else\nvColor1 = color;\nvColor2 = color2;\n#endif\nbase_radius.w = radius * matrixScale( modelViewMatrix );\nvec3 center = position;\nvec3 dir = normalize( position2 - position1 );\nfloat ext = length( position2 - position1 ) / 2.0;\nvec3 cam_dir;\nif( ortho == 0.0 ){\ncam_dir = ( modelViewMatrixInverse * vec4( 0, 0, 0, 1 ) ).xyz - center;\n}else{\ncam_dir = ( modelViewMatrixInverse * vec4( 0, 0, 1, 0 ) ).xyz;\n}\ncam_dir = normalize( cam_dir );\nvec3 ldir;\nfloat b = dot( cam_dir, dir );\nend_b.w = b;\nif( b < 0.0 )\nldir = -ext * dir;\nelse\nldir = ext * dir;\nvec3 left = radius * normalize( cross( cam_dir, ldir ) );\nvec3 up = radius * normalize( cross( left, ldir ) );\naxis = normalize( normalMatrix * ldir );\nU = normalize( normalMatrix * up );\nV = normalize( normalMatrix * left );\nvec4 base4 = modelViewMatrix * vec4( center - ldir, 1.0 );\nbase_radius.xyz = base4.xyz / base4.w;\nvec4 end4 = modelViewMatrix * vec4( center + ldir, 1.0 );\nend_b.xyz = end4.xyz / end4.w;\nw = modelViewMatrix * vec4(\ncenter + mapping.x*ldir + mapping.y*left + mapping.z*up, 1.0\n);\ngl_Position = projectionMatrix * w;\ngl_Position.z = 0.0;\n}"),zt.add("shader/CylinderImpostor.frag","#define STANDARD\n#define IMPOSTOR\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 interiorColor;\nuniform float interiorDarkening;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float clipNear;\nuniform mat4 projectionMatrix;\nuniform float ortho;\nvarying vec3 axis;\nvarying vec4 base_radius;\nvarying vec4 end_b;\nvarying vec3 U;\nvarying vec3 V;\nvarying vec4 w;\n#ifdef PICKING\nuniform float objectId;\nvarying vec3 vPickingColor;\n#else\nvarying vec3 vColor1;\nvarying vec3 vColor2;\n#include common\n#include fog_pars_fragment\n#include bsdfs\n#include lights_pars_begin\n#include lights_physical_pars_fragment\n#endif\nbool interior = false;\nfloat distSq3( vec3 v3a, vec3 v3b ){\nreturn (\n( v3a.x - v3b.x ) * ( v3a.x - v3b.x ) +\n( v3a.y - v3b.y ) * ( v3a.y - v3b.y ) +\n( v3a.z - v3b.z ) * ( v3a.z - v3b.z )\n);\n}\nfloat calcDepth( in vec3 cameraPos ){\nvec2 clipZW = cameraPos.z * projectionMatrix[2].zw + projectionMatrix[3].zw;\nreturn 0.5 + 0.5 * clipZW.x / clipZW.y;\n}\nfloat calcClip( vec3 cameraPos ){\nreturn dot( vec4( cameraPos, 1.0 ), vec4( 0.0, 0.0, 1.0, clipNear - 0.5 ) );\n}\nvoid main(){\nvec3 ray_target = w.xyz / w.w;\nvec3 base = base_radius.xyz; float vRadius = base_radius.w; vec3 end = end_b.xyz; float b = end_b.w;\nvec3 ray_origin = vec3(0.0); vec3 ortho_ray_direction = vec3(0.0, 0.0, 1.0); vec3 persp_ray_direction = normalize(ray_origin - ray_target);\nvec3 ray_direction = mix(persp_ray_direction, ortho_ray_direction, ortho);\nmat3 basis = mat3( U, V, axis );\nvec3 diff = ray_target - 0.5 * (base + end);\nvec3 P = diff * basis;\nfloat dz = dot( axis, ray_direction );\nfloat radius2 = vRadius*vRadius;\nvec3 D = vec3(dot(U, ray_direction),\ndot(V, ray_direction),\ndz);\nfloat a0 = P.x*P.x + P.y*P.y - radius2;\nfloat a1 = P.x*D.x + P.y*D.y;\nfloat a2 = D.x*D.x + D.y*D.y;\nfloat d = a1*a1 - a0*a2;\nif (d < 0.0) {\ndiscard;\n}\nfloat dist = (-a1 + sqrt(d)) / a2;\nvec3 surface_point = ray_target + dist * ray_direction;\nvec3 base_to_surface = surface_point - base;\nvec3 _normal = normalize( base_to_surface - axis * dot(base_to_surface, axis) );\nfloat base_cap_test = dot( base_to_surface, axis );\nfloat end_cap_test = dot((surface_point - end), axis);\n#ifndef CAP\nvec3 new_point2 = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;\nvec3 tmp_point2 = new_point2 - base;\n#endif\nif (base_cap_test < 0.0) {\nfloat dNV;\nfloat near;\nvec3 front_point;\nif ( ortho == 1.0 ) {\nfront_point = ray_target;\n} else {\ndNV = dot(-axis, ray_direction);\nnear = dot(-axis, (base)) / dNV;\nfront_point = ray_direction * near + ray_origin;\n}\nif (dot(front_point - base, front_point-base) > radius2) {\ndiscard;\n}\n#ifdef CAP\nsurface_point = front_point;\n_normal = axis;\n#else\nsurface_point = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;\ndNV = dot(-axis, ray_direction);\nnear = dot(axis, end) / dNV;\nnew_point2 = ray_direction * near + ray_origin;\nif (dot(new_point2 - end, new_point2-base) < radius2) {\ndiscard;\n}\ninterior = true;\n#endif\n}\nif( end_cap_test > 0.0 )\n{\nfloat dNV;\nfloat near;\nvec3 end_point;\nif ( ortho == 1.0 ) {\nend_point = ray_target;\n} else {\ndNV = dot(axis, ray_direction);\nif (dNV < 0.0) {\ndiscard;\n}\nnear = dot(axis, end) / dNV;\nend_point = ray_direction * near + ray_origin;\n}\nif( dot(end_point - end, end_point-base) > radius2 ) {\ndiscard;\n}\n#ifdef CAP\nsurface_point = end_point;\n_normal = axis;\n#else\nsurface_point = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;\ndNV = dot(-axis, ray_direction);\nnear = dot(-axis, (base)) / dNV;\nnew_point2 = ray_direction * near + ray_origin;\nif (dot(new_point2 - base, new_point2-base) < radius2) {\ndiscard;\n}\ninterior = true;\n#endif\n}\ngl_FragDepthEXT = calcDepth( surface_point );\n#ifdef NEAR_CLIP\nif( calcClip( surface_point ) > 0.0 ){\ndist = (-a1 - sqrt(d)) / a2;\nsurface_point = ray_target + dist * ray_direction;\nif( calcClip( surface_point ) > 0.0 ) {\ndiscard;\n}\ninterior = true;\ngl_FragDepthEXT = calcDepth( surface_point );\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( clipNear - 0.5 ) ) ) + ( 0.0000001 / vRadius ) );\n}\n}else if( gl_FragDepthEXT <= 0.0 ){\ndist = (-a1 - sqrt(d)) / a2;\nsurface_point = ray_target + dist * ray_direction;\ninterior = true;\ngl_FragDepthEXT = calcDepth( surface_point );\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n}\n#else\nif( gl_FragDepthEXT <= 0.0 ){\ndist = (-a1 - sqrt(d)) / a2;\nsurface_point = ray_target + dist * ray_direction;\ninterior = true;\ngl_FragDepthEXT = calcDepth( surface_point );\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n}\n#endif\nif (gl_FragDepthEXT < 0.0) {\ndiscard;\n}\nif (gl_FragDepthEXT > 1.0) {\ndiscard;\n}\n#ifdef PICKING\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 vViewPosition = -surface_point;\nvec3 vNormal = _normal;\nvec3 vColor;\nif( distSq3( surface_point, end ) < distSq3( surface_point, base ) ){\nif( b < 0.0 ){\nvColor = vColor1;\n}else{\nvColor = vColor2;\n}\n}else{\nif( b > 0.0 ){\nvColor = vColor1;\n}else{\nvColor = vColor2;\n}\n}\nvec4 diffuseColor = vec4( diffuse, opacity );\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\nvec3 totalEmissiveLight = emissive;\n#include color_fragment\n#include roughnessmap_fragment\n#include metalnessmap_fragment\nvec3 normal = normalize( vNormal );\nvec3 nonPerturbedNormal = normal;\n#include lights_physical_fragment\n#include lights_fragment_begin\n#include lights_fragment_end\nvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;\nif( interior ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const Rl=new Float32Array([-1,1,-1,-1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,-1,1]),Ll=new Uint16Array([0,1,2,1,4,2,2,4,3,4,5,3]);class Nl extends Pa{constructor(t,e={}){super("v3",t,e)}get mapping(){return Rl}get mappingIndices(){return Ll}get mappingIndicesSize(){return 12}get mappingSize(){return 6}get mappingItemSize(){return 3}}const zl=Object.assign({openEnded:!1},Ms),Vl=Object.assign({openEnded:{updateShader:!0}},Ts);class Ul extends Nl{constructor(t,i={}){super(t,i),this.parameterTypes=Vl,this.isImpostor=!0,this.vertexShader="CylinderImpostor.vert",this.fragmentShader="CylinderImpostor.frag",this.addUniforms({modelViewMatrixInverse:{value:new e.Matrix4},ortho:{value:0}}),this.addAttributes({position1:{type:"v3",value:null},position2:{type:"v3",value:null},color2:{type:"c",value:null},radius:{type:"f",value:null}}),this.setAttributes(t),this.makeMapping()}get defaultParameters(){return zl}getDefines(t){const e=Nl.prototype.getDefines.call(this,t);return this.parameters.openEnded||(e.CAP=1),e}}Object.assign({disableImpostor:!1},El,zl);const jl=class{constructor(t,e={}){return!t.color2&&t.color&&(t.color2=t.color),!Mt||e&&e.disableImpostor?new $l(t,e):new Ul(t,e)}};jt.add("cylinder",jl);class Gl extends ml{constructor(t,e,i){super(t,e,i),this.type="axes",this.parameters=Object.assign({radiusSize:{type:"number",precision:3,max:10,min:.001},sphereDetail:!0,radialSegments:!0,disableImpostor:!0,showAxes:{type:"boolean",rebuild:!0},showBox:{type:"boolean",rebuild:!0}},this.parameters,{assembly:null}),this.init(i)}init(t){const e=t||{};e.radiusSize=l(e.radiusSize,.5),e.colorValue=l(e.colorValue,"lightgreen"),e.useInteriorColor=l(e.useInteriorColor,!0),this.showAxes=l(e.showAxes,!0),this.showBox=l(e.showBox,!1),super.init(e)}getPrincipalAxes(){let t;const e=this.getAssembly();return e&&(t=e.partList[0].getSelection()),this.structureView.getPrincipalAxes(t)}getAxesData(t){const i=this.getPrincipalAxes(),r=new e.Color(this.colorValue);let n=0,s=0;this.showAxes&&(n+=6,s+=3),this.showBox&&(n+=8,s+=12);const o=new Float32Array(3*n),a=ye(n,r.r,r.g,r.b),c=ge(n,this.radiusSize),l=new Float32Array(3*s),u=new Float32Array(3*s),h=ye(s,r.r,r.g,r.b),d=ge(s,this.radiusSize);let m=0;if(this.showAxes){const t=function(t,e){t.toArray(o,2*m),e.toArray(o,2*m+3),t.toArray(l,m),e.toArray(u,m),m+=3};t(i.begA,i.endA),t(i.begB,i.endB),t(i.begC,i.endC)}if(this.showBox){const r=new e.Vector3,{d1a:n,d2a:s,d3a:a,d1b:c,d2b:h,d3b:d}=i.getProjectedScaleForAtoms(t);let f=2*m;const p=function(t,e,n){r.copy(i.center).addScaledVector(i.normVecA,t).addScaledVector(i.normVecB,e).addScaledVector(i.normVecC,n),r.toArray(o,f),f+=3};p(n,s,a),p(n,s,d),p(n,h,d),p(n,h,a),p(c,h,d),p(c,h,a),p(c,s,a),p(c,s,d);let g=m;const y=function(t,e){r.fromArray(o,2*m+3*t).toArray(l,g),r.fromArray(o,2*m+3*e).toArray(u,g),g+=3};y(0,1),y(0,3),y(0,6),y(1,2),y(1,7),y(2,3),y(2,4),y(3,5),y(4,5),y(4,7),y(5,6),y(6,7)}const f=new zn(i);return{vertex:{position:o,color:a,radius:c,picking:f},edge:{position1:l,position2:u,color:h,color2:h,radius:d,picking:f}}}create(){const t=this.getAxesData(this.structureView);this.sphereBuffer=new Da(t.vertex,this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0})),this.cylinderBuffer=new jl(t.edge,this.getBufferParams({openEnded:!0,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0})),this.dataList.push({sview:this.structureView,bufferList:[this.sphereBuffer,this.cylinderBuffer]})}createData(t){}updateData(t,e){const i=this.getAxesData(e.sview),r={},n={};t&&!t.position||(Object.assign(r,{position:i.vertex.position}),Object.assign(n,{position1:i.edge.position1,position2:i.edge.position2})),t&&!t.color||(Object.assign(r,{color:i.vertex.color}),Object.assign(n,{color:i.edge.color,color2:i.edge.color})),t&&!t.radius||(Object.assign(r,{radius:i.vertex.radius}),Object.assign(n,{radius:i.edge.radius})),this.sphereBuffer.setAttributes(r),this.cylinderBuffer.setAttributes(n)}}Lt.add("axes",Gl);class Hl extends ml{constructor(t,e,i){super(t,e,i),this.type="ball+stick",this.parameters=Object.assign({sphereDetail:!0,radialSegments:!0,openEnded:!0,disableImpostor:!0,aspectRatio:{type:"number",precision:1,max:10,min:1},lineOnly:{type:"boolean",rebuild:!0},cylinderOnly:{type:"boolean",rebuild:!0},multipleBond:{type:"select",rebuild:!0,options:{off:"off",symmetric:"symmetric",offset:"offset"}},bondScale:{type:"number",precision:2,max:1,min:.01},bondSpacing:{type:"number",precision:2,max:2,min:.5},linewidth:{type:"integer",max:50,min:1,buffer:!0}},this.parameters),this.init(i)}init(t){var e=t||{};e.radiusType=l(e.radiusType,"size"),e.radiusSize=l(e.radiusSize,.15),e.useInteriorColor=l(e.useInteriorColor,!0),this.aspectRatio=l(e.aspectRatio,2),this.lineOnly=l(e.lineOnly,!1),this.cylinderOnly=l(e.cylinderOnly,!1),this.multipleBond=l(e.multipleBond,"off"),this.bondSpacing=l(e.bondSpacing,1),this.bondScale=l(e.bondScale,.4),this.linewidth=l(e.linewidth,2),super.init(e)}getAtomRadius(t){return this.aspectRatio*super.getAtomRadius(t)}getAtomParams(t,e){var i=super.getAtomParams(t,e);return i.radiusParams.scale*=this.aspectRatio,i}getAtomData(t,e,i){return t.getAtomData(this.getAtomParams(e,i))}getBondParams(t,e){return e=Object.assign({multipleBond:this.multipleBond,bondSpacing:this.bondSpacing,bondScale:this.bondScale},e),super.getBondParams(t,e)}getBondData(t,e,i){return t.getBondData(this.getBondParams(e,i))}createData(t){const e=[];if(this.lineOnly)this.lineBuffer=new kl(this.getBondData(t,{position:!0,color:!0,picking:!0}),this.getBufferParams({linewidth:this.linewidth})),e.push(this.lineBuffer);else{const i=new jl(this.getBondData(t),this.getBufferParams({openEnded:this.openEnded,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0}));if(e.push(i),!this.cylinderOnly){const i=new Da(this.getAtomData(t),this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0}));e.push(i)}}return{bufferList:e}}updateData(t,e){"off"!==this.multipleBond&&t&&t.radius&&(t.position=!0);const i=this.getBondData(e.sview,t);if(this.lineOnly){const r={};t&&!t.position||Object.assign(r,{position1:i.position1,position2:i.position2}),t&&!t.color||Object.assign(r,{color:i.color,color2:i.color2}),e.bufferList[0].setAttributes(r)}else{var r={};if(t&&!t.position||Object.assign(r,{position1:i.position1,position2:i.position2}),t&&!t.color||Object.assign(r,{color:i.color,color2:i.color2}),t&&!t.radius||Object.assign(r,{radius:i.radius}),e.bufferList[0].setAttributes(r),!this.cylinderOnly){var n=this.getAtomData(e.sview,t),s={};t&&!t.position||Object.assign(s,{position:n.position}),t&&!t.color||Object.assign(s,{color:n.color}),t&&!t.radius||Object.assign(s,{radius:n.radius}),e.bufferList[1].setAttributes(s)}}}setParameters(t={}){let e=!1;const i={};return(t.aspectRatio||t.bondSpacing||t.bondScale)&&(Object.assign(i,{radius:!0}),Mt&&!this.disableImpostor||(e=!0)),super.setParameters(t,i,e),this}}Lt.add("ball+stick",Hl);class ql extends Hl{constructor(t,e,i){super(t,e,i),this.type="backbone",this.parameters=Object.assign({},this.parameters,{multipleBond:null,bondSpacing:null}),this.init(i)}init(t){var e=t||{};e.aspectRatio=l(e.aspectRatio,1),e.radiusSize=l(e.radiusSize,.25),super.init(e)}getAtomRadius(t){return t.isTrace()?super.getAtomRadius(t):0}getAtomData(t,e,i){return t.getBackboneAtomData(this.getAtomParams(e,i))}getBondData(t,e,i){return t.getBackboneBondData(this.getBondParams(e,i))}}Lt.add("backbone",ql);class Wl extends Hl{constructor(t,e,i){super(t,e,i),this.type="base",this.parameters=Object.assign({},this.parameters,{multipleBond:null,bondSpacing:null})}init(t){let e=t||{};e.aspectRatio=l(e.aspectRatio,1),e.radiusSize=l(e.radiusSize,.3),super.init(e)}getAtomData(t,e,i){return t.getRungAtomData(this.getAtomParams(e,i))}getBondData(t,e,i){let r=this.getBondParams(e,i);return Object.assign(r.colorParams,{rung:!0}),t.getRungBondData(r)}}Lt.add("base",Wl);class Xl{constructor(t,i){this.m=t,this.tension=i,this.dt=1/this.m,this.delta=1e-4,this.vec1=new e.Vector3,this.vec2=new e.Vector3,this.vDir=new e.Vector3,this.vTan=new e.Vector3,this.vNorm=new e.Vector3,this.vBin=new e.Vector3,this.m2=Math.ceil(this.m/2)}interpolateToArr(t,e,i,r,n,s,o){s[o+0]=$(t.x,e.x,i.x,r.x,n,this.tension),s[o+1]=$(t.y,e.y,i.y,r.y,n,this.tension),s[o+2]=$(t.z,e.z,i.z,r.z,n,this.tension)}interpolateToVec(t,e,i,r,n,s){s.x=$(t.x,e.x,i.x,r.x,n,this.tension),s.y=$(t.y,e.y,i.y,r.y,n,this.tension),s.z=$(t.z,e.z,i.z,r.z,n,this.tension)}interpolatePosition(t,e,i,r,n,s){for(var o=0;o<this.m;++o){var a=s+3*o,c=this.dt*o;this.interpolateToArr(t,e,i,r,c,n,a)}}interpolateTangent(t,e,i,r,n,s){for(var o=0;o<this.m;++o){var a=this.dt*o,c=a-this.delta,l=a+this.delta,u=s+3*o;c<0&&(c=0),l>1&&(l=1),this.interpolateToVec(t,e,i,r,c,this.vec1),this.interpolateToVec(t,e,i,r,l,this.vec2),this.vec2.sub(this.vec1).normalize(),this.vec2.toArray(n,u)}}vectorSubdivide(t,e,i,r,n){let s,o=e.next(),a=e.next(),c=e.next();const l=e.size,u=l-1;let h=r||0;for(let r=0;r<u;++r)s=o,o=a,a=c,c=e.next(),t.apply(this,[s,o,a,c,i,h]),h+=3*this.m;n&&(s=e.get(l-2),o=e.get(l-1),a=e.get(0),c=e.get(1),t.apply(this,[s,o,a,c,i,h]),h+=3*this.m)}getPosition(t,e,i,r){t.reset(),this.vectorSubdivide(this.interpolatePosition,t,e,i,r);var n=t.size-1,s=n*this.m*3;r&&(s+=3*this.m);var o=t.get(r?0:n);e[s]=o.x,e[s+1]=o.y,e[s+2]=o.z}getTangent(t,e,i,r){t.reset(),this.vectorSubdivide(this.interpolateTangent,t,e,i,r);let n=(t.size-1)*this.m*3;r&&(n+=3*this.m),ve(e,e,n-3,n,3)}interpolateNormalDir(t,e,i,r,n,s,o,a,c,l,u,h,d){for(let m=0;m<this.m;++m){let f=h+3*m;d&&(f+=3*this.m2);const p=this.dt*m;this.interpolateToVec(t,e,i,r,p,this.vec1),this.interpolateToVec(n,s,o,a,p,this.vec2),this.vDir.subVectors(this.vec2,this.vec1).normalize(),this.vTan.fromArray(c,f),this.vBin.crossVectors(this.vDir,this.vTan).normalize(),this.vBin.toArray(u,f),this.vNorm.crossVectors(this.vTan,this.vBin).normalize(),this.vNorm.toArray(l,f)}}interpolateNormal(t,e,i,r,n){for(var s=0;s<this.m;++s){var o=n+3*s;t.copy(this.vNorm),this.vTan.fromArray(e,o),this.vBin.crossVectors(t,this.vTan).normalize(),this.vBin.toArray(r,o),this.vNorm.crossVectors(this.vTan,this.vBin).normalize(),this.vNorm.toArray(i,o)}}getNormal(t,e,i,r,n,s){this.vNorm.set(0,0,1);const o=t-1;let a=n||0;for(var c=0;c<o;++c)this.interpolateNormal(this.vDir,e,i,r,a),a+=3*this.m;s&&(this.interpolateNormal(this.vDir,e,i,r,a),a+=3*this.m),this.vBin.toArray(r,a),this.vNorm.toArray(i,a)}getNormalDir(t,i,r,n,s,o,a,c){t.reset(),i.reset();const l=new e.Vector3,u=new e.Vector3,h=new e.Vector3,d=new e.Vector3,m=new e.Vector3,f=(new e.Vector3).copy(t.next()),p=(new e.Vector3).copy(t.next()),g=(new e.Vector3).copy(t.next()),y=new e.Vector3,b=(new e.Vector3).copy(i.next()),_=(new e.Vector3).copy(i.next()),x=(new e.Vector3).copy(i.next());this.vNorm.set(0,0,1);let v=t.size,w=v-1,A=o||0;for(var S=0;S<w;++S)m.copy(f),f.copy(p),p.copy(g),g.copy(t.next()),y.copy(b),b.copy(_),_.copy(x),x.copy(i.next()),0===S?(l.subVectors(y,m),u.subVectors(b,f),l.dot(u)<0&&(u.multiplyScalar(-1),b.addVectors(f,u)),h.subVectors(_,p),u.dot(h)<0&&(h.multiplyScalar(-1),_.addVectors(p,h))):h.copy(d),d.subVectors(x,g),h.dot(d)<0&&(d.multiplyScalar(-1),x.addVectors(g,d)),this.interpolateNormalDir(m,f,p,g,y,b,_,x,r,n,s,A,c),A+=3*this.m;if(a&&(m.copy(t.get(v-2)),f.copy(t.get(v-1)),p.copy(t.get(0)),g.copy(t.get(1)),y.copy(i.get(v-2)),b.copy(i.get(v-1)),_.copy(i.get(0)),x.copy(i.get(1)),h.copy(d),d.subVectors(x,g),h.dot(d)<0&&(d.multiplyScalar(-1),x.addVectors(g,d)),this.interpolateNormalDir(m,f,p,g,y,b,_,x,r,n,s,A,c),A+=3*this.m),c){this.vBin.fromArray(s,3*this.m2),this.vNorm.fromArray(n,3*this.m2);for(var C=0;C<this.m2;++C)this.vBin.toArray(s,3*C),this.vNorm.toArray(n,3*C)}else this.vBin.toArray(s,A),this.vNorm.toArray(n,A)}interpolateColor(t,e,i,r,n){var s,o;for(s=0;s<this.m2;++s)o=n+3*s,i.apply(this,[t,r,o]);for(s=this.m2;s<this.m;++s)o=n+3*s,i.apply(this,[e,r,o])}getColor(t,e,i,r,n){let s;t.reset(),t.next();let o=t.next();for(var a=t.size,c=a-1,l=r||0,u=0;u<c;++u)s=o,o=t.next(),this.interpolateColor(s,o,e,i,l),l+=3*this.m;n&&(s=t.get(a-1),o=t.get(0),this.interpolateColor(s,o,e,i,l),l+=3*this.m),i[l]=i[l-3],i[l+1]=i[l-2],i[l+2]=i[l-1]}interpolatePicking(t,e,i,r,n){var s;for(s=0;s<this.m2;++s)r[n+s]=i.apply(this,[t]);for(s=this.m2;s<this.m;++s)r[n+s]=i.apply(this,[e])}getPicking(t,e,i,r,n){let s;t.reset(),t.next();let o=t.next();const a=t.size,c=a-1;let l=r||0;for(var u=0;u<c;++u)s=o,o=t.next(),this.interpolatePicking(s,o,e,i,l),l+=this.m;n&&(s=t.get(a-1),o=t.get(0),this.interpolatePicking(s,o,e,i,l),l+=this.m),i[l]=i[l-1]}interpolateSize(t,e,i,r,n){const s=i.apply(this,[t]),o=i.apply(this,[e]);for(let t=0;t<this.m;++t){let e=t/this.m;r[n+t]=(1-e)*s+e*o}}getSize(t,e,i,r,n){let s;t.reset(),t.next();let o=t.next();const a=t.size,c=a-1;let l=r||0;for(var u=0;u<c;++u)s=o,o=t.next(),this.interpolateSize(s,o,e,i,l),l+=this.m;n&&(s=t.get(a-1),o=t.get(0),this.interpolateSize(s,o,e,i,l),l+=this.m),i[l]=i[l-1]}}class Yl{constructor(t,e){this.polymer=t,this.size=t.residueCount;var i=e||{};this.directional=i.directional||!1,this.positionIterator=i.positionIterator||!1,this.subdiv=i.subdiv||1,this.smoothSheet=i.smoothSheet||!1,i.tension?this.tension=i.tension:this.tension=this.polymer.isNucleic()?.5:.9,this.interpolator=new Xl(this.subdiv,this.tension)}getAtomIterator(t,i){const r=this.polymer,n=r.structure,s=r.residueCount;let o=0,a=-1;const c=[n.getAtomProxy(),n.getAtomProxy(),n.getAtomProxy(),n.getAtomProxy()],l=[new e.Vector3,new e.Vector3,new e.Vector3,new e.Vector3];var u=n.getAtomProxy(),h=n.getAtomProxy();function d(e){var n=c[o%4];if(n.index=r.getAtomIndexByType(e,t),i&&e>0&&e<s&&"e"===n.sstruc){var a=l[o%4];return u.index=r.getAtomIndexByType(e+1,t),h.index=r.getAtomIndexByType(e-1,t),a.addVectors(u,h).add(n).add(n).multiplyScalar(.25),o+=1,a}return o+=1,n}return{size:s,next:function(){var t=d(a);return a+=1,t},get:d,reset:function(){o=0,a=-1}}}getSubdividedColor(t){var e=this.subdiv,i=this.polymer,r=(i.residueCount-1)*e*3+3;i.isCyclic&&(r+=3*e);var n=new Float32Array(r),s=this.getAtomIterator("trace"),o=t||{};o.structure=i.structure;var a=$t.getScheme(o);return this.interpolator.getColor(s,(function(t,e,i){a.atomColorToArray(t,e,i)}),n,0,i.isCyclic),{color:n}}getSubdividedPicking(){var t=this.subdiv,e=this.polymer,i=(e.residueCount-1)*t+1;e.isCyclic&&(i+=t);var r=e.structure,n=this.getAtomIterator("trace"),s=new Float32Array(i);return this.interpolator.getPicking(n,(function(t){return t.index}),s,0,e.isCyclic),{picking:new Nn(s,r)}}getSubdividedPosition(){return{position:this.getPosition()}}getSubdividedOrientation(){const t=this.getTangent(),e=this.getNormals(t);return{tangent:t,normal:e.normal,binormal:e.binormal}}getSubdividedSize(t){var e=this.subdiv,i=this.polymer,r=(i.residueCount-1)*e+1;i.isCyclic&&(r+=e);var n=new Float32Array(r),s=this.getAtomIterator("trace"),o=new ro(t);return this.interpolator.getSize(s,(function(t){return o.atomRadius(t)}),n,0,i.isCyclic),{size:n}}getPosition(){const t=this.subdiv,e=this.polymer;let i=(e.residueCount-1)*t*3+3;e.isCyclic&&(i+=3*t);const r=new Float32Array(i),n=this.positionIterator||this.getAtomIterator("trace",this.smoothSheet);return this.interpolator.getPosition(n,r,0,e.isCyclic),r}getTangent(){const t=this.subdiv,e=this.polymer;let i=(this.size-1)*t*3+3;e.isCyclic&&(i+=3*t);const r=new Float32Array(i),n=this.positionIterator||this.getAtomIterator("trace",this.smoothSheet);return this.interpolator.getTangent(n,r,0,e.isCyclic),r}getNormals(t){const e=this.subdiv,i=this.polymer,r=i.isProtein(),n=this.size;let s=(n-1)*e*3+3;i.isCyclic&&(s+=3*e);const o=new Float32Array(s),a=new Float32Array(s);if(this.directional&&!this.polymer.isCg()){const e=this.getAtomIterator("direction1"),n=this.getAtomIterator("direction2");this.interpolator.getNormalDir(e,n,t,o,a,0,i.isCyclic,r)}else this.interpolator.getNormal(n,t,o,a,0,i.isCyclic);return{normal:o,binormal:a}}}const Kl=new e.Vector3,Zl=new e.Vector3,Ql=Object.assign({radialSegments:4,capped:!1,aspectRatio:1},Ms);class Jl extends Bs{constructor(t,e={}){super(function(t,e={}){const i=l(e.radialSegments,4),r=l(e.capped,!1),n=r?i:0,s=r?i-2:0,o=t.position.length/3,a=o*i*3+2*n*3,c=2*(o-1)*i*3+2*s*3;return{position:new Float32Array(a),color:new Float32Array(a),index:v(c,a/3),normal:new Float32Array(a),picking:t.picking}}(t,e),e),this.capVertices=this.parameters.capped?this.parameters.radialSegments:0,this.capTriangles=this.parameters.capped?this.parameters.radialSegments-2:0,this.size2=t.position.length/3,t.primitiveId=be(this.size2),this.setAttributes(t),this.makeIndex()}get defaultParameters(){return Ql}setAttributes(t={}){const e=this.parameters.aspectRatio,i=this.size2,r=i-1,n=this.parameters.radialSegments,s=this.geometry.attributes;let o,a,c,l,u,h,d,m,f,p,g,y,b;t.position&&(o=t.position,a=t.normal,c=t.binormal,l=t.tangent,h=t.size,m=s.position.array,p=s.normal.array,s.position.needsUpdate=!0,s.normal.needsUpdate=!0),t.color&&(u=t.color,f=s.color.array,s.color.needsUpdate=!0),t.primitiveId&&(d=t.primitiveId,g=s.primitiveId.array,s.primitiveId.needsUpdate=!0);let _=0,x=0,v=0,w=0,A=0,S=0,C=0,P=0,I=0,k=0;const M=[],T=[],D=[],B=[],F=[],E=[];if(o)for(let t=0;t<n;++t){const i=t/n*2*Math.PI;M[t]=e*Math.cos(i),T[t]=Math.sin(i),D[t]=e*Math.cos(i-.01),B[t]=Math.sin(i-.01),F[t]=e*Math.cos(i+.01),E[t]=Math.sin(i+.01)}for(let t=0;t<i;++t){y=3*t,b=y*n,o&&l&&a&&c&&h&&(Kl.set(l[y],l[y+1],l[y+2]),x=a[y],v=a[y+1],w=a[y+2],A=c[y],S=c[y+1],C=c[y+2],P=o[y],I=o[y+1],k=o[y+2],_=h[t]);for(let e=0;e<n;++e){const i=b+3*e;if(o){const t=-_*M[e],r=_*T[e],n=-_*D[e],s=_*B[e],o=-_*F[e],a=_*E[e];m[i]=P+t*x+r*A,m[i+1]=I+t*v+r*S,m[i+2]=k+t*w+r*C,Zl.set(o*x+a*A-(n*x+s*A),o*v+a*S-(n*v+s*S),o*w+a*C-(n*w+s*C)).cross(Kl),p[i]=Zl.x,p[i+1]=Zl.y,p[i+2]=Zl.z}u&&(f[i]=u[y],f[i+1]=u[y+1],f[i+2]=u[y+2]),d&&(g[t*n+e]=d[t])}}y=0,b=3*i*n;for(let t=0;t<n;++t){const e=y+3*t,r=b+3*t;o&&l&&(m[r]=m[e],m[r+1]=m[e+1],m[r+2]=m[e+2],p[r]=l[y],p[r+1]=l[y+1],p[r+2]=l[y+2]),u&&(f[r]=f[e],f[r+1]=f[e+1],f[r+2]=f[e+2]),d&&(g[i*n+t]=g[0+t])}y=3*(i-1)*n,b=3*(i+1)*n;for(let t=0;t<n;++t){const e=y+3*t,s=b+3*t;o&&l&&(m[s]=m[e],m[s+1]=m[e+1],m[s+2]=m[e+2],p[s]=l[3*r],p[s+1]=l[3*r+1],p[s+2]=l[3*r+2]),u&&(f[s]=f[e],f[s+1]=f[e+1],f[s+2]=f[e+2]),d&&(g[(i+1)*n+t]=g[(i-1)*n+t])}}makeIndex(){const t=this.geometry.getIndex();if(!t)return void Dt.error("Index is null");const e=t.array,i=this.size2,r=i-1,n=this.capTriangles,s=this.parameters.radialSegments,o=this.parameters.radialSegments+1;let a,c;for(let t=0;t<r;++t){const i=t*s*3*2,r=t*s,n=(t+1)*s;for(let t=0;t<s;++t)c=i+3*t*2,e[c]=r+t,e[c+1]=r+(t+1)%s,e[c+2]=n+t,e[c+3]=n+t,e[c+4]=r+(t+1)%s,e[c+5]=n+(t+1)%s}const l=[0];for(let t=1;t<o/2;++t)l.push(t),s-t!==t&&l.push(s-t);c=r*s*3*2,a=i*s;for(let t=0;t<l.length-2;++t)t%2==0?(e[c+3*t+0]=a+l[t+0],e[c+3*t+1]=a+l[t+1],e[c+3*t+2]=a+l[t+2]):(e[c+3*t+0]=a+l[t+2],e[c+3*t+1]=a+l[t+1],e[c+3*t+2]=a+l[t+0]);c=r*s*3*2+3*n,a=i*s+s;for(let t=0;t<l.length-2;++t)t%2==0?(e[c+3*t+0]=a+l[t+0],e[c+3*t+1]=a+l[t+1],e[c+3*t+2]=a+l[t+2]):(e[c+3*t+0]=a+l[t+2],e[c+3*t+1]=a+l[t+1],e[c+3*t+2]=a+l[t+0])}}class tu extends ml{constructor(t,e,i){super(t,e,i),this.type="cartoon",this.parameters=Object.assign({aspectRatio:{type:"number",precision:1,max:10,min:1,rebuild:!0},subdiv:{type:"integer",max:50,min:1,rebuild:!0},radialSegments:{type:"integer",max:50,min:1,rebuild:!0},tension:{type:"number",precision:1,max:1,min:.1},capped:{type:"boolean",rebuild:!0},smoothSheet:{type:"boolean",rebuild:!0}},this.parameters),this.init(i)}init(t){var e=t||{};e.colorScheme=l(e.colorScheme,"chainname"),e.colorScale=l(e.colorScale,"RdYlBu"),e.radiusType=l(e.radiusType,"sstruc"),e.radiusScale=l(e.radiusScale,.7),e.useInteriorColor=l(e.useInteriorColor,!0),this.aspectRatio=l(e.aspectRatio,5),this.tension=l(e.tension,NaN),this.capped=l(e.capped,!0),this.smoothSheet=l(e.smoothSheet,!1),"low"===e.quality?(this.subdiv=3,this.radialSegments=6):"medium"===e.quality?this.subdiv=6:"high"===e.quality?this.subdiv=12:this.subdiv=l(e.subdiv,6),super.init(e)}getSplineParams(t){return Object.assign({subdiv:this.subdiv,tension:this.tension,directional:1!==this.aspectRatio,smoothSheet:this.smoothSheet},t)}getSpline(t){return new Yl(t,this.getSplineParams())}getAspectRatio(t){return t.isCg()?1:this.aspectRatio}getAtomRadius(t){return t.isTrace()?super.getAtomRadius(t):0}createData(t){let e=[],i=[];return this.structure.eachPolymer((t=>{if(t.residueCount<4)return;i.push(t);const r=this.getSpline(t),n=this.getAspectRatio(t),s=r.getSubdividedPosition(),o=r.getSubdividedOrientation(),a=r.getSubdividedColor(this.getColorParams()),c=r.getSubdividedPicking(),l=r.getSubdividedSize(this.getRadiusParams());e.push(new Jl(Object.assign({},s,o,a,c,l),this.getBufferParams({radialSegments:this.radialSegments,aspectRatio:n,capped:this.capped})))}),t.getSelection()),{bufferList:e,polymerList:i}}updateData(e,i){t.Debug&&Dt.time(this.type+" repr update"),e=e||{};for(var r=0,n=i.polymerList.length;r<n;++r){var s={},o=i.polymerList[r],a=this.getSpline(o),c=this.getAspectRatio(o);if(Object.assign(i.bufferList[r],{aspectRatio:c}),e.position||e.radius){var l=a.getSubdividedPosition(),u=a.getSubdividedOrientation(),h=a.getSubdividedSize(this.getRadiusParams(c));s.position=l.position,s.normal=u.normal,s.binormal=u.binormal,s.tangent=u.tangent,s.size=h.size}if(e.color){var d=a.getSubdividedColor(this.getColorParams());s.color=d.color}if(e.picking){var m=a.getSubdividedPicking();s.picking=m.picking}i.bufferList[r].setAttributes(s)}t.Debug&&Dt.timeEnd(this.type+" repr update")}setParameters(t){var e={};return t&&t.aspectRatio&&(e.radius=!0),t&&t.tension&&(e.position=!0),super.setParameters(t,e,!1),this}}Lt.add("cartoon",tu);class eu extends ml{constructor(t,e,i){super(t,e,i),this.type="contact",this.parameters=Object.assign({hydrogenBond:{type:"boolean",rebuild:!0},weakHydrogenBond:{type:"boolean",rebuild:!0},waterHydrogenBond:{type:"boolean",rebuild:!0},backboneHydrogenBond:{type:"boolean",rebuild:!0},hydrophobic:{type:"boolean",rebuild:!0},halogenBond:{type:"boolean",rebuild:!0},ionicInteraction:{type:"boolean",rebuild:!0},metalCoordination:{type:"boolean",rebuild:!0},cationPi:{type:"boolean",rebuild:!0},piStacking:{type:"boolean",rebuild:!0},filterSele:{type:"text",rebuild:!0},labelVisible:{type:"boolean",rebuild:!0},labelFixedSize:{type:"boolean",buffer:"fixedSize"},labelSize:{type:"number",precision:3,max:10,min:.001,rebuild:!0},labelUnit:{type:"select",rebuild:!0,options:{"":"",angstrom:"angstrom",nm:"nm"}},maxHydrophobicDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxHbondDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxHbondSulfurDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxHbondAccAngle:{type:"integer",max:180,min:0,rebuild:!0},maxHbondDonAngle:{type:"integer",max:180,min:0,rebuild:!0},maxHbondAccPlaneAngle:{type:"integer",max:90,min:0,rebuild:!0},maxHbondDonPlaneAngle:{type:"integer",max:90,min:0,rebuild:!0},maxPiStackingDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxPiStackingOffset:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxPiStackingAngle:{type:"integer",max:180,min:0,rebuild:!0},maxCationPiDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxCationPiOffset:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxIonicDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxHalogenBondDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},maxHalogenBondAngle:{type:"integer",max:180,min:0,rebuild:!0},maxMetalDist:{type:"number",precision:1,max:10,min:.1,rebuild:!0},refineSaltBridges:{type:"boolean",rebuild:!0},masterModelIndex:{type:"integer",max:1e3,min:-1,rebuild:!0},lineOfSightDistFactor:{type:"number",precision:1,max:10,min:0,rebuild:!0},radialSegments:!0,disableImpostor:!0},this.parameters),this.init(i)}init(t){var e=t||{};e.radiusSize=l(e.radiusSize,.05),e.useInteriorColor=l(e.useInteriorColor,!0),this.hydrogenBond=l(e.hydrogenBond,!0),this.weakHydrogenBond=l(e.weakHydrogenBond,!1),this.waterHydrogenBond=l(e.waterHydrogenBond,!1),this.backboneHydrogenBond=l(e.backboneHydrogenBond,!1),this.hydrophobic=l(e.hydrophobic,!1),this.halogenBond=l(e.halogenBond,!0),this.ionicInteraction=l(e.ionicInteraction,!0),this.metalCoordination=l(e.metalCoordination,!0),this.cationPi=l(e.cationPi,!0),this.piStacking=l(e.piStacking,!0),this.filterSele=l(e.filterSele,""),this.labelVisible=l(e.labelVisible,!1),this.labelFixedSize=l(e.labelFixedSize,!1),this.labelSize=l(e.labelSize,2),this.labelUnit=l(e.labelUnit,""),this.maxHydrophobicDist=l(e.maxHydrophobicDist,4),this.maxHbondDist=l(e.maxHbondDist,3.5),this.maxHbondSulfurDist=l(e.maxHbondSulfurDist,4.1),this.maxHbondAccAngle=l(e.maxHbondAccAngle,45),this.maxHbondDonAngle=l(e.maxHbondDonAngle,45),this.maxHbondAccPlaneAngle=l(e.maxHbondAccPlaneAngle,90),this.maxHbondDonPlaneAngle=l(e.maxHbondDonPlaneAngle,30),this.maxPiStackingDist=l(e.maxPiStackingDist,5.5),this.maxPiStackingOffset=l(e.maxPiStackingOffset,2),this.maxPiStackingAngle=l(e.maxPiStackingAngle,30),this.maxCationPiDist=l(e.maxCationPiDist,6),this.maxCationPiOffset=l(e.maxCationPiOffset,2),this.maxIonicDist=l(e.maxIonicDist,5),this.maxHalogenBondDist=l(e.maxHalogenBondDist,3.5),this.maxHalogenBondAngle=l(e.maxHalogenBondAngle,30),this.maxMetalDist=l(e.maxMetalDist,3),this.refineSaltBridges=l(e.refineSaltBridges,!0),this.masterModelIndex=l(e.masterModelIndex,-1),this.lineOfSightDistFactor=l(e.lineOfSightDistFactor,1),super.init(e)}getAtomRadius(){return 0}getContactData(t){const e={maxHydrophobicDist:this.maxHydrophobicDist,maxHbondDist:this.maxHbondDist,maxHbondSulfurDist:this.maxHbondSulfurDist,maxHbondAccAngle:this.maxHbondAccAngle,maxHbondDonAngle:this.maxHbondDonAngle,maxHbondAccPlaneAngle:this.maxHbondAccPlaneAngle,maxHbondDonPlaneAngle:this.maxHbondDonPlaneAngle,maxPiStackingDist:this.maxPiStackingDist,maxPiStackingOffset:this.maxPiStackingOffset,maxPiStackingAngle:this.maxPiStackingAngle,maxCationPiDist:this.maxCationPiDist,maxCationPiOffset:this.maxCationPiOffset,maxIonicDist:this.maxIonicDist,maxHalogenBondDist:this.maxHalogenBondDist,maxHalogenBondAngle:this.maxHalogenBondAngle,maxMetalDist:this.maxMetalDist,refineSaltBridges:this.refineSaltBridges,masterModelIndex:this.masterModelIndex,lineOfSightDistFactor:this.lineOfSightDistFactor},i={hydrogenBond:this.hydrogenBond,weakHydrogenBond:this.weakHydrogenBond,waterHydrogenBond:this.waterHydrogenBond,backboneHydrogenBond:this.backboneHydrogenBond,hydrophobic:this.hydrophobic,halogenBond:this.halogenBond,ionicInteraction:this.ionicInteraction,metalCoordination:this.metalCoordination,cationPi:this.cationPi,piStacking:this.piStacking,radius:this.radiusSize*this.radiusScale,filterSele:this.filterSele};return $n(Bn(t,e),t,i)}createData(t){const e=this.getContactData(t),i=[new jl(ir(e),this.getBufferParams({sphereDetail:1,dullInterior:!0,disableImpostor:this.disableImpostor}))];if(this.labelVisible){const t={size:this.labelSize,unit:this.labelUnit};i.push(new Cl(function(t,e){const i=fe(t.position1,t.position2),r=[],n=pe(t.position1,t.position2),s=n.length/3;for(let t=0;t<s;t++){const i=3*t,s=Math.sqrt(Math.pow(n[i],2)+Math.pow(n[i+1],2)+Math.pow(n[i+2],2));switch(e.unit){case"angstrom":r[t]=s.toFixed(2)+" "+String.fromCharCode(8491);break;case"nm":r[t]=(s/10).toFixed(2)+" nm";break;default:r[t]=s.toFixed(2)}}return{position:i,size:ge(i.length/3,e.size),color:t.color,text:r}}(e,t),this.getBufferParams({fixedSize:this.labelFixedSize})))}return{bufferList:i}}}Lt.add("contact",eu);class iu extends fl{constructor(t,e,i){super(t,e,i),this.type="dihedral",this.parameters=Object.assign({atomQuad:{type:"hidden",rebuild:!0},extendLine:{type:"boolean",rebuild:!0,default:!0},lineVisible:{type:"boolean",default:!0},planeVisible:{type:"boolean",default:!0},sectorVisible:{type:"boolean",default:!0}},this.parameters),this.init(i)}init(t){const e=t||{};e.side=l(e.side,"double"),e.opacity=l(e.opacity,.5),this.atomQuad=l(e.atomQuad,[]),this.extendLine=l(e.extendLine,!0),this.lineVisible=l(e.lineVisible,!0),this.planeVisible=l(e.planeVisible,!0),this.sectorVisible=l(e.sectorVisible,!0),super.init(e)}createData(t){if(!t.atomCount||!this.atomQuad.length)return;const i=function(t,e={}){const i=l(e.angleStep,Math.PI/90),r=t.length,n=t.length/12,s=new Float32Array(n),o=new Float32Array(3*n),a=new Array(n),c=new Array(n),u=new Array(n),h=new Array(n),d=new Array(n);let m=0,f=0,p=0;const g=Li(),y=Li(),b=Li(),_=Li(),x=Li(),v=Li(),w=Li(),A=Li(),S=Li(),C=Li(),P=Li(),I=Li(),k=Li(),M=Li(),T=Li();let D=0;for(var B=0;B<r;B+=12){if(ji(g,t,B),ji(y,t,B+3),ji(b,t,B+6),ji(_,t,B+9),Vi(x,g,y),Vi(v,b,y),0===qi(v))continue;Vi(w,_,b),Xi(A,v,.5),Ui(S,y,A),Yi(x,x),Yi(v,v),Yi(w,w),Vi(A,g,S);const r=zi(A,v)>0;Vi(A,_,S);const n=zi(A,v)<0;if(Xi(A,v,zi(v,x)),Vi(C,x,A),Xi(A,v,zi(v,w)),Vi(P,w,A),0===qi(C)||0===qi(P))continue;Yi(C,C),Yi(P,P);const l=s[D]=er(C,P);a[D]=(de*l).toFixed(1)+String.fromCharCode(176),Ni(M,C,v),Yi(M,M),zi(M,P)<0&&tr(M,M),gl(A,S,C,M,l/2),Gi(A,o,3*D);const F=Math.ceil(l/i),E=F+(e.extendLine?4:2),O=e.extendLine?36:0,$=new Float32Array(3*E),R=new Float32Array(3*E),L=new Float32Array(9*F),N=new Float32Array(O);c[D]=$,u[D]=R,h[D]=L,d[D]=N,e.extendLine&&(r?(Vi(A,g,b),Yi(A,A),Xi(I,A,1/zi(C,A)),Ui(I,I,b)):(Xi(I,x,1/zi(C,x)),Ui(I,I,y)),n?(Vi(A,_,y),Yi(A,A),Xi(k,A,1/zi(P,A)),Ui(k,k,y)):(Xi(k,w,1/zi(P,w)),Ui(k,k,b))),Ui(T,S,C);let z=0;e.extendLine?(Gi(g,$,z),Gi(I,R,z),z+=3,Gi(I,$,z),Gi(T,R,z),z+=3,Gi(I,N,0),Gi(T,N,3),Gi(r?b:y,N,6),Gi(r?b:y,N,9),Gi(T,N,12),Gi(S,N,15)):(Gi(S,$,z),Gi(T,R,z),z+=3);const V=function(t,e){const i=9*e;Gi(S,L,i),Gi(T,L,i+3),Gi(T,$,z),gl(T,S,C,M,t),Gi(T,L,i+6),Gi(T,R,z),z+=3};let U=0;for(let t=i;t<l;t+=i)V(t,U++);V(l,U++),e.extendLine?(Gi(T,$,3*(E-2)),Gi(k,R,3*(E-2)),Gi(k,$,3*(E-1)),Gi(_,R,3*(E-1)),Gi(k,N,18),Gi(T,N,21),Gi(n?y:b,N,24),Gi(n?y:b,N,27),Gi(T,N,30),Gi(S,N,33)):(Gi(T,$,z),Gi(S,R,z),z+=3),m+=3*E,f+=9*F,p+=O,D+=1}const F=D,E=new Float32Array(m),O=new Float32Array(m),$=new Float32Array(f),R=new Float32Array(p);let L=0,N=0,z=0;for(let t=0;t<F;t++){const e=c[t],i=u[t],r=h[t],n=d[t];ve(e,E,0,L,e.length),ve(i,O,0,L,i.length),ve(r,$,0,N,r.length),ve(n,R,0,z,n.length),L+=e.length,N+=r.length,z+=n.length}return{labelPosition:o.subarray(0,3*F),labelText:a.slice(0,F),linePosition1:E,linePosition2:O,planePosition:R,sectorPosition:$}}(pl(t,this.atomQuad),{extendLine:this.extendLine}),r=this.n=i.labelText.length,n=new e.Color(this.labelColor);this.textBuffer=new Cl({position:i.labelPosition,size:ge(r,this.labelSize),color:ye(r,n.r,n.g,n.b),text:i.labelText},this.getLabelBufferParams());const s=new e.Color(this.colorValue);this.lineLength=i.linePosition1.length/3;const o=ye(this.lineLength,s.r,s.g,s.b);return this.lineBuffer=new kl(nr({position1:i.linePosition1,position2:i.linePosition2,color:o,color2:o}),this.getBufferParams({linewidth:this.linewidth,visible:this.lineVisible,opacity:this.lineOpacity})),this.planeLength=i.planePosition.length/3,this.planeBuffer=new Bs({position:i.planePosition,color:ye(this.planeLength,s.r,s.g,s.b)},this.getBufferParams({visible:this.planeVisible})),this.sectorLength=i.sectorPosition.length/3,this.sectorBuffer=new Bs({position:i.sectorPosition,color:ye(this.sectorLength,s.r,s.g,s.b)},this.getBufferParams({visible:this.sectorVisible})),{bufferList:[this.textBuffer,this.lineBuffer,this.planeBuffer,this.sectorBuffer]}}updateData(t,i){super.updateData(t,i);const r={},n={},s={};if(t.color){const t=new e.Color(this.colorValue);Object.assign(r,{color:ye(this.lineLength,t.r,t.g,t.b),color2:ye(this.lineLength,t.r,t.g,t.b)}),Object.assign(n,{color:ye(this.planeLength,t.r,t.g,t.b)}),Object.assign(s,{color:ye(this.sectorLength,t.r,t.g,t.b)})}this.lineBuffer.setAttributes(r),this.planeBuffer.setAttributes(n),this.sectorBuffer.setAttributes(s)}setParameters(t){return super.setParameters(t,{},!1),!t||void 0===t.lineVisible&&void 0===t.sectorVisible&&void 0===t.planeVisible||this.setVisibility(this.visible),t&&t.lineOpacity&&this.lineBuffer.setParameters({opacity:t.lineOpacity}),t&&void 0!==t.opacity&&this.lineBuffer.setParameters({opacity:this.lineOpacity}),t&&t.linewidth&&this.lineBuffer.setParameters({linewidth:t.linewidth}),this}setVisibility(t,e){return super.setVisibility(t,!0),this.lineBuffer&&this.lineBuffer.setVisibility(this.lineVisible&&this.visible),this.planeBuffer&&this.planeBuffer.setVisibility(this.planeVisible&&this.visible),this.sectorBuffer&&this.sectorBuffer.setVisibility(this.sectorVisible&&this.visible),e||this.viewer.requestRender(),this}}Lt.add("dihedral",iu);function ru(t,e){function i(t,e){return e in t}const r=Object.assign({},t);for(const t in r)i(r,t)&&i(e,t)&&(r[t]=l(e[t],r[t]));return r}function nu(t,i){const r=new e.Color(t),n=new Float32Array(3*i);return ye(i,r.r,r.g,r.b,n),n}class su extends ml{constructor(t,e,i){super(t,e,i),this.type="dihedral-histogram",this.parameters=Object.assign({histogramsData:{type:"hidden",rebuild:!0},histogramBinBorderVisible:{type:"boolean",default:!0},scaleBinToSectorArea:{type:"boolean",rebuild:!0,default:!1}},this.parameters),this.init(i)}init(t){const e=t||{},i=ru({histogramBinBorderColor:"grey",adjacentBondArrowColor:"black",distantBondArrowColor:"magenta",frontHistogramColor:"green",backHistogramColor:"blue",opaqueMiddleDiscColor:"white"},e);Object.assign(this,i);const r=ru({histogramsData:[],histogramOpacity:1,opaqueMiddleDiscVisible:!0,opaqueMiddleDiscOpacity:1,histogramBinBorderVisible:!0,histogramBinBorderWidth:1,histogramBinBorderOpacity:.5,bondArrowVisible:!0,bondArrowWidth:2,bondArrowOpacity:1,scaleBinToSectorArea:!1},e);Object.assign(this,r),this.histogramsData.forEach((t=>{const e=ru(i,t);Object.assign(t,e)})),e.side=l(e.side,"double"),e.opacity=l(e.opacity,.5),e.radiusType=l(e.radiusType,"size"),e.radiusSize=l(e.radiusSize,.15),super.init(e)}getHistogramBinBorderBufferParameters(){return this.getBufferParams({linewidth:this.histogramBinBorderWidth,visible:this.histogramBinBorderVisible,opacity:this.histogramBinBorderOpacity})}getBondArrowsBufferParameters(){return this.getBufferParams({linewidth:this.bondArrowWidth,visible:this.bondArrowVisible,opacity:this.bondArrowOpacity})}getOpaqueMiddleDiscBufferParameters(){return this.getBufferParams({visible:this.opaqueMiddleDiscVisible,opacity:this.opaqueMiddleDiscOpacity})}getHistogramBufferParameters(){return this.getBufferParams({visible:!0,opacity:this.histogramOpacity,side:"double"})}createData(t){if(!t.atomCount||!this.histogramsData.length)return;this.histogramsData.forEach((e=>e.atomPositions=pl(t,[e.atomQuad])));const e=this.scaleBinToSectorArea?function(t){return Math.sqrt(t)}:function(t){return t};function i(t){const e=t.map((t=>t.length)),i=new Float32Array(Ce(e));let r=0;for(let e=0;e<t.length;e++)i.set(t[e],r),r+=t[e].length;return i}function r(t,e){return new kl({position1:i(t.map((t=>t.startPoints))),position2:i(t.map((t=>t.endPoints))),color:i(t.map((t=>t.startColors))),color2:i(t.map((t=>t.endColors)))},e)}function n(t,e){return new Bs({position:i(t.map((t=>t.triangles))),color:i(t.map((t=>t.triangleColors)))},e)}this.histogramsData.forEach((t=>t.histogram360Scaled=t.histogram360.map(e)));const s=[];for(let t=0;t<this.histogramsData.length;t++){let e,i=this.histogramsData[t];i.histogram360.length>=3&&(e=ou(i)),void 0!==e&&s.push(e)}return this.frontHistogramBinBordersBuffer=r(s.map((t=>t.frontHistogramBinBorders)),this.getHistogramBinBorderBufferParameters()),this.backHistogramBinBordersBuffer=r(s.map((t=>t.backHistogramBinBorders)),this.getHistogramBinBorderBufferParameters()),this.adjacentBondArrowsBuffer=r(s.map((t=>t.adjacentBondArrows)),this.getBondArrowsBufferParameters()),this.distantBondArrowsBuffer=r(s.map((t=>t.distantBondArrows)),this.getBondArrowsBufferParameters()),this.opaqueMiddleDiscBuffer=n(s.map((t=>t.opaqueMiddleDisc)),this.getOpaqueMiddleDiscBufferParameters()),this.frontHistogramBuffer=n(s.map((t=>t.frontHistogram)),this.getHistogramBufferParameters()),this.backHistogramBuffer=n(s.map((t=>t.backHistogram)),this.getHistogramBufferParameters()),{bufferList:[].concat(this.frontHistogramBinBordersBuffer,this.backHistogramBinBordersBuffer,this.adjacentBondArrowsBuffer,this.distantBondArrowsBuffer,this.opaqueMiddleDiscBuffer,this.frontHistogramBuffer,this.backHistogramBuffer)}}setParameters(t){return super.setParameters(t,{},!1),t&&void 0!==t.histogramBinBorderVisible&&this.setVisibility(this.visible),this}setVisibility(t,e){return super.setVisibility(t,!0),this.frontHistogramBinBordersBuffer&&this.frontHistogramBinBordersBuffer.setVisibility(this.histogramBinBorderVisible),this.backHistogramBinBordersBuffer&&this.backHistogramBinBordersBuffer.setVisibility(this.histogramBinBorderVisible),e||this.viewer.requestRender(),this}}function ou(t){const e=t.atomPositions,i=t.histogram360Scaled,r=i.length<=180?360:2*i.length,n={triangles:new Float32Array(3*r*3),triangleColors:nu(t.opaqueMiddleDiscColor,3*r)},s={triangles:new Float32Array(3*i.length*3),triangleColors:nu(t.frontHistogramColor,3*i.length)},o={triangles:new Float32Array(3*i.length*3),triangleColors:nu(t.backHistogramColor,3*i.length)},a={startPoints:new Float32Array(3*i.length),endPoints:new Float32Array(3*i.length),startColors:nu(t.histogramBinBorderColor,i.length),endColors:nu(t.histogramBinBorderColor,i.length)},c={startPoints:new Float32Array(3*i.length),endPoints:new Float32Array(3*i.length),startColors:nu(t.histogramBinBorderColor,i.length),endColors:nu(t.histogramBinBorderColor,i.length)},l={startPoints:new Float32Array(6),endPoints:new Float32Array(6),startColors:nu(t.adjacentBondArrowColor,i.length),endColors:nu(t.adjacentBondArrowColor,i.length)},u={startPoints:new Float32Array(6),endPoints:new Float32Array(6),startColors:nu(t.distantBondArrowColor,i.length),endColors:nu(t.distantBondArrowColor,i.length)},h=Li(),d=Li(),m=Li(),f=Li(),p=Li(),g=Li(),y=Li(),b=Li(),_=Li(),x=Li(),v=Li(),w=Li(),A=Li(),S=Li(),C=Li(),P=Li(),I=[h,d,m,f];for(let t=0;t<I.length;t++)ji(I[t],e,3*t);if(Vi(p,h,d),Vi(g,m,d),Vi(b,f,m),0===qi(g))return;if(Xi(C,g,.5),Ui(_,d,C),Yi(p,p),Yi(g,g),Yi(b,b),tr(y,g),Xi(C,y,zi(y,p)),Vi(x,p,C),Xi(C,g,zi(g,b)),Vi(v,b,C),0===qi(x)||0===qi(v))return;Yi(x,x),Yi(v,v);const k=Math.acos(zi(x,v));Ni(w,y,x),Ni(A,g,v),Yi(w,w),Yi(A,A);let M=k;zi(w,v)<0&&(M=-k),Ui(S,_,x);const T=Math.max.apply(null,i),D=2*Math.PI/i.length;function B(t,e,r,n,s){const o=3*e*3;Gi(_,t,o);const a=Number(i[e])/T;Xi(C,r,a),Xi(P,n,a),gl(S,_,C,P,e*s),Gi(S,t,o+3),gl(S,_,C,P,(e+1)*s),Gi(S,t,o+6)}function F(t,e,r,n,s){ve(_,l.startPoints,0,3*r,_.length),gl(C,_,n,s,0+0*D),ve(C,l.endPoints,0,3*r,_.length),ve(_,u.startPoints,0,3*r,_.length),gl(C,_,n,s,M),ve(C,u.endPoints,0,3*r,_.length);for(let t=0;t<i.length;t++)ve(_,e.startPoints,0,3*t,_.length),gl(C,_,n,s,0+D*t),ve(C,e.endPoints,0,3*t,C.length);for(let e=0;e<i.length;e++)B(t.triangles,e,n,s,D)}const E=2*Math.PI/r;for(let t=0;t<r;t++){const e=3*t*3;Gi(_,n.triangles,e),gl(S,_,x,w,t*E),Gi(S,n.triangles,e+3),gl(S,_,x,w,(t+1)*E),Gi(S,n.triangles,e+6)}return Xi(C,g,-.01),Ui(_,_,C),F(s,a,0,x,w),Xi(C,g,.02),Ui(_,_,C),F(o,c,1,v,A),{opaqueMiddleDisc:n,frontHistogram:s,backHistogram:o,frontHistogramBinBorders:a,backHistogramBinBorders:c,adjacentBondArrows:l,distantBondArrows:u}}Lt.add("dihedral-histogram",su);class au extends fl{constructor(t,e,i){super(t,e,i),this.type="distance",this.parameters=Object.assign({radialSegments:!0,openEnded:!0,disableImpostor:!0,labelUnit:{type:"select",rebuild:!0,options:{"":"",angstrom:"angstrom",nm:"nm"}},useCylinder:{type:"boolean",rebuild:!0},atomPair:{type:"hidden",rebuild:!0}},this.parameters),this.init(i)}init(t){const e=t||{};e.linewidth=l(e.linewidth,5),e.radiusType=l(e.radiusType,"size"),e.radiusSize=l(e.radiusSize,.2),this.labelUnit=l(e.labelUnit,""),this.useCylinder=l(e.useCylinder,!1),this.atomPair=l(e.atomPair,[]),super.init(e)}getDistanceData(t,e){let i=e.length;const r=new Array(i);let n=new Float32Array(3*i);const s=new gt,o=new gt,a=new lo,c=t.getAtomProxy(),l=t.getAtomProxy();let u=0;const h=t.getAtomSet();e.forEach(((e,i)=>{let d=e[0],m=e[1];if("number"==typeof d&&Number.isInteger(d)&&"number"==typeof m&&Number.isInteger(m)){if(!h.get(d)||!h.get(m))return void(u+=1);c.index=d,l.index=m}else{s.setString(d),o.setString(m);var f=t.getAtomIndices(s),p=t.getAtomIndices(o);if(!f.length||!p.length)return void(u+=1);c.index=f[0],l.index=p[0]}a.addBond(c,l,1),i-=u;var g=c.distanceTo(l);switch(this.labelUnit){case"angstrom":r[i]=g.toFixed(2)+" "+String.fromCharCode(8491);break;case"nm":r[i]=(g/10).toFixed(2)+" nm";break;default:r[i]=g.toFixed(2)}var y=3*i;n[y+0]=(c.x+l.x)/2,n[y+1]=(c.y+l.y)/2,n[y+2]=(c.z+l.z)/2})),u>0&&(i-=u,n=n.subarray(0,3*i));var d=new Sr(a.count,!0);return{text:r,position:n,bondSet:d,bondStore:a}}getBondData(t,e,i){const r=t.getBondData(this.getBondParams(e,i));return r.picking&&(r.picking=new Gn(r.picking.array,r.picking.structure,i.bondStore)),r}createData(t){if(!t.atomCount||!this.atomPair.length)return;const i=this.atomPair.length,r=new e.Color(this.labelColor),n=this.getDistanceData(t,this.atomPair);this.textBuffer=new Cl({position:n.position,size:ge(i,this.labelSize),color:ye(i,r.r,r.g,r.b),text:n.text},this.getLabelBufferParams());const s={bondSet:n.bondSet,bondStore:n.bondStore},o=this.getBondData(t,{position:!0,color:!0,picking:!0,radius:this.useCylinder},s);return this.useCylinder?this.distanceBuffer=new jl(o,this.getBufferParams({openEnded:this.openEnded,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0})):this.distanceBuffer=new kl(rr(o),this.getBufferParams({linewidth:this.linewidth,visible:this.lineVisible,opacity:this.lineOpacity})),{bondSet:n.bondSet,bondStore:n.bondStore,position:n.position,bufferList:[this.textBuffer,this.distanceBuffer]}}updateData(t,e){super.updateData(t,e);const i={bondSet:e.bondSet,bondStore:e.bondStore},r=this.getBondData(e.sview,t,i),n={};t&&!t.color||Object.assign(n,{color:r.color,color2:r.color2}),t&&!t.radius||Object.assign(n,{radius:r.radius}),this.distanceBuffer.setAttributes(n)}setParameters(t){return super.setParameters(t,{},!1),this.useCylinder||(t&&t.lineOpacity&&this.distanceBuffer.setParameters({opacity:t.lineOpacity}),t&&void 0!==t.opacity&&this.distanceBuffer.setParameters({opacity:this.lineOpacity}),t&&t.linewidth&&this.distanceBuffer.setParameters({linewidth:t.linewidth})),this}}function cu(t){return 2*(t.position.length/3)*3}Lt.add("distance",au);const lu=Object.assign({scale:1,color:"grey"},Ms);class uu extends Ds{constructor(t,i={}){super({position:new Float32Array(cu(t)),color:new Float32Array(cu(t))},i),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag";const r=new e.Color(this.parameters.color),n=this.geometry.attributes;ye(cu(t)/3,r.r,r.g,r.b,n.color.array),this.setAttributes(t)}get defaultParameters(){return lu}setAttributes(t={}){const e=this.geometry.attributes;let i,r,n;t.position&&t.vector&&(i=t.position,r=t.vector,n=e.position.array,e.position.needsUpdate=!0);const s=this.size/2,o=this.parameters.scale;if(i&&r)for(let t=0;t<s;t++){const e=2*t*3,s=3*t;n[e+0]=i[s+0],n[e+1]=i[s+1],n[e+2]=i[s+2],n[e+3]=i[s+0]+r[s+0]*o,n[e+4]=i[s+1]+r[s+1]*o,n[e+5]=i[s+2]+r[s+2]*o}}}class hu extends ml{constructor(t,e,i){super(t,e,i),this.type="helixorient",this.parameters=Object.assign({sphereDetail:!0,disableImpostor:!0},this.parameters),this.init(i)}init(t){const e=t||{};e.colorScheme=l(e.colorScheme,"sstruc"),e.radiusType=l(e.radiusType,"size"),e.radiusSize=l(e.radiusSize,.15),e.radiusScale=l(e.radiusScale,1),e.useInteriorColor=l(e.useInteriorColor,!0),super.init(e)}createData(t){const e=[],i=[];return this.structure.eachPolymer((t=>{if(t.residueCount<4)return;i.push(t);const r=new po(t),n=r.getPosition(),s=r.getColor(this.getColorParams()),o=r.getSize(this.getRadiusParams()),a=r.getPicking();e.push(new Da({position:n.center,color:s.color,radius:o.size,picking:a.picking},this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0})),new uu({position:n.center,vector:n.axis},this.getBufferParams({color:"skyblue",scale:1})),new uu({position:n.center,vector:n.resdir},this.getBufferParams({color:"lightgreen",scale:1})))}),t.getSelection()),{bufferList:e,polymerList:i}}updateData(e,i){t.Debug&&Dt.time(this.type+" repr update"),e=e||{};for(let t=0,r=i.polymerList.length;t<r;++t){const r=3*t,n={},s=i.polymerList[t],o=new po(s);if(e.position){const t=o.getPosition();Object.assign(n,{position:t.center}),i.bufferList[r+1].setAttributes({position:t.center,vector:t.axis}),i.bufferList[r+2].setAttributes({position:t.center,vector:t.resdir})}i.bufferList[r].setAttributes(n)}t.Debug&&Dt.timeEnd(this.type+" repr update")}}Lt.add("helixorient",hu);class du extends Hl{constructor(t,e,i){super(t,e,i),this.type="licorice",this.parameters=Object.assign({},this.parameters,{aspectRatio:null})}init(t){var e=t||{};e.aspectRatio=1,super.init(e)}}Lt.add("licorice",du),zt.add("shader/HyperballStickImpostor.vert","\nattribute vec3 mapping;\nattribute float radius;\nattribute float radius2;\nattribute vec3 position1;\nattribute vec3 position2;\nvarying mat4 matrix_near;\nvarying vec4 prime1;\nvarying vec4 prime2;\nvarying float vRadius;\nvarying float vRadius2;\n#ifdef PICKING\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\nattribute vec3 color2;\nvarying vec3 vColor1;\nvarying vec3 vColor2;\n#endif\nuniform float shrink;\nuniform mat4 modelViewProjectionMatrix;\nuniform mat4 modelViewProjectionMatrixInverse;\nvoid main(){\nvRadius = radius;\nvRadius2 = radius2;\nvec4 spaceposition;\nvec3 position_atom1;\nvec3 position_atom2;\nvec4 vertex_position;\n#ifdef PICKING\nvPickingColor = unpackColor( primitiveId );\n#else\nvColor1 = color;\nvColor2 = color2;\n#endif\nfloat radius1 = radius;\nposition_atom1 = position1;\nposition_atom2 = position2;\nfloat distance = distance( position_atom1, position_atom2 );\nspaceposition.z = mapping.z * distance;\nif (radius1 > radius2) {\nspaceposition.y = mapping.y * 1.5 * radius1;\nspaceposition.x = mapping.x * 1.5 * radius1;\n} else {\nspaceposition.y = mapping.y * 1.5 * radius2;\nspaceposition.x = mapping.x * 1.5 * radius2;\n}\nspaceposition.w = 1.0;\nvec4 e3 = vec4( 1.0 );\nvec3 e1, e1_temp, e2, e2_temp;\ne3.xyz = normalize(position_atom1-position_atom2);\nif (e3.z == 0.0) { e3.z = 0.0000000000001;}\nif ( (position_atom1.x - position_atom2.x) == 0.0) { position_atom1.x += 0.001;}\nif ( (position_atom1.y - position_atom2.y) == 0.0) { position_atom1.y += 0.001;}\nif ( (position_atom1.z - position_atom2.z) == 0.0) { position_atom1.z += 0.001;}\nvec4 focus = vec4( 1.0 );\nfocus.x = ( position_atom1.x*position_atom1.x - position_atom2.x*position_atom2.x +\n( radius2*radius2 - radius1*radius1 )*e3.x*e3.x/shrink )/(2.0*(position_atom1.x - position_atom2.x));\nfocus.y = ( position_atom1.y*position_atom1.y - position_atom2.y*position_atom2.y +\n( radius2*radius2 - radius1*radius1 )*e3.y*e3.y/shrink )/(2.0*(position_atom1.y - position_atom2.y));\nfocus.z = ( position_atom1.z*position_atom1.z - position_atom2.z*position_atom2.z +\n( radius2*radius2 - radius1*radius1 )*e3.z*e3.z/shrink )/(2.0*(position_atom1.z - position_atom2.z));\ne1.x = 1.0;\ne1.y = 1.0;\ne1.z = ( (e3.x*focus.x + e3.y*focus.y + e3.z*focus.z) - e1.x*e3.x - e1.y*e3.y)/e3.z;\ne1_temp = e1 - focus.xyz;\ne1 = normalize(e1_temp);\ne2_temp = e1.yzx * e3.zxy - e1.zxy * e3.yzx;\ne2 = normalize(e2_temp);\nmat3 R= mat3( e1.xyz, e2.xyz, e3.xyz );\nvertex_position.xyz = R * spaceposition.xyz;\nvertex_position.w = 1.0;\nvertex_position.x += (position_atom1.x+position_atom2.x) / 2.0;\nvertex_position.y += (position_atom1.y+position_atom2.y) / 2.0;\nvertex_position.z += (position_atom1.z+position_atom2.z) / 2.0;\ngl_Position = modelViewProjectionMatrix * vertex_position;\nvec4 i_near, i_far;\nvec4 near = gl_Position;\nnear.z = 0.0 ;\nnear = modelViewProjectionMatrixInverse * near;\ni_near = near;\nvec4 far = gl_Position;\nfar.z = far.w ;\ni_far = modelViewProjectionMatrixInverse * far;\nprime1 = vec4( position_atom1 - (position_atom1 - focus.xyz)*shrink, 1.0 );\nprime2 = vec4( position_atom2 - (position_atom2 - focus.xyz)*shrink, 1.0 );\nfloat Rsquare = (radius1*radius1/shrink) - (\n(position_atom1.x - focus.x)*(position_atom1.x - focus.x) +\n(position_atom1.y - focus.y)*(position_atom1.y - focus.y) +\n(position_atom1.z - focus.z)*(position_atom1.z - focus.z)\n);\nfocus.w = Rsquare;\nmatrix_near = mat4( i_near, i_far, focus, e3 );\ngl_Position.z = 0.0;\n}"),zt.add("shader/HyperballStickImpostor.frag","#define STANDARD\n#define IMPOSTOR\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 interiorColor;\nuniform float interiorDarkening;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float clipNear;\nuniform float shrink;\nuniform mat4 modelViewMatrix;\nuniform mat4 modelViewProjectionMatrix;\nuniform mat4 modelViewMatrixInverseTranspose;\nuniform mat4 projectionMatrix;\nvarying mat4 matrix_near;\nvarying vec4 prime1;\nvarying vec4 prime2;\nvarying float vRadius;\nvarying float vRadius2;\n#ifdef PICKING\nuniform float objectId;\nvarying vec3 vPickingColor;\n#else\nvarying vec3 vColor1;\nvarying vec3 vColor2;\n#include common\n#include fog_pars_fragment\n#include bsdfs\n#include lights_pars_begin\n#include lights_physical_pars_fragment\n#endif\nbool interior = false;\nfloat calcClip( vec4 cameraPos ){\nreturn dot( cameraPos, vec4( 0.0, 0.0, 1.0, clipNear - 0.5 ) );\n}\nfloat calcClip( vec3 cameraPos ){\nreturn calcClip( vec4( cameraPos, 1.0 ) );\n}\nfloat calcDepth( in vec3 cameraPos ){\nvec2 clipZW = cameraPos.z * projectionMatrix[2].zw + projectionMatrix[3].zw;\nreturn 0.5 + 0.5 * clipZW.x / clipZW.y;\n}\nstruct Ray {\nvec3 origin ;\nvec3 direction ;\n};\nbool cutoff_plane (vec3 M, vec3 cutoff, vec3 x3){\nfloat a = x3.x;\nfloat b = x3.y;\nfloat c = x3.z;\nfloat d = -x3.x*cutoff.x-x3.y*cutoff.y-x3.z*cutoff.z;\nfloat l = a*M.x+b*M.y+c*M.z+d;\nif (l<0.0) {return true;}\nelse{return false;}\n}\nvec3 isect_surf(Ray r, mat4 matrix_coef){\nvec4 direction = vec4(r.direction, 0.0);\nvec4 origin = vec4(r.origin, 1.0);\nfloat a = dot(direction,(matrix_coef*direction));\nfloat b = dot(origin,(matrix_coef*direction));\nfloat c = dot(origin,(matrix_coef*origin));\nfloat delta =b*b-a*c;\ngl_FragColor.a = 1.0;\nif (delta<0.0){\ndiscard;\n}\nfloat t1 =(-b-sqrt(delta))/a;\nreturn r.origin+t1*r.direction;\n}\nvec3 isect_surf2(Ray r, mat4 matrix_coef){\nvec4 direction = vec4(r.direction, 0.0);\nvec4 origin = vec4(r.origin, 1.0);\nfloat a = dot(direction,(matrix_coef*direction));\nfloat b = dot(origin,(matrix_coef*direction));\nfloat c = dot(origin,(matrix_coef*origin));\nfloat delta =b*b-a*c;\ngl_FragColor.a = 1.0;\nif (delta<0.0){\ndiscard;\n}\nfloat t2 =(-b+sqrt(delta))/a;\nreturn r.origin+t2*r.direction;\n}\nRay primary_ray(vec4 near1, vec4 far1){\nvec3 near=near1.xyz/near1.w;\nvec3 far=far1.xyz/far1.w;\nreturn Ray(near,far-near);\n}\nfloat update_z_buffer(vec3 M, mat4 ModelViewP){\nfloat depth1;\nvec4 Ms=(ModelViewP*vec4(M,1.0));\nreturn depth1=(1.0+Ms.z/Ms.w)/2.0;\n}\nvoid main(){\nfloat radius = max( vRadius, vRadius2 );\nvec4 i_near, i_far, focus;\nvec3 e3, e1, e1_temp, e2;\ni_near = vec4(matrix_near[0][0],matrix_near[0][1],matrix_near[0][2],matrix_near[0][3]);\ni_far = vec4(matrix_near[1][0],matrix_near[1][1],matrix_near[1][2],matrix_near[1][3]);\nfocus = vec4(matrix_near[2][0],matrix_near[2][1],matrix_near[2][2],matrix_near[2][3]);\ne3 = vec3(matrix_near[3][0],matrix_near[3][1],matrix_near[3][2]);\ne1.x = 1.0;\ne1.y = 1.0;\ne1.z = ( (e3.x*focus.x + e3.y*focus.y + e3.z*focus.z) - e1.x*e3.x - e1.y*e3.y)/e3.z;\ne1_temp = e1 - focus.xyz;\ne1 = normalize(e1_temp);\ne2 = normalize(cross(e1,e3));\nvec4 equation = focus;\nfloat shrinkfactor = shrink;\nfloat t1 = -1.0/(1.0-shrinkfactor);\nfloat t2 = 1.0/(shrinkfactor);\nvec4 colonne1, colonne2, colonne3, colonne4;\nmat4 mat;\nvec3 equation1 = vec3(t2,t2,t1);\nfloat A1 = - e1.x*equation.x - e1.y*equation.y - e1.z*equation.z;\nfloat A2 = - e2.x*equation.x - e2.y*equation.y - e2.z*equation.z;\nfloat A3 = - e3.x*equation.x - e3.y*equation.y - e3.z*equation.z;\nfloat A11 = equation1.x*e1.x*e1.x + equation1.y*e2.x*e2.x + equation1.z*e3.x*e3.x;\nfloat A21 = equation1.x*e1.x*e1.y + equation1.y*e2.x*e2.y + equation1.z*e3.x*e3.y;\nfloat A31 = equation1.x*e1.x*e1.z + equation1.y*e2.x*e2.z + equation1.z*e3.x*e3.z;\nfloat A41 = equation1.x*e1.x*A1 + equation1.y*e2.x*A2 + equation1.z*e3.x*A3;\nfloat A22 = equation1.x*e1.y*e1.y + equation1.y*e2.y*e2.y + equation1.z*e3.y*e3.y;\nfloat A32 = equation1.x*e1.y*e1.z + equation1.y*e2.y*e2.z + equation1.z*e3.y*e3.z;\nfloat A42 = equation1.x*e1.y*A1 + equation1.y*e2.y*A2 + equation1.z*e3.y*A3;\nfloat A33 = equation1.x*e1.z*e1.z + equation1.y*e2.z*e2.z + equation1.z*e3.z*e3.z;\nfloat A43 = equation1.x*e1.z*A1 + equation1.y*e2.z*A2 + equation1.z*e3.z*A3;\nfloat A44 = equation1.x*A1*A1 + equation1.y*A2*A2 + equation1.z*A3*A3 - equation.w;\ncolonne1 = vec4(A11,A21,A31,A41);\ncolonne2 = vec4(A21,A22,A32,A42);\ncolonne3 = vec4(A31,A32,A33,A43);\ncolonne4 = vec4(A41,A42,A43,A44);\nmat = mat4(colonne1,colonne2,colonne3,colonne4);\nRay ray = primary_ray(i_near,i_far) ;\nvec3 M;\nM = isect_surf(ray, mat);\nif (cutoff_plane(M, prime1.xyz, -e3) || cutoff_plane(M, prime2.xyz, e3)){ discard; }\nvec4 M1 = vec4(M,1.0);\nvec4 M2 = mat*M1;\nvec3 _normal = ( modelViewMatrixInverseTranspose * M2 ).xyz;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix) ;\n#ifdef NEAR_CLIP\nif( calcClip( modelViewMatrix * vec4( M, 1.0 ) ) > 0.0 ){\nM = isect_surf2(ray, mat);\nif( calcClip( modelViewMatrix * vec4( M, 1.0 ) ) > 0.0 )\ndiscard;\ninterior = true;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix) ;\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( clipNear - 0.5 ) ) ) + ( 0.0000001 / radius ) );\n}\n}else if( gl_FragDepthEXT <= 0.0 ){\nM = isect_surf2(ray, mat);\ninterior = true;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix);\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / radius );\n}\n}\n#else\nif( gl_FragDepthEXT <= 0.0 ){\nM = isect_surf2(ray, mat);\ninterior = true;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix) ;\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / radius );\n}\n}\n#endif\nif (cutoff_plane(M, prime1.xyz, -e3) || cutoff_plane(M, prime2.xyz, e3)){ discard; }\nif (gl_FragDepthEXT < 0.0)\ndiscard;\nif (gl_FragDepthEXT > 1.0)\ndiscard;\nfloat distance_ratio = ((M.x-prime2.x)*e3.x + (M.y-prime2.y)*e3.y +(M.z-prime2.z)*e3.z) /\ndistance(prime2.xyz,prime1.xyz);\n#ifdef PICKING\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 vViewPosition = -( modelViewMatrix * vec4( M, 1.0 ) ).xyz;\nvec3 vNormal = _normal;\nvec3 vColor;\nif( distance_ratio>0.5 ){\nvColor = vColor1;\n}else{\nvColor = vColor2;\n}\nvec4 diffuseColor = vec4( diffuse, opacity );\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\nvec3 totalEmissiveLight = emissive;\n#include color_fragment\n#include roughnessmap_fragment\n#include metalnessmap_fragment\nvec3 normal = normalize( vNormal );\nvec3 nonPerturbedNormal = normal;\n#include lights_physical_fragment\n#include lights_fragment_begin\n#include lights_fragment_end\nvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;\nif( interior ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const mu=new Float32Array([-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,-1,1,-1,1,1,-1,1,1,1,-1,1,1]),fu=new Uint16Array([0,1,2,0,2,3,1,5,6,1,6,2,4,6,5,4,7,6,0,7,4,0,3,7,0,5,1,0,4,5,3,2,6,3,6,7]);class pu extends Pa{constructor(t,e={}){super("v3",t,e)}get mapping(){return mu}get mappingIndices(){return fu}get mappingIndicesSize(){return 36}get mappingSize(){return 8}get mappingItemSize(){return 3}}const gu=Object.assign({shrink:.14},Ms),yu=Object.assign({shrink:{uniform:!0}},Ts);class bu extends pu{constructor(t,i={}){super(t,i),this.parameterTypes=yu,this.isImpostor=!0,this.vertexShader="HyperballStickImpostor.vert",this.fragmentShader="HyperballStickImpostor.frag",this.addUniforms({modelViewProjectionMatrix:{value:new e.Matrix4},modelViewProjectionMatrixInverse:{value:new e.Matrix4},modelViewMatrixInverseTranspose:{value:new e.Matrix4},shrink:{value:this.parameters.shrink}}),this.addAttributes({position1:{type:"v3",value:null},position2:{type:"v3",value:null},color2:{type:"c",value:null},radius:{type:"f",value:null},radius2:{type:"f",value:null}}),this.setAttributes(t),this.makeMapping()}get defaultParameters(){return gu}}Object.assign({disableImpostor:!1},El,gu);const _u=class{constructor(t,e={}){return!Mt||e&&e.disableImpostor?(t.radius=function(t,e){const i=t.length,r=new Float32Array(i);for(let n=0;n<i;n++)r[n]=Math.min(t[n],e[n]);return r}(t.radius,t.radius2),new $l(t,e)):new bu(t,e)}};class xu extends du{constructor(t,e,i){super(t,e,i),this.type="hyperball",this.parameters=Object.assign({shrink:{type:"number",precision:3,max:1,min:.001,buffer:!0}},this.parameters,{multipleBond:null,bondSpacing:null})}init(t){var e=t||{};e.radiusScale=l(e.radiusScale,.2),e.radiusType=l(e.radiusType,"vdw"),e.useInteriorColor=l(e.useInteriorColor,!0),this.shrink=l(e.shrink,.12),super.init(e)}getBondParams(t,e){return t&&!t.radius||(e=Object.assign({radius2:!0},e)),super.getBondParams(t,e)}createData(t){var e=new Da(t.getAtomData(this.getAtomParams()),this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0}));return this.__center=new Float32Array(3*t.bondCount),{bufferList:[e,new _u(t.getBondData(this.getBondParams()),this.getBufferParams({shrink:this.shrink,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0}))]}}updateData(t,e){var i=e.sview.getAtomData(this.getAtomParams()),r=e.sview.getBondData(this.getBondParams()),n={},s={};if(!t||t.position){Object.assign(n,{position:i.position});var o=r.position1,a=r.position2;Object.assign(s,{position:fe(o,a,this.__center),position1:o,position2:a})}t&&!t.color||(Object.assign(n,{color:i.color}),Object.assign(s,{color:r.color,color2:r.color2})),t&&!t.radius||(Object.assign(n,{radius:i.radius}),Object.assign(s,{radius:r.radius,radius2:r.radius2})),e.bufferList[0].setAttributes(n),e.bufferList[1].setAttributes(s)}}Lt.add("hyperball",xu);class vu{constructor(t,e={},i=""){this.type=t,this.text=e,this.format=i,this.errorLogged=!1}atomLabel(t){let e;switch(this.type){case"atomname":e=t.atomname;break;case"atomindex":e=`${t.index}`;break;case"occupancy":e=t.occupancy.toFixed(2);break;case"bfactor":e=t.bfactor.toFixed(2);break;case"serial":e=`${t.serial}`;break;case"element":e=t.element;break;case"atom":e=`${t.atomname}|${t.index}`;break;case"resname":e=t.resname;break;case"resno":e=`${t.resno}`;break;case"res":e=`${Hr[t.resname.toUpperCase()]||t.resname}${t.resno}`;break;case"residue":const i=Hr[t.resname.toUpperCase()];e=i&&!t.inscode?`${i}${t.resno}`:`[${t.resname}]${t.resno}${t.inscode}`;break;case"text":e=this.text[t.index];break;case"format":try{e=n.sprintf(this.format,t)}catch(t){this.errorLogged||(this.errorLogged=!0,console.log(t.message))}break;default:e=t.qualifiedName()}return void 0===e?"":e}}vu.types={"":"",atomname:"atom name",atomindex:"atom index",occupancy:"occupancy",bfactor:"b-factor",serial:"serial",element:"element",atom:"atom name + index",resname:"residue name",resno:"residue no",res:"one letter code + no",residue:"[residue name] + no + inscode",text:"text",format:"format",qualified:"qualified name"};class wu extends ml{constructor(t,e,i){super(t,e,i),this.type="label",this.parameters=Object.assign({labelType:{type:"select",options:vu.types,rebuild:!0},labelText:{type:"hidden",rebuild:!0},labelFormat:{type:"text",rebuild:!0},labelGrouping:{type:"select",options:{atom:"atom",residue:"residue"},rebuild:!0},fontFamily:{type:"select",options:{"sans-serif":"sans-serif",monospace:"monospace",serif:"serif"},buffer:!0},fontStyle:{type:"select",options:{normal:"normal",italic:"italic"},buffer:!0},fontWeight:{type:"select",options:{normal:"normal",bold:"bold"},buffer:!0},xOffset:{type:"number",precision:1,max:20,min:-20,buffer:!0},yOffset:{type:"number",precision:1,max:20,min:-20,buffer:!0},zOffset:{type:"number",precision:1,max:20,min:-20,buffer:!0},attachment:{type:"select",options:{"bottom-left":"bottom-left","bottom-center":"bottom-center","bottom-right":"bottom-right","middle-left":"middle-left","middle-center":"middle-center","middle-right":"middle-right","top-left":"top-left","top-center":"top-center","top-right":"top-right"},rebuild:!0},showBorder:{type:"boolean",buffer:!0},borderColor:{type:"color",buffer:!0},borderWidth:{type:"number",precision:2,max:.3,min:0,buffer:!0},showBackground:{type:"boolean",rebuild:!0},backgroundColor:{type:"color",buffer:!0},backgroundMargin:{type:"number",precision:2,max:2,min:0,rebuild:!0},backgroundOpacity:{type:"range",step:.01,max:1,min:0,buffer:!0},fixedSize:{type:"boolean",buffer:!0}},this.parameters,{side:null,flatShaded:null,wireframe:null,linewidth:null,roughness:null,metalness:null,diffuse:null}),this.init(i)}init(t){const e=t||{};this.labelType=l(e.labelType,"res"),this.labelText=l(e.labelText,{}),this.labelFormat=l(e.labelFormat,""),this.labelGrouping=l(e.labelGrouping,"atom"),this.fontFamily=l(e.fontFamily,"sans-serif"),this.fontStyle=l(e.fontStyle,"normal"),this.fontWeight=l(e.fontWeight,"bold"),this.xOffset=l(e.xOffset,0),this.yOffset=l(e.yOffset,0),this.zOffset=l(e.zOffset,.5),this.attachment=l(e.attachment,"bottom-left"),this.showBorder=l(e.showBorder,!1),this.borderColor=l(e.borderColor,"lightgrey"),this.borderWidth=l(e.borderWidth,.15),this.showBackground=l(e.showBackground,!1),this.backgroundColor=l(e.backgroundColor,"lightgrey"),this.backgroundMargin=l(e.backgroundMargin,.5),this.backgroundOpacity=l(e.backgroundOpacity,1),this.fixedSize=l(e.fixedSize,!1),super.init(e)}getTextData(t,e){const i=this.getAtomParams(e),r=new vu(this.labelType,this.labelText,this.labelFormat);let n,s,o,a,c,l,u;if("atom"===this.labelGrouping){const c=t.getAtomData(i);n=c.position,s=c.radius,o=c.color,e&&!e.text||(a=[],t.eachAtom((t=>a.push(r.atomLabel(t)))))}else if("residue"===this.labelGrouping){e&&!e.position||(c=[]),e&&!e.color||(u=[]),e&&!e.radius||(l=[]),e&&!e.text||(a=[]),i.colorParams&&(i.colorParams.structure=t.getStructure());const h=$t.getScheme(i.colorParams),d=new ro(i.radiusParams),m=t.getAtomProxy();let f=0;t.eachResidue((t=>{const i=3*f;t.isProtein()||t.isNucleic()?(m.index=t.traceAtomIndex,e&&!e.position||m.positionToArray(c,i)):(m.index=t.atomOffset,e&&!e.position||t.positionToArray(c,i)),e&&!e.color||h.atomColorToArray(m,u,i),e&&!e.radius||(l[f]=d.atomRadius(m)),e&&!e.text||a.push(r.atomLabel(m)),++f})),e&&!e.position||(n=new Float32Array(c)),e&&!e.color||(o=new Float32Array(u)),e&&!e.radius||(s=new Float32Array(l))}return{position:n,size:s,color:o,text:a}}createData(t){return{bufferList:[new Cl(this.getTextData(t,{position:!0,color:!0,radius:!0,text:!0}),this.getBufferParams({fontFamily:this.fontFamily,fontStyle:this.fontStyle,fontWeight:this.fontWeight,xOffset:this.xOffset,yOffset:this.yOffset,zOffset:this.zOffset,attachment:this.attachment,showBorder:this.showBorder,borderColor:this.borderColor,borderWidth:this.borderWidth,showBackground:this.showBackground,backgroundColor:this.backgroundColor,backgroundMargin:this.backgroundMargin,backgroundOpacity:this.backgroundOpacity,fixedSize:this.fixedSize}))]}}updateData(t,e){e.bufferList[0].setAttributes(this.getTextData(e.sview,t))}getAtomRadius(){return 0}}function Au(t){const e=t.getAtomSet(),i=t.getBondSet(),r=t.getBondProxy();return i.forEach((function(t){r.index=t,e.clear(r.atomIndex1),e.clear(r.atomIndex2)})),e}Lt.add("label",wu);class Su extends ml{constructor(t,e,i){super(t,e,i),this.type="line",this.parameters=Object.assign({multipleBond:{type:"select",rebuild:!0,options:{off:"off",symmetric:"symmetric",offset:"offset"}},bondSpacing:{type:"number",precision:2,max:2,min:.5},linewidth:{type:"integer",max:50,min:1,buffer:!0},lines:{type:"boolean",rebuild:!0},crosses:{type:"select",rebuild:!0,options:{off:"off",lone:"lone",all:"all"}},crossSize:{type:"number",precision:2,max:2,min:.1}},this.parameters,{flatShaded:null,side:null,wireframe:null,roughness:null,metalness:null}),this.init(i)}init(t){var e=t||{};this.multipleBond=l(e.multipleBond,"off"),this.bondSpacing=l(e.bondSpacing,1),this.linewidth=l(e.linewidth,2),this.lines=l(e.lines,!0),this.crosses=l(e.crosses,"lone"),this.crossSize=l(e.crossSize,.4),super.init(e)}getAtomRadius(t){return.1}getBondParams(t,e){return e=Object.assign({multipleBond:this.multipleBond,bondSpacing:this.bondSpacing,radiusParams:{type:"size",size:.1,scale:1}},e),super.getBondParams(t,e)}_crossData(t,e){if(t&&!t.position&&!t.color)return;const i={};"lone"===this.crosses&&Object.assign(i,{atomSet:Au(e)});const r=e.getAtomData(this.getAtomParams(t,i)),n={},s=r.position,o=r.color,a=r.picking,c=(s||o).length,l=3*c;let u=new Float32Array(0),h=new Float32Array(0),d=new Float32Array(0),m=new Float32Array(0),f=0,p=new Float32Array(0);t&&!t.position||(u=n.position1=new Float32Array(l),h=n.position2=new Float32Array(l),f=this.crossSize/2),t&&!t.color||(d=n.color=new Float32Array(l),m=n.color2=new Float32Array(l)),t&&!t.picking||(p=new Float32Array(3*r.picking.array.length));for(let e=0;e<c;e++){const i=3*e,r=3*i;if(!t||t.position){const t=s[i],e=s[i+1],n=s[i+2];u[r]=t-f,u[r+1]=e,u[r+2]=n,h[r]=t+f,h[r+1]=e,h[r+2]=n,u[r+3]=t,u[r+4]=e-f,u[r+5]=n,h[r+3]=t,h[r+4]=e+f,h[r+5]=n,u[r+6]=t,u[r+7]=e,u[r+8]=n-f,h[r+6]=t,h[r+7]=e,h[r+8]=n+f}if(!t||t.color){const t=r+9;for(let e=r;e<t;e+=3)d[e]=m[e]=o[i],d[e+1]=m[e+1]=o[i+1],d[e+2]=m[e+2]=o[i+2]}t&&!t.picking||(p[i]=p[i+1]=p[i+2]=a.array[e])}return t&&!t.picking||(n.picking=new Nn(p,a.structure)),n}createData(t){const e={position:!0,color:!0,picking:!0},i=[];if(this.lines){const r=t.getBondData(this.getBondParams(e)),n=new kl(r,this.getBufferParams({linewidth:this.linewidth}));i.push(n)}if("off"!==this.crosses){const r=new kl(this._crossData(e,t),this.getBufferParams({linewidth:this.linewidth}));i.push(r)}return{bufferList:i}}updateData(t,e){let i=0;if(this.lines){const r=e.sview.getBondData(this.getBondParams(t)),n={};t&&!t.position||Object.assign(n,{position1:r.position1,position2:r.position2}),t&&!t.color||Object.assign(n,{color:r.color,color2:r.color2}),e.bufferList[i++].setAttributes(n)}if("off"!==this.crosses){const r=this._crossData(t,e.sview),n={};t&&!t.position||Object.assign(n,{position1:r.position1,position2:r.position2}),t&&!t.color||Object.assign(n,{color:r.color,color2:r.color2}),e.bufferList[i++].setAttributes(n)}}setParameters(t){var e={};return t&&(t.bondSpacing||t.crossSize)&&Object.assign(e,{position:!0}),super.setParameters(t,e,!1),this}}function Cu(t,e,i,r,n){const s=new(r=r||Int32Array)(t*e*i*(n=n||1));function o(t,r,s){return((t*e+r)*i+s)*n}return{data:s,index:o,set:function(t,e,i,...r){const a=o(t,e,i);for(let t=0;t<n;++t)s[a+t]=r[t]},toArray:function(t,e,i,r=[],a=0){const c=o(t,e,i);for(let t=0;t<n;++t)r[a+t]=s[c+t]},fromArray:function(t,e,i,r,a=0){const c=o(t,e,i);for(let t=0;t<n;++t)s[c+t]=r[a+t]},copy:function(t){s.set(t.data)}}}function Pu(t,e,i){var r=vs(e),n=Ei(t);0===t.length&&(n[0].set([0,0,0]),n[1].set([0,0,0]));var s,o,a,c,l,u,h,d,m,f,p,g,y,b,_,x=n[0],v=n[1];function w(t,e,i,n,w){s=e||1.4,o=i||2,g=w||!0;var A=0;for(var S in r)A=Math.max(A,S);var C=ws(x,v,A,o,t?s:0);c=C.dim[0],l=C.dim[1],u=C.dim[2],h=C.matrix,d=C.tran,o=C.scaleFactor,m={},f={},I(t),p=s*o,a=n||s/o,y=new Uint8Array(c*l*u),t&&(b=new Float64Array(c*l*u)),g&&(_=new Int32Array(c*l*u))}var A=1,S=2,C=4,P=[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])];function I(t){var e,i,n,a,c,l,u,h,d,p;for(var g in r)if(e=parseFloat(g),!m[g]){for(l=(u=t?(e+s)*o+.5:e*o+.5)*u,h=Math.floor(u)+1,d=new Int32Array(h*h),p=0,i=0;i<h;++i)for(n=0;n<h;++n)(a=i*i+n*n)>l?d[p]=-1:(c=Math.sqrt(l-a),d[p]=Math.floor(c)),++p;f[g]=h,m[g]=d}}function k(i){var r,n,s,a,h,p,b,x,v,w,S,C,P,I,k,M,T,D,B=3*i,F=i;r=Math.floor(.5+o*(t[B]+d[0])),n=Math.floor(.5+o*(t[B+1]+d[1])),s=Math.floor(.5+o*(t[B+2]+d[2]));var E,O=e[F],$=m[O],R=0,L=l*u,N=f[O];for(w=0;w<N;++w)for(S=0;S<N;++S){if(-1!==(E=$[R]))for(M=-1;M<2;++M)for(T=-1;T<2;++T)for(D=-1;D<2;++D)if(0!==M&&0!==T&&0!==D)for(b=M*w,v=D*S,C=0;C<=E;++C)if(I=n+(x=C*T),k=s+v,!((P=r+b)<0||I<0||k<0||P>=c||I>=l||k>=u)){var z=P*L+I*u+k;if(g)if(y[z]&A){if(y[z]&A){var V=_[z];V!==B&&b*b+x*x+v*v<(a=r+b-Math.floor(.5+o*(t[V]+d[0])))*a+(h=n+x-Math.floor(.5+o*(t[V+1]+d[1])))*h+(p=s+v-Math.floor(.5+o*(t[V+2]+d[2])))*p&&(_[z]=i)}}else y[z]|=A,_[z]=i;else y[z]|=A}R++}}function M(e){var i,r;for(console.time("EDTSurface fillvoxels"),i=0,r=y.length;i<r;++i)y[i]=0,e&&(b[i]=-1),g&&(_[i]=-1);for(i=0,r=t.length/3;i<r;++i)k(i);for(i=0,r=y.length;i<r;++i)y[i]&A&&(y[i]|=S);console.timeEnd("EDTSurface fillvoxels")}function T(i){var r,n,s,a,h,p,b,x,v,w,A,C,P,I,k,M,T,D,B,F=3*i,E=i,O=0;r=Math.floor(.5+o*(t[F]+d[0])),n=Math.floor(.5+o*(t[F+1]+d[1])),s=Math.floor(.5+o*(t[F+2]+d[2]));var $=e[E],R=l*u;for(P=0,B=f[$];P<B;++P)for(I=0;I<B;++I){if(-1!==m[$][O])for(M=-1;M<2;++M)for(T=-1;T<2;++T)for(D=-1;D<2;++D)if(0!==M&&0!==T&&0!==D)for(b=M*P,v=D*I,k=0;k<=m[$][O];++k)if(A=n+(x=k*T),C=s+v,!((w=r+b)<0||A<0||C<0||w>=c||A>=l||C>=u)){var L=w*R+A*u+C;if(y[L]&S){if(g){var N=_[L];b*b+x*x+v*v<(a=Math.floor(.5+o*(t[N]+d[0])))*a+(h=Math.floor(.5+o*(t[N+1]+d[1])))*h+(p=Math.floor(.5+o*(t[N+2]+d[2])))*p&&(_[L]=i)}}else y[L]|=S,g&&(_[L]=i)}O++}}function D(){var t,e,i,r;console.time("EDTSurface fastdistancemap");var n,s=Cu(c,l,u,Uint16Array,3),o=l*u,h=p*p,d=0;for(t=0;t<c;++t)for(e=0;e<l;++e)for(i=0;i<u;++i)y[n=t*o+e*u+i]&=~S,y[n]&A&&y[n]&C&&(s.set(t,e,i,t,e,i),b[n]=0,y[n]|=S,d+=1);var m=new Int32Array(3*d),f=0,x=new Int32Array(3*d),v=0;for(t=0;t<c;++t)for(e=0;e<l;++e)for(i=0;i<u;++i)y[n=t*o+e*u+i]&C&&(m[f]=t,m[f+1]=e,m[f+2]=i,f+=3,y[n]&=~C);do{for(v=B(m,s,f,x),f=0,t=0,r=v;t<r;t+=3)n=o*x[t]+u*x[t+1]+x[t+2],y[n]&=~C,b[n]<=1.0404*h&&(m[f]=x[t],m[f+1]=x[t+1],m[f+2]=x[t+2],f+=3)}while(f>0);var w,P=a*a,I=new Uint16Array(3);for(t=0;t<c;++t)for(e=0;e<l;++e)for(i=0;i<u;++i)y[n=t*o+e*u+i]&=~C,y[n]&A&&(y[n]&S&&!(y[n]&S&&b[n]>=P)||(y[n]|=C,g&&y[n]&S&&(s.toArray(t,e,i,I),w=I[0]*o+I[1]*u+I[2],_[n]=_[w])));console.timeEnd("EDTSurface fastdistancemap")}function B(t,e,i,r){var n,s,o,a,h,d,m,f,p,g,_,x,v=new Uint16Array(3),w=0;if(0===i)return w;var I=-1,k=-1,M=-1,T=l*u;for(m=0,p=i;m<p;m+=3)for(n=t[m],s=t[m+1],o=t[m+2],e.toArray(n,s,o,v),f=0;f<6;++f)I=n+(x=P[f])[0],k=s+x[1],M=o+x[2],I<c&&I>-1&&k<l&&k>-1&&M<u&&M>-1&&(y[_=I*T+u*k+M]&A&&!(y[_]&S)?(e.fromArray(I,k,M,v),g=(a=I-v[0])*a+(h=k-v[1])*h+(d=M-v[2])*d,b[_]=g,y[_]|=S,y[_]|=C,r[w]=I,r[w+1]=k,r[w+2]=M,w+=3):y[_]&A&&y[_]&S&&(g=(a=I-v[0])*a+(h=k-v[1])*h+(d=M-v[2])*d)<b[_]&&(e.fromArray(I,k,M,v),b[_]=g,y[_]&C||(y[_]|=C,r[w]=I,r[w+1]=k,r[w+2]=M,w+=3)));for(m=0,p=i;m<p;m+=3)for(n=t[m],s=t[m+1],o=t[m+2],e.toArray(n,s,o,v),f=6;f<18;f++)I=n+(x=P[f])[0],k=s+x[1],M=o+x[2],I<c&&I>-1&&k<l&&k>-1&&M<u&&M>-1&&(y[_=I*T+u*k+M]&A&&!(y[_]&S)?(e.fromArray(I,k,M,v),g=(a=I-v[0])*a+(h=k-v[1])*h+(d=M-v[2])*d,b[_]=g,y[_]|=S,y[_]|=C,r[w]=I,r[w+1]=k,r[w+2]=M,w+=3):y[_]&A&&y[_]&S&&(g=(a=I-v[0])*a+(h=k-v[1])*h+(d=M-v[2])*d)<b[_]&&(e.fromArray(I,k,M,v),b[_]=g,y[_]&C||(y[_]|=C,r[w]=I,r[w+1]=k,r[w+2]=M,w+=3)));for(m=0,p=i;m<p;m+=3)for(n=t[m],s=t[m+1],o=t[m+2],e.toArray(n,s,o,v),f=18;f<26;f++)I=n+(x=P[f])[0],k=s+x[1],M=o+x[2],I<c&&I>-1&&k<l&&k>-1&&M<u&&M>-1&&(y[_=I*T+u*k+M]&A&&!(y[_]&S)?(e.fromArray(I,k,M,v),g=(a=I-v[0])*a+(h=k-v[1])*h+(d=M-v[2])*d,b[_]=g,y[_]|=S,y[_]|=C,r[w]=I,r[w+1]=k,r[w+2]=M,w+=3):y[_]&A&&y[_]&S&&(g=(a=I-v[0])*a+(h=k-v[1])*h+(d=M-v[2])*d)<b[_]&&(e.fromArray(I,k,M,v),b[_]=g,y[_]&C||(y[_]|=C,r[w]=I,r[w+1]=k,r[w+2]=M,w+=3)));return w}this.getVolume=function(e,r,n,s,o){console.time("EDTSurface.getVolume");var a="vws"!==e;w(a,r,n,s,o),M(a),function(){var t,e,i,r=l*u;for(t=0;t<c;++t)for(e=0;e<u;++e)for(i=0;i<l;++i){var n=t*r+i*u+e;if(y[n]&A)for(var s=0;s<26;){var o=t+P[s][0],a=e+P[s][2],h=i+P[s][1];if(o>-1&&o<c&&h>-1&&h<l&&a>-1&&a<u&&!(y[o*r+h*u+a]&A)){y[n]|=C;break}s++}}}(),"ms"!==e&&"ses"!==e||D(),"ses"===e&&(I(!1),function(){var e,i;for(e=0,i=y.length;e<i;++e)y[e]&=~S;for(e=0,i=t.length/3;e<i;++e)T(e)}()),function(t){var e,i=y.length;if("vws"===t)for(e=0;e<i;++e)y[e]&=~C,y[e]=y[e]&S?1:0;else if("ms"===t)for(e=0;e<i;++e)y[e]&=~S,y[e]&C&&(y[e]|=S),y[e]&=~C,y[e]=y[e]&S?1:0;else if("ses"===t)for(e=0;e<i;++e)y[e]&C&&y[e]&S?y[e]&=~C:y[e]&C&&!(y[e]&S)&&(y[e]|=S),y[e]=y[e]&S?1:0;else if("sas"===t)for(e=0;e<i;++e)y[e]&=~C,y[e]=y[e]&S?1:0}(e);for(var h=0,d=_.length;h<d;++h)_[h]=i[_[h]];return console.timeEnd("EDTSurface.getVolume"),{data:y,nx:u,ny:l,nz:c,atomindex:_}},this.getSurface=function(t,e,i,r,n,s,o){var a=this.getVolume(t,e,i,r,n);return new Ss(a.data,a.nx,a.ny,a.nz,a.atomindex).getSurface(1,s,void 0,h,o)}}function Iu(t,e,i,r,n,s,o){o=Math.max(.1,o);var a=t.length,c=n[0],l=n[1],u=n[2],h=s[0],d=s[1],m=s[2];function f(t,e){return Math.floor((t-e)/o)}for(var p,g,y,b=f(h,c)+1,_=f(d,l)+1,x=f(m,u)+1,v=b*_*x,w=_*x,A=[],S=0;S<a;S++){var C=(p=t[S],g=e[S],y=i[S],(f(p,c)*_+f(g,l))*x+f(y,u));void 0===A[C]?A[C]=[S]:A[C].push(S)}var P=new Uint32Array(v),I=new Uint16Array(v),k=new Uint32Array(a),M=0,T=0;for(S=0;S<v;S++){var D=P[S]=M,B=A[S];if(void 0!==B)for(var F=0;F<B.length;F++)k[M]=B[F],M++;var E=M-D;I[S]=E,E>T&&(T=E)}return{neighbourListLength:27*T+1,withinRadii:function(n,s,o,a,h){for(var d=0,m=f(n,c),p=f(s,l),g=f(o,u),y=Math.max(0,m-1),v=Math.max(0,p-1),A=Math.max(0,g-1),S=Math.min(b,m+2),C=Math.min(_,p+2),M=Math.min(x,g+2),T=y;T<S;++T)for(var D=T*w,B=v;B<C;++B)for(var F=B*x,E=A;E<M;++E)for(var O=D+F+E,$=P[O],R=$+I[O],L=$;L<R;L++){var N=k[L],z=t[N]-n,V=e[N]-s,U=i[N]-o,j=r[N]+a;z*z+V*V+U*U<=j*j&&(h[d++]=k[L])}h[d]=-1}}}function ku(t,e,i){const r=e.length,n=new Float32Array(r),s=new Float32Array(r),o=new Float32Array(r);for(let e=0;e<r;e++){const i=3*e;n[e]=t[i],s[e]=t[i+1],o[e]=t[i+2]}let a=Ei(t);0===t.length&&(a[0].set([0,0,0]),a[1].set([0,0,0]));const c=a[0],u=a[1];let h,d,m,f,p,g,y,b,_,x,v,w,A,S,C,P,I,k,M=-1;const T=new Float32Array([0,0,0]),D=new Float32Array([0,0,0]),B=new Float32Array([0,0,0]),F=new Float32Array([0,0,0]);let E;function O(t,i,a,T){f=l(t,1.4),p=l(i,2),g=l(a,!0),y=l(T,30),h=new Float32Array(r),d=new Float32Array(r);for(let t=0;t<h.length;++t){var D=e[t]+f;h[t]=D,d[t]=D*D}m=0;for(let t=0;t<h.length;++t)h[t]>m&&(m=h[t]);!function(){const t=ws(c,u,m,p,0);p=t.scaleFactor,b=t.dim,_=t.matrix,E=Math.max(5,2+Math.floor(f*p)),x=ge(b[0]*b[1]*b[2],-1001),v=new Int32Array(x.length),w=new Float32Array(b[0]),A=new Float32Array(b[1]),S=new Float32Array(b[2]),$(w,c[0],1/p),$(A,c[1],1/p),$(S,c[2],1/p)}(),function(){var t=0,e=2*Math.PI/y;P=new Float32Array(y),C=new Float32Array(y);for(var i=0;i<y;i++)P[i]=Math.cos(t),C[i]=Math.sin(t),t+=e}(),I=Iu(n,s,o,h,c,u,2.01*m),k=new Int32Array(I.neighbourListLength),M=-1}function $(t,e,i){for(let r=0;r<t.length;r++)t[r]=e+i*r}function R(t,e,i,r,n){let s;if(-1!==M){if(s=M,s!==r&&s!==n&&L(s,t,e,i))return s;M=-1}var o=0;for(s=k[o];s>=0;){if(s!==r&&s!==n&&L(s,t,e,i))return M=s,s;s=k[++o]}return M=-1,-1}function L(e,i,r,n){var s=3*e,o=d[e],a=t[s]-i,c=t[s+1]-r,l=t[s+2]-n;return a*a+c*c+l*l<o}function N(){for(var t=0;t<r;t++){var e=n[t],i=s[t],a=o[t],l=h[t],u=d[t];I.withinRadii(e,i,a,l,k);for(var m=Math.ceil(l*p),f=Math.floor(p*(e-c[0])),y=Math.floor(p*(i-c[1])),_=Math.floor(p*(a-c[2])),C=Math.max(0,f-m),P=Math.max(0,y-m),M=Math.max(0,_-m),T=Math.min(b[0],f+m+2),D=Math.min(b[1],y+m+2),B=Math.min(b[2],_+m+2),F=C;F<T;F++)for(var E=w[F]-e,O=b[1]*b[2]*F,$=P;$<D;$++)for(var L=A[$]-i,N=E*E+L*L,z=O+b[2]*$,V=M;V<B;V++){var U=S[V]-a,j=N+U*U;if(j<u){var G=V+z;x[G]<0&&(x[G]=-x[G]);var H=Math.sqrt(j),q=l/H,W=E*q,X=L*q,Y=U*q;if(-1===R(W+=e,X+=i,Y+=a,t,-1)){var K=l-H;K<x[G]&&(x[G]=K,g&&(v[G]=t))}}}}}function z(t,e){var i=h[t],r=h[e],a=T[0]=n[e]-n[t],l=T[1]=s[e]-s[t],u=T[2]=o[e]-o[t],d=a*a+l*l+u*u,m=Math.sqrt(d),f=i*((i*i+m*m-r*r)/(2*i*m));Yi(T,T),function(t,e){t[0]=t[1]=t[2]=1,0!==e[0]?t[0]=(e[1]+e[2])/-e[0]:0!==e[1]?t[1]=(e[0]+e[2])/-e[1]:0!==e[2]&&(t[2]=(e[0]+e[1])/-e[2])}(B,T),Yi(B,B),Ni(F,T,B),Yi(F,F);var _=Math.sqrt(i*i-f*f);Xi(B,B,_),Xi(F,F,_),Xi(T,T,f),D[0]=T[0]+n[t],D[1]=T[1]+s[t],D[2]=T[2]+o[t],M=-1;for(var I=E,k=0;k<y;k++){var O=P[k],$=C[k],L=D[0]+O*B[0]+$*F[0],N=D[1]+O*B[1]+$*F[1],z=D[2]+O*B[2]+$*F[2];if(-1===R(L,N,z,t,e))for(var V=Math.floor(p*(L-c[0])),U=Math.floor(p*(N-c[1])),j=Math.floor(p*(z-c[2])),G=Math.max(0,V-I),H=Math.max(0,U-I),q=Math.max(0,j-I),W=Math.min(b[0],V+I+2),X=Math.min(b[1],U+I+2),Y=Math.min(b[2],j+I+2),K=G;K<W;K++){a=L-w[K];for(var Z=b[1]*b[2]*K,Q=H;Q<X;Q++)for(var J=a*a+(l=N-A[Q])*l,tt=Z+b[2]*Q,et=q;et<Y;et++){d=J+(u=z-S[et])*u;var it=et+tt,rt=x[it];if(rt>0&&d<rt*rt&&(x[it]=Math.sqrt(d),g)){const i=a*T[0]+l*T[1]+u*T[2];v[it]=i<0?e:t}}}}}function V(t,e,a){console.time("AVSurface.getVolume"),console.time("AVSurface.init"),O(t,e,a),console.timeEnd("AVSurface.init"),console.time("AVSurface.projectPoints"),N(),console.timeEnd("AVSurface.projectPoints"),console.time("AVSurface.projectTorii"),function(){for(var t=0;t<r;t++){I.withinRadii(n[t],s[t],o[t],h[t],k);for(var e=0,i=k[e];i>=0;)t<i&&z(t,i),i=k[++e]}}(),console.timeEnd("AVSurface.projectTorii"),function(){for(var t=0;t<x.length;t++)x[t]<0&&(x[t]=0)}(),function(){for(var t=0;t<v.length;t++)v[t]=i[v[t]]}(),console.timeEnd("AVSurface.getVolume")}this.getSurface=function(t,e,i,r,n,s,o){return V(e,i,n),new Ss(x,b[2],b[1],b[0],v).getSurface(e,!1,void 0,_,o)}}Lt.add("line",Su),Object.assign(Pu,{__deps:[ws,vs,Ss,Ei,Cu]}),Object.assign(ku,{__deps:[ws,Ss,ge,Ei,Xi,Ni,Yi,Iu,l]}),Ot.add("molsurf",(function(t,e){const i=t.data.args,r=t.data.params;if(i&&r){const t=new("av"===r.type?ku:Pu)(i.coordList,i.radiusList,i.indexList).getSurface(r.type,r.probeRadius,r.scaleFactor,r.cutoff,!0,r.smooth,r.contour),n=[t.position.buffer,t.index.buffer];t.normal&&n.push(t.normal.buffer),t.atomindex&&n.push(t.atomindex.buffer);e({sd:t,p:r},n)}}),[Pu,ku]);class Mu{constructor(t){this.structure=t}_getAtomData(t){return this.structure.getAtomData({what:{position:!0,radius:!0,index:!0},radiusParams:l(t.radiusParams,{type:"vdw",scale:1})})}_makeSurface(t,e){var i=new As(e.name,"",t);return i.info.type=e.type,i.info.probeRadius=e.probeRadius,i.info.scaleFactor=e.scaleFactor,i.info.smooth=e.smooth,i.info.cutoff=e.cutoff,i}getSurface(t){const e=t||{},i=this._getAtomData(t),r=i.position,n=i.radius,s=i.index,o=new("av"===e.type?ku:Pu)(r,n,s).getSurface(e.type,e.probeRadius,e.scaleFactor,e.cutoff,!0,e.smooth,e.contour);return this._makeSurface(o,e)}getSurfaceWorker(t,e){const i=Object.assign({},t);if(window.hasOwnProperty("Worker")){void 0===this.worker&&(this.worker=new Ti("molsurf"));const r=this._getAtomData(t),n=r.position,s=r.radius,o=r.index,a={args:{coordList:n,radiusList:s,indexList:o},params:i},c=[n.buffer,s.buffer,o.buffer];this.worker.post(a,c,(t=>{e(this._makeSurface(t.data.sd,i))}),(t=>{console.warn("MolecularSurface.getSurfaceWorker error - trying without worker",t),this.worker.terminate(),this.worker=void 0;const r=this.getSurface(i);e(r)}))}else{const t=this.getSurface(i);e(t)}}dispose(){this.worker&&this.worker.terminate()}}class Tu extends ml{constructor(t,e,i){super(t,e,i),this.type="surface",this.parameters=Object.assign({surfaceType:{type:"select",rebuild:!0,options:{vws:"vws",sas:"sas",ms:"ms",ses:"ses",av:"av"}},probeRadius:{type:"number",precision:1,max:20,min:0,rebuild:!0},smooth:{type:"integer",precision:1,max:10,min:0,rebuild:!0},scaleFactor:{type:"number",precision:1,max:5,min:0,rebuild:!0},cutoff:{type:"number",precision:2,max:50,min:0,rebuild:!0},contour:{type:"boolean",rebuild:!0},background:{type:"boolean",rebuild:!0},opaqueBack:{type:"boolean",buffer:!0},filterSele:{type:"text",rebuild:!0},colorVolume:{type:"hidden"},useWorker:{type:"boolean",rebuild:!0}},this.parameters,{radius:null,scale:null}),this.__infoList=[],this.structure.signals.refreshed.add((()=>{this.__forceNewMolsurf=!0})),this.toBePrepared=!0,this.init(i)}init(t){const e=t||{};e.colorScheme=l(e.colorScheme,"uniform"),e.colorValue=l(e.colorValue,14540253),e.disablePicking=l(e.disablePicking,!0),this.surfaceType=l(e.surfaceType,"ms"),this.probeRadius=l(e.probeRadius,1.4),this.smooth=l(e.smooth,2),this.scaleFactor=l(e.scaleFactor,2),this.cutoff=l(e.cutoff,0),this.contour=l(e.contour,!1),this.background=l(e.background,!1),this.opaqueBack=l(e.opaqueBack,!0),this.filterSele=l(e.filterSele,""),this.colorVolume=l(e.colorVolume,void 0),this.useWorker=l(e.useWorker,!0),super.init(t)}prepareData(t,i,r){let n=this.__infoList[i];if(n||(n={},this.__infoList[i]=n),n.molsurf&&n.sele===t.selection.string)r(i);else{if(this.filterSele){const n=t.structure.getView(new gt(this.filterSele)),s=n.boundingBox.getSize(new e.Vector3),o=Math.max(s.x,s.y,s.z),a=t.getAtomSetWithinPoint(n.center,o/2+6);if(0===(t=t.getView(new gt(t.getAtomSetWithinSelection(a,3).toSeleString()))).atomCount)return void r(i)}n.sele=t.selection.string,n.molsurf=new Mu(t);const s=this.getSurfaceParams(),o=t=>{n.surface=t,r(i)};this.useWorker?n.molsurf.getSurfaceWorker(s,o):o(n.molsurf.getSurface(s))}}prepare(t){if((this.__forceNewMolsurf||this.__sele!==this.selection.string||this.__surfaceParams!==JSON.stringify(this.getSurfaceParams()))&&(this.__infoList.forEach((t=>{t&&t.molsurf&&t.molsurf.dispose()})),this.__infoList.length=0),0===this.structureView.atomCount)return void t();const e=()=>{this.__sele=this.selection.string,this.__surfaceParams=JSON.stringify(this.getSurfaceParams()),this.__forceNewMolsurf=!1,t()},i="default"===this.assembly?this.defaultAssembly:this.assembly,r=this.structure.biomolDict[i];r?r.partList.forEach(((t,i)=>{const n=t.getView(this.structureView);this.prepareData(n,i,(t=>{t===r.partList.length-1&&e()}))})):this.prepareData(this.structureView,0,e)}createData(t,e){const i=this.__infoList[e],r=i.surface;if(!r)return;const n={position:r.getPosition(),color:r.getColor(this.getColorParams()),index:r.getFilteredIndex(this.filterSele,t)},s=[];if(r.contour){const t=new Rs(n,this.getBufferParams({wireframe:!1}));s.push(t)}else{Object.assign(n,{normal:r.getNormal(),picking:r.getPicking(t.getStructure())});const e=new Fs(n,this.getBufferParams({background:this.background,opaqueBack:this.opaqueBack,dullInterior:!1}));if("double"==this.getBufferParams().side){const t=new $s(e);s.push(t)}else s.push(e)}return{bufferList:s,info:i}}updateData(t,e){const i={};if(t.position||t.radius)return this.__forceNewMolsurf=!0,void this.build();t.color&&(i.color=e.info.surface.getColor(this.getColorParams())),t.index&&(i.index=e.info.surface.getFilteredIndex(this.filterSele,e.sview)),e.bufferList[0].setAttributes(i)}setParameters(t,e={},i){return t&&t.filterSele&&(e.index=!0),t&&void 0!==t.colorVolume&&(e.color=!0),t&&t.wireframe&&(t.contour||void 0===t.contour&&this.contour)&&(t.wireframe=!1),super.setParameters(t,e,i),this}getSurfaceParams(t={}){return Object.assign({type:this.surfaceType,probeRadius:this.probeRadius,scaleFactor:this.scaleFactor,smooth:this.smooth&&!this.contour,cutoff:this.cutoff,contour:this.contour,useWorker:this.useWorker,radiusParams:this.getRadiusParams()},t)}getColorParams(){const t=super.getColorParams();return t.volume=this.colorVolume,t}getAtomRadius(){return 0}clear(){super.clear()}dispose(){this.__infoList.forEach((t=>{t&&t.molsurf&&t.molsurf.dispose()})),this.__infoList.length=0,super.dispose()}}Lt.add("surface",Tu);class Du extends ml{constructor(t,e,i){super(t,e,i),this.type="point",this.parameters=Object.assign({pointSize:{type:"number",precision:1,max:100,min:0,buffer:!0},sizeAttenuation:{type:"boolean",buffer:!0},sortParticles:{type:"boolean",rebuild:!0},useTexture:{type:"boolean",buffer:!0},alphaTest:{type:"range",step:.001,max:1,min:0,buffer:!0},forceTransparent:{type:"boolean",buffer:!0},edgeBleach:{type:"range",step:.001,max:1,min:0,buffer:!0}},this.parameters,{flatShaded:null,wireframe:null,linewidth:null,side:null,roughness:null,metalness:null}),this.init(i)}init(t){var e=t||{};this.pointSize=l(e.pointSize,1),this.sizeAttenuation=l(e.sizeAttenuation,!0),this.sortParticles=l(e.sortParticles,!1),this.useTexture=l(e.useTexture,!1),this.alphaTest=l(e.alphaTest,.5),this.forceTransparent=l(e.forceTransparent,!1),this.edgeBleach=l(e.edgeBleach,0),super.init(e)}createData(t){var e=t.getAtomData(this.getAtomParams({position:!0,color:!0,picking:!0}));return{bufferList:[new Oa(e,this.getBufferParams({pointSize:this.pointSize,sizeAttenuation:this.sizeAttenuation,sortParticles:this.sortParticles,useTexture:this.useTexture,alphaTest:this.alphaTest,forceTransparent:this.forceTransparent,edgeBleach:this.edgeBleach}))]}}updateData(t,e){var i=e.sview.getAtomData(this.getAtomParams(t)),r={};t&&!t.position||Object.assign(r,{position:i.position}),t&&!t.color||Object.assign(r,{color:i.color}),e.bufferList[0].setAttributes(r)}getAtomRadius(){return.1}}Lt.add("point",Du),zt.add("shader/Ribbon.vert","#define STANDARD\nuniform float clipNear;\nuniform vec3 clipCenter;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\nattribute vec3 dir;\nattribute float size;\n#ifdef PICKING\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\n#include color_pars_vertex\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#endif\n#endif\n#include common\nvoid main(void){\n#ifdef PICKING\nvPickingColor = unpackColor( primitiveId );\n#else\n#include color_vertex\n#include beginnormal_vertex\n#include defaultnormal_vertex\n#ifndef FLAT_SHADED\nvNormal = normalize( transformedNormal );\n#endif\n#endif\n#include begin_vertex\ntransformed += normalize( dir ) * size;\n#include project_vertex\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvViewPosition = -mvPosition.xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n}");const Bu=new Uint16Array([0,1,2,1,3,2]);function Fu(t){return 3*(4*(t.position.length/3-1))}class Eu extends Bs{constructor(t,e={}){super({position:new Float32Array(Fu(t)),color:new Float32Array(Fu(t)),index:v(Fu(t),Fu(t)/3),normal:new Float32Array(Fu(t)),picking:t.picking},e),this.vertexShader="Ribbon.vert";const i=t.position.length/3-1,r=4*i,n=3*r;this.addAttributes({dir:{type:"v3",value:new Float32Array(n)}}),this.addAttributes({size:{type:"f",value:new Float32Array(r)}}),t.primitiveId=be(i),this.setAttributes(t),this.makeIndex()}setAttributes(t={}){const e=this.size/4,i=this.geometry.attributes;let r,n,s,o,a,c,l,u,h,d,m,f,p,g,y,b,_,x,v;t.position&&(r=t.position,l=i.position.array,i.position.needsUpdate=!0),t.normal&&(n=t.normal,u=i.normal.array,i.normal.needsUpdate=!0),t.size&&(s=t.size,h=i.size.array,i.size.needsUpdate=!0),t.dir&&(o=t.dir,d=i.dir.array,i.dir.needsUpdate=!0),t.color&&(a=t.color,m=i.color.array,i.color.needsUpdate=!0),t.primitiveId&&(c=t.primitiveId,f=i.primitiveId.array,i.primitiveId.needsUpdate=!0);let w=s?s[0]:null;for(p=0;p<e;++p){for(x=3*p,y=3*p*4,_=4*p,r&&(l[y]=l[y+3]=r[x],l[y+1]=l[y+4]=r[x+1],l[y+2]=l[y+5]=r[x+2],l[y+6]=l[y+9]=r[x+3],l[y+7]=l[y+10]=r[x+4],l[y+8]=l[y+11]=r[x+5]),n&&(u[y]=u[y+3]=-n[x],u[y+1]=u[y+4]=-n[x+1],u[y+2]=u[y+5]=-n[x+2],u[y+6]=u[y+9]=-n[x+3],u[y+7]=u[y+10]=-n[x+4],u[y+8]=u[y+11]=-n[x+5]),g=0;g<4;++g)b=y+3*g,a&&(m[b]=a[x],m[b+1]=a[x+1],m[b+2]=a[x+2]),c&&(f[_+g]=c[p]);s&&(v=s[p],w!==s[p]?(h[_]=w,h[_+1]=w,h[_+2]=v,h[_+3]=v):(h[_]=v,h[_+1]=v,h[_+2]=v,h[_+3]=v),w=v),o&&(d[y]=o[x],d[y+1]=o[x+1],d[y+2]=o[x+2],d[y+3]=-o[x],d[y+4]=-o[x+1],d[y+5]=-o[x+2],d[y+6]=o[x+3],d[y+7]=o[x+4],d[y+8]=o[x+5],d[y+9]=-o[x+3],d[y+10]=-o[x+4],d[y+11]=-o[x+5])}}makeIndex(){const t=this.geometry.getIndex();if(!t)return void Dt.error("Index is null");const e=t.array,i=e.length/4/3;for(let t=0;t<i;++t){const i=6*t,r=4*t;e.set(Bu,i);for(let t=0;t<6;++t)e[i+t]+=r}}}class Ou extends ml{constructor(t,e,i){super(t,e,i),this.type="ribbon",this.parameters=Object.assign({subdiv:{type:"integer",max:50,min:1,rebuild:!0},tension:{type:"number",precision:1,max:1,min:.1},smoothSheet:{type:"boolean",rebuild:!0}},this.parameters,{side:null,wireframe:null,linewidth:null}),this.init(i)}init(t){var e=t||{};e.colorScheme=l(e.colorScheme,"chainname"),e.colorScale=l(e.colorScale,"RdYlBu"),e.radiusType=l(e.radiusType,"sstruc"),e.radiusScale=l(e.radiusScale,4),"low"===e.quality?this.subdiv=3:"medium"===e.quality?this.subdiv=6:"high"===e.quality?this.subdiv=12:this.subdiv=l(e.subdiv,6),this.tension=l(e.tension,NaN),this.smoothSheet=l(e.smoothSheet,!1),super.init(e)}getSplineParams(t){return Object.assign({subdiv:this.subdiv,tension:this.tension,directional:!0,smoothSheet:this.smoothSheet},t)}getAtomRadius(t){return t.isTrace()?super.getAtomRadius(t):0}createData(t){var e=[],i=[];return this.structure.eachPolymer((t=>{if(!(t.residueCount<4)){i.push(t);var r=new Yl(t,this.getSplineParams()),n=r.getSubdividedPosition(),s=r.getSubdividedOrientation(),o=r.getSubdividedColor(this.getColorParams()),a=r.getSubdividedPicking(),c=r.getSubdividedSize(this.getRadiusParams());e.push(new Eu({position:n.position,normal:s.binormal,dir:s.normal,color:o.color,size:c.size,picking:a.picking},this.getBufferParams()))}}),t.getSelection()),{bufferList:e,polymerList:i}}updateData(t,e){t=t||{};var i=0,r=e.polymerList.length;for(i=0;i<r;++i){var n={},s=new Yl(e.polymerList[i],this.getSplineParams());if(t.position){var o=s.getSubdividedPosition(),a=s.getSubdividedOrientation();Object.assign(n,{position:o.position,normal:a.binormal,dir:a.normal})}if(t.radius||t.scale){var c=s.getSubdividedSize(this.getRadiusParams());Object.assign(n,{size:c.size})}if(t.color){var l=s.getSubdividedColor(this.getColorParams());Object.assign(n,{color:l.color})}e.bufferList[i].setAttributes(n)}}setParameters(t){var e={};return t&&t.tension&&Object.assign(e,{position:!0}),super.setParameters(t,e,!1),this}}Lt.add("ribbon",Ou);class $u extends ml{constructor(t,e,i){super(t,e,i),this.type="rocket",this.parameters=Object.assign({localAngle:{type:"integer",max:180,min:0,rebuild:!0},centerDist:{type:"number",precision:1,max:10,min:0,rebuild:!0},ssBorder:{type:"boolean",rebuild:!0},radialSegments:!0,openEnded:!0,disableImpostor:!0},this.parameters),this.init(i)}init(t){let e=t||{};e.colorScheme=l(e.colorScheme,"sstruc"),e.radiusSize=l(e.radiusSize,1.5),e.radiusScale=l(e.radiusScale,1),e.openEnded=l(e.openEnded,!1),e.useInteriorColor=l(e.useInteriorColor,!0),this.localAngle=l(e.localAngle,30),this.centerDist=l(e.centerDist,2.5),this.ssBorder=l(e.ssBorder,!1),super.init(e)}createData(t){let e=0;const i=[],r=[];this.structure.eachPolymer((t=>{if(t.residueCount<4||t.isNucleic())return;const n=new go(t),s=n.getAxis(this.localAngle,this.centerDist,this.ssBorder,this.getColorParams(),this.getRadiusParams());e+=s.size.length,i.push(s),r.push(n)}),t.getSelection());const n={begin:new Float32Array(3*e),end:new Float32Array(3*e),size:new Float32Array(e),color:new Float32Array(3*e),picking:{}};let s=new Float32Array(e),o=0;i.forEach((function(t){n.begin.set(t.begin,3*o),n.end.set(t.end,3*o),n.size.set(t.size,o),n.color.set(t.color,3*o),s.set(t.picking.array,o),o+=t.size.length})),e&&(n.picking=new Nn(s,t.getStructure()));return{bufferList:[new jl({position1:n.begin,position2:n.end,color:n.color,color2:n.color,radius:n.size,picking:n.picking},this.getBufferParams({openEnded:this.openEnded,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0}))],axisList:i,helixbundleList:r,axisData:n}}updateData(t,e){if((t=t||{}).position)this.build();else{var i={};if(t.color||t.radius){var r=0;e.helixbundleList.forEach((i=>{var n=i.getAxis(this.localAngle,this.centerDist,this.ssBorder,this.getColorParams(),this.getRadiusParams());t.color&&e.axisData.color.set(n.color,3*r),(t.radius||t.scale)&&e.axisData.size.set(n.size,r),r+=n.size.length})),t.color&&Object.assign(i,{color:e.axisData.color,color2:e.axisData.color}),(t.radius||t.scale)&&Object.assign(i,{radius:e.axisData.size})}e.bufferList[0].setAttributes(i)}}}Lt.add("rocket",$u);class Ru extends tu{constructor(t,e,i){super(t,e,i),this.type="rope",this.parameters=Object.assign({smooth:{type:"integer",max:15,min:0,rebuild:!0}},this.parameters,{aspectRatio:null,smoothSheet:null})}init(t){var e=t||{};e.aspectRatio=1,e.tension=l(e.tension,.5),e.radiusScale=l(e.radiusScale,5),e.smoothSheet=!1,this.smooth=l(e.smooth,2),super.init(e)}getSpline(t){var e=new po(t);return new Yl(t,this.getSplineParams({directional:!1,positionIterator:e.getCenterIterator(this.smooth)}))}}Lt.add("rope",Ru);class Lu extends ml{constructor(t,e,i){super(t,e,i),this.type="spacefill",this.parameters=Object.assign({sphereDetail:!0,disableImpostor:!0},this.parameters),this.init(i)}init(t){var e=t||{};e.useInteriorColor=l(e.useInteriorColor,!0),super.init(e)}createData(t){return{bufferList:[new Da(t.getAtomData(this.getAtomParams()),this.getBufferParams({sphereDetail:this.sphereDetail,dullInterior:!0,disableImpostor:this.disableImpostor}))]}}updateData(t,e){var i=e.sview.getAtomData(this.getAtomParams(t)),r={};t&&!t.position||Object.assign(r,{position:i.position}),t&&!t.color||Object.assign(r,{color:i.color}),t&&!t.radius||Object.assign(r,{radius:i.radius}),e.bufferList[0].setAttributes(r)}}function Nu(t){return 3*(t.position.length/3-1)*2}Lt.add("spacefill",Lu);class zu extends Ds{constructor(t,e={}){super({position:new Float32Array(Nu(t)),color:new Float32Array(Nu(t))},e),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag",this.setAttributes(t)}setAttributes(t){let e,i,r,n;const s=this.geometry.attributes;if(t.position&&(e=t.position,r=s.position.array,s.position.needsUpdate=!0),t.color&&(i=t.color,n=s.color.array,s.color.needsUpdate=!0),!e&&!i)return void Dt.warn("TraceBuffer.prototype.setAttributes no data");let o,a;const c=this.size-1;for(let t=0;t<c;++t)o=3*t,a=3*t*2,e&&(r[a]=e[o],r[a+1]=e[o+1],r[a+2]=e[o+2],r[a+3]=e[o+3],r[a+4]=e[o+4],r[a+5]=e[o+5]),i&&(n[a]=i[o],n[a+1]=i[o+1],n[a+2]=i[o+2],n[a+3]=i[o+3],n[a+4]=i[o+4],n[a+5]=i[o+5])}}class Vu extends ml{constructor(t,e,i){super(t,e,i),this.type="trace",this.parameters=Object.assign({subdiv:{type:"integer",max:50,min:1,rebuild:!0},tension:{type:"number",precision:1,max:1,min:.1},smoothSheet:{type:"boolean",rebuild:!0}},this.parameters,{flatShaded:null,side:null,wireframe:null}),this.init(i)}init(t){var e=t||{};e.colorScheme=l(e.colorScheme,"chainname"),e.colorScale=l(e.colorScale,"RdYlBu"),"low"===e.quality?this.subdiv=3:"medium"===e.quality?this.subdiv=6:"high"===e.quality?this.subdiv=12:this.subdiv=l(e.subdiv,6),this.tension=l(e.tension,NaN),this.smoothSheet=l(e.smoothSheet,!1),super.init(e)}getSplineParams(t){return Object.assign({subdiv:this.subdiv,tension:this.tension,directional:!1,smoothSheet:this.smoothSheet},t)}getAtomRadius(t){return t.isTrace()?.1:0}createData(t){var e=[],i=[];return this.structure.eachPolymer((t=>{if(!(t.residueCount<4)){i.push(t);var r=new Yl(t,this.getSplineParams()),n=r.getSubdividedPosition(),s=r.getSubdividedColor(this.getColorParams());e.push(new zu(Object.assign({},n,s),this.getBufferParams()))}}),t.getSelection()),{bufferList:e,polymerList:i}}updateData(t,e){t=t||{};var i=0,r=e.polymerList.length;for(i=0;i<r;++i){var n={},s=new Yl(e.polymerList[i],this.getSplineParams());if(t.position){var o=s.getSubdividedPosition();Object.assign(n,{position:o.position})}if(t.color){var a=s.getSubdividedColor(this.getColorParams());Object.assign(n,{color:a.color})}e.bufferList[i].setAttributes(n)}}setParameters(t){var e={};return t&&t.tension&&Object.assign(e,{position:!0}),super.setParameters(t,e,!1),this}}Lt.add("trace",Vu);class Uu extends tu{constructor(t,e,i){super(t,e,i),this.type="tube",this.parameters=Object.assign({},this.parameters,{aspectRatio:null})}init(t){var e=t||{};e.aspectRatio=1,e.radiusScale=l(e.radiusScale,2),"low"===e.quality&&(this.radialSegments=5),super.init(e)}getSplineParams(){return super.getSplineParams({directional:!1})}}Lt.add("tube",Uu);class ju extends ml{constructor(t,e,i){super(t,e,i),this.type="unitcell",this.parameters=Object.assign({radiusSize:{type:"number",precision:3,max:10,min:.001},sphereDetail:!0,radialSegments:!0,disableImpostor:!0},this.parameters,{assembly:null}),this.init(i)}init(t){const e=t||{};let i=.5;this.structure.unitcell&&(i=Math.cbrt(this.structure.unitcell.volume)/200),e.radiusSize=l(e.radiusSize,i),e.colorValue=l(e.colorValue,"orange"),e.useInteriorColor=l(e.useInteriorColor,!0),super.init(e)}getUnitcellData(t){return t.unitcell.getData(t)}create(){const t=this.structureView.getStructure();if(!t.unitcell)return;const e=this.getUnitcellData(t);this.sphereBuffer=new Da(e.vertex,this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0})),this.cylinderBuffer=new jl(e.edge,this.getBufferParams({openEnded:!0,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0})),this.dataList.push({sview:this.structureView,bufferList:[this.sphereBuffer,this.cylinderBuffer]})}createData(t){}updateData(t,e){const i=e.sview.getStructure();if(!i.unitcell)return;const r=this.getUnitcellData(i),n={},s={};t&&!t.position||(Object.assign(n,{position:r.vertex.position}),Object.assign(s,{position1:r.edge.position1,position2:r.edge.position2})),t&&!t.color||(Object.assign(n,{color:r.vertex.color}),Object.assign(s,{color:r.edge.color,color2:r.edge.color2})),t&&!t.radius||(Object.assign(n,{radius:r.vertex.radius}),Object.assign(s,{radius:r.edge.radius})),this.sphereBuffer.setAttributes(n),this.cylinderBuffer.setAttributes(s)}}Lt.add("unitcell",ju);class Gu extends ml{constructor(t,e,i){super(t,e,i),this.type="validation",this.parameters=Object.assign({},this.parameters,{radiusType:null,radiusSize:null,radiusScale:null}),this.init(i)}init(t){const e=t||{};e.colorValue=l(e.colorValue,"#f0027f"),e.useInteriorColor=l(e.useInteriorColor,!0),super.init(e)}createData(t){if(!t.validation)return;const e=t.validation.getClashData({structure:t,color:this.colorValue});return{bufferList:[new jl(e,this.getBufferParams({openEnded:!1}))]}}}Lt.add("validation",Gu);const Hu=new e.Vector3,qu=new e.Vector3,Wu=new e.Vector3,Xu=new e.Vector3(0,1,0);const Yu=Object.assign({radialSegments:60,openEnded:!1},Ms);class Ku extends wa{constructor(t,i={}){super({position:new Float32Array(t.position1.length),color:t.color,picking:t.picking},i,function(t={}){const i=new e.ConeGeometry(1,1,l(t.radialSegments,60),1,l(t.openEnded,!1));return i.applyMatrix4((new e.Matrix4).makeRotationX(-Math.PI/2)),i}(i)),this.updateNormals=!0,this._position=new Float32Array(t.position1.length),this.setAttributes(t,!0)}get defaultParameters(){return Yu}applyPositionTransform(t,e,i){qu.fromArray(this._position1,i),Wu.fromArray(this._position2,i),t.lookAt(qu,Wu,Xu);const r=this._radius[e];Hu.set(r,r,qu.distanceTo(Wu)),t.scale(Hu)}setAttributes(t={},e){t.position1&&t.position2&&(fe(t.position1,t.position2,this._position),this._position1=t.position1,this._position2=t.position2,t.position=this._position),t.radius&&(this._radius=t.radius),super.setAttributes(t,e)}}jt.add("cone",Ku);class Zu{constructor(t=[]){this.geometryList=t}computeBoundingBox(){this.boundingBox?this.boundingBox.empty():this.boundingBox=new e.Box3,this.geometryList.forEach((t=>{t.boundingBox||t.computeBoundingBox(),this.boundingBox.union(t.boundingBox)}))}}const Qu=Object.assign({aspectRatio:1.5,radialSegments:50,openEnded:!1,disableImpostor:!1},Ms);class Ju{constructor(t,i={}){this.group=new e.Group,this.wireframeGroup=new e.Group,this.pickingGroup=new e.Group,this.visible=!0,this.parameters=u(i,this.defaultParameters),this.splitPosition=new Float32Array(t.position1.length),this.cylinderRadius=new Float32Array(t.radius.length);const r=this.makeAttributes(t),n={radialSegments:this.parameters.radialSegments,openEnded:this.parameters.openEnded,disableImpostor:this.parameters.disableImpostor};this.cylinderBuffer=new jl(r.cylinder,n),this.coneBuffer=new Ku(r.cone,n),this.geometry=new Zu([this.cylinderBuffer.geometry,this.coneBuffer.geometry]),this.matrix=l(i.matrix,new e.Matrix4),this.picking=t.picking}get defaultParameters(){return Qu}set matrix(t){Ds.prototype.setMatrix.call(this,t)}get matrix(){return this.group.matrix.clone()}get pickable(){return!!this.picking}makeAttributes(t={}){const i=this.splitPosition,r=this.cylinderRadius,n=this.parameters.aspectRatio;let s,o;const a={},c={};if(t.radius){for(s=0,o=r.length;s<o;++s)r[s]=t.radius[s]/n;a.radius=r,c.radius=t.radius}if(t.position1&&t.position2){const l=new e.Vector3,u=new e.Vector3,h=new e.Vector3,d=new e.Vector3;for(s=0,o=i.length;s<o;s+=3){l.fromArray(t.position1,s),u.fromArray(t.position2,s),h.subVectors(l,u);const e=h.length(),o=r[s/3]*n*2,a=Math.min(e,o);h.setLength(a),d.copy(u).add(h),d.toArray(i,s)}a.position1=t.position1,a.position2=i,c.position1=i,c.position2=t.position2}return t.color&&(a.color=t.color,a.color2=t.color,c.color=t.color),{cylinder:a,cone:c}}getMesh(){return(new e.Group).add(this.cylinderBuffer.getMesh(),this.coneBuffer.getMesh())}getWireframeMesh(){return(new e.Group).add(this.cylinderBuffer.getWireframeMesh(),this.coneBuffer.getWireframeMesh())}getPickingMesh(){return(new e.Group).add(this.cylinderBuffer.getPickingMesh(),this.coneBuffer.getPickingMesh())}setAttributes(t={}){const e=this.makeAttributes(t);this.cylinderBuffer.setAttributes(e.cylinder),this.coneBuffer.setAttributes(e.cone)}setParameters(t={}){(t=Object.assign({},t))&&void 0!==t.matrix&&(this.matrix=t.matrix),delete t.matrix,t&&void 0!==t.wireframe&&(this.parameters.wireframe=t.wireframe,this.setVisibility(this.visible)),this.cylinderBuffer.setParameters(t),this.coneBuffer.setParameters(t)}setVisibility(t){Ds.prototype.setVisibility.call(this,t)}dispose(){this.cylinderBuffer.dispose(),this.coneBuffer.dispose()}}jt.add("arrow",Ju);const th=new e.Vector3,eh=new e.Vector3,ih=new e.Vector3,rh=new e.Vector3(0,0,0);class nh extends wa{constructor(t,i={}){super(t,i,new e.BoxGeometry(1,1,1)),this.updateNormals=!0,this.setAttributes(t,!0)}applyPositionTransform(t,e,i){eh.fromArray(this._heightAxis,i),ih.fromArray(this._depthAxis,i),t.lookAt(rh,eh,ih),th.set(this._size[e],ih.length(),eh.length()),t.scale(th)}setAttributes(t={},e){t.size&&(this._size=t.size),t.heightAxis&&(this._heightAxis=t.heightAxis),t.depthAxis&&(this._depthAxis=t.depthAxis),super.setAttributes(t,e)}}jt.add("box",nh);const sh=new e.Vector3,oh=new e.Vector3,ah=new e.Vector3,ch=new e.Vector3(0,0,0),lh=Object.assign({sphereDetail:2},Ms);class uh extends wa{constructor(t,i={}){super(t,i,new e.IcosahedronGeometry(1,l(i.sphereDetail,2))),this.updateNormals=!0,this.setAttributes(t,!0)}get defaultParameters(){return lh}applyPositionTransform(t,e,i){oh.fromArray(this._majorAxis,i),ah.fromArray(this._minorAxis,i),t.lookAt(ch,oh,ah),sh.set(this._radius[e],ah.length(),oh.length()),t.scale(sh)}setAttributes(t={},e){t.radius&&(this._radius=t.radius),t.majorAxis&&(this._majorAxis=t.majorAxis),t.minorAxis&&(this._minorAxis=t.minorAxis),super.setAttributes(t,e)}}jt.add("ellipsoid",uh);const hh=new e.Vector3,dh=new e.Vector3,mh=new e.Vector3,fh=new e.Vector3(0,0,0);class ph extends wa{constructor(t,i={}){super(t,i,new e.IcosahedronGeometry(1,0)),this.updateNormals=!0,this.setAttributes(t,!0)}applyPositionTransform(t,e,i){dh.fromArray(this._heightAxis,i),mh.fromArray(this._depthAxis,i),t.lookAt(fh,dh,mh),hh.set(this._size[e],mh.length(),dh.length()),t.scale(hh)}setAttributes(t={},e){t.size&&(this._size=t.size),t.heightAxis&&(this._heightAxis=t.heightAxis),t.depthAxis&&(this._depthAxis=t.depthAxis),super.setAttributes(t,e)}}jt.add("icosahedron",ph);const gh=new e.Vector3,yh=new e.Vector3,bh=new e.Vector3,_h=new e.Vector3(0,0,0);class xh extends wa{constructor(t,i={}){super(t,i,new e.OctahedronGeometry(1,0)),this.updateNormals=!0,this.setAttributes(t,!0)}applyPositionTransform(t,e,i){yh.fromArray(this._heightAxis,i),bh.fromArray(this._depthAxis,i),t.lookAt(_h,yh,bh),gh.set(this._size[e],bh.length(),yh.length()),t.scale(gh)}setAttributes(t={},e){t.size&&(this._size=t.size),t.heightAxis&&(this._heightAxis=t.heightAxis),t.depthAxis&&(this._depthAxis=t.depthAxis),super.setAttributes(t,e)}}jt.add("octahedron",xh);const vh=new e.Vector3,wh=new e.Vector3,Ah=new e.Vector3,Sh=new e.Vector3(0,0,0);class Ch extends wa{constructor(t,i={}){super(t,i,new e.TetrahedronGeometry(1,0)),this.updateNormals=!0,this.setAttributes(t,!0)}applyPositionTransform(t,e,i){wh.fromArray(this._heightAxis,i),Ah.fromArray(this._depthAxis,i),t.lookAt(Sh,wh,Ah),vh.set(this._size[e],Ah.length(),wh.length()),t.scale(vh)}setAttributes(t={},e){t.size&&(this._size=t.size),t.heightAxis&&(this._heightAxis=t.heightAxis),t.depthAxis&&(this._depthAxis=t.depthAxis),super.setAttributes(t,e)}}jt.add("tetrahedron",Ch);const Ph=new e.Vector3,Ih=new e.Vector3,kh=new e.Vector3,Mh=new e.Vector3(0,0,0),Th=Object.assign({radiusRatio:.2,radialSegments:16,tubularSegments:32},Ms);class Dh extends wa{constructor(t,i={}){super(t,i,new e.TorusGeometry(1,l(i.radiusRatio,.2),l(i.radialSegments,16),l(i.tubularSegments,32))),this.updateNormals=!0,this.setAttributes(t,!0)}get defaultParameters(){return Th}applyPositionTransform(t,e,i){Ih.fromArray(this._majorAxis,i),kh.fromArray(this._minorAxis,i),t.lookAt(Mh,Ih,kh);const r=this._radius[e];Ph.set(r,r,r),t.scale(Ph)}setAttributes(t={},e){t.radius&&(this._radius=t.radius),t.majorAxis&&(this._majorAxis=t.majorAxis),t.minorAxis&&(this._minorAxis=t.minorAxis),super.setAttributes(t,e)}}function Bh(t,e){return{start:e&&void 0!==e.start?Math.max(Math.min(e.start,t-1),0):0,end:e&&void 0!==e.end?Math.min(e.end,t):t}}function Fh(t,e){const i=e&&void 0!==e.array?e.array:Array,{start:r,end:n}=Bh(t,e);return{array:new i(n-r),start:r,end:n}}function Eh(t,e,i){const{array:r,start:n}=Fh(t,i);return function(t,e,i){for(let r=0,n=e.length;r<n;r++)e[r]=t(i+r);return e}(e,r,n)}function Oh(t){return!!t.buffer&&"number"==typeof t.byteLength&&"number"==typeof t.BYTES_PER_ELEMENT}function $h(t,e){const{constructor:i,buffer:r,length:n,byteOffset:s,BYTES_PER_ELEMENT:o}=t,{start:a,end:c}=Bh(n,e);return 0===a&&c===n?t:new i(r,s+o*a,Math.min(n,c-a))}jt.add("torus",Dh);const Rh=1e-6;function Lh(t,e,i){return Math.abs(t-e)<=i}function Nh(t,e,i){return Math.max(e,Math.min(i,t))}function zh(t,e,i,r,n,s){const o=(i-t)*s,a=(r-e)*s,c=n*n;return(2*e-2*i+o+a)*(n*c)+(-3*e+3*i-2*o-a)*c+o*n+e}function Vh(t,e,i,r){const n=1-r;return n*n*t+2*n*r*e+r*r*i}const Uh=isFinite;function jh(){return jh.zero()}!function(t){function e(){const t=[.1,0,0];return t[0]=0,t}function i(t,i,r){const n=e();return n[0]=t,n[1]=i,n[2]=r,n}function r(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function n(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t}function s(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t}function o(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t}function a(t,e,i,r){return t[0]=e[0]+i[0]*r,t[1]=e[1]+i[1]*r,t[2]=e[2]+i[2]*r,t}function c(t){const e=t[0],i=t[1],r=t[2];return e*e+i*i+r*r}function l(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function u(t,e){const i=e[0],r=e[1],n=e[2];let s=i*i+r*r+n*n;return s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s),t}function h(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function d(t,e,i){const r=e[0],n=e[1],s=e[2],o=i[0],a=i[1],c=i[2];return t[0]=n*c-s*a,t[1]=s*o-r*c,t[2]=r*a-n*o,t}t.zero=e,t.clone=function(t){const i=e();return i[0]=t[0],i[1]=t[1],i[2]=t[2],i},t.isFinite=function(t){return Uh(t[0])&&Uh(t[1])&&Uh(t[2])},t.hasNaN=function(t){return isNaN(t[0])||isNaN(t[1])||isNaN(t[2])},t.setNaN=function(t){return t[0]=NaN,t[1]=NaN,t[2]=NaN,t},t.fromObj=function(t){return i(t.x,t.y,t.z)},t.toObj=function(t){return{x:t[0],y:t[1],z:t[2]}},t.fromArray=function(t,e,i){return t[0]=e[i+0],t[1]=e[i+1],t[2]=e[i+2],t},t.toArray=function(t,e,i){return e[i+0]=t[0],e[i+1]=t[1],e[i+2]=t[2],e},t.create=i,t.ofArray=function(t){const i=e();return i[0]=t[0],i[1]=t[1],i[2]=t[2],i},t.set=function(t,e,i,r){return t[0]=e,t[1]=i,t[2]=r,t},t.copy=r,t.add=n,t.sub=s,t.mul=function(t,e,i){return t[0]=e[0]*i[0],t[1]=e[1]*i[1],t[2]=e[2]*i[2],t},t.div=function(t,e,i){return t[0]=e[0]/i[0],t[1]=e[1]/i[1],t[2]=e[2]/i[2],t},t.scale=o,t.scaleAndAdd=a,t.scaleAndSub=function(t,e,i,r){return t[0]=e[0]-i[0]*r,t[1]=e[1]-i[1]*r,t[2]=e[2]-i[2]*r,t},t.addScalar=function(t,e,i){return t[0]=e[0]+i,t[1]=e[1]+i,t[2]=e[2]+i,t},t.subScalar=function(t,e,i){return t[0]=e[0]-i,t[1]=e[1]-i,t[2]=e[2]-i,t},t.round=function(t,e){return t[0]=Math.round(e[0]),t[1]=Math.round(e[1]),t[2]=Math.round(e[2]),t},t.ceil=function(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t},t.floor=function(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t},t.trunc=function(t,e){return t[0]=Math.trunc(e[0]),t[1]=Math.trunc(e[1]),t[2]=Math.trunc(e[2]),t},t.abs=function(t,e){return t[0]=Math.abs(e[0]),t[1]=Math.abs(e[1]),t[2]=Math.abs(e[2]),t},t.min=function(t,e,i){return t[0]=Math.min(e[0],i[0]),t[1]=Math.min(e[1],i[1]),t[2]=Math.min(e[2],i[2]),t},t.max=function(t,e,i){return t[0]=Math.max(e[0],i[0]),t[1]=Math.max(e[1],i[1]),t[2]=Math.max(e[2],i[2]),t},t.clamp=function(t,e,i,r){return t[0]=Math.max(i[0],Math.min(r[0],e[0])),t[1]=Math.max(i[1],Math.min(r[1],e[1])),t[2]=Math.max(i[2],Math.min(r[2],e[2])),t},t.distance=function(t,e){const i=e[0]-t[0],r=e[1]-t[1],n=e[2]-t[2];return Math.sqrt(i*i+r*r+n*n)},t.squaredDistance=function(t,e){const i=e[0]-t[0],r=e[1]-t[1],n=e[2]-t[2];return i*i+r*r+n*n},t.magnitude=function(t){const e=t[0],i=t[1],r=t[2];return Math.sqrt(e*e+i*i+r*r)},t.squaredMagnitude=c,t.setMagnitude=function(t,e,i){return o(t,u(t,e),i)},t.negate=l,t.inverse=function(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t},t.normalize=u,t.dot=h,t.cross=d,t.lerp=function(t,e,i,r){const n=e[0],s=e[1],o=e[2];return t[0]=n+r*(i[0]-n),t[1]=s+r*(i[1]-s),t[2]=o+r*(i[2]-o),t};const m=e();function f(t,e){const i=Math.sqrt(c(t)*c(e));if(0===i)return Math.PI/2;const r=h(t,e)/i;return Math.acos(Nh(r,-1,1))}t.slerp=function(t,e,i,r){const s=Nh(h(e,i),-1,1),c=Math.acos(s)*r;return a(m,i,e,-s),u(m,m),n(t,o(t,e,Math.cos(c)),o(m,m,Math.sin(c)))},t.hermite=function(t,e,i,r,n,s){const o=s*s,a=o*(2*s-3)+1,c=o*(s-2)+s,l=o*(s-1),u=o*(3-2*s);return t[0]=e[0]*a+i[0]*c+r[0]*l+n[0]*u,t[1]=e[1]*a+i[1]*c+r[1]*l+n[1]*u,t[2]=e[2]*a+i[2]*c+r[2]*l+n[2]*u,t},t.bezier=function(t,e,i,r,n,s){const o=1-s,a=o*o,c=s*s,l=a*o,u=3*s*a,h=3*c*o,d=c*s;return t[0]=e[0]*l+i[0]*u+r[0]*h+n[0]*d,t[1]=e[1]*l+i[1]*u+r[1]*h+n[1]*d,t[2]=e[2]*l+i[2]*u+r[2]*h+n[2]*d,t},t.quadraticBezier=function(t,e,i,r,n){return t[0]=Vh(e[0],i[0],r[0],n),t[1]=Vh(e[1],i[1],r[1],n),t[2]=Vh(e[2],i[2],r[2],n),t},t.spline=function(t,e,i,r,n,s,o){return t[0]=zh(e[0],i[0],r[0],n[0],s,o),t[1]=zh(e[1],i[1],r[1],n[1],s,o),t[2]=zh(e[2],i[2],r[2],n[2],s,o),t},t.random=function(t,e){const i=2*Math.random()*Math.PI,r=2*Math.random()-1,n=Math.sqrt(1-r*r)*e;return t[0]=Math.cos(i)*n,t[1]=Math.sin(i)*n,t[2]=r*e,t},t.transformMat4=function(t,e,i){const r=e[0],n=e[1],s=e[2],o=1/(i[3]*r+i[7]*n+i[11]*s+i[15]||1);return t[0]=(i[0]*r+i[4]*n+i[8]*s+i[12])*o,t[1]=(i[1]*r+i[5]*n+i[9]*s+i[13])*o,t[2]=(i[2]*r+i[6]*n+i[10]*s+i[14])*o,t},t.transformDirection=function(t,e,i){const r=e[0],n=e[1],s=e[2];return t[0]=i[0]*r+i[4]*n+i[8]*s,t[1]=i[1]*r+i[5]*n+i[9]*s,t[2]=i[2]*r+i[6]*n+i[10]*s,u(t,t)},t.transformMat4Offset=function(t,e,i,r,n,s){const o=e[0+n],a=e[1+n],c=e[2+n],l=1/(i[3+s]*o+i[7+s]*a+i[11+s]*c+i[15+s]||1);return t[0+r]=(i[0+s]*o+i[4+s]*a+i[8+s]*c+i[12+s])*l,t[1+r]=(i[1+s]*o+i[5+s]*a+i[9+s]*c+i[13+s])*l,t[2+r]=(i[2+s]*o+i[6+s]*a+i[10+s]*c+i[14+s])*l,t},t.transformDirectionOffset=function(t,e,i,r,n,s){const o=e[0+n],a=e[1+n],c=e[2+n];t[0+r]=i[0+s]*o+i[4+s]*a+i[8+s]*c,t[1+r]=i[1+s]*o+i[5+s]*a+i[9+s]*c,t[2+r]=i[2+s]*o+i[6+s]*a+i[10+s]*c;const l=Math.hypot(t[0+r],t[1+r],t[2+r]);return l>0&&(t[0+r]/=l,t[1+r]/=l,t[2+r]/=l),t},t.transformMat3=function(t,e,i){const r=e[0],n=e[1],s=e[2];return t[0]=r*i[0]+n*i[3]+s*i[6],t[1]=r*i[1]+n*i[4]+s*i[7],t[2]=r*i[2]+n*i[5]+s*i[8],t},t.transformQuat=function(t,e,i){const r=e[0],n=e[1],s=e[2],o=i[0],a=i[1],c=i[2],l=i[3],u=l*r+a*s-c*n,h=l*n+c*r-o*s,d=l*s+o*n-a*r,m=-o*r-a*n-c*s;return t[0]=u*l+m*-o+h*-c-d*-a,t[1]=h*l+m*-a+d*-o-u*-c,t[2]=d*l+m*-c+u*-a-h*-o,t},t.angle=f;const p=e(),g=e(),y=e(),b=e(),_=e(),x=e(),v=e();t.dihedralAngle=function(t,e,i,r){s(p,t,e),s(g,i,e),s(y,e,i),s(b,r,i),d(_,p,g),d(x,y,b);const n=f(_,x);return d(v,_,x),h(g,v)>0?n:-n},t.directionFromSpherical=function(e,i,r,n){return t.set(e,n*Math.cos(r)*Math.sin(i),n*Math.sin(r)*Math.sin(i),n*Math.cos(i))},t.exactEquals=function(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]},t.equals=function(t,e){const i=t[0],r=t[1],n=t[2],s=e[0],o=e[1],a=e[2];return Math.abs(i-s)<=Rh*Math.max(1,Math.abs(i),Math.abs(s))&&Math.abs(r-o)<=Rh*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-a)<=Rh*Math.max(1,Math.abs(n),Math.abs(a))};const w=e();t.makeRotation=function(e,i,r){const n=f(i,r);if(Math.abs(n)<1e-4)return qh.setIdentity(e);if(Math.abs(n-Math.PI)<Rh)return qh.fromScaling(e,t.negUnit);const s=d(w,i,r);return qh.fromRotation(e,n,s)},t.isZero=function(t){return 0===t[0]&&0===t[1]&&0===t[2]},t.projectPointOnVector=function(t,e,i,r){return s(t,e,r),n(t,o(t,i,h(i,t)/c(i)),r)};const A=e();function S(t,e,i){return o(t,i,h(i,e)/c(i))}t.projectPointOnPlane=function(t,e,i,r){return u(A,i),s(t,e,r),s(t,e,o(A,A,h(t,A)))},t.projectOnVector=S;const C=e();t.projectOnPlane=function(t,e,i){return S(C,e,i),s(t,e,C)},t.orthogonalize=function(t,e,i){return u(t,d(t,d(t,e,i),e))},t.matchDirection=function(t,e,i){return h(e,i)>0?r(t,e):l(t,r(t,e)),t};const P=e(),I=e();t.triangleNormal=function(t,e,i,r){return s(P,i,e),s(I,r,e),u(t,d(t,P,I))},t.toString=function(t,e){return`[${t[0].toPrecision(e)} ${t[1].toPrecision(e)} ${t[2].toPrecision(e)}]`},t.origin=i(0,0,0),t.unit=i(1,1,1),t.negUnit=i(-1,-1,-1),t.unitX=i(1,0,0),t.unitY=i(0,1,0),t.unitZ=i(0,0,1),t.negUnitX=i(-1,0,0),t.negUnitY=i(0,-1,0),t.negUnitZ=i(0,0,-1)}(jh||(jh={}));const Gh=Math.PI/180;function Hh(t){return t*Gh}function qh(){return qh.zero()}function Wh(){return Wh.zero()}function Xh(){return Xh.zero()}function Yh(){return Yh.zero()}function Kh(t){throw new Error("unreachable")}function Zh(){return Zh.zero()}var Qh,Jh,td,ed;function id(t,e,i){let r=e,n=0,s=1;for(45===t.charCodeAt(r)?(s=-1,++r):43===t.charCodeAt(r)&&++r;r<i;r++){const e=t.charCodeAt(r)-48;if(e>9||e<0)return s*n|0;n=10*n+e|0}return s*n}function rd(t,e,i,r){return 43===e.charCodeAt(i)&&i++,t*Math.pow(10,id(e,i,r))}function nd(t,e,i){let r=e,n=1,s=0,o=0,a=1;for(45===t.charCodeAt(r)?(n=-1,++r):43===t.charCodeAt(r)&&++r;r<i;){let e=t.charCodeAt(r)-48;if(!(e>=0&&e<10)){if(-2===e){for(++r;r<i;){if(e=t.charCodeAt(r)-48,!(e>=0&&e<10))return 53===e||21===e?rd(n*(s+o/a),t,r+1,i):n*(s+o/a);o=10*o+e,a*=10,++r}return n*(s+o/a)}if(53===e||21===e)return rd(n*s,t,r+1,i);break}s=10*s+e,++r}return n*s}function sd(t,e,i,r){return{schema:i,__array:void 0,isDefined:0===r,rowCount:e,value:e=>t,valueKind:t=>r,toArray:i=>{const{array:r}=Fh(e,i);for(let e=0,i=r.length;e<i;e++)r[e]=t;return r},areValuesEqual:(t,e)=>!0}}function od({value:t,valueKind:e,areValuesEqual:i,rowCount:r,schema:n}){return{schema:n,__array:void 0,isDefined:!0,rowCount:r,value:t,valueKind:e||(t=>0),toArray:e=>{const{array:i,start:n}=Fh(r,e);for(let e=0,r=i.length;e<r;e++)i[e]=t(e+n);return i},areValuesEqual:i||((e,i)=>t(e)===t(i))}}function ad({array:t,schema:e,valueKind:i}){const r=t.length,n=e.T,s="str"===e.valueType?"lowercase"===e.transform?e=>{const i=t[e];return"string"==typeof i?i.toLowerCase():`${null!=i?i:n}`.toLowerCase()}:"uppercase"===e.transform?e=>{const i=t[e];return"string"==typeof i?i.toUpperCase():`${null!=i?i:n}`.toUpperCase()}:e=>{const i=t[e];return"string"==typeof i?i:`${null!=i?i:n}`}:e=>t[e],o=Oh(t);return{schema:e,__array:t,isDefined:!0,rowCount:r,value:s,valueKind:i||(t=>0),toArray:"str"===e.valueType?"lowercase"===e.transform?e=>{const{start:i,end:s}=Bh(r,e),o=new(e&&void 0!==e.array?e.array:t.constructor)(s-i);for(let e=0,r=s-i;e<r;e++){const r=t[i+e];o[e]="string"==typeof r?r.toLowerCase():`${null!=r?r:n}`.toLowerCase()}return o}:"uppercase"===e.transform?e=>{const{start:i,end:s}=Bh(r,e),o=new(e&&void 0!==e.array?e.array:t.constructor)(s-i);for(let e=0,r=s-i;e<r;e++){const r=t[i+e];o[e]="string"==typeof r?r.toUpperCase():`${null!=r?r:n}`.toUpperCase()}return o}:e=>{const{start:i,end:s}=Bh(r,e),o=new(e&&void 0!==e.array?e.array:t.constructor)(s-i);for(let e=0,r=s-i;e<r;e++){const r=t[i+e];o[e]="string"==typeof r?r:`${null!=r?r:n}`}return o}:o?e=>$h(t,e):e=>{const{start:i,end:n}=Bh(r,e);if(0===i&&n===t.length)return t;const s=new(e&&void 0!==e.array?e.array:t.constructor)(n-i);for(let e=0,r=n-i;e<r;e++)s[e]=t[i+e];return s},areValuesEqual:(e,i)=>t[e]===t[i]}}function cd(t,e,i){return t.isDefined?0===e&&i===t.rowCount?t:t.__array&&Oh(t.__array)?function(t,e,i){const r=$h(t.__array,{start:e,end:i}),n=t.valueKind;return ad({array:r,schema:t.schema,valueKind:t=>n(e+t)})}(t,e,i):function(t,e,i){const r=t.value,n=t.valueKind,s=t.areValuesEqual,o=0===e?r:t=>r(t+e),a=i-e;return{schema:t.schema,__array:void 0,isDefined:t.isDefined,rowCount:a,value:o,valueKind:0===e?n:t=>n(t+e),toArray:t=>{const{array:i}=Fh(a,t);for(let t=0,n=i.length;t<n;t++)i[t]=r(t+e);return i},areValuesEqual:0===e?s:(t,i)=>s(t+e,i+e)}}(t,e,i):Jh.Undefined(i-e,t.schema)}function ld(t,e,i){return 0===t.rowCount||i&&function(t,e){if(t.length!==e)return!1;for(let e=0,i=t.length;e<i;e++)if(t[e]!==e)return!1;return!0}(e,t.rowCount)?t:t.__array&&typeof t.value(0)==typeof t.__array[0]?function(t,e){const i=t.__array,r=new i.constructor(e.length);for(let t=0,n=e.length;t<n;t++)r[t]=i[e[t]];const n=t.valueKind;return ad({array:r,schema:t.schema,valueKind:t=>n(e[t])})}(t,e):function(t,e){const i=t.value,r=t.valueKind,n=t.areValuesEqual,s=t=>i(e[t]),o=e.length;return{schema:t.schema,__array:void 0,isDefined:t.isDefined,rowCount:o,value:s,valueKind:t=>r(e[t]),toArray:t=>{const{array:r}=Fh(o,t);for(let t=0,n=r.length;t<n;t++)r[t]=i(e[t]);return r},areValuesEqual:(t,i)=>n(e[t],e[i])}}(t,e)}function ud(t,e,i){return t[e]-t[i]}function hd(t,e,i){const r=t[e];t[e]=t[i],t[i]=r}function dd(t,e,i,r){const n=i+r>>1;return e(t,i,r)>0?e(t,i,n)>0?e(t,n,r)>0?n:r:i:e(t,r,n)>0?e(t,n,i)>0?n:i:r}function md(t,e,i){const{cmp:r,swap:n,data:s,parts:o}=t;let a=e+1,c=i;for(n(s,e,dd(s,r,e,i));r(s,c,e)>0;)--c;for(let t=e+1;t<=c;t++){const i=r(s,t,e);if(i>0){for(n(s,t,c),--c;r(s,c,e)>0;)--c;t--}else 0===i&&(n(s,t,a),a++)}for(let t=e;t<a;t++)n(s,t,e+c-t);o[0]=c-a+e+1,o[1]=c}function fd({data:t,cmp:e,swap:i},r,n){for(let s=r+1;s<=n;s++){let n=s-1;for(;n>=r&&e(t,n,n+1)>0;)i(t,n,n+1),n-=1}}function pd(t,e,i){const{parts:r}=t;for(;e<i;){if(i-e<16)return void fd(t,e,i);md(t,e,i);const n=r[0],s=r[1];n-e<i-s?(pd(t,e,n-1),e=s+1):(pd(t,s+1,i),i=n-1)}}function gd(t,e,i,r){let n=i+1,s=r;hd(t,i,dd(t,ud,i,r));const o=t[i];for(;t[s]>o;)--s;for(let e=i+1;e<=s;e++){const i=t[e];if(i>o){for(hd(t,e,s),--s;t[s]>o;)--s;e--}else i===o&&(hd(t,e,n),++n)}for(let e=i;e<n;e++)hd(t,e,i+s-e);e[0]=s-n+i+1,e[1]=s}function yd(t,e,i){for(let r=e+1;r<=i;r++){const i=t[r];let n=r-1;for(;n>=e&&t[n]>i;)t[n+1]=t[n],n-=1;t[n+1]=i}}function bd(t,e,i,r){for(;i<r;){if(r-i<16)return void yd(t,i,r);gd(t,e,i,r);const n=e[0],s=e[1];n-i<r-s?(bd(t,e,i,n-1),i=s+1):(bd(t,e,s+1,r),r=n-1)}}function _d(t,e=ud){return function(t,e,i,r=ud){r===ud?bd(t,[0,0],e,i-1):pd({data:t,cmp:r,swap:hd,parts:[0,0]},e,i-1);return t}(t,0,t.length,e)}!function(t){function e(){const t=[.1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];return t[0]=0,t}function i(){const t=e();return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function r(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function n(t){for(let e=0;e<16;e++)t[e]=0;return t}t.zero=e,t.identity=i,t.setIdentity=r,t.setZero=n,t.ofRows=function(t){const i=e();for(let e=0;e<4;e++){const r=t[e];for(let t=0;t<4;t++)i[4*t+e]=r[t]}return i};const s=i();function o(t,e,i){for(let r=0;r<16;r++)if(Math.abs(t[r]-e[r])>i)return!1;return!0}function a(t,e,i,r){t[4*i+e]=r}function c(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function l(t,e){const i=e[0]+e[5]+e[10];let r=0;return i>0?(r=2*Math.sqrt(i+1),t[3]=.25*r,t[0]=(e[6]-e[9])/r,t[1]=(e[8]-e[2])/r,t[2]=(e[1]-e[4])/r):e[0]>e[5]&&e[0]>e[10]?(r=2*Math.sqrt(1+e[0]-e[5]-e[10]),t[3]=(e[6]-e[9])/r,t[0]=.25*r,t[1]=(e[1]+e[4])/r,t[2]=(e[8]+e[2])/r):e[5]>e[10]?(r=2*Math.sqrt(1+e[5]-e[0]-e[10]),t[3]=(e[8]-e[2])/r,t[0]=(e[1]+e[4])/r,t[1]=.25*r,t[2]=(e[6]+e[9])/r):(r=2*Math.sqrt(1+e[10]-e[0]-e[5]),t[3]=(e[1]-e[4])/r,t[0]=(e[8]+e[2])/r,t[1]=(e[6]+e[9])/r,t[2]=.25*r),t}function u(t,e){const i=e[0],r=e[1],n=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=e[9],d=e[10],m=e[11],f=e[12],p=e[13],g=e[14],y=e[15],b=i*a-r*o,_=i*c-n*o,x=i*l-s*o,v=r*c-n*a,w=r*l-s*a,A=n*l-s*c,S=u*p-h*f,C=u*g-d*f,P=u*y-m*f,I=h*g-d*p,k=h*y-m*p,M=d*y-m*g;let T=b*M-_*k+x*I+v*P-w*C+A*S;return!!T&&(T=1/T,t[0]=(a*M-c*k+l*I)*T,t[1]=(n*k-r*M-s*I)*T,t[2]=(p*A-g*w+y*v)*T,t[3]=(d*w-h*A-m*v)*T,t[4]=(c*P-o*M-l*C)*T,t[5]=(i*M-n*P+s*C)*T,t[6]=(g*x-f*A-y*_)*T,t[7]=(u*A-d*x+m*_)*T,t[8]=(o*k-a*P+l*S)*T,t[9]=(r*P-i*k-s*S)*T,t[10]=(f*w-p*x+y*b)*T,t[11]=(h*x-u*w-m*b)*T,t[12]=(a*C-o*I-c*S)*T,t[13]=(i*I-r*C+n*S)*T,t[14]=(p*_-f*v-g*b)*T,t[15]=(u*v-h*_+d*b)*T,!0)}function h(t,e,i){const r=e[0],n=e[1],s=e[2],o=e[3],a=e[4],c=e[5],l=e[6],u=e[7],h=e[8],d=e[9],m=e[10],f=e[11],p=e[12],g=e[13],y=e[14],b=e[15];let _=i[0],x=i[1],v=i[2],w=i[3];return t[0]=_*r+x*a+v*h+w*p,t[1]=_*n+x*c+v*d+w*g,t[2]=_*s+x*l+v*m+w*y,t[3]=_*o+x*u+v*f+w*b,_=i[4],x=i[5],v=i[6],w=i[7],t[4]=_*r+x*a+v*h+w*p,t[5]=_*n+x*c+v*d+w*g,t[6]=_*s+x*l+v*m+w*y,t[7]=_*o+x*u+v*f+w*b,_=i[8],x=i[9],v=i[10],w=i[11],t[8]=_*r+x*a+v*h+w*p,t[9]=_*n+x*c+v*d+w*g,t[10]=_*s+x*l+v*m+w*y,t[11]=_*o+x*u+v*f+w*b,_=i[12],x=i[13],v=i[14],w=i[15],t[12]=_*r+x*a+v*h+w*p,t[13]=_*n+x*c+v*d+w*g,t[14]=_*s+x*l+v*m+w*y,t[15]=_*o+x*u+v*f+w*b,t}function d(t,e,i){let n=i[0],s=i[1],o=i[2],a=Math.sqrt(n*n+s*s+o*o);if(Math.abs(a)<Rh)return r(t);a=1/a,n*=a,s*=a,o*=a;const c=Math.sin(e),l=Math.cos(e),u=1-l;return t[0]=n*n*u+l,t[1]=s*n*u+o*c,t[2]=o*n*u-s*c,t[3]=0,t[4]=n*s*u-o*c,t[5]=s*s*u+l,t[6]=o*s*u+n*c,t[7]=0,t[8]=n*o*u+s*c,t[9]=s*o*u-n*c,t[10]=o*o*u+l,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}t.isIdentity=function(t,e){return o(t,s,void 0===e?Rh:e)},t.hasNaN=function(t){for(let e=0;e<16;e++)if(isNaN(t[e]))return!0;return!1},t.areEqual=o,t.setValue=a,t.getValue=function(t,e,i){return t[4*i+e]},t.toArray=function(t,e,i){return e[i+0]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=t[3],e[i+4]=t[4],e[i+5]=t[5],e[i+6]=t[6],e[i+7]=t[7],e[i+8]=t[8],e[i+9]=t[9],e[i+10]=t[10],e[i+11]=t[11],e[i+12]=t[12],e[i+13]=t[13],e[i+14]=t[14],e[i+15]=t[15],e},t.fromArray=function(t,e,i){return t[0]=e[i+0],t[1]=e[i+1],t[2]=e[i+2],t[3]=e[i+3],t[4]=e[i+4],t[5]=e[i+5],t[6]=e[i+6],t[7]=e[i+7],t[8]=e[i+8],t[9]=e[i+9],t[10]=e[i+10],t[11]=e[i+11],t[12]=e[i+12],t[13]=e[i+13],t[14]=e[i+14],t[15]=e[i+15],t},t.fromBasis=function(t,e,i,r){return n(t),a(t,0,0,e[0]),a(t,1,0,e[1]),a(t,2,0,e[2]),a(t,0,1,i[0]),a(t,1,1,i[1]),a(t,2,1,i[2]),a(t,0,2,r[0]),a(t,1,2,r[1]),a(t,2,2,r[2]),a(t,3,3,1),t},t.copy=c,t.clone=function(t){return c(e(),t)},t.getTranslation=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t},t.getScaling=function(t,e){const i=e[0],r=e[1],n=e[2],s=e[4],o=e[5],a=e[6],c=e[8],l=e[9],u=e[10];return t[0]=Math.sqrt(i*i+r*r+n*n),t[1]=Math.sqrt(s*s+o*o+a*a),t[2]=Math.sqrt(c*c+l*l+u*u),t},t.getRotation=l,t.extractRotation=function(t,e){const i=1/Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),r=1/Math.sqrt(e[4]*e[4]+e[5]*e[5]+e[6]*e[6]),n=1/Math.sqrt(e[8]*e[8]+e[9]*e[9]+e[10]*e[10]);return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[3]=0,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=0,t[8]=e[8]*n,t[9]=e[9]*n,t[10]=e[10]*n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},t.transpose=function(t,e){if(t===e){const i=e[1],r=e[2],n=e[3],s=e[6],o=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=i,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=s,t[11]=e[14],t[12]=n,t[13]=o,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t},t.tryInvert=u,t.invert=function(t,e){return u(t,e)||console.warn("non-invertible matrix.",e),t},t.mul=h,t.mulOffset=function(t,e,i,r,n,s){const o=e[0+n],a=e[1+n],c=e[2+n],l=e[3+n],u=e[4+n],h=e[5+n],d=e[6+n],m=e[7+n],f=e[8+n],p=e[9+n],g=e[10+n],y=e[11+n],b=e[12+n],_=e[13+n],x=e[14+n],v=e[15+n];let w=i[0+s],A=i[1+s],S=i[2+s],C=i[3+s];return t[0+r]=w*o+A*u+S*f+C*b,t[1+r]=w*a+A*h+S*p+C*_,t[2+r]=w*c+A*d+S*g+C*x,t[3+r]=w*l+A*m+S*y+C*v,w=i[4+s],A=i[5+s],S=i[6+s],C=i[7+s],t[4+r]=w*o+A*u+S*f+C*b,t[5+r]=w*a+A*h+S*p+C*_,t[6+r]=w*c+A*d+S*g+C*x,t[7+r]=w*l+A*m+S*y+C*v,w=i[8+s],A=i[9+s],S=i[10+s],C=i[11+s],t[8+r]=w*o+A*u+S*f+C*b,t[9+r]=w*a+A*h+S*p+C*_,t[10+r]=w*c+A*d+S*g+C*x,t[11+r]=w*l+A*m+S*y+C*v,w=i[12+s],A=i[13+s],S=i[14+s],C=i[15+s],t[12+r]=w*o+A*u+S*f+C*b,t[13+r]=w*a+A*h+S*p+C*_,t[14+r]=w*c+A*d+S*g+C*x,t[15+r]=w*l+A*m+S*y+C*v,t},t.mul3=function(t,e,i,r){return h(t,h(t,e,i),r)},t.translate=function(t,e,i){const r=i[0],n=i[1],s=i[2];let o,a,c,l,u,h,d,m,f,p,g,y;return e===t?(t[12]=e[0]*r+e[4]*n+e[8]*s+e[12],t[13]=e[1]*r+e[5]*n+e[9]*s+e[13],t[14]=e[2]*r+e[6]*n+e[10]*s+e[14],t[15]=e[3]*r+e[7]*n+e[11]*s+e[15]):(o=e[0],a=e[1],c=e[2],l=e[3],u=e[4],h=e[5],d=e[6],m=e[7],f=e[8],p=e[9],g=e[10],y=e[11],t[0]=o,t[1]=a,t[2]=c,t[3]=l,t[4]=u,t[5]=h,t[6]=d,t[7]=m,t[8]=f,t[9]=p,t[10]=g,t[11]=y,t[12]=o*r+u*n+f*s+e[12],t[13]=a*r+h*n+p*s+e[13],t[14]=c*r+d*n+g*s+e[14],t[15]=l*r+m*n+y*s+e[15]),t},t.fromTranslation=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t},t.setTranslation=function(t,e){return t[12]=e[0],t[13]=e[1],t[14]=e[2],t},t.setAxes=function(t,e,i,r){return t[0]=i[0],t[4]=i[1],t[8]=i[2],t[1]=r[0],t[5]=r[1],t[9]=r[2],t[2]=e[0],t[6]=e[1],t[10]=e[2],t},t.rotate=function(t,e,r,n){let s=n[0],o=n[1],a=n[2],c=Math.sqrt(s*s+o*o+a*a);if(Math.abs(c)<Rh)return i();c=1/c,s*=c,o*=c,a*=c;const l=Math.sin(r),u=Math.cos(r),h=1-u,d=e[0],m=e[1],f=e[2],p=e[3],g=e[4],y=e[5],b=e[6],_=e[7],x=e[8],v=e[9],w=e[10],A=e[11],S=s*s*h+u,C=o*s*h+a*l,P=a*s*h-o*l,I=s*o*h-a*l,k=o*o*h+u,M=a*o*h+s*l,T=s*a*h+o*l,D=o*a*h-s*l,B=a*a*h+u;return t[0]=d*S+g*C+x*P,t[1]=m*S+y*C+v*P,t[2]=f*S+b*C+w*P,t[3]=p*S+_*C+A*P,t[4]=d*I+g*k+x*M,t[5]=m*I+y*k+v*M,t[6]=f*I+b*k+w*M,t[7]=p*I+_*k+A*M,t[8]=d*T+g*D+x*B,t[9]=m*T+y*D+v*B,t[10]=f*T+b*D+w*B,t[11]=p*T+_*D+A*B,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t},t.fromRotation=d,t.scale=function(t,e,i){const r=i[0],n=i[1],s=i[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*n,t[5]=e[5]*n,t[6]=e[6]*n,t[7]=e[7]*n,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},t.scaleUniformly=function(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[3]=e[3]*i,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*i,t[9]=e[9]*i,t[10]=e[10]*i,t[11]=e[11]*i,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},t.fromScaling=function(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},t.fromUniformScaling=function(t,e){return t[0]=e,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},t.fromMat3=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[4]=e[3],t[5]=e[4],t[6]=e[5],t[8]=e[6],t[9]=e[7],t[10]=e[8],t},t.compose=function(t,e,i,r){const[n,s,o,a]=i,c=n+n,l=s+s,u=o+o,h=n*c,d=n*l,m=n*u,f=s*l,p=s*u,g=o*u,y=a*c,b=a*l,_=a*u,[x,v,w]=r;return t[0]=(1-(f+g))*x,t[1]=(d+_)*x,t[2]=(m-b)*x,t[3]=0,t[4]=(d-_)*v,t[5]=(1-(h+g))*v,t[6]=(p+y)*v,t[7]=0,t[8]=(m+b)*w,t[9]=(p-y)*w,t[10]=(1-(h+f))*w,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t};const m=[0,0,0],f=e();function p(t){const e=t[0],i=t[1],r=t[2],n=t[3],s=t[4],o=t[5],a=t[6],c=t[7],l=t[8],u=t[9],h=t[10],d=t[11],m=t[12],f=t[13],p=t[14],g=t[15];return(e*o-i*s)*(h*g-d*p)-(e*a-r*s)*(u*g-d*f)+(e*c-n*s)*(u*p-h*f)+(i*a-r*o)*(l*g-d*m)-(i*c-n*o)*(l*p-h*m)+(r*c-n*a)*(l*f-u*m)}t.decompose=function(t,e,i,r){let n=jh.magnitude(jh.set(m,t[0],t[1],t[2]));const s=jh.magnitude(jh.set(m,t[4],t[5],t[6])),o=jh.magnitude(jh.set(m,t[8],t[9],t[10]));p(t)<0&&(n=-n),e[0]=t[12],e[1]=t[13],e[2]=t[14],c(f,t);const a=1/n,u=1/s,h=1/o;return f[0]*=a,f[1]*=a,f[2]*=a,f[4]*=u,f[5]*=u,f[6]*=u,f[8]*=h,f[9]*=h,f[10]*=h,l(i,f),r[0]=n,r[1]=s,r[2]=o,t},t.makeTable=function(t){let e="";for(let i=0;i<4;i++){for(let r=0;r<4;r++)e+=t[4*r+i].toString(),r<3&&(e+=" ");i<3&&(e+="\n")}return e},t.determinant=p,t.isRotationAndTranslation=function(t,e){return function(t,e){const i=t[0],r=t[1],n=t[2],s=t[3],o=t[4],a=t[5],c=t[6],l=t[7],u=t[8],h=t[9],d=t[10],m=t[11],f=t[15];if(!(Lh(f,1,e)&&Lh(s,0,e)&&Lh(l,0,e)&&Lh(m,0,e)))return!1;if(!Lh(Math.abs(i*(a*d-c*h)-r*(o*d-c*u)+n*(o*h-a*u)),1,e))return!1;return!0}(t,void 0!==e?e:Rh)},t.isTranslationAndUniformScaling=function(t,e){return function(t,e){const i=t[0];return Lh(t[1],0,e)&&Lh(t[2],0,e)&&Lh(t[3],0,e)&&Lh(t[4],0,e)&&Lh(t[5],i,e)&&Lh(t[6],0,e)&&Lh(t[7],0,e)&&Lh(t[8],0,e)&&Lh(t[9],0,e)&&Lh(t[10],i,e)&&Lh(t[11],0,e)&&Lh(t[15],1,e)}(t,void 0!==e?e:Rh)},t.fromQuat=function(t,e){const i=e[0],r=e[1],n=e[2],s=e[3],o=i+i,a=r+r,c=n+n,l=i*o,u=r*o,h=r*a,d=n*o,m=n*a,f=n*c,p=s*o,g=s*a,y=s*c;return t[0]=1-h-f,t[1]=u+y,t[2]=d-g,t[3]=0,t[4]=u-y,t[5]=1-l-f,t[6]=m+p,t[7]=0,t[8]=d+g,t[9]=m-p,t[10]=1-l-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},t.fromEuler=function(t,e,i){const r=e[0],n=e[1],s=e[2],o=Math.cos(r),a=Math.sin(r),c=Math.cos(n),l=Math.sin(n),u=Math.cos(s),h=Math.sin(s);if("XYZ"===i){const e=o*u,i=o*h,r=a*u,n=a*h;t[0]=c*u,t[4]=-c*h,t[8]=l,t[1]=i+r*l,t[5]=e-n*l,t[9]=-a*c,t[2]=n-e*l,t[6]=r+i*l,t[10]=o*c}else if("YXZ"===i){const e=c*u,i=c*h,r=l*u,n=l*h;t[0]=e+n*a,t[4]=r*a-i,t[8]=o*l,t[1]=o*h,t[5]=o*u,t[9]=-a,t[2]=i*a-r,t[6]=n+e*a,t[10]=o*c}else if("ZXY"===i){const e=c*u,i=c*h,r=l*u,n=l*h;t[0]=e-n*a,t[4]=-o*h,t[8]=r+i*a,t[1]=i+r*a,t[5]=o*u,t[9]=n-e*a,t[2]=-o*l,t[6]=a,t[10]=o*c}else if("ZYX"===i){const e=o*u,i=o*h,r=a*u,n=a*h;t[0]=c*u,t[4]=r*l-i,t[8]=e*l+n,t[1]=c*h,t[5]=n*l+e,t[9]=i*l-r,t[2]=-l,t[6]=a*c,t[10]=o*c}else if("YZX"===i){const e=o*c,i=o*l,r=a*c,n=a*l;t[0]=c*u,t[4]=n-e*h,t[8]=r*h+i,t[1]=h,t[5]=o*u,t[9]=-a*u,t[2]=-l*u,t[6]=i*h+r,t[10]=e-n*h}else if("XZY"===i){const e=o*c,i=o*l,r=a*c,n=a*l;t[0]=c*u,t[4]=-h,t[8]=l*u,t[1]=e*h+n,t[5]=o*u,t[9]=i*h-r,t[2]=r*h-i,t[6]=a*u,t[10]=n*h+e}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},t.perspective=function(t,e,i,r,n,s,o){const a=2*s/(i-e),c=2*s/(r-n),l=(i+e)/(i-e),u=(r+n)/(r-n),h=-(o+s)/(o-s),d=-2*o*s/(o-s);return t[0]=a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=c,t[6]=0,t[7]=0,t[8]=l,t[9]=u,t[10]=h,t[11]=-1,t[12]=0,t[13]=0,t[14]=d,t[15]=0,t},t.ortho=function(t,e,i,r,n,s,o){const a=1/(i-e),c=1/(r-n),l=1/(o-s),u=(i+e)*a,h=(r+n)*c,d=(o+s)*l;return t[0]=2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-2*l,t[11]=0,t[12]=-u,t[13]=-h,t[14]=-d,t[15]=1,t},t.lookAt=function(t,e,i,n){let s,o,a,c,l,u,h,d,m,f;const p=e[0],g=e[1],y=e[2],b=n[0],_=n[1],x=n[2],v=i[0],w=i[1],A=i[2];return Math.abs(p-v)<Rh&&Math.abs(g-w)<Rh&&Math.abs(y-A)<Rh?r(t):(h=p-v,d=g-w,m=y-A,f=1/Math.sqrt(h*h+d*d+m*m),h*=f,d*=f,m*=f,s=_*m-x*d,o=x*h-b*m,a=b*d-_*h,f=Math.sqrt(s*s+o*o+a*a),f?(f=1/f,s*=f,o*=f,a*=f):(s=0,o=0,a=0),c=d*a-m*o,l=m*s-h*a,u=h*o-d*s,f=Math.sqrt(c*c+l*l+u*u),f?(f=1/f,c*=f,l*=f,u*=f):(c=0,l=0,u=0),t[0]=s,t[1]=c,t[2]=h,t[3]=0,t[4]=o,t[5]=l,t[6]=d,t[7]=0,t[8]=a,t[9]=u,t[10]=m,t[11]=0,t[12]=-(s*p+o*g+a*y),t[13]=-(c*p+l*g+u*y),t[14]=-(h*p+d*g+m*y),t[15]=1,t)},t.targetTo=function(t,e,i,r){const n=e[0],s=e[1],o=e[2],a=r[0],c=r[1],l=r[2];let u=n-i[0],h=s-i[1],d=o-i[2],m=u*u+h*h+d*d;m>0&&(m=1/Math.sqrt(m),u*=m,h*=m,d*=m);let f=c*d-l*h,p=l*u-a*d,g=a*h-c*u;return m=f*f+p*p+g*g,m>0&&(m=1/Math.sqrt(m),f*=m,p*=m,g*=m),t[0]=f,t[1]=p,t[2]=g,t[3]=0,t[4]=h*g-d*p,t[5]=d*f-u*g,t[6]=u*p-h*f,t[7]=0,t[8]=u,t[9]=h,t[10]=d,t[11]=0,t[12]=n,t[13]=s,t[14]=o,t[15]=1,t},t.fromPermutation=function(t,e){n(t);for(let i=0;i<4;i++){a(t,i,e[i],1)}return t},t.getMaxScaleOnAxis=function(t){const e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],r=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,r))};const g=[1,0,0],y=[0,1,0],b=[0,0,1];t.rotX90=d(e(),Hh(90),g),t.rotX180=d(e(),Hh(180),g),t.rotY90=d(e(),Hh(90),y),t.rotY180=d(e(),Hh(180),y),t.rotY270=d(e(),Hh(270),y),t.rotZ90=d(e(),Hh(90),b),t.rotZ180=d(e(),Hh(180),b),t.rotXY90=h(e(),t.rotX90,t.rotY90),t.rotZY90=h(e(),t.rotZ90,t.rotY90),t.rotZYZ90=h(e(),t.rotZY90,t.rotZ90),t.rotZ90X180=h(e(),t.rotZ90,t.rotX180),t.rotY90Z180=h(e(),t.rotY90,t.rotZ180),t.id=i()}(qh||(qh={})),function(t){function e(){const t=[.1,0,0,0,0,0,0,0,0];return t[0]=0,t}function i(){const t=e();return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function r(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}t.zero=e,t.identity=i,t.setIdentity=function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t},t.toArray=function(t,e,i){return e[i+0]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=t[3],e[i+4]=t[4],e[i+5]=t[5],e[i+6]=t[6],e[i+7]=t[7],e[i+8]=t[8],e},t.fromArray=function(t,e,i){return t[0]=e[i+0],t[1]=e[i+1],t[2]=e[i+2],t[3]=e[i+3],t[4]=e[i+4],t[5]=e[i+5],t[6]=e[i+6],t[7]=e[i+7],t[8]=e[i+8],t},t.fromColumns=function(t,e,i,r){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=i[0],t[4]=i[1],t[5]=i[2],t[6]=r[0],t[7]=r[1],t[8]=r[2],t},t.fromMat4=r;const n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];t.fromEuler=function(t,e,i){return qh.fromEuler(n,e,i),r(t,n)},t.create=function(t,i,r,n,s,o,a,c,l){const u=e();return u[0]=t,u[1]=i,u[2]=r,u[3]=n,u[4]=s,u[5]=o,u[6]=a,u[7]=c,u[8]=l,u};const s=i();function o(t,e,i){for(let r=0;r<9;r++)if(Math.abs(t[r]-e[r])>i)return!1;return!0}function a(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function c(t,e){if(t===e){const i=e[1],r=e[2],n=e[5];t[1]=e[3],t[2]=e[6],t[3]=i,t[5]=e[7],t[6]=r,t[7]=n}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t}function l(t,e){const i=e[0],r=e[1],n=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=u*o-a*l,d=-u*s+a*c,m=l*s-o*c;let f=i*h+r*d+n*m;return f?(f=1/f,t[0]=h*f,t[1]=(-u*r+n*l)*f,t[2]=(a*r-n*o)*f,t[3]=d*f,t[4]=(u*i-n*c)*f,t[5]=(-a*i+n*s)*f,t[6]=m*f,t[7]=(-l*i+r*c)*f,t[8]=(o*i-r*s)*f,t):(console.warn("non-invertible matrix.",e),t)}function u(t){const e=t[0],i=t[1],r=t[2],n=t[3],s=t[4],o=t[5],a=t[6],c=t[7],l=t[8];return e*(l*s-o*c)+i*(-l*n+o*a)+r*(c*n-s*a)}function h(t){return t[0]+t[4]+t[8]}function d(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t[2]=e[2]-i[2],t[3]=e[3]-i[3],t[4]=e[4]-i[4],t[5]=e[5]-i[5],t[6]=e[6]-i[6],t[7]=e[7]-i[7],t[8]=e[8]-i[8],t}function m(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[3]=e[3]*i,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*i,t}t.isIdentity=function(t,e){return o(t,s,void 0===e?Rh:e)},t.hasNaN=function(t){for(let e=0;e<9;e++)if(isNaN(t[e]))return!0;return!1},t.clone=function(t){return a(e(),t)},t.areEqual=o,t.setValue=function(t,e,i,r){t[3*i+e]=r},t.getValue=function(t,e,i){return t[3*i+e]},t.copy=a,t.transpose=c,t.invert=l,t.symmtricFromUpper=function(t,e){return t===e?(t[3]=e[1],t[6]=e[2],t[7]=e[5]):(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[1],t[4]=e[4],t[5]=e[5],t[6]=e[2],t[7]=e[5],t[8]=e[8]),t},t.symmtricFromLower=function(t,e){return t===e?(t[1]=e[3],t[2]=e[6],t[5]=e[7]):(t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[3],t[4]=e[4],t[5]=e[7],t[6]=e[6],t[7]=e[7],t[8]=e[8]),t},t.determinant=u,t.trace=h,t.sub=d,t.add=function(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t[3]=e[3]+i[3],t[4]=e[4]+i[4],t[5]=e[5]+i[5],t[6]=e[6]+i[6],t[7]=e[7]+i[7],t[8]=e[8]+i[8],t},t.mul=function(t,e,i){const r=e[0],n=e[1],s=e[2],o=e[3],a=e[4],c=e[5],l=e[6],u=e[7],h=e[8],d=i[0],m=i[1],f=i[2],p=i[3],g=i[4],y=i[5],b=i[6],_=i[7],x=i[8];return t[0]=d*r+m*o+f*l,t[1]=d*n+m*a+f*u,t[2]=d*s+m*c+f*h,t[3]=p*r+g*o+y*l,t[4]=p*n+g*a+y*u,t[5]=p*s+g*c+y*h,t[6]=b*r+_*o+x*l,t[7]=b*n+_*a+x*u,t[8]=b*s+_*c+x*h,t},t.subScalar=function(t,e,i){return t[0]=e[0]-i,t[1]=e[1]-i,t[2]=e[2]-i,t[3]=e[3]-i,t[4]=e[4]-i,t[5]=e[5]-i,t[6]=e[6]-i,t[7]=e[7]-i,t[8]=e[8]-i,t},t.addScalar=function(t,e,i){return t[0]=e[0]+i,t[1]=e[1]+i,t[2]=e[2]+i,t[3]=e[3]+i,t[4]=e[4]+i,t[5]=e[5]+i,t[6]=e[6]+i,t[7]=e[7]+i,t[8]=e[8]+i,t},t.mulScalar=m;const f=Math.PI/3,p=e();t.symmetricEigenvalues=function(e,i){const r=i[1]*i[1]+i[2]*i[2]+i[5]*i[5];if(0===r)e[0]=i[0],e[1]=i[4],e[2]=i[8];else{const n=h(i)/3,s=i[0]-n,o=i[4]-n,a=i[8]-n,c=s*s+o*o+a*a+2*r,l=Math.sqrt(c/6);m(p,t.Identity,n),d(p,i,p),m(p,p,1/l);const g=u(p)/2,y=g<=-1?f:g>=1?0:Math.acos(g)/3;e[0]=n+2*l*Math.cos(y),e[2]=n+2*l*Math.cos(y+2*f),e[1]=3*n-e[0]-e[2]}return e};const g=[.1,0,0],y=[.1,0,0],b=[.1,0,0],_=[.1,0,0],x=[.1,0,0],v=[.1,0,0];t.eigenvector=function(t,e,i){jh.set(g,e[0]-i,e[1],e[2]),jh.set(y,e[1],e[4]-i,e[5]),jh.set(b,e[2],e[5],e[8]-i),jh.cross(_,g,y),jh.cross(x,g,b),jh.cross(v,y,b);const r=jh.dot(_,_),n=jh.dot(x,x),s=jh.dot(v,v);let o=r,a=0;return n>o&&(o=n,a=1),s>o&&(a=2),0===a?jh.scale(t,_,1/Math.sqrt(r)):1===a?jh.scale(t,x,1/Math.sqrt(n)):jh.scale(t,v,1/Math.sqrt(s)),t},t.directionTransform=function(t,e){return r(t,e),l(t,t),c(t,t),t},t.Identity=i(),t.innerProduct=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]+t[4]*e[4]+t[5]*e[5]+t[6]*e[6]+t[7]*e[7]+t[8]*e[8]}}(Wh||(Wh={})),function(t){function e(){const t=[.1,0];return t[0]=0,t}t.zero=e,t.clone=function(t){const i=e();return i[0]=t[0],i[1]=t[1],i},t.create=function(t,i){const r=e();return r[0]=t,r[1]=i,r},t.hasNaN=function(t){return isNaN(t[0])||isNaN(t[1])},t.toArray=function(t,e,i){return e[i+0]=t[0],e[i+1]=t[1],e},t.fromArray=function(t,e,i){return t[0]=e[i+0],t[1]=e[i+1],t},t.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t},t.set=function(t,e,i){return t[0]=e,t[1]=i,t},t.add=function(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t},t.sub=function(t,e,i){return t[0]=e[0]-i[0],t[1]=e[1]-i[1],t},t.mul=function(t,e,i){return t[0]=e[0]*i[0],t[1]=e[1]*i[1],t},t.div=function(t,e,i){return t[0]=e[0]/i[0],t[1]=e[1]/i[1],t},t.scale=function(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t},t.round=function(t,e){return t[0]=Math.round(e[0]),t[1]=Math.round(e[1]),t},t.ceil=function(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t},t.floor=function(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t},t.distance=function(t,e){const i=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(i*i+r*r)},t.squaredDistance=function(t,e){const i=e[0]-t[0],r=e[1]-t[1];return i*i+r*r},t.magnitude=function(t){const e=t[0],i=t[1];return Math.sqrt(e*e+i*i)},t.squaredMagnitude=function(t){const e=t[0],i=t[1];return e*e+i*i},t.inverse=function(t,e){return t[0]=1/e[0],t[1]=1/e[1],t},t.areEqual=function(t,e){return t[0]===e[0]&&t[1]===e[1]},t.toString=function(t,e){return`[${t[0].toPrecision(e)} ${t[1].toPrecision(e)}}]`}}(Xh||(Xh={})),function(t){function e(){const t=[.1,0,0,0];return t[0]=0,t}function i(t,e){return t[0]=e.center[0],t[1]=e.center[1],t[2]=e.center[2],t[3]=e.radius,t}t.zero=e,t.clone=function(t){const i=e();return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i},t.create=function(t,i,r,n){const s=e();return s[0]=t,s[1]=i,s[2]=r,s[3]=n,s},t.fromSphere=i,t.ofSphere=function(t){return i(e(),t)},t.hasNaN=function(t){return isNaN(t[0])||isNaN(t[1])||isNaN(t[2])||isNaN(t[3])},t.toArray=function(t,e,i){return e[i+0]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=t[3],e},t.fromArray=function(t,e,i){return t[0]=e[i+0],t[1]=e[i+1],t[2]=e[i+2],t[3]=e[i+3],t},t.toVec3Array=function(t,e,i){e[i+0]=t[0],e[i+1]=t[1],e[i+2]=t[2]},t.fromVec3Array=function(t,e,i){return t[0]=e[i+0],t[1]=e[i+1],t[2]=e[i+2],t[3]=0,t},t.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},t.set=function(t,e,i,r,n){return t[0]=e,t[1]=i,t[2]=r,t[3]=n,t},t.add=function(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t[3]=e[3]+i[3],t},t.distance=function(t,e){const i=e[0]-t[0],r=e[1]-t[1],n=e[2]-t[2],s=e[3]-t[3];return Math.sqrt(i*i+r*r+n*n+s*s)},t.scale=function(t,e,i){return t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t[4]=e[4]*i,t},t.round=function(t,e){return t[0]=Math.round(e[0]),t[1]=Math.round(e[1]),t[2]=Math.round(e[2]),t[3]=Math.round(e[3]),t},t.ceil=function(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t[3]=Math.ceil(e[3]),t},t.floor=function(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t[3]=Math.floor(e[3]),t},t.squaredDistance=function(t,e){const i=e[0]-t[0],r=e[1]-t[1],n=e[2]-t[2],s=e[3]-t[3];return i*i+r*r+n*n+s*s},t.norm=function(t){const e=t[0],i=t[1],r=t[2],n=t[3];return Math.sqrt(e*e+i*i+r*r+n*n)},t.squaredNorm=function(t){const e=t[0],i=t[1],r=t[2],n=t[3];return e*e+i*i+r*r+n*n},t.transformMat4=function(t,e,i){const r=e[0],n=e[1],s=e[2],o=e[3];return t[0]=i[0]*r+i[4]*n+i[8]*s+i[12]*o,t[1]=i[1]*r+i[5]*n+i[9]*s+i[13]*o,t[2]=i[2]*r+i[6]*n+i[10]*s+i[14]*o,t[3]=i[3]*r+i[7]*n+i[11]*s+i[15]*o,t},t.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},t.inverse=function(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t},t.exactEquals=function(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]},t.equals=function(t,e){const i=t[0],r=t[1],n=t[2],s=t[3],o=e[0],a=e[1],c=e[2],l=e[3];return Math.abs(i-o)<=Rh*Math.max(1,Math.abs(i),Math.abs(o))&&Math.abs(r-a)<=Rh*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(n-c)<=Rh*Math.max(1,Math.abs(n),Math.abs(c))&&Math.abs(s-l)<=Rh*Math.max(1,Math.abs(s),Math.abs(l))},t.toString=function(t,e){return`[${t[0].toPrecision(e)} ${t[1].toPrecision(e)} ${t[2].toPrecision(e)}  ${t[3].toPrecision(e)}]`}}(Yh||(Yh={})),function(t){function e(){const t=[.1,0,0,0];return t[0]=0,t}function i(){const t=e();return t[3]=1,t}function r(t,e,i){i*=.5;const r=Math.sin(i);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(i),t}function n(t,e,i,r){const n=e[0],s=e[1],o=e[2],a=e[3];let c,l,u,h,d,m=i[0],f=i[1],p=i[2],g=i[3];return l=n*m+s*f+o*p+a*g,l<0&&(l=-l,m=-m,f=-f,p=-p,g=-g),1-l>1e-6?(c=Math.acos(l),u=Math.sin(c),h=Math.sin((1-r)*c)/u,d=Math.sin(r*c)/u):(h=1-r,d=r),t[0]=h*n+d*m,t[1]=h*s+d*f,t[2]=h*o+d*p,t[3]=h*a+d*g,t}function s(t,e){const i=e[0]+e[4]+e[8];let r;if(i>0)r=Math.sqrt(i+1),t[3]=.5*r,r=.5/r,t[0]=(e[5]-e[7])*r,t[1]=(e[6]-e[2])*r,t[2]=(e[1]-e[3])*r;else{let i=0;e[4]>e[0]&&(i=1),e[8]>e[3*i+i]&&(i=2);const n=(i+1)%3,s=(i+2)%3;r=Math.sqrt(e[3*i+i]-e[3*n+n]-e[3*s+s]+1),t[i]=.5*r,r=.5/r,t[3]=(e[3*n+s]-e[3*s+n])*r,t[n]=(e[3*n+i]+e[3*i+n])*r,t[s]=(e[3*s+i]+e[3*i+s])*r}return t}t.zero=e,t.identity=i,t.setIdentity=function(t){t[0]=0,t[1]=0,t[2]=0,t[3]=1},t.hasNaN=function(t){return isNaN(t[0])||isNaN(t[1])||isNaN(t[2])||isNaN(t[3])},t.create=function(t,e,r,n){const s=i();return s[0]=t,s[1]=e,s[2]=r,s[3]=n,s},t.setAxisAngle=r,t.getAxisAngle=function(t,e){const i=2*Math.acos(e[3]),r=Math.sin(i/2);return 0!==r?(t[0]=e[0]/r,t[1]=e[1]/r,t[2]=e[2]/r):(t[0]=1,t[1]=0,t[2]=0),i},t.multiply=function(t,e,i){const r=e[0],n=e[1],s=e[2],o=e[3],a=i[0],c=i[1],l=i[2],u=i[3];return t[0]=r*u+o*a+n*l-s*c,t[1]=n*u+o*c+s*a-r*l,t[2]=s*u+o*l+r*c-n*a,t[3]=o*u-r*a-n*c-s*l,t},t.rotateX=function(t,e,i){i*=.5;const r=e[0],n=e[1],s=e[2],o=e[3],a=Math.sin(i),c=Math.cos(i);return t[0]=r*c+o*a,t[1]=n*c+s*a,t[2]=s*c-n*a,t[3]=o*c-r*a,t},t.rotateY=function(t,e,i){i*=.5;const r=e[0],n=e[1],s=e[2],o=e[3],a=Math.sin(i),c=Math.cos(i);return t[0]=r*c-s*a,t[1]=n*c+o*a,t[2]=s*c+r*a,t[3]=o*c-n*a,t},t.rotateZ=function(t,e,i){i*=.5;const r=e[0],n=e[1],s=e[2],o=e[3],a=Math.sin(i),c=Math.cos(i);return t[0]=r*c+n*a,t[1]=n*c-r*a,t[2]=s*c+o*a,t[3]=o*c-s*a,t},t.calculateW=function(t,e){const i=e[0],r=e[1],n=e[2];return t[0]=i,t[1]=r,t[2]=n,t[3]=Math.sqrt(Math.abs(1-i*i-r*r-n*n)),t},t.slerp=n,t.invert=function(t,e){const i=e[0],r=e[1],n=e[2],s=e[3],o=i*i+r*r+n*n+s*s,a=o?1/o:0;return t[0]=-i*a,t[1]=-r*a,t[2]=-n*a,t[3]=s*a,t},t.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},t.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},t.fromMat3=s,t.fromEuler=function(t,e,i){const[r,n,s]=e,o=Math.cos(r/2),a=Math.cos(n/2),c=Math.cos(s/2),l=Math.sin(r/2),u=Math.sin(n/2),h=Math.sin(s/2);switch(i){case"XYZ":t[0]=l*a*c+o*u*h,t[1]=o*u*c-l*a*h,t[2]=o*a*h+l*u*c,t[3]=o*a*c-l*u*h;break;case"YXZ":t[0]=l*a*c+o*u*h,t[1]=o*u*c-l*a*h,t[2]=o*a*h-l*u*c,t[3]=o*a*c+l*u*h;break;case"ZXY":t[0]=l*a*c-o*u*h,t[1]=o*u*c+l*a*h,t[2]=o*a*h+l*u*c,t[3]=o*a*c-l*u*h;break;case"ZYX":t[0]=l*a*c-o*u*h,t[1]=o*u*c+l*a*h,t[2]=o*a*h-l*u*c,t[3]=o*a*c+l*u*h;break;case"YZX":t[0]=l*a*c+o*u*h,t[1]=o*u*c+l*a*h,t[2]=o*a*h-l*u*c,t[3]=o*a*c-l*u*h;break;case"XZY":t[0]=l*a*c-o*u*h,t[1]=o*u*c-l*a*h,t[2]=o*a*h+l*u*c,t[3]=o*a*c+l*u*h;break;default:Kh()}return t};const o=[0,0,0];function a(t,e){const i=e[0],r=e[1],n=e[2],s=e[3];let o=i*i+r*r+n*n+s*s;return o>0&&(o=1/Math.sqrt(o),t[0]=i*o,t[1]=r*o,t[2]=n*o,t[3]=s*o),t}t.fromUnitVec3=function(t,e,i){let r=jh.dot(e,i)+1;return r<Rh?(r=0,Math.abs(e[0])>Math.abs(e[2])?jh.set(o,-e[1],e[0],0):jh.set(o,0,-e[2],e[1])):jh.cross(o,e,i),t[0]=o[0],t[1]=o[1],t[2]=o[2],t[3]=r,a(t,t),t},t.clone=function(t){const i=e();return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i},t.toArray=function(t,e,i){return e[i+0]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=t[3],e},t.fromArray=function(t,e,i){return t[0]=e[i+0],t[1]=e[i+1],t[2]=e[i+2],t[3]=e[i+3],t},t.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},t.set=function(t,e,i,r,n){return t[0]=e,t[1]=i,t[2]=r,t[3]=n,t},t.exactEquals=function(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]},t.equals=function(t,e){const i=t[0],r=t[1],n=t[2],s=t[3],o=e[0],a=e[1],c=e[2],l=e[3];return Math.abs(i-o)<=Rh*Math.max(1,Math.abs(i),Math.abs(o))&&Math.abs(r-a)<=Rh*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(n-c)<=Rh*Math.max(1,Math.abs(n),Math.abs(c))&&Math.abs(s-l)<=Rh*Math.max(1,Math.abs(s),Math.abs(l))},t.add=function(t,e,i){return t[0]=e[0]+i[0],t[1]=e[1]+i[1],t[2]=e[2]+i[2],t[3]=e[3]+i[3],t},t.normalize=a;const c=[0,0,0],l=[1,0,0],u=[0,1,0];t.rotationTo=function(t,e,i){const n=jh.dot(e,i);return n<-.999999?(jh.cross(c,l,e),jh.magnitude(c)<1e-6&&jh.cross(c,u,e),jh.normalize(c,c),r(t,c,Math.PI),t):n>.999999?(t[0]=0,t[1]=0,t[2]=0,t[3]=1,t):(jh.cross(c,e,i),t[0]=c[0],t[1]=c[1],t[2]=c[2],t[3]=1+n,a(t,t))};const h=e(),d=e();t.sqlerp=function(t,e,i,r,s,o){return n(h,e,s,o),n(d,i,r,o),n(t,h,d,2*o*(1-o)),t};const m=[0,0,0,0,0,0,0,0,0];t.setAxes=function(t,e,i,r){return m[0]=i[0],m[3]=i[1],m[6]=i[2],m[1]=r[0],m[4]=r[1],m[7]=r[2],m[2]=-e[0],m[5]=-e[1],m[8]=-e[2],a(t,s(t,m))},t.toString=function(t,e){return`[${t[0].toPrecision(e)} ${t[1].toPrecision(e)} ${t[2].toPrecision(e)}  ${t[3].toPrecision(e)}]`},t.Identity=i()}(Zh||(Zh={})),function(t){function e(t,e,n){const s=function(t,e,i){const r=[];for(let t=0;t<e.length;t++)r[t]=e[e.length-t-1];const n=[1];for(let e=1;e<t.length;e++)n[e]=t[r[e-1]];return{dimensions:t,axisOrderFastToSlow:r,axisOrderSlowToFast:e,accessDimensions:n,defaultCtor:i||Float64Array}}(t,e,n),{get:o,set:a,add:c,dataOffset:l,getCoords:u}=i(s);return{rank:t.length,dimensions:t,axisOrderSlowToFast:e,create:r(s),get:o,set:a,add:c,dataOffset:l,getCoords:u}}function i(t){const{dimensions:e,axisOrderFastToSlow:i}=t;switch(e.length){case 1:return{get:(t,e)=>t[e],set:(t,e,i)=>t[e]=i,add:(t,e,i)=>t[e]+=i,dataOffset:t=>t,getCoords:(t,e)=>(e[0]=t,e)};case 2:if(0===i[0]&&1===i[1]){const t=e[0];return{get:(e,i,r)=>e[r*t+i],set:(e,i,r,n)=>e[r*t+i]=n,add:(e,i,r,n)=>e[r*t+i]+=n,dataOffset:(e,i)=>i*t+e,getCoords:(e,i)=>(i[0]=e%t,i[1]=Math.floor(e/t),i)}}if(1===i[0]&&0===i[1]){const t=e[1];return{get:(e,i,r)=>e[i*t+r],set:(e,i,r,n)=>e[i*t+r]=n,add:(e,i,r,n)=>e[i*t+r]+=n,dataOffset:(e,i)=>e*t+i,getCoords:(e,i)=>(i[0]=Math.floor(e/t),i[1]=e%t,i)}}throw new Error("bad axis order");case 3:if(0===i[0]&&1===i[1]&&2===i[2]){const t=e[0],i=e[1],r=t*i;return{get:(e,i,n,s)=>e[i+n*t+s*r],set:(e,i,n,s,o)=>e[i+n*t+s*r]=o,add:(e,i,n,s,o)=>e[i+n*t+s*r]+=o,dataOffset:(e,i,n)=>e+i*t+n*r,getCoords:(e,r)=>{const n=Math.floor(e/t);return r[0]=e%t,r[1]=n%i,r[2]=Math.floor(n/i),r}}}if(0===i[0]&&2===i[1]&&1===i[2]){const t=e[0],i=e[2],r=t*i;return{get:(e,i,n,s)=>e[i+s*t+n*r],set:(e,i,n,s,o)=>e[i+s*t+n*r]=o,add:(e,i,n,s,o)=>e[i+s*t+n*r]+=o,dataOffset:(e,i,n)=>e+n*t+i*r,getCoords:(e,r)=>{const n=Math.floor(e/t);return r[0]=e%t,r[1]=Math.floor(n/i),r[2]=n%i,r}}}if(1===i[0]&&0===i[1]&&2===i[2]){const t=e[1],i=e[0],r=t*i;return{get:(e,i,n,s)=>e[n+i*t+s*r],set:(e,i,n,s,o)=>e[n+i*t+s*r]=o,add:(e,i,n,s,o)=>e[n+i*t+s*r]+=o,dataOffset:(e,i,n)=>i+e*t+n*r,getCoords:(e,r)=>{const n=Math.floor(e/t);return r[0]=n%i,r[1]=e%t,r[2]=Math.floor(n/i),r}}}if(1===i[0]&&2===i[1]&&0===i[2]){const t=e[1],i=e[2],r=t*i;return{get:(e,i,n,s)=>e[n+s*t+i*r],set:(e,i,n,s,o)=>e[n+s*t+i*r]=o,add:(e,i,n,s,o)=>e[n+s*t+i*r]+=o,dataOffset:(e,i,n)=>i+n*t+e*r,getCoords:(e,r)=>{const n=Math.floor(e/t);return r[0]=Math.floor(n/i),r[1]=e%t,r[2]=n%i,r}}}if(2===i[0]&&0===i[1]&&1===i[2]){const t=e[2],i=e[0],r=t*i;return{get:(e,i,n,s)=>e[s+i*t+n*r],set:(e,i,n,s,o)=>e[s+i*t+n*r]=o,add:(e,i,n,s,o)=>e[s+i*t+n*r]+=o,dataOffset:(e,i,n)=>n+e*t+i*r,getCoords:(e,r)=>{const n=Math.floor(e/t);return r[0]=n%i,r[1]=Math.floor(n/i),r[2]=e%t,r}}}if(2===i[0]&&1===i[1]&&0===i[2]){const t=e[2],i=e[1],r=t*i;return{get:(e,i,n,s)=>e[s+n*t+i*r],set:(e,i,n,s,o)=>e[s+n*t+i*r]=o,add:(e,i,n,s,o)=>e[s+n*t+i*r]+=o,dataOffset:(e,i,n)=>n+i*t+e*r,getCoords:(e,r)=>{const n=Math.floor(e/t);return r[0]=Math.floor(n/i),r[1]=n%i,r[2]=e%t,r}}}throw new Error("bad axis order");default:return{get:(e,...i)=>e[n(t,i)],set:(e,...i)=>e[n(t,i)]=i[i.length-1],add:(e,...i)=>e[n(t,i)]+=i[i.length-1],dataOffset:(...e)=>n(t,e),getCoords:(e,i)=>function(t,e,i){const{dimensions:r,axisOrderFastToSlow:n}=t,s=r.length;let o=e;for(let t=0;t<s;t++){const e=r[n[t]];i[n[t]]=o%e,o=Math.floor(o/e)}return i[n[s+1]]=o,i}(t,e,i)}}}function r(t){const{dimensions:e}=t;let i=1;for(let t=0,r=e.length;t<r;t++)i*=e[t];return e=>new(e||t.defaultCtor)(i)}function n(t,e){const{accessDimensions:i,axisOrderFastToSlow:r}=t,n=i.length-1;let s=i[n]*e[r[n]];for(let t=n-1;t>=0;t--)s=(s+e[r[t]])*i[t];return s}function s(t,e){const i=[];for(let r=0;r<t.length;r++)i[r]=t[e[r]];return i}t.create=function(t,e){return{space:t,data:e}},t.Space=e,t.Data1=function(t){return t},t.Vector=function(t,i){return e([t],[0],i)},t.ColumnMajorMatrix=function(t,i,r){return e([t,i],[1,0],r)},t.RowMajorMatrix=function(t,i,r){return e([t,i],[0,1],r)},t.toMat4=function(t,e,i){if(2!==e.rank)throw new Error("Invalid tensor rank");const r=Math.min(4,e.dimensions[0]),n=Math.min(4,e.dimensions[1]);for(let s=0;s<r;s++)for(let r=0;r<n;r++)qh.setValue(t,s,r,e.get(i,s,r));return t},t.toMat3=function(t,e,i){if(2!==e.rank)throw new Error("Invalid tensor rank");const r=Math.min(3,e.dimensions[0]),n=Math.min(3,e.dimensions[1]);for(let s=0;s<r;s++)for(let r=0;r<n;r++)Wh.setValue(t,s,r,e.get(i,s,r));return t},t.toVec3=function(t,e,i){if(1!==e.rank)throw new Error("Invalid tensor rank");const r=Math.min(3,e.dimensions[0]);for(let e=0;e<r;e++)t[e]=i[e];return t},t.toVec4=function(t,e,i){if(1!==e.rank)throw new Error("Invalid tensor rank");const r=Math.min(4,e.dimensions[0]);for(let e=0;e<r;e++)t[e]=i[e];return t},t.areEqualExact=function(t,e){const i=t.length;if(i!==e.length)return!1;for(let r=0;r<i;r++)if(t[r]!==e[r])return!1;return!0},t.invertAxisOrder=function(t){const e=[];for(let i=0;i<t.length;i++)e[i]=t[t.length-i-1];return e},t.convertToCanonicalAxisIndicesFastToSlow=function(t){const e=new Int32Array(t.length);for(let i=0;i<t.length;i++)e[t[i]]=i;return t=>s(t,e)},t.convertToCanonicalAxisIndicesSlowToFast=function(t){const e=new Int32Array(t.length);for(let i=0;i<t.length;i++)e[t[t.length-i-1]]=i;return t=>s(t,e)}}(Qh||(Qh={})),function(t){let e;function i(t,e){return sd(e.T,t,e,1)}function r(t){return od(t)}!function(t){function e(e,i=t.float){return{"@type":"tensor",T:e.create(),space:e,valueType:"tensor",baseType:i}}t.str={"@type":"str",T:"",valueType:"str"},t.ustr={"@type":"str",T:"",valueType:"str",transform:"uppercase"},t.lstr={"@type":"str",T:"",valueType:"str",transform:"lowercase"},t.int={"@type":"int",T:0,valueType:"int"},t.coord={"@type":"coord",T:0,valueType:"float"},t.float={"@type":"float",T:0,valueType:"float"},t.Str=function(t){var e;return{"@type":"str",T:null!==(e=null==t?void 0:t.defaultValue)&&void 0!==e?e:"",transform:null==t?void 0:t.transform,valueType:"str"}},t.Int=function(t=0){return{"@type":"int",T:t,valueType:"int"}},t.Float=function(t=0){return{"@type":"float",T:t,valueType:"float"}},t.Tensor=e,t.Vector=function(i,r=t.float){return e(Qh.Vector(i,"int"===r["@type"]?Int32Array:Float64Array),r)},t.Matrix=function(i,r,n=t.float){return e(Qh.ColumnMajorMatrix(i,r,"int"===n["@type"]?Int32Array:Float64Array),n)},t.Aliased=function(t){return t},t.List=function(t,e,i=[]){return{"@type":"list",T:i,separator:t,itemParse:e,valueType:"list"}}}(e=t.Schema||(t.Schema={})),t.is=function(t){return!!t&&!!t.schema&&!!t.value},t.ValueKind={Present:0,NotPresent:1,Unknown:2},t.Undefined=i,t.ofConst=function(t,e,i){return sd(t,e,i,0)},t.ofLambda=r,t.range=function(t,i){return r({value:e=>e+t,rowCount:Math.max(i-t+1,0),schema:e.int})},t.ofArray=function(t){return ad(t)},t.ofIntArray=function(t){return ad({array:t,schema:e.int})},t.ofFloatArray=function(t){return ad({array:t,schema:e.float})},t.ofStringArray=function(t){return ad({array:t,schema:e.str})},t.ofStringAliasArray=function(t){return ad({array:t,schema:e.Aliased(e.str)})},t.ofStringListArray=function(t,i=","){return ad({array:t,schema:e.List(i,(t=>t))})},t.ofIntTokens=function(t){const{count:i,data:r,indices:n}=t;return od({value:t=>id(r,n[2*t],n[2*t+1])||0,rowCount:i,schema:e.int})},t.ofFloatTokens=function(t){const{count:i,data:r,indices:n}=t;return od({value:t=>nd(r,n[2*t],n[2*t+1])||0,rowCount:i,schema:e.float})},t.ofStringTokens=function(t){const{count:i,data:r,indices:n}=t;return od({value:t=>{const e=r.substring(n[2*t],n[2*t+1]);return"."===e||"?"===e?"":e},rowCount:i,schema:e.str})},t.window=function(t,e,i){return cd(t,e,i)},t.view=function(t,e,i=!0){return ld(t,e,i)},t.createFirstIndexMap=function(t){return function(t){const e=new Map;for(let i=0,r=t.rowCount;i<r;i++){const r=t.value(i);e.has(r)||e.set(t.value(i),i)}return e}(t)},t.createIndexer=function(t){return function(t){const e=new Map;for(let i=0,r=t.rowCount;i<r;i++){const r=t.value(i);e.has(r)||e.set(t.value(i),i)}return t=>e.has(t)?e.get(t):-1}(t)},t.mapToArray=function(t,e,i){return function(t,e,i){const r=new i(t.rowCount);for(let i=0,n=t.rowCount;i<n;i++)r[i]=e(t.value(i));return r}(t,e,i||Array)},t.areEqual=function(t,e){return function(t,e){return t===e||t.rowCount===e.rowCount&&t.isDefined===e.isDefined&&t.schema.valueType===e.schema.valueType&&(t.__array&&e.__array?function(t,e){const i=t.__array,r=e.__array;for(let e=0,n=t.rowCount;e<n;e++)if(i[e]!==r[e])return!1;return!0}(t,e):function(t,e){const i=t.value,r=e.value;for(let e=0,n=t.rowCount;e<n;e++)if(i(e)!==r(e))return!1;return!0}(t,e))}(t,e)},t.indicesOf=function(t,e){return function(t,e){const i=[],r=t.value;for(let n=0,s=t.rowCount;n<s;n++)e(r(n))&&(i[i.length]=n);return i}(t,e)},t.asArrayColumn=function(t,e){return t.__array?t:t.isDefined?ad({array:t.toArray({array:e}),schema:t.schema,valueKind:t.valueKind}):i(t.rowCount,t.schema)},t.copyToArray=function(t,e,i=0){if(!t.isDefined)return;const r=t.__array;if(r)for(let t=0,n=r.length;t<n;t++)e[i+t]=r[t];else for(let r=0,n=t.rowCount;r<n;r++)e[i+r]=t.value(r)},t.isIdentity=function(t){for(let e=0,i=t.rowCount;e<i;e++)if(e!==t.value(e))return!1;return!0}}(Jh||(Jh={})),function(t){t.create=function(t){return t},t.has=function(t,e){return!!(t&e)},t.hasAll=function(t,e){return!!e&&(t&e)===e}}(td||(td={})),function(t){t.create=function(t=512){return{current:[],offset:0,capacity:t,chunks:[]}},t.getString=function(t){return t.chunks.length?(t.offset>0&&(t.chunks[t.chunks.length]=t.current.length===t.offset?t.current.join(""):t.current.slice(0,t.offset).join("")),t.chunks.join("")):t.current.length===t.offset?t.current.join(""):t.current.splice(0,t.offset).join("")},t.getSize=function(t){let e=0;for(const i of t.chunks)e+=i.length;for(let i=0;i<t.offset;i++)e+=t.current[i].length;return e},t.getChunks=function(t){return t.offset>0&&(t.current.length===t.offset?t.chunks[t.chunks.length]=t.current.join(""):t.chunks[t.chunks.length]=t.current.slice(0,t.offset).join(""),t.offset=0),t.chunks};const e=[];function i(t,i){i>0&&r(t,e[i])}function r(t,e){t.offset===t.capacity&&(t.chunks[t.chunks.length]=t.current.join(""),t.offset=0),t.current[t.offset++]=e}!function(){let t="";for(let i=0;i<512;i++)e[i]=t,t+=" "}(),t.newline=function(t){r(t,"\n")},t.whitespace=i,t.whitespace1=function(t){r(t," ")},t.write=function(t,e){e&&(t.offset===t.capacity&&(t.chunks[t.chunks.length]=t.current.join(""),t.offset=0),t.current[t.offset++]=e)},t.writeSafe=r,t.writePadLeft=function(t,e,n){if(!e)return void i(t,n);i(t,n-e.length),r(t,e)},t.writePadRight=function(t,e,n){if(!e)return void i(t,n);const s=n-e.length;r(t,e),i(t,s)},t.writeInteger=function(t,e){r(t,""+e)},t.writeIntegerAndSpace=function(t,e){r(t,e+" ")},t.writeIntegerPadLeft=function(t,e,n){const s=""+e;i(t,n-s.length),r(t,s)},t.writeIntegerPadRight=function(t,e,n){const s=""+e,o=n-s.length;r(t,s),i(t,o)},t.writeFloat=function(t,e,i){r(t,""+Math.round(i*e)/i)},t.writeFloatPadLeft=function(t,e,n,s){const o=""+Math.round(n*e)/n;i(t,s-o.length),r(t,o)},t.writeFloatPadRight=function(t,e,n,s){const o=""+Math.round(n*e)/n,a=s-o.length;r(t,o),i(t,a)}}(ed||(ed={}));const xd=function(){if("undefined"!=typeof window&&window.performance){const t=window.performance;return()=>t.now()}return"undefined"!=typeof process&&"undefined"!==process.hrtime&&"function"==typeof process.hrtime?()=>{const t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:Date.now?()=>Date.now():()=>+new Date}();var vd,wd,Ad;function Sd(t,e){return t-e}function Cd(t=0,e=Number.MAX_SAFE_INTEGER){let i=t;return()=>{const t=i;return i=(i+1)%e,t}}!function(t){const e="undefined"!=typeof btoa?btoa:t=>Buffer.from(t).toString("base64"),i=[];t.create22=function(){let t=+new Date+xd();for(let e=0;e<16;e++)i[e]=String.fromCharCode((t+255*Math.random())%255|0),t=Math.floor(t/255);return e(i.join("")).replace(/\+/g,"-").replace(/\//g,"_").substr(0,22)},t.createv4=function(){let t=+new Date+xd();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?i:3&i|8).toString(16)}))},t.is=function(t){return"string"==typeof t}}(vd||(vd={})),function(t){class e{has(t){return!1}forEach(t,e){return e}constructor(){this.size=0}}class i{has(t){return t===this.idx}forEach(t,e){return t(this.idx,e),e}constructor(t){this.idx=t,this.size=1}}class r{has(t){return t<this.length&&!!this.mask[t]}_forEach(t,e){for(let i=0;i<this.length;i++)this.mask[i]&&t(i,e)}forEach(t,e){return this._forEach(t,e),e}constructor(t,e){this.mask=t,this.size=e,this.length=t.length}}class n{has(t){return!0}_forEach(t,e){for(let i=0;i<this.size;i++)t(i,e)}forEach(t,e){return this._forEach(t,e),e}constructor(t){this.size=t}}class s{has(t){return this.set.has(t)}_forEach(t,e){for(const i of this.flatten())t(i,e)}flatten(){if(this._flat)return this._flat;const t=new Int32Array(this.size);let e=0;return this.set.forEach((i=>t[e++]=i)),function(t){Array.prototype.sort.call(t,Sd)}(t),this._flat=t,this._flat}forEach(t,e){return this._forEach(t,e),e}constructor(t){this.set=t,this._flat=void 0,this.size=t.size}}function o(t){return new s(t)}function a(t,e){return new r(t,e)}t.always=function(t){return new n(t)},t.never=new e,t.ofSet=o,t.singleton=function(t){return new i(t)},t.ofUniqueIndices=function(t){const o=t.length;if(0===o)return new e;if(1===o)return new i(t[0]);let a=0;for(const e of t)e>a&&(a=e);if(o===a)return new n(o);if(o/a<1/12){const e=new Set;for(const i of t)e.add(i);return new s(e)}const c=new Int8Array(a+1);for(const e of t)c[e]=1;return new r(c,t.length)},t.ofMask=a,t.hasAny=function(t,e){for(const i of e)if(t.has(i))return!0;return!1},t.complement=function(t,e){let i=0,r=0;if(e.forEach((e=>{t.has(e)||(i++,e>r&&(r=e))})),i/r<1/12){const i=new Set;return e.forEach((e=>{t.has(e)||i.add(e)})),o(i)}{const n=new Uint8Array(r+1);return e.forEach((e=>{t.has(e)||(n[e]=1)})),a(n,i)}}}(wd||(wd={})),function(t){t.create=function(t){return{ref:t}},t.set=function(t,e){return t.ref=e,t}}(Ad||(Ad={}));const Pd=Cd(0,2147483647);var Id,kd,Md,Td,Dd;function Bd(t){const{data:e,indices:i}=t;return function(t,r){const n=i[2*t],s=i[2*r],o=i[2*t+1]-n;if(o!==i[2*r+1]-s)return!1;for(let t=0;t<o;t++)if(e.charCodeAt(t+n)!==e.charCodeAt(t+s))return!1;return!0}}function Fd(t,e){return{name:e,blocks:t}}function Ed(t,e,i,r=[]){return{categoryNames:t,header:i,categories:e,saveFrames:r,getField(t){const[i,r]=t.split(".");return e[i].getField(r||"")}}}function Od(t,e,i,r){return{rowCount:e,name:t,fieldNames:[...i],getField:t=>r[t]}}!function(t){t.create=function(t,e){return{id:Pd(),version:0,value:t,metadata:e}},t.withValue=function(t,e){return{id:t.id,version:t.version+1,value:e,metadata:t.metadata}}}(Id||(Id={})),function(t){function e(t,e){return Ad.set(t,Id.withValue(t.ref,e))}t.create=function(t,e){return Ad.create(Id.create(t,e))},t.update=e,t.set=function(t,e){return Ad.set(t,e)},t.updateIfChanged=function(t,i){return t.ref.value!==i?e(t,i):t}}(kd||(kd={})),function(t){function e(t,e,i){const r=Object.create(null),n=Object.keys(e);r._rowCount=i.length,r._columns=n,r._schema=e;for(const e of n)r[e]=Jh.view(t[e],i);return r}function i(t,e){const i=Object.create(null),{_columns:r}=t;for(let n=0;n<r.length;n++){const s=r[n];i[s]=t[s].value(e)}return i}t.is=function(t){return t&&"number"==typeof t._rowCount&&!!t._columns&&!!t._schema},t.pickColumns=function(t,e,i={}){const r=Object.create(null),n=Object.keys(t);r._rowCount=e._rowCount,r._columns=n,r._schema=t;for(const t of n)if(e[t])r[t]=e[t];else{if(!i[t])throw Error(`Cannot find column '${t}'.`);r[t]=i[t]}return r},t.ofColumns=function(t,e){const i=Object.keys(e);return{_rowCount:e[i[0]].rowCount,_columns:i,_schema:t,...e}},t.ofPartialColumns=function(t,e,i){const r=Object.create(null),n=Object.keys(t);r._rowCount=i,r._columns=n,r._schema=t;for(const s of n)r[s]=s in e?e[s]:Jh.Undefined(i,t[s]);return r},t.ofUndefinedColumns=function(t,e){const i=Object.create(null),r=Object.keys(t);i._rowCount=e,i._columns=r,i._schema=t;for(const n of r)i[n]=Jh.Undefined(e,t[n]);return i},t.ofRows=function(t,e){const i=Object.create(null),r=e.length,n=Object.keys(t);i._rowCount=r,i._columns=n,i._schema=t;for(const s of n)i[s]=Jh.ofLambda({rowCount:r,schema:t[s],value:t=>e[t][s],valueKind:t=>void 0===e[t][s]?1:0});return i},t.ofArrays=function(t,e){var i;const r=Object.create(null),n=Object.keys(t);r._rowCount=0,r._columns=n,r._schema=t;for(const s of n)void 0!==e[s]?(r[s]=Jh.ofArray({array:e[s],schema:t[s]}),r._rowCount=null===(i=e[s])||void 0===i?void 0:i.length):r[s]=Jh.Undefined(r._rowCount,t[s]);return r},t.view=e,t.pick=function(t,i,r){const n=[];for(let e=0,i=t._rowCount;e<i;++e)r(e)&&n.push(e);return e(t,i,n)},t.window=function(t,e,i,r){if(0===i&&r===t._rowCount)return t;const n=Object.create(null),s=Object.keys(e);n._rowCount=r-i,n._columns=s,n._schema=e;for(const e of s)n[e]=Jh.window(t[e],i,r);return n},t.concat=function(t,e){const i=Object.create(null),r=Object.keys(e);i._rowCount=0;for(const e of t)i._rowCount+=e._rowCount;const n={};for(const t of r)n[t]=new Array(i._rowCount);i._columns=r,i._schema=e;let s=0;for(const e of t){for(const t of r)Jh.copyToArray(e[t],n[t],s);s+=e._rowCount}for(const t of r)i[t]=Jh.ofArray({array:n[t],schema:e[t]});return i},t.columnToArray=function(t,e,i){t[e]=Jh.asArrayColumn(t[e],i)},t.sort=function(t,e){const i=new Int32Array(t._rowCount);for(let t=0,e=i.length;t<e;t++)i[t]=t;_d(i,((t,i,r)=>e(i,r)));let r=!0;for(let t=0,e=i.length;t<e;t++)if(i[t]!==t){r=!1;break}if(r)return t;const n=Object.create(null);n._rowCount=t._rowCount,n._columns=t._columns,n._schema=t._schema;for(const e of t._columns)n[e]=Jh.view(t[e],i,!1);return n},t.areEqual=function(t,e){if(t._rowCount!==e._rowCount)return!1;if(t._columns.length!==e._columns.length)return!1;for(const i of t._columns)if(!e[i])return!1;for(const i of t._columns)if(!Jh.areEqual(t[i],e[i]))return!1;return!0},t.getRow=i,t.pickRow=function(t,e){for(let r=0,n=t._rowCount;r<n;++r)if(e(r))return i(t,r)},t.getRows=function(t){const e=[],{_rowCount:r}=t;for(let n=0;n<r;n++)e[n]=i(t,n);return e},t.toArrays=function(t){const e={},{_columns:i}=t;for(let r=0;r<i.length;r++){const n=i[r];e[n]=t[n].toArray()}return e},t.formatToString=function(t){const e=ed.create(),{_columns:i,_rowCount:r}=t;let n=1;ed.write(e,"|");for(let t=0;t<i.length;t++)ed.write(e,i[t]),ed.write(e,"|"),n+=i[t].length+1;ed.newline(e),ed.write(e,new Array(n+1).join("-")),ed.newline(e);for(let n=0;n<r;n++){ed.write(e,"|");for(let r=0;r<i.length;r++){const s=t[i[r]];0===s.valueKind(n)?(ed.write(e,s.value(n)),ed.write(e,"|")):ed.write(e,".|")}ed.newline(e)}return ed.getString(e)}}(Md||(Md={})),function(t){t.ofTables=function(t,e,i){const r=Object.keys(i),n=Object.create(null),s=[];n._name=t,n._tableNames=s,n._schema=e;for(const t of r)Md.is(i[t])&&(n[t]=i[t],s[s.length]=t);return n},t.getTablesAsRows=function(t){const e={};for(const i of t._tableNames)e[i]=Md.getRows(t[i]);return e}}(Td||(Td={})),function(t){function e(t,e){const i=Object.keys(e);return{rowCount:i.length>0?e[i[0]].rowCount:0,name:t,fieldNames:i,getField:t=>e[t]}}t.empty=function(t){return{rowCount:0,name:t,fieldNames:[],getField(t){}}},t.ofFields=e,t.ofTable=function(t,i){const r={};for(const t of i._columns)r[t]=Dd.ofColumn(i[t]);return e(t,r)}}(Od||(Od={})),function(t){function e(t){const e=t.length,i=e=>{const i=t[e];return i&&"."!==i&&"?"!==i?i:""},r=e=>{const i=t[e];return id(i,0,i.length)||0},n=e=>{const i=t[e];return nd(i,0,i.length)||0};return{__array:void 0,binaryEncoding:void 0,isDefined:!0,rowCount:e,str:i,int:r,float:n,valueKind:e=>{const i=t[e],r=i.length;if(r>1)return 0;if(0===r)return 1;const n=i.charCodeAt(0);return 46===n?1:63===n?2:0},areValuesEqual:(e,i)=>t[e]===t[i],toStringArray:r=>r?Eh(e,i,r):t,toIntArray:t=>Eh(e,r,t),toFloatArray:t=>Eh(e,n,t)}}function i(t){const{rowCount:e,valueKind:i,areValuesEqual:r,isDefined:n}=t;let s,o,a;switch(t.schema.valueType){case"float":case"int":s=e=>""+t.value(e),o=t.value,a=t.value;break;case"str":s=t.value,o=e=>{const i=t.value(e);return id(i,0,i.length)||0},a=e=>{const i=t.value(e);return nd(i,0,i.length)||0};break;case"list":const{separator:e}=t.schema;s=i=>t.value(i).join(e),o=t=>NaN,a=t=>NaN;break;default:throw new Error(`unsupported valueType '${t.schema.valueType}'`)}return{__array:void 0,binaryEncoding:void 0,isDefined:n,rowCount:e,str:s,int:o,float:a,valueKind:i,areValuesEqual:r,toStringArray:t=>Eh(e,s,t),toIntArray:t=>Eh(e,o,t),toFloatArray:t=>Eh(e,a,t)}}t.ofString=function(t){return e([t])},t.ofStrings=e,t.ofNumbers=function(t){const e=t.length,i=e=>""+t[e],r=e=>t[e],n=i=>!i||i.array&&t instanceof i.array?t:Eh(e,r,i);return{__array:void 0,binaryEncoding:void 0,isDefined:!0,rowCount:e,str:i,int:r,float:r,valueKind:t=>0,areValuesEqual:(e,i)=>t[e]===t[i],toStringArray:t=>Eh(e,i,t),toIntArray:n,toFloatArray:n}},t.ofTokens=function(t){const{data:e,indices:i,count:r}=t,n=t=>{const r=e.substring(i[2*t],i[2*t+1]);return"."===r||"?"===r?"":r},s=t=>id(e,i[2*t],i[2*t+1])||0,o=t=>nd(e,i[2*t],i[2*t+1])||0;return{__array:void 0,binaryEncoding:void 0,isDefined:!0,rowCount:r,str:n,int:s,float:o,valueKind:t=>{const r=i[2*t],n=i[2*t+1]-r;if(n>1)return 0;if(0===n)return 1;const s=e.charCodeAt(r);return 46===s?1:63===s?2:0},areValuesEqual:Bd(t),toStringArray:t=>Eh(r,n,t),toIntArray:t=>Eh(r,s,t),toFloatArray:t=>Eh(r,o,t)}},t.ofColumn=i,t.ofUndefined=function(t,e){return i(Jh.Undefined(t,e))}}(Dd||(Dd={}));const $d="undefined"!=typeof setImmediate?"undefined"!=typeof window?{setImmediate:(t,...e)=>window.setImmediate(t,...e),clearImmediate:t=>window.clearImmediate(t)}:{setImmediate:setImmediate,clearImmediate:clearImmediate}:function(){const t=function(){const t="undefined"!=typeof window&&window,e="undefined"!=typeof self&&"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&self,i="undefined"!=typeof global&&global;return t||i||e}(),e={},i="undefined"!=typeof document?document:void 0;let r,n=1;function s(t){delete e[t]}function o(t){const i=e[t];s(t),function(t){const e=t.callback,i=t.args;switch(i.length){case 0:e();break;case 1:e(i[0]);break;case 2:e(i[0],i[1]);break;case 3:e(i[0],i[1],i[2]);break;default:e.apply(void 0,i)}}(i)}return"undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?r=function(t){process.nextTick((function(){o(t)}))}:function(){if(t&&t.postMessage&&!t.importScripts){let e=!0;const i=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=i,e}}()?function(){const e="setImmediate$"+Math.random()+"$",i=function(i){i.source===t&&"string"==typeof i.data&&0===i.data.indexOf(e)&&o(+i.data.slice(e.length))};window.addEventListener?window.addEventListener("message",i,!1):window.attachEvent("onmessage",i),r=function(t){window.postMessage(e+t,"*")}}():"undefined"!=typeof MessageChannel?function(){const t=new MessageChannel;t.port1.onmessage=function(t){o(t.data)},r=function(e){t.port2.postMessage(e)}}():i&&"onreadystatechange"in i.createElement("script")?function(){const t=i.documentElement;r=function(e){let r=i.createElement("script");r.onreadystatechange=function(){o(e),r.onreadystatechange=null,t.removeChild(r),r=null},t.appendChild(r)}}():r=function(t){setTimeout(o,0,t)},{setImmediate:function(t,...i){"function"!=typeof t&&(t=new Function(""+t));const s={callback:t,args:i};return e[n]=s,r(n),n++},clearImmediate:s}}();function Rd(t){$d.setImmediate(t)}const Ld={setImmediate:$d.setImmediate,clearImmediate:$d.clearImmediate,immediatePromise:()=>new Promise(Rd),delay:(t,e=void 0)=>new Promise((i=>setTimeout(i,t,e)))};!function(){try{return"production"===process.env.NODE_ENV}catch(t){return!1}}(),function(){try{const t=process.env.DEBUG;return"*"===t||"molstar"===t}catch(t){return!1}}();const Nd="undefined"!=typeof performance&&!!performance.mark&&performance.measure&&!1;var zd;function Vd(t,e,i=250){const r=function(t,e,i){const r={abortRequested:!1,treeAborted:!1,reason:""};return{updateRateMs:i,lastNotified:xd(),observer:e,abortToken:r,taskId:t.id,root:{progress:Ud(t),children:[]},tryAbort:jd(r)}}(t,e,i);return qd(t,new Kd(r,r.root))}function Ud(t){return{taskId:t.id,taskName:t.name,message:"",startedTime:0,canAbort:!0,isIndeterminate:!0,current:0,max:0}}function jd(t){return e=>{t.abortRequested=!0,t.reason=e||t.reason}}function Gd(t){return{progress:{...t.progress},children:t.children.map(Gd)}}function Hd(t){return t.progress.canAbort&&t.children.every(Hd)}async function qd(t,e){zd.markStart(t),e.node.progress.startedTime=xd();try{const i=await t.f(e);return zd.markEnd(t),zd.measure(t),e.info.abortToken.abortRequested&&Wd(e.info),i}catch(i){throw Qd.isAbort(i)&&(e.isAborted=!0,e.node.children.length>0&&await new Promise((t=>{e.onChildrenFinished=t})),t.onAbort&&t.onAbort()),i}}function Wd(t){throw t.abortToken.treeAborted||(t.abortToken.treeAborted=!0,Xd(t.root),Yd(t,xd())),Qd.Aborted(t.abortToken.reason)}function Xd(t){const e=t.progress;e.isIndeterminate=!0,e.canAbort=!1,e.message="Aborting...";for(const e of t.children)Xd(e)}function Yd(t,e){t.lastNotified=e;const i=function(t){return{root:Gd(t.root),canAbort:Hd(t.root),requestAbort:t.tryAbort}}(t);t.observer(i)}!function(t){function e(t){return`startTask${t.id}`}function i(t){return`endTask${t.id}`}t.markStart=function(t){Nd&&performance.mark(e(t))},t.markEnd=function(t){Nd&&performance.mark(i(t))},t.measure=function(t){Nd&&performance.measure(`✳️ ${t.name}`,e(t),i(t))}}(zd||(zd={}));class Kd{checkAborted(){this.info.abortToken.abortRequested&&(this.isAborted=!0,Wd(this.info))}get shouldUpdate(){return this.checkAborted(),xd()-this.lastUpdatedTime>this.info.updateRateMs}updateProgress(t){if(this.checkAborted(),!t)return;const e=this.node.progress;"string"==typeof t?(e.message=t,e.isIndeterminate=!0):(void 0!==t.canAbort&&(e.canAbort=t.canAbort),void 0!==t.message&&(e.message=t.message),void 0!==t.current&&(e.current=t.current),void 0!==t.max&&(e.max=t.max),e.isIndeterminate=void 0===e.current||void 0===e.max,void 0!==t.isIndeterminate&&(e.isIndeterminate=t.isIndeterminate))}update(t,e){if(this.lastUpdatedTime=xd(),this.updateProgress(t),!e)return Yd(this.info,this.lastUpdatedTime),this.checkAborted(),Ld.immediatePromise()}async runChild(t,e){this.updateProgress(e);const i={progress:Ud(t),children:[]},r=this.node.children;r.push(i);const n=new Kd(this.info,i);try{return await qd(t,n)}catch(t){if(Qd.isAbort(t)&&this.isAborted)return;throw t}finally{const t=r.indexOf(i);if(t>=0){for(let e=t,i=r.length-1;e<i;e++)r[e]=r[e+1];r.pop()}0===r.length&&this.onChildrenFinished&&this.onChildrenFinished()}}constructor(t,e){this.isSynchronous=!1,this.isExecuting=!0,this.lastUpdatedTime=0,this.onChildrenFinished=void 0,this.node=e,this.info=t}}const Zd=new class{constructor(){this.shouldUpdate=!1,this.isSynchronous=!0}update(t,e){}};var Qd,Jd,tm,em,im,rm;async function nm(t,e,i,r,n){let s=Math.max(e,0),o=0,a=0;if(t.isSynchronous)return r(Number.MAX_SAFE_INTEGER,i),i;let c=xd(),l=0,u=0;for(;(l=r(s,i))>0;){o+=l;const e=xd()-c;u+=e,a+=e,t.shouldUpdate&&(await n(t,i,o),s=Math.round(u*o/a)+1,c=xd(),u=0)}return t.shouldUpdate&&await n(t,i,o),i}function sm(t){return{data:t,position:0,length:t.length,lineNumber:1,tokenStart:0,tokenEnd:0}}function om(t){for(;t.position<t.length;)switch(t.data.charCodeAt(t.position)){case 9:case 10:case 13:case 32:return void(t.tokenEnd=t.position);default:++t.position}t.tokenEnd=t.position}function am(t){return!(t.length-t.position<2)&&(39===t.data.charCodeAt(t.position+1)&&39===t.data.charCodeAt(t.position+2))}function cm(t,e,i){let r;const n=i-e,s=t.tokenStart-e,o=t.tokenEnd-t.tokenStart;if(o<n)return!1;for(r=e;r<i;++r)if(t.data.charCodeAt(r)!==t.data.charCodeAt(r+s))return!1;return n===o||46===t.data.charCodeAt(r+s)}function lm(t){let e;for(e=t.tokenStart;e<t.tokenEnd;++e)if(46===t.data.charCodeAt(e))return e;return e}function um(t,e){return t.data.substring(t.tokenStart,e)}function hm(t){return t.data.substring(t.tokenStart,t.tokenEnd)}function dm(t){const e=function(t){let e=10;for(;t.position<t.length;){const i=t.data.charCodeAt(t.position);switch(i){case 9:case 32:e=i,++t.position;break;case 10:13!==e&&++t.lineNumber,e=i,++t.position;break;case 13:e=i,++t.position,++t.lineNumber;break;default:return e}}return e}(t);if(t.position>=t.length)return void(t.tokenType=6);t.tokenStart=t.position,t.tokenEnd=t.position,t.isEscaped=!1;const i=t.data.charCodeAt(t.position);switch(i){case 35:!function(t){for(;t.position<t.length;){const e=t.data.charCodeAt(t.position);if(10===e||13===e)return;++t.position}}(t),t.tokenType=5;break;case 39:if(am(t)){!function(t){for(t.position+=3;t.position<t.length;){if(39===t.data.charCodeAt(t.position)&&am(t))return t.tokenStart+=3,t.tokenEnd=t.position,t.isEscaped=!0,void(t.position+=3);++t.position}t.tokenEnd=t.position}(t),t.tokenType=3;break}case 34:!function(t,e){let i,r;for(++t.position;t.position<t.length;)if(r=t.data.charCodeAt(t.position),r===e)switch(i=t.data.charCodeAt(t.position+1),i){case 9:case 10:case 13:case 32:return t.tokenStart++,t.tokenEnd=t.position,t.isEscaped=!0,void++t.position;default:if(void 0===i)return t.tokenStart++,t.tokenEnd=t.position,t.isEscaped=!0,void++t.position;++t.position}else{if(10===r||13===r)return void(t.tokenEnd=t.position);++t.position}t.tokenEnd=t.position}(t,i),t.tokenType=3;break;case 59:10===e||13===e?function(t){let e,i=59,r=t.position+1;for(;r<t.length;){if(e=t.data.charCodeAt(r),59===e&&(10===i||13===i)){for(t.position=r+1,t.tokenStart++,r--,e=t.data.charCodeAt(r);10===e||13===e;)r--,e=t.data.charCodeAt(r);return t.tokenEnd=r+1,void(t.isEscaped=!0)}(13===e||10===e&&13!==i)&&t.lineNumber++,i=e,++r}t.position=r}(t):om(t),t.tokenType=3;break;default:t.isImportGet?function(t){for(;t.position<t.length;){if(93===t.data.charCodeAt(t.position))return++t.position,t.tokenEnd=t.position,void(t.isImportGet=!1);++t.position}}(t):om(t),t.isEscaped?t.tokenType=3:95===t.data.charCodeAt(t.tokenStart)?(t.inSaveFrame&&function(t){return t.tokenEnd-t.tokenStart==11&&105===t.data.charCodeAt(t.tokenStart+1)&&109===t.data.charCodeAt(t.tokenStart+2)&&112===t.data.charCodeAt(t.tokenStart+3)&&111===t.data.charCodeAt(t.tokenStart+4)&&114===t.data.charCodeAt(t.tokenStart+5)&&116===t.data.charCodeAt(t.tokenStart+6)&&46===t.data.charCodeAt(t.tokenStart+7)&&103===t.data.charCodeAt(t.tokenStart+8)&&101===t.data.charCodeAt(t.tokenStart+9)&&116===t.data.charCodeAt(t.tokenStart+10)}(t)&&(t.isImportGet=!0),t.tokenType=4):t.tokenEnd-t.tokenStart>=5&&95===t.data.charCodeAt(t.tokenStart+4)?!function(t){let e=t.data.charCodeAt(t.tokenStart);return!(68!==e&&100!==e||(e=t.data.charCodeAt(t.tokenStart+1),65!==e&&97!==e||(e=t.data.charCodeAt(t.tokenStart+2),84!==e&&116!==e||(e=t.data.charCodeAt(t.tokenStart+3),65!==e&&97!==e))))}(t)?!function(t){let e=t.data.charCodeAt(t.tokenStart);return!(83!==e&&115!==e||(e=t.data.charCodeAt(t.tokenStart+1),65!==e&&97!==e||(e=t.data.charCodeAt(t.tokenStart+2),86!==e&&118!==e||(e=t.data.charCodeAt(t.tokenStart+3),69!==e&&101!==e))))}(t)?!function(t){if(t.tokenEnd-t.tokenStart!=5)return!1;let e=t.data.charCodeAt(t.tokenStart);return!(76!==e&&108!==e||(e=t.data.charCodeAt(t.tokenStart+1),79!==e&&111!==e||(e=t.data.charCodeAt(t.tokenStart+2),79!==e&&111!==e||(e=t.data.charCodeAt(t.tokenStart+3),80!==e&&112!==e))))}(t)?t.tokenType=3:t.tokenType=2:t.tokenType=1:t.tokenType=0:t.tokenType=3}}function mm(t){for(dm(t);5===t.tokenType;)dm(t)}function fm(){return{categoryNames:[],categoryData:Object.create(null)}}function pm(t,e){const i=Object.create(null);for(const r of t){const t=e[r];i[r]=Od(t.name,t.rowCount,t.fieldNames,t.fields)}return i}function gm(t,e,i){return Ed(t.categoryNames,pm(t.categoryNames,t.categoryData),e,i)}function ym(t,e){return Ed(t.categoryNames,pm(t.categoryNames,t.categoryData),e)}function bm(t,e,i,r,n){if(e in t.categoryData){const i=t.categoryData[e];i.fieldNames.push(...r),Object.assign(i.fields,n)}else t.categoryData[e]={name:e,rowCount:i,fieldNames:r,fields:n},t.categoryNames.push(e)}function _m(t,e){const i=t.tokenStart,r=lm(t),n=um(t,r),s=Object.create(null),o=[];let a=!0;for(;a;){if(4!==t.tokenType||!cm(t,i,r)){a=!1;break}const e=hm(t).substring(n.length+1);if(mm(t),3!==t.tokenType)return{hasError:!0,errorLine:t.lineNumber,errorMessage:"Expected value."};s[e]=Dd.ofTokens({data:t.data,indices:[t.tokenStart,t.tokenEnd],count:1}),o[o.length]=e,mm(t)}return bm(e,n.substr(1),1,o,s),{hasError:!1,errorLine:0,errorMessage:""}}function xm(t,e){const{tokenizer:i,tokens:r,fieldCount:n}=e;let s=e.tokenCount,o=0;for(;3===i.tokenType&&o<t;)em.add(r[s++%n],i.tokenStart,i.tokenEnd),mm(i),o++;return e.tokenCount=s,o}function vm(t,e){return t.update({message:"Parsing...",current:e.tokenizer.position,max:e.tokenizer.data.length})}async function wm(t,e){const i=t.lineNumber;mm(t);const r=um(t,lm(t)),n=function(t){let e;for(e=t.tokenStart;e<t.tokenEnd;++e)if(46===t.data.charCodeAt(e))return!1;return!0}(t),s=[];for(;4===t.tokenType;)s[s.length]=n?hm(t):hm(t).substring(r.length+1),mm(t);const o="_atom_site"===r?t.data.length/100|0:32,a=[],c=s.length;for(let e=0;e<c;e++)a[e]=em.create(t.data,o);const l={fieldCount:c,tokenCount:0,tokenizer:t,tokens:a};if(await nm(t.runtimeCtx,1e6,l,xm,vm),l.tokenCount%c!=0)return{hasError:!0,errorLine:t.lineNumber,errorMessage:`The number of values for loop starting at line ${i} is not a multiple of the number of columns.`};const u=l.tokenCount/c|0;if(n)for(let t=0;t<c;t++){const i={"":Dd.ofTokens(a[t])};bm(e,s[t].substr(1),u,[""],i)}else{const t=Object.create(null);for(let e=0;e<c;e++)t[s[e]]=Dd.ofTokens(a[e]);bm(e,r.substr(1),u,s,t)}return{hasError:!1,errorLine:0,errorMessage:""}}function Am(t,e){return im.error(e,t)}async function Sm(t,e){const i=[],r=function(t,e){return{data:t,length:t.length,position:0,tokenStart:0,tokenEnd:0,tokenType:6,lineNumber:1,isEscaped:!1,isImportGet:!1,inSaveFrame:!1,runtimeCtx:e}}(t,e);let n="",s=fm(),o=[],a=fm();const c=function(t,e,i){return{categoryNames:t,header:i,categories:e}}(a.categoryNames,pm(a.categoryNames,a.categoryData),"");let l="";for(e.update({message:"Parsing...",current:0,max:t.length}),mm(r);6!==r.tokenType;){const e=r.tokenType;if(0===e){if(r.inSaveFrame)return Am(r.lineNumber,"Unexpected data block inside a save frame.");s.categoryNames.length>0&&i.push(gm(s,n,o)),n=t.substring(r.tokenStart+5,r.tokenEnd),s=fm(),o=[],mm(r)}else if(1===e){if(r.tokenEnd-r.tokenStart==5)a.categoryNames.length>0&&(o[o.length]=ym(a,l)),r.inSaveFrame=!1;else{if(r.inSaveFrame)return Am(r.lineNumber,"Save frames cannot be nested.");r.inSaveFrame=!0,l=t.substring(r.tokenStart+5,r.tokenEnd),a=fm()}mm(r)}else if(2===e){const t=await wm(r,r.inSaveFrame?a:s);if(t.hasError)return Am(t.errorLine,t.errorMessage)}else{if(4!==e)return console.log(r.tokenType,sm.getTokenString(r)),Am(r.lineNumber,"Unexpected token. Expected data_, loop_, or data name.");{const t=_m(r,r.inSaveFrame?a:s);if(t.hasError)return Am(t.errorLine,t.errorMessage)}}}return r.inSaveFrame?Am(r.lineNumber,`Unfinished save frame (${c.header}).`):((s.categoryNames.length>0||o.length>0)&&i.push(gm(s,n,o)),function(t){return im.success(t)}(Fd(i)))}function Cm(t){return Qd.create("Parse CIF",(async e=>await Sm(t,e)))}!function(t){class e{run(t,e=250){return t?Vd(this,t,e):this.f(Zd)}runAsChild(t,e){return t.isSynchronous?this.f(Zd):function(t,e,i){return t.runChild(e,i)}(t,this,e)}runInContext(t){return t.isSynchronous?this.f(Zd):function(t,e){return qd(e,t)}(t,this)}constructor(t,e,i){this.name=t,this.f=e,this.onAbort=i,this.id=n()}}function i(t){const e=t;return!!t&&"number"==typeof e.id&&"string"==typeof e.name&&!!e.run}function r(t,i,r){return new e(t,i,r)}t.is=i,t.isAbort=function(t){return!!t&&!!t.isAborted},t.Aborted=function(t){return{isAborted:!0,reason:t,toString:()=>"Aborted"+(t?": "+t:"")}},t.create=r,t.constant=function(t,e){return r(t,(async t=>e))},t.empty=function(){return r("",(async t=>{}))},t.fail=function(t,e){return r(t,(async t=>{throw new Error(e)}))},t.resolveInContext=function(t,e){return i(t)?e?t.runInContext(e):t.run():t};const n=Cd(0,1073741823)}(Qd||(Qd={})),function(t){t.Synchronous=Zd}(Jd||(Jd={})),function(t){function e(t,i=""){const r=t.progress;if(!t.children.length)return r.isIndeterminate?`${i}${r.taskName}: ${r.message}`:`${i}${r.taskName}: [${r.current}/${r.max}] ${r.message}`;const n=i+"  |_ ",s=t.children.map((t=>e(t,n)));return r.isIndeterminate?`${i}${r.taskName}: ${r.message}\n${s.join("\n")}`:`${i}${r.taskName}: [${r.current}/${r.max}] ${r.message}\n${s.join("\n")}`}t.format=function(t){return e(t.root)}}(tm||(tm={})),function(t){function e(t){return t.data.substring(t.tokenStart,t.tokenEnd)}function i(t){const{data:e}=t;for(;t.position<t.length;)switch(e.charCodeAt(t.position)){case 10:return t.tokenEnd=t.position,++t.position,++t.lineNumber,!0;case 13:return t.tokenEnd=t.position,++t.position,++t.lineNumber,10===e.charCodeAt(t.position)&&++t.position,!0;default:++t.position}return t.tokenEnd=t.position,t.tokenStart!==t.tokenEnd}function r(t){return t.tokenStart=t.position,i(t)}function n(t,e,i){let n=0;for(let s=0;s<e;s++){if(!r(t))return n;em.addUnchecked(i,t.tokenStart,t.tokenEnd),n++}return n}function s(t,e,i){const{data:r}=t;let n=e,s=i-1,o=r.charCodeAt(n);for(;(9===o||32===o)&&n<=s;)o=r.charCodeAt(++n);for(o=r.charCodeAt(s);(9===o||32===o)&&s>=n;)o=r.charCodeAt(--s);return t.tokenStart=n,t.tokenEnd=s+1,t.position=i,t}t.getTokenString=e,t.reset=function(t){t.position=0,t.lineNumber=1,t.tokenStart=0,t.tokenEnd=0},t.eatLine=i,t.markStart=function(t){t.tokenStart=t.position},t.markLine=r,t.readLine=function(t){return r(t),e(t)},t.readLineTrim=function(t){r(t);const i=t.position;return s(t,t.tokenStart,t.tokenEnd),t.position=i,e(t)},t.markLines=function(t,e){const i=em.create(t.data,2*e);return n(t,e,i),i},t.readLines=function(e,i){const r=[];for(let n=0;n<i;n++)r.push(t.readLine(e));return r},t.readLinesAsync=async function(t,e,i,r=1e5){const s=em.create(t.data,2*e);let o=0;return await nm(i,r,t,((t,i)=>{const r=Math.min(e-o,t);return n(i,r,s),o+=r,r}),((t,e)=>t.update({message:"Parsing...",current:e.position,max:e.length}))),s},t.readAllLines=function(e){const i=t(e),n=em.create(i.data,Math.max(e.length/80,2));for(;r(i);)em.add(n,i.tokenStart,i.tokenEnd);return n},t.readAllLinesAsync=async function(e,i,n=1e5){const s=t(e),o=em.create(s.data,Math.max(e.length/80,2));return await nm(i,n,s,((t,e)=>(function(t,e,i){let n=0;for(let s=0;s<e;s++){if(!r(t))return n;em.add(i,t.tokenStart,t.tokenEnd),n++}}(e,t,o),e.position<e.length?t:0)),((t,e)=>t.update({message:"Parsing...",current:e.position,max:e.length}))),o},t.eatValue=function(t){for(;t.position<t.length;)switch(t.data.charCodeAt(t.position)){case 9:case 10:case 13:case 32:return void(t.tokenEnd=t.position);default:++t.position}t.tokenEnd=t.position},t.skipWhitespace=function(t){let e=-1;for(;t.position<t.length;){const i=t.data.charCodeAt(t.position);switch(i){case 9:case 32:e=i,++t.position;break;case 10:13!==e&&++t.lineNumber,e=i,++t.position;break;case 13:e=i,++t.position,++t.lineNumber;break;default:return e}}return e},t.trim=s}(sm||(sm={})),function(t){function e(t,e,i){const r=t;r.offset>r.indicesLenMinus2&&function(t){const e=new Uint32Array(1.61*t.indices.length|0);e.set(t.indices),t.indices=e,t.indicesLenMinus2=e.length-2|0}(r),r.indices[r.offset++]=e,r.indices[r.offset++]=i,t.count++}t.add=e,t.addToken=function(t,i){e(t,i.tokenStart,i.tokenEnd)},t.addUnchecked=function(t,e,i){t.indices[t.offset++]=e,t.indices[t.offset++]=i,t.count++},t.create=function(t,e){return{data:t,indicesLenMinus2:(e=Math.max(10,e))-2|0,count:0,offset:0,indices:new Uint32Array(e)}}}(em||(em={})),function(t){t.error=function(t,i=-1){return new e(t,i)},t.success=function(t,e=[]){return new i(t,e)};class e{toString(){return this.line>=0?`[Line ${this.line}] ${this.message}`:this.message}constructor(t,e){this.message=t,this.line=e,this.isError=!0}}t.Error=e;class i{constructor(t,e){this.result=t,this.warnings=e,this.isError=!1}}t.Success=i}(im||(im={})),function(t){var e,i;(e=t.IntDataType||(t.IntDataType={}))[e.Int8=1]="Int8",e[e.Int16=2]="Int16",e[e.Int32=3]="Int32",e[e.Uint8=4]="Uint8",e[e.Uint16=5]="Uint16",e[e.Uint32=6]="Uint32",(i=t.FloatDataType||(t.FloatDataType={}))[i.Float32=32]="Float32",i[i.Float64=33]="Float64",t.getDataType=function(e){let i;return i=e instanceof Int8Array?t.IntDataType.Int8:e instanceof Int16Array?t.IntDataType.Int16:e instanceof Int32Array?t.IntDataType.Int32:e instanceof Uint8Array?t.IntDataType.Uint8:e instanceof Uint16Array?t.IntDataType.Uint16:e instanceof Uint32Array?t.IntDataType.Uint32:e instanceof Float32Array?t.FloatDataType.Float32:e instanceof Float64Array?t.FloatDataType.Float64:t.IntDataType.Int32,i},t.isSignedIntegerDataType=function(t){if(t instanceof Int8Array||t instanceof Int16Array||t instanceof Int32Array)return!0;for(let e=0,i=t.length;e<i;e++)if(e<0)return!1;return!0}}(rm||(rm={}));const Pm=13330===new Uint16Array(new Uint8Array([18,52]).buffer)[0];function Im(t){let e=t.data;for(let i=t.encoding.length-1;i>=0;i--)e=km(e,t.encoding[i]);return e}function km(t,e){switch(e.kind){case"ByteArray":switch(e.type){case rm.IntDataType.Uint8:return t;case rm.IntDataType.Int8:return function(t){return new Int8Array(t.buffer,t.byteOffset)}(t);case rm.IntDataType.Int16:return function(t){return Dm(t,2,Int16Array)}(t);case rm.IntDataType.Uint16:return function(t){return Dm(t,2,Uint16Array)}(t);case rm.IntDataType.Int32:return function(t){return Dm(t,4,Int32Array)}(t);case rm.IntDataType.Uint32:return function(t){return Dm(t,4,Uint32Array)}(t);case rm.FloatDataType.Float32:return function(t){return Dm(t,4,Float32Array)}(t);case rm.FloatDataType.Float64:return function(t){return Dm(t,8,Float64Array)}(t);default:Kh(e.type)}case"FixedPoint":return function(t,e){const i=t.length,r=Tm(e.srcType,i),n=1/e.factor;for(let e=0;e<i;e++)r[e]=n*t[e];return r}(t,e);case"IntervalQuantization":return function(t,e){const i=t.length,r=Tm(e.srcType,i),n=(e.max-e.min)/(e.numSteps-1),s=e.min;for(let e=0;e<i;e++)r[e]=s+n*t[e];return r}(t,e);case"RunLength":return function(t,e){const i=Mm(e.srcType,e.srcSize);let r=0;for(let e=0,n=t.length;e<n;e+=2){const n=t[e],s=t[e+1];for(let t=0;t<s;++t)i[r++]=n}return i}(t,e);case"Delta":return function(t,e){const i=t.length,r=Mm(e.srcType,i);if(!i)return t;r[0]=t[0]+(0|e.origin);for(let e=1;e<i;++e)r[e]=t[e]+r[e-1];return r}(t,e);case"IntegerPacking":return function(t,e){return t.length===e.srcSize?t:e.isUnsigned?function(t,e){const i=1===e.byteCount?255:65535,r=t.length,n=new Int32Array(e.srcSize);let s=0,o=0;for(;s<r;){let e=0,r=t[s];for(;r===i;)e+=r,s++,r=t[s];e+=r,n[o]=e,s++,o++}return n}(t,e):function(t,e){const i=1===e.byteCount?127:32767,r=-i-1,n=t.length,s=new Int32Array(e.srcSize);let o=0,a=0;for(;o<n;){let e=0,n=t[o];for(;n===i||n===r;)e+=n,o++,n=t[o];e+=n,s[a]=e,o++,a++}return s}(t,e)}(t,e);case"StringArray":return function(t,e){const i=Im({encoding:e.offsetEncoding,data:e.offsets}),r=Im({encoding:e.dataEncoding,data:t}),n=e.stringData,s=new Array(i.length);s[0]="";for(let t=1,e=i.length;t<e;t++)s[t]=n.substring(i[t-1],i[t]);let o=0;const a=new Array(r.length);for(let t=0,e=r.length;t<e;t++)a[o++]=s[r[t]+1];return a}(t,e)}}function Mm(t,e){switch(t){case rm.IntDataType.Int8:return new Int8Array(e);case rm.IntDataType.Int16:return new Int16Array(e);case rm.IntDataType.Int32:return new Int32Array(e);case rm.IntDataType.Uint8:return new Uint8Array(e);case rm.IntDataType.Uint16:return new Uint16Array(e);case rm.IntDataType.Uint32:return new Uint32Array(e);default:return new Int32Array(e)}}function Tm(t,e){switch(t){case rm.FloatDataType.Float32:return new Float32Array(e);case rm.FloatDataType.Float64:default:return new Float64Array(e)}}function Dm(t,e,i){return new i(Pm?t.buffer:function(t,e){const i=new ArrayBuffer(t.length),r=new Uint8Array(i);for(let i=0,n=t.length;i<n;i+=e)for(let n=0;n<e;n++)r[i+e-n-1]=t[i+n];return i}(t,e))}var Bm,Fm,Em,Om,$m;function Rm(t,e,i){let r,n=1;for(r=0;r<e;r++){const e=n*t;if(Math.abs(Math.round(e)-e)<=i)return r;n*=10}return-1}function Lm(t){return Fm.classify(t)}!function(t){function e(t){const e=t.growBy*t.elementSize;t.currentSize=e,t.currentIndex=0,t.currentChunk=new t.ctor(e),t.allocatedSize+=e,t.chunks[t.chunks.length]=t.currentChunk}function i(t,e){const{ctor:i,chunks:r,currentIndex:n}=t;if(!r.length)return new i(0);if(1===r.length&&(e||n===t.allocatedSize))return r[0];let s=0;for(let t=0,e=r.length-1;t<e;t++)s+=r[t].length;s+=t.currentIndex;const o=new i(s);let a=0;if(o.buffer)for(let t=0,e=r.length-1;t<e;t++)o.set(r[t],a),a+=r[t].length;else for(let t=0,e=r.length-1;t<e;t++){const e=r[t];for(let t=0,i=e.length;t<i;t++)o[a+t]=e[t];a+=e.length}const c=r[r.length-1];if(o.buffer&&n>=t.currentSize)o.set(c,a);else for(let t=0,e=c.length;t<e;t++)o[a+t]=c[t];return o}t.is=function(t){return t.creator&&t.chunkSize},t.add4=function(t,i,r,n,s){t.currentIndex>=t.currentSize&&e(t);const o=t.currentChunk,a=t.currentIndex;return o[a]=i,o[a+1]=r,o[a+2]=n,o[a+3]=s,t.currentIndex+=4,t.elementCount++},t.add3=function(t,i,r,n){t.currentIndex>=t.currentSize&&e(t);const s=t.currentChunk,o=t.currentIndex;return s[o]=i,s[o+1]=r,s[o+2]=n,t.currentIndex+=3,t.elementCount++},t.add2=function(t,i,r){t.currentIndex>=t.currentSize&&e(t);const n=t.currentChunk,s=t.currentIndex;return n[s]=i,n[s+1]=r,t.currentIndex+=2,t.elementCount++},t.add=function(t,i){return t.currentIndex>=t.currentSize&&e(t),t.currentChunk[t.currentIndex]=i,t.currentIndex+=1,t.elementCount++},t.addRepeat=function(t,i,r){for(let n=0;n<i;n++)t.currentIndex>=t.currentSize&&e(t),t.currentChunk[t.currentIndex++]=r,t.elementCount++;return t.elementCount},t.addMany=function(t,i){const{elementSize:r}=t;for(let n=0,s=i.length;n<s;n+=r){t.currentIndex>=t.currentSize&&e(t);const{currentChunk:s}=t;for(let e=0;e<r;e++)s[t.currentIndex++]=i[n+e];t.elementCount++}return t.elementCount},t.compact=function(t,e=!1){return i(t,e)},t._compact=i,t.create=function(t,e,i,r){const n={ctor:t,elementSize:e,growBy:Math.max(1,Math.ceil(i)),allocatedSize:0,elementCount:0,currentSize:0,currentChunk:void 0,currentIndex:0,chunks:[]};if(void 0===r)return n;if("number"==typeof r)return n.currentChunk=new t(r*e),n.allocatedSize=r*e,n.currentSize=n.currentChunk.length,n.chunks[0]=n.currentChunk,n;const s=r;if(s.length%e!=0)throw new Error("initialChunk length must be a multiple of the element size.");return n.currentChunk=s,n.allocatedSize=s.length,n.currentSize=s.length,n.chunks[0]=s,n}}(Bm||(Bm={})),function(t){function e(t,e){return t>=0?Math.ceil((t+1)/e):Math.ceil((t+1)/(-e-1))}function i({limit8:t,limit16:i},r,n){r.pack8+=e(n,t),r.pack16+=e(n,i),r.count+=1}function r(t,i){t.pack8+=e(i,127),t.pack16+=e(i,32767),t.count+=1}function n(t){return 4*t.count<2*t.pack16?{length:4*t.count,elem:4}:2*t.pack16<t.pack8?{length:2*t.pack16,elem:2}:{length:t.pack8,elem:1}}function s(t,e){const r={pack8:0,pack16:0,count:0};for(let n=0,s=t.length;n<s;n++)i(e,r,t[n]);return{...n(r),kind:"pack"}}function o(t,e){const i={pack8:0,pack16:0,count:0};let s=t[0];for(let e=1,n=t.length;e<n;e++)r(i,t[e]-s),s=t[e];return{...n(i),kind:"delta"}}function a(t,e){const r={pack8:0,pack16:0,count:0};let s=1;for(let n=1,o=t.length;n<o;n++)t[n-1]!==t[n]?(i(e,r,t[n-1]),i(e,r,s),s=1):s++;return i(e,r,t[t.length-1]),i(e,r,s),{...n(r),kind:"rle"}}function c(t,e){const i={pack8:0,pack16:0,count:0};let s=1,o=0,a=0;for(let e=1,n=t.length;e<n;e++){const n=t[e]-o;a!==n?(r(i,a),r(i,s),s=1):s++,a=n,o=t[e]}return r(i,a),r(i,s),{...n(i),kind:"delta-rle"}}function l(t){const e=function(t){let e=!1;for(let i=0,r=t.length;i<r;i++)if(t[i]<0){e=!0;break}return e?{signed:e,limit8:127,limit16:32767}:{signed:e,limit8:255,limit16:65535}}(t),i=[s(t,e),a(t,e),o(t),c(t)];return i.sort(((t,e)=>t.length-e.length)),i}t.getSize=l,t.classify=function(t){if(t.length<2)return $m.by($m.byteArray);switch(l(t)[0].kind){case"pack":return $m.by($m.integerPacking);case"rle":return $m.by($m.runLength).and($m.integerPacking);case"delta":return $m.by($m.delta).and($m.integerPacking);case"delta-rle":return $m.by($m.delta).and($m.runLength).and($m.integerPacking);default:Kh()}}}(Fm||(Fm={})),function(t){t.classify=function(t){const{mantissaDigits:e,integerDigits:i}=function(t,e,i){let r=1,n=0;for(let s=0,o=t.length;s<o;s++){if(r>=0){const n=Rm(t[s],e,i);n<0?r=-1:n>r&&(r=n)}const o=Math.abs(t[s]);if(o>i){const t=Math.floor(Math.log10(Math.abs(o)))+1;t>n&&(n=t)}}return{mantissaDigits:r,integerDigits:n}}(t,4,1e-6);if(e<0||e+i>10)return $m.by($m.byteArray);if(0===e)return Fm.classify(t);const r=function(t){let e=1;for(let i=0;i<t;i++)e*=10;return e}(e),n=new Int32Array(t.length);for(let e=0,i=t.length;e<i;e++)n[e]=Math.round(r*t[e]);const s=Fm.getSize(n)[0],o=$m.by($m.fixedPoint(r));switch(s.kind){case"pack":return o.and($m.integerPacking);case"rle":return o.and($m.runLength).and($m.integerPacking);case"delta":return o.and($m.delta).and($m.integerPacking);case"delta-rle":return o.and($m.delta).and($m.runLength).and($m.integerPacking);default:Kh()}}}(Em||(Em={}));class Nm{and(t){return new Nm(this.providers.concat([t]))}encode(t){const e=[];for(const i of this.providers){const r=i(t);if(!r.encodings.length)throw new Error("Encodings must be non-empty.");t=r.data;for(const t of r.encodings)e.push(t)}if(!(t instanceof Uint8Array))throw new Error("The encoding must result in a Uint8Array. Fix your encoding chain.");return{encoding:e,data:t}}constructor(t){this.providers=t}}!function(t){function e(t){return new Nm([t])}function i(t){switch(t.kind){case"ByteArray":return $m.byteArray;case"FixedPoint":return $m.fixedPoint(t.factor);case"IntervalQuantization":return $m.intervalQuantizaiton(t.min,t.max,t.numSteps);case"RunLength":return $m.runLength;case"Delta":return $m.delta;case"IntegerPacking":return $m.integerPacking;case"StringArray":return $m.stringArray}}t.by=e,t.fromEncoding=function(t){let r=e(i(t[0]));for(let e=1;e<t.length&&"IntegerPacking"!==t[e-1].kind;e++)r=r.and(i(t[e]));return r}}(Om||(Om={})),function(t){t.by=function(t){return new Nm([t])};const e={[rm.IntDataType.Int16]:function(t,e,i){t.setInt16(2*e,i,!0)},[rm.IntDataType.Uint16]:function(t,e,i){t.setUint16(2*e,i,!0)},[rm.IntDataType.Int32]:function(t,e,i){t.setInt32(4*e,i,!0)},[rm.IntDataType.Uint32]:function(t,e,i){t.setUint32(4*e,i,!0)},[rm.FloatDataType.Float32]:function(t,e,i){t.setFloat32(4*e,i,!0)},[rm.FloatDataType.Float64]:function(t,e,i){t.setFloat64(8*e,i,!0)}},i={[rm.IntDataType.Int16]:2,[rm.IntDataType.Uint16]:2,[rm.IntDataType.Int32]:4,[rm.IntDataType.Uint32]:4,[rm.FloatDataType.Float32]:4,[rm.FloatDataType.Float64]:8};function r(t){const r=rm.getDataType(t);if(r===rm.IntDataType.Int8)return function(t){return{encodings:[{kind:"ByteArray",type:rm.IntDataType.Int8}],data:new Uint8Array(t.buffer,t.byteOffset)}}(t);if(r===rm.IntDataType.Uint8)return function(t){return{encodings:[{kind:"ByteArray",type:rm.IntDataType.Uint8}],data:t}}(t);const n=new Uint8Array(t.length*i[r]),s=e[r],o=new DataView(n.buffer);for(let e=0,i=t.length;e<i;e++)s(o,e,t[e]);return{encodings:[{kind:"ByteArray",type:r}],data:n}}function n(t,e){let i=0;for(let r=0,n=t.length;r<n;r++)i+=t[r]/e|0;return i+=t.length,i}function s(t,e){const i=-e-1;let r=0;for(let n=0,s=t.length;n<s;n++){const s=t[n];r+=s>=0?s/e|0:s/i|0}return r+=t.length,r}t.byteArray=r,t.fixedPoint=function(t){return e=>function(t,e){const i=rm.getDataType(t),r=new Int32Array(t.length);for(let i=0,n=t.length;i<n;i++)r[i]=Math.round(t[i]*e);return{encodings:[{kind:"FixedPoint",factor:e,srcType:i}],data:r}}(e,t)},t.intervalQuantizaiton=function(t,e,i,r=Int32Array){return n=>function(t,e,i,r,n){const s=rm.getDataType(t);if(!t.length)return{encodings:[{kind:"IntervalQuantization",min:e,max:i,numSteps:r,srcType:s}],data:new Int32Array(0)};if(i<e){const t=e;e=i,i=t}const o=(i-e)/(r-1),a=new n(t.length);for(let n=0,s=t.length;n<s;n++){const s=t[n];a[n]=s<=e?0:s>=i?r-1:0|Math.round((s-e)/o)}return{encodings:[{kind:"IntervalQuantization",min:e,max:i,numSteps:r,srcType:s}],data:a}}(n,t,e,i,r)},t.runLength=function(t){let e=rm.getDataType(t);if(void 0===e&&(t=new Int32Array(t),e=rm.IntDataType.Int32),!t.length)return{encodings:[{kind:"RunLength",srcType:e,srcSize:0}],data:new Int32Array(0)};let i=2;for(let e=1,r=t.length;e<r;e++)t[e-1]!==t[e]&&(i+=2);const r=new Int32Array(i);let n=0,s=1;for(let e=1,i=t.length;e<i;e++)t[e-1]!==t[e]?(r[n]=t[e-1],r[n+1]=s,s=1,n+=2):++s;return r[n]=t[t.length-1],r[n+1]=s,{encodings:[{kind:"RunLength",srcType:e,srcSize:t.length}],data:r}},t.delta=function(t){if(!rm.isSignedIntegerDataType(t))throw new Error("Only signed integer types can be encoded using delta encoding.");let e=rm.getDataType(t);if(void 0===e&&(t=new Int32Array(t),e=rm.IntDataType.Int32),!t.length)return{encodings:[{kind:"Delta",origin:0,srcType:e}],data:new t.constructor(0)};const i=new t.constructor(t.length),r=t[0];i[0]=t[0];for(let e=1,r=t.length;e<r;e++)i[e]=t[e]-t[e-1];return i[0]=0,{encodings:[{kind:"Delta",origin:r,srcType:e}],data:i}},t.integerPacking=function(t){const e=function(t){const e=function(t){for(let e=0,i=t.length;e<i;e++)if(t[e]<0)return!0;return!1}(t),i=e?s(t,127):n(t,255),r=e?s(t,32767):n(t,65535);return 4*t.length<2*r?{isSigned:e,size:t.length,bytesPerElement:4}:2*r<i?{isSigned:e,size:r,bytesPerElement:2}:{isSigned:e,size:i,bytesPerElement:1}}(t);return 4===e.bytesPerElement?r(t):function(t,e){const i=e.isSigned?1===e.bytesPerElement?127:32767:1===e.bytesPerElement?255:65535,n=-i-1,s=t.length,o=e.isSigned?1===e.bytesPerElement?new Int8Array(e.size):new Int16Array(e.size):1===e.bytesPerElement?new Uint8Array(e.size):new Uint16Array(e.size);let a=0;for(let e=0;e<s;e++){let r=t[e];if(r>=0)for(;r>=i;)o[a]=i,++a,r-=i;else for(;r<=n;)o[a]=n,++a,r-=n;o[a]=r,++a}const c=r(o);return{encodings:[{kind:"IntegerPacking",byteCount:e.bytesPerElement,isUnsigned:!e.isSigned,srcSize:s},c.encodings[0]],data:c.data}}(t,e)},t.stringArray=function(t){const e=Object.create(null),i=[],r=new Int32Array(t.length),n=Bm.create(Int32Array,1,Math.min(1024,t.length<32?t.length+1:Math.round(t.length/8)+1));Bm.add(n,0);let s=0,o=0;for(const a of t){if(null==a){r[o++]=-1;continue}let t=e[a];void 0===t&&(s+=a.length,t=i.length,i[t]=a,e[a]=t,Bm.add(n,s)),r[o++]=t}const a=Bm.compact(n),c=Lm(a).encode(a),l=Lm(r).encode(r);return{encodings:[{kind:"StringArray",dataEncoding:l.encoding,stringData:i.join(""),offsetEncoding:c.encoding,offsets:c.data}],data:l.data}}}($m||($m={}));const zm=function(){const t=[];for(let e=0;e<1024;e++)t[e]=String.fromCharCode(e);return t}();function Vm(t){throw new Error(t)}const Um="undefined"!=typeof TextDecoder?new TextDecoder:void 0;function jm(t,e,i){if(Um){const r=e||i!==t.length?t.subarray(e,e+i):t;return Um.decode(r)}return function(t,e,i){const r=zm;let n,s=0;const o=[];for(let a=e,c=e+i;a<c;a++){const e=t[a];128&e?192==(224&e)?o[s++]=r[(15&e)<<6|63&t[++a]]:224==(240&e)?o[s++]=String.fromCharCode((15&e)<<12|(63&t[++a])<<6|63&t[++a]):240==(248&e)?o[s++]=String.fromCharCode((7&e)<<18|(63&t[++a])<<12|(63&t[++a])<<6|63&t[++a]):Vm("Invalid byte "+e.toString(16)):o[s++]=r[e],512===s&&(n=n||[],n[n.length]=o.join(""),s=0)}return n?(s>0&&(n[n.length]=o.slice(0,s).join("")),n.join("")):o.slice(0,s).join("")}(t,e,i)}function Gm(t,e){const i={};for(let r=0;r<e;r++){i[Xm(t)]=Xm(t)}return i}function Hm(t,e){const i=new Uint8Array(e),r=t.offset;for(let n=0;n<e;n++)i[n]=t.buffer[n+r];return t.offset+=e,i}function qm(t,e){const i=jm(t.buffer,t.offset,e);return t.offset+=e,i}function Wm(t,e){const i=new Array(e);for(let r=0;r<e;r++)i[r]=Xm(t);return i}function Xm(t){const e=t.buffer[t.offset];let i,r;if(!(128&e))return t.offset++,e;if(128==(240&e))return r=15&e,t.offset++,Gm(t,r);if(144==(240&e))return r=15&e,t.offset++,Wm(t,r);if(160==(224&e))return r=31&e,t.offset++,qm(t,r);if(!(224&~e))return i=t.dataView.getInt8(t.offset),t.offset++,i;switch(e){case 192:return t.offset++,null;case 194:return t.offset++,!1;case 195:return t.offset++,!0;case 196:return r=t.dataView.getUint8(t.offset+1),t.offset+=2,Hm(t,r);case 197:return r=t.dataView.getUint16(t.offset+1),t.offset+=3,Hm(t,r);case 198:return r=t.dataView.getUint32(t.offset+1),t.offset+=5,Hm(t,r);case 202:return i=t.dataView.getFloat32(t.offset+1),t.offset+=5,i;case 203:return i=t.dataView.getFloat64(t.offset+1),t.offset+=9,i;case 204:return i=t.buffer[t.offset+1],t.offset+=2,i;case 205:return i=t.dataView.getUint16(t.offset+1),t.offset+=3,i;case 206:return i=t.dataView.getUint32(t.offset+1),t.offset+=5,i;case 208:return i=t.dataView.getInt8(t.offset+1),t.offset+=2,i;case 209:return i=t.dataView.getInt16(t.offset+1),t.offset+=3,i;case 210:return i=t.dataView.getInt32(t.offset+1),t.offset+=5,i;case 217:return r=t.dataView.getUint8(t.offset+1),t.offset+=2,qm(t,r);case 218:return r=t.dataView.getUint16(t.offset+1),t.offset+=3,qm(t,r);case 219:return r=t.dataView.getUint32(t.offset+1),t.offset+=5,qm(t,r);case 220:return r=t.dataView.getUint16(t.offset+1),t.offset+=3,Wm(t,r);case 221:return r=t.dataView.getUint32(t.offset+1),t.offset+=5,Wm(t,r);case 222:return r=t.dataView.getUint16(t.offset+1),t.offset+=3,Gm(t,r);case 223:return r=t.dataView.getUint32(t.offset+1),t.offset+=5,Gm(t,r)}throw new Error("Unknown type 0x"+e.toString(16))}function Ym(t){const e=Object.create(null),i=Object.create(null);for(const i of t.columns)e[i.name]=i;return{rowCount:t.rowCount,name:t.name.substr(1),fieldNames:t.columns.map((t=>t.name)),getField(t){const r=e[t];if(r)return i[t]||(i[t]=function(t){const e=t.mask?Im(t.mask):void 0,i=Im(t.data),r=Oh(i),n=r?e?t=>0===e[t]?""+i[t]:"":t=>""+i[t]:e?t=>0===e[t]?i[t]:"":t=>i[t],s=r?t=>i[t]:t=>{const e=i[t];return id(e,0,e.length)},o=r?t=>i[t]:t=>{const e=i[t];return nd(e,0,e.length)},a=e?t=>e[t]:t=>0,c=i.length;return{__array:i,binaryEncoding:t.data.encoding,isDefined:!0,rowCount:c,str:n,int:s,float:o,valueKind:a,areValuesEqual:(t,e)=>i[t]===i[e],toStringArray:t=>Eh(c,n,t),toIntArray:r?t=>$h(i,t):t=>Eh(c,s,t),toFloatArray:r?t=>$h(i,t):t=>Eh(c,o,t)}}(r)),i[t]}}}function Km(t){return Qd.create("Parse BinaryCIF",(async e=>{const i=[0,3];try{const e=Xm({buffer:r=t,offset:0,dataView:new DataView(r.buffer)});if(!function(t,e){for(let i=0;i<2;i++)if(t[i]>e[i])return!1;return!0}(i,e.version.match(/(\d)\.(\d)\.\d/).slice(1).map((t=>+t))))return im.error(`Unsupported format version. Current ${e.version}, required ${i.join(".")}.`);const n=Fd(e.dataBlocks.map((t=>{const e=Object.create(null);for(const i of t.categories)e[i.name.substr(1)]=Ym(i);return Ed(t.categories.map((t=>t.name.substr(1))),e,t.header)})));return im.success(n)}catch(t){return im.error(""+t)}var r}))}var Zm;function Qm(t,e,i){return function(t,e,i){const r=Object.create(null);for(const n of Object.keys(t))r[n]=of(n,t[n],e,i);return Td.ofTables(e.header,t,r)}(t,e,i)}function Jm(t){switch(t.valueType){case"str":return(e,i,r)=>function(t,e,i,r){return{schema:t,__array:e.__array,isDefined:e.isDefined,rowCount:e.rowCount,value:"lowercase"===t.transform?t=>i(t).toLowerCase():"uppercase"===t.transform?t=>i(t).toUpperCase():i,valueKind:e.valueKind,areValuesEqual:e.areValuesEqual,toArray:"lowercase"===t.transform?t=>Array.from(r(t)).map((t=>t.toLowerCase())):"uppercase"===t.transform?t=>Array.from(r(t)).map((t=>t.toUpperCase())):r}}(t,e,e.str,e.toStringArray);case"int":return(e,i,r)=>tf(t,e,e.int,e.toIntArray);case"float":return(e,i,r)=>tf(t,e,e.float,e.toFloatArray);case"list":throw new Error("Use createListColumn instead.");case"tensor":throw new Error("Use createTensorColumn instead.")}}function tf(t,e,i,r){return{schema:t,__array:e.__array,isDefined:e.isDefined,rowCount:e.rowCount,value:i,valueKind:e.valueKind,areValuesEqual:e.areValuesEqual,toArray:r}}function ef(t,e,i){const r=t.separator,n=t.itemParse,s=e.getField(i),o=s?t=>s.str(t).split(r).map((t=>n(t.trim()))).filter((t=>!!t)):t=>[];return{schema:t,__array:void 0,isDefined:!!s,rowCount:e.rowCount,value:o,valueKind:s?s.valueKind:()=>1,areValuesEqual:(t,e)=>function(t,e){const i=t.length;if(i!==e.length)return!1;for(let r=0;r<i;r++)if(t[r]!==e[r])return!1;return!0}(o(t),o(e)),toArray:t=>Eh(e.rowCount,o,t)}}function rf(t,e,i){const r=t.space,n=e.fieldNames.includes(`${i}[0]`)||e.fieldNames.includes(`${i}[0][0]`)||e.fieldNames.includes(`${i}[0][0][0]`),s=n?0:1,o=e.fieldNames.includes(`${i}_1`)||e.fieldNames.includes(`${i}_11`)||e.fieldNames.includes(`${i}_111`)?"underscore":"brackets",a=function(t,e,i,r){const n=i?0:1;switch(e){case 1:return"brackets"===r?e=>`${t}[${e+n}]`:e=>`${t}_${e+n}`;case 2:return"brackets"===r?(e,i)=>`${t}[${e+n}][${i+n}]`:(e,i)=>`${t}_${e+n}${i+n}`;case 3:return"brackets"===r?(e,i,r)=>`${t}[${e+n}][${i+n}][${r+n}]`:(e,i,r)=>`${t}_${e+n}${i+n}${r+n}`;default:throw new Error("Tensors with rank > 3 or rank 0 are currently not supported.")}}(i,r.rank,n,o),c=e.getField(a(s,s,s))||Jh.Undefined(e.rowCount,t),l=t=>function(t,e,i,r){const n=e.create();if(1===e.rank){const s=e.dimensions[0];for(let o=0;o<s;o++){const s=t.getField(r(o));e.set(n,o,s?s.float(i):0)}}else if(2===e.rank){const s=e.dimensions[0],o=e.dimensions[1];for(let a=0;a<s;a++)for(let s=0;s<o;s++){const o=t.getField(r(a,s));e.set(n,a,s,o?o.float(i):0)}}else{if(3!==e.rank)throw new Error("Tensors with rank > 3 or rank 0 are currently not supported.");{const s=e.dimensions[0],o=e.dimensions[1],a=e.dimensions[2];for(let c=0;c<s;c++)for(let s=0;s<o;s++)for(let o=0;o<a;o++){const a=t.getField(r(c,s,o));e.set(n,c,s,o,a?a.float(i):0)}}}return n}(e,r,t,a);return{schema:t,__array:void 0,isDefined:c.isDefined,rowCount:e.rowCount,value:l,valueKind:c.valueKind,areValuesEqual:(t,e)=>Qh.areEqualExact(l(t),l(e)),toArray:t=>Eh(e.rowCount,l,t)}}!function(t){function e(t){return t.replace(".","_").replace(/\[/,"_").replace(/(\[|\])/g,"")}t.canonical=e,t.equal=function(t,i){return e(t)===e(i)},t.create=function(t,i,r=!1){const n=`${t}${i?`.${i}`:""}`;return r?e(n):n}}(Zm||(Zm={}));class nf{constructor(t,e,i){this._isDefined=i;const r=Object.keys(e);this._rowCount=t.rowCount,this._columns=r,this._schema=e;const n=Object.create(null);for(const i of r)Object.defineProperty(this,i,{get:function(){if(n[i])return n[i];const r=e[i];if("list"===r.valueType)n[i]=ef(r,t,i);else if("tensor"===r.valueType)n[i]=rf(r,t,i);else{const e=Jm(r),s=t.getField(i);n[i]=s?e(s,t,i):Jh.Undefined(t.rowCount,r)}return n[i]},enumerable:!0,configurable:!1})}}function sf(t,e,i,r){const n=Zm.create(e,t),s=Zm.canonical(n);if(s in i)return i[s];if(r&&n in r)for(const t of r[n]){const e=Zm.canonical(t);if(e in i)return i[e]}}function of(t,e,i,r){let n=i.categories[t];if(r){const s=function(t){const e=Object.create(null);for(const i of Object.keys(t.categories))for(const r of t.categories[i].fieldNames)e[Zm.create(i,r,!0)]=t.categories[i].getField(r);return e}(i),o=Object.create(null),a=[];let c=0;for(const i of Object.keys(e)){const e=sf(i,t,s,r);e&&(o[i]=e,a.push(i),c=e.rowCount)}n={rowCount:c,name:t,fieldNames:[...a],getField:t=>o[t]}}return new nf(n||Od.empty(t),e,!!n)}var af=Jh.Schema;const cf=af.str,lf=af.int,uf=af.float,hf=af.coord,df=af.Aliased,mf=af.Matrix,ff=af.Vector,pf=af.lstr,gf=af.List,yf={atom_site:{auth_asym_id:cf,auth_atom_id:cf,auth_comp_id:cf,auth_seq_id:lf,B_iso_or_equiv:uf,Cartn_x:hf,Cartn_y:hf,Cartn_z:hf,group_PDB:df(cf),id:lf,label_alt_id:cf,label_asym_id:cf,label_atom_id:cf,label_comp_id:cf,label_entity_id:cf,label_seq_id:lf,occupancy:uf,type_symbol:cf,pdbx_PDB_ins_code:cf,pdbx_PDB_model_num:lf,pdbx_formal_charge:lf,pdbx_label_index:lf,pdbx_sifts_xref_db_name:cf,pdbx_sifts_xref_db_acc:cf,pdbx_sifts_xref_db_num:cf,pdbx_sifts_xref_db_res:cf,ihm_model_id:lf},atom_site_anisotrop:{id:lf,type_symbol:cf,U:mf(3,3),U_esd:mf(3,3),pdbx_auth_seq_id:cf,pdbx_auth_asym_id:cf,pdbx_auth_atom_id:cf,pdbx_auth_comp_id:cf,pdbx_label_seq_id:lf,pdbx_label_alt_id:cf,pdbx_label_asym_id:cf,pdbx_label_atom_id:cf,pdbx_label_comp_id:cf,pdbx_PDB_ins_code:cf},atom_sites:{entry_id:cf,fract_transf_matrix:mf(3,3),fract_transf_vector:ff(3)},audit_author:{name:cf,pdbx_ordinal:lf,identifier_ORCID:cf},audit_conform:{dict_location:cf,dict_name:cf,dict_version:cf},cell:{angle_alpha:uf,angle_beta:uf,angle_gamma:uf,entry_id:cf,length_a:uf,length_b:uf,length_c:uf,Z_PDB:lf,pdbx_unique_axis:cf},chem_comp:{formula:cf,formula_weight:uf,id:cf,mon_nstd_flag:df(pf),name:cf,type:df(pf),pdbx_synonyms:gf(";",(t=>t))},chem_comp_bond:{atom_id_1:cf,atom_id_2:cf,comp_id:cf,value_order:df(pf),pdbx_ordinal:lf,pdbx_stereo_config:df(pf),pdbx_aromatic_flag:df(pf)},citation:{book_publisher:cf,country:cf,id:cf,journal_abbrev:cf,journal_id_ASTM:cf,journal_id_CSD:cf,journal_id_ISSN:cf,journal_volume:cf,page_first:cf,page_last:cf,title:cf,year:lf,pdbx_database_id_DOI:cf,pdbx_database_id_PubMed:lf},citation_author:{citation_id:cf,name:cf,ordinal:lf},database_2:{database_id:df(pf),database_code:cf},entity:{details:cf,formula_weight:uf,id:cf,src_method:df(pf),type:df(pf),pdbx_description:gf(",",(t=>t)),pdbx_number_of_molecules:lf,pdbx_mutation:cf,pdbx_fragment:cf,pdbx_ec:gf(",",(t=>t))},entity_poly:{entity_id:cf,nstd_linkage:df(pf),nstd_monomer:df(pf),type:df(cf),pdbx_strand_id:gf(",",(t=>t)),pdbx_seq_one_letter_code:cf,pdbx_seq_one_letter_code_can:cf,pdbx_target_identifier:cf},entity_poly_seq:{entity_id:cf,hetero:df(pf),mon_id:cf,num:lf},entry:{id:cf},exptl:{entry_id:cf,method:df(cf)},software:{classification:cf,date:cf,description:cf,name:cf,type:df(pf),version:cf,pdbx_ordinal:lf},struct:{entry_id:cf,title:cf,pdbx_descriptor:cf},struct_asym:{details:cf,entity_id:cf,id:cf,pdbx_modified:cf,pdbx_blank_PDB_chainid_flag:df(cf)},struct_conf:{beg_label_asym_id:cf,beg_label_comp_id:cf,beg_label_seq_id:lf,beg_auth_asym_id:cf,beg_auth_comp_id:cf,beg_auth_seq_id:lf,conf_type_id:df(pf),details:cf,end_label_asym_id:cf,end_label_comp_id:cf,end_label_seq_id:lf,end_auth_asym_id:cf,end_auth_comp_id:cf,end_auth_seq_id:lf,id:cf,pdbx_beg_PDB_ins_code:cf,pdbx_end_PDB_ins_code:cf,pdbx_PDB_helix_class:cf,pdbx_PDB_helix_length:lf,pdbx_PDB_helix_id:cf},struct_conn:{conn_type_id:df(pf),details:cf,id:cf,ptnr1_label_asym_id:cf,ptnr1_label_atom_id:cf,ptnr1_label_comp_id:cf,ptnr1_label_seq_id:lf,ptnr1_auth_asym_id:cf,ptnr1_auth_comp_id:cf,ptnr1_auth_seq_id:lf,ptnr1_symmetry:cf,ptnr2_label_asym_id:cf,ptnr2_label_atom_id:cf,ptnr2_label_comp_id:cf,ptnr2_label_seq_id:lf,ptnr2_auth_asym_id:cf,ptnr2_auth_comp_id:cf,ptnr2_auth_seq_id:lf,ptnr2_symmetry:cf,pdbx_ptnr1_PDB_ins_code:cf,pdbx_ptnr1_label_alt_id:cf,pdbx_ptnr1_standard_comp_id:cf,pdbx_ptnr2_PDB_ins_code:cf,pdbx_ptnr2_label_alt_id:cf,pdbx_ptnr3_PDB_ins_code:cf,pdbx_ptnr3_label_alt_id:cf,pdbx_ptnr3_label_asym_id:cf,pdbx_ptnr3_label_atom_id:cf,pdbx_ptnr3_label_comp_id:cf,pdbx_ptnr3_label_seq_id:lf,pdbx_PDB_id:cf,pdbx_dist_value:uf,pdbx_value_order:df(pf)},struct_conn_type:{criteria:cf,id:df(pf),reference:cf},struct_keywords:{entry_id:cf,text:gf(",",(t=>t)),pdbx_keywords:cf},struct_ncs_oper:{code:df(cf),details:cf,id:lf,matrix:mf(3,3),vector:ff(3)},struct_sheet_range:{beg_label_asym_id:cf,beg_label_comp_id:cf,beg_label_seq_id:lf,end_label_asym_id:cf,end_label_comp_id:cf,end_label_seq_id:lf,beg_auth_asym_id:cf,beg_auth_comp_id:cf,beg_auth_seq_id:lf,end_auth_asym_id:cf,end_auth_comp_id:cf,end_auth_seq_id:lf,id:cf,sheet_id:cf,pdbx_beg_PDB_ins_code:cf,pdbx_end_PDB_ins_code:cf},struct_site:{details:cf,id:cf,pdbx_num_residues:lf,pdbx_evidence_code:cf,pdbx_auth_asym_id:cf,pdbx_auth_comp_id:cf,pdbx_auth_seq_id:cf,pdbx_auth_ins_code:cf},struct_site_gen:{details:cf,id:cf,label_alt_id:cf,label_asym_id:cf,label_atom_id:cf,label_comp_id:cf,label_seq_id:lf,auth_asym_id:cf,auth_comp_id:cf,auth_seq_id:cf,site_id:cf,symmetry:cf,pdbx_auth_ins_code:cf,pdbx_num_res:lf},symmetry:{entry_id:cf,cell_setting:df(pf),Int_Tables_number:lf,space_group_name_Hall:cf,"space_group_name_H-M":cf},pdbx_database_status:{status_code:df(cf),status_code_sf:df(cf),status_code_mr:df(cf),entry_id:cf,recvd_initial_deposition_date:cf,SG_entry:df(pf),deposit_site:df(cf),process_site:df(cf),status_code_cs:df(cf),methods_development_category:df(cf),pdb_format_compatible:df(pf)},pdbx_nonpoly_scheme:{asym_id:cf,entity_id:cf,mon_id:cf,pdb_strand_id:cf,ndb_seq_num:cf,pdb_seq_num:cf,auth_seq_num:cf,pdb_mon_id:cf,auth_mon_id:cf,pdb_ins_code:cf},pdbx_database_related:{db_name:cf,details:cf,db_id:cf,content_type:df(cf)},pdbx_entity_nonpoly:{entity_id:cf,comp_id:cf,name:cf},pdbx_chem_comp_synonyms:{name:cf,comp_id:cf,provenance:df(cf)},pdbx_chem_comp_identifier:{comp_id:cf,identifier:cf,type:df(cf),program:cf,program_version:cf},pdbx_unobs_or_zero_occ_residues:{id:lf,polymer_flag:df(pf),occupancy_flag:df(lf),PDB_model_num:lf,auth_asym_id:cf,auth_comp_id:cf,auth_seq_id:cf,PDB_ins_code:cf,label_asym_id:cf,label_comp_id:cf,label_seq_id:lf},pdbx_struct_mod_residue:{id:lf,auth_asym_id:cf,auth_comp_id:cf,auth_seq_id:lf,PDB_ins_code:cf,label_asym_id:cf,label_comp_id:cf,label_seq_id:lf,parent_comp_id:cf,details:cf},pdbx_struct_oper_list:{id:cf,type:df(cf),name:cf,symmetry_operation:cf,matrix:mf(3,3),vector:ff(3)},pdbx_struct_assembly:{method_details:cf,oligomeric_details:cf,oligomeric_count:lf,details:cf,id:cf},pdbx_struct_assembly_gen:{asym_id_list:gf(",",(t=>t)),assembly_id:cf,oper_expression:cf},pdbx_reference_entity_list:{prd_id:cf,ref_entity_id:cf,type:df(pf),details:cf,component_id:lf},pdbx_reference_entity_link:{link_id:lf,prd_id:cf,details:cf,ref_entity_id_1:cf,ref_entity_id_2:cf,entity_seq_num_1:lf,entity_seq_num_2:lf,comp_id_1:cf,comp_id_2:cf,atom_id_1:cf,atom_id_2:cf,value_order:df(pf),component_1:lf,component_2:lf,link_class:df(cf)},pdbx_reference_entity_poly_link:{link_id:lf,prd_id:cf,ref_entity_id:cf,component_id:lf,entity_seq_num_1:lf,entity_seq_num_2:lf,comp_id_1:cf,comp_id_2:cf,atom_id_1:cf,atom_id_2:cf,value_order:df(pf)},pdbx_molecule:{prd_id:cf,instance_id:lf,asym_id:cf},pdbx_molecule_features:{prd_id:cf,class:df(pf),type:df(pf),name:cf,details:cf},entity_src_nat:{entity_id:cf,pdbx_organism_scientific:cf,pdbx_plasmid_name:cf,pdbx_src_id:lf,pdbx_beg_seq_num:lf,pdbx_end_seq_num:lf},entity_src_gen:{entity_id:cf,pdbx_gene_src_gene:gf(",",(t=>t)),pdbx_gene_src_scientific_name:cf,plasmid_name:cf,pdbx_src_id:lf,pdbx_beg_seq_num:lf,pdbx_end_seq_num:lf},pdbx_entity_src_syn:{organism_scientific:cf,entity_id:cf,pdbx_src_id:lf,pdbx_beg_seq_num:lf,pdbx_end_seq_num:lf},pdbx_entity_branch_descriptor:{entity_id:cf,descriptor:cf,type:df(pf),program:cf,program_version:cf,ordinal:lf},pdbx_entity_instance_feature:{details:cf,feature_type:df(cf),auth_asym_id:cf,asym_id:cf,auth_seq_num:cf,seq_num:lf,comp_id:cf,auth_comp_id:cf,ordinal:lf},pdbx_entity_branch_list:{entity_id:cf,hetero:df(pf),comp_id:cf,num:lf},pdbx_entity_branch_link:{link_id:lf,details:cf,entity_id:cf,entity_branch_list_num_1:lf,entity_branch_list_num_2:lf,comp_id_1:cf,comp_id_2:cf,atom_id_1:cf,leaving_atom_id_1:cf,atom_stereo_config_1:df(pf),atom_id_2:cf,leaving_atom_id_2:cf,atom_stereo_config_2:df(pf),value_order:df(pf)},pdbx_entity_branch:{entity_id:cf,type:df(cf)},pdbx_branch_scheme:{entity_id:cf,hetero:df(pf),asym_id:cf,mon_id:cf,num:lf,pdb_asym_id:cf,pdb_seq_num:cf,pdb_mon_id:cf,auth_asym_id:cf,auth_seq_num:cf,auth_mon_id:cf},pdbx_chem_comp_related:{comp_id:cf,related_comp_id:cf,relationship_type:df(cf),details:cf},ihm_starting_model_details:{starting_model_id:cf,entity_id:cf,entity_description:cf,asym_id:cf,entity_poly_segment_id:lf,starting_model_source:df(cf),starting_model_auth_asym_id:cf,starting_model_sequence_offset:lf,dataset_list_id:lf},ihm_starting_comparative_models:{id:lf,starting_model_id:cf,starting_model_auth_asym_id:cf,starting_model_seq_id_begin:lf,starting_model_seq_id_end:lf,template_auth_asym_id:cf,template_seq_id_begin:lf,template_seq_id_end:lf,template_sequence_identity:uf,template_sequence_identity_denominator:df(lf),template_dataset_list_id:lf,alignment_file_id:lf},ihm_starting_model_seq_dif:{id:lf,entity_id:cf,asym_id:cf,seq_id:lf,comp_id:cf,starting_model_id:cf,db_asym_id:cf,db_seq_id:lf,db_comp_id:cf,details:cf},ihm_model_representation:{id:lf,name:cf,details:cf},ihm_model_representation_details:{id:lf,representation_id:lf,entity_poly_segment_id:lf,entity_id:cf,entity_description:cf,entity_asym_id:cf,model_object_primitive:df(cf),starting_model_id:cf,model_mode:df(cf),model_granularity:df(cf),model_object_count:lf},ihm_struct_assembly_details:{id:lf,assembly_id:lf,parent_assembly_id:lf,entity_description:cf,entity_id:cf,asym_id:cf,entity_poly_segment_id:lf},ihm_struct_assembly:{id:lf,name:cf,description:cf},ihm_modeling_protocol:{id:lf,num_steps:lf,protocol_name:cf},ihm_modeling_protocol_details:{id:lf,protocol_id:lf,step_id:lf,struct_assembly_id:lf,dataset_group_id:lf,struct_assembly_description:cf,step_name:cf,step_method:cf,num_models_begin:lf,num_models_end:lf,multi_scale_flag:df(pf),multi_state_flag:df(pf),ordered_flag:df(pf),script_file_id:lf,software_id:lf},ihm_multi_state_modeling:{state_id:lf,state_group_id:lf,population_fraction:uf,population_fraction_sd:uf,state_type:cf,state_name:cf,experiment_type:df(cf),details:cf},ihm_modeling_post_process:{id:lf,protocol_id:lf,analysis_id:lf,step_id:lf,type:df(cf),feature:df(cf),num_models_begin:lf,num_models_end:lf},ihm_ensemble_info:{ensemble_id:lf,ensemble_name:cf,post_process_id:lf,model_group_id:lf,ensemble_clustering_method:df(cf),ensemble_clustering_feature:df(cf),num_ensemble_models:lf,num_ensemble_models_deposited:lf,ensemble_precision_value:uf,ensemble_file_id:lf},ihm_model_list:{model_id:lf,model_name:cf,assembly_id:lf,protocol_id:lf,representation_id:lf},ihm_model_group:{id:lf,name:cf,details:cf},ihm_model_group_link:{model_id:lf,group_id:lf},ihm_model_representative:{id:lf,model_group_id:lf,model_id:lf,selection_criteria:df(cf)},ihm_dataset_list:{id:lf,data_type:df(cf),database_hosted:df(pf)},ihm_dataset_group:{id:lf,name:cf,application:df(cf),details:cf},ihm_dataset_group_link:{dataset_list_id:lf,group_id:lf},ihm_related_datasets:{dataset_list_id_derived:lf,dataset_list_id_primary:lf},ihm_dataset_related_db_reference:{id:lf,dataset_list_id:lf,db_name:df(cf),accession_code:cf,version:cf,details:cf},ihm_external_reference_info:{reference_id:lf,reference_provider:cf,reference_type:df(cf),reference:cf,refers_to:df(cf),associated_url:cf},ihm_external_files:{id:lf,reference_id:lf,file_path:cf,content_type:df(cf),file_size_bytes:uf,details:cf},ihm_dataset_external_reference:{id:lf,dataset_list_id:lf,file_id:lf},ihm_localization_density_files:{id:lf,file_id:lf,ensemble_id:lf,entity_id:cf,entity_poly_segment_id:lf,asym_id:cf},ihm_predicted_contact_restraint:{id:lf,group_id:lf,entity_id_1:cf,entity_id_2:cf,asym_id_1:cf,asym_id_2:cf,comp_id_1:cf,comp_id_2:cf,seq_id_1:lf,seq_id_2:lf,rep_atom_1:df(cf),rep_atom_2:df(cf),distance_lower_limit:uf,distance_upper_limit:uf,probability:uf,restraint_type:df(cf),model_granularity:df(cf),dataset_list_id:lf,software_id:lf},ihm_cross_link_list:{id:lf,group_id:lf,entity_description_1:cf,entity_description_2:cf,entity_id_1:cf,entity_id_2:cf,comp_id_1:cf,comp_id_2:cf,seq_id_1:lf,seq_id_2:lf,linker_type:df(cf),dataset_list_id:lf},ihm_cross_link_restraint:{id:lf,group_id:lf,entity_id_1:cf,entity_id_2:cf,asym_id_1:cf,asym_id_2:cf,comp_id_1:cf,comp_id_2:cf,seq_id_1:lf,seq_id_2:lf,atom_id_1:cf,atom_id_2:cf,restraint_type:df(cf),conditional_crosslink_flag:df(cf),model_granularity:df(cf),distance_threshold:uf,psi:uf,sigma_1:uf,sigma_2:uf},ihm_cross_link_result_parameters:{id:lf,restraint_id:lf,model_id:lf,psi:uf,sigma_1:uf,sigma_2:uf},ihm_2dem_class_average_restraint:{id:lf,dataset_list_id:lf,number_raw_micrographs:lf,pixel_size_width:uf,pixel_size_height:uf,image_resolution:uf,image_segment_flag:df(pf),number_of_projections:lf,struct_assembly_id:lf,details:cf},ihm_2dem_class_average_fitting:{id:lf,restraint_id:lf,model_id:lf,cross_correlation_coefficient:uf,rot_matrix:mf(3,3),tr_vector:ff(3)},ihm_3dem_restraint:{id:lf,dataset_list_id:lf,model_id:lf,struct_assembly_id:lf,fitting_method:cf,number_of_gaussians:lf,cross_correlation_coefficient:uf},ihm_sas_restraint:{id:lf,dataset_list_id:lf,model_id:lf,struct_assembly_id:lf,profile_segment_flag:df(pf),fitting_atom_type:cf,fitting_method:cf,fitting_state:df(cf),radius_of_gyration:uf,chi_value:uf,details:cf},ihm_starting_model_coord:{ordinal_id:lf,starting_model_id:cf,group_PDB:df(cf),id:lf,type_symbol:cf,entity_id:cf,atom_id:cf,comp_id:cf,seq_id:lf,asym_id:cf,Cartn_x:uf,Cartn_y:uf,Cartn_z:uf,B_iso_or_equiv:uf},ihm_sphere_obj_site:{id:lf,entity_id:cf,seq_id_begin:lf,seq_id_end:lf,asym_id:cf,Cartn_x:uf,Cartn_y:uf,Cartn_z:uf,object_radius:uf,rmsf:uf,model_id:lf},ihm_gaussian_obj_site:{id:lf,entity_id:cf,seq_id_begin:lf,seq_id_end:lf,asym_id:cf,mean_Cartn_x:uf,mean_Cartn_y:uf,mean_Cartn_z:uf,weight:uf,covariance_matrix:mf(3,3),model_id:lf},ihm_gaussian_obj_ensemble:{id:lf,entity_id:cf,seq_id_begin:lf,seq_id_end:lf,asym_id:cf,mean_Cartn_x:uf,mean_Cartn_y:uf,mean_Cartn_z:uf,weight:uf,covariance_matrix:mf(3,3),ensemble_id:lf},ihm_feature_list:{feature_id:lf,feature_type:df(cf),entity_type:df(cf)},ihm_poly_residue_feature:{ordinal_id:lf,feature_id:lf,entity_id:cf,asym_id:cf,comp_id_begin:cf,comp_id_end:cf,seq_id_begin:lf,seq_id_end:lf},ihm_derived_distance_restraint:{id:lf,group_id:lf,feature_id_1:lf,feature_id_2:lf,group_conditionality:df(cf),random_exclusion_fraction:uf,distance_upper_limit:uf,restraint_type:df(cf),dataset_list_id:lf},ma_model_list:{ordinal_id:lf,model_id:lf,model_group_id:lf,model_name:cf,model_group_name:cf,model_type:df(cf),data_id:lf},ma_target_entity:{entity_id:cf,data_id:lf,origin:df(cf)},ma_target_entity_instance:{asym_id:cf,entity_id:cf,details:cf},ma_target_ref_db_details:{target_entity_id:cf,db_name:df(cf),db_code:cf,db_accession:cf,seq_db_isoform:cf,seq_db_align_begin:cf,seq_db_align_end:cf,ncbi_taxonomy_id:cf,organism_scientific:cf},ma_data:{id:lf,content_type:df(cf),content_type_other_details:cf,name:cf},ma_software_group:{ordinal_id:lf,group_id:lf,software_id:lf},ma_qa_metric:{id:lf,name:cf,type:df(cf),mode:df(cf),software_group_id:lf},ma_qa_metric_global:{ordinal_id:lf,model_id:lf,metric_id:lf,metric_value:uf},ma_qa_metric_local:{ordinal_id:lf,model_id:lf,label_asym_id:cf,label_seq_id:lf,label_comp_id:cf,metric_id:lf,metric_value:uf}};var bf=Jh.Schema;const _f=bf.str,xf=bf.float,vf=bf.List,wf=bf.lstr,Af=bf.Aliased,Sf=bf.int,Cf=bf.coord,Pf={chem_comp:{formula:_f,formula_weight:xf,id:_f,mon_nstd_parent_comp_id:vf(",",(t=>t)),name:_f,one_letter_code:_f,three_letter_code:_f,type:Af(wf),pdbx_synonyms:vf(";",(t=>t)),pdbx_type:_f,pdbx_ambiguous_flag:_f,pdbx_replaced_by:_f,pdbx_replaces:_f,pdbx_formal_charge:Sf,pdbx_model_coordinates_details:_f,pdbx_model_coordinates_db_code:_f,pdbx_ideal_coordinates_details:_f,pdbx_ideal_coordinates_missing_flag:Af(wf),pdbx_model_coordinates_missing_flag:Af(wf),pdbx_initial_date:_f,pdbx_modified_date:_f,pdbx_release_status:Af(_f),pdbx_processing_site:Af(_f)},chem_comp_atom:{alt_atom_id:_f,atom_id:_f,charge:Sf,model_Cartn_x:Cf,model_Cartn_y:Cf,model_Cartn_z:Cf,comp_id:_f,type_symbol:_f,pdbx_align:Sf,pdbx_ordinal:Sf,pdbx_model_Cartn_x_ideal:Cf,pdbx_model_Cartn_y_ideal:Cf,pdbx_model_Cartn_z_ideal:Cf,pdbx_stereo_config:Af(wf),pdbx_aromatic_flag:Af(wf),pdbx_leaving_atom_flag:Af(wf)},chem_comp_bond:{atom_id_1:_f,atom_id_2:_f,comp_id:_f,value_order:Af(wf),pdbx_ordinal:Sf,pdbx_stereo_config:Af(wf),pdbx_aromatic_flag:Af(wf)},pdbx_chem_comp_descriptor:{comp_id:_f,descriptor:_f,type:Af(wf),program:_f,program_version:_f},pdbx_chem_comp_identifier:{comp_id:_f,identifier:_f,type:Af(_f),program:_f,program_version:_f}};var If=Jh.Schema;const kf=If.str,Mf=If.float,Tf=If.lstr,Df=If.Aliased,Bf=If.int,Ff={pdbx_reference_molecule:{prd_id:kf,formula_weight:Mf,formula:kf,type:Df(Tf),type_evidence_code:kf,class:Df(Tf),class_evidence_code:kf,name:kf,represent_as:Df(Tf),chem_comp_id:kf,compound_details:kf,description:kf,representative_PDB_id_code:kf,release_status:Df(Tf),replaces:kf,replaced_by:kf},pdbx_reference_entity_list:{prd_id:kf,ref_entity_id:kf,type:Df(Tf),details:kf,component_id:Bf},pdbx_reference_entity_nonpoly:{prd_id:kf,ref_entity_id:kf,name:kf,chem_comp_id:kf},pdbx_reference_entity_link:{link_id:Bf,prd_id:kf,details:kf,ref_entity_id_1:kf,ref_entity_id_2:kf,entity_seq_num_1:Bf,entity_seq_num_2:Bf,comp_id_1:kf,comp_id_2:kf,atom_id_1:kf,atom_id_2:kf,value_order:Df(Tf),component_1:Bf,component_2:Bf,link_class:Df(kf)},pdbx_reference_entity_poly_link:{link_id:Bf,prd_id:kf,ref_entity_id:kf,component_id:Bf,entity_seq_num_1:Bf,entity_seq_num_2:Bf,comp_id_1:kf,comp_id_2:kf,atom_id_1:kf,atom_id_2:kf,value_order:Df(Tf)},pdbx_reference_entity_poly:{prd_id:kf,ref_entity_id:kf,type:Df(kf),db_code:kf,db_name:kf},pdbx_reference_entity_poly_seq:{prd_id:kf,ref_entity_id:kf,mon_id:kf,parent_mon_id:kf,num:Bf,observed:Df(Tf),hetero:Df(Tf)},pdbx_reference_entity_sequence:{prd_id:kf,ref_entity_id:kf,type:Df(kf),NRP_flag:Df(kf),one_letter_codes:kf},pdbx_reference_entity_src_nat:{prd_id:kf,ref_entity_id:kf,ordinal:Bf,organism_scientific:kf,taxid:kf,db_code:kf,db_name:kf},pdbx_prd_audit:{prd_id:kf,date:kf,processing_site:Df(kf),action_type:Df(kf)}};var Ef=Jh.Schema;const Of=Ef.str,$f={datablock:{id:Of,description:Of},dictionary:{title:Of,datablock_id:Of,version:Of},dictionary_history:{version:Of,update:Of,revision:Of},sub_category:{id:Of,description:Of},category_group_list:{id:Of,parent_id:Of,description:Of},item_type_list:{code:Of,primitive_code:Of,construct:Of,detail:Of},item_units_list:{code:Of,detail:Of},item_units_conversion:{from_code:Of,to_code:Of,operator:Of,factor:Ef.float}};var Rf=Jh.Schema;const Lf=Rf.str,Nf=Rf.int,zf=Rf.float,Vf=Rf.Aliased,Uf=Rf.Vector;Vf(Lf),Vf(Lf),Vf(Lf),Vf(Lf),Uf(3),Uf(3);const jf={volume_data_3d_info:{name:Lf,axis_order:Uf(3,Nf),origin:Uf(3),dimensions:Uf(3),sample_rate:Nf,sample_count:Uf(3,Nf),spacegroup_number:Nf,spacegroup_cell_size:Uf(3),spacegroup_cell_angles:Uf(3),mean_source:zf,mean_sampled:zf,sigma_source:zf,sigma_sampled:zf,min_source:zf,min_sampled:zf,max_source:zf,max_sampled:zf},volume_data_3d:{values:zf}};var Gf=Jh.Schema;const Hf=Gf.float,qf=Gf.int,Wf=Gf.str,Xf={cell:{angle_alpha:Hf,angle_beta:Hf,angle_gamma:Hf,formula_units_z:qf,length_a:Hf,length_b:Hf,length_c:Hf,volume:Hf},chemical:{melting_point:Hf,name_common:Wf,name_systematic:Wf},chemical_formula:{moiety:Wf,sum:Wf,weight:Hf},space_group:{crystal_system:Wf,it_number:qf,"name_h-m_full":Wf},space_group_symop:{operation_xyz:Wf},geom_bond:{atom_site_label_1:Wf,atom_site_label_2:Wf,distance:Hf,publ_flag:Wf,site_symmetry_1:Wf,site_symmetry_2:Wf,valence:Hf},audit:{block_doi:Wf},database_code:{cod:Wf,csd:Wf,depnum_ccdc_archive:Wf,depnum_ccdc_fiz:Wf,icsd:Wf,mdf:Wf,nbs:Wf},atom_site:{adp_type:Wf,calc_flag:Wf,disorder_assembly:Wf,disorder_group:Wf,fract_x:Hf,fract_y:Hf,fract_z:Hf,label:Wf,occupancy:Hf,refinement_flags:Wf,site_symmetry_multiplicity:qf,type_symbol:Wf,u_iso_or_equiv:Hf},atom_site_aniso:{label:Wf,u_11:Hf,u:(0,Gf.Matrix)(3,3),u_12:Hf,u_13:Hf,u_22:Hf,u_23:Hf,u_33:Hf},atom_type:{description:Wf,symbol:Wf},atom_type_scat:{dispersion_imag:Hf,dispersion_real:Hf,source:Wf}},Yf={"cell.formula_units_z":["cell_formula_units_Z"],"space_group.it_number":["space_group_IT_number","symmetry_Int_Tables_number"],"space_group.name_h-m_full":["symmetry_space_group_name_H-M"],"space_group_symop.operation_xyz":["symmetry_equiv_pos_as_xyz"],"geom_bond.atom_site_label_1":["geom_bond_atom_site_id_1"],"geom_bond.atom_site_label_2":["geom_bond_atom_site_id_2"],"geom_bond.distance":["geom_bond_dist"],"audit.block_doi":["audit_block_DOI"],"database_code.cod":["database_code_COD"],"database_code.csd":["database_code_CSD"],"database_code.depnum_ccdc_archive":["database_code_depnum_CCDC_archive"],"database_code.depnum_ccdc_fiz":["database_code_depnum_CCDC_fiz"],"database_code.icsd":["database_code_ICSD"],"database_code.mdf":["database_code_MDF"],"database_code.nbs":["database_code_NBS"],"atom_site.adp_type":["atom_site_ADP_type","atom_site_thermal_displace_type"],"atom_site.label":["atom_site_id"],"atom_site.site_symmetry_multiplicity":["atom_site_symmetry_multiplicity"],"atom_site.u_iso_or_equiv":["atom_site_U_iso_or_equiv"],"atom_site_aniso.label":["atom_site_anisotrop_id"],"atom_site_aniso.u_11":["atom_site_aniso_U_11","atom_site_anisotrop_U_11"],"atom_site_aniso.u_12":["atom_site_aniso_U_12","atom_site_anisotrop_U_12"],"atom_site_aniso.u_13":["atom_site_aniso_U_13","atom_site_anisotrop_U_13"],"atom_site_aniso.u_22":["atom_site_aniso_U_22","atom_site_anisotrop_U_22"],"atom_site_aniso.u_23":["atom_site_aniso_U_23","atom_site_anisotrop_U_23"],"atom_site_aniso.u_33":["atom_site_aniso_U_33","atom_site_anisotrop_U_33"]};const Kf=Jh.Schema.int,Zf={volume_data_3d_info:jf.volume_data_3d_info,segmentation_data_table:{set_id:Kf,segment_id:Kf},segmentation_data_3d:{values:Kf}},Qf={parse:t=>"string"==typeof t?Cm(t):Km(t),parseText:Cm,parseBinary:Km,toDatabaseCollection:function(t,e,i){const r={};for(const n of e.blocks)r[n.header]=Qm(t,n,i);return r},toDatabase:Qm,schema:{mmCIF:t=>Qm(yf,t),CCD:t=>Qm(Pf,t),BIRD:t=>Qm(Ff,t),dic:t=>Qm($f,t),cifCore:t=>Qm(Xf,t,Yf),densityServer:t=>Qm(jf,t),segmentation:t=>Qm(Zf,t)}};class Jf{constructor(t,e){var i=e||{};this.streamer=t,this.name=l(i.name,""),this.path=l(i.path,"")}get type(){return""}get __objName(){return""}get isBinary(){return!1}get isJson(){return!1}get isXml(){return!1}parse(){return this.streamer.read().then((()=>kc(this,void 0,void 0,(function*(){return yield this._beforeParse(),yield this._parse(),yield this._afterParse(),this[this.__objName]}))))}_parse(){}_beforeParse(){}_afterParse(){t.Debug&&Dt.log(this[this.__objName])}}class tp extends Jf{constructor(t,e){var i=e||{};super(t,i),this.firstModelOnly=l(i.firstModelOnly,!1),this.asTrajectory=l(i.asTrajectory,!1),this.cAlphaOnly=l(i.cAlphaOnly,!1),this.structure=new fa(this.name,this.path),this.structureBuilder=new To(this.structure)}get type(){return"structure"}get __objName(){return"structure"}}class ep{constructor(t,e,i="",r,n=[]){this.structure=t,this.index=e,this.description=i,this.entityType=function(t){switch(t=t.toLowerCase()){case"polymer":return 1;case"non-polymer":return 2;case"macrolide":return 3;case"water":return 4;default:return 0}}(r||""),this.chainIndexList=n,n.forEach((function(i){t.chainStore.entityIndex[i]=e}))}get type(){return function(t){switch(t){case 1:return"polymer";case 2:return"non-polymer";case 3:return"macrolide";case 4:return"water";default:return}}(this.entityType)}getEntityType(){return this.entityType}isPolymer(){return 1===this.entityType}isNonPolymer(){return 2===this.entityType}isMacrolide(){return 3===this.entityType}isWater(){return 4===this.entityType}eachChain(t){const e=this.structure.getChainProxy();this.chainIndexList.forEach((function(i){e.index=i,t(e)}))}}const ip={a:1,b:1,c:1,alpha:90,beta:90,gamma:90,spacegroup:"P 1"};class rp{constructor(t=ip){this.cartToFrac=new e.Matrix4,this.fracToCart=new e.Matrix4,this.a=t.a,this.b=t.b,this.c=t.c,this.alpha=t.alpha,this.beta=t.beta,this.gamma=t.gamma,this.spacegroup=t.spacegroup;const i=T(this.alpha),r=T(this.beta),n=T(this.gamma),s=Math.cos(i),o=Math.cos(r),a=Math.cos(n),c=Math.sin(r),l=Math.sin(n);if(this.volume=this.a*this.b*this.c*Math.sqrt(1-s*s-o*o-a*a+2*s*o*a),void 0===t.cartToFrac){const t=this.a*this.b*l/this.volume,e=(o*a-s)/(c*l);this.fracToCart.set(this.a,0,0,0,this.b*a,this.b*l,0,0,this.c*o,-this.c*c*e,1/t,0,0,0,0,1).transpose(),this.cartToFrac.copy(this.fracToCart).invert()}else this.cartToFrac.copy(t.cartToFrac),this.fracToCart.copy(this.cartToFrac).invert()}getPosition(t){const i=new Float32Array(24);if(t.unitcell){const r=t.unitcell,n=t.center.clone().applyMatrix4(r.cartToFrac).floor(),s=new e.Vector3;let o=0;const a=function(t,e,a){s.set(t,e,a).add(n).applyMatrix4(r.fracToCart).toArray(i,o),o+=3};a(0,0,0),a(1,0,0),a(0,1,0),a(0,0,1),a(1,1,0),a(1,0,1),a(0,1,1),a(1,1,1)}return i}getCenter(t){return function(t,i=new e.Vector3){const r=t.length;for(let e=0;e<r;e+=3)i.x+=t[e],i.y+=t[e+1],i.z+=t[e+2];return i.divideScalar(r/3),i}(this.getPosition(t))}getData(t,i={}){const r=l(i.colorValue,"orange"),n=l(i.radius,Math.cbrt(this.volume)/200),s=new e.Color(r),o=new e.Vector3,a=this.getPosition(t),c=ye(8,s.r,s.g,s.b),u=ge(8,n),h=new Float32Array(36),d=new Float32Array(36),m=ye(12,s.r,s.g,s.b),f=ge(12,n);let p=0;function g(t,e){o.fromArray(a,3*t).toArray(h,p),o.fromArray(a,3*e).toArray(d,p),p+=3}g(0,1),g(0,2),g(0,3),g(1,4),g(1,5),g(2,6),g(3,5),g(4,7),g(5,7),g(2,4),g(7,6),g(3,6);const y=new Xn(this,t);return{vertex:{position:a,color:c,radius:u,picking:y},edge:{position1:h,position2:d,color:m,color2:m,radius:f,picking:y}}}}const np={1:"h",2:"h",3:"i",4:"h",5:"g",6:"h",7:"h",8:"h",9:"h",10:"h",0:"h"},sp=["DAL","DAR","DSG","DAS","DCY","DGL","DGN","DHI","DIL","DLE","DLY","MED","DPN","DPR","DSN","DTH","DTR","DTY","DVA","DNE"],op=["MOL_ID","MOLECULE","CHAIN","FRAGMENT","SYNONYM","EC","ENGINEERED","MUTATION","OTHER_DETAILS"],ap=/\s+/;function cp(t,e,i){let r=`${t}`;return e&&(r+=`:${e}`),i&&(r+=`^${i}`),r}class lp extends tp{constructor(t,e){const i=e||{};super(t,i),this.hex=l(i.hex,!1),this.inferBonds=l(i.inferBonds,"all")}get type(){return"pdb"}_parse(){t.Debug&&Dt.time("PdbParser._parse "+this.name);let i=!1;const r=this.streamer.peekLines(1)[0],n=r.substr(62,4),s=r.substr(72,4);n===s&&s.trim()&&(i=!0);const o="pqr"===this.type,a="pdbqt"===this.type,c=this.structure,l=this.structureBuilder,u=this.hex;let h=10,d=10;const m=this.firstModelOnly,f=this.asTrajectory,p=this.cAlphaOnly,g=c.frames,y=c.boxes;let b,_,x=!1;const v=c.biomolDict;let w,A,S,C,P,I,k,M,T,D,B,F,E,O,$,R,L,N,z,V,U,j,G={};const H={},q={},W=[];let X,Y;const K={},Z={},Q={};let J,tt,et,it,rt,nt,st;const ot={};let at;const ct={helices:[],sheets:[]},lt=ct.helices,ut=ct.sheets,ht=c.atomMap,dt=c.atomStore;dt.resize(Math.round(this.streamer.data.length/80)),(o||a)&&dt.addField("partialCharge",1,"float32"),o&&dt.addField("radius",1,"float32");const mt=c.getAtomProxy(),ft=c.getAtomProxy();let pt=0,gt=0,yt=!0;this.streamer.eachChunkOfLines((function(t){!function(t,r,n){for(let s=t;s<r;++s)if(C=n[s],P=C.substr(0,6),"ATOM  "===P||"HETATM"===P){if(yt&&(f?(x?(b=new Float32Array(3*dt.count),g.push(b)):b=[],_=0):m||(G={}),J=1,tt=J.toString(),et=!0,yt=!1),m&&gt>0)continue;let t,e,r,n,s,c=0;if(o){if(n=C.split(ap),c=10===n.length?1:0,F=n[2],p&&"CA"!==F)continue;t=parseFloat(n[6-c]),e=parseFloat(n[7-c]),r=parseFloat(n[8-c])}else{if(F=C.substr(12,4).trim(),p&&"CA"!==F)continue;t=parseFloat(C.substr(30,8)),e=parseFloat(C.substr(38,8)),r=parseFloat(C.substr(46,8))}if(f){const i=3*_;if(b[i+0]=t,b[i+1]=e,b[i+2]=r,_+=1,x)continue}o?(I=parseInt(n[1]),s="",E="H"===C[0],k=c?"":n[4],M=parseInt(n[5-c]),B="",T=n[3],$="",D=1):(I=parseInt(C.substr(6,5),h),u&&99999===I&&(h=16),E="H"===C[0],k=C[21].trim(),M=parseInt(C.substr(22,4),d),u&&9999===M&&(d=16),B=C[26].trim(),T=C.substr(17,4).trim()||"MOL",O=parseFloat(C.substr(60,6)),$=C[16].trim(),D=parseFloat(C.substr(54,6)),i||(a?(s=C.substr(76,3).trim(),s in nn&&(s=nn[s])):(s=C.substr(76,2).trim(),k||(k=C.substr(72,4).trim())),R=parseInt((C.substr(79,1)+C.substr(78,1)).trim()))),dt.growIfFull(),dt.atomTypeId[pt]=ht.add(F,s),dt.x[pt]=t,dt.y[pt]=e,dt.z[pt]=r,dt.serial[pt]=I,dt.altloc[pt]=$.charCodeAt(0),dt.occupancy[pt]=isNaN(D)?0:D,o?(dt.partialCharge[pt]=parseFloat(n[9-c]),dt.radius[pt]=parseFloat(n[10-c])):(dt.bfactor[pt]=isNaN(O)?0:O,a&&(dt.partialCharge[pt]=parseFloat(C.substr(70,6))),isFinite(R)&&(dt.formalCharge||dt.addField("formalCharge",1,"int8"),dt.formalCharge[pt]=R));const y=cp(M,k,B);!E||Z[y]||sp.includes(T)?et||it===k||(J+=1,tt=J.toString()):it===k&&nt===T&&(Zr.includes(T)||rt===M&&st===B)||(J+=1,tt=J.toString(),rt=M,nt=T,st=B),l.addAtom(gt,k,tt,T,M,E,void 0,B),G[I]=pt,pt+=1,et=!1,it=k}else if("CONECT"===P){const t=G[parseInt(C.substr(6,5))],e=[11,16,21,26],i={};if(void 0===t)continue;for(let r=0;r<4;++r){let n=parseInt(C.substr(e[r],5));if(!Number.isNaN(n)&&(n=G[n],void 0!==n))if(t<n?(mt.index=t,ft.index=n):(mt.index=n,ft.index=t),void 0!==i[n])c.bondStore.bondOrder[i[n]]+=1;else{const t=mt.index+"|"+ft.index;void 0===q[t]&&(q[t]=!0,i[n]=c.bondStore.count,c.bondStore.addBond(mt,ft,1))}}}else if("HELIX "===P){L=C[19].trim(),N=parseInt(C.substr(21,4)),z=C[25].trim(),V=C[31].trim(),U=parseInt(C.substr(33,4)),j=C[37].trim();let t=parseInt(C.substr(39,1));t=(np[t]||np[0]).charCodeAt(0),lt.push([L,N,z,V,U,j,t])}else if("SHEET "===P)L=C[21].trim(),N=parseInt(C.substr(22,4)),z=C[26].trim(),V=C[32].trim(),U=parseInt(C.substr(33,4)),j=C[37].trim(),ut.push([L,N,z,V,U,j]);else if("HETNAM"===P)K[C.substr(11,3)]=C.substr(15).trim();else if("SEQRES"===P){const t=C[11].trim();t!==at&&(ot[t]=[],at=t),ot[t].push(...C.substr(19).trim().split(ap))}else if("MODRES"===P){const t=C.substr(12,3).trim(),e=C[16].trim(),i=C[22].trim(),r=parseInt(C.substr(18,4).trim()),n=cp(r,e,i);Z[n]={resname:t,chainname:e,inscode:i,resno:r}}else if("COMPND"===P){const t=C.substr(10,70).trim(),e=t.indexOf(":"),i=t.substring(0,e);let r;op.includes(i)?(Y=i,r=t.substring(e+2)):r=t,r=r.replace(/;$/,""),"MOL_ID"===Y?(X={chainList:[],name:""},W.push(X)):"MOLECULE"===Y?(X.name&&(X.name+=" "),X.name+=r):"CHAIN"===Y&&Array.prototype.push.apply(X.chainList,r.split(/\s*,\s*/))}else if(C.startsWith("TER")){const t=c.getChainProxy(c.chainStore.count-1);Q[t.chainname]=t.index,J+=1,tt=J.toString(),et=!0}else if("REMARK"===P&&"350"===C.substr(7,3)){if("BIOMOLECULE:"===C.substr(11,12)){let t=C.substr(23).trim();/^(0|[1-9][0-9]*)$/.test(t)&&(t="BU"+t),w=new ko(t),v[t]=w}else if("BIOMT"===C.substr(13,5)){const t=C.split(/\s+/),i=parseInt(C[18])-1;0===i&&(S=new e.Matrix4,A.matrixList.push(S));const r=S.elements;r[0+i]=parseFloat(t[4]),r[4+i]=parseFloat(t[5]),r[8+i]=parseFloat(t[6]),r[12+i]=parseFloat(t[7])}else if("APPLY THE FOLLOWING TO CHAINS:"===C.substr(11,30)||"                   AND CHAINS:"===C.substr(11,30)){"APPLY"===C.substr(11,5)&&(A=w.addPart());const t=C.substr(41,30).split(",");for(let e=0,i=t.length;e<i;++e){const i=t[e].trim();i&&A.chainList.push(i)}}}else if("HEADER"===P)c.id=C.substr(62,4);else if("TITLE "===P)c.title+=(c.title?" ":"")+C.substr(10,70).trim();else if("MODEL "===P)yt=!0;else if("ENDMDL"===P||"END"===C.trim()){if(yt)continue;f&&!x&&(g.push(new Float32Array(b)),x=!0),gt+=1,yt=!0}else if("MTRIX"===C.substr(0,5)){if("1"===C[59])continue;if(!w||"NCS"!==w.name){const t="NCS";w=new ko(t),v[t]=w,A=w.addPart()}const t=C.split(/\s+/),i=parseInt(C[5])-1;0===i&&(S=new e.Matrix4,A.matrixList.push(S));const r=S.elements;r[0+i]=parseFloat(t[2]),r[4+i]=parseFloat(t[3]),r[8+i]=parseFloat(t[4]),r[12+i]=parseFloat(t[5])}else if("ORIGX"===C.substr(0,5)){H.origx||(H.origx=new e.Matrix4);const t=C.split(/\s+/),i=parseInt(C[5])-1,r=H.origx.elements;r[0+i]=parseFloat(t[1]),r[4+i]=parseFloat(t[2]),r[8+i]=parseFloat(t[3]),r[12+i]=parseFloat(t[4])}else if("SCALE"===C.substr(0,5)){H.scale||(H.scale=new e.Matrix4);const t=C.split(/\s+/),i=parseInt(C[5])-1,r=H.scale.elements;r[0+i]=parseFloat(t[1]),r[4+i]=parseFloat(t[2]),r[8+i]=parseFloat(t[3]),r[12+i]=parseFloat(t[4])}else if("CRYST1"===P){const t=parseFloat(C.substr(6,9)),e=parseFloat(C.substr(15,9)),i=parseFloat(C.substr(24,9)),r=parseFloat(C.substr(33,7)),n=parseFloat(C.substr(40,7)),s=parseFloat(C.substr(47,7)),o=C.substr(55,11).trim(),a=new Float32Array(9);a[0]=t,a[4]=e,a[8]=i,y.push(a),0===gt&&(H.a=t,H.b=e,H.c=i,H.alpha=r,H.beta=n,H.gamma=s,H.spacegroup=o)}}(0,t.length,t)})),l.finalize();const bt=W.length;if(bt){c.eachChain((function(t){t.entityIndex=bt})),W.forEach((function(t,e){const i=t.chainList.map((function(t){return Q[t]}));c.entityList.push(new ep(c,e,t.name,"polymer",i))}));let t=W.length;const e=c.getResidueProxy(),i={};c.eachChain((function(t){t.entityIndex===bt&&(e.index=t.residueOffset,i[e.resname]||(i[e.resname]=[]),i[e.resname].push(t.index))})),Object.keys(i).forEach((function(e){const r=i[e];let n="non-polymer",s=K[e]||e;Zr.includes(e)&&(s="water",n="water"),c.entityList.push(new ep(c,t,s,n,r)),t+=1}))}void 0!==H.a?c.unitcell=new rp(H):c.unitcell=void 0,(lt.length||ut.length)&&Do(c,ct),c.finalizeAtoms(),i||Oo(c),$o(c,this.inferBonds),c.finalizeBonds(),lt.length||ut.length||Bo(c),Vo(c),t.Debug&&Dt.timeEnd("PdbParser._parse "+this.name)}}Nt.add("pdb",lp),Nt.add("pdb1",lp),Nt.add("ent",lp);class up{constructor(t){this.structure=t,this.dict={},this.structure=t}add(t,e,i){this.dict[t]={chemCompType:e},i&&(this.dict[t].bonds=i)}addBond(t,e,i,r){const n=this.dict[t];if(!n)return;n.bonds||(n.bonds={atom1:[],atom2:[],bondOrders:[]});const s=n.bonds;s.atom1.push(e),s.atom2.push(i),s.bondOrders.push(r)}getBonds(t,e){var i;const r=null===(i=this.dict[t])||void 0===i?void 0:i.bonds;if(!r)return;const n=this.structure.atomMap,s=new Map(e.map(((t,e)=>{var i;return[null===(i=n.get(t))||void 0===i?void 0:i.atomname,e]}))),o=[],a=[],c=[];let l,u;for(let t=0;t<r.atom1.length;t++)void 0!==(l=s.get(r.atom1[t]))&&void 0!==(u=s.get(r.atom2[t]))&&(o.push(l),a.push(u),c.push(r.bondOrders[t]));return{atomIndices1:o,atomIndices2:a,bondOrders:c}}}const hp=/^\D{1,2}/,dp={HELX_RH_AL_P:"h",STRN:"e",HELX_RH_3T_P:"g",HELX_RH_PI_P:"i",HELX_LH_PP_P:"e",TURN_TY1_P:"t",BEND:"s",OTHER:" "},mp={AROM:1,DELO:2,DIRECTED:0,DOUB:2,PI:0,POLY:0,QUAD:4,SING:1,TRIP:3};function fp(t){switch(t.toLowerCase()){case"?":case"sing":return 1;case"doub":return 2;case"trip":return 3;case"quad":return 4}return 0}class pp extends tp{get type(){return"cif"}get isBinary(){return!1}_parse(){var i,r,n,s,o,a,c,l,u,h,d,m,f,p,g,y,b,x,v,w,A;return kc(this,void 0,void 0,(function*(){Dt.time("CifParser._parse "+this.name);const S=this.structure,C=this.structureBuilder,P=this.firstModelOnly,I=this.asTrajectory,k=S.frames;let M,T;const D=this.isBinary?Qf.parseBinary(this.streamer.data):Qf.parseText(this.streamer.compressed?_(this.streamer.data):this.streamer.data),B=yield D.run();if(B.isError)throw B;const F=B.result.blocks[0];if("chem_comp"in F.categories&&"chem_comp_atom"in F.categories&&!("struct"in F.categories))!function(t,e,i){const r=e.atomStore,n=e.atomMap;let s,o;const a=t.chem_comp,c=t.chem_comp_atom,l=t.chem_comp_bond;let u;a&&((u=a.getField("name"))&&(e.title=u.str(0)),(u=a.getField("id"))&&(e.id=u.str(0)));const h={};if(c){let t,e,s,a;o=c.rowCount,r.resize(2*o);const l=c.getField("atom_id"),u=c.getField("type_symbol"),d=c.getField("pdbx_component_comp_id"),m=c.getField("pdbx_residue_numbering");[["model_Cartn_x","model_Cartn_y","model_Cartn_z"],["pdbx_model_Cartn_x_ideal","pdbx_model_Cartn_y_ideal","pdbx_model_Cartn_z_ideal"]].forEach((([f,p,g],y)=>{var b;const _=c.getField(f),x=c.getField(p),v=c.getField(g),w=y*o;for(let c=0;c<o;++c){const o=c+w;r.growIfFull(),t=null==l?void 0:l.str(c),e=null==u?void 0:u.str(c),h[t]=c,r.atomTypeId[o]=n.add(t,e),r.x[o]=_.float(c),r.y[o]=x.float(c),r.z[o]=v.float(c),r.serial[o]=c,s=d.str(c),a=null!==(b=null==m?void 0:m.int(c))&&void 0!==b?b:1,i.addAtom(y,"","",s,a,!0)}}))}if(c&&l){let t,i,r;o=l.rowCount;const n=c.rowCount,a=e.getAtomProxy(),u=e.getAtomProxy(),d=l.getField("atom_id_1"),m=l.getField("atom_id_2"),f=l.getField("value_order");for(s=0;s<o;++s)t=d.str(s),i=m.str(s),r=fp(f.str(s)),a.index=h[t],u.index=h[i],e.bondStore.growIfFull(),e.bondStore.addBond(a,u,r),a.index+=n,u.index+=n,e.bondStore.growIfFull(),e.bondStore.addBond(a,u,r)}}(F.categories,S,C),C.finalize(),S.finalizeAtoms(),S.finalizeBonds(),Ho(S);else if("atom_site_type_symbol"in F.categories&&"atom_site_label"in F.categories&&"atom_site_fract_x"in F.categories)!function(t,i,r){var n,s,o=i.atomStore,a=i.atomMap;t.header&&(i.id=t.header,i.name=t.header),i.unitcell=new rp({a:t.getField("cell_length_a").float(0),b:t.getField("cell_length_b").float(0),c:t.getField("cell_length_c").float(0),alpha:t.getField("cell_angle_alpha").float(0),beta:t.getField("cell_angle_beta").float(0),gamma:t.getField("cell_angle_gamma").float(0),spacegroup:t.getField("symmetry_space_group_name_H-M").str(0)});const c=new e.Vector3,l=new e.Vector3,u=t.getField("atom_site_type_symbol");if(!u)return;const h=null!==(n=u.rowCount)&&void 0!==n?n:0,d=t.getField("atom_site_type_symbol"),m=t.getField("atom_site_fract_x"),f=t.getField("atom_site_fract_y"),p=t.getField("atom_site_fract_z"),g=t.getField("atom_site_occupancy"),y={};for(let t=0;t<h;++t){o.growIfFull();const e=d.str(t),n=u.str(t);let h=y[n];if(!h){const t=n.match(hp);y[n]=h=null!==(s=null==t?void 0:t[0])&&void 0!==s?s:n}o.atomTypeId[t]=a.add(e,h),c.set(m.float(t),f.float(t),p.float(t)),c.applyMatrix4(i.unitcell.fracToCart),l.add(c),o.x[t]=c.x,o.y[t]=c.y,o.z[t]=c.z,g&&(o.occupancy[t]=g.float(t)),o.serial[t]=t,r.addAtom(0,"","","HET",1,!0)}l.divideScalar(h),i.center=l,Vo(i);const b=new e.Vector3,_=new e.Vector3,x=i.biomolDict.SUPERCELL.partList[0].matrixList;let v=h;function w(t){return a.get(o.atomTypeId[t]).covalent}const A=new e.Matrix4;for(let t=0;t<h;++t){const e=w(t);c.set(o.x[t],o.y[t],o.z[t]),x.forEach((function(i){if(!A.equals(i)){b.copy(c),b.applyMatrix4(i);for(let i=0;i<h;++i){_.set(o.x[i],o.y[i],o.z[i]);const n=b.distanceToSquared(_),s=w(i)+e,a=s+.3,c=s-.5;if(n<a*a&&n>c*c)return o.growIfFull(),o.atomTypeId[v]=o.atomTypeId[t],o.x[v]=b.x,o.y[v]=b.y,o.z[v]=b.z,o.occupancy[v]=o.occupancy[t],o.serial[v]=v,o.altloc[v]="A".charCodeAt(0),r.addAtom(0,"","","HET",1,!0),void(v+=1)}}}))}}(F,S,C),C.finalize(),S.finalizeAtoms(),$o(S),S.finalizeBonds();else{const _={},D={},B=S.atomMap,E=S.atomStore,O=F.categories.atom_site;let $=O.rowCount;const R=O.getField("pdbx_PDB_model_num");if(!(null===(i=null==R?void 0:R.areValuesEqual(0,$-1))||void 0===i||i)&&(I||P)){const t=R.int(0);for(let e=0;e<$;e++)if(R.int(e)>t){$=e;break}}S.chemCompMap=new up(S);const L=F.categories.chem_comp;let N=L.getField("id");const z=L.getField("type");for(let t=0;t<L.rowCount;t++)S.chemCompMap.add(N.str(t),z.str(t).toUpperCase());if(F.categoryNames.includes("chem_comp_bond")){const t=F.categories.chem_comp_bond;N=t.getField("comp_id");const e=t.getField("atom_id_1"),i=t.getField("atom_id_2"),r=t.getField("value_order");for(let n=0;n<t.rowCount;n++){const t=mp[r.str(n).toUpperCase()];t&&S.chemCompMap.addBond(N.str(n),e.str(n),i.str(n),t)}}const V=(t,e,i)=>{const r=t.getField(e);return r?r.toFloatArray({array:Float32Array,start:0,end:i}):new Float32Array(i)};E.resize($),E.x=V(O,"Cartn_x",$),E.y=V(O,"Cartn_y",$),E.z=V(O,"Cartn_z",$),E.serial=O.getField("id").toIntArray({start:0,end:$}),E.bfactor=V(O,"B_iso_or_equiv",$),E.occupancy=V(O,"occupancy",$);const U=O.getField("label_alt_id");(null==U?void 0:U.isDefined)&&(E.altloc=Uint8Array.from(U.toStringArray(),(t=>t.charCodeAt(0))));const j=O.getField("label_atom_id"),G=O.getField("type_symbol");N=O.getField("label_comp_id");const H=null!==(r=O.getField("auth_seq_id"))&&void 0!==r?r:O.getField("label_seq_id"),q=O.getField("pdbx_PDB_ins_code"),W=O.getField("auth_asym_id"),X=O.getField("label_asym_id"),Y=O.getField("group_PDB"),K=O.getField("label_entity_id");for(let t=0;t<$;t++){const e=null!==(n=null==R?void 0:R.int(t))&&void 0!==n?n:1,i=null!==(s=null==W?void 0:W.str(t))&&void 0!==s?s:"",r=null!==(o=null==X?void 0:X.str(t))&&void 0!==o?o:"",h=null!==(a=null==N?void 0:N.str(t))&&void 0!==a?a:"",d=null!==(c=null==H?void 0:H.int(t))&&void 0!==c?c:0,m="H"===(null==Y?void 0:Y.str(t)[0]),f=null!==(l=null==q?void 0:q.str(t))&&void 0!==l?l:"",p=null!==(u=null==K?void 0:K.int(t))&&void 0!==u?u:1;E.atomTypeId[t]=B.add((null==j?void 0:j.str(t))||"",null==G?void 0:G.str(t)),C.addAtom(e-1,i,r,h,d,m,void 0,f),_[r]=i,D[p]||(D[p]=new Set),D[p].add(S.chainStore.count-1)}if(I){const t=O.rowCount/$|0,e=O.getField("Cartn_x"),i=O.getField("Cartn_y"),r=O.getField("Cartn_z");for(let n=0;n<t;n++){M=new Float32Array(3*$);const t=n*$,s=t+$;T=0;for(let n=t;n<s;n++)M[T+0]=e.float(n),M[T+1]=i.float(n),M[T+2]=r.float(n),T+=3;k.push(M)}}const Z=function(t,e,i){var r,n,s,o,a,c;const l=[],u=[];let h,d,m,f;const p=t.struct_conf;if(null==p?void 0:p.fieldNames.includes("pdbx_PDB_helix_class")){const t=p.getField("pdbx_beg_PDB_ins_code"),e=p.getField("pdbx_end_PDB_ins_code"),s=p.getField("pdbx_PDB_helix_class"),o=p.getField("beg_label_asym_id"),a=p.getField("end_label_asym_id"),c=p.getField("beg_auth_seq_id"),u=p.getField("end_auth_seq_id");for(h=0,d=p.rowCount;h<d;++h){const d=null==s?void 0:s.int(h);Number.isFinite(d)&&(m=null!==(r=null==t?void 0:t.str(h))&&void 0!==r?r:"",f=null!==(n=null==e?void 0:e.str(h))&&void 0!==n?n:"",l.push([i[o.str(h)],c.int(h),m,i[a.str(h)],u.int(h),f,(np[d]||np[0]).charCodeAt(0)]))}}else if(null==p?void 0:p.fieldNames.includes("conf_type_id")){const t=p.getField("conf_type_id"),e=p.getField("pdbx_beg_PDB_ins_code"),r=p.getField("pdbx_end_PDB_ins_code"),n=p.getField("beg_label_asym_id"),a=p.getField("end_label_asym_id"),c=p.getField("beg_auth_seq_id"),g=p.getField("end_auth_seq_id");let y;for(h=0,d=p.rowCount;h<d;++h){const d=t.str(h);(y=dp[d])&&(m=null!==(s=null==e?void 0:e.str(h))&&void 0!==s?s:"",f=null!==(o=null==r?void 0:r.str(h))&&void 0!==o?o:"","h"===y||"g"===y||"i"===y?l.push([i[n.str(h)],c.int(h),m,i[a.str(h)],g.int(h),f,y.charCodeAt(0)]):"e"===y&&u.push([i[n.str(h)],c.int(h),m,i[a.str(h)],g.int(h),f]))}}const g=t.struct_sheet_range;if(g&&0===u.length){const t=g.getField("pdbx_beg_PDB_ins_code"),e=g.getField("pdbx_end_PDB_ins_code"),r=g.getField("beg_label_asym_id"),n=g.getField("end_label_asym_id"),s=g.getField("beg_auth_seq_id"),o=g.getField("end_auth_seq_id");for(h=0,d=g.rowCount;h<d;++h)m=null!==(a=null==t?void 0:t.str(h))&&void 0!==a?a:"",f=null!==(c=null==e?void 0:e.str(h))&&void 0!==c?c:"",u.push([i[r.str(h)],s.int(h),m,i[n.str(h)],o.int(h),f])}return!(!p&&!g)&&{helices:l,sheets:u}}(F.categories,0,_);let Q,J;if(function(t,i,r){const n={},s=i.biomolDict;if(t.pdbx_struct_oper_list){const i=t.pdbx_struct_oper_list,r=i.getField("id"),s=i.getField("matrix[1][1]"),o=i.getField("matrix[1][2]"),a=i.getField("matrix[1][3]"),c=i.getField("matrix[2][1]"),l=i.getField("matrix[2][2]"),u=i.getField("matrix[2][3]"),h=i.getField("matrix[3][1]"),d=i.getField("matrix[3][2]"),m=i.getField("matrix[3][3]"),f=i.getField("vector[1]"),p=i.getField("vector[2]"),g=i.getField("vector[3]");for(let t=0;t<i.rowCount;t++){const i=new e.Matrix4,y=i.elements;y[0]=s.float(t),y[1]=o.float(t),y[2]=a.float(t),y[4]=c.float(t),y[5]=l.float(t),y[6]=u.float(t),y[8]=h.float(t),y[9]=d.float(t),y[10]=m.float(t),y[3]=f.float(t),y[7]=p.float(t),y[11]=g.float(t),i.transpose(),n[r.str(t)]=i}}if(t.pdbx_struct_assembly_gen){const i=t.pdbx_struct_assembly_gen,o=function(t){const e={};return t.replace(/[()']/g,"").split(",").forEach((function(t){if(t.includes("-"))for(var i=t.split("-"),r=parseInt(i[0]),s=parseInt(i[1]);r<=s;++r)e[r]=n[r];else e[t]=n[t]})),e},a=i.getField("assembly_id"),c=i.getField("oper_expression"),l=i.getField("asym_id_list");for(let t=0;t<i.rowCount;t++){const i=a.int(t);let n={},u=c.str(t).replace(/['"]\(|['"]/g,"");if(u.includes(")(")||u.indexOf("(")>0){const[t,i]=u.split("(").filter((t=>!!t)),r=o(t),s=o(i);Object.keys(r).forEach((function(t){Object.keys(s).forEach((function(i){const o=new e.Matrix4;o.multiplyMatrices(r[t],s[i]),n[t+"x"+i]=o}))}))}else n=o(u);const h=[];for(let t in n)h.push(n[t]);let d=""+i;/^(0|[1-9][0-9]*)$/.test(d)&&(d="BU"+d);const m=l.str(t).split(",").map((t=>r[t]));void 0===s[d]&&(s[d]=new ko(d)),s[d].addPart(h,m)}}if(t.struct_ncs_oper){const i=t.struct_ncs_oper,r="NCS";s[r]=new ko(r);const n=s[r].addPart(),o=i.getField("code"),a=i.getField("matrix[1][1]"),c=i.getField("matrix[1][2]"),l=i.getField("matrix[1][3]"),u=i.getField("matrix[2][1]"),h=i.getField("matrix[2][2]"),d=i.getField("matrix[2][3]"),m=i.getField("matrix[3][1]"),f=i.getField("matrix[3][2]"),p=i.getField("matrix[3][3]"),g=i.getField("vector[1]"),y=i.getField("vector[2]"),b=i.getField("vector[3]");for(let t=0;t<i.rowCount;t++){if("given"===o.str(t))return;const i=new e.Matrix4,r=i.elements;r[0]=a.float(t),r[1]=c.float(t),r[2]=l.float(t),r[4]=u.float(t),r[5]=h.float(t),r[6]=d.float(t),r[8]=m.float(t),r[9]=f.float(t),r[10]=p.float(t),r[3]=g.float(t),r[7]=y.float(t),r[11]=b.float(t),i.transpose(),n.matrixList.push(i)}0===n.matrixList.length&&delete s[r]}const o={};if(t.cell){const e=t.cell,r=e.getField("length_a").float(0),n=e.getField("length_b").float(0),s=e.getField("length_c").float(0),a=new Float32Array(9);a[0]=r,a[4]=n,a[8]=s,i.boxes.push(a),o.a=r,o.b=n,o.c=s,o.alpha=e.getField("angle_alpha").float(0),o.beta=e.getField("angle_beta").float(0),o.gamma=e.getField("angle_gamma").float(0)}t.symmetry&&(o.spacegroup=t.symmetry.getField("space_group_name_H-M").str(0));const a=new e.Matrix4;if(t.database_PDB_matrix){const e=t.database_PDB_matrix,i=a.elements,r=e.getField("origx[1][1]"),n=e.getField("origx[1][2]"),s=e.getField("origx[1][3]"),c=e.getField("origx[2][1]"),l=e.getField("origx[2][2]"),u=e.getField("origx[2][3]"),h=e.getField("origx[3][1]"),d=e.getField("origx[3][2]"),m=e.getField("origx[3][3]"),f=e.getField("origx_vector[1]"),p=e.getField("origx_vector[2]"),g=e.getField("origx_vector[3]");i[0]=r.float(0),i[1]=n.float(0),i[2]=s.float(0),i[4]=c.float(0),i[5]=l.float(0),i[6]=u.float(0),i[8]=h.float(0),i[9]=d.float(0),i[10]=m.float(0),i[3]=f.float(0),i[7]=p.float(0),i[11]=g.float(0),a.transpose(),o.origx=a}const c=new e.Matrix4;if(t.atom_sites){const e=t.atom_sites,i=c.elements,r=e.getField("fract_transf_matrix[1][1]"),n=e.getField("fract_transf_matrix[1][2]"),s=e.getField("fract_transf_matrix[1][3]"),a=e.getField("fract_transf_matrix[2][1]"),l=e.getField("fract_transf_matrix[2][2]"),u=e.getField("fract_transf_matrix[2][3]"),h=e.getField("fract_transf_matrix[3][1]"),d=e.getField("fract_transf_matrix[3][2]"),m=e.getField("fract_transf_matrix[3][3]"),f=e.getField("fract_transf_vector[1]"),p=e.getField("fract_transf_vector[2]"),g=e.getField("fract_transf_vector[3]");i[0]=r.float(0),i[1]=n.float(0),i[2]=s.float(0),i[4]=a.float(0),i[5]=l.float(0),i[6]=u.float(0),i[8]=h.float(0),i[9]=d.float(0),i[10]=m.float(0),i[3]=f.float(0),i[7]=p.float(0),i[11]=g.float(0),c.transpose(),o.scale=c}void 0!==o.a?i.unitcell=new rp(o):i.unitcell=void 0}(F.categories,S,_),function(e,i,r){const n=e.struct_conn;if(n){const e=i.getAtomProxy(),a=i.getAtomProxy(),c={},l=n.getField("conn_type_id"),u=n.getField("ptnr1_symmetry"),h=n.getField("pdbx_ptnr1_PDB_ins_code"),d=n.getField("pdbx_ptnr1_label_alt_id"),m=n.getField("ptnr1_auth_seq_id"),f=n.getField("ptnr1_label_asym_id"),p=n.getField("ptnr1_label_atom_id"),g=n.getField("ptnr2_symmetry"),y=n.getField("pdbx_ptnr2_PDB_ins_code"),b=n.getField("pdbx_ptnr2_label_alt_id"),_=n.getField("ptnr2_auth_seq_id"),x=n.getField("ptnr2_label_asym_id"),v=n.getField("ptnr2_label_atom_id"),w=n.getField("pdbx_value_order");for(let A=0,S=n.rowCount;A<S;++A){const n=l.str(A);if("hydrog"===n||"mismat"===n||"saltbr"===n)continue;if("1_555"!==u.str(A)||"1_555"!==g.str(A))continue;const S=h.str(A),C=d.str(A),P=m.str(A)+(S?"^"+S:"")+":"+r[f.str(A)]+"."+p.str(A)+(C?"%"+C:"");let I=c[P];if(!I){const e=new gt(P);if(e.selection.error){t.Debug&&Dt.warn("invalid selection for connection",P);continue}I=i.getAtomIndices(e),c[P]=I}const k=y.str(A),M=b.str(A),T=_.str(A)+(k?"^"+k:"")+":"+r[x.str(A)]+"."+v.str(A)+(M?"%"+M:"");let D=c[T];if(!D){const e=new gt(T);if(e.selection.error){t.Debug&&Dt.warn("invalid selection for connection",T);continue}D=i.getAtomIndices(e),c[T]=D}var s=I.length,o=D.length;if(s>o&&([s,o]=[o,s],[I,D]=[D,I]),0!==s&&0!==o)for(let t=0;t<o;++t)e.index=I[t%s],a.index=D[t],e&&a?i.bondStore.addBond(e,a,fp(w.str(A))):Dt.log("atoms for connection not found");else t.Debug&&Dt.warn("no atoms found for",P,T)}}}(F.categories,S,_),function(t,e,i){var r;if(t.entity){const n=t.entity,s=n.getField("id"),o=n.getField("pdbx_description"),a=n.getField("type"),c=n.rowCount;for(let t=0;t<c;++t){const n=Array.from(null!==(r=i[s.int(t)])&&void 0!==r?r:[]);e.entityList[t]=new ep(e,t,null==o?void 0:o.str(t),a.str(t),n)}}}(F.categories,S,D),(Q=null===(h=F.categories.struct)||void 0===h?void 0:h.getField("title"))&&(J=Q.str(0))&&(S.title=J),(Q=null===(d=F.categories.entry)||void 0===d?void 0:d.getField("id"))&&(J=Q.str(0))&&(S.id=J),F.categories.pdbx_audit_revision_history){if(Q=null===(m=F.categories.pdbx_audit_revision_history)||void 0===m?void 0:m.getField("revision_date"))for(let t=0;t<Q.rowCount;t++)if(J=Q.str(t)){S.header.releaseDate=J;break}if(Q=null===(f=F.categories.pdbx_database_status)||void 0===f?void 0:f.getField("recvd_initial_deposition_date"))for(let t=0;t<Q.rowCount;t++)if(J=Q.str(t)){S.header.depositionDate=J;break}}else if(F.categories.database_PDB_rev){if(Q=null===(p=F.categories.database_PDB_rev)||void 0===p?void 0:p.getField("date"))for(let t=0;t<Q.rowCount;t++)if(J=Q.str(t)){S.header.releaseDate=J;break}if(Q=null===(g=F.categories.database_PDB_rev)||void 0===g?void 0:g.getField("date_original"))for(let t=0;t<Q.rowCount;t++)if(J=Q.str(t)){S.header.depositionDate=J;break}}(Q=null!==(b=null===(y=F.categories.reflns)||void 0===y?void 0:y.getField("d_resolution_high"))&&void 0!==b?b:null===(x=F.categories.refine)||void 0===x?void 0:x.getField("ls_d_res_high"))&&0===Q.valueKind(0)&&(S.header.resolution=Q.float(0)),(Q=null===(v=F.categories.refine)||void 0===v?void 0:v.getField("ls_R_factor_R_free"))&&0===Q.valueKind(0)&&(S.header.rFree=Q.float(0)),(Q=null===(w=F.categories.refine)||void 0===w?void 0:w.getField("ls_R_factor_R_work"))&&0===Q.valueKind(0)&&(S.header.rFree=Q.float(0)),(Q=null===(A=F.categories.exptl)||void 0===A?void 0:A.getField("method"))&&(S.header.experimentalMethods=Q.toStringArray().slice()),C.finalize(),S.finalizeAtoms(),$o(S),S.finalizeBonds(),Z?Do(S,Z):Bo(S),Vo(S),S.extraData.cif=F}t.Debug&&Dt.timeEnd("CifParser._parse "+this.name)}))}}Nt.add("bcif",class extends pp{get type(){return"bcif"}get isBinary(){return!0}}),Nt.add("cif",pp),Nt.add("mcif",pp),Nt.add("mmcif",pp);Nt.add("gro",class extends tp{get type(){return"gro"}_parse(){t.Debug&&Dt.time("GroParser._parse "+this.name);var e,i,r=this.structure,n=this.structureBuilder,s=this.firstModelOnly,o=this.asTrajectory,a=this.cAlphaOnly,c=r.frames,l=r.boxes,u=this.streamer.peekLines(3);r.title=u[0].trim();var h,d,m,f,p=5+(u[2].length-u[2].lastIndexOf(".")-1),g=20+p,y=20+2*p,b=parseInt(u[1]),_=b+3,x=r.atomMap,v=r.atomStore;v.resize(b);var w=0,A=0,S=0;this.streamer.eachChunkOfLines((function(t){!function(t,r,u){for(var C=t;C<r;++C){var P=++S-1,I=u[C];if(I)if(P%_==0)o&&(e=new Float32Array(3*b),c.push(e),i=0);else if(P%_==1);else if(P%_==_-1){var k=I.trim().split(/\s+/),M=new Float32Array(9);if(M[0]=10*parseFloat(k[0]),M[4]=10*parseFloat(k[1]),M[8]=10*parseFloat(k[2]),l.push(M),s)return!0;A+=1}else{if(h=I.substr(10,5).trim(),a&&"CA"!==h)continue;var T=10*parseFloat(I.substr(20,p)),D=10*parseFloat(I.substr(g,p)),B=10*parseFloat(I.substr(y,p));if(o){var F=3*i;if(e[F+0]=T,e[F+1]=D,e[F+2]=B,i+=1,P>_)continue}d=I.substr(5,5).trim(),m=parseInt(I.substr(0,5)),f=parseInt(I.substr(15,5)),v.growIfFull(),v.atomTypeId[w]=x.add(h),v.x[w]=T,v.y[w]=D,v.z[w]=B,v.serial[w]=f,n.addAtom(A,"","",d,m,!1,"l"),w+=1}}}(0,t.length,t)})),n.finalize(),r.finalizeAtoms(),Oo(r),$o(r),r.finalizeBonds(),Bo(r),t.Debug&&Dt.timeEnd("GroParser._parse "+this.name)}});var gp=["mmtfVersion","mmtfProducer","unitCell","spaceGroup","structureId","title","depositionDate","releaseDate","experimentalMethods","resolution","rFree","rWork","bioAssemblyList","ncsOperatorList","entityList","groupList","numBonds","numAtoms","numGroups","numChains","numModels","groupsPerChain","chainsPerModel"].concat(["xCoordList","yCoordList","zCoordList","groupIdList","groupTypeList","chainIdList","bFactorList","atomIdList","altLocList","occupancyList","secStructList","insCodeList","sequenceIndexList","chainNameList","bondAtomList","bondOrderList"]);function yp(t,e,i){return e?new t(e.buffer,e.byteOffset,e.byteLength/(i||1)):void 0}function bp(t){return yp(DataView,t)}function _p(t){return yp(Int8Array,t)}function xp(t){return yp(Int32Array,t,4)}function vp(t,e){var i=t.length/2;e||(e=new Int16Array(i));for(var r=0,n=0;r<i;++r,n+=2)e[r]=t[n]<<8^t[n+1];return e}function wp(t,e){var i=t.length/4;e||(e=new Int32Array(i));for(var r=0,n=0;r<i;++r,n+=4)e[r]=t[n]<<24^t[n+1]<<16^t[n+2]<<8^t[n+3];return e}function Ap(t,e,i){var r=t.length,n=1/e;i||(i=new Float32Array(r));for(var s=0;s<r;++s)i[s]=t[s]*n;return i}function Sp(t,e){var i,r;if(!e){var n=0;for(i=0,r=t.length;i<r;i+=2)n+=t[i+1];e=new t.constructor(n)}var s=0;for(i=0,r=t.length;i<r;i+=2)for(var o=t[i],a=t[i+1],c=0;c<a;++c)e[s]=o,++s;return e}function Cp(t,e){var i=t.length;e||(e=new t.constructor(i)),i&&(e[0]=t[0]);for(var r=1;r<i;++r)e[r]=t[r]+e[r-1];return e}function Pp(t,e){var i,r,n=t instanceof Int8Array?127:32767,s=-n-1,o=t.length;if(!e){var a=0;for(i=0;i<o;++i)t[i]<n&&t[i]>s&&++a;e=new Int32Array(a)}for(i=0,r=0;i<o;){for(var c=0;t[i]===n||t[i]===s;)c+=t[i],++i;c+=t[i],++i,e[r]=c,++r}return e}function Ip(t,e,i){return Ap(Pp(t,xp(i)),e,i)}function kp(t,e,i){var r=Pp(t,xp(i));return function(t,e,i){return Ap(Cp(t,xp(i)),e,i)}(r,e,yp(Float32Array,r,4))}function Mp(t){var e=0,i=new DataView(t.buffer);function r(t){for(var e={},i=0;i<t;i++){e[a()]=a()}return e}function n(i){var r=t.subarray(e,e+i);return e+=i,r}function s(i){var r=t.subarray(e,e+i);e+=i;var n=65535;if(i>n){for(var s=[],o=0;o<r.length;o+=n)s.push(String.fromCharCode.apply(null,r.subarray(o,o+n)));return s.join("")}return String.fromCharCode.apply(null,r)}function o(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=a();return e}function a(){var a,c,l=t[e];if(!(128&l))return e++,l;if(128==(240&l))return e++,r(c=15&l);if(144==(240&l))return e++,o(c=15&l);if(160==(224&l))return e++,s(c=31&l);if(!(224&~l))return a=i.getInt8(e),e++,a;switch(l){case 192:return e++,null;case 194:return e++,!1;case 195:return e++,!0;case 196:return c=i.getUint8(e+1),e+=2,n(c);case 197:return c=i.getUint16(e+1),e+=3,n(c);case 198:return c=i.getUint32(e+1),e+=5,n(c);case 202:return a=i.getFloat32(e+1),e+=5,a;case 203:return a=i.getFloat64(e+1),e+=9,a;case 204:return a=t[e+1],e+=2,a;case 205:return a=i.getUint16(e+1),e+=3,a;case 206:return a=i.getUint32(e+1),e+=5,a;case 208:return a=i.getInt8(e+1),e+=2,a;case 209:return a=i.getInt16(e+1),e+=3,a;case 210:return a=i.getInt32(e+1),e+=5,a;case 217:return c=i.getUint8(e+1),e+=2,s(c);case 218:return c=i.getUint16(e+1),e+=3,s(c);case 219:return c=i.getUint32(e+1),e+=5,s(c);case 220:return c=i.getUint16(e+1),e+=3,o(c);case 221:return c=i.getUint32(e+1),e+=5,o(c);case 222:return c=i.getUint16(e+1),e+=3,r(c);case 223:return c=i.getUint32(e+1),e+=5,r(c)}throw new Error("Unknown type 0x"+l.toString(16))}return a()}function Tp(t,e,i,r){switch(t){case 1:return function(t,e){var i=t.length;e||(e=new Float32Array(i/4));for(var r=bp(e),n=bp(t),s=0,o=0,a=i/4;s<a;++s,o+=4)r.setFloat32(o,n.getFloat32(o),!0);return e}(e);case 2:return _p(e);case 3:return vp(e);case 4:return wp(e);case 5:return yp(Uint8Array,e);case 6:return Sp(wp(e),new Uint8Array(i));case 7:return Sp(wp(e));case 8:return function(t,e){return Cp(Sp(t),e)}(wp(e));case 9:return n=wp(e),s=wp(r)[0],Ap(Sp(n,xp(o)),s,o);case 10:return kp(vp(e),wp(r)[0]);case 11:return Ap(vp(e),wp(r)[0]);case 12:return Ip(vp(e),wp(r)[0]);case 13:return Ip(_p(e),wp(r)[0]);case 14:return Pp(vp(e));case 15:return Pp(_p(e))}var n,s,o}function Dp(t,e){var i=(e=e||{}).ignoreFields,r={};return gp.forEach((function(e){var n,s,o,a,c,l=!!i&&-1!==i.indexOf(e),u=t[e];l||void 0===u||(u instanceof Uint8Array?r[e]=Tp.apply(null,(s=bp(n=u),o=s.getInt32(0),a=s.getInt32(4),c=n.subarray(8,12),[o,n=n.subarray(12),a,c])):r[e]=u)})),r}const Bp={0:"i".charCodeAt(0),1:"s".charCodeAt(0),2:"h".charCodeAt(0),3:"e".charCodeAt(0),4:"g".charCodeAt(0),5:"b".charCodeAt(0),6:"t".charCodeAt(0),7:"l".charCodeAt(0),"-1":"".charCodeAt(0)};Nt.add("mmtf",class extends tp{get type(){return"mmtf"}get isBinary(){return!0}_parse(){let i,r,n,s,o;t.Debug&&Dt.time("MmtfParser._parse "+this.name);const a=this.structure,c=Dp(Mp(this.streamer.data));let l,u,h,d,m,f;if(["depositionDate","releaseDate","resolution","rFree","rWork","experimentalMethods"].forEach((function(t){void 0!==c[t]&&(a.header[t]=c[t])})),a.id=c.structureId,a.title=c.title,a.atomStore.addField("formalCharge",1,"int8"),this.firstModelOnly||this.asTrajectory){for(m=1,d=c.chainsPerModel[0],h=0,i=0,r=d;i<r;++i)h+=c.groupsPerChain[i];for(u=0,i=0,r=h;i<r;++i)o=c.groupList[c.groupTypeList[i]],u+=o.atomNameList.length;l=c.numBonds,f=[d]}else l=c.numBonds,u=c.numAtoms,h=c.numGroups,d=c.numChains,m=c.numModels,f=c.chainsPerModel;if(l+=h,this.asTrajectory)for(i=0,r=c.numModels;i<r;++i){const t=new Float32Array(3*u),e=u*i;for(n=0;n<u;++n){const i=3*n,r=n+e;t[i]=c.xCoordList[r],t[i+1]=c.yCoordList[r],t[i+2]=c.zCoordList[r]}a.frames.push(t)}const p=new Uint32Array(l),g=new Uint32Array(l),y=new Uint8Array(l),b=new Uint32Array(u),_=new Int8Array(u),x=new Uint32Array(h),v=new Uint32Array(h),w=new Uint32Array(h),A=new Uint16Array(d),S=new Uint32Array(d),C=new Uint32Array(d),P=new Uint32Array(m),I=new Uint32Array(m);let k=0;for(i=0,r=m;i<r;++i){const t=f[i];for(P[i]=k,I[i]=t,n=0;n<t;++n)A[n+k]=i;k+=t}const M=c.groupsPerChain;let T=0;for(i=0,r=d;i<r;++i){const t=M[i];for(S[i]=T,C[i]=t,n=0;n<t;++n)x[n+T]=i;T+=t}let D=0,B=0;for(i=0,r=h;i<r;++i){o=c.groupList[c.groupTypeList[i]];const t=o.atomNameList.length,e=o.formalChargeList,r=o.bondAtomList,a=o.bondOrderList;for(n=0,s=a.length;n<s;++n)p[B]=D+r[2*n],g[B]=D+r[2*n+1],y[B]=a[n],B+=1;for(v[i]=D,w[i]=t,n=0;n<t;++n)b[D]=i,_[D]=e[n],D+=1}const F=c.bondAtomList;if(F)for(c.bondOrderList&&y.set(c.bondOrderList,B),i=0,r=F.length;i<r;i+=2){const t=F[i],e=F[i+1];t<u&&e<u&&(p[B]=t,g[B]=e,B+=1)}a.bondStore.length=y.length,a.bondStore.count=B,a.bondStore.atomIndex1=p,a.bondStore.atomIndex2=g,a.bondStore.bondOrder=y,a.atomStore.length=u,a.atomStore.count=u,a.atomStore.residueIndex=b,a.atomStore.atomTypeId=new Uint16Array(u),a.atomStore.x=c.xCoordList.subarray(0,u),a.atomStore.y=c.yCoordList.subarray(0,u),a.atomStore.z=c.zCoordList.subarray(0,u),a.atomStore.serial=c.atomIdList.subarray(0,u),a.atomStore.bfactor=c.bFactorList.subarray(0,u),a.atomStore.altloc=c.altLocList.subarray(0,u),a.atomStore.occupancy=c.occupancyList.subarray(0,u),a.atomStore.formalCharge=_,a.residueStore.length=h,a.residueStore.count=h,a.residueStore.chainIndex=x,a.residueStore.residueTypeId=c.groupTypeList,a.residueStore.atomOffset=v,a.residueStore.atomCount=w,a.residueStore.resno=c.groupIdList.subarray(0,h),a.residueStore.sstruc=c.secStructList.subarray(0,h),a.residueStore.inscode=c.insCodeList.subarray(0,h),a.chainStore.length=d,a.chainStore.count=d,a.chainStore.entityIndex=new Uint16Array(d),a.chainStore.modelIndex=A,a.chainStore.residueOffset=S,a.chainStore.residueCount=C,a.chainStore.chainname=c.chainNameList.subarray(0,4*d),a.chainStore.chainid=c.chainIdList.subarray(0,4*d),a.modelStore.length=m,a.modelStore.count=m,a.modelStore.chainOffset=P,a.modelStore.chainCount=I;let E={};for(i=0,r=c.groupList.length;i<r;++i){const t=c.groupList[i],e=[];for(n=0,s=t.atomNameList.length;n<s;++n){const i=t.elementList[n].toUpperCase(),r=t.atomNameList[n];e.push(a.atomMap.add(r,i))}const r=t.chemCompType.toUpperCase(),o=Er.includes(r),l=t.bondOrderList.length,u=new Array(l),h=new Array(l);for(n=0;n<l;++n)u[n]=t.bondAtomList[2*n],h[n]=t.bondAtomList[2*n+1];const d={atomIndices1:u,atomIndices2:h,bondOrders:t.bondOrderList};E[i]=a.residueMap.add(t.groupName,e,o,r,d)}for(i=0,r=h;i<r;++i)a.residueStore.residueTypeId[i]=E[a.residueStore.residueTypeId[i]];for(i=0,r=a.atomStore.count;i<r;++i){const t=a.atomStore.residueIndex[i],e=a.residueMap.list[a.residueStore.residueTypeId[t]],r=a.residueStore.atomOffset[t];a.atomStore.atomTypeId[i]=e.atomTypeIdList[i-r]}if(c.secStructList){const t=c.secStructList.length;for(i=0,r=a.residueStore.count;i<r;++i){const e=Bp[a.residueStore.sstruc[i%t]];void 0!==e&&(a.residueStore.sstruc[i]=e)}}if(c.entityList&&c.entityList.forEach((function(t,e){a.entityList[e]=new ep(a,e,t.description,t.type,t.chainIndexList)})),c.bioAssemblyList&&c.bioAssemblyList.forEach((function(t,i){const r=i+1,n=new ko(""+r);a.biomolDict["BU"+r]=n;let s={};t.transformList.forEach((function(t){const i=(new e.Matrix4).fromArray(t.matrix).transpose(),r=t.chainIndexList.map((function(t){let e="";for(let i=0;i<4;++i){const r=c.chainNameList[4*t+i];if(!r)break;e+=String.fromCharCode(r)}return e})),o=s[r.toString()];o?o.matrixList.push(i):s[r.toString()]=n.addPart([i],r)}))})),c.ncsOperatorList){const t="NCS",i=new ko(t),r=i.addPart();c.ncsOperatorList.forEach((function(t){const i=(new e.Matrix4).fromArray(t).transpose();r.matrixList.push(i)})),r.matrixList.length>0&&(a.biomolDict[t]=i)}const O=c.unitCell;O&&Array.isArray(O)&&O[0]?a.unitcell=new rp({a:O[0],b:O[1],c:O[2],alpha:O[3],beta:O[4],gamma:O[5],spacegroup:c.spaceGroup}):a.unitcell=void 0,zo(a,!0),No(a,!0),a.finalizeAtoms(),a.finalizeBonds(),Vo(a),t.Debug&&Dt.timeEnd("MmtfParser._parse "+this.name)}});const Fp=/\s+/,Ep={1:1,2:2,3:3,am:1,ar:1,du:1,un:1,nc:0};Nt.add("mol2",class extends tp{get type(){return"mol2"}_parse(){t.Debug&&Dt.time("Mol2Parser._parse "+this.name);const e=this.structure,i=this.structureBuilder,r=this.firstModelOnly,n=this.asTrajectory,s=e.frames;let o,a,c=!1;const l=e.atomMap,u=e.atomStore;u.resize(Math.round(this.streamer.data.length/60)),u.addField("partialCharge",1,"float32");let h=0,d=0,m=0,f=-1,p=0,g=0;const y=e.getAtomProxy(),b=e.getAtomProxy();this.streamer.eachChunkOfLines((function(t){!function(t,_,x){for(let v=t;v<_;++v){const t=x[v].trim();if(""!==t&&"#"!==t[0])if("@"===t[0])"@<TRIPOS>MOLECULE"===t?(g=1,d=0,++f):"@<TRIPOS>ATOM"===t?(g=2,m=u.count,n&&(a=0,o=new Float32Array(3*p),s.push(o),f>0&&(c=!0))):g="@<TRIPOS>BOND"===t?3:0;else if(1===g){if(0===d)e.title=t,e.id=t;else if(1===d){const e=t.split(Fp);p=parseInt(e[0])}++d}else if(2===g){const e=t.split(Fp);if(r&&f>0)continue;const s=parseFloat(e[2]),d=parseFloat(e[3]),m=parseFloat(e[4]);if(n){const t=3*a;if(o[t+0]=s,o[t+1]=d,o[t+2]=m,a+=1,c)continue}const p=e[0],g=e[1],y=e[5].split(".")[0],b=e[6]?parseInt(e[6]):1,_=e[7]?e[7]:"",x=e[8]?parseFloat(e[8]):0;u.growIfFull(),u.atomTypeId[h]=l.add(g,y),u.x[h]=s,u.y[h]=d,u.z[h]=m,u.serial[h]=+p,u.partialCharge[h]=x,i.addAtom(f,"","",_,b,!0),h+=1}else if(3===g){if(r&&f>0)continue;if(n&&f>0)continue;const i=t.split(Fp);y.index=parseInt(i[1])-1+m,b.index=parseInt(i[2])-1+m;const s=Ep[i[3]];e.bondStore.addBond(y,b,s)}}}(0,t.length,t)})),i.finalize(),e.finalizeAtoms(),Oo(e),No(e,!0),zo(e,!0),e.finalizeBonds(),Ho(e),Bo(e),t.Debug&&Dt.timeEnd("Mol2Parser._parse "+this.name)}});Nt.add("pdbqt",class extends lp{get type(){return"pdbqt"}});Nt.add("pqr",class extends lp{get type(){return"pqr"}});const Op=/> +<(.+)>/;class $p extends tp{get type(){return"sdf"}_parse(){t.Debug&&Dt.time("SdfParser._parse "+this.name);const e=this.structure,i=this.structureBuilder,r=this.firstModelOnly,n=this.asTrajectory,s=this.streamer.peekLines(2);e.id=s[0].trim(),e.title=s[1].trim();const o=e.frames;let a,c,l=!1;const u=e.atomMap,h=e.atomStore;h.resize(Math.round(this.streamer.data.length/50)),h.addField("formalCharge",1,"int8");const d=e.getAtomProxy(),m=e.getAtomProxy();let f=0,p=0,g=0,y=0;const b=[];let _,x,v,w,A,S,C,P,I,k,M,T,D,B,F=!1,E={};e.extraData.sdf=b;let O=!1,$=!1,R=!1,L=[],N=[];const z=new Map;this.streamer.eachChunkOfLines((function(t){!function(t,s,V){for(let U=t;U<s;++U){const t=V[U];if(O&&t&&(L=t.substring(7).split(" "),N.length&&(L=[...N,...L],N=[]),"-"===L[L.length-1]))L.pop(),N=L;else{if("$$$$"===t.substr(0,4))p=-1,++g,y=h.count,b.push(E),E={},F=!1,O=!1;else if(3===p)O=t.indexOf(" V3000")>-1,O?z.clear():(x=parseInt(t.substr(0,3)),v=parseInt(t.substr(3,3)),w=4,A=w+x,S=A,C=S+v,n&&(c=0,a=new Float32Array(3*x),o.push(a),g>0&&(l=!0)));else if(O&&"COUNTS"===L[0])x=parseInt(L[1]),n&&(c=0,a=new Float32Array(3*x),o.push(a),g>0&&(l=!0));else if(O&&2==L.length)"ATOM"===L[1]?"BEGIN"===L[0]?$=!0:"END"===L[0]&&($=!1):"BOND"===L[1]&&("BEGIN"===L[0]?R=!0:"END"===L[0]&&(R=!1));else if($||!O&&p>=w&&p<A){if(r&&g>0)continue;let e=0;if(O){if(P=parseFloat(L[2]),I=parseFloat(L[3]),k=parseFloat(L[4]),T=L[1],D=parseInt(L[0]),z.set(D,f),M=T+D,L.length>6){let t=L.slice(6).find((t=>0===t.indexOf("CHG=")));t&&(e=parseInt(t.substring(4)))}}else P=parseFloat(t.substr(0,10)),I=parseFloat(t.substr(10,10)),k=parseFloat(t.substr(20,10)),T=t.substr(31,3).trim(),M=T+(f-y+1);if(n){const t=3*c;if(a[t+0]=P,a[t+1]=I,a[t+2]=k,c+=1,l)continue}h.growIfFull(),h.atomTypeId[f]=u.add(M,T),h.x[f]=P,h.y[f]=I,h.z[f]=k,h.serial[f]=O?D:f,h.formalCharge[f]=e,i.addAtom(g,"","","HET",1,!0),f+=1}else if(R||!O&&p>=S&&p<C){if(r&&g>0)continue;if(n&&g>0)continue;O?(d.index=z.get(parseInt(L[2])),m.index=z.get(parseInt(L[3])),B=parseInt(L[1])):(d.index=parseInt(t.substr(0,3))-1+y,m.index=parseInt(t.substr(3,3))-1+y,B=parseInt(t.substr(6,3))),e.bondStore.addBond(d,m,B)}else if("M  CHG"===t.substr(0,6)){const e=parseInt(t.substr(6,3));for(let i=0,r=10;i<e;++i,r+=8){const e=parseInt(t.substr(r,3))-1+y,i=parseInt(t.substr(r+4,3));h.formalCharge[e]=i}}else">"===t.charAt(0)&&(_=t.match(Op))?(F=_[1],E[F]=[]):!1!==F&&t&&E[F].push(t);++p}}}(0,t.length,t)})),i.finalize(),e.finalizeAtoms(),e.finalizeBonds(),Ho(e),t.Debug&&Dt.timeEnd("SdfParser._parse "+this.name)}_postProcess(){Ho(this.structure)}}Nt.add("sdf",$p),Nt.add("sd",$p),Nt.add("mol",$p);function Rp(t,e,i){return parseInt(t.substr(e,i).trim())}class Lp extends tp{get type(){return"prmtop"}_parse(){t.Debug&&Dt.time("PrmtopParser._parse "+this.name);const e=this.structure,i=this.structureBuilder,r=e.atomMap,n=e.atomStore;n.addField("partialCharge",1,"float32"),n.addField("radius",1,"float32");const s=[],o={},a=["NATOM","NTYPES","NBONH","MBONA","NTHETH","MTHETA","NPHIH","MPHIA","NHPARM","NPARM","NNB","NRES","NBONA","NTHETA","NPHIA","NUMBND","NUMANG","NPTRA","NATYP","NPHB","IFPERT","NBPER","NGPER","NDPER","MBPER","MGPER","MDPER","IFBOX","NMXRS","IFCAP","NUMEXTRA","NCOPY"];let c,l,u,h,d;a.forEach((t=>{o[t]=0}));let m,f,p,g,y,b=new Uint8Array(0);this.streamer.eachChunkOfLines((function(t){!function(t,e,i){for(let r=t;r<e;++r){const t=i[r],e=t.trim();if(e)if(t.startsWith("%FORMAT"));else if(t.startsWith("%FLAG")){const e=t.substr(5).trim();g=0,"TITLE"===e?p=0:"POINTERS"===e?p=1:"ATOM_NAME"===e?p=2:"CHARGE"===e?p=3:"MASS"===e?p=4:"RESIDUE_LABEL"===e?p=5:"RESIDUE_POINTER"===e?p=6:"BONDS_INC_HYDROGEN"===e?(y=0,p=7):"BONDS_WITHOUT_HYDROGEN"===e?(y=o.NBONH,p=8):p="RADII"===e?9:void 0}else if(0===p)s.push(e);else if(1===p){const e=Math.min(g+10,32);for(let i=0;g<e;++i,++g)o[a[g]]=parseInt(t.substr(8*i,8).trim());c=new Array(o.NATOM),l=new Float32Array(o.NATOM),u=new Float32Array(o.NATOM),n.resize(o.NATOM);const i=o.NBONH+o.MBONA;h=new Uint32Array(i),d=new Uint32Array(i),b=new Uint8Array(i),m=new Array(o.NRES),f=new Uint32Array(o.NRES)}else if(2===p){const e=Math.min(g+20,o.NATOM);for(let i=0;g<e;++i,++g)c[g]=t.substr(4*i,4).trim()}else if(3===p){const e=Math.min(g+5,o.NATOM);for(let i=0;g<e;++i,++g)l[g]=parseFloat(t.substr(16*i,16))/18.2223}else if(4===p);else if(5===p){const e=Math.min(g+20,o.NRES);for(let i=0;g<e;++i,++g)m[g]=t.substr(4*i,4).trim()}else if(6===p){const e=Math.min(g+10,o.NRES);for(let i=0;g<e;++i,++g)f[g]=Rp(t,8*i,8)}else if(7===p){const e=Math.min(g+10,3*o.NBONH);for(let i=0;g<e;++i,++g){const e=g%3;0===e&&(h[y]=Rp(t,8*i,8)/3),1===e&&(d[y]=Rp(t,8*i,8)/3,b[y]=1,++y)}}else if(8===p){const e=Math.min(g+10,3*o.MBONA);for(let i=0;g<e;++i,++g){const e=g%3;0===e&&(h[y]=Rp(t,8*i,8)/3),1===e&&(d[y]=Rp(t,8*i,8)/3,b[y]=1,++y)}}else if(9===p){const e=Math.min(g+5,o.NATOM);for(let i=0;g<e;++i,++g)u[g]=parseFloat(t.substr(16*i,16))}}}(0,t.length,t)})),e.title=s.join(" ");const _=o.NATOM;let x=0,v=m[0],w=1;for(let t=0;t<_;++t)t+1===f[x+1]&&(++x,v=m[x],w=x+1),n.atomTypeId[t]=r.add(c[t]),n.serial[t]=t+1,i.addAtom(0,"","",v,w,!1);n.partialCharge.set(l),n.radius.set(u),e.bondStore.length=b.length,e.bondStore.count=b.length,e.bondStore.atomIndex1=h,e.bondStore.atomIndex2=d,e.bondStore.bondOrder=b,i.finalize(),e.finalizeAtoms(),e.finalizeBonds(),No(e,!0),zo(e,!0,!0),Oo(e,!0),Ho(e),t.Debug&&Dt.timeEnd("PrmtopParser._parse "+this.name)}}Nt.add("prmtop",Lp),Nt.add("parm7",Lp);const Np=/\s+/,zp=/(^\*|REMARK)*/;Nt.add("psf",class extends tp{get type(){return"psf"}_parse(){t.Debug&&Dt.time("PsfParser._parse "+this.name);const e=this.structure,i=this.structureBuilder,r=e.atomMap,n=e.atomStore;n.addField("partialCharge",1,"float32");const s=[];let o,a,c,l,u,h,d=0,m=0,f=0;this.streamer.eachChunkOfLines((function(t){!function(t,e,p){for(let g=t;g<e;++g){const t=p[g].trim();if(t)if(2===o){const e=t.split(Np),s=parseInt(e[0]),o=e[1],l=parseInt(e[2]),u=e[3],h=e[4],f=parseFloat(e[6]);o!==c&&(a=Eo(m),++m),n.growIfFull(),n.atomTypeId[d]=r.add(h),n.serial[d]=s,n.partialCharge[d]=f,i.addAtom(0,a,a,u,l,!1),d+=1,c=o}else if(3===o){const e=t.split(Np);for(let t=0,i=e.length;t<i;t+=2)l[f]=parseInt(e[t])-1,u[f]=parseInt(e[t+1])-1,h[f]=1,f+=1}else if(1===o)s.push(t.replace(zp,"").trim());else if(4===o);else if(5===o);else if(6===o);else if(t.includes("!NATOM")){o=2;const e=parseInt(t.split(Np)[0]);n.resize(e)}else if(t.includes("!NBOND")){o=3;const e=parseInt(t.split(Np)[0]);l=new Uint32Array(e),u=new Uint32Array(e),h=new Uint8Array(e)}else t.includes("!NTITLE")?o=1:t.includes("!NTHETA")?o=4:t.includes("!NPHI")?o=5:t.includes("!NIMPHI")&&(o=6);else o=void 0}}(0,t.length,t)})),e.title=s.join(" "),e.bondStore.length=h.length,e.bondStore.count=f,e.bondStore.atomIndex1=l,e.bondStore.atomIndex2=u,e.bondStore.bondOrder=h,i.finalize(),e.finalizeAtoms(),e.finalizeBonds(),No(e,!0),zo(e,!0,!0),Ho(e),t.Debug&&Dt.timeEnd("PsfParser._parse "+this.name)}});const Vp=/\[ (.+) \]/,Up=/\s+/;Nt.add("top",class extends tp{get type(){return"top"}_parse(){t.Debug&&Dt.time("TopParser._parse "+this.name);const e=this.structure,i=this.structureBuilder,r=e.atomMap,n=e.bondStore,s=e.atomStore;s.addField("partialCharge",1,"float32");const o=[],a={};let c,l;this.streamer.eachChunkOfLines((function(t){!function(t,i,r){for(let n=t;n<i;++n){const t=r[n];let i=t.trim();if(!i||"*"===i[0]||";"===i[0])continue;if(i.startsWith("#include"))throw new Error("TopParser: #include statements not allowed");const s=t.match(Vp);if(null!==s){const t=s[1];"moleculetype"===t?(l=2,c={atoms:[],bonds:[]}):l="atoms"===t?3:"bonds"===t?4:"system"===t?0:"molecules"===t?1:void 0;continue}const u=i.indexOf(";");if(-1!==u&&(i=i.substring(0,u).trim()),2===l){const t=i.split(Up)[0];a[t]=c}else if(3===l){const t=i.split(Up);c.atoms.push([parseInt(t[2]),t[3],t[4],parseFloat(t[6])])}else if(4===l){const t=i.split(Up);c.bonds.push([parseInt(t[0]),parseInt(t[1])])}else if(0===l)e.title=i;else if(1===l){const t=i.split(Up);o.push([t[0],parseInt(t[1])])}}}(0,t.length,t)}));let u=0,h=0;o.forEach((function(t){const[e,i]=t,r=a[e];u+=i*r.atoms.length,h+=i*r.bonds.length})),s.resize(u),n.resize(h);let d,m=0,f=0,p=0,g=0,y=0,b=0;o.forEach((function(t){const[e,o]=t,c=a[e],l=Eo(g);for(let t=0;t<o;++t){d=-1;const t=Zr.includes(e)?l:Eo(p);c.atoms.forEach((function(e){const[n,o,a,c]=e;n!==d&&++f,s.atomTypeId[m]=r.add(a),s.serial[m]=m+1,s.partialCharge[m]=c,i.addAtom(0,l,t,o,f+1,!1),++m,d=n})),c.bonds.forEach((function(t){n.atomIndex1[y]=b+t[0]-1,n.atomIndex2[y]=b+t[1]-1,++y})),++p,b+=c.atoms.length}++g})),n.count=h,i.finalize(),e.finalizeAtoms(),e.finalizeBonds(),No(e,!0),zo(e,!0,!0),Ho(e),t.Debug&&Dt.timeEnd("TopParser._parse "+this.name)}});class jp extends Jf{constructor(t,e){super(t,e),this.frames=new rc(this.name,this.path)}get type(){return"trajectory"}get __objName(){return"frames"}}function Gp(t,e){if(t)throw new TypeError("Not a valid NetCDF v3.x file: "+e)}function Hp(t){t.offset%4!=0&&t.skip(4-t.offset%4)}function qp(t){const e=t.readUint32(),i=t.readChars(e);return Hp(t),i}Nt.add("dcd",class extends jp{get type(){return"dcd"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("DcdParser._parse "+this.name);const e=w(this.streamer.data),i=new DataView(e),r=this.frames,n=r.coordinates,s=r.boxes,o={};let a=0;const c=new Int32Array(e,0,23),l=c[0]!==i.getInt32(0);if(84!==c[0]){const t=e.byteLength;for(let e=0;e<t;e+=4)i.setFloat32(e,i.getFloat32(e),!0)}84!==c[0]&&Dt.error("dcd bad format, header block start");"CORD"!==String.fromCharCode(i.getUint8(4),i.getUint8(5),i.getUint8(6),i.getUint8(7))&&Dt.error("dcd bad format, format string");let u=!1,h=!1,d=!1;0!==c[22]&&(u=!0,0!==c[12]&&(h=!0),1===c[13]&&(d=!0)),o.NSET=c[2],o.ISTART=c[3],o.NSAVC=c[4],o.NAMNF=c[10],o.DELTA=u?i.getFloat32(44,l):i.getFloat64(44,l),84!==c[22]&&Dt.error("dcd bad format, header block end"),a=a+84+8;const m=i.getInt32(a,l),f=a+1;if((m-4)%80!=0&&Dt.error("dcd bad format, title block start"),o.TITLE=_(new Uint8Array(e,f,m)),i.getInt32(f+m+4-1,l)!==m&&Dt.error("dcd bad format, title block end"),a=a+m+8,4!==i.getInt32(a,l)&&Dt.error("dcd bad format, natom block start"),o.NATOM=i.getInt32(a+4,l),4!==i.getInt32(a+8,l)&&Dt.error("dcd bad format, natom block end"),a=a+4+8,o.NAMNF>0)return void Dt.error("dcd format with fixed atoms unsupported, aborting");const p=o.NATOM,g=4*p;for(let t=0,r=o.NSET;t<r;++t){if(h){a+=4;const t=new Float32Array(9);t[0]=i.getFloat64(a,l),t[4]=i.getFloat64(a+16,l),t[8]=i.getFloat64(a+40,l),s.push(t),a+=48,a+=4}const r=new Float32Array(3*p);for(let n=0;n<3;++n){i.getInt32(a,l)!==g&&Dt.error("dcd bad format, coord block start",t,n),a+=4;const s=new Float32Array(e,a,p);for(let t=0;t<p;++t)r[3*t+n]=s[t];a+=g,i.getInt32(a,l)!==g&&Dt.error("dcd bad format, coord block end",t,n),a+=4}if(n.push(r),d){a+=4+i.getInt32(a,l)+4}}o.DELTA&&(r.deltaTime=20.45482949774598*o.DELTA),o.ISTART>=1&&(r.timeOffset=(o.ISTART-1)*r.deltaTime),t.Debug&&Dt.timeEnd("DcdParser._parse "+this.name)}});const Wp={BYTE:1,CHAR:2,SHORT:3,INT:4,FLOAT:5,DOUBLE:6};function Xp(t){switch(Number(t)){case Wp.BYTE:return"byte";case Wp.CHAR:return"char";case Wp.SHORT:return"short";case Wp.INT:return"int";case Wp.FLOAT:return"float";case Wp.DOUBLE:return"double";default:return"undefined"}}function Yp(t){switch(Number(t)){case Wp.BYTE:case Wp.CHAR:return 1;case Wp.SHORT:return 2;case Wp.INT:case Wp.FLOAT:return 4;case Wp.DOUBLE:return 8;default:return-1}}function Kp(t){switch(String(t)){case"byte":return Wp.BYTE;case"char":return Wp.CHAR;case"short":return Wp.SHORT;case"int":return Wp.INT;case"float":return Wp.FLOAT;case"double":return Wp.DOUBLE;default:return-1}}function Zp(t,e){if(1!==t){const i=new Array(t);for(let r=0;r<t;r++)i[r]=e();return i}return e()}function Qp(t,e,i){switch(e){case Wp.BYTE:return t.readBytes(i);case Wp.CHAR:return function(t){if(0===t.charCodeAt(t.length-1))return t.substring(0,t.length-1);return t}(t.readChars(i));case Wp.SHORT:return Zp(i,t.readInt16.bind(t));case Wp.INT:return Zp(i,t.readInt32.bind(t));case Wp.FLOAT:return Zp(i,t.readFloat32.bind(t));case Wp.DOUBLE:return Zp(i,t.readFloat64.bind(t));default:return void Gp(!0,"non valid type "+e)}}const Jp=0,tg=10,eg=11,ig=12;function rg(t,e){const i={recordDimension:{length:t.readUint32()}};i.version=e;const r=function(t){let e,i,r;const n=t.readUint32();if(n===Jp)return Gp(t.readUint32()!==Jp,"wrong empty tag for list of dimensions"),[];{Gp(n!==tg,"wrong tag for list of dimensions");const s=t.readUint32();e=new Array(s);for(let n=0;n<s;n++){const s=qp(t),o=t.readUint32();0===o&&(i=n,r=s),e[n]={name:s,size:o}}return{dimensions:e,recordId:i,recordName:r}}}(t);i.recordDimension.id=r.recordId,i.recordDimension.name=r.recordName,i.dimensions=r.dimensions,i.globalAttributes=ng(t);const n=function(t,e,i){const r=t.readUint32();let n,s=0;if(r===Jp)return Gp(t.readUint32()!==Jp,"wrong empty tag for list of variables"),[];{Gp(r!==eg,"wrong tag for list of variables");const o=t.readUint32();n=new Array(o);for(let r=0;r<o;r++){const o=qp(t),a=t.readUint32(),c=new Array(a);for(let e=0;e<a;e++)c[e]=t.readUint32();const l=ng(t),u=t.readUint32();Gp(u<1&&u>6,"non valid type "+u);const h=t.readUint32();let d=t.readUint32();2===i&&(Gp(d>0,"offsets larger than 4GB not supported"),d=t.readUint32()),c[0]===e&&(s+=h),n[r]={name:o,dimensions:c,attributes:l,type:Xp(u),size:h,offset:d,record:c[0]===e}}}return{variables:n,recordStep:s}}(t,r.recordId,e);return i.variables=n.variables,i.recordDimension.recordStep=n.recordStep,i}function ng(t){let e;const i=t.readUint32();if(i===Jp)return Gp(t.readUint32()!==Jp,"wrong empty tag for list of attributes"),[];{Gp(i!==ig,"wrong tag for list of attributes");const r=t.readUint32();e=new Array(r);for(let i=0;i<r;i++){const r=qp(t),n=t.readUint32();Gp(n<1||n>6,"non valid type "+n);const s=t.readUint32(),o=Qp(t,n,s);Hp(t),e[i]={name:r,type:Xp(n),value:o}}}return e}class sg{constructor(t){const e=new re(t);e.setBigEndian(),Gp("CDF"!==e.readChars(3),"should start with CDF");const i=e.readByte();Gp(i>2,"unknown version"),this.header=rg(e,i),this.buffer=e}get version(){return 1===this.header.version?"classic format":"64-bit offset format"}get recordDimension(){return this.header.recordDimension}get dimensions(){return this.header.dimensions}get globalAttributes(){return this.header.globalAttributes}get variables(){return this.header.variables}hasDataVariable(t){return-1!==this.header.variables.findIndex((function(e){return e.name===t}))}getDataVariable(t){let e;return e="string"==typeof t?this.header.variables.find((function(e){return e.name===t})):t,Gp(void 0===e,"variable not found"),this.buffer.seek(e.offset),e.record?function(t,e,i){const r=Kp(e.type),n=e.size?e.size/Yp(r):1,s=i.length,o=new Array(s),a=i.recordStep;for(let e=0;e<s;e++){const i=t.offset;o[e]=Qp(t,r,n),t.seek(i+a)}return o}(this.buffer,e,this.header.recordDimension):function(t,e){const i=Kp(e.type),r=e.size/Yp(i),n=new Array(r);for(let e=0;e<r;e++)n[e]=Qp(t,i,1);return n}(this.buffer,e)}}class og extends jp{get type(){return"nctraj"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("NctrajParser._parse "+this.name);const e=new sg(this.streamer.data),i=this.frames,r=i.coordinates,n=i.boxes,s=i.times;e.getDataVariable("coordinates").forEach((function(t){r.push(new Float32Array(t))})),e.hasDataVariable("cell_lengths")&&e.getDataVariable("cell_lengths").forEach((function(t){n.push(new Float32Array(t))})),e.hasDataVariable("time")&&e.getDataVariable("time").forEach((function(t){s.push(t)})),s.length>=1&&(i.timeOffset=s[0]),s.length>=2&&(i.deltaTime=s[1]-s[0]),t.Debug&&Dt.timeEnd("NctrajParser._parse "+this.name)}}Nt.add("nctraj",og),Nt.add("ncdf",og),Nt.add("nc",og);Nt.add("trr",class extends jp{get type(){return"trr"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("TrrParser._parse "+this.name);const e=w(this.streamer.data),i=new DataView(e),r=this.frames,n=r.coordinates,s=r.boxes,o=r.times;let a=0;for(;;){a+=8;const t=i.getInt32(a);a+=4,a+=t;const r=i.getInt32(a+8),c=i.getInt32(a+12),l=i.getInt32(a+16),u=i.getInt32(a+28),h=i.getInt32(a+32),d=i.getInt32(a+36),m=i.getInt32(a+40);a+=52;const f=r/9,p=3*m;if(8===f?o.push(i.getFloat64(a)):o.push(i.getFloat32(a)),a+=2*f,r){const t=new Float32Array(9);if(8===f)for(let e=0;e<9;++e)t[e]=10*i.getFloat64(a),a+=8;else for(let e=0;e<9;++e)t[e]=10*i.getFloat32(a),a+=4;s.push(t)}if(a+=c,a+=l,u){let t;if(8===f){t=new Float32Array(p);for(let e=0;e<p;++e)t[e]=10*i.getFloat64(a),a+=8}else{const i=new Uint32Array(e,a,p);for(let t=0;t<p;++t){const e=i[t];i[t]=(255&e)<<24|(65280&e)<<8|e>>8&65280|e>>24&255}t=new Float32Array(e,a,p);for(let e=0;e<p;++e)t[e]*=10,a+=4}n.push(t)}if(a+=h,a+=d,a>=e.byteLength)break}o.length>=1&&(r.timeOffset=o[0]),o.length>=2&&(r.deltaTime=o[1]-o[0]),t.Debug&&Dt.timeEnd("TrrParser._parse "+this.name)}});const ag=new Uint32Array([0,0,0,0,0,0,0,0,0,8,10,12,16,20,25,32,40,50,64,80,101,128,161,203,256,322,406,512,645,812,1024,1290,1625,2048,2580,3250,4096,5060,6501,8192,10321,13003,16384,20642,26007,32768,41285,52015,65536,82570,104031,131072,165140,208063,262144,330280,416127,524287,660561,832255,1048576,1321122,1664510,2097152,2642245,3329021,4194304,5284491,6658042,8388607,10568983,13316085,16777216]);function cg(t){let e=1,i=0;for(;t>=e&&i<32;)i++,e<<=1;return i}const lg=new Uint8Array(32);function ug(t,e){let i=1,r=0;lg[0]=1;for(let r=0;r<t;r++){let t,n=0;for(t=0;t<i;t++)n+=lg[t]*e[r],lg[t]=255&n,n>>=8;for(;0!==n;)lg[t++]=255&n,n>>=8;i=t}let n=1;for(i--;lg[i]>=n;)r++,n*=2;return r+8*i}function hg(t,e,i,r){const n=(1<<i)-1;let s=r[1],o=r[2],a=t[0],c=0;for(;i>=8;)o=o<<8|e[a++],c|=o>>s<<i-8,i-=8;return i>0&&(s<i&&(s+=8,o=o<<8|e[a++]),s-=i,c|=o>>s&(1<<i)-1),c&=n,t[0]=a,t[1]=s,t[2]=o,c}const dg=new Int32Array(32);function mg(t,e,i,r,n,s,o){let a=0;for(dg[1]=0,dg[2]=0,dg[3]=0;r>8;)dg[a++]=hg(t,e,8,o),r-=8;r>0&&(dg[a++]=hg(t,e,r,o));for(let t=i-1;t>0;t--){let e=0;for(let i=a-1;i>=0;i--){e=e<<8|dg[i];const r=e/n[t]|0;dg[i]=r,e-=r*n[t]}s[t]=e}s[0]=dg[0]|dg[1]<<8|dg[2]<<16|dg[3]<<24}Nt.add("xtc",class extends jp{get type(){return"xtc"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("XtcParser._parse "+this.name);const e=w(this.streamer.data),i=new DataView(e),r=this.frames,n=r.coordinates,s=r.boxes,o=r.times,a=new Int32Array(6),c=new Int32Array(3),l=new Int32Array(3),u=new Uint32Array(3),h=new Float32Array(3),d=new Float32Array(3);let m=0;const f=new Int32Array(3),p=new Uint32Array(f.buffer);for(;;){let t;const r=i.getInt32(m+4);m+=12;const g=3*r;o.push(i.getFloat32(m)),m+=4;const y=new Float32Array(9);for(let t=0;t<9;++t)y[t]=10*i.getFloat32(m),m+=4;if(s.push(y),r<=9){t=new Float32Array(r);for(let e=0;e<r;++e)t[e]=i.getFloat32(m),m+=4}else{f[0]=f[1]=f[2]=0,c[0]=c[1]=c[2]=0,u[0]=u[1]=u[2]=0,l[0]=l[1]=l[2]=0,h[0]=h[1]=h[2]=0,d[0]=d[1]=d[2]=0,t=new Float32Array(g);let r=0;const n=i.getInt32(m);m+=4;const s=i.getFloat32(m);let o;m+=4,a[0]=i.getInt32(m),a[1]=i.getInt32(m+4),a[2]=i.getInt32(m+8),a[3]=i.getInt32(m+12),a[4]=i.getInt32(m+16),a[5]=i.getInt32(m+20),c[0]=a[3]-a[0]+1,c[1]=a[4]-a[1]+1,c[2]=a[5]-a[2]+1,m+=24,(c[0]|c[1]|c[2])>16777215?(l[0]=cg(c[0]),l[1]=cg(c[1]),l[2]=cg(c[2]),o=0):o=ug(3,c);let y=i.getInt32(m);m+=4;let b=y-1;b=9>b?9:b;let _=ag[b]/2|0,x=ag[y]/2|0;u[0]=u[1]=u[2]=ag[y];let v=4*Math.ceil(i.getInt32(m)/4);m+=4;const w=1/s;let A=0,S=0;const C=new Uint8Array(e,m);for(h[0]=h[1]=h[2]=0;S<n;){0===o?(h[0]=hg(f,C,l[0],p),h[1]=hg(f,C,l[1],p),h[2]=hg(f,C,l[2],p)):mg(f,C,3,o,c,h,p),S++,h[0]+=a[0],h[1]+=a[1],h[2]+=a[2],d[0]=h[0],d[1]=h[1],d[2]=h[2];let e=0;if(1===hg(f,C,1,p)&&(A=hg(f,C,5,p),e=A%3,A-=e,e--),A>0){h[0]=h[1]=h[2]=0;for(let e=0;e<A;e+=3){if(mg(f,C,3,y,u,h,p),S++,h[0]+=d[0]-x,h[1]+=d[1]-x,h[2]+=d[2]-x,0===e){let e=h[0];h[0]=d[0],d[0]=e,e=h[1],h[1]=d[1],d[1]=e,e=h[2],h[2]=d[2],d[2]=e,t[r++]=d[0]*w,t[r++]=d[1]*w,t[r++]=d[2]*w}else d[0]=h[0],d[1]=h[1],d[2]=h[2];t[r++]=h[0]*w,t[r++]=h[1]*w,t[r++]=h[2]*w}}else t[r++]=h[0]*w,t[r++]=h[1]*w,t[r++]=h[2]*w;if(y+=e,e<0?(x=_,_=y>9?ag[y-1]/2|0:0):e>0&&(_=x,x=ag[y]/2|0),u[0]=u[1]=u[2]=ag[y],0===u[0]||0===u[1]||0===u[2])return void console.error("(xdrfile error) Undefined error.")}m+=v}for(let e=0;e<g;e++)t[e]*=10;if(n.push(t),m>=e.byteLength)break}o.length>=1&&(r.timeOffset=o[0]),o.length>=2&&(r.deltaTime=o[1]-o[0]),t.Debug&&Dt.timeEnd("XtcParser._parse "+this.name)}});class fg extends Jf{constructor(t,e){const i=e||{};super(t,i),this.volume=new Cs(this.name,this.path),this.voxelSize=l(i.voxelSize,1)}get type(){return"volume"}get __objName(){return"volume"}_afterParse(){this.volume.setMatrix(this.getMatrix()),super._afterParse()}getMatrix(){return new e.Matrix4}}const pg=/\s+/,gg=/-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/g,yg=.529177210859;class bg extends fg{get type(){return"cube"}_parse(){t.Debug&&Dt.time("CubeParser._parse "+this.name);const i=this.volume,r=this.streamer.peekLines(6),n={},s=yg*this.voxelSize;function o(t,e){var i=r[t].trim().split(pg)[e];return parseFloat(i)}n.atomCount=Math.abs(o(2,0)),n.originX=o(2,1)*yg,n.originY=o(2,2)*yg,n.originZ=o(2,3)*yg,n.NVX=o(3,0),n.NVY=o(4,0),n.NVZ=o(5,0),n.basisX=new e.Vector3(o(3,1),o(3,2),o(3,3)).multiplyScalar(s),n.basisY=new e.Vector3(o(4,1),o(4,2),o(4,3)).multiplyScalar(s),n.basisZ=new e.Vector3(o(5,1),o(5,2),o(5,3)).multiplyScalar(s);const a=new Float32Array(n.NVX*n.NVY*n.NVZ);let c=0,l=0;const u=o(2,0)>0?0:1;this.streamer.eachChunkOfLines((function(t){!function(t,e,i){for(let r=t;r<e;++r){const t=i[r].trim();if(""!==t&&l>=n.atomCount+6+u){const e=t.match(gg);for(let t=0,i=e.length;t<i;++t)a[c]=parseFloat(e[t]),++c}++l}}(0,t.length,t)})),i.header=n,i.setData(a,n.NVZ,n.NVY,n.NVX),t.Debug&&Dt.timeEnd("CubeParser._parse "+this.name)}getMatrix(){const t=this.volume.header,i=new e.Matrix4;return i.multiply((new e.Matrix4).makeTranslation(t.originX,t.originY,t.originZ)),i.multiply((new e.Matrix4).makeBasis(t.basisZ,t.basisY,t.basisX)),i}}Nt.add("cub",bg),Nt.add("cube",bg);class _g extends fg{get type(){return"dsn6"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("Dsn6Parser._parse "+this.name);const e=this.volume,i={};let r,n;const s=w(this.streamer.data),o=new Int16Array(s),a=new Uint8Array(s),c=String.fromCharCode.apply(null,a.subarray(0,512));if(c.startsWith(":-)"))i.xStart=parseInt(c.substr(10,5)),i.yStart=parseInt(c.substr(15,5)),i.zStart=parseInt(c.substr(20,5)),i.xExtent=parseInt(c.substr(32,5)),i.yExtent=parseInt(c.substr(38,5)),i.zExtent=parseInt(c.substr(42,5)),i.xRate=parseInt(c.substr(52,5)),i.yRate=parseInt(c.substr(58,5)),i.zRate=parseInt(c.substr(62,5)),i.xlen=parseFloat(c.substr(73,10))*this.voxelSize,i.ylen=parseFloat(c.substr(83,10))*this.voxelSize,i.zlen=parseFloat(c.substr(93,10))*this.voxelSize,i.alpha=parseFloat(c.substr(103,10)),i.beta=parseFloat(c.substr(113,10)),i.gamma=parseFloat(c.substr(123,10)),r=parseFloat(c.substr(138,12))/100,n=parseInt(c.substr(155,8)),i.sigma=100*parseFloat(c.substr(170,12));else{if(100!==o[18])for(let t=0,e=o.length;t<e;++t){const e=o[t];o[t]=(255&e)<<8|e>>8&255}i.xStart=o[0],i.yStart=o[1],i.zStart=o[2],i.xExtent=o[3],i.yExtent=o[4],i.zExtent=o[5],i.xRate=o[6],i.yRate=o[7],i.zRate=o[8];const t=1/o[17],e=t*this.voxelSize;i.xlen=o[9]*e,i.ylen=o[10]*e,i.zlen=o[11]*e,i.alpha=o[12]*t,i.beta=o[13]*t,i.gamma=o[14]*t,r=o[15]/100,n=o[16],i.gamma=o[14]*t}e.header=i,t.Debug&&Dt.log(i,r,n);const l=new Float32Array(i.xExtent*i.yExtent*i.zExtent);let u=512;const h=Math.ceil(i.xExtent/8),d=Math.ceil(i.yExtent/8),m=Math.ceil(i.zExtent/8);for(var f=0;f<m;++f)for(var p=0;p<d;++p)for(var g=0;g<h;++g)for(var y=0;y<8;++y)for(var b=8*f+y,_=0;_<8;++_)for(var x=8*p+_,v=0;v<8;++v){var A=8*g+v;if(!(A<i.xExtent&&x<i.yExtent&&b<i.zExtent)){u+=8-v;break}l[(A*i.yExtent+x)*i.zExtent+b]=(a[u]-n)/r,++u}e.setData(l,i.zExtent,i.yExtent,i.xExtent),i.sigma&&e.setStats(void 0,void 0,void 0,i.sigma),t.Debug&&Dt.timeEnd("Dsn6Parser._parse "+this.name)}getMatrix(){const t=this.volume.header,i=[t.xlen,0,0],r=[t.ylen*Math.cos(Math.PI/180*t.gamma),t.ylen*Math.sin(Math.PI/180*t.gamma),0],n=[t.zlen*Math.cos(Math.PI/180*t.beta),t.zlen*(Math.cos(Math.PI/180*t.alpha)-Math.cos(Math.PI/180*t.gamma)*Math.cos(Math.PI/180*t.beta))/Math.sin(Math.PI/180*t.gamma),0];n[2]=Math.sqrt(t.zlen*t.zlen*Math.sin(Math.PI/180*t.beta)*Math.sin(Math.PI/180*t.beta)-n[1]*n[1]);const s=[[],i,r,n],o=[0,t.xRate,t.yRate,t.zRate],a=[0,1,2,3],c=new e.Matrix4;return c.set(s[a[1]][0]/o[a[1]],s[a[2]][0]/o[a[2]],s[a[3]][0]/o[a[3]],0,s[a[1]][1]/o[a[1]],s[a[2]][1]/o[a[2]],s[a[3]][1]/o[a[3]],0,s[a[1]][2]/o[a[1]],s[a[2]][2]/o[a[2]],s[a[3]][2]/o[a[3]],0,0,0,0,1),c.multiply((new e.Matrix4).makeRotationY(T(90))),c.multiply((new e.Matrix4).makeTranslation(-t.zStart,t.yStart,t.xStart)),c.multiply((new e.Matrix4).makeScale(-1,1,1)),c}}Nt.add("dsn6",_g),Nt.add("brix",_g);const xg=/\s+/;class vg extends fg{get type(){return"dx"}_parse(){t.Debug&&Dt.time("DxParser._parse "+this.name);const e=this.volume,i=this.streamer.peekLines(30),r=this.parseHeaderLines(i),n=this.volume.header,s=r.dataLineStart,o=n.nx*n.ny*n.nz,a=new Float32Array(o);let c=0,l=0;this.streamer.eachChunkOfLines((function(t){!function(t,e,i){for(let r=t;r<e;++r){if(c<o&&l>s){const t=i[r].trim();if(""!==t){const e=t.split(xg);for(let t=0,i=e.length;t<i;++t)a[c]=parseFloat(e[t]),++c}}++l}}(0,t.length,t)})),e.setData(a,n.nz,n.ny,n.nx),t.Debug&&Dt.timeEnd("DxParser._parse "+this.name)}parseHeaderLines(t){const e={},i=t.length;let r=0,n=0,s=0;for(let o=0;o<i;++o){let i;const a=t[o];if(a.startsWith("object 1"))i=a.split(xg),e.nx=parseInt(i[5]),e.ny=parseInt(i[6]),e.nz=parseInt(i[7]);else if(a.startsWith("origin"))i=a.split(xg),e.xmin=parseFloat(i[1]),e.ymin=parseFloat(i[2]),e.zmin=parseFloat(i[3]);else if(a.startsWith("delta"))i=a.split(xg),0===s?e.hx=parseFloat(i[1])*this.voxelSize:1===s?e.hy=parseFloat(i[2])*this.voxelSize:2===s&&(e.hz=parseFloat(i[3])*this.voxelSize),s+=1;else if(a.startsWith("object 3")){r=o,n+=a.length+1;break}n+=a.length+1}return this.volume.header=e,{dataLineStart:r,headerByteCount:n}}getMatrix(){const t=this.volume.header,i=new e.Matrix4;return i.multiply((new e.Matrix4).makeRotationY(T(90))),i.multiply((new e.Matrix4).makeTranslation(-t.zmin,t.ymin,t.xmin)),i.multiply((new e.Matrix4).makeScale(-t.hz,t.hy,t.hx)),i}}Nt.add("dx",vg);Nt.add("dxbin",class extends vg{get type(){return"dxbin"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("DxbinParser._parse "+this.name);const e=w(this.streamer.data),i=function(t,e=10485760,i="\n"){let r="",n=[];for(let s=0;s<t.length;s+=e){const o=_(t.subarray(s,s+e)),a=o.lastIndexOf(i);if(-1===a)r+=o;else{const t=r+o.substr(0,a);n=n.concat(t.split(i)),r=a===o.length-i.length?"":o.substr(a+i.length)}}return""!==r&&n.push(r),n}(new Uint8Array(e,0,1e3)),r=this.parseHeaderLines(i),n=this.volume.header,s=r.headerByteCount,o=n.nx*n.ny*n.nz,a=new DataView(e),c=new Float32Array(o);for(let t=0;t<o;++t)c[t]=a.getFloat64(8*t+s,!0);this.volume.setData(c,n.nz,n.ny,n.nx),t.Debug&&Dt.timeEnd("DxbinParser._parse "+this.name)}});class wg extends fg{get type(){return"mrc"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("MrcParser._parse "+this.name);const e=this.volume,i={},r=w(this.streamer.data),n=new Int32Array(r,0,56),s=new Float32Array(r,0,56),o=new DataView(r);if(i.MAP=String.fromCharCode(o.getUint8(208),o.getUint8(209),o.getUint8(210),o.getUint8(211)),i.MACHST=[o.getUint8(212),o.getUint8(213)],17===i.MACHST[0]&&17===i.MACHST[1]){const t=r.byteLength;for(let e=0;e<t;e+=4)o.setFloat32(e,o.getFloat32(e),!0)}let a;if(i.NX=n[0],i.NY=n[1],i.NZ=n[2],i.MODE=n[3],i.NXSTART=n[4],i.NYSTART=n[5],i.NZSTART=n[6],i.MX=n[7],i.MY=n[8],i.MZ=n[9],i.xlen=s[10]*this.voxelSize,i.ylen=s[11]*this.voxelSize,i.zlen=s[12]*this.voxelSize,i.alpha=s[13],i.beta=s[14],i.gamma=s[15],i.MAPC=n[16],i.MAPR=n[17],i.MAPS=n[18],i.DMIN=s[19],i.DMAX=s[20],i.DMEAN=s[21],i.ISPG=n[22],i.NSYMBT=n[23],i.LSKFLG=n[24],i.originX=s[49],i.originY=s[50],i.originZ=s[51],i.ARMS=s[54],e.header=i,2===i.MODE)a=new Float32Array(r,1024+i.NSYMBT,i.NX*i.NY*i.NZ);else if(0===i.MODE){if(a=new Float32Array(new Int8Array(r,1024+i.NSYMBT,i.NX*i.NY*i.NZ)),-128===n[39]&&127===n[40]){const t=(i.DMAX-i.DMIN)/255,e=.5*(i.DMIN+i.DMAX+t);for(let i=0,r=a.length;i<r;++i)a[i]=t*a[i]+e}}else Dt.error("MrcParser unknown mode",i.MODE);e.setData(a,i.NX,i.NY,i.NZ),0!==i.ARMS&&e.setStats(i.DMIN,i.DMAX,i.DMEAN,i.ARMS),t.Debug&&Dt.timeEnd("MrcParser._parse "+this.name)}getMatrix(){const t=this.volume.header,i=[t.xlen,0,0],r=[t.ylen*Math.cos(Math.PI/180*t.gamma),t.ylen*Math.sin(Math.PI/180*t.gamma),0],n=[t.zlen*Math.cos(Math.PI/180*t.beta),t.zlen*(Math.cos(Math.PI/180*t.alpha)-Math.cos(Math.PI/180*t.gamma)*Math.cos(Math.PI/180*t.beta))/Math.sin(Math.PI/180*t.gamma),0];n[2]=Math.sqrt(t.zlen*t.zlen*Math.sin(Math.PI/180*t.beta)*Math.sin(Math.PI/180*t.beta)-n[1]*n[1]);const s=[[],i,r,n],o=[0,t.MX,t.MY,t.MZ],a=[0,t.MAPC,t.MAPR,t.MAPS],c=new e.Matrix4;return c.set(s[a[1]][0]/o[a[1]],s[a[2]][0]/o[a[2]],s[a[3]][0]/o[a[3]],0,s[a[1]][1]/o[a[1]],s[a[2]][1]/o[a[2]],s[a[3]][1]/o[a[3]],0,s[a[1]][2]/o[a[1]],s[a[2]][2]/o[a[2]],s[a[3]][2]/o[a[3]],0,0,0,0,1),c.setPosition(new e.Vector3(t.originX,t.originY,t.originZ)),c.multiply((new e.Matrix4).makeTranslation(t.NXSTART,t.NYSTART,t.NZSTART)),c}}Nt.add("mrc",wg),Nt.add("ccp4",wg),Nt.add("map",wg);const Ag=/\s+/;function Sg(t){return t.trim().split(Ag).map(parseFloat)}class Cg extends fg{get type(){return"xplor"}_parse(){t.Debug&&Dt.time("XplorParser._parse "+this.name);const e=this.volume,i=this.streamer.peekLines(8),r={};let n;n=i[2].startsWith("REMARKS")?parseInt(i[1].substring(0,8))+2:5;const s=n+3,o=Sg(i[n]);r.NA=o[0],r.AMIN=o[1],r.AMAX=o[2],r.NB=o[3],r.BMIN=o[4],r.BMAX=o[5],r.NC=o[6],r.CMIN=o[7],r.CMAX=o[8];const a=Sg(i[n+1]);r.a=a[0]*this.voxelSize,r.b=a[1]*this.voxelSize,r.c=a[2]*this.voxelSize,r.alpha=a[3],r.beta=a[4],r.gamma=a[5];const c=r.AMAX-r.AMIN+1,l=r.BMAX-r.BMIN+1,u=r.CMAX-r.CMIN+1,h=c*l*u,d=new Float32Array(h),m=Math.ceil(1+c*l/6);let f=0,p=0;this.streamer.eachChunkOfLines((function(t){!function(t,e,i){for(let n=t;n<e;++n){const t=i[n];if(p>=s&&(p-s)%m!=0&&f<h)for(let e=0,i=6;e<i;++e){const i=parseFloat(t.substr(12*e,12));if(isNaN(i))break;d[f++]=i}else if(f===h){const e=t.trim();if(e&&"-9999"!==e){const e=Sg(t);r.RAVE=e[0],r.RSIGMA=e[1]}}++p}}(0,t.length,t)})),e.header=r,e.setData(d,c,l,u),0!==r.RAVE&&1!==r.RSIGMA&&e.setStats(void 0,void 0,r.RAVE,r.RSIGMA),t.Debug&&Dt.timeEnd("XplorParser._parse "+this.name)}getMatrix(){const t=this.volume.header,i=[t.a,0,0],r=[t.b*Math.cos(Math.PI/180*t.gamma),t.b*Math.sin(Math.PI/180*t.gamma),0],n=[t.c*Math.cos(Math.PI/180*t.beta),t.c*(Math.cos(Math.PI/180*t.alpha)-Math.cos(Math.PI/180*t.gamma)*Math.cos(Math.PI/180*t.beta))/Math.sin(Math.PI/180*t.gamma),0];n[2]=Math.sqrt(t.c*t.c*Math.sin(Math.PI/180*t.beta)*Math.sin(Math.PI/180*t.beta)-n[1]*n[1]);const s=[[],i,r,n],o=[0,t.NA,t.NB,t.NC],a=[0,1,2,3],c=new e.Matrix4;return c.set(s[a[1]][0]/o[a[1]],s[a[2]][0]/o[a[2]],s[a[3]][0]/o[a[3]],0,s[a[1]][1]/o[a[1]],s[a[2]][1]/o[a[2]],s[a[3]][1]/o[a[3]],0,s[a[1]][2]/o[a[1]],s[a[2]][2]/o[a[2]],s[a[3]][2]/o[a[3]],0,0,0,0,1),c.multiply((new e.Matrix4).makeTranslation(t.AMIN,t.BMIN,t.CMIN)),c}}function Pg(t,e,i){let r,n,s;t/=360,e/=100,i/=100;const o=Math.floor(6*t),a=6*t-o,c=i*(1-e),l=i*(1-a*e),u=i*(1-(1-a)*e);switch(o%6){case 0:r=i,n=u,s=c;break;case 1:r=l,n=i,s=c;break;case 2:r=c,n=i,s=u;break;case 3:r=c,n=l,s=i;break;case 4:r=u,n=c,s=i;break;case 5:r=i,n=c,s=l}return[r,n,s]}Nt.add("xplor",Cg),Nt.add("cns",Cg);const Ig={red:Pg(0,100,100),orange:Pg(20,100,100),gold:Pg(40,100,100),yellow:Pg(60,100,100),lime:Pg(80,100,100),green:Pg(120,80,100),sea:Pg(150,100,100),cyan:Pg(180,100,85),sky:Pg(210,75,95),blue:Pg(240,70,100),purple:Pg(275,75,100),magenta:Pg(300,95,100),hotpink:Pg(335,100,100),pink:Pg(350,55,100),peach:Pg(25,75,100),lilac:Pg(275,55,100),pinktint:Pg(340,30,100),peachtint:Pg(25,50,100),yellowtint:Pg(60,50,100),greentint:Pg(135,40,100),bluetint:Pg(220,40,100),lilactint:Pg(275,35,100),white:Pg(0,0,100),gray:Pg(0,0,50),brown:Pg(20,45,75),deadwhite:[1,1,1],deadblack:[0,0,0],invisible:[0,0,0]},kg=/[\s,]+/,Mg=/[^{}\s]*{[^{}]+}|[^{}\s]+/g,Tg=/^{+|}+$/g,Dg=/^['"]+|['"]+$/g,Bg=/\s*=\s*/g;function Fg(t){let e,i,r,n=[];const s=(t=t.replace(Bg,"=")).match(Mg);for(let t=1;t<s.length;++t){const o=s[t];if("{"===o[0])e=o.substring(1,o.length-1);else{const t=o.split("=");2===t.length&&("color"===t[0]?i=Ig[t[1]]:"width"===t[0]?r=parseInt(t[1]):"master"===t[0]&&n.push(t[1].replace(Tg,"")))}}return{listName:e,listColor:i,listMasters:n,listWidth:r}}function Eg(t){const e=(t=t.trim()).indexOf("{"),i=t.indexOf("}"),r=t.substr(i+1).split(kg),n=t.substr(e+1,i-1),s=[parseFloat(r[r.length-3]),parseFloat(r[r.length-2]),parseFloat(r[r.length-1])];let o,a,c,l=!1,u=!1;for(let t=4;t<=r.length;t++){const e=r[r.length-t];e in Ig&&(o=Ig[r[r.length-t]]),e.startsWith("width")&&(a=parseInt(e.substring(5))),e.startsWith("r=")&&(c=parseFloat(e.split("=")[1])),e.startsWith("P")&&(l=!0),e.startsWith("X")&&(u=!0)}return{label:n,position:s,color:o,radius:c,width:a,isLineBreak:l,isTriangleBreak:u}}function Og(t){const e=t.indexOf("{"),i=t.indexOf("}");return t.substring(-1!==e?e+1:0,-1!==i?i:void 0).trim()}function $g(t){const e=t.indexOf("}");return-1===e?void 0:t.substr(e+1).trim()}function Rg(t){let e="",i=[],r={};const n=(t=t.replace(Bg,"=")).match(Mg);for(let t=1;t<n.length;++t){const s=n[t];if("{"===s[0])e=s.substring(1,s.length-1);else{const t=s.split("=");2===t.length?"master"===t[0]?i.push(t[1].replace(Tg,"")):r[t[0]]=t[1].replace(Tg,""):r[t[0]]=!0}}return{groupName:e,groupFlags:r,groupMasters:i}}Nt.add("kin",class extends Jf{get type(){return"kin"}get __objName(){return"kinemage"}_parse(){t.Debug&&Dt.time(`KinParser._parse ${this.name}`);const i={kinemage:void 0,onewidth:void 0,"1viewid":void 0,pdbfile:void 0,texts:[],text:"",captions:[],caption:"",groupDict:{},subgroupDict:{},masterDict:{},pointmasterDict:{},dotLists:[],vectorLists:[],ballLists:[],ribbonLists:[]};let r,n;this.kinemage=i;let s,o,a,c,l,u,h,d,m,f,p,g,y,b,_,x,v,w,A,S,C,P,I=!1,k="",M=!1,T="",D=null,B=null,F=!1,E="",O=!1,$="",R=!1,L=!1;if(this.streamer.eachChunkOfLines((function(t){!function(t,e,N){for(let V=t;V<e;++V){const t=N[V];if("@"===t[0]&&(I=!1,M=!1,F=!1,O=!1,R=!1,L=!1),t)if(t.startsWith("@dotlist")){let{listColor:e,listName:l,listMasters:u}=Fg(t);I=!0,k="",o=[],a=[],c=[],s=e,r&&(u=u.concat(r)),n&&(u=u.concat(n)),i.dotLists.push({name:l,masterArray:u,labelArray:o,positionArray:a,colorArray:c})}else if(t.startsWith("@vectorlist")){let{listMasters:e,listName:s,listWidth:o,listColor:a}=Fg(t);e&&e.forEach((function(t){i.masterDict[t]||(i.masterDict[t]={indent:!1,visible:!1})})),M=!0,T="",D=null,B=null,h=[],d=[],m=[],f=[],p=[],g=[],l=a,u=[],o&&u.push(o),r&&(e=e.concat(r)),n&&(e=e.concat(n)),i.vectorLists.push({name:s,masterArray:e,label1Array:h,label2Array:d,position1Array:m,position2Array:f,color1Array:p,color2Array:g,width:u})}else if(t.startsWith("@balllist")){let{listName:e,listColor:s,listMasters:o}=Fg(t);o&&o.forEach((function(t){i.masterDict[t]||(i.masterDict[t]={indent:!1,visible:!1})})),F=!0,E="",_=[],y=[],x=[],v=[],b=s,r&&(o=o.concat(r)),n&&(o=o.concat(n)),i.ballLists.push({name:e,masterArray:o,labelArray:_,radiusArray:y,positionArray:x,colorArray:v})}else if(t.startsWith("@ribbonlist")||t.startsWith("@trianglelist")){let{listMasters:e,listName:s,listColor:o}=Fg(t);e&&e.forEach((function(t){i.masterDict[t]||(i.masterDict[t]={indent:!1,visible:!1})})),O=!0,$="",A=[],S=[],C=[],P=[],w=o,r&&(e=e.concat(r)),n&&(e=e.concat(n)),i.ribbonLists.push({name:s,masterArray:e,labelArray:A,positionArray:S,breakArray:C,colorArray:P})}else if(t.startsWith("@text"))R=!0,i.texts.push(t.substr(5));else if(t.startsWith("@caption"))L=!0,i.captions.push(t.substr(8));else if(I){let{label:e,color:i,position:r}=Eg(t);'"'===e?e=k:k=e,void 0===i&&(i=s),o.push(e),a.push(...r),c.push(...i)}else if(M){let e=t.replace(/(?!^){/g,"\n{").split(/\n/);for(var z=0;z<e.length;z++){let t=e[z],{label:i,color:r,width:n,position:s,isLineBreak:o}=Eg(t);'"'===i?i=T:T=i,void 0===r&&(r=l),o||null!==D&&(n&&u.push(n),h.push(T),m.push(...D),p.push(...B),d.push(i),f.push(...s),g.push(...r)),T=i,D=s,B=r}}else if(F){let{label:e,radius:i,color:r,position:n}=Eg(t);'"'===e?e=E:E=e,void 0===i&&(i=1),void 0===r&&(r=b),_.push(e),y.push(i),x.push(...n),v.push(...r)}else if(O){let{label:e,color:i,position:r,isTriangleBreak:n}=Eg(t);'"'===e?e=$:$=e,void 0===i&&(i=w),A.push(e),S.push(...r),C.push(n),P.push(...i)}else if(R)i.texts.push(t);else if(L)i.captions.push(t);else if(t.startsWith("@kinemage"))i.kinemage=parseInt(t.substr(9).trim());else if(t.startsWith("@onewidth"))i.onewidth=!0;else if(t.startsWith("@1viewid"))i["1viewid"]=Og(t);else if(t.startsWith("@pdbfile"))i.pdbfile=Og(t);else if(t.startsWith("@group")){let{groupName:e,groupFlags:n,groupMasters:s}=Rg(t);i.groupDict[e]||(i.groupDict[e]={dominant:!1,animate:!1},r=s),r&&r.forEach((function(t){i.masterDict[t]||(i.masterDict[t]={indent:!1,visible:!1})}));for(let t in n)i.groupDict[e][t]=n[t]}else if(t.startsWith("@subgroup")){const{groupName:e,groupFlags:r,groupMasters:s}=Rg(t);i.subgroupDict[e]||(i.subgroupDict[e]={dominant:!1,animate:!1},n=s),n&&n.forEach((function(t){i.masterDict[t]||(i.masterDict[t]={indent:!1,visible:!1})}));for(let t in r)i.subgroupDict[e][t]=r[t]}else if(t.startsWith("@master")){const e=Og(t),r=$g(t);i.masterDict[e]||(i.masterDict[e]={indent:!1,visible:!1}),"on"===r?i.masterDict[e].visible=!0:"off"===r?i.masterDict[e].visible=!1:"indent"===r&&(i.masterDict[e].indent=!0)}else if(t.startsWith("@pointmaster")){const{groupName:e,groupFlags:r}=Rg(t);i.pointmasterDict[e]={id:Object.keys(r)[0].replace(Dg,"")}}else console.log(t);else I=!1,M=!1,F=!1,O=!1}}(0,t.length,t)})),i.text=i.texts.join("\n").trim(),i.caption=i.captions.join("\n").trim(),i.ribbonLists){let t=[];i.ribbonLists.forEach((function(i){t.push(function(t){let{labelArray:e,positionArray:i,colorArray:r,breakArray:n}=t,s=[],o=[],a=[],c=[];for(let t=0;t<n.length/3;t++){let l=3*t,u=9*t;n[l+1]||n[l+2]||(s.push(e[l]),s.push(e[l+1]),s.push(e[l+2]),c.push(n[l]),c.push(n[l+1]),c.push(n[l+2]),o.push(i[u]),o.push(i[u+1]),o.push(i[u+2]),o.push(i[u+3]),o.push(i[u+4]),o.push(i[u+5]),o.push(i[u+6]),o.push(i[u+7]),o.push(i[u+8]),a.push(r[u]),a.push(r[u+1]),a.push(r[u+2]),a.push(r[u+3]),a.push(r[u+4]),a.push(r[u+5]),a.push(r[u+6]),a.push(r[u+7]),a.push(r[u+8]))}return{name:t.name,masterArray:t.masterArray,labelArray:s,positionArray:o,breakArray:c,colorArray:a}}(function(t){let{labelArray:i,positionArray:r,colorArray:n,breakArray:s}=t,o=[];for(let t=0;t<3*(i.length-2);++t)o[t]=i[t-2*Math.floor(t/3)];let a=[];for(let t=0;t<3*(s.length-2);++t)a[t]=s[t-2*Math.floor(t/3)];let c=[];for(let t=0;t<9*(r.length/3-2);++t)c[t]=r[t-6*Math.floor(t/9)];let l=[];for(let t=0;t<9*(n.length/3-2);++t)l[t]=n[t-6*Math.floor(t/9)];let u=[];for(let t=0;t<c.length/3;++t)u.push(new e.Vector3(c[3*t],c[3*t]+1,c[3*t]+2));return{name:t.name,masterArray:t.masterArray,labelArray:o,positionArray:c,breakArray:a,colorArray:l}}(i)))})),i.ribbonLists=t}t.Debug&&Dt.timeEnd(`KinParser._parse ${this.name}`)}});class Lg extends Jf{constructor(t,e){super(t,e),this.loader=this.getLoader(),this.surface=new As(this.name,this.path)}get type(){return"surface"}get __objName(){return"surface"}_parse(){var t=this.loader.parse(this.streamer.asText());this.surface.fromGeometry(t)}}const Ng=function(){this.regexp={vertex_pattern:/^v\s+([\d.+\-eE]+)\s+([\d.+\-eE]+)\s+([\d.+\-eE]+)/,normal_pattern:/^vn\s+([\d.+\-eE]+)\s+([\d.+\-eE]+)\s+([\d.+\-eE]+)/,uv_pattern:/^vt\s+([\d.+\-eE]+)\s+([\d.+\-eE]+)/,face_vertex:/^f\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)(?:\s+(-?\d+))?/,face_vertex_uv:/^f\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+))?/,face_vertex_uv_normal:/^f\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+)\/(-?\d+))?/,face_vertex_normal:/^f\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)(?:\s+(-?\d+)\/\/(-?\d+))?/,object_pattern:/^[og]\s*(.+)?/,smoothing_pattern:/^s\s+(\d+|on|off)/,material_library_pattern:/^mtllib /,material_use_pattern:/^usemtl /}};Ng.prototype={constructor:Ng,setPath:function(t){this.path=t},_createParserState:function(){var t={objects:[],object:{},vertices:[],normals:[],startObject:function(t,e){if(this.object&&!1===this.object.fromDeclaration)return this.object.name=t,void(this.object.fromDeclaration=!1!==e);this.object={name:t||"",geometry:{vertices:[],normals:[]},fromDeclaration:!1!==e},this.objects.push(this.object)},parseVertexIndex:function(t,e){var i=parseInt(t,10);return 3*(i>=0?i-1:i+e/3)},parseNormalIndex:function(t,e){var i=parseInt(t,10);return 3*(i>=0?i-1:i+e/3)},addVertex:function(t,e,i){var r=this.vertices,n=this.object.geometry.vertices;n.push(r[t+0]),n.push(r[t+1]),n.push(r[t+2]),n.push(r[e+0]),n.push(r[e+1]),n.push(r[e+2]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[i+2])},addVertexLine:function(t){var e=this.vertices,i=this.object.geometry.vertices;i.push(e[t+0]),i.push(e[t+1]),i.push(e[t+2])},addNormal:function(t,e,i){var r=this.normals,n=this.object.geometry.normals;n.push(r[t+0]),n.push(r[t+1]),n.push(r[t+2]),n.push(r[e+0]),n.push(r[e+1]),n.push(r[e+2]),n.push(r[i+0]),n.push(r[i+1]),n.push(r[i+2])},addFace:function(t,e,i,r,n,s,o,a){var c,l=this.vertices.length,u=this.parseVertexIndex(t,l),h=this.parseVertexIndex(e,l),d=this.parseVertexIndex(i,l);if(void 0===r?this.addVertex(u,h,d):(c=this.parseVertexIndex(r,l),this.addVertex(u,h,c),this.addVertex(h,d,c)),void 0!==n){var m=this.normals.length;u=this.parseNormalIndex(n,m),h=n===s?u:this.parseNormalIndex(s,m),d=n===o?u:this.parseNormalIndex(o,m),void 0===r?this.addNormal(u,h,d):(c=this.parseNormalIndex(a,m),this.addNormal(u,h,c),this.addNormal(h,d,c))}},addLineGeometry:function(t){this.object.geometry.type="Line";for(var e=this.vertices.length,i=0,r=t.length;i<r;i++)this.addVertexLine(this.parseVertexIndex(t[i],e))}};return t.startObject("",!1),t},parse:function(t){var i,r,n=this._createParserState();-1!==t.indexOf("\r\n")&&(t=t.replace(/\r\n/g,"\n")),-1!==t.indexOf("\\\n")&&(t=t.replace(/\\\n/g,""));var s=t.split("\n"),o="",a="",c="",l=[],u="function"==typeof"".trimLeft;for(i=0,r=s.length;i<r;i++)if(o=s[i],0!==(o=u?o.trimLeft():o.trim()).length&&"#"!==(a=o.charAt(0)))if("v"===a){if(" "===(c=o.charAt(1))&&null!==(l=this.regexp.vertex_pattern.exec(o)))n.vertices.push(parseFloat(l[1]),parseFloat(l[2]),parseFloat(l[3]));else if("n"===c&&null!==(l=this.regexp.normal_pattern.exec(o)))n.normals.push(parseFloat(l[1]),parseFloat(l[2]),parseFloat(l[3]));else if("t"!==c||null===this.regexp.uv_pattern.exec(o))throw new Error("Unexpected vertex/normal/uv line: '"+o+"'")}else if("f"===a)if(null!==(l=this.regexp.face_vertex_uv_normal.exec(o)))n.addFace(l[1],l[4],l[7],l[10],l[3],l[6],l[9],l[12]);else if(null!==this.regexp.face_vertex_uv.exec(o));else if(null!==(l=this.regexp.face_vertex_normal.exec(o)))n.addFace(l[1],l[3],l[5],l[7],l[2],l[4],l[6],l[8]);else{if(null===(l=this.regexp.face_vertex.exec(o)))throw new Error("Unexpected face line: '"+o+"'");n.addFace(l[1],l[2],l[3],l[4])}else if("l"===a){var h=o.substring(1).trim().split(" "),d=[],m=[];if(-1===o.indexOf("/"))d=h;else for(var f=0,p=h.length;f<p;f++){var g=h[f].split("/");""!==g[0]&&d.push(g[0]),""!==g[1]&&m.push(g[1])}n.addLineGeometry(d,m)}else if(null!==(l=this.regexp.object_pattern.exec(o))){var y=l[0].substr(1).trim();n.startObject(y)}else if(this.regexp.material_use_pattern.test(o));else if(this.regexp.material_library_pattern.test(o));else if(null===this.regexp.smoothing_pattern.exec(o)){if("\0"===o)continue;throw new Error("Unexpected line: '"+o+"'")}var b=[];for(i=0,r=n.objects.length;i<r;i++){var _=n.objects[i].geometry;if(0!==_.vertices.length){var x=new e.BufferGeometry;x.setAttribute("position",new e.BufferAttribute(new Float32Array(_.vertices),3)),_.normals.length>0?x.setAttribute("normal",new e.BufferAttribute(new Float32Array(_.normals),3)):x.computeVertexNormals(),b.push(x)}}return b}};Nt.add("obj",class extends Lg{get type(){return"obj"}getLoader(){return new Ng}});const zg=["int8","char","uint8","uchar","int16","short","uint16","ushort","int32","int","uint32","uint","float32","float","float64","double"];function Vg(t){if(function(t){return zg.includes(t)}(t))return t;throw new Error(`Unsupported data type: ${t}`)}function Ug(t){if("object"!=typeof t||null===t)throw new Error("Expected element to be an object");if("string"!=typeof t.name)throw new Error("Expected element.name to be a string");if("number"!=typeof t.count)throw new Error("Expected element.count to be a number");if(!Array.isArray(t.properties))throw new Error("Expected element.properties to be an array")}function jg(t,e,i){switch(e){case"int8":case"char":return{read:e=>t.getInt8(e),size:1};case"uint8":case"uchar":return{read:e=>t.getUint8(e),size:1};case"int16":case"short":return{read:e=>t.getInt16(e,i),size:2};case"uint16":case"ushort":return{read:e=>t.getUint16(e,i),size:2};case"int32":case"int":return{read:e=>t.getInt32(e,i),size:4};case"uint32":case"uint":return{read:e=>t.getUint32(e,i),size:4};case"float32":case"float":return{read:e=>t.getFloat32(e,i),size:4};case"float64":case"double":return{read:e=>t.getFloat64(e,i),size:8};default:throw new Error(`Unsupported data type: ${e}`)}}function Gg(t,e){const i={};let r=0;for(let n=0;n<e.length;n++){const s=e[n],o=s.valueReader;if(s.isList){const e=[],n=s.countReader.read(t+r);r+=s.countReader.size;for(let i=0;i<n;i++)e.push(o.read(t+r)),r+=o.size;i[s.name]=e}else i[s.name]=o.read(t+r),r+=o.size}return[i,r]}class Hg{constructor(){this._color=new e.Color,this.propertyNameMapping={},this.customPropertyMapping={}}setPropertyNameMapping(t){this.propertyNameMapping=t}createBuffer(){const t={indices:[],vertices:[],normals:[],uvs:[],faceVertexUvs:[],colors:[],faceVertexColors:[]};for(const e of Object.keys(this.customPropertyMapping))t[e]=[];return t}extractHeaderText(t){let e=0,i=!0,r="";const n=[],s=(new TextDecoder).decode(t.subarray(0,5)),o=/^ply\r\n/.test(s);do{const s=String.fromCharCode(t[e++]);"\n"!==s&&"\r"!==s?r+=s:("end_header"===r&&(i=!1),""!==r&&(n.push(r),r=""))}while(i&&e<t.length);return!0===o&&e++,{headerText:n.join("\r")+"\r",headerLength:e}}handleElement(t,e,i,r){if("vertex"===e){t.vertices.push(i[r.attrX],i[r.attrY],i[r.attrZ]),null!==r.attrNX&&null!==r.attrNY&&null!==r.attrNZ&&t.normals.push(i[r.attrNX],i[r.attrNY],i[r.attrNZ]),null!==r.attrS&&null!==r.attrT&&t.uvs.push(i[r.attrS],i[r.attrT]),null!==r.attrR&&null!==r.attrG&&null!==r.attrB&&(this._color.setRGB(i[r.attrR]/255,i[r.attrG]/255,i[r.attrB]/255).convertSRGBToLinear(),t.colors.push(this._color.r,this._color.g,this._color.b));for(const e of Object.keys(this.customPropertyMapping))for(const r of this.customPropertyMapping[e])t[e].push(i[r])}else if("face"===e){const e=i.vertex_indices||i.vertex_index,n=i.texcoord;3===e.length?(t.indices.push(e[0],e[1],e[2]),n&&6===n.length&&(t.faceVertexUvs.push(n[0],n[1]),t.faceVertexUvs.push(n[2],n[3]),t.faceVertexUvs.push(n[4],n[5]))):4===e.length&&(t.indices.push(e[0],e[1],e[3]),t.indices.push(e[1],e[2],e[3])),null!==r.attrR&&null!==r.attrG&&null!==r.attrB&&(this._color.setRGB(i[r.attrR]/255,i[r.attrG]/255,i[r.attrB]/255).convertSRGBToLinear(),t.faceVertexColors.push(this._color.r,this._color.g,this._color.b),t.faceVertexColors.push(this._color.r,this._color.g,this._color.b),t.faceVertexColors.push(this._color.r,this._color.g,this._color.b))}}parse(t){let e;if(t instanceof ArrayBuffer){const i=new Uint8Array(t),{headerText:r,headerLength:n}=this.extractHeaderText(i),s=this.parseHeader(r,n);if("ascii"===s.format){const t=(new TextDecoder).decode(i);e=this.parseASCII(t,s)}else e=this.parseBinary(i,s)}else e=this.parseASCII(t,this.parseHeader(t));return e}parseHeader(t,e=0){let i="";const r=/^ply([\s\S]*)end_header(\r\n|\r|\n)/.exec(t);null!==r&&(i=r[1]);const n={comments:[],elements:[],headerLength:e,objInfo:"",format:"",version:""},s=i.split(/\r\n|\r|\n/);let o;for(let t=0;t<s.length;t++){let e=s[t];if(e=e.trim(),""===e)continue;const i=e.split(/\s+/),r=i.shift();switch(e=i.join(" "),r){case"format":n.format=i[0],n.version=i[1];break;case"comment":n.comments.push(e);break;case"element":void 0!==o&&(Ug(o),n.elements.push(o)),o={name:i[0],count:parseInt(i[1]),properties:[]};break;case"property":if(void 0===o){console.warn("property without element");continue}o.properties.push(qg(i,this.propertyNameMapping));break;case"obj_info":n.objInfo=e;break;default:console.log("unhandled",r,i)}}return void 0!==o&&n.elements.push(o),n}parseASCII(t,e){const i=this.createBuffer();let r,n;r=null!==(n=/end_header\s+(\S[\s\S]*\S|\S)\s*$/.exec(t))?n[1].split(/\s+/):[];const s=new Kg(r);t:for(let t=0;t<e.elements.length;t++){const r=e.elements[t],n=Yg(r.properties);for(let t=0;t<r.count;t++){const t=Xg(r.properties,s);if(!t)break t;this.handleElement(i,r.name,t,n)}}return this.postProcess(i)}parseBinary(t,e){const i=this.createBuffer(),r="binary_little_endian"===e.format,n=new DataView(t,e.headerLength);let s,o=0;for(let t=0;t<e.elements.length;t++){const a=e.elements[t],c=a.properties,l=Yg(c),u=this.makeBinaryProperties(c,n,r);for(let t=0;t<a.count;t++){s=Gg(o,u),o+=s[1];const t=s[0];this.handleElement(i,a.name,t,l)}}return this.postProcess(i)}postProcess(t){let i=new e.BufferGeometry;t.indices.length>0&&i.setIndex(t.indices),i.setAttribute("position",new e.Float32BufferAttribute(t.vertices,3)),t.normals.length>0&&i.setAttribute("normal",new e.Float32BufferAttribute(t.normals,3)),t.uvs.length>0&&i.setAttribute("uv",new e.Float32BufferAttribute(t.uvs,2)),t.colors.length>0&&i.setAttribute("color",new e.Float32BufferAttribute(t.colors,3)),(t.faceVertexUvs.length>0||t.faceVertexColors.length>0)&&(i=i.toNonIndexed(),t.faceVertexUvs.length>0&&i.setAttribute("uv",new e.Float32BufferAttribute(t.faceVertexUvs,2)),t.faceVertexColors.length>0&&i.setAttribute("color",new e.Float32BufferAttribute(t.faceVertexColors,3)));for(const r of Object.keys(this.customPropertyMapping))t[r].length>0&&i.setAttribute(r,new e.Float32BufferAttribute(t[r],this.customPropertyMapping[r].length));return i.computeBoundingSphere(),i}makeBinaryProperties(t,e,i){const r=[];for(let n=0,s=t.length;n<s;n++){const s=t[n];s.isList?r.push(Object.assign(Object.assign({},s),{countReader:jg(e,s.countType,i),valueReader:jg(e,s.type,i)})):r.push(Object.assign(Object.assign({},s),{valueReader:jg(e,s.type,i)}))}return r}}function qg(t,e){const i=t[0];let r;return r="list"===i?{isList:!0,name:t[3],type:Vg(t[2]),countType:Vg(t[1])}:{isList:!1,name:t[1],type:Vg(i)},r.name in e&&(r.name=e[r.name]),r}function Wg(t,e){switch(e){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(t);case"float":case"double":case"float32":case"float64":return parseFloat(t)}return 0}function Xg(t,e){const i={name:"",type:""};for(let r=0;r<t.length;r++){if(e.empty())return null;const n=t[r];if(n.isList){const t=[],r=Wg(e.next(),n.countType);for(let i=0;i<r;i++){if(e.empty())return null;t.push(Wg(e.next(),n.type))}i[n.name]=t}else i[t[r].name]=Wg(e.next(),t[r].type)}return i}function Yg(t){const e=t.map((t=>t.name));function i(t){for(let i=0,r=t.length;i<r;i++){const r=t[i];if(e.includes(r))return r}return null}return{attrX:i(["x","px","posx"])||"x",attrY:i(["y","py","posy"])||"y",attrZ:i(["z","pz","posz"])||"z",attrNX:i(["nx","normalx"]),attrNY:i(["ny","normaly"]),attrNZ:i(["nz","normalz"]),attrS:i(["s","u","texture_u","tx"]),attrT:i(["t","v","texture_v","ty"]),attrR:i(["red","diffuse_red","r","diffuse_r"]),attrG:i(["green","diffuse_green","g","diffuse_g"]),attrB:i(["blue","diffuse_blue","b","diffuse_b"])}}class Kg{constructor(t){this.arr=t,this.i=0}empty(){return this.i>=this.arr.length}next(){return this.arr[this.i++]}}Nt.add("ply",class extends Lg{get type(){return"ply"}getLoader(){return new Hg}});Nt.add("csv",class extends Jf{constructor(t,e){const i=e||{};super(t,i),this.delimiter=l(i.delimiter,","),this.comment=l(i.comment,"#"),this.columnNames=l(i.columnNames,!1),this.table={name:this.name,path:this.path,columnNames:[],data:[]}}get type(){return"csv"}get __objName(){return"table"}_parse(){const t=this.table.data,e=new RegExp("\\s*"+this.delimiter+"\\s*");let i=0;this.streamer.eachChunkOfLines((r=>{const n=r.length;for(let s=0;s<n;++s){const n=r[s].trim();if(n.startsWith(this.comment))continue;const o=n.split(e);0===i?this.table.columnNames=o:n&&t.push(o),++i}}))}});Nt.add("json",class extends Jf{constructor(t,e){const i=e||{};super(t,i),this.string=l(i.string,!1),this.json={name:this.name,path:this.path,data:{}}}get type(){return"json"}get __objName(){return"json"}get isJson(){return!0}_parse(){this.streamer.isBinary()||this.string?this.json.data=JSON.parse(this.streamer.asText()):this.json.data=this.streamer.data}});Nt.add("msgpack",class extends Jf{constructor(t,e){super(t,e||{}),this.msgpack={name:this.name,path:this.path,data:void 0}}get type(){return"msgpack"}get __objName(){return"msgpack"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("MsgpackParser._parse "+this.name),this.msgpack.data=Mp(this.streamer.data),t.Debug&&Dt.timeEnd("MsgpackParser._parse "+this.name)}});Nt.add("netcdf",class extends Jf{constructor(t,e){super(t,e||{}),this.netcdf={name:this.name,path:this.path,data:void 0}}get type(){return"netcdf"}get __objName(){return"netcdf"}get isBinary(){return!0}_parse(){t.Debug&&Dt.time("NetcdfParser._parse "+this.name),this.netcdf.data=new sg(this.streamer.data),t.Debug&&Dt.timeEnd("NetcdfParser._parse "+this.name)}});class Zg extends Jf{constructor(t,e){super(t,e),this.text={name:this.name,path:this.path,data:""}}get type(){return"text"}get __objName(){return"text"}_parse(){this.text.data=this.streamer.asText()}}Nt.add("txt",Zg),Nt.add("text",Zg);const Qg=/^['"]|['"]$/g,Jg=/^<([\w-:.]+)\s*/,ty=/^([^<]*)/,ey=/([\w:-]+)\s*=\s*("[^"]*"|'[^']*'|\w+)\s*/;function iy(t){return t=t.trim().replace(/<!--[\s\S]*?-->/g,""),{declaration:e(),root:i()};function e(){if(!n(/^<\?xml\s*/))return;const t={attributes:{}};for(;!s()&&!o("?>");){const e=r();if(!e)return t;t.attributes[e.name]=e.value}return n(/\?>\s*/),t}function i(){const t=n(Jg);if(!t)return;const e={name:t[1],attributes:{},children:[]};for(;!(s()||o(">")||o("?>")||o("/>"));){const t=r();if(!t)return e;e.attributes[t.name]=t.value}if(n(/^\s*\/>\s*/))return e;let a;for(n(/\??>\s*/),e.content=function(){const t=n(ty);return t?t[1]:""}();a=i();)e.children.push(a);return n(/^<\/[\w-:.]+>\s*/),e}function r(){const t=n(ey);var e;if(t)return{name:t[1],value:(e=t[2],e.replace(Qg,""))}}function n(e){const i=t.match(e);if(i)return t=t.slice(i[0].length),i}function s(){return 0===t.length}function o(e){return 0===t.indexOf(e)}}class ry extends Jf{constructor(t,e){const i=e||{};super(t,i),this.useDomParser=l(i.useDomParser,!1),this.xml={name:this.name,path:this.path,data:{}}}get type(){return"xml"}get __objName(){return"xml"}get isXml(){return!0}__xmlParser(t){return iy(t)}__domParser(t){return(new window.DOMParser).parseFromString(t,"text/xml")}_parse(){t.Debug&&Dt.time("XmlParser._parse "+this.name),this.useDomParser?this.streamer.data instanceof Document?this.xml.data=this.streamer.data:this.xml.data=this.__domParser(this.streamer.asText()):this.xml.data=this.__xmlParser(this.streamer.asText()),t.Debug&&Dt.timeEnd("XmlParser._parse "+this.name)}}function ny(t,e){const i=t.getNamedItem(e);return null!==i?i.value:""}function sy(t,e,i=!1){const r=ny(t,"icode").trim(),n=ny(t,"chain").trim(),s=ny(t,"altcode");let o=ny(t,"resnum");return r&&(o+="^"+r),n&&(o+=":"+n),e&&(o+="."+e),i&&s.trim()&&(o+="%"+s),o+="/"+(parseInt(ny(t,"model"))-1),o}function oy(t){const e=ny(t,"chain").trim();let i=`[${ny(t,"rescode")}]${ny(t,"resnum")}`;return e&&(i+=`:${e}`),i}function ay(t,e,i){void 0===t[e]?t[e]=i:t[e]|=i}function cy(t,e){return null!==t&&t.value===e}function ly(t,e,i){let r=0;const n=e.getElementsByTagName("clash");for(let e=0,i=n.length;e<i;++e)if(t[ny(n[e].attributes,"cid")]){r+=1;break}e.getElementsByTagName("angle-outlier").length>0&&(r+=1);e.getElementsByTagName("bond-outlier").length>0&&(r+=1);return e.getElementsByTagName("plane-outlier").length>0&&(r+=1),cy(i.getNamedItem("rota"),"OUTLIER")&&(r+=1),cy(i.getNamedItem("rama"),"OUTLIER")&&(r+=1),cy(i.getNamedItem("RNApucker"),"outlier")&&(r+=1),r}Nt.add("xml",ry);class uy{constructor(t,e){this.name=t,this.path=e,this.rsrzDict={},this.rsccDict={},this.rciDict={},this.clashDict={},this.clashArray=[],this.geoDict={},this.geoAtomDict={},this.atomDict={},this.clashSele="NONE"}get type(){return"validation"}fromXml(e){t.Debug&&Dt.time("Validation.fromXml");const i=this.rsrzDict,r=this.rsccDict,n=this.rciDict,s=this.clashDict,o=this.clashArray,a=this.geoDict,c=this.geoAtomDict,l=this.atomDict,u=e.getElementsByTagName("Entry");if(1===u.length){const t=u[0].getElementsByTagName("chemical_shift_list");if(1===t.length){const e=t[0].getElementsByTagName("random_coil_index");for(let t=0,i=e.length;t<i;++t){const i=e[t].attributes;n[oy(i)]=parseFloat(ny(i,"value"))}}}const h=e.getElementsByTagName("ModelledSubgroup"),d={},m=[];t.Debug&&Dt.time("Validation.fromXml#clashDict");for(let t=0,n=h.length;t<n;++t){const n=h[t],a=n.attributes,c=sy(a);null!==a.getNamedItem("rsrz")&&(i[c]=parseFloat(ny(a,"rsrz"))),null!==a.getNamedItem("rscc")&&(r[c]=parseFloat(ny(a,"rscc")));const u=e.createAttribute("sele");u.value=c,a.setNamedItem(u);const f=n.getElementsByTagName("clash");for(let t=0,e=f.length;t<e;++t){const e=f[t].attributes,i=ny(e,"atom");if("H"!==Go(i)){const t=ny(e,"cid"),r=sy(a,i,!0);if(l[r]=!0,void 0===d[t])d[t]={sele1:r,res1:c};else{const e=d[t];e.res1!==c&&(e.sele2=r,e.res2=c,m.push(e.res1,c),s[t]=e,o.push(e))}}}}t.Debug&&Dt.timeEnd("Validation.fromXml#clashDict");for(let t=0,e=h.length;t<e;++t){const e=h[t],i=e.attributes,r=ny(i,"sele");if("."!==ny(i,"seq")){const t=ly(s,e,i);t>0&&(a[r]=t)}else{const t=e.getElementsByTagName("clash"),i=e.getElementsByTagName("mog-bond-outlier"),n=e.getElementsByTagName("mog-angle-outlier");if(i.length>0||n.length>0||t.length>0){const e={};c[r]=e;for(let i=0,r=t.length;i<r;++i){const r=t[i].attributes;s[ny(r,"cid")]&&ay(e,ny(r,"atom"),1)}for(let t=0,r=i.length;t<r;++t){ny(i[t].attributes,"atoms").split(",").forEach((function(t){ay(e,t,2)}))}for(let t=0,i=n.length;t<i;++t){ny(n[t].attributes,"atoms").split(",").forEach((function(t){ay(e,t,4)}))}}}}this.clashSele=m.length?m.join(" OR "):"NONE",t.Debug&&Dt.timeEnd("Validation.fromXml")}getClashData(i){t.Debug&&Dt.time("Validation.getClashData");const r=i||{},n=r.structure,s=n.atomSet,o=new e.Color(l(r.color,"#f0027f")),a=n.getAtomProxy(),c=n.getAtomProxy(),u=new e.Vector3,h=new e.Vector3,d=new e.Vector3,m=this.clashArray,f=m.length,p=new Float32Array(3*f),g=new Float32Array(3*f),y=ye(f,o.r,o.g,o.b),b=new Float32Array(f),_=new Float32Array(f);t.Debug&&Dt.time("Validation.getClashData#atomDict");const x=this.atomDict;n.eachAtom((function(t){const e=function(t){const e=t.inscode,i=t.chainname,r=t.atomname,n=t.altloc;let s=t.resno+"";return e&&(s+="^"+e),i&&(s+=":"+i),r&&(s+="."+r),n&&(s+="%"+n),s+="/"+t.modelIndex,s}(t);!0===x[e]&&(x[e]=t.index)})),t.Debug&&Dt.timeEnd("Validation.getClashData#atomDict");let v=0;return m.forEach((function(t,e){if(a.index=x[t.sele1],c.index=x[t.sele2],void 0===a.index||void 0===c.index||!s.isSet(a.index,c.index))return;u.subVectors(c,a).setLength(a.vdw),h.copy(a).add(u),u.subVectors(a,c).setLength(c.vdw),d.copy(c).add(u);const i=a.distanceTo(c)/2,r=Math.sqrt(a.vdw*a.vdw-i*i),n=Math.sqrt(c.vdw*c.vdw-i*i);h.toArray(p,3*v),d.toArray(g,3*v),b[v]=(r+n)/2,_[v]=e,++v})),t.Debug&&Dt.timeEnd("Validation.getClashData"),{position1:p.subarray(0,3*v),position2:g.subarray(0,3*v),color:y.subarray(0,3*v),color2:y.subarray(0,3*v),radius:b.subarray(0,v),picking:new jn(_.subarray(0,v),this,n)}}}function hy(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)}function dy(t,e,i,r,n){if(e.subarray&&t.subarray)t.set(e.subarray(i,i+r),n);else for(var s=0;s<r;s++)t[n+s]=e[i+s]}function my(t,e,i,r){for(var n=65535&t,s=t>>>16&65535,o=0;0!==i;){i-=o=i>2e3?2e3:i;do{s=s+(n=n+e[r++]|0)|0}while(--o);n%=65521,s%=65521}return n|s<<16}Nt.add("validation",class extends ry{constructor(t,e){super(t,e||{}),this.useDomParser=!0,this.validation=new uy(this.name,this.path)}get __objName(){return"validation"}get isXml(){return!0}_parse(){super._parse(),t.Debug&&Dt.time("ValidationParser._parse "+this.name),this.validation.fromXml(this.xml.data),t.Debug&&Dt.timeEnd("ValidationParser._parse "+this.name)}});var fy=function(){for(var t,e=[],i=0;i<256;i++){t=i;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e}();function py(t,e,i,r){var n=fy,s=r+i;t^=-1;for(var o=r;o<s;o++)t=t>>>8^n[255&(t^e[o])];return~t}var gy=30,yy=12;function by(t,e){var i,r,n,s,o,a,c,l,u,h,d,m,f,p,g,y,b,_,x,v,w,A,S,C,P;i=t.state,r=t.next_in,C=t.input,n=r+(t.avail_in-5),s=t.next_out,P=t.output,o=s-(e-t.avail_out),a=s+(t.avail_out-257),c=i.dmax,l=i.wsize,u=i.whave,h=i.wnext,d=i.window,m=i.hold,f=i.bits,p=i.lencode,g=i.distcode,y=(1<<i.lenbits)-1,b=(1<<i.distbits)-1;t:do{f<15&&(m+=C[r++]<<f,f+=8,m+=C[r++]<<f,f+=8),_=p[m&y];e:for(;;){if(m>>>=x=_>>>24,f-=x,0===(x=_>>>16&255))P[s++]=65535&_;else{if(!(16&x)){if(64&x){if(32&x){i.mode=yy;break t}t.msg="invalid literal/length code",i.mode=gy;break t}_=p[(65535&_)+(m&(1<<x)-1)];continue e}for(v=65535&_,(x&=15)&&(f<x&&(m+=C[r++]<<f,f+=8),v+=m&(1<<x)-1,m>>>=x,f-=x),f<15&&(m+=C[r++]<<f,f+=8,m+=C[r++]<<f,f+=8),_=g[m&b];;){if(m>>>=x=_>>>24,f-=x,16&(x=_>>>16&255)){if(w=65535&_,f<(x&=15)&&(m+=C[r++]<<f,(f+=8)<x&&(m+=C[r++]<<f,f+=8)),(w+=m&(1<<x)-1)>c){t.msg="invalid distance too far back",i.mode=gy;break t}if(m>>>=x,f-=x,w>(x=s-o)){if((x=w-x)>u&&i.sane){t.msg="invalid distance too far back",i.mode=gy;break t}if(A=0,S=d,0===h){if(A+=l-x,x<v){v-=x;do{P[s++]=d[A++]}while(--x);A=s-w,S=P}}else if(h<x){if(A+=l+h-x,(x-=h)<v){v-=x;do{P[s++]=d[A++]}while(--x);if(A=0,h<v){v-=x=h;do{P[s++]=d[A++]}while(--x);A=s-w,S=P}}}else if(A+=h-x,x<v){v-=x;do{P[s++]=d[A++]}while(--x);A=s-w,S=P}for(;v>2;)P[s++]=S[A++],P[s++]=S[A++],P[s++]=S[A++],v-=3;v&&(P[s++]=S[A++],v>1&&(P[s++]=S[A++]))}else{A=s-w;do{P[s++]=P[A++],P[s++]=P[A++],P[s++]=P[A++],v-=3}while(v>2);v&&(P[s++]=P[A++],v>1&&(P[s++]=P[A++]))}break}if(64&x){t.msg="invalid distance code",i.mode=gy;break t}_=g[(65535&_)+(m&(1<<x)-1)]}}break}}while(r<n&&s<a);r-=v=f>>3,m&=(1<<(f-=v<<3))-1,t.next_in=r,t.next_out=s,t.avail_in=r<n?n-r+5:5-(r-n),t.avail_out=s<a?a-s+257:257-(s-a),i.hold=m,i.bits=f}var _y=15,xy=852,vy=592,wy=0,Ay=1,Sy=2,Cy=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Py=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],Iy=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],ky=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];function My(t,e,i,r,n,s,o,a){var c,l,u,h,d,m,f,p,g,y=a.bits,b=0,_=0,x=0,v=0,w=0,A=0,S=0,C=0,P=0,I=0,k=null,M=0,T=new Uint16Array(_y+1),D=new Uint16Array(_y+1),B=null,F=0;for(b=0;b<=_y;b++)T[b]=0;for(_=0;_<r;_++)T[e[i+_]]++;for(w=y,v=_y;v>=1&&0===T[v];v--);if(w>v&&(w=v),0===v)return n[s++]=20971520,n[s++]=20971520,a.bits=1,0;for(x=1;x<v&&0===T[x];x++);for(w<x&&(w=x),C=1,b=1;b<=_y;b++)if(C<<=1,(C-=T[b])<0)return-1;if(C>0&&(t===wy||1!==v))return-1;for(D[1]=0,b=1;b<_y;b++)D[b+1]=D[b]+T[b];for(_=0;_<r;_++)0!==e[i+_]&&(o[D[e[i+_]]++]=_);if(t===wy?(k=B=o,m=19):t===Ay?(k=Cy,M-=257,B=Py,F-=257,m=256):(k=Iy,B=ky,m=-1),I=0,_=0,b=x,d=s,A=w,S=0,u=-1,h=(P=1<<w)-1,t===Ay&&P>xy||t===Sy&&P>vy)return 1;for(;;){f=b-S,o[_]<m?(p=0,g=o[_]):o[_]>m?(p=B[F+o[_]],g=k[M+o[_]]):(p=96,g=0),c=1<<b-S,x=l=1<<A;do{n[d+(I>>S)+(l-=c)]=f<<24|p<<16|g}while(0!==l);for(c=1<<b-1;I&c;)c>>=1;if(0!==c?(I&=c-1,I+=c):I=0,_++,0==--T[b]){if(b===v)break;b=e[i+o[_]]}if(b>w&&(I&h)!==u){for(0===S&&(S=w),d+=x,C=1<<(A=b-S);A+S<v&&!((C-=T[A+S])<=0);)A++,C<<=1;if(P+=1<<A,t===Ay&&P>xy||t===Sy&&P>vy)return 1;n[u=I&h]=w<<24|A<<16|d-s}}return 0!==I&&(n[d+I]=b-S<<24|64<<16),a.bits=w,0}var Ty=1,Dy=2,By=0,Fy=-2,Ey=1,Oy=12,$y=30,Ry=852,Ly=592;function Ny(t){return(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24)}function zy(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Vy(t){var e;return t&&t.state?((e=t.state).wsize=0,e.whave=0,e.wnext=0,function(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=Ey,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(Ry),e.distcode=e.distdyn=new Int32Array(Ly),e.sane=1,e.back=-1,By):Fy}(t)):Fy}function Uy(t,e){var i,r;return t?(r=new zy,t.state=r,r.window=null,i=function(t,e){var i,r;return t&&t.state?(r=t.state,e<0?(i=0,e=-e):(i=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?Fy:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=i,r.wbits=e,Vy(t))):Fy}(t,e),i!==By&&(t.state=null),i):Fy}var jy,Gy,Hy=!0;function qy(t){if(Hy){var e;for(jy=new Int32Array(512),Gy=new Int32Array(32),e=0;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(My(Ty,t.lens,0,288,jy,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;My(Dy,t.lens,0,32,Gy,0,t.work,{bits:5}),Hy=!1}t.lencode=jy,t.lenbits=9,t.distcode=Gy,t.distbits=5}function Wy(t,e,i,r){var n,s=t.state;return null===s.window&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),r>=s.wsize?(dy(s.window,e,i-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):((n=s.wsize-s.wnext)>r&&(n=r),dy(s.window,e,i-r,n,s.wnext),(r-=n)?(dy(s.window,e,i-r,r,0),s.wnext=r,s.whave=s.wsize):(s.wnext+=n,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=n))),0}function Xy(t,e){var i,r,n,s,o,a,c,l,u,h,d,m,f,p,g,y,b,_,x,v,w,A,S,C,P=0,I=new Uint8Array(4),k=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return Fy;(i=t.state).mode===Oy&&(i.mode=13),o=t.next_out,n=t.output,c=t.avail_out,s=t.next_in,r=t.input,a=t.avail_in,l=i.hold,u=i.bits,h=a,d=c,A=By;t:for(;;)switch(i.mode){case Ey:if(0===i.wrap){i.mode=13;break}for(;u<16;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(2&i.wrap&&35615===l){i.check=0,I[0]=255&l,I[1]=l>>>8&255,i.check=py(i.check,I,2,0),l=0,u=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",i.mode=$y;break}if(8!=(15&l)){t.msg="unknown compression method",i.mode=$y;break}if(u-=4,w=8+(15&(l>>>=4)),0===i.wbits)i.wbits=w;else if(w>i.wbits){t.msg="invalid window size",i.mode=$y;break}i.dmax=1<<w,t.adler=i.check=1,i.mode=512&l?10:Oy,l=0,u=0;break;case 2:for(;u<16;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(i.flags=l,8!=(255&i.flags)){t.msg="unknown compression method",i.mode=$y;break}if(57344&i.flags){t.msg="unknown header flags set",i.mode=$y;break}i.head&&(i.head.text=l>>8&1),512&i.flags&&(I[0]=255&l,I[1]=l>>>8&255,i.check=py(i.check,I,2,0)),l=0,u=0,i.mode=3;case 3:for(;u<32;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}i.head&&(i.head.time=l),512&i.flags&&(I[0]=255&l,I[1]=l>>>8&255,I[2]=l>>>16&255,I[3]=l>>>24&255,i.check=py(i.check,I,4,0)),l=0,u=0,i.mode=4;case 4:for(;u<16;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}i.head&&(i.head.xflags=255&l,i.head.os=l>>8),512&i.flags&&(I[0]=255&l,I[1]=l>>>8&255,i.check=py(i.check,I,2,0)),l=0,u=0,i.mode=5;case 5:if(1024&i.flags){for(;u<16;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}i.length=l,i.head&&(i.head.extra_len=l),512&i.flags&&(I[0]=255&l,I[1]=l>>>8&255,i.check=py(i.check,I,2,0)),l=0,u=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&((m=i.length)>a&&(m=a),m&&(i.head&&(w=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),dy(i.head.extra,r,s,m,w)),512&i.flags&&(i.check=py(i.check,r,m,s)),a-=m,s+=m,i.length-=m),i.length))break t;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===a)break t;m=0;do{w=r[s+m++],i.head&&w&&i.length<65536&&(i.head.name+=String.fromCharCode(w))}while(w&&m<a);if(512&i.flags&&(i.check=py(i.check,r,m,s)),a-=m,s+=m,w)break t}else i.head&&(i.head.name=null);i.length=0,i.mode=8;case 8:if(4096&i.flags){if(0===a)break t;m=0;do{w=r[s+m++],i.head&&w&&i.length<65536&&(i.head.comment+=String.fromCharCode(w))}while(w&&m<a);if(512&i.flags&&(i.check=py(i.check,r,m,s)),a-=m,s+=m,w)break t}else i.head&&(i.head.comment=null);i.mode=9;case 9:if(512&i.flags){for(;u<16;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(l!==(65535&i.check)){t.msg="header crc mismatch",i.mode=$y;break}l=0,u=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=Oy;break;case 10:for(;u<32;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}t.adler=i.check=Ny(l),l=0,u=0,i.mode=11;case 11:if(0===i.havedict)return t.next_out=o,t.avail_out=c,t.next_in=s,t.avail_in=a,i.hold=l,i.bits=u,2;t.adler=i.check=1,i.mode=Oy;case Oy:if(5===e||6===e)break t;case 13:if(i.last){l>>>=7&u,u-=7&u,i.mode=27;break}for(;u<3;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}switch(i.last=1&l,u-=1,3&(l>>>=1)){case 0:i.mode=14;break;case 1:if(qy(i),i.mode=20,6===e){l>>>=2,u-=2;break t}break;case 2:i.mode=17;break;case 3:t.msg="invalid block type",i.mode=$y}l>>>=2,u-=2;break;case 14:for(l>>>=7&u,u-=7&u;u<32;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if((65535&l)!=(l>>>16^65535)){t.msg="invalid stored block lengths",i.mode=$y;break}if(i.length=65535&l,l=0,u=0,i.mode=15,6===e)break t;case 15:i.mode=16;case 16:if(m=i.length){if(m>a&&(m=a),m>c&&(m=c),0===m)break t;dy(n,r,s,m,o),a-=m,s+=m,c-=m,o+=m,i.length-=m;break}i.mode=Oy;break;case 17:for(;u<14;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(i.nlen=257+(31&l),l>>>=5,u-=5,i.ndist=1+(31&l),l>>>=5,u-=5,i.ncode=4+(15&l),l>>>=4,u-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=$y;break}i.have=0,i.mode=18;case 18:for(;i.have<i.ncode;){for(;u<3;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}i.lens[k[i.have++]]=7&l,l>>>=3,u-=3}for(;i.have<19;)i.lens[k[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,S={bits:i.lenbits},A=My(0,i.lens,0,19,i.lencode,0,i.work,S),i.lenbits=S.bits,A){t.msg="invalid code lengths set",i.mode=$y;break}i.have=0,i.mode=19;case 19:for(;i.have<i.nlen+i.ndist;){for(;y=(P=i.lencode[l&(1<<i.lenbits)-1])>>>16&255,b=65535&P,!((g=P>>>24)<=u);){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(b<16)l>>>=g,u-=g,i.lens[i.have++]=b;else{if(16===b){for(C=g+2;u<C;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(l>>>=g,u-=g,0===i.have){t.msg="invalid bit length repeat",i.mode=$y;break}w=i.lens[i.have-1],m=3+(3&l),l>>>=2,u-=2}else if(17===b){for(C=g+3;u<C;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}u-=g,w=0,m=3+(7&(l>>>=g)),l>>>=3,u-=3}else{for(C=g+7;u<C;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}u-=g,w=0,m=11+(127&(l>>>=g)),l>>>=7,u-=7}if(i.have+m>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=$y;break}for(;m--;)i.lens[i.have++]=w}}if(i.mode===$y)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=$y;break}if(i.lenbits=9,S={bits:i.lenbits},A=My(Ty,i.lens,0,i.nlen,i.lencode,0,i.work,S),i.lenbits=S.bits,A){t.msg="invalid literal/lengths set",i.mode=$y;break}if(i.distbits=6,i.distcode=i.distdyn,S={bits:i.distbits},A=My(Dy,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,S),i.distbits=S.bits,A){t.msg="invalid distances set",i.mode=$y;break}if(i.mode=20,6===e)break t;case 20:i.mode=21;case 21:if(a>=6&&c>=258){t.next_out=o,t.avail_out=c,t.next_in=s,t.avail_in=a,i.hold=l,i.bits=u,by(t,d),o=t.next_out,n=t.output,c=t.avail_out,s=t.next_in,r=t.input,a=t.avail_in,l=i.hold,u=i.bits,i.mode===Oy&&(i.back=-1);break}for(i.back=0;y=(P=i.lencode[l&(1<<i.lenbits)-1])>>>16&255,b=65535&P,!((g=P>>>24)<=u);){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(y&&!(240&y)){for(_=g,x=y,v=b;y=(P=i.lencode[v+((l&(1<<_+x)-1)>>_)])>>>16&255,b=65535&P,!(_+(g=P>>>24)<=u);){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}l>>>=_,u-=_,i.back+=_}if(l>>>=g,u-=g,i.back+=g,i.length=b,0===y){i.mode=26;break}if(32&y){i.back=-1,i.mode=Oy;break}if(64&y){t.msg="invalid literal/length code",i.mode=$y;break}i.extra=15&y,i.mode=22;case 22:if(i.extra){for(C=i.extra;u<C;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}i.length+=l&(1<<i.extra)-1,l>>>=i.extra,u-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;y=(P=i.distcode[l&(1<<i.distbits)-1])>>>16&255,b=65535&P,!((g=P>>>24)<=u);){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(!(240&y)){for(_=g,x=y,v=b;y=(P=i.distcode[v+((l&(1<<_+x)-1)>>_)])>>>16&255,b=65535&P,!(_+(g=P>>>24)<=u);){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}l>>>=_,u-=_,i.back+=_}if(l>>>=g,u-=g,i.back+=g,64&y){t.msg="invalid distance code",i.mode=$y;break}i.offset=b,i.extra=15&y,i.mode=24;case 24:if(i.extra){for(C=i.extra;u<C;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}i.offset+=l&(1<<i.extra)-1,l>>>=i.extra,u-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=$y;break}i.mode=25;case 25:if(0===c)break t;if(m=d-c,i.offset>m){if((m=i.offset-m)>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=$y;break}m>i.wnext?(m-=i.wnext,f=i.wsize-m):f=i.wnext-m,m>i.length&&(m=i.length),p=i.window}else p=n,f=o-i.offset,m=i.length;m>c&&(m=c),c-=m,i.length-=m;do{n[o++]=p[f++]}while(--m);0===i.length&&(i.mode=21);break;case 26:if(0===c)break t;n[o++]=i.length,c--,i.mode=21;break;case 27:if(i.wrap){for(;u<32;){if(0===a)break t;a--,l|=r[s++]<<u,u+=8}if(d-=c,t.total_out+=d,i.total+=d,d&&(t.adler=i.check=i.flags?py(i.check,n,d,o-d):my(i.check,n,d,o-d)),d=c,(i.flags?l:Ny(l))!==i.check){t.msg="incorrect data check",i.mode=$y;break}l=0,u=0}i.mode=28;case 28:if(i.wrap&&i.flags){for(;u<32;){if(0===a)break t;a--,l+=r[s++]<<u,u+=8}if(l!==(4294967295&i.total)){t.msg="incorrect length check",i.mode=$y;break}l=0,u=0}i.mode=29;case 29:A=1;break t;case $y:A=-3;break t;case 31:return-4;default:return Fy}return t.next_out=o,t.avail_out=c,t.next_in=s,t.avail_in=a,i.hold=l,i.bits=u,(i.wsize||d!==t.avail_out&&i.mode<$y&&(i.mode<27||4!==e))&&Wy(t,t.output,t.next_out,d-t.avail_out),h-=t.avail_in,d-=t.avail_out,t.total_in+=h,t.total_out+=d,i.total+=d,i.wrap&&d&&(t.adler=i.check=i.flags?py(i.check,n,d,t.next_out-d):my(i.check,n,d,t.next_out-d)),t.data_type=i.bits+(i.last?64:0)+(i.mode===Oy?128:0)+(20===i.mode||15===i.mode?256:0),(0===h&&0===d||4===e)&&A===By&&(A=-5),A}function Yy(t,e){var i,r=e.length;return t&&t.state?0!==(i=t.state).wrap&&11!==i.mode?Fy:11===i.mode&&my(1,e,r,0)!==i.check?-3:Wy(t,e,r,r)?(i.mode=31,-4):(i.havedict=1,By):Fy}var Ky=!0,Zy=!0;try{String.fromCharCode.apply(null,[0])}catch(t){Ky=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){Zy=!1}for(var Qy=new Uint8Array(256),Jy=0;Jy<256;Jy++)Qy[Jy]=Jy>=252?6:Jy>=248?5:Jy>=240?4:Jy>=224?3:Jy>=192?2:1;function tb(t){var e,i,r,n,s,o=t.length,a=0;for(n=0;n<o;n++)55296==(64512&(i=t.charCodeAt(n)))&&n+1<o&&56320==(64512&(r=t.charCodeAt(n+1)))&&(i=65536+(i-55296<<10)+(r-56320),n++),a+=i<128?1:i<2048?2:i<65536?3:4;for(e=new Uint8Array(a),s=0,n=0;s<a;n++)55296==(64512&(i=t.charCodeAt(n)))&&n+1<o&&56320==(64512&(r=t.charCodeAt(n+1)))&&(i=65536+(i-55296<<10)+(r-56320),n++),i<128?e[s++]=i:i<2048?(e[s++]=192|i>>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e}function eb(t,e){var i,r,n,s,o=e||t.length,a=new Array(2*o);for(r=0,i=0;i<o;)if((n=t[i++])<128)a[r++]=n;else if((s=Qy[n])>4)a[r++]=65533,i+=s-1;else{for(n&=2===s?31:3===s?15:7;s>1&&i<o;)n=n<<6|63&t[i++],s--;s>1?a[r++]=65533:n<65536?a[r++]=n:(n-=65536,a[r++]=55296|n>>10&1023,a[r++]=56320|1023&n)}return function(t,e){if(e<65537&&(t.subarray&&Zy||!t.subarray&&Ky))return String.fromCharCode.apply(null,hy(t,e));for(var i="",r=0;r<e;r++)i+=String.fromCharCode(t[r]);return i}(a,r)}function ib(t,e){var i;for((e=e||t.length)>t.length&&(e=t.length),i=e-1;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+Qy[t[i]]>e?i:e}Qy[254]=Qy[254]=1;var rb=0,nb={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};function sb(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function ob(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var ab=Object.prototype.toString;function cb(t){if(!(this instanceof cb))return new cb(t);this.options=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(var r in i)i.hasOwnProperty(r)&&(t[r]=i[r])}}return t}({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(15&e.windowBits||(e.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new sb,this.strm.avail_out=0;var i,r,n,s=Uy(this.strm,e.windowBits);if(s!==rb)throw new Error(nb[s]);this.header=new ob,i=this.strm,r=this.header,i&&i.state&&2&(n=i.state).wrap&&(n.head=r,r.done=!1)}cb.prototype.push=function(t,e){var i,r,n,s,o,a,c=this.strm,l=this.options.chunkSize,u=this.options.dictionary,h=!1;if(this.ended)return!1;r=e===~~e?e:!0===e?4:0,"string"==typeof t?c.input=function(t){for(var e=new Uint8Array(t.length),i=0,r=e.length;i<r;i++)e[i]=t.charCodeAt(i);return e}(t):"[object ArrayBuffer]"===ab.call(t)?c.input=new Uint8Array(t):c.input=t,c.next_in=0,c.avail_in=c.input.length;do{if(0===c.avail_out&&(c.output=new Uint8Array(l),c.next_out=0,c.avail_out=l),2===(i=Xy(c,0))&&u&&(a="string"==typeof u?tb(u):"[object ArrayBuffer]"===ab.call(u)?new Uint8Array(u):u,i=Yy(this.strm,a)),-5===i&&!0===h&&(i=rb,h=!1),1!==i&&i!==rb)return this.onEnd(i),this.ended=!0,!1;c.next_out&&(0!==c.avail_out&&1!==i&&(0!==c.avail_in||4!==r&&2!==r)||("string"===this.options.to?(n=ib(c.output,c.next_out),s=c.next_out-n,o=eb(c.output,n),c.next_out=s,c.avail_out=l-s,s&&dy(c.output,c.output,n,s,0),this.onData(o)):this.onData(hy(c.output,c.next_out)))),0===c.avail_in&&0===c.avail_out&&(h=!0)}while((c.avail_in>0||0===c.avail_out)&&1!==i);return 1===i&&(r=4),4===r?(i=function(t){if(!t||!t.state)return Fy;var e=t.state;return e.window&&(e.window=null),t.state=null,By}(this.strm),this.onEnd(i),this.ended=!0,i===rb):2!==r||(this.onEnd(rb),c.avail_out=0,!0)},cb.prototype.onData=function(t){this.chunks.push(t)},cb.prototype.onEnd=function(t){t===rb&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=function(t){var e,i,r,n,s,o;for(r=0,e=0,i=t.length;e<i;e++)r+=t[e].length;for(o=new Uint8Array(r),n=0,e=0,i=t.length;e<i;e++)s=t[e],o.set(s,n),n+=s.length;return o}(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},Vt.add("gz",(function(t){let e;t instanceof ArrayBuffer&&(t=new Uint8Array(t));try{e=function(t,e){var i=new cb(e);if(i.push(t,!0),i.err)throw i.msg;return i.result}(t)}catch(i){e=t}return e}));class lb{}const ub="https:";Rt.add("rcsb",new class extends lb{getUrl(t){const e=Qt(t),i=e.name.indexOf("_")>-1?e.name:e.name.substring(0,4);return!["pdb","cif"].includes(e.ext)||!1!==e.compressed&&"gz"!==e.compressed?("mmtf"===e.ext&&(Dt.warn("MMTF files distribution has been discontinued by RCSB PDB as of July 2024.\n Defaulting to bcif format instead. See https://www.rcsb.org/news/65a1af31c76ca3abcc925d0c for the deprecation notice"),e.base.endsWith(".bb")&&Dt.warn("Backbone only files are not available from RCSB PDB anymore."),e.ext=""),e.ext?Dt.warn("unsupported ext",e.ext):Dt.warn('mmCif files available from RCSB PDB lack connectivity information.\n Consider using PDBe as the data provider for using "Updated mmCif files" that contain residues connectivity records.'),ub+"//models.rcsb.org/"+i+".bcif.gz"):ub+"//files.rcsb.org/download/"+e.path}getExt(t){const e=Qt(t).ext;return e||"bcif"}});const hb="//www.ebi.ac.uk/pdbe/entry-files/download/";Rt.add("pdbe",new class extends lb{getUrl(t){const e=Qt(t);let i,r=e.name.indexOf("_")>-1?e.name:e.name.substring(0,4);switch(e.ext){case"cif":i=hb+r+"_updated.cif";break;case"pdb":case"ent":r.startsWith("pdb")||(r="pdb"+r),i=hb+r+".ent";break;case"bcif":i=hb+e.path;break;case"":i=hb+r+".bcif";break;default:Dt.warn("unsupported ext",e.ext),i=hb+r+".bcif"}return"https://"+i}getExt(t){const e=Qt(t).ext;return e||"bcif"}});const db="//pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/",mb="/SDF?record_type=3d";Rt.add("pubchem",new class extends lb{getUrl(t){const e=Qt(t),i=e.name;let r;return e.ext&&"sdf"!==e.ext?(Dt.warn("unsupported ext",e.ext),r=db+i+mb):r=db+i+mb,function(){const t=window.location.protocol;return null===t.match(/http(s)?:/gi)?"http:":t}()+r}getExt(t){const e=Qt(t).ext;return e||"sdf"}});class fb extends lb{getUrl(t){return t}getExt(t){return Qt(t).ext}}Rt.add("ftp",new fb),Rt.add("http",new fb),Rt.add("https",new fb);const pb="//alphafold.ebi.ac.uk/files/AF-",gb="-F1-model_v4.pdb";Rt.add("alphafold",new class extends lb{getUrl(t){const e=Qt(t),i=e.name;let r;return e.ext&&"pdb"!==e.ext?(Dt.warn("unsupported AF ext",e.ext),r=pb+i+gb):r=pb+i+gb,"https://"+r}getExt(t){const e=Qt(t).ext;return e||"pdb"}});const yb=/^((http|https|ftp):)*\/\//;function bb(t,e){return{type:"integer",max:t,min:e}}function _b(t,e,i){return{type:"number",precision:t,max:e,min:i}}function xb(t,e,i){return{type:"range",step:t,max:e,min:i}}function vb(...t){return{type:"select",options:t.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e]:e})),{})}}const wb={backgroundColor:{type:"color"},quality:vb("auto","low","medium","high"),sampleLevel:xb(1,5,-1),impostor:{type:"boolean"},workerDefault:{type:"boolean"},rotateSpeed:_b(1,10,0),zoomSpeed:_b(1,10,0),panSpeed:_b(1,10,0),clipNear:xb(1,100,0),clipFar:xb(1,100,0),clipDist:bb(200,0),clipMode:vb("scene","camera"),clipScale:vb("relative","absolute"),fogNear:xb(1,100,0),fogFar:xb(1,100,0),cameraType:vb("perspective","orthographic","stereo"),cameraEyeSep:_b(3,1,.01),cameraFov:xb(1,120,15),lightColor:{type:"color"},lightIntensity:_b(2,10,0),ambientColor:{type:"color"},ambientIntensity:_b(2,10,0),hoverTimeout:bb(1e4,-1),tooltip:{type:"boolean"},mousePreset:vb(...Object.keys(zs))};Object.defineProperty(t,"Box3",{enumerable:!0,get:function(){return e.Box3}}),Object.defineProperty(t,"Color",{enumerable:!0,get:function(){return e.Color}}),Object.defineProperty(t,"Euler",{enumerable:!0,get:function(){return e.Euler}}),Object.defineProperty(t,"Matrix3",{enumerable:!0,get:function(){return e.Matrix3}}),Object.defineProperty(t,"Matrix4",{enumerable:!0,get:function(){return e.Matrix4}}),Object.defineProperty(t,"Plane",{enumerable:!0,get:function(){return e.Plane}}),Object.defineProperty(t,"Quaternion",{enumerable:!0,get:function(){return e.Quaternion}}),Object.defineProperty(t,"Vector2",{enumerable:!0,get:function(){return e.Vector2}}),Object.defineProperty(t,"Vector3",{enumerable:!0,get:function(){return e.Vector3}}),Object.defineProperty(t,"Signal",{enumerable:!0,get:function(){return r.Signal}}),t.AngleRepresentation=Ml,t.ArrowBuffer=Ju,t.Assembly=ko,t.AxesRepresentation=Gl,t.BackboneRepresentation=ql,t.BallAndStickRepresentation=Hl,t.BaseRepresentation=Wl,t.BoxBuffer=nh,t.BufferRepresentation=_a,t.CartoonRepresentation=tu,t.Collection=Ja,t.Colormaker=U,t.ColormakerRegistry=$t,t.Component=Qa,t.ComponentCollection=wc,t.ConeBuffer=Ku,t.ContactRepresentation=eu,t.Counter=ne,t.CylinderBuffer=jl,t.DatasourceRegistry=Rt,t.DecompressorRegistry=Vt,t.DihedralHistogramRepresentation=su,t.DihedralRepresentation=iu,t.DistanceRepresentation=au,t.EllipsoidBuffer=uh,t.Frames=rc,t.HelixorientRepresentation=hu,t.HyperballRepresentation=xu,t.IcosahedronBuffer=ph,t.Kdtree=Ao,t.KeyActions=js,t.LabelRepresentation=wu,t.LeftMouseButton=1,t.LicoriceRepresentation=du,t.LineRepresentation=Su,t.MdsrvDatasource=class extends lb{constructor(t=""){super(),this.baseUrl=t}getListing(t=""){let e=`${this.baseUrl}dir/${t}`;return"/"!==e[e.length-1]&&(e+="/"),te(e,{ext:"json"}).then((e=>({path:t,data:e.data})))}getUrl(t){const e=Qt(t);return`${this.baseUrl}file/${e.path}${e.query}`}getCountUrl(t){const e=Qt(t);return`${this.baseUrl}traj/numframes/${e.path}${e.query}`}getFrameUrl(t,e){const i=Qt(t);return`${this.baseUrl}traj/frame/${e}/${i.path}${i.query}`}getFrameParams(t,e){return`atomIndices=${e.join(";")}`}getPathUrl(t,e){const i=Qt(t);return`${this.baseUrl}traj/path/${e}/${i.path}${i.query}`}getExt(t){return Qt(t).ext}},t.MeasurementDefaultParams=Bt,t.MeshBuffer=Bs,t.MiddleMouseButton=2,t.MolecularSurface=Mu,t.MolecularSurfaceRepresentation=Tu,t.MouseActions=Ns,t.OctahedronBuffer=xh,t.ParserRegistry=Nt,t.PdbWriter=class extends ee{constructor(t,e){super(),this.mimeType="text/plain",this.defaultName="structure",this.defaultExt="pdb";const i=Object.assign({},e);this.renumberSerial=l(i.renumberSerial,!0),this.remarks=function(t){return Array.isArray(t)?t:[t]}(l(i.remarks,[])),this.structure=t,this._records=[]}_writeRecords(){this._records.length=0,this._writeTitle(),this._writeRemarks(),this._writeAtoms()}_writeTitle(){this._records.push(n.sprintf("TITLE %-74s",this.structure.name))}_writeRemarks(){this.remarks.forEach((t=>{this._records.push(n.sprintf("REMARK %-73s",t))})),this.structure.trajectory&&(this._records.push(n.sprintf("REMARK %-73s","Trajectory '"+this.structure.trajectory.name+"'")),this._records.push(n.sprintf("REMARK %-73s",`Frame ${this.structure.trajectory.frame}`)))}_writeAtoms(){let t=1,e=1,i=" ",r=" ";const s=this.structure.modelStore.count>1;this.structure.eachModel((o=>{s&&this._records.push(n.sprintf("MODEL     %4d%-66s",e++,"")),o.eachAtom((e=>{const s=e.hetero?"HETATM%5d %-4s %3s %1s%4d    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%1s%1s":"ATOM  %5d %-4s %3s %1s%4d    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%1s%1s",o=this.renumberSerial?t:e.serial;let a=e.atomname;(1===a.length||a.length<4&&1===e.element.length&&a[0]===e.element)&&(a=" "+a),e.formalCharge?(i=Math.abs(e.formalCharge).toPrecision(1),r=e.formalCharge>0?"+":"-"):(i=" ",r=" "),this._records.push(n.sprintf(s,o,a,e.resname,l(e.chainname," "),e.resno,e.x,e.y,e.z,l(e.occupancy,1),l(e.bfactor,0),"",l(e.element,""),i,r)),t+=1}),this.structure.getSelection()),s&&this._records.push(n.sprintf("%-80s","ENDMDL"))})),this._records.push(n.sprintf("%-80s","END"))}getString(){return console.warn("PdbWriter.getString() is deprecated, use .getData instead"),this.getData()}getData(){return this._writeRecords(),this._records.join("\n")}},t.PickingProxy=ai,t.PointBuffer=Oa,t.PointRepresentation=Du,t.Queue=ki,t.RepresentationCollection=tc,t.RepresentationElement=Xa,t.RepresentationRegistry=Lt,t.RibbonRepresentation=Ou,t.RightMouseButton=3,t.RocketRepresentation=$u,t.RopeRepresentation=Ru,t.ScriptExtensions=Et,t.SdfWriter=class extends ee{constructor(t){super(),this.mimeType="text/plain",this.defaultName="structure",this.defaultExt="sdf",this.structure=t,this._records=[]}get idString(){return this.structure.id}get titleString(){return"  "+this.structure.title}get countsString(){return n.sprintf("%3i%3i  0  0  0  0  0  0  0  0999 V2000",this.structure.atomCount,this.structure.bondCount)}get chargeLines(){const t=[];this.structure.eachAtom((e=>{null!=e.formalCharge&&0!==e.formalCharge&&t.push([e.index,e.formalCharge])}));const e=[];for(let i=0;i<t.length;i+=8){const r=Math.min(8,t.length-i);let s=n.sprintf("M  CHG%3i",r);for(let e=i;e<i+r;e++)s+=n.sprintf(" %3i %3i",t[e][0]+1,t[e][1]);e.push(s)}return e}formatAtom(t){let e=0;null!=t.formalCharge&&0!==t.formalCharge&&(e=4-t.formalCharge);const i=n.sprintf("%10.4f%10.4f%10.4f %-3s 0%3i  0  0  0",t.x,t.y,t.z,t.element,e);if(48!==i.length)throw new Error("Incompatible atom for sdf format");return i}formatBond(t){return n.sprintf("%3i%3i%3i  0  0  0",t.atomIndex1+1,t.atomIndex2+1,t.bondOrder)}_writeRecords(){this._records.length=0,this._writeHeader(),this._writeCTab(),this._writeFooter()}_writeHeader(){this._records.push(this.idString,this.titleString,"")}_writeCTab(){this._records.push(this.countsString),this.structure.eachAtom((t=>{this._records.push(this.formatAtom(t))})),this.structure.eachBond((t=>{this._records.push(this.formatBond(t))})),this.chargeLines.forEach((t=>{this._records.push(t)})),this._records.push("M  END")}_writeFooter(){this._records.push("$$$$")}getData(){return this._writeRecords(),this._records.join("\n")}},t.Selection=gt,t.Shape=ba,t.ShapeComponent=Pc,t.SpacefillRepresentation=Lu,t.SpatialHash=xr,t.SphereBuffer=Da,t.Stage=class{constructor(t,e={}){this.signals={parametersChanged:new r.Signal,fullscreenChanged:new r.Signal,componentAdded:new r.Signal,componentRemoved:new r.Signal,clicked:new r.Signal,hovered:new r.Signal},this.tasks=new ne,this.compList=[],this.defaultFileParams={},this.logList=[],this.viewer=new He(t),this.viewer.renderer&&(this.tooltip=document.createElement("div"),Object.assign(this.tooltip.style,{display:"none",position:"fixed",zIndex:"1000000",pointerEvents:"none",backgroundColor:"rgba( 0, 0, 0, 0.6 )",color:"lightgrey",padding:"8px",fontFamily:"sans-serif"}),this.viewer.container.appendChild(this.tooltip),this.mouseObserver=new We(this.viewer.renderer.domElement),this.viewerControls=new yi(this),this.trackballControls=new si(this),this.pickingControls=new ci(this),this.animationControls=new Ii(this),this.mouseControls=new Us(this),this.keyControls=new Hs(this),this.pickingBehavior=new qs(this),this.mouseBehavior=new Ws(this),this.animationBehavior=new Xs(this),this.keyBehavior=new Ks(this),this.spinAnimation=this.animationControls.spin([0,1,0],.005),this.spinAnimation.pause(!0),this.rockAnimation=this.animationControls.rock([0,1,0],.005),this.rockAnimation.pause(!0),this.parameters=u(e,Cc),this.setParameters(this.parameters),this.viewer.animate())}setParameters(t={}){h(this.parameters,t);const e=t,i=this.parameters,r=this.viewer,n=this.trackballControls;return void 0!==e.quality&&this.setQuality(i.quality),void 0!==e.impostor&&this.setImpostor(i.impostor),void 0!==e.rotateSpeed&&(n.rotateSpeed=i.rotateSpeed),void 0!==e.zoomSpeed&&(n.zoomSpeed=i.zoomSpeed),void 0!==e.panSpeed&&(n.panSpeed=i.panSpeed),void 0!==e.mousePreset&&this.mouseControls.preset(i.mousePreset),this.mouseObserver.setParameters({hoverTimeout:i.hoverTimeout}),r.setClip(i.clipNear,i.clipFar,i.clipDist,i.clipMode,i.clipScale),r.setFog(void 0,i.fogNear,i.fogFar),r.setCamera(i.cameraType,i.cameraFov,i.cameraEyeSep),r.setSampling(i.sampleLevel),r.setBackground(i.backgroundColor),r.setLight(i.lightColor,i.lightIntensity,i.ambientColor,i.ambientIntensity),this.signals.parametersChanged.dispatch(this.getParameters()),this}log(t){console.log("STAGE LOG",t),this.logList.push(t)}getParameters(){return Object.assign({},this.parameters)}defaultFileRepresentation(e){if(e instanceof _c){let i,r,n;e.setSelection("/0");const s=e.structure;if(s.biomolDict.BU1){const t=s.biomolDict.BU1;i=t.getAtomCount(s),r=t.getResidueCount(s),n=t.getInstanceCount(),e.setDefaultAssembly("BU1")}else i=s.getModelProxy(0).atomCount,r=s.getModelProxy(0).residueCount,n=1;let o=i;Pt&&(o*=4);const a=s.atomStore.count/s.residueStore.count<2;a&&(o*=10);let c="chainname",l="RdYlBu",u=!1;if(1===s.getChainnameCount(new gt("polymer and /0"))&&(c="residueindex",l="Spectral",u=!0),t.Debug&&console.log(o,i,n,a),r/n<4)e.addRepresentation("ball+stick",{colorScheme:"element",radiusScale:2,aspectRatio:1.5,bondScale:.3,bondSpacing:.75,quality:"auto"});else if(n>5&&o>15e3||o>7e5){let t=Math.min(2,Math.max(.1,6e3/(o/n)));a&&(t=Math.min(t,.5)),e.addRepresentation("surface",{colorScheme:c,colorScale:l,colorReverse:u,sele:"polymer",surfaceType:"av",probeRadius:1.4,scaleFactor:t,useWorker:!1})}else o>25e4?e.addRepresentation("backbone",{colorScheme:c,colorScale:l,colorReverse:u,lineOnly:!0}):o>1e5?e.addRepresentation("backbone",{colorScheme:c,colorScale:l,colorReverse:u,quality:"low",disableImpostor:!0,radiusScale:2}):o>8e4?e.addRepresentation("backbone",{colorScheme:c,colorScale:l,colorReverse:u,radiusScale:2}):(e.addRepresentation("cartoon",{colorScheme:c,colorScale:l,colorReverse:u,radiusScale:.7,aspectRatio:5,quality:"auto"}),o<5e4&&e.addRepresentation("base",{colorScheme:c,colorScale:l,colorReverse:u,quality:"auto"}),e.addRepresentation("ball+stick",{sele:"ligand",colorScheme:"element",radiusScale:2,aspectRatio:1.5,bondScale:.3,bondSpacing:.75,quality:"auto"}));e.structure.frames.length&&e.addTrajectory()}else(e instanceof xc||e instanceof vc)&&e.addRepresentation("surface");this.tasks.onZeroOnce(this.autoView,this)}loadFile(t,e={}){const i=Object.assign({},this.defaultFileParams,e),r=Qt(t).name;this.tasks.increment(),this.log(`loading file '${r}'`);const n=l(i.ext,Qt(t).ext);let s;return s=Nt.isTrajectory(n)?Promise.reject(new Error(`loadFile: ext '${n}' is a trajectory and must be loaded into a structure component`)):te(t,i),s.then((t=>{this.log(`loaded '${r}'`);const e=this.addComponentFromObject(t,i);return i.defaultRepresentation&&this.defaultFileRepresentation(e),this.tasks.decrement(),e}),(t=>{this.tasks.decrement();const e=`error loading file: '${t}'`;throw this.log(e),e}))}loadScript(t){const e=Qt(t).name;return this.log(`loading script '${e}'`),te(t).then((t=>{this.tasks.increment(),this.log(`running script '${e}'`),t.run(this).then((()=>{this.tasks.decrement(),this.log(`finished script '${e}'`)})),this.log(`called script '${e}'`)}),(t=>{this.tasks.decrement();const i=`errored script '${e}' "${t}"`;throw this.log(i),i}))}addComponent(t){t?(this.compList.push(t),this.signals.componentAdded.dispatch(t)):Dt.warn("Stage.addComponent: no component given")}addComponentFromObject(t,e={}){const i=Ut.get(t.type);if(i){const r=new i(this,t,e);return this.addComponent(r),r}Dt.warn("no component for object type",t.type)}removeComponent(t){const e=this.compList.indexOf(t);-1!==e&&(this.compList.splice(e,1),t.dispose(),this.signals.componentRemoved.dispatch(t))}removeAllComponents(){this.compList.slice().forEach((t=>this.removeComponent(t)))}handleResize(){this.viewer.handleResize()}setSize(t,e){const i=this.viewer.container;i!==document.body&&(void 0!==t&&(i.style.width=t),void 0!==e&&(i.style.height=e),this.handleResize())}toggleFullscreen(t){if(!(document.fullscreenEnabled||document.mozFullScreenEnabled||document.webkitFullscreenEnabled||document.msFullscreenEnabled))return void Dt.log("fullscreen mode (currently) not possible");const e=this;function i(){return document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement}function r(){if(!i()&&e.lastFullscreenElement){const t=e.lastFullscreenElement;t.style.width=t.dataset.normalWidth||"",t.style.height=t.dataset.normalHeight||"",document.removeEventListener("fullscreenchange",r),document.removeEventListener("mozfullscreenchange",r),document.removeEventListener("webkitfullscreenchange",r),document.removeEventListener("MSFullscreenChange",r),e.handleResize(),e.signals.fullscreenChanged.dispatch(!1)}}t=t||this.viewer.container,this.lastFullscreenElement=t,i()?document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen():(t.dataset.normalWidth=t.style.width||"",t.dataset.normalHeight=t.style.height||"",t.style.width=window.screen.width+"px",t.style.height=window.screen.height+"px",t.requestFullscreen?t.requestFullscreen():t.msRequestFullscreen?t.msRequestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen&&t.webkitRequestFullscreen(),document.addEventListener("fullscreenchange",r),document.addEventListener("mozfullscreenchange",r),document.addEventListener("webkitfullscreenchange",r),document.addEventListener("MSFullscreenChange",r),this.handleResize(),this.signals.fullscreenChanged.dispatch(!0),setTimeout((function(){e.handleResize()}),100))}setSpin(t){t?(this.spinAnimation.resume(!0),this.rockAnimation.pause(!0)):this.spinAnimation.pause(!0)}setRock(t){t?(this.rockAnimation.resume(!0),this.spinAnimation.pause(!0)):this.rockAnimation.pause(!0)}toggleSpin(){this.setSpin(this.spinAnimation.paused)}toggleRock(){this.setRock(this.rockAnimation.paused)}getFocus(){const t=this.parameters;if("scene"!==t.clipMode)return 0;let e=t.clipNear;return"absolute"===t.clipScale&&(e=this.viewer.absoluteToRelative(e)),2*e}setFocus(t){if("scene"!==this.parameters.clipMode)return;let e,i,r,n;"relative"===this.parameters.clipScale?(e=E(t/2,0,49.9),i=100-e,r=50,n=function(t){return E(t,0,100)}(2*i-50)):(e=this.viewer.relativeToAbsolute(t/2),i=e,r=0,n=2*i),this.setParameters({clipNear:e,clipFar:i,fogNear:r,fogFar:n})}getZoomForBox(t){const e=t.getSize(Sc),i=Math.max(e.x,e.y,e.z),r=Math.min(e.x,e.y,e.z);let n=i+Math.sqrt(r);const s=T(this.viewer.perspectiveCamera.fov),o=this.viewer.width,a=this.viewer.height,c=a<o?1:o/a;return n=Math.abs(.5*n/c/Math.sin(s/2)),n+=this.parameters.clipDist,-n}getBox(){return this.viewer.boundingBox}getZoom(){return this.getZoomForBox(this.getBox())}getCenter(t){return this.getBox().getCenter(t||new e.Vector3)}autoView(t){this.animationControls.zoomMove(this.getCenter(),this.getZoom(),l(t,0))}makeImage(t={}){return new Promise(((e,i)=>{this.tasks.onZeroOnce((()=>{this.tasks.increment(),this.viewer.makeImage(t).then((t=>{this.tasks.decrement(),e(t)})).catch((t=>{this.tasks.decrement(),i(t)}))}))}))}setImpostor(t){this.parameters.impostor=t;const e=["spacefill","ball+stick","licorice","hyperball","backbone","rocket","helixorient","contact","distance","dot"];this.eachRepresentation((function(i){if(!e.includes(i.getType()))return;const r=i.getParameters();r.disableImpostor=!t,i.build(r)}))}setQuality(t){this.parameters.quality=t;const e=["tube","cartoon","ribbon","trace","rope"],i=["spacefill","ball+stick","licorice","hyperball","backbone","rocket","helixorient","contact","distance","dot"];this.eachRepresentation((function(r){const n=r.getParameters();if(!e.includes(r.getType())){if(!i.includes(r.getType()))return;if(!n.disableImpostor)return void(r.repr.quality=t)}n.quality=t,r.build(n)}))}eachComponent(t,e){this.compList.slice().forEach((i=>{void 0!==e&&e!==i.type||t(i)}))}eachRepresentation(t,e){this.eachComponent((i=>{i.reprList.slice().forEach((r=>{void 0!==e&&e!==r.getType()||t(r,i)}))}))}getComponentsByName(t){const e=[];return this.eachComponent((i=>{(void 0===t||Ac(t,i))&&e.push(i)})),new wc(e)}getComponentsByObject(t){const e=[];return this.eachComponent((i=>{i.object===t&&e.push(i)})),new wc(e)}getRepresentationsByName(t){const e=[];return this.eachRepresentation(((i,r)=>{(void 0===t||Ac(t,i))&&e.push(i)})),new tc(e)}measureClear(){this.eachComponent((t=>t.measureClear()),"structure")}measureUpdate(){this.eachComponent((t=>t.measureUpdate()),"structure")}dispose(){this.tasks.dispose(),this.viewer.dispose(),this.mouseObserver.dispose()}},t.StaticDatasource=class extends lb{constructor(t=""){super(),this.baseUrl=t}getUrl(t){const e=Qt(t);let i=this.baseUrl+e.path;return yb.test(this.baseUrl)||(i=function(t){const e=window.location,i=e.pathname,r=i.substring(0,i.lastIndexOf("/")+1);return e.origin+r+t}(i)),i}getExt(t){return Qt(t).ext}},t.StlWriter=class extends ee{constructor(t){super(),this.mimeType="application/vnd.ms-pki.stl",this.defaultName="surface",this.defaultExt="stl",this.surface=t}getData(){const t=this.surface.index.length/3,i=new re(2*t+3*t*4*4+80+4);i.skip(80),i.writeUint32(t);const r=new e.Vector3,n=new e.Vector3,s=new e.Vector3,o=new e.Vector3;for(let e=0;e<t;e++){const t=[this.surface.index[3*e],this.surface.index[3*e+1],this.surface.index[3*e+2]];n.fromArray(this.surface.normal,3*t[0]),s.fromArray(this.surface.normal,3*t[1]),o.fromArray(this.surface.normal,3*t[2]),r.addVectors(n,s).add(o).normalize(),i.writeFloat32(r.x),i.writeFloat32(r.y),i.writeFloat32(r.z);for(let e=0;e<3;e++)r.fromArray(this.surface.position,3*t[e]),i.writeFloat32(r.x),i.writeFloat32(r.y),i.writeFloat32(r.z);i.writeUint16(0)}return new DataView(i.buffer)}},t.Structure=fa,t.StructureComponent=_c,t.StructureComponentDefaultParameters=bc,t.StructureRepresentation=ml,t.Superposition=nc,t.SurfaceComponent=xc,t.TetrahedronBuffer=Ch,t.TextBuffer=Cl,t.TorusBuffer=Dh,t.TraceRepresentation=Vu,t.TrajectoryPlayer=oc,t.TubeRepresentation=Uu,t.UIStageParameters=wb,t.UnitcellRepresentation=ju,t.ValidationRepresentation=Gu,t.Version="2.5.0",t.Viewer=He,t.Volume=Cs,t.VolumeComponent=vc,t.WidelineBuffer=kl,t.autoLoad=te,t.concatStructures=function(e,...i){t.Debug&&Dt.time("concatStructures");const r=new fa(e,""),n=new To(r),s=r.atomStore,o=r.atomMap;s.addField("formalCharge",1,"int8"),s.addField("partialCharge",1,"float32");const a={};let c=0,l=0,u=0;i.forEach((t=>{t.eachAtom((t=>{s.growIfFull(),s.atomTypeId[c]=o.add(t.atomname,t.element),s.x[c]=t.x,s.y[c]=t.y,s.z[c]=t.z,s.serial[c]=t.serial,s.formalCharge[c]=t.formalCharge,s.partialCharge[c]=t.partialCharge,s.altloc[c]=t.altloc,s.occupancy[c]=t.occupancy,s.bfactor[c]=t.bfactor,n.addAtom(t.modelIndex+u,t.chainname,t.chainid,t.resname,t.resno,1===t.hetero,t.sstruc,t.inscode),a[t.index+l]=c,c+=1})),l+=t.atomStore.count,u+=t.modelStore.count}));const h=r.bondStore,d=r.getAtomProxy(),m=r.getAtomProxy();return l=0,i.forEach((t=>{t.eachBond((t=>{d.index=a[t.atomIndex1+l],m.index=a[t.atomIndex2+l],h.addBond(d,m,t.bondOrder)})),l+=t.atomStore.count})),n.finalize(),zo(r,!0),No(r,!0),r.finalizeAtoms(),r.finalizeBonds(),Ho(r),t.Debug&&Dt.timeEnd("concatStructures"),r},t.download=f,t.flatten=function t(e,i){i=l(i,[]);for(let r=0;r<e.length;r++)Array.isArray(e[r])?t(e[r],i):i.push(e[r]);return i},t.getDataInfo=Jt,t.getFileInfo=Qt,t.getQuery=c,t.guessElement=Go,t.setDebug=function(e){t.Debug=e},t.setListingDatasource=function(e){t.ListingDatasource=e},t.setMeasurementDefaultParams=function(t={}){Object.assign(Bt,t)},t.setTrajectoryDatasource=function(e){t.TrajectoryDatasource=e},t.superpose=yc,t.throttle=function(t,e,i){let r,n,s,o=null,a=0;function c(){a=!1===i.leading?0:Date.now(),o=null,s=t.apply(r,n),o||(r=n=null)}return i||(i={}),function(){var l=Date.now();a||!1!==i.leading||(a=l);var u=e-(l-a);return r=this,n=arguments,u<=0||u>e?(o&&(clearTimeout(o),o=null),a=l,s=t.apply(r,n),o||(r=n=null)):o||!1===i.trailing||(o=setTimeout(c,u)),s}},t.uniqueArray=b,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ngl.umd.js.map
