builder.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Copyright (c) 2018 Mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { Expression } from './expression';
  7. import { MSymbol } from './symbol';
  8. import { MolScriptSymbolTable as SymbolTable } from './symbol-table';
  9. export namespace MolScriptBuilder {
  10. export const core = SymbolTable.core;
  11. export const struct = SymbolTable.structureQuery;
  12. export const internal = SymbolTable.internal;
  13. /** Atom-name constructor */
  14. export function atomName(s: string) { return struct.type.atomName([s]); }
  15. /** Element-symbol constructor */
  16. export function es(s: string) { return struct.type.elementSymbol([s]); }
  17. /** List constructor */
  18. export function list(...xs: Expression[]) { return core.type.list(xs); }
  19. /** Set constructor */
  20. export function set(...xs: Expression[]) { return core.type.set(xs); }
  21. /** RegEx constructor */
  22. export function re(pattern: string, flags?: string) { return core.type.regex([pattern, flags]); }
  23. /** Function constructor */
  24. export function fn(x: Expression) { return core.ctrl.fn([x]); }
  25. export function evaluate(x: Expression) { return core.ctrl.eval([x]); }
  26. const _acp = struct.atomProperty.core, _ammp = struct.atomProperty.macromolecular, _atp = struct.atomProperty.topology;
  27. /** atom core property */
  28. export function acp(p: keyof typeof _acp) { return (_acp[p] as MSymbol<any>)(); };
  29. /** atom topology property */
  30. export function atp(p: keyof typeof _atp) { return (_atp[p] as MSymbol<any>)(); };
  31. /** atom macromolecular property */
  32. export function ammp(p: keyof typeof _ammp) { return (_ammp[p] as MSymbol<any>)(); };
  33. const _aps = struct.atomSet.propertySet;
  34. /** atom core property set */
  35. export function acpSet(p: keyof typeof _acp) { return _aps([acp(p)]); };
  36. /** atom topology property set */
  37. export function atpSet(p: keyof typeof _atp) { return _aps([atp(p)]); };
  38. /** atom macromolecular property set */
  39. export function ammpSet(p: keyof typeof _ammp) { return _aps([ammp(p)]); };
  40. }