operators.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  4. * @author Panagiotis Tourlas <panagiot_tourlov@hotmail.com>
  5. *
  6. * @author Koya Sakuma
  7. * This module is based on jmol transpiler from MolQL and modified in similar manner as pymol and vmd tranpilers. \
  8. */
  9. import * as P from '../../../mol-util/monadic-parser';
  10. import * as h from '../helper';
  11. import { MolScriptBuilder } from '../../../mol-script/language/builder';
  12. const B = MolScriptBuilder;
  13. import { OperatorList } from '../types';
  14. import { Expression } from '../../language/expression';
  15. export const operators: OperatorList = [
  16. {
  17. '@desc': 'Selects atoms that are not included in s1.',
  18. '@examples': ['not ARG'],
  19. name: 'not',
  20. type: h.prefix,
  21. rule: P.MonadicParser.alt(P.MonadicParser.regex(/NOT/i).skip(P.MonadicParser.whitespace), P.MonadicParser.string('!').skip(P.MonadicParser.optWhitespace)),
  22. map: (op, selection) => h.invertExpr(selection),
  23. },
  24. {
  25. '@desc': 'Selects atoms included in both s1 and s2.',
  26. '@examples': ['ASP and .CA'],
  27. name: 'and',
  28. type: h.binaryLeft,
  29. rule: h.infixOp(/AND|&/i),
  30. map: (op, selection, by) => B.struct.modifier.intersectBy({ 0: selection, by })
  31. },
  32. {
  33. '@desc': 'Selects atoms included in either s1 or s2.',
  34. '@examples': ['ASP or GLU'],
  35. name: 'or',
  36. type: h.binaryLeft,
  37. rule: h.infixOp(/OR|\||\|\|/i),
  38. map: (op, s1, s2) => B.struct.combinator.merge([s1, s2])
  39. },
  40. {
  41. '@desc': 'Selects atoms within a specified distance of a selection',
  42. '@examples': ['within 5 of name FE'],
  43. name: 'within',
  44. type: h.prefix,
  45. rule: h.prefixOp(/within\s+([-+]?[0-9]*\.?[0-9]+)\s+of/, 1).map((x: any) => parseFloat(x)),
  46. map: (radius: number, selection: Expression) => {
  47. return B.struct.modifier.includeSurroundings({ 0: selection, radius });
  48. }
  49. },
  50. ];