cartoon.ts 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Structure } from 'mol-model/structure';
  7. import { Task } from 'mol-task';
  8. import { Loci, isEmptyLoci } from 'mol-model/loci';
  9. import { PolymerTraceVisual, PolymerTraceParams } from '../visual/polymer-trace-mesh';
  10. import { PolymerGapVisual, PolymerGapParams } from '../visual/polymer-gap-cylinder';
  11. import { NucleotideBlockVisual, NucleotideBlockParams } from '../visual/nucleotide-block-mesh';
  12. import { SizeThemeName, SizeThemeOptions } from 'mol-theme/size';
  13. import { getQualityProps } from '../../util';
  14. import { paramDefaultValues, SelectParam, NumberParam } from 'mol-util/parameter';
  15. import { UnitsRepresentation } from '../units-representation';
  16. import { PickingId } from 'mol-geo/geometry/picking';
  17. import { MarkerAction } from 'mol-geo/geometry/marker-data';
  18. import { StructureRepresentation } from '../index';
  19. // import { PolymerDirectionVisual, DefaultPolymerDirectionProps } from '../visual/polymer-direction-wedge';
  20. export const CartoonParams = {
  21. ...PolymerTraceParams,
  22. ...PolymerGapParams,
  23. ...NucleotideBlockParams,
  24. // ...PolymerDirectionParams,
  25. sizeTheme: SelectParam<SizeThemeName>('Size Theme', '', 'uniform', SizeThemeOptions),
  26. sizeValue: NumberParam('Size Value', '', 0.6, 0, 10, 0.1),
  27. }
  28. export const DefaultCartoonProps = paramDefaultValues(CartoonParams)
  29. export type CartoonProps = typeof DefaultCartoonProps
  30. export type CartoonRepresentation = StructureRepresentation<CartoonProps>
  31. export function CartoonRepresentation(): CartoonRepresentation {
  32. const traceRepr = UnitsRepresentation('Polymer trace mesh', PolymerTraceVisual)
  33. const gapRepr = UnitsRepresentation('Polymer gap cylinder', PolymerGapVisual)
  34. const blockRepr = UnitsRepresentation('Nucleotide block mesh', NucleotideBlockVisual)
  35. // const directionRepr = UnitsRepresentation('Polymer direction wedge', PolymerDirectionVisual)
  36. let currentProps: CartoonProps
  37. return {
  38. label: 'Cartoon',
  39. params: CartoonParams,
  40. get renderObjects() {
  41. return [ ...traceRepr.renderObjects, ...gapRepr.renderObjects,
  42. ...blockRepr.renderObjects // , ...directionRepr.renderObjects
  43. ]
  44. },
  45. get props() {
  46. return { ...traceRepr.props, ...gapRepr.props, ...blockRepr.props }
  47. },
  48. createOrUpdate: (props: Partial<CartoonProps> = {}, structure?: Structure) => {
  49. const qualityProps = getQualityProps(Object.assign({}, currentProps, props), structure)
  50. currentProps = Object.assign({}, DefaultCartoonProps, currentProps, props, qualityProps)
  51. return Task.create('Creating CartoonRepresentation', async ctx => {
  52. await traceRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
  53. await gapRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
  54. await blockRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
  55. // await directionRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
  56. })
  57. },
  58. getLoci: (pickingId: PickingId) => {
  59. const traceLoci = traceRepr.getLoci(pickingId)
  60. const gapLoci = gapRepr.getLoci(pickingId)
  61. const blockLoci = blockRepr.getLoci(pickingId)
  62. // const directionLoci = directionRepr.getLoci(pickingId)
  63. return !isEmptyLoci(traceLoci) ? traceLoci
  64. : !isEmptyLoci(gapLoci) ? gapLoci
  65. : blockLoci
  66. // : !isEmptyLoci(blockLoci) ? blockLoci
  67. // : directionLoci
  68. },
  69. mark: (loci: Loci, action: MarkerAction) => {
  70. const markTrace = traceRepr.mark(loci, action)
  71. const markGap = gapRepr.mark(loci, action)
  72. const markBlock = blockRepr.mark(loci, action)
  73. // const markDirection = directionRepr.mark(loci, action)
  74. return markTrace || markGap || markBlock // \\ markDirection
  75. },
  76. destroy() {
  77. traceRepr.destroy()
  78. gapRepr.destroy()
  79. blockRepr.destroy()
  80. // directionRepr.destroy()
  81. }
  82. }
  83. }