Explorar el Código

Structure.bondCount

Alexander Rose hace 5 años
padre
commit
d285076acb

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

@@ -15,7 +15,7 @@ import Unit from './unit'
 import { StructureLookup3D } from './util/lookup3d';
 import { CoarseElements } from '../model/properties/coarse';
 import { StructureSubsetBuilder } from './util/subset-builder';
-import { InterUnitBonds, computeInterUnitBonds } from './unit/links';
+import { InterUnitBonds, computeInterUnitBonds, Link } from './unit/links';
 import { PairRestraints, CrossLinkRestraint, extractCrossLinkRestraints } from './unit/pair-restraints';
 import StructureSymmetry from './symmetry';
 import StructureProperties from './properties';
@@ -57,6 +57,7 @@ class Structure {
         /** Hash based on all unit.id values in the structure, reflecting the units transformation */
         transformHash: number,
         elementCount: number,
+        bondCount: number,
         uniqueElementCount: number,
         polymerResidueCount: number,
         polymerUnitCount: number,
@@ -68,6 +69,7 @@ class Structure {
         hashCode: -1,
         transformHash: -1,
         elementCount: -1,
+        bondCount: -1,
         uniqueElementCount: -1,
         polymerResidueCount: -1,
         polymerUnitCount: -1,
@@ -84,6 +86,14 @@ class Structure {
         return this._props.elementCount;
     }
 
+    /** Count of all bonds (intra- and inter-unit) in the structure */
+    get bondCount() {
+        if (!this._props.bondCount) {
+            this._props.bondCount = this.interUnitBonds.bondCount + Link.getIntraUnitBondCount(this)
+        }
+        return this._props.bondCount;
+    }
+
     get hasCustomProperties() {
         return !!this._props.customProps && this._props.customProps.all.length > 0;
     }

+ 10 - 1
src/mol-model/structure/structure/unit/links.ts

@@ -8,7 +8,7 @@
 import { Unit, StructureElement } from '../../structure'
 import Structure from '../structure';
 import { LinkType } from '../../model/types';
-import { SortedArray } from '../../../../mol-data/int';
+import { SortedArray, Iterator } from '../../../../mol-data/int';
 
 export * from './links/data'
 export * from './links/intra-compute'
@@ -142,6 +142,15 @@ namespace Link {
         }
     }
 
+    export function getIntraUnitBondCount(structure: Structure) {
+        let count = 0
+        for (let i = 0, il = structure.units.length; i < il; ++i) {
+            const u = structure.units[i]
+            if (Unit.isAtomic(u)) count += u.links.edgeCount / 2 // only count one direction
+        }
+        return count
+    }
+
     export interface ElementLinkData {
         otherUnit: Unit.Atomic
         otherIndex: StructureElement.UnitIndex