preset.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 { StateObjectRef } from '../../../../mol-state';
  7. import { StructureRepresentationPresetProvider, presetStaticComponent } from '../../../../mol-plugin-state/builder/structure/representation-preset';
  8. import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
  9. import { ColorNames } from '../../../../mol-util/color/names';
  10. import { CellPackColorThemeProvider } from './color';
  11. export const CellpackPackingPresetParams = {
  12. traceOnly: PD.Boolean(true),
  13. representation: PD.Select('gaussian-surface', PD.arrayToOptions(['gaussian-surface', 'spacefill', 'point', 'orientation'])),
  14. }
  15. export type CellpackPackingPresetParams = PD.ValuesFor<typeof CellpackPackingPresetParams>
  16. export const CellpackPackingPreset = StructureRepresentationPresetProvider({
  17. id: 'preset-structure-representation-cellpack-packing',
  18. display: { name: 'CellPack Packing' },
  19. params: () => CellpackPackingPresetParams,
  20. async apply(ref, params, plugin) {
  21. const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref);
  22. if (!structureCell) return {};
  23. const reprProps = {
  24. ignoreHydrogens: true,
  25. traceOnly: params.traceOnly
  26. };
  27. const components = {
  28. polymer: await presetStaticComponent(plugin, structureCell, 'polymer')
  29. };
  30. if (params.representation === 'gaussian-surface') {
  31. Object.assign(reprProps, {
  32. quality: 'custom', resolution: 10, radiusOffset: 2, doubleSided: false
  33. })
  34. } else if (params.representation === 'spacefill' && params.traceOnly) {
  35. Object.assign(reprProps, { sizeFactor: 2 })
  36. }
  37. const { update, builder, typeParams } = StructureRepresentationPresetProvider.reprBuilder(plugin, {});
  38. const color = CellPackColorThemeProvider.name
  39. const representations = {
  40. polymer: builder.buildRepresentation<any>(update, components.polymer, { type: params.representation, typeParams: { ...typeParams, ...reprProps }, color }, { tag: 'polymer' })
  41. };
  42. await update.commit({ revertOnError: true })
  43. return { components, representations };
  44. }
  45. });
  46. //
  47. export const CellpackMembranePresetParams = {
  48. representation: PD.Select('gaussian-surface', PD.arrayToOptions(['gaussian-surface', 'spacefill', 'point', 'orientation'])),
  49. }
  50. export type CellpackMembranePresetParams = PD.ValuesFor<typeof CellpackMembranePresetParams>
  51. export const CellpackMembranePreset = StructureRepresentationPresetProvider({
  52. id: 'preset-structure-representation-cellpack-membrane',
  53. display: { name: 'CellPack Membrane' },
  54. params: () => CellpackMembranePresetParams,
  55. async apply(ref, params, plugin) {
  56. const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref);
  57. if (!structureCell) return {};
  58. const reprProps = {
  59. ignoreHydrogens: true,
  60. };
  61. const components = {
  62. membrane: await presetStaticComponent(plugin, structureCell, 'all', { label: 'Membrane' })
  63. };
  64. if (params.representation === 'gaussian-surface') {
  65. Object.assign(reprProps, {
  66. quality: 'custom', resolution: 10, radiusOffset: 2, doubleSided: false
  67. })
  68. }
  69. const { update, builder, typeParams } = StructureRepresentationPresetProvider.reprBuilder(plugin, {});
  70. const representations = {
  71. membrane: builder.buildRepresentation(update, components.membrane, { type: 'gaussian-surface', typeParams: { ...typeParams, ...reprProps }, color: 'uniform', colorParams: { value: ColorNames.lightgrey } }, { tag: 'all' })
  72. };
  73. await update.commit({ revertOnError: true })
  74. return { components, representations };
  75. }
  76. });