Ver Fonte

membrane orientation behavior

JonStargaryen há 4 anos atrás
pai
commit
3f80230f4f

+ 124 - 0
src/extensions/membrane-orientation/behavior.ts

@@ -0,0 +1,124 @@
+/**
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
+ */
+
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
+import { StructureRepresentationPresetProvider, PresetStructureRepresentations } from '../../mol-plugin-state/builder/structure/representation-preset';
+import { MembraneOrientationProvider } from '../../mol-model-props/computed/membrane-orientation';
+import { StateObjectRef } from '../../mol-state';
+import { Task } from '../../mol-task';
+import { AccessibleSurfaceAreaColorThemeProvider } from '../../mol-model-props/computed/themes/accessible-surface-area';
+import { PluginBehavior } from '../../mol-plugin/behavior';
+import { StructureSelectionQuery, StructureSelectionCategory } from '../../mol-plugin-state/helpers/structure-selection-query';
+import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
+import { DefaultQueryRuntimeTable, QuerySymbolRuntime } from '../../mol-script/runtime/query/base';
+import { MembraneOrientationRepresentationProvider } from './representation';
+import { CustomPropSymbol } from '../../mol-script/language/symbol';
+import Type from '../../mol-script/language/type';
+import { isInMembranePlane } from '../../mol-model-props/computed/membrane-orientation/ANVIL';
+import { StructureProperties } from '../../mol-model/structure';
+import { Vec3 } from '../../mol-math/linear-algebra';
+
+export const MembraneOrientationData = PluginBehavior.create<{ autoAttach: boolean }>({
+    name: 'membrane-orientation-prop',
+    category: 'custom-props',
+    display: {
+        name: 'Membrane Orientation',
+        description: 'Initialize orientation of membrane layers. Data calculated with ANVIL algorithm.' // TODO add ' or obtained via RCSB PDB'
+    },
+    ctor: class extends PluginBehavior.Handler<{ autoAttach: boolean }> {
+        private provider = MembraneOrientationProvider
+
+        register(): void {
+            DefaultQueryRuntimeTable.addCustomProp(this.provider.descriptor);
+
+            this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach);
+
+            this.ctx.representation.structure.themes.colorThemeRegistry.add(AccessibleSurfaceAreaColorThemeProvider);
+
+            this.ctx.representation.structure.registry.add(MembraneOrientationRepresentationProvider);
+            this.ctx.query.structure.registry.add(isTransmembrane);
+
+            this.ctx.builders.structure.representation.registerPreset(MembraneOrientationPreset);
+        }
+
+        update(p: { autoAttach: boolean }) {
+            let updated = this.params.autoAttach !== p.autoAttach;
+            this.params.autoAttach = p.autoAttach;
+            this.ctx.customStructureProperties.setDefaultAutoAttach(this.provider.descriptor.name, this.params.autoAttach);
+            return updated;
+        }
+
+        unregister() {
+            DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
+            this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
+
+            this.ctx.representation.structure.themes.colorThemeRegistry.remove(AccessibleSurfaceAreaColorThemeProvider);
+
+            this.ctx.representation.structure.registry.remove(MembraneOrientationRepresentationProvider);
+            this.ctx.query.structure.registry.remove(isTransmembrane);
+
+            this.ctx.builders.structure.representation.unregisterPreset(MembraneOrientationPreset);
+        }
+    },
+    params: () => ({
+        autoAttach: PD.Boolean(false)
+    })
+});
+
+const pos = Vec3();
+const isTransmembraneSymbol = QuerySymbolRuntime.Dynamic(CustomPropSymbol('membrane-orientation', 'is-transmembrane', Type.Bool),
+    ctx => {
+        const structure = ctx.currentStructure;
+        const { x, y, z } = StructureProperties.atom;
+        if (!structure.isAtomic) return 0;
+        const membraneOrientation = MembraneOrientationProvider.get(structure).value;
+        if (!membraneOrientation) return false;
+        Vec3.set(pos, x(ctx.element), y(ctx.element), z(ctx.element));
+        const { normal, p1, p2 } = membraneOrientation!;
+        return isInMembranePlane(pos, normal, p1, p2);
+    });
+
+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': isTransmembraneSymbol.symbol(),
+            })
+        ])
+    ])
+]), {
+    description: 'Select residues that are embedded between the membrane layers.',
+    category: StructureSelectionCategory.Residue,
+    ensureCustomProperties: (ctx, structure) => {
+        return MembraneOrientationProvider.attach(ctx, structure);
+    }
+});
+
+export const MembraneOrientationPreset = StructureRepresentationPresetProvider({
+    id: 'preset-membrane-orientation',
+    display: {
+        name: 'Membrane Orientation', group: 'Annotation',
+        description: 'Initialize orientation of membrane layers. Data calculated with ANVIL algorithm.' // TODO add ' or obtained via RCSB PDB'
+    },
+    isApplicable(a) {
+        return MembraneOrientationProvider.isApplicable(a.data);
+    },
+    params: () => StructureRepresentationPresetProvider.CommonParams,
+    async apply(ref, params, plugin) {
+        const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref);
+        const structure  = structureCell?.obj?.data;
+        if (!structureCell || !structure) return {};
+
+        await plugin.runTask(Task.create('Membrane Orientation', async runtime => {
+            await MembraneOrientationProvider.attach({ runtime, assetManager: plugin.managers.asset }, structure);
+        }));
+
+        const colorTheme = AccessibleSurfaceAreaColorThemeProvider.name as any;
+        return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme }, plugin);
+    }
+});

+ 1 - 1
src/extensions/membrane-orientation/representation.ts

@@ -52,7 +52,7 @@ const BilayerRimsParams = {
     ...SharedParams,
     ...Lines.Params,
     lineSizeAttenuation: PD.Boolean(true),
-    linesSize: PD.Numeric(1, { min: 0.01, max: 50, step: 0.01 }),
+    linesSize: PD.Numeric(0.5, { min: 0.01, max: 50, step: 0.01 }),
     dashedLines: PD.Boolean(true)
 };
 export type BilayerRimsParams = typeof BilayerRimsParams

+ 2 - 2
src/mol-model-props/computed/membrane-orientation.ts

@@ -15,7 +15,7 @@ import { AccessibleSurfaceAreaProvider } from './accessible-surface-area';
 import { MembraneOrientation } from '../../mol-model/structure/model/properties/membrane-orientation';
 
 function getMembraneOrientationParams(data?: Structure) {
-    let defaultType = 'anvil' as 'anvil' | 'db'; // TODO flip - OPM (or some other db-source) should be default if PDB identifier is known
+    let defaultType = 'anvil' as 'anvil' | 'db'; // TODO flip - db should be default if PDB identifier is known
     return {
         type: PD.MappedStatic(defaultType, {
             'db': PD.EmptyGroup({ label: 'DB' }),
@@ -42,7 +42,7 @@ export const MembraneOrientationProvider: CustomStructureProperty.Provider<Membr
         const p = { ...PD.getDefaultValues(MembraneOrientationParams), ...props };
         switch (p.type.name) {
             case 'anvil': return { value: await computeAnvil(ctx, data, p.type.params) };
-            case 'db': throw Error('TODO impl');
+            case 'db': throw Error('TODO impl'); // TODO RCSB integration
         }
     }
 });

+ 1 - 1
src/mol-model-props/computed/membrane-orientation/ANVIL.ts

@@ -241,7 +241,7 @@ function qValue(currentStats: HphobHphil, initialStats: HphobHphil): number {
             Math.sqrt(part_tot * initialStats.hphob * initialStats.hphil * (initialStats.hphob + initialStats.hphil - part_tot));
 }
 
-function isInMembranePlane(testPoint: Vec3, normalVector: Vec3, planePoint1: Vec3, planePoint2: Vec3): boolean {
+export function isInMembranePlane(testPoint: Vec3, normalVector: Vec3, planePoint1: Vec3, planePoint2: Vec3): boolean {
     const d1 = -Vec3.dot(normalVector, planePoint1);
     const d2 = -Vec3.dot(normalVector, planePoint2);
     const d = -Vec3.dot(normalVector, testPoint);