ball-and-stick.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 { BuiltInSizeThemeName, BuiltInSizeThemeOptions } from 'mol-theme/size';
  17. import { BuiltInColorThemeName, BuiltInColorThemeOptions } from 'mol-theme/color';
  18. import { UnitKind, UnitKindOptions } from '../visual/util/common';
  19. const BallAndStickVisuals = {
  20. 'element-sphere': (getParams: RepresentationParamsGetter<Structure, ElementSphereParams>) => UnitsRepresentation('Element sphere mesh', getParams, ElementSphereVisual),
  21. 'intra-link': (getParams: RepresentationParamsGetter<Structure, IntraUnitLinkParams>) => UnitsRepresentation('Intra-unit link cylinder', getParams, IntraUnitLinkVisual),
  22. 'inter-link': (getParams: RepresentationParamsGetter<Structure, InterUnitLinkParams>) => ComplexRepresentation('Inter-unit link cylinder', getParams, InterUnitLinkVisual),
  23. }
  24. type BallAndStickVisualName = keyof typeof BallAndStickVisuals
  25. const BallAndStickVisualOptions = Object.keys(BallAndStickVisuals).map(name => [name, name] as [BallAndStickVisualName, string])
  26. export const BallAndStickParams = {
  27. ...ElementSphereParams,
  28. ...IntraUnitLinkParams,
  29. ...InterUnitLinkParams,
  30. unitKinds: PD.MultiSelect<UnitKind>('Unit Kind', '', ['atomic'], UnitKindOptions),
  31. sizeFactor: PD.Numeric('Size Factor', '', 0.2, 0.01, 10, 0.01),
  32. sizeTheme: PD.Select<BuiltInSizeThemeName>('Size Theme', '', 'uniform', BuiltInSizeThemeOptions),
  33. colorTheme: PD.Select<BuiltInColorThemeName>('Color Theme', '', 'polymer-index', BuiltInColorThemeOptions),
  34. visuals: PD.MultiSelect<BallAndStickVisualName>('Visuals', '', ['element-sphere', 'intra-link', 'inter-link'], BallAndStickVisualOptions),
  35. }
  36. export type BallAndStickParams = typeof BallAndStickParams
  37. export function getBallAndStickParams(ctx: ThemeRegistryContext, structure: Structure) {
  38. return PD.clone(BallAndStickParams)
  39. }
  40. export type BallAndStickRepresentation = StructureRepresentation<BallAndStickParams>
  41. export function BallAndStickRepresentation(getParams: RepresentationParamsGetter<Structure, BallAndStickParams>): BallAndStickRepresentation {
  42. return Representation.createMulti('Ball & Stick', getParams, BallAndStickVisuals as unknown as Representation.Def<Structure, BallAndStickParams>)
  43. }
  44. export const BallAndStickRepresentationProvider: StructureRepresentationProvider<typeof BallAndStickParams> = {
  45. factory: BallAndStickRepresentation, getParams: getBallAndStickParams
  46. }