From 3cba621fcf54cacc0abb3d15e9cc97e9f707e753 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 13 May 2023 16:22:50 -0700 Subject: [PATCH] add cantor-pairing functions to mol-script --- CHANGELOG.md | 1 + src/mol-script/language/symbol-table/core.ts | 8 ++++---- src/mol-script/runtime/query/table.ts | 6 +++++- src/mol-script/script/mol-script/symbols.ts | 3 +++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e8354d4c..5d2891175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Note that since we don't clearly distinguish between a public and private interf - Support `ignoreHydrogens` in interactions representation - Add hydroxyproline (HYP) commonly present in collagen molecules to the list of amino acids - Fix assemblies for Archive PDB files (do not generate unique `label_asym_id` if `REMARK 350` is present) +- Add cantor-pairing functions to `mol-script` ## [v3.34.0] - 2023-04-16 diff --git a/src/mol-script/language/symbol-table/core.ts b/src/mol-script/language/symbol-table/core.ts index 4661b69bc..6692c5d5e 100644 --- a/src/mol-script/language/symbol-table/core.ts +++ b/src/mol-script/language/symbol-table/core.ts @@ -46,10 +46,6 @@ export const TTargs = Arguments.Dictionary({ 1: Argument(Type.Num) }); -const XX = { test: Argument(Type.Str) }; -const t: Arguments.PropTypes<typeof XX> = 0 as any; -t.test; - const type = { '@header': 'Types', bool: symbol(Arguments.Dictionary({ 0: Argument(Type.AnyValue) }), Type.Bool, 'Convert a value to boolean.'), @@ -116,6 +112,10 @@ const math = { min: binOp(Type.Num), max: binOp(Type.Num), + cantorPairing: binRel(Type.Num, Type.Num), + sortedCantorPairing: binRel(Type.Num, Type.Num), + invertCantorPairing: symbol(Arguments.Dictionary({ 0: Argument(Type.Num) }), Types.List(Type.Num)), + floor: unaryOp(Type.Num), ceil: unaryOp(Type.Num), roundInt: unaryOp(Type.Num), diff --git a/src/mol-script/runtime/query/table.ts b/src/mol-script/runtime/query/table.ts index a87b23c7e..eee428041 100644 --- a/src/mol-script/runtime/query/table.ts +++ b/src/mol-script/runtime/query/table.ts @@ -12,7 +12,7 @@ import { ElementSymbol, BondType, SecondaryStructureType } from '../../../mol-mo import { SetUtils } from '../../../mol-util/set'; import { upperCaseAny } from '../../../mol-util/string'; import { VdwRadius, AtomWeight, AtomNumber } from '../../../mol-model/structure/model/properties/atomic'; -import { cantorPairing } from '../../../mol-data/util'; +import { cantorPairing, invertCantorPairing, sortedCantorPairing } from '../../../mol-data/util'; import { bundleElementImpl, bundleGenerator } from '../../../mol-model/structure/query/queries/internal'; import { arrayEqual } from '../../../mol-util/array'; @@ -118,6 +118,10 @@ const symbols = [ return ret; }), + C(MolScript.core.math.cantorPairing, (ctx, v) => cantorPairing(v[0](ctx), v[1](ctx))), + C(MolScript.core.math.sortedCantorPairing, (ctx, v) => sortedCantorPairing(v[0](ctx), v[1](ctx))), + C(MolScript.core.math.invertCantorPairing, (ctx, v) => invertCantorPairing([0, 0], v[0](ctx))), + C(MolScript.core.math.floor, (ctx, v) => Math.floor(v[0](ctx))), C(MolScript.core.math.ceil, (ctx, v) => Math.ceil(v[0](ctx))), C(MolScript.core.math.roundInt, (ctx, v) => Math.round(v[0](ctx))), diff --git a/src/mol-script/script/mol-script/symbols.ts b/src/mol-script/script/mol-script/symbols.ts index feb891928..fa9243edc 100644 --- a/src/mol-script/script/mol-script/symbols.ts +++ b/src/mol-script/script/mol-script/symbols.ts @@ -54,6 +54,9 @@ export const SymbolTable = [ Alias(MolScript.core.math.mod, 'mod'), Alias(MolScript.core.math.min, 'min'), Alias(MolScript.core.math.max, 'max'), + Alias(MolScript.core.math.cantorPairing, 'cantor-pairing'), + Alias(MolScript.core.math.sortedCantorPairing, 'sorted-cantor-pairing'), + Alias(MolScript.core.math.invertCantorPairing, 'invert-cantor-pairing'), Alias(MolScript.core.math.floor, 'floor'), Alias(MolScript.core.math.ceil, 'ceil'), Alias(MolScript.core.math.roundInt, 'round'), -- GitLab