Browse Source

added density preset

Alexander Rose 5 years ago
parent
commit
bce79d1368
2 changed files with 64 additions and 14 deletions
  1. 15 1
      src/structure-viewer/helpers/preset.ts
  2. 49 13
      src/structure-viewer/helpers/volume.ts

+ 15 - 1
src/structure-viewer/helpers/preset.ts

@@ -83,7 +83,11 @@ type FeatureProps = {
     target: Target
 } & BaseProps
 
-export type PresetProps = ValidationProps | StandardProps | SymmetryProps | FeatureProps
+type DensityProps = {
+    kind: 'density'
+} & BaseProps
+
+export type PresetProps = ValidationProps | StandardProps | SymmetryProps | FeatureProps | DensityProps
 
 export class PresetManager {
     get customState() {
@@ -102,6 +106,8 @@ export class PresetManager {
                 return this.symmetry(props.symmetryIndex, props.assemblyId, props.modelIndex)
             case 'validation':
                 return this.validation(props.colorTheme, props.showClashes, props.assemblyId, props.modelIndex)
+            case 'density':
+                return this.density(props.assemblyId, props.modelIndex)
         }
     }
 
@@ -256,6 +262,14 @@ export class PresetManager {
         this.focusOnLoci()
     }
 
+    async density(assemblyId?: string, modelIndex?: number) {
+        await this.ensureAssembly(assemblyId, modelIndex)
+        await this.customState.structureView.setSymmetry(-1)
+        await this.default()
+        await this.customState.volumeData.setView('cell')
+        this.focusOnLoci()
+    }
+
     async ensureAssembly(assemblyId?: string, modelIndex?: number, neverApplyDefault?: boolean) {
         const oldSize = this.customState.structureView.getSize()
 

+ 49 - 13
src/structure-viewer/helpers/volume.ts

@@ -6,11 +6,12 @@
 
 import { StateElements, StructureViewerState } from '../types';
 import { PluginCommands } from 'molstar/lib/mol-plugin/command';
-import { StateSelection } from 'molstar/lib/mol-state';
+import { StateSelection, StateBuilder } from 'molstar/lib/mol-state';
 import { PluginContext } from 'molstar/lib/mol-plugin/context';
-import { InitVolumeStreaming, CreateVolumeStreamingInfo } from 'molstar/lib/mol-plugin/behavior/dynamic/volume-streaming/transformers';
+import { InitVolumeStreaming, CreateVolumeStreamingInfo, CreateVolumeStreamingBehavior } from 'molstar/lib/mol-plugin/behavior/dynamic/volume-streaming/transformers';
 import { ParamDefinition as PD } from 'molstar/lib/mol-util/param-definition';
 import { Model } from 'molstar/lib/mol-model/structure';
+import { deepClone } from 'molstar/lib/mol-util/object';
 import { modelHasMap } from './util';
 
 export class VolumeData {
@@ -19,32 +20,67 @@ export class VolumeData {
     }
 
     get state() {
-        return this.plugin.state.dataState;
+        return this.plugin.state.dataState
+    }
+
+    async applyState(tree: StateBuilder) {
+        await PluginCommands.State.Update.dispatch(this.plugin, { state: this.state, tree });
     }
 
     async init() {
-        const r = this.state.select(StateSelection.Generators.ofTransformer(CreateVolumeStreamingInfo))[0];
-        if (r) return;
+        const r = this.state.select(StateSelection.Generators.ofTransformer(CreateVolumeStreamingInfo))[0]
+        if (r) return
 
         const { props } = this.customState
-        const model = this.state.select(StateElements.Model)[0].obj;
-        const asm = this.state.select(StateElements.Assembly)[0].obj;
+        const model = this.state.select(StateElements.Model)[0].obj
+        const asm = this.state.select(StateElements.Assembly)[0].obj
         if (!model || !asm) return
 
         const m = model.data as Model
         if (modelHasMap(m)) {
-            const params = PD.getDefaultValues(InitVolumeStreaming.definition.params!(asm, this.plugin));
+            const params = PD.getDefaultValues(InitVolumeStreaming.definition.params!(asm, this.plugin))
             params.defaultView = 'selection-box';
-            params.options.behaviorRef = StateElements.VolumeStreaming;
+            params.options.behaviorRef = StateElements.VolumeStreaming
             params.options.serverUrl = props.volumeServerUrl
-            await this.plugin.runTask(this.state.applyAction(InitVolumeStreaming, params, StateElements.Assembly));
+            await this.plugin.runTask(this.state.applyAction(InitVolumeStreaming, params, StateElements.Assembly))
         }
     }
 
+    async setView(view: 'off' | 'cell' | 'selection-box') {
+        const r = this.state.select(StateSelection.Generators.ofTransformer(CreateVolumeStreamingInfo))[0]
+        if (!r) return
+
+        const vol = this.state.select(StateElements.VolumeStreaming)[0]
+        if (!vol) return
+
+        const tree = this.state.build();
+        tree.to(StateElements.VolumeStreaming).update(
+            CreateVolumeStreamingBehavior,
+            props => {
+                const p = deepClone(props)
+                if (p.entry.params.view.name !== view) {
+                    p.entry.params.view.name = view
+                    if (view === 'selection-box') {
+                        p.entry.params.view.params = {
+                            radius: 5,
+                            topRight: [0, 0, 0],
+                            bottomLeft: [0, 0, 0],
+                        }
+                    } else {
+                        p.entry.params.view.params = {}
+                    }
+                }
+                return p
+            }
+        )
+
+        await this.applyState(tree)
+    }
+
     async remove() {
-        const r = this.state.select(StateSelection.Generators.ofTransformer(CreateVolumeStreamingInfo))[0];
-        if (!r) return;
-        await PluginCommands.State.RemoveObject.dispatch(this.plugin, { state: this.state, ref: r.transform.ref });
+        const r = this.state.select(StateSelection.Generators.ofTransformer(CreateVolumeStreamingInfo))[0]
+        if (!r) return
+        await PluginCommands.State.RemoveObject.dispatch(this.plugin, { state: this.state, ref: r.transform.ref })
     }
 
     constructor(private plugin: PluginContext) {