molstar
Version:
A comprehensive macromolecular library.
79 lines (78 loc) • 4.4 kB
JavaScript
/**
* Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Color } from '../../mol-util/color';
import { StructureElement, Unit, Bond } from '../../mol-model/structure';
import { ParamDefinition as PD } from '../../mol-util/param-definition';
import { ChainIdColorTheme, ChainIdColorThemeParams } from './chain-id';
import { UniformColorTheme, UniformColorThemeParams } from './uniform';
import { assertUnreachable } from '../../mol-util/type-helpers';
import { EntityIdColorTheme, EntityIdColorThemeParams } from './entity-id';
import { MoleculeTypeColorTheme, MoleculeTypeColorThemeParams } from './molecule-type';
import { EntitySourceColorTheme, EntitySourceColorThemeParams } from './entity-source';
import { ModelIndexColorTheme, ModelIndexColorThemeParams } from './model-index';
import { StructureIndexColorTheme, StructureIndexColorThemeParams } from './structure-index';
var DefaultIllustrativeColor = Color(0xEEEEEE);
var Description = "Assigns an illustrative color that gives every chain a color based on the chosen style but with lighter carbons (inspired by David Goodsell's Molecule of the Month style).";
export var IllustrativeColorThemeParams = {
style: PD.MappedStatic('entity-id', {
uniform: PD.Group(UniformColorThemeParams),
'chain-id': PD.Group(ChainIdColorThemeParams),
'entity-id': PD.Group(EntityIdColorThemeParams),
'entity-source': PD.Group(EntitySourceColorThemeParams),
'molecule-type': PD.Group(MoleculeTypeColorThemeParams),
'model-index': PD.Group(ModelIndexColorThemeParams),
'structure-index': PD.Group(StructureIndexColorThemeParams),
}),
carbonLightness: PD.Numeric(0.8, { min: -6, max: 6, step: 0.1 })
};
export function getIllustrativeColorThemeParams(ctx) {
var params = PD.clone(IllustrativeColorThemeParams);
return params;
}
export function IllustrativeColorTheme(ctx, props) {
var _a = props.style.name === 'uniform' ? UniformColorTheme(ctx, props.style.params) :
props.style.name === 'chain-id' ? ChainIdColorTheme(ctx, props.style.params) :
props.style.name === 'entity-id' ? EntityIdColorTheme(ctx, props.style.params) :
props.style.name === 'entity-source' ? EntitySourceColorTheme(ctx, props.style.params) :
props.style.name === 'molecule-type' ? MoleculeTypeColorTheme(ctx, props.style.params) :
props.style.name === 'model-index' ? ModelIndexColorTheme(ctx, props.style.params) :
props.style.name === 'structure-index' ? StructureIndexColorTheme(ctx, props.style.params) :
assertUnreachable(props.style), styleColor = _a.color, legend = _a.legend;
function illustrativeColor(location, typeSymbol) {
var baseColor = styleColor(location, false);
return typeSymbol === 'C' ? Color.lighten(baseColor, props.carbonLightness) : baseColor;
}
function color(location) {
if (StructureElement.Location.is(location) && Unit.isAtomic(location.unit)) {
var typeSymbol = location.unit.model.atomicHierarchy.atoms.type_symbol.value(location.element);
return illustrativeColor(location, typeSymbol);
}
else if (Bond.isLocation(location) && Unit.isAtomic(location.aUnit)) {
var elementIndex = location.aUnit.elements[location.aIndex];
var typeSymbol = location.aUnit.model.atomicHierarchy.atoms.type_symbol.value(elementIndex);
return illustrativeColor(location, typeSymbol);
}
return DefaultIllustrativeColor;
}
return {
factory: IllustrativeColorTheme,
granularity: 'group',
preferSmoothing: true,
color: color,
props: props,
description: Description,
legend: legend
};
}
export var IllustrativeColorThemeProvider = {
name: 'illustrative',
label: 'Illustrative',
category: "Miscellaneous" /* ColorTheme.Category.Misc */,
factory: IllustrativeColorTheme,
getParams: getIllustrativeColorThemeParams,
defaultValues: PD.getDefaultValues(IllustrativeColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; }
};