Browse Source

check for structure equivalency not identity

Alexander Rose 6 years ago
parent
commit
bd09914f24

+ 5 - 13
src/mol-canvas3d/canvas3d.ts

@@ -79,9 +79,6 @@ interface Canvas3D {
     readonly stats: RendererStats
     readonly interaction: Canvas3dInteractionHelper['events']
 
-    // TODO: is this a good solution?
-    setSceneAnimating(animating: boolean): void
-
     dispose: () => void
 }
 
@@ -137,8 +134,6 @@ namespace Canvas3D {
         const debugHelper = new BoundingSphereHelper(webgl, scene, p.debug);
         const interactionHelper = new Canvas3dInteractionHelper(identify, getLoci, input);
 
-        let isSceneAnimating = false
-
         function getLoci(pickingId: PickingId) {
             let loci: Loci = EmptyLoci
             let repr: Representation.Any = Representation.Empty
@@ -153,13 +148,13 @@ namespace Canvas3D {
             return { loci, repr }
         }
 
-        function mark(loci: Representation.Loci, action: MarkerAction) {
-            const repr = loci.repr
+        function mark(reprLoci: Representation.Loci, action: MarkerAction) {
+            const { repr, loci } = reprLoci
             let changed = false
             if (repr) {
-                changed = repr.mark(loci.loci, action)
+                changed = repr.mark(loci, action)
             } else {
-                reprRenderObjects.forEach((_, _repr) => { changed = _repr.mark(loci.loci, action) || changed })
+                reprRenderObjects.forEach((_, _repr) => { changed = _repr.mark(loci, action) || changed })
             }
             if (changed) {
                 scene.update(void 0, true)
@@ -263,7 +258,7 @@ namespace Canvas3D {
             currentTime = now();
             camera.transition.tick(currentTime);
             draw(false);
-            if (!camera.transition.inTransition && !isSceneAnimating) interactionHelper.tick(currentTime);
+            if (!camera.transition.inTransition) interactionHelper.tick(currentTime);
             window.requestAnimationFrame(animate)
         }
 
@@ -436,9 +431,6 @@ namespace Canvas3D {
             get interaction() {
                 return interactionHelper.events
             },
-            setSceneAnimating(animating) {
-                isSceneAnimating = animating;
-            },
             dispose: () => {
                 scene.clear()
                 debugHelper.clear()

+ 0 - 2
src/mol-plugin/state/animation/manager.ts

@@ -89,7 +89,6 @@ class PluginAnimationManager extends PluginComponent<PluginAnimationManager.Stat
     }
 
     start() {
-        this.context.canvas3d.setSceneAnimating(true);
         this.updateState({ animationState: 'playing' });
         if (!this.context.behaviors.state.isAnimating.value) {
             this.context.behaviors.state.isAnimating.next(true);
@@ -104,7 +103,6 @@ class PluginAnimationManager extends PluginComponent<PluginAnimationManager.Stat
     }
 
     stop() {
-        this.context.canvas3d.setSceneAnimating(false);
         if (typeof this._frame !== 'undefined') cancelAnimationFrame(this._frame);
         if (this.context.behaviors.state.isAnimating.value) {
             this.context.behaviors.state.isAnimating.next(false);

+ 2 - 2
src/mol-repr/structure/complex-visual.ts

@@ -186,7 +186,7 @@ export function ComplexVisual<G extends Geometry, P extends ComplexParams & Geom
             }
 
             let changed = false
-            if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructure)) {
+            if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructure))) {
                 changed = apply(Interval.ofBounds(0, groupCount * instanceCount))
             } else {
                 changed = eachLocation(loci, currentStructure, apply)
@@ -221,7 +221,7 @@ export function ComplexVisual<G extends Geometry, P extends ComplexParams & Geom
                     return applyOverpaintColor(tOverpaint.ref.value.array, start, end, color, alpha)
                 }
 
-                if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructure)) {
+                if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructure))) {
                     apply(Interval.ofBounds(0, groupCount * instanceCount))
                 } else {
                     eachLocation(loci, currentStructure, apply)

+ 2 - 2
src/mol-repr/structure/units-visual.ts

@@ -232,7 +232,7 @@ export function UnitsVisual<G extends Geometry, P extends UnitsParams & Geometry
             }
 
             let changed = false
-            if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructureGroup.structure)) {
+            if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructureGroup.structure))) {
                 changed = apply(Interval.ofBounds(0, groupCount * instanceCount))
             } else {
                 changed = eachLocation(loci, currentStructureGroup, apply)
@@ -267,7 +267,7 @@ export function UnitsVisual<G extends Geometry, P extends UnitsParams & Geometry
                     return applyOverpaintColor(tOverpaint.ref.value.array, start, end, color, alpha)
                 }
 
-                if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructureGroup.structure)) {
+                if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructureGroup.structure))) {
                     apply(Interval.ofBounds(0, groupCount * instanceCount))
                 } else {
                     eachLocation(loci, currentStructureGroup, apply)

+ 2 - 2
src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts

@@ -119,7 +119,7 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) {
 function eachCarbohydrateLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) {
     let changed = false
     if (Link.isLoci(loci)) {
-        if (loci.structure !== structure) return false
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         const { getLinkIndex } = structure.carbohydrates
         for (const l of loci.links) {
             const idx = getLinkIndex(l.aUnit, l.aUnit.elements[l.aIndex], l.bUnit, l.bUnit.elements[l.bIndex])
@@ -128,7 +128,7 @@ function eachCarbohydrateLink(loci: Loci, structure: Structure, apply: (interval
             }
         }
     } else if (StructureElement.isLoci(loci)) {
-        if (loci.structure !== structure) return false
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         // TODO mark link only when both of the link elements are in a StructureElement.Loci
         const { getElementIndex, getLinkIndices, elements } = structure.carbohydrates
         for (const e of loci.elements) {

+ 18 - 18
src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts

@@ -195,25 +195,25 @@ function getCarbohydrateLoci(pickingId: PickingId, structure: Structure, id: num
 function eachCarbohydrate(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) {
     const { getElementIndex, getAnomericCarbon } = structure.carbohydrates
     let changed = false
-    if (StructureElement.isLoci(loci)) {
-        for (const e of loci.elements) {
-            OrderedSet.forEach(e.indices, v => {
-                const { model, elements } = e.unit
-                const { index, offsets } = model.atomicHierarchy.residueAtomSegments
-                const rI = index[elements[v]]
-                const unitIndexMin = OrderedSet.findPredecessorIndex(elements, offsets[rI])
-                const unitIndexMax = OrderedSet.findPredecessorIndex(elements, offsets[rI + 1] - 1)
-                const unitIndexInterval = Interval.ofRange(unitIndexMin, unitIndexMax)
-                if (!OrderedSet.isSubset(e.indices, unitIndexInterval)) return
-                const eI = getAnomericCarbon(e.unit, rI)
-                if (eI !== undefined) {
-                    const idx = getElementIndex(e.unit, eI)
-                    if (idx !== undefined) {
-                        if (apply(Interval.ofBounds(idx * 2, idx * 2 + 2))) changed = true
-                    }
+    if (!StructureElement.isLoci(loci)) return false
+    if (!Structure.areEquivalent(loci.structure, structure)) return false
+    for (const e of loci.elements) {
+        OrderedSet.forEach(e.indices, v => {
+            const { model, elements } = e.unit
+            const { index, offsets } = model.atomicHierarchy.residueAtomSegments
+            const rI = index[elements[v]]
+            const unitIndexMin = OrderedSet.findPredecessorIndex(elements, offsets[rI])
+            const unitIndexMax = OrderedSet.findPredecessorIndex(elements, offsets[rI + 1] - 1)
+            const unitIndexInterval = Interval.ofRange(unitIndexMin, unitIndexMax)
+            if (!OrderedSet.isSubset(e.indices, unitIndexInterval)) return
+            const eI = getAnomericCarbon(e.unit, rI)
+            if (eI !== undefined) {
+                const idx = getElementIndex(e.unit, eI)
+                if (idx !== undefined) {
+                    if (apply(Interval.ofBounds(idx * 2, idx * 2 + 2))) changed = true
                 }
-            })
-        }
+            }
+        })
     }
     return changed
 }

+ 2 - 2
src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts

@@ -131,9 +131,9 @@ function getTerminalLinkLoci(pickingId: PickingId, structure: Structure, id: num
 // TODO for each link when both of the link elements are in a StructureElement.Loci
 function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) {
     const { getTerminalLinkIndex } = structure.carbohydrates
-
     let changed = false
     if (Link.isLoci(loci)) {
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         for (const l of loci.links) {
             const idx = getTerminalLinkIndex(l.aUnit, l.aUnit.elements[l.aIndex], l.bUnit, l.bUnit.elements[l.bIndex])
             if (idx !== undefined) {
@@ -141,7 +141,7 @@ function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: In
             }
         }
     } else if (StructureElement.isLoci(loci)) {
-        if (loci.structure !== structure) return false
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         // TODO mark link only when both of the link elements are in a StructureElement.Loci
         const { getElementIndex, getTerminalLinkIndices, elements } = structure.carbohydrates
         for (const e of loci.elements) {

+ 1 - 1
src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts

@@ -106,9 +106,9 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) {
 
 function eachCrossLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) {
     const crossLinks = structure.crossLinkRestraints
-
     let changed = false
     if (Link.isLoci(loci)) {
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         for (const b of loci.links) {
             const indices = crossLinks.getPairIndices(b.aIndex, b.aUnit, b.bIndex, b.bUnit)
             if (indices) {

+ 2 - 2
src/mol-repr/structure/visual/inter-unit-link-cylinder.ts

@@ -98,7 +98,7 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) {
 function eachLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) {
     let changed = false
     if (Link.isLoci(loci)) {
-        if (loci.structure !== structure) return false
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         for (const b of loci.links) {
             const idx = structure.links.getBondIndex(b.aIndex, b.aUnit, b.bIndex, b.bUnit)
             if (idx !== -1) {
@@ -106,7 +106,7 @@ function eachLink(loci: Loci, structure: Structure, apply: (interval: Interval)
             }
         }
     } else if (StructureElement.isLoci(loci)) {
-        if (loci.structure !== structure) return false
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         // TODO mark link only when both of the link elements are in a StructureElement.Loci
         for (const e of loci.elements) {
             OrderedSet.forEach(e.indices, v => {

+ 2 - 2
src/mol-repr/structure/visual/intra-unit-link-cylinder.ts

@@ -116,7 +116,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval:
     let changed = false
     if (Link.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (loci.structure !== structure) return false
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         const unit = group.units[0]
         if (!Unit.isAtomic(unit)) return false
         const groupCount = unit.links.edgeCount * 2
@@ -131,7 +131,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval:
         }
     } else if (StructureElement.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (loci.structure !== structure) return false
+        if (!Structure.areEquivalent(loci.structure, structure)) return false
         const unit = group.units[0]
         if (!Unit.isAtomic(unit)) return false
         const groupCount = unit.links.edgeCount * 2

+ 1 - 1
src/mol-repr/structure/visual/util/element.ts

@@ -72,7 +72,7 @@ export function eachElement(loci: Loci, structureGroup: StructureGroup, apply: (
     let changed = false
     if (!StructureElement.isLoci(loci)) return false
     const { structure, group } = structureGroup
-    if (loci.structure !== structure) return false
+    if (!Structure.areEquivalent(loci.structure, structure)) return false
     const elementCount = group.elements.length
     for (const e of loci.elements) {
         const unitIdx = group.unitIndexMap.get(e.unit.id)

+ 2 - 2
src/mol-repr/structure/visual/util/nucleotide.ts

@@ -4,7 +4,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { Unit, StructureElement } from 'mol-model/structure';
+import { Unit, StructureElement, Structure } from 'mol-model/structure';
 import { getNucleotideElements } from 'mol-model/structure/structure/util/nucleotide';
 import { Loci, EmptyLoci } from 'mol-model/loci';
 import { OrderedSet, Interval } from 'mol-data/int';
@@ -44,7 +44,7 @@ export function eachNucleotideElement(loci: Loci, structureGroup: StructureGroup
     let changed = false
     if (!StructureElement.isLoci(loci)) return false
     const { structure, group } = structureGroup
-    if (loci.structure !== structure) return false
+    if (!Structure.areEquivalent(loci.structure, structure)) return false
     const unit = group.units[0]
     if (!Unit.isAtomic(unit)) return false
     const { nucleotideElements, model, elements } = unit

+ 3 - 3
src/mol-repr/structure/visual/util/polymer.ts

@@ -4,7 +4,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { Unit, ElementIndex, StructureElement, Link } from 'mol-model/structure';
+import { Unit, ElementIndex, StructureElement, Link, Structure } from 'mol-model/structure';
 import SortedRanges from 'mol-data/int/sorted-ranges';
 import { OrderedSet, Interval } from 'mol-data/int';
 import { EmptyLoci, Loci } from 'mol-model/loci';
@@ -82,7 +82,7 @@ export function eachPolymerElement(loci: Loci, structureGroup: StructureGroup, a
     let changed = false
     if (!StructureElement.isLoci(loci)) return false
     const { structure, group } = structureGroup
-    if (loci.structure !== structure) return false
+    if (!Structure.areEquivalent(loci.structure, structure)) return false
     const { polymerElements, model, elements } = group.units[0]
     const { index, offsets } = model.atomicHierarchy.residueAtomSegments
     const { traceElementIndex } = model.atomicHierarchy.derived.residue
@@ -130,7 +130,7 @@ export function eachPolymerGapElement(loci: Loci, structureGroup: StructureGroup
     let changed = false
     if (!Link.isLoci(loci)) return false
     const { structure, group } = structureGroup
-    if (loci.structure !== structure) return false
+    if (!Structure.areEquivalent(loci.structure, structure)) return false
     const groupCount = group.units[0].gapElements.length
     for (const b of loci.links) {
         const unitIdx = group.unitIndexMap.get(b.aUnit.id)