RcsbFv3DAssembly.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import * as React from "react";
  2. import {RcsbFv3DAbstract} from "./RcsbFv3DAbstract";
  3. import {
  4. AssemblyTrajectoryParamsType,
  5. AssemblyTrajectoryPresetProvider
  6. } from "../RcsbFvStructure/StructureViewers/MolstarViewer/TrajectoryPresetProvider/AssemblyTrajectoryPresetProvider";
  7. import {RcsbFvAdditionalConfig} from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvModule/RcsbFvModuleInterface";
  8. import {InstanceSequenceConfig} from "@rcsb/rcsb-saguaro-app/build/dist/RcsbFvWeb/RcsbFvBuilder/RcsbFvInstanceBuilder";
  9. import {OperatorInfo} from "../RcsbFvStructure/StructureViewerInterface";
  10. import {
  11. LoadMethod,
  12. LoadMolstarInterface,
  13. LoadMolstarReturnType
  14. } from "../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarActionManager";
  15. import {ViewerProps} from "@rcsb/rcsb-molstar/build/src/viewer";
  16. import {StructureViewer} from "../RcsbFvStructure/StructureViewers/StructureViewer";
  17. import {MolstarManagerFactory} from "../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarManagerFactory";
  18. import {RcsbFv3DCssConfig} from "./RcsbFv3DComponent";
  19. import uniqid from "uniqid";
  20. import {RcsbFvStructure} from "../RcsbFvStructure/RcsbFvStructure";
  21. import {
  22. AssemblyPfvManagerFactory
  23. } from "../RcsbFvSequence/SequenceViews/RcsbView/PfvManagerFactoryImplementation/AssemblyPfvManagerFactory";
  24. import {
  25. AssemblyCallbackManagerFactory
  26. } from "../RcsbFvSequence/SequenceViews/RcsbView/CallbackManagerFactoryImplementation/AssemblyCallbackManager";
  27. import {AssemblyBehaviourObserver} from "../RcsbFvStructure/StructureViewerBehaviour/AssemblyBehaviour";
  28. import {HelpLinkComponent} from "../RcsbFvSequence/SequenceViews/RcsbView/Components/HelpLinkComponent";
  29. import {MolstarTools} from "../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarUtils/MolstarTools";
  30. import getModelIdFromTrajectory = MolstarTools.getModelIdFromTrajectory;
  31. import {
  32. MolstarAssemblyLoader
  33. } from "../RcsbFvStructure/StructureViewers/MolstarViewer/MolstarUtils/MolstarAssemblyLoader";
  34. type RcsbFv3DAssemblyAdditionalConfig = RcsbFvAdditionalConfig & {operatorChangeCallback?:(operatorInfo: OperatorInfo)=>void};
  35. export interface RcsbFv3DAssemblyInterface {
  36. elementId?: string;
  37. config: {
  38. entryId: string;
  39. assemblyId?: string;
  40. title?: string;
  41. subtitle?: string;
  42. };
  43. additionalConfig?: RcsbFv3DAssemblyAdditionalConfig;
  44. instanceSequenceConfig?: InstanceSequenceConfig;
  45. useOperatorsFlag?:boolean;
  46. molstarProps?: Partial<ViewerProps>;
  47. cssConfig?: RcsbFv3DCssConfig;
  48. }
  49. type AssemblyLoadMolstarType = LoadMolstarInterface<AssemblyTrajectoryParamsType,LoadMolstarReturnType>;
  50. export class RcsbFv3DAssembly extends RcsbFv3DAbstract<
  51. {instanceSequenceConfig?:InstanceSequenceConfig},
  52. AssemblyLoadMolstarType,
  53. LoadMolstarReturnType,
  54. {viewerElement:string|HTMLElement,viewerProps:Partial<ViewerProps>},
  55. undefined
  56. >{
  57. constructor(params: RcsbFv3DAssemblyInterface) {
  58. const elementId: string = params.elementId ?? uniqid("RcsbFv3D_");
  59. super({
  60. elementId: params.elementId ?? elementId,
  61. sequenceConfig:{
  62. title: params.config.title,
  63. subtitle: params.config.subtitle,
  64. config:{
  65. rcsbId:params.config.entryId,
  66. additionalConfig:params.additionalConfig,
  67. useOperatorsFlag:params.useOperatorsFlag,
  68. pfvParams:{
  69. instanceSequenceConfig:params.instanceSequenceConfig
  70. },
  71. pfvManagerFactory: new AssemblyPfvManagerFactory(),
  72. callbackManagerFactory: new AssemblyCallbackManagerFactory(),
  73. additionalContent:(props)=>(<HelpLinkComponent {...props} helpHref={"/docs/sequence-viewers/3d-protein-feature-view"}/>)
  74. }
  75. },
  76. structureConfig: {
  77. structureViewerConfig: {
  78. viewerElement: RcsbFvStructure.componentId(elementId),
  79. viewerProps:params.molstarProps ?? {}
  80. }
  81. },
  82. structureViewer: new StructureViewer<
  83. AssemblyLoadMolstarType,
  84. LoadMolstarReturnType,
  85. {viewerElement:string|HTMLElement,viewerProps:Partial<ViewerProps>}
  86. >(new MolstarManagerFactory(getModelIdFromTrajectory)),
  87. structureViewerBehaviourObserver: new AssemblyBehaviourObserver<AssemblyLoadMolstarType,LoadMolstarReturnType>(
  88. new MolstarAssemblyLoader({
  89. entryId: params.config.entryId,
  90. assemblyId: typeof (params.config.assemblyId) === "string" && params.config.assemblyId?.length > 0 ? params.config.assemblyId : '1'
  91. })
  92. ),
  93. cssConfig: params.cssConfig
  94. });
  95. }
  96. }