Browse Source

fixes: StructureElement.Loci.union, Structure.parent

Alexander Rose 5 years ago
parent
commit
e42c664a8c

+ 5 - 0
src/mol-model/structure/structure/element.ts

@@ -157,11 +157,16 @@ namespace StructureElement {
             for (const e of ys.elements) {
                 if (map.has(e.unit.id)) {
                     elements[elements.length] = { unit: e.unit, indices: OrderedSet.union(map.get(e.unit.id)!, e.indices) };
+                    map.delete(e.unit.id)
                 } else {
                     elements[elements.length] = e;
                 }
             }
 
+            map.forEach((indices, id) => {
+                elements[elements.length] = { unit: xs.structure.unitMap.get(id)!, indices };
+            });
+
             return Loci(xs.structure, elements);
         }
 

+ 2 - 1
src/mol-model/structure/structure/structure.ts

@@ -141,6 +141,7 @@ class Structure {
         return new Structure.ElementLocationIterator(this);
     }
 
+    /** the root/top-most parent or `undefined` in case this is the root */
     get parent() {
         return this._props.parent;
     }
@@ -240,7 +241,7 @@ class Structure {
     constructor(units: ArrayLike<Unit>, parent: Structure | undefined, coordinateSystem?: SymmetryOperator) {
         this.unitMap = this.initUnits(units);
         this.units = units as ReadonlyArray<Unit>;
-        if (parent) this._props.parent = parent;
+        if (parent) this._props.parent = parent.parent || parent;
         if (coordinateSystem) this._props.coordinateSystem = coordinateSystem;
         else if (parent) this._props.coordinateSystem = parent.coordinateSystem;
     }