Alexander Rose преди 6 години
родител
ревизия
c647ab3150

+ 2 - 1
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)

+ 2 - 1
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)

+ 3 - 3
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

+ 3 - 14
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'))

+ 6 - 7
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)
 }