From 198e2f204322896827b20123d3bcc8e45f482fc4 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Wed, 16 Oct 2019 15:48:39 -0700
Subject: [PATCH] support for currentSelection in StructureSelectionHelper and
 surroundings query

---
 .../util/structure-selection-helper.ts        | 22 +++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/mol-plugin/util/structure-selection-helper.ts b/src/mol-plugin/util/structure-selection-helper.ts
index 5ff06f836..13bb99190 100644
--- a/src/mol-plugin/util/structure-selection-helper.ts
+++ b/src/mol-plugin/util/structure-selection-helper.ts
@@ -7,7 +7,7 @@
 import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
 import { StateSelection } from '../../mol-state';
 import { PluginStateObject } from '../state/objects';
-import { QueryContext, StructureSelection, StructureQuery } from '../../mol-model/structure';
+import { QueryContext, StructureSelection, StructureQuery, StructureElement } from '../../mol-model/structure';
 import { compile } from '../../mol-script/runtime/query/compiler';
 import { Loci } from '../../mol-model/loci';
 import { PluginContext } from '../context';
@@ -185,6 +185,17 @@ const coarse = MS.struct.modifier.union([
     })
 ])
 
+const surroundings = MS.struct.modifier.union([
+    MS.struct.modifier.exceptBy({
+        0: MS.struct.modifier.includeSurroundings({
+            0: MS.internal.generator.current(),
+            radius: 5,
+            'as-whole-residues': true
+        }),
+        by: MS.internal.generator.current()
+    })
+])
+
 export const StructureSelectionQueries = {
     all,
     polymer,
@@ -202,6 +213,7 @@ export const StructureSelectionQueries = {
     connectedOnly,
     modified,
     coarse,
+    surroundings,
 }
 
 export const CompiledStructureSelectionQueries = (function () {
@@ -241,7 +253,13 @@ export class StructureSelectionHelper {
 
         for (const so of this.structures) {
             const s = so.obj!.data
-            const result = compiled(new QueryContext(s))
+
+            const current = this.plugin.helpers.structureSelectionManager.get(s)
+            const currentSelection = Loci.isEmpty(current)
+                ? StructureSelection.Empty(s)
+                : StructureSelection.Singletons(s, StructureElement.Loci.toStructure(current))
+
+            const result = compiled(new QueryContext(s, { currentSelection }))
             const loci = StructureSelection.toLociWithSourceUnits(result)
             this._set(modifier, loci)
         }
-- 
GitLab