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

"coord" column schema

parent 088e61bc
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ namespace Column {
export function aliased<T>(t: Type): Aliased<T> { return t as any as Aliased<T>; }
}
export type Schema<T = any> = Schema.Scalar | Schema.Vector | Schema.Matrix | Schema.Aliased<T>
export type Schema<T = any> = Schema.Scalar<T> | Schema.Vector | Schema.Matrix
export namespace Schema {
export interface FloatPrecision {
......@@ -48,23 +48,26 @@ namespace Column {
full: number
}
export type Scalar = Schema.Str | Schema.Int | Schema.Float
export type Scalar<T = any> = Schema.Str | Schema.Int | Schema.Float | Schema.Coordinate| Schema.Aliased<T>
export function FP(full: number, acceptable: number, low: number): FloatPrecision { return { low, full, acceptable }; }
export type Str = { '@type': 'schema', T: string, kind: 'str' }
export type Int = { '@type': 'schema', T: number, kind: 'int' }
export type Float = { '@type': 'schema', T: number, kind: 'float', precision: FloatPrecision }
export type Vector = { '@type': 'schema', T: number[], dim: number, kind: 'vector' };
export type Matrix = { '@type': 'schema', T: number[][], rows: number, cols: number, kind: 'matrix' };
export type Aliased<T> = { '@type': 'schema', T: T } & { kind: 'str' | 'int' | 'float' }
export type Str = { '@type': 'str', T: string, kind: 'str' }
export type Int = { '@type': 'int', T: number, kind: 'int' }
export type Float = { '@type': 'float', T: number, kind: 'float', precision: FloatPrecision }
export type Coordinate = { '@type': 'coord', T: number, kind: 'float' }
export const str: Str = { '@type': 'schema', T: '', kind: 'str' };
export const int: Int = { '@type': 'schema', T: 0, kind: 'int' };
export function float(precision: FloatPrecision): Float { return { '@type': 'schema', T: 0, kind: 'float', precision } };
export type Vector = { '@type': 'vector', T: number[], dim: number, kind: 'vector' };
export type Matrix = { '@type': 'matrix', T: number[][], rows: number, cols: number, kind: 'matrix' };
export type Aliased<T> = { '@type': 'aliased', T: T } & { kind: 'str' | 'int' | 'float' }
export function vector(dim: number): Vector { return { '@type': 'schema', T: [] as number[], dim, kind: 'vector' }; }
export function matrix(rows: number, cols: number): Matrix { return { '@type': 'schema', T: [] as number[][], rows, cols, kind: 'matrix' }; }
export const str: Str = { '@type': 'str', T: '', kind: 'str' };
export const int: Int = { '@type': 'int', T: 0, kind: 'int' };
export const coord: Coordinate = { '@type': 'coord', T: 0, kind: 'float' };
export function float(precision: FloatPrecision): Float { return { '@type': 'float', T: 0, kind: 'float', precision } };
export function vector(dim: number): Vector { return { '@type': 'vector', T: [] as number[], dim, kind: 'vector' }; }
export function matrix(rows: number, cols: number): Matrix { return { '@type': 'matrix', T: [] as number[][], rows, cols, kind: 'matrix' }; }
export function aliased<T>(t: Schema): Aliased<T> { return t as any as Aliased<T>; }
}
......
......@@ -218,9 +218,9 @@ const atom_site = {
label_seq_id: int,
pdbx_PDB_ins_code: str,
pdbx_formal_charge: str,
Cartn_x: float(FP(6, 3, 1)),
Cartn_y: float(FP(6, 3, 1)),
Cartn_z: float(FP(6, 3, 1)),
Cartn_x: Schema.coord,
Cartn_y: Schema.coord,
Cartn_z: Schema.coord,
occupancy: float(FP(2, 2, 1)),
B_iso_or_equiv: float(FP(2, 2, 1)),
auth_atom_id: str,
......
......@@ -7,7 +7,10 @@
import Iterator from 'mol-base/collections/iterator'
import { Column } from 'mol-base/collections/database'
import Encoder from '../encoder'
//import { ArrayEncoder, ArrayEncoding as E } from '../../common/binary-cif'
// TODO: support for "coordinate fields", make "coordinate precision" a parameter of the encoder
// TODO: automatically detect "precision" of floating point arrays.
// TODO: automatically detect "best encoding" for integer arrays. This could be used for "fixed-point" as well.
export const enum FieldType {
Str, Int, Float
......@@ -26,7 +29,7 @@ export type FieldDefinition<Key = any, Data = any> =
| FieldDefinitionBase<Key, Data> & { type: FieldType.Float, value(key: Key, data: Data): number }
export interface FieldFormat {
// TODO
// TODO: do we actually need this?
// textDecimalPlaces: number,
// stringEncoder: ArrayEncoder,
// numericEncoder: ArrayEncoder,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment