molio.js 7.5 KB

1
  1. !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.MOLIO={})}(this,function(t){"use strict";function n(t,n,e){var i=0,r=1;for(45===t.charCodeAt(n)&&(r=-1,n++);n<e;n++){var o=t.charCodeAt(n)-48;if(o>9||o<0)return r*i|0;i=10*i+o|0}return r*i}function e(t,e,i,r){return 43===e.charCodeAt(i)&&i++,t*Math.pow(10,n(e,i,r))}function i(t,n,i){var r=1,o=0,s=0,u=1;for(45===t.charCodeAt(n)&&(r=-1,++n);n<i;){var a=t.charCodeAt(n)-48;if(!(a>=0&&a<10)){if(-2===a){for(++n;n<i;){if(!((a=t.charCodeAt(n)-48)>=0&&a<10))return 53===a||21===a?e(r*(o+s/u),t,n+1,i):r*(o+s/u);s=10*s+a,u*=10,++n}return r*(o+s/u)}if(53===a||21===a)return e(r*o,t,n+1,i);break}o=10*o+a,++n}return r*o}function r(t){for(;t.position<t.length;)switch(t.data.charCodeAt(t.position)){case 10:return t.currentTokenEnd=t.position,++t.position,void++t.currentLineNumber;case 13:return t.currentTokenEnd=t.position,++t.position,++t.currentLineNumber,void(10===t.data.charCodeAt(t.position)&&++t.position);default:++t.position}t.currentTokenEnd=t.position}function o(t){for(;t.position<t.length;)switch(t.data.charCodeAt(t.position)){case 9:case 10:case 13:case 32:return void(t.currentTokenEnd=t.position);default:++t.position}t.currentTokenEnd=t.position}function s(t){for(var n=10;t.position<t.length;){var e=t.data.charCodeAt(t.position);switch(e){case 9:case 32:n=e,++t.position;break;case 10:13!==n&&++t.currentLineNumber,n=e,++t.position;break;case 13:n=e,++t.position,++t.currentLineNumber;break;default:return n}}return n}function u(t){return{data:t,position:0,length:t.length,currentLineNumber:1,currentTokenStart:0,currentTokenEnd:0,numberOfAtoms:0,hasVelocities:!1,numberOfDecimalPlaces:3}}function a(t,n){r(t);for(var e=t.currentTokenStart,i=t.currentTokenEnd,o=t.currentTokenStart,s=e;s<i&&!d(t.data,s);)++s;if(d(t.data,s)){for(var u=s+2;s>e&&c(t.data,s-1);)--s;for(v.add(n,o,s);u<i&&32===t.data.charCodeAt(u);)++u;for(;s>u&&32===t.data.charCodeAt(s-1);)--s;v.add(n,u,i)}else v.add(n,o,s),v.add(n,s,s)}function c(t,n){var e=t.charCodeAt(n);return 32===e||44===e}function d(t,n){var e=t.charCodeAt(n);return(84===e||116===e)&&61===t.charCodeAt(n+1)}function h(t,e){s(t),t.currentTokenStart=t.position,o(t),t.numberOfAtoms=n(t.data,t.currentTokenStart,t.currentTokenEnd),v.add(e,t.currentTokenStart,t.currentTokenEnd),r(t)}function f(t,n){console.log("MOINMOIN");var e=["residueNumber","residueName","atomName","atomNumber","x","y","z"];t.hasVelocities&&e.push("vx","vy","vz");for(var i,o,s,u=[5,5,5,5,8,8,8,8,8,8],a=e.length,c=v.create(2*t.numberOfAtoms*a),d=t.position,h=0;h<t.numberOfAtoms;++h){t.currentTokenStart=t.position,o=t.currentTokenStart;for(var f=0;f<a;++f){for(s=i=o,d=o=i+u[f];s<d&&32===t.data.charCodeAt(s);)++s;for(;d>s&&32===t.data.charCodeAt(d-1);)--d;v.addUnchecked(c,s,d)}t.position=d,r(t)}n.addTable(new k(t.data,"atoms",e,c))}function p(t,n){for(var e=0;e<3;++e)s(t),t.currentTokenStart=t.position,o(t),v.add(n,t.currentTokenStart,t.currentTokenEnd)}function l(t){return w.success(t)}function m(t){var n=u(t),e=new x(t),i=new E(t);e.blocks.push(i);var r=["title","timeInPs","numberOfAtoms","boxX","boxY","boxZ"],o=v.create(2*r.length),s=new k(n.data,"header",r,o);return i.addTable(s),a(n,o),h(n,o),f(n,i),p(n,o),l(e)}var v;!function(t){function n(t){var n=new Int32Array(1.61*t.indices.length|0);n.set(t.indices),t.indices=n,t.indicesLenMinus2=n.length-2|0}t.add=function(t,e,i){t.count>t.indicesLenMinus2&&n(t),t.indices[t.count++]=e,t.indices[t.count++]=i},t.addUnchecked=function(t,n,e){t.indices[t.count++]=n,t.indices[t.count++]=e},t.create=function(t){return{indicesLenMinus2:t-2|0,count:0,indices:new Int32Array(t)}}}(v||(v={}));var g=function(){this.isDefined=!1};g.prototype.getString=function(t){return null},g.prototype.getInteger=function(t){return 0},g.prototype.getFloat=function(t){return 0},g.prototype.getValuePresence=function(t){return 1},g.prototype.areValuesEqual=function(t,n){return!0},g.prototype.stringEquals=function(t,n){return null===n};var b,y=new g;!function(t){t.create=function(){return Object.create(null)},t.get=function(t,n){if(n.length>6)return n;var e=t[n];return void 0!==e?e:(t[n]=n,n)}}(b||(b={}));var C=function(t,n,e,i){this.data=n,this.name=e,this.index=i,this.stringPool=b.create(),this.isDefined=!0,this.indices=t.indices,this.columnCount=t.columnCount};C.prototype.getString=function(t){var n=2*(t*this.columnCount+this.index);return b.get(this.stringPool,this.data.substring(this.indices[n],this.indices[n+1]))},C.prototype.getInteger=function(t){var e=2*(t*this.columnCount+this.index);return n(this.data,this.indices[e],this.indices[e+1])},C.prototype.getFloat=function(t){var n=2*(t*this.columnCount+this.index);return i(this.data,this.indices[n],this.indices[n+1])},C.prototype.stringEquals=function(t,n){var e=this,i=2*(t*this.columnCount+this.index),r=this.indices[i],o=n.length;if(o!==this.indices[i+1]-r)return!1;for(var s=0;s<o;s++)if(e.data.charCodeAt(s+r)!==n.charCodeAt(s))return!1;return!0},C.prototype.areValuesEqual=function(t,n){var e=this,i=2*(t*this.columnCount+this.index),r=2*(n*this.columnCount+this.index),o=this.indices[i],s=this.indices[r],u=this.indices[i+1]-o;if(u!==this.indices[r+1]-s)return!1;for(var a=0;a<u;a++)if(e.data.charCodeAt(a+o)!==e.data.charCodeAt(a+s))return!1;return!0},C.prototype.getValuePresence=function(t){var n=2*(t*this.columnCount+this.index);return this.indices[n]===this.indices[n+1]?1:0};var A=function(t){function n(){t.apply(this,arguments)}return t&&(n.__proto__=t),n.prototype=Object.create(t&&t.prototype),n.prototype.constructor=n,n.prototype.getString=function(n){var e=t.prototype.getString.call(this,n);return"."===e||"?"===e?null:e},n.prototype.getValuePresence=function(t){var n=2*(t*this.columnCount+this.index),e=this.indices[n];if(this.indices[n+1]-e!=1)return 0;var i=this.data.charCodeAt(e);return 46===i?1:63===i?2:0},n}(C),k=function(t,n,e,i){this.name=n,this.indices=i.indices,this.data=t,this.columnCount=e.length,this.rowCount=i.count/2/e.length|0,this.initColumns(e)},T={columnNames:{}};T.columnNames.get=function(){return this.columnNameList},k.prototype.getColumn=function(t){var n=this.columnIndices.get(t);return void 0!==n?new C(this,this.data,t,n):y},k.prototype.initColumns=function(t){var n=this;this.columnIndices=new Map,this.columnNameList=[];for(var e=0;e<t.length;e++)n.columnIndices.set(t[e],e),n.columnNameList.push(t[e])},Object.defineProperties(k.prototype,T);var w;!function(t){function n(){t.apply(this,arguments)}t&&(n.__proto__=t),n.prototype=Object.create(t&&t.prototype),n.prototype.constructor=n,n.prototype.getColumn=function(t){var n=this.columnIndices.get(t);return void 0!==n?new A(this,this.data,t,n):y},n.prototype.initColumns=function(t){var n=this;this.columnIndices=new Map,this.columnNameList=[];for(var e=0;e<t.length;e++){var i=t[e].substr(n.name.length+1);n.columnIndices.set(i,e),n.columnNameList.push(i)}}}(k);!function(t){t.error=function(t,n){return void 0===n&&(n=-1),new L(t,n)},t.success=function(t,n){return void 0===n&&(n=[]),new N(t,n)}}(w||(w={}));var L=function(t,n){this.message=t,this.line=n,this.isError=!0};L.prototype.toString=function(){return this.line>=0?"[Line "+this.line+"] "+this.message:this.message};var N=function(t,n){this.result=t,this.warnings=n,this.isError=!1},x=function(t){this.blocks=[],this.data=t},E=function(t){this.data=t,this.tableMap=new Map,this.tableList=[]};E.prototype.getTable=function(t){return this.tableMap.get(t)},E.prototype.addTable=function(t){this.tableList[this.tableList.length]=t,this.tableMap.set(t.name,t)},t.groReader=function(t){return m(t)},Object.defineProperty(t,"__esModule",{value:!0})});