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

structure properties (part 1 of ???)

parent d0f3acda
No related branches found
No related tags found
No related merge requests found
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
*/ */
import * as Formats from './model/formats' import * as Formats from './model/formats'
import CommonProperties from './model/common' //import CommonProperties from './model/properties/common'
import MacromoleculeProperties from './model/macromolecule' import MacromoleculeProperties from './model/properties/macromolecule'
import Conformation from './model/conformation' import Conformation from './model/properties/conformation'
import Segmentation from '../mol-base/collections/integer/segmentation' import Segmentation from '../mol-base/collections/integer/segmentation'
/** /**
...@@ -18,9 +18,11 @@ import Segmentation from '../mol-base/collections/integer/segmentation' ...@@ -18,9 +18,11 @@ import Segmentation from '../mol-base/collections/integer/segmentation'
interface Model extends Readonly<{ interface Model extends Readonly<{
id: string, id: string,
model_num: number,
sourceData: Formats.RawData, sourceData: Formats.RawData,
common: CommonProperties, //common: CommonProperties,
macromolecule: MacromoleculeProperties, macromolecule: MacromoleculeProperties,
conformation: Conformation, conformation: Conformation,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
import { RawData } from '../formats' 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 Model from '../../model'
import Interval from '../../../mol-base/collections/integer/interval' import Interval from '../../../mol-base/collections/integer/interval'
import Segmentation from '../../../mol-base/collections/integer/segmentation' import Segmentation from '../../../mol-base/collections/integer/segmentation'
...@@ -57,7 +57,8 @@ function createModel(raw: RawData, data: mmCIF, bounds: Interval): Model { ...@@ -57,7 +57,8 @@ function createModel(raw: RawData, data: mmCIF, bounds: Interval): Model {
return { return {
id: uuId(), id: uuId(),
sourceData: raw, sourceData: raw,
common: 0 as any, model_num: 0, // TODO: fix
//common: 0 as any,
macromolecule: 0 as any, macromolecule: 0 as any,
conformation: 0 as any, conformation: 0 as any,
version: { data: 0, conformation: 0 }, version: { data: 0, conformation: 0 },
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author David Sehnal <david.sehnal@gmail.com> * @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 = export type RawData =
| { source: 'mmCIF', data: mmCIF } | { source: 'mmCIF', data: mmCIF_Frame }
\ No newline at end of file \ No newline at end of file
/**
* 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
...@@ -4,6 +4,23 @@ ...@@ -4,6 +4,23 @@
* @author David Sehnal <david.sehnal@gmail.com> * @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 { interface Common {
} }
......
/**
* 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
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
import parseText from './cif/text/parser' import parseText from './cif/text/parser'
import parseBinary from './cif/binary/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 { 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 { export default {
parseText, parseText,
parseBinary, parseBinary,
applySchema, applySchema,
schema: { schema: {
mmCIF: (block: Block) => applySchema(mmCIF, block) mmCIF: (frame: Frame) => applySchema<typeof mmCIF_Schema, mmCIF_Frame>(mmCIF_Schema, frame)
} }
} }
......
...@@ -24,8 +24,8 @@ import Column, { createAndFillArray } from '../../../mol-base/collections/column ...@@ -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> { export function toTypedFrame<Schema extends FrameSchema, Frame extends TypedFrame<Schema> = TypedFrame<Schema>>(schema: Schema, frame: Data.Frame): Frame {
return createTypedFrame(schema, frame) as TypedFrame<Schema>; return createTypedFrame(schema, frame) as Frame;
} }
export function toTypedCategory<Schema extends CategorySchema>(schema: Schema, category: Data.Category): TypedCategory<Schema> { 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 ...@@ -33,13 +33,14 @@ export function toTypedCategory<Schema extends CategorySchema>(schema: Schema, c
} }
export type FrameSchema = { [category: string]: CategorySchema } 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> = { export type TypedFrame<Schema extends FrameSchema> = {
readonly _header?: string, readonly _header?: string,
readonly _frame: Data.Frame readonly _frame: Data.Frame
} & { [C in keyof Schema]: TypedCategory<Schema[C]> } } & { [C in keyof Schema]: TypedCategory<Schema[C]> }
export type CategorySchema = { [field: string]: Field.Schema<any> } 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> = { export type TypedCategory<Schema extends CategorySchema> = {
readonly _rowCount: number, readonly _rowCount: number,
readonly _isDefined: boolean, readonly _isDefined: boolean,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
*/ */
import { Field, TypedFrame } from '../schema' import { Field, TypedFrame, TypedFrameShape } from '../schema'
const str = Field.str(); const str = Field.str();
const int = Field.int(); const int = Field.int();
...@@ -14,9 +14,11 @@ const entry = { ...@@ -14,9 +14,11 @@ const entry = {
id: str id: str
} }
type EntityType = 'polymer' | 'non-polymer' | 'water'
const entity = { const entity = {
id: str, id: str,
type: str as Field.Schema<'polymer' | 'non-polymer' | 'water'>, type: str as Field.Schema<EntityType>,
src_method: str, src_method: str,
pdbx_description: str, pdbx_description: str,
formula_weight: float, formula_weight: float,
...@@ -225,7 +227,7 @@ const atom_site = { ...@@ -225,7 +227,7 @@ const atom_site = {
pdbx_PDB_model_num: int pdbx_PDB_model_num: int
} }
const mmCIF = { export const Schema = {
entry, entry,
entity, entity,
exptl, exptl,
...@@ -242,5 +244,6 @@ const mmCIF = { ...@@ -242,5 +244,6 @@ const mmCIF = {
pdbx_struct_mod_residue, pdbx_struct_mod_residue,
atom_site atom_site
}; };
type mmCIF = TypedFrame<typeof mmCIF>
export default mmCIF; export interface Frame extends TypedFrame<typeof Schema> { }
\ No newline at end of file export interface Shape extends TypedFrameShape<typeof Schema> { }
\ No newline at end of file
...@@ -117,7 +117,7 @@ async function runCIF(input: string | Uint8Array) { ...@@ -117,7 +117,7 @@ async function runCIF(input: string | Uint8Array) {
console.time('createModels'); console.time('createModels');
const models = buildModels(mmcif); const models = buildModels(mmcif);
console.timeEnd('createModels'); console.timeEnd('createModels');
console.log(models[0].common); console.log(models[0].id);
// const schema = await _dic() // const schema = await _dic()
// if (schema) { // if (schema) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment