|
@@ -2,6 +2,7 @@
|
|
|
* Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
+ * @author David Sehnal <david.sehnal@gmail.com>
|
|
|
*/
|
|
|
|
|
|
// import * as util from 'util'
|
|
@@ -15,69 +16,77 @@ import CIF from './reader/cif/index'
|
|
|
// const file = 'test.gro'
|
|
|
const file = 'md_1u19_trj.gro'
|
|
|
|
|
|
-export function _gro() {
|
|
|
- fs.readFile(`./examples/${file}`, 'utf8', function (err, input) {
|
|
|
- if (err) {
|
|
|
- return console.log(err);
|
|
|
- }
|
|
|
- // console.log(data);
|
|
|
-
|
|
|
- console.time('parse')
|
|
|
- const parsed = Gro(input)
|
|
|
- console.timeEnd('parse')
|
|
|
- if (parsed.isError) {
|
|
|
- console.log(parsed)
|
|
|
- return;
|
|
|
- }
|
|
|
+async function runGro(input: string) {
|
|
|
+ console.time('parseGro');
|
|
|
+ const comp = Gro(input);
|
|
|
+ const running = comp.runWithContext(new Computation.ObservableContext({ updateRateMs: 250 }));
|
|
|
+ running.subscribe(p => console.log(`[Gro] ${(p.current / p.max * 100).toFixed(2)} (${p.elapsedMs | 0}ms)`));
|
|
|
+ const parsed = await running.result;
|
|
|
+ console.timeEnd('parseGro');
|
|
|
+
|
|
|
+ if (parsed.isError) {
|
|
|
+ console.log(parsed);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- const groFile = parsed.result
|
|
|
+ const groFile = parsed.result
|
|
|
|
|
|
- console.log('structure count: ', groFile.structures.length);
|
|
|
+ console.log('structure count: ', groFile.structures.length);
|
|
|
|
|
|
- const data = groFile.structures[0];
|
|
|
+ const data = groFile.structures[0];
|
|
|
|
|
|
- // const header = groFile.blocks[0].getCategory('header')
|
|
|
- const { header, atoms } = data;
|
|
|
- console.log(JSON.stringify(header, null, 2));
|
|
|
- console.log('number of atoms:', atoms.count);
|
|
|
+ // const header = groFile.blocks[0].getCategory('header')
|
|
|
+ const { header, atoms } = data;
|
|
|
+ console.log(JSON.stringify(header, null, 2));
|
|
|
+ console.log('number of atoms:', atoms.count);
|
|
|
|
|
|
- console.log(`'${atoms.residueNumber.value(1)}'`)
|
|
|
- console.log(`'${atoms.residueName.value(1)}'`)
|
|
|
- console.log(`'${atoms.atomName.value(1)}'`)
|
|
|
- console.log(atoms.z.value(1))
|
|
|
- console.log(`'${atoms.z.value(1)}'`)
|
|
|
+ console.log(`'${atoms.residueNumber.value(1)}'`)
|
|
|
+ console.log(`'${atoms.residueName.value(1)}'`)
|
|
|
+ console.log(`'${atoms.atomName.value(1)}'`)
|
|
|
+ console.log(atoms.z.value(1))
|
|
|
+ console.log(`'${atoms.z.value(1)}'`)
|
|
|
|
|
|
- const n = atoms.count;
|
|
|
- console.log('rowCount', n)
|
|
|
+ const n = atoms.count;
|
|
|
+ console.log('rowCount', n)
|
|
|
|
|
|
- console.time('getFloatArray x')
|
|
|
- const x = atoms.x.toArray({ array: Float32Array })
|
|
|
- console.timeEnd('getFloatArray x')
|
|
|
- console.log(x.length, x[0], x[x.length - 1])
|
|
|
+ console.time('getFloatArray x')
|
|
|
+ const x = atoms.x.toArray({ array: Float32Array })
|
|
|
+ console.timeEnd('getFloatArray x')
|
|
|
+ console.log(x.length, x[0], x[x.length - 1])
|
|
|
|
|
|
- console.time('getFloatArray y')
|
|
|
- const y = atoms.y.toArray({ array: Float32Array })
|
|
|
- console.timeEnd('getFloatArray y')
|
|
|
- console.log(y.length, y[0], y[y.length - 1])
|
|
|
+ console.time('getFloatArray y')
|
|
|
+ const y = atoms.y.toArray({ array: Float32Array })
|
|
|
+ console.timeEnd('getFloatArray y')
|
|
|
+ console.log(y.length, y[0], y[y.length - 1])
|
|
|
|
|
|
- console.time('getFloatArray z')
|
|
|
- const z = atoms.z.toArray({ array: Float32Array })
|
|
|
- console.timeEnd('getFloatArray z')
|
|
|
- console.log(z.length, z[0], z[z.length - 1])
|
|
|
+ console.time('getFloatArray z')
|
|
|
+ const z = atoms.z.toArray({ array: Float32Array })
|
|
|
+ console.timeEnd('getFloatArray z')
|
|
|
+ console.log(z.length, z[0], z[z.length - 1])
|
|
|
|
|
|
- console.time('getIntArray residueNumber')
|
|
|
- const residueNumber = atoms.residueNumber.toArray({ array: Int32Array })
|
|
|
- console.timeEnd('getIntArray residueNumber')
|
|
|
- console.log(residueNumber.length, residueNumber[0], residueNumber[residueNumber.length - 1])
|
|
|
+ console.time('getIntArray residueNumber')
|
|
|
+ const residueNumber = atoms.residueNumber.toArray({ array: Int32Array })
|
|
|
+ console.timeEnd('getIntArray residueNumber')
|
|
|
+ console.log(residueNumber.length, residueNumber[0], residueNumber[residueNumber.length - 1])
|
|
|
+}
|
|
|
+
|
|
|
+async function _gro() {
|
|
|
+ fs.readFile(`./examples/${file}`, 'utf8', function (err, input) {
|
|
|
+ if (err) {
|
|
|
+ return console.log(err);
|
|
|
+ }
|
|
|
+ runGro(input)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+_gro()
|
|
|
+
|
|
|
async function runCIF(input: string | Uint8Array) {
|
|
|
console.time('parseCIF');
|
|
|
const comp = typeof input === 'string' ? CIF.parseText(input) : CIF.parseBinary(input);
|
|
|
-
|
|
|
+
|
|
|
const running = comp.runWithContext(new Computation.ObservableContext({ updateRateMs: 250 }));
|
|
|
- running.subscribe(p => console.log(`${(p.current / p.max * 100).toFixed(2)} (${p.elapsedMs | 0}ms)`));
|
|
|
+ running.subscribe(p => console.log(`[CIF] ${(p.current / p.max * 100).toFixed(2)} (${p.elapsedMs | 0}ms)`));
|
|
|
const parsed = await running.result;
|
|
|
console.timeEnd('parseCIF');
|
|
|
if (parsed.isError) {
|
|
@@ -98,7 +107,7 @@ async function runCIF(input: string | Uint8Array) {
|
|
|
|
|
|
export function _cif() {
|
|
|
let path = `./examples/1cbs_updated.cif`;
|
|
|
- path = 'c:/test/quick/3j3q.cif';
|
|
|
+ path = '../test/3j3q.cif';
|
|
|
fs.readFile(path, 'utf8', function (err, input) {
|
|
|
if (err) {
|
|
|
return console.log(err);
|