diff --git a/src/mol-model/structure/structure/unit.ts b/src/mol-model/structure/structure/unit.ts index 88db3d07de3a48fbab4b086f2dca70a19788e487..d50179acd7784097e4e6d6d3d66d1b232df8c7a4 100644 --- a/src/mol-model/structure/structure/unit.ts +++ b/src/mol-model/structure/structure/unit.ts @@ -14,7 +14,7 @@ import { ValueRef } from '../../../mol-util'; import { UnitRings } from './unit/rings'; import StructureElement from './element' import { ChainIndex, ResidueIndex, ElementIndex } from '../model/indexing'; -import { IntMap, SortedArray } from '../../../mol-data/int'; +import { IntMap, SortedArray, Segmentation } from '../../../mol-data/int'; import { hash2, hashFnv32a } from '../../../mol-data/util'; import { getAtomicPolymerElements, getCoarsePolymerElements, getAtomicGapElements, getCoarseGapElements, getNucleotideElements, getProteinElements } from './util/polymer'; import { mmCIF_Schema } from '../../../mol-io/reader/cif/schema/mmcif'; @@ -202,6 +202,20 @@ namespace Unit { return this.props.proteinElements.ref; } + get residueCount(): number { + if (this.props.residueCount.ref !== undefined) return this.props.residueCount.ref; + + let residueCount = 0 + const residueIt = Segmentation.transientSegments(this.model.atomicHierarchy.residueAtomSegments, this.elements) + while (residueIt.hasNext) { + residueIt.move() + residueCount += 1 + } + + this.props.residueCount.ref = residueCount; + return this.props.residueCount.ref!; + } + getResidueIndex(elementIndex: StructureElement.UnitIndex) { return this.model.atomicHierarchy.residueAtomSegments.index[this.elements[elementIndex]]; } @@ -227,6 +241,7 @@ namespace Unit { gapElements: ValueRef<SortedArray<ElementIndex> | undefined> nucleotideElements: ValueRef<SortedArray<ElementIndex> | undefined> proteinElements: ValueRef<SortedArray<ElementIndex> | undefined> + residueCount: ValueRef<number | undefined> } function AtomicProperties(): AtomicProperties { @@ -238,6 +253,7 @@ namespace Unit { gapElements: ValueRef.create(void 0), nucleotideElements: ValueRef.create(void 0), proteinElements: ValueRef.create(void 0), + residueCount: ValueRef.create(void 0), }; }