Bladeren bron

accessible surface area improvements

- added mol-script symbols
- helpers to get normalized value and flag
Alexander Rose 5 jaren geleden
bovenliggende
commit
fd19d29ef6

+ 26 - 3
src/mol-model-props/computed/accessible-surface-area.ts

@@ -1,5 +1,5 @@
 /**
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  *
  * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -7,9 +7,12 @@
 
 
 import { ParamDefinition as PD } from '../../mol-util/param-definition'
 import { ParamDefinition as PD } from '../../mol-util/param-definition'
 import { ShrakeRupleyComputationParams, AccessibleSurfaceArea } from './accessible-surface-area/shrake-rupley';
 import { ShrakeRupleyComputationParams, AccessibleSurfaceArea } from './accessible-surface-area/shrake-rupley';
-import { Structure, CustomPropertyDescriptor } from '../../mol-model/structure';
+import { Structure, CustomPropertyDescriptor, Unit } from '../../mol-model/structure';
 import { CustomStructureProperty } from '../common/custom-structure-property';
 import { CustomStructureProperty } from '../common/custom-structure-property';
 import { CustomProperty } from '../common/custom-property';
 import { CustomProperty } from '../common/custom-property';
+import { QuerySymbolRuntime } from '../../mol-script/runtime/query/compiler';
+import { CustomPropSymbol } from '../../mol-script/language/symbol';
+import Type from '../../mol-script/language/type';
 
 
 export const AccessibleSurfaceAreaParams = {
 export const AccessibleSurfaceAreaParams = {
     ...ShrakeRupleyComputationParams
     ...ShrakeRupleyComputationParams
@@ -17,13 +20,33 @@ export const AccessibleSurfaceAreaParams = {
 export type AccessibleSurfaceAreaParams = typeof AccessibleSurfaceAreaParams
 export type AccessibleSurfaceAreaParams = typeof AccessibleSurfaceAreaParams
 export type AccessibleSurfaceAreaProps = PD.Values<AccessibleSurfaceAreaParams>
 export type AccessibleSurfaceAreaProps = PD.Values<AccessibleSurfaceAreaParams>
 
 
+export const AccessibleSurfaceAreaSymbols = {
+    isBuried: QuerySymbolRuntime.Dynamic(CustomPropSymbol('computed', 'accessible-surface-area.is-buried', Type.Bool),
+        ctx => {
+            if (!Unit.isAtomic(ctx.element.unit)) return false
+            const accessibleSurfaceArea = AccessibleSurfaceAreaProvider.get(ctx.element.structure).value
+            if (!accessibleSurfaceArea) return false
+            return AccessibleSurfaceArea.getFlag(ctx.element, accessibleSurfaceArea) === AccessibleSurfaceArea.Flag.Buried
+        }
+    ),
+    isAccessible: QuerySymbolRuntime.Dynamic(CustomPropSymbol('computed', 'accessible-surface-area.is-accessible', Type.Bool),
+        ctx => {
+            if (!Unit.isAtomic(ctx.element.unit)) return false
+            const accessibleSurfaceArea = AccessibleSurfaceAreaProvider.get(ctx.element.structure).value
+            if (!accessibleSurfaceArea) return false
+            return AccessibleSurfaceArea.getFlag(ctx.element, accessibleSurfaceArea) === AccessibleSurfaceArea.Flag.Accessible
+        }
+    ),
+}
+
 export type AccessibleSurfaceAreaValue = AccessibleSurfaceArea
 export type AccessibleSurfaceAreaValue = AccessibleSurfaceArea
 
 
 export const AccessibleSurfaceAreaProvider: CustomStructureProperty.Provider<AccessibleSurfaceAreaParams, AccessibleSurfaceAreaValue> = CustomStructureProperty.createProvider({
 export const AccessibleSurfaceAreaProvider: CustomStructureProperty.Provider<AccessibleSurfaceAreaParams, AccessibleSurfaceAreaValue> = CustomStructureProperty.createProvider({
     label: 'Accessible Surface Area',
     label: 'Accessible Surface Area',
     descriptor: CustomPropertyDescriptor({
     descriptor: CustomPropertyDescriptor({
         name: 'molstar_accessible_surface_area',
         name: 'molstar_accessible_surface_area',
-        // TODO `cifExport` and `symbol`
+        symbols: AccessibleSurfaceAreaSymbols,
+        // TODO `cifExport`
     }),
     }),
     type: 'root',
     type: 'root',
     defaultParams: AccessibleSurfaceAreaParams,
     defaultParams: AccessibleSurfaceAreaParams,

+ 26 - 10
src/mol-model-props/computed/accessible-surface-area/shrake-rupley.ts

@@ -9,7 +9,7 @@ import { Task, RuntimeContext } from '../../../mol-task';
 // import { BitFlags } from '../../../mol-util';
 // import { BitFlags } from '../../../mol-util';
 import { ParamDefinition as PD } from '../../../mol-util/param-definition'
 import { ParamDefinition as PD } from '../../../mol-util/param-definition'
 import { Vec3 } from '../../../mol-math/linear-algebra';
 import { Vec3 } from '../../../mol-math/linear-algebra';
-import { Structure } from '../../../mol-model/structure';
+import { Structure, StructureElement, StructureProperties } from '../../../mol-model/structure';
 import { assignRadiusForHeavyAtoms } from './shrake-rupley/radii';
 import { assignRadiusForHeavyAtoms } from './shrake-rupley/radii';
 import { ShrakeRupleyContext, VdWLookup, MaxAsa, DefaultMaxAsa } from './shrake-rupley/common';
 import { ShrakeRupleyContext, VdWLookup, MaxAsa, DefaultMaxAsa } from './shrake-rupley/common';
 import { computeArea } from './shrake-rupley/area';
 import { computeArea } from './shrake-rupley/area';
@@ -86,19 +86,35 @@ namespace AccessibleSurfaceArea {
         return points;
         return points;
     }
     }
 
 
-    // export namespace SolventAccessibility {
-    //     export const is: (t: number, f: Flag) => boolean = BitFlags.has
-    //     export const create: (f: Flag) => number = BitFlags.create
-    //     export const enum Flag {
-    //         _ = 0x0,
-    //         BURIED = 0x1,
-    //         ACCESSIBLE = 0x2
-    //     }
-    // }
+    export const enum Flag {
+        NA = 0x0,
+        Buried = 0x1,
+        Accessible = 0x2
+    }
 
 
     /** Get relative area for a given component id */
     /** Get relative area for a given component id */
     export function normalize(compId: string, asa: number) {
     export function normalize(compId: string, asa: number) {
         const maxAsa = MaxAsa[compId] || DefaultMaxAsa;
         const maxAsa = MaxAsa[compId] || DefaultMaxAsa;
         return asa / maxAsa
         return asa / maxAsa
     }
     }
+
+    export function getValue(location: StructureElement.Location, accessibleSurfaceArea: AccessibleSurfaceArea) {
+        const { getSerialIndex } = location.structure.root.serialMapping
+        const { area, serialResidueIndex } = accessibleSurfaceArea
+        const rSI = serialResidueIndex[getSerialIndex(location.unit, location.element)]
+        if (rSI === -1) return -1
+        return area[rSI]
+    }
+
+    export function getNormalizedValue(location: StructureElement.Location, accessibleSurfaceArea: AccessibleSurfaceArea) {
+        const value = getValue(location, accessibleSurfaceArea)
+        return value === -1 ? -1 : normalize(StructureProperties.residue.label_comp_id(location), value)
+    }
+
+    export function getFlag(location: StructureElement.Location, accessibleSurfaceArea: AccessibleSurfaceArea) {
+        const value = getNormalizedValue(location, accessibleSurfaceArea)
+        return value === -1 ? Flag.NA :
+            value < 0.16 ? Flag.Buried :
+                Flag.Accessible
+    }
 }
 }

+ 5 - 7
src/mol-model-props/computed/themes/accessible-surface-area.ts

@@ -1,5 +1,5 @@
 /**
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  *
  * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -10,7 +10,7 @@ import { ParamDefinition as PD } from '../../../mol-util/param-definition'
 import { Color, ColorScale } from '../../../mol-util/color'
 import { Color, ColorScale } from '../../../mol-util/color'
 import { ThemeDataContext } from '../../../mol-theme/theme'
 import { ThemeDataContext } from '../../../mol-theme/theme'
 import { ColorTheme, LocationColor } from '../../../mol-theme/color'
 import { ColorTheme, LocationColor } from '../../../mol-theme/color'
-import { StructureProperties, StructureElement, Unit } from '../../../mol-model/structure'
+import { StructureElement, Unit } from '../../../mol-model/structure'
 import { AccessibleSurfaceAreaProvider } from '../accessible-surface-area'
 import { AccessibleSurfaceAreaProvider } from '../accessible-surface-area'
 import { AccessibleSurfaceArea } from '../accessible-surface-area/shrake-rupley'
 import { AccessibleSurfaceArea } from '../accessible-surface-area/shrake-rupley'
 import { CustomProperty } from '../../common/custom-property'
 import { CustomProperty } from '../../common/custom-property'
@@ -36,18 +36,16 @@ export function AccessibleSurfaceAreaColorTheme(ctx: ThemeDataContext, props: PD
         domain: [0.0, 1.0]
         domain: [0.0, 1.0]
     })
     })
 
 
-    const { label_comp_id } = StructureProperties.residue
     const accessibleSurfaceArea = ctx.structure && AccessibleSurfaceAreaProvider.get(ctx.structure)
     const accessibleSurfaceArea = ctx.structure && AccessibleSurfaceAreaProvider.get(ctx.structure)
     const contextHash = accessibleSurfaceArea?.version
     const contextHash = accessibleSurfaceArea?.version
 
 
     if (accessibleSurfaceArea?.value && ctx.structure) {
     if (accessibleSurfaceArea?.value && ctx.structure) {
-        const { getSerialIndex } = ctx.structure.root.serialMapping
-        const { area, serialResidueIndex } = accessibleSurfaceArea.value
+        const asa = accessibleSurfaceArea.value
 
 
         color = (location: Location): Color => {
         color = (location: Location): Color => {
             if (StructureElement.Location.is(location) && Unit.isAtomic(location.unit)) {
             if (StructureElement.Location.is(location) && Unit.isAtomic(location.unit)) {
-                const rSI = serialResidueIndex[getSerialIndex(location.unit, location.element)]
-                return rSI === -1 ? DefaultColor : scale.color(AccessibleSurfaceArea.normalize(label_comp_id(location), area[rSI]))
+                const value = AccessibleSurfaceArea.getNormalizedValue(location, asa)
+                return value === -1 ? DefaultColor : scale.color(value)
             }
             }
             return DefaultColor
             return DefaultColor
         }
         }

+ 6 - 0
src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts

@@ -11,6 +11,7 @@ import { Loci } from '../../../../../mol-model/loci';
 import { AccessibleSurfaceAreaColorThemeProvider } from '../../../../../mol-model-props/computed/themes/accessible-surface-area';
 import { AccessibleSurfaceAreaColorThemeProvider } from '../../../../../mol-model-props/computed/themes/accessible-surface-area';
 import { OrderedSet } from '../../../../../mol-data/int';
 import { OrderedSet } from '../../../../../mol-data/int';
 import { arraySum } from '../../../../../mol-util/array';
 import { arraySum } from '../../../../../mol-util/array';
+import { DefaultQueryRuntimeTable } from '../../../../../mol-script/runtime/query/compiler';
 
 
 export const AccessibleSurfaceArea = PluginBehavior.create<{ autoAttach: boolean, showTooltip: boolean }>({
 export const AccessibleSurfaceArea = PluginBehavior.create<{ autoAttach: boolean, showTooltip: boolean }>({
     name: 'computed-accessible-surface-area-prop',
     name: 'computed-accessible-surface-area-prop',
@@ -36,12 +37,17 @@ export const AccessibleSurfaceArea = PluginBehavior.create<{ autoAttach: boolean
         }
         }
 
 
         register(): void {
         register(): void {
+            DefaultQueryRuntimeTable.addCustomProp(this.provider.descriptor);
+
             this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach);
             this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach);
             this.ctx.structureRepresentation.themeCtx.colorThemeRegistry.add('accessible-surface-area', AccessibleSurfaceAreaColorThemeProvider)
             this.ctx.structureRepresentation.themeCtx.colorThemeRegistry.add('accessible-surface-area', AccessibleSurfaceAreaColorThemeProvider)
             this.ctx.lociLabels.addProvider(this.label);
             this.ctx.lociLabels.addProvider(this.label);
         }
         }
 
 
         unregister() {
         unregister() {
+            // TODO
+            // DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
+
             this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
             this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
             this.ctx.structureRepresentation.themeCtx.colorThemeRegistry.remove('accessible-surface-area')
             this.ctx.structureRepresentation.themeCtx.colorThemeRegistry.remove('accessible-surface-area')
             this.ctx.lociLabels.removeProvider(this.label);
             this.ctx.lociLabels.removeProvider(this.label);