index.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { RcsbFv3DCustomInterface} from "../RcsbFv3D/RcsbFv3DCustom";
  2. import { DebugUtil } from "./tmdet-extension/debug-utils";
  3. import { createFeatureViewerConfing } from "./FeatureViewConfig";
  4. import { fetchDescriptor, registerRegionDescriptorData } from "./UniTmpHelper";
  5. import { TmFv3DCustom } from "./tmdet-viewer/TmFv3DCustom";
  6. import { updateSiteColors } from "./tmdet-extension/tmdet-color-theme";
  7. import { createRcsbFeatureViewer, TmFv1DElement } from "./tmdet-viewer/TmFv1DComponent";
  8. customElements.define("tm-saguaro-1d", TmFv1DElement);
  9. function createRcsb3DViewer(configParams: any) {
  10. document.addEventListener("DOMContentLoaded", (event) => {
  11. (async function(event) {
  12. updateSiteColors(configParams.side1);
  13. DebugUtil.enableLog();
  14. const panel3dConfig = await createConfig(configParams);
  15. DebugUtil.log('Panel config', JSON.stringify(panel3dConfig));
  16. const panel3d = new TmFv3DCustom(panel3dConfig);
  17. panel3d.render();
  18. })();
  19. });
  20. }
  21. async function createConfig(configParams: any): Promise<RcsbFv3DCustomInterface> {
  22. const pdbEntry = configParams.pdbEntry;
  23. const labelAsymId = configParams.labelAsymId;
  24. const params: any = {
  25. title: configParams.title,
  26. subtitle: configParams.subtitle,
  27. side1: configParams.side1,
  28. htpEntry: configParams.htpEntry,
  29. pdbEntry: configParams.pdbEntry,
  30. structureUrl: configParams.structureUrl!,
  31. labelAsymId: labelAsymId,
  32. pdbtmEntry: `${pdbEntry}_${labelAsymId}`
  33. };
  34. if (pdbEntry) {
  35. console.log('annotation data:', configParams.annotationData);
  36. await registerRegionDescriptorData(configParams.annotationData, params.side1);
  37. }
  38. if (configParams.configData) {
  39. console.log('config data:', configParams.configData);
  40. params.fvConfigData = await fetchDescriptor(configParams.configData);
  41. }
  42. const { sequenceConfig, molstarConfig } = await createFeatureViewerConfing(params);
  43. const panel3dConfig: RcsbFv3DCustomInterface = {
  44. elementId: configParams.elementId,
  45. sequencePanelConfig: sequenceConfig,
  46. structurePanelConfig: molstarConfig
  47. };
  48. molstarConfig.structureViewerConfig.viewerProps.layoutShowSequence = true;
  49. (molstarConfig as any).loadConfig.loadParams.params = {
  50. preset: { modelIndex: 0 }
  51. }
  52. return panel3dConfig;
  53. }
  54. export {
  55. DebugUtil,
  56. createRcsb3DViewer,
  57. createRcsbFeatureViewer,
  58. TmFv1DElement
  59. };