index.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Copyright (C) 2022, Protein Bioinformatics Research Group, RCNS
  3. *
  4. * Licensed under CC BY-NC 4.0, see LICENSE file for more info.
  5. *
  6. * @author Gabor Tusnady <tusnady.gabor@ttk.hu>
  7. * @author Csongor Gerdan <gerdan.csongor@ttk.hu>
  8. */
  9. import { TMDETMembraneOrientation } from '../../extensions/tmdet/behavior';
  10. import { createPlugin } from '../../mol-plugin-ui';
  11. import { PluginUIContext } from '../../mol-plugin-ui/context';
  12. import { PluginLayoutControlsDisplay } from '../../mol-plugin/layout';
  13. import { DefaultPluginUISpec, PluginUISpec } from '../../mol-plugin-ui/spec';
  14. import { PluginConfig } from '../../mol-plugin/config';
  15. import { PluginSpec } from '../../mol-plugin/spec';
  16. import '../../mol-util/polyfill';
  17. import { ObjectKeys } from '../../mol-util/type-helpers';
  18. import './embedded.html';
  19. import './favicon.ico';
  20. import './index.html';
  21. require('mol-plugin-ui/skin/light.scss');
  22. export { PLUGIN_VERSION as version } from '../../mol-plugin/version';
  23. export { setDebugMode, setProductionMode } from '../../mol-util/debug';
  24. export { loadWithUNITMPMembraneRepresentation } from '../../extensions/tmdet/behavior';
  25. export { loadInitialSnapshot } from '../../extensions/tmdet/camera';
  26. export { DebugUtil } from '../../extensions/tmdet/debug-utils';
  27. const Extensions = {
  28. 'tmdet-membrane-orientation': PluginSpec.Behavior(TMDETMembraneOrientation)
  29. };
  30. const DefaultViewerOptions = {
  31. extensions: ObjectKeys(Extensions),
  32. layoutIsExpanded: true,
  33. layoutShowControls: true,
  34. layoutShowRemoteState: true,
  35. layoutControlsDisplay: 'reactive' as PluginLayoutControlsDisplay,
  36. layoutShowSequence: true,
  37. layoutShowLog: true,
  38. layoutShowLeftPanel: true,
  39. collapseLeftPanel: false,
  40. disableAntialiasing: false,
  41. pixelScale: 1,
  42. enableWboit: true,
  43. viewportShowExpand: PluginConfig.Viewport.ShowExpand.defaultValue,
  44. viewportShowControls: PluginConfig.Viewport.ShowControls.defaultValue,
  45. viewportShowSettings: PluginConfig.Viewport.ShowSettings.defaultValue,
  46. viewportShowSelectionMode: PluginConfig.Viewport.ShowSelectionMode.defaultValue,
  47. viewportShowAnimation: PluginConfig.Viewport.ShowAnimation.defaultValue,
  48. pluginStateServer: PluginConfig.State.DefaultServer.defaultValue,
  49. volumeStreamingServer: PluginConfig.VolumeStreaming.DefaultServer.defaultValue,
  50. volumeStreamingDisabled: !PluginConfig.VolumeStreaming.Enabled.defaultValue,
  51. pdbProvider: PluginConfig.Download.DefaultPdbProvider.defaultValue,
  52. emdbProvider: PluginConfig.Download.DefaultEmdbProvider.defaultValue,
  53. };
  54. type ViewerOptions = typeof DefaultViewerOptions;
  55. export class Viewer {
  56. plugin: PluginUIContext
  57. constructor(elementOrId: string | HTMLElement, options: Partial<ViewerOptions> = {}) {
  58. const o = { ...DefaultViewerOptions, ...options };
  59. const defaultSpec = DefaultPluginUISpec();
  60. const spec: PluginUISpec = {
  61. actions: defaultSpec.actions,
  62. behaviors: [
  63. ...defaultSpec.behaviors,
  64. ...o.extensions.map(e => Extensions[e]),
  65. ],
  66. animations: [...defaultSpec.animations || []],
  67. customParamEditors: defaultSpec.customParamEditors,
  68. layout: {
  69. initial: {
  70. isExpanded: o.layoutIsExpanded,
  71. showControls: o.layoutShowControls,
  72. controlsDisplay: o.layoutControlsDisplay,
  73. regionState: {
  74. bottom: 'full',
  75. left: o.collapseLeftPanel ? 'collapsed' : 'full',
  76. right: 'full',
  77. top: 'full',
  78. }
  79. },
  80. },
  81. components: {
  82. ...defaultSpec.components,
  83. controls: {
  84. ...defaultSpec.components?.controls,
  85. top: o.layoutShowSequence ? undefined : 'none',
  86. bottom: o.layoutShowLog ? undefined : 'none',
  87. left: o.layoutShowLeftPanel ? undefined : 'none',
  88. },
  89. remoteState: o.layoutShowRemoteState ? 'default' : 'none',
  90. },
  91. config: [
  92. [PluginConfig.General.DisableAntialiasing, o.disableAntialiasing],
  93. [PluginConfig.General.PixelScale, o.pixelScale],
  94. [PluginConfig.General.EnableWboit, o.enableWboit],
  95. [PluginConfig.Viewport.ShowExpand, o.viewportShowExpand],
  96. [PluginConfig.Viewport.ShowControls, o.viewportShowControls],
  97. [PluginConfig.Viewport.ShowSettings, o.viewportShowSettings],
  98. [PluginConfig.Viewport.ShowSelectionMode, o.viewportShowSelectionMode],
  99. [PluginConfig.Viewport.ShowAnimation, o.viewportShowAnimation],
  100. [PluginConfig.State.DefaultServer, o.pluginStateServer],
  101. [PluginConfig.State.CurrentServer, o.pluginStateServer],
  102. [PluginConfig.VolumeStreaming.DefaultServer, o.volumeStreamingServer],
  103. [PluginConfig.VolumeStreaming.Enabled, !o.volumeStreamingDisabled],
  104. [PluginConfig.Download.DefaultPdbProvider, o.pdbProvider],
  105. [PluginConfig.Download.DefaultEmdbProvider, o.emdbProvider]
  106. ]
  107. };
  108. const element = typeof elementOrId === 'string'
  109. ? document.getElementById(elementOrId)
  110. : elementOrId;
  111. if (!element) throw new Error(`Could not get element with id '${elementOrId}'`);
  112. this.plugin = createPlugin(element, spec);
  113. }
  114. handleResize() {
  115. this.plugin.layout.events.updated.next();
  116. }
  117. }