Skip to content
Snippets Groups Projects
Commit fd92c916 authored by Alexander Rose's avatar Alexander Rose
Browse files

added coordinates support to model

parent f5e88083
No related branches found
No related tags found
No related merge requests found
/**
* 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
......@@ -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'
......
/**
* 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
/**
* 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
......@@ -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,
......
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