Skip to content
Snippets Groups Projects
Select Git revision
  • 8e1876fc25c219d26b6c9e85a543e7ade324d434
  • 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

array.ts

Blame
  • structure-wrapper.ts 3.60 KiB
    /**
     * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { Structure, Model, Format } from 'mol-model/structure';
    import { PerformanceMonitor } from 'mol-util/performance-monitor';
    import { Cache } from './cache';
    import Config from '../config';
    import CIF from 'mol-io/reader/cif'
    import * as util from 'util'
    import * as fs from 'fs'
    import * as zlib from 'zlib'
    import { Job } from './jobs';
    import { ConsoleLogger } from 'mol-util/console-logger';
    
    require('util.promisify').shim();
    
    export enum StructureSourceType {
        File,
        Cache
    }
    
    export interface StructureInfo {
        sourceType: StructureSourceType;
        readTime: number;
        parseTime: number;
        createModelTime: number;
    
        sourceId: string,
        entryId: string
    }
    
    export class StructureWrapper {
        info: StructureInfo;
    
        key: string;
        approximateSize: number;
        structure: Structure;
    }
    
    export async function getStructure(job: Job): Promise<StructureWrapper> {
        if (Config.cacheParams.useCache) {
            const ret = StructureCache.get(job.key);
            if (ret) return ret;
        }
        const ret = await readStructure(job.key, job.sourceId, job.entryId);
        if (Config.cacheParams.useCache) {
            StructureCache.add(ret);
        }
        return ret;
    }
    
    export const StructureCache = new Cache<StructureWrapper>(s => s.key, s => s.approximateSize);
    const perf = new PerformanceMonitor();
    
    const readFileAsync = util.promisify(fs.readFile);
    const unzipAsync = util.promisify<zlib.InputType, Buffer>(zlib.unzip);
    
    async function readFile(filename: string) {
        const isGz = /\.gz$/i.test(filename);
        if (filename.match(/\.bcif/)) {
            let input = await readFileAsync(filename)
            if (isGz) input = await unzipAsync(input);
            const data = new Uint8Array(input.byteLength);
            for (let i = 0; i < input.byteLength; i++) data[i] = input[i];
            return data;
        } else {
            if (isGz) {