Browse Source

wip, structure view tools

Alexander Rose 5 years ago
parent
commit
5846d7c4b4

+ 1 - 1
src/mol-gl/renderer.ts

@@ -52,7 +52,7 @@ export const RendererParams = {
     ambientIntensity: PD.Numeric(0.4, { min: 0.0, max: 1.0, step: 0.01 }),
 
     metalness: PD.Numeric(0.0, { min: 0.0, max: 1.0, step: 0.01 }),
-    roughness: PD.Numeric(0.4, { min: 0.0, max: 1.0, step: 0.01 }),
+    roughness: PD.Numeric(1.0, { min: 0.0, max: 1.0, step: 0.01 }),
     reflectivity: PD.Numeric(0.5, { min: 0.0, max: 1.0, step: 0.01 }),
 }
 export type RendererProps = PD.Values<typeof RendererParams>

+ 0 - 1
src/mol-model/structure/structure/element.ts

@@ -473,7 +473,6 @@ namespace StructureElement {
                     atom: { set, ranges },
                     chain: { opName: [ opName ] },
                 }
-
         }
     }
 

+ 7 - 16
src/mol-plugin/ui/structure/representation.tsx

@@ -12,6 +12,7 @@ import { ColorOptions } from '../controls/parameters';
 import { Color } from '../../../mol-util/color';
 import { ButtonSelect, Options } from '../controls/common';
 import { StructureSelectionQueries as Q } from '../../util/structure-selection-helper';
+import { MolScriptBuilder as MS } from '../../../mol-script/language/builder';
 
 abstract class BaseStructureRepresentationControls extends PluginUIComponent {
     onChange = (value: string) => {
@@ -83,22 +84,12 @@ class SelectionStructureRepresentationControls extends BaseStructureRepresentati
 
 export class StructureRepresentationControls extends PluginUIComponent {
     preset = async () => {
-        const { structureSelection: sel, structureRepresentation: rep } = this.plugin.helpers
-        const lociGetter = (structure: Structure) => {
-            const loci = this.plugin.helpers.structureSelectionManager.get(structure)
-            return isEmptyLoci(loci) ? StructureElement.Loci.none(structure) : loci
-        }
-
-        sel.set('add', Q.all())
-        await rep.set('add', 'cartoon', lociGetter)
-        await rep.set('add', 'carbohydrate', lociGetter)
-
-        sel.set('only', Q.ligandsPlusConnected())
-        sel.set('add', Q.branchedConnectedOnly())
-        sel.set('add', Q.water())
-        await rep.set('add', 'ball-and-stick', lociGetter)
-
-        sel.set('remove', Q.all())
+        const { structureRepresentation: rep } = this.plugin.helpers
+        await rep.setFromExpression('add', 'cartoon', Q.all)
+        await rep.setFromExpression('add', 'carbohydrate', Q.all)
+        await rep.setFromExpression('add', 'ball-and-stick', MS.struct.modifier.union([
+            MS.struct.combinator.merge([ Q.ligandsPlusConnected, Q.branchedConnectedOnly, Q.water ])
+        ]))
     }
 
     render() {

+ 1 - 1
src/mol-plugin/ui/structure/selection.tsx

@@ -51,7 +51,7 @@ export class StructureSelectionControls extends PluginUIComponent<{}, {}> {
     }
 
     set = (modifier: SelectionModifier, value: string) => {
-        const query = StructureSelectionQueries[value as keyof typeof StructureSelectionQueries]()
+        const query = StructureSelectionQueries[value as keyof typeof StructureSelectionQueries]
         this.plugin.helpers.structureSelection.set(modifier, query)
     }
 

+ 11 - 1
src/mol-plugin/util/structure-representation-helper.ts

@@ -7,9 +7,11 @@
 import { PluginStateObject } from '../../mol-plugin/state/objects';
 import { StateTransforms } from '../../mol-plugin/state/transforms';
 import { StateTransformer, StateSelection, StateObjectCell, StateTransform } from '../../mol-state';
-import { StructureElement, Structure } from '../../mol-model/structure';
+import { StructureElement, Structure, StructureSelection, QueryContext } from '../../mol-model/structure';
 import { PluginContext } from '../context';
 import { StructureRepresentation3DHelpers } from '../state/transforms/representation';
+import Expression from '../../mol-script/language/expression';
+import { compile } from '../../mol-script/runtime/query/compiler';
 
 type StructureTransform = StateObjectCell<PluginStateObject.Molecule.Structure, StateTransform<StateTransformer<any, PluginStateObject.Molecule.Structure, any>>>
 const RepresentationManagerTag = 'representation-controls'
@@ -76,6 +78,14 @@ export class StructureRepresentationHelper {
         }
     }
 
+    async setFromExpression(modifier: SelectionModifier, type: string, expression: Expression) {
+        return this.set(modifier, type, (structure) => {
+            const compiled = compile<StructureSelection>(expression)
+            const result = compiled(new QueryContext(structure))
+            return StructureSelection.toLoci2(result)
+        })
+    }
+
     constructor(private plugin: PluginContext) {
 
     }

+ 18 - 13
src/mol-plugin/util/structure-selection-helper.ts

@@ -7,10 +7,13 @@
 import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
 import { StateSelection } from '../../mol-state';
 import { PluginStateObject } from '../state/objects';
-import { QueryContext, StructureSelection, QueryFn } from '../../mol-model/structure';
+import { QueryContext, StructureSelection } from '../../mol-model/structure';
 import { compile } from '../../mol-script/runtime/query/compiler';
 import { Loci } from '../../mol-model/loci';
 import { PluginContext } from '../context';
+import Expression from '../../mol-script/language/expression';
+
+const all = MS.struct.generator.all()
 
 const polymers = MS.struct.modifier.union([
     MS.struct.generator.atomGroups({
@@ -89,16 +92,16 @@ const coarse = MS.struct.modifier.union([
 ])
 
 export const StructureSelectionQueries = {
-    all: () => compile<StructureSelection>(MS.struct.generator.all()),
-    polymers: () => compile<StructureSelection>(polymers),
-    backboneTrace: () => compile<StructureSelection>(backboneTrace),
-    water: () => compile<StructureSelection>(water),
-    branched: () => compile<StructureSelection>(branched),
-    branchedPlusConnected: () => compile<StructureSelection>(branchedPlusConnected),
-    branchedConnectedOnly: () => compile<StructureSelection>(branchedConnectedOnly),
-    ligands: () => compile<StructureSelection>(ligands),
-    ligandsPlusConnected: () => compile<StructureSelection>(ligandsPlusConnected),
-    coarse: () => compile<StructureSelection>(coarse),
+    all,
+    polymers,
+    backboneTrace,
+    water,
+    branched,
+    branchedPlusConnected,
+    branchedConnectedOnly,
+    ligands,
+    ligandsPlusConnected,
+    coarse,
 }
 
 //
@@ -125,10 +128,12 @@ export class StructureSelectionHelper {
         }
     }
 
-    set(modifier: SelectionModifier, query: QueryFn<StructureSelection>) {
+    set(modifier: SelectionModifier, query: Expression) {
+        const compiled = compile<StructureSelection>(query)
+
         for (const so of this.structures) {
             const s = so.obj!.data
-            const result = query(new QueryContext(s))
+            const result = compiled(new QueryContext(s))
             const loci = StructureSelection.toLoci2(result)
             this._set(modifier, loci)
         }