carbohydrate.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 { CarbohydrateSymbolVisual, CarbohydrateSymbolParams } from '../visual/carbohydrate-symbol-mesh';
  10. import { CarbohydrateLinkVisual, CarbohydrateLinkParams } from '../visual/carbohydrate-link-cylinder';
  11. import { SizeThemeName, SizeThemeOptions } from 'mol-theme/size';
  12. import { getQualityProps } from '../../util';
  13. import { paramDefaultValues, SelectParam, NumberParam } from 'mol-util/parameter';
  14. import { PickingId } from 'mol-geo/geometry/picking';
  15. import { MarkerAction } from 'mol-geo/geometry/marker-data';
  16. import { ComplexRepresentation } from '../complex-representation';
  17. import { StructureRepresentation } from '../index';
  18. export const CarbohydrateParams = {
  19. ...CarbohydrateSymbolParams,
  20. ...CarbohydrateLinkParams,
  21. sizeTheme: SelectParam<SizeThemeName>('Size Theme', '', 'uniform', SizeThemeOptions),
  22. sizeValue: NumberParam('Size Value', '', 1, 0, 0.1, 20),
  23. sizeFactor: NumberParam('Size Factor', '', 1, 0, 10, 0.1),
  24. }
  25. export const DefaultCarbohydrateProps = paramDefaultValues(CarbohydrateParams)
  26. export type CarbohydrateProps = typeof DefaultCarbohydrateProps
  27. export type CarbohydrateRepresentation = StructureRepresentation<CarbohydrateProps>
  28. export function CarbohydrateRepresentation(): CarbohydrateRepresentation {
  29. const carbohydrateSymbolRepr = ComplexRepresentation('Carbohydrate symbol mesh', CarbohydrateSymbolVisual)
  30. const carbohydrateLinkRepr = ComplexRepresentation('Carbohydrate link cylinder', CarbohydrateLinkVisual)
  31. let currentProps: CarbohydrateProps
  32. return {
  33. label: 'Carbohydrate',
  34. params: CarbohydrateParams,
  35. get renderObjects() {
  36. return [ ...carbohydrateSymbolRepr.renderObjects, ...carbohydrateLinkRepr.renderObjects ]
  37. },
  38. get props() {
  39. return { ...carbohydrateSymbolRepr.props, ...carbohydrateLinkRepr.props }
  40. },
  41. createOrUpdate: (props: Partial<CarbohydrateProps> = {}, structure?: Structure) => {
  42. const qualityProps = getQualityProps(Object.assign({}, currentProps, props), structure)
  43. currentProps = Object.assign({}, DefaultCarbohydrateProps, currentProps, props, qualityProps)
  44. return Task.create('Creating CarbohydrateRepresentation', async ctx => {
  45. await carbohydrateSymbolRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
  46. await carbohydrateLinkRepr.createOrUpdate(currentProps, structure).runInContext(ctx)
  47. })
  48. },
  49. getLoci: (pickingId: PickingId) => {
  50. const carbohydrateSymbolLoci = carbohydrateSymbolRepr.getLoci(pickingId)
  51. const carbohydrateLinkLoci = carbohydrateLinkRepr.getLoci(pickingId)
  52. return !isEmptyLoci(carbohydrateSymbolLoci) ? carbohydrateSymbolLoci
  53. : carbohydrateLinkLoci
  54. },
  55. mark: (loci: Loci, action: MarkerAction) => {
  56. const markSymbol = carbohydrateSymbolRepr.mark(loci, action)
  57. const markLink = carbohydrateLinkRepr.mark(loci, action)
  58. return markSymbol || markLink
  59. },
  60. destroy() {
  61. carbohydrateSymbolRepr.destroy()
  62. carbohydrateLinkRepr.destroy()
  63. }
  64. }
  65. }