carbohydrate.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { Representation, RepresentationContext, RepresentationParamsGetter } from '../../../mol-repr/representation';
  8. import { ThemeRegistryContext } from '../../../mol-theme/theme';
  9. import { ParamDefinition as PD } from '../../../mol-util/param-definition';
  10. import { ComplexRepresentation } from '../complex-representation';
  11. import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation';
  12. import { CarbohydrateLinkParams, CarbohydrateLinkVisual } from '../visual/carbohydrate-link-cylinder';
  13. import { CarbohydrateSymbolParams, CarbohydrateSymbolVisual } from '../visual/carbohydrate-symbol-mesh';
  14. import { CarbohydrateTerminalLinkParams, CarbohydrateTerminalLinkVisual } from '../visual/carbohydrate-terminal-link-cylinder';
  15. const CarbohydrateVisuals = {
  16. 'carbohydrate-symbol': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, CarbohydrateSymbolParams>) => ComplexRepresentation('Carbohydrate symbol mesh', ctx, getParams, CarbohydrateSymbolVisual),
  17. 'carbohydrate-link': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, CarbohydrateLinkParams>) => ComplexRepresentation('Carbohydrate link cylinder', ctx, getParams, CarbohydrateLinkVisual),
  18. 'carbohydrate-terminal-link': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, CarbohydrateTerminalLinkParams>) => ComplexRepresentation('Carbohydrate terminal link cylinder', ctx, getParams, CarbohydrateTerminalLinkVisual),
  19. }
  20. export const CarbohydrateParams = {
  21. ...CarbohydrateSymbolParams,
  22. ...CarbohydrateLinkParams,
  23. ...CarbohydrateTerminalLinkParams,
  24. visuals: PD.MultiSelect(['carbohydrate-symbol', 'carbohydrate-link', 'carbohydrate-terminal-link'], PD.objectToOptions(CarbohydrateVisuals)),
  25. }
  26. export type CarbohydrateParams = typeof CarbohydrateParams
  27. export function getCarbohydrateParams(ctx: ThemeRegistryContext, structure: Structure) {
  28. return PD.clone(CarbohydrateParams)
  29. }
  30. export type CarbohydrateRepresentation = StructureRepresentation<CarbohydrateParams>
  31. export function CarbohydrateRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, CarbohydrateParams>): CarbohydrateRepresentation {
  32. return Representation.createMulti('Carbohydrate', ctx, getParams, StructureRepresentationStateBuilder, CarbohydrateVisuals as unknown as Representation.Def<Structure, CarbohydrateParams>)
  33. }
  34. export const CarbohydrateRepresentationProvider: StructureRepresentationProvider<CarbohydrateParams> = {
  35. label: 'Carbohydrate',
  36. description: 'Displays carbohydrate symbols (3D SNFG).',
  37. factory: CarbohydrateRepresentation,
  38. getParams: getCarbohydrateParams,
  39. defaultValues: PD.getDefaultValues(CarbohydrateParams),
  40. defaultColorTheme: 'carbohydrate-symbol',
  41. defaultSizeTheme: 'uniform',
  42. isApplicable: (structure: Structure) => structure.carbohydrates.elements.length > 0
  43. }