Select Git revision
controls.tsx
trace-iterator.ts 19.69 KiB
/**
* Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Unit, StructureElement, ElementIndex, ResidueIndex, Structure } from '../../../../../mol-model/structure';
import { Segmentation, SortedArray } from '../../../../../mol-data/int';
import { MoleculeType, SecondaryStructureType } from '../../../../../mol-model/structure/model/types';
import Iterator from '../../../../../mol-data/iterator';
import { Vec3 } from '../../../../../mol-math/linear-algebra';
import SortedRanges from '../../../../../mol-data/int/sorted-ranges';
import { CoarseSphereConformation, CoarseGaussianConformation } from '../../../../../mol-model/structure/model/properties/coarse';
import { getPolymerRanges } from '../polymer';
import { AtomicConformation } from '../../../../../mol-model/structure/model/properties/atomic';
import { ComputedSecondaryStructure } from '../../../../../mol-model-props/computed/secondary-structure';
import { SecondaryStructure } from '../../../../../mol-model/structure/model/properties/seconday-structure';
/**
* Iterates over individual residues/coarse elements in polymers of a unit while
* providing information about the neighbourhood in the underlying model for drawing splines
*/
export function PolymerTraceIterator(unit: Unit, structure: Structure): Iterator<PolymerTraceElement> {
switch (unit.kind) {
case Unit.Kind.Atomic: return new AtomicPolymerTraceIterator(unit, structure)
case Unit.Kind.Spheres:
case Unit.Kind.Gaussians:
return new CoarsePolymerTraceIterator(unit, structure)
}
}
interface PolymerTraceElement {
center: StructureElement
centerPrev: StructureElement
centerNext: StructureElement
first: boolean, last: boolean
secStrucFirst: boolean, secStrucLast: boolean
secStrucType: SecondaryStructureType
moleculeType: MoleculeType
isCoarseBackbone: boolean
coarseBackboneFirst: boolean, coarseBackboneLast: boolean
p0: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, p4: Vec3
d12: Vec3, d23: Vec3
}
const SecStrucTypeNA = SecondaryStructureType.create(SecondaryStructureType.Flag.NA)
function createPolymerTraceElement (unit: Unit): PolymerTraceElement {
return {
center: StructureElement.create(unit),
centerPrev: StructureElement.create(unit),
centerNext: StructureElement.create(unit),
first: false, last: false,
secStrucFirst: false, secStrucLast: false,
secStrucType: SecStrucTypeNA,
moleculeType: MoleculeType.unknown,
coarseBackboneFirst: false, coarseBackboneLast: false,
isCoarseBackbone: false,
p0: Vec3(), p1: Vec3(), p2: Vec3(), p3: Vec3(), p4: Vec3(),
d12: Vec3(), d23: Vec3()
}
}
const enum AtomicPolymerTraceIteratorState { nextPolymer, nextResidue }
const tmpDir = Vec3()
const tmpVecA = Vec3()
const tmpVecB = Vec3()