Browse Source

tweak logic

Sebastian Bittrich 2 years ago
parent
commit
bb108f5e21

+ 5 - 10
src/viewer/helpers/rscc/behavior.ts

@@ -8,10 +8,9 @@ import {
     PresetStructureRepresentations,
     StructureRepresentationPresetProvider
 } from 'molstar/lib/mol-plugin-state/builder/structure/representation-preset';
-import { ValidationReport, ValidationReportProvider } from 'molstar/lib/extensions/rcsb/validation-report/prop';
+import { ValidationReport } from 'molstar/lib/extensions/rcsb/validation-report/prop';
 import { Model } from 'molstar/lib/mol-model/structure/model';
 import { StateObjectRef } from 'molstar/lib/mol-state';
-import { Task } from 'molstar/lib/mol-task';
 import { RSCCColorThemeProvider } from './color';
 import { PluginBehavior } from 'molstar/lib/mol-plugin/behavior/behavior';
 import { RSCC, RSCCProvider } from './prop';
@@ -20,7 +19,7 @@ import { StructureElement } from 'molstar/lib/mol-model/structure/structure';
 import { OrderedSet } from 'molstar/lib/mol-data/int';
 import { ParamDefinition as PD } from 'molstar/lib/mol-util/param-definition';
 
-export const ValidationReportRSCCPreset = StructureRepresentationPresetProvider({
+export const RSCCPreset = StructureRepresentationPresetProvider({
     id: 'preset-structure-representation-rcsb-validation-report-rscc',
     display: {
         name: 'Validation Report (RSCC)', group: 'Annotation',
@@ -35,12 +34,6 @@ export const ValidationReportRSCCPreset = StructureRepresentationPresetProvider(
         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 }, structure.models[0]);
-        }));
-
-        if (!ValidationReportProvider.get(structure.models[0]).value?.rscc || ValidationReportProvider.get(structure.models[0]).value?.rscc.size === 0) throw Error('No RSCC available');
-
         const colorTheme = RSCCColorThemeProvider.name as any;
         return PresetStructureRepresentations.auto.apply(ref, { ...params, theme: { globalName: colorTheme, focus: { name: colorTheme } } }, plugin);
     }
@@ -81,6 +74,7 @@ export const RSCCScore = PluginBehavior.create<{ autoAttach: boolean, showToolti
             this.ctx.managers.lociLabels.addProvider(this.labelProvider);
 
             this.ctx.representation.structure.themes.colorThemeRegistry.add(RSCCColorThemeProvider);
+            this.ctx.builders.structure.representation.registerPreset(RSCCPreset);
         }
 
         update(p: { autoAttach: boolean, showTooltip: boolean }) {
@@ -92,9 +86,10 @@ export const RSCCScore = PluginBehavior.create<{ autoAttach: boolean, showToolti
         }
 
         unregister() {
-            this.ctx.customModelProperties.unregister(RSCCProvider.descriptor.name);
+            this.ctx.customModelProperties.unregister(this.provider.descriptor.name);
             this.ctx.managers.lociLabels.removeProvider(this.labelProvider);
             this.ctx.representation.structure.themes.colorThemeRegistry.remove(RSCCColorThemeProvider);
+            this.ctx.builders.structure.representation.unregisterPreset(RSCCPreset);
         }
     },
     params: () => ({

+ 4 - 3
src/viewer/helpers/rscc/prop.ts

@@ -21,8 +21,6 @@ export type RSCC = PropertyWrapper<{
 }>
 
 export namespace RSCC {
-    import createInfo = PropertyWrapper.createInfo;
-
     export function getScore(e: StructureElement.Location): [number, string] {
         if (!Unit.isAtomic(e.unit)) return [-1, 'No Score'];
         const prop = RSCCProvider.get(e.unit.model).value;
@@ -44,7 +42,7 @@ export namespace RSCC {
     }
 
     export async function obtain(ctx: CustomProperty.Context, model: Model, props: RSCCProps): Promise<CustomProperty.Data<any>> {
-        return { value: { info: createInfo(), data: await _obtain(ctx, model, props) } };
+        return { value: { info: PropertyWrapper.createInfo(), data: await _obtain(ctx, model, props) } };
     }
 
     async function _obtain(ctx: CustomProperty.Context, model: Model, _props: RSCCProps): Promise<RSCC['data'] | undefined> {
@@ -111,6 +109,9 @@ export const RSCCProvider: CustomModelProperty.Provider<RSCCParams, RSCC> = Cust
     getParams: () => RSCCParams,
     isApplicable: (data: Model) => RSCC.isApplicable(data),
     obtain: async (ctx: CustomProperty.Context, data: Model, props: Partial<RSCCProps>) => {
+        await ValidationReportProvider.attach(ctx, data);
+        if (!ValidationReportProvider.get(data).value?.rscc || ValidationReportProvider.get(data).value?.rscc.size === 0) throw Error('No RSCC available');
+
         const p = { ...PD.getDefaultValues(RSCCParams), ...props };
         return await RSCC.obtain(ctx, data, p);
     }

+ 3 - 3
src/viewer/ui/validation.tsx

@@ -8,7 +8,7 @@ import { CollapsableControls, CollapsableState } from 'molstar/lib/mol-plugin-ui
 import { StructureHierarchyManager } from 'molstar/lib/mol-plugin-state/manager/structure/hierarchy';
 import { ValidationReport } from 'molstar/lib/extensions/rcsb/validation-report/prop';
 import { ValidationReportGeometryQualityPreset } from 'molstar/lib/extensions/rcsb/validation-report/behavior';
-import { ValidationReportRSCCPreset } from '../helpers/rscc/behavior';
+import { RSCCPreset } from '../helpers/rscc/behavior';
 import { ActionMenu } from 'molstar/lib/mol-plugin-ui/controls/action-menu';
 import { Model } from 'molstar/lib/mol-model/structure/model';
 import { MmcifFormat } from 'molstar/lib/mol-model-formats/structure/mmcif';
@@ -120,7 +120,7 @@ export class ValidationReportControls extends CollapsableControls<{}, Validation
 
     requestRSCCPreset = async () => {
         try {
-            await ValidationReportRSCCPreset.apply(this.pivot.cell, Object.create(null), this.plugin);
+            await RSCCPreset.apply(this.pivot.cell, Object.create(null), this.plugin);
         } catch (err) {
             // happens e.g. for 4HHB
             this.setState(({ errorStates }) => {
@@ -155,7 +155,7 @@ export class ValidationReportControls extends CollapsableControls<{}, Validation
         if (this.rsccData) {
             out.push({
                 kind: 'item',
-                label: rsccReportError || validationReportError ? 'Failed to Obtain RSCC Values' : (noValidationReport ? 'No RSCC Values Available' : 'Real Space Correlation Coefficient (RSCC)'),
+                label: rsccReportError || validationReportError ? 'Failed to Obtain RSCC Values' : (noValidationReport ? 'No RSCC Values Available' : 'Real-Space Correlation Coefficient (RSCC)'),
                 value: this.requestRSCCPreset,
                 disabled: noValidationReport || validationReportError || rsccReportError
             });