Przeglądaj źródła

Add a preset for DNATCO Confal Pyramids representation

Michal Malý 4 lat temu
rodzic
commit
7898840003
1 zmienionych plików z 41 dodań i 1 usunięć
  1. 41 1
      src/extensions/dnatco/confal-pyramids/behavior.ts

+ 41 - 1
src/extensions/dnatco/confal-pyramids/behavior.ts

@@ -6,12 +6,48 @@
  */
 
 import { ConfalPyramidsColorThemeProvider } from './color';
-import { ConfalPyramidsProvider } from './property';
+import { ConfalPyramids, ConfalPyramidsProvider } from './property';
 import { ConfalPyramidsRepresentationProvider } from './representation';
 import { Loci } from '../../../mol-model/loci';
 import { PluginBehavior } from '../../../mol-plugin/behavior/behavior';
+import { StructureRepresentationPresetProvider, PresetStructureRepresentations } from '../../../mol-plugin-state/builder/structure/representation-preset';
+import { StateObjectRef } from '../../../mol-state';
+import { Task } from '../../../mol-task';
 import { ParamDefinition as PD } from '../../../mol-util/param-definition';
 
+export const DnatcoConfalPyramidsPreset = StructureRepresentationPresetProvider({
+    id: 'preset-structure-representation-confal-pyramids',
+    display: {
+        name: 'Confal Pyramids',
+        description: 'Schematic depiction of conformer class and confal value.',
+    },
+    isApplicable(a) {
+        return a.data.models.length >= 1 && a.data.models.some(m => ConfalPyramids.isApplicable(m));
+    },
+    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 {};
+
+        await plugin.runTask(Task.create('Confal Pyramids', async runtime => {
+            await ConfalPyramidsProvider.attach({ runtime, assetManager: plugin.managers.asset }, model);
+        }));
+
+        const { components, representations } = await PresetStructureRepresentations.auto.apply(ref, { ...params }, plugin);
+
+        const pyramids = await plugin.builders.structure.tryCreateComponentStatic(structureCell, 'nucleic', { label: 'Confal Pyramids' });
+        const { update, builder, typeParams } = StructureRepresentationPresetProvider.reprBuilder(plugin, params);
+
+        let pyramidsRepr;
+        if (representations)
+            pyramidsRepr = builder.buildRepresentation(update, pyramids,  { type: ConfalPyramidsRepresentationProvider, typeParams, color: ConfalPyramidsColorThemeProvider }, { tag: 'confal-pyramdis' } );
+
+        await update.commit({ revertOnError: true });
+        return  { components: { ...components, pyramids }, representations: { ...representations, pyramidsRepr } };
+    }
+});
+
 export const DnatcoConfalPyramids = PluginBehavior.create<{ autoAttach: boolean, showToolTip: boolean }>({
     name: 'dnatco-confal-pyramids-prop',
     category: 'custom-props',
@@ -38,6 +74,8 @@ export const DnatcoConfalPyramids = PluginBehavior.create<{ autoAttach: boolean,
 
             this.ctx.representation.structure.themes.colorThemeRegistry.add(ConfalPyramidsColorThemeProvider);
             this.ctx.representation.structure.registry.add(ConfalPyramidsRepresentationProvider);
+
+            this.ctx.builders.structure.representation.registerPreset(DnatcoConfalPyramidsPreset);
         }
 
         update(p: { autoAttach: boolean, showToolTip: boolean }) {
@@ -54,6 +92,8 @@ export const DnatcoConfalPyramids = PluginBehavior.create<{ autoAttach: boolean,
 
             this.ctx.representation.structure.registry.remove(ConfalPyramidsRepresentationProvider);
             this.ctx.representation.structure.themes.colorThemeRegistry.remove(ConfalPyramidsColorThemeProvider);
+
+            this.ctx.builders.structure.representation.unregisterPreset(DnatcoConfalPyramidsPreset);
         }
     },
     params: () => ({