diff --git a/src/mol-script/language/builder.ts b/src/mol-script/language/builder.ts index a4ea6a0931a4b677250f9851997b046aebf848e5..213b47a7af669e630ed9416806e15a0fdf8f3e43 100644 --- a/src/mol-script/language/builder.ts +++ b/src/mol-script/language/builder.ts @@ -5,7 +5,7 @@ */ import Expression from './expression' -import { Symbol } from './symbol' +import { MSymbol } from './symbol' import SymbolTable from './symbol-table' namespace Builder { @@ -22,13 +22,13 @@ namespace Builder { const _acp = struct.atomProperty.core, _ammp = struct.atomProperty.macromolecular, _atp = struct.atomProperty.topology; // atom core property - export function acp(p: keyof typeof _acp) { return (_acp[p] as Symbol<any>)() }; + export function acp(p: keyof typeof _acp) { return (_acp[p] as MSymbol<any>)() }; // atom topology property - export function atp(p: keyof typeof _atp) { return (_atp[p] as Symbol<any>)() }; + export function atp(p: keyof typeof _atp) { return (_atp[p] as MSymbol<any>)() }; // atom macromolecular property - export function ammp(p: keyof typeof _ammp) { return (_ammp[p] as Symbol<any>)() }; + export function ammp(p: keyof typeof _ammp) { return (_ammp[p] as MSymbol<any>)() }; // atom property sets const _aps = struct.atomSet.propertySet diff --git a/src/mol-script/language/helpers.ts b/src/mol-script/language/helpers.ts index 9b384a2f87b847b6b8dc9f2f17c4429595a0acda..926cb216c211e90251628a8052605d896d6d4fbc 100644 --- a/src/mol-script/language/helpers.ts +++ b/src/mol-script/language/helpers.ts @@ -5,18 +5,18 @@ */ import Type from './type' -import { Symbol, Arguments, isSymbol } from './symbol' +import { MSymbol, Arguments, isSymbol } from './symbol' export function symbol<A extends Arguments, T extends Type<S>, S>(args: A, type: T, description?: string) { - return Symbol('', args, type, description); + return MSymbol('', args, type, description); } export function normalizeTable(table: any) { _normalizeTable('', '', table); } -export function symbolList(table: any): Symbol[] { - const list: Symbol[] = []; +export function symbolList(table: any): MSymbol[] { + const list: MSymbol[] = []; _symbolList(table, list); return list; } @@ -42,7 +42,7 @@ function _normalizeTable(namespace: string, key: string, obj: any) { } } -function _symbolList(obj: any, list: Symbol[]) { +function _symbolList(obj: any, list: MSymbol[]) { if (isSymbol(obj)) { list.push(obj); return; diff --git a/src/mol-script/language/symbol-table.ts b/src/mol-script/language/symbol-table.ts index cfdb112a32415a4f47b45811cdbc223b993a43dd..6f47d15d9cef2872174dc4376b35eff27dc749dd 100644 --- a/src/mol-script/language/symbol-table.ts +++ b/src/mol-script/language/symbol-table.ts @@ -7,7 +7,7 @@ import core from './symbol-table/core' import structureQuery from './symbol-table/structure-query' import { normalizeTable, symbolList } from './helpers' -import { Symbol } from './symbol' +import { MSymbol } from './symbol' const table = { core, structureQuery }; @@ -16,7 +16,7 @@ normalizeTable(table); export const SymbolList = symbolList(table); export const SymbolMap = (function() { - const map: { [id: string]: Symbol | undefined } = Object.create(null); + const map: { [id: string]: MSymbol | undefined } = Object.create(null); for (const s of SymbolList) map[s.id] = s; return map; })(); diff --git a/src/mol-script/language/symbol-table/core.ts b/src/mol-script/language/symbol-table/core.ts index c0bcac64f6d638ca0ace61f197974e1034a9d48e..b4164f6133e2e580cbbb3d1a7f437391566742e3 100644 --- a/src/mol-script/language/symbol-table/core.ts +++ b/src/mol-script/language/symbol-table/core.ts @@ -5,7 +5,7 @@ */ import Type from '../type' -import { Symbol, Arguments, Argument } from '../symbol' +import { MSymbol, Arguments, Argument } from '../symbol' import { symbol, normalizeTable, symbolList } from '../helpers' export namespace Types { @@ -174,7 +174,7 @@ normalizeTable(table); export const SymbolList = symbolList(table); export const SymbolMap = (function() { - const map: { [id: string]: Symbol | undefined } = Object.create(null); + const map: { [id: string]: MSymbol | undefined } = Object.create(null); for (const s of SymbolList) map[s.id] = s; return map; })(); diff --git a/src/mol-script/language/symbol.ts b/src/mol-script/language/symbol.ts index d6c2dbe33a2e8826c9c4a087797893af0cf3ccb2..c928809b91c619afc49d8142ab44ca05ecf985a2 100644 --- a/src/mol-script/language/symbol.ts +++ b/src/mol-script/language/symbol.ts @@ -50,7 +50,7 @@ export namespace Arguments { export type ExpressionArguments<T> = { [P in keyof T]?: Expression } | { [index: number]: Expression } -export interface Symbol<A extends Arguments = Arguments, T extends Type = Type> { +export interface MSymbol<A extends Arguments = Arguments, T extends Type = Type> { (args?: ExpressionArguments<A['@type']>): Expression, info: { namespace: string, @@ -62,8 +62,8 @@ export interface Symbol<A extends Arguments = Arguments, T extends Type = Type> id: string, } -export function Symbol<A extends Arguments, T extends Type>(name: string, args: A, type: T, description?: string) { - const symbol: Symbol<A, T> = function(args: ExpressionArguments<A['@type']>) { +export function MSymbol<A extends Arguments, T extends Type>(name: string, args: A, type: T, description?: string) { + const symbol: MSymbol<A, T> = function(args: ExpressionArguments<A['@type']>) { return Expression.Apply(Expression.Symbol(symbol.id), args as any); } as any; symbol.info = { namespace: '', name, description }; @@ -73,10 +73,10 @@ export function Symbol<A extends Arguments, T extends Type>(name: string, args: return symbol; } -export function isSymbol(x: any): x is Symbol { - const s = x as Symbol; +export function isSymbol(x: any): x is MSymbol { + const s = x as MSymbol; return typeof s === 'function' && !!s.info && !!s.args && typeof s.info.namespace === 'string' && !!s.type; } -export type SymbolMap = { [id: string]: Symbol | undefined } +export type SymbolMap = { [id: string]: MSymbol | undefined } diff --git a/src/mol-script/runtime/environment.ts b/src/mol-script/runtime/environment.ts index c969ecdf66b1e95eec8468dbc91ee18345378492..54882d11a24416b72b889d962410aea0ee0e80cb 100644 --- a/src/mol-script/runtime/environment.ts +++ b/src/mol-script/runtime/environment.ts @@ -4,7 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { Symbol } from '../language/symbol' +import { MSymbol } from '../language/symbol' import { SymbolRuntime } from './symbol' import { Macro } from './macro'; import Expression from '../language/expression'; @@ -25,11 +25,11 @@ class Environment { this.macroTable.delete(name); } - addSymbolRuntime(symbol: Symbol, runtime: SymbolRuntime) { + addSymbolRuntime(symbol: MSymbol, runtime: SymbolRuntime) { this.runtimeTable.set(symbol.id, runtime); } - removeSymbolRuntime(symbol: Symbol) { + removeSymbolRuntime(symbol: MSymbol) { this.runtimeTable.delete(symbol.id); } } diff --git a/src/mol-script/script/mol-script/symbols.ts b/src/mol-script/script/mol-script/symbols.ts index 2d25e4338e734d190b8c4ab5dfdb726666a3ad31..dbbf1c5f843acac78b0f53bbf25fdf2409c3a1d9 100644 --- a/src/mol-script/script/mol-script/symbols.ts +++ b/src/mol-script/script/mol-script/symbols.ts @@ -4,7 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { Symbol, Arguments, Argument } from '../../language/symbol' +import { MSymbol, Arguments, Argument } from '../../language/symbol' import B from '../../language/builder' import * as M from './macro' import MolScript from '../../language/symbol-table' @@ -14,11 +14,11 @@ import Expression from '../../language/expression' import { UniqueArray } from 'mol-data/generic' export type MolScriptSymbol = - | { kind: 'alias', aliases: string[], symbol: Symbol } - | { kind: 'macro', aliases: string[], symbol: Symbol, translate: (args: any) => Expression } + | { kind: 'alias', aliases: string[], symbol: MSymbol } + | { kind: 'macro', aliases: string[], symbol: MSymbol, translate: (args: any) => Expression } -function Alias(symbol: Symbol<any>, ...aliases: string[]): MolScriptSymbol { return { kind: 'alias', aliases, symbol }; } -function Macro(symbol: Symbol<any>, translate: (args: any) => Expression, ...aliases: string[]): MolScriptSymbol { +function Alias(symbol: MSymbol<any>, ...aliases: string[]): MolScriptSymbol { return { kind: 'alias', aliases, symbol }; } +function Macro(symbol: MSymbol<any>, translate: (args: any) => Expression, ...aliases: string[]): MolScriptSymbol { symbol.info.namespace = 'molscript-macro'; symbol.id = `molscript-macro.${symbol.info.name}`; return { kind: 'macro', symbol, translate, aliases: [symbol.info.name, ...aliases] }; @@ -105,12 +105,12 @@ export const SymbolTable = [ Alias(MolScript.structureQuery.generator.rings, 'sel.atom.rings'), Alias(MolScript.structureQuery.generator.empty, 'sel.atom.empty'), - Macro(Symbol('sel.atom.atoms', Arguments.Dictionary({ + Macro(MSymbol('sel.atom.atoms', Arguments.Dictionary({ 0: Argument(Type.Bool, { isOptional: true, defaultValue: true, description: 'Test applied to each atom.' }) }), Struct.Types.ElementSelection, 'A selection of singleton atom sets.'), args => B.struct.generator.atomGroups({ 'atom-test': M.tryGetArg(args, 0, true) })), - Macro(Symbol('sel.atom.res', Arguments.Dictionary({ + Macro(MSymbol('sel.atom.res', Arguments.Dictionary({ 0: Argument(Type.Bool, { isOptional: true, defaultValue: true, description: 'Test applied to the 1st atom of each residue.' }) }), Struct.Types.ElementSelection, 'A selection of atom sets grouped by residue.'), args => B.struct.generator.atomGroups({ @@ -118,7 +118,7 @@ export const SymbolTable = [ 'group-by': B.ammp('residueKey') })), - Macro(Symbol('sel.atom.chains', Arguments.Dictionary({ + Macro(MSymbol('sel.atom.chains', Arguments.Dictionary({ 0: Argument(Type.Bool, { isOptional: true, defaultValue: true, description: 'Test applied to the 1st atom of each chain.' }) }), Struct.Types.ElementSelection, 'A selection of atom sets grouped by chain.'), args => B.struct.generator.atomGroups({ @@ -138,7 +138,7 @@ export const SymbolTable = [ Alias(MolScript.structureQuery.modifier.includeConnected, 'sel.atom.include-connected'), Alias(MolScript.structureQuery.modifier.expandProperty, 'sel.atom.expand-property'), - Macro(Symbol('sel.atom.around', Arguments.Dictionary({ + Macro(MSymbol('sel.atom.around', Arguments.Dictionary({ 0: Argument(Type.Bool, { isOptional: true, defaultValue: true, description: 'Test applied to the 1st atom of each chain.' }) }), Struct.Types.ElementSelection, 'A selection of singleton atom sets with centers within "radius" of the center of any atom in the given selection.'), args => B.struct.modifier.exceptBy({ @@ -169,22 +169,22 @@ export const SymbolTable = [ Alias(MolScript.structureQuery.atomSet.reduce, 'atom.set.reduce'), Alias(MolScript.structureQuery.atomSet.propertySet, 'atom.set.property'), - Macro(Symbol('atom.set.max', Arguments.Dictionary({ + Macro(MSymbol('atom.set.max', Arguments.Dictionary({ 0: Argument(Type.Num, { description: 'Numeric atom property.'}) }), Type.Num, 'Maximum of the given property in the current atom set.'), args => M.aggregate(M.tryGetArg(args, 0), B.core.math.max)), - Macro(Symbol('atom.set.sum', Arguments.Dictionary({ + Macro(MSymbol('atom.set.sum', Arguments.Dictionary({ 0: Argument(Type.Num, { description: 'Numeric atom property.'}) }), Type.Num, 'Sum of the given property in the current atom set.'), args => M.aggregate(M.tryGetArg(args, 0), B.core.math.add, 0)), - Macro(Symbol('atom.set.avg', Arguments.Dictionary({ + Macro(MSymbol('atom.set.avg', Arguments.Dictionary({ 0: Argument(Type.Num, { description: 'Numeric atom property.'}) }), Type.Num, 'Average of the given property in the current atom set.'), args => B.core.math.div([ M.aggregate(M.tryGetArg(args, 0), B.core.math.add, 0), B.struct.atomSet.atomCount() ])), - Macro(Symbol('atom.set.min', Arguments.Dictionary({ + Macro(MSymbol('atom.set.min', Arguments.Dictionary({ 0: Argument(Type.Num, { description: 'Numeric atom property.'}) }), Type.Num, 'Minimum of the given property in the current atom set.'), args => M.aggregate(M.tryGetArg(args, 0), B.core.math.min)) @@ -231,14 +231,14 @@ export const SymbolTable = [ Alias(MolScript.structureQuery.atomProperty.macromolecular.isModified, 'atom.is-modified'), Alias(MolScript.structureQuery.atomProperty.macromolecular.modifiedParentName, 'atom.modified-parent'), - Macro(Symbol('atom.sec-struct.is', Arguments.List(Struct.Types.SecondaryStructureFlag), Type.Bool, + Macro(MSymbol('atom.sec-struct.is', Arguments.List(Struct.Types.SecondaryStructureFlag), Type.Bool, `Test if the current atom is part of an secondary structure. Optionally specify allowed sec. struct. types: ${Type.oneOfValues(Struct.Types.SecondaryStructureFlag).join(', ')}`), args => B.core.flags.hasAny([B.struct.atomProperty.macromolecular.secondaryStructureFlags(), B.struct.type.secondaryStructureFlags(args)])), ], [ 'Bond Properties', Alias(MolScript.structureQuery.bondProperty.order, 'bond.order'), - Macro(Symbol('bond.is', Arguments.List(Struct.Types.BondFlag), Type.Bool, + Macro(MSymbol('bond.is', Arguments.List(Struct.Types.BondFlag), Type.Bool, `Test if the current bond has at least one (or all if partial = false) of the specified flags: ${Type.oneOfValues(Struct.Types.BondFlag).join(', ')}`), args => B.core.flags.hasAny([B.struct.bondProperty.flags(), B.struct.type.bondFlags(M.getPositionalArgs(args))])), ]