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

calculate model center as dynamic prop

parent 34b04847
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,8 @@ import { CustomProperties } from '../common/custom-property'; ...@@ -15,6 +15,8 @@ import { CustomProperties } from '../common/custom-property';
import { SecondaryStructure } from './properties/seconday-structure'; import { SecondaryStructure } from './properties/seconday-structure';
import { SaccharideComponentMap } from '../structure/carbohydrates/constants'; import { SaccharideComponentMap } from '../structure/carbohydrates/constants';
import { ModelFormat } from '../../../mol-model-formats/structure/format'; import { ModelFormat } from '../../../mol-model-formats/structure/format';
import { calcModelCenter } from './util';
import { Vec3 } from '../../../mol-math/linear-algebra';
/** /**
* Interface to the "source data" of the molecule. * Interface to the "source data" of the molecule.
...@@ -75,4 +77,12 @@ export interface Model extends Readonly<{ ...@@ -75,4 +77,12 @@ export interface Model extends Readonly<{
export namespace Model { export namespace Model {
// TODO: is this enough? // TODO: is this enough?
export type Trajectory = ReadonlyArray<Model> export type Trajectory = ReadonlyArray<Model>
const CenterProp = '__Center__'
export function getCenter(model: Model): Vec3 {
if (model._dynamicPropertyData[CenterProp]) return model._dynamicPropertyData[CenterProp]
const center = calcModelCenter(model.atomicConformation, model.coarseConformation)
model._dynamicPropertyData[CenterProp] = center
return center
}
} }
\ 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 { Vec3 } from '../../../mol-math/linear-algebra';
import { AtomicConformation } from './properties/atomic';
import { CoarseConformation } from './properties/coarse';
import { arrayMinMax } from '../../../mol-util/array';
export function calcModelCenter(atomicConformation: AtomicConformation, coarseConformation?: CoarseConformation) {
let rangesX: number[] = []
let rangesY: number[] = []
let rangesZ: number[] = []
if (atomicConformation.x.length) {
rangesX.push(...arrayMinMax(atomicConformation.x))
rangesY.push(...arrayMinMax(atomicConformation.y))
rangesZ.push(...arrayMinMax(atomicConformation.z))
}
if (coarseConformation) {
if (coarseConformation.spheres.x.length) {
rangesX.push(...arrayMinMax(coarseConformation.spheres.x))
rangesY.push(...arrayMinMax(coarseConformation.spheres.y))
rangesZ.push(...arrayMinMax(coarseConformation.spheres.z))
}
if (coarseConformation.gaussians.x.length) {
rangesX.push(...arrayMinMax(coarseConformation.gaussians.x))
rangesY.push(...arrayMinMax(coarseConformation.gaussians.y))
rangesZ.push(...arrayMinMax(coarseConformation.gaussians.z))
}
}
const [minX, maxX] = arrayMinMax(rangesX)
const [minY, maxY] = arrayMinMax(rangesY)
const [minZ, maxZ] = arrayMinMax(rangesZ)
const x = minX + (maxX - minX) / 2
const y = minY + (maxY - minY) / 2
const z = minZ + (maxZ - minZ) / 2
return Vec3.create(x, y, z)
}
\ 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