Browse Source

mol-model: added StructureQuery.runExpr

David Sehnal 5 years ago
parent
commit
ca66e334c1
2 changed files with 14 additions and 10 deletions
  1. 5 10
      src/apps/basic-wrapper/index.ts
  2. 9 0
      src/mol-model/structure/query/query.ts

+ 5 - 10
src/apps/basic-wrapper/index.ts

@@ -15,14 +15,11 @@ import { PluginStateObject as PSO, PluginStateObject } from '../../mol-plugin/st
 import { AnimateModelIndex } from '../../mol-plugin/state/animation/built-in';
 import { StateBuilder, StateTransform } from '../../mol-state';
 import { StripedResidues } from './coloring';
-import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
-// import { BasicWrapperControls } from './controls';
 import { StaticSuperpositionTestData, buildStaticSuperposition, dynamicSuperpositionTest } from './superposition';
 import { PDBeStructureQualityReport } from '../../mol-plugin/behavior/dynamic/custom-props';
 import { CustomToastMessage } from './controls';
 import { EmptyLoci } from '../../mol-model/loci';
-import { compile } from '../../mol-script/runtime/query/compiler';
-import { StructureSelection, QueryContext } from '../../mol-model/structure';
+import { StructureSelection, StructureQuery } from '../../mol-model/structure';
 require('mol-plugin/skin/light.scss')
 
 type SupportedFormats = 'cif' | 'pdb'
@@ -151,13 +148,11 @@ class BasicWrapper {
     interactivity = {
         highlightOn: () => {
             const seq_id = 7;
-            const query = compile<StructureSelection>(
-                MS.struct.generator.atomGroups({
-                    'residue-test': MS.core.rel.eq([MS.struct.atomProperty.macromolecular.label_seq_id(), seq_id]),
-                    'group-by': MS.struct.atomProperty.macromolecular.residueKey()
-                }));
             const data = (this.plugin.state.dataState.select('asm')[0].obj as PluginStateObject.Molecule.Structure).data;
-            const sel = query(new QueryContext(data));
+            const sel = StructureQuery.runExpr(Q => Q.struct.generator.atomGroups({
+                'residue-test': Q.core.rel.eq([Q.struct.atomProperty.macromolecular.label_seq_id(), seq_id]),
+                'group-by': Q.struct.atomProperty.macromolecular.residueKey()
+            }), data);
             const loci = StructureSelection.toLociWithSourceUnits(sel);
             this.plugin.interactivity.lociHighlights.highlightOnly({ loci });
         },

+ 9 - 0
src/mol-model/structure/query/query.ts

@@ -7,12 +7,21 @@
 import { Structure } from '../structure'
 import { StructureSelection } from './selection'
 import { QueryContext, QueryFn, QueryContextOptions } from './context';
+import Expression from '../../../mol-script/language/expression';
+import { compile } from '../../../mol-script/runtime/query/compiler';
+import { MolScriptBuilder } from '../../../mol-script/language/builder';
 
 interface StructureQuery extends QueryFn<StructureSelection> { }
 namespace StructureQuery {
     export function run(query: StructureQuery, structure: Structure, options?: QueryContextOptions) {
         return query(new QueryContext(structure, options));
     }
+
+    export function runExpr(expr: Expression | ((builder: typeof MolScriptBuilder) => Expression), structure: Structure, options?: QueryContextOptions) {
+        const e = typeof expr === 'function' ? expr(MolScriptBuilder) : expr;
+        const query = compile<StructureSelection>(e);
+        return query(new QueryContext(structure, options));
+    }
 }
 
 export { StructureQuery }