diff --git a/src/mol-math/geometry/spacegroup/cell.ts b/src/mol-math/geometry/spacegroup/cell.ts new file mode 100644 index 0000000000000000000000000000000000000000..4f7deda347a80168157c52895aeff813b77de89c --- /dev/null +++ b/src/mol-math/geometry/spacegroup/cell.ts @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +import { Vec3 } from '../../linear-algebra' + +export { Cell } + +interface Cell { + readonly size: Vec3 + readonly anglesInRadians: Vec3 +} + +function Cell() { + return Cell.empty() +} + +namespace Cell { + export function create(size: Vec3, anglesInRadians: Vec3): Cell { return { size, anglesInRadians } } + export function empty(): Cell { return { size: Vec3(), anglesInRadians: Vec3() } } +} \ No newline at end of file diff --git a/src/mol-model/structure.ts b/src/mol-model/structure.ts index 3dff04a4684f0c1ad2062fb255eb10755ffa7ea8..6c6ed3a16d82460f3c83f537e285074d70edbb96 100644 --- a/src/mol-model/structure.ts +++ b/src/mol-model/structure.ts @@ -4,6 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ +export * from './structure/coordinates' export * from './structure/model' export * from './structure/structure' export * from './structure/query' diff --git a/src/mol-model/structure/coordinates.ts b/src/mol-model/structure/coordinates.ts new file mode 100644 index 0000000000000000000000000000000000000000..50d52667c502ad55b6071dbd662962f1c45314d8 --- /dev/null +++ b/src/mol-model/structure/coordinates.ts @@ -0,0 +1,7 @@ +/** + * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +export * from './coordinates/coordinates' \ No newline at end of file diff --git a/src/mol-model/structure/coordinates/coordinates.ts b/src/mol-model/structure/coordinates/coordinates.ts new file mode 100644 index 0000000000000000000000000000000000000000..a590fe1f839d41e68756fe365bfd7cee3b16af78 --- /dev/null +++ b/src/mol-model/structure/coordinates/coordinates.ts @@ -0,0 +1,127 @@ +/** + * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +import { UUID } from '../../../mol-util'; +import { Cell } from '../../../mol-math/geometry/spacegroup/cell'; +import { Model } from '../model'; +import { AtomicConformation } from '../model/properties/atomic'; +import { CustomProperties } from '../../structure'; +import { Mutable } from '../../../mol-util/type-helpers'; +import { Column } from '../../../mol-data/db'; + +export interface Frame { + readonly elementCount: number + readonly cell: Cell + readonly time: Time + + // positions + readonly x: ArrayLike<number> + readonly y: ArrayLike<number> + readonly z: ArrayLike<number> + + // optional velocities + readonly velocities?: { + readonly vx: ArrayLike<number> + readonly vy: ArrayLike<number> + readonly vz: ArrayLike<number> + } + + // optional forces + readonly forces?: { + readonly fx: ArrayLike<number> + readonly fy: ArrayLike<number> + readonly fz: ArrayLike<number> + } +} + +// + +export { Time } + +interface Time { + value: number + unit: Time.Unit +} + +function Time(value: number, unit: Time.Unit) { + return { value, unit } +} + +namespace Time { + export type Unit = 'ps' | 'step' + + // TODO: conversion utilities +} + +// + +export { Coordinates } + +interface Coordinates { + readonly id: UUID + + readonly frames: Frame[] + + /** Number of elements (e.g. atoms) in frames */ + readonly elementCount: number + + readonly hasVelocities: boolean + readonly hasForces: boolean + + readonly deltaTime: Time + readonly timeOffset: Time +} + +namespace Coordinates { + export function create(frames: Frame[], deltaTime: Time, timeOffset: Time): Coordinates { + const elementCount = frames[0].elementCount + const hasVelocities = !!frames[0].velocities + const hasForces = !!frames[0].forces + + return { + id: UUID.create22(), + frames, + elementCount, + hasVelocities, + hasForces, + deltaTime, + timeOffset + } + } +} + +function getAtomicConformation(frame: Frame, atomId: Column<number>): AtomicConformation { + return { + id: UUID.create22(), + atomId, + occupancy: Column.ofConst(1, frame.elementCount, Column.Schema.int), + B_iso_or_equiv: Column.ofConst(0, frame.elementCount, Column.Schema.float), + x: frame.x, + y: frame.y, + z: frame.z, + } +} + +export function trajectoryFromModelAndCoordinates(model: Model, coordinates: Coordinates): Model.Trajectory { + const trajectory: Mutable<Model.Trajectory> = [] + const { frames } = coordinates + for (let i = 0, il = frames.length; i < il; ++i) { + const f = frames[i] + const m = { + ...model, + id: UUID.create22(), + modelNum: i, + atomicConformation: getAtomicConformation(f, model.atomicConformation.atomId), + // TODO: add support for supplying sphere and gaussian coordinates in addition to atomic coordinates + // coarseConformation: coarse.conformation, + customProperties: new CustomProperties(), + _staticPropertyData: Object.create(null), + _dynamicPropertyData: Object.create(null) + } + trajectory.push(m) + } + return trajectory +} \ No newline at end of file diff --git a/src/mol-model/structure/model/model.ts b/src/mol-model/structure/model/model.ts index 3b0be2a6eb49553bc0ac8c8b640ecdb235b9901c..e7a247677c164cafeacab7a2085b295042d20c1f 100644 --- a/src/mol-model/structure/model/model.ts +++ b/src/mol-model/structure/model/model.ts @@ -31,7 +31,12 @@ export interface Model extends Readonly<{ /** the name of the entry/file/collection the model is part of */ entry: string, - /** for IHM, corresponds to ihm_model_list.model_id */ + /** + * corresponds to + * - for IHM: `ihm_model_list.model_id` + * - for standard mmCIF: `atom_site.pdbx_PDB_model_num` + * - for models from coordinates: frame index + */ modelNum: number, sourceData: ModelFormat,