Select Git revision
webpack.config.production.js
-
David Sehnal authoredDavid Sehnal authored
structure-wrapper.ts 5.43 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, { CifFrame } 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';
import { ModelPropertiesProvider } from '../property-provider';
require('util.promisify').shim();
export enum StructureSourceType {
File,
Cache
}
export interface StructureInfo {
sourceType: StructureSourceType;
readTime: number;
parseTime: number;
createModelTime: number;
attachPropsTime: number;
sourceId: string,
entryId: string
}
export interface StructureWrapper {
info: StructureInfo,
isBinary: boolean,
key: string,
approximateSize: number,
models: ArrayLike<Model>,
modelMap: Map<number, Model>,
structureModelMap: Map<number, Structure>,
propertyProvider: ModelPropertiesProvider | undefined,
cifFrame: CifFrame
}
export async function createStructureWrapperFromJob(job: Job, propertyProvider: ModelPropertiesProvider | undefined, allowCache = true): Promise<StructureWrapper> {
if (allowCache && Config.cacheParams.useCache) {
const ret = StructureCache.get(job.key);
if (ret) return ret;
}
const ret = await readStructureWrapper(job.key, job.sourceId, job.entryId, propertyProvider);
if (allowCache && 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)