preset.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. export const CellpackPackingsPresetParams = {
  10. traceOnly: PD.Boolean(true),
  11. polymerOnly: PD.Boolean(true),
  12. representation: PD.Select('gaussian-surface', PD.arrayToOptions(['gaussian-surface', 'spacefill', 'point', 'orientation'])),
  13. hue: PD.Interval([0, 360])
  14. }
  15. export type CellpackPackingsPresetParams = PD.ValuesFor<typeof CellpackPackingsPresetParams>
  16. export const CellpackPackingsPreset = StructureRepresentationPresetProvider({
  17. id: 'preset-structure-representation-cellpack',
  18. display: { name: 'CellPack' },
  19. params: () => CellpackPackingsPresetParams,
  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. structure: params.polymerOnly
  29. ? await presetStaticComponent(plugin, structureCell, 'polymer')
  30. : await presetStaticComponent(plugin, structureCell, 'all')
  31. };
  32. const selectionType = params.polymerOnly ? 'polymer' : 'all'
  33. if (params.representation === 'gaussian-surface') {
  34. Object.assign(reprProps, {
  35. quality: 'custom', resolution: 10, radiusOffset: 2, doubleSided: false
  36. })
  37. } else if (params.representation === 'spacefill' && params.traceOnly) {
  38. Object.assign(reprProps, { sizeFactor: 2 })
  39. }
  40. const { update, builder, typeParams } = StructureRepresentationPresetProvider.reprBuilder(plugin, {});
  41. const color = 'model-index'
  42. const colorParams = {
  43. palette: {
  44. name: 'generate',
  45. params: {
  46. hue: params.hue, chroma: [30, 80], luminance: [15, 85],
  47. clusteringStepCount: 50, minSampleCount: 800,
  48. maxCount: 75
  49. }
  50. }
  51. }
  52. const representations = {
  53. structure: builder.buildRepresentation<any>(update, components.structure, { type: params.representation, typeParams: { ...typeParams, ...reprProps }, color, colorParams }, { tag: selectionType })
  54. };
  55. await plugin.updateDataState(update, { revertOnError: true });
  56. return { components, representations };
  57. }
  58. });