Browse Source

added StructureElement.Loci.toStructure

Alexander Rose 5 years ago
parent
commit
6ae3d4110d
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/mol-model/structure/structure/element/loci.ts

+ 11 - 0
src/mol-model/structure/structure/element/loci.ts

@@ -78,6 +78,17 @@ export namespace Loci {
         return Loci(structure, []);
     }
 
+    export function toStructure(loci: Loci): Structure {
+        const units: Unit[] = []
+        for (const e of loci.elements) {
+            const { unit, indices } = e
+            const elements = new Int32Array(OrderedSet.size(indices))
+            OrderedSet.forEach(indices, (v, i) => elements[i] = unit.elements[v])
+            units.push(unit.getChild(SortedArray.ofSortedArray(elements)))
+        }
+        return Structure.create(units, { parent: loci.structure.parent })
+    }
+
     export function remap(loci: Loci, structure: Structure): Loci {
         if (structure === loci.structure) return loci