TmViewer.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. import { Viewer, ViewerProps } from '@rcsb/rcsb-molstar/build/src/viewer';
  10. import { TmDetColorThemeProvider } from '../tmdet-extension/tmdet-color-theme';
  11. import { MembraneOrientationPreset } from '../tmdet-extension/behavior';
  12. import { TmDetLabelProvider } from '../tmdet-extension/labeling';
  13. import { loadInitialSnapshot, rotateCamera, storeCameraSnapshot } from '../tmdet-extension/camera';
  14. import { BuiltInTrajectoryFormat } from 'molstar/lib/mol-plugin-state/formats/trajectory';
  15. import { PresetProps } from '../preset2';
  16. import { Mat4 } from 'molstar/lib/commonjs/mol-math/linear-algebra';
  17. import { TrajectoryHierarchyPresetProvider } from 'molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset';
  18. export class TmViewer extends Viewer {
  19. constructor(elementOrId: string | HTMLElement, props: Partial<ViewerProps> = {}) {
  20. console.log("TmViewer constructor");
  21. super(elementOrId, props);
  22. this.initBehavior();
  23. }
  24. public async initBehavior() {
  25. let tree = this.plugin.state.behaviors.build();
  26. this.plugin.builders.structure.representation.registerPreset(MembraneOrientationPreset);
  27. this.plugin.representation.structure.themes.colorThemeRegistry.add(TmDetColorThemeProvider);
  28. this.plugin.managers.lociLabels.addProvider(TmDetLabelProvider);
  29. await this.plugin.runTask(this.plugin.state.behaviors.updateTree(tree, { doNotUpdateCurrent: true, doNotLogTiming: true }));
  30. }
  31. loadStructureFromUrl<P, S>(url: string, format: BuiltInTrajectoryFormat, isBinary: boolean, config?: {
  32. props?: PresetProps & {
  33. dataLabel?: string;
  34. };
  35. matrix?: Mat4;
  36. reprProvider?: TrajectoryHierarchyPresetProvider<P, S>;
  37. params?: P;
  38. }): Promise<any> {
  39. this.plugin.canvas3dInitialized.then(() => {
  40. console.log('Camera initialization started', this.plugin.canvas3d?.camera)
  41. storeCameraSnapshot(this.plugin); // store if it is not stored yet
  42. loadInitialSnapshot(this.plugin); // load if there is a stored one
  43. // INVALID DATA CELL: setTimeout(() => { this.plugin.clear(); }, 100); // clear scene after some delay
  44. setTimeout(() => { (async () => {
  45. await rotateCamera(this.plugin);
  46. })(); }, 500);
  47. });
  48. const result = super.loadStructureFromUrl(url, format, isBinary, config);
  49. return result;
  50. }
  51. }