Browse Source

structure builder tweaks

David Sehnal 5 years ago
parent
commit
4375cae70d

+ 9 - 1
src/mol-plugin-state/builder/structure.ts

@@ -9,7 +9,7 @@ import { StateObjectRef, StateObjectSelector, StateTransformer } from '../../mol
 import { PluginStateObject as SO } from '../objects';
 import { StateTransforms } from '../transforms';
 import { RootStructureDefinition } from '../helpers/root-structure';
-import { StructureComponentParams } from '../helpers/structure-component';
+import { StructureComponentParams, StaticStructureComponentType } from '../helpers/structure-component';
 import { BuildInTrajectoryFormat, TrajectoryFormatProvider } from '../formats/trajectory';
 import { StructureRepresentationBuilder } from './structure/representation';
 import { StructureSelectionQuery } from '../helpers/structure-selection-query';
@@ -153,6 +153,14 @@ export class StructureBuilder {
         return selector;
     }
 
+    tryCreateStaticComponent(params: { structure: StateObjectRef<SO.Molecule.Structure>, type: StaticStructureComponentType, key: string, label?: string, tags?: string[] }) { 
+        return this.tryCreateComponent(params.structure, {
+            type: { name: 'static', params: params.type },
+            nullIfEmpty: true,
+            label: ''
+        }, params.key, params.tags);
+    }
+
     tryCreateQueryComponent(params: { structure: StateObjectRef<SO.Molecule.Structure>, query: StructureSelectionQuery, key: string, label?: string, tags?: string[] }): Promise<StateObjectRef<SO.Molecule.Structure> | undefined> {
         return this.plugin.runTask(Task.create('Query Component', async taskCtx => {
             let { structure, query, key, label, tags } = params;        

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

@@ -45,12 +45,12 @@ const polymerAndLigand = StructureRepresentationProvider({
         const reprTags = [this.id, RepresentationProviderTags.Representation];
 
         const components = {
-            polymer: await staticComponent(plugin, structureCell, 'polymer'),
-            ligand: await staticComponent(plugin, structureCell, 'ligand'),
-            nonStandard: await staticComponent(plugin, structureCell, 'non-standard'),
-            branched: await staticComponent(plugin, structureCell, 'branched'),
-            water: await staticComponent(plugin, structureCell, 'water'),
-            coarse: await staticComponent(plugin, structureCell, 'coarse')
+            polymer: await presetStaticComponent(plugin, structureCell, 'polymer'),
+            ligand: await presetStaticComponent(plugin, structureCell, 'ligand'),
+            nonStandard: await presetStaticComponent(plugin, structureCell, 'non-standard'),
+            branched: await presetStaticComponent(plugin, structureCell, 'branched'),
+            water: await presetStaticComponent(plugin, structureCell, 'water'),
+            coarse: await presetStaticComponent(plugin, structureCell, 'coarse')
         };
 
         const builder = state.build();
@@ -89,8 +89,8 @@ const proteinAndNucleic = StructureRepresentationProvider({
         const reprTags = [this.id, RepresentationProviderTags.Representation];
 
         const components = {
-            protein: await selectionComponent(plugin, structureCell, 'protein'),
-            nucleic: await selectionComponent(plugin, structureCell, 'nucleic'),
+            protein: await presetSelectionComponent(plugin, structureCell, 'protein'),
+            nucleic: await presetSelectionComponent(plugin, structureCell, 'nucleic'),
         };
 
         const builder = state.build();
@@ -124,14 +124,14 @@ const coarseSurface = StructureRepresentationProvider({
                 smoothness: 0.5,
                 visuals: ['structure-gaussian-surface-mesh']
             })
-            components.trace = await selectionComponent(plugin, structureCell, 'trace')
+            components.trace = await presetSelectionComponent(plugin, structureCell, 'trace')
         } else if(size === Structure.Size.Huge) {
             Object.assign(gaussianProps, {
                 smoothness: 0.5,
             })
-            components.trace = await selectionComponent(plugin, structureCell, 'polymer')
+            components.trace = await presetSelectionComponent(plugin, structureCell, 'polymer')
         } else {
-            components.trace = await selectionComponent(plugin, structureCell, 'polymer')
+            components.trace = await presetSelectionComponent(plugin, structureCell, 'polymer')
         }
 
         const params = StructureRepresentation3DHelpers.createParams(plugin, structure, {
@@ -163,7 +163,7 @@ const polymerCartoon = StructureRepresentationProvider({
         const reprTags = [this.id, RepresentationProviderTags.Representation];
 
         const components = {
-            polymer: await selectionComponent(plugin, structureCell, 'polymer'),
+            polymer: await presetSelectionComponent(plugin, structureCell, 'polymer'),
         };
 
         const builder = state.build();
@@ -186,7 +186,7 @@ const atomicDetail = StructureRepresentationProvider({
         const reprTags = [this.id, RepresentationProviderTags.Representation];
 
         const components = {
-            all: await selectionComponent(plugin, structureCell, 'all'),
+            all: await presetSelectionComponent(plugin, structureCell, 'all'),
         };
 
         const builder = state.build();
@@ -201,20 +201,22 @@ const atomicDetail = StructureRepresentationProvider({
     }
 });
 
-function staticComponent(plugin: PluginContext, structure: StateObjectRef<PluginStateObject.Molecule.Structure>, type: StaticStructureComponentType) {
-    return plugin.builders.structure.tryCreateComponent(structure, {
-        type: { name: 'static', params: type },
-        nullIfEmpty: true,
-        label: ''
-    }, `static-${type}`, [RepresentationProviderTags.Component]);
+export function presetStaticComponent(plugin: PluginContext, structure: StateObjectRef<PluginStateObject.Molecule.Structure>, type: StaticStructureComponentType) {
+    return plugin.builders.structure.tryCreateStaticComponent({
+        structure,
+        type,
+        key: `static-${type}`,
+        tags: [RepresentationProviderTags.Component]
+    });
 }
 
-function selectionComponent(plugin: PluginContext, structure: StateObjectRef<PluginStateObject.Molecule.Structure>, query: keyof typeof Q) {
-    return plugin.builders.structure.tryCreateComponent(structure, {
-        type: { name: 'expression', params: Q[query].expression },
-        nullIfEmpty: true,
-        label: Q[query].label
-    }, `selection-${query}`, [RepresentationProviderTags.Component]);
+export function presetSelectionComponent(plugin: PluginContext, structure: StateObjectRef<PluginStateObject.Molecule.Structure>, query: keyof typeof Q) {
+    return plugin.builders.structure.tryCreateQueryComponent({ 
+        structure,
+        query: Q[query],
+        key: `selection-${query}`,
+        tags: [RepresentationProviderTags.Component]
+    });
 }
 
 export const PresetStructureReprentations = {