Browse Source

wip, structure tools, repr presets

Alexander Rose 5 years ago
parent
commit
3b1a2f19a4

+ 2 - 10
src/mol-plugin/ui/structure/representation.tsx

@@ -10,9 +10,7 @@ import { Structure, StructureElement } from '../../../mol-model/structure';
 import { isEmptyLoci } from '../../../mol-model/loci';
 import { ColorOptions, ParameterControls } 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';
+import { ButtonSelect, Options } from '../controls/common'
 import { ParamDefinition as PD } from '../../../mol-util/param-definition';
 
 abstract class BaseStructureRepresentationControls extends PluginUIComponent {
@@ -92,13 +90,7 @@ class SelectionStructureRepresentationControls extends BaseStructureRepresentati
 
 export class StructureRepresentationControls extends PluginUIComponent {
     preset = async () => {
-        const { structureRepresentation: rep } = this.plugin.helpers
-        await rep.clear()
-        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 ])
-        ]))
+        await this.plugin.helpers.structureRepresentation.preset()
     }
 
     onChange = async (p: { param: PD.Base<any>, name: string, value: any }) => {

+ 12 - 0
src/mol-plugin/util/structure-representation-helper.ts

@@ -12,6 +12,8 @@ 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';
+import { StructureSelectionQueries as Q } from '../util/structure-selection-helper';
+import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
 
 type StructureTransform = StateObjectCell<PSO.Molecule.Structure, StateTransform<StateTransformer<any, PSO.Molecule.Structure, any>>>
 const RepresentationManagerTag = 'representation-controls'
@@ -145,6 +147,16 @@ export class StructureRepresentationHelper {
         this._ignoreHydrogens = ignoreHydrogens
     }
 
+    async preset() {
+        // TODO generalize and make configurable
+        await this.clear()
+        await this.setFromExpression('add', 'cartoon', Q.all)
+        await this.setFromExpression('add', 'carbohydrate', Q.all)
+        await this.setFromExpression('add', 'ball-and-stick', MS.struct.modifier.union([
+            MS.struct.combinator.merge([ Q.ligandsPlusConnected, Q.branchedConnectedOnly, Q.water ])
+        ]))
+    }
+
     constructor(private plugin: PluginContext) {
 
     }