Browse Source

bonds tweaks

Alexander Rose 5 years ago
parent
commit
c0b5102d31

+ 7 - 1
src/mol-model/structure/structure/structure.ts

@@ -278,7 +278,7 @@ class Structure {
     get isAtomic() {
         for (const u of this.units) if (Unit.isAtomic(u)) return false;
         return true;
-        }
+    }
 
     /** Contains some atomic units */
     get hasAtomic() {
@@ -959,6 +959,12 @@ namespace Structure {
     export function elementDescription(s: Structure) {
         return s.elementCount === 1 ? '1 element' : `${s.elementCount} elements`
     }
+
+    export function validUnitPair(s: Structure, a: Unit, b: Unit) {
+        return s.masterModel
+            ? a.model === b.model || a.model === s.masterModel || b.model === s.masterModel
+            : a.model === b.model
+    }
 }
 
 export default Structure

+ 1 - 0
src/mol-model/structure/structure/unit/bonds.ts

@@ -55,6 +55,7 @@ namespace Bond {
     }
 
     export function areLociEqual(a: Loci, b: Loci) {
+        if (a.structure !== b.structure) return false
         if (a.bonds.length !== b.bonds.length) return false
         for (let i = 0, il = a.bonds.length; i < il; ++i) {
             if (!areLocationsEqual(a.bonds[i], b.bonds[i])) return false

+ 3 - 12
src/mol-model/structure/structure/unit/bonds/inter-compute.ts

@@ -171,7 +171,7 @@ function findPairBonds(unitA: Unit.Atomic, unitB: Unit.Atomic, props: BondComput
 }
 
 export interface InterBondComputationProps extends BondComputationProps {
-    validUnitPair: (unitA: Unit, unitB: Unit) => boolean
+    validUnitPair: (structure: Structure, unitA: Unit, unitB: Unit) => boolean
 }
 
 function findBonds(structure: Structure, props: InterBondComputationProps) {
@@ -197,7 +197,7 @@ function findBonds(structure: Structure, props: InterBondComputationProps) {
         const closeUnits = lookup.findUnitIndices(imageCenter[0], imageCenter[1], imageCenter[2], bs.radius + MAX_RADIUS);
         for (let i = 0; i < closeUnits.count; i++) {
             const other = structure.units[closeUnits.indices[i]];
-            if (!Unit.isAtomic(other) || unit.id >= other.id || !validUnitPair(unit, other)) continue;
+            if (!Unit.isAtomic(other) || unit.id >= other.id || !validUnitPair(structure, unit, other)) continue;
 
             if (other.elements.length >= unit.elements.length) findPairBonds(unit, other, props, map);
             else findPairBonds(other, unit, props, map);
@@ -207,19 +207,10 @@ function findBonds(structure: Structure, props: InterBondComputationProps) {
     return new InterUnitBonds(map);
 }
 
-function ValidUnitPair(structure: Structure) {
-    const { masterModel } = structure
-    if (masterModel) {
-        return (a: Unit, b: Unit) => a.model === b.model || a.model === masterModel || b.model === masterModel
-    } else {
-        return (a: Unit, b: Unit) => a.model === b.model
-    }
-}
-
 function computeInterUnitBonds(structure: Structure, props?: Partial<InterBondComputationProps>): InterUnitBonds {
     return findBonds(structure, {
         ...DefaultBondComputationProps,
-        validUnitPair: (props && props.validUnitPair) || ValidUnitPair(structure),
+        validUnitPair: (props && props.validUnitPair) || Structure.validUnitPair,
     });
 }