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. const SpacefillVisuals = {
  14. 'element-sphere': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, ElementSphereParams>) => UnitsRepresentation('Sphere mesh', ctx, getParams, getElementSphereVisual(ctx.webgl)),
  15. }
  16. export const SpacefillParams = {
  17. ...ElementSphereParams,
  18. }
  19. export type SpacefillParams = typeof SpacefillParams
  20. export function getSpacefillParams(ctx: ThemeRegistryContext, structure: Structure) {
  21. return PD.clone(SpacefillParams)
  22. }
  23. export type SpacefillRepresentation = StructureRepresentation<SpacefillParams>
  24. export function SpacefillRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, SpacefillParams>): SpacefillRepresentation {
  25. return Representation.createMulti('Spacefill', ctx, getParams, StructureRepresentationStateBuilder, SpacefillVisuals as unknown as Representation.Def<Structure, SpacefillParams>)
  26. }
  27. export const SpacefillRepresentationProvider = StructureRepresentationProvider({
  28. name: 'spacefill',
  29. label: 'Spacefill',
  30. description: 'Displays atomic/coarse elements as spheres.',
  31. factory: SpacefillRepresentation,
  32. getParams: getSpacefillParams,
  33. defaultValues: PD.getDefaultValues(SpacefillParams),
  34. defaultColorTheme: { name: 'element-symbol' },
  35. defaultSizeTheme: { name: 'physical' },
  36. isApplicable: (structure: Structure) => structure.elementCount > 0
  37. })