spacefill.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Copyright (c) 2018-2021 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 { 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, ElementSphereVisual),
  15. };
  16. export const SpacefillParams = {
  17. ...ElementSphereParams,
  18. };
  19. export type SpacefillParams = typeof SpacefillParams
  20. export function getSpacefillParams(ctx: ThemeRegistryContext, structure: Structure) {
  21. const params = PD.clone(SpacefillParams);
  22. if (structure.isCoarseGrained) {
  23. params.sizeFactor.defaultValue = 2;
  24. }
  25. return params;
  26. }
  27. export type SpacefillRepresentation = StructureRepresentation<SpacefillParams>
  28. export function SpacefillRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, SpacefillParams>): SpacefillRepresentation {
  29. return Representation.createMulti('Spacefill', ctx, getParams, StructureRepresentationStateBuilder, SpacefillVisuals as unknown as Representation.Def<Structure, SpacefillParams>);
  30. }
  31. export const SpacefillRepresentationProvider = StructureRepresentationProvider({
  32. name: 'spacefill',
  33. label: 'Spacefill',
  34. description: 'Displays atomic/coarse elements as spheres.',
  35. factory: SpacefillRepresentation,
  36. getParams: getSpacefillParams,
  37. defaultValues: PD.getDefaultValues(SpacefillParams),
  38. defaultColorTheme: { name: 'element-symbol' },
  39. defaultSizeTheme: { name: 'physical' },
  40. isApplicable: (structure: Structure) => structure.elementCount > 0
  41. });