Browse Source

SubstructureParentHelper.get takes decorators into account

David Sehnal 5 years ago
parent
commit
c060664f84

+ 5 - 3
src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts

@@ -121,11 +121,13 @@ export class StructureFocusRepresentationBehavior extends PluginBehavior.WithSub
         return PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true, doNotUpdateCurrent: true } });
     }
 
-    private async focus(loci: StructureElement.Loci) {
-        const parent = this.plugin.helpers.substructureParent.get(loci.structure);
+    private async focus(sourceLoci: StructureElement.Loci) {
+        const parent = this.plugin.helpers.substructureParent.get(sourceLoci.structure);
         if (!parent || !parent.obj) return;
 
-        const residueLoci = StructureElement.Loci.extendToWholeResidues(StructureElement.Loci.remap(loci, parent.obj!.data));
+        const loci = StructureElement.Loci.remap(sourceLoci, parent.obj!.data);
+
+        const residueLoci = StructureElement.Loci.extendToWholeResidues(loci);
         const residueBundle = StructureElement.Bundle.fromLoci(residueLoci);
 
         const surroundings = MS.struct.modifier.includeSurroundings({

+ 1 - 1
src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts

@@ -251,7 +251,7 @@ export namespace VolumeStreaming {
                 return Box3D.empty();
             }
 
-            const parent = this.plugin.helpers.substructureParent.get(loci.structure);
+            const parent = this.plugin.helpers.substructureParent.get(loci.structure, true);
             if (!parent) return Box3D.empty();
             const root = this.getStructureRoot();
             if (!root || root.obj?.data !== parent.obj?.data) return Box3D.empty();

+ 13 - 1
src/mol-plugin/util/substructure-parent-helper.ts

@@ -16,11 +16,23 @@ class SubstructureParentHelper {
     private root = new Map<Structure, { ref: string, count: number }>();
     private tracked = new Map<string, Structure>();
 
+    private getDecorator(root: string): string {
+        const tree = this.plugin.state.data.tree;
+        const children = tree.children.get(root);
+        if (children.size !== 1) return root;
+        const child = children.first();
+        if (tree.transforms.get(child).transformer.definition.isDecorator) {
+            return this.getDecorator(child);
+        }
+        return root;
+    }
+
     /** Returns the root node of given structure if existing, takes decorators into account */
     get(s: Structure, ignoreDecorators = false): StateObjectCell<PluginStateObject.Molecule.Structure> | undefined {
         const r = this.root.get(s);
         if (!r) return;
-        return this.plugin.state.data.cells.get(r.ref);
+        if (ignoreDecorators) return this.plugin.state.data.cells.get(r.ref);
+        return this.plugin.state.data.cells.get(this.getDecorator(r.ref));
     }
 
     private addMapping(state: State, ref: string, obj: StateObject) {