Skip to content
Snippets Groups Projects
Select Git revision
  • ci-bullseye
  • master default protected
  • wip/bigtop-3.0.0
  • bio3
  • feature/certificates2
5 results

ctx.yaml

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;
        }