Alexander Rose 5 роки тому
батько
коміт
67b60cff60

+ 18 - 0
src/mol-model/structure/structure/unit.ts

@@ -18,6 +18,8 @@ import { IntMap, SortedArray, Segmentation } from '../../../mol-data/int';
 import { hash2, hashFnv32a } from '../../../mol-data/util';
 import { getAtomicPolymerElements, getCoarsePolymerElements, getAtomicGapElements, getCoarseGapElements, getNucleotideElements, getProteinElements } from './util/polymer';
 import { mmCIF_Schema } from '../../../mol-io/reader/cif/schema/mmcif';
+import { PrincipalAxes } from '../../../mol-math/linear-algebra/matrix/principal-axes';
+import { getPrincipalAxes } from './util/principal-axes';
 
 /**
  * A building block of a structure that corresponds to an atomic or
@@ -183,6 +185,12 @@ namespace Unit {
             return this.props.lookup3d.ref;
         }
 
+        get principalAxes() {
+            if (this.props.principalAxes.ref) return this.props.principalAxes.ref;
+            this.props.principalAxes.ref = getPrincipalAxes(this);
+            return this.props.principalAxes.ref;
+        }
+
         get links() {
             if (this.props.links.ref) return this.props.links.ref;
             this.props.links.ref = computeIntraUnitBonds(this);
@@ -254,6 +262,7 @@ namespace Unit {
 
     interface AtomicProperties {
         lookup3d: ValueRef<Lookup3D | undefined>,
+        principalAxes: ValueRef<PrincipalAxes | undefined>,
         links: ValueRef<IntraUnitLinks | undefined>,
         rings: ValueRef<UnitRings | undefined>
         polymerElements: ValueRef<SortedArray<ElementIndex> | undefined>
@@ -266,6 +275,7 @@ namespace Unit {
     function AtomicProperties(): AtomicProperties {
         return {
             lookup3d: ValueRef.create(void 0),
+            principalAxes: ValueRef.create(void 0),
             links: ValueRef.create(void 0),
             rings: ValueRef.create(void 0),
             polymerElements: ValueRef.create(void 0),
@@ -313,6 +323,12 @@ namespace Unit {
             return this.props.lookup3d.ref;
         }
 
+        get principalAxes() {
+            if (this.props.principalAxes.ref) return this.props.principalAxes.ref;
+            this.props.principalAxes.ref = getPrincipalAxes(this as Unit.Spheres | Unit.Gaussians); // TODO get rid of casting
+            return this.props.principalAxes.ref;
+        }
+
         get polymerElements() {
             if (this.props.polymerElements.ref) return this.props.polymerElements.ref;
             this.props.polymerElements.ref = getCoarsePolymerElements(this as Unit.Spheres | Unit.Gaussians); // TODO get rid of casting
@@ -347,6 +363,7 @@ namespace Unit {
 
     interface CoarseProperties {
         lookup3d: ValueRef<Lookup3D | undefined>,
+        principalAxes: ValueRef<PrincipalAxes | undefined>,
         polymerElements: ValueRef<SortedArray<ElementIndex> | undefined>
         gapElements: ValueRef<SortedArray<ElementIndex> | undefined>
     }
@@ -354,6 +371,7 @@ namespace Unit {
     function CoarseProperties(): CoarseProperties {
         return {
             lookup3d: ValueRef.create(void 0),
+            principalAxes: ValueRef.create(void 0),
             polymerElements: ValueRef.create(void 0),
             gapElements: ValueRef.create(void 0),
         };

+ 26 - 0
src/mol-model/structure/structure/util/principal-axes.ts

@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
+
+import { PrincipalAxes } from '../../../../mol-math/linear-algebra/matrix/principal-axes';
+import Unit from '../unit';
+import { Vec3 } from '../../../../mol-math/linear-algebra';
+
+const tempPos = Vec3.zero();
+export function toPositionsArray(unit: Unit) {
+    const pos = unit.conformation.invariantPosition
+    const { elements } = unit
+    const positions = new Float32Array(elements.length * 3)
+    for (let i = 0, il = elements.length; i < il; i++) {
+        pos(elements[i], tempPos)
+        Vec3.toArray(tempPos, positions, i * 3)
+    }
+    return positions
+}
+
+export function getPrincipalAxes(unit: Unit): PrincipalAxes {
+    const positions = toPositionsArray(unit)
+    return PrincipalAxes.ofPositions(positions)
+}