Browse Source

remove tryAdjustBoundary for now

- not precise enough/too costly
Alexander Rose 4 years ago
parent
commit
b4813ff866
2 changed files with 13 additions and 69 deletions
  1. 0 52
      src/mol-math/geometry/boundary.ts
  2. 13 17
      src/mol-model/structure/structure/unit.ts

+ 0 - 52
src/mol-math/geometry/boundary.ts

@@ -10,15 +10,11 @@ import { Vec3 } from '../linear-algebra';
 import { OrderedSet } from '../../mol-data/int';
 import { BoundaryHelper } from './boundary-helper';
 import { Box3D, Sphere3D } from '../geometry';
-import { EPSILON, equalEps } from '../linear-algebra/3d/common';
 
 export type Boundary = { readonly box: Box3D, readonly sphere: Sphere3D }
 
 // avoiding namespace lookup improved performance in Chrome (Aug 2020)
 const v3set = Vec3.set;
-const v3copy = Vec3.copy;
-const v3distance = Vec3.distance;
-const v3squaredDistance = Vec3.squaredDistance;
 
 const boundaryHelperCoarse = new BoundaryHelper('14');
 const boundaryHelperFine = new BoundaryHelper('98');
@@ -58,52 +54,4 @@ export function getBoundary(data: PositionData): Boundary {
     }
 
     return { box: boundaryHelper.getBox(), sphere };
-}
-
-const extremPoint = Vec3();
-export function tryAdjustBoundary(data: PositionData, boundary: Boundary): Boundary | undefined {
-    const { x, y, z, indices } = data;
-    const n = OrderedSet.size(indices);
-    const { center, radius } = boundary.sphere;
-
-    const threshold = (radius / 100) * 5;
-    const upper = radius + threshold;
-    const upperSq = upper * upper;
-
-    let maxDistSq = 0;
-    for (let t = 0; t < n; t++) {
-        const i = OrderedSet.getAt(indices, t);
-        v3set(p, x[i], y[i], z[i]);
-        const distSq = v3squaredDistance(p, center);
-        if (distSq > upperSq) return;
-
-        if (distSq > maxDistSq) {
-            maxDistSq = distSq;
-            v3copy(extremPoint, p);
-        }
-    }
-
-    const adjustedRadius = Math.sqrt(maxDistSq);
-
-    if (equalEps(adjustedRadius, radius, EPSILON)) {
-        return boundary;
-    } else if (equalEps(adjustedRadius, radius, threshold)) {
-        if (Sphere3D.hasExtrema(boundary.sphere)) {
-            let flag = false;
-            for (const e of boundary.sphere.extrema) {
-                if (v3distance(e, extremPoint) < threshold * 2) {
-                    flag = true;
-                    break;
-                }
-            }
-            if (!flag) return;
-        }
-
-        const deltaRadius = adjustedRadius - radius;
-        const sphere = Sphere3D.expand(Sphere3D(), boundary.sphere, deltaRadius);
-        const box = Box3D.fromSphere3D(Box3D(), sphere);
-        return { box, sphere };
-    }
-
-    return;
 }

+ 13 - 17
src/mol-model/structure/structure/unit.ts

@@ -20,7 +20,7 @@ import { getAtomicPolymerElements, getCoarsePolymerElements, getAtomicGapElement
 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';
-import { Boundary, getBoundary, tryAdjustBoundary } from '../../../mol-math/geometry/boundary';
+import { Boundary, getBoundary } from '../../../mol-math/geometry/boundary';
 import { Mat4 } from '../../../mol-math/linear-algebra';
 import { IndexPairBonds } from '../../../mol-model-formats/structure/property/bonds/index-pair';
 import { ElementSetIntraBondCache } from './unit/bonds/element-set-intra-bond-cache';
@@ -214,11 +214,7 @@ namespace Unit {
         }
 
         remapModel(model: Model) {
-            let boundary = this.props.boundary;
-            if (boundary && !Unit.isSameConformation(this, model)) {
-                const { x, y, z } = model.atomicConformation;
-                boundary = tryAdjustBoundary({ x, y, z, indices: this.elements }, boundary);
-            }
+            const boundary = Unit.isSameConformation(this, model) ? this.props.boundary : undefined;
             const props = { ...this.props, bonds: tryRemapBonds(this, this.props.bonds, model), boundary, lookup3d: undefined, principalAxes: undefined };
             const conformation = this.model.atomicConformation !== model.atomicConformation
                 ? SymmetryOperator.createMapping(this.conformation.operator, model.atomicConformation)
@@ -358,19 +354,13 @@ namespace Unit {
 
         applyOperator(id: number, operator: SymmetryOperator, dontCompose = false): Unit {
             const op = dontCompose ? operator : SymmetryOperator.compose(this.conformation.operator, operator);
-            const ret = createCoarse(id, this.invariantId, this.chainGroupId, this.traits, this.model, this.kind, this.elements, SymmetryOperator.createMapping(op, this.getCoarseConformation(), this.conformation.r), this.props);
-            // (ret as Coarse<K, C>)._lookup3d = this._lookup3d;
-            return ret;
+            return createCoarse(id, this.invariantId, this.chainGroupId, this.traits, this.model, this.kind, this.elements, SymmetryOperator.createMapping(op, this.getCoarseConformation(), this.conformation.r), this.props);
         }
 
         remapModel(model: Model): Unit.Spheres | Unit.Gaussians {
             const coarseConformation = this.getCoarseConformation();
             const modelCoarseConformation = getCoarseConformation(this.kind, model);
-            let boundary = this.props.boundary;
-            if (boundary) {
-                const { x, y, z } = modelCoarseConformation;
-                boundary = tryAdjustBoundary({ x, y, z, indices: this.elements }, boundary);
-            }
+            const boundary = Unit.isSameConformation(this as Unit.Spheres | Unit.Gaussians, model) ? this.props.boundary : undefined; // TODO get rid of casting
             const props = { ...this.props, boundary, lookup3d: undefined, principalAxes: undefined };
             const conformation = coarseConformation !== modelCoarseConformation
                 ? SymmetryOperator.createMapping(this.conformation.operator, modelCoarseConformation)
@@ -489,9 +479,9 @@ namespace Unit {
         return isSameConformation(a, model) ? old : void 0;
     }
 
-    export function isSameConformation(a: Atomic, model: Model) {
-        const xs = a.elements;
-        const { x: xa, y: ya, z: za } = a.conformation.coordinates;
+    export function isSameConformation(u: Unit, model: Model) {
+        const xs = u.elements;
+        const { x: xa, y: ya, z: za } = u.conformation.coordinates;
         const { x: xb, y: yb, z: zb } = model.atomicConformation;
 
         for (let i = 0, _i = xs.length; i < _i; i++) {
@@ -501,6 +491,12 @@ namespace Unit {
 
         return true;
     }
+
+    export function getConformation(u: Unit) {
+        return u.kind === Kind.Atomic ? u.model.atomicConformation :
+            u.kind === Kind.Spheres ? u.model.coarseConformation.spheres :
+                u.model.coarseConformation.gaussians;
+    }
 }
 
 export default Unit;