point.ts 2.0 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 { ElementPointVisual, ElementPointParams } from '../visual/element-point';
  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 { Representation, RepresentationParamsGetter, RepresentationContext } from '../../../mol-repr/representation';
  11. import { ThemeRegistryContext } from '../../../mol-theme/theme';
  12. import { Structure } from '../../../mol-model/structure';
  13. const PointVisuals = {
  14. 'element-point': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, ElementPointParams>) => UnitsRepresentation('Points', ctx, getParams, ElementPointVisual),
  15. }
  16. export const PointParams = {
  17. ...ElementPointParams,
  18. }
  19. export type PointParams = typeof PointParams
  20. export function getPointParams(ctx: ThemeRegistryContext, structure: Structure) {
  21. return PD.clone(PointParams)
  22. }
  23. export type PointRepresentation = StructureRepresentation<PointParams>
  24. export function PointRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, PointParams>): PointRepresentation {
  25. return Representation.createMulti('Point', ctx, getParams, StructureRepresentationStateBuilder, PointVisuals as unknown as Representation.Def<Structure, PointParams>)
  26. }
  27. export const PointRepresentationProvider = StructureRepresentationProvider({
  28. name: 'point',
  29. label: 'Point',
  30. description: 'Displays elements (atoms, coarse spheres) as spheres.',
  31. factory: PointRepresentation,
  32. getParams: getPointParams,
  33. defaultValues: PD.getDefaultValues(PointParams),
  34. defaultColorTheme: { name: 'element-symbol' },
  35. defaultSizeTheme: { name: 'physical' },
  36. isApplicable: (structure: Structure) => structure.elementCount > 0
  37. })