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

added occupancy color theme

parent 7600d0a4
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ import { EntitySourceColorThemeProvider } from './color/entity-source';
import { IllustrativeColorThemeProvider } from './color/illustrative';
import { HydrophobicityColorThemeProvider } from './color/hydrophobicity';
import { ModelIndexColorThemeProvider } from './color/model-index';
import { OccupancyColorThemeProvider } from './color/occupancy';
export type LocationColor = (location: Location, isSecondary: boolean) => Color
......@@ -82,6 +83,7 @@ export const BuiltInColorThemes = {
'illustrative': IllustrativeColorThemeProvider,
'model-index': ModelIndexColorThemeProvider,
'molecule-type': MoleculeTypeColorThemeProvider,
'occupancy': OccupancyColorThemeProvider,
'polymer-id': PolymerIdColorThemeProvider,
'polymer-index': PolymerIndexColorThemeProvider,
'residue-name': ResidueNameColorThemeProvider,
......
/**
* Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Color, ColorScale } from '../../mol-util/color';
import { StructureElement, Unit, Link, ElementIndex } from '../../mol-model/structure';
import { Location } from '../../mol-model/location';
import { ColorTheme } from '../color';
import { ParamDefinition as PD } from '../../mol-util/param-definition'
import { ThemeDataContext } from '../theme';
import { ColorListName, ColorListOptionsScale } from '../../mol-util/color/lists';
const DefaultOccupancyColor = Color(0xCCCCCC)
const Description = `Assigns a color based on the occupancy of an atom.`
export const OccupancyColorThemeParams = {
domain: PD.Interval([0, 1]),
list: PD.ColorList<ColorListName>('purples', ColorListOptionsScale),
}
export type OccupancyColorThemeParams = typeof OccupancyColorThemeParams
export function getOccupancyColorThemeParams(ctx: ThemeDataContext) {
return OccupancyColorThemeParams // TODO return copy
}
export function getOccupancy(unit: Unit, element: ElementIndex): number {
if (Unit.isAtomic(unit)) {
return unit.model.atomicConformation.occupancy.value(element)
} else {
return 0
}
}
export function OccupancyColorTheme(ctx: ThemeDataContext, props: PD.Values<OccupancyColorThemeParams>): ColorTheme<OccupancyColorThemeParams> {
const scale = ColorScale.create({
reverse: false,
domain: props.domain,
listOrName: props.list,
})
function color(location: Location): Color {
if (StructureElement.Location.is(location)) {
return scale.color(getOccupancy(location.unit, location.element))
} else if (Link.isLocation(location)) {
return scale.color(getOccupancy(location.aUnit, location.aUnit.elements[location.aIndex]))
}
return DefaultOccupancyColor
}
return {
factory: OccupancyColorTheme,
granularity: 'group',
color,
props,
description: Description,
legend: scale ? scale.legend : undefined
}
}
export const OccupancyColorThemeProvider: ColorTheme.Provider<OccupancyColorThemeParams> = {
label: 'Occupancy',
factory: OccupancyColorTheme,
getParams: getOccupancyColorThemeParams,
defaultValues: PD.getDefaultValues(OccupancyColorThemeParams),
isApplicable: (ctx: ThemeDataContext) => !!ctx.structure
}
\ 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