internal.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { Segmentation } from '../../../../mol-data/int';
  7. import StructureElement from '../../../../mol-model/structure/structure/element';
  8. import { StructureProperties as P, Unit } from '../../structure';
  9. import Structure from '../../structure/structure';
  10. import { StructureQuery } from '../query';
  11. import { StructureSelection } from '../selection';
  12. import { QueryContext } from '../context';
  13. import { LinkType } from '../../model/types';
  14. export function defaultLinkTest(ctx: QueryContext) {
  15. return LinkType.isCovalent(ctx.atomicLink.type);
  16. }
  17. export function atomicSequence(): StructureQuery {
  18. return ctx => {
  19. const { inputStructure } = ctx;
  20. const l = StructureElement.create();
  21. const units: Unit[] = [];
  22. for (const unit of inputStructure.units) {
  23. if (unit.kind !== Unit.Kind.Atomic) continue;
  24. l.unit = unit;
  25. const elements = unit.elements;
  26. l.element = elements[0];
  27. if (P.entity.type(l) !== 'polymer') continue;
  28. const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, elements);
  29. let residueCount = 0;
  30. while (residuesIt.hasNext) {
  31. residueCount++;
  32. residuesIt.move();
  33. }
  34. if (residueCount < 8) continue;
  35. units.push(unit);
  36. }
  37. return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure, ));
  38. };
  39. }
  40. export function water(): StructureQuery {
  41. return ctx => {
  42. const { inputStructure } = ctx;
  43. const l = StructureElement.create();
  44. const units: Unit[] = [];
  45. for (const unit of inputStructure.units) {
  46. if (unit.kind !== Unit.Kind.Atomic) continue;
  47. l.unit = unit;
  48. const elements = unit.elements;
  49. l.element = elements[0];
  50. if (P.entity.type(l) !== 'water') continue;
  51. units.push(unit);
  52. }
  53. return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure));
  54. };
  55. }
  56. export function atomicHet(): StructureQuery {
  57. return ctx => {
  58. const { inputStructure } = ctx;
  59. const l = StructureElement.create();
  60. const units: Unit[] = [];
  61. for (const unit of inputStructure.units) {
  62. if (unit.kind !== Unit.Kind.Atomic) continue;
  63. l.unit = unit;
  64. const elements = unit.elements;
  65. l.element = elements[0];
  66. if (P.entity.type(l) === 'water') continue;
  67. if (P.entity.type(l) === 'polymer') {
  68. const residuesIt = Segmentation.transientSegments(unit.model.atomicHierarchy.residueAtomSegments, elements);
  69. let residueCount = 0;
  70. while (residuesIt.hasNext) {
  71. residueCount++;
  72. residuesIt.move();
  73. }
  74. if (residueCount >= 8) continue;
  75. }
  76. units.push(unit);
  77. }
  78. return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure));
  79. };
  80. }
  81. export function spheres(): StructureQuery {
  82. return ctx => {
  83. const { inputStructure } = ctx;
  84. const units: Unit[] = [];
  85. for (const unit of inputStructure.units) {
  86. if (unit.kind !== Unit.Kind.Spheres) continue;
  87. units.push(unit);
  88. }
  89. return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure));
  90. };
  91. }