Skip to content
Snippets Groups Projects
Commit 44b8f5c1 authored by Alexander Rose's avatar Alexander Rose
Browse files

added molecule-type color scheme

parent 4dfafb53
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ import { CustomColorTheme } from './color/custom'; ...@@ -21,6 +21,7 @@ import { CustomColorTheme } from './color/custom';
import { ResidueNameColorTheme } from './color/residue-name'; import { ResidueNameColorTheme } from './color/residue-name';
import { SequenceIdColorTheme } from './color/sequence-id'; import { SequenceIdColorTheme } from './color/sequence-id';
import { SecondaryStructureColorTheme } from './color/secondary-structure'; import { SecondaryStructureColorTheme } from './color/secondary-structure';
import { MoleculeTypeColorTheme } from './color/molecule-type';
export type LocationColor = (location: Location, isSecondary: boolean) => Color export type LocationColor = (location: Location, isSecondary: boolean) => Color
...@@ -57,6 +58,7 @@ export function ColorTheme(props: ColorThemeProps): ColorTheme { ...@@ -57,6 +58,7 @@ export function ColorTheme(props: ColorThemeProps): ColorTheme {
case 'custom': return CustomColorTheme(props) case 'custom': return CustomColorTheme(props)
case 'element-index': return ElementIndexColorTheme(props) case 'element-index': return ElementIndexColorTheme(props)
case 'element-symbol': return ElementSymbolColorTheme(props) case 'element-symbol': return ElementSymbolColorTheme(props)
case 'molecule-type': return MoleculeTypeColorTheme(props)
case 'residue-name': return ResidueNameColorTheme(props) case 'residue-name': return ResidueNameColorTheme(props)
case 'secondary-structure': return SecondaryStructureColorTheme(props) case 'secondary-structure': return SecondaryStructureColorTheme(props)
case 'sequence-id': return SequenceIdColorTheme(props) case 'sequence-id': return SequenceIdColorTheme(props)
...@@ -84,6 +86,7 @@ export const ColorThemeInfo = { ...@@ -84,6 +86,7 @@ export const ColorThemeInfo = {
'custom': {}, 'custom': {},
'element-index': {}, 'element-index': {},
'element-symbol': {}, 'element-symbol': {},
'molecule-type': {},
'residue-name': {}, 'residue-name': {},
'secondary-structure': {}, 'secondary-structure': {},
'sequence-id': {}, 'sequence-id': {},
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Color, ColorMap } from 'mol-util/color';
import { StructureElement, Unit, Link, ElementIndex } from 'mol-model/structure';
import { Location } from 'mol-model/location';
import { ColorThemeProps, ColorTheme, TableLegend } from '../color';
import { MoleculeType } from 'mol-model/structure/model/types';
import { getElementMoleculeType } from 'mol-model/structure/util';
const MoleculeTypeColors = ColorMap({
water: 0x386cb0,
ion: 0xf0027f,
protein: 0xbeaed4,
RNA: 0xfdc086,
DNA: 0xbf5b17,
PNA: 0x42A49A,
saccharide: 0x7fc97f,
})
const DefaultMoleculeTypeColor = Color(0xffff99)
const Description = 'Assigns a color based on the molecule type of a residue.'
export function moleculeTypeColor(unit: Unit, element: ElementIndex): Color {
const moleculeType = getElementMoleculeType(unit, element)
switch (moleculeType) {
case MoleculeType.water: return MoleculeTypeColors.water
case MoleculeType.ion: return MoleculeTypeColors.ion
case MoleculeType.protein: return MoleculeTypeColors.protein
case MoleculeType.RNA: return MoleculeTypeColors.RNA
case MoleculeType.DNA: return MoleculeTypeColors.DNA
case MoleculeType.PNA: return MoleculeTypeColors.PNA
case MoleculeType.saccharide: return MoleculeTypeColors.saccharide
}
return DefaultMoleculeTypeColor
}
export function MoleculeTypeColorTheme(props: ColorThemeProps): ColorTheme {
function color(location: Location): Color {
if (StructureElement.isLocation(location)) {
return moleculeTypeColor(location.unit, location.element)
} else if (Link.isLocation(location)) {
return moleculeTypeColor(location.aUnit, location.aUnit.elements[location.aIndex])
}
return DefaultMoleculeTypeColor
}
return {
granularity: 'group',
color,
description: Description,
legend: TableLegend(Object.keys(MoleculeTypeColors).map(name => {
return [name, (MoleculeTypeColors as any)[name] as Color] as [string, Color]
}).concat([[ 'Other/unknown', DefaultMoleculeTypeColor ]]))
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment