diff --git a/src/apps/structure-info/model.ts b/src/apps/structure-info/model.ts index b6a66fcf6aa54b9d06f42d02bd3bc5369ccfab43..75501e48801f7c70976c2919e92858ea522d550b 100644 --- a/src/apps/structure-info/model.ts +++ b/src/apps/structure-info/model.ts @@ -29,20 +29,20 @@ async function readPdbFile(path: string) { } export function atomLabel(model: Model, aI: number) { - const { atoms, residues, chains, residueSegments, chainSegments } = model.atomicHierarchy + const { atoms, residues, chains, residueAtomSegments, chainAtomSegments } = model.atomicHierarchy const { label_atom_id } = atoms const { label_comp_id, label_seq_id } = residues const { label_asym_id } = chains - const rI = residueSegments.segmentMap[aI] - const cI = chainSegments.segmentMap[aI] + const rI = residueAtomSegments.index[aI] + const cI = chainAtomSegments.index[aI] return `${label_asym_id.value(cI)} ${label_comp_id.value(rI)} ${label_seq_id.value(rI)} ${label_atom_id.value(aI)}` } export function residueLabel(model: Model, rI: number) { - const { residues, chains, residueSegments, chainSegments } = model.atomicHierarchy + const { residues, chains, residueAtomSegments, chainAtomSegments } = model.atomicHierarchy const { label_comp_id, label_seq_id } = residues const { label_asym_id } = chains - const cI = chainSegments.segmentMap[residueSegments.segments[rI]] + const cI = chainAtomSegments.index[residueAtomSegments.offsets[rI]] return `${label_asym_id.value(cI)} ${label_comp_id.value(rI)} ${label_seq_id.value(rI)}` } diff --git a/src/mol-data/int/_spec/segmentation.spec.ts b/src/mol-data/int/_spec/segmentation.spec.ts index f91eff82ac3ad56bdaa039d07a933faf015400bc..ef253062a74e3205f9a472fc0163ecea97384118 100644 --- a/src/mol-data/int/_spec/segmentation.spec.ts +++ b/src/mol-data/int/_spec/segmentation.spec.ts @@ -21,12 +21,12 @@ describe('segments', () => { it('ofOffsetts', () => { const p = Segmentation.ofOffsets([10, 12], Interval.ofBounds(10, 14)); - expect(p.segments).toEqual(new Int32Array([0, 2, 4])) + expect(p.offsets).toEqual(new Int32Array([0, 2, 4])) }); it('map', () => { const segs = Segmentation.create([0, 1, 2]); - expect(segs.segmentMap).toEqual(new Int32Array([0, 1])); + expect(segs.index).toEqual(new Int32Array([0, 1])); expect(Segmentation.getSegment(segs, 0)).toBe(0); expect(Segmentation.getSegment(segs, 1)).toBe(1); }); diff --git a/src/mol-data/int/impl/segmentation.ts b/src/mol-data/int/impl/segmentation.ts index a5534e52a2d412e9be7e288fe13b9a39ba51e704..c43d04ba368c1bbadac09414221c27bf1d733e6b 100644 --- a/src/mol-data/int/impl/segmentation.ts +++ b/src/mol-data/int/impl/segmentation.ts @@ -12,23 +12,23 @@ import Segs from '../segmentation' interface Segmentation { /** Segments stored as a sorted array */ - segments: SortedArray, + offsets: SortedArray, /** Mapping of values to segments */ - segmentMap: Int32Array, + index: Int32Array, /** Number of segments */ count: number } export function create(values: ArrayLike<number>): Segmentation { - const segments = SortedArray.ofSortedArray(values); - const max = SortedArray.max(segments); - const segmentMap = new Int32Array(max); + const offsets = SortedArray.ofSortedArray(values); + const max = SortedArray.max(offsets); + const index = new Int32Array(max); for (let i = 0, _i = values.length - 1; i < _i; i++) { for (let j = values[i], _j = values[i + 1]; j < _j; j++) { - segmentMap[j] = i; + index[j] = i; } } - return { segments, segmentMap, count: values.length - 1 }; + return { offsets, index, count: values.length - 1 }; } export function ofOffsets(offsets: ArrayLike<number>, bounds: Interval): Segmentation { @@ -42,12 +42,12 @@ export function ofOffsets(offsets: ArrayLike<number>, bounds: Interval): Segment } export function count({ count }: Segmentation) { return count; } -export function getSegment({ segmentMap }: Segmentation, value: number) { return segmentMap[value]; } +export function getSegment({ index }: Segmentation, value: number) { return index[value]; } -export function projectValue({ segments }: Segmentation, set: OrderedSet, value: number): Interval { - const last = OrderedSet.max(segments); - const idx = value >= last ? -1 : OrderedSet.findPredecessorIndex(segments, value - 1); - return OrderedSet.findRange(set, OrderedSet.getAt(segments, idx), OrderedSet.getAt(segments, idx + 1) - 1); +export function projectValue({ offsets }: Segmentation, set: OrderedSet, value: number): Interval { + const last = OrderedSet.max(offsets); + const idx = value >= last ? -1 : OrderedSet.findPredecessorIndex(offsets, value - 1); + return OrderedSet.findRange(set, OrderedSet.getAt(offsets, idx), OrderedSet.getAt(offsets, idx + 1) - 1); } export class SegmentIterator<T extends number = number> implements Iterator<Segs.Segment<T>> { @@ -107,5 +107,5 @@ export class SegmentIterator<T extends number = number> implements Iterator<Segs export function segments(segs: Segmentation, set: OrderedSet, segment?: Segs.Segment) { const int = typeof segment !== 'undefined' ? Interval.ofBounds(segment.start, segment.end) : Interval.ofBounds(0, OrderedSet.size(set)); - return new SegmentIterator(segs.segments, segs.segmentMap, set, int); + return new SegmentIterator(segs.offsets, segs.index, set, int); } \ No newline at end of file diff --git a/src/mol-data/int/segmentation.ts b/src/mol-data/int/segmentation.ts index 94abaaa0f1b823c16ff5b37e252e7d5b7c40af8e..6007a20c24917c997194c46fefb612147bcb64c4 100644 --- a/src/mol-data/int/segmentation.ts +++ b/src/mol-data/int/segmentation.ts @@ -24,8 +24,10 @@ namespace Segmentation { interface Segmentation<T extends number = number> { '@type': 'segmentation', - readonly segments: ArrayLike<T>, - readonly segmentMap: ArrayLike<number>, + /** All segments are defined by offsets [offsets[i], offsets[i + 1]) for i \in [0, count - 1] */ + readonly offsets: ArrayLike<T>, + /** Segment index of the i-th element */ + readonly index: ArrayLike<number>, readonly count: number } diff --git a/src/mol-geo/representation/structure/visual/util/polymer.ts b/src/mol-geo/representation/structure/visual/util/polymer.ts index b663fc5a08ffbbeeb0e0ba988ed94b9cc7f51bb0..cc83cba84f042faceab0beb0824f2ae8ae3bf3bb 100644 --- a/src/mol-geo/representation/structure/visual/util/polymer.ts +++ b/src/mol-geo/representation/structure/visual/util/polymer.ts @@ -17,9 +17,9 @@ export function getPolymerElementCount(unit: Unit) { const { elements } = unit const l = Element.Location(unit) if (Unit.isAtomic(unit)) { - const { polymerSegments, residueSegments } = unit.model.atomicHierarchy - const polymerIt = Segmentation.transientSegments(polymerSegments, elements); - const residuesIt = Segmentation.transientSegments(residueSegments, elements); + const { polymerAtomSegments, residueAtomSegments } = unit.model.atomicHierarchy + const polymerIt = Segmentation.transientSegments(polymerAtomSegments, elements); + const residuesIt = Segmentation.transientSegments(residueAtomSegments, elements); while (polymerIt.hasNext) { residuesIt.setSegment(polymerIt.move()); while (residuesIt.hasNext) { @@ -147,9 +147,9 @@ export class AtomicPolymerBackboneIterator<T extends number = number> implements } constructor(unit: Unit.Atomic) { - const { polymerSegments, residueSegments } = unit.model.atomicHierarchy - this.polymerIt = Segmentation.transientSegments(polymerSegments, unit.elements); - this.residueIt = Segmentation.transientSegments(residueSegments, unit.elements); + const { polymerAtomSegments, residueAtomSegments } = unit.model.atomicHierarchy + this.polymerIt = Segmentation.transientSegments(polymerAtomSegments, unit.elements); + this.residueIt = Segmentation.transientSegments(residueAtomSegments, unit.elements); this.pos = unit.conformation.invariantPosition this.value = createPolymerBackbonePair(unit) this.hasNext = this.residueIt.hasNext || this.polymerIt.hasNext @@ -318,9 +318,9 @@ export class AtomicPolymerTraceIterator<T extends number = number> implements It } constructor(unit: Unit.Atomic) { - const { polymerSegments, residueSegments } = unit.model.atomicHierarchy - this.polymerIt = Segmentation.transientSegments(polymerSegments, unit.elements); - this.residueIt = Segmentation.transientSegments(residueSegments, unit.elements); + const { polymerAtomSegments, residueAtomSegments } = unit.model.atomicHierarchy + this.polymerIt = Segmentation.transientSegments(polymerAtomSegments, unit.elements); + this.residueIt = Segmentation.transientSegments(residueAtomSegments, unit.elements); // this.pos = unit.conformation.invariantPosition this.value = createPolymerTraceElement(unit) this.hasNext = this.residueIt.hasNext || this.polymerIt.hasNext diff --git a/src/mol-model/structure/export/categories/secondary-structure.ts b/src/mol-model/structure/export/categories/secondary-structure.ts index 7d051ddc55de482ad13f93e8b065cafb81eb9baf..1236e534540309826fe5b69d1ca24fb2546e3e94 100644 --- a/src/mol-model/structure/export/categories/secondary-structure.ts +++ b/src/mol-model/structure/export/categories/secondary-structure.ts @@ -88,7 +88,7 @@ function findElements<T extends SecondaryStructure.Element>(ctx: CifExportContex // currently can only support this for "identity" operators. if (!Unit.isAtomic(unit) || !unit.conformation.operator.isIdentity) continue; - const segs = unit.model.atomicHierarchy.residueSegments; + const segs = unit.model.atomicHierarchy.residueAtomSegments; const residues = Segmentation.transientSegments(segs, unit.elements); let current: Segmentation.Segment<Element>, move = true; @@ -110,8 +110,8 @@ function findElements<T extends SecondaryStructure.Element>(ctx: CifExportContex if (startIdx !== key[current.index]) { move = false; ssElements[ssElements.length] = { - start: Element.Location(unit, segs.segments[start]), - end: Element.Location(unit, segs.segments[prev]), + start: Element.Location(unit, segs.offsets[start]), + end: Element.Location(unit, segs.offsets[prev]), length: prev - start + 1, element } diff --git a/src/mol-model/structure/model/formats/mmcif/atomic.ts b/src/mol-model/structure/model/formats/mmcif/atomic.ts index 736c81fe63d4fcc2a062462e22c8088f7a1dfb9f..5ab6ded5d7192a896499d3ce4853fc2578d62618 100644 --- a/src/mol-model/structure/model/formats/mmcif/atomic.ts +++ b/src/mol-model/structure/model/formats/mmcif/atomic.ts @@ -92,9 +92,9 @@ export function getAtomicHierarchyAndConformation(format: mmCIF_Format, atom_sit } const hierarchySegments: AtomicSegments = { - residueSegments: Segmentation.ofOffsets(hierarchyOffsets.residues, Interval.ofBounds(0, atom_site._rowCount)), - chainSegments: Segmentation.ofOffsets(hierarchyOffsets.chains, Interval.ofBounds(0, atom_site._rowCount)), - polymerSegments: Segmentation.ofOffsets(hierarchyOffsets.polymers, Interval.ofBounds(0, atom_site._rowCount)), + residueAtomSegments: Segmentation.ofOffsets(hierarchyOffsets.residues, Interval.ofBounds(0, atom_site._rowCount)), + chainAtomSegments: Segmentation.ofOffsets(hierarchyOffsets.chains, Interval.ofBounds(0, atom_site._rowCount)), + polymerAtomSegments: Segmentation.ofOffsets(hierarchyOffsets.polymers, Interval.ofBounds(0, atom_site._rowCount)), } const hierarchyKeys = getAtomicKeys(hierarchyData, entities, hierarchySegments); diff --git a/src/mol-model/structure/model/formats/mmcif/bonds/comp.ts b/src/mol-model/structure/model/formats/mmcif/bonds/comp.ts index b89b473df9e6dfccb1d0732099290c60a1c4382d..6a3f12ffe0b76444f4d8d14ee9ba6506acd80a36 100644 --- a/src/mol-model/structure/model/formats/mmcif/bonds/comp.ts +++ b/src/mol-model/structure/model/formats/mmcif/bonds/comp.ts @@ -137,7 +137,7 @@ export namespace ComponentBond { const loc = Element.Location(); for (const unit of s.units) { if (!Unit.isAtomic(unit)) continue; - const residues = Segmentation.transientSegments(unit.model.atomicHierarchy.residueSegments, unit.elements); + const residues = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, unit.elements); loc.unit = unit; while (residues.hasNext) { const seg = residues.move(); diff --git a/src/mol-model/structure/model/formats/mmcif/secondary-structure.ts b/src/mol-model/structure/model/formats/mmcif/secondary-structure.ts index af127410e8bc68c8adb4b201df6091c0ed1d4cec..2e181f668b2c1b45bece85f5125aeee64de28d9a 100644 --- a/src/mol-model/structure/model/formats/mmcif/secondary-structure.ts +++ b/src/mol-model/structure/model/formats/mmcif/secondary-structure.ts @@ -135,7 +135,7 @@ function assignSecondaryStructureEntry(hierarchy: AtomicHierarchy, entry: Second const { endSeqNumber, endInsCode, key, type } = entry; let rI = resStart; - while (rI <= resEnd) { + while (rI < resEnd) { const seqNumber = label_seq_id.value(rI); data.type[rI] = type; data.key[rI] = key; @@ -150,18 +150,17 @@ function assignSecondaryStructureEntry(hierarchy: AtomicHierarchy, entry: Second } function assignSecondaryStructureRanges(hierarchy: AtomicHierarchy, map: SecondaryStructureMap, data: SecondaryStructureData) { - const { segments: chainAtomSegments, count: chainCount } = hierarchy.chainSegments; - const { segmentMap: residueIndex } = hierarchy.residueSegments; + const { count: chainCount } = hierarchy.chainAtomSegments; const { label_asym_id } = hierarchy.chains; const { label_seq_id, pdbx_PDB_ins_code } = hierarchy.residues; for (let cI = 0; cI < chainCount; cI++) { - const resStart = residueIndex[chainAtomSegments[cI]], resEnd = residueIndex[chainAtomSegments[cI + 1] - 1]; + const resStart = AtomicHierarchy.chainStartResidueIndex(hierarchy, cI), resEnd = AtomicHierarchy.chainEndResidueIndexExcl(hierarchy, cI); const asymId = label_asym_id.value(cI); if (map.has(asymId)) { const entries = map.get(asymId)!; - for (let rI = resStart; rI <= resEnd; rI++) { + for (let rI = resStart; rI < resEnd; rI++) { const seqNumber = label_seq_id.value(rI); if (entries.has(seqNumber)) { const entry = entries.get(seqNumber)!; diff --git a/src/mol-model/structure/model/formats/mmcif/util.ts b/src/mol-model/structure/model/formats/mmcif/util.ts index 672acf2efc9049c90a361e289088ce1240100c8b..7c4806cc1988dd921eedaba84536b02578a585c5 100644 --- a/src/mol-model/structure/model/formats/mmcif/util.ts +++ b/src/mol-model/structure/model/formats/mmcif/util.ts @@ -17,9 +17,9 @@ export function findEntityIdByAsymId(model: Model, asymId: string) { } export function findAtomIndexByLabelName(model: Model, residueIndex: number, atomName: string, altLoc: string | null): Element { - const { segments } = model.atomicHierarchy.residueSegments; + const { offsets } = model.atomicHierarchy.residueAtomSegments; const { label_atom_id, label_alt_id } = model.atomicHierarchy.atoms; - for (let i = segments[residueIndex], n = segments[residueIndex + 1]; i < n; ++i) { + for (let i = offsets[residueIndex], n = offsets[residueIndex + 1]; i < n; ++i) { if (label_atom_id.value(i) === atomName && (!altLoc || label_alt_id.value(i) === altLoc)) return i as Element; } return -1 as Element; diff --git a/src/mol-model/structure/model/properties/atomic/hierarchy.ts b/src/mol-model/structure/model/properties/atomic/hierarchy.ts index 12c9de4c1ed01dfbaaa055a7d2e7756ced2ed743..2d2612a759769bc91317157fa71c3b08f8048ba5 100644 --- a/src/mol-model/structure/model/properties/atomic/hierarchy.ts +++ b/src/mol-model/structure/model/properties/atomic/hierarchy.ts @@ -49,14 +49,22 @@ export interface AtomicData { export interface AtomicSegments { /** Maps residueIndex to a range of atoms [segments[rI], segments[rI + 1]) */ - residueSegments: Segmentation<Element>, - /** Maps chainIndex to a range of atoms [segments[cI], segments[cI + 1]) */ - chainSegments: Segmentation<Element>, + residueAtomSegments: Segmentation<Element>, + /** + * Maps chainIndex to a range of atoms [segments[cI], segments[cI + 1]), + * + * residues of i-th chain are accessed like this: + * const rI = residueAtomSegments.index, offsets = chainAtomSegments.offsets; + * const start = rI[offsets[i]], const end = rI[offsets[i + 1] - 1] + 1; + * for (let j = start; j < end; i++) { } + */ + chainAtomSegments: Segmentation<Element>, /** * bonded/connected stretches of polymer chains, i.e. a chain will be * broken into multiple polymer segments if there are missing residues */ - polymerSegments: Segmentation<Element> + polymerAtomSegments: Segmentation<Element> + // TODO: include entity segments? } @@ -79,4 +87,16 @@ export interface AtomicKeys { } type _Hierarchy = AtomicData & AtomicSegments & AtomicKeys -export interface AtomicHierarchy extends _Hierarchy { } \ No newline at end of file +export interface AtomicHierarchy extends _Hierarchy { } + +export namespace AtomicHierarchy { + /** Start residue inclusive */ + export function chainStartResidueIndex(segs: AtomicSegments, cI: number) { + return segs.residueAtomSegments.index[segs.chainAtomSegments.offsets[cI]]; + } + + /** End residue exclusive */ + export function chainEndResidueIndexExcl(segs: AtomicSegments, cI: number) { + return segs.residueAtomSegments.index[segs.chainAtomSegments.offsets[cI + 1] - 1] + 1; + } +} \ No newline at end of file diff --git a/src/mol-model/structure/model/properties/sequence.ts b/src/mol-model/structure/model/properties/sequence.ts index 7725eb561352a4c044b1cd410160e545f31aa8e8..ec7b5da767dbf045ace0d18035ab81b0612a2ea6 100644 --- a/src/mol-model/structure/model/properties/sequence.ts +++ b/src/mol-model/structure/model/properties/sequence.ts @@ -25,7 +25,7 @@ namespace StructureSequence { export function fromAtomicHierarchy(entities: Entities, hierarchy: AtomicHierarchy, modResMap?: Map<string, string>): StructureSequence { const { label_comp_id, label_seq_id } = hierarchy.residues - const { chainSegments, residueSegments } = hierarchy + const { chainAtomSegments, residueAtomSegments } = hierarchy const byEntityKey: StructureSequence['byEntityKey'] = { }; const sequences: StructureSequence.Entity[] = []; @@ -42,8 +42,8 @@ namespace StructureSequence { } cI--; - const rStart = residueSegments.segmentMap[chainSegments.segments[start]]; - const rEnd = residueSegments.segmentMap[chainSegments.segments[cI + 1]]; + const rStart = residueAtomSegments.index[chainAtomSegments.offsets[start]]; + const rEnd = residueAtomSegments.index[chainAtomSegments.offsets[cI + 1]]; const compId = Column.window(label_comp_id, rStart, rEnd); const num = Column.window(label_seq_id, rStart, rEnd); diff --git a/src/mol-model/structure/model/properties/utils/atomic-keys.ts b/src/mol-model/structure/model/properties/utils/atomic-keys.ts index dc4a3ac3f8818c333e59dad03d222e23110bc150..0fdf1c8e58b44d26addce926a79358071ea96b2a 100644 --- a/src/mol-model/structure/model/properties/utils/atomic-keys.ts +++ b/src/mol-model/structure/model/properties/utils/atomic-keys.ts @@ -67,7 +67,7 @@ export function getAtomicKeys(data: AtomicData, entities: Entities, segments: At const atomSet = Interval.ofBounds(0, data.atoms._rowCount); - const chainsIt = Segmentation.transientSegments(segments.chainSegments, atomSet); + const chainsIt = Segmentation.transientSegments(segments.chainAtomSegments, atomSet); while (chainsIt.hasNext) { const chainSegment = chainsIt.move(); const cI = chainSegment.index; @@ -81,7 +81,7 @@ export function getAtomicKeys(data: AtomicData, entities: Entities, segments: At entityKey[cI] = eKey; const residueMap = getElementSubstructureKeyMap(residueMaps, cKey); - const residuesIt = Segmentation.transientSegments(segments.residueSegments, atomSet, chainSegment); + const residuesIt = Segmentation.transientSegments(segments.residueAtomSegments, atomSet, chainSegment); while (residuesIt.hasNext) { const residueSegment = residuesIt.move(); const rI = residueSegment.index; diff --git a/src/mol-model/structure/model/properties/utils/coarse-keys.ts b/src/mol-model/structure/model/properties/utils/coarse-keys.ts index 8ea3f848ca2a2117f11df7f6f41cbcec68318462..4e4f613018db6b5495a774165d6b897f5edf27e3 100644 --- a/src/mol-model/structure/model/properties/utils/coarse-keys.ts +++ b/src/mol-model/structure/model/properties/utils/coarse-keys.ts @@ -65,7 +65,7 @@ export function getCoarseKeys(data: CoarseElementData, entities: Entities): Coar } for (let cI = 0; cI < chainSegments.count; cI++) { - const start = chainSegments.segments[cI], end = chainSegments.segments[cI + 1]; + const start = chainSegments.offsets[cI], end = chainSegments.offsets[cI + 1]; const map = getElementSubstructureKeyMap(chainMaps, entityKey[start]); const key = getElementKey(map, asym_id.value(start), chainCounter); for (let i = start; i < end; i++) chainKey[i] = key; diff --git a/src/mol-model/structure/query/generators.ts b/src/mol-model/structure/query/generators.ts index 290a8434117072f3439ab327cc212948021e1369..fd13be1fb7597025b65f39771015d3971be75d48 100644 --- a/src/mol-model/structure/query/generators.ts +++ b/src/mol-model/structure/query/generators.ts @@ -83,8 +83,8 @@ function atomGroupsSegmented({ entityTest, chainTest, residueTest, atomTest }: A const elements = unit.elements; builder.beginUnit(unit.id); - const chainsIt = Segmentation.transientSegments(unit.model.atomicHierarchy.chainSegments, elements); - const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueSegments, elements); + const chainsIt = Segmentation.transientSegments(unit.model.atomicHierarchy.chainAtomSegments, elements); + const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, elements); while (chainsIt.hasNext) { const chainSegment = chainsIt.move(); l.element = OrderedSet.getAt(elements, chainSegment.start); @@ -130,8 +130,8 @@ function atomGroupsGrouped({ entityTest, chainTest, residueTest, atomTest, group l.unit = unit; const elements = unit.elements; - const chainsIt = Segmentation.transientSegments(unit.model.atomicHierarchy.chainSegments, elements); - const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueSegments, elements); + const chainsIt = Segmentation.transientSegments(unit.model.atomicHierarchy.chainAtomSegments, elements); + const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, elements); while (chainsIt.hasNext) { const chainSegment = chainsIt.move(); l.element = OrderedSet.getAt(elements, chainSegment.start); diff --git a/src/mol-model/structure/query/modifiers.ts b/src/mol-model/structure/query/modifiers.ts index 3b332ff7fcfc9d142ae080968375a3c54af0eedb..01150fa2ff3c4aaf828dc151d88671dd4a7039ba 100644 --- a/src/mol-model/structure/query/modifiers.ts +++ b/src/mol-model/structure/query/modifiers.ts @@ -21,14 +21,14 @@ function getWholeResidues(ctx: RuntimeContext, source: Structure, structure: Str continue; } - const { residueSegments } = unit.model.atomicHierarchy; + const { residueAtomSegments } = unit.model.atomicHierarchy; const elements = unit.elements; builder.beginUnit(unit.id); - const residuesIt = Segmentation.transientSegments(residueSegments, elements); + const residuesIt = Segmentation.transientSegments(residueAtomSegments, elements); while (residuesIt.hasNext) { const rI = residuesIt.move().index; - for (let j = residueSegments.segments[rI], _j = residueSegments.segments[rI + 1]; j < _j; j++) { + for (let j = residueAtomSegments.offsets[rI], _j = residueAtomSegments.offsets[rI + 1]; j < _j; j++) { builder.addElement(j); } } diff --git a/src/mol-model/structure/structure/structure.ts b/src/mol-model/structure/structure/structure.ts index 7202df6b7937c805104ed526a5c63e393c7d1c8f..d5f053a437c7972c30f5ff943b0645f7f44c5d18 100644 --- a/src/mol-model/structure/structure/structure.ts +++ b/src/mol-model/structure/structure/structure.ts @@ -118,20 +118,20 @@ namespace Structure { * of consecutive "single atom chains". */ export function ofModel(model: Model): Structure { - const chains = model.atomicHierarchy.chainSegments; + const chains = model.atomicHierarchy.chainAtomSegments; const builder = new StructureBuilder(); for (let c = 0; c < chains.count; c++) { - const start = chains.segments[c]; + const start = chains.offsets[c]; // merge all consecutive "single atom chains" while (c + 1 < chains.count - && chains.segments[c + 1] - chains.segments[c] === 1 - && chains.segments[c + 2] - chains.segments[c + 1] === 1) { + && chains.offsets[c + 1] - chains.offsets[c] === 1 + && chains.offsets[c + 2] - chains.offsets[c + 1] === 1) { c++; } - const elements = SortedArray.ofBounds(start as Element, chains.segments[c + 1] as Element); + const elements = SortedArray.ofBounds(start as Element, chains.offsets[c + 1] as Element); builder.addUnit(Unit.Kind.Atomic, model, SymmetryOperator.Default, elements); } @@ -151,7 +151,7 @@ namespace Structure { function addCoarseUnits(builder: StructureBuilder, model: Model, elements: CoarseElements, kind: Unit.Kind) { const { chainSegments } = elements; for (let cI = 0; cI < chainSegments.count; cI++) { - const elements = SortedArray.ofBounds(chainSegments.segments[cI] as Element, chainSegments.segments[cI + 1] as Element); + const elements = SortedArray.ofBounds(chainSegments.offsets[cI] as Element, chainSegments.offsets[cI + 1] as Element); builder.addUnit(kind, model, SymmetryOperator.Default, elements); } } @@ -266,7 +266,7 @@ namespace Structure { l.unit = unit; const elements = unit.elements; - const chainsIt = Segmentation.transientSegments(unit.model.atomicHierarchy.chainSegments, elements); + const chainsIt = Segmentation.transientSegments(unit.model.atomicHierarchy.chainAtomSegments, elements); while (chainsIt.hasNext) { const chainSegment = chainsIt.move(); l.element = elements[chainSegment.start]; diff --git a/src/mol-model/structure/structure/unit.ts b/src/mol-model/structure/structure/unit.ts index 92d0da4976ae61b274077657d485a18ce7e40c0d..14d0fc8185d93f24c8df04b5828abf4c18da0b4c 100644 --- a/src/mol-model/structure/structure/unit.ts +++ b/src/mol-model/structure/structure/unit.ts @@ -123,8 +123,8 @@ namespace Unit { this.elements = elements; this.conformation = conformation; - this.residueIndex = model.atomicHierarchy.residueSegments.segmentMap; - this.chainIndex = model.atomicHierarchy.chainSegments.segmentMap; + this.residueIndex = model.atomicHierarchy.residueAtomSegments.index; + this.chainIndex = model.atomicHierarchy.chainAtomSegments.index; this.props = props; } } diff --git a/src/mol-model/structure/structure/unit/rings/compute.ts b/src/mol-model/structure/structure/unit/rings/compute.ts index c0bafe3e3abe380d3557ef14edfdd3225299902b..69ffa0506d0499e7870ff19010edf55d95d45405 100644 --- a/src/mol-model/structure/structure/unit/rings/compute.ts +++ b/src/mol-model/structure/structure/unit/rings/compute.ts @@ -13,7 +13,7 @@ export default function computeRings(unit: Unit.Atomic) { const size = largestResidue(unit); const state = State(unit, size); - const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueSegments, unit.elements); + const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, unit.elements); while (residuesIt.hasNext) { const seg = residuesIt.move(); processResidue(state, seg.start, seg.end); @@ -75,7 +75,7 @@ function resetState(state: State) { } function largestResidue(unit: Unit.Atomic) { - const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueSegments, unit.elements); + const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, unit.elements); let size = 0; while (residuesIt.hasNext) { const seg = residuesIt.move();