atom-set.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Koya Sakuma
  5. * Adapted from MolQL implemtation of atom-set.ts
  6. *
  7. * Copyright (c) 2017 MolQL contributors, licensed under MIT, See LICENSE file for more info.
  8. *
  9. * @author David Sehnal <david.sehnal@gmail.com>
  10. */
  11. /*
  12. import Environment from '../environment'
  13. import Expression from '../expression'
  14. import Context from '../context'
  15. import AtomSet from '../../data/atom-set'
  16. import AtomSelection from '../../data/atom-selection'
  17. import ElementAddress from '../../data/element-address'
  18. import { FastSet } from '../../../utils/collections'
  19. import { getAtomSetProperties } from './filters'
  20. */
  21. import { StructureQuery} from '../query';
  22. import { StructureSelection } from '../selection';
  23. //import { getCurrentStructurePropertiesInternal, UnitTypeProperties } from './filters';
  24. import { getCurrentStructurePropertiesInternal} from './filters';
  25. import { QueryContext, QueryFn } from '../context';
  26. // import { none } from './generators';
  27. // import { HashSet } from '../../../../mol-data/generic';
  28. // import { Structure } from '../../structure';
  29. /*
  30. import { SetUtils } from '../../../../mol-util/set';
  31. import { Unit } from '../../structure';
  32. import { QueryContext, QueryFn, QueryPredicate } from '../context';
  33. import { StructureQuery } from '../query';
  34. import { StructureSelection } from '../selection';
  35. import { structureAreIntersecting } from '../utils/structure-set';
  36. import { Vec3 } from '../../../../mol-math/linear-algebra';
  37. import { checkStructureMaxRadiusDistance, checkStructureMinMaxDistance } from '../utils/structure-distance';
  38. import { Structure } from '../../structure/structure';
  39. import { StructureElement } from '../../structure/element';
  40. import { SortedArray } from '../../../../mol-data/int';
  41. */
  42. /*
  43. export function pick(query: StructureQuery, pred: QueryPredicate): StructureQuery {
  44. return ctx => {
  45. const sel = query(ctx);
  46. const ret = StructureSelection.LinearBuilder(ctx.inputStructure);
  47. ctx.pushCurrentElement();
  48. StructureSelection.forEach(sel, (s, i) => {
  49. ctx.currentStructure = s;
  50. if (pred(ctx)) ret.add(s);
  51. if (i % 100) ctx.throwIfTimedOut();
  52. });
  53. ctx.popCurrentStructure();
  54. return ret.getSelection();
  55. };
  56. }
  57. export function pick(env: Environment, selection: Selection, pred: Expression<boolean>) {
  58. const sel = selection(env);
  59. const ret = AtomSelection.linearBuilder();
  60. Environment.lockSlot(env, 'atomSet');
  61. const { slots } = env;
  62. for (const atomSet of AtomSelection.atomSets(sel)) {
  63. slots.atomSet = atomSet;
  64. if (pred(env)) ret.add(atomSet);
  65. }
  66. Environment.unlockSlot(env, 'atomSet');
  67. return ret.getSelection();
  68. }
  69. */
  70. // xport function merge(queries: ArrayLike<StructureQuery>): S
  71. // export function atomCount(env: Environment) {
  72. // return AtomSet.count(env.slots.atomSet);
  73. // }
  74. // export function atomCount(query : StructureSelection) : StructureQuery {
  75. // export function atomCount(env: Environment) {
  76. // return AtomSet.count(env.slots.atomSet);
  77. // }
  78. /*
  79. export function atomCount(ctx: QueryContext) {
  80. return (ctx: QueryContext) => {
  81. const all = StructureSelection.Singletons(ctx.inputStructure, ctx.inputStructure)
  82. const x: number = StructureSelection.structureCount(all);
  83. return x;
  84. };
  85. }
  86. */
  87. export function atomCount(ctx: QueryContext) {
  88. return (ctx: QueryContext) => {
  89. const all = StructureSelection.Singletons(ctx.currentStructure, ctx.currentStructure);
  90. const x: number = StructureSelection.structureCount(all);
  91. return x;
  92. };
  93. }
  94. // export function atomCount(ctx: QueryContext) {
  95. // return (ctx: any) => {
  96. // const x: number = StructureSelection.structureCount(ctx);
  97. // return x;
  98. // };
  99. // }
  100. // export function countQuery(env: Environment, query: Expression<AtomSelection>) {
  101. // const sel = query(Environment(Context.ofAtomSet(env.context, env.slots.atomSet)))
  102. // return AtomSelection.atomSets(sel).length;
  103. // }
  104. export function countQuery(ctx: QueryContext, query: StructureQuery) {
  105. return (ctx: QueryContext) => {
  106. const sel = query(ctx);
  107. const x: number = StructureSelection.structureCount(sel);
  108. return x;
  109. };
  110. }
  111. //export function propertySet(ctx: QueryContext, prop: UnitTypeProperties) {
  112. export function propertySet(ctx: QueryContext, prop: QueryFn<any>) {
  113. return (ctx: QueryContext) => {
  114. const set = new Set();
  115. const x = getCurrentStructurePropertiesInternal(ctx, prop, set);
  116. // console.log(x)
  117. return x;
  118. };
  119. }
  120. /*
  121. unction getSelectionProperties(ctx: QueryContext, query: StructureQuery, props: UnitTypeProperties) {
  122. const sel = query(ctx);
  123. ctx.pushCurrentElement();
  124. StructureSelection.forEach(sel, (s, i) => {
  125. ctx.currentStructure = s;
  126. getCurrentStructureProperties(ctx, props, set);
  127. if (i % 10) ctx.throwIfTimedOut();
  128. });
  129. ctx.popCurrentElement();
  130. return set;
  131. */