UNPKG

molstar

Version:

A comprehensive macromolecular library.

84 lines (83 loc) 5.16 kB
"use strict"; /** * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.IllustrativeColorThemeProvider = exports.IllustrativeColorTheme = exports.getIllustrativeColorThemeParams = exports.IllustrativeColorThemeParams = void 0; var color_1 = require("../../mol-util/color"); var structure_1 = require("../../mol-model/structure"); var param_definition_1 = require("../../mol-util/param-definition"); var chain_id_1 = require("./chain-id"); var uniform_1 = require("./uniform"); var type_helpers_1 = require("../../mol-util/type-helpers"); var entity_id_1 = require("./entity-id"); var molecule_type_1 = require("./molecule-type"); var entity_source_1 = require("./entity-source"); var model_index_1 = require("./model-index"); var structure_index_1 = require("./structure-index"); var DefaultIllustrativeColor = (0, color_1.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)."; exports.IllustrativeColorThemeParams = { style: param_definition_1.ParamDefinition.MappedStatic('entity-id', { uniform: param_definition_1.ParamDefinition.Group(uniform_1.UniformColorThemeParams), 'chain-id': param_definition_1.ParamDefinition.Group(chain_id_1.ChainIdColorThemeParams), 'entity-id': param_definition_1.ParamDefinition.Group(entity_id_1.EntityIdColorThemeParams), 'entity-source': param_definition_1.ParamDefinition.Group(entity_source_1.EntitySourceColorThemeParams), 'molecule-type': param_definition_1.ParamDefinition.Group(molecule_type_1.MoleculeTypeColorThemeParams), 'model-index': param_definition_1.ParamDefinition.Group(model_index_1.ModelIndexColorThemeParams), 'structure-index': param_definition_1.ParamDefinition.Group(structure_index_1.StructureIndexColorThemeParams), }), carbonLightness: param_definition_1.ParamDefinition.Numeric(0.8, { min: -6, max: 6, step: 0.1 }) }; function getIllustrativeColorThemeParams(ctx) { var params = param_definition_1.ParamDefinition.clone(exports.IllustrativeColorThemeParams); return params; } exports.getIllustrativeColorThemeParams = getIllustrativeColorThemeParams; function IllustrativeColorTheme(ctx, props) { var _a = props.style.name === 'uniform' ? (0, uniform_1.UniformColorTheme)(ctx, props.style.params) : props.style.name === 'chain-id' ? (0, chain_id_1.ChainIdColorTheme)(ctx, props.style.params) : props.style.name === 'entity-id' ? (0, entity_id_1.EntityIdColorTheme)(ctx, props.style.params) : props.style.name === 'entity-source' ? (0, entity_source_1.EntitySourceColorTheme)(ctx, props.style.params) : props.style.name === 'molecule-type' ? (0, molecule_type_1.MoleculeTypeColorTheme)(ctx, props.style.params) : props.style.name === 'model-index' ? (0, model_index_1.ModelIndexColorTheme)(ctx, props.style.params) : props.style.name === 'structure-index' ? (0, structure_index_1.StructureIndexColorTheme)(ctx, props.style.params) : (0, type_helpers_1.assertUnreachable)(props.style), styleColor = _a.color, legend = _a.legend; function illustrativeColor(location, typeSymbol) { var baseColor = styleColor(location, false); return typeSymbol === 'C' ? color_1.Color.lighten(baseColor, props.carbonLightness) : baseColor; } function color(location) { if (structure_1.StructureElement.Location.is(location) && structure_1.Unit.isAtomic(location.unit)) { var typeSymbol = location.unit.model.atomicHierarchy.atoms.type_symbol.value(location.element); return illustrativeColor(location, typeSymbol); } else if (structure_1.Bond.isLocation(location) && structure_1.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 }; } exports.IllustrativeColorTheme = IllustrativeColorTheme; exports.IllustrativeColorThemeProvider = { name: 'illustrative', label: 'Illustrative', category: "Miscellaneous" /* ColorTheme.Category.Misc */, factory: IllustrativeColorTheme, getParams: getIllustrativeColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.IllustrativeColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; } };