From 6873b798d39440832211dbcea64f1dcda94af2bd Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Tue, 5 Mar 2019 15:49:36 -0800 Subject: [PATCH] added StructureSelection.toLoci2 returning the source units (propably won't work for queries that create units with new transforms) --- src/mol-model/structure/query/selection.ts | 36 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/mol-model/structure/query/selection.ts b/src/mol-model/structure/query/selection.ts index 901452573..c13c370da 100644 --- a/src/mol-model/structure/query/selection.ts +++ b/src/mol-model/structure/query/selection.ts @@ -36,21 +36,47 @@ namespace StructureSelection { } export function toLoci(sel: StructureSelection): StructureElement.Loci { - const loci: { unit: Unit, indices: OrderedSet<StructureElement.UnitIndex> }[] = []; + const elements: { unit: Unit, indices: OrderedSet<StructureElement.UnitIndex> }[] = []; const { unitMap } = sel.source; for (const unit of unionStructure(sel).units) { if (unit === unitMap.get(unit.id)) { - loci[loci.length] = { unit, indices: OrderedSet.ofBounds(0 as StructureElement.UnitIndex, unit.elements.length as StructureElement.UnitIndex) }; + elements[elements.length] = { + unit, + indices: OrderedSet.ofBounds(0 as StructureElement.UnitIndex, unit.elements.length as StructureElement.UnitIndex) + }; + } else { + elements[elements.length] = { + unit, + indices: OrderedSet.ofSortedArray(SortedArray.indicesOf(unitMap.get(unit.id).elements, unit.elements)) + }; + } + } + + return StructureElement.Loci(sel.source, elements); + } + + /** use source unit in loci.elements */ + export function toLoci2(sel: StructureSelection): StructureElement.Loci { + const elements: { unit: Unit, indices: OrderedSet<StructureElement.UnitIndex> }[] = []; + const { unitMap } = sel.source; + + for (const _unit of unionStructure(sel).units) { + const unit = unitMap.get(_unit.id) + if (unit === _unit) { + elements[elements.length] = { + unit, + indices: OrderedSet.ofBounds(0 as StructureElement.UnitIndex, unit.elements.length as StructureElement.UnitIndex) + }; } else { - loci[loci.length] = { + elements[elements.length] = { unit, - indices: OrderedSet.ofSortedArray(SortedArray.indicesOf(sel.source.unitMap.get(unit.id).elements, unit.elements)) + indices: OrderedSet.ofSortedArray(SortedArray.indicesOf(unit.elements, _unit.elements)) }; } } - return StructureElement.Loci(sel.source, loci); + return StructureElement.Loci(sel.source, elements); } export interface Builder { -- GitLab