ソースを参照

added Structure.root

Alexander Rose 5 年 前
コミット
5e83c3350a

+ 3 - 3
src/mol-model/structure/structure/element.ts

@@ -575,7 +575,7 @@ namespace StructureElement {
                 elements.push({ groupedUnits, set: e.set, ranges: e.ranges })
             })
 
-            return { hash: (loci.structure.parent || loci.structure).hashCode, elements }
+            return { hash: loci.structure.root.hashCode, elements }
         }
 
         function getUnitsFromIds(unitIds: ArrayLike<number>, structure: Structure) {
@@ -588,7 +588,7 @@ namespace StructureElement {
         }
 
         export function toLoci(query: Query, parent: Structure): Loci {
-            if (query.hash !== -1 && query.hash !== (parent.parent || parent).hashCode) {
+            if (query.hash !== -1 && query.hash !== parent.root.hashCode) {
                 new Error('Query not compatible with given structure')
             }
             const elements: Loci['elements'][0][] = []
@@ -625,7 +625,7 @@ namespace StructureElement {
         }
 
         export function toStructure(query: Query, parent: Structure): Structure {
-            if (query.hash !== -1 && query.hash !== (parent.parent || parent).hashCode) {
+            if (query.hash !== -1 && query.hash !== parent.root.hashCode) {
                 new Error('Query not compatible with given structure')
             }
             const units: Unit[] = []

+ 10 - 5
src/mol-model/structure/structure/structure.ts

@@ -146,7 +146,12 @@ class Structure {
         return new Structure.ElementLocationIterator(this);
     }
 
-    /** the root/top-most parent or `undefined` in case this is the root */
+    /** The parent or itself in case this is the root */
+    get root() {
+        return this._props.parent || this;
+    }
+
+    /** The root/top-most parent or `undefined` in case this is the root */
     get parent() {
         return this._props.parent;
     }
@@ -629,13 +634,13 @@ namespace Structure {
     }
 
     /** Check if the structures or their parents are equivalent */
-    export function areParentsEquivalent(a: Structure, b: Structure) {
-        return areEquivalent(a.parent || a, b.parent || b)
+    export function areRootsEquivalent(a: Structure, b: Structure) {
+        return areEquivalent(a.root, b.root)
     }
 
     /** Check if the structures or their parents are equal */
-    export function areParentsEqual(a: Structure, b: Structure) {
-        return (a.parent || a) === (b.parent || b)
+    export function areRootsEqual(a: Structure, b: Structure) {
+        return a.root === b.root
     }
 
     export class ElementLocationIterator implements Iterator<StructureElement> {

+ 5 - 7
src/mol-plugin/state/transforms/representation.ts

@@ -302,23 +302,21 @@ const ExplodeStructureRepresentation3D = PluginStateTransform.BuiltIn({
     },
     apply({ a, params }) {
         const structure = a.data.source.data;
-        const rootStructure = structure.parent || structure;
-        const unitTransforms = new StructureUnitTransforms(rootStructure);
+        const unitTransforms = new StructureUnitTransforms(structure.root);
         explodeStructure(structure, unitTransforms, params.t);
         return new SO.Molecule.Structure.Representation3DState({
             state: { unitTransforms },
-            initialState: { unitTransforms: new StructureUnitTransforms(rootStructure) },
-            info: rootStructure,
+            initialState: { unitTransforms: new StructureUnitTransforms(structure.root) },
+            info: structure.root,
             source: a
         }, { label: `Explode T = ${params.t.toFixed(2)}` });
     },
     update({ a, b, newParams, oldParams }) {
         const structure = a.data.source.data;
-        const rootStructure = structure.parent || structure;
-        if (b.data.info !== rootStructure) return StateTransformer.UpdateResult.Recreate;
+        if (b.data.info !== structure.root) return StateTransformer.UpdateResult.Recreate;
         if (oldParams.t === newParams.t) return StateTransformer.UpdateResult.Unchanged;
         const unitTransforms = b.data.state.unitTransforms!;
-        explodeStructure(rootStructure, unitTransforms, newParams.t);
+        explodeStructure(structure.root, unitTransforms, newParams.t);
         b.label = `Explode T = ${newParams.t.toFixed(2)}`;
         b.data.source = a;
         return StateTransformer.UpdateResult.Updated;

+ 2 - 2
src/mol-plugin/ui/sequence/hetero.ts

@@ -26,7 +26,7 @@ export class HeteroSequenceWrapper extends SequenceWrapper<StructureUnit> {
         let changed = false
         const { structure, unit } = this.data
         if (StructureElement.isLoci(loci)) {
-            if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
+            if (!Structure.areRootsEquivalent(loci.structure, structure)) return false
             loci = StructureElement.Loci.remap(loci, structure)
 
             for (const e of loci.elements) {
@@ -39,7 +39,7 @@ export class HeteroSequenceWrapper extends SequenceWrapper<StructureUnit> {
                 }
             }
         } else if (Structure.isLoci(loci)) {
-            if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
+            if (!Structure.areRootsEquivalent(loci.structure, structure)) return false
 
             if (apply(Interval.ofBounds(0, this.length))) changed = true
         }

+ 2 - 2
src/mol-plugin/ui/sequence/polymer.ts

@@ -37,7 +37,7 @@ export class PolymerSequenceWrapper extends SequenceWrapper<StructureUnit> {
         let changed = false
         const { structure, unit } = this.data
         if (StructureElement.isLoci(loci)) {
-            if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
+            if (!Structure.areRootsEquivalent(loci.structure, structure)) return false
             loci = StructureElement.Loci.remap(loci, structure)
 
             const { offset } = this.sequence
@@ -49,7 +49,7 @@ export class PolymerSequenceWrapper extends SequenceWrapper<StructureUnit> {
                 }
             }
         } else if (Structure.isLoci(loci)) {
-            if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
+            if (!Structure.areRootsEquivalent(loci.structure, structure)) return false
 
             if (apply(this.observed)) changed = true
         }

+ 1 - 1
src/mol-plugin/util/interactivity.ts

@@ -101,7 +101,7 @@ namespace Interactivity {
             }
             if (Structure.isLoci(loci)) {
                 // convert to StructureElement.Loci of root structure
-                loci = Structure.toStructureElementLoci(Structure.Loci(loci.structure.parent || loci.structure))
+                loci = Structure.toStructureElementLoci(Structure.Loci(loci.structure.root))
             }
             if (StructureElement.isLoci(loci) && loci.structure.parent) {
                 // ensure the root structure is used

+ 1 - 2
src/mol-plugin/util/structure-overpaint-helper.ts

@@ -34,9 +34,8 @@ export class StructureOverpaintHelper {
             const overpaint = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.OverpaintStructureRepresentation3D, r.transform.ref).withTag(OverpaintManagerTag));
 
             const structure = r.obj!.data.source.data
-            const rootStructure = structure.parent || structure
 
-            callback(update, r, rootStructure, overpaint[0])
+            callback(update, r, structure.root, overpaint[0])
         }
 
         await this.plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true }));

+ 1 - 1
src/mol-repr/structure/complex-representation.ts

@@ -57,7 +57,7 @@ export function ComplexRepresentation<P extends StructureParams>(label: string,
     function mark(loci: Loci, action: MarkerAction) {
         if (!_structure) return false
         if (!StructureElement.isLoci(loci) && !Link.isLoci(loci)) return false
-        if (!Structure.areParentsEquivalent(loci.structure, _structure)) return false
+        if (!Structure.areRootsEquivalent(loci.structure, _structure)) return false
         if (StructureElement.isLoci(loci)) {
             loci = StructureElement.Loci.remap(loci, _structure)
         } else if (Link.isLoci(loci)) {

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

@@ -165,7 +165,7 @@ export function ComplexVisual<G extends Geometry, P extends ComplexParams & Geom
     }
 
     function lociApply(loci: Loci, apply: (interval: Interval) => boolean) {
-        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areParentsEquivalent(loci.structure, currentStructure))) {
+        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areRootsEquivalent(loci.structure, currentStructure))) {
             return apply(Interval.ofBounds(0, locationIt.groupCount * locationIt.instanceCount))
         } else {
             return eachLocation(loci, currentStructure, apply)

+ 1 - 1
src/mol-repr/structure/units-representation.ts

@@ -166,7 +166,7 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, ctx: R
         let changed = false
         if (!_structure) return false
         if (!StructureElement.isLoci(loci) && !Link.isLoci(loci)) return false
-        if (!Structure.areParentsEquivalent(loci.structure, _structure)) return false
+        if (!Structure.areRootsEquivalent(loci.structure, _structure)) return false
         if (StructureElement.isLoci(loci)) {
             loci = StructureElement.Loci.remap(loci, _structure)
             if (loci.elements.length === 0) return false

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

@@ -215,7 +215,7 @@ export function UnitsVisual<G extends Geometry, P extends UnitsParams & Geometry
     }
 
     function lociApply(loci: Loci, apply: (interval: Interval) => boolean) {
-        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areParentsEquivalent(loci.structure, currentStructureGroup.structure))) {
+        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areRootsEquivalent(loci.structure, currentStructureGroup.structure))) {
             return apply(Interval.ofBounds(0, locationIt.groupCount * locationIt.instanceCount))
         } else {
             return eachLocation(loci, currentStructureGroup, apply)

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

@@ -162,7 +162,7 @@ export function eachPolymerGapElement(loci: Loci, structureGroup: StructureGroup
     let changed = false
     if (Link.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
+        if (!Structure.areRootsEquivalent(loci.structure, structure)) return false
         loci = Link.remapLoci(loci, structure)
         const groupCount = group.units[0].gapElements.length
         for (const b of loci.links) {
@@ -177,7 +177,7 @@ export function eachPolymerGapElement(loci: Loci, structureGroup: StructureGroup
         }
     } else if (StructureElement.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
+        if (!Structure.areRootsEquivalent(loci.structure, structure)) return false
         loci = StructureElement.Loci.remap(loci, structure)
         const groupCount = group.units[0].gapElements.length
         for (const e of loci.elements) {