diff --git a/src/mol-data/model.ts b/src/mol-data/model.ts index bc5a486946ba4e8f5231a1536bd8767fd58bfce7..2d238f801d6d6f23cb616599298ce088cfae6de4 100644 --- a/src/mol-data/model.ts +++ b/src/mol-data/model.ts @@ -5,9 +5,9 @@ */ import * as Formats from './model/formats' -import CommonProperties from './model/common' -import MacromoleculeProperties from './model/macromolecule' -import Conformation from './model/conformation' +//import CommonProperties from './model/properties/common' +import MacromoleculeProperties from './model/properties/macromolecule' +import Conformation from './model/properties/conformation' import Segmentation from '../mol-base/collections/integer/segmentation' /** @@ -18,9 +18,11 @@ import Segmentation from '../mol-base/collections/integer/segmentation' interface Model extends Readonly<{ id: string, + model_num: number, + sourceData: Formats.RawData, - common: CommonProperties, + //common: CommonProperties, macromolecule: MacromoleculeProperties, conformation: Conformation, diff --git a/src/mol-data/model/builders/mmcif.ts b/src/mol-data/model/builders/mmcif.ts index 9fe460f0c7bc2ec4b312b9084f30d903d9e862e4..e9a26ff171bf7d642e9467c727124489d7a362e1 100644 --- a/src/mol-data/model/builders/mmcif.ts +++ b/src/mol-data/model/builders/mmcif.ts @@ -5,7 +5,7 @@ */ import { RawData } from '../formats' -import mmCIF from '../../../mol-io/reader/cif/schema/mmcif' +import { Frame as mmCIF } from '../../../mol-io/reader/cif/schema/mmcif' import Model from '../../model' import Interval from '../../../mol-base/collections/integer/interval' import Segmentation from '../../../mol-base/collections/integer/segmentation' @@ -57,7 +57,8 @@ function createModel(raw: RawData, data: mmCIF, bounds: Interval): Model { return { id: uuId(), sourceData: raw, - common: 0 as any, + model_num: 0, // TODO: fix + //common: 0 as any, macromolecule: 0 as any, conformation: 0 as any, version: { data: 0, conformation: 0 }, diff --git a/src/mol-data/model/common.ts b/src/mol-data/model/common.ts deleted file mode 100644 index 885f7c2f5448e89a84ea5372289cd6cccc82b35d..0000000000000000000000000000000000000000 --- a/src/mol-data/model/common.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. - * - * @author David Sehnal <david.sehnal@gmail.com> - */ - -interface Common { - -} - -export default Common \ No newline at end of file diff --git a/src/mol-data/model/formats.ts b/src/mol-data/model/formats.ts index 1f98e96f5ebc6fc2e3cf5745c27b3849800e19b3..56ec708a4d03e60e7e7578a9a405c73aac39407f 100644 --- a/src/mol-data/model/formats.ts +++ b/src/mol-data/model/formats.ts @@ -4,7 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import mmCIF from '../../mol-io/reader/cif/schema/mmcif' +import { Frame as mmCIF_Frame } from '../../mol-io/reader/cif/schema/mmcif' export type RawData = - | { source: 'mmCIF', data: mmCIF } \ No newline at end of file + | { source: 'mmCIF', data: mmCIF_Frame } \ No newline at end of file diff --git a/src/mol-data/model/macromolecule.ts b/src/mol-data/model/macromolecule.ts deleted file mode 100644 index 368d780f2d90ffef3e2e4886f0fc32d2d814db88..0000000000000000000000000000000000000000 --- a/src/mol-data/model/macromolecule.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. - * - * @author David Sehnal <david.sehnal@gmail.com> - */ - -interface Macromolecule { - -} - -export default Macromolecule \ No newline at end of file diff --git a/src/mol-data/model/properties/basic.ts b/src/mol-data/model/properties/basic.ts new file mode 100644 index 0000000000000000000000000000000000000000..1837912b6d1cdaeca9af1e182208ac4da7537b4f --- /dev/null +++ b/src/mol-data/model/properties/basic.ts @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import Column from '../../../mol-base/collections/column' + +export type Table<Data> = { [E in keyof Data]: Column<Data[E]> } + +export interface ElementSymbol extends String { '@type': 'element-symbol' } +export function ElementSymbol(s: string): ElementSymbol { + // TODO: optimize? + return s.toUpperCase() as any; +} + + +export interface Atoms extends Table<{ + name: string, + elementSymbol: ElementSymbol, + +}> { } + +interface Common { + +} + +export default Common \ No newline at end of file diff --git a/src/mol-data/model/conformation.ts b/src/mol-data/model/properties/conformation.ts similarity index 100% rename from src/mol-data/model/conformation.ts rename to src/mol-data/model/properties/conformation.ts diff --git a/src/mol-data/model/properties/macromolecule.ts b/src/mol-data/model/properties/macromolecule.ts new file mode 100644 index 0000000000000000000000000000000000000000..1285ba4d37c384f9e1a42ed08f3a12f36e763162 --- /dev/null +++ b/src/mol-data/model/properties/macromolecule.ts @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import Column from '../../../mol-base/collections/column' +import { Shape as mmCIF } from '../../../mol-io/reader/cif/schema/mmcif' + +export type Table<Data> = { [E in keyof Data]: Column<Data[E]> } + +export interface ElementSymbol extends String { '@type': 'element-symbol' } +export function ElementSymbol(s: string): ElementSymbol { + // TODO: optimize? + return s.toUpperCase() as any; +} + +export interface Atoms extends Table<{ + // unique number for each atom + key: number, + + id: number, + type_symbol: ElementSymbol, + label_atom_id: string, + auth_atom_id: string, + label_alt_id: string, + auth_alt_id: string, + pdbx_formal_charge: string, + occupancy: number, + B_iso_or_equiv: number +}> { } + +export interface Residues extends Table<{ + // unique number for each residue + key: number, + + group_PDB: string, + + label_comp_id: string, + auth_comp_id: string, + label_seq_id: number, + auth_seq_id: number, + pdbx_PDB_ins_code: string +}> { } + +export interface Chains extends Table<{ + // unique number for each chain + key: number, + + label_asym_id: string, + auth_asym_id: string +}> { } + +export interface Entities extends Table<{ + // unique number for each entity + // row index to the EntityData table + key: number, + label_entity_id: string, + pdbx_PDB_model_num: number +}> { } + +type _EntityData = mmCIF['entity'] +export interface EntityData extends _EntityData { } + +export interface Macromolecule { + atoms: Atoms, + residues: Residues, + chains: Chains, + entities: Entities +} + +export default Macromolecule \ No newline at end of file diff --git a/src/mol-data/model/properties/symmetry.ts b/src/mol-data/model/properties/symmetry.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/mol-io/reader/cif.ts b/src/mol-io/reader/cif.ts index 0d44a5482dab5a2fda4b3e08860233c9c856adbe..29a734f04605785d2f8fc49a5e3d2a6b4b6db60a 100644 --- a/src/mol-io/reader/cif.ts +++ b/src/mol-io/reader/cif.ts @@ -6,16 +6,16 @@ import parseText from './cif/text/parser' import parseBinary from './cif/binary/parser' -import { Block } from './cif/data-model' +import { Frame } from './cif/data-model' import { toTypedFrame as applySchema } from './cif/schema' -import mmCIF from './cif/schema/mmcif' +import { Schema as mmCIF_Schema, Frame as mmCIF_Frame } from './cif/schema/mmcif' export default { parseText, parseBinary, applySchema, schema: { - mmCIF: (block: Block) => applySchema(mmCIF, block) + mmCIF: (frame: Frame) => applySchema<typeof mmCIF_Schema, mmCIF_Frame>(mmCIF_Schema, frame) } } diff --git a/src/mol-io/reader/cif/schema.ts b/src/mol-io/reader/cif/schema.ts index 7d603fc73f3710f279c20c33c7952860768b5087..368aaa11098108cc7ce99677d0a764eee09b22f2 100644 --- a/src/mol-io/reader/cif/schema.ts +++ b/src/mol-io/reader/cif/schema.ts @@ -24,8 +24,8 @@ import Column, { createAndFillArray } from '../../../mol-base/collections/column ////////////////////////////////////////////// -export function toTypedFrame<Schema extends FrameSchema>(schema: Schema, frame: Data.Frame): TypedFrame<Schema> { - return createTypedFrame(schema, frame) as TypedFrame<Schema>; +export function toTypedFrame<Schema extends FrameSchema, Frame extends TypedFrame<Schema> = TypedFrame<Schema>>(schema: Schema, frame: Data.Frame): Frame { + return createTypedFrame(schema, frame) as Frame; } export function toTypedCategory<Schema extends CategorySchema>(schema: Schema, category: Data.Category): TypedCategory<Schema> { @@ -33,13 +33,14 @@ export function toTypedCategory<Schema extends CategorySchema>(schema: Schema, c } export type FrameSchema = { [category: string]: CategorySchema } +export type TypedFrameShape<Schema extends FrameSchema> = { [C in keyof Schema]: TypedCategoryShape<Schema[C]> } export type TypedFrame<Schema extends FrameSchema> = { readonly _header?: string, readonly _frame: Data.Frame } & { [C in keyof Schema]: TypedCategory<Schema[C]> } - export type CategorySchema = { [field: string]: Field.Schema<any> } +export type TypedCategoryShape<Schema extends CategorySchema> = { [F in keyof Schema]: Column<Schema[F]['T']> } export type TypedCategory<Schema extends CategorySchema> = { readonly _rowCount: number, readonly _isDefined: boolean, diff --git a/src/mol-io/reader/cif/schema/mmcif.ts b/src/mol-io/reader/cif/schema/mmcif.ts index b317a628481b7292b353517ebdc4f9f04c47b42d..a5d3ba1567e63dc17b42123231f1e3195c2a3141 100644 --- a/src/mol-io/reader/cif/schema/mmcif.ts +++ b/src/mol-io/reader/cif/schema/mmcif.ts @@ -4,7 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { Field, TypedFrame } from '../schema' +import { Field, TypedFrame, TypedFrameShape } from '../schema' const str = Field.str(); const int = Field.int(); @@ -14,9 +14,11 @@ const entry = { id: str } +type EntityType = 'polymer' | 'non-polymer' | 'water' + const entity = { id: str, - type: str as Field.Schema<'polymer' | 'non-polymer' | 'water'>, + type: str as Field.Schema<EntityType>, src_method: str, pdbx_description: str, formula_weight: float, @@ -225,7 +227,7 @@ const atom_site = { pdbx_PDB_model_num: int } -const mmCIF = { +export const Schema = { entry, entity, exptl, @@ -242,5 +244,6 @@ const mmCIF = { pdbx_struct_mod_residue, atom_site }; -type mmCIF = TypedFrame<typeof mmCIF> -export default mmCIF; \ No newline at end of file + +export interface Frame extends TypedFrame<typeof Schema> { } +export interface Shape extends TypedFrameShape<typeof Schema> { } \ No newline at end of file diff --git a/src/script.ts b/src/script.ts index e05c5e817689fb20e596e8d8abfe004ff89846c2..dbe952e166678bedb9cb3ed5eba471aa1d4fc768 100644 --- a/src/script.ts +++ b/src/script.ts @@ -117,7 +117,7 @@ async function runCIF(input: string | Uint8Array) { console.time('createModels'); const models = buildModels(mmcif); console.timeEnd('createModels'); - console.log(models[0].common); + console.log(models[0].id); // const schema = await _dic() // if (schema) {