builder.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 function atomName(s: string) { return struct.type.atomName([s]); }
  13. export function es(s: string) { return struct.type.elementSymbol([s]); }
  14. export function list(...xs: Expression[]) { return core.type.list(xs); }
  15. export function set(...xs: Expression[]) { return core.type.set(xs); }
  16. export function fn(x: Expression) { return core.ctrl.fn([x]); }
  17. export function evaluate(x: Expression) { return core.ctrl.eval([x]); }
  18. const _acp = struct.atomProperty.core, _ammp = struct.atomProperty.macromolecular, _atp = struct.atomProperty.topology;
  19. // atom core property
  20. export function acp(p: keyof typeof _acp) { return (_acp[p] as MSymbol<any>)() };
  21. // atom topology property
  22. export function atp(p: keyof typeof _atp) { return (_atp[p] as MSymbol<any>)() };
  23. // atom macromolecular property
  24. export function ammp(p: keyof typeof _ammp) { return (_ammp[p] as MSymbol<any>)() };
  25. // atom property sets
  26. const _aps = struct.atomSet.propertySet
  27. export function acpSet(p: keyof typeof _acp) { return _aps([ acp(p) ]) };
  28. export function atpSet(p: keyof typeof _atp) { return _aps([ atp(p) ]) };
  29. export function ammpSet(p: keyof typeof _ammp) { return _aps([ ammp(p) ]) };
  30. }