preset2.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { ParamDefinition as PD } from 'molstar/lib/mol-util/param-definition';
  7. import { TrajectoryHierarchyPresetProvider } from 'molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset';
  8. import { PluginStateObject } from 'molstar/lib/mol-plugin-state/objects';
  9. import {
  10. StateObjectSelector,
  11. StateObject,
  12. StateTransformer,
  13. StateObjectRef,
  14. } from 'molstar/lib/mol-state';
  15. import { Mat4, Vec3 } from 'molstar/lib/mol-math/linear-algebra';
  16. import { Target } from '@rcsb/rcsb-molstar/build/src/viewer/helpers/selection';
  17. import { MembraneOrientationPreset } from './tmdet-extension/behavior';
  18. import { TmDetDescriptorCache } from './tmdet-extension/prop';
  19. import { DebugUtil } from './tmdet-extension/debug-utils';
  20. import { StateTransforms } from 'molstar/lib/mol-plugin-state/transforms';
  21. import { applyTransformations } from './tmdet-extension/transformation';
  22. type BaseProps = {
  23. assemblyId?: string
  24. modelIndex?: number
  25. plddt?: 'off' | 'single-chain' | 'on'
  26. }
  27. export { Mat4 } from 'molstar/lib/mol-math/linear-algebra';
  28. export type AlignmentProps = {
  29. kind: 'alignment',
  30. targets?: (Target & {
  31. matrix?: Mat4
  32. })[],
  33. colors: {
  34. value: number,
  35. targets: Target[]
  36. }[]
  37. } & BaseProps
  38. export type EmptyProps = {
  39. kind: 'empty'
  40. } & BaseProps
  41. type ValidationProps = {
  42. kind: 'validation'
  43. colorTheme?: string
  44. showClashes?: boolean
  45. } & BaseProps
  46. type StandardProps = {
  47. kind: 'standard'
  48. } & BaseProps
  49. type SymmetryProps = {
  50. kind: 'symmetry'
  51. symmetryIndex?: number
  52. } & BaseProps
  53. type FeatureProps = {
  54. kind: 'feature'
  55. target: Target
  56. } & BaseProps
  57. type DensityProps = {
  58. kind: 'density'
  59. } & BaseProps
  60. type MembraneProps = {
  61. kind: 'membrane',
  62. } & BaseProps
  63. type FeatureDensityProps = {
  64. kind: 'feature-density',
  65. target: Target,
  66. radius?: number,
  67. hiddenChannels?: string[]
  68. } & BaseProps
  69. export type MotifProps = {
  70. kind: 'motif',
  71. label?: string,
  72. targets: Target[],
  73. color?: number
  74. } & BaseProps
  75. export type NakbProps = {
  76. kind: 'nakb'
  77. } & BaseProps
  78. export type PresetProps = ValidationProps | StandardProps | SymmetryProps | FeatureProps | DensityProps | AlignmentProps |
  79. MembraneProps | FeatureDensityProps | MotifProps | NakbProps | EmptyProps;
  80. const RcsbParams = () => ({
  81. preset: PD.Value<PresetProps>({ kind: 'standard', assemblyId: '' }, { isHidden: true })
  82. });
  83. type StructureObject = StateObjectSelector<PluginStateObject.Molecule.Structure, StateTransformer<StateObject<any, StateObject.Type<any>>, StateObject<any, StateObject.Type<any>>, any>>
  84. export const TmDetRcsbPreset = TrajectoryHierarchyPresetProvider({
  85. id: 'tmdet-preset-trajectory-rcsb',
  86. display: { name: 'TMDET RCSB Preset' },
  87. isApplicable: () => true,
  88. params: RcsbParams,
  89. async apply(trajectory: StateObjectRef<PluginStateObject.Molecule.Trajectory>, params, plugin) {
  90. console.log('TMDET RCSB PRESET: apply start', params);
  91. const modelParams = { modelIndex: 0 };
  92. const props = {
  93. type: {
  94. name: 'assembly' as const,
  95. params: { id: '1' }
  96. }
  97. };
  98. await plugin.state.data.build().to(trajectory)
  99. .apply(StateTransforms.Model.ModelFromTrajectory, modelParams, { ref: 'model' })
  100. .apply(StateTransforms.Model.StructureFromModel, props, { ref: 'assembly' })
  101. .apply(StateTransforms.Model.TransformStructureConformation, {
  102. transform: {
  103. name: 'components',
  104. params: { axis: Vec3.unitY, angle: 90, translation: Vec3.zero() }
  105. }
  106. })
  107. .commit();
  108. const builder = plugin.builders.structure;
  109. const model = new StateObjectSelector(plugin.state.data.build().to('model').ref, plugin.state.data);
  110. const modelProperties = await builder.insertModelProperties(model.ref);
  111. const structure = new StateObjectSelector(plugin.state.data.build().to('assembly').ref, plugin.state.data);
  112. const structureProperties = await builder.insertStructureProperties(structure);
  113. // const representation = await plugin.builders.structure.representation.applyPreset(
  114. // structureProperties, 'auto', { theme: { globalName: 'tmdet-custom-color-theme' } });
  115. const representation = await plugin.builders.structure.representation.applyPreset<any>(structureProperties, MembraneOrientationPreset, {});
  116. // await plugin.builders.structure.hierarchy.applyPreset(
  117. // trajectory, 'default', { representationPreset: TMDET_STRUCTURE_PRESET_ID as any });
  118. (window as any).plugin = plugin;
  119. const result = {
  120. model,
  121. modelProperties,
  122. unitcell: undefined,
  123. structure,
  124. structureProperties,
  125. representation
  126. };
  127. console.log(result);
  128. return result;
  129. }
  130. });