Browse Source

mol-plugin: structure repr preset updates
- added "theme" object to params
- added carbonByChainId option
- added Structure.DefaultRepresentationPresetParams plugin config option

David Sehnal 4 years ago
parent
commit
9126416389

+ 1 - 1
src/extensions/rcsb/assembly-symmetry/behavior.ts

@@ -182,7 +182,7 @@ export const AssemblySymmetryPreset = StructureRepresentationPresetProvider({
 
         const assemblySymmetry = await tryCreateAssemblySymmetry(plugin, structureCell);
         const colorTheme = assemblySymmetry.isOk ? Tag.Cluster as any : undefined;
-        const preset = await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusTheme: { name: colorTheme } }, plugin);
+        const preset = await PresetStructureRepresentations.auto.apply(ref, { ...params, theme: { globalName: colorTheme, focus: { name: colorTheme } } }, plugin);
 
         return { components: preset.components, representations: { ...preset.representations, assemblySymmetry } };
     }

+ 3 - 3
src/extensions/rcsb/validation-report/behavior.ts

@@ -317,7 +317,7 @@ export const ValidationReportGeometryQualityPreset = StructureRepresentationPres
         }));
 
         const colorTheme = GeometryQualityColorThemeProvider.name as any;
-        const { components, representations } = await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusTheme: { name: colorTheme } }, plugin);
+        const { components, representations } = await PresetStructureRepresentations.auto.apply(ref, { ...params, theme: { globalName: colorTheme, focus: { name: colorTheme } } }, plugin);
 
         const clashes = await plugin.builders.structure.tryCreateComponentFromExpression(structureCell, hasClash.expression, 'clashes', { label: 'Clashes' });
 
@@ -354,7 +354,7 @@ export const ValidationReportDensityFitPreset = StructureRepresentationPresetPro
         }));
 
         const colorTheme = DensityFitColorThemeProvider.name as any;
-        return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusTheme: { name: colorTheme } }, plugin);
+        return await PresetStructureRepresentations.auto.apply(ref, { ...params, theme: { globalName: colorTheme, focus: { name: colorTheme } } }, plugin);
     }
 });
 
@@ -378,6 +378,6 @@ export const ValidationReportRandomCoilIndexPreset = StructureRepresentationPres
         }));
 
         const colorTheme = RandomCoilIndexColorThemeProvider.name as any;
-        return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme, focusTheme: { name: colorTheme } }, plugin);
+        return await PresetStructureRepresentations.auto.apply(ref, { ...params, theme: { globalName: colorTheme, focus: { name: colorTheme } } }, plugin);
     }
 });

+ 21 - 16
src/mol-plugin-state/builder/structure/representation-preset.ts

@@ -32,10 +32,13 @@ 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>('')),
-        focusTheme: PD.Optional(PD.Group({
-            name: PD.Optional(PD.Text<ColorTheme.BuiltIn>('')),
-            params: PD.Optional(PD.Value<ColorTheme.BuiltInParams<ColorTheme.BuiltIn>>({} as any))
+        theme: PD.Optional(PD.Group({
+            globalName: PD.Optional(PD.Text<ColorTheme.BuiltIn>('')),
+            carbonByChainId: PD.Optional(PD.Boolean(true)),
+            focus: PD.Optional(PD.Group({
+                name: PD.Optional(PD.Text<ColorTheme.BuiltIn>('')),
+                params: PD.Optional(PD.Value<ColorTheme.BuiltInParams<ColorTheme.BuiltIn>>({} as any))
+            }))
         }))
     };
     export type CommonParams = PD.ValuesFor<typeof CommonParams>
@@ -49,9 +52,10 @@ export namespace StructureRepresentationPresetProvider {
         };
         if (params.quality && params.quality !== 'auto') typeParams.quality = params.quality;
         if (params.ignoreHydrogens !== void 0) typeParams.ignoreHydrogens = !!params.ignoreHydrogens;
-        const color: ColorTheme.BuiltIn | undefined = params.globalThemeName ? params.globalThemeName : void 0;
+        const color: ColorTheme.BuiltIn | undefined = params.theme?.globalName ? params.theme?.globalName : void 0;
+        const ballAndStickColor: ColorTheme.BuiltInParams<'element-symbol'> = typeof params.theme?.carbonByChainId !== 'undefined' ? { carbonByChainId: !!params.theme?.carbonByChainId } : { };
 
-        return { update, builder, color, typeParams };
+        return { update, builder, color, typeParams, ballAndStickColor };
     }
 
     export function updateFocusRepr<T extends ColorTheme.BuiltIn>(plugin: PluginContext, structure: Structure, themeName: T | undefined, themeParams: ColorTheme.BuiltInParams<T> | undefined) {
@@ -137,12 +141,13 @@ const polymerAndLigand = StructureRepresentationPresetProvider({
             sizeFactor: structure.isCoarseGrained ? 0.8 : 0.2,
         };
 
-        const { update, builder, typeParams, color } = reprBuilder(plugin, params);
+        const { update, builder, typeParams, color, ballAndStickColor } = reprBuilder(plugin, params);
+
         const representations = {
             polymer: builder.buildRepresentation(update, components.polymer, { type: 'cartoon', typeParams: { ...typeParams, ...cartoonProps }, color }, { tag: 'polymer' }),
-            ligand: builder.buildRepresentation(update, components.ligand, { type: 'ball-and-stick', typeParams, color }, { tag: 'ligand' }),
-            nonStandard: builder.buildRepresentation(update, components.nonStandard, { type: 'ball-and-stick', typeParams, color }, { tag: 'non-standard' }),
-            branchedBallAndStick: builder.buildRepresentation(update, components.branched, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.3 }, color }, { tag: 'branched-ball-and-stick' }),
+            ligand: builder.buildRepresentation(update, components.ligand, { type: 'ball-and-stick', typeParams, color, colorParams: ballAndStickColor }, { tag: 'ligand' }),
+            nonStandard: builder.buildRepresentation(update, components.nonStandard, { type: 'ball-and-stick', typeParams, color, colorParams: ballAndStickColor }, { tag: 'non-standard' }),
+            branchedBallAndStick: builder.buildRepresentation(update, components.branched, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.3 }, color, colorParams: ballAndStickColor }, { tag: 'branched-ball-and-stick' }),
             branchedSnfg3d: builder.buildRepresentation(update, components.branched, { type: 'carbohydrate', typeParams, color }, { tag: 'branched-snfg-3d' }),
             water: builder.buildRepresentation(update, components.water, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.6 }, color }, { tag: 'water' }),
             lipid: builder.buildRepresentation(update, components.lipid, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.6 }, color, colorParams: { carbonByChainId: false } }, { tag: 'lipid' }),
@@ -150,7 +155,7 @@ const polymerAndLigand = StructureRepresentationPresetProvider({
         };
 
         await update.commit({ revertOnError: false });
-        await updateFocusRepr(plugin, structure, params.focusTheme?.name, params.focusTheme?.params);
+        await updateFocusRepr(plugin, structure, params.theme?.focus?.name, params.theme?.focus?.params);
 
         return { components, representations };
     }
@@ -188,7 +193,7 @@ const proteinAndNucleic = StructureRepresentationPresetProvider({
         };
 
         await update.commit({ revertOnError: true });
-        await updateFocusRepr(plugin, structure, params.focusTheme?.name, params.focusTheme?.params);
+        await updateFocusRepr(plugin, structure, params.theme?.focus?.name, params.theme?.focus?.params);
 
         return { components, representations };
     }
@@ -237,7 +242,7 @@ const coarseSurface = StructureRepresentationPresetProvider({
         };
 
         await update.commit({ revertOnError: true });
-        await updateFocusRepr(plugin, structure, params.focusTheme?.name, params.focusTheme?.params);
+        await updateFocusRepr(plugin, structure, params.theme?.focus?.name, params.theme?.focus?.params);
 
         return { components, representations };
     }
@@ -269,7 +274,7 @@ const polymerCartoon = StructureRepresentationPresetProvider({
         };
 
         await update.commit({ revertOnError: true });
-        await updateFocusRepr(plugin, structure, params.focusTheme?.name, params.focusTheme?.params);
+        await updateFocusRepr(plugin, structure, params.theme?.focus?.name, params.theme?.focus?.params);
 
         return { components, representations };
     }
@@ -299,9 +304,9 @@ const atomicDetail = StructureRepresentationPresetProvider({
             });
         }
 
-        const { update, builder, typeParams, color } = reprBuilder(plugin, params);
+        const { update, builder, typeParams, color, ballAndStickColor } = reprBuilder(plugin, params);
         const representations = {
-            all: builder.buildRepresentation(update, components.all, { type: 'ball-and-stick', typeParams, color }, { tag: 'all' }),
+            all: builder.buildRepresentation(update, components.all, { type: 'ball-and-stick', typeParams, color, colorParams: ballAndStickColor }, { tag: 'all' }),
         };
         if (params.showCarbohydrateSymbol) {
             Object.assign(representations, {

+ 7 - 2
src/mol-plugin-state/builder/structure/representation.ts

@@ -16,6 +16,7 @@ import { PluginStateObject } from '../../objects';
 import { StructureRepresentation3D } from '../../transforms/representation';
 import { PresetStructureRepresentations, StructureRepresentationPresetProvider } from './representation-preset';
 import { arrayRemoveInPlace } from '../../../mol-util/array';
+import { PluginConfig } from '../../../mol-plugin/config';
 
 // TODO factor out code shared with TrajectoryHierarchyBuilder?
 
@@ -102,10 +103,14 @@ export class StructureRepresentationBuilder {
             return;
         }
 
-        const prms = params || (provider.params
-            ? PD.getDefaultValues(provider.params(cell.obj, this.plugin) as PD.Params)
+        const pd = provider.params?.(cell.obj, this.plugin) as PD.Params || {};
+        let prms = params || (provider.params
+            ? PD.getDefaultValues(pd)
             : {});
 
+        const defaults = this.plugin.config.get(PluginConfig.Structure.DefaultRepresentationPresetParams);
+        prms = PD.merge(pd, defaults, prms);
+
         const task = Task.create(`${provider.display.name}`, () => provider.apply(cell, prms, this.plugin) as Promise<any>);
         return this.plugin.runTask(task);
     }

+ 2 - 0
src/mol-plugin/config.ts

@@ -9,6 +9,7 @@ import { Structure, Model } from '../mol-model/structure';
 import { PluginContext } from './context';
 import { PdbDownloadProvider } from '../mol-plugin-state/actions/structure';
 import { EmdbDownloadProvider } from '../mol-plugin-state/actions/volume';
+import { StructureRepresentationPresetProvider } from '../mol-plugin-state/builder/structure/representation-preset';
 
 export class PluginConfigItem<T = any> {
     toString() { return this.key; }
@@ -45,6 +46,7 @@ export const PluginConfig = {
     },
     Structure: {
         SizeThresholds: item('structure.size-thresholds', Structure.DefaultSizeThresholds),
+        DefaultRepresentationPresetParams: item<StructureRepresentationPresetProvider.CommonParams>('structure.default-representation-preset-params', { theme: { carbonByChainId: false } })
     }
 };