structure-quality-report.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { OrderedSet } from '../../../../../mol-data/int';
  7. import { StructureQualityReport } from '../../../../../mol-model-props/pdbe/structure-quality-report';
  8. import { StructureQualityReportColorTheme } from '../../../../../mol-model-props/pdbe/themes/structure-quality-report';
  9. import { Loci } from '../../../../../mol-model/loci';
  10. import { StructureElement } from '../../../../../mol-model/structure';
  11. import { ParamDefinition as PD } from '../../../../../mol-util/param-definition';
  12. import { PluginBehavior } from '../../../behavior';
  13. import { ThemeDataContext } from '../../../../../mol-theme/theme';
  14. import { CustomPropertyRegistry } from '../../../../../mol-model-props/common/custom-property-registry';
  15. export const PDBeStructureQualityReport = PluginBehavior.create<{ autoAttach: boolean }>({
  16. name: 'pdbe-structure-quality-report-prop',
  17. category: 'custom-props',
  18. display: { name: 'PDBe Structure Quality Report' },
  19. ctor: class extends PluginBehavior.Handler<{ autoAttach: boolean }> {
  20. private attach = StructureQualityReport.createAttachTask(
  21. m => `https://www.ebi.ac.uk/pdbe/api/validation/residuewise_outlier_summary/entry/${m.label.toLowerCase()}`,
  22. this.ctx.fetch
  23. );
  24. private provider: CustomPropertyRegistry.ModelProvider = {
  25. option: [StructureQualityReport.Descriptor.name, 'PDBe Structure Quality Report'],
  26. descriptor: StructureQualityReport.Descriptor,
  27. defaultSelected: this.params.autoAttach,
  28. attachableTo: () => true,
  29. attach: this.attach
  30. }
  31. register(): void {
  32. this.ctx.customModelProperties.register(this.provider);
  33. this.ctx.lociLabels.addProvider(labelPDBeValidation);
  34. this.ctx.structureRepresentation.themeCtx.colorThemeRegistry.add('pdbe-structure-quality-report', {
  35. label: 'PDBe Structure Quality Report',
  36. factory: StructureQualityReportColorTheme,
  37. getParams: () => ({}),
  38. defaultValues: {},
  39. isApplicable: (ctx: ThemeDataContext) => !!ctx.structure && !ctx.structure.isEmpty && ctx.structure.models[0].customProperties.has(StructureQualityReport.Descriptor)
  40. })
  41. }
  42. update(p: { autoAttach: boolean }) {
  43. let updated = this.params.autoAttach !== p.autoAttach
  44. this.params.autoAttach = p.autoAttach;
  45. this.provider.defaultSelected = p.autoAttach;
  46. return updated;
  47. }
  48. unregister() {
  49. console.log('unregister')
  50. this.ctx.customModelProperties.unregister(StructureQualityReport.Descriptor.name);
  51. this.ctx.lociLabels.removeProvider(labelPDBeValidation);
  52. this.ctx.structureRepresentation.themeCtx.colorThemeRegistry.remove('pdbe-structure-quality-report')
  53. }
  54. },
  55. params: () => ({
  56. autoAttach: PD.Boolean(false)
  57. })
  58. });
  59. function labelPDBeValidation(loci: Loci): string | undefined {
  60. switch (loci.kind) {
  61. case 'element-loci':
  62. const e = loci.elements[0];
  63. const u = e.unit;
  64. if (!u.model.customProperties.has(StructureQualityReport.Descriptor)) return void 0;
  65. const se = StructureElement.Location.create(u, u.elements[OrderedSet.getAt(e.indices, 0)]);
  66. const issues = StructureQualityReport.getIssues(se);
  67. if (issues.length === 0) return 'PDBe Validation: No Issues';
  68. return `PDBe Validation: ${issues.join(', ')}`;
  69. default: return void 0;
  70. }
  71. }