molio.esm.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * from https://github.com/dsehnal/CIFTools.js
  5. * @author David Sehnal <david.sehnal@gmail.com>
  6. */
  7. /**
  8. * Efficient integer and float parsers.
  9. *
  10. * For the purposes of parsing numbers from the mmCIF data representations,
  11. * up to 4 times faster than JS parseInt/parseFloat.
  12. */
  13. function parseInt(str, start, end) {
  14. var ret = 0, neg = 1;
  15. if (str.charCodeAt(start) === 45 /* - */) {
  16. neg = -1;
  17. start++;
  18. }
  19. for (; start < end; start++) {
  20. var c = str.charCodeAt(start) - 48;
  21. if (c > 9 || c < 0)
  22. { return (neg * ret) | 0; }
  23. else
  24. { ret = (10 * ret + c) | 0; }
  25. }
  26. return neg * ret;
  27. }
  28. function parseScientific(main, str, start, end) {
  29. // handle + in '1e+1' separately.
  30. if (str.charCodeAt(start) === 43 /* + */)
  31. { start++; }
  32. return main * Math.pow(10.0, parseInt(str, start, end));
  33. }
  34. function parseFloat(str, start, end) {
  35. var neg = 1.0, ret = 0.0, point = 0.0, div = 1.0;
  36. if (str.charCodeAt(start) === 45) {
  37. neg = -1.0;
  38. ++start;
  39. }
  40. while (start < end) {
  41. var c = str.charCodeAt(start) - 48;
  42. if (c >= 0 && c < 10) {
  43. ret = ret * 10 + c;
  44. ++start;
  45. }
  46. else if (c === -2) {
  47. ++start;
  48. while (start < end) {
  49. c = str.charCodeAt(start) - 48;
  50. if (c >= 0 && c < 10) {
  51. point = 10.0 * point + c;
  52. div = 10.0 * div;
  53. ++start;
  54. }
  55. else if (c === 53 || c === 21) {
  56. return parseScientific(neg * (ret + point / div), str, start + 1, end);
  57. }
  58. else {
  59. return neg * (ret + point / div);
  60. }
  61. }
  62. return neg * (ret + point / div);
  63. }
  64. else if (c === 53 || c === 21) {
  65. return parseScientific(neg * ret, str, start + 1, end);
  66. }
  67. else
  68. { break; }
  69. }
  70. return neg * ret;
  71. }
  72. /*
  73. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  74. *
  75. * from https://github.com/dsehnal/CIFTools.js
  76. * @author David Sehnal <david.sehnal@gmail.com>
  77. */
  78. /**
  79. * Eat everything until a newline occurs.
  80. */
  81. function eatLine(state) {
  82. while (state.position < state.length) {
  83. switch (state.data.charCodeAt(state.position)) {
  84. case 10:// \n
  85. state.currentTokenEnd = state.position;
  86. ++state.position;
  87. ++state.currentLineNumber;
  88. return;
  89. case 13:// \r
  90. state.currentTokenEnd = state.position;
  91. ++state.position;
  92. ++state.currentLineNumber;
  93. if (state.data.charCodeAt(state.position) === 10) {
  94. ++state.position;
  95. }
  96. return;
  97. default:
  98. ++state.position;
  99. }
  100. }
  101. state.currentTokenEnd = state.position;
  102. }
  103. /**
  104. * Eat everything until a whitespace/newline occurs.
  105. */
  106. function eatValue(state) {
  107. while (state.position < state.length) {
  108. switch (state.data.charCodeAt(state.position)) {
  109. case 9: // \t
  110. case 10: // \n
  111. case 13: // \r
  112. case 32:// ' '
  113. state.currentTokenEnd = state.position;
  114. return;
  115. default:
  116. ++state.position;
  117. break;
  118. }
  119. }
  120. state.currentTokenEnd = state.position;
  121. }
  122. /**
  123. * Skips all the whitespace - space, tab, newline, CR
  124. * Handles incrementing line count.
  125. */
  126. function skipWhitespace(state) {
  127. var prev = 10;
  128. while (state.position < state.length) {
  129. var c = state.data.charCodeAt(state.position);
  130. switch (c) {
  131. case 9: // '\t'
  132. case 32:// ' '
  133. prev = c;
  134. ++state.position;
  135. break;
  136. case 10:// \n
  137. // handle \r\n
  138. if (prev !== 13) {
  139. ++state.currentLineNumber;
  140. }
  141. prev = c;
  142. ++state.position;
  143. break;
  144. case 13:// \r
  145. prev = c;
  146. ++state.position;
  147. ++state.currentLineNumber;
  148. break;
  149. default:
  150. return prev;
  151. }
  152. }
  153. return prev;
  154. }
  155. /*
  156. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  157. *
  158. * from https://github.com/dsehnal/CIFTools.js
  159. * @author David Sehnal <david.sehnal@gmail.com>
  160. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  161. */
  162. var Tokens;
  163. (function (Tokens) {
  164. function resize(tokens) {
  165. // scale the size using golden ratio, because why not.
  166. var newBuffer = new Int32Array((1.61 * tokens.indices.length) | 0);
  167. newBuffer.set(tokens.indices);
  168. tokens.indices = newBuffer;
  169. tokens.indicesLenMinus2 = (newBuffer.length - 2) | 0;
  170. }
  171. function add(tokens, start, end) {
  172. if (tokens.count > tokens.indicesLenMinus2) {
  173. resize(tokens);
  174. }
  175. tokens.indices[tokens.count++] = start;
  176. tokens.indices[tokens.count++] = end;
  177. }
  178. Tokens.add = add;
  179. function addUnchecked(tokens, start, end) {
  180. tokens.indices[tokens.count++] = start;
  181. tokens.indices[tokens.count++] = end;
  182. }
  183. Tokens.addUnchecked = addUnchecked;
  184. function create(size) {
  185. return {
  186. indicesLenMinus2: (size - 2) | 0,
  187. count: 0,
  188. indices: new Int32Array(size)
  189. };
  190. }
  191. Tokens.create = create;
  192. })(Tokens || (Tokens = {}));
  193. /*
  194. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  195. *
  196. * from https://github.com/dsehnal/CIFTools.js
  197. * @author David Sehnal <david.sehnal@gmail.com>
  198. */
  199. /**
  200. * Represents a column that is not present.
  201. */
  202. var _UndefinedColumn = function _UndefinedColumn() {
  203. this.isDefined = false;
  204. };
  205. _UndefinedColumn.prototype.getString = function getString (row) { return null; };
  206. _UndefinedColumn.prototype.getInteger = function getInteger (row) { return 0; };
  207. _UndefinedColumn.prototype.getFloat = function getFloat (row) { return 0.0; };
  208. _UndefinedColumn.prototype.getValuePresence = function getValuePresence (row) { return 1 /* NotSpecified */; };
  209. _UndefinedColumn.prototype.areValuesEqual = function areValuesEqual (rowA, rowB) { return true; };
  210. _UndefinedColumn.prototype.stringEquals = function stringEquals (row, value) { return value === null; };
  211. var UndefinedColumn = new _UndefinedColumn();
  212. /*
  213. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  214. *
  215. * from https://github.com/dsehnal/CIFTools.js
  216. * @author David Sehnal <david.sehnal@gmail.com>
  217. */
  218. var ShortStringPool;
  219. (function (ShortStringPool) {
  220. function create() { return Object.create(null); }
  221. ShortStringPool.create = create;
  222. function get(pool, str) {
  223. if (str.length > 6)
  224. { return str; }
  225. var value = pool[str];
  226. if (value !== void 0)
  227. { return value; }
  228. pool[str] = str;
  229. return str;
  230. }
  231. ShortStringPool.get = get;
  232. })(ShortStringPool || (ShortStringPool = {}));
  233. /*
  234. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  235. *
  236. * from https://github.com/dsehnal/CIFTools.js
  237. * @author David Sehnal <david.sehnal@gmail.com>
  238. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  239. */
  240. /**
  241. * Represents a single column.
  242. */
  243. var TextColumn = function TextColumn(table, data, name, index) {
  244. this.data = data;
  245. this.name = name;
  246. this.index = index;
  247. this.stringPool = ShortStringPool.create();
  248. this.isDefined = true;
  249. this.indices = table.indices;
  250. this.columnCount = table.columnCount;
  251. };
  252. /**
  253. * Returns the string value at given row.
  254. */
  255. TextColumn.prototype.getString = function getString (row) {
  256. var i = (row * this.columnCount + this.index) * 2;
  257. return ShortStringPool.get(this.stringPool, this.data.substring(this.indices[i], this.indices[i + 1]));
  258. };
  259. /**
  260. * Returns the integer value at given row.
  261. */
  262. TextColumn.prototype.getInteger = function getInteger (row) {
  263. var i = (row * this.columnCount + this.index) * 2;
  264. return parseInt(this.data, this.indices[i], this.indices[i + 1]);
  265. };
  266. /**
  267. * Returns the float value at given row.
  268. */
  269. TextColumn.prototype.getFloat = function getFloat (row) {
  270. var i = (row * this.columnCount + this.index) * 2;
  271. return parseFloat(this.data, this.indices[i], this.indices[i + 1]);
  272. };
  273. /**
  274. * Returns true if the token has the specified string value.
  275. */
  276. TextColumn.prototype.stringEquals = function stringEquals (row, value) {
  277. var this$1 = this;
  278. var aIndex = (row * this.columnCount + this.index) * 2, s = this.indices[aIndex], len = value.length;
  279. if (len !== this.indices[aIndex + 1] - s)
  280. { return false; }
  281. for (var i = 0; i < len; i++) {
  282. if (this$1.data.charCodeAt(i + s) !== value.charCodeAt(i))
  283. { return false; }
  284. }
  285. return true;
  286. };
  287. /**
  288. * Determines if values at the given rows are equal.
  289. */
  290. TextColumn.prototype.areValuesEqual = function areValuesEqual (rowA, rowB) {
  291. var this$1 = this;
  292. var aIndex = (rowA * this.columnCount + this.index) * 2;
  293. var bIndex = (rowB * this.columnCount + this.index) * 2;
  294. var aS = this.indices[aIndex];
  295. var bS = this.indices[bIndex];
  296. var len = this.indices[aIndex + 1] - aS;
  297. if (len !== this.indices[bIndex + 1] - bS)
  298. { return false; }
  299. for (var i = 0; i < len; i++) {
  300. if (this$1.data.charCodeAt(i + aS) !== this$1.data.charCodeAt(i + bS)) {
  301. return false;
  302. }
  303. }
  304. return true;
  305. };
  306. TextColumn.prototype.getValuePresence = function getValuePresence (row) {
  307. var index = 2 * (row * this.columnCount + this.index);
  308. if (this.indices[index] === this.indices[index + 1]) {
  309. return 1 /* NotSpecified */;
  310. }
  311. return 0 /* Present */;
  312. };
  313. var CifColumn = (function (TextColumn) {
  314. function CifColumn () {
  315. TextColumn.apply(this, arguments);
  316. }
  317. if ( TextColumn ) CifColumn.__proto__ = TextColumn;
  318. CifColumn.prototype = Object.create( TextColumn && TextColumn.prototype );
  319. CifColumn.prototype.constructor = CifColumn;
  320. CifColumn.prototype.getString = function getString (row) {
  321. var ret = TextColumn.prototype.getString.call(this, row);
  322. if (ret === '.' || ret === '?')
  323. { return null; }
  324. return ret;
  325. };
  326. /**
  327. * Returns true if the value is not defined (. or ? token).
  328. */
  329. CifColumn.prototype.getValuePresence = function getValuePresence (row) {
  330. var index = 2 * (row * this.columnCount + this.index);
  331. var s = this.indices[index];
  332. if (this.indices[index + 1] - s !== 1)
  333. { return 0 /* Present */; }
  334. var v = this.data.charCodeAt(s);
  335. if (v === 46 /* . */)
  336. { return 1 /* NotSpecified */; }
  337. if (v === 63 /* ? */)
  338. { return 2 /* Unknown */; }
  339. return 0 /* Present */;
  340. };
  341. return CifColumn;
  342. }(TextColumn));
  343. /*
  344. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  345. *
  346. * from https://github.com/dsehnal/CIFTools.js
  347. * @author David Sehnal <david.sehnal@gmail.com>
  348. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  349. */
  350. /**
  351. * Represents a category backed by a string.
  352. */
  353. var TextCategory = function TextCategory(data, name, columns, tokens) {
  354. this.name = name;
  355. this.indices = tokens.indices;
  356. this.data = data;
  357. this.columnCount = columns.length;
  358. this.rowCount = (tokens.count / 2 / columns.length) | 0;
  359. this.initColumns(columns);
  360. };
  361. var prototypeAccessors = { columnNames: {} };
  362. prototypeAccessors.columnNames.get = function () {
  363. return this.columnNameList;
  364. };
  365. /**
  366. * Get a column object that makes accessing data easier.
  367. */
  368. TextCategory.prototype.getColumn = function getColumn (name) {
  369. var i = this.columnIndices.get(name);
  370. if (i !== void 0)
  371. { return new TextColumn(this, this.data, name, i); }
  372. return UndefinedColumn;
  373. };
  374. TextCategory.prototype.initColumns = function initColumns (columns) {
  375. var this$1 = this;
  376. this.columnIndices = new Map();
  377. this.columnNameList = [];
  378. for (var i = 0; i < columns.length; i++) {
  379. this$1.columnIndices.set(columns[i], i);
  380. this$1.columnNameList.push(columns[i]);
  381. }
  382. };
  383. Object.defineProperties( TextCategory.prototype, prototypeAccessors );
  384. var CifCategory = (function (TextCategory) {
  385. function CifCategory () {
  386. TextCategory.apply(this, arguments);
  387. }
  388. if ( TextCategory ) CifCategory.__proto__ = TextCategory;
  389. CifCategory.prototype = Object.create( TextCategory && TextCategory.prototype );
  390. CifCategory.prototype.constructor = CifCategory;
  391. CifCategory.prototype.getColumn = function getColumn (name) {
  392. var i = this.columnIndices.get(name);
  393. if (i !== void 0)
  394. { return new CifColumn(this, this.data, name, i); }
  395. return UndefinedColumn;
  396. };
  397. CifCategory.prototype.initColumns = function initColumns (columns) {
  398. var this$1 = this;
  399. this.columnIndices = new Map();
  400. this.columnNameList = [];
  401. for (var i = 0; i < columns.length; i++) {
  402. var colName = columns[i].substr(this$1.name.length + 1);
  403. this$1.columnIndices.set(colName, i);
  404. this$1.columnNameList.push(colName);
  405. }
  406. };
  407. return CifCategory;
  408. }(TextCategory));
  409. /*
  410. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  411. *
  412. * from https://github.com/dsehnal/CIFTools.js
  413. * @author David Sehnal <david.sehnal@gmail.com>
  414. */
  415. var ParserResult;
  416. (function (ParserResult) {
  417. function error(message, line) {
  418. if ( line === void 0 ) line = -1;
  419. return new ParserError(message, line);
  420. }
  421. ParserResult.error = error;
  422. function success(result, warnings) {
  423. if ( warnings === void 0 ) warnings = [];
  424. return new ParserSuccess(result, warnings);
  425. }
  426. ParserResult.success = success;
  427. })(ParserResult || (ParserResult = {}));
  428. var ParserError = function ParserError(message, line) {
  429. this.message = message;
  430. this.line = line;
  431. this.isError = true;
  432. };
  433. ParserError.prototype.toString = function toString () {
  434. if (this.line >= 0) {
  435. return ("[Line " + (this.line) + "] " + (this.message));
  436. }
  437. return this.message;
  438. };
  439. var ParserSuccess = function ParserSuccess(result, warnings) {
  440. this.result = result;
  441. this.warnings = warnings;
  442. this.isError = false;
  443. };
  444. /*
  445. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  446. *
  447. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  448. */
  449. var GroFile = function GroFile(data) {
  450. this.blocks = [];
  451. this.data = data;
  452. };
  453. var GroBlock = function GroBlock(data) {
  454. this.data = data;
  455. this.categoryMap = new Map();
  456. this.categoryList = [];
  457. };
  458. GroBlock.prototype.getCategory = function getCategory (name) {
  459. return this.categoryMap.get(name);
  460. };
  461. /**
  462. * Adds a category.
  463. */
  464. GroBlock.prototype.addCategory = function addCategory (category) {
  465. this.categoryList[this.categoryList.length] = category;
  466. this.categoryMap.set(category.name, category);
  467. };
  468. function createTokenizer(data) {
  469. return {
  470. data: data,
  471. position: 0,
  472. length: data.length,
  473. currentLineNumber: 1,
  474. currentTokenStart: 0,
  475. currentTokenEnd: 0,
  476. numberOfAtoms: 0,
  477. hasVelocities: false,
  478. numberOfDecimalPlaces: 3
  479. };
  480. }
  481. /**
  482. * title string (free format string, optional time in ps after 't=')
  483. */
  484. function handleTitleString(state, tokens) {
  485. eatLine(state);
  486. // console.log('title', state.data.substring(state.currentTokenStart, state.currentTokenEnd))
  487. var start = state.currentTokenStart;
  488. var end = state.currentTokenEnd;
  489. var valueStart = state.currentTokenStart;
  490. var valueEnd = start;
  491. while (valueEnd < end && !isTime(state.data, valueEnd))
  492. { ++valueEnd; }
  493. if (isTime(state.data, valueEnd)) {
  494. var timeStart = valueEnd + 2;
  495. while (valueEnd > start && isSpaceOrComma(state.data, valueEnd - 1))
  496. { --valueEnd; }
  497. Tokens.add(tokens, valueStart, valueEnd); // title
  498. while (timeStart < end && state.data.charCodeAt(timeStart) === 32)
  499. { ++timeStart; }
  500. while (valueEnd > timeStart && state.data.charCodeAt(valueEnd - 1) === 32)
  501. { --valueEnd; }
  502. Tokens.add(tokens, timeStart, end); // time
  503. }
  504. else {
  505. Tokens.add(tokens, valueStart, valueEnd); // title
  506. Tokens.add(tokens, valueEnd, valueEnd); // empty token for time
  507. }
  508. }
  509. function isSpaceOrComma(data, position) {
  510. var c = data.charCodeAt(position);
  511. return c === 32 || c === 44;
  512. }
  513. function isTime(data, position) {
  514. // T/t
  515. var c = data.charCodeAt(position);
  516. if (c !== 84 && c !== 116)
  517. { return false; }
  518. // =
  519. if (data.charCodeAt(position + 1) !== 61)
  520. { return false; }
  521. return true;
  522. }
  523. // function isDot(state: TokenizerState): boolean {
  524. // // .
  525. // if (state.data.charCodeAt(state.currentTokenStart) !== 46) return false;
  526. // return true;
  527. // }
  528. // function numberOfDecimalPlaces (state: TokenizerState) {
  529. // // var ndec = firstLines[ 2 ].length - firstLines[ 2 ].lastIndexOf('.') - 1
  530. // const start = state.currentTokenStart
  531. // const end = state.currentTokenEnd
  532. // for (let i = end; start < i; --i) {
  533. // // .
  534. // if (state.data.charCodeAt(i) === 46) return end - start - i
  535. // }
  536. // throw new Error('Could not determine number of decimal places')
  537. // }
  538. /**
  539. * number of atoms (free format integer)
  540. */
  541. function handleNumberOfAtoms(state, tokens) {
  542. skipWhitespace(state);
  543. state.currentTokenStart = state.position;
  544. eatValue(state);
  545. state.numberOfAtoms = parseInt(state.data, state.currentTokenStart, state.currentTokenEnd);
  546. Tokens.add(tokens, state.currentTokenStart, state.currentTokenEnd);
  547. eatLine(state);
  548. }
  549. // function checkForVelocities (state: GroState) {
  550. // }
  551. /**
  552. * This format is fixed, ie. all columns are in a fixed position.
  553. * Optionally (for now only yet with trjconv) you can write gro files
  554. * with any number of decimal places, the format will then be n+5
  555. * positions with n decimal places (n+1 for velocities) in stead
  556. * of 8 with 3 (with 4 for velocities). Upon reading, the precision
  557. * will be inferred from the distance between the decimal points
  558. * (which will be n+5). Columns contain the following information
  559. * (from left to right):
  560. * residue number (5 positions, integer)
  561. * residue name (5 characters)
  562. * atom name (5 characters)
  563. * atom number (5 positions, integer)
  564. * position (in nm, x y z in 3 columns, each 8 positions with 3 decimal places)
  565. * velocity (in nm/ps (or km/s), x y z in 3 columns, each 8 positions with 4 decimal places)
  566. */
  567. function handleAtoms(state, block) {
  568. console.log('MOINMOIN');
  569. var name = 'atoms';
  570. var columns = ['residueNumber', 'residueName', 'atomName', 'atomNumber', 'x', 'y', 'z'];
  571. if (state.hasVelocities) {
  572. columns.push('vx', 'vy', 'vz');
  573. }
  574. var fieldSizes = [5, 5, 5, 5, 8, 8, 8, 8, 8, 8];
  575. var columnCount = columns.length;
  576. var tokens = Tokens.create(state.numberOfAtoms * 2 * columnCount);
  577. var start;
  578. var end;
  579. var valueStart;
  580. var valueEnd = state.position;
  581. for (var i = 0; i < state.numberOfAtoms; ++i) {
  582. state.currentTokenStart = state.position;
  583. end = state.currentTokenStart;
  584. for (var j = 0; j < columnCount; ++j) {
  585. start = end;
  586. end = start + fieldSizes[j];
  587. // trim
  588. valueStart = start;
  589. valueEnd = end;
  590. while (valueStart < valueEnd && state.data.charCodeAt(valueStart) === 32)
  591. { ++valueStart; }
  592. while (valueEnd > valueStart && state.data.charCodeAt(valueEnd - 1) === 32)
  593. { --valueEnd; }
  594. Tokens.addUnchecked(tokens, valueStart, valueEnd);
  595. }
  596. state.position = valueEnd;
  597. eatLine(state);
  598. }
  599. block.addCategory(new TextCategory(state.data, name, columns, tokens));
  600. }
  601. /**
  602. * box vectors (free format, space separated reals), values:
  603. * v1(x) v2(y) v3(z) v1(y) v1(z) v2(x) v2(z) v3(x) v3(y),
  604. * the last 6 values may be omitted (they will be set to zero).
  605. * Gromacs only supports boxes with v1(y)=v1(z)=v2(z)=0.
  606. */
  607. function handleBoxVectors(state, tokens) {
  608. // just read the first three values, ignore any remaining
  609. for (var i = 0; i < 3; ++i) {
  610. skipWhitespace(state);
  611. state.currentTokenStart = state.position;
  612. eatValue(state);
  613. Tokens.add(tokens, state.currentTokenStart, state.currentTokenEnd);
  614. }
  615. }
  616. /**
  617. * Creates an error result.
  618. */
  619. // function error(line: number, message: string) {
  620. // return ParserResult.error<GroFile>(message, line);
  621. // }
  622. /**
  623. * Creates a data result.
  624. */
  625. function result(data) {
  626. return ParserResult.success(data);
  627. }
  628. function parseInternal(data) {
  629. var state = createTokenizer(data);
  630. var file = new GroFile(data);
  631. var block = new GroBlock(data);
  632. file.blocks.push(block);
  633. var headerColumns = ['title', 'timeInPs', 'numberOfAtoms', 'boxX', 'boxY', 'boxZ'];
  634. var headerTokens = Tokens.create(2 * headerColumns.length);
  635. var header = new TextCategory(state.data, 'header', headerColumns, headerTokens);
  636. block.addCategory(header);
  637. handleTitleString(state, headerTokens);
  638. handleNumberOfAtoms(state, headerTokens);
  639. handleAtoms(state, block);
  640. handleBoxVectors(state, headerTokens);
  641. return result(file);
  642. }
  643. function parse(data) {
  644. return parseInternal(data);
  645. }
  646. /*
  647. * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
  648. *
  649. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  650. */
  651. export { parse as groReader };
  652. //# sourceMappingURL=molio.esm.js.map