TmViewer.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author Joan Segura <joan.segura@rcsb.org>
  6. * @author Yana Rose <yana.rose@rcsb.org>
  7. * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  8. */
  9. /**
  10. * Copyright (C) 2023, Protein Bioinformatics Research Group, RCNS
  11. *
  12. * Licensed under CC BY-NC 4.0, see LICENSE file for more info.
  13. *
  14. * @author Gabor Tusnady <tusnady.gabor@ttk.hu>
  15. * @author Csongor Gerdan <gerdan.csongor@ttk.hu>
  16. */
  17. import { Viewer, ViewerProps } from '@rcsb/rcsb-molstar/build/src/viewer';
  18. import { TmDetColorThemeProvider } from '../tmdet-extension/tmdet-color-theme';
  19. import { MembraneOrientationPreset } from '../tmdet-extension/behavior';
  20. import { TmDetLabelProvider } from '../tmdet-extension/labeling';
  21. import { loadInitialSnapshot, rotateCamera, storeCameraSnapshot } from '../tmdet-extension/camera';
  22. import { BuiltInTrajectoryFormat } from 'molstar/lib/mol-plugin-state/formats/trajectory';
  23. import { PresetProps } from '@rcsb/rcsb-molstar/build/src/viewer/helpers/preset';
  24. import { Mat4 } from 'molstar/lib/commonjs/mol-math/linear-algebra';
  25. import { TrajectoryHierarchyPresetProvider } from 'molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset';
  26. export class TmViewer extends Viewer {
  27. constructor(elementOrId: string | HTMLElement, props: Partial<ViewerProps> = {}) {
  28. console.log("TmViewer constructor");
  29. super(elementOrId, props);
  30. this.initBehavior();
  31. }
  32. public async initBehavior() {
  33. let tree = this.plugin.state.behaviors.build();
  34. this.plugin.builders.structure.representation.registerPreset(MembraneOrientationPreset);
  35. this.plugin.representation.structure.themes.colorThemeRegistry.add(TmDetColorThemeProvider);
  36. this.plugin.managers.lociLabels.addProvider(TmDetLabelProvider);
  37. await this.plugin.runTask(this.plugin.state.behaviors.updateTree(tree, { doNotUpdateCurrent: true, doNotLogTiming: true }));
  38. }
  39. loadStructureFromUrl<P, S>(url: string, format: BuiltInTrajectoryFormat, isBinary: boolean, config?: {
  40. props?: PresetProps & {
  41. dataLabel?: string;
  42. };
  43. matrix?: Mat4;
  44. reprProvider?: TrajectoryHierarchyPresetProvider<P, S>;
  45. params?: P;
  46. }): Promise<any> {
  47. this.plugin.canvas3dInitialized.then(() => {
  48. console.log('Camera initialization started', this.plugin.canvas3d?.camera)
  49. storeCameraSnapshot(this.plugin); // store if it is not stored yet
  50. loadInitialSnapshot(this.plugin); // load if there is a stored one
  51. // INVALID DATA CELL: setTimeout(() => { this.plugin.clear(); }, 100); // clear scene after some delay
  52. setTimeout(() => { (async () => {
  53. await rotateCamera(this.plugin);
  54. })(); }, 500);
  55. });
  56. const result = super.loadStructureFromUrl(url, format, isBinary, config);
  57. return result;
  58. }
  59. }