ball-and-stick.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 { ElementSphereVisual, ElementSphereParams } from '../visual/element-sphere';
  7. import { IntraUnitLinkVisual, IntraUnitLinkParams } from '../visual/intra-unit-link-cylinder';
  8. import { InterUnitLinkVisual, InterUnitLinkParams } from '../visual/inter-unit-link-cylinder';
  9. import { ParamDefinition as PD } from 'mol-util/param-definition';
  10. import { UnitsRepresentation } from '../units-representation';
  11. import { ComplexRepresentation } from '../complex-representation';
  12. import { StructureRepresentation, StructureRepresentationProvider } from '../representation';
  13. import { Representation, RepresentationParamsGetter } from 'mol-repr/representation';
  14. import { ThemeRegistryContext } from 'mol-theme/theme';
  15. import { Structure } from 'mol-model/structure';
  16. import { BuiltInColorThemeOptions, BuiltInColorThemes, ColorTheme } from 'mol-theme/color';
  17. import { UnitKind, UnitKindOptions } from '../visual/util/common';
  18. const BallAndStickVisuals = {
  19. 'element-sphere': (getParams: RepresentationParamsGetter<Structure, ElementSphereParams>) => UnitsRepresentation('Element sphere mesh', getParams, ElementSphereVisual),
  20. 'intra-link': (getParams: RepresentationParamsGetter<Structure, IntraUnitLinkParams>) => UnitsRepresentation('Intra-unit link cylinder', getParams, IntraUnitLinkVisual),
  21. 'inter-link': (getParams: RepresentationParamsGetter<Structure, InterUnitLinkParams>) => ComplexRepresentation('Inter-unit link cylinder', getParams, InterUnitLinkVisual),
  22. }
  23. type BallAndStickVisualName = keyof typeof BallAndStickVisuals
  24. const BallAndStickVisualOptions = Object.keys(BallAndStickVisuals).map(name => [name, name] as [BallAndStickVisualName, string])
  25. export const BallAndStickParams = {
  26. ...ElementSphereParams,
  27. ...IntraUnitLinkParams,
  28. ...InterUnitLinkParams,
  29. unitKinds: PD.MultiSelect<UnitKind>(['atomic'], UnitKindOptions),
  30. sizeFactor: PD.Numeric(0.3, { min: 0.01, max: 10, step: 0.01 }),
  31. sizeAspectRatio: PD.Numeric(2/3, { min: 0.01, max: 3, step: 0.01 }),
  32. colorTheme: PD.Mapped('polymer-index', BuiltInColorThemeOptions, name => PD.Group((BuiltInColorThemes as { [k: string]: ColorTheme.Provider<any> })[name].getParams({}))),
  33. visuals: PD.MultiSelect<BallAndStickVisualName>(['element-sphere', 'intra-link', 'inter-link'], BallAndStickVisualOptions),
  34. }
  35. export type BallAndStickParams = typeof BallAndStickParams
  36. export function getBallAndStickParams(ctx: ThemeRegistryContext, structure: Structure) {
  37. return PD.clone(BallAndStickParams)
  38. }
  39. export type BallAndStickRepresentation = StructureRepresentation<BallAndStickParams>
  40. export function BallAndStickRepresentation(getParams: RepresentationParamsGetter<Structure, BallAndStickParams>): BallAndStickRepresentation {
  41. return Representation.createMulti('Ball & Stick', getParams, BallAndStickVisuals as unknown as Representation.Def<Structure, BallAndStickParams>)
  42. }
  43. export const BallAndStickRepresentationProvider: StructureRepresentationProvider<typeof BallAndStickParams> = {
  44. label: 'Ball & Stick',
  45. description: 'Displays atoms as spheres and bonds as cylinders.',
  46. factory: BallAndStickRepresentation,
  47. getParams: getBallAndStickParams,
  48. defaultValues: PD.getDefaultValues(BallAndStickParams)
  49. }