Skip to content
Snippets Groups Projects
Commit 31c3955f authored by David Sehnal's avatar David Sehnal
Browse files

Include CifFrame in Format.mmCif, fix makeBuckets

parent 81e4cb38
Branches
No related tags found
No related merge requests found
...@@ -9,12 +9,11 @@ import * as argparse from 'argparse' ...@@ -9,12 +9,11 @@ import * as argparse from 'argparse'
require('util.promisify').shim(); require('util.promisify').shim();
// import { Table } from 'mol-data/db' // import { Table } from 'mol-data/db'
import CIF from 'mol-io/reader/cif' import { CifFrame } from 'mol-io/reader/cif'
import { Model, Structure, Element, Unit, Queries } from 'mol-model/structure' import { Model, Structure, Element, Unit, Queries, Format } from 'mol-model/structure'
// import { Run, Progress } from 'mol-task' // import { Run, Progress } from 'mol-task'
import { OrderedSet } from 'mol-data/int'; import { OrderedSet } from 'mol-data/int';
import { Table } from 'mol-data/db'; import { Table } from 'mol-data/db';
import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif';
import { openCif, downloadCif } from './helpers'; import { openCif, downloadCif } from './helpers';
import { BitFlags } from 'mol-util'; import { BitFlags } from 'mol-util';
import { SecondaryStructureType } from 'mol-model/structure/model/types'; import { SecondaryStructureType } from 'mol-model/structure/model/types';
...@@ -24,12 +23,12 @@ import { UnitRings } from 'mol-model/structure/structure/unit/rings'; ...@@ -24,12 +23,12 @@ import { UnitRings } from 'mol-model/structure/structure/unit/rings';
async function downloadFromPdb(pdb: string) { async function downloadFromPdb(pdb: string) {
// `https://files.rcsb.org/download/${pdb}.cif` // `https://files.rcsb.org/download/${pdb}.cif`
const parsed = await downloadCif(`http://www.ebi.ac.uk/pdbe/static/entry/${pdb}_updated.cif`, false); 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) { async function readPdbFile(path: string) {
const parsed = await openCif(path); const parsed = await openCif(path);
return CIF.schema.mmCIF(parsed.blocks[0]); return parsed.blocks[0];
} }
export function atomLabel(model: Model, aI: number) { export function atomLabel(model: Model, aI: number) {
...@@ -189,8 +188,8 @@ export function printIHMModels(model: Model) { ...@@ -189,8 +188,8 @@ export function printIHMModels(model: Model) {
console.log(Table.formatToString(model.coarseHierarchy.models)); console.log(Table.formatToString(model.coarseHierarchy.models));
} }
async function run(mmcif: mmCIF_Database) { async function run(frame: CifFrame) {
const models = await Model.create({ kind: 'mmCIF', data: mmcif }).run(); const models = await Model.create(Format.mmCIF(frame)).run();
const structure = Structure.ofModel(models[0]); const structure = Structure.ofModel(models[0]);
//printSequence(models[0]); //printSequence(models[0]);
//printIHMModels(models[0]); //printIHMModels(models[0]);
......
...@@ -54,7 +54,7 @@ function _makeBuckets(indices: Helpers.ArrayLike<number>, ...@@ -54,7 +54,7 @@ function _makeBuckets(indices: Helpers.ArrayLike<number>,
} }
if (sortBuckets && !sorted) { if (sortBuckets && !sorted) {
sort(bucketList, start, end, sortAsc, arraySwap); sort(bucketList, 0, bucketList.length, sortAsc, arraySwap);
} }
let offset = 0; let offset = 0;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// import { File as GroFile } from 'mol-io/reader/gro/schema' // import { File as GroFile } from 'mol-io/reader/gro/schema'
import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif' import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif'
import CIF, { CifFrame } from 'mol-io/reader/cif';
type Format = type Format =
// | Format.gro // | Format.gro
...@@ -13,7 +14,11 @@ type Format = ...@@ -13,7 +14,11 @@ type Format =
namespace Format { namespace Format {
// export interface gro { kind: 'gro', data: GroFile } // 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 export default Format
\ No newline at end of file
...@@ -8,7 +8,7 @@ import { readFileAs, readUrlAs } from 'mol-util/read' ...@@ -8,7 +8,7 @@ import { readFileAs, readUrlAs } from 'mol-util/read'
import { idFactory } from 'mol-util/id-factory' import { idFactory } from 'mol-util/id-factory'
import { StateContext } from './context'; import { StateContext } from './context';
import { getFileInfo } from 'mol-util/file-info'; 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 { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif';
import { Model, Structure } from 'mol-model/structure'; import { Model, Structure } from 'mol-model/structure';
import { StructureRepresentation } from 'mol-geo/representation/structure'; import { StructureRepresentation } from 'mol-geo/representation/structure';
...@@ -94,10 +94,10 @@ export namespace CifEntity { ...@@ -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 namespace MmcifEntity {
export function ofMmcifDb(ctx: StateContext, db: mmCIF_Database): MmcifEntity { export function ofMmcifDb(ctx: StateContext, mmCif: { db: mmCIF_Database, frame: CifFrame }): MmcifEntity {
return StateEntity.create(ctx, 'mmcif', db) return StateEntity.create(ctx, 'mmcif', mmCif)
} }
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import CIF from 'mol-io/reader/cif' import CIF from 'mol-io/reader/cif'
import { FileEntity, DataEntity, UrlEntity, CifEntity, MmcifEntity, ModelEntity, StructureEntity, SpacefillEntity, AnyEntity, NullEntity, BondEntity } from './entity'; 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 { StateContext } from './context';
import Spacefill, { SpacefillProps } from 'mol-geo/representation/structure/spacefill'; import Spacefill, { SpacefillProps } from 'mol-geo/representation/structure/spacefill';
...@@ -55,13 +55,14 @@ export const DataToCif: DataToCif = StateTransform.create('data', 'cif', 'data-t ...@@ -55,13 +55,14 @@ export const DataToCif: DataToCif = StateTransform.create('data', 'cif', 'data-t
export type CifToMmcif = StateTransform<CifEntity, MmcifEntity, {}> export type CifToMmcif = StateTransform<CifEntity, MmcifEntity, {}>
export const CifToMmcif: CifToMmcif = StateTransform.create('cif', 'mmcif', 'cif-to-mmcif', export const CifToMmcif: CifToMmcif = StateTransform.create('cif', 'mmcif', 'cif-to-mmcif',
async function (ctx: StateContext, cifEntity: CifEntity) { 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 type MmcifToModel = StateTransform<MmcifEntity, ModelEntity, {}>
export const MmcifToModel: MmcifToModel = StateTransform.create('mmcif', 'model', 'mmcif-to-model', export const MmcifToModel: MmcifToModel = StateTransform.create('mmcif', 'model', 'mmcif-to-model',
async function (ctx: StateContext, mmcifEntity: MmcifEntity) { 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) return ModelEntity.ofModels(ctx, models)
}) })
......
...@@ -2,7 +2,7 @@ import * as util from 'util' ...@@ -2,7 +2,7 @@ import * as util from 'util'
import * as fs from 'fs' import * as fs from 'fs'
import CIF from 'mol-io/reader/cif' 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 { GridLookup3D } from 'mol-math/geometry';
// import { sortArray } from 'mol-data/util'; // import { sortArray } from 'mol-data/util';
...@@ -31,12 +31,11 @@ export async function readCIF(path: string) { ...@@ -31,12 +31,11 @@ export async function readCIF(path: string) {
throw parsed; throw parsed;
} }
const data = parsed.result.blocks[0]; const mmcif = Format.mmCIF(parsed.result.blocks[0]);
const mmcif = CIF.schema.mmCIF(data); const models = await Model.create(mmcif).run();
const models = await Model.create({ kind: 'mmCIF', data: mmcif }).run();
const structures = models.map(Structure.ofModel); const structures = models.map(Structure.ofModel);
return { mmcif, models, structures }; return { mmcif: mmcif.data, models, structures };
} }
export async function test() { export async function test() {
......
...@@ -11,7 +11,7 @@ import * as fs from 'fs' ...@@ -11,7 +11,7 @@ import * as fs from 'fs'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import CIF from 'mol-io/reader/cif' 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 { Segmentation, OrderedSet } from 'mol-data/int'
import to_mmCIF from 'mol-model/structure/export/mmcif' import to_mmCIF from 'mol-model/structure/export/mmcif'
...@@ -70,11 +70,11 @@ export async function readCIF(path: string) { ...@@ -70,11 +70,11 @@ export async function readCIF(path: string) {
const data = parsed.result.blocks[0]; const data = parsed.result.blocks[0];
console.time('schema') console.time('schema')
const mmcif = CIF.schema.mmCIF(data); const mmcif = Format.mmCIF(data);
console.timeEnd('schema') console.timeEnd('schema')
console.time('buildModels') console.time('buildModels')
const models = await Model.create({ kind: 'mmCIF', data: mmcif }).run(); const models = await Model.create(mmcif).run();
console.timeEnd('buildModels') console.timeEnd('buildModels')
const structures = models.map(Structure.ofModel); const structures = models.map(Structure.ofModel);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author David Sehnal <david.sehnal@gmail.com> * @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 { PerformanceMonitor } from 'mol-util/performance-monitor';
import { Cache } from './cache'; import { Cache } from './cache';
import Config from '../config'; import Config from '../config';
...@@ -89,10 +89,10 @@ async function readStructure(key: string, sourceId: string, entryId: string) { ...@@ -89,10 +89,10 @@ async function readStructure(key: string, sourceId: string, entryId: string) {
const data = await readFile(filename); const data = await readFile(filename);
perf.end('read'); perf.end('read');
perf.start('parse'); perf.start('parse');
const mmcif = CIF.schema.mmCIF((await parseCif(data)).blocks[0]); const frame = (await parseCif(data)).blocks[0];
perf.end('parse'); perf.end('parse');
perf.start('createModel'); 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'); perf.end('createModel');
const structure = Structure.ofModel(models[0]); const structure = Structure.ofModel(models[0]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment