AlignmentTrajectoryPresetProvider.ts 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2021 RCSB PDB and contributors, licensed under MIT, See LICENSE file for more info.
  3. * @author Joan Segura Mora <joan.segura@rcsb.org>
  4. */
  5. import {TrajectoryHierarchyPresetProvider} from "molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset";
  6. import {PluginContext} from "molstar/lib/mol-plugin/context";
  7. import {PluginStateObject} from "molstar/lib/mol-plugin-state/objects";
  8. import {ParamDefinition, ParamDefinition as PD} from "molstar/lib/mol-util/param-definition";
  9. import {StateObjectRef, StateObjectSelector} from "molstar/lib/mol-state";
  10. import {RootStructureDefinition} from "molstar/lib/mol-plugin-state/helpers/root-structure";
  11. import {StateTransformer} from "molstar/lib/mol-state/transformer";
  12. import {StateObject} from "molstar/lib/mol-state/object";
  13. import {
  14. StructureRepresentationPresetProvider
  15. } from "molstar/lib/mol-plugin-state/builder/structure/representation-preset";
  16. import {PLDDTConfidenceColorThemeProvider} from "molstar/lib/extensions/model-archive/quality-assessment/color/plddt";
  17. import {AlignmentRepresentationPresetProvider} from "./AlignmentRepresentationPresetProvider";
  18. import {TargetAlignment} from "@rcsb/rcsb-api-tools/build/RcsbGraphQL/Types/Borrego/GqlTypes";
  19. export type TrajectoryParamsType = {
  20. pdb?: {entryId:string;entityId:string;};
  21. targetAlignment?: TargetAlignment;
  22. assemblyId?: string;
  23. modelIndex?: number;
  24. plddt?: 'off' | 'single-chain' | 'on';
  25. }
  26. type StructureObject = StateObjectSelector<PluginStateObject.Molecule.Structure, StateTransformer<StateObject<any, StateObject.Type<any>>, StateObject<any, StateObject.Type<any>>, any>>
  27. export const AlignmentTrajectoryPresetProvider = TrajectoryHierarchyPresetProvider<TrajectoryParamsType,any>({
  28. id: 'alignment-to-reference',
  29. display: {
  30. name: 'Alignemnt to Reference'
  31. },
  32. isApplicable: (trajectory: PluginStateObject.Molecule.Trajectory, plugin: PluginContext): boolean => true,
  33. params: (trajectory: PluginStateObject.Molecule.Trajectory | undefined, plugin: PluginContext):ParamDefinition.For<TrajectoryParamsType> => ({
  34. pdb:PD.Value<{entryId:string;entityId:string;}|undefined>(undefined),
  35. targetAlignment: PD.Value<TargetAlignment|undefined>(undefined),
  36. assemblyId:PD.Value<string|undefined>(undefined),
  37. modelIndex:PD.Value<number|undefined>(undefined),
  38. plddt:PD.Value<'off' | 'single-chain' | 'on' | undefined>(undefined)
  39. }),
  40. apply: async (trajectory: StateObjectRef<PluginStateObject.Molecule.Trajectory>, params: TrajectoryParamsType, plugin: PluginContext) => {
  41. const builder = plugin.builders.structure;
  42. const modelParams = { modelIndex: params.modelIndex || 0 };
  43. const structureParams: RootStructureDefinition.Params = { name: 'model', params: {} };
  44. if (params.assemblyId && params.assemblyId !== '' && params.assemblyId !== '0') {
  45. Object.assign(structureParams, {
  46. name: 'assembly',
  47. params: { id: params.assemblyId }
  48. } as RootStructureDefinition.Params);
  49. }
  50. const model = await builder.createModel(trajectory, modelParams);
  51. const modelProperties = await builder.insertModelProperties(model);
  52. const unitcell: StateObjectSelector | undefined = undefined;
  53. const structure = await builder.createStructure(modelProperties || model, structureParams);
  54. const structureProperties = await builder.insertStructureProperties(structure);
  55. const representation: StructureRepresentationPresetProvider.Result | undefined = await plugin.builders.structure.representation.applyPreset(
  56. structureProperties,
  57. AlignmentRepresentationPresetProvider,
  58. {
  59. pdb:params.pdb,
  60. targetAlignment:params.targetAlignment
  61. }
  62. );
  63. //TODO what is the purpose of this return?
  64. return {
  65. model,
  66. modelProperties,
  67. unitcell,
  68. structure,
  69. structureProperties,
  70. representation
  71. };
  72. }
  73. });
  74. function checkPlddtColorTheme(structure: StructureObject | undefined, plddt: 'on' | 'single-chain' | 'off') {
  75. if (!structure?.data) return false;
  76. if (plddt === 'off') return false;
  77. if (plddt === 'single-chain' && structure.data?.polymerUnitCount !== 1) return false;
  78. return PLDDTConfidenceColorThemeProvider.isApplicable({ structure: structure.data });
  79. }