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

wip, strongly typed indexes in Model

parent 1cb49130
No related branches found
No related tags found
No related merge requests found
Showing with 24 additions and 26 deletions
...@@ -141,8 +141,8 @@ namespace Column { ...@@ -141,8 +141,8 @@ namespace Column {
return createFirstIndexMapOfColumn(column); return createFirstIndexMapOfColumn(column);
} }
export function createIndexer<T>(column: Column<T>) { export function createIndexer<T, R extends number = number>(column: Column<T>) {
return createIndexerOfColumn(column); return createIndexerOfColumn(column) as ((e: T) => R);
} }
export function mapToArray<T, S>(column: Column<T>, f: (v: T) => S, ctor?: ArrayCtor<S>): ArrayLike<S> { export function mapToArray<T, S>(column: Column<T>, f: (v: T) => S, ctor?: ArrayCtor<S>): ArrayLike<S> {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
*/ */
import Model from './model/model' import { Model } from './model/model'
import * as Types from './model/types' import * as Types from './model/types'
import Format from './model/format' import Format from './model/format'
import { ModelSymmetry } from './model/properties/symmetry' import { ModelSymmetry } from './model/properties/symmetry'
......
...@@ -11,7 +11,7 @@ import { Tensor, Vec3 } from 'mol-math/linear-algebra'; ...@@ -11,7 +11,7 @@ import { Tensor, Vec3 } from 'mol-math/linear-algebra';
import { Task, RuntimeContext } from 'mol-task'; import { Task, RuntimeContext } from 'mol-task';
import UUID from 'mol-util/uuid'; import UUID from 'mol-util/uuid';
import Format from '../format'; import Format from '../format';
import Model from '../model'; import { Model } from '../model';
import { Entities } from '../properties/common'; import { Entities } from '../properties/common';
import { CustomProperties } from '../properties/custom'; import { CustomProperties } from '../properties/custom';
import { ModelSymmetry } from '../properties/symmetry'; import { ModelSymmetry } from '../properties/symmetry';
......
...@@ -10,7 +10,7 @@ import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif'; ...@@ -10,7 +10,7 @@ import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif';
import UUID from 'mol-util/uuid'; import UUID from 'mol-util/uuid';
import { Element } from '../../../../structure'; import { Element } from '../../../../structure';
import Format from '../../format'; import Format from '../../format';
import Model from '../../model'; import { Model } from '../../model';
import { AtomicConformation, AtomicData, AtomicHierarchy, AtomicSegments, AtomsSchema, ChainsSchema, ResiduesSchema } from '../../properties/atomic'; import { AtomicConformation, AtomicData, AtomicHierarchy, AtomicSegments, AtomsSchema, ChainsSchema, ResiduesSchema } from '../../properties/atomic';
import { getAtomicKeys } from '../../properties/utils/atomic-keys'; import { getAtomicKeys } from '../../properties/utils/atomic-keys';
import { ElementSymbol } from '../../types'; import { ElementSymbol } from '../../types';
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import Model from '../../../model' import { Model } from '../../../model'
import { LinkType } from '../../../types' import { LinkType } from '../../../types'
import { ModelPropertyDescriptor } from '../../../properties/custom'; import { ModelPropertyDescriptor } from '../../../properties/custom';
import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif'; import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif';
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import Model from '../../../model' import { Model } from '../../../model'
import { Element, Structure } from '../../../../structure' import { Element, Structure } from '../../../../structure'
import { LinkType } from '../../../types' import { LinkType } from '../../../types'
import { findEntityIdByAsymId, findAtomIndexByLabelName } from '../util' import { findEntityIdByAsymId, findAtomIndexByLabelName } from '../util'
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import Model from '../../../model' import { Model } from '../../../model'
import { Table } from 'mol-data/db' import { Table } from 'mol-data/db'
import { mmCIF_Schema } from 'mol-io/reader/cif/schema/mmcif'; import { mmCIF_Schema } from 'mol-io/reader/cif/schema/mmcif';
import { findAtomIndexByLabelName } from '../util'; import { findAtomIndexByLabelName } from '../util';
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import Model from '../../model' import { Model } from '../../model'
import { Element } from '../../../structure' import { Element } from '../../../structure'
export function findEntityIdByAsymId(model: Model, asymId: string) { export function findEntityIdByAsymId(model: Model, asymId: string) {
......
...@@ -22,7 +22,7 @@ import { ChemicalComponent } from './properties/chemical-component'; ...@@ -22,7 +22,7 @@ import { ChemicalComponent } from './properties/chemical-component';
* *
* "Atoms" are integers in the range [0, atomCount). * "Atoms" are integers in the range [0, atomCount).
*/ */
interface Model extends Readonly<{ export interface Model extends Readonly<{
id: UUID, id: UUID,
label: string, label: string,
...@@ -64,25 +64,17 @@ interface Model extends Readonly<{ ...@@ -64,25 +64,17 @@ interface Model extends Readonly<{
} { } } { }
namespace Model { export namespace Model {
export function create(format: Format) { export function create(format: Format) {
switch (format.kind) { switch (format.kind) {
// case 'gro': return from_gro(format); // case 'gro': return from_gro(format);
case 'mmCIF': return from_mmCIF(format); case 'mmCIF': return from_mmCIF(format);
} }
} }
// TODO: figure the place to include this?
// export interface Property<T, K> { (model: Model, index: number): T, _kind: K }
// export interface AtomicProperty<T> extends Property<T, 'atomic'> { }
// export interface CoarseProperty<T> extends Property<T, 'coarse'> { }
// export interface SphereProperty<T> extends Property<T, 'sphere'> { }
// export interface GaussianProperty<T> extends Property<T, 'gaussian'> { }
// export function atomProp<T>(p: (model: Model, i: number) => T): AtomicProperty<T> { return p as any; }
// export function residueProp<T>(p: (model: Model, residueIndex: number) => T): AtomicProperty<T> {
// return p as any;
// }
} }
export default Model
\ No newline at end of file export type ElementIndex = { readonly '@type': 'element-index' } & number
export type ResidueIndex = { readonly '@type': 'residue-index' } & number
export type ChainIndex = { readonly '@type': 'chain-index' } & number
export type EntityIndex = { readonly '@type': 'entity-index' } & number
\ No newline at end of file
...@@ -80,9 +80,15 @@ export interface AtomicKeys { ...@@ -80,9 +80,15 @@ export interface AtomicKeys {
// also index to the Entities table. // also index to the Entities table.
entityKey: ArrayLike<number>, entityKey: ArrayLike<number>,
/**
* @returns index or -1 if not present.
*/
findChainKey(entityId: string, label_asym_id: string): number, findChainKey(entityId: string, label_asym_id: string): number,
/** Unique number for each of the residue. Also the index of the 1st occurence of this residue. */ /**
* Unique number for each of the residue. Also the index of the 1st occurence of this residue.
* @returns index or -1 if not present.
*/
findResidueKey(entityId: string, label_asym_id: string, label_comp_id: string, auth_seq_id: number, pdbx_PDB_ins_code: string): number findResidueKey(entityId: string, label_asym_id: string, label_comp_id: string, auth_seq_id: number, pdbx_PDB_ins_code: string): number
} }
......
...@@ -8,5 +8,5 @@ import { mmCIF_Database as mmCIF } from 'mol-io/reader/cif/schema/mmcif' ...@@ -8,5 +8,5 @@ import { mmCIF_Database as mmCIF } from 'mol-io/reader/cif/schema/mmcif'
export interface Entities { export interface Entities {
data: mmCIF['entity'], data: mmCIF['entity'],
getEntityIndex(id: string): number getEntityIndex(id: string): import('../model').EntityIndex
} }
\ No newline at end of file
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