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

added polymer-index color-scheme

parent 6c362a0f
No related branches found
No related tags found
No related merge requests found
......@@ -37,16 +37,17 @@ export interface ColorProps {
}
export function getColorThemeProps(props: ColorProps): ColorThemeProps {
return {
name: props.colorTheme,
domain: props.colorDomain,
value: props.colorValue,
structure: props.structure,
color: props.colorFunction,
granularity: props.colorGranularity,
description: props.colorDescription,
legend: props.colorLegend
const p: ColorThemeProps = {
name: props.colorTheme
}
if (props.colorDomain !== undefined) p.domain = props.colorDomain
if (props.colorValue !== undefined) p.value = props.colorValue
if (props.structure !== undefined) p.structure = props.structure
if (props.colorFunction !== undefined) p.color = props.colorFunction
if (props.colorGranularity !== undefined) p.granularity = props.colorGranularity
if (props.colorDescription !== undefined) p.description = props.colorDescription
if (props.colorLegend !== undefined) p.legend = props.colorLegend
return p
}
export function createColors(ctx: RuntimeContext, locationIt: LocationIterator, props: ColorProps, colorData?: ColorData): Promise<ColorData> {
......
......@@ -20,7 +20,7 @@ export interface StructureRepresentation<P extends RepresentationProps = {}> ext
export const StructureParams = {
...Geometry.Params,
colorTheme: SelectParam<ColorThemeName>('Color Theme', '', 'unit-index', ColorThemeOptions),
colorTheme: SelectParam<ColorThemeName>('Color Theme', '', 'polymer-index', ColorThemeOptions),
sizeTheme: SelectParam<SizeThemeName>('Size Theme', '', 'physical', SizeThemeOptions),
}
export const DefaultStructureProps = paramDefaultValues(StructureParams)
......
......@@ -22,6 +22,7 @@ import { ResidueNameColorTheme } from './color/residue-name';
import { SequenceIdColorTheme } from './color/sequence-id';
import { SecondaryStructureColorTheme } from './color/secondary-structure';
import { MoleculeTypeColorTheme } from './color/molecule-type';
import { PolymerIndexColorTheme } from './color/polymer-index';
export type LocationColor = (location: Location, isSecondary: boolean) => Color
......@@ -59,6 +60,7 @@ export function ColorTheme(props: ColorThemeProps): ColorTheme {
case 'element-index': return ElementIndexColorTheme(props)
case 'element-symbol': return ElementSymbolColorTheme(props)
case 'molecule-type': return MoleculeTypeColorTheme(props)
case 'polymer-index': return PolymerIndexColorTheme(props)
case 'residue-name': return ResidueNameColorTheme(props)
case 'secondary-structure': return SecondaryStructureColorTheme(props)
case 'sequence-id': return SequenceIdColorTheme(props)
......@@ -87,6 +89,7 @@ export const ColorThemeInfo = {
'element-index': {},
'element-symbol': {},
'molecule-type': {},
'polymer-index': {},
'residue-name': {},
'secondary-structure': {},
'sequence-id': {},
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { ColorScale, Color } from 'mol-util/color';
import { Location } from 'mol-model/location';
import { StructureElement, Link } from 'mol-model/structure';
import { ColorTheme, ColorThemeProps, LocationColor } from '../color';
const DefaultColor = Color(0xCCCCCC)
const Description = 'Gives every polymer a unique color based on the position (index) of the polymer in the list of polymers in the structure.'
export function PolymerIndexColorTheme(props: ColorThemeProps): ColorTheme {
let color: LocationColor
let scale: ColorScale | undefined = undefined
if (props.structure) {
const { units } = props.structure
let polymerCount = 0
for (let i = 0, il = units.length; i <il; ++i) {
if (units[i].polymerElements.length > 0) ++polymerCount
}
scale = ColorScale.create({ domain: [ 0, polymerCount - 1 ] })
const unitIdColor = new Map<number, Color>()
for (let i = 0, j = 0, il = units.length; i <il; ++i) {
if (units[i].polymerElements.length > 0) {
unitIdColor.set(units[i].id, scale.color(j))
++j
}
}
color = (location: Location): Color => {
let color: Color | undefined
if (StructureElement.isLocation(location)) {
color = unitIdColor.get(location.unit.id)
} else if (Link.isLocation(location)) {
color = unitIdColor.get(location.aUnit.id)
}
return color !== undefined ? color : DefaultColor
}
} else {
color = () => DefaultColor
}
return {
granularity: 'instance',
color,
description: Description,
legend: scale ? scale.legend : undefined
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ export function UnitIndexColorTheme(props: ColorThemeProps): ColorTheme {
scale = ColorScale.create({ domain: [ 0, units.length - 1 ] })
const unitIdColor = new Map<number, Color>()
for (let i = 0, il = units.length; i <il; ++i) {
unitIdColor.set(units[i].id, scale.color(units[i].id))
unitIdColor.set(units[i].id, scale.color(i))
}
color = (location: Location): Color => {
......
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