density-fit.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { ThemeDataContext } from '../../../mol-theme/theme';
  7. import { ColorTheme, LocationColor } from '../../../mol-theme/color';
  8. import { ParamDefinition as PD } from '../../../mol-util/param-definition'
  9. import { Color, ColorScale } from '../../../mol-util/color';
  10. import { StructureElement } from '../../../mol-model/structure';
  11. import { Location } from '../../../mol-model/location';
  12. import { CustomProperty } from '../../common/custom-property';
  13. import { ValidationReportProvider, ValidationReport } from '../validation-report';
  14. const DefaultColor = Color(0xCCCCCC)
  15. export function DensityFitColorTheme(ctx: ThemeDataContext, props: {}): ColorTheme<{}> {
  16. let color: LocationColor = () => DefaultColor
  17. const scaleRsrz = ColorScale.create({
  18. minLabel: 'Poor',
  19. maxLabel: 'Better',
  20. domain: [2, 0],
  21. listOrName: 'red-yellow-blue',
  22. })
  23. const scaleRscc = ColorScale.create({
  24. minLabel: 'Poor',
  25. maxLabel: 'Better',
  26. domain: [0.678, 1.0],
  27. listOrName: 'red-yellow-blue',
  28. })
  29. const validationReport = ctx.structure && ValidationReportProvider.get(ctx.structure.models[0])
  30. const contextHash = validationReport?.version
  31. const model = ctx.structure?.models[0]
  32. if (validationReport?.value && model) {
  33. const { rsrz, rscc } = validationReport.value
  34. const residueIndex = model.atomicHierarchy.residueAtomSegments.index
  35. color = (location: Location): Color => {
  36. if (StructureElement.Location.is(location) && location.unit.model === model) {
  37. const rsrzValue = rsrz.get(residueIndex[location.element])
  38. if (rsrzValue !== undefined) return scaleRsrz.color(rsrzValue)
  39. const rsccValue = rscc.get(residueIndex[location.element])
  40. if (rsccValue !== undefined) return scaleRscc.color(rsccValue)
  41. return DefaultColor
  42. }
  43. return DefaultColor
  44. }
  45. }
  46. return {
  47. factory: DensityFitColorTheme,
  48. granularity: 'group',
  49. color,
  50. props,
  51. contextHash,
  52. description: 'Assigns residue colors according to the density fit using normalized Real Space R (RSRZ) for polymer residues and real space correlation coefficient (RSCC) for ligands. Colors range from poor (RSRZ = 2 or RSCC = 0.678) - to better (RSRZ = 0 or RSCC = 1.0). Data from wwPDB Validation Report, obtained via RCSB PDB.',
  53. legend: scaleRsrz.legend
  54. }
  55. }
  56. export const DensityFitColorThemeProvider: ColorTheme.Provider<{}> = {
  57. label: 'Density Fit',
  58. category: ColorTheme.Category.Validation,
  59. factory: DensityFitColorTheme,
  60. getParams: () => ({}),
  61. defaultValues: PD.getDefaultValues({}),
  62. isApplicable: (ctx: ThemeDataContext) => ValidationReport.isApplicable(ctx.structure?.models[0]),
  63. ensureCustomProperties: (ctx: CustomProperty.Context, data: ThemeDataContext) => {
  64. return data.structure ? ValidationReportProvider.attach(ctx, data.structure.models[0]) : Promise.resolve()
  65. }
  66. }