MolstarComponentAction.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {
  2. ComponentActionFactoryInterface,
  3. ComponentActionInterface
  4. } from "../../../StructureUtils/ComponentActionInterface";
  5. import {LoadMolstarReturnType} from "../MolstarActionManager";
  6. import {RcsbFvStateInterface} from "../../../../RcsbFvState/RcsbFvStateInterface";
  7. import {createSelectionExpressions} from "@rcsb/rcsb-molstar/build/src/viewer/helpers/selection";
  8. export class MolstarComponentActionFactory implements ComponentActionFactoryInterface<LoadMolstarReturnType> {
  9. getComponentAction(config: { stateManager: RcsbFvStateInterface }): ComponentActionInterface<LoadMolstarReturnType> {
  10. return new MolstarComponentAction(config.stateManager);
  11. }
  12. }
  13. class MolstarComponentAction implements ComponentActionInterface<LoadMolstarReturnType> {
  14. private readonly stateManager: RcsbFvStateInterface;
  15. constructor(stateManager: RcsbFvStateInterface) {
  16. this.stateManager =stateManager;
  17. }
  18. accept(trajectory: LoadMolstarReturnType, context: { entryId:string; entityId:string; } | { entryId:string; instanceId:string; }): void {
  19. const components = trajectory.representation?.components;
  20. if(!components)
  21. return;
  22. if(!components["polymer"]){
  23. this.stateManager.next<
  24. "missing-component",
  25. {tag:"aligned"|"polymer"|"non-polymer";entryId:string;entityId:string;}|{tag:"aligned"|"polymer"|"non-polymer";entryId:string;instanceId:string;}
  26. >({
  27. type:"missing-component",
  28. view: "3d-view",
  29. data: {
  30. tag:"polymer",
  31. ...context
  32. }
  33. });
  34. }
  35. for(const expression of createSelectionExpressions(context.entryId)) {
  36. if(components[expression.tag] && expression.tag != "polymer" && expression.tag != "water")
  37. return;
  38. }
  39. this.stateManager.next<
  40. "missing-component",
  41. {tag:"aligned"|"polymer"|"non-polymer";entryId:string;entityId:string;}|{tag:"aligned"|"polymer"|"non-polymer";entryId:string;instanceId:string;}
  42. >({
  43. type:"missing-component",
  44. view: "3d-view",
  45. data: {
  46. tag:"non-polymer",
  47. ...context
  48. }
  49. });
  50. }
  51. }