diff --git a/src/mol-geo/representation/structure/visual/polymer-direction-wedge.ts b/src/mol-geo/representation/structure/visual/polymer-direction-wedge.ts index 2416ef089851893f697d471c8f200e9df4bb5662..b6eaf79647a2004288a76212be17ce0f6090618a 100644 --- a/src/mol-geo/representation/structure/visual/polymer-direction-wedge.ts +++ b/src/mol-geo/representation/structure/visual/polymer-direction-wedge.ts @@ -16,6 +16,7 @@ import { SecondaryStructureType, MoleculeType } from 'mol-model/structure/model/ import { StructureElementIterator } from './util/location-iterator'; import { DefaultUnitsMeshProps, UnitsMeshVisual } from '../units-visual'; import { SizeThemeProps, SizeTheme } from 'mol-view/theme/size'; +import { OrderedSet } from 'mol-data/int'; const t = Mat4.identity() const sVec = Vec3.zero() @@ -48,7 +49,7 @@ async function createPolymerDirectionWedgeMesh(ctx: RuntimeContext, unit: Unit, const polymerTraceIt = PolymerTraceIterator(unit) while (polymerTraceIt.hasNext) { const v = polymerTraceIt.move() - builder.setId(v.center.element) + builder.setId(OrderedSet.findPredecessorIndex(unit.elements, v.center.element)) const isNucleic = v.moleculeType === MoleculeType.DNA || v.moleculeType === MoleculeType.RNA const isSheet = SecondaryStructureType.is(v.secStrucType, SecondaryStructureType.Flag.Beta) diff --git a/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts b/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts index 86ee412bf4c70f4ec68f00c75b8e429cea4cb553..da04a008c769a1214ee024875f64ee4dbe317e84 100644 --- a/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts +++ b/src/mol-geo/representation/structure/visual/polymer-trace-mesh.ts @@ -15,6 +15,7 @@ import { SecondaryStructureType, MoleculeType } from 'mol-model/structure/model/ import { StructureElementIterator } from './util/location-iterator'; import { UnitsMeshVisual, DefaultUnitsMeshProps } from '../units-visual'; import { SizeThemeProps, SizeTheme } from 'mol-view/theme/size'; +import { OrderedSet } from 'mol-data/int'; export interface PolymerTraceMeshProps { sizeTheme: SizeThemeProps @@ -43,7 +44,7 @@ async function createPolymerTraceMesh(ctx: RuntimeContext, unit: Unit, props: Po const polymerTraceIt = PolymerTraceIterator(unit) while (polymerTraceIt.hasNext) { const v = polymerTraceIt.move() - builder.setId(v.center.element) + builder.setId(OrderedSet.findPredecessorIndex(unit.elements, v.center.element)) const isNucleic = v.moleculeType === MoleculeType.DNA || v.moleculeType === MoleculeType.RNA const isSheet = SecondaryStructureType.is(v.secStrucType, SecondaryStructureType.Flag.Beta) diff --git a/src/mol-geo/representation/structure/visual/util/location-iterator.ts b/src/mol-geo/representation/structure/visual/util/location-iterator.ts index 79e58062934db58cf38f5e31a5ae0faf913d73ec..aad0da64abdedce9ec3d4221379b91f56e256255 100644 --- a/src/mol-geo/representation/structure/visual/util/location-iterator.ts +++ b/src/mol-geo/representation/structure/visual/util/location-iterator.ts @@ -103,7 +103,7 @@ export namespace StructureElementIterator { const elementCount = group.elements.length const instanceCount = group.units.length const location = StructureElement.create(unit) - const getLocation = (elementIndex: number, instanceIndex: number) => { + const getLocation = (elementIndex: number) => { location.element = unit.elements[elementIndex] return location } @@ -117,7 +117,7 @@ export namespace LinkIterator { const elementCount = Unit.isAtomic(unit) ? unit.links.edgeCount * 2 : 0 const instanceCount = group.units.length const location = StructureElement.create(unit) - const getLocation = (elementIndex: number, instanceIndex: number) => { + const getLocation = (elementIndex: number) => { location.element = unit.elements[(unit as Unit.Atomic).links.a[elementIndex]] return location } @@ -128,7 +128,7 @@ export namespace LinkIterator { const elementCount = structure.links.bondCount const instanceCount = 1 const location = Link.Location() - const getLocation = (elementIndex: number, instanceIndex: number) => { + const getLocation = (elementIndex: number) => { const bond = structure.links.bonds[elementIndex] location.aUnit = bond.unitA location.aIndex = bond.indexA as StructureElement.UnitIndex diff --git a/src/mol-geo/representation/structure/visual/util/polymer/trace-iterator.ts b/src/mol-geo/representation/structure/visual/util/polymer/trace-iterator.ts index e304208088159359912777b228740c80288d120c..df4cfabc5ae57639e16fed87086ab7af9f5f78ec 100644 --- a/src/mol-geo/representation/structure/visual/util/polymer/trace-iterator.ts +++ b/src/mol-geo/representation/structure/visual/util/polymer/trace-iterator.ts @@ -5,7 +5,7 @@ */ import { Unit, StructureElement, ElementIndex, ResidueIndex } from 'mol-model/structure'; -import { Segmentation, SortedArray } from 'mol-data/int'; +import { Segmentation } from 'mol-data/int'; import { MoleculeType, SecondaryStructureType, AtomRole } from 'mol-model/structure/model/types'; import Iterator from 'mol-data/iterator'; import { Vec3 } from 'mol-math/linear-algebra'; @@ -94,7 +94,6 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> if (residueIndex < this.residueSegmentMin) { const cyclicIndex = cyclicPolymerMap.get(this.residueSegmentMin) if (cyclicIndex !== undefined) { - residueIndex = cyclicIndex - (this.residueSegmentMin - residueIndex - 1) as ResidueIndex } else { residueIndex = this.residueSegmentMin @@ -107,17 +106,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> residueIndex = this.residueSegmentMax } } - return getElementIndexForAtomRole(this.unit.model, residueIndex as ResidueIndex, atomRole) - } - - private getElementIndex(residueIndex: ResidueIndex, atomRole: AtomRole) { - const index = this.getAtomIndex(residueIndex, atomRole) - // TODO handle case when it returns -1 - const elementIndex = SortedArray.indexOf(this.unit.elements, index) as ElementIndex - if (elementIndex === -1) { - console.log('-1', residueIndex, atomRole, index) - } - return elementIndex === -1 ? 0 as ElementIndex : elementIndex + return getElementIndexForAtomRole(this.unit.model, residueIndex, atomRole) } private setControlPoint(out: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, residueIndex: ResidueIndex) { @@ -146,7 +135,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> if (this.state === AtomicPolymerTraceIteratorState.nextResidue) { const { index: residueIndex } = residueIt.move(); - value.center.element = this.getElementIndex(residueIndex, 'trace') + value.center.element = this.getAtomIndex(residueIndex, 'trace') this.pos(this.p0, this.getAtomIndex(residueIndex - 3 as ResidueIndex, 'trace')) this.pos(this.p1, this.getAtomIndex(residueIndex - 2 as ResidueIndex, 'trace')) diff --git a/src/mol-geo/util/color-data.ts b/src/mol-geo/util/color-data.ts index 5b89a4a07850aec6adc35bf89e90c90430352911..47e7eaf1d2383bdcc81eebf46a45d6864b1fb913 100644 --- a/src/mol-geo/util/color-data.ts +++ b/src/mol-geo/util/color-data.ts @@ -77,8 +77,8 @@ export function createInstanceColor(locationIt: LocationIterator, colorFn: Locat const { instanceCount} = locationIt const colors = colorData && colorData.tColor.ref.value.array.length >= instanceCount * 3 ? colorData.tColor.ref.value : createTextureImage(instanceCount, 3) while (locationIt.hasNext && !locationIt.isNextNewInstance) { - const v = locationIt.move() - Color.toArray(colorFn(v.location, v.isSecondary), colors.array, v.instanceIndex * 3) + const { location, isSecondary, instanceIndex } = locationIt.move() + Color.toArray(colorFn(location, isSecondary), colors.array, instanceIndex * 3) locationIt.skipInstance() } return createTextureColor(colors, 'instance', colorData) @@ -89,9 +89,8 @@ export function createElementColor(locationIt: LocationIterator, colorFn: Locati const { elementCount } = locationIt const colors = colorData && colorData.tColor.ref.value.array.length >= elementCount * 3 ? colorData.tColor.ref.value : createTextureImage(elementCount, 3) while (locationIt.hasNext && !locationIt.isNextNewInstance) { - const v = locationIt.move() - // console.log(v) - Color.toArray(colorFn(v.location, v.isSecondary), colors.array, v.elementIndex * 3) + const { location, isSecondary, elementIndex } = locationIt.move() + Color.toArray(colorFn(location, isSecondary), colors.array, elementIndex * 3) } return createTextureColor(colors, 'element', colorData) } @@ -102,8 +101,8 @@ export function createElementInstanceColor(locationIt: LocationIterator, colorFn const count = instanceCount * elementCount const colors = colorData && colorData.tColor.ref.value.array.length >= count * 3 ? colorData.tColor.ref.value : createTextureImage(count, 3) while (locationIt.hasNext && !locationIt.isNextNewInstance) { - const v = locationIt.move() - Color.toArray(colorFn(v.location, v.isSecondary), colors.array, v.index * 3) + const { location, isSecondary, index } = locationIt.move() + Color.toArray(colorFn(location, isSecondary), colors.array, index * 3) } return createTextureColor(colors, 'elementInstance', colorData) } \ No newline at end of file