JonStargaryen %!s(int64=4) %!d(string=hai) anos
pai
achega
9d0190c11c

+ 4 - 4
src/extensions/membrane-orientation/behavior.ts

@@ -10,7 +10,6 @@ import { StructureRepresentationPresetProvider, PresetStructureRepresentations }
 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';
@@ -21,6 +20,7 @@ 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';
+import { HydrophobicityColorThemeProvider } from '../../mol-theme/color/hydrophobicity';
 
 export const MembraneOrientationData = PluginBehavior.create<{ autoAttach: boolean }>({
     name: 'membrane-orientation-prop',
@@ -37,7 +37,7 @@ export const MembraneOrientationData = PluginBehavior.create<{ autoAttach: boole
 
             this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach);
 
-            this.ctx.representation.structure.themes.colorThemeRegistry.add(AccessibleSurfaceAreaColorThemeProvider);
+            this.ctx.representation.structure.themes.colorThemeRegistry.add(HydrophobicityColorThemeProvider);
 
             this.ctx.representation.structure.registry.add(MembraneOrientationRepresentationProvider);
             this.ctx.query.structure.registry.add(isTransmembrane);
@@ -56,7 +56,7 @@ export const MembraneOrientationData = PluginBehavior.create<{ autoAttach: boole
             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.themes.colorThemeRegistry.remove(HydrophobicityColorThemeProvider);
 
             this.ctx.representation.structure.registry.remove(MembraneOrientationRepresentationProvider);
             this.ctx.query.structure.registry.remove(isTransmembrane);
@@ -118,7 +118,7 @@ export const MembraneOrientationPreset = StructureRepresentationPresetProvider({
             await MembraneOrientationProvider.attach({ runtime, assetManager: plugin.managers.asset }, structure);
         }));
 
-        const colorTheme = AccessibleSurfaceAreaColorThemeProvider.name as any;
+        const colorTheme = HydrophobicityColorThemeProvider.name as any;
         return await PresetStructureRepresentations.auto.apply(ref, { ...params, globalThemeName: colorTheme }, plugin);
     }
 });

+ 63 - 0
src/extensions/membrane-orientation/color.ts

@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 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 { ThemeDataContext } from '../../mol-theme/theme';
+import { ColorTheme, LocationColor } from '../../mol-theme/color';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
+import { Color } from '../../mol-util/color';
+import { TableLegend } from '../../mol-util/legend';
+import { StructureElement, Unit, StructureProperties } from '../../mol-model/structure';
+import { isHydrophobic } from '../../mol-model-props/computed/membrane-orientation/ANVIL';
+import { Location } from '../../mol-model/location';
+
+const DefaultColor = Color(0x909090);
+
+const HydrophobicColor = Color(0x2166ac);
+const HydrophilicColor = Color(0xfee08b);
+
+const ColorLegend = TableLegend([
+    ['Data unavailable', DefaultColor],
+    ['Hydrophobic', HydrophobicColor],
+    ['Hydrophilic', HydrophilicColor],
+]);
+
+export function HydrophobicityColorTheme(ctx: ThemeDataContext, props: {}): ColorTheme<{}> {
+    let color: LocationColor = () => DefaultColor;
+    const { label_comp_id } = StructureProperties.residue;
+
+    if (ctx.structure) {
+        color = (location: Location): Color => {
+            if (StructureElement.Location.is(location) && Unit.isAtomic(location.unit)) {
+                if (isHydrophobic(label_comp_id(location))) {
+                    return HydrophobicColor;
+                } else {
+                    return HydrophilicColor;
+                }
+            }
+            return DefaultColor;
+        };
+    }
+
+    return {
+        factory: HydrophobicityColorTheme,
+        granularity: 'group',
+        color,
+        props,
+        description: 'Assigns residue colors according to their hydrophobicity.',
+        legend: ColorLegend
+    };
+}
+
+export const HydrophobicityColorThemeProvider: ColorTheme.Provider<{}, 'hydrophobicity'> = {
+    name: 'hydrophobicity',
+    label: 'Hydrophobicity',
+    category: ColorTheme.Category.Residue,
+    factory: HydrophobicityColorTheme,
+    getParams: () => ({}),
+    defaultValues: PD.getDefaultValues({}),
+    isApplicable: (ctx: ThemeDataContext) => !!ctx.structure
+};

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

@@ -333,12 +333,12 @@ namespace HphobHphil {
         }
         return of(hphob, hphil);
     }
+}
 
-    // ANVIL-specific (not general) definition of membrane-favoring amino acids
-    const HYDROPHOBIC_AMINO_ACIDS = new Set(['ALA', 'CYS', 'GLY', 'HIS', 'ILE', 'LEU', 'MET', 'PHE', 'SER', 'THR', 'VAL']);
-    function isHydrophobic(label_comp_id: string): boolean {
-        return HYDROPHOBIC_AMINO_ACIDS.has(label_comp_id);
-    }
+// ANVIL-specific (not general) definition of membrane-favoring amino acids
+const HYDROPHOBIC_AMINO_ACIDS = new Set(['ALA', 'CYS', 'GLY', 'HIS', 'ILE', 'LEU', 'MET', 'PHE', 'SER', 'THR', 'VAL']);
+export function isHydrophobic(label_comp_id: string): boolean {
+    return HYDROPHOBIC_AMINO_ACIDS.has(label_comp_id);
 }
 
 function setLocation(l: StructureElement.Location, structure: Structure, serialIndex: number) {