Browse Source

reintroduce custom prop

JonStargaryen 4 years ago
parent
commit
99415ef290

+ 8 - 3
src/extensions/membrane-orientation/behavior.ts

@@ -7,7 +7,7 @@
 
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { StructureRepresentationPresetProvider, PresetStructureRepresentations } from '../../mol-plugin-state/builder/structure/representation-preset';
-import { MembraneOrientationProvider, MembraneOrientation } from './membrane-orientation';
+import { MembraneOrientationProvider, isTransmembrane } from './membrane-orientation';
 import { StateObjectRef, StateAction, StateTransformer, StateTransform } from '../../mol-state';
 import { Task } from '../../mol-task';
 import { PluginBehavior } from '../../mol-plugin/behavior';
@@ -15,6 +15,7 @@ import { MembraneOrientationRepresentationProvider, MembraneOrientationParams, M
 import { HydrophobicityColorThemeProvider } from '../../mol-theme/color/hydrophobicity';
 import { PluginStateObject, PluginStateTransform } from '../../mol-plugin-state/objects';
 import { PluginContext } from '../../mol-plugin/context';
+import { DefaultQueryRuntimeTable } from '../../mol-script/runtime/query/compiler';
 
 export const MembraneOrientationData = PluginBehavior.create<{ autoAttach: boolean }>({
     name: 'membrane-orientation-prop',
@@ -27,11 +28,13 @@ export const MembraneOrientationData = PluginBehavior.create<{ autoAttach: boole
         private provider = MembraneOrientationProvider
 
         register(): void {
+            DefaultQueryRuntimeTable.addCustomProp(this.provider.descriptor);
+
             this.ctx.state.data.actions.add(InitMembraneOrientation3D);
             this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach);
 
             this.ctx.representation.structure.registry.add(MembraneOrientationRepresentationProvider);
-            this.ctx.query.structure.registry.add(MembraneOrientation.isTransmembrane);
+            this.ctx.query.structure.registry.add(isTransmembrane);
 
             this.ctx.builders.structure.representation.registerPreset(MembraneOrientationPreset);
         }
@@ -44,11 +47,13 @@ export const MembraneOrientationData = PluginBehavior.create<{ autoAttach: boole
         }
 
         unregister() {
+            DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
+
             this.ctx.state.data.actions.remove(InitMembraneOrientation3D);
             this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
 
             this.ctx.representation.structure.registry.remove(MembraneOrientationRepresentationProvider);
-            this.ctx.query.structure.registry.remove(MembraneOrientation.isTransmembrane);
+            this.ctx.query.structure.registry.remove(isTransmembrane);
 
             this.ctx.builders.structure.representation.unregisterPreset(MembraneOrientationPreset);
         }

+ 30 - 32
src/extensions/membrane-orientation/membrane-orientation.ts

@@ -37,39 +37,37 @@ interface MembraneOrientation {
     readonly centroid: Vec3
 }
 
-namespace MembraneOrientation {
-    const pos = Vec3();
-    export const symbols = {
-        isTransmembrane: QuerySymbolRuntime.Dynamic(CustomPropSymbol('membrane-orientation', 'is-transmembrane', Type.Bool),
-            ctx => {
-                const structure = ctx.currentStructure;
-                const { x, y, z } = StructureProperties.atom;
-                if (!structure.isAtomic) return false;
-                const membraneOrientation = MembraneOrientationProvider.get(structure).value;
-                if (!membraneOrientation) return false;
-                Vec3.set(pos, x(ctx.element), y(ctx.element), z(ctx.element));
-                const { normalVector: normal, planePoint1: p1, planePoint2: p2 } = membraneOrientation!;
-                return isInMembranePlane(pos, normal, p1, p2);
-            })
-    };
+const pos = Vec3();
+export const MembraneOrientationSymbols = {
+    isTransmembrane: QuerySymbolRuntime.Dynamic(CustomPropSymbol('computed', 'membrane-orientation.is-transmembrane', Type.Bool),
+        ctx => {
+            const structure = ctx.currentStructure;
+            const { x, y, z } = StructureProperties.atom;
+            if (!structure.isAtomic) return false;
+            const membraneOrientation = MembraneOrientationProvider.get(structure).value;
+            if (!membraneOrientation) return false;
+            Vec3.set(pos, x(ctx.element), y(ctx.element), z(ctx.element));
+            const { normalVector, planePoint1, planePoint2 } = membraneOrientation!;
+            return isInMembranePlane(pos, normalVector, planePoint1, planePoint2);
+        })
+}
 
-    export const isTransmembrane = StructureSelectionQuery('Residues Embedded in Membrane', MS.struct.modifier.union([
-        MS.struct.modifier.wholeResidues([
-            MS.struct.modifier.union([
-                MS.struct.generator.atomGroups({
-                    'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']),
-                    'atom-test': symbols.isTransmembrane.symbol(),
-                })
-            ])
+export const isTransmembrane = StructureSelectionQuery('Residues Embedded in Membrane', MS.struct.modifier.union([
+    MS.struct.modifier.wholeResidues([
+        MS.struct.modifier.union([
+            MS.struct.generator.atomGroups({
+                'chain-test': MS.core.rel.eq([MS.ammp('objectPrimitive'), 'atomistic']),
+                'atom-test': MembraneOrientationSymbols.isTransmembrane.symbol(),
+            })
         ])
-    ]), {
-        description: 'Select residues that are embedded between the membrane layers.',
-        category: StructureSelectionCategory.Residue,
-        ensureCustomProperties: (ctx, structure) => {
-            return MembraneOrientationProvider.attach(ctx, structure);
-        }
-    });
-}
+    ])
+]), {
+    description: 'Select residues that are embedded between the membrane layers.',
+    category: StructureSelectionCategory.Residue,
+    ensureCustomProperties: (ctx, structure) => {
+        return MembraneOrientationProvider.attach(ctx, structure);
+    }
+});
 
 export { MembraneOrientation };
 
@@ -77,7 +75,7 @@ export const MembraneOrientationProvider: CustomStructureProperty.Provider<Membr
     label: 'Membrane Orientation',
     descriptor: CustomPropertyDescriptor({
         name: 'molstar_computed_membrane_orientation',
-        symbols: MembraneOrientation.symbols
+        symbols: MembraneOrientationSymbols,
         // TODO `cifExport`
     }),
     type: 'root',