nazuchem 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Accept the same IR object or JSON string as the facade's JSON reader.
3
+ * @param {any} input
4
+ * @returns {any}
5
+ */
6
+ export function moleculeToName(input) {
7
+ const ret = wasm.moleculeToName(input);
8
+ if (ret[2]) {
9
+ throw takeFromExternrefTable0(ret[1]);
10
+ }
11
+ return takeFromExternrefTable0(ret[0]);
12
+ }
13
+
14
+ /**
15
+ * Return a validated IR v1 plain object with the Rust JSON field names.
16
+ * @param {string} name
17
+ * @returns {any}
18
+ */
19
+ export function nameToMolecule(name) {
20
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
21
+ const len0 = WASM_VECTOR_LEN;
22
+ const ret = wasm.nameToMolecule(ptr0, len0);
23
+ if (ret[2]) {
24
+ throw takeFromExternrefTable0(ret[1]);
25
+ }
26
+ return takeFromExternrefTable0(ret[0]);
27
+ }
28
+
29
+ /**
30
+ * Interpret a name using the facade's strict name-to-structure policy.
31
+ * @param {string} name
32
+ * @returns {string}
33
+ */
34
+ export function nameToSmiles(name) {
35
+ let deferred3_0;
36
+ let deferred3_1;
37
+ try {
38
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
39
+ const len0 = WASM_VECTOR_LEN;
40
+ const ret = wasm.nameToSmiles(ptr0, len0);
41
+ var ptr2 = ret[0];
42
+ var len2 = ret[1];
43
+ if (ret[3]) {
44
+ ptr2 = 0; len2 = 0;
45
+ throw takeFromExternrefTable0(ret[2]);
46
+ }
47
+ deferred3_0 = ptr2;
48
+ deferred3_1 = len2;
49
+ return getStringFromWasm0(ptr2, len2);
50
+ } finally {
51
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Return the complete Rust Name, including nested preference assessment.
57
+ * @param {string} smiles
58
+ * @returns {any}
59
+ */
60
+ export function smilesToName(smiles) {
61
+ const ptr0 = passStringToWasm0(smiles, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
62
+ const len0 = WASM_VECTOR_LEN;
63
+ const ret = wasm.smilesToName(ptr0, len0);
64
+ if (ret[2]) {
65
+ throw takeFromExternrefTable0(ret[1]);
66
+ }
67
+ return takeFromExternrefTable0(ret[0]);
68
+ }
69
+ export function __wbg___wbindgen_is_undefined_8c687d0b90d5b524(arg0) {
70
+ const ret = arg0 === undefined;
71
+ return ret;
72
+ }
73
+ export function __wbg___wbindgen_string_get_92ab86bb19cbc12f(arg0, arg1) {
74
+ const obj = arg1;
75
+ const ret = typeof(obj) === 'string' ? obj : undefined;
76
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
77
+ var len1 = WASM_VECTOR_LEN;
78
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
79
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
80
+ }
81
+ export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
82
+ throw new Error(getStringFromWasm0(arg0, arg1));
83
+ }
84
+ export function __wbg_new_a32a1ab6c6655abe(arg0, arg1) {
85
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
86
+ return ret;
87
+ }
88
+ export function __wbg_now_e7c6795a7f81e10f(arg0) {
89
+ const ret = arg0.now();
90
+ return ret;
91
+ }
92
+ export function __wbg_parse_6937a9050adfb0e1() { return handleError(function (arg0, arg1) {
93
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
94
+ return ret;
95
+ }, arguments); }
96
+ export function __wbg_performance_3fcf6e32a7e1ed0a(arg0) {
97
+ const ret = arg0.performance;
98
+ return ret;
99
+ }
100
+ export function __wbg_set_a377297433dfea63() { return handleError(function (arg0, arg1, arg2) {
101
+ const ret = Reflect.set(arg0, arg1, arg2);
102
+ return ret;
103
+ }, arguments); }
104
+ export function __wbg_set_name_6e2a5da46a9ae1e7(arg0, arg1, arg2) {
105
+ arg0.name = getStringFromWasm0(arg1, arg2);
106
+ }
107
+ export function __wbg_static_accessor_GLOBAL_8eb4cd83130a11a0() {
108
+ const ret = typeof global === 'undefined' ? null : global;
109
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
110
+ }
111
+ export function __wbg_static_accessor_GLOBAL_THIS_1e7044f654e934db() {
112
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
113
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
114
+ }
115
+ export function __wbg_static_accessor_SELF_d8b50611246a6d92() {
116
+ const ret = typeof self === 'undefined' ? null : self;
117
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
118
+ }
119
+ export function __wbg_static_accessor_WINDOW_fd0bc376bf0f8b42() {
120
+ const ret = typeof window === 'undefined' ? null : window;
121
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
122
+ }
123
+ export function __wbg_stringify_54b3d9b61602aee6() { return handleError(function (arg0) {
124
+ const ret = JSON.stringify(arg0);
125
+ return ret;
126
+ }, arguments); }
127
+ export function __wbindgen_generic_0000000000000001(arg0, arg1) {
128
+ // Cast intrinsic for `Ref(String) -> Externref`.
129
+ const ret = getStringFromWasm0(arg0, arg1);
130
+ return ret;
131
+ }
132
+ export function __wbindgen_init_externref_table() {
133
+ const table = wasm.__wbindgen_externrefs;
134
+ const offset = table.grow(4);
135
+ table.set(0, undefined);
136
+ table.set(offset + 0, undefined);
137
+ table.set(offset + 1, null);
138
+ table.set(offset + 2, true);
139
+ table.set(offset + 3, false);
140
+ }
141
+ function addToExternrefTable0(obj) {
142
+ const idx = wasm.__externref_table_alloc();
143
+ wasm.__wbindgen_externrefs.set(idx, obj);
144
+ return idx;
145
+ }
146
+
147
+ let cachedDataViewMemory0 = null;
148
+ function getDataViewMemory0() {
149
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
150
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
151
+ }
152
+ return cachedDataViewMemory0;
153
+ }
154
+
155
+ function getStringFromWasm0(ptr, len) {
156
+ return decodeText(ptr >>> 0, len);
157
+ }
158
+
159
+ let cachedUint8ArrayMemory0 = null;
160
+ function getUint8ArrayMemory0() {
161
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
162
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
163
+ }
164
+ return cachedUint8ArrayMemory0;
165
+ }
166
+
167
+ function handleError(f, args) {
168
+ try {
169
+ return f.apply(this, args);
170
+ } catch (e) {
171
+ const idx = addToExternrefTable0(e);
172
+ wasm.__wbindgen_exn_store(idx);
173
+ }
174
+ }
175
+
176
+ function isLikeNone(x) {
177
+ return x === undefined || x === null;
178
+ }
179
+
180
+ function passStringToWasm0(arg, malloc, realloc) {
181
+ if (realloc === undefined) {
182
+ const buf = cachedTextEncoder.encode(arg);
183
+ const ptr = malloc(buf.length, 1) >>> 0;
184
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
185
+ WASM_VECTOR_LEN = buf.length;
186
+ return ptr;
187
+ }
188
+
189
+ let len = arg.length;
190
+ let ptr = malloc(len, 1) >>> 0;
191
+
192
+ const mem = getUint8ArrayMemory0();
193
+
194
+ let offset = 0;
195
+
196
+ for (; offset < len; offset++) {
197
+ const code = arg.charCodeAt(offset);
198
+ if (code > 0x7F) break;
199
+ mem[ptr + offset] = code;
200
+ }
201
+ if (offset !== len) {
202
+ if (offset !== 0) {
203
+ arg = arg.slice(offset);
204
+ }
205
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
206
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
207
+ const ret = cachedTextEncoder.encodeInto(arg, view);
208
+
209
+ offset += ret.written;
210
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
211
+ }
212
+
213
+ WASM_VECTOR_LEN = offset;
214
+ return ptr;
215
+ }
216
+
217
+ function takeFromExternrefTable0(idx) {
218
+ const value = wasm.__wbindgen_externrefs.get(idx);
219
+ wasm.__externref_table_dealloc(idx);
220
+ return value;
221
+ }
222
+
223
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
224
+ cachedTextDecoder.decode();
225
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
226
+ let numBytesDecoded = 0;
227
+ function decodeText(ptr, len) {
228
+ numBytesDecoded += len;
229
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
230
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
231
+ cachedTextDecoder.decode();
232
+ numBytesDecoded = len;
233
+ }
234
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
235
+ }
236
+
237
+ const cachedTextEncoder = new TextEncoder();
238
+
239
+ if (!('encodeInto' in cachedTextEncoder)) {
240
+ cachedTextEncoder.encodeInto = function (arg, view) {
241
+ const buf = cachedTextEncoder.encode(arg);
242
+ view.set(buf);
243
+ return {
244
+ read: arg.length,
245
+ written: buf.length
246
+ };
247
+ };
248
+ }
249
+
250
+ let WASM_VECTOR_LEN = 0;
251
+
252
+
253
+ let wasm;
254
+ export function __wbg_set_wasm(val) {
255
+ wasm = val;
256
+ }
Binary file
@@ -0,0 +1,70 @@
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+ // Origin: original
3
+ // Source: Nazuchem | bindings/wasm/scripts/build.ts | Phase B step 9
4
+ const raw = require("./nazuchem.js");
5
+ // SPDX-License-Identifier: MIT OR Apache-2.0
6
+ // Origin: original
7
+ // Source: Nazuchem | bindings/wasm/src/wrapper.js | Phase B step 9
8
+
9
+ class NazuchemError extends Error {
10
+ constructor(message, kind) {
11
+ super(message);
12
+ this.name = "NazuchemError";
13
+ this.kind = kind;
14
+ }
15
+ }
16
+
17
+ // The web target initializes Wasm after importing the module. Keep the constants
18
+ // in JS so they are available before initialization, while the build derives
19
+ // their values from the same Rust schema bundled in the release.
20
+ const IR_VERSION = 1;
21
+ const JSON_SCHEMA = "{\n \"$defs\": {\n \"Atom\": {\n \"additionalProperties\": false,\n \"description\": \"An atom with its stated hydrogen origin, locants, and attachment label.\\n\\nJSON omits zero charge, zero radical electrons, and false\\n`hydrogens_stated`, restoring those defaults when the fields are absent.\",\n \"properties\": {\n \"atom_map\": {\n \"description\": \"An explicit SMILES atom-map number, independent of text labels.\",\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": [\n \"integer\",\n \"null\"\n ]\n },\n \"attachment_point\": {\n \"description\": \"A numbered wildcard attachment, corresponding to OPSIN `_AP{n}`.\",\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": [\n \"integer\",\n \"null\"\n ]\n },\n \"charge\": {\n \"description\": \"Formal charge; defaults to zero when omitted from JSON.\",\n \"format\": \"int8\",\n \"maximum\": 127,\n \"minimum\": -128,\n \"type\": \"integer\"\n },\n \"element\": {\n \"description\": \"Atomic number; zero denotes a wildcard or attachment point.\",\n \"format\": \"uint8\",\n \"maximum\": 118,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"hydrogens\": {\n \"description\": \"Hydrogen atoms not represented as graph vertices.\",\n \"format\": \"uint8\",\n \"maximum\": 255,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"hydrogens_stated\": {\n \"description\": \"Distinguishes explicitly stated counts such as `[CH4]` from inferred `C`.\\nDefaults to false when omitted from JSON.\",\n \"type\": \"boolean\"\n },\n \"isotope\": {\n \"description\": \"Isotope mass number. Isotopic hydrogen is an atom, never a count.\",\n \"format\": \"uint16\",\n \"maximum\": 65535,\n \"minimum\": 1,\n \"type\": [\n \"integer\",\n \"null\"\n ]\n },\n \"label\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"locants\": {\n \"description\": \"All name locants, in name order. Parent membership controls display.\",\n \"items\": {\n \"type\": \"string\"\n },\n \"type\": \"array\"\n },\n \"radical_electrons\": {\n \"description\": \"Stated unpaired electron count; defaults to zero when omitted from JSON.\",\n \"format\": \"uint8\",\n \"maximum\": 255,\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"element\",\n \"hydrogens\"\n ],\n \"type\": \"object\"\n },\n \"AxialWinding\": {\n \"description\": \"Axis winding relative to its ordered references, independent of CIP ranking.\\n\\nLook along `bond.atoms[0]` toward `bond.atoms[1]`. The first reference pair is\\nattached to the near end, the second to the far end. `Clockwise` means the\\nshortest turn from the projection of `refs[0]` to `refs[2]` is clockwise;\\n`Anticlockwise` means anticlockwise. Swapping either pair reverses winding.\\nReversing the bond and exchanging the two pairs preserves winding. These\\nvalues describe the stored reference order, not CIP M/P descriptors; no\\nligand priorities are inferred. `Unknown` records stated unknown winding.\",\n \"enum\": [\n \"clockwise\",\n \"anticlockwise\",\n \"unknown\"\n ],\n \"type\": \"string\"\n },\n \"Bond\": {\n \"additionalProperties\": false,\n \"description\": \"A localized bond; endpoint order defines double-bond references and the position-variation attachment end.\",\n \"properties\": {\n \"atoms\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"maxItems\": 2,\n \"minItems\": 2,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"order\": {\n \"$ref\": \"#/$defs/BondOrder\"\n }\n },\n \"required\": [\n \"atoms\",\n \"order\"\n ],\n \"type\": \"object\"\n },\n \"BondOrder\": {\n \"enum\": [\n \"single\",\n \"double\",\n \"triple\",\n \"quadruple\"\n ],\n \"type\": \"string\"\n },\n \"Connectivity\": {\n \"enum\": [\n \"head_to_tail\",\n \"head_to_head\",\n \"unknown\"\n ],\n \"type\": \"string\"\n },\n \"PositionVariation\": {\n \"additionalProperties\": false,\n \"description\": \"Possible attachment endpoints for a position-variation bond.\",\n \"properties\": {\n \"bond\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"endpoints\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n }\n },\n \"required\": [\n \"bond\",\n \"endpoints\"\n ],\n \"type\": \"object\"\n },\n \"Ref\": {\n \"anyOf\": [\n {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n {\n \"enum\": [\n \"implicit_hydrogen\",\n \"lone_pair\"\n ],\n \"type\": \"string\"\n }\n ]\n },\n \"Relation\": {\n \"enum\": [\n \"cis\",\n \"trans\",\n \"unknown\"\n ],\n \"type\": \"string\"\n },\n \"RepeatUnit\": {\n \"additionalProperties\": false,\n \"description\": \"A repeating unit, including its bonds to atoms outside the unit.\",\n \"properties\": {\n \"atoms\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"attachment_points\": {\n \"description\": \"External wildcard atom identities that represent polymer end roles.\",\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"connectivity\": {\n \"$ref\": \"#/$defs/Connectivity\"\n },\n \"crossing_bonds\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"label\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n }\n },\n \"required\": [\n \"atoms\",\n \"connectivity\"\n ],\n \"type\": \"object\"\n },\n \"Stereo\": {\n \"description\": \"Ordered structural stereochemistry, independent of CIP assignment.\\n\\nUnknown winding/relation records stated unknown (wavy/ξ) stereochemistry;\\nan absent entry means unspecified stereochemistry. For a double bond,\\n`refs[i]` is attached to `bonds[bond].atoms[i]`. For an atropisomer,\\n`refs[0..2]` are attached to the first bond end and `refs[2..4]` to the second.\\nAxial chirality of allenes and other cumulenes is not representable in v1.\\nEquality is structural: equivalent configurations with permuted references\\nand adjusted winding can compare unequal.\",\n \"oneOf\": [\n {\n \"additionalProperties\": false,\n \"properties\": {\n \"center\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"kind\": {\n \"const\": \"tetrahedral\",\n \"type\": \"string\"\n },\n \"neighbors\": {\n \"items\": {\n \"$ref\": \"#/$defs/Ref\"\n },\n \"maxItems\": 4,\n \"minItems\": 4,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"winding\": {\n \"$ref\": \"#/$defs/Winding\"\n }\n },\n \"required\": [\n \"kind\",\n \"center\",\n \"neighbors\",\n \"winding\"\n ],\n \"type\": \"object\"\n },\n {\n \"additionalProperties\": false,\n \"properties\": {\n \"bond\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"kind\": {\n \"const\": \"double_bond\",\n \"type\": \"string\"\n },\n \"refs\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"maxItems\": 2,\n \"minItems\": 2,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"relation\": {\n \"$ref\": \"#/$defs/Relation\"\n }\n },\n \"required\": [\n \"kind\",\n \"bond\",\n \"refs\",\n \"relation\"\n ],\n \"type\": \"object\"\n },\n {\n \"additionalProperties\": false,\n \"properties\": {\n \"bond\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"kind\": {\n \"const\": \"atropisomer\",\n \"type\": \"string\"\n },\n \"refs\": {\n \"items\": {\n \"$ref\": \"#/$defs/Ref\"\n },\n \"maxItems\": 4,\n \"minItems\": 4,\n \"type\": \"array\"\n },\n \"winding\": {\n \"$ref\": \"#/$defs/AxialWinding\"\n }\n },\n \"required\": [\n \"kind\",\n \"bond\",\n \"refs\",\n \"winding\"\n ],\n \"type\": \"object\"\n }\n ]\n },\n \"StereoGroup\": {\n \"oneOf\": [\n {\n \"additionalProperties\": false,\n \"properties\": {\n \"id\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"kind\": {\n \"const\": \"and\",\n \"type\": \"string\"\n },\n \"stereo\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n }\n },\n \"required\": [\n \"kind\",\n \"id\",\n \"stereo\"\n ],\n \"type\": \"object\"\n },\n {\n \"additionalProperties\": false,\n \"properties\": {\n \"id\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"kind\": {\n \"const\": \"or\",\n \"type\": \"string\"\n },\n \"stereo\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n }\n },\n \"required\": [\n \"kind\",\n \"id\",\n \"stereo\"\n ],\n \"type\": \"object\"\n }\n ]\n },\n \"Winding\": {\n \"description\": \"Tetrahedral winding, viewed from `neighbors[0]` toward the center.\\n\\n`Clockwise` means `neighbors[1]`, `neighbors[2]`, `neighbors[3]` occur in\\nclockwise order in that view; `Anticlockwise` means the reverse order.\\n`Unknown` records explicitly unknown configuration. No stereo entry means\\nunspecified configuration.\",\n \"enum\": [\n \"clockwise\",\n \"anticlockwise\",\n \"unknown\"\n ],\n \"type\": \"string\"\n }\n },\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"atoms\": {\n \"items\": {\n \"$ref\": \"#/$defs/Atom\"\n },\n \"type\": \"array\"\n },\n \"bonds\": {\n \"items\": {\n \"$ref\": \"#/$defs/Bond\"\n },\n \"type\": \"array\"\n },\n \"nazuchem_ir\": {\n \"const\": 1,\n \"type\": \"integer\"\n },\n \"parent\": {\n \"items\": {\n \"format\": \"uint32\",\n \"maximum\": 4294967295,\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"polymers\": {\n \"items\": {\n \"$ref\": \"#/$defs/RepeatUnit\"\n },\n \"type\": \"array\"\n },\n \"position_variation\": {\n \"items\": {\n \"$ref\": \"#/$defs/PositionVariation\"\n },\n \"type\": \"array\"\n },\n \"stereo\": {\n \"items\": {\n \"$ref\": \"#/$defs/Stereo\"\n },\n \"type\": \"array\"\n },\n \"stereo_groups\": {\n \"items\": {\n \"$ref\": \"#/$defs/StereoGroup\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"nazuchem_ir\",\n \"atoms\",\n \"bonds\"\n ],\n \"title\": \"Molecule\",\n \"type\": \"object\"\n}\n";
22
+
23
+ function call(operation, value) {
24
+ try {
25
+ return operation(value);
26
+ } catch (source) {
27
+ if (source instanceof Error && source.name === "NazuchemError") {
28
+ throw new NazuchemError(source.message, source.kind);
29
+ }
30
+ if (source instanceof WebAssembly.RuntimeError) {
31
+ throw new NazuchemError(source.message, "internal");
32
+ }
33
+ throw source;
34
+ }
35
+ }
36
+
37
+ function nameToSmiles(name) { return call(raw.nameToSmiles, name); }
38
+ function flattenName(result) {
39
+ return {
40
+ text: result.text,
41
+ omittedStereo: result.omitted_stereo,
42
+ omittedUnits: result.omitted_units,
43
+ verification: result.verification,
44
+ status: result.status.status,
45
+ reason: result.status.reason ?? null,
46
+ alternatives: result.alternatives.map((alternative) => ({
47
+ name: alternative.name,
48
+ status: alternative.status.status,
49
+ reason: alternative.status.reason ?? null,
50
+ })),
51
+ };
52
+ }
53
+ function smilesToName(smiles) { return flattenName(call(raw.smilesToName, smiles)); }
54
+ function nameToMolecule(name) { return call(raw.nameToMolecule, name); }
55
+ // JSON.stringify would silently turn nonfinite numbers into null. Validate the
56
+ // supplied object first so nullable IR fields cannot discard invalid input.
57
+ function assertFiniteNumbers(value, seen = new WeakSet()) {
58
+ if (typeof value === "number" && !Number.isFinite(value)) {
59
+ throw new NazuchemError("molecule numbers must be finite", "serialize");
60
+ }
61
+ if (value === null || typeof value !== "object" || seen.has(value)) return;
62
+ seen.add(value);
63
+ for (const child of Object.values(value)) assertFiniteNumbers(child, seen);
64
+ }
65
+ function moleculeToName(molecule) {
66
+ assertFiniteNumbers(molecule);
67
+ return flattenName(call(raw.moleculeToName, molecule));
68
+ }
69
+
70
+ module.exports = { NazuchemError, IR_VERSION, JSON_SCHEMA, nameToSmiles, smilesToName, nameToMolecule, moleculeToName };
@@ -0,0 +1,109 @@
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+ // Origin: original
3
+ // Source: Nazuchem | bindings/wasm/src/index.d.ts | Phase B step 9
4
+
5
+ /** Rust serde vocabulary; preference is independent of identity verification. */
6
+ export type NameReason =
7
+ | "sulfonyl_prefix" | "amino_prefix" | "cation_prefix" | "functional_class"
8
+ | "hydride_parent" | "unretained_parent" | "diamide_locants" | "fusion_component"
9
+ | "unregistered_retained_component" | "higher_order_fusion" | "benzo_fusion"
10
+ | "multiplicative" | "acyl_prefix" | "ring_assembly" | "von_baeyer_fusion_fallback"
11
+ | "linear_phane" | "opsin_fusion_layout" | "fusion_multiparent" | "hydro_prefix_locants"
12
+ | "bridged_fused_parent" | "unaudited_parent" | "unaudited_path"
13
+ | "substituted_retained_parent" | "atom_order" | "amine_chalcogenide"
14
+ | "amine_oxide_zwitterion" | "principal_group_tie" | "lambda_parent_hydrogen"
15
+ | "spiro_hydrogen" | "isotope_placement" | "boughton_isotope" | "radical_ion"
16
+ | "anion_parent" | "cation_parent" | "ionic_suffix_order" | "salt_ion_order"
17
+ | "adduct" | "phane" | "relative_ring_stereo" | "endo_exo_stereo" | "unknown_configuration"
18
+ | "axial_alternative";
19
+
20
+ export type NameStatus = "preferred" | "not_preferred" | "unverified";
21
+
22
+ export interface AlternativeName {
23
+ name: string;
24
+ status: NameStatus;
25
+ reason: NameReason | null;
26
+ }
27
+
28
+ export interface Verification {
29
+ name: string;
30
+ smiles: string;
31
+ }
32
+
33
+ /** Complete naming result; Rust's tagged status is flattened as status/reason. */
34
+ export interface Name {
35
+ text: string;
36
+ status: NameStatus;
37
+ reason: NameReason | null;
38
+ alternatives: AlternativeName[];
39
+ omittedStereo: string[];
40
+ omittedUnits: number;
41
+ verification: Verification | null;
42
+ }
43
+
44
+ /** Integer ranges and graph constraints are enforced by the Rust IR reader. */
45
+ export interface Atom {
46
+ element: number;
47
+ hydrogens: number;
48
+ isotope?: number | null;
49
+ charge?: number;
50
+ hydrogens_stated?: boolean;
51
+ radical_electrons?: number;
52
+ label?: string | null;
53
+ atom_map?: number | null;
54
+ attachment_point?: number | null;
55
+ locants?: string[];
56
+ }
57
+
58
+ export type BondOrder = "single" | "double" | "triple" | "quadruple";
59
+ export interface Bond { atoms: [number, number]; order: BondOrder }
60
+ export type Ref = number | "implicit_hydrogen" | "lone_pair";
61
+ export type Winding = "clockwise" | "anticlockwise" | "unknown";
62
+ export type AxialWinding = "clockwise" | "anticlockwise" | "unknown";
63
+ export type Relation = "cis" | "trans" | "unknown";
64
+
65
+ /** Ordered structural stereo; these windings do not encode CIP labels. */
66
+ export type Stereo =
67
+ | { kind: "tetrahedral"; center: number; neighbors: [Ref, Ref, Ref, Ref]; winding: Winding }
68
+ | { kind: "double_bond"; bond: number; refs: [number, number]; relation: Relation }
69
+ | { kind: "atropisomer"; bond: number; refs: [Ref, Ref, Ref, Ref]; winding: AxialWinding };
70
+
71
+ export type StereoGroup =
72
+ | { kind: "and"; id: number; stereo: [number, ...number[]] }
73
+ | { kind: "or"; id: number; stereo: [number, ...number[]] };
74
+
75
+ export type Connectivity = "head_to_tail" | "head_to_head" | "unknown";
76
+ export interface RepeatUnit {
77
+ atoms: [number, ...number[]];
78
+ connectivity: Connectivity;
79
+ crossing_bonds?: number[];
80
+ attachment_points?: number[];
81
+ label?: string | null;
82
+ }
83
+ export interface PositionVariation { bond: number; endpoints: [number, ...number[]] }
84
+
85
+ /** Exact IR v1 JSON shape. Optional fields take the Rust defaults when absent. */
86
+ export interface Molecule {
87
+ nazuchem_ir: 1;
88
+ atoms: Atom[];
89
+ bonds: Bond[];
90
+ stereo?: Stereo[];
91
+ stereo_groups?: StereoGroup[];
92
+ position_variation?: PositionVariation[];
93
+ polymers?: RepeatUnit[];
94
+ parent?: number[];
95
+ }
96
+
97
+ export type ErrorKind = "init" | "parse" | "warning" | "serialize" | "naming" | "internal";
98
+ export class NazuchemError extends Error {
99
+ readonly kind: ErrorKind;
100
+ constructor(message: string, kind: ErrorKind);
101
+ }
102
+
103
+ export const IR_VERSION: 1;
104
+ /** Published draft-2020-12 schema as a JSON string, identical to Rust JSON_SCHEMA. */
105
+ export const JSON_SCHEMA: string;
106
+ export function nameToSmiles(name: string): string;
107
+ export function smilesToName(smiles: string): Name;
108
+ export function nameToMolecule(name: string): Molecule;
109
+ export function moleculeToName(molecule: Molecule | string): Name;