diff --git a/src/mol-model/structure/structure/element.ts b/src/mol-model/structure/structure/element.ts index b3801b3a1263309ba7262e98de63d54255886371..8ac7af0c113873bfc35d6fae413435400d17e115 100644 --- a/src/mol-model/structure/structure/element.ts +++ b/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); } diff --git a/src/mol-model/structure/structure/structure.ts b/src/mol-model/structure/structure/structure.ts index ed9b314f75a207bdf21b7a295cdba5530faca8fb..03569e40a691a22fcd4e21b6b5c28709c282a01c 100644 --- a/src/mol-model/structure/structure/structure.ts +++ b/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; }