From 297b9bd3ffee4efb6ddb6ed0ee3d62428868709b Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Fri, 22 May 2020 10:27:31 -0700 Subject: [PATCH] update focus color in repr presets --- .../rcsb/assembly-symmetry/behavior.ts | 4 +-- .../rcsb/validation-report/behavior.ts | 25 ++++++++++--------- .../structure/representation-preset.ts | 21 +++++++++++++++- .../structure-focus-representation.ts | 4 +-- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/extensions/rcsb/assembly-symmetry/behavior.ts b/src/extensions/rcsb/assembly-symmetry/behavior.ts index bebc5e868..37e3ad3a5 100644 --- a/src/extensions/rcsb/assembly-symmetry/behavior.ts +++ b/src/extensions/rcsb/assembly-symmetry/behavior.ts @@ -181,8 +181,8 @@ export const AssemblySymmetryPreset = StructureRepresentationPresetProvider({ } const assemblySymmetry = await tryCreateAssemblySymmetry(plugin, structureCell); - const globalThemeName = assemblySymmetry.isOk ? Tag.Cluster as any : undefined; - const preset = await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName }, plugin); + const colorTheme = assemblySymmetry.isOk ? Tag.Cluster as any : undefined; + const preset = await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusThemeName: colorTheme }, plugin); return { components: preset.components, representations: { ...preset.representations, assemblySymmetry } }; } diff --git a/src/extensions/rcsb/validation-report/behavior.ts b/src/extensions/rcsb/validation-report/behavior.ts index 638dadbdf..c995d197e 100644 --- a/src/extensions/rcsb/validation-report/behavior.ts +++ b/src/extensions/rcsb/validation-report/behavior.ts @@ -309,15 +309,15 @@ export const ValidationReportGeometryQualityPreset = StructureRepresentationPres params: () => StructureRepresentationPresetProvider.CommonParams, async apply(ref, params, plugin) { const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref); - const model = structureCell?.obj?.data.model; - if (!structureCell || !model) return {}; + const structure = structureCell?.obj?.data; + if (!structureCell || !structure) return {}; await plugin.runTask(Task.create('Validation Report', async runtime => { - await ValidationReportProvider.attach({ runtime, assetManager: plugin.managers.asset }, model); + await ValidationReportProvider.attach({ runtime, assetManager: plugin.managers.asset }, structure.models[0]); })); const colorTheme = GeometryQualityColorThemeProvider.name as any; - const { components, representations } = await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme }, plugin); + const { components, representations } = await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusThemeName: colorTheme }, plugin); const clashes = await plugin.builders.structure.tryCreateComponentFromExpression(structureCell, hasClash.expression, 'clashes', { label: 'Clashes' }); @@ -329,6 +329,7 @@ export const ValidationReportGeometryQualityPreset = StructureRepresentationPres } await update.commit({ revertOnError: true }); + return { components: { ...components, clashes }, representations: { ...representations, clashesBallAndStick, clashesRepr } }; } }); @@ -345,15 +346,15 @@ export const ValidationReportDensityFitPreset = StructureRepresentationPresetPro params: () => StructureRepresentationPresetProvider.CommonParams, async apply(ref, params, plugin) { const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref); - const model = structureCell?.obj?.data.model; - if (!structureCell || !model) return {}; + const structure = structureCell?.obj?.data; + if (!structureCell || !structure) return {}; await plugin.runTask(Task.create('Validation Report', async runtime => { - await ValidationReportProvider.attach({ runtime, assetManager: plugin.managers.asset }, model); + await ValidationReportProvider.attach({ runtime, assetManager: plugin.managers.asset }, structure.models[0]); })); const colorTheme = DensityFitColorThemeProvider.name as any; - return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme }, plugin); + return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusThemeName: colorTheme }, plugin); } }); @@ -369,14 +370,14 @@ export const ValidationReportRandomCoilIndexPreset = StructureRepresentationPres params: () => StructureRepresentationPresetProvider.CommonParams, async apply(ref, params, plugin) { const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref); - const model = structureCell?.obj?.data.model; - if (!structureCell || !model) return {}; + const structure = structureCell?.obj?.data; + if (!structureCell || !structure) return {}; await plugin.runTask(Task.create('Validation Report', async runtime => { - await ValidationReportProvider.attach({ runtime, assetManager: plugin.managers.asset }, model); + await ValidationReportProvider.attach({ runtime, assetManager: plugin.managers.asset }, structure.models[0]); })); const colorTheme = RandomCoilIndexColorThemeProvider.name as any; - return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme }, plugin); + return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusThemeName: colorTheme }, plugin); } }); \ No newline at end of file diff --git a/src/mol-plugin-state/builder/structure/representation-preset.ts b/src/mol-plugin-state/builder/structure/representation-preset.ts index 88b2d561a..da3087388 100644 --- a/src/mol-plugin-state/builder/structure/representation-preset.ts +++ b/src/mol-plugin-state/builder/structure/representation-preset.ts @@ -16,6 +16,8 @@ import { StateObjectRef, StateObjectSelector } from '../../../mol-state'; import { StaticStructureComponentType } from '../../helpers/structure-component'; import { StructureSelectionQueries as Q } from '../../helpers/structure-selection-query'; import { PluginConfig } from '../../../mol-plugin/config'; +import { StructureFocusRepresentation } from '../../../mol-plugin/behavior/dynamic/selection/structure-focus-representation'; +import { createStructureColorThemeParams } from '../../helpers/structure-representation-params'; export interface StructureRepresentationPresetProvider<P = any, S extends _Result = _Result> extends PresetProvider<PluginStateObject.Molecule.Structure, P, S> { } export function StructureRepresentationPresetProvider<P, S extends _Result>(repr: StructureRepresentationPresetProvider<P, S>) { return repr; } @@ -30,7 +32,8 @@ export namespace StructureRepresentationPresetProvider { export const CommonParams = { ignoreHydrogens: PD.Optional(PD.Boolean(false)), quality: PD.Optional(PD.Select<VisualQuality>('auto', VisualQualityOptions)), - globalThemeName: PD.Optional(PD.Text<ColorTheme.BuiltIn>('')) + globalThemeName: PD.Optional(PD.Text<ColorTheme.BuiltIn>('')), + focusThemeName: PD.Optional(PD.Text<ColorTheme.BuiltIn>('')) }; export type CommonParams = PD.ValuesFor<typeof CommonParams> @@ -47,6 +50,14 @@ export namespace StructureRepresentationPresetProvider { return { update, builder, color, typeParams }; } + + export function updateFocusRepr(plugin: PluginContext, structure: Structure, themeName?: ColorTheme.BuiltIn) { + return plugin.state.updateBehavior(StructureFocusRepresentation, p => { + const c = createStructureColorThemeParams(plugin, structure, 'ball-and-stick', themeName); + p.surroundingsParams.colorTheme = c; + p.targetParams.colorTheme = c; + }); + } } type _Result = StructureRepresentationPresetProvider.Result @@ -54,6 +65,7 @@ type _Result = StructureRepresentationPresetProvider.Result const CommonParams = StructureRepresentationPresetProvider.CommonParams; type CommonParams = StructureRepresentationPresetProvider.CommonParams const reprBuilder = StructureRepresentationPresetProvider.reprBuilder; +const updateFocusRepr = StructureRepresentationPresetProvider.updateFocusRepr; const auto = StructureRepresentationPresetProvider({ id: 'preset-structure-representation-auto', @@ -131,6 +143,7 @@ const polymerAndLigand = StructureRepresentationPresetProvider({ }; await update.commit({ revertOnError: false }); + await updateFocusRepr(plugin, structure, params.focusThemeName); return { components, representations }; } @@ -168,6 +181,8 @@ const proteinAndNucleic = StructureRepresentationPresetProvider({ }; await update.commit({ revertOnError: true }); + await updateFocusRepr(plugin, structure, params.focusThemeName); + return { components, representations }; } }); @@ -215,6 +230,8 @@ const coarseSurface = StructureRepresentationPresetProvider({ }; await update.commit({ revertOnError: true }); + await updateFocusRepr(plugin, structure, params.focusThemeName); + return { components, representations }; } }); @@ -245,6 +262,8 @@ const polymerCartoon = StructureRepresentationPresetProvider({ }; await update.commit({ revertOnError: true }); + await updateFocusRepr(plugin, structure, params.focusThemeName); + return { components, representations }; } }); diff --git a/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts b/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts index 0e733fc8f..051152665 100644 --- a/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts +++ b/src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts @@ -29,7 +29,7 @@ const StructureFocusRepresentationParams = (plugin: PluginContext) => { }), surroundingsParams: PD.Group(reprParams, { label: 'Surroundings', - customDefault: createStructureRepresentationParams(plugin, void 0, { type: 'ball-and-stick', color: 'element-symbol', size: 'physical', typeParams: { sizeFactor: 0.16 } }) + customDefault: createStructureRepresentationParams(plugin, void 0, { type: 'ball-and-stick', size: 'physical', typeParams: { sizeFactor: 0.16 } }) }), nciParams: PD.Group(reprParams, { label: 'Non-covalent Int.', @@ -57,7 +57,7 @@ export enum StructureFocusRepresentationTags { const TagSet: Set<StructureFocusRepresentationTags> = new Set([StructureFocusRepresentationTags.TargetSel, StructureFocusRepresentationTags.TargetRepr, StructureFocusRepresentationTags.SurrSel, StructureFocusRepresentationTags.SurrRepr, StructureFocusRepresentationTags.SurrNciRepr]); -export class StructureFocusRepresentationBehavior extends PluginBehavior.WithSubscribers<StructureFocusRepresentationProps> { +class StructureFocusRepresentationBehavior extends PluginBehavior.WithSubscribers<StructureFocusRepresentationProps> { private get surrLabel() { return `[Focus] Surroundings (${this.params.expandRadius} Å)`; } private ensureShape(cell: StateObjectCell<PluginStateObject.Molecule.Structure>) { -- GitLab