diff --git a/src/extensions/dnatco/confal-pyramids/behavior.ts b/src/extensions/dnatco/confal-pyramids/behavior.ts index 2333dadf4eba40d7d9a09a45bfc6bc253b06ccc6..0041cd3b452e54a51953d64157e4fbedd60d0b32 100644 --- a/src/extensions/dnatco/confal-pyramids/behavior.ts +++ b/src/extensions/dnatco/confal-pyramids/behavior.ts @@ -5,6 +5,7 @@ * @author Jiří Černý <jiri.cerny@ibt.cas.cz> */ +import { ConfalPyramidsColorThemeProvider } from './color'; import { ConfalPyramidsProvider } from './property'; import { ConfalPyramidsRepresentationProvider } from './representation'; import { Loci } from '../../../mol-model/loci'; @@ -35,9 +36,8 @@ export const DnatcoConfalPyramids = PluginBehavior.create<{ autoAttach: boolean, this.ctx.customModelProperties.register(this.provider, this.params.autoAttach); this.ctx.managers.lociLabels.addProvider(this.labelConfalPyramids); + this.ctx.representation.structure.themes.colorThemeRegistry.add(ConfalPyramidsColorThemeProvider); this.ctx.representation.structure.registry.add(ConfalPyramidsRepresentationProvider); - - /* TODO: Add color provider */ } update(p: { autoAttach: boolean, showToolTip: boolean }) { @@ -53,8 +53,7 @@ export const DnatcoConfalPyramids = PluginBehavior.create<{ autoAttach: boolean, this.ctx.managers.lociLabels.removeProvider(this.labelConfalPyramids); this.ctx.representation.structure.registry.remove(ConfalPyramidsRepresentationProvider); - - /* TODO: Unregister color provider */ + this.ctx.representation.structure.themes.colorThemeRegistry.remove(ConfalPyramidsColorThemeProvider); } }, params: () => ({ diff --git a/src/extensions/dnatco/confal-pyramids/color.ts b/src/extensions/dnatco/confal-pyramids/color.ts new file mode 100644 index 0000000000000000000000000000000000000000..ededefa0d3f44639c9503dd1cc40edfb8953568c --- /dev/null +++ b/src/extensions/dnatco/confal-pyramids/color.ts @@ -0,0 +1,178 @@ +/** + * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Michal Malý <michal.maly@ibt.cas.cz> + * @author Jiří Černý <jiri.cerny@ibt.cas.cz> + */ + +import { ConfalPyramids, ConfalPyramidsProvider } from './property'; +import { ConfalPyramidsTypes as CPT } from './types'; +import { Location } from '../../../mol-model/location'; +import { CustomProperty } from '../../../mol-model-props/common/custom-property'; +import { ColorTheme } from '../../../mol-theme/color'; +import { ThemeDataContext } from '../../../mol-theme/theme'; +import { Color } from '../../../mol-util/color'; +import { ParamDefinition as PD } from '../../../mol-util/param-definition'; + +const DefaultColor = Color(0xCCCCCC); +const Description = 'Assigns colors to confal pyramids'; +const ErrorColor = Color(0xFFA10A); + +type ConformerClasses = 'A' | 'B' | 'BII' | 'miB' | 'Z' | 'IC' | 'OPN' | 'SYN' | 'N'; + +const ColorMapping: ReadonlyMap<ConformerClasses, Color> = new Map([ + ['A', Color(0xFFC1C1)], + ['B', Color(0xC8CFFF)], + ['BII', Color(0x0059DA)], + ['miB', Color(0x3BE8FB)], + ['Z', Color(0x01F60E)], + ['IC', Color(0xFA5CFB)], + ['OPN', Color(0xE90000)], + ['SYN', Color(0xFFFF01)], + ['N', Color(0xF2F2F2)], +]); + +const NtCToClasses: ReadonlyMap<string, [ConformerClasses, ConformerClasses]> = new Map([ + ['NANT', ['N', 'N']], + ['AA00', ['A', 'A']], + ['AA02', ['A', 'A']], + ['AA03', ['A', 'A']], + ['AA04', ['A', 'A']], + ['AA08', ['A', 'A']], + ['AA09', ['A', 'A']], + ['AA01', ['A', 'A']], + ['AA05', ['A', 'A']], + ['AA06', ['A', 'A']], + ['AA10', ['A', 'A']], + ['AA11', ['A', 'A']], + ['AA07', ['A', 'A']], + ['AA12', ['A', 'A']], + ['AA13', ['A', 'A']], + ['AB01', ['A', 'B']], + ['AB02', ['A', 'B']], + ['AB03', ['A', 'B']], + ['AB04', ['A', 'B']], + ['AB05', ['A', 'B']], + ['BA01', ['B', 'A']], + ['BA05', ['B', 'A']], + ['BA09', ['B', 'A']], + ['BA08', ['BII', 'A']], + ['BA10', ['B', 'A']], + ['BA13', ['BII', 'A']], + ['BA16', ['BII', 'A']], + ['BA17', ['BII', 'A']], + ['BB00', ['B', 'B']], + ['BB01', ['B', 'B']], + ['BB17', ['B', 'B']], + ['BB02', ['B', 'B']], + ['BB03', ['B', 'B']], + ['BB11', ['B', 'B']], + ['BB16', ['B', 'B']], + ['BB04', ['B', 'BII']], + ['BB05', ['B', 'BII']], + ['BB07', ['BII', 'BII']], + ['BB08', ['BII', 'BII']], + ['BB10', ['miB', 'miB']], + ['BB12', ['miB', 'miB']], + ['BB13', ['miB', 'miB']], + ['BB14', ['miB', 'miB']], + ['BB15', ['miB', 'miB']], + ['BB20', ['miB', 'miB']], + ['IC01', ['IC', 'IC']], + ['IC02', ['IC', 'IC']], + ['IC03', ['IC', 'IC']], + ['IC04', ['IC', 'IC']], + ['IC05', ['IC', 'IC']], + ['IC06', ['IC', 'IC']], + ['IC07', ['IC', 'IC']], + ['OP01', ['OPN', 'OPN']], + ['OP02', ['OPN', 'OPN']], + ['OP03', ['OPN', 'OPN']], + ['OP04', ['OPN', 'OPN']], + ['OP05', ['OPN', 'OPN']], + ['OP06', ['OPN', 'OPN']], + ['OP07', ['OPN', 'OPN']], + ['OP08', ['OPN', 'OPN']], + ['OP09', ['OPN', 'OPN']], + ['OP10', ['OPN', 'OPN']], + ['OP11', ['OPN', 'OPN']], + ['OP12', ['OPN', 'OPN']], + ['OP13', ['OPN', 'OPN']], + ['OP14', ['OPN', 'OPN']], + ['OP15', ['OPN', 'OPN']], + ['OP16', ['OPN', 'OPN']], + ['OP17', ['OPN', 'OPN']], + ['OP18', ['OPN', 'OPN']], + ['OP19', ['OPN', 'OPN']], + ['OP20', ['OPN', 'OPN']], + ['OP21', ['OPN', 'OPN']], + ['OP22', ['OPN', 'OPN']], + ['OP23', ['OPN', 'OPN']], + ['OP24', ['OPN', 'OPN']], + ['OP25', ['OPN', 'OPN']], + ['OP26', ['OPN', 'OPN']], + ['OP27', ['OPN', 'OPN']], + ['OP28', ['OPN', 'OPN']], + ['OP29', ['OPN', 'OPN']], + ['OP30', ['OPN', 'OPN']], + ['OP31', ['OPN', 'OPN']], + ['OPS1', ['OPN', 'OPN']], + ['OP1S', ['OPN', 'SYN']], + ['AAS1', ['SYN', 'A']], + ['AB1S', ['A', 'SYN']], + ['AB2S', ['A', 'SYN']], + ['BB1S', ['B', 'SYN']], + ['BB2S', ['B', 'SYN']], + ['BBS1', ['SYN', 'B']], + ['ZZ01', ['Z', 'Z']], + ['ZZ02', ['Z', 'Z']], + ['ZZ1S', ['Z', 'SYN']], + ['ZZ2S', ['Z', 'SYN']], + ['ZZS1', ['SYN', 'Z']], + ['ZZS2', ['SYN', 'Z']], +]); + +function getConformerColor(ntc: string, useLower: boolean): Color { + const item = NtCToClasses.get(ntc); + if (!item) return ErrorColor; + return ColorMapping.get(useLower ? item[1] : item[0]) ?? ErrorColor; +} + +export const ConfalPyramidsColorThemeParams = {}; +export type ConfalPyramidsColorThemeParams = typeof ConfalPyramidsColorThemeParams +export function getConfalPyramidsColorThemeParams(ctx: ThemeDataContext) { + return ConfalPyramidsColorThemeParams; // TODO return copy +} + +export function ConfalPyramidsColorTheme(ctx: ThemeDataContext, props: PD.Values<ConfalPyramidsColorThemeParams>): ColorTheme<ConfalPyramidsColorThemeParams> { + function color(location: Location, isSecondary: boolean): Color { + if (CPT.isLocation(location)) { + const { pyramid, isLower } = location.data; + return getConformerColor(pyramid.NtC, isLower); + } + + return DefaultColor; + } + + return { + factory: ConfalPyramidsColorTheme, + granularity: 'group', + color, + props, + description: Description, + }; +} + +export const ConfalPyramidsColorThemeProvider: ColorTheme.Provider<ConfalPyramidsColorThemeParams, 'confal-pyramids'> = { + name: 'confal-pyramids', + label: 'Confal Pyramids', + category: ColorTheme.Category.Residue, + factory: ConfalPyramidsColorTheme, + getParams: getConfalPyramidsColorThemeParams, + defaultValues: PD.getDefaultValues(ConfalPyramidsColorThemeParams), + isApplicable: (ctx: ThemeDataContext) => !!ctx.structure && ctx.structure.models.some(m => ConfalPyramids.isApplicable(m)), + ensureCustomProperties: { + attach: (ctx: CustomProperty.Context, data: ThemeDataContext) => data.structure ? ConfalPyramidsProvider.attach(ctx, data.structure.models[0], void 0, true) : Promise.resolve(), + detach: (data) => data.structure && data.structure.models[0].customProperties.reference(ConfalPyramidsProvider.descriptor, false) + } +}; diff --git a/src/extensions/dnatco/confal-pyramids/representation.ts b/src/extensions/dnatco/confal-pyramids/representation.ts index 51ffe42c260a8d6eedf6ac7b0ce7d466412aa709..841fc4cdb6571154f75edeb8c9c1f8f0b5a54ad5 100644 --- a/src/extensions/dnatco/confal-pyramids/representation.ts +++ b/src/extensions/dnatco/confal-pyramids/representation.ts @@ -23,7 +23,6 @@ import { StructureRepresentation, StructureRepresentationProvider, StructureRepr import { StructureGroup, UnitsMeshParams, UnitsMeshVisual, UnitsVisual } from '../../../mol-repr/structure/units-visual'; import { VisualUpdateState } from '../../../mol-repr/util'; import { VisualContext } from '../../../mol-repr/visual'; -import { Color } from '../../../mol-util/color'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { Theme, ThemeRegistryContext } from '../../../mol-theme/theme'; import { NullLocation } from '../../../mol-model/location'; @@ -159,7 +158,7 @@ export const ConfalPyramidsRepresentationProvider = StructureRepresentationProvi factory: ConfalPyramidsRepresentation, getParams: getConfalPyramidsParams, defaultValues: PD.getDefaultValues(ConfalPyramidsParams), - defaultColorTheme: { name: 'uniform', props: { value: Color(0xFF3D5A) } }, // TODO: Change to the actual color theme once it is implemented + defaultColorTheme: { name: 'confal-pyramids' }, defaultSizeTheme: { name: 'uniform' }, isApplicable: (structure: Structure) => structure.models.some(m => ConfalPyramids.isApplicable(m)), ensureCustomProperties: {