interactions.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { ParamDefinition as PD } from '../../../mol-util/param-definition';
  7. import { Representation, RepresentationParamsGetter, RepresentationContext } from '../../../mol-repr/representation';
  8. import { ThemeRegistryContext } from '../../../mol-theme/theme';
  9. import { Structure } from '../../../mol-model/structure';
  10. import { UnitsRepresentation, StructureRepresentation, StructureRepresentationStateBuilder, StructureRepresentationProvider, ComplexRepresentation } from '../../../mol-repr/structure/representation';
  11. import { InteractionsIntraUnitParams, InteractionsIntraUnitVisual } from './interactions-intra-unit-cylinder';
  12. import { InteractionsProvider } from '../interactions';
  13. import { InteractionsInterUnitParams, InteractionsInterUnitVisual } from './interactions-inter-unit-cylinder';
  14. import { CustomProperty } from '../../common/custom-property';
  15. import { getUnitKindsParam } from '../../../mol-repr/structure/params';
  16. const InteractionsVisuals = {
  17. 'intra-unit': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, InteractionsIntraUnitParams>) => UnitsRepresentation('Intra-unit interactions cylinder', ctx, getParams, InteractionsIntraUnitVisual),
  18. 'inter-unit': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, InteractionsInterUnitParams>) => ComplexRepresentation('Inter-unit interactions cylinder', ctx, getParams, InteractionsInterUnitVisual),
  19. };
  20. export const InteractionsParams = {
  21. ...InteractionsIntraUnitParams,
  22. ...InteractionsInterUnitParams,
  23. unitKinds: getUnitKindsParam(['atomic']),
  24. sizeFactor: PD.Numeric(0.2, { min: 0.01, max: 1, step: 0.01 }),
  25. visuals: PD.MultiSelect(['intra-unit', 'inter-unit'], PD.objectToOptions(InteractionsVisuals)),
  26. };
  27. export type InteractionsParams = typeof InteractionsParams
  28. export function getInteractionParams(ctx: ThemeRegistryContext, structure: Structure) {
  29. return PD.clone(InteractionsParams);
  30. }
  31. export type InteractionRepresentation = StructureRepresentation<InteractionsParams>
  32. export function InteractionRepresentation(ctx: RepresentationContext, getParams: RepresentationParamsGetter<Structure, InteractionsParams>): InteractionRepresentation {
  33. return Representation.createMulti('Interactions', ctx, getParams, StructureRepresentationStateBuilder, InteractionsVisuals as unknown as Representation.Def<Structure, InteractionsParams>);
  34. }
  35. export const InteractionsRepresentationProvider = StructureRepresentationProvider({
  36. name: 'interactions',
  37. label: 'Non-covalent Interactions',
  38. description: 'Displays non-covalent interactions as dashed cylinders.',
  39. factory: InteractionRepresentation,
  40. getParams: getInteractionParams,
  41. defaultValues: PD.getDefaultValues(InteractionsParams),
  42. defaultColorTheme: { name: 'interaction-type' },
  43. defaultSizeTheme: { name: 'uniform' },
  44. isApplicable: (structure: Structure) => structure.elementCount > 0 && InteractionsProvider.isApplicable(structure),
  45. ensureCustomProperties: {
  46. attach: (ctx: CustomProperty.Context, structure: Structure) => InteractionsProvider.attach(ctx, structure, void 0, true),
  47. detach: (data) => InteractionsProvider.ref(data, false)
  48. },
  49. getData: (structure: Structure, props: PD.Values<InteractionsParams>) => {
  50. return props.includeParent ? structure.asParent() : structure;
  51. },
  52. mustRecreate: (oldProps: PD.Values<InteractionsParams>, newProps: PD.Values<InteractionsParams>) => {
  53. return oldProps.includeParent !== newProps.includeParent;
  54. }
  55. });