UNPKG

molstar

Version:

A comprehensive macromolecular library.

105 lines (104 loc) 5.33 kB
/** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { ParamDefinition as PD } from '../../../../mol-util/param-definition'; import { Color } from '../../../../mol-util/color'; import { Bond, StructureElement } from '../../../../mol-model/structure'; import { ValidationReportProvider, ValidationReport } from '../prop'; import { TableLegend } from '../../../../mol-util/legend'; import { SetUtils } from '../../../../mol-util/set'; var DefaultColor = Color(0x909090); var NoIssuesColor = Color(0x2166ac); var OneIssueColor = Color(0xfee08b); var TwoIssuesColor = Color(0xf46d43); var ThreeOrMoreIssuesColor = Color(0xa50026); var ColorLegend = TableLegend([ ['Data unavailable', DefaultColor], ['No issues', NoIssuesColor], ['One issue', OneIssueColor], ['Two issues', TwoIssuesColor], ['Three or more issues', ThreeOrMoreIssuesColor], ]); export function getGeometricQualityColorThemeParams(ctx) { var validationReport = !!ctx.structure && ctx.structure.models.length > 0 && ValidationReportProvider.get(ctx.structure.models[0]).value; var options = []; if (validationReport) { var kinds_1 = new Set(); validationReport.geometryIssues.forEach(function (v) { return v.forEach(function (k) { return kinds_1.add(k); }); }); kinds_1.forEach(function (k) { return options.push([k, k]); }); } return { ignore: PD.MultiSelect([], options) }; } export function GeometryQualityColorTheme(ctx, props) { var _a; var color = function () { return DefaultColor; }; var validationReport = !!ctx.structure && ctx.structure.models.length > 0 ? ValidationReportProvider.get(ctx.structure.models[0]) : void 0; var contextHash = validationReport === null || validationReport === void 0 ? void 0 : validationReport.version; var value = validationReport === null || validationReport === void 0 ? void 0 : validationReport.value; var model = (_a = ctx.structure) === null || _a === void 0 ? void 0 : _a.models[0]; if (value && model) { var geometryIssues_1 = value.geometryIssues, clashes_1 = value.clashes, bondOutliers_1 = value.bondOutliers, angleOutliers_1 = value.angleOutliers; var residueIndex_1 = model.atomicHierarchy.residueAtomSegments.index; var polymerType_1 = model.atomicHierarchy.derived.residue.polymerType; var ignore_1 = new Set(props.ignore); var getColor_1 = function (element) { var rI = residueIndex_1[element]; var value = geometryIssues_1.get(rI); if (value === undefined) return DefaultColor; var count = SetUtils.differenceSize(value, ignore_1); if (count > 0 && polymerType_1[rI] === 0 /* PolymerType.NA */) { count = 0; if (!ignore_1.has('clash') && clashes_1.getVertexEdgeCount(element) > 0) count += 1; if (!ignore_1.has('mog-bond-outlier') && bondOutliers_1.index.has(element)) count += 1; if (!ignore_1.has('mog-angle-outlier') && angleOutliers_1.index.has(element)) count += 1; } switch (count) { case undefined: return DefaultColor; case 0: return NoIssuesColor; case 1: return OneIssueColor; case 2: return TwoIssuesColor; default: return ThreeOrMoreIssuesColor; } }; color = function (location) { if (StructureElement.Location.is(location) && location.unit.model === model) { return getColor_1(location.element); } else if (Bond.isLocation(location) && location.aUnit.model === model) { return getColor_1(location.aUnit.elements[location.aIndex]); } return DefaultColor; }; } return { factory: GeometryQualityColorTheme, granularity: 'group', preferSmoothing: true, color: color, props: props, contextHash: contextHash, description: 'Assigns residue colors according to the number of (filtered) geometry issues. Data from wwPDB Validation Report, obtained via RCSB PDB.', legend: ColorLegend }; } export var GeometryQualityColorThemeProvider = { name: ValidationReport.Tag.GeometryQuality, label: 'Geometry Quality', category: "Validation" /* ColorTheme.Category.Validation */, factory: GeometryQualityColorTheme, getParams: getGeometricQualityColorThemeParams, defaultValues: PD.getDefaultValues(getGeometricQualityColorThemeParams({})), isApplicable: function (ctx) { var _a; return ValidationReport.isApplicable((_a = ctx.structure) === null || _a === void 0 ? void 0 : _a.models[0]); }, ensureCustomProperties: { attach: function (ctx, data) { return data.structure ? ValidationReportProvider.attach(ctx, data.structure.models[0], void 0, true) : Promise.resolve(); }, detach: function (data) { return data.structure && ValidationReportProvider.ref(data.structure.models[0], false); } } };