operators.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Koya Sakuma <koya.sakuma.work@gmail.com>
  5. */
  6. import * as P from '../../../mol-util/monadic-parser';
  7. import * as h from '../helper';
  8. import { MolScriptBuilder } from '../../../mol-script/language/builder';
  9. const B = MolScriptBuilder;
  10. import { OperatorList } from '../types';
  11. import { Expression } from '../../language/expression';
  12. export const operators: OperatorList = [
  13. {
  14. '@desc': 'Selects atoms in s1 that are within X Angstroms of any atom in s2.',
  15. '@examples': ['within(5.0, [HEM])'],
  16. name: 'within',
  17. type: h.prefixRemoveKet,
  18. rule: h.prefixOpNoWhiteSpace(/within\s*\(\s*([-+]?[0-9]*\.?[0-9]+)\s*,/, 1).map((x: any) => {
  19. return parseFloat(x);
  20. }),
  21. map: (radius: number, target: Expression) => {
  22. return B.struct.filter.within({
  23. 0: B.struct.generator.all(),
  24. target,
  25. 'max-radius': radius,
  26. });
  27. },
  28. },
  29. {
  30. '@desc': 'Selects atoms that are not included in s1.',
  31. '@examples': ['not [ARG]'],
  32. name: 'not',
  33. type: h.prefix,
  34. rule: P.MonadicParser.alt(P.MonadicParser.regex(/NOT/i).skip(P.MonadicParser.whitespace), P.MonadicParser.string('!').skip(P.MonadicParser.optWhitespace)),
  35. map: (op, selection) => h.invertExpr(selection),
  36. },
  37. {
  38. '@desc': 'Selects atoms included in both s1 and s2.',
  39. '@examples': ['[ASP] and :.CA'],
  40. name: 'and',
  41. type: h.binaryLeft,
  42. rule: P.MonadicParser.alt(h.infixOp(/AND|&/i)),
  43. map: (op, selection, by) => B.struct.modifier.intersectBy({ 0: selection, by })
  44. },
  45. {
  46. '@desc': 'Selects atoms included in either s1 or s2.',
  47. '@examples': ['[ASP] or [GLU]'],
  48. name: 'or',
  49. abbr: [','],
  50. type: h.binaryLeft,
  51. rule: P.MonadicParser.alt(h.infixOp(/OR|\||\|\||,/i)),
  52. map: (op, s1, s2) => B.struct.combinator.merge([s1, s2])
  53. },
  54. ];