Browse Source

unify structure representation params creation

David Sehnal 5 years ago
parent
commit
5edc924e4f

+ 5 - 8
src/apps/basic-wrapper/helpers.ts

@@ -8,11 +8,11 @@ import { Mat4, Vec3 } from '../../mol-math/linear-algebra';
 import { PluginContext } from '../../mol-plugin/context';
 import { PluginStateObject as PSO } from '../../mol-plugin-state/objects';
 import { StateTransforms } from '../../mol-plugin-state/transforms';
-import { StructureRepresentation3DHelpers } from '../../mol-plugin-state/transforms/representation';
 import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
 import { StateBuilder } from '../../mol-state';
 import Expression from '../../mol-script/language/expression';
 import { BuiltInColorThemeName } from '../../mol-theme/color';
+import { createStructureRepresentationParams } from '../../mol-plugin-state/helpers/structure-representation-params';
 type SupportedFormats = 'cif' | 'pdb'
 
 export namespace StateHelper {
@@ -79,21 +79,18 @@ export namespace StateHelper {
     export function visual(ctx: PluginContext, visualRoot: StateBuilder.To<PSO.Molecule.Structure>) {
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'atomic-sequence' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'cartoon'), { tags: 'seq-visual' });
+                createStructureRepresentationParams(ctx, void 0, { type: 'cartoon' }), { tags: 'seq-visual' });
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'atomic-het' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'ball-and-stick'), { tags: 'het-visual' });
-        // visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'water' })
-        //     .apply(StateTransforms.Representation.StructureRepresentation3D,
-        //         StructureRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'ball-and-stick', { alpha: 0.51 }), { tags: 'water-visual' });
+                createStructureRepresentationParams(ctx, void 0, { type: 'ball-and-stick' }), { tags: 'het-visual' });
         return visualRoot;
     }
 
-    export function ballsAndSticks(ctx: PluginContext, visualRoot: StateBuilder.To<PSO.Molecule.Structure>, expression: Expression, coloring?: BuiltInColorThemeName) {
+    export function ballsAndSticks(ctx: PluginContext, visualRoot: StateBuilder.To<PSO.Molecule.Structure>, expression: Expression, color?: BuiltInColorThemeName) {
         visualRoot
             .apply(StateTransforms.Model.StructureSelectionFromExpression, { expression })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'ball-and-stick', void 0, coloring), { tags: 'het-visual' });
+                createStructureRepresentationParams(ctx, void 0, { type: 'ball-and-stick', color }), { tags: 'het-visual' });
         return visualRoot;
     }
 

+ 5 - 5
src/apps/basic-wrapper/index.ts

@@ -9,7 +9,6 @@ import './index.html'
 import { PluginContext } from '../../mol-plugin/context';
 import { PluginCommands } from '../../mol-plugin/commands';
 import { StateTransforms } from '../../mol-plugin-state/transforms';
-import { StructureRepresentation3DHelpers } from '../../mol-plugin-state/transforms/representation';
 import { Color } from '../../mol-util/color';
 import { PluginStateObject as PSO, PluginStateObject } from '../../mol-plugin-state/objects';
 import { AnimateModelIndex } from '../../mol-plugin-state/animation/built-in';
@@ -21,6 +20,7 @@ import { CustomToastMessage } from './controls';
 import { EmptyLoci } from '../../mol-model/loci';
 import { StructureSelection } from '../../mol-model/structure';
 import { Script } from '../../mol-script/script';
+import { createStructureRepresentationParams } from '../../mol-plugin-state/helpers/structure-representation-params';
 require('mol-plugin-ui/skin/light.scss')
 
 type SupportedFormats = 'cif' | 'pdb'
@@ -76,16 +76,16 @@ class BasicWrapper {
     private visual(visualRoot: StateBuilder.To<PSO.Molecule.Structure>) {
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'atomic-sequence' }, { ref: 'seq' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(this.plugin, 'cartoon'), { ref: 'seq-visual' });
+                createStructureRepresentationParams(this.plugin, void 0, { type: 'cartoon' }), { ref: 'seq-visual' });
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'atomic-het' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(this.plugin, 'ball-and-stick'), { ref: 'het-visual' });
+                createStructureRepresentationParams(this.plugin, void 0, { type: 'ball-and-stick' }), { ref: 'het-visual' });
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'water' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(this.plugin, 'ball-and-stick', { alpha: 0.51 }), { ref: 'water-visual' });
+                createStructureRepresentationParams(this.plugin, void 0, { type: 'ball-and-stick', typeParams: { alpha: 0.51 } }), { ref: 'water-visual' });
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'spheres' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(this.plugin, 'spacefill'), { ref: 'ihm-visual' });
+                createStructureRepresentationParams(this.plugin, void 0, { type: 'spacefill' }), { ref: 'ihm-visual' });
         return visualRoot;
     }
 

+ 3 - 3
src/apps/demos/lighting/index.ts

@@ -9,10 +9,10 @@ import './index.html'
 import { PluginContext } from '../../../mol-plugin/context';
 import { PluginCommands } from '../../../mol-plugin/commands';
 import { StateTransforms } from '../../../mol-plugin-state/transforms';
-import { StructureRepresentation3DHelpers } from '../../../mol-plugin-state/transforms/representation';
 import { PluginStateObject as PSO } from '../../../mol-plugin-state/objects';
 import { StateBuilder } from '../../../mol-state';
 import { Canvas3DProps } from '../../../mol-canvas3d/canvas3d';
+import { createStructureRepresentationParams } from '../../../mol-plugin-state/helpers/structure-representation-params';
 require('mol-plugin-ui/skin/light.scss')
 
 type SupportedFormats = 'cif' | 'pdb'
@@ -134,10 +134,10 @@ class LightingDemo {
     private visual(visualRoot: StateBuilder.To<PSO.Molecule.Structure>) {
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'atomic-sequence' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(this.plugin, 'spacefill', {}, 'illustrative'), { ref: 'seq-visual' });
+                createStructureRepresentationParams(this.plugin, void 0, { type: 'spacefill', color: 'illustrative' }), { ref: 'seq-visual' });
         visualRoot.apply(StateTransforms.Model.StructureComplexElement, { type: 'atomic-het' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.getDefaultParamsStatic(this.plugin, 'ball-and-stick'), { ref: 'het-visual' });
+                createStructureRepresentationParams(this.plugin, void 0, { type: 'ball-and-stick' }), { ref: 'het-visual' });
         return visualRoot;
     }
 

+ 3 - 3
src/apps/viewer/extensions/cellpack/model.ts

@@ -16,7 +16,6 @@ import { trajectoryFromPDB } from '../../../../mol-model-formats/structure/pdb';
 import { Mat4, Vec3, Quat } from '../../../../mol-math/linear-algebra';
 import { SymmetryOperator } from '../../../../mol-math/geometry';
 import { Task } from '../../../../mol-task';
-import { StructureRepresentation3DHelpers } from '../../../../mol-plugin-state/transforms/representation';
 import { StateTransforms } from '../../../../mol-plugin-state/transforms';
 import { distinctColors } from '../../../../mol-util/color/distinct';
 import { ModelIndexColorThemeProvider } from '../../../../mol-theme/color/model-index';
@@ -30,6 +29,7 @@ import { CifCategory, CifField } from '../../../../mol-io/reader/cif';
 import { mmCIF_Schema } from '../../../../mol-io/reader/cif/schema/mmcif';
 import { Column } from '../../../../mol-data/db';
 import { createModels } from '../../../../mol-model-formats/structure/basic/parser';
+import { createStructureRepresentationParams } from '../../../../mol-plugin-state/helpers/structure-representation-params';
 
 function getCellPackModelUrl(fileName: string, baseUrl: string) {
     return `${baseUrl}/results/${fileName}`
@@ -396,7 +396,7 @@ export const LoadCellPackModel = StateAction.build({
         }
         cellpackTree
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.createParams(ctx, Structure.Empty, {
+                createStructureRepresentationParams(ctx, Structure.Empty, {
                     ...getReprParams(ctx, params.preset),
                     ...getColorParams(hue)
                 })
@@ -412,7 +412,7 @@ export const LoadCellPackModel = StateAction.build({
             .apply(StateTransforms.Model.StructureFromModel, undefined, { state: { isGhost: true } })
             .apply(StateTransforms.Misc.CreateGroup, { label: 'HIV1_envelope_Membrane' })
             .apply(StateTransforms.Representation.StructureRepresentation3D,
-                StructureRepresentation3DHelpers.createParams(ctx, Structure.Empty, {
+                createStructureRepresentationParams(ctx, Structure.Empty, {
                     ...getReprParams(ctx, params.preset),
                     color: UniformColorThemeProvider
                 })

+ 3 - 3
src/apps/viewer/extensions/jolecule.ts

@@ -18,7 +18,7 @@
 // import { UUID } from '../../../mol-util';
 // import { ColorNames } from '../../../mol-util/color/names';
 // import { Camera } from '../../../mol-canvas3d/camera';
-// import { StructureRepresentation3DHelpers } from '../../../mol-plugin/state/transforms/representation';
+// import { createStructureRepresentation3dParamss } from '../../../mol-plugin/state/transforms/representation';
 // import { createDefaultStructureComplex } from '../../../mol-plugin/util/structure-complex-helper';
 
 // export const CreateJoleculeState = StateAction.build({
@@ -108,13 +108,13 @@
 //         group
 //             .apply(StateTransforms.Model.StructureSelectionFromExpression, { expression: MS.struct.modifier.wholeResidues([ expression ]), label: 'Residue' })
 //             .apply(StateTransforms.Representation.StructureRepresentation3D,
-//                 StructureRepresentation3DHelpers.getDefaultParamsStatic(plugin, 'ball-and-stick', {  }));
+//                 createStructureRepresentation3dParamss.getDefaultParamsStatic(plugin, 'ball-and-stick', {  }));
 //     }
 //     if (params.e.selected && params.e.selected.length > 0) {
 //         b.to(template.structure)
 //             .apply(StateTransforms.Model.StructureSelectionFromExpression, { expression: createExpression(params.e.selected), label: `Selected` })
 //             .apply(StateTransforms.Representation.StructureRepresentation3D,
-//                 StructureRepresentation3DHelpers.getDefaultParamsStatic(plugin, 'ball-and-stick'));
+//                 createStructureRepresentation3dParamss.getDefaultParamsStatic(plugin, 'ball-and-stick'));
 //     }
 //     // TODO
 //     // for (const l of params.e.distances) {

+ 21 - 22
src/examples/proteopedia-wrapper/index.ts

@@ -10,7 +10,6 @@ import './index.html'
 import { PluginContext } from '../../mol-plugin/context';
 import { PluginCommands } from '../../mol-plugin/commands';
 import { StateTransforms } from '../../mol-plugin-state/transforms';
-import { StructureRepresentation3DHelpers } from '../../mol-plugin-state/transforms/representation';
 import { Color } from '../../mol-util/color';
 import { PluginStateObject as PSO, PluginStateObject } from '../../mol-plugin-state/objects';
 import { AnimateModelIndex } from '../../mol-plugin-state/animation/built-in';
@@ -23,12 +22,10 @@ import { PluginState } from '../../mol-plugin/state';
 import { Scheduler } from '../../mol-task';
 import { createProteopediaCustomTheme } from './coloring';
 import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
-import { BuiltInStructureRepresentations } from '../../mol-repr/structure/registry';
-import { BuiltInColorThemes } from '../../mol-theme/color';
-import { BuiltInSizeThemes } from '../../mol-theme/size';
 import { ColorNames } from '../../mol-util/color/names';
 import { InitVolumeStreaming, CreateVolumeStreamingInfo } from '../../mol-plugin/behavior/dynamic/volume-streaming/transformers';
 import { DefaultCanvas3DParams, Canvas3DProps } from '../../mol-canvas3d/canvas3d';
+import { createStructureRepresentationParams } from '../../mol-plugin-state/helpers/structure-representation-params';
 // import { Vec3 } from 'mol-math/linear-algebra';
 // import { ParamDefinition } from 'mol-util/param-definition';
 // import { Text } from 'mol-geo/geometry/text/text';
@@ -127,9 +124,10 @@ class MolStarProteopediaWrapper {
                 root.delete(StateElements.SequenceVisual);
             } else {
                 root.applyOrUpdate(StateElements.SequenceVisual, StateTransforms.Representation.StructureRepresentation3D,
-                    StructureRepresentation3DHelpers.getDefaultParamsWithTheme(this.plugin,
-                        (style.sequence && style.sequence.kind) || 'cartoon',
-                        (style.sequence && style.sequence.coloring) || 'unit-index', structure));
+                    createStructureRepresentationParams(this.plugin, structure, {
+                        type: (style.sequence && style.sequence.kind) || 'cartoon',
+                        color: (style.sequence && style.sequence.coloring) || 'unit-index'
+                    }));
             }
         }
 
@@ -142,9 +140,10 @@ class MolStarProteopediaWrapper {
                     root.delete(StateElements.HetVisual);
                 } else {
                     root.applyOrUpdate(StateElements.HetVisual, StateTransforms.Representation.StructureRepresentation3D,
-                        StructureRepresentation3DHelpers.getDefaultParamsWithTheme(this.plugin,
-                            (style.hetGroups && style.hetGroups.kind) || 'ball-and-stick',
-                            (style.hetGroups && style.hetGroups.coloring), structure));
+                        createStructureRepresentationParams(this.plugin, structure, {
+                            type: (style.hetGroups && style.hetGroups.kind) || 'ball-and-stick',
+                            color: style.hetGroups && style.hetGroups.coloring
+                        }));
                 }
             }
         }
@@ -158,7 +157,7 @@ class MolStarProteopediaWrapper {
                     root.delete(StateElements.Het3DSNFG);
                 } else {
                     root.applyOrUpdate(StateElements.Het3DSNFG, StateTransforms.Representation.StructureRepresentation3D,
-                        StructureRepresentation3DHelpers.getDefaultParamsWithTheme(this.plugin, 'carbohydrate', void 0, structure));
+                        createStructureRepresentationParams(this.plugin, structure, { type: 'carbohydrate' }));
                 }
             }
         }
@@ -169,9 +168,11 @@ class MolStarProteopediaWrapper {
                 root.delete(StateElements.WaterVisual);
             } else {
                 root.applyOrUpdate(StateElements.WaterVisual, StateTransforms.Representation.StructureRepresentation3D,
-                    StructureRepresentation3DHelpers.getDefaultParamsWithTheme(this.plugin,
-                        (style.water && style.water.kind) || 'ball-and-stick',
-                        (style.water && style.water.coloring), structure, { alpha: 0.51 }));
+                    createStructureRepresentationParams(this.plugin, structure, {
+                        type: (style.water && style.water.kind) || 'ball-and-stick',
+                        typeParams: { alpha: 0.51 },
+                        color: style.water && style.water.coloring
+                    }));
             }
         }
 
@@ -408,19 +409,17 @@ class MolStarProteopediaWrapper {
 
     private createSurVisualParams() {
         const asm = this.state.select(StateElements.Assembly)[0].obj as PluginStateObject.Molecule.Structure;
-        return StructureRepresentation3DHelpers.createParams(this.plugin, asm.data, {
-            type: BuiltInStructureRepresentations['ball-and-stick'],
-            color: BuiltInColorThemes.uniform, colorParams: { value: ColorNames.gray },
-            size: BuiltInSizeThemes.uniform, sizeParams: { value: 0.33 }
+        return createStructureRepresentationParams(this.plugin, asm.data, {
+            type: 'ball-and-stick',
+            color: 'uniform', colorParams: { value: ColorNames.gray },
+            size: 'uniform', sizeParams: { value: 0.33 }
         });
     }
 
     private createCoreVisualParams() {
         const asm = this.state.select(StateElements.Assembly)[0].obj as PluginStateObject.Molecule.Structure;
-        return StructureRepresentation3DHelpers.createParams(this.plugin, asm.data, {
-            type: BuiltInStructureRepresentations['ball-and-stick'],
-            // color: [BuiltInColorThemes.uniform, () => ({ value: ColorNames.gray })],
-            // size: [BuiltInSizeThemes.uniform, () => ({ value: 0.33 } )]
+        return createStructureRepresentationParams(this.plugin, asm.data, {
+            type: 'ball-and-stick'
         });
     }
 

+ 12 - 12
src/mol-plugin-state/builder/structure/preset.ts

@@ -75,15 +75,15 @@ const polymerAndLigand = StructureRepresentationProvider({
 
         const { update, builder, typeParams, color } = reprBuilder(plugin, params);
         const representations = {
-            polymer: builder.builtInRepresentation(update, components.polymer, { type: 'cartoon', typeParams, color }),
-            ligand: builder.builtInRepresentation(update, components.ligand, { type: 'ball-and-stick', typeParams, color }),
-            nonStandard: builder.builtInRepresentation(update, components.nonStandard, { type: 'ball-and-stick', typeParams, color: color || 'polymer-id' }),
+            polymer: builder.buildRepresentation(update, components.polymer, { type: 'cartoon', typeParams, color }),
+            ligand: builder.buildRepresentation(update, components.ligand, { type: 'ball-and-stick', typeParams, color }),
+            nonStandard: builder.buildRepresentation(update, components.nonStandard, { type: 'ball-and-stick', typeParams, color: color || 'polymer-id' }),
             branched: components.branched && {
-                ballAndStick: builder.builtInRepresentation(update, components.branched, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.15 }, color }),
-                snfg3d: builder.builtInRepresentation(update, components.branched, { type: 'carbohydrate', typeParams, color }),
+                ballAndStick: builder.buildRepresentation(update, components.branched, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.15 }, color }),
+                snfg3d: builder.buildRepresentation(update, components.branched, { type: 'carbohydrate', typeParams, color }),
             },
-            water: builder.builtInRepresentation(update, components.water, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.51 }, color }),
-            coarse: builder.builtInRepresentation(update, components.coarse, { type: 'spacefill', typeParams, color: color || 'polymer-id' })
+            water: builder.buildRepresentation(update, components.water, { type: 'ball-and-stick', typeParams: { ...typeParams, alpha: 0.51 }, color }),
+            coarse: builder.buildRepresentation(update, components.coarse, { type: 'spacefill', typeParams, color: color || 'polymer-id' })
         };
 
         await state.updateTree(update, { revertOnError: false }).runInContext(ctx);
@@ -103,8 +103,8 @@ const proteinAndNucleic = StructureRepresentationProvider({
 
         const { update, builder, typeParams, color } = reprBuilder(plugin, params);
         const representations = {
-            protein: builder.builtInRepresentation(update, components.protein, { type: 'cartoon', typeParams, color }),
-            nucleic: builder.builtInRepresentation(update, components.nucleic, { type: 'gaussian-surface', typeParams, color })
+            protein: builder.buildRepresentation(update, components.protein, { type: 'cartoon', typeParams, color }),
+            nucleic: builder.buildRepresentation(update, components.nucleic, { type: 'gaussian-surface', typeParams, color })
         };
 
         await state.updateTree(update, { revertOnError: true }).runInContext(ctx);
@@ -142,7 +142,7 @@ const coarseSurface = StructureRepresentationProvider({
         
         const { update, builder, typeParams, color } = reprBuilder(plugin, params);
         const representations = {
-            trace: builder.builtInRepresentation(update, components.trace, { type: 'gaussian-surface', typeParams: { ...typeParams, ...gaussianProps }, color })
+            trace: builder.buildRepresentation(update, components.trace, { type: 'gaussian-surface', typeParams: { ...typeParams, ...gaussianProps }, color })
         };
 
         await state.updateTree(update, { revertOnError: true }).runInContext(ctx);
@@ -161,7 +161,7 @@ const polymerCartoon = StructureRepresentationProvider({
 
         const { update, builder, typeParams, color } = reprBuilder(plugin, params);
         const representations = {
-            polymer: builder.builtInRepresentation(update, components.polymer, { type: 'cartoon', typeParams, color })
+            polymer: builder.buildRepresentation(update, components.polymer, { type: 'cartoon', typeParams, color })
         };
 
         await state.updateTree(update, { revertOnError: true }).runInContext(ctx);
@@ -181,7 +181,7 @@ const atomicDetail = StructureRepresentationProvider({
 
         const { update, builder, typeParams, color } = reprBuilder(plugin, params);
         const representations = {
-            all: builder.builtInRepresentation(update, components.all, { type: 'ball-and-stick', typeParams, color })
+            all: builder.buildRepresentation(update, components.all, { type: 'ball-and-stick', typeParams, color })
         };
 
         await state.updateTree(update, { revertOnError: true }).runInContext(ctx);

+ 15 - 18
src/mol-plugin-state/builder/structure/representation.ts

@@ -4,23 +4,20 @@
  * @author David Sehnal <david.sehnal@gmail.com>
  */
 
+import { UniqueArray } from '../../../mol-data/generic';
 import { arrayFind } from '../../../mol-data/util';
 import { Structure } from '../../../mol-model/structure';
-import { StateTransform, StateTree, StateSelection, StateObjectRef, StateBuilder } from '../../../mol-state';
+import { PluginContext } from '../../../mol-plugin/context';
+import { StateBuilder, StateObjectRef, StateObjectSelector, StateSelection, StateTransform, StateTree } from '../../../mol-state';
 import { Task } from '../../../mol-task';
 import { isProductionMode } from '../../../mol-util/debug';
 import { objectForEach } from '../../../mol-util/object';
 import { ParamDefinition as PD } from '../../../mol-util/param-definition';
-import { PluginContext } from '../../../mol-plugin/context';
-import { PresetStructureReprentations } from './preset';
-import { StructureRepresentationProvider, RepresentationProviderTags } from './provider';
-import { UniqueArray } from '../../../mol-data/generic';
+import { createStructureRepresentationParams, StructureRepresentationBuiltInProps, StructureRepresentationProps } from '../../helpers/structure-representation-params';
 import { PluginStateObject } from '../../objects';
-import { StructureRepresentation3D, StructureRepresentation3DHelpers } from '../../transforms/representation';
-import { RepresentationProvider } from '../../../mol-repr/representation';
-import { SizeTheme, BuiltInSizeThemeName } from '../../../mol-theme/size';
-import { ColorTheme, BuiltInColorThemeName } from '../../../mol-theme/color';
-import { BuiltInStructureRepresentationsName } from '../../../mol-repr/structure/registry';
+import { StructureRepresentation3D } from '../../transforms/representation';
+import { PresetStructureReprentations } from './preset';
+import { RepresentationProviderTags, StructureRepresentationProvider } from './provider';
 
 export type StructureRepresentationProviderRef = keyof PresetStructureReprentations | StructureRepresentationProvider | string
 
@@ -143,13 +140,13 @@ export class StructureRepresentationBuilder {
         return this.plugin.runTask(task);
     }
 
-    async addRepresentation<R extends RepresentationProvider<Structure, any, any>, C extends ColorTheme.Provider<any>, S extends SizeTheme.Provider<any>>
-        (structure: StateObjectRef<PluginStateObject.Molecule.Structure>, props?: StructureRepresentation3DHelpers.Props<R, C, S>) {
-
+    async addRepresentation<P extends StructureRepresentationBuiltInProps>(structure: StateObjectRef<PluginStateObject.Molecule.Structure>, props?: P): Promise<StateObjectSelector<PluginStateObject.Molecule.Structure.Representation3D>>
+    async addRepresentation<P extends StructureRepresentationProps>(structure: StateObjectRef<PluginStateObject.Molecule.Structure>, props?: P): Promise<StateObjectSelector<PluginStateObject.Molecule.Structure.Representation3D>>
+    async addRepresentation(structure: StateObjectRef<PluginStateObject.Molecule.Structure>, props?: any) {
         const data = StateObjectRef.resolveAndCheck(this.dataState, structure)?.obj?.data;
         if (!data) return;
 
-        const params = StructureRepresentation3DHelpers.createParams(this.plugin, data, props);
+        const params = createStructureRepresentationParams(this.plugin, data, props);
         const repr = this.dataState.build()
             .to(structure)
             .apply(StructureRepresentation3D, params, { tags: RepresentationProviderTags.Representation });
@@ -158,14 +155,14 @@ export class StructureRepresentationBuilder {
         return  repr.selector;
     }
 
-    builtInRepresentation<R extends BuiltInStructureRepresentationsName, C extends BuiltInColorThemeName, S extends BuiltInSizeThemeName>
-        (builder: StateBuilder.Root, structure: StateObjectRef<PluginStateObject.Molecule.Structure> | undefined, props?: StructureRepresentation3DHelpers.BuildInProps<R, C, S>) {
-
+    async buildRepresentation<P extends StructureRepresentationBuiltInProps>(builder: StateBuilder.Root, structure: StateObjectRef<PluginStateObject.Molecule.Structure> | undefined, props?: P): Promise<StateObjectSelector<PluginStateObject.Molecule.Structure.Representation3D>>
+    async buildRepresentation<P extends StructureRepresentationProps>(builder: StateBuilder.Root, structure: StateObjectRef<PluginStateObject.Molecule.Structure> | undefined, props?: P): Promise<StateObjectSelector<PluginStateObject.Molecule.Structure.Representation3D>>
+    async buildRepresentation(builder: StateBuilder.Root, structure: StateObjectRef<PluginStateObject.Molecule.Structure> | undefined, props?: any) {
         if (!structure) return;
         const data = StateObjectRef.resolveAndCheck(this.dataState, structure)?.obj?.data;
         if (!data) return;
 
-        const params = StructureRepresentation3DHelpers.createBuiltInParams(this.plugin, data, props);
+        const params = createStructureRepresentationParams(this.plugin, data, props);
         return builder
             .to(structure)
             .apply(StructureRepresentation3D, params, { tags: RepresentationProviderTags.Representation })

+ 99 - 0
src/mol-plugin-state/helpers/structure-representation-params.ts

@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author David Sehnal <david.sehnal@gmail.com>
+ */
+
+import { Structure } from '../../mol-model/structure';
+import { PluginContext } from '../../mol-plugin/context';
+import { RepresentationProvider } from '../../mol-repr/representation';
+import { BuiltInStructureRepresentations, BuiltInStructureRepresentationsName } from '../../mol-repr/structure/registry'
+import { StateTransformer } from '../../mol-state';
+import { BuiltInColorThemeName, BuiltInColorThemes, ColorTheme } from '../../mol-theme/color';
+import { BuiltInSizeThemeName, BuiltInSizeThemes, SizeTheme } from '../../mol-theme/size';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
+import { StructureRepresentation3D } from '../transforms/representation';
+
+export interface StructureRepresentationBuiltInProps<
+    R extends BuiltInStructureRepresentationsName = BuiltInStructureRepresentationsName,
+    C extends BuiltInColorThemeName = BuiltInColorThemeName,
+    S extends BuiltInSizeThemeName = BuiltInSizeThemeName> {
+    /** Using any registered name will work, but code completion will break */
+    type?: R,
+    typeParams?: Partial<RepresentationProvider.ParamValues<BuiltInStructureRepresentations[R]>>,
+    /** Using any registered name will work, but code completion will break */
+    color?: C,
+    colorParams?: Partial<ColorTheme.ParamValues<BuiltInColorThemes[C]>>,
+    /** Using any registered name will work, but code completion will break */
+    size?: S,
+    sizeParams?: Partial<SizeTheme.ParamValues<BuiltInSizeThemes[S]>>
+}
+
+export interface StructureRepresentationProps<
+    R extends RepresentationProvider<Structure> = RepresentationProvider<Structure>,
+    C extends ColorTheme.Provider = ColorTheme.Provider,
+    S extends SizeTheme.Provider = SizeTheme.Provider> {
+    type?: R,
+    typeParams?: Partial<RepresentationProvider.ParamValues<R>>,
+    color?: C,
+    colorParams?: Partial<ColorTheme.ParamValues<C>>,
+    size?: S,
+    sizeParams?: Partial<SizeTheme.ParamValues<S>>
+}
+
+export function createStructureRepresentationParams
+    <R extends BuiltInStructureRepresentationsName, C extends BuiltInColorThemeName, S extends BuiltInSizeThemeName>
+    (ctx: PluginContext, structure?: Structure, props?: StructureRepresentationBuiltInProps<R, C, S>): StateTransformer.Params<StructureRepresentation3D>
+export function createStructureRepresentationParams
+    <R extends RepresentationProvider<Structure>, C extends ColorTheme.Provider, S extends SizeTheme.Provider>
+    (ctx: PluginContext, structure?: Structure, props?: StructureRepresentationProps<R, C, S>): StateTransformer.Params<StructureRepresentation3D> 
+export function createStructureRepresentationParams(ctx: PluginContext, structure?: Structure, props: any = {}): StateTransformer.Params<StructureRepresentation3D>  {
+    const p = props as StructureRepresentationBuiltInProps;
+    if (typeof p.type === 'string' || typeof p.color === 'string' || typeof p.size === 'string') return createParamsByName(ctx, structure || Structure.Empty, props);
+    return createParamsProvider(ctx, structure || Structure.Empty, props);
+}
+
+function createParamsByName(ctx: PluginContext, structure: Structure, props: StructureRepresentationBuiltInProps): StateTransformer.Params<StructureRepresentation3D> {
+    const typeProvider = (props.type && ctx.structureRepresentation.registry.get(props.type))
+        || ctx.structureRepresentation.registry.default.provider;
+    const colorProvider = (props.color && ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(props.color)) 
+        || ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(typeProvider.defaultColorTheme.name);
+    const sizeProvider = (props.size && ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(props.size))
+        || ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(typeProvider.defaultSizeTheme.name);
+
+    return createParamsProvider(ctx, structure, {
+        type: typeProvider,
+        typeParams: props.typeParams,
+        color: colorProvider,
+        colorParams: props.colorParams,
+        size: sizeProvider,
+        sizeParams: props.sizeParams
+    });
+}
+
+function createParamsProvider(ctx: PluginContext, structure: Structure, props: StructureRepresentationProps = {}): StateTransformer.Params<StructureRepresentation3D> {
+    const { themeCtx } = ctx.structureRepresentation
+    const themeDataCtx = { structure };
+    
+    const repr = props.type || ctx.structureRepresentation.registry.default.provider;
+    const reprDefaultParams = PD.getDefaultValues(repr.getParams(themeCtx, structure));
+    const reprParams = Object.assign(reprDefaultParams, props.typeParams);
+    
+    const color = props.color || themeCtx.colorThemeRegistry.get(repr.defaultColorTheme.name);
+    const colorName = themeCtx.colorThemeRegistry.getName(color);
+    const colorDefaultParams = PD.getDefaultValues(color.getParams(themeDataCtx));
+    if (colorName === repr.defaultColorTheme.name) Object.assign(colorDefaultParams, repr.defaultColorTheme.props);
+    const colorParams = Object.assign(colorDefaultParams, props.colorParams);
+
+    const size = props.size || themeCtx.sizeThemeRegistry.get(repr.defaultSizeTheme.name);
+    const sizeName = themeCtx.sizeThemeRegistry.getName(size);
+    const sizeDefaultParams = PD.getDefaultValues(size.getParams(themeDataCtx));
+    if (sizeName === repr.defaultSizeTheme.name) Object.assign(sizeDefaultParams, repr.defaultSizeTheme.props);
+    const sizeParams = Object.assign(sizeDefaultParams, props.sizeParams);
+
+    return ({
+        type: { name: ctx.structureRepresentation.registry.getName(repr), params: reprParams },
+        colorTheme: { name: colorName, params: colorParams },
+        sizeTheme: { name: sizeName, params: sizeParams }
+    });
+}

+ 2 - 100
src/mol-plugin-state/transforms/representation.ts

@@ -8,15 +8,12 @@
 import { Structure, StructureElement } from '../../mol-model/structure';
 import { VolumeData, VolumeIsoValue } from '../../mol-model/volume';
 import { PluginContext } from '../../mol-plugin/context';
-import { RepresentationProvider } from '../../mol-repr/representation';
-import { BuiltInStructureRepresentationsName, BuiltInStructureRepresentations } from '../../mol-repr/structure/registry';
-import { StructureParams } from '../../mol-repr/structure/representation';
 import { BuiltInVolumeRepresentationsName } from '../../mol-repr/volume/registry';
 import { VolumeParams } from '../../mol-repr/volume/representation';
 import { StateTransformer, StateObject } from '../../mol-state';
 import { Task } from '../../mol-task';
-import { BuiltInColorThemeName, BuiltInColorThemes, ColorTheme } from '../../mol-theme/color';
-import { BuiltInSizeThemeName, BuiltInSizeThemes, SizeTheme } from '../../mol-theme/size';
+import { BuiltInColorThemeName, ColorTheme } from '../../mol-theme/color';
+import { BuiltInSizeThemeName, SizeTheme } from '../../mol-theme/size';
 import { Theme } from '../../mol-theme/theme';
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { PluginStateObject as SO, PluginStateTransform } from '../objects';
@@ -39,7 +36,6 @@ import { DihedralParams, DihedralRepresentation } from '../../mol-repr/shape/loc
 import { ModelSymmetry } from '../../mol-model-formats/structure/property/symmetry';
 
 export { StructureRepresentation3D }
-export { StructureRepresentation3DHelpers }
 export { ExplodeStructureRepresentation3D }
 export { UnwindStructureAssemblyRepresentation3D }
 export { OverpaintStructureRepresentation3DFromScript }
@@ -48,100 +44,6 @@ export { TransparencyStructureRepresentation3DFromScript }
 export { TransparencyStructureRepresentation3DFromBundle }
 export { VolumeRepresentation3D }
 
-namespace StructureRepresentation3DHelpers {
-    export type BuildInProps<R extends BuiltInStructureRepresentationsName, C extends BuiltInColorThemeName, S extends BuiltInSizeThemeName> = {
-        type?: R,
-        typeParams?: Partial<RepresentationProvider.ParamValues<BuiltInStructureRepresentations[R]>>,
-        color?: C,
-        colorParams?: Partial<ColorTheme.ParamValues<BuiltInColorThemes[C]>>,
-        size?: S,
-        sizeParams?: Partial<SizeTheme.ParamValues<BuiltInSizeThemes[S]>>
-    }
-
-    export type Props<R extends RepresentationProvider<Structure, any, any> = any, C extends ColorTheme.Provider<any> = any, S extends SizeTheme.Provider<any> = any> = {
-        type?: R,
-        typeParams?: Partial<RepresentationProvider.ParamValues<R>>,
-        color?: C,
-        colorParams?: Partial<ColorTheme.ParamValues<C>>,
-        size?: S,
-        sizeParams?: Partial<SizeTheme.ParamValues<S>>
-    }
-
-    export function createBuiltInParams<R extends BuiltInStructureRepresentationsName, C extends BuiltInColorThemeName, S extends BuiltInSizeThemeName>(
-        ctx: PluginContext, structure: Structure, props: BuildInProps<R, C, S> = {}
-    ) {
-        const type = (props.type && ctx.structureRepresentation.registry.get(props.type))
-            || ctx.structureRepresentation.registry.default.provider;
-        const color = (props.color && ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(props.color)) 
-            || ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme.name);
-        const size = (props.size && ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(props.size))
-            || ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme.name);
-
-        const ps: Props = {
-            type: type,
-            typeParams: props.typeParams,
-            color,
-            colorParams: props.colorParams,
-            size,
-            sizeParams: props.sizeParams
-        };
-
-        return createParams(ctx, structure, ps);
-    }
-
-    export function createParams<R extends RepresentationProvider<Structure, any, any>, C extends ColorTheme.Provider<any>, S extends SizeTheme.Provider<any>>(
-        ctx: PluginContext, structure: Structure, props: Props<R, C, S> = {}): StateTransformer.Params<StructureRepresentation3D> {
-
-        const { themeCtx } = ctx.structureRepresentation
-        const themeDataCtx = { structure }
-
-        const repr = props.type || ctx.structureRepresentation.registry.default.provider;
-        const reprDefaultParams = PD.getDefaultValues(repr.getParams(themeCtx, structure));
-        const reprParams = { ...reprDefaultParams, ...props.typeParams };
-
-        const color = props.color || themeCtx.colorThemeRegistry.get(repr.defaultColorTheme.name);
-        const colorDefaultParams = { ...PD.getDefaultValues(color.getParams(themeDataCtx)), ...repr.defaultColorTheme.props }
-        const colorParams = { ...colorDefaultParams, ...props.colorParams };
-
-        const size = props.size || themeCtx.sizeThemeRegistry.get(repr.defaultSizeTheme.name);
-        const sizeDefaultParams = { ...PD.getDefaultValues(size.getParams(themeDataCtx)), ...repr.defaultSizeTheme.props }
-        const sizeParams = { ...sizeDefaultParams, ...props.sizeParams };
-
-        return ({
-            type: { name: ctx.structureRepresentation.registry.getName(repr), params: reprParams },
-            colorTheme: { name: themeCtx.colorThemeRegistry.getName(color), params: colorParams },
-            sizeTheme: { name: themeCtx.sizeThemeRegistry.getName(size), params: sizeParams }
-        })
-    }
-
-    export function getDefaultParamsWithTheme(ctx: PluginContext, reprName: BuiltInStructureRepresentationsName, colorName: BuiltInColorThemeName | undefined, structure: Structure, structureParams?: Partial<PD.Values<StructureParams>>): StateTransformer.Params<StructureRepresentation3D> {
-        const type = ctx.structureRepresentation.registry.get(reprName);
-
-        const themeDataCtx = { structure };
-        const color = colorName || type.defaultColorTheme.name;
-        const colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(color).getParams(themeDataCtx);
-        const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme.name).getParams(themeDataCtx)
-        const structureDefaultParams = PD.getDefaultValues(type.getParams(ctx.structureRepresentation.themeCtx, structure))
-        return ({
-            type: { name: reprName, params: structureParams ? { ...structureDefaultParams, ...structureParams } : structureDefaultParams },
-            colorTheme: { name: color, params: PD.getDefaultValues(colorParams) },
-            sizeTheme: { name: type.defaultSizeTheme.name, params: PD.getDefaultValues(sizeParams) }
-        })
-    }
-
-    export function getDefaultParamsStatic(ctx: PluginContext, name: BuiltInStructureRepresentationsName, structureParams?: Partial<PD.Values<StructureParams>>, colorName?: BuiltInColorThemeName): StateTransformer.Params<StructureRepresentation3D> {
-        const type = ctx.structureRepresentation.registry.get(name);
-        const color = colorName || type.defaultColorTheme.name;
-        const colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(color).defaultValues;
-        const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme.name).defaultValues
-        return ({
-            type: { name, params: structureParams ? { ...type.defaultValues, ...structureParams } : type.defaultValues },
-            colorTheme: { name: color, params: colorParams },
-            sizeTheme: { name: type.defaultSizeTheme.name, params: sizeParams }
-        })
-    }
-}
-
 type StructureRepresentation3D = typeof StructureRepresentation3D
 const StructureRepresentation3D = PluginStateTransform.BuiltIn({
     name: 'structure-representation-3d',

+ 16 - 18
src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts

@@ -5,23 +5,21 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { Structure, StructureElement, Bond } from '../../../../mol-model/structure';
-import { PluginBehavior } from '../../../../mol-plugin/behavior';
-import { PluginCommands } from '../../../commands';
+import { InteractionsRepresentationProvider } from '../../../../mol-model-props/computed/representations/interactions';
+import { InteractionTypeColorThemeProvider } from '../../../../mol-model-props/computed/themes/interaction-type';
+import { EmptyLoci, isEmptyLoci, Loci } from '../../../../mol-model/loci';
+import { Bond, Structure, StructureElement } from '../../../../mol-model/structure';
+import { createStructureRepresentationParams } from '../../../../mol-plugin-state/helpers/structure-representation-params';
 import { PluginStateObject } from '../../../../mol-plugin-state/objects';
 import { StateTransforms } from '../../../../mol-plugin-state/transforms';
-import { StructureRepresentation3DHelpers } from '../../../../mol-plugin-state/transforms/representation';
-import { BuiltInStructureRepresentations } from '../../../../mol-repr/structure/registry';
+import { PluginBehavior } from '../../../../mol-plugin/behavior';
 import { MolScriptBuilder as MS } from '../../../../mol-script/language/builder';
 import { StateObjectCell, StateSelection, StateTransform } from '../../../../mol-state';
-import { BuiltInColorThemes } from '../../../../mol-theme/color';
 import { BuiltInSizeThemes } from '../../../../mol-theme/size';
-import { ButtonsType, ModifiersKeys } from '../../../../mol-util/input/input-observer';
 import { Binding } from '../../../../mol-util/binding';
+import { ButtonsType, ModifiersKeys } from '../../../../mol-util/input/input-observer';
 import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
-import { isEmptyLoci, Loci, EmptyLoci } from '../../../../mol-model/loci';
-import { InteractionsRepresentationProvider } from '../../../../mol-model-props/computed/representations/interactions';
-import { InteractionTypeColorThemeProvider } from '../../../../mol-model-props/computed/themes/interaction-type';
+import { PluginCommands } from '../../../commands';
 
 const B = ButtonsType
 const M = ModifiersKeys
@@ -48,22 +46,22 @@ const TagSet: Set<StructureRepresentationInteractionTags> = new Set([StructureRe
 
 export class StructureRepresentationInteractionBehavior extends PluginBehavior.WithSubscribers<StructureRepresentationInteractionProps> {
     private createResVisualParams(s: Structure) {
-        return StructureRepresentation3DHelpers.createParams(this.plugin, s, {
-            type: BuiltInStructureRepresentations['ball-and-stick'],
-            size: BuiltInSizeThemes.uniform
+        return createStructureRepresentationParams(this.plugin, s, {
+            type: 'ball-and-stick',
+            size: 'uniform'
         });
     }
 
     private createSurVisualParams(s: Structure) {
-        return StructureRepresentation3DHelpers.createParams(this.plugin, s, {
-            type: BuiltInStructureRepresentations['ball-and-stick'],
-            color: BuiltInColorThemes['element-symbol'],
-            size: BuiltInSizeThemes.uniform
+        return createStructureRepresentationParams(this.plugin, s, {
+            type: 'ball-and-stick',
+            color: 'element-symbol',
+            size: 'uniform'
         });
     }
 
     private createSurNciVisualParams(s: Structure) {
-        return StructureRepresentation3DHelpers.createParams(this.plugin, s, {
+        return createStructureRepresentationParams(this.plugin, s, {
             type: InteractionsRepresentationProvider,
             color: InteractionTypeColorThemeProvider,
             size: BuiltInSizeThemes.uniform

+ 2 - 2
src/mol-repr/representation.ts

@@ -39,7 +39,7 @@ export type RepresentationFactory<D, P extends PD.Params, S extends Representati
 
 //
 
-export interface RepresentationProvider<D, P extends PD.Params, S extends Representation.State> {
+export interface RepresentationProvider<D = any, P extends PD.Params = any, S extends Representation.State = any> {
     readonly label: string
     readonly description: string
     readonly factory: RepresentationFactory<D, P, S>
@@ -92,7 +92,7 @@ export class RepresentationRegistry<D, S extends Representation.State> {
         this._name.set(provider, name)
     }
 
-    getName(provider: RepresentationProvider<D, any, S>): string {
+    getName(provider: RepresentationProvider<D, any, any>): string {
         if (!this._name.has(provider)) throw new Error(`'${provider.label}' is not a registered represenatation provider.`);
         return this._name.get(provider)!;
     }

+ 1 - 1
src/mol-theme/color.ts

@@ -70,7 +70,7 @@ namespace ColorTheme {
         return themeA.contextHash === themeB.contextHash && themeA.factory === themeB.factory && deepEqual(themeA.props, themeB.props)
     }
 
-    export interface Provider<P extends PD.Params> extends ThemeProvider<ColorTheme<P>, P> { }
+    export interface Provider<P extends PD.Params = any> extends ThemeProvider<ColorTheme<P>, P> { }
     export const EmptyProvider: Provider<{}> = { label: '', category: '', factory: EmptyFactory, getParams: () => ({}), defaultValues: {}, isApplicable: () => true }
 
     export type Registry = ThemeRegistry<ColorTheme<any>>

+ 1 - 1
src/mol-theme/size.ts

@@ -31,7 +31,7 @@ namespace SizeTheme {
         return themeA.factory === themeB.factory && deepEqual(themeA.props, themeB.props)
     }
 
-    export interface Provider<P extends PD.Params> extends ThemeProvider<SizeTheme<P>, P> { }
+    export interface Provider<P extends PD.Params = any> extends ThemeProvider<SizeTheme<P>, P> { }
     export const EmptyProvider: Provider<{}> = { label: '', category: '', factory: EmptyFactory, getParams: () => ({}), defaultValues: {}, isApplicable: () => true }
 
     export type Registry = ThemeRegistry<SizeTheme<any>>