Prechádzať zdrojové kódy

mol-model: struct conn bonds fix

David Sehnal 5 rokov pred
rodič
commit
c0236650f0

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

@@ -80,8 +80,10 @@ function findPairBonds(unitA: Unit.Atomic, unitB: Unit.Atomic, props: BondComput
             let added = false;
             for (const se of structConnEntries) {
                 for (const p of se.partners) {
+                    if (aI === p.atomIndex) continue;
+
                     const _bI = SortedArray.indexOf(unitB.elements, p.atomIndex) as StructureElement.UnitIndex;
-                    if (_bI < 0 || _aI === _bI) continue;
+                    if (_bI < 0) continue;
                     // check if the bond is within MAX_RADIUS for this pair of units
                     if (getDistance(unitA, aI, unitB, p.atomIndex) > MAX_RADIUS) continue;
                     builder.add(_aI, _bI, { order: se.order, flag: se.flags });

+ 13 - 4
src/mol-model/structure/structure/unit/bonds/intra-compute.ts

@@ -29,6 +29,8 @@ function getGraph(atomA: StructureElement.UnitIndex[], atomB: StructureElement.U
     return builder.createGraph({ flags, order });
 }
 
+const __structConnAdded = new Set<StructureElement.UnitIndex>();
+
 function _computeBonds(unit: Unit.Atomic, props: BondComputationProps): IntraUnitBonds {
     const MAX_RADIUS = 4;
 
@@ -51,6 +53,8 @@ function _computeBonds(unit: Unit.Atomic, props: BondComputationProps): IntraUni
     let lastResidue = -1;
     let componentMap: Map<string, Map<string, { flags: number, order: number }>> | undefined = void 0;
 
+    const structConnAdded = __structConnAdded;
+
     for (let _aI = 0 as StructureElement.UnitIndex; _aI < atomCount; _aI++) {
         const aI =  atoms[_aI];
 
@@ -67,17 +71,22 @@ function _computeBonds(unit: Unit.Atomic, props: BondComputationProps): IntraUni
         }
 
         const structConnEntries = props.forceCompute ? void 0 : structConn && structConn.getAtomEntries(aI);
-        const structConnAdded = new Set<StructureElement.UnitIndex>()
+        let hasStructConn = false;
         if (structConnEntries) {
             for (const se of structConnEntries) {
                 for (const p of se.partners) {
+                    if (aI === p.atomIndex) continue;
+
                     const _bI = SortedArray.indexOf(unit.elements, p.atomIndex) as StructureElement.UnitIndex;
-                    if (_bI < 0 || _aI === _bI) continue;
+                    if (_bI < 0) continue;
                     atomA[atomA.length] = _aI;
                     atomB[atomB.length] = _bI;
                     flags[flags.length] = se.flags;
                     order[order.length] = se.order;
-                    structConnAdded.add(_bI)
+
+                    if (!hasStructConn) structConnAdded.clear();
+                    hasStructConn = true;
+                    structConnAdded.add(_bI);
                 }
             }
         }
@@ -106,7 +115,7 @@ function _computeBonds(unit: Unit.Atomic, props: BondComputationProps): IntraUni
 
         for (let ni = 0; ni < count; ni++) {
             const _bI = indices[ni];
-            if (structConnAdded.has(_bI)) continue;
+            if (hasStructConn && structConnAdded.has(_bI)) continue;
 
             const bI = atoms[_bI];
             if (bI <= aI) continue;