UNPKG

molstar

Version:

A comprehensive macromolecular library.

106 lines (105 loc) 4.52 kB
/** * Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __awaiter, __generator } from "tslib"; import { QualityAssessment, QualityAssessmentProvider } from '../prop'; import { Bond, StructureElement, Unit } from '../../../../mol-model/structure'; import { Color, ColorScale } from '../../../../mol-util/color'; import { ParamDefinition as PD } from '../../../../mol-util/param-definition'; var DefaultColor = Color(0xaaaaaa); export function getQmeanScoreColorThemeParams(ctx) { return {}; } export function QmeanScoreColorTheme(ctx, props) { var color = function () { return DefaultColor; }; var scale = ColorScale.create({ domain: [0, 1], listOrName: [ [Color(0xFF5000), 0.5], [Color(0x025AFD), 1.0] ] }); if (ctx.structure) { var l_1 = StructureElement.Location.create(ctx.structure.root); var getColor_1 = function (location) { var _a, _b; var unit = location.unit, element = location.element; if (!Unit.isAtomic(unit)) return DefaultColor; var qualityAssessment = QualityAssessmentProvider.get(unit.model).value; var score = (_b = (_a = qualityAssessment === null || qualityAssessment === void 0 ? void 0 : qualityAssessment.qmean) === null || _a === void 0 ? void 0 : _a.get(unit.model.atomicHierarchy.residueAtomSegments.index[element])) !== null && _b !== void 0 ? _b : -1; if (score < 0) { return DefaultColor; } else { return scale.color(score); } }; color = function (location) { if (StructureElement.Location.is(location)) { return getColor_1(location); } else if (Bond.isLocation(location)) { l_1.unit = location.aUnit; l_1.element = location.aUnit.elements[location.aIndex]; return getColor_1(l_1); } return DefaultColor; }; } return { factory: QmeanScoreColorTheme, granularity: 'group', preferSmoothing: true, color: color, props: props, description: 'Assigns residue colors according to the QMEAN score.', legend: scale.legend }; } export var QmeanScoreColorThemeProvider = { name: 'qmean-score', label: 'QMEAN Score', category: "Validation" /* ColorTheme.Category.Validation */, factory: QmeanScoreColorTheme, getParams: getQmeanScoreColorThemeParams, defaultValues: PD.getDefaultValues(getQmeanScoreColorThemeParams({})), isApplicable: function (ctx) { var _a; return !!((_a = ctx.structure) === null || _a === void 0 ? void 0 : _a.models.some(function (m) { return QualityAssessment.isApplicable(m, 'qmean'); })); }, ensureCustomProperties: { attach: function (ctx, data) { return __awaiter(void 0, void 0, void 0, function () { var _i, _a, m; return __generator(this, function (_b) { switch (_b.label) { case 0: if (!data.structure) return [3 /*break*/, 4]; _i = 0, _a = data.structure.models; _b.label = 1; case 1: if (!(_i < _a.length)) return [3 /*break*/, 4]; m = _a[_i]; return [4 /*yield*/, QualityAssessmentProvider.attach(ctx, m, void 0, true)]; case 2: _b.sent(); _b.label = 3; case 3: _i++; return [3 /*break*/, 1]; case 4: return [2 /*return*/]; } }); }); }, detach: function (data) { return __awaiter(void 0, void 0, void 0, function () { var _i, _a, m; return __generator(this, function (_b) { if (data.structure) { for (_i = 0, _a = data.structure.models; _i < _a.length; _i++) { m = _a[_i]; QualityAssessmentProvider.ref(m, false); } } return [2 /*return*/]; }); }); } } };