diff --git a/src/mol-base/collections/database/column.ts b/src/mol-base/collections/database/column.ts index a6110269f7d30c082a0c31839463d3b0b2fd5970..23bf57ec4ec7dd73f4b7b9c76f5afa61c2916807 100644 --- a/src/mol-base/collections/database/column.ts +++ b/src/mol-base/collections/database/column.ts @@ -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>; } } diff --git a/src/mol-io/reader/cif/schema/mmcif.ts b/src/mol-io/reader/cif/schema/mmcif.ts index 939c9039e0947fd6e9f32fb6ef3c2912d4abecac..59b31c1014f3fcb4485071d71ee1cdcc806bc610 100644 --- a/src/mol-io/reader/cif/schema/mmcif.ts +++ b/src/mol-io/reader/cif/schema/mmcif.ts @@ -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, diff --git a/src/mol-io/writer/cif/encoder.ts b/src/mol-io/writer/cif/encoder.ts index ad036fcba4c5200854e8bf16e150a472a4987a2e..7f97314c5b36c37d1fcf7048472b5b0907c95a1b 100644 --- a/src/mol-io/writer/cif/encoder.ts +++ b/src/mol-io/writer/cif/encoder.ts @@ -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,