spacefill.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 { getElementSphereVisual, ElementSphereParams } from '../visual/element-sphere';
  7. import { UnitsRepresentation } from '../units-representation';
  8. import { ParamDefinition as PD } from 'mol-util/param-definition';
  9. import { StructureRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation';
  10. import { RepresentationParamsGetter, RepresentationContext, Representation } from 'mol-repr/representation';
  11. import { ThemeRegistryContext } from 'mol-theme/theme';
  12. import { Structure } from 'mol-model/structure';
  13. import { UnitKind, UnitKindOptions } from '../visual/util/common';
  14. const SpacefillVisuals = {
  15. 'element-sphere': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, ElementSphereParams>) => UnitsRepresentation('Sphere mesh', ctx, getParams, getElementSphereVisual(ctx.webgl)),
  16. }
  17. export const SpacefillParams = {
  18. ...ElementSphereParams,
  19. unitKinds: PD.MultiSelect<UnitKind>(['atomic', 'spheres'], UnitKindOptions),
  20. }
  21. export type SpacefillParams = typeof SpacefillParams
  22. export function getSpacefillParams(ctx: ThemeRegistryContext, structure: Structure) {
  23. return PD.clone(SpacefillParams)
  24. }
  25. export type SpacefillRepresentation = StructureRepresentation<SpacefillParams>
  26. export function SpacefillRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, SpacefillParams>): SpacefillRepresentation {
  27. return Representation.createMulti('Spacefill', ctx, getParams, StructureRepresentationStateBuilder, SpacefillVisuals as unknown as Representation.Def<Structure, SpacefillParams>)
  28. }
  29. export const SpacefillRepresentationProvider: StructureRepresentationProvider<SpacefillParams> = {
  30. label: 'Spacefill',
  31. description: 'Displays atomic/coarse elements as spheres.',
  32. factory: SpacefillRepresentation,
  33. getParams: getSpacefillParams,
  34. defaultValues: PD.getDefaultValues(SpacefillParams),
  35. defaultColorTheme: 'element-symbol',
  36. defaultSizeTheme: 'physical'
  37. }