prop.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. /**
  8. * Copyright (C) 2022, Protein Bioinformatics Research Group, RCNS
  9. *
  10. * Licensed under CC BY-NC 4.0, see LICENSE file for more info.
  11. *
  12. * @author Gabor Tusnady <tusnady.gabor@ttk.hu>
  13. * @author Csongor Gerdan <gerdan.csongor@ttk.hu>
  14. */
  15. import { ParamDefinition as PD } from 'molstar/lib/mol-util/param-definition';
  16. import { Structure, StructureProperties, Unit } from 'molstar/lib/mol-model/structure';
  17. import { CustomPropertyDescriptor } from 'molstar/lib/mol-model/custom-property';
  18. import { isInMembranePlane, TMDETParams } from './algorithm';
  19. import { CustomStructureProperty } from 'molstar/lib/mol-model-props/common/custom-structure-property';
  20. import { CustomProperty } from 'molstar/lib/mol-model-props/common/custom-property';
  21. import { Vec3 } from 'molstar/lib/mol-math/linear-algebra';
  22. import { QuerySymbolRuntime } from 'molstar/lib/mol-script/runtime/query/base';
  23. import { CustomPropSymbol } from 'molstar/lib/mol-script/language/symbol';
  24. import { Type } from 'molstar/lib/mol-script/language/type';
  25. import { membraneOrientation } from './behavior';
  26. import { ChainList, PDBTMDescriptor } from './types';
  27. export const MembraneOrientationParams = {
  28. ...TMDETParams
  29. };
  30. export type MembraneOrientationParams = typeof MembraneOrientationParams
  31. export type MembraneOrientationProps = PD.Values<MembraneOrientationParams>
  32. export { MembraneOrientation };
  33. /**
  34. * Simple storage to made PDBTM descriptor available globally.
  35. *
  36. * @author Csongor Gerdan <gerdan.csongor@ttk.hu>
  37. */
  38. class DescriptorCache {
  39. private map: Map<string, PDBTMDescriptor>;
  40. constructor() {
  41. this.map = new Map<string, PDBTMDescriptor>();
  42. }
  43. add(descriptor: PDBTMDescriptor) {
  44. const key = descriptor.pdb_id.toLowerCase();
  45. if (!this.map.has(key)) {
  46. this.map.set(key, descriptor);
  47. }
  48. }
  49. get(key: string) {
  50. key = key.toLowerCase();
  51. return this.map.get(key);
  52. }
  53. }
  54. export const TmDetDescriptorCache = new DescriptorCache();
  55. class ChainListCache {
  56. private map: Map<string, ChainList>;
  57. constructor() {
  58. this.map = new Map<string, ChainList>();
  59. }
  60. set(key: string, chains: ChainList) {
  61. key = key.toLowerCase();
  62. if (!this.map.has(key)) {
  63. this.map.set(key, chains);
  64. }
  65. }
  66. get(key: string) {
  67. key = key.toLowerCase();
  68. return this.map.get(key);
  69. }
  70. }
  71. export const TmDetChainListCache = new ChainListCache();
  72. interface MembraneOrientation {
  73. // point in membrane boundary
  74. readonly planePoint1: Vec3,
  75. // point in opposite side of membrane boundary
  76. readonly planePoint2: Vec3,
  77. // normal vector of membrane layer
  78. readonly normalVector: Vec3,
  79. // the radius of the membrane layer
  80. readonly radius: number,
  81. readonly centroid: Vec3
  82. }
  83. namespace MembraneOrientation {
  84. export enum Tag {
  85. Representation = 'membrane-orientation-3d'
  86. }
  87. const pos = Vec3();
  88. export const symbols = {
  89. isTransmembrane: QuerySymbolRuntime.Dynamic(CustomPropSymbol('computed', 'membrane-orientation.is-transmembrane', Type.Bool),
  90. ctx => {
  91. const { unit, structure } = ctx.element;
  92. const { x, y, z } = StructureProperties.atom;
  93. if (!Unit.isAtomic(unit)) return 0;
  94. const membraneOrientation = MembraneOrientationProvider.get(structure).value;
  95. if (!membraneOrientation) return 0;
  96. Vec3.set(pos, x(ctx.element), y(ctx.element), z(ctx.element));
  97. const { normalVector, planePoint1, planePoint2 } = membraneOrientation;
  98. return isInMembranePlane(pos, normalVector, planePoint1, planePoint2);
  99. })
  100. };
  101. }
  102. export const MembraneOrientationProvider: CustomStructureProperty.Provider<MembraneOrientationParams, MembraneOrientation> = CustomStructureProperty.createProvider({
  103. label: 'TMDET Membrane Orientation Provider',
  104. descriptor: CustomPropertyDescriptor({
  105. name: 'tmdet_computed_membrane_orientation',
  106. symbols: MembraneOrientation.symbols,
  107. // TODO `cifExport`
  108. }),
  109. type: 'root',
  110. defaultParams: MembraneOrientationParams,
  111. // getParams: (data: Structure) => MembraneOrientationParams,
  112. getParams: function(data: Structure) {
  113. //DebugUtil.log('getParams:: DEBUG', MembraneOrientationParams);
  114. return MembraneOrientationParams;
  115. },
  116. isApplicable: (data: Structure) => true,
  117. obtain: async (ctx: CustomProperty.Context, data: Structure, props: Partial<MembraneOrientationProps>) => {
  118. //DebugUtil.log('obtain:: DEBUG', data.customPropertyDescriptors);
  119. let result = membraneOrientation;
  120. //DebugUtil.log("RESULT of 'obtain:'", result);
  121. return { value: result };
  122. }
  123. });