Ver código fonte

wip, interactions options for representation panel

Alexander Rose 5 anos atrás
pai
commit
137e23c025

+ 4 - 0
src/mol-plugin-ui/structure/representation.tsx

@@ -17,6 +17,7 @@ import { CollapsableControls } from '../base';
 import { StateSelection, StateObject } from '../../mol-state';
 import { PluginStateObject } from '../../mol-plugin-state/objects';
 import { ColorOptions } from '../controls/color';
+import { InteractionsProvider } from '../../mol-model-props/computed/interactions';
 
 interface BaseStructureRepresentationControlsState {
     isDisabled: boolean
@@ -135,6 +136,7 @@ export class StructureRepresentationControls extends CollapsableControls<Collaps
         if (p.name === 'options') {
             await this.plugin.helpers.structureRepresentation.setIgnoreHydrogens(!p.value.showHydrogens)
             await this.plugin.helpers.structureRepresentation.setQuality(p.value.visualQuality)
+            await this.plugin.helpers.structureRepresentation.setInteractionsProps(p.value.interactions)
             this.forceUpdate()
         }
     }
@@ -145,6 +147,7 @@ export class StructureRepresentationControls extends CollapsableControls<Collaps
             options: PD.Group({
                 showHydrogens: PD.Boolean(options.showHydrogens, { description: 'Toggle display of hydrogen atoms in representations' }),
                 visualQuality: PD.Select<VisualQuality>(options.visualQuality, VisualQualityOptions, { description: 'Control the visual/rendering quality of representations' }),
+                interactions: PD.Group(InteractionsProvider.defaultParams, { label: 'Non-covalent Interactions' }),
             }, { isExpanded: true })
         }
     }
@@ -155,6 +158,7 @@ export class StructureRepresentationControls extends CollapsableControls<Collaps
             options: {
                 showHydrogens: !rep.ignoreHydrogens,
                 visualQuality: rep.quality,
+                interactions: rep.interactionProps,
             }
         }
     }

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

@@ -9,10 +9,13 @@ import { StateTransforms } from '../../mol-plugin-state/transforms';
 import { StateTransformer, StateSelection, StateObjectCell, StateTransform, StateBuilder } from '../../mol-state';
 import { StructureElement, Structure, StructureSelection, QueryContext } from '../../mol-model/structure';
 import { PluginContext } from '../context';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { StructureRepresentation3DHelpers } from '../../mol-plugin-state/transforms/representation';
 import Expression from '../../mol-script/language/expression';
 import { compile } from '../../mol-script/runtime/query/compiler';
 import { VisualQuality } from '../../mol-geo/geometry/base';
+import { InteractionsProps } from '../../mol-model-props/computed/interactions/interactions';
+import { InteractionsProvider } from '../../mol-model-props/computed/interactions';
 
 type StructureTransform = StateObjectCell<PSO.Molecule.Structure, StateTransform<StateTransformer<any, PSO.Molecule.Structure, any>>>
 type RepresentationTransform = StateObjectCell<PSO.Molecule.Structure.Representation3D, StateTransform<StateTransformer<any, PSO.Molecule.Structure.Representation3D, any>>>
@@ -240,6 +243,34 @@ export class StructureRepresentationHelper {
         this._quality = quality
     }
 
+    private _interactionProps = PD.getDefaultValues(InteractionsProvider.defaultParams)
+    get interactionProps () { return this._interactionProps }
+    async setInteractionsProps(interactionProps: InteractionsProps) {
+        const state = this.plugin.state.dataState;
+        const update = state.build()
+        const structures = state.select(StateSelection.Generators.rootsOfType(PSO.Molecule.Structure))
+        for (const structure of structures) {
+            const reprStructure = this.getRepresentationStructure(structure.transform.ref, 'interactions') // TODO use enum for type name
+            if (reprStructure) {
+                const customStructureProps = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Model.CustomStructureProperties, reprStructure.transform.ref))[0]
+
+                const params = PD.getDefaultValues(this.plugin.customStructureProperties.getParams(structure.obj?.data))
+                params.autoAttach.push(InteractionsProvider.descriptor.name)
+                params.properties[InteractionsProvider.descriptor.name] = interactionProps
+
+                if (customStructureProps) {
+                    update.to(customStructureProps).update(params)
+                } else {
+                    update.to(reprStructure)
+                        .insert(StateTransforms.Model.CustomStructureProperties, params)
+                }
+            }
+        }
+        await this.plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true }))
+
+        this._interactionProps = interactionProps
+    }
+
     constructor(private plugin: PluginContext) {
 
     }