Pārlūkot izejas kodu

structure properties (part 1 of ???)

David Sehnal 7 gadi atpakaļ
vecāks
revīzija
641f9b13d5

+ 6 - 4
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,
 

+ 3 - 2
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 },

+ 0 - 11
src/mol-data/model/common.ts

@@ -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

+ 2 - 2
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 }
+    | { source: 'mmCIF', data: mmCIF_Frame }

+ 0 - 11
src/mol-data/model/macromolecule.ts

@@ -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

+ 28 - 0
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

+ 0 - 0
src/mol-data/model/conformation.ts → src/mol-data/model/properties/conformation.ts


+ 72 - 0
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

+ 0 - 0
src/mol-data/model/properties/symmetry.ts


+ 3 - 3
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)
     }
 }
 

+ 4 - 3
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,

+ 8 - 5
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;
+
+export interface Frame extends TypedFrame<typeof Schema> { }
+export interface Shape extends TypedFrameShape<typeof Schema> { }

+ 1 - 1
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) {