Skip to content
Snippets Groups Projects
Commit e3470396 authored by Alexander Rose's avatar Alexander Rose
Browse files

trace iterator optimiation

parent a500e55c
Branches
Tags
No related merge requests found
...@@ -6,12 +6,11 @@ ...@@ -6,12 +6,11 @@
import { Unit, StructureElement, ElementIndex, ResidueIndex } from 'mol-model/structure'; import { Unit, StructureElement, ElementIndex, ResidueIndex } from 'mol-model/structure';
import { Segmentation } from 'mol-data/int'; import { Segmentation } from 'mol-data/int';
import { MoleculeType, SecondaryStructureType, AtomRole } from 'mol-model/structure/model/types'; import { MoleculeType, SecondaryStructureType } from 'mol-model/structure/model/types';
import Iterator from 'mol-data/iterator'; import Iterator from 'mol-data/iterator';
import { Vec3 } from 'mol-math/linear-algebra'; import { Vec3 } from 'mol-math/linear-algebra';
import SortedRanges from 'mol-data/int/sorted-ranges'; import SortedRanges from 'mol-data/int/sorted-ranges';
import { CoarseSphereConformation, CoarseGaussianConformation } from 'mol-model/structure/model/properties/coarse'; import { CoarseSphereConformation, CoarseGaussianConformation } from 'mol-model/structure/model/properties/coarse';
import { getAtomicMoleculeType, getElementIndexForAtomRole } from 'mol-model/structure/util';
import { getPolymerRanges } from '../polymer'; import { getPolymerRanges } from '../polymer';
import { AtomicConformation } from 'mol-model/structure/model/properties/atomic'; import { AtomicConformation } from 'mol-model/structure/model/properties/atomic';
...@@ -69,6 +68,9 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> ...@@ -69,6 +68,9 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement>
private nextSecStrucType: SecondaryStructureType private nextSecStrucType: SecondaryStructureType
private state: AtomicPolymerTraceIteratorState = AtomicPolymerTraceIteratorState.nextPolymer private state: AtomicPolymerTraceIteratorState = AtomicPolymerTraceIteratorState.nextPolymer
private residueAtomSegments: Segmentation<ElementIndex, ResidueIndex> private residueAtomSegments: Segmentation<ElementIndex, ResidueIndex>
private traceElementIndex: ArrayLike<ElementIndex>
private directionElementIndex: ArrayLike<ElementIndex>
private moleculeType: ArrayLike<MoleculeType>
private atomicConformation: AtomicConformation private atomicConformation: AtomicConformation
private p0 = Vec3.zero(); private p0 = Vec3.zero();
...@@ -98,24 +100,23 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> ...@@ -98,24 +100,23 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement>
this.residueSegmentMax = index[this.unit.elements[polymerSegment.end - 1]] this.residueSegmentMax = index[this.unit.elements[polymerSegment.end - 1]]
} }
private getElementIndex(residueIndex: ResidueIndex, atomRole: AtomRole) { private getResidueIndex(residueIndex: number) {
if (residueIndex < this.residueSegmentMin) { if (residueIndex < this.residueSegmentMin) {
const cyclicIndex = this.cyclicPolymerMap.get(this.residueSegmentMin) const cyclicIndex = this.cyclicPolymerMap.get(this.residueSegmentMin)
if (cyclicIndex !== undefined) { if (cyclicIndex !== undefined) {
residueIndex = cyclicIndex - (this.residueSegmentMin - residueIndex - 1) as ResidueIndex residueIndex = cyclicIndex - (this.residueSegmentMin - residueIndex - 1)
} else { } else {
residueIndex = this.residueSegmentMin residueIndex = this.residueSegmentMin
} }
} else if (residueIndex > this.residueSegmentMax) { } else if (residueIndex > this.residueSegmentMax) {
const cyclicIndex = this.cyclicPolymerMap.get(this.residueSegmentMax) const cyclicIndex = this.cyclicPolymerMap.get(this.residueSegmentMax)
if (cyclicIndex !== undefined) { if (cyclicIndex !== undefined) {
residueIndex = cyclicIndex + (residueIndex - this.residueSegmentMax - 1) as ResidueIndex residueIndex = cyclicIndex + (residueIndex - this.residueSegmentMax - 1)
} else { } else {
residueIndex = this.residueSegmentMax residueIndex = this.residueSegmentMax
} }
} }
const elementIndex = getElementIndexForAtomRole(this.unit.model, residueIndex, atomRole) return residueIndex as ResidueIndex
return elementIndex === -1 ? this.residueAtomSegments.offsets[residueIndex] : elementIndex
} }
private setControlPoint(out: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, residueIndex: ResidueIndex) { private setControlPoint(out: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, residueIndex: ResidueIndex) {
...@@ -151,22 +152,22 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> ...@@ -151,22 +152,22 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement>
this.nextSecStrucType = residueIt.hasNext ? this.secondaryStructureType[residueIndex + 1] : SecStrucTypeNA this.nextSecStrucType = residueIt.hasNext ? this.secondaryStructureType[residueIndex + 1] : SecStrucTypeNA
value.secStrucType = this.currSecStrucType value.secStrucType = this.currSecStrucType
value.center.element = this.getElementIndex(residueIndex, 'trace') value.center.element = this.traceElementIndex[residueIndex]
value.first = residueIndex === this.residueSegmentMin value.first = residueIndex === this.residueSegmentMin
value.last = residueIndex === this.residueSegmentMax value.last = residueIndex === this.residueSegmentMax
value.secStrucFirst = this.prevSecStrucType !== this.currSecStrucType value.secStrucFirst = this.prevSecStrucType !== this.currSecStrucType
value.secStrucLast = this.currSecStrucType !== this.nextSecStrucType value.secStrucLast = this.currSecStrucType !== this.nextSecStrucType
value.moleculeType = getAtomicMoleculeType(this.unit.model, residueIndex) value.moleculeType = this.moleculeType[residueIndex]
if (value.first) { if (value.first) {
this.pos(this.p0, this.getElementIndex(residueIndex - 3 as ResidueIndex, 'trace')) this.pos(this.p0, this.traceElementIndex[this.getResidueIndex(residueIndex - 3)])
this.pos(this.p1, this.getElementIndex(residueIndex - 2 as ResidueIndex, 'trace')) this.pos(this.p1, this.traceElementIndex[this.getResidueIndex(residueIndex - 2)])
this.pos(this.p2, this.getElementIndex(residueIndex - 1 as ResidueIndex, 'trace')) this.pos(this.p2, this.traceElementIndex[this.getResidueIndex(residueIndex - 1)])
this.pos(this.p3, value.center.element) this.pos(this.p3, value.center.element)
this.pos(this.p4, this.getElementIndex(residueIndex + 1 as ResidueIndex, 'trace')) this.pos(this.p4, this.traceElementIndex[this.getResidueIndex(residueIndex + 1)])
this.pos(this.p5, this.getElementIndex(residueIndex + 2 as ResidueIndex, 'trace')) this.pos(this.p5, this.traceElementIndex[this.getResidueIndex(residueIndex + 2)])
this.pos(this.v12, this.getElementIndex(residueIndex - 1 as ResidueIndex, 'direction')) this.pos(this.v12, this.directionElementIndex[this.getResidueIndex(residueIndex - 1)])
} else { } else {
Vec3.copy(this.p0, this.p1) Vec3.copy(this.p0, this.p1)
Vec3.copy(this.p1, this.p2) Vec3.copy(this.p1, this.p2)
...@@ -177,8 +178,8 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> ...@@ -177,8 +178,8 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement>
Vec3.copy(this.v12, this.v23) Vec3.copy(this.v12, this.v23)
} }
this.pos(this.p6, this.getElementIndex(residueIndex + 3 as ResidueIndex, 'trace')) this.pos(this.p6, this.traceElementIndex[this.getResidueIndex(residueIndex + 3 as ResidueIndex)])
this.pos(this.v23, this.getElementIndex(residueIndex, 'direction')) this.pos(this.v23, this.directionElementIndex[residueIndex])
this.setControlPoint(value.p0, this.p0, this.p1, this.p2, residueIndex - 2 as ResidueIndex) this.setControlPoint(value.p0, this.p0, this.p1, this.p2, residueIndex - 2 as ResidueIndex)
this.setControlPoint(value.p1, this.p1, this.p2, this.p3, residueIndex - 1 as ResidueIndex) this.setControlPoint(value.p1, this.p1, this.p2, this.p3, residueIndex - 1 as ResidueIndex)
...@@ -202,6 +203,9 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> ...@@ -202,6 +203,9 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement>
constructor(private unit: Unit.Atomic) { constructor(private unit: Unit.Atomic) {
this.atomicConformation = unit.model.atomicConformation this.atomicConformation = unit.model.atomicConformation
this.residueAtomSegments = unit.model.atomicHierarchy.residueAtomSegments this.residueAtomSegments = unit.model.atomicHierarchy.residueAtomSegments
this.traceElementIndex = unit.model.atomicHierarchy.derived.residue.traceElementIndex
this.directionElementIndex = unit.model.atomicHierarchy.derived.residue.directionElementIndex
this.moleculeType = unit.model.atomicHierarchy.derived.residue.moleculeType
this.cyclicPolymerMap = unit.model.atomicHierarchy.cyclicPolymerMap this.cyclicPolymerMap = unit.model.atomicHierarchy.cyclicPolymerMap
this.secondaryStructureType = unit.model.properties.secondaryStructure.type this.secondaryStructureType = unit.model.properties.secondaryStructure.type
this.polymerIt = SortedRanges.transientSegments(getPolymerRanges(unit), unit.elements) this.polymerIt = SortedRanges.transientSegments(getPolymerRanges(unit), unit.elements)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment