Browse Source

mol-model: check if bonds can be remapped in Unit.Atomic

David Sehnal 4 years ago
parent
commit
7045545419

+ 15 - 1
src/mol-model/structure/structure/unit.ts

@@ -209,7 +209,8 @@ namespace Unit {
                 const { x, y, z } = this.model.atomicConformation;
                 boundary = tryAdjustBoundary({ x, y, z, indices: this.elements }, boundary);
             }
-            const props = { ...this.props, boundary, lookup3d: undefined, principalAxes: undefined };
+            const bonds = this.props.bonds && canRemapBonds(this, model) ? this.props.bonds : void 0;
+            const props = { ...this.props, bonds, boundary, lookup3d: undefined, principalAxes: undefined };
             const conformation = this.model.atomicConformation !== model.atomicConformation
                 ? SymmetryOperator.createMapping(this.conformation.operator, model.atomicConformation)
                 : this.conformation;
@@ -455,6 +456,19 @@ namespace Unit {
 
         return true;
     }
+
+    function canRemapBonds(a: Atomic, model: Model) {
+        const xs = a.elements;
+        const { x: xa, y: ya, z: za } = a.conformation.coordinates;
+        const { x: xb, y: yb, z: zb } = model.atomicConformation;
+
+        for (let i = 0, _i = xs.length; i < _i; i++) {
+            const u = xs[i];
+            if (xa[u] !== xb[u] || ya[u] !== yb[u] || za[u] !== zb[u]) return false;
+        }
+
+        return true;
+    }
 }
 
 export default Unit;

+ 1 - 1
src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts

@@ -73,7 +73,7 @@ function createIntraUnitBondCylinderMesh(ctx: VisualContext, unit: Unit, structu
             const r = Math.min(rA, rB) * sizeAspectRatio;
             const oA = Math.sqrt(Math.max(0, rA * rA - r * r)) - 0.05;
             const oB = Math.sqrt(Math.max(0, rB * rB - r * r)) - 0.05;
-                        
+
             pos(elements[a[edgeIndex]], posA);
             pos(elements[b[edgeIndex]], posB);