physical.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 { StructureElement, Unit, Link, ElementIndex } from 'mol-model/structure';
  7. import { Location } from 'mol-model/location';
  8. import { SizeTheme } from '../size';
  9. import { VdwRadius } from 'mol-model/structure/model/properties/atomic';
  10. import { ParamDefinition as PD } from 'mol-util/param-definition'
  11. import { ThemeDataContext } from 'mol-theme/theme';
  12. const DefaultSize = 1
  13. const Description = 'Assigns a physical size.'
  14. export const PhysicalSizeThemeParams = {}
  15. export type PhysicalSizeThemeParams = typeof PhysicalSizeThemeParams
  16. export function getPhysicalSizeThemeParams(ctx: ThemeDataContext) {
  17. return PhysicalSizeThemeParams // TODO return copy
  18. }
  19. export function getPhysicalRadius(unit: Unit, element: ElementIndex): number {
  20. if (Unit.isAtomic(unit)) {
  21. return VdwRadius(unit.model.atomicHierarchy.atoms.type_symbol.value(element))
  22. } else if (Unit.isSpheres(unit)) {
  23. return unit.model.coarseConformation.spheres.radius[element]
  24. } else {
  25. return 0
  26. }
  27. }
  28. /**
  29. * Create attribute data with the physical size of an element,
  30. * i.e. vdw for atoms and radius for coarse spheres
  31. */
  32. export function PhysicalSizeTheme(ctx: ThemeDataContext, props: PD.Values<PhysicalSizeThemeParams>): SizeTheme<PhysicalSizeThemeParams> {
  33. function size(location: Location): number {
  34. let size: number
  35. if (StructureElement.isLocation(location)) {
  36. size = getPhysicalRadius(location.unit, location.element)
  37. } else if (Link.isLocation(location)) {
  38. size = getPhysicalRadius(location.aUnit, location.aUnit.elements[location.aIndex])
  39. } else {
  40. size = DefaultSize
  41. }
  42. return size
  43. }
  44. return {
  45. factory: PhysicalSizeTheme,
  46. granularity: 'group',
  47. size,
  48. props,
  49. description: Description
  50. }
  51. }
  52. export const PhysicalSizeThemeProvider: SizeTheme.Provider<PhysicalSizeThemeParams> = {
  53. label: 'Physical',
  54. factory: PhysicalSizeTheme,
  55. getParams: getPhysicalSizeThemeParams,
  56. defaultValues: PD.getDefaultValues(PhysicalSizeThemeParams)
  57. }