Browse Source

Include CifFrame in Format.mmCif, fix makeBuckets

David Sehnal 6 years ago
parent
commit
31c3955f1c

+ 6 - 7
src/apps/structure-info/model.ts

@@ -9,12 +9,11 @@ import * as argparse from 'argparse'
 require('util.promisify').shim();
 
 // import { Table } from 'mol-data/db'
-import CIF from 'mol-io/reader/cif'
-import { Model, Structure, Element, Unit, Queries } from 'mol-model/structure'
+import { CifFrame } from 'mol-io/reader/cif'
+import { Model, Structure, Element, Unit, Queries, Format } from 'mol-model/structure'
 // import { Run, Progress } from 'mol-task'
 import { OrderedSet } from 'mol-data/int';
 import { Table } from 'mol-data/db';
-import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif';
 import { openCif, downloadCif } from './helpers';
 import { BitFlags } from 'mol-util';
 import { SecondaryStructureType } from 'mol-model/structure/model/types';
@@ -24,12 +23,12 @@ import { UnitRings } from 'mol-model/structure/structure/unit/rings';
 async function downloadFromPdb(pdb: string) {
     // `https://files.rcsb.org/download/${pdb}.cif`
     const parsed = await downloadCif(`http://www.ebi.ac.uk/pdbe/static/entry/${pdb}_updated.cif`, false);
-    return CIF.schema.mmCIF(parsed.blocks[0]);
+    return parsed.blocks[0];
 }
 
 async function readPdbFile(path: string) {
     const parsed = await openCif(path);
-    return CIF.schema.mmCIF(parsed.blocks[0]);
+    return parsed.blocks[0];
 }
 
 export function atomLabel(model: Model, aI: number) {
@@ -189,8 +188,8 @@ export function printIHMModels(model: Model) {
     console.log(Table.formatToString(model.coarseHierarchy.models));
 }
 
-async function run(mmcif: mmCIF_Database) {
-    const models = await Model.create({ kind: 'mmCIF', data: mmcif }).run();
+async function run(frame: CifFrame) {
+    const models = await Model.create(Format.mmCIF(frame)).run();
     const structure = Structure.ofModel(models[0]);
     //printSequence(models[0]);
     //printIHMModels(models[0]);

+ 1 - 1
src/mol-data/util/buckets.ts

@@ -54,7 +54,7 @@ function _makeBuckets(indices: Helpers.ArrayLike<number>,
     }
 
     if (sortBuckets && !sorted) {
-        sort(bucketList, start, end, sortAsc, arraySwap);
+        sort(bucketList, 0, bucketList.length, sortAsc, arraySwap);
     }
 
     let offset = 0;

+ 6 - 1
src/mol-model/structure/model/format.ts

@@ -6,6 +6,7 @@
 
 // import { File as GroFile } from 'mol-io/reader/gro/schema'
 import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif'
+import CIF, { CifFrame } from 'mol-io/reader/cif';
 
 type Format =
     // | Format.gro
@@ -13,7 +14,11 @@ type Format =
 
 namespace Format {
     // export interface gro { kind: 'gro', data: GroFile }
-    export interface mmCIF { kind: 'mmCIF', data: mmCIF_Database }
+    export interface mmCIF { kind: 'mmCIF', data: mmCIF_Database, frame: CifFrame }
+
+    export function mmCIF(frame: CifFrame, data?: mmCIF_Database): mmCIF {
+        return { kind: 'mmCIF', data: data || CIF.schema.mmCIF(frame), frame };
+    }
 }
 
 export default Format

+ 4 - 4
src/mol-view/state/entity.ts

@@ -8,7 +8,7 @@ import { readFileAs, readUrlAs } from 'mol-util/read'
 import { idFactory } from 'mol-util/id-factory'
 import { StateContext } from './context';
 import { getFileInfo } from 'mol-util/file-info';
-import { CifFile } from 'mol-io/reader/cif';
+import { CifFile, CifFrame } from 'mol-io/reader/cif';
 import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif';
 import { Model, Structure } from 'mol-model/structure';
 import { StructureRepresentation } from 'mol-geo/representation/structure';
@@ -94,10 +94,10 @@ export namespace CifEntity {
     }
 }
 
-export type MmcifEntity = StateEntity<mmCIF_Database, 'mmcif'>
+export type MmcifEntity = StateEntity<{ db: mmCIF_Database, frame: CifFrame }, 'mmcif'>
 export namespace MmcifEntity {
-    export function ofMmcifDb(ctx: StateContext, db: mmCIF_Database): MmcifEntity {
-        return StateEntity.create(ctx, 'mmcif', db)
+    export function ofMmcifDb(ctx: StateContext, mmCif: { db: mmCIF_Database, frame: CifFrame }): MmcifEntity {
+        return StateEntity.create(ctx, 'mmcif', mmCif)
     }
 }
 

+ 4 - 3
src/mol-view/state/transform.ts

@@ -6,7 +6,7 @@
 
 import CIF from 'mol-io/reader/cif'
 import { FileEntity, DataEntity, UrlEntity, CifEntity, MmcifEntity, ModelEntity, StructureEntity, SpacefillEntity, AnyEntity, NullEntity, BondEntity } from './entity';
-import { Model, Structure } from 'mol-model/structure';
+import { Model, Structure, Format } from 'mol-model/structure';
 
 import { StateContext } from './context';
 import Spacefill, { SpacefillProps } from 'mol-geo/representation/structure/spacefill';
@@ -55,13 +55,14 @@ export const DataToCif: DataToCif = StateTransform.create('data', 'cif', 'data-t
 export type CifToMmcif = StateTransform<CifEntity, MmcifEntity, {}>
 export const CifToMmcif: CifToMmcif = StateTransform.create('cif', 'mmcif', 'cif-to-mmcif',
     async function (ctx: StateContext, cifEntity: CifEntity) {
-        return MmcifEntity.ofMmcifDb(ctx, CIF.schema.mmCIF(cifEntity.value.blocks[0]))
+        const frame = cifEntity.value.blocks[0];
+        return MmcifEntity.ofMmcifDb(ctx, { frame, db: CIF.schema.mmCIF(frame) })
     })
 
 export type MmcifToModel = StateTransform<MmcifEntity, ModelEntity, {}>
 export const MmcifToModel: MmcifToModel = StateTransform.create('mmcif', 'model', 'mmcif-to-model',
     async function (ctx: StateContext, mmcifEntity: MmcifEntity) {
-        const models = await Model.create({ kind: 'mmCIF', data: mmcifEntity.value }).run(ctx.log)
+        const models = await Model.create(Format.mmCIF(mmcifEntity.value.frame, mmcifEntity.value.db)).run(ctx.log)
         return ModelEntity.ofModels(ctx, models)
     })
 

+ 4 - 5
src/perf-tests/lookup3d.ts

@@ -2,7 +2,7 @@ import * as util from 'util'
 import * as fs from 'fs'
 import CIF from 'mol-io/reader/cif'
 
-import { Structure, Model } from 'mol-model/structure'
+import { Structure, Model, Format } from 'mol-model/structure'
 
 import { GridLookup3D } from 'mol-math/geometry';
 // import { sortArray } from 'mol-data/util';
@@ -31,12 +31,11 @@ export async function readCIF(path: string) {
         throw parsed;
     }
 
-    const data = parsed.result.blocks[0];
-    const mmcif = CIF.schema.mmCIF(data);
-    const models = await Model.create({ kind: 'mmCIF', data: mmcif }).run();
+    const mmcif = Format.mmCIF(parsed.result.blocks[0]);
+    const models = await Model.create(mmcif).run();
     const structures = models.map(Structure.ofModel);
 
-    return { mmcif, models, structures };
+    return { mmcif: mmcif.data, models, structures };
 }
 
 export async function test() {

+ 3 - 3
src/perf-tests/structure.ts

@@ -11,7 +11,7 @@ import * as fs from 'fs'
 import fetch from 'node-fetch'
 import CIF from 'mol-io/reader/cif'
 
-import { Structure, Model, Queries as Q, Element, Selection, StructureSymmetry, Query } from 'mol-model/structure'
+import { Structure, Model, Queries as Q, Element, Selection, StructureSymmetry, Query, Format } from 'mol-model/structure'
 //import { Segmentation, OrderedSet } from 'mol-data/int'
 
 import to_mmCIF from 'mol-model/structure/export/mmcif'
@@ -70,11 +70,11 @@ export async function readCIF(path: string) {
 
     const data = parsed.result.blocks[0];
     console.time('schema')
-    const mmcif = CIF.schema.mmCIF(data);
+    const mmcif = Format.mmCIF(data);
 
     console.timeEnd('schema')
     console.time('buildModels')
-    const models = await Model.create({ kind: 'mmCIF', data: mmcif }).run();
+    const models = await Model.create(mmcif).run();
     console.timeEnd('buildModels')
     const structures = models.map(Structure.ofModel);
 

+ 3 - 3
src/servers/model/server/structure-wrapper.ts

@@ -4,7 +4,7 @@
  * @author David Sehnal <david.sehnal@gmail.com>
  */
 
-import { Structure, Model } from 'mol-model/structure';
+import { Structure, Model, Format } from 'mol-model/structure';
 import { PerformanceMonitor } from 'mol-util/performance-monitor';
 import { Cache } from './cache';
 import Config from '../config';
@@ -89,10 +89,10 @@ async function readStructure(key: string, sourceId: string, entryId: string) {
     const data = await readFile(filename);
     perf.end('read');
     perf.start('parse');
-    const mmcif = CIF.schema.mmCIF((await parseCif(data)).blocks[0]);
+    const frame = (await parseCif(data)).blocks[0];
     perf.end('parse');
     perf.start('createModel');
-    const models = await Model.create({ kind: 'mmCIF', data: mmcif }).run();
+    const models = await Model.create(Format.mmCIF(frame)).run();
     perf.end('createModel');
 
     const structure = Structure.ofModel(models[0]);