Skip to content
Snippets Groups Projects
Select Git revision
  • b95e47ce6bd32b9438f5f638e98ce5067b8a2456
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

structure.ts

Blame
  • structure.ts 20.25 KiB
    /**
     * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import * as B from 'benchmark'
    
    import * as util from 'util'
    import * as fs from 'fs'
    import fetch from 'node-fetch'
    import CIF from 'mol-io/reader/cif'
    
    import { Structure, Model, Queries as Q, StructureElement, StructureSelection, StructureSymmetry, StructureQuery, Format, StructureProperties as SP } from 'mol-model/structure'
    //import { Segmentation, OrderedSet } from 'mol-data/int'
    
    import to_mmCIF from 'mol-model/structure/export/mmcif'
    import { Vec3 } from 'mol-math/linear-algebra';
    //import { printUnits } from 'apps/structure-info/model';
    //import { EquivalenceClasses } from 'mol-data/util';
    
    require('util.promisify').shim();
    const readFileAsync = util.promisify(fs.readFile);
    const writeFileAsync = util.promisify(fs.writeFile);
    
    async function readData(path: string) {
        if (path.match(/\.bcif$/)) {
            const input = await readFileAsync(path)
            const data = new Uint8Array(input.byteLength);
            for (let i = 0; i < input.byteLength; i++) data[i] = input[i];
            return data;
        } else {
            return readFileAsync(path, 'utf8');
        }
    }
    
    // (Symbol as any).asyncIterator = (Symbol as any).asyncIterator || Symbol.for('Symbol.asyncIterator');
    
    // interface ProgressGenerator<T> extends AsyncIterableIterator<number | T> {
    //     next(cont?: boolean): Promise<IteratorResult<number | T>>
    // }
    
    // async function *test(): ProgressGenerator<boolean> {
    //     const r = yield await new Promise<number>(res => res(10));
    //     return r;
    // }
    
    // async function runIt(itP: () => ProgressGenerator<boolean>) {
    //     const it = itP();
    //     while (true) {
    //         const { value, done } = await it.next(true);
    //         if (done) return value;
    //     }
    // }
    
    // runIt(test).then(r => console.log('rerdasdasda', r))
    
    export async function readCIF(path: string) {
        console.time('readData');
        const input = await readData(path)
        console.timeEnd('readData');
    
        console.time('parse');
        const comp = typeof input === 'string' ? CIF.parseText(input) : CIF.parseBinary(input);
        const parsed = await comp.run();
        console.timeEnd('parse');
        if (parsed.isError) {
            throw parsed;
        }